diff options
Diffstat (limited to 'engines/sci/gfx/resource')
-rw-r--r-- | engines/sci/gfx/resource/sci_pal_1.cpp | 55 | ||||
-rw-r--r-- | engines/sci/gfx/resource/sci_pic_0.cpp | 147 | ||||
-rw-r--r-- | engines/sci/gfx/resource/sci_resmgr.cpp | 55 | ||||
-rw-r--r-- | engines/sci/gfx/resource/sci_view_0.cpp | 12 | ||||
-rw-r--r-- | engines/sci/gfx/resource/sci_view_1.cpp | 33 |
5 files changed, 128 insertions, 174 deletions
diff --git a/engines/sci/gfx/resource/sci_pal_1.cpp b/engines/sci/gfx/resource/sci_pal_1.cpp index c448550655..74fb8629b7 100644 --- a/engines/sci/gfx/resource/sci_pal_1.cpp +++ b/engines/sci/gfx/resource/sci_pal_1.cpp @@ -39,13 +39,13 @@ namespace Sci { #define SCI_PAL_FORMAT_VARIABLE_FLAGS 0 #define SCI_PAL_FORMAT_CONSTANT_FLAGS 1 -gfx_pixmap_color_t *gfxr_read_pal11(int id, int *colors_nr, byte *resource, int size) { +Palette *gfxr_read_pal11(int id, byte *resource, int size) { int start_color = resource[25]; int format = resource[32]; int entry_size = 0; - gfx_pixmap_color_t *retval; + Palette *retval; byte *pal_data = resource + 37; - int _colors_nr = *colors_nr = READ_LE_UINT16(resource + 29); + int _colors_nr = READ_LE_UINT16(resource + 29); int i; switch (format) { @@ -57,28 +57,21 @@ gfx_pixmap_color_t *gfxr_read_pal11(int id, int *colors_nr, byte *resource, int break; } - retval = (gfx_pixmap_color_t *)sci_malloc(sizeof(gfx_pixmap_color_t) * (_colors_nr + start_color)); - memset(retval, 0, sizeof(gfx_pixmap_color_t) * (_colors_nr + start_color)); + retval = new Palette(_colors_nr + start_color); + char buf[100]; + sprintf(buf, "read_pal11 (id %d)", id); + retval->name = buf; for (i = 0; i < start_color; i ++) { - retval[i].global_index = GFX_COLOR_INDEX_UNMAPPED; - retval[i].r = 0; - retval[i].g = 0; - retval[i].b = 0; + retval->setColor(i, 0, 0, 0); } for (i = start_color; i < start_color + _colors_nr; i ++) { switch (format) { case SCI_PAL_FORMAT_CONSTANT_FLAGS: - retval[i].global_index = GFX_COLOR_INDEX_UNMAPPED; - retval[i].r = pal_data[0]; - retval[i].g = pal_data[1]; - retval[i].b = pal_data[2]; + retval->setColor(i, pal_data[0], pal_data[1], pal_data[2]); break; case SCI_PAL_FORMAT_VARIABLE_FLAGS: - retval[i].global_index = GFX_COLOR_INDEX_UNMAPPED; - retval[i].r = pal_data[1]; - retval[i].g = pal_data[2]; - retval[i].b = pal_data[3]; + retval->setColor(i, pal_data[1], pal_data[2], pal_data[3]); break; } pal_data += entry_size; @@ -87,11 +80,10 @@ gfx_pixmap_color_t *gfxr_read_pal11(int id, int *colors_nr, byte *resource, int return retval; } -gfx_pixmap_color_t *gfxr_read_pal1(int id, int *colors_nr, byte *resource, int size) { +Palette *gfxr_read_pal1(int id, byte *resource, int size) { int counter = 0; int pos; unsigned int colors[MAX_COLORS] = {0}; - gfx_pixmap_color_t *retval; if (size < PALETTE_START + 4) { GFXERROR("Palette resource too small in %04x\n", id); @@ -118,26 +110,22 @@ gfx_pixmap_color_t *gfxr_read_pal1(int id, int *colors_nr, byte *resource, int s return NULL; } - retval = (gfx_pixmap_color_t*)sci_malloc(sizeof(gfx_pixmap_color_t) * counter); + Palette *retval = new Palette(counter); + char buf[100]; + sprintf(buf, "read_pal1 (id %d)", id); + retval->name = buf; - *colors_nr = counter; for (pos = 0; pos < counter; pos++) { unsigned int color = colors[pos]; - - retval[pos].global_index = GFX_COLOR_INDEX_UNMAPPED; - retval[pos].r = (color >> 8) & 0xff; - retval[pos].g = (color >> 16) & 0xff; - retval[pos].b = (color >> 24) & 0xff; + retval->setColor(pos, (color >> 8) & 0xff, (color >> 16) & 0xff, (color >> 24) & 0xff); } return retval; } -gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, Common::File &file) { +Palette *gfxr_read_pal1_amiga(Common::File &file) { int i; - gfx_pixmap_color_t *retval; - - retval = (gfx_pixmap_color_t *)sci_malloc(sizeof(gfx_pixmap_color_t) * 32); + Palette *retval = new Palette(32); for (i = 0; i < 32; i++) { int b1, b2; @@ -150,14 +138,9 @@ gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, Common::File &file) { return NULL; } - retval[i].global_index = GFX_COLOR_INDEX_UNMAPPED; - retval[i].r = (b1 & 0xf) * 0x11; - retval[i].g = ((b2 & 0xf0) >> 4) * 0x11; - retval[i].b = (b2 & 0xf) * 0x11; + retval->setColor(i, (b1 & 0xf) * 0x11, ((b2 & 0xf0) >> 4) * 0x11, (b2 & 0xf) * 0x11); } - *colors_nr = 32; - return retval; } diff --git a/engines/sci/gfx/resource/sci_pic_0.cpp b/engines/sci/gfx/resource/sci_pic_0.cpp index f4f0027b3d..b91ad8ff05 100644 --- a/engines/sci/gfx/resource/sci_pic_0.cpp +++ b/engines/sci/gfx/resource/sci_pic_0.cpp @@ -99,9 +99,9 @@ gfx_pixmap_color_t gfx_sci0_image_colors[SCI0_MAX_PALETTE+1][GFX_SCI0_IMAGE_COLO #undef C3 #undef C4 -gfx_pixmap_color_t gfx_sci0_pic_colors[GFX_SCI0_PIC_COLORS_NR]; // Initialized during initialization - -static int _gfxr_pic0_colors_initialized = 0; +Palette* gfx_sci0_pic_colors = 0; // Initialized during initialization +Palette* gfx_sci0_image_pal[SCI0_MAX_PALETTE+1]; +Palette* embedded_view_pal = 0; #define SCI1_PALETTE_SIZE 1284 @@ -121,18 +121,28 @@ gfx_pixmap_color_t embedded_view_colors[16] = { }; void gfxr_init_static_palette() { - if (!_gfxr_pic0_colors_initialized) { + if (!gfx_sci0_pic_colors) { + gfx_sci0_pic_colors = new Palette(256); + gfx_sci0_pic_colors->name = "gfx_sci0_pic_colors"; for (int i = 0; i < 256; i++) { - gfx_sci0_pic_colors[i].global_index = GFX_COLOR_INDEX_UNMAPPED; - gfx_sci0_pic_colors[i].r = INTERCOL(gfx_sci0_image_colors[sci0_palette][i & 0xf].r, - gfx_sci0_image_colors[sci0_palette][i >> 4].r); - gfx_sci0_pic_colors[i].g = INTERCOL(gfx_sci0_image_colors[sci0_palette][i & 0xf].g, - gfx_sci0_image_colors[sci0_palette][i >> 4].g); - gfx_sci0_pic_colors[i].b = INTERCOL(gfx_sci0_image_colors[sci0_palette][i & 0xf].b, - gfx_sci0_image_colors[sci0_palette][i >> 4].b); + byte r = INTERCOL(gfx_sci0_image_colors[sci0_palette][i & 0xf].r, + gfx_sci0_image_colors[sci0_palette][i >> 4].r); + byte g = INTERCOL(gfx_sci0_image_colors[sci0_palette][i & 0xf].g, + gfx_sci0_image_colors[sci0_palette][i >> 4].g); + byte b = INTERCOL(gfx_sci0_image_colors[sci0_palette][i & 0xf].b, + gfx_sci0_image_colors[sci0_palette][i >> 4].b); + gfx_sci0_pic_colors->setColor(i,r,g,b); } //warning("Uncomment me after fixing sci0_palette changes to reset me"); //_gfxr_pic0_colors_initialized = 1; + + for (int i = 0; i <= SCI0_MAX_PALETTE; ++i) { + gfx_sci0_image_pal[i] = new Palette(gfx_sci0_image_colors[i], GFX_SCI0_IMAGE_COLORS_NR); + gfx_sci0_image_pal[i]->name = "gfx_sci0_image_pal[i]"; + } + + embedded_view_pal = new Palette(embedded_view_colors, 16); + embedded_view_pal->name = "embedded_view_pal"; } } @@ -150,28 +160,26 @@ gfxr_pic_t *gfxr_init_pic(gfx_mode_t *mode, int ID, int sci1) { pic->visual_map = gfx_pixmap_alloc_index_data(gfx_new_pixmap(320 * mode->xfact, 200 * mode->yfact, ID, 0, 0)); - pic->visual_map->colors = gfx_sci0_pic_colors; - pic->visual_map->colors_nr = GFX_SCI0_PIC_COLORS_NR; + + // Initialize colors + if (!sci1) { + pic->ID = ID; + gfxr_init_static_palette(); + } + + pic->visual_map->palette = gfx_sci0_pic_colors->getref(); pic->visual_map->color_key = GFX_PIXMAP_COLOR_KEY_NONE; - pic->visual_map->flags = GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; - pic->priority_map->flags = GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; - pic->control_map->flags = GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; + pic->visual_map->flags = 0; + pic->priority_map->flags = 0; + pic->control_map->flags = 0; if (mode->xfact > 1 || mode->yfact > 1) { pic->visual_map->flags |= GFX_PIXMAP_FLAG_SCALED_INDEX; pic->priority_map->flags |= GFX_PIXMAP_FLAG_SCALED_INDEX; } - pic->priority_map->colors = gfx_sci0_image_colors[sci0_palette]; - pic->priority_map->colors_nr = GFX_SCI0_IMAGE_COLORS_NR; - pic->control_map->colors = gfx_sci0_image_colors[sci0_palette]; - pic->control_map->colors_nr = GFX_SCI0_IMAGE_COLORS_NR; - - // Initialize colors - if (!sci1) { - pic->ID = ID; - gfxr_init_static_palette(); - } + pic->priority_map->palette = gfx_sci0_image_pal[sci0_palette]->getref(); + pic->control_map->palette = gfx_sci0_image_pal[sci0_palette]->getref(); pic->undithered_buffer_size = pic->visual_map->index_xl * pic->visual_map->index_yl; pic->undithered_buffer = NULL; @@ -1257,14 +1265,18 @@ void gfxr_remove_artifacts_pic0(gfxr_pic_t *dest, gfxr_pic_t *src) { } -static void view_transparentize(gfx_pixmap_t *view, byte *pic_index_data, int posx, int posy, int width, int height) { +static void view_transparentize(gfx_pixmap_t *view, gfx_pixmap_t *background, int posx, int posy, int width, int height) { int i, j; + byte *pic_index_data = background->index_data; + + // FIXME: this assumes view and background have the same palette... + // We may want to do a reverse mapping or similar to make it general, + // but this (hopefully...) suffices for the current uses of this function. for (i = 0;i < width;i++) for (j = 0;j < height;j++) { if (view->index_data[j*width+i] == view->color_key) { - view->index_data[j*width+i] = - pic_index_data[(j+posy)*width+i+posx]; + view->index_data[j*width+i] = pic_index_data[(j+posy)*width+i+posx]; } } } @@ -1274,7 +1286,7 @@ extern gfx_pixmap_t *gfxr_draw_cel1(int id, int loop, int cel, int mirrored, byt extern void _gfx_crossblit_simple(byte *dest, byte *src, int dest_line_width, int src_line_width, int xl, int yl, int bpp); void gfxr_draw_pic01(gfxr_pic_t *pic, int flags, int default_palette, int size, byte *resource, - gfxr_pic0_params_t *style, int resid, int sci1, gfx_pixmap_color_t *static_pal, int static_pal_nr) { + gfxr_pic0_params_t *style, int resid, int sci1, Palette *static_pal) { const int default_palette_table[GFXR_PIC0_PALETTE_SIZE] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0x88, @@ -1610,8 +1622,9 @@ void gfxr_draw_pic01(gfxr_pic_t *pic, int flags, int default_palette, int size, case PIC_SCI1_OPX_SET_PALETTE: p0printf("Set palette @%d\n", pos); - pic->visual_map->flags &= ~GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; - pic->visual_map->colors = gfxr_read_pal1(resid, &pic->visual_map->colors_nr, + if (pic->visual_map->palette) + pic->visual_map->palette->free(); + pic->visual_map->palette = gfxr_read_pal1(resid, resource + pos, SCI1_PALETTE_SIZE); pos += SCI1_PALETTE_SIZE; goto end_op_loop; @@ -1640,17 +1653,9 @@ void gfxr_draw_pic01(gfxr_pic_t *pic, int flags, int default_palette, int size, int nodraw = 0; gfx_pixmap_t *view; - //gfx_mode_t *mode; p0printf("Embedded view @%d\n", pos); -#if 0 - // Set up mode structure for resizing the view - Graphics::PixelFormat format = { 1, 0, 0, 0, 0, 0, 0, 0, 0 }; // 1bpp, which handles masks and the rest for us - mode = gfx_new_mode(pic->visual_map->index_xl / 320, - pic->visual_map->index_yl / 200, format, 16, 0); -#endif - GET_ABS_COORDS(posx, posy); bytesize = (*(resource + pos)) + (*(resource + pos + 1) << 8); p0printf("(%d, %d)\n", posx, posy); @@ -1658,7 +1663,7 @@ void gfxr_draw_pic01(gfxr_pic_t *pic, int flags, int default_palette, int size, if (!sci1 && !nodraw) view = gfxr_draw_cel0(-1, -1, -1, resource + pos, bytesize, NULL, 0); else - view = gfxr_draw_cel1(-1, -1, -1, 0, resource + pos, bytesize, NULL, static_pal_nr == GFX_SCI1_AMIGA_COLORS_NR); + view = gfxr_draw_cel1(-1, -1, -1, 0, resource + pos, bytesize, NULL, (static_pal && static_pal->size() == GFX_SCI1_AMIGA_COLORS_NR)); pos += bytesize; if (nodraw) continue; @@ -1667,7 +1672,7 @@ void gfxr_draw_pic01(gfxr_pic_t *pic, int flags, int default_palette, int size, // we can only safely replace the palette if it's static // *if it's not for some reason, we should die - if (!(view->flags & GFX_PIXMAP_FLAG_EXTERNAL_PALETTE) && !sci1) { + if (view->palette && view->palette->isShared() && !sci1) { sciprintf("gfx_draw_pic0(): can't set a non-static palette for an embedded view!\n"); } @@ -1675,40 +1680,36 @@ void gfxr_draw_pic01(gfxr_pic_t *pic, int flags, int default_palette, int size, // nibble of the color index to the high nibble. if (sci1) { - if (static_pal_nr == GFX_SCI1_AMIGA_COLORS_NR) { + if (static_pal && static_pal->size() == GFX_SCI1_AMIGA_COLORS_NR) { // Assume Amiga game - pic->visual_map->colors = static_pal; - pic->visual_map->colors_nr = static_pal_nr; - pic->visual_map->flags |= GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; + pic->visual_map->palette = static_pal->getref(); } - view->colors = pic->visual_map->colors; - view->colors_nr = pic->visual_map->colors_nr; + if (view->palette) view->palette->free(); + view->palette = pic->visual_map->palette->copy(); } else - view->colors = embedded_view_colors; + view->palette = embedded_view_pal->getref(); // Hack to prevent overflowing the visual map buffer. // Yes, this does happen otherwise. if (view->index_yl + sci_titlebar_size > 200) sci_titlebar_size = 0; -#if 0 - // FIXME: This doesn't just scale the image, but also - // tries to fit the colours into the palette in 'mode', - // breaking colours in e.g., KQ5 floppy. + // Set up mode structure for resizing the view + Graphics::PixelFormat format = { 1, 0, 0, 0, 0, 0, 0, 0, 0 }; // 1byte/p, which handles masks and the rest for us + gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_xl / 320, + pic->visual_map->index_yl / 200, format, view->palette, 0); + gfx_xlate_pixmap(view, mode, GFX_XLATE_FILTER_NONE); -#endif + gfx_free_mode(mode); if (flags & DRAWPIC01_FLAG_OVERLAID_PIC) - view_transparentize(view, pic->visual_map->index_data, posx, sci_titlebar_size + posy, + view_transparentize(view, pic->visual_map, posx, sci_titlebar_size + posy, view->index_xl, view->index_yl); _gfx_crossblit_simple(pic->visual_map->index_data + (sci_titlebar_size * 320) + posy * 320 + posx, view->index_data, pic->visual_map->index_xl, view->index_xl, view->index_xl, view->index_yl, 1); -#if 0 - gfx_free_mode(mode); -#endif gfx_free_pixmap(NULL, view); } goto end_op_loop; @@ -1777,36 +1778,32 @@ end_op_loop: {} } void gfxr_draw_pic11(gfxr_pic_t *pic, int flags, int default_palette, int size, byte *resource, - gfxr_pic0_params_t *style, int resid, gfx_pixmap_color_t *static_pal, int static_pal_nr) { + gfxr_pic0_params_t *style, int resid, Palette *static_pal) { int has_bitmap = READ_LE_UINT16(resource + 4); int vector_data_ptr = READ_LE_UINT16(resource + 16); int palette_data_ptr = READ_LE_UINT16(resource + 28); int bitmap_data_ptr = READ_LE_UINT16(resource + 32); int sci_titlebar_size = style->pic_port_bounds.y; - //gfx_mode_t *mode; gfx_pixmap_t *view = NULL; -#if 0 - // Set up mode structure for resizing the view - Graphics::PixelFormat format = { 1, 0, 0, 0, 0, 0, 0, 0, 0 }; // 1bpp, which handles masks and the rest for us - mode = gfx_new_mode(pic->visual_map->index_xl / 320, pic->visual_map->index_yl / 200, - format, 16, 0); -#endif - pic->visual_map->colors = gfxr_read_pal11(-1, &(pic->visual_map->colors_nr), resource + palette_data_ptr, 1284); + if (pic->visual_map->palette) pic->visual_map->palette->free(); + pic->visual_map->palette = gfxr_read_pal11(-1, resource + palette_data_ptr, 1284); if (has_bitmap) view = gfxr_draw_cel11(-1, 0, 0, 0, resource, resource + bitmap_data_ptr, size - bitmap_data_ptr, NULL); if (view) { - view->colors = pic->visual_map->colors; - view->colors_nr = pic->visual_map->colors_nr; + view->palette = pic->visual_map->palette->getref(); + + // Set up mode structure for resizing the view + Graphics::PixelFormat format = { 1, 0, 0, 0, 0, 0, 0, 0, 0 }; // 1 byte/p, which handles masks and the rest for us + gfx_mode_t *mode = gfx_new_mode(pic->visual_map->index_xl / 320, pic->visual_map->index_yl / 200, format, view->palette, 0); -#if 0 gfx_xlate_pixmap(view, mode, GFX_XLATE_FILTER_NONE); -#endif + gfx_free_mode(mode); if (flags & DRAWPIC01_FLAG_OVERLAID_PIC) - view_transparentize(view, pic->visual_map->index_data, 0, 0, view->index_xl, view->index_yl); + view_transparentize(view, pic->visual_map, 0, 0, view->index_xl, view->index_yl); // Hack to prevent overflowing the visual map buffer. // Yes, this does happen otherwise. @@ -1823,8 +1820,7 @@ void gfxr_draw_pic11(gfxr_pic_t *pic, int flags, int default_palette, int size, GFXWARN("No view was contained in SCI1.1 pic resource"); } - gfxr_draw_pic01(pic, flags, default_palette, size - vector_data_ptr, resource + vector_data_ptr, style, resid, 1, - static_pal, static_pal_nr); + gfxr_draw_pic01(pic, flags, default_palette, size - vector_data_ptr, resource + vector_data_ptr, style, resid, 1, static_pal); } void gfxr_dither_pic0(gfxr_pic_t *pic, int dmode, int pattern) { @@ -1841,8 +1837,7 @@ void gfxr_dither_pic0(gfxr_pic_t *pic, int dmode, int pattern) { return; // Nothing to do if (dmode == GFXR_DITHER_MODE_D16) { // Limit to 16 colors - pic->visual_map->colors = gfx_sci0_image_colors[sci0_palette]; - pic->visual_map->colors_nr = GFX_SCI0_IMAGE_COLORS_NR; + pic->visual_map->palette = gfx_sci0_image_pal[sci0_palette]->getref(); } for (y = 0; y < yl; y++) { diff --git a/engines/sci/gfx/resource/sci_resmgr.cpp b/engines/sci/gfx/resource/sci_resmgr.cpp index 97ecfb3d1d..c3646eb6b4 100644 --- a/engines/sci/gfx/resource/sci_resmgr.cpp +++ b/engines/sci/gfx/resource/sci_resmgr.cpp @@ -101,31 +101,25 @@ int gfxr_interpreter_calculate_pic(gfx_resstate_t *state, gfxr_pic_t *scaled_pic if (state->version >= SCI_VERSION_01_VGA) { if (need_unscaled) { if (state->version == SCI_VERSION_1_1) - gfxr_draw_pic11(unscaled_pic, flags, default_palette, res->size, res->data, &basic_style, res->id, - state->static_palette, state->static_palette_entries); + gfxr_draw_pic11(unscaled_pic, flags, default_palette, res->size, res->data, &basic_style, res->id, state->static_palette); else - gfxr_draw_pic01(unscaled_pic, flags, default_palette, res->size, res->data, &basic_style, res->id, 1, - state->static_palette, state->static_palette_entries); + gfxr_draw_pic01(unscaled_pic, flags, default_palette, res->size, res->data, &basic_style, res->id, 1, state->static_palette); } if (scaled_pic && scaled_pic->undithered_buffer) memcpy(scaled_pic->visual_map->index_data, scaled_pic->undithered_buffer, scaled_pic->undithered_buffer_size); if (state->version == SCI_VERSION_1_1) - gfxr_draw_pic11(scaled_pic, flags, default_palette, res->size, res->data, &style, res->id, - state->static_palette, state->static_palette_entries); + gfxr_draw_pic11(scaled_pic, flags, default_palette, res->size, res->data, &style, res->id, state->static_palette); else - gfxr_draw_pic01(scaled_pic, flags, default_palette, res->size, res->data, &style, res->id, state->version, - state->static_palette, state->static_palette_entries); + gfxr_draw_pic01(scaled_pic, flags, default_palette, res->size, res->data, &style, res->id, state->version, state->static_palette); } else { if (need_unscaled) - gfxr_draw_pic01(unscaled_pic, flags, default_palette, res->size, res->data, &basic_style, res->id, 0, - state->static_palette, state->static_palette_entries); + gfxr_draw_pic01(unscaled_pic, flags, default_palette, res->size, res->data, &basic_style, res->id, 0, state->static_palette); if (scaled_pic && scaled_pic->undithered_buffer) memcpy(scaled_pic->visual_map->index_data, scaled_pic->undithered_buffer, scaled_pic->undithered_buffer_size); - gfxr_draw_pic01(scaled_pic, flags, default_palette, res->size, res->data, &style, res->id, 0, - state->static_palette, state->static_palette_entries); + gfxr_draw_pic01(scaled_pic, flags, default_palette, res->size, res->data, &style, res->id, 0, state->static_palette); if (need_unscaled) gfxr_remove_artifacts_pic0(scaled_pic, unscaled_pic); @@ -147,12 +141,12 @@ int gfxr_interpreter_calculate_pic(gfx_resstate_t *state, gfxr_pic_t *scaled_pic return GFX_OK; } -void gfxr_palettize_view(gfxr_view_t *view, gfx_pixmap_color_t *source, int source_entries) { - int i; - - for (i = 0;i < MIN(view->colors_nr, source_entries);i++) { - if ((view->colors[i].r == 0) && (view->colors[i].g == 0) && (view->colors[i].b == 0)) { - view->colors[i] = source[i]; +void gfxr_palettize_view(gfxr_view_t *view, Palette *source) { + for (unsigned i = 0; i < MIN(view->palette->size(), source->size()); i++) { + const PaletteEntry& vc = view->palette->getColor(i); + if (vc.r == 0 && vc.g == 0 && vc.b == 0) { + const PaletteEntry& sc = source->getColor(i); + view->palette->setColor(i, sc.r, sc.g, sc.b); } } } @@ -179,7 +173,7 @@ gfxr_view_t *gfxr_interpreter_get_view(gfx_resstate_t *state, int nr, void *inte case SCI_VERSION_01_VGA_ODD: case SCI_VERSION_1_EARLY: case SCI_VERSION_1_LATE: - result = gfxr_draw_view1(resid, res->data, res->size, state->static_palette, state->static_palette_entries); + result = gfxr_draw_view1(resid, res->data, res->size, state->static_palette); break; case SCI_VERSION_1_1: case SCI_VERSION_32: @@ -188,12 +182,11 @@ gfxr_view_t *gfxr_interpreter_get_view(gfx_resstate_t *state, int nr, void *inte } if (state->version >= SCI_VERSION_01_VGA) { - if (!result->colors) { - result->colors = (gfx_pixmap_color_t *)sci_malloc(sizeof(gfx_pixmap_color_t) * state->static_palette_entries); - memset(result->colors, 0, sizeof(gfx_pixmap_color_t) * state->static_palette_entries); - result->colors_nr = state->static_palette_entries; + if (!result->palette) { + result->palette = new Palette(state->static_palette->size()); + result->palette->name = "interpreter_get_view"; } - gfxr_palettize_view(result, state->static_palette, state->static_palette_entries); + gfxr_palettize_view(result, state->static_palette); } return result; } @@ -235,9 +228,9 @@ gfx_pixmap_t *gfxr_interpreter_get_cursor(gfx_resstate_t *state, int nr, void *i byte *resource = res->data; retval = gfx_pixmap_alloc_index_data(gfx_new_pixmap(CURSOR_SIZE, CURSOR_SIZE, resid, 0, 0)); - retval->colors = gfx_sci01_cursor_colors; - retval->colors_nr = (state->version != SCI_VERSION_0) ? 3 : 2; - retval->flags |= GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; + // FIXME: don't copy palette + retval->palette = new Palette(gfx_sci01_cursor_colors, (state->version != SCI_VERSION_0) ? 3 : 2); + retval->palette->name = "cursor"; retval->color_key = GFX_CURSOR_TRANSPARENT; if (state->version != SCI_VERSION_0) { @@ -305,15 +298,15 @@ int *gfxr_interpreter_get_resources(gfx_resstate_t *state, gfx_resource_type_t t return resources; } -gfx_pixmap_color_t *gfxr_interpreter_get_static_palette(gfx_resstate_t *state, int version, int *colors_nr, void *internal) { +Palette *gfxr_interpreter_get_static_palette(gfx_resstate_t *state, int version, int *colors_nr, void *internal) { if (version >= SCI_VERSION_01_VGA) return gfxr_interpreter_get_palette(state, version, colors_nr, internal, 999); *colors_nr = GFX_SCI0_PIC_COLORS_NR; - return gfx_sci0_pic_colors; + return gfx_sci0_pic_colors->getref(); } -gfx_pixmap_color_t *gfxr_interpreter_get_palette(gfx_resstate_t *state, int version, int *colors_nr, void *internal, int nr) { +Palette *gfxr_interpreter_get_palette(gfx_resstate_t *state, int version, int *colors_nr, void *internal, int nr) { ResourceManager *resmgr = (ResourceManager *)state->misc_payload; Resource *res; @@ -329,7 +322,7 @@ gfx_pixmap_color_t *gfxr_interpreter_get_palette(gfx_resstate_t *state, int vers case SCI_VERSION_01_VGA_ODD : case SCI_VERSION_1_EARLY : case SCI_VERSION_1_LATE : - return gfxr_read_pal1(res->id, colors_nr, res->data, res->size); + return gfxr_read_pal1(res->id, res->data, res->size); case SCI_VERSION_1_1 : case SCI_VERSION_32 : GFXDEBUG("Palettes are not yet supported in this SCI version\n"); diff --git a/engines/sci/gfx/resource/sci_view_0.cpp b/engines/sci/gfx/resource/sci_view_0.cpp index 8a9c4c024a..6a0ca140c4 100644 --- a/engines/sci/gfx/resource/sci_view_0.cpp +++ b/engines/sci/gfx/resource/sci_view_0.cpp @@ -49,14 +49,11 @@ gfx_pixmap_t *gfxr_draw_cel0(int id, int loop, int cel, byte *resource, int size retval->xoffset = mirrored ? xhot : -xhot; retval->yoffset = -yhot; - retval->flags |= GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; if (view) { - retval->colors = view->colors; - retval->colors_nr = view->colors_nr; + retval->palette = view->palette->getref(); } else { - retval->colors = gfx_sci0_image_colors[sci0_palette]; - retval->colors_nr = GFX_SCI0_IMAGE_COLORS_NR; + retval->palette = gfx_sci0_image_pal[sci0_palette]->getref(); } if (xl <= 0 || yl <= 0) { @@ -183,9 +180,8 @@ gfxr_view_t *gfxr_draw_view0(int id, byte *resource, int size, int palette) { view->loops_nr = resource[V0_LOOPS_NR_OFFSET]; // Set palette - view->colors_nr = GFX_SCI0_IMAGE_COLORS_NR; - view->flags = GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; - view->colors = gfx_sci0_image_colors[sci0_palette]; + view->flags = 0; + view->palette = gfx_sci0_image_pal[sci0_palette]->getref(); if ((palette_ofs) && (palette >= 0)) { byte *paldata = resource + palette_ofs + (palette * GFX_SCI0_IMAGE_COLORS_NR); diff --git a/engines/sci/gfx/resource/sci_view_1.cpp b/engines/sci/gfx/resource/sci_view_1.cpp index b9f5477bd1..937264d84c 100644 --- a/engines/sci/gfx/resource/sci_view_1.cpp +++ b/engines/sci/gfx/resource/sci_view_1.cpp @@ -244,12 +244,8 @@ gfx_pixmap_t *gfxr_draw_cel1(int id, int loop, int cel, int mirrored, byte *reso retval->xoffset = (mirrored) ? xhot : -xhot; retval->yoffset = -yhot; - if (view) { - retval->colors = view->colors; - retval->colors_nr = view->colors_nr; - } - - retval->flags |= GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; + if (view) + retval->palette = view->palette->getref(); if (xl <= 0 || yl <= 0) { gfx_free_pixmap(NULL, retval); @@ -316,8 +312,7 @@ static int gfxr_draw_loop1(gfxr_loop_t *dest, int id, int loop, int mirrored, by #define V1_MAGICS_NR 5 //static byte view_magics[V1_MAGICS_NR] = {0x80, 0x00, 0x00, 0x00, 0x00}; -gfxr_view_t *gfxr_draw_view1(int id, byte *resource, int size, gfx_pixmap_color_t *static_pal, - int static_pal_nr) { +gfxr_view_t *gfxr_draw_view1(int id, byte *resource, int size, Palette *static_pal) { int i; int palette_offset; gfxr_view_t *view; @@ -358,22 +353,18 @@ gfxr_view_t *gfxr_draw_view1(int id, byte *resource, int size, gfx_pixmap_color_ free(view); return NULL; } - if (!(view->colors = gfxr_read_pal1(id, &(view->colors_nr), - resource + palette_offset, size - palette_offset))) { + if (!(view->palette = gfxr_read_pal1(id, resource + palette_offset, size - palette_offset))) { GFXERROR("view %04x: Palette reading failed. Aborting...\n", id); free(view); return NULL; } - } else if (static_pal_nr == GFX_SCI1_AMIGA_COLORS_NR) { + } else if (static_pal && static_pal->size() == GFX_SCI1_AMIGA_COLORS_NR) { // Assume we're running an amiga game. amiga_game = 1; - view->colors = static_pal; - view->colors_nr = static_pal_nr; - view->flags |= GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; + view->palette = static_pal->getref(); } else { GFXWARN("view %04x: Doesn't have a palette. Can FreeSCI handle this?\n", view->ID); - view->colors = NULL; - view->colors_nr = 0; + view->palette = NULL; } view->loops = (gfxr_loop_t*)sci_malloc(sizeof(gfxr_loop_t) * view->loops_nr); @@ -434,12 +425,8 @@ gfx_pixmap_t *gfxr_draw_cel11(int id, int loop, int cel, int mirrored, byte *res retval->xoffset = (mirrored) ? xdisplace : -xdisplace; retval->yoffset = -ydisplace; - if (view) { - retval->colors = view->colors; - retval->colors_nr = view->colors_nr; - } - - retval->flags |= GFX_PIXMAP_FLAG_EXTERNAL_PALETTE; + if (view) + retval->palette = view->palette->getref(); if (xl <= 0 || yl <= 0) { gfx_free_pixmap(NULL, retval); @@ -494,7 +481,7 @@ gfxr_view_t *gfxr_draw_view11(int id, byte *resource, int size) { view->loops = (gfxr_loop_t *)calloc(view->loops_nr, sizeof(gfxr_loop_t)); // There is no indication of size here, but this is certainly large enough - view->colors = gfxr_read_pal11(id, &view->colors_nr, resource + palette_offset, 1284); + view->palette = gfxr_read_pal11(id, resource + palette_offset, 1284); seeker = resource + header_size; for (i = 0; i < view->loops_nr; i++) { |