im in a bit of a pickle :S this is probably a lot easier than i imagine. i am a undergrad working on robotics and the robot im working on takes pictures in RGB565 which is 16 bit. but i dont know how that works :/

i understrand 24 bit where red green and blue have a byte each but you cant divide 16 into 3 equal part... so i read more and found that the color is in format RRRRRGGGGGGBBBBB (which is 16 bits) but its odd that green has a bigger range than the other two.

can someone tell me how to read color from this?

any help would be great. thanks in advanced :D

6 Years
Discussion Span
Last Post by Momerath

so for example if i wanted the reddest thing would i do:

if (R > G && R > B){LED = 1;}else{LED = 0;}

Just a little more background information on why the number of green bits is larger than the other two:
(Excerpt from Programming Windows, Fifth Edition by Charles Petzold (c) 1998, Chapter 14, "Bitmap Dimensions")
In recent years, full-color video adapter boards have become quite common. These use either 16 bits or 24 bits per pixel. Sometimes with 16 bits per pixel, one bit is unused and the other 15 bits are apportioned equally for the red, green, and blue primaries. This allows a total of 32,768 colors with combinations of 32 shades each of red, green, and blue. More commonly, 6 bits are used for green (the color that humans are most sensitive to) and 65,536 colors are available. For the nontechnical PC user who doesn't want to see wacky numbers like 32,768 or 65,536, such video display boards are usually said to be "high color" adapters that provide "thousands of colors."
(bold and color are my addition)
If you want an excellent and exhaustive presentation of Device-Independent bitmaps and Device-Dependent bitmaps (and how to program for them under Windows) I recommend you borrow or buy a copy of that book and pay special attention to Chapter 15. All the examples are in C language, but the techniques are translatable to other languages without too much trouble.

Edited by BitBlt: n/a


@Momerath what value is actually stored in R,G and B (how do i compare values?) it compiles fine if i make them int or char.

this is my code:

int R,B,G;
		for(i=0; i<100; i++)
			B = (buffer[50] + buffer[50+1]) & 0x1f;
			G = ((buffer[50] + buffer[50+1]) >> 5) & 0x3f;
			R = ((buffer[50] + buffer[50+1]) >> 11) & 0x1f ;
			if (R > 100){lighton();}else{lightoff();}

any help would be helpful :)


R is the amount of Red in the color. It ranges from 0 to 31.
G is the amount of Green in the color. It ranges from 0 to 63.
B is the amount of Blue in the color. It ranges from 0 to 31.

(0,0,0) is black, (31, 63, 31) is white.


so for example if i wanted the reddest thing would i do:


Edited by peter_budo: Keep It Spam-Free - Do not mention, plug or refer to any product, service, or website you are affiliated with


so for example if i wanted the reddest thing would i do:

You'd need to define what you mean by 'reddest'. For example, let's say we have to RGB colors with the values (31,1,0) and (30,0,0). Which is 'redder'? The first has a higher red value, but has a tiny amount of green. The second doesn't have the full red value, but has no other colors in it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.