From: Ian Jackson Date: Mon, 14 Jul 2008 12:46:28 +0000 (+0100) Subject: qemu ioemu rendering fixes for palette handling (another dropped patch) X-Git-Tag: xen-3.3.0-rc1~37 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=1ec7aa3263bc7fd78bcc40e4ceb2ca067a1a8687;p=qemu-xen-4.0-testing.git qemu ioemu rendering fixes for palette handling (another dropped patch) Stefano reports that this part of xen-unstable 17334:baff5b3aaf13 was accidentally dropped. Signed-off-by: Stefano Stabellini --- diff --git a/console.h b/console.h index 1ec937a0..c3b11304 100644 --- 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; diff --git a/hw/vga.c b/hw/vga.c index c2ab8d67..6ad9ab5a 100644 --- 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 d583ffae..72e7d821 100644 --- 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; }