PDA

View Full Version : Genesis Colour Palette



matteus
05-19-2008, 06:16 AM
Bare with me i'm still learning but the genesis uses 3 bit RGB I gather.

So I was pondering how I'd generate a colour palette to display all possible colours using something like C# or VB?

what are the increments for each RGB Value?

TmEE
05-19-2008, 07:30 AM
DIM Colors&(511)
i%=0
for R%=0 to 7
for G%=0 to 7
for B%=0 to 7
Colors&(i%)=((R%*36)*&H10000) OR ((G%*36)+&100) OR (B%*36)
i%=i%+1
next B%, G%, R%

matteus
05-19-2008, 08:13 AM
cheers tiido may have a few more questions shortly ;)

matteus
05-19-2008, 08:49 AM
Tiido,
Does this mean increments of 36???

Colors&(i%)=((R%*36)*&H10000) OR ((G%*36)+&100) OR (B%*36)

what are &h10000 and &100

TmEE
05-19-2008, 09:02 AM
yes, increments are 36, &H means hex... you should learn the hex and bin stuff, its great way to nice optimizations and fitting many numbers into single variable.

matteus
05-19-2008, 09:32 AM
thanks tiido

I had to learn bin and hex for my degree but have long since forgotten it :(

I've finished off the code it generates the colour sheet....I never realised the colour selection for the genesis was so washed out it reminds me of my clothes after about 100 or so washes

tomaitheous
05-19-2008, 10:17 AM
If you're looking to draw using a 3bit palette source, here are some arrange color charts: here (http://pcedev.net//gfx_tools/color_grid_336colors.bmp) , here (http://pcedev.net//gfx_tools/HSL_map2.bmp) , here (http://pcedev.net//gfx_tools/primary_Luma_scale.bmp). They don't show all 512 colors, but are more for color/luma relation/layout.

matteus
05-19-2008, 10:28 AM
Thanks for that tom!

I'm currently looking at writing my own image development tool based on the Genesis Colour palette. So first port of call was obviously looking for a method to generate all 512 possible colours as grid to be later used as a sampler tool!

I've attached the grid i generated from the code so far....it looks wrong but maybe that's purely because of the colour ordering ?

tomaitheous
05-19-2008, 11:43 AM
Yeah, that chart looks incorrect. Doesn't look like a 3bit palette map.

Try this:

unsigned char red; //or Uint8 if you prefer
unsigned char blue;
unsigned char green;

for(int r=0;r<8;r++)
{
for(int g=0;g<8;g++)
{
for(int b=0;b<8;b++)
{
red=r*36;
blue=b*36;
green=g*36;

//then output red, green, and blue to what ever interface you're using.

}}}

matteus
05-19-2008, 11:59 AM
here's the code I'm using:

For myRed = 0 To 7
For myGreen = 0 To 7
For myBlue = 0 To 7
Dim myGraphics As Graphics
Dim myBrush As New SolidBrush(Color.FromArgb(100, 0, 0, 0))
Dim myRectangle As Rectangle

'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(hwnd:=ActiveForm().Handle)

'create a rectangle object
myRectangle = New Rectangle(x:=myX, y:=myY, Width:=20, Height:=20)

'draw the rectangle to the surface
myGraphics.DrawRectangle(pen:=New Pen(Color.Black), rect:=myRectangle)

'create solid brush object
myBrush = New SolidBrush(Color.FromArgb(100, myRed * 36, myGreen * 36, myBlue * 36))

'fill rectangle with solid brush
myGraphics.FillRectangle(brush:=myBrush, rect:=myRectangle)

myGraphics = Nothing
myBrush = Nothing
myRectangle = Nothing

If currentNumber = 31 Then
myX = 50
myY = myY + 20
currentNumber = 0
Else
myX = myX + 20
currentNumber = currentNumber + 1
End If
Next
Next
Next

matteus
05-19-2008, 12:10 PM
think I've sorted it....is this looking closer? if so it was just a matter of removing the alpha channel from Color.FromArgb

matteus
05-19-2008, 01:47 PM
after some considerable time messing around i've rewritten the whole thing in C#

private void Form1_Paint(object sender, PaintEventArgs e){

int myX = 50;

int myY = 50;

int currentNumber = 0;

for (int myRed = 0; myRed < 8; myRed++)
{
for (int myGreen = 0; myGreen < 8; myGreen++)
{
for (int myBlue = 0; myBlue < 8; myBlue++)
{
Graphics graphicsObject = e.Graphics;

Color BrushColor = Color.FromArgb(0, 0, 0);

SolidBrush myBrush = new SolidBrush(BrushColor);

Rectangle r = new Rectangle();

r.X = myX;

r.Y = myY;

r.Width = 20;

r.Height = 20;

Pen coloredPen = new Pen(Color.Black);

graphicsObject.DrawRectangle(coloredPen, r);

BrushColor = Color.FromArgb(myRed * 36, myGreen * 36, myBlue * 36);

myBrush = new SolidBrush(BrushColor);

graphicsObject.FillRectangle(myBrush, r);

if (currentNumber == 31) {
myX = 50;
myY = myY + 20;
currentNumber = 0;
} else {
myX = myX + 20;
currentNumber = currentNumber + 1;
}

}
}
}
}

TmEE
05-20-2008, 05:52 AM
check my 512 or 960(1024) color demo for what the colors look like if you really want to be sure.

matteus
05-20-2008, 06:10 AM
How'd you manage to increase it to 1024 ??? how on earth did you do that.... is that some kind of alpha effect or quick switching?

matteus
05-20-2008, 03:47 PM
making good progress I've come to a bit of a stump though....

At present I take an image and convert it to the 512 possible colours of the genesis main colour palette.

Right next how do I decide upon the 4 x 16 colour palettes?

Do I take an overall array sample of the number of colours from the 512 used in the picture, order them by RGB value and then take a sample using some random algorithm I can't even comprehend right now?

(excuse the avril examples)

tomaitheous
05-20-2008, 09:15 PM
Right next how do I decide upon the 4 x 16 colour palettes?

That's the 64 million dollar question ;)

There is no clear cut way to do it. But I can tell you this, you will need to decimate and/or merge colors in sub palettes until you get the pic to fit within the 4 sub palette structure. You'll have to come up with a priority system for the main and repeating colors through out the sub palettes. Also, it's 16,15,15,15 - not 4x16 since color 0 of all palettes is color 0 of the first sub palette. And if you plan to have sprites or another BG layer show underneath, you're limited to 15,15,15,15 sub palettes.


EDIT: If you're looking for some source/examples, here's something related: http://www.hyakushiki.net/j-idols2.zip . It's written in BASIC and setup for 16x16(15) sub palettes and dithering, but you should be able to modify/port it ;)

matteus
06-03-2008, 05:40 AM
Hey again,
Thanks for that additional piece of information at the end of your post tomaitheous I've only just noticed it!

Well working on my own I've managed to convert the image to 512 colours then reduce each 8 x 8 pixel tile to the 15 most used colours through order of occurance and then nearest match replacement.

That code does alot of what i do already but is alot more optimised lol

matteus
06-16-2008, 07:31 AM
Just wanted to come back and write a bit more about what i'm doing with this maybe someone might be able to give me a hand!

Right I'm at a point where each 8 x 8 has 15 colours from the genesis colour palette.

I've a few questions about the next stage though.

Should I optimise the image to use only the top 60 most used colours based on the number of pixels the colour is used?

Should I optimise the image to use the top 60 colours per tile reoccurance?

Or finally is it a better practise to not optimised to 60 colours and simple try and find the best 4 x 15 colour palettes based on the current colour count?

Something at the back of my mind niggles me that if i optimise to 60 then create the palettes, i may find my image has occurances where tiles don't best fit easily.

Please excuse my lack of knowledge, I've bugger all experience in this department!

dragonboy
06-16-2008, 09:00 AM
try each of them and see what works best

if all of them don't work, try taking your original picture and down grade it to a smaller RGB pallette (such as a 6-bit palette instead of 9-bit) and then take the average color in the original picture for every color in the 6-bit RGB picture, round that average to the nearest color on the 9-bit RGB pallette.

Do that if possible, and then try to make 4x15 color pallettes out of them. It should be easier then.

matteus
06-16-2008, 09:53 AM
hey dragonboy!
I was reading your other thread about compression earlier you sound like you sure know your stuff :) Yet another young brain box like tiido making me feel old and unexperienced with programming hehe thanks for your help though which has left me with another technique to try out when writing my application.

