Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

TL;DR because it used to be popular among camera engineers and other people who manipulated image data early on.


This begs the question: why was BGR popular among camera engineers while RGB seems to be common in software?


The article says "The reason the early developers at OpenCV chose BGR color format is that back then BGR color format was popular among camera manufacturers and software providers. E.g. in Windows, when specifying color value using COLORREF they use the BGR format 0x00bbggrr.". So it claims that both camera engineers and software used BGR. I'm not convinced though - the Win32 macro to create a COLORREF is RGB(r,g,b), and there are 3 macros to get the R, G and B components out of a COLORREF. Until today I've never realized that a COLORREF stores its components in BGR order, and I've done Win32 graphics programming for 20 years. I think it has more to do with that the 'original' graphics-oriented architectures (SGI workstations and such) were big endian (for no particular reason, probably, although people have come up with retrofact rationalizations probably), and everyone just used that. Some 'standards' don't need a reason, someone just needs to make a choice and everyone else should just stick with it...


Also, I'm pretty sure that COLORREF is xBGR format because colour data in memory is RGBx format and when you read it DWORD at a time on a little-endian machine, you end up with xBGR in registers. So an array of COLORREFs in memory is RGBx format...

On the other hand, BMP is BGR format on disk and in memory[1] when using 24-bit colour. I think "opencv used BGR because BGR was the format of the default image file type on the first platform it was written for" might explain it better. Camera makers probably did the same thing - output BMPs before JPEG was developed.

[1] Yes, technically BMP also has bitmasks that let you store the colour channels in any order with any precision, but almost all BMPs I've come across just use the default BGR format.


Big endian vs little endian hardware?


That’s my understanding - a lot of the low power devices were big endian as for whatever reason big endian and risc seemed heavily correlated for decades, similarly the early mainframes and whatnot were big endian which is why a lot of network protocols use big endian formats.


Probably the popularity of the Motorola chips?


Seems plausible - I just couldn’t recall who was dominating embedded chips at the time


I've noticed that decisions like this are sometimes made for the sake of being the opposite of something else and then the two coexist decades within neighboring realms to the frustration and bafflement of users.


"decisions like this are sometimes made for the sake of being the opposite of something else and then the two coexist decades within neighboring realms to the frustration and bafflement of users"

Oh, you mean a political two-party system?


He should've made a 10 minute youtube video with animations of horse's ass, etc just to reveal this in the last 15 seconds... "if you liked this video, please like, subscribe, share and hit that bell icon to bla bla bla!".

All that writing for a one line explanation...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: