Sign in to follow this  
praveen_cheruku

RGB666 to RGB332 data conversion

Recommended Posts

hi everyone, I am trying to interface kyocera's 800*480 color LCD to 8-bit controller. LCD is having 18 bit data interface(6-Red,6-Green,6-Blue (RGB666)). Now i need to take 8 bits out of it. I found that RGB332 color standard is used generally. Which bits(MSB or LSB) i need to select from Red, Green, Blue? i.e How can i convert from RGB666 to RGB332? Please let me know if you have any literature about this. thanks in advance praveen

Share this post


Link to post
Share on other sites
you could use logic and shift operators to extract the data from the RGB666 value and place it in a RGB332:

extract
-------------------------------------

B = value & 63
G = (value >> 6) & 63
R = (value >> 12) & 63

then get the most significant bits(3, 3, 2):

R = (R >> 3) & 7
G = (G >> 3) & 7
B = (B >> 4) & 15

the final RGB332 value will then be:

( R << 5 | G << 2 | B )

I don't know what data types you use to store these values, but as long as the 18 bits are the least significant bits of whatever data type and the bit ordering is big endian then this should work.

[Edited by - staticVoid2 on March 6, 2008 1:59:43 AM]

Share this post


Link to post
Share on other sites
thanks a lot for replies..

i have done the following thing to ensure uniform distribution of colors..

i have taken MSB's from each color of R,G,B. Also tied LSB's with MSB's as shown below:

for blue: B5 tied with B3,B1
B4 tied with B2,B0


for green: G5 tied with G2
G4 tied with G1
G3 tied with G0


for red: R5 tied with R2
R4 tied with R1
R3 tied with R0

Please suggest me if there are any changes required..

Share this post


Link to post
Share on other sites
MSBs should be used

asuming that the color is stored with red, being at the left of the number..

the input color value will be something like...

given color (r5 r4 r3 r2 r1 r0 g5 g4 g3 g2 g1 g0 b5 b4 b3 b2 b1 b0)
RED MASK 1..1..1..1..1..1..0..0..0..0..0..0..0..0..0..0..0..0 = 0x3f000
Green mask 0..0..0..0..0..0..1..1..1..1..1..1..0..0..0..0..0..0 = 0xfc0
Blue mash 0..0..0..0..0..0..0..0..0..0..0..0..1..1..1..1..1..1 = 0x3f

so, the individual channel values will be..

inputRed = (inputColor & 0x3f000) >> 12
inputGreen = (inputColor & 0xfc0) >> 6
inputBlue = (inputColor & 0x3f)

// these are not values alone
// the values are shifted to fit the output
outputRedBits = (inputRed & 0x30) << 2
outputGreenBits = (inputGreen & 0x30) >> 1
outputBlueBits = (inputBlue & 0x30) >> 4

outputColor = outputRedBits | outputGreenBits | outputBlueBits


In case, if Red is being stored at the right side, u need to interchange red with blue and blue with red, as staticvoid2 suggested.

[Edited by - Saughmraat on March 6, 2008 12:37:39 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by praveen_cheruku
thanks a lot for replies..

i have done the following thing to ensure uniform distribution of colors..

i have taken MSB's from each color of R,G,B. Also tied LSB's with MSB's as shown below:

for blue: B5 tied with B3,B1
B4 tied with B2,B0


....
Please suggest me if there are any changes required..


1) What do u mean by tieing?

2) if u want to ensure uniform distribution, u should set something like..

outputB1 = inputB5, outputB0 = inputB4;

Share this post


Link to post
Share on other sites
I am doing this at hardware level(physical wires) and not at software level..

I have an LCD module with 18 bit interface(6 Red bits,6 Blue & 6 Green) and the 18 bit bit data has to come from a Video RAM. To minimize memory requirements, Video RAM size is choosen with 8-bit data width. Since Video RAM can output only 8 bits at once, 18 bit interface of LCD has to be converted to 8-bit interface(physically).

I hope my query is clear..

praveen

Share this post


Link to post
Share on other sites
simply tying to the higher bits is not necessarily correct. It is more correct to repeat the smaller bit-pattern across the full range of the larger.

I believe I understand correctly that you want to drive an 18bit RGB666 display using an 8bit port from a micro-controller using RGB332 format.

If that is the case, the best color results will be given by reapeating the R & G patterns twice, and the B pattern three times. Doing this will give you a fuller color range representation from 0% to 100% intensity. With the simple method of only mapping to the highest bits, you will only get a color representation in the range of 0% to 90% in the R & G values, and only 0% to 76% in the B value -- all because the lower bits will always be 0.

repeating the pattern gives the full range and also gives better distribution among intermediate shades.

Share this post


Link to post
Share on other sites
Dear ravyne2001,

Thanks a lot for your reply..

Infact i have done the same thing whatever you are saying..

18 bit interface of LCD is :

R5 R4 R3 R2 R1 R0 G5 G4 G3 G2 G1 G0 B5 B4 B3 B2 B1 B0 (18 bit)

I have shorted(physically) R5,R4,R3 with R2,R1,R0 respectively. Similar thing is done for green bits. So the pattern is repeated twice for R,G bits.

However, for blue bits, B5,B4 are shorted with B3,B2 respectively
B5,B4 are also shorted with B1,B0 respectively

So the pattern is repeated thrice for blue bits.

Please suggest me if there are any changes are required.


praveen

Share this post


Link to post
Share on other sites
Yes, that is exactly what I was suggesting. There may be some additional electrical considerations to make sure you're supplying enough volts/watts to drive the additional lines but you've connected the lines correctly. Then again, LCDs are digital so you aren't running through a D/A converter or R2R ladder, so its probably not an issue. I don't know, I'm not an electronics guru [grin]

In the pixel core of my software renderer thats exactly the same formula I use to convert from lesser bit-depths to higher ones. When I go from higher bit-depths to lower ones I simply use the appropriate number of high bits.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this