It is currently Wed Oct 18, 2017 5:20 pm

All times are UTC - 7 hours



Forum rules


Related:



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Color palette generator
PostPosted: Sun Jul 03, 2016 10:52 am 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2285
Today I have an idea for a new project. Create an SNES ROM that generates a color palette using math. Since the SNES has 256 palette entries, I'll try using a palette that uses 5 lumas, 24 hues, and 2 saturations, plus 7 shades of grey. This gives me 5*24*2+7=247 colors. Hue and Saturation would be adjusted using the D-pad.

The way the colors are going to be generated are the following:

-First it will calculate the magnitude of 2 color axis using the hue and saturation information. We'll call them A and B.
-Then it will calculate the R-Y, G-Y and B-Y with the following formula:
R-Y = -2(A+B)
G-Y = A
B-Y = 5B
-Then it will add the color differences to 5 8-bit luma values. The luma values have a gamma curve of y=x^2.
-Then it will detect clipping, and adjust saturation accordingly.
-Then it will reduce the bit depth to 5 bits per color channel, with a gamma curve of y=sqrt(x).


Top
 Profile  
 
PostPosted: Sun Jul 03, 2016 11:45 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7230
Location: Chexbres, VD, Switzerland
Sounds pretty cool. This'd be mostly useful for graphical modes that does indeed allow to use the 256 colours, I believe it's mode 3, 4 and 7 (correct me if I'm wrong).


Top
 Profile  
 
PostPosted: Wed Jul 06, 2016 2:09 pm 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2285
Anyone know how to clip the saturation of a color? It appears a lot harder than I thought.


Top
 Profile  
 
PostPosted: Wed Jul 06, 2016 11:43 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7230
Location: Chexbres, VD, Switzerland
What do you mean exactly by "clip the saturation of a colour" ?


Top
 Profile  
 
PostPosted: Thu Jul 07, 2016 5:31 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19097
Location: NE Indiana, USA (NTSC)
I assume it refers to situations where applying the transformation from YUV or YIQ to RGB would produce component intensity less than 0 or greater than full scale.

As for greater than full scale: Try not making white ($20/$30) full scale. Make it #F0F0F0 or something to give headroom for colors that exceed that value.

As for less than zero: Many TVs during the NES era weren't perfectly adjusted. The misleading names of "brightness" and "contrast" knobs (really black level and signal amplification) didn't help matters. Try making black #0F0F0F and seeing if that helps.


Top
 Profile  
 
PostPosted: Thu Jul 07, 2016 7:51 am 
Offline

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
tepples wrote:
The misleading names of "brightness" and "contrast" knobs (really black level and signal amplification) didn't help matters.

Oooooh so that is how they worked. Nice to know. So wait, this means the best setting would be 0% brightness and 100% contrast? o.o (actually probably not 0% brightness since CRT response is not linear)


Top
 Profile  
 
PostPosted: Thu Jul 07, 2016 8:31 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19097
Location: NE Indiana, USA (NTSC)
On a CRT, you should set "contrast" the way you'd set "backlight brightness" on an LCD, so that neither the TV nor room lighting overpowers the other.

The "brightness" knob exists for two reasons. One is that the NTSC signal doesn't contain a reliable reference for black level. Set it too low, and the black level adjustment will end up producing negative luma levels, crushing shadows. The other is that TV screens aren't completely black; they reflect some room light even when luma is 0. Leaving black level at minimum may cause room light to overpower shadows in that case as well. On displays whose black level is set too low, some parts of Haunted: Halloween '85 will be nearly invisible because the artist insisted on using a lot of $06, $07, and $08.


Top
 Profile  
 
PostPosted: Fri Jul 08, 2016 5:05 pm 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2285
I was looking up different colorspaces and found it looks like Hunter-Lab decreases saturation towards black. It's something similar to this:

Y = L^2
X = a*L + Y
Z = b*L + Y

The weird thing about Lab color space is that blue is placed in a weird spot. In my opinion it's too far from cyan, and too close to red.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group