Ticket #8405: thumbnail-v3-2.patch

File thumbnail-v3-2.patch, 24.2 KB (added by lordhoto, 16 years ago)

new standalone patch

  • 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  
    720720        }
    721721}
    722722
     723void 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
    723730void OSystem_SDL::clearScreen() {
    724731        assert (_transactionMode == kTransactionNone);
    725732
  • 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  
    6767        // The screen will not be updated to reflect the new bitmap
    6868        void copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h);
    6969
     70        // Copies the screen to a buffer
     71        void grabScreen(byte *buf);
     72
    7073        // Clear the screen
    7174        void clearScreen();
    7275
  • common/module.mk

    diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/common/module.mk ./scummvm/common/module.mk
    old new  
    2121        common/scaler/hq3x.o \
    2222        common/scaler/scale2x.o \
    2323        common/scaler/scale3x.o \
    24         common/scaler/scalebit.o
     24        common/scaler/scalebit.o \
     25        common/scaler/thumbnail.o
    2526
    2627ifdef HAVE_NASM
    2728MODULE_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
     28template<int bitFormat>
     29void 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
     45template<int bitFormat>
     46void 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
     81void 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  
    5959
    6060extern int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY);
    6161
     62// creates a 160x100 thumbnail for 320x200 games
     63// and 160x120 thumbnail for 320x240 and 640x480 games
     64// only 565 mode
     65enum {
     66        kThumbnailWidth = 160,
     67        kThumbnailHeight_1 = 100,
     68        kThumbnailHeight_2 = 120
     69};
     70extern void createThumbnail(const uint8* src, uint32 srcPitch, uint8* dstPtr, uint32 dstPitch, int width, int height);
     71
    6272enum {
    6373        GFX_NORMAL = 0,
    6474        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  
    290290         * @see updateScreen
    291291         */
    292292        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) {}
    293298       
    294299        /**
    295300         * 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  
    2121#include "stdafx.h"
    2222#include "common/system.h"
    2323#include "common/util.h"
     24#include "common/scaler.h"
    2425#include "gui/newgui.h"
    2526#include "gui/dialog.h"
    2627
     
    405406}
    406407
    407408//
     409// Copies a Surface to the Overlay
     410//
     411void 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//
    408424// Draw the mouse cursor (animated). This is mostly ripped from the cursor code in gfx.cpp
    409425// We could plug in a different cursor here if we like to.
    410426//
  • gui/newgui.h

    diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/gui/newgui.h ./scummvm/gui/newgui.h
    old new  
    146146        int getFontHeight() const;
    147147
    148148        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);
    149150
    150151        void addDirtyRect(int x, int y, int w, int h);
    151152};
  • gui/widget.cpp

    diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/gui/widget.cpp ./scummvm/gui/widget.cpp
    old new  
    2424#include "gui/dialog.h"
    2525#include "gui/newgui.h"
    2626
    27 
    2827namespace GUI {
    2928
    3029Widget::Widget(GuiObject *boss, int x, int y, int w, int h)
     
    260259        return (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - 4) + _valueMin;
    261260}
    262261
     262#pragma mark -
     263
     264GraphicsWidget::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
     270GraphicsWidget::~GraphicsWidget() {
     271        delete [] _gfx;
     272}
     273
     274void 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
     291void 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
    263307} // 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  
    5252        kListWidget                     = 'LIST',
    5353        kScrollBarWidget        = 'SCRB',
    5454        kPopUpWidget            = 'POPU',
    55         kTabWidget                      = 'TABW'
     55        kTabWidget                      = 'TABW',
     56        kGraphicsWidget         = 'GFXW'
    5657};
    5758
    5859enum {
     
    210211        int posToValue(int pos);
    211212};
    212213
     214/* GraphicsWidget */
     215class GraphicsWidget : public Widget {
     216public:
     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);
     222protected:
     223        void drawWidget(bool hilite);
     224       
     225        uint8 *_gfx;
     226        int _gfxWidth, _gfxHeight, _bpp;
     227};
     228
    213229} // End of namespace GUI
    214230
    215231#endif
  • scumm/dialogs.cpp

    diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/dialogs.cpp ./scummvm/scumm/dialogs.cpp
    old new  
    2222
    2323#include "common/config-manager.h"
    2424#include "common/system.h"
     25#include "common/scaler.h"
    2526
    2627#include "gui/chooser.h"
    2728#include "gui/newgui.h"
     
    147148
    148149#pragma mark -
    149150
    150 
    151151const Common::String ScummDialog::queryResString(int stringno) {
    152152        byte buf[256];
    153153        byte *result;
     
    199199        kQuitCmd = 'QUIT'
    200200};
    201201
    202 class SaveLoadChooser : public GUI::ChooserDialog {
     202class SaveLoadChooser : public GUI::ChooserDialog, public ScummSaveLoadChooser {
    203203        typedef Common::String String;
    204204        typedef Common::StringList StringList;
    205205protected:
     
    210210       
    211211        virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
    212212        const String &getResultString() const;
     213        void setList(const StringList& list) { GUI::ChooserDialog::setList(list); }
     214        int runModal() { return GUI::ChooserDialog::runModal(); }
    213215};
    214216
    215217SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode)
     
    250252        }
    251253}
    252254
     255#pragma mark -
     256
     257enum {
     258        kChooseCmd = 'Chos'
     259};
     260
     261// only for use with >= 640x400 resolutions
     262class SaveLoadChooserEx : public GUI::Dialog, public ScummSaveLoadChooser {
     263        typedef Common::String String;
     264        typedef Common::StringList StringList;
     265protected:
     266        bool _saveMode;
     267        GUI::ListWidget         *_list;
     268        GUI::ButtonWidget       *_chooseButton;
     269        GUI::GraphicsWidget     *_gfxWidget;
     270        ScummEngine                     *_scumm;
     271
     272public:
     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
     281SaveLoadChooserEx::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
     301const Common::String &SaveLoadChooserEx::getResultString() const {
     302        return _list->getSelectedString();
     303}
     304
     305void SaveLoadChooserEx::setList(const StringList& list) {
     306        _list->setList(list);
     307}
     308
     309int SaveLoadChooserEx::runModal() {
     310        g_gui.enableScaling(false);
     311        int ret = GUI::Dialog::runModal();
     312        g_gui.enableScaling(true);
     313        return ret;
     314}
     315
     316void 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
    253356Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) {
    254357        // Get savegame names
    255358        Common::StringList l;
     
    308411#ifndef DISABLE_HELP
    309412        _helpDialog = new HelpDialog(scumm);
    310413#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        }
    313421}
    314422
    315423MainMenuDialog::~MainMenuDialog() {
  • scumm/dialogs.h

    diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/dialogs.h ./scummvm/scumm/dialogs.h
    old new  
    5454        const String queryResString(int stringno);
    5555};
    5656
    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)
     60class ScummSaveLoadChooser
     61{
     62public:
     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};
    5869
    5970class MainMenuDialog : public ScummDialog {
    6071public:
     
    6879#ifndef DISABLE_HELP
    6980        GUI::Dialog             *_helpDialog;
    7081#endif
    71         SaveLoadChooser *_saveDialog;
    72         SaveLoadChooser *_loadDialog;
     82        ScummSaveLoadChooser    *_saveDialog;
     83        ScummSaveLoadChooser    *_loadDialog;
    7384
    7485        void save();
    7586        void load();
  • scumm/module.mk

    diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/module.mk ./scummvm/scumm/module.mk
    old new  
    7575        scumm/smush/smush_player.o \
    7676        scumm/smush/saud_channel.o \
    7777        scumm/smush/smush_mixer.o \
    78         scumm/smush/smush_font.o
     78        scumm/smush/smush_font.o \
     79        scumm/thumbnail.o
    7980
    8081MODULE_DIRS += \
    8182        scumm \
  • scumm/saveload.cpp

    diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/saveload.cpp ./scummvm/scumm/saveload.cpp
    old new  
    8787        Serializer ser(out, true, CURRENT_VER);
    8888        saveOrLoad(&ser, CURRENT_VER);
    8989        delete out;
     90        saveThumbnailToSlot(slot);
    9091        debug(1, "State saved as '%s'", filename);
    9192        return true;
    9293}
  • scumm/scumm.cpp

    diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/scumm.cpp ./scummvm/scumm/scumm.cpp
    old new  
    596596          _features(gs.features),
    597597          gdi(this),
    598598          res(this),
    599           _pauseDialog(0), _mainMenuDialog(0), _versionDialog(0),
     599          _pauseDialog(0), _mainMenuDialog(0), _versionDialog(0), _thumbnail(0), _thumbnailWidth(0), _thumbnailHeight(0),
    600600          _targetName(detector->_targetName) {
    601601
    602602        // 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  
    562562        void requestSave(int slot, const char *name, bool temporary = false);
    563563        void requestLoad(int slot);
    564564
     565// thumbnail stuff
     566public:
     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
     573protected:
     574        void loadThumbnailFromData(const uint16* data);
     575        void saveThumbnailToSlot(int slot);
     576        uint16 *_thumbnail;
     577        uint16 _thumbnailWidth, _thumbnailHeight;
     578// ends here
     579
    565580protected:
    566581        /* Script VM - should be in Script class */
    567582        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
     30namespace Scumm {
     31
     32inline 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
     36inline 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
     42void 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
     79void 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
     94void 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
     120void 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