]> xenbits.xensource.com Git - qemu-xen-3.3-testing.git/commitdiff
qemu ioemu rendering fixes for palette handling (another dropped patch)
authorIan Jackson <iwj@mariner.uk.xensource.com>
Mon, 14 Jul 2008 12:46:28 +0000 (13:46 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 14 Jul 2008 12:46:28 +0000 (13:46 +0100)
Stefano reports that this part of xen-unstable 17334:baff5b3aaf13
was accidentally dropped.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
console.h
hw/vga.c
sdl.c

index 1ec937a0e82f13332a0a40e0b03cdf36194f1867..c3b113042830c6fcc08b01a1e734b8e09cfa5010 100644 (file)
--- a/console.h
+++ b/console.h
@@ -73,6 +73,7 @@ struct DisplayState {
     int width;
     int height;
     void *opaque;
+    uint32_t *palette;
     struct QEMUTimer *gui_timer;
     uint64_t gui_timer_interval;
     int idle;
index c2ab8d67c91990e2e7bf72aba0892876b871de0d..6ad9ab5a1b4346fb2caceec2e470d1df0661c337 100644 (file)
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -2038,6 +2038,7 @@ void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
     s->vram_offset = vga_ram_offset;
     s->vram_size = vga_ram_size;
     s->ds = ds;
+    ds->palette = s->last_palette;
     s->get_bpp = vga_get_bpp;
     s->get_offsets = vga_get_offsets;
     s->get_resolution = vga_get_resolution;
diff --git a/sdl.c b/sdl.c
index d583ffae2cd1016ac6a85083d1fd79fd97f1b84b..72e7d821a1efab41ee0bb2581ef7da4f84eb2cd7 100644 (file)
--- a/sdl.c
+++ b/sdl.c
@@ -90,19 +90,33 @@ static void opengl_setdata(DisplayState *ds, void *pixels)
     glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
     switch (ds->depth) {
         case 8:
-            tex_format = GL_RGB;
-            tex_type = GL_UNSIGNED_BYTE_3_3_2;
-            glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
+            if (ds->palette == NULL) {
+                tex_format = GL_RGB;
+                tex_type = GL_UNSIGNED_BYTE_3_3_2;
+            } else {
+                int i;
+                GLushort paletter[256], paletteg[256], paletteb[256];
+                for (i = 0; i < 256; i++) {
+                    uint8_t rgb = ds->palette[i] >> 16;
+                    paletter[i] = ((rgb & 0xe0) >> 5) * 65535 / 7;
+                    paletteg[i] = ((rgb & 0x1c) >> 2) * 65535 / 7;
+                    paletteb[i] = (rgb & 0x3) * 65535 / 3;
+                }
+                glPixelMapusv(GL_PIXEL_MAP_I_TO_R, 256, paletter);
+                glPixelMapusv(GL_PIXEL_MAP_I_TO_G, 256, paletteg);
+                glPixelMapusv(GL_PIXEL_MAP_I_TO_B, 256, paletteb);
+
+                tex_format = GL_COLOR_INDEX;
+                tex_type = GL_UNSIGNED_BYTE;
+            }
             break;
         case 16:
             tex_format = GL_RGB;
             tex_type = GL_UNSIGNED_SHORT_5_6_5;
-            glPixelStorei (GL_UNPACK_ALIGNMENT, 2);
             break;
         case 24:
             tex_format = GL_BGR;
             tex_type = GL_UNSIGNED_BYTE;
-            glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
             break;
         case 32:
             if (!ds->bgr) {
@@ -112,7 +126,6 @@ static void opengl_setdata(DisplayState *ds, void *pixels)
                 tex_format = GL_RGBA;
                 tex_type = GL_UNSIGNED_BYTE;                
             }
-            glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
             break;
     }   
     glPixelStorei(GL_UNPACK_ROW_LENGTH, (ds->linesize * 8) / ds->depth);
@@ -189,6 +202,17 @@ static void sdl_setdata(DisplayState *ds, void *pixels)
             return;
     }
     shared = SDL_CreateRGBSurfaceFrom(pixels, width, height, ds->depth, ds->linesize, rmask , gmask, bmask, amask);
+    if (ds->depth == 8 && ds->palette != NULL) {
+        SDL_Color palette[256];
+        int i;
+        for (i = 0; i < 256; i++) {
+            uint8_t rgb = ds->palette[i] >> 16;
+            palette[i].r = ((rgb & 0xe0) >> 5) * 255 / 7;
+            palette[i].g = ((rgb & 0x1c) >> 2) * 255 / 7;
+            palette[i].b = (rgb & 0x3) * 255 / 3;
+        }
+        SDL_SetColors(shared, palette, 0, 256);
+    }
     ds->data = pixels;
 }