diff options
author | Paul Gilbert | 2012-11-30 23:15:47 +1100 |
---|---|---|
committer | Paul Gilbert | 2012-11-30 23:15:47 +1100 |
commit | b230dff1e9631cd61775685a9676ec5ab04ff19e (patch) | |
tree | b0f1337932263d3a5cc0f2a01261de00bbcf481c /engines | |
parent | b0ce324685882c5e302958f64ad15dc04c0b9eae (diff) | |
download | scummvm-rg350-b230dff1e9631cd61775685a9676ec5ab04ff19e.tar.gz scummvm-rg350-b230dff1e9631cd61775685a9676ec5ab04ff19e.tar.bz2 scummvm-rg350-b230dff1e9631cd61775685a9676ec5ab04ff19e.zip |
HOPKINS: Fix savegame thumbnails
Diffstat (limited to 'engines')
-rw-r--r-- | engines/hopkins/dialogs.cpp | 7 | ||||
-rw-r--r-- | engines/hopkins/saveload.cpp | 67 | ||||
-rw-r--r-- | engines/hopkins/saveload.h | 5 |
3 files changed, 74 insertions, 5 deletions
diff --git a/engines/hopkins/dialogs.cpp b/engines/hopkins/dialogs.cpp index 645f06dc65..436e4f694a 100644 --- a/engines/hopkins/dialogs.cpp +++ b/engines/hopkins/dialogs.cpp @@ -653,7 +653,10 @@ void DialogsManager::LOAD_SAUVE(int a1) { for (slotNumber = 1; slotNumber <= 6; ++slotNumber) { if (_vm->_saveLoadManager.readSavegameHeader(slotNumber, header)) { - thumb = (byte *)header.thumbnail->pixels; + Graphics::Surface thumb8; + _vm->_saveLoadManager.convertThumb16To8(header.thumbnail, &thumb8); + + thumb = (byte *)thumb8.pixels; switch (slotNumber) { case 1: @@ -676,6 +679,8 @@ void DialogsManager::LOAD_SAUVE(int a1) { break; } + thumb8.free(); + header.thumbnail->free(); delete header.thumbnail; } } diff --git a/engines/hopkins/saveload.cpp b/engines/hopkins/saveload.cpp index 47fc140290..0abd519a81 100644 --- a/engines/hopkins/saveload.cpp +++ b/engines/hopkins/saveload.cpp @@ -225,12 +225,30 @@ void SaveLoadManager::createThumbnail(Graphics::Surface *s) { int w = _vm->_graphicsManager.Reel_Reduc(SCREEN_WIDTH, REDUCE_AMOUNT); int h = _vm->_graphicsManager.Reel_Reduc(SCREEN_HEIGHT - 40, REDUCE_AMOUNT); - s->create(w, h, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)); + Graphics::Surface thumb8; + thumb8.create(w, h, Graphics::PixelFormat::createFormatCLUT8()); - _vm->_graphicsManager.Reduc_Ecran(_vm->_graphicsManager.VESA_BUFFER, (byte *)s->pixels, + _vm->_graphicsManager.Reduc_Ecran(_vm->_graphicsManager.VESA_BUFFER, (byte *)thumb8.pixels, _vm->_eventsManager.start_x, 20, SCREEN_WIDTH, SCREEN_HEIGHT - 40, 80); - _vm->_graphicsManager.INIT_TABLE(45, 80, _vm->_graphicsManager.Palette); -// _vm->_graphicsManager.Trans_bloc2((byte *)s->pixels, _vm->_graphicsManager.TABLE_COUL, 11136); + + // Convert the 8-bit pixel to 16 bit surface + s->create(w, h, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)); + + const byte *srcP = (const byte *)thumb8.pixels; + uint16 *destP = (uint16 *)s->pixels; + + for (int yp = 0; yp < h; ++yp) { + // Copy over the line, using the source pixels as lookups into the pixels palette + const byte *lineSrcP = srcP; + uint16 *lineDestP = destP; + + for (int xp = 0; xp < w; ++xp) + *lineDestP++ = *(uint16 *)&_vm->_graphicsManager.PAL_PIXELS[*lineSrcP++ * 2]; + + // Move to the start of the next line + srcP += w; + destP += w; + } } void SaveLoadManager::syncSavegameData(Common::Serializer &s) { @@ -251,4 +269,45 @@ void SaveLoadManager::syncCharacterLocation(Common::Serializer &s, CharacterLoca s.syncAsSint16LE(item.field4); } +void SaveLoadManager::convertThumb16To8(Graphics::Surface *thumb16, Graphics::Surface *thumb8) { + thumb8->create(thumb16->w, thumb16->h, Graphics::PixelFormat::createFormatCLUT8()); + Graphics::PixelFormat pixelFormat16(2, 5, 6, 5, 0, 11, 5, 0, 0); + + uint16 palette[PALETTE_SIZE]; + for (int palIndex = 0; palIndex < PALETTE_SIZE; ++palIndex) + palette[palIndex] = READ_LE_UINT16(&_vm->_graphicsManager.PAL_PIXELS[palIndex * 2]); + + const uint16 *srcP = (const uint16 *)thumb16->pixels; + byte *destP = (byte *)thumb8->pixels; + + for (int yp = 0; yp < thumb16->h; ++yp) { + const uint16 *lineSrcP = srcP; + byte *lineDestP = destP; + + for (int xp = 0; xp < thumb16->w; ++xp) { + byte r, g, b; + pixelFormat16.colorToRGB(*lineSrcP++, r, g, b); + + // Scan the palette for the closest match + int difference = 99999, foundIndex = 0; + for (int palIndex = 0; palIndex < PALETTE_SIZE; ++palIndex) { + byte rCurrent, gCurrent, bCurrent; + pixelFormat16.colorToRGB(palette[palIndex], rCurrent, gCurrent, bCurrent); + + int diff = ABS((int)r - (int)rCurrent) + ABS((int)g - (int)gCurrent) + ABS((int)b - (int)bCurrent); + if (diff < difference) { + difference = diff; + foundIndex = palIndex; + } + } + + *lineDestP++ = foundIndex; + } + + // Move to the start of the next line + srcP += thumb16->w; + destP += thumb16->w; + } +} + } // End of namespace Hopkins diff --git a/engines/hopkins/saveload.h b/engines/hopkins/saveload.h index f4f94995a9..aa59fe7ba4 100644 --- a/engines/hopkins/saveload.h +++ b/engines/hopkins/saveload.h @@ -64,6 +64,11 @@ public: static bool readSavegameHeader(int slot, hopkinsSavegameHeader &header); Common::Error save(int slot, const Common::String &saveName); Common::Error restore(int slot); + + /** + * Converts a 16-bit thumbnail to 8 bit paletted using the currently active palette. + */ + void convertThumb16To8(Graphics::Surface *thumb16, Graphics::Surface *thumb8); }; } // End of namespace Hopkins |