> why is BGR() instead RGB()?
And in an alternate reality, someone's asking
why is RGB() instead BGR()?
Plus there's the whole "do you read left to right or right to left" when looking at bytes in a word.
Which depends on whether you're looking at big-endian or little-endian data.
My guess that you mean that the rgb values are stored as bgr in the output buffer. The reason for this is most likely that the buffer is an array of COLORREF which is a DWORD. See:
Can you respond to Peter's request? I do not see "BGR()" in your code.
But anyway, as the others mentioned, it seems like Windows DIB bitmaps are BGR (0x00BBGGRR), and you can't change this.
microsoft has _byteswap*** family of functions. If I am not mistaken, this lets you, even in 64 bit, tap the CPUs bswap command, to byte-order flip a register.
the int from rgb macro can be flipped and if needed, shifted then assigned.
If you need to do that a lot, make a BGR() function to mirror the RGB() macro.
If you do not need to call RGB at all, doing it directly is faster than doing it and then flipping it, even with the register command.
OR, you could do it directly:
unsigned char * realpixels = (unsigned char *)Pixels;
realpixels[PosY*Width*3+PosX] = 255;
realpixels[PosY*Width*3+PosX+1] = 0;
realpixels[PosY*Width*3+PosX+2] = 0;
and you need that 4th byte, which is either position 0 or position 3.
If its position 0, fix the above with a +1 for the RGB info and do whatever to the [0] byte.
if its position 3, leave above alone and do whatever to [..+3] byte.
be sure to test it... use it to set all the pixels to red, then green, then blue and if all 3 colors work, you are loading the right bytes.