views:

1927

answers:

3
+2  Q: 

BGR Color Space

I understand RGB --- value (0-255)Red,(0-255)Green,(0-255)Blue to form a color.

What is exactly BGR color space ? How is it different from RGB color space ?

+2  A: 

It's just RGB in a different order. Converting between them is simple - the BGR seems to be a 24-bit representation (may be stored in a 32-bit variable) where the top 8 bits are blue, next 8 are green and least significant 8 are red.

RGB values tend to be written as RGB(r,g,b) where the r/g/b values are between 0 and 255 inclusive or as #rrggbb, where rr/gg/bb are 8-bit hex values. All the BGR values I've seen tend to be simple integers between 0 and 16777215 (0xffffff).

paxdiablo
+2  A: 

RGB stands for Red Green Blue. Most often, an RGB color is stored in a structure or unsigned integer with Blue occupying the least significant "area" (a byte in 32-bit and 24-bit formats), Green the second least, and Red the third least.

BGR is the same, except the order of areas is reversed. Red occupies the least significant area, Green the second (still), and Blue the third.

On some platforms (e.g. the Gamegear) a BGR model is used. However, for most, like your computer, RGB is used [citation-needed] (though BGR is supported by many graphic API's for compatability). I'm not sure why exactly it's used; probably historical.

Example: #FF0000 is pure red when read as an RGB hex color (#rrggbb), because the third area (numbers are read right to left!) is FF (maximum value, full color) and the other two areas are 00 (minimum value, no color). If #FF0000 were read as a BGR hex color, it'd be pure blue.

strager
"like your computer" is probably not correct - Windows uses BGR.
Mark Ransom
+1  A: 

Its about endianness.

RGB is a byte-order. But a deliberate implementation choice of most vanilla Graphics libraries is that they treat colours as unsigned 32-bit integers internally, with the three (or four, as alpha is typically included) components packed into the integer.

On a little-endian machine (such as x86) the integer 0x01020304 will actually be stored in memory as 0x04030201. And thus 0x00BBGGRR will be stored as 0xRRGGBB00!

So the term BGR (and BGRA etc) is a leaky abstraction where the graphics library is explaining how the integer is logically ordered, so as to make your code that is directly accessing the colour components individually more readable.

Will
But in Windows, the necessary byte order is 0xBB, 0xGG, 0xRR - how do you explain that?
Mark Ransom
I don't believe it has anything to do with endianness. The Gamegear uses BGR color, as well as the Wonderswan Color, but the Gameboy Color and Advance use RGB color. All are little-endian systems (Z80, 80286-based, Z80-based, and ARM, respectively).
strager
http://dev.chromium.org/developers/design-documents/graphics-and-skia search for "The epic battle of RGBA and BGRA"
Will