Ticket #8405: thumbnail-v3-2.patch
File thumbnail-v3-2.patch, 24.2 KB (added by , 20 years ago) |
---|
-
backends/sdl/graphics.cpp
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/backends/sdl/graphics.cpp ./scummvm/backends/sdl/graphics.cpp
old new 720 720 } 721 721 } 722 722 723 void OSystem_SDL::grabScreen(byte* buf) { 724 assert(buf); assert(_screen); 725 Common::StackLock lock(_graphicsMutex); 726 727 memcpy(buf, _screen->pixels, sizeof(byte) * _screenWidth * _screenHeight); 728 } 729 723 730 void OSystem_SDL::clearScreen() { 724 731 assert (_transactionMode == kTransactionNone); 725 732 -
backends/sdl/sdl-common.h
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/backends/sdl/sdl-common.h ./scummvm/backends/sdl/sdl-common.h
old new 67 67 // The screen will not be updated to reflect the new bitmap 68 68 void copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h); 69 69 70 // Copies the screen to a buffer 71 void grabScreen(byte *buf); 72 70 73 // Clear the screen 71 74 void clearScreen(); 72 75 -
common/module.mk
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/common/module.mk ./scummvm/common/module.mk
old new 21 21 common/scaler/hq3x.o \ 22 22 common/scaler/scale2x.o \ 23 23 common/scaler/scale3x.o \ 24 common/scaler/scalebit.o 24 common/scaler/scalebit.o \ 25 common/scaler/thumbnail.o 25 26 26 27 ifdef HAVE_NASM 27 28 MODULE_OBJS += \ -
common/scaler/thumbnail.cpp
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/common/scaler/thumbnail.cpp ./scummvm/common/scaler/thumbnail.cpp
old new 1 /* ScummVM - Scumm Interpreter 2 * Copyright (C) 2001 Ludvig Strigeus 3 * Copyright (C) 2001-2005 The ScummVM project 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Header: $ 20 * 21 */ 22 23 #include "stdafx.h" 24 #include "common/scummsys.h" 25 #include "scaler.h" 26 #include "scaler/intern.h" 27 28 template<int bitFormat> 29 void createThumbnail_2(const uint8* src, uint32 srcPitch, uint8* dstPtr, uint32 dstPitch, int width, int height) { 30 for (int y = 0; y < height; y += 2) { 31 for (int x = 0; x < width; x += 2, dstPtr += 2) { 32 uint16 colorx1y1 = *(((const uint16*)src) + x); 33 uint16 colorx2y1 = *(((const uint16*)src) + x + 1); 34 35 uint16 colorx1y2 = *(((const uint16*)(src + srcPitch)) + x); 36 uint16 colorx2y2 = *(((const uint16*)(src + srcPitch)) + x + 1); 37 38 *((uint16*)dstPtr) = Q_INTERPOLATE<bitFormat>(colorx1y1, colorx2y1, colorx1y2, colorx2y2); 39 } 40 dstPtr += (dstPitch - 320); 41 src += 2 * srcPitch; 42 } 43 } 44 45 template<int bitFormat> 46 void createThumbnail_4(const uint8* src, uint32 srcPitch, uint8* dstPtr, uint32 dstPitch, int width, int height) { 47 for (int y = 0; y < height; y += 4) { 48 for (int x = 0; x < width; x += 4, dstPtr += 2) { 49 uint16 colorx1y1 = *(((const uint16*)src) + x); 50 uint16 colorx2y1 = *(((const uint16*)src) + x + 1); 51 uint16 colorx3y1 = *(((const uint16*)src) + x + 2); 52 uint16 colorx4y1 = *(((const uint16*)src) + x + 3); 53 54 uint16 colorx1y2 = *(((const uint16*)(src + srcPitch)) + x); 55 uint16 colorx2y2 = *(((const uint16*)(src + srcPitch)) + x + 1); 56 uint16 colorx3y2 = *(((const uint16*)(src + srcPitch)) + x + 2); 57 uint16 colorx4y2 = *(((const uint16*)(src + srcPitch)) + x + 3); 58 59 uint16 colorx1y3 = *(((const uint16*)(src + srcPitch * 2)) + x); 60 uint16 colorx2y3 = *(((const uint16*)(src + srcPitch * 2)) + x + 1); 61 uint16 colorx3y3 = *(((const uint16*)(src + srcPitch * 2)) + x + 2); 62 uint16 colorx4y3 = *(((const uint16*)(src + srcPitch * 2)) + x + 3); 63 64 uint16 colorx1y4 = *(((const uint16*)(src + srcPitch * 3)) + x); 65 uint16 colorx2y4 = *(((const uint16*)(src + srcPitch * 3)) + x + 1); 66 uint16 colorx3y4 = *(((const uint16*)(src + srcPitch * 3)) + x + 2); 67 uint16 colorx4y4 = *(((const uint16*)(src + srcPitch * 3)) + x + 3); 68 69 uint16 upleft = Q_INTERPOLATE<bitFormat>(colorx1y1, colorx2y1, colorx1y2, colorx2y2); 70 uint16 upright = Q_INTERPOLATE<bitFormat>(colorx3y1, colorx4y1, colorx3y2, colorx4y2); 71 uint16 downleft = Q_INTERPOLATE<bitFormat>(colorx1y3, colorx2y3, colorx1y4, colorx2y4); 72 uint16 downright = Q_INTERPOLATE<bitFormat>(colorx3y3, colorx4y3, colorx3y4, colorx4y4); 73 74 *((uint16*)dstPtr) = Q_INTERPOLATE<bitFormat>(upleft, upright, downleft, downright); 75 } 76 dstPtr += (dstPitch - 320); 77 src += 4 * srcPitch; 78 } 79 } 80 81 void createThumbnail(const uint8* src, uint32 srcPitch, uint8* dstPtr, uint32 dstPitch, int width, int height) { 82 // only 1/2 and 1/4 downscale supported 83 if(width != 320 && width != 640) 84 return; 85 86 const int downScaleMode = (width == 320) ? 2 : 4; 87 88 if(downScaleMode == 2) { 89 createThumbnail_2<565>(src, srcPitch, dstPtr, dstPitch, width, height); 90 } else if(downScaleMode == 4) { 91 createThumbnail_4<565>(src, srcPitch, dstPtr, dstPitch, width, height); 92 } 93 } -
common/scaler.h
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/common/scaler.h ./scummvm/common/scaler.h
old new 59 59 60 60 extern int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY); 61 61 62 // creates a 160x100 thumbnail for 320x200 games 63 // and 160x120 thumbnail for 320x240 and 640x480 games 64 // only 565 mode 65 enum { 66 kThumbnailWidth = 160, 67 kThumbnailHeight_1 = 100, 68 kThumbnailHeight_2 = 120 69 }; 70 extern void createThumbnail(const uint8* src, uint32 srcPitch, uint8* dstPtr, uint32 dstPitch, int width, int height); 71 62 72 enum { 63 73 GFX_NORMAL = 0, 64 74 GFX_DOUBLESIZE = 1, -
common/system.h
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/common/system.h ./scummvm/common/system.h
old new 290 290 * @see updateScreen 291 291 */ 292 292 virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) = 0; 293 294 /** 295 * Copies the screen to a buffer 296 */ 297 virtual void grabScreen(byte *buf) {} 293 298 294 299 /** 295 300 * Clear the screen to black. -
gui/newgui.cpp
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/gui/newgui.cpp ./scummvm/gui/newgui.cpp
old new 21 21 #include "stdafx.h" 22 22 #include "common/system.h" 23 23 #include "common/util.h" 24 #include "common/scaler.h" 24 25 #include "gui/newgui.h" 25 26 #include "gui/dialog.h" 26 27 … … 405 406 } 406 407 407 408 // 409 // Copies a Surface to the Overlay 410 // 411 void NewGui::drawSurface(const OverlayColor* data, int x, int y, int width, int height, int pitch) { 412 if(_scaleFactor == 1) { 413 uint8* dst = (uint8*)getBasePtr(x, y); 414 for (int y_ = 0; y_ < height; ++y_, dst += _screen.pitch) { 415 memcpy(dst, &((const uint8*)data)[y_ * pitch], width * sizeof(OverlayColor)); 416 } 417 } else if(_scaleFactor == 2) { 418 Normal2x((const uint8*)data, pitch, (uint8*)getBasePtr(x * 2, y * 2), _screen.pitch, width, height); 419 } 420 addDirtyRect(x, y, width, height); 421 } 422 423 // 408 424 // Draw the mouse cursor (animated). This is mostly ripped from the cursor code in gfx.cpp 409 425 // We could plug in a different cursor here if we like to. 410 426 // -
gui/newgui.h
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/gui/newgui.h ./scummvm/gui/newgui.h
old new 146 146 int getFontHeight() const; 147 147 148 148 void drawBitmap(uint32 *bitmap, int x, int y, OverlayColor color, int h = 8); 149 void drawSurface(const OverlayColor* data, int x, int y, int width, int height, int pitch); 149 150 150 151 void addDirtyRect(int x, int y, int w, int h); 151 152 }; -
gui/widget.cpp
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/gui/widget.cpp ./scummvm/gui/widget.cpp
old new 24 24 #include "gui/dialog.h" 25 25 #include "gui/newgui.h" 26 26 27 28 27 namespace GUI { 29 28 30 29 Widget::Widget(GuiObject *boss, int x, int y, int w, int h) … … 260 259 return (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - 4) + _valueMin; 261 260 } 262 261 262 #pragma mark - 263 264 GraphicsWidget::GraphicsWidget(GuiObject *boss, int x, int y, int w, int h) 265 : Widget(boss, x, y, w, h), _gfx(0), _gfxWidth(0), _gfxHeight(0), _bpp(0) { 266 _flags = WIDGET_ENABLED | WIDGET_CLEARBG; 267 _type = kGraphicsWidget; 268 } 269 270 GraphicsWidget::~GraphicsWidget() { 271 delete [] _gfx; 272 } 273 274 void GraphicsWidget::setGfx(int width, int height, int bpp, const uint8 *data) { 275 delete [] _gfx; 276 _gfx = 0; 277 278 if(!data) 279 return; 280 281 _gfx = new uint8[width * height * bpp]; 282 assert(_gfx); 283 284 _gfxWidth = width; 285 _gfxHeight = height; 286 _bpp = bpp; 287 288 memcpy(_gfx, data, width * height * bpp); 289 } 290 291 void GraphicsWidget::drawWidget(bool hilite) { 292 if(sizeof(OverlayColor) != _bpp || !_gfx) { 293 g_gui.drawString("No preview", _x, _y + _h / 2 - g_gui.getFontHeight() / 2, _w, g_gui._textcolor, Graphics::kTextAlignCenter); 294 return; 295 } 296 297 uint drawWidth = _gfxWidth, drawHeight = _gfxHeight; 298 299 if(_w < _gfxWidth) 300 drawWidth = _w; 301 if(_h < _gfxHeight) 302 drawHeight = _h; 303 304 g_gui.drawSurface((OverlayColor*)_gfx, _x, _y, drawWidth, drawHeight, _gfxWidth * _bpp); 305 } 306 263 307 } // End of namespace GUI -
gui/widget.h
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/gui/widget.h ./scummvm/gui/widget.h
old new 52 52 kListWidget = 'LIST', 53 53 kScrollBarWidget = 'SCRB', 54 54 kPopUpWidget = 'POPU', 55 kTabWidget = 'TABW' 55 kTabWidget = 'TABW', 56 kGraphicsWidget = 'GFXW' 56 57 }; 57 58 58 59 enum { … … 210 211 int posToValue(int pos); 211 212 }; 212 213 214 /* GraphicsWidget */ 215 class GraphicsWidget : public Widget { 216 public: 217 GraphicsWidget(GuiObject *boss, int x, int y, int w, int h); 218 ~GraphicsWidget(); 219 220 // bpp = _byte_ per pixel 221 void setGfx(int width, int height, int bpp, const uint8 *data); 222 protected: 223 void drawWidget(bool hilite); 224 225 uint8 *_gfx; 226 int _gfxWidth, _gfxHeight, _bpp; 227 }; 228 213 229 } // End of namespace GUI 214 230 215 231 #endif -
scumm/dialogs.cpp
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/dialogs.cpp ./scummvm/scumm/dialogs.cpp
old new 22 22 23 23 #include "common/config-manager.h" 24 24 #include "common/system.h" 25 #include "common/scaler.h" 25 26 26 27 #include "gui/chooser.h" 27 28 #include "gui/newgui.h" … … 147 148 148 149 #pragma mark - 149 150 150 151 151 const Common::String ScummDialog::queryResString(int stringno) { 152 152 byte buf[256]; 153 153 byte *result; … … 199 199 kQuitCmd = 'QUIT' 200 200 }; 201 201 202 class SaveLoadChooser : public GUI::ChooserDialog {202 class SaveLoadChooser : public GUI::ChooserDialog, public ScummSaveLoadChooser { 203 203 typedef Common::String String; 204 204 typedef Common::StringList StringList; 205 205 protected: … … 210 210 211 211 virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); 212 212 const String &getResultString() const; 213 void setList(const StringList& list) { GUI::ChooserDialog::setList(list); } 214 int runModal() { return GUI::ChooserDialog::runModal(); } 213 215 }; 214 216 215 217 SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode) … … 250 252 } 251 253 } 252 254 255 #pragma mark - 256 257 enum { 258 kChooseCmd = 'Chos' 259 }; 260 261 // only for use with >= 640x400 resolutions 262 class SaveLoadChooserEx : public GUI::Dialog, public ScummSaveLoadChooser { 263 typedef Common::String String; 264 typedef Common::StringList StringList; 265 protected: 266 bool _saveMode; 267 GUI::ListWidget *_list; 268 GUI::ButtonWidget *_chooseButton; 269 GUI::GraphicsWidget *_gfxWidget; 270 ScummEngine *_scumm; 271 272 public: 273 SaveLoadChooserEx(const String &title, const String &buttonLabel, bool saveMode, ScummEngine *engine); 274 275 virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); 276 const String &getResultString() const; 277 void setList(const StringList& list); 278 int runModal(); 279 }; 280 281 SaveLoadChooserEx::SaveLoadChooserEx(const String &title, const String &buttonLabel, bool saveMode, ScummEngine *engine) 282 : Dialog(8, 8, engine->_system->getOverlayWidth() - 2 * 8, engine->_system->getOverlayHeight() - 16), _saveMode(saveMode), _list(0), _chooseButton(0), _gfxWidget(0), _scumm(engine) { 283 284 new StaticTextWidget(this, 10, 6, _w - 2 * 10, kLineHeight, title, kTextAlignCenter); 285 286 // Add choice list 287 _list = new GUI::ListWidget(this, 10, 18, _w - 2 * 10 - 180, _h - 14 - 24 - 10); 288 _list->setEditable(saveMode); 289 _list->setNumberingMode(saveMode ? GUI::kListNumberingOne : GUI::kListNumberingZero); 290 291 // Add the thumbnail displayer 292 _gfxWidget = new GUI::GraphicsWidget(this, _w - (kThumbnailWidth + 22), _y + 6, kThumbnailWidth + 8, ((_scumm->_system->getHeight() % 200) ? kThumbnailHeight_2 : kThumbnailHeight_1) + 8); 293 _gfxWidget->setFlags(GUI::WIDGET_BORDER); 294 295 // Buttons 296 addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "Cancel", kCloseCmd, 0); 297 _chooseButton = addButton(_w-(kButtonWidth + 10), _h - 24, buttonLabel, kChooseCmd, 0); 298 _chooseButton->setEnabled(false); 299 } 300 301 const Common::String &SaveLoadChooserEx::getResultString() const { 302 return _list->getSelectedString(); 303 } 304 305 void SaveLoadChooserEx::setList(const StringList& list) { 306 _list->setList(list); 307 } 308 309 int SaveLoadChooserEx::runModal() { 310 g_gui.enableScaling(false); 311 int ret = GUI::Dialog::runModal(); 312 g_gui.enableScaling(true); 313 return ret; 314 } 315 316 void SaveLoadChooserEx::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { 317 int selItem = _list->getSelected(); 318 switch (cmd) { 319 case GUI::kListItemActivatedCmd: 320 case GUI::kListItemDoubleClickedCmd: 321 if (selItem >= 0) { 322 if (_saveMode || !getResultString().isEmpty()) { 323 _list->endEditMode(); 324 setResult(selItem); 325 close(); 326 } 327 } 328 break; 329 case kChooseCmd: 330 _list->endEditMode(); 331 setResult(selItem); 332 close(); 333 break; 334 case GUI::kListSelectionChangedCmd: 335 _scumm->loadThumbnailFromSlot(_saveMode ? selItem + 1 : selItem); 336 _gfxWidget->setGfx(_scumm->getThumbnailWidth(), _scumm->getThumbnailHeight(), 2, (const uint8*)_scumm->getThumbnail()); 337 _gfxWidget->draw(); 338 if (_saveMode) { 339 _list->startEditMode(); 340 } 341 // Disable button if nothing is selected, or (in load mode) if an empty 342 // list item is selected. We allow choosing an empty item in save mode 343 // because we then just assign a default name. 344 _chooseButton->setEnabled(selItem >= 0 && (_saveMode || !getResultString().isEmpty())); 345 _chooseButton->draw(); 346 break; 347 case kCloseCmd: 348 setResult(-1); 349 default: 350 GUI::Dialog::handleCommand(sender, cmd, data); 351 } 352 } 353 354 #pragma mark - 355 253 356 Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) { 254 357 // Get savegame names 255 358 Common::StringList l; … … 308 411 #ifndef DISABLE_HELP 309 412 _helpDialog = new HelpDialog(scumm); 310 413 #endif 311 _saveDialog = new SaveLoadChooser("Save game:", "Save", true); 312 _loadDialog = new SaveLoadChooser("Load game:", "Load", false); 414 if(scumm->_system->getOverlayWidth() == 320) { 415 _saveDialog = new SaveLoadChooser("Save game:", "Save", true); 416 _loadDialog = new SaveLoadChooser("Load game:", "Load", false); 417 } else { 418 _saveDialog = new SaveLoadChooserEx("Save game:", "Save", true, scumm); 419 _loadDialog = new SaveLoadChooserEx("Load game:", "Load", false, scumm); 420 } 313 421 } 314 422 315 423 MainMenuDialog::~MainMenuDialog() { -
scumm/dialogs.h
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/dialogs.h ./scummvm/scumm/dialogs.h
old new 54 54 const String queryResString(int stringno); 55 55 }; 56 56 57 class SaveLoadChooser; 57 // to have a base for all different Save/Load Choosers 58 // currently only for SaveLoadChooser (320x200) 59 // and for SaveLoadChooserEx (640x400/640x480) 60 class ScummSaveLoadChooser 61 { 62 public: 63 virtual ~ScummSaveLoadChooser() {}; 64 65 virtual const Common::String &getResultString() const = 0; 66 virtual void setList(const Common::StringList& list) = 0; 67 virtual int runModal() = 0; 68 }; 58 69 59 70 class MainMenuDialog : public ScummDialog { 60 71 public: … … 68 79 #ifndef DISABLE_HELP 69 80 GUI::Dialog *_helpDialog; 70 81 #endif 71 S aveLoadChooser *_saveDialog;72 S aveLoadChooser *_loadDialog;82 ScummSaveLoadChooser *_saveDialog; 83 ScummSaveLoadChooser *_loadDialog; 73 84 74 85 void save(); 75 86 void load(); -
scumm/module.mk
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/module.mk ./scummvm/scumm/module.mk
old new 75 75 scumm/smush/smush_player.o \ 76 76 scumm/smush/saud_channel.o \ 77 77 scumm/smush/smush_mixer.o \ 78 scumm/smush/smush_font.o 78 scumm/smush/smush_font.o \ 79 scumm/thumbnail.o 79 80 80 81 MODULE_DIRS += \ 81 82 scumm \ -
scumm/saveload.cpp
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/saveload.cpp ./scummvm/scumm/saveload.cpp
old new 87 87 Serializer ser(out, true, CURRENT_VER); 88 88 saveOrLoad(&ser, CURRENT_VER); 89 89 delete out; 90 saveThumbnailToSlot(slot); 90 91 debug(1, "State saved as '%s'", filename); 91 92 return true; 92 93 } -
scumm/scumm.cpp
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/scumm.cpp ./scummvm/scumm/scumm.cpp
old new 596 596 _features(gs.features), 597 597 gdi(this), 598 598 res(this), 599 _pauseDialog(0), _mainMenuDialog(0), _versionDialog(0), 599 _pauseDialog(0), _mainMenuDialog(0), _versionDialog(0), _thumbnail(0), _thumbnailWidth(0), _thumbnailHeight(0), 600 600 _targetName(detector->_targetName) { 601 601 602 602 // Copy MD5 checksum -
scumm/scumm.h
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/scumm.h ./scummvm/scumm/scumm.h
old new 562 562 void requestSave(int slot, const char *name, bool temporary = false); 563 563 void requestLoad(int slot); 564 564 565 // thumbnail stuff 566 public: 567 void createThumbnail(); 568 void loadThumbnailFromSlot(int slot); 569 const uint16* getThumbnail() { return _thumbnail; } 570 uint16 getThumbnailHeight() { return _thumbnailHeight; } 571 uint16 getThumbnailWidth() { return _thumbnailWidth; } 572 573 protected: 574 void loadThumbnailFromData(const uint16* data); 575 void saveThumbnailToSlot(int slot); 576 uint16 *_thumbnail; 577 uint16 _thumbnailWidth, _thumbnailHeight; 578 // ends here 579 565 580 protected: 566 581 /* Script VM - should be in Script class */ 567 582 uint32 _localScriptOffsets[256]; -
scumm/thumbnail.cpp
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/thumbnail.cpp ./scummvm/scumm/thumbnail.cpp
old new 1 /* ScummVM - Scumm Interpreter 2 * Copyright (C) 2001 Ludvig Strigeus 3 * Copyright (C) 2001-2005 The ScummVM project 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Header: $ 20 * 21 */ 22 23 #include "common/stdafx.h" 24 #include "common/scummsys.h" 25 #include "common/system.h" 26 #include "common/savefile.h" 27 #include "common/scaler.h" 28 #include "scumm.h" 29 30 namespace Scumm { 31 32 inline uint16 RGBToColor(const uint8 r, const uint8 g, const uint8 b) { 33 return ((((r >> 3) & 0x1F) << 11) | (((g >> 2) & 0x3F) << 5) | ((b >> 3) & 0x1F)); 34 } 35 36 inline void colorToRGB(uint16 color, uint8 &r, uint8 &g, uint8 &b) { 37 r = (((color >> 11) & 0x1F) << 3); 38 g = (((color >> 5) & 0x3F) << 2); 39 b = ((color&0x1F) << 3); 40 } 41 42 void ScummEngine::createThumbnail() { 43 if(sizeof(OverlayColor) != sizeof(uint16)) 44 return; 45 46 byte *temporaryScreen = new byte[_system->getWidth() * _system->getHeight()]; 47 assert(temporaryScreen); 48 49 _system->grabScreen(temporaryScreen); 50 51 uint16 *screen = new uint16[_system->getWidth() * _system->getHeight()]; 52 assert(screen); 53 54 const uint8 *palette = _currentPalette; 55 56 for(int y = 0; y < _system->getHeight(); ++y) { 57 for(int x = 0; x < _system->getWidth(); ++x) { 58 uint8 index = temporaryScreen[y * _system->getWidth() + x]; 59 screen[y * _system->getWidth() + x] = RGBToColor(palette[index * 3], palette[index * 3 + 1], palette[index * 3 + 2]); 60 } 61 } 62 63 delete [] temporaryScreen; 64 temporaryScreen = 0; 65 66 uint16 newHeight = _system->getHeight() == 480 ? kThumbnailHeight_2 : kThumbnailHeight_1; 67 68 if(_thumbnail && _thumbnailHeight != newHeight) 69 delete [] _thumbnail; 70 71 _thumbnailWidth = kThumbnailWidth; 72 _thumbnailHeight = newHeight; 73 _thumbnail = new uint16[kThumbnailWidth * newHeight]; 74 ::createThumbnail((const uint8*)screen, _system->getWidth() * 2, (uint8*)_thumbnail, 320, _system->getWidth(), _system->getHeight()); 75 76 delete [] screen; 77 } 78 79 void ScummEngine::loadThumbnailFromData(const uint16* data) { 80 if(sizeof(OverlayColor) != sizeof(uint16) || !_thumbnail) 81 return; 82 83 for (int y = 0; y < _thumbnailHeight; ++y) { 84 for (int x = 0; x < _thumbnailWidth; ++x) { 85 uint8 r, g, b; 86 colorToRGB(data[y * 160 + x], r, g, b); 87 88 // converting to current OSystem Color 89 _thumbnail[y * 160 + x] = _system->RGBToColor(r, g, b); 90 } 91 } 92 } 93 94 void ScummEngine::loadThumbnailFromSlot(int slot) { 95 char filename[128]; 96 makeSavegameName(filename, slot, false); 97 strcat(filename, ".tmb"); 98 99 delete [] _thumbnail; 100 _thumbnail = 0; 101 102 SaveFile *in; 103 if (!(in = _saveFileMan->openSavefile(filename, false))) { 104 delete in; 105 return; 106 } 107 108 _thumbnailWidth = in->readUint16LE(); 109 _thumbnailHeight = in->readUint16LE(); 110 111 _thumbnail = new uint16[_thumbnailWidth*_thumbnailHeight]; 112 113 for (uint16 p = 0; p <_thumbnailWidth*_thumbnailHeight; ++p) 114 _thumbnail[p] = in->readUint16LE(); 115 116 loadThumbnailFromData(_thumbnail); 117 delete in; 118 } 119 120 void ScummEngine::saveThumbnailToSlot(int slot) { 121 char filename[128]; 122 makeSavegameName(filename, slot, false); 123 strcat(filename, ".tmb"); 124 125 SaveFile *out; 126 if (!(out = _saveFileMan->openSavefile(filename, true))) 127 return; 128 129 createThumbnail(); 130 131 out->writeUint16LE(_thumbnailWidth); 132 out->writeUint16LE(_thumbnailHeight); 133 134 for (uint16 p = 0; p < _thumbnailWidth*_thumbnailHeight; ++p) 135 out->writeUint16LE(_thumbnail[p]); 136 137 delete [] _thumbnail; 138 _thumbnail = 0; 139 140 delete out; 141 } 142 } // end of namespace Scumm