RGB interpreted as BGR

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
shikhin
Member
Member
Posts: 274
Joined: Sat Oct 09, 2010 3:35 am
Libera.chat IRC: shikhin
Contact:

RGB interpreted as BGR

Post by shikhin »

Hi,

Lately, I've been working on my 24-bpp blitting code. Before setting a mode, I do certain checks on it to find whether it's usable or not. One of this includes checking whether the pixel format for the mode is acceptable or not. As of now, "acceptable" includes only 8:8:8 RGB for 24-bpp.

To verify this, I use the *MaskSize and *FieldPosition fields provided by VBE Function 01h.

Now comes the strange part.

On Bochs, QEMU (without "-std xyz"), QEMU (with "-std vga") and virtualbox, the reported 24-bpp modes are in the 8:8:8 RGB format, as desired.

On QEMU (without "-std xyz"), the colors come up exactly as expected. On every other emulator, the colors are a little messed up, as would happen if a 8:8:8 RGB input image is interpreted as 8:8:8 BGR. I've attached two screenshots, which describe the scenario.

(oh, and I'm pretty sure my input image is RGB)

Screenshot 1
QEMU (without "-std xyz")


Image

Screenshot 2
Every other emulator


Image

Unfortunately, both of my test beds don't support 24-bpp modes, so I've been unable to record the output on real machines. I'm pretty sure I'm doing something wrong - so guidance would be wanted.

Regards,
Shikhin
Last edited by shikhin on Tue Dec 27, 2011 11:27 am, edited 1 time in total.
http://shikhin.in/

Current status: Gandr.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: RGB interpreted as BGR

Post by Karlosoft »

There is no evidence that a video card should use the RGB order of bytes. The fields and their position are defined in the struct of the video mode taken from vbe ;)
shikhin
Member
Member
Posts: 274
Joined: Sat Oct 09, 2010 3:35 am
Libera.chat IRC: shikhin
Contact:

Re: RGB interpreted as BGR

Post by shikhin »

Hi,
Karlosoft wrote:There is no evidence that a video card should use the RGB order of bytes. The fields and their position are defined in the struct of the video mode taken from vbe ;)
Shikhin wrote:As of now, "acceptable" includes only 8:8:8 RGB for 24-bpp.
Shikhin wrote:To verify this, I use the *MaskSize and *FieldPosition fields provided by VBE Function 01h.
Shikhin wrote:On Bochs, QEMU (without "-std xyz"), QEMU (with "-std vga") and virtualbox, the reported 24-bpp modes are in the 8:8:8 RGB format, as desired.
Hmm.

EDIT: Doh. Had typed in Function 02h in both the posts, instead of Function 01h.

Regards,
Shikhin
http://shikhin.in/

Current status: Gandr.
shikhin
Member
Member
Posts: 274
Joined: Sat Oct 09, 2010 3:35 am
Libera.chat IRC: shikhin
Contact:

Re: RGB interpreted as BGR

Post by shikhin »

Hi,
berkus wrote:Can you provide the values for the field positions and masks please?
Well, before that, I discovered something which truly deserves http://tinyurl.com/cmqjumd. Since the code worked on QEMU without any command line options, I never bothered verifying the mode I set there. Moreover, when I changed the input stream to BGR, the colors over there got reversed. So, I thought that everything was right on it

Recently, I discovered that I was setting a 16-bpp mode on it, which is why the colors were right over there. #-o

However, that still doesn't resolve my issue.
RedFieldPosition = 16, RedMaskSize = 8;
GreenFieldPosition = 8, GreenMaskSize = 8;
BlueFieldPosition = 0, BlueMaskSize = 8;
My input image is generated from a BMP. As far as I know, BMP is in BGR format. I convert this into RGB by inter-changing the Blue and Red bytes. The same input data is used by the 8-bpp, 15-bpp and 16-bpp code, which convert the pixel into the required format. The colors in these modes are absolutely fine, which makes me believe that the input data is in RGB.

However, I might be mis-interpreting the colors everywhere. :)

Regards,
Shikhin
http://shikhin.in/

Current status: Gandr.
shikhin
Member
Member
Posts: 274
Joined: Sat Oct 09, 2010 3:35 am
Libera.chat IRC: shikhin
Contact:

Re: RGB interpreted as BGR

Post by shikhin »

Hi,
berkus wrote:Which makes me believe there must be a bug in your code, debug.

(EDIT: it seems obvious to me that a good test images will be the all-Red, all-Green and all-Blue bitmaps)
Yeah. Before the latest finding on QEMU without any command line flag, I wasn't so sure where the bug existed. Should be easier to find now. Thanks (for all the fish)!

Regards,
Shikhin
http://shikhin.in/

Current status: Gandr.
Post Reply