diff options
-rw-r--r-- | engines/sci/gfx/gfx_driver.cpp | 10 | ||||
-rw-r--r-- | engines/sci/gfx/gfx_pixmap_scale.cpp | 2 | ||||
-rw-r--r-- | engines/sci/gfx/operations.cpp | 24 | ||||
-rw-r--r-- | engines/sci/gfx/palette.cpp | 52 | ||||
-rw-r--r-- | engines/sci/gfx/palette.h | 32 |
5 files changed, 67 insertions, 53 deletions
diff --git a/engines/sci/gfx/gfx_driver.cpp b/engines/sci/gfx/gfx_driver.cpp index e4d8f8b8cb..dd98843e0f 100644 --- a/engines/sci/gfx/gfx_driver.cpp +++ b/engines/sci/gfx/gfx_driver.cpp @@ -86,9 +86,9 @@ static void drawProc(int x, int y, int c, void *data) { memcpy(p + (y * 320* drv->getMode()->scaleFactor + x), &col, 1); } -void GfxDriver::drawLine(Common::Point start, Common::Point end, gfx_color_t color, +void GfxDriver::drawLine(Common::Point start, Common::Point end, gfx_color_t color, gfx_line_mode_t line_mode, gfx_line_style_t line_style) { - uint32 scolor = color.visual.parent_index; + uint32 scolor = color.visual.getParentIndex(); int scaleFactor = (line_mode == GFX_LINE_MODE_FINE)? 1: _mode->scaleFactor; int xsize = _mode->xsize; int ysize = _mode->ysize; @@ -119,7 +119,7 @@ void GfxDriver::drawFilledRect(rect_t rect, gfx_color_t color1, gfx_color_t colo if (color1.mask & GFX_MASK_VISUAL) { for (int i = rect.y; i < rect.y + rect.height; i++) { memset(_visual[0] + (i * _mode->xsize + rect.x), - color1.visual.parent_index, rect.width); + color1.visual.getParentIndex(), rect.width); } } @@ -228,7 +228,7 @@ void GfxDriver::setPointer(gfx_pixmap_t *pointer, Common::Point *hotspot) { // FIXME: The palette size check is a workaround for cursors using non-palette colour GFX_CURSOR_TRANSPARENT // Note that some cursors don't have a palette in SQ5 if (pointer->palette && color < pointer->palette->size()) - color = pointer->palette->getColor(color).parent_index; + color = pointer->palette->getColor(color).getParentIndex(); memset(&linebase[xc], color, _mode->scaleFactor); } @@ -241,7 +241,7 @@ void GfxDriver::setPointer(gfx_pixmap_t *pointer, Common::Point *hotspot) { // Note that some cursors don't have a palette (e.g. in SQ5 and QFG3) byte color_key = pointer->color_key; if ((pointer->color_key != GFX_PIXMAP_COLOR_KEY_NONE) && (pointer->palette && (uint)pointer->color_key < pointer->palette->size())) - color_key = pointer->palette->getColor(pointer->color_key).parent_index; + color_key = pointer->palette->getColor(pointer->color_key).getParentIndex(); CursorMan.replaceCursor(cursorData, pointer->width, pointer->height, hotspot->x, hotspot->y, color_key); CursorMan.showMouse(true); diff --git a/engines/sci/gfx/gfx_pixmap_scale.cpp b/engines/sci/gfx/gfx_pixmap_scale.cpp index 65a44c524f..5681bdac1c 100644 --- a/engines/sci/gfx/gfx_pixmap_scale.cpp +++ b/engines/sci/gfx/gfx_pixmap_scale.cpp @@ -58,7 +58,7 @@ static void _gfx_xlate_pixmap_unfiltered(gfx_mode_t *mode, gfx_pixmap_t *pxm, in // Calculate all colors for (i = 0; i < pxm->colors_nr(); i++) - result_colors[i] = pxm->palette->getColor(i).parent_index; + result_colors[i] = pxm->palette->getColor(i).getParentIndex(); if (!separate_alpha_map && pxm->color_key != GFX_PIXMAP_COLOR_KEY_NONE) result_colors[pxm->color_key] = 0; diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp index 1f6812d633..1787643ae7 100644 --- a/engines/sci/gfx/operations.cpp +++ b/engines/sci/gfx/operations.cpp @@ -405,7 +405,7 @@ void gfxop_init(GfxState *state, state->driver = new GfxDriver(xfact, yfact, mode); state->gfxResMan = new GfxResManager(state->options, state->driver, resMan); - + gfxop_set_clip_zone(state, gfx_rect(0, 0, 320, 200)); state->pointerZone = Common::Rect(0, 0, 320, 200); @@ -536,7 +536,7 @@ void gfxop_set_color(GfxState *state, gfx_color_t *color, int r, int g, int b, i color->alpha = a; if (PALETTE_MODE) { - color->visual.parent_index = state->driver->getMode()->palette->findNearbyColor(r,g,b,true); + color->visual._parentIndex = PALETTE_MODE->findNearbyColor(r,g,b,true); } } } @@ -556,11 +556,11 @@ void gfxop_set_system_color(GfxState *state, unsigned int index, gfx_color_t *co if (!PALETTE_MODE) return; - if (index >= state->driver->getMode()->palette->size()) { - error("Attempt to set invalid color index %02x as system color", color->visual.parent_index); + if (index >= PALETTE_MODE->size()) { + error("Attempt to set invalid color index %02x as system color", color->visual.getParentIndex()); } - state->driver->getMode()->palette->makeSystemColor(index, color->visual); + PALETTE_MODE->makeSystemColor(index, color->visual); } void gfxop_free_color(GfxState *state, gfx_color_t *color) { @@ -776,7 +776,7 @@ void gfxop_draw_line(GfxState *state, Common::Point start, Common::Point end, end.y += yfact >> 1; } - if (color.visual.parent_index == -1) + if (color.visual.getParentIndex() == -1) gfxop_set_color(state, &color, color); _gfxop_draw_line_clipped(state, start, end, color, line_mode, line_style); } @@ -894,7 +894,7 @@ void gfxop_draw_box(GfxState *state, rect_t box, gfx_color_t color1, gfx_color_t if (shade_type == GFX_BOX_SHADE_FLAT) { color1.priority = 0; color1.control = 0; - if (color1.visual.parent_index == -1) + if (color1.visual.getParentIndex() == -1) gfxop_set_color(state, &color1, color1); drv->drawFilledRect(new_box, color1, color1, GFX_SHADE_FLAT); return; @@ -1052,9 +1052,9 @@ static void _gfxop_set_pointer(GfxState *state, gfx_pixmap_t *pxm, Common::Point // may change when a new PIC is loaded. The cursor has to be regenerated // from this pxm at that point. (An alternative might be to ensure the // cursor only uses colours in the static part of the palette?) - if (pxm && state->driver->getMode()->palette) { + if (pxm && PALETTE_MODE) { assert(pxm->palette); - pxm->palette->mergeInto(state->driver->getMode()->palette); + pxm->palette->mergeInto(PALETTE_MODE); } state->driver->setPointer(pxm, hotspot); } @@ -1306,7 +1306,7 @@ static sci_event_t scummvm_get_event(GfxDriver *drv) { input.character = ev.kbd.ascii; // Debug console - if (ev.kbd.flags == Common::KBD_CTRL && ev.kbd.keycode == Common::KEYCODE_d) { + if (ev.kbd.flags == Common::KBD_CTRL && ev.kbd.keycode == Common::KEYCODE_d) { // Open debug console Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger(); con->attach(); @@ -1625,8 +1625,8 @@ static void _gfxop_set_pic(GfxState *state) { // FIXME: The _gfxop_install_pixmap call below updates the OSystem palette. // This is too soon, since it causes brief palette corruption until the // screen is updated too. (Possibly related: EngineState::pic_not_valid .) - if (state->pic->visual_map->palette && state->driver->getMode()->palette) { - state->pic->visual_map->palette->forceInto(state->driver->getMode()->palette); + if (state->pic->visual_map->palette && PALETTE_MODE) { + state->pic->visual_map->palette->forceInto(PALETTE_MODE); _gfxop_install_pixmap(state->driver, state->pic->visual_map); } diff --git a/engines/sci/gfx/palette.cpp b/engines/sci/gfx/palette.cpp index a3dc84325c..eb3382c5de 100644 --- a/engines/sci/gfx/palette.cpp +++ b/engines/sci/gfx/palette.cpp @@ -52,7 +52,7 @@ Palette::Palette(const PaletteEntry *colors, uint s) { _colors[i].g = colors[i].g; _colors[i].b = colors[i].b; _colors[i].refcount = 0; - _colors[i].parent_index = -1; + _colors[i]._parentIndex = -1; } } @@ -108,22 +108,22 @@ void Palette::unmerge() { int count = 0; for (uint i = 0; i < _size; ++i) { - if (_colors[i].refcount == PALENTRY_FREE) { - assert(_colors[i].parent_index == 0); + if (_colors[i].refcount == PaletteEntry::FREE) { + assert(_colors[i]._parentIndex == 0); } - int pi = _colors[i].parent_index; + int pi = _colors[i]._parentIndex; assert(pi >= 0); assert(pi < (int)_parent->_size); assert(_parent->_colors[pi].refcount != 0); - assert(_parent->_colors[pi].refcount != PALENTRY_FREE); - if (_parent->_colors[pi].refcount != PALENTRY_LOCKED) + assert(_parent->_colors[pi].refcount != PaletteEntry::FREE); + if (_parent->_colors[pi].refcount != PaletteEntry::LOCKED) _parent->_colors[pi].refcount--; if (_parent->_colors[pi].refcount == 0) { - _parent->_colors[pi].refcount = PALENTRY_FREE; + _parent->_colors[pi].refcount = PaletteEntry::FREE; count++; } - _colors[i].parent_index = -1; + _colors[i]._parentIndex = -1; } #ifdef DEBUG_MERGE fprintf(stderr, "Unmerge free %d colors\n", count); @@ -142,12 +142,12 @@ void Palette::setColor(uint index, byte r, byte g, byte b, int parentIndex) { PaletteEntry& entry = _colors[index]; - assert(entry.refcount == PALENTRY_FREE || entry.refcount == 0); + assert(entry.refcount == PaletteEntry::FREE || entry.refcount == 0); entry.refcount = 0; entry.r = r; entry.g = g; entry.b = b; - entry.parent_index = parentIndex; + entry._parentIndex = parentIndex; _dirty = true; } @@ -158,7 +158,7 @@ void Palette::makeSystemColor(uint index, const PaletteEntry &color) { entry.r = color.r; entry.g = color.g; entry.b = color.b; - entry.refcount = PALENTRY_LOCKED; + entry.refcount = PaletteEntry::LOCKED; } uint Palette::findNearbyColor(byte r, byte g, byte b, bool lock) { @@ -171,7 +171,7 @@ uint Palette::findNearbyColor(byte r, byte g, byte b, bool lock) { for (uint i = 0; i < _size; ++i) { PaletteEntry& entry = _colors[i]; - if (entry.refcount != PALENTRY_FREE) { + if (entry.refcount != PaletteEntry::FREE) { int dr = abs(entry.r - r); int dg = abs(entry.g - g); int db = abs(entry.b - b); @@ -179,7 +179,7 @@ uint Palette::findNearbyColor(byte r, byte g, byte b, bool lock) { if (dr == 0 && dg == 0 && db == 0) { // Exact match //exact = true; - if (lock && entry.refcount != PALENTRY_LOCKED) + if (lock && entry.refcount != PaletteEntry::LOCKED) entry.refcount++; return i; } @@ -205,7 +205,7 @@ uint Palette::findNearbyColor(byte r, byte g, byte b, bool lock) { } //exact = false; - if (lock && _colors[bestcolor].refcount != PALENTRY_LOCKED) { + if (lock && _colors[bestcolor].refcount != PaletteEntry::LOCKED) { #if 0 _colors[bestcolor].r = r; _colors[bestcolor].g = g; @@ -244,10 +244,10 @@ bool Palette::mergeInto(Palette *parent) { for (uint i = 0; i < _size; ++i) { PaletteEntry& entry = _colors[i]; - if (entry.refcount == PALENTRY_FREE) { + if (entry.refcount == PaletteEntry::FREE) { // Force all unused colours to index 0 - entry.parent_index = 0; - if (_parent->_colors[0].refcount != PALENTRY_LOCKED) + entry._parentIndex = 0; + if (_parent->_colors[0].refcount != PaletteEntry::LOCKED) _parent->_colors[0].refcount++; if (_colors[i].r || _colors[i].g || _colors[i].b) warning("Non-black unused colour in pic: index %d, %02X %02X %02X", i, _colors[i].r, _colors[i].g, _colors[i].b); @@ -261,8 +261,8 @@ bool Palette::mergeInto(Palette *parent) { if (pi > used_max) used_max = pi; if (pi < used_min) used_min = pi; #endif - entry.parent_index = pi; - if (_parent->_colors[pi].refcount != PALENTRY_LOCKED) + entry._parentIndex = pi; + if (_parent->_colors[pi].refcount != PaletteEntry::LOCKED) _parent->_colors[pi].refcount++; } #ifdef DEBUG_MERGE @@ -284,18 +284,18 @@ void Palette::forceInto(Palette *parent) { _revision = parent->_revision; for (unsigned int i = 0; i < _size; ++i) { - // FIXME: PALENTRY_LOCKED doesn't work well with forceInto... - if (_colors[i].refcount != PALENTRY_FREE) { + // FIXME: PaletteEntry::LOCKED doesn't work well with forceInto... + if (_colors[i].refcount != PaletteEntry::FREE) { _parent->_colors[i] = _colors[i]; - _parent->_colors[i].parent_index = -1; - _colors[i].parent_index = i; - if (_parent->_colors[i].refcount != PALENTRY_LOCKED) + _parent->_colors[i]._parentIndex = -1; + _colors[i]._parentIndex = i; + if (_parent->_colors[i].refcount != PaletteEntry::LOCKED) _parent->_colors[i].refcount = 1; } else { _parent->_colors[i].refcount = 0; // Force all unused colours to index 0 - _colors[i].parent_index = 0; - if (_parent->_colors[0].refcount != PALENTRY_LOCKED) { + _colors[i]._parentIndex = 0; + if (_parent->_colors[0].refcount != PaletteEntry::LOCKED) { if (i == 0) _parent->_colors[0].refcount = 1; else diff --git a/engines/sci/gfx/palette.h b/engines/sci/gfx/palette.h index 63de4bd7ab..a9a16a8ef9 100644 --- a/engines/sci/gfx/palette.h +++ b/engines/sci/gfx/palette.h @@ -31,15 +31,21 @@ namespace Sci { -const int PALENTRY_LOCKED = -42; -const int PALENTRY_FREE = -41; +class PaletteEntry { -struct PaletteEntry { + friend class Palette; + + enum { + LOCKED = -42, + FREE = -41 + }; + +public: PaletteEntry() - : r(0), g(0), b(0), parent_index(-1), refcount(PALENTRY_FREE) + : r(0), g(0), b(0), _parentIndex(-1), refcount(FREE) { } PaletteEntry(byte R, byte G, byte B) - : r(R), g(G), b(B), parent_index(-1), refcount(PALENTRY_FREE) + : r(R), g(G), b(B), _parentIndex(-1), refcount(LOCKED) { } /** @name Color data */ @@ -47,9 +53,12 @@ struct PaletteEntry { byte r, g, b; /** @} */ + inline int getParentIndex() const { return _parentIndex; } + /** Index in parent palette, or -1 */ - int parent_index; + int _parentIndex; +protected: /** * Number of references from child palettes. (This includes palettes * of pixmaps.) @@ -99,9 +108,14 @@ private: Palette *_parent; - bool _dirty; /**< Palette has changed */ - int _refcount; /**< Number of pixmaps (or other objects) using this palette */ - int _revision; /**< When this is incremented, all child references are invalidated */ + /** Palette has changed */ + bool _dirty; + + /** Number of pixmaps (or other objects) using this palette */ + int _refcount; + + /** When this is incremented, all child references are invalidated */ + int _revision; }; |