2005-05-09 00:09:01 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2001-2006 The ScummVM project
|
2005-05-09 00:09:01 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-05-09 00:09:01 +00:00
|
|
|
*
|
2006-02-11 09:55:41 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-05-09 00:09:01 +00:00
|
|
|
*
|
|
|
|
*/
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-09 00:09:01 +00:00
|
|
|
#include "common/stdafx.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/savefile.h"
|
2006-02-20 20:40:12 +00:00
|
|
|
#include "graphics/scaler.h"
|
2005-06-24 17:08:21 +00:00
|
|
|
#include "scumm/scumm.h"
|
2005-05-09 00:09:01 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2005-05-10 23:17:38 +00:00
|
|
|
Graphics::Surface *ScummEngine::loadThumbnail(Common::InSaveFile *file) {
|
2005-05-09 00:09:01 +00:00
|
|
|
ThumbnailHeader header;
|
2006-02-25 02:47:22 +00:00
|
|
|
|
|
|
|
header.type = file->readUint32BE();
|
2005-05-26 10:07:37 +00:00
|
|
|
// We also accept the bad 'BMHT' header here, for the sake of compatibility
|
|
|
|
// with some older savegames which were written incorrectly due to a bug in
|
|
|
|
// ScummVM which wrote the thumb header type incorrectly on LE systems.
|
2006-02-25 02:47:22 +00:00
|
|
|
if (header.type != MKID_BE('THMB') && header.type != MKID_BE('BMHT'))
|
2005-05-09 00:09:01 +00:00
|
|
|
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();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-09 00:09:01 +00:00
|
|
|
// TODO: support other bpp values than 2
|
|
|
|
if (header.bpp != 2) {
|
|
|
|
file->skip(header.size - 14);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-09 00:09:01 +00:00
|
|
|
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);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-09 00:09:01 +00:00
|
|
|
// converting to current OSystem Color
|
|
|
|
*pixels++ = _system->RGBToColor(r, g, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return thumb;
|
|
|
|
}
|
|
|
|
|
2005-05-10 23:17:38 +00:00
|
|
|
void ScummEngine::saveThumbnail(Common::OutSaveFile *file) {
|
2005-05-09 00:09:01 +00:00
|
|
|
Graphics::Surface thumb;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-10-08 22:04:52 +00:00
|
|
|
#ifndef PALMOS_68K
|
2005-05-09 00:09:01 +00:00
|
|
|
if (!createThumbnailFromScreen(&thumb))
|
2005-10-08 22:04:52 +00:00
|
|
|
#endif
|
2005-05-09 00:09:01 +00:00
|
|
|
thumb.create(kThumbnailWidth, kThumbnailHeight2, sizeof(uint16));
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-09 00:09:01 +00:00
|
|
|
ThumbnailHeader header;
|
2006-02-25 02:47:22 +00:00
|
|
|
header.type = MKID_BE('THMB');
|
2005-11-27 02:35:57 +00:00
|
|
|
#if defined(PALMOS_ARM) || defined(__GP32__)
|
2005-10-08 22:04:52 +00:00
|
|
|
// sizeof(header) is hardcoded here, because the compiler add padding to
|
|
|
|
// have a 4byte aligned struct and there is no easy way to pack it.
|
|
|
|
header.size = 14 + thumb.w*thumb.h*thumb.bytesPerPixel;
|
|
|
|
#else
|
2005-05-09 00:09:01 +00:00
|
|
|
header.size = sizeof(header) + thumb.w*thumb.h*thumb.bytesPerPixel;
|
2005-10-08 22:04:52 +00:00
|
|
|
#endif
|
2005-05-09 00:09:01 +00:00
|
|
|
header.version = THMB_VERSION;
|
|
|
|
header.width = thumb.w;
|
|
|
|
header.height = thumb.h;
|
|
|
|
header.bpp = thumb.bytesPerPixel;
|
|
|
|
|
2006-02-25 02:47:22 +00:00
|
|
|
file->writeUint32BE(header.type);
|
2005-05-09 00:09:01 +00:00
|
|
|
file->writeUint32BE(header.size);
|
|
|
|
file->writeByte(header.version);
|
|
|
|
file->writeUint16BE(header.width);
|
|
|
|
file->writeUint16BE(header.height);
|
|
|
|
file->writeByte(header.bpp);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-09 00:09:01 +00:00
|
|
|
// 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
|