aboutsummaryrefslogtreecommitdiff
path: root/scumm/thumbnail.cpp
diff options
context:
space:
mode:
authorMax Horn2005-05-09 00:09:01 +0000
committerMax Horn2005-05-09 00:09:01 +0000
commitc33cc2ce85dea20cd0eb749a06276d12ff31956c (patch)
tree1526599eb4dd8c0e6a4479b3e19f77a53a6af0ab /scumm/thumbnail.cpp
parent20c8944189941dbf0286afc28b361f7bb4e09e74 (diff)
downloadscummvm-rg350-c33cc2ce85dea20cd0eb749a06276d12ff31956c.tar.gz
scummvm-rg350-c33cc2ce85dea20cd0eb749a06276d12ff31956c.tar.bz2
scummvm-rg350-c33cc2ce85dea20cd0eb749a06276d12ff31956c.zip
Last part of patch #1163026 (Thumbnails for ScummEngine)
svn-id: r17982
Diffstat (limited to 'scumm/thumbnail.cpp')
-rw-r--r--scumm/thumbnail.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/scumm/thumbnail.cpp b/scumm/thumbnail.cpp
new file mode 100644
index 0000000000..dbe21698ed
--- /dev/null
+++ b/scumm/thumbnail.cpp
@@ -0,0 +1,129 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2005 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed file the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
+#include "common/stdafx.h"
+#include "common/scummsys.h"
+#include "common/system.h"
+#include "common/savefile.h"
+#include "common/scaler.h"
+#include "scumm.h"
+
+namespace Scumm {
+
+#define THMB_VERSION 1
+
+#if !defined(__GNUC__)
+ #pragma START_PACK_STRUCTS
+#endif
+
+struct ThumbnailHeader {
+ uint32 type;
+ uint32 size;
+ byte version;
+ uint16 width, height;
+ byte bpp;
+} GCC_PACK;
+
+#if !defined(__GNUC__)
+ #pragma END_PACK_STRUCTS
+#endif
+
+
+inline void colorToRGB(uint16 color, uint8 &r, uint8 &g, uint8 &b) {
+ r = (((color >> 11) & 0x1F) << 3);
+ g = (((color >> 5) & 0x3F) << 2);
+ b = ((color&0x1F) << 3);
+}
+
+Graphics::Surface *ScummEngine::loadThumbnail(InSaveFile *file) {
+ ThumbnailHeader header;
+ header.type = file->readUint32BE();
+ if (header.type != MKID('THMB'))
+ return 0;
+
+ header.size = file->readUint32BE();
+ header.version = file->readByte();
+
+ if (header.version > THMB_VERSION) {
+ file->skip(header.size - 9);
+ warning("Loading a newer thumbnail version");
+ return 0;
+ }
+
+ header.width = file->readUint16BE();
+ header.height = file->readUint16BE();
+ header.bpp = file->readByte();
+
+ // TODO: support other bpp values than 2
+ if (header.bpp != 2) {
+ file->skip(header.size - 14);
+ return 0;
+ }
+
+ Graphics::Surface *thumb = new Graphics::Surface();
+ thumb->create(header.width, header.height, sizeof(uint16));
+
+ uint16* pixels = (uint16 *)thumb->pixels;
+
+ for (int y = 0; y < thumb->h; ++y) {
+ for (int x = 0; x < thumb->w; ++x) {
+ uint8 r, g, b;
+ colorToRGB(file->readUint16BE(), r, g, b);
+
+ // converting to current OSystem Color
+ *pixels++ = _system->RGBToColor(r, g, b);
+ }
+ }
+
+ return thumb;
+}
+
+void ScummEngine::saveThumbnail(OutSaveFile *file) {
+ Graphics::Surface thumb;
+
+ if (!createThumbnailFromScreen(&thumb))
+ thumb.create(kThumbnailWidth, kThumbnailHeight2, sizeof(uint16));
+
+ ThumbnailHeader header;
+ header.type = MKID('THMB');
+ header.size = sizeof(header) + thumb.w*thumb.h*thumb.bytesPerPixel;
+ header.version = THMB_VERSION;
+ header.width = thumb.w;
+ header.height = thumb.h;
+ header.bpp = thumb.bytesPerPixel;
+
+ file->writeUint32BE(header.type);
+ file->writeUint32BE(header.size);
+ file->writeByte(header.version);
+ file->writeUint16BE(header.width);
+ file->writeUint16BE(header.height);
+ file->writeByte(header.bpp);
+
+ // TODO: for later this shouldn't be casted to uint16...
+ uint16* pixels = (uint16 *)thumb.pixels;
+ for (uint16 p = 0; p < thumb.w*thumb.h; ++p, ++pixels)
+ file->writeUint16BE(*pixels);
+
+ thumb.free();
+}
+
+} // end of namespace Scumm