256 color palette
BlitzPlus Forums/BlitzPlus Programming/256 color palette
| ||
For the past two hours, I've been trying to write an algorithm to make a 8-bit color palette. I have failed. Could someone write one for me? Or could someone give me a good image of an 8-bit palette? I'm using panels and SetPanelColor(). This is the array of panels: Dim hPalette(256) And I need each one filled with a certain color. There are 32 rows and 8 columns. I'm not really good at mixing colors... and this is the best I could come up with: For p=0 To 85 SetPanelColor(hPalette(p),colr,colg,colb) colr=colr+3 Next colr=0 For p=86 To 170 SetPanelColor(hPalette(p),colr,colg,colb) colg=colg+3 Next colg=0 For p=170 To 256 SetPanelColor(hPalette(p),colr,colg,colb) colb=colb+3 Next |
| ||
you want a panel for each selectable color ???? 10 goto "plan B" :) |
| ||
tadaa, an 8-bit palette in less then 18 minutes :) I could add more features, like one to update the palette image with new colors, but that should be doable by you already .. if you really want clean routines, try to work with banks and make a fool-proof 'gadget' out of it, see the tutorials for that. ; small 8-bit palette, by CS_TBL ; Blitzplus window=CreateWindow("palette",0,0,640,480) ; RGB values are stored in: paletteR(0..255),paletteG(0..255),paletteB(0..255) Dim paletteR(255),paletteG(255),paletteB(255) For t=0 To 239 paletteR(t)=Rnd(0,255) paletteG(t)=Rnd(0,255) paletteB(t)=Rnd(0,255) Next For t=240 To 255 paletteR(t)=i paletteG(t)=i paletteB(t)=i i=i+16 Next ; 256 squares, 16x16, each square is 16x16 in size: Global palette=CreateCanvas(32,32,16*16,16*16,window) Global currentcolor=255 ; currentcolor always has the current drawing color ; make an image of the palette ( see palettedraw() ) Global paletteIMG=CreateImage(16*16,16*16) SetBuffer ImageBuffer(paletteIMG) t=0 For y=0 To 15 For x=0 To 15 Color paletteR(t),paletteG(t),paletteB(t) Rect x*16,y*16,16,16,True t=t+1 Next Next SetBuffer DesktopBuffer() ; initialize palettedraw() ;----------------------------------- Repeat WaitEvent() If EventID()=$803 quit=True paletteactions() Until quit ;----------------------------------- End ;----------------------------------- Function palettedraw() SetBuffer CanvasBuffer(palette) DrawBlock paletteIMG,0,0 x=(currentcolor Mod 16) y=currentcolor / 16 Color 255,255,255: Rect x*16,y*16,16,16,False Color 0,0,0: Rect x*16+1,y*16+1,14,14,False FlipCanvas palette End Function Function paletteactions() If EventSource()=palette If EventID()=$201 If EventData()=1 mx=EventX()/16 my=EventY()/16 If mx<0 mx=0 If my<0 my=0 If mx>15 mx=15 If my>15 my=15 currentcolor=mx+my*16 palettedraw() EndIf EndIf EndIf End Function |
| ||
See all that stuff in there Homer? That's why your robot didn't work! |
| ||
Ehhh... I mean a "true" 8-bit palette. Not 256 randomly selected colors. |
| ||
what is a 'true' 8-bit palette ? :) |
| ||
What exactly are you trying to accomplish? Have a 'generic' 8 bit pallete that can show 'any' color (and has several different shades of all colors in it), or do you want to find the best looking palette to represent a particular true-color image in? Those would be two entirely different problems to solve, so we really would need more info on what you are trying to do here. |
| ||
I'm not too good at colors. I'm talking about making a palette that would be compatible with a 256 color monitor. |
| ||
a .. "256 color monitor" ?? Sorry, but I really miss the point here, do you want a 'palette' (a specific list with 256 RGB values)? Or do you want a B+ 'gadget' to show the palette, and with the possibiliy to select one? |
| ||
As blue is I think least easy for human eye to recognize I would try encoding the 8 bits as 3:3:2 RGB format:For p=0 To 255 colr=p and $e0 colg=(p and $1c) shl 3 colb=(p and $3) shl 6 SetPanelColor(hPalette(p),colr,colg,colb) Next If you want to fit in with Windows you only have 236 custom colors, as the first and last 10 colors are predefined. |
| ||
If you know any C++ you could always get a copy of allegro(free) and write a true 256 color display userlib. it's only a couple of function calls in allegro to set on up..and they're v.fast.(-edit- err cos it has a bunch of palette functions to go with it) |
| ||
I thought Blitz wouldn't run in 8-bit mode anyway? |
| ||
I thought Blitz wouldn't run in 8-bit mode anyway? You are right -- so even when you restrict yourself to a 256 color palette, the game still wouldn't work since internally blitz requires at least a 16 bit (high color) display. |
| ||
Screw it -- I'll continue learning assembly. |
| ||
Hold on a sec, deadmoap. Is there any particular reason you don't want to use high color (15\16 bit) or true color (24\32 bit) graphics? I haven't seen a 256 color digital monitor since the IBM 286 days! A long time ago, 8 bit displays were quite a bit faster then the new upstart 'high color' display cards because graphics chips at that time were slow and didn't have dedicated graphics processor, etc. Nowadays, though, there isn't much of an advantage except these two points: half to one third as much memory (8 bits versus 16 or 24\32) and color cycling animation (low cpu overhead). But since fast gfx cards are plentiful and cheap and B+ doesn't support register-based graphics (Purebasic does, though ;) then the point is moot anyways! If I were you, I'd forget about the 8 bit display unless you are programming for a REALLY old system, in which case you'd probably want a dos-based programming langauge anyway! Hope this helps, Russell |
| ||
Definetely what Russell said :D deadmoap, if you are on an older system, or programing for an older system with an old EGA or VGA graphics card (back in the days of MS-DOS) then I'll assume you are familure with good old Quickbasic...if so do some google searches for that and I'm sure there are folks and websites to help you...Off hand I can't recall the exact DOS interupts used to assign/read/adjust the palette...then again DOS used a different memory system then currently in use (I can recall the headaches involved in trying to do things outside the 640k Dos limit...EMS and XMS memory utilities and libraries helped reach much of that protected memory realistate...Gack!, I for one am glad those old MS-DOS days are gone) Anyway... Blitz can load, and you can use 8-bit paletted images just fine...even greyscale, 16 color (4-bit), and I think even good old 1-bit (pure black and white) images too...Blitz converts the images when loading to either 16 or 32 bit color (depending on what you have the color depth set to) However to do any of the infamous old 8-bit paletteing tricks, you will need to figure out a way to emulate such... |
| ||
If I'm not mistaken... 256 color modes were 16 bit color, just that they could only display 256 colors simultaneously. You still chose those colors from RGB * 256 shades.......... So there's no such thing as a "true" 256 color palette as you suggest. |
| ||
256 color "register" modes used 256 18-bit color tables. That is, (if I remember correctly...it's been a while) each 8 bit pixel pointed to one of the 18-bit color registers so that any REGISTER could be any of 262,144 colors. Although only 256 DIFFERENT different colors could be defined at any one time...unless you used special tricks. There still are some uses for this mode (games), but for the most part it has been largely abandoned. 32 bit mode is nice, if you have use for the alpha channel. But I wonder why there are no 48 bit output modes to be used with HDRI imaging? Russell |