Updated BGR vs. RGB vga patch...
Hello,
attached is an updated version (against today's CVS) of a patch to enable B/G/R color encoding rather than R/G/B with the command-line option -bgr. I found the original here (post by Martin Bochnig):
http://lists.nongnu.org/archive/html/qemu-devel/2005-09/msg00059.html
It's main intention is to deal with some 24-bit Sun/SPARC X servers, including SunRays. But you can also mimic this behavior with a VNC server if you want.
Anyway, it may not be too interesting to most, but it is to me at the moment, so I figured I'd share. To use it, you can pass in the -bgr command line option to qemu. You can get some psychadelic colors if you're really bored and want to try it on an R/G/B 24-bit X server, like XFree86 or X.org :)
Regards,
Leo Reiter
Signature · 8 lines
Leonardo E. Reiter Vice President of Product Development, CTO Win4Lin, Inc. Virtual Computing from Desktop to Data Center Main: +1 512 339 7979 Fax: +1 512 532 6501 http://www.win4lin.com
Index: vl.c
===================================================================
RCS file: /cvsroot/qemu/qemu/vl.c,v
retrieving revision 1.168
vl.c +7 -0
@@ -128,6 +128,7 @@int vm_running;int rtc_utc =1 ;int cirrus_vga_enabled =1 ; +int bgr_display_enabled =0 ;#ifdef TARGET_SPARC int graphic_width =1024 ;int graphic_height =768 ;
@@ -4131,6 +4132,7 @@"-m megs set virtual RAM size to megs MB [default=%d]\n" "-smp n set the number of CPUs to 'n' [default=1]\n" "-nographic disable graphical output and redirect serial I/Os to console\n" +"-bgr invert colors for HOSTS using certain SPARC frame buffers\n" #ifndef _WIN32"-k language use keyboard layout (for example \"fr\" for French)\n" #endif
@@ -4283,6 +4285,7 @@ QEMU_OPTION_cirrusvga, QEMU_OPTION_g, QEMU_OPTION_std_vga, + QEMU_OPTION_bgr, QEMU_OPTION_monitor, QEMU_OPTION_serial, QEMU_OPTION_parallel,
@@ -4360,6 +4363,7 @@ { "full-screen", 0, QEMU_OPTION_full_screen }, { "pidfile", HAS_ARG, QEMU_OPTION_pidfile }, { "win2k-hack", 0, QEMU_OPTION_win2k_hack }, + { "bgr", 0, QEMU_OPTION_bgr }, { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice }, { "smp", HAS_ARG, QEMU_OPTION_smp },
@@ -4850,6 +4854,9 @@case QEMU_OPTION_std_vga: cirrus_vga_enabled =0 ;break ; +case QEMU_OPTION_bgr: + bgr_display_enabled =1 ; +break ;case QEMU_OPTION_g: {const char *p;
Index: vl.h
===================================================================
RCS file: /cvsroot/qemu/qemu/vl.h,v
retrieving revision 1.107
vl.h +1 -0
@@ -130,6 +130,7 @@extern int bios_size;extern int rtc_utc;extern int cirrus_vga_enabled; +extern int bgr_display_enabled;extern int graphic_width;extern int graphic_height;extern int graphic_depth;
Index: hw/vga.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/vga.c,v
retrieving revision 1.42
vga.c +20 -0
@@ -790,23 +790,43 @@static inline unsigned int rgb_to_pixel8 (unsigned int r,unsigned int g,unsigned b) { +if (bgr_display_enabled) { +return ((b >>5 ) <<5 ) | ((g >>5 ) <<2 ) | (r >>6 ); +} +else {return ((r >>5 ) <<5 ) | ((g >>5 ) <<2 ) | (b >>6 ); } +}static inline unsigned int rgb_to_pixel15 (unsigned int r,unsigned int g,unsigned b) { +if (bgr_display_enabled) { +return ((b >>3 ) <<10 ) | ((g >>3 ) <<5 ) | (r >>3 ); +} +else {return ((r >>3 ) <<10 ) | ((g >>3 ) <<5 ) | (b >>3 ); } +}static inline unsigned int rgb_to_pixel16 (unsigned int r,unsigned int g,unsigned b) { +if (bgr_display_enabled) { +return ((b >>3 ) <<11 ) | ((g >>2 ) <<5 ) | (r >>3 ); +} +else {return ((r >>3 ) <<11 ) | ((g >>2 ) <<5 ) | (b >>3 ); } +}static inline unsigned int rgb_to_pixel32 (unsigned int r,unsigned int g,unsigned b) { +if (bgr_display_enabled) { +return (b <<16 ) | (g <<8 ) | r; +} +else {return (r <<16 ) | (g <<8 ) | b; } +}#define DEPTH 8#include "vga_template.h"
Quoted 5 lines · Leonardo E. Reiter
Hello,
attached is an updated version (against today's CVS) of a patch to enable B/G/R color encoding rather than R/G/B with the command-line option -bgr. I found the original here (post by Martin Bochnig):
Shouldn't we be able to figure this out by asking SDL and/or the X server? Also, adding an if to the low-level conversion routines seems a bad idea for performance.
Paul
You can definitely figure it out by asking the X server or SDL. I don't know enough SDL to have hacked it in myself. X is pretty simple on the other hand.
As for where to add it, I agree that the low level conversions are not a great place to add this. I didn't originate the patch, I just updated it. Unfortunately none of the VGA is optimized - everything happens pixel by pixel already. Adding what probably amounts to 2 instructions (probably a couple of clock cycles) per pixel doesn't seem to do anything for performance really. The VGA is already slow.
Unfortunately X11 will not allow you to force a certain color order in 24-bit mode. You can tell it to force byte-order but this only affects 16-bit blits - it's ignored for 24-bit since the individual components of the 24-bit blits, even if packed into 32-bits, are still 8-bits long.
That's what the color masks are for. There is no efficient way to do
this at the server level that I can see. If you find a better way (within the current scope of the VGA architecture), I'd be glad to try to implement it. I was just sharing something that was useful to me.
Thanks,
Leo Reiter
Quoted 13 lines · Paul Brook
Quoted 5 lines · Leonardo E. Reiter
Hello,
attached is an updated version (against today's CVS) of a patch to enable B/G/R color encoding rather than R/G/B with the command-line option -bgr. I found the original here (post by Martin Bochnig):
Shouldn't we be able to figure this out by asking SDL and/or the X server? Also, adding an if to the low-level conversion routines seems a bad idea for performance.
Paul
Signature · 8 lines
Leonardo E. Reiter Vice President of Product Development, CTO Win4Lin, Inc. Virtual Computing from Desktop to Data Center Main: +1 512 339 7979 Fax: +1 512 532 6501 http://www.win4lin.com
Actually it should probably be made conditionally compiled for now, until the VGA architecture changes to something more efficient. Would you agree with that? That way, people who know they will need the hack can enable it at configure/compile time, and the rest will not be affected.
How does that sound? I'd be happy to post an updated patch that does that.
- Leo
Quoted 13 lines · Paul Brook
Quoted 5 lines · Leonardo E. Reiter
Hello,
attached is an updated version (against today's CVS) of a patch to enable B/G/R color encoding rather than R/G/B with the command-line option -bgr. I found the original here (post by Martin Bochnig):
Shouldn't we be able to figure this out by asking SDL and/or the X server? Also, adding an if to the low-level conversion routines seems a bad idea for performance.
Paul
Signature · 8 lines
Leonardo E. Reiter Vice President of Product Development, CTO Win4Lin, Inc. Virtual Computing from Desktop to Data Center Main: +1 512 339 7979 Fax: +1 512 532 6501 http://www.win4lin.com
Quoted 8 lines
Unfortunately X11 will not allow you to force a certain color order in 24-bit mode. You can tell it to force byte-order but this only affects 16-bit blits - it's ignored for 24-bit since the individual components of the 24-bit blits, even if packed into 32-bits, are still 8-bits long.
That's what the color masks are for. There is no efficient way to do
this at the server level that I can see. If you find a better way (within the current scope of the VGA architecture), I'd be glad to try to implement it. I was just sharing something that was useful to me.
It should be possible to select between different 24-bit packings the same way different bit depths are handled.
Paul
Okay, that makes perfect sense. Let me see if I can figure out how to get SDL to report the ordering, and I'll try to roll it out that way.
thanks for clarifying,
- Leo Reiter
Quoted 13 lines · Paul Brook
Quoted 8 lines
Unfortunately X11 will not allow you to force a certain color order in 24-bit mode. You can tell it to force byte-order but this only affects 16-bit blits - it's ignored for 24-bit since the individual components of the 24-bit blits, even if packed into 32-bits, are still 8-bits long.
That's what the color masks are for. There is no efficient way to do
this at the server level that I can see. If you find a better way (within the current scope of the VGA architecture), I'd be glad to try to implement it. I was just sharing something that was useful to me.It should be possible to select between different 24-bit packings the same way different bit depths are handled.
Paul
Signature · 8 lines
Leonardo E. Reiter Vice President of Product Development, CTO Win4Lin, Inc. Virtual Computing from Desktop to Data Center Main: +1 512 339 7979 Fax: +1 512 532 6501 http://www.win4lin.com
Quoted 6 lines · Leonardo E. Reiter
Actually it should probably be made conditionally compiled for now, until the VGA architecture changes to something more efficient. Would you agree with that? That way, people who know they will need the hack can enable it at configure/compile time, and the rest will not be affected.
How does that sound? I'd be happy to post an updated patch that does that.
Making it a configure option sounds a stunningly bad idea. If you're going down that route you may as well make all the output format selection a compile-time option.
Paul
I was talking about enabling the use of the -bgr flag at compile time, to save the check at runtime if the user doesn't even care about the flag, not forcing the determination of the blit order altogether at compile-time. In any case, this is moot, your clarification on how to better implement it makes it much more clear to me and is a much better idea. Mails to the list are a bit delayed, that's all ;)
Thanks,
Leo
Quoted 13 lines · Paul Brook
Quoted 6 lines · Leonardo E. Reiter
Actually it should probably be made conditionally compiled for now, until the VGA architecture changes to something more efficient. Would you agree with that? That way, people who know they will need the hack can enable it at configure/compile time, and the rest will not be affected.
How does that sound? I'd be happy to post an updated patch that does that.
Making it a configure option sounds a stunningly bad idea. If you're going down that route you may as well make all the output format selection a compile-time option.
Paul
Signature · 8 lines
Leonardo E. Reiter Vice President of Product Development, CTO Win4Lin, Inc. Virtual Computing from Desktop to Data Center Main: +1 512 339 7979 Fax: +1 512 532 6501 http://www.win4lin.com
Quoted 6 lines · Leonardo E. Reiter
I was talking about enabling the use of the -bgr flag at compile time, to save the check at runtime if the user doesn't even care about the flag, not forcing the determination of the blit order altogether at compile-time. In any case, this is moot, your clarification on how to better implement it makes it much more clear to me and is a much better idea. Mails to the list are a bit delayed, that's all ;)
Ok. For the record I also think it's a bad idea to have features conditionally compiled. Either something is worth including, or we have to ask whether there's any point having it in qemu at all.
The exception being debug code, which probably isn't useful unless you're already building qemu from source.
Paul
Here's a better patch... I can't seem to validate BGR X servers in 15 or 16-bit mode. This may not make sense (or be prevalent) on little-endian machines anyway (I'm using VNC server on a little endian box to test against.) In any case, 24 and 32-bit works like a charm. I use the same basic logic as the original patch, so it's possible it was always broken for 16-bit... especially given that most Sun X servers run in 24-bit, which is what the originators intended the patch for.
Anyway, I didn't spend time figuring out how to query SDL for the ordering. You still have to manually pass in -bgr. The good news is that all the computation is now done at compile-time, with only very few tests done at run-time. I agree with your assessment of compile-time versus run-time options... I was merely suggesting a compromise to fend off the minor performance hit of using the old patch. But the method you suggested is much better and that's how it's implemented now.
Thanks,
Leo Reiter
Quoted 4 lines · Paul Brook
Ok. For the record I also think it's a bad idea to have features conditionally compiled. Either something is worth including, or we have to ask whether there's any point having it in qemu at all. The exception being debug code, which probably isn't useful unless you're already building qemu from source.
Paul
Signature · 8 lines
Leonardo E. Reiter Vice President of Product Development, CTO Win4Lin, Inc. Virtual Computing from Desktop to Data Center Main: +1 512 339 7979 Fax: +1 512 532 6501 http://www.win4lin.com
Here's a better patch (attached this time!)...
I can't seem to validate BGR X servers in 15 or
16-bit mode. This may not make sense (or be prevalent) on little-endian machines anyway (I'm using VNC server on a little endian box to test against.) In any case, 24 and 32-bit works like a charm. I use the same basic logic as the original patch, so it's possible it was always broken for 16-bit... especially given that most Sun X servers run in 24-bit, which is what the originators intended the patch for.
Anyway, I didn't spend time figuring out how to query SDL for the ordering. You still have to manually pass in -bgr. The good news is that all the computation is now done at compile-time, with only very few tests done at run-time. I agree with your assessment of compile-time versus run-time options... I was merely suggesting a compromise to fend off the minor performance hit of using the old patch. But the method you suggested is much better and that's how it's implemented now.
Thanks,
Leo Reiter
Quoted 4 lines · Paul Brook
Ok. For the record I also think it's a bad idea to have features conditionally compiled. Either something is worth including, or we have to ask whether there's any point having it in qemu at all. The exception being debug code, which probably isn't useful unless you're already building qemu from source.
Paul
Signature · 8 lines
Leonardo E. Reiter Vice President of Product Development, CTO Win4Lin, Inc. Virtual Computing from Desktop to Data Center Main: +1 512 339 7979 Fax: +1 512 532 6501 http://www.win4lin.com
Index: vl.c
===================================================================
RCS file: /cvsroot/qemu/qemu/vl.c,v
retrieving revision 1.168
vl.c +7 -0
@@ -128,6 +128,7 @@int vm_running;int rtc_utc =1 ;int cirrus_vga_enabled =1 ; +int bgr_display_enabled =0 ;#ifdef TARGET_SPARC int graphic_width =1024 ;int graphic_height =768 ;
@@ -4131,6 +4132,7 @@"-m megs set virtual RAM size to megs MB [default=%d]\n" "-smp n set the number of CPUs to 'n' [default=1]\n" "-nographic disable graphical output and redirect serial I/Os to console\n" +"-bgr invert colors for HOSTS using certain SPARC frame buffers\n" #ifndef _WIN32"-k language use keyboard layout (for example \"fr\" for French)\n" #endif
@@ -4283,6 +4285,7 @@ QEMU_OPTION_cirrusvga, QEMU_OPTION_g, QEMU_OPTION_std_vga, + QEMU_OPTION_bgr, QEMU_OPTION_monitor, QEMU_OPTION_serial, QEMU_OPTION_parallel,
@@ -4360,6 +4363,7 @@ { "full-screen", 0, QEMU_OPTION_full_screen }, { "pidfile", HAS_ARG, QEMU_OPTION_pidfile }, { "win2k-hack", 0, QEMU_OPTION_win2k_hack }, + { "bgr", 0, QEMU_OPTION_bgr }, { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice }, { "smp", HAS_ARG, QEMU_OPTION_smp },
@@ -4850,6 +4854,9 @@case QEMU_OPTION_std_vga: cirrus_vga_enabled =0 ;break ; +case QEMU_OPTION_bgr: + bgr_display_enabled =1 ; +break ;case QEMU_OPTION_g: {const char *p;
Index: vl.h
===================================================================
RCS file: /cvsroot/qemu/qemu/vl.h,v
retrieving revision 1.107
vl.h +1 -0
@@ -130,6 +130,7 @@extern int bios_size;extern int rtc_utc;extern int cirrus_vga_enabled; +extern int bgr_display_enabled;extern int graphic_width;extern int graphic_height;extern int graphic_depth;
Index: hw/vga.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/vga.c,v
retrieving revision 1.42
vga.c +78 -10
180 lines not on this page · raw message
Index: hw/vga_template.h
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/vga_template.h,v
retrieving revision 1.11
vga_template.h +46 -13
133 lines not on this page · raw message
Quoted 1 line · Leonardo E. Reiter
Anyway, I didn't spend time figuring out how to query SDL for the ordering. You still have to manually pass in -bgr. The good news is that all the computation is now done at compile-time, with only very few tests done at run-time. I agree with your assessment of compile-time versus run-time options... I was merely suggesting a compromise to fend off the minor performance hit of using the old patch. But the method you suggested is much better and that's how it's implemented now.
I maybe going out on a limb here, but isn't rgb/bgr trivially deducible
from: sdl.c:screen->format->[RGBA]shift.
Signature · 1 line
mailto:[email protected]
Probably... I just don't know anything about SDL and I needed this patch to work right away with at least the command-line option. It's definitely deducible from X11, and that's very easy.
- Leo Reiter
Quoted 8 lines · malc
Quoted 1 line · Leonardo E. Reiter
Anyway, I didn't spend time figuring out how to query SDL for the ordering. You still have to manually pass in -bgr. The good news is that all the computation is now done at compile-time, with only very few tests done at run-time. I agree with your assessment of compile-time versus run-time options... I was merely suggesting a compromise to fend off the minor performance hit of using the old patch. But the method you suggested is much better and that's how it's implemented now.
I maybe going out on a limb here, but isn't rgb/bgr trivially deducible
from: sdl.c:screen->format->[RGBA]shift.
Signature · 8 lines
Leonardo E. Reiter Vice President of Product Development, CTO Win4Lin, Inc. Virtual Computing from Desktop to Data Center Main: +1 512 339 7979 Fax: +1 512 532 6501 http://www.win4lin.com
Quoted 12 lines · Leonardo E. Reiter
Hello,
attached is an updated version (against today's CVS) of a patch to enable B/G/R color encoding rather than R/G/B with the command-line option -bgr. I found the original here (post by Martin Bochnig):
http://lists.nongnu.org/archive/html/qemu-devel/2005-09/msg00059.html
It's main intention is to deal with some 24-bit Sun/SPARC X servers, including SunRays. But you can also mimic this behavior with a VNC server if you want.
Quoted 5 lines
Anyway, it may not be too interesting to most, but it is to me at the moment, so I figured I'd share. To use it, you can pass in the -bgr command line option to qemu. You can get some psychadelic colors if you're really bored and want to try it on an R/G/B 24-bit X server, like XFree86 or X.org :)
FWIW, the SGI O2 has the same problem, I heard the Xorg server got fixed recently to take this into account. I don't know if the fix is O2 specific.
Btw, wouldn't it be the right thing to add a Sun framebuffer emulation instead of fiddling with VGA? Or is the hardware in question actually VGA compatible?
Thiemo
Hi Thiemo,
the goal of my patch (and the original which I derived from) was to give the VGA device the ability to display correctly on BGR X servers. Most likely this is for target-i386 emulation, such as for running Windows guests. That's my need for the patch anyway. In my case, I'm trying to get the colors to look right on a Sun Ray thin client served up from an x86_64 Linux box running the SRSS software from Sun (SunRay server basically.) The emulator sessions run Windows 2000/XP, hence the need for VGA fixes.
If the O2's 24-bit display is similar to the Sun's (i.e. B/G/R, 24-bit depth, 32-bit pixel width), then the patch should fix the problem on the O2 as well when using PC hardware emulation (i.e. i386-softmmu)
- Leo Reiter
Quoted 17 lines · Thiemo Seufer
FWIW, the SGI O2 has the same problem, I heard the Xorg server got fixed recently to take this into account. I don't know if the fix is O2 specific.
Btw, wouldn't it be the right thing to add a Sun framebuffer emulation instead of fiddling with VGA? Or is the hardware in question actually VGA compatible?
Thiemo
_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel
Signature · 8 lines
Leonardo E. Reiter Vice President of Product Development, CTO Win4Lin, Inc. Virtual Computing from Desktop to Data Center Main: +1 512 339 7979 Fax: +1 512 532 6501 http://www.win4lin.com
How's this:
Index: sdl.c
===================================================================
RCS file: /cvsroot/qemu/qemu/sdl.c,v
retrieving revision 1.25
sdl.c 11 Apr 2006 17:03:51 -0000 renamed from sdl.c 9 Apr 2006 01:06:34 -0000 1.25 +5 -0
@@ -510,4 +510,9 @@ gui_fullscreen_initial_grab = 1; sdl_grab_start(); } + + /* guess to use BGR mode by seeing if the blue color mask is greater than + * the red color mask, indicating that blue comes before red */ + if (screen->format->Bmask > screen->format->Rmask) + bgr_display_enabled = 1; }
combined with my prior bgr patch of course (bgr_display_enabled doesn't exist otherwise.) If you think it's right, let me know, or post a better one. Either way I can post an updated BGR patch with this hack.
You can still manually use -bgr if you want, or perhaps the meaning of
-bgr should be to enable this test. It may not be correct in all circumstances. Maybe Paul Brook can weigh in too since he originally suggested that this patch should determine this automatically.
Thanks,
Leo Reiter
Quoted 8 lines · malc
Quoted 1 line · Leonardo E. Reiter
Anyway, I didn't spend time figuring out how to query SDL for the ordering. You still have to manually pass in -bgr. The good news is that all the computation is now done at compile-time, with only very few tests done at run-time. I agree with your assessment of compile-time versus run-time options... I was merely suggesting a compromise to fend off the minor performance hit of using the old patch. But the method you suggested is much better and that's how it's implemented now.
I maybe going out on a limb here, but isn't rgb/bgr trivially deducible
from: sdl.c:screen->format->[RGBA]shift.
Signature · 8 lines
Leonardo E. Reiter Vice President of Product Development, CTO Win4Lin, Inc. Virtual Computing from Desktop to Data Center Main: +1 512 339 7979 Fax: +1 512 532 6501 http://www.win4lin.com
By the way, I did verify that the patch works correctly in B/G/R 5/6/5 mode - I wasn't sure about 16-bit BGR before. However, in 16-bit mode, only -std-vga works correctly if the X server is in BGR mode. In 24-bit BGR mode, cirrus has no problem. I think there is some 16-bit trickery going on in the cirrus implementation, but I haven't had much time to figure it out. Also the cirrus implementation is really hard to follow for me, so if anyone has any idea, I'd appreciate it.
Thanks,
Leo Reiter
Quoted 8 lines · malc
Quoted 1 line · Leonardo E. Reiter
Anyway, I didn't spend time figuring out how to query SDL for the ordering. You still have to manually pass in -bgr. The good news is that all the computation is now done at compile-time, with only very few tests done at run-time. I agree with your assessment of compile-time versus run-time options... I was merely suggesting a compromise to fend off the minor performance hit of using the old patch. But the method you suggested is much better and that's how it's implemented now.
I maybe going out on a limb here, but isn't rgb/bgr trivially deducible
from: sdl.c:screen->format->[RGBA]shift.
Signature · 8 lines
Leonardo E. Reiter Vice President of Product Development, CTO Win4Lin, Inc. Virtual Computing from Desktop to Data Center Main: +1 512 339 7979 Fax: +1 512 532 6501 http://www.win4lin.com