Making Images Straight from the Palette

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
XMLTorrent
Newbie
Posts: 6
Joined: Tue Aug 29, 2006 1:40 pm
Location: United States
Contact:

Making Images Straight from the Palette

Post by XMLTorrent »

Okay I know about the OUT command and the hexadecimal addresses for reading and writing to the palette.

My question is since mode 13 is 256 color mode and those stupid standard DOS colors only go to 16, is there anyway for me to extract the RGB colors from the palette, store the colors in an array, and then use those RGB arrays to create images with?

For example, like I wanted to read a block of data statements that contained the RGB values I extracted from the palette.

Or would this be easier accomplished by simply loading a bitmap file into memory and then displaying that on the screen? Thanks in advance.
User avatar
Stoves
Veteran
Posts: 101
Joined: Fri Feb 10, 2006 12:24 am
Location: Nashville, TN

Questing for The Palette

Post by Stoves »

What do you mean by "the Palette"?

Reading your post is slightly confusing, because at first you seem to be talking about the screen palette when you mention that screen 13 has 256 attributes, but then it seems like you switch to the actual screen pixel colors when you talk about saving the individual RGB colors of the pixels that make up the screen picture. That said, I'm not entirely sure what you're asking, so this will be a long post. Sorry. Since you said you're already familiar with OUT, hex addreses, etc., I'll just post relevant code.

BTW, take a look at Pete's collection of Palette and Colors tutorials at http://www.petesqbsite.com/sections/tut ... cs.shtml#3 for more info.

Capturing the current palette

Code: Select all

SCREEN 13

DIM pal(255, 2) AS INTEGER
DIM attribute AS INTEGER

FOR attribute = 0 TO 255
  OUT &H3C7, attribute
  pal(attribute, 0) = INP(&H3C9)
  pal(attribute, 1) = INP(&H3C9)
  pal(attribute, 2) = INP(&H3C9)
NEXT attribute
Saving a palette to a file

Code: Select all

DIM f AS INTEGER

f = FREEFILE

OPEN "palFile" FOR BINARY AS #f
  FOR attribute = 0 TO 255
    PUT #f, , pal(attribute, 0)
    PUT #f, , pal(attribute, 1)
    PUT #f, , pal(attribute, 2)
  NEXT attribute
CLOSE #f

Loading the current palette from a file

Code: Select all

f = FREEFILE

OPEN "palFile" FOR BINARY AS #f
  FOR attribute = 0 TO 255
    GET #f, , pal(attribute, 0)
    GET #f, , pal(attribute, 1)
    GET #f, , pal(attribute, 2)
  NEXT attribute
CLOSE #f
Clearing the current palette

Code: Select all

FOR attribute = 0 TO 255
  OUT &H3C8, attribute
  OUT &H3C9, 0
  OUT &H3C9, 0
  OUT &H3C9, 0
NEXT attribute
Setting the current palette

Code: Select all

FOR attribute = 0 TO 255
  OUT &H3C8, attribute
  OUT &H3C9, pal(attribute, 0)
  OUT &H3C9, pal(attribute, 1)
  OUT &H3C9, pal(attribute, 2)
NEXT attribute
Changing the color of a specific palette attribute

Code: Select all

DIM red AS INTEGER, green AS INTEGER, blue AS INTEGER

attribute = 15     ' change the default white palette color
red = 63            ' use the maximum amount of red
green = 0          ' use the minimum amount of green
blue = 50           ' use a decent amount of blue

'change attribute 15 to a purplish color
OUT &H3C8, attribute
OUT &H3C9, red
OUT &H3C9, green
OUT &H3C9, blue
Getting the "color"/attribute of a particular screen pixel

Code: Select all

DIM screenPosX AS INTEGER, screenPosY AS INTEGER, screenWidth AS LONG

screenWidth = 320

screenPosX = 150
screenPosY = 100

DEF SEG = &HA000
attribute = PEEK((screenPosX - 1) + ((screenPosY - 1) * screenWidth)
DEF SEG
Setting the "color"/attribute of a particular screen pixel

Code: Select all

REDIM screenWidth AS LONG

attribute = 14   'Yellow by default

DEF SEG = &HA000
POKE((screenPosx - 1) + ((screenPosY - 1) * screenWidth), attribute)
DEF SEG
Saving the current screen to a file

Code: Select all

DIM pixelsToSave AS INTEGER, screenHeight AS LONG

screenWidth = 320
screenHeight =200
pixelsToSave = screenHeight * screenWidth

DEF SEG = &HA000
BSAVE "scrnshot.pic", 0, pixelsToSave
DEF SEG
Loading a screenshot from a file to the screen

Code: Select all

DEF SEG = &HA000
BLOAD "scrnshot.pic"
DEF SEG
XMLTorrent
Newbie
Posts: 6
Joined: Tue Aug 29, 2006 1:40 pm
Location: United States
Contact:

Post by XMLTorrent »

Thanks a lot. That's exactly what I wanted. I apologize for the "un-clarity" of my post. I was trying to say what I wanted and it came out completely different. :o
Post Reply