Making a palette?

Blitz3D Forums/Blitz3D Beginners Area/Making a palette?

JBR(Posted 2009) [#1]
Hi, need to create maybe a 1024 colour palette.

It needs to have 'main' colours such as red, green, blue, etc and some shades.

Is there somewhere I can get such a palette or maybe cannabolize one from somewhere?

Thanks
Jim


jfk EO-11110(Posted 2009) [#2]
I'm not sure if I understand you right. Palette was something that was used when Computers had 256 Colors only, but each one could be any eg. 24 Bit RGB Color.

So I don't know why you would need that, simply use the 256 Colors you want.

If you want to reduce the number of colors from eg. a photo then you might use a bitwise color detail reduction. Simply start erasing the lower significant bits of Colors:

rgb=readpixel(x,y) and $FFFFFF ; get original RGB

r=(rgb and $FF0000) shr 16 ;  separate red, green and blue
g=(rgb and $FF00) shr 8
b=(rgb and $FF)

r=r and %11111000 ; erase 3 lowest significant bits
g=g and %11111000
b=b and %11111000
rgb2= (r shl 16) or (g shl 8) or (b) ; re-assambling rgb

writepixelfast x,y,rgb2



Bobysait(Posted 2009) [#3]
Of just apply a mask to the pixel.
rgb2=ReadPixel(x,y) And $F0F0F0



JBR(Posted 2009) [#4]
Thanks guys.

Jim


jfk EO-11110(Posted 2009) [#5]
Bobysait is right, his suggestion is much easier, altough I tried to show how the bits work :)

Now I think I understand what you was talking about. A simple palette for a color picker, right?. Well you may use any true color palette and then reduce the color detail, as described earlier. Or try google images "palette". (Interestingly, with "palette 256" I get much better hits than with "palette 1024")


JBR(Posted 2009) [#6]
Thanks again, yes I'm just looking for a 'color picker' with limited colours. So getting the palette from an image may work for me.

Jim


Ginger Tea(Posted 2009) [#7]
Interestingly, with "palette 256" I get much better hits than with "palette 1024"


and so you would, no clut (colour look up table) used anything higher than 256 indexes, once we reached 24bit colour as standard VGA as was became redundant in all but .gif files.

in the dos days having multiple paletts was handy as you could change the hero's colour by swapping the 16 or so colours you had assigned to his uniform with another


_PJ_(Posted 2009) [#8]
I might niot be 100% on what oytu're after, but it sounds like you just want to be able to allow the user to pick fropm a limited (i.e. 256 colours) selection?

Something I worked with before I dived in and wernt with the 'full' colour-picker of Blitzsys was simply create with code or draw in paint a 16*16 image with all of the colour range you want, then have a function which grabs the data either by GetColor from the image as displayed, or, perhaps if it's a code-generated palette, as a formulae of the X/Y location on the palette iage:

if thius isn't so clear, here's a sample of some code:

 Graphics 800,600
SetBuffer BackBuffer()

Global Palette=BuildPalette()


Global CurrentRed=255
Global CurrentGreen=255
Global CurrentBlue=255

While Not KeyDown(1)
	
	DrawImage Palette,GraphicsWidth() - ImageWidth(Palette),0
	Color 255,255,255
	Rect 0,0,128,64,False
	Color CurrentRed,CurrentGreen,CurrentBlue
	Rect 1,1,126,62,True
	
	If (MouseDown(1))
		If ((MouseX()>(GraphicsWidth() - ImageWidth(Palette))) And (MouseY()<ImageHeight(Palette)))
			PickColor(MouseX(),MouseY())
		End If
	End If
	Flip
Wend
End

Function BuildPalette()
	
	Local PaletteImage=CreateImage(64,64)	; Note 64 is used instead of 16, single pixels are likely too small to select accurately witht he mouse cursor.
	
	SetBuffer ImageBuffer(PaletteImage)
	
	Local IterRed=0
	Local IterGreen=0
	Local IterBlue=0
	
	For IterRed=0 To 7
		For IterGreen=0 To 7
			Color IterRed Shl 6,IterGreen Shl 6,IterBlue Shl 6
			Rect IterRed Shl 2,IterGreen Shl 2,4,4,True
		Next
	Next
	IterGreen=0
	For IterRed=8 To 15
		For IterBlue=0 To 7
			Color (IterRed-8) Shl 6,IterGreen Shl 6,IterBlue Shl 6
			Rect IterRed Shl 2,IterBlue Shl 2,4,4,True
		Next
	Next
	IterRed=0
	For IterGreen=0 To 7
		For IterBlue=8 To 15
			Color IterRed Shl 6,IterGreen Shl 6,(IterBlue - 8) Shl 6
			Rect IterGreen Shl 2,IterBlue Shl 2,4,4,True
		Next
	Next
	
	For IterGreen=8 To 15
		For IterBlue=8 To 15
			Color (IterBlue - 8) Shl 6,(IterBlue - 8) Shl 6,(IterBlue - 8) Shl 6
			Rect IterGreen Shl 2,IterBlue Shl 2,4,4,True
		Next
	Next
	
	SetBuffer BackBuffer()
	Return PaletteImage
End Function

Function PickColor(X,Y)
	GetColor X,Y
	CurrentRed=ColorRed()
	CurrentGreen=ColorGreen()
	CurrentBlue=ColorBlue()
End Function



JBR(Posted 2009) [#9]
Thanks Malice.