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 ?
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 ?
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).
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.
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.