matteus
06-17-2008, 04:16 AM
Where did the lovely sarcastic comment about word documents and roms go.....

dragonboy
06-17-2008, 11:55 PM
Where did the lovely sarcastic comment about word documents and roms go.....

I clicked on one of your sig links and it brought me to a website about some new homebrew rpg game and I was like "oh my God, you made this game all by yourself?"

matteus
06-18-2008, 03:57 AM
ahh the game you speak of is pier-solar and nope its not something by me but there are a few people in this forum who are involved with it: 108 Stars, Fonz, TmEE to name just a few.

I'm just very passionate about the Megadrive and Mega-CD I was brought up on them both and so do my best to help promote Pier-Solar. I got retro-gamer (UK magazine) to contact them with regards to an interview, I run the unofficial site, the facebook group, etc, etc

TmEE
06-18-2008, 07:16 AM
You forgot Zebbe !!!

matteus
06-18-2008, 07:30 AM
Beg my pardon ;) yes Zebbe too...As for the jib in the ribs about word documents and roms....

I may know little but I'm not that much of a dope :P

dragonboy
06-18-2008, 02:55 PM
Beg my pardon ;) yes Zebbe too...As for the jib in the ribs about word documents and roms....

I may know little but I'm not that much of a dope :P

I feel sorry for you.:( I deleted my "sarcastic" post because it didn't sound like what I intended to say. I don't want you to feel bad.

Zebbe
06-18-2008, 03:08 PM
You forgot Zebbe !!!

And TulioAdriano, the creator of the project !!!

108 Stars
06-18-2008, 03:44 PM
dragonboy, you have been on Sega-16 all this time now, talked about tech-stuff (I think I remember a thread where you and/or tomaitheous critizized TmEEīs sound-know-how) and you have never heard of our project???:o

Man, I canīt believe it....feature on Sega-16, 2 pages in Retro Gamer magazine, a website, lots of forums and newssites talking about it....was all our effort to make this public in vain?:(

Rusty Venture
06-18-2008, 03:51 PM
108 Stars, that car humping gif is too much.

108 Stars
06-18-2008, 03:57 PM
What do you mean? That GIF has made me so much more popular!

And it is not just a car, it is the KNIGHT-2000, the most technologically advanced vehicle of the 80īs....well, second to the DeLorean.
And it still beats that ugly new Knight Rider I saw on photos....no wonder David loves it!

Rusty Venture
06-18-2008, 04:00 PM
I'm sure it has elevated your status in the ranks of the German "Hoff Party", but it is still too much for those not affiliated with them.

108 Stars
06-18-2008, 04:02 PM
Does that mean you give me some positive rep?:D
Actually, it was you who gave me the idea to look for GIFs of him for my sig.

Still better than PedoBear, right?

Rusty Venture
06-18-2008, 04:16 PM
Drop the car humping and I might consider giving you positive rep.

108 Stars
06-18-2008, 04:19 PM
Man, you look cute all of a sudden....but.....no!

I wonīt drop it if Melf doesnīt tell me it is too erotic for his forum!!!!

Zebbe
06-18-2008, 05:00 PM
I don't know if a Pier Solar logo fits between those two GIFs...

playgen
06-18-2008, 05:04 PM
I'm only seeing one Hoff Gif :confused:

Zebbe
06-18-2008, 05:28 PM
To the left is where he humps Kitt, to the right is a constant zooming to his crotch.

playgen
06-18-2008, 05:30 PM
I'm just seeing zooming pants here

matteus
06-18-2008, 05:41 PM
The car humping gif was classic......I'm not sure pier-solar is worthy of sitting between the holf ;)

tomaitheous
06-18-2008, 07:24 PM
Mean ol' Hoff sandwich on that pier-solar gif. Also, I'm not sure why anyone would take exception to the car humping gif, when the other hoff-gif lookes like he's got a totally exposed "full-on" in some of the frames. Or am I the only one that sees that?

Rusty Venture
06-18-2008, 10:57 PM
Man, you look cute all of a sudden....but.....no!

If I looked like my avatar I wouldn't be here discussing Hoff gifs!



Mean ol' Hoff sandwich on that pier-solar gif. Also, I'm not sure why anyone would take exception to the car humping gif, when the other hoff-gif lookes like he's got a totally exposed "full-on" in some of the frames. Or am I the only one that sees that?

I compromised on that one. The only thing Germans like more than Hoff as their ruler is half naked pics of Hoff. Plus, the man did single handedly destroy communism with his music.

108 Stars
06-19-2008, 02:36 AM
I'm only seeing one Hoff Gif :confused:

Oh my, maybe you can refresh or something....you would not wanna miss that Hoff-GIF!
I did not do it myself though, I just resized it for the sig.:)

Dirt Ball Gamer
06-19-2008, 04:58 AM
Hoff playin the berlin wall was tight

kevinski
09-01-2008, 10:55 PM
Tiido,
Does this mean increments of 36???

Colors&(i%)=((R%*36)*&H10000) OR ((G%*36)+&100) OR (B%*36)

what are &h10000 and &100

I'm curious...assuming that the values can range from 0 to 255 for any given color, then how does it make sense for the colors to be in increments of 36? Wouldn't it be 32? Could anyone explain this? I'm interested in mapping some graphics to the Genesis color palette, but I need to know how to get the appropriate colors.

Incrementing it by 36 would mean that the maximum value would be 288, right?

tomaitheous
09-02-2008, 03:21 AM
No, increment of 36 starts with 0. Zero to seven is the 8 elements. So it's R*36, G*36, B*36. If you use 32, you get somewhat dull colors, i.e. pure white won't be pure white. This is for the RGB side of the VDP. The NTSC and PAL encoder chips will convert the RGB to a different format and some of the colors will be slightly more or less different (it also depends on the gamma mapping of the composite encoder).

You could added a linear (or nonlinear) adjustment so that the highest colors get more of a boost - with RGB max equaling 255/255/255. This would give brighter colors in the upper range without effecting the bottom range. But this isn't really as big improvement as over going from using increments of 32 to increments of 36.

kevinski
09-03-2008, 06:32 PM
Ah, so it's 0, 36, 72, 108, 144, 180, 216, 252? I don't understand how this could ever result in white, though, as wouldn't that mean that "white" would be 252, 252, 252? It really wouldn't be white, assuming that this is still on a scale from 0 to 255. I'm not disputing anything that's being said, for the record. I'm actually just wanting to get this right whenever I make my palette.

tomaitheous
09-03-2008, 07:18 PM
252,252,252 is less than 1.2% of pure white. You're telling me that difference is too much!? If so, like I posted previous - add a linear gamma correction. It would have to be floating point, but just grab the integer part after the correction. Or just make an easy readable table by hand.

matteus
09-03-2008, 07:19 PM
I can't believe this thread is back from the dead........

kevinski
09-03-2008, 09:18 PM
I never said that the difference was too much. I was just wanting to make sure that this was the case. And yeah, I Googled something regarding the Genesis color palette, and this topic popped up in the results. :P