Jump to content
IGNORED

RGB2CRY


SCPCD

Recommended Posts

To convert RGB to CRY is a simple process but needs a bit of brute force.
In the Tech Ref manual is a table for the CRY palette split into the (YUV_)R , (YUV_)G and (YUV_)B values. So if we go Cry(index:8 , intensity:8 )  to RGB then

R = (YUV_R[index] * intensity) / 256
G = (YUV_G[index] * intensity) / 256
B = (YUV_B[index] * intensity) / 256


So to go RGB to CRY  we need to find the colour with the least error

So go through all intensities 0 to 255 and use a bit of Pythagoras

 

deltaR = rgbR - R(index,intensity)

lengthR = SQRT(deltaR * deltaR)

 

deltaG = rgbG - G(index,intensity)

lengthG = SQRT(deltaG * deltaG)
 

deltaB = rgbB - B(index,intensity)

lengthB = SQRT(deltaB * deltaB)
 

length = lengthR * LengthG * LengthB;

 

At the smallest length then the cry value is index:intensity

 

 



 

Link to comment
Share on other sites

In the Tech Ref manual there is also an explanation that CRY is designed in such a way that no brute force is really needed and it can be converted in constant time.

The intensity is just I = max(R,G,B), then R2 = R * 255 / I, G2 = G * 255 / I, B2 = B * 255 / I.

Now we just need 3 2D 256x256 tables with color component of CRY: [R2,G2], [R2,B2], [G2,B2] and we are using one table that is indexed by other two components than the max one.

Edited by laoo
Link to comment
Share on other sites

4 hours ago, Seedy1812 said:

To convert RGB to CRY is a simple process but needs a bit of brute force.

 

(...)

 

At the smallest length then the cry value is index:intensity

3 hours ago, laoo said:

In the Tech Ref manual there is also an explanation that CRY is designed in such a way that no brute force is really needed and it can be converted in constant time.

The intensity is just I = max(R,G,B), then R2 = R * 255 / I, G2 = G * 255 / I, B2 = B * 255 / I.

Now we just need 3 2D 256x256 tables with color component of CRY: [R2,G2], [R2,B2], [G2,B2] and we are using one table that is indexed by other two components than the max one.

Yes, that's what I do in my converter.

 

The thing is, in theory, you shouldn't have to use brute force to create the lookup tables ; you should be able to compute the CRY value directly using a mathematical formula. But in practice, it doesn't work quite right.

Edited by Zerosquare
Link to comment
Share on other sites

1 hour ago, Zerosquare said:

Yes, that's what I do in my converter.

 

The thing is, in theory, you shouldn't have to use brute force to create the lookup tables ; you should be able to compute the CRY value directly using a mathematical formula. But in practice, it doesn't work quite right.

 From the 16 million RGB colours you have to map this down to 65536 CRY colours . As the intensity decreases the perceived number of colours reduce. ( The darker the colour the more they look the same ). For most colours there is no RGB to CRY match so you have to find the nearest one.

You are only finding the the output CRY value . The Cry lookup tables are constant so there is they do not have to be calculated.

Edited by Seedy1812
Link to comment
Share on other sites

  • 8 months later...

 As a side-effect of my tooling efforts I've created an image that shows where are CRY colors with intensity 255 on three RGB planes. Left-bottom are all colors with R=255, left-upper have blue=255 and right-top have green=255. Black points are in place of colors representable using CRY.

I decided to share it because it's interesting to know which areas are more densly populated by CRY colors and which on the contrary and besides it looks cool :)

 

RGBCRY.png

  • Like 4
Link to comment
Share on other sites

Strangely can't edit my post and just wanted to add another diagram with Voronoi cells for each CRY color. These are actually three separate images combined in one, so there are separate cells on the edges of squares.

voronoi.png

Edited by laoo
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...