2010-07-31 09:53:02 +00:00
|
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
|
*
|
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
|
*
|
|
|
|
|
* 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 in 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2010-08-06 13:13:25 +00:00
|
|
|
|
/*
|
2010-07-31 09:53:02 +00:00
|
|
|
|
* This code is based on Broken Sword 2.5 engine
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
|
|
|
|
*
|
|
|
|
|
* Licensed under GNU GPL v2
|
|
|
|
|
*
|
|
|
|
|
*/
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-11-19 17:03:07 +00:00
|
|
|
|
#include "common/memstream.h"
|
2011-04-24 11:34:27 +03:00
|
|
|
|
#include "common/textconsole.h"
|
2010-07-30 09:02:39 +00:00
|
|
|
|
#include "sword25/gfx/screenshot.h"
|
2010-09-19 05:00:45 +00:00
|
|
|
|
#include "sword25/kernel/filesystemutil.h"
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-08-05 12:48:19 +00:00
|
|
|
|
namespace Sword25 {
|
|
|
|
|
|
2011-05-13 19:19:58 +03:00
|
|
|
|
#define THUMBNAIL_VERSION 1
|
|
|
|
|
|
2010-10-19 20:54:30 +00:00
|
|
|
|
bool Screenshot::saveToFile(Graphics::Surface *data, Common::WriteStream *stream) {
|
2010-09-19 05:00:45 +00:00
|
|
|
|
// Convert the RGBA data to RGB
|
2010-10-19 20:54:30 +00:00
|
|
|
|
const byte *pSrc = (const byte *)data->getBasePtr(0, 0);
|
2011-05-13 18:49:14 +03:00
|
|
|
|
|
|
|
|
|
// Write our own custom header
|
|
|
|
|
stream->writeUint32BE(MKTAG('S','C','R','N')); // SCRN, short for "Screenshot"
|
|
|
|
|
stream->writeUint16LE(data->w);
|
|
|
|
|
stream->writeUint16LE(data->h);
|
2011-05-13 19:19:58 +03:00
|
|
|
|
stream->writeByte(THUMBNAIL_VERSION);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-10-19 20:54:30 +00:00
|
|
|
|
for (uint y = 0; y < data->h; y++) {
|
|
|
|
|
for (uint x = 0; x < data->w; x++) {
|
2011-05-23 12:12:26 +02:00
|
|
|
|
// This is only called by createThumbnail below, which
|
|
|
|
|
// provides a fake 'surface' with LE data in it.
|
2010-09-19 05:00:45 +00:00
|
|
|
|
uint32 srcPixel = READ_LE_UINT32(pSrc);
|
|
|
|
|
pSrc += sizeof(uint32);
|
2011-05-13 18:49:14 +03:00
|
|
|
|
stream->writeByte((srcPixel >> 16) & 0xff); // R
|
|
|
|
|
stream->writeByte((srcPixel >> 8) & 0xff); // G
|
|
|
|
|
stream->writeByte(srcPixel & 0xff); // B
|
2010-09-19 05:00:45 +00:00
|
|
|
|
}
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-11-19 17:03:07 +00:00
|
|
|
|
Common::SeekableReadStream *Screenshot::createThumbnail(Graphics::Surface *data) {
|
2010-09-19 05:00:45 +00:00
|
|
|
|
// This method takes a screen image with a dimension of 800x600, and creates a screenshot with a dimension of 200x125.
|
2011-06-20 00:59:48 +02:00
|
|
|
|
// First 50 pixels are cut off the top and bottom (the interface boards in the game). The remaining image of 800x500
|
|
|
|
|
// will be on a 16th of its size, reduced by being handed out in 4x4 pixel blocks and the average of each block
|
2010-09-19 05:00:45 +00:00
|
|
|
|
// generates a pixel of the target image. Finally, the result as a PNG file is stored as a file.
|
|
|
|
|
|
|
|
|
|
// The source image must be 800x600.
|
2011-04-17 17:29:37 +02:00
|
|
|
|
if (data->w != 800 || data->h != 600 || data->format.bytesPerPixel != 4) {
|
2011-01-23 14:49:50 +00:00
|
|
|
|
error("The sreenshot dimensions have to be 800x600 in order to be saved as a thumbnail.");
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-09-19 05:00:45 +00:00
|
|
|
|
// Buffer for the output thumbnail
|
|
|
|
|
Graphics::Surface thumbnail;
|
2011-04-17 16:31:49 +02:00
|
|
|
|
thumbnail.create(200, 125, g_system->getScreenFormat());
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// <20>ber das Zielbild iterieren und einen Pixel zur Zeit berechnen.
|
2010-09-02 12:14:04 +00:00
|
|
|
|
uint x, y;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
x = y = 0;
|
2011-06-20 00:59:48 +02:00
|
|
|
|
|
2010-09-19 05:00:45 +00:00
|
|
|
|
for (byte *pDest = (byte *)thumbnail.pixels; pDest < ((byte *)thumbnail.pixels + thumbnail.pitch * thumbnail.h); ) {
|
|
|
|
|
// Get an average over a 4x4 pixel block in the source image
|
|
|
|
|
int alpha, red, green, blue;
|
|
|
|
|
alpha = red = green = blue = 0;
|
|
|
|
|
for (int j = 0; j < 4; ++j) {
|
2010-10-19 20:54:30 +00:00
|
|
|
|
const uint32 *srcP = (const uint32 *)data->getBasePtr(x * 4, y * 4 + j + 50);
|
2010-09-19 05:00:45 +00:00
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
2011-05-23 12:12:26 +02:00
|
|
|
|
uint32 pixel = READ_UINT32(srcP + i);
|
2010-09-19 05:00:45 +00:00
|
|
|
|
alpha += (pixel >> 24);
|
|
|
|
|
red += (pixel >> 16) & 0xff;
|
|
|
|
|
green += (pixel >> 8) & 0xff;
|
|
|
|
|
blue += pixel & 0xff;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-19 05:00:45 +00:00
|
|
|
|
// Write target pixel
|
|
|
|
|
*pDest++ = blue / 16;
|
|
|
|
|
*pDest++ = green / 16;
|
|
|
|
|
*pDest++ = red / 16;
|
|
|
|
|
*pDest++ = alpha / 16;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-19 05:00:45 +00:00
|
|
|
|
// Move to next block
|
2010-07-29 19:53:02 +00:00
|
|
|
|
++x;
|
2010-09-19 05:00:45 +00:00
|
|
|
|
if (x == thumbnail.w) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
x = 0;
|
|
|
|
|
++y;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-19 05:00:45 +00:00
|
|
|
|
// Create a PNG representation of the thumbnail data
|
|
|
|
|
Common::MemoryWriteStreamDynamic *stream = new Common::MemoryWriteStreamDynamic();
|
2010-10-19 20:54:30 +00:00
|
|
|
|
saveToFile(&thumbnail, stream);
|
2010-08-07 20:09:40 +00:00
|
|
|
|
|
2010-09-19 05:00:45 +00:00
|
|
|
|
// Output a MemoryReadStream that encompasses the written data
|
2010-11-19 17:03:07 +00:00
|
|
|
|
Common::SeekableReadStream *result = new Common::MemoryReadStream(stream->getData(), stream->size(),
|
2010-09-19 05:00:45 +00:00
|
|
|
|
DisposeAfterUse::YES);
|
|
|
|
|
return result;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
2010-08-05 12:48:19 +00:00
|
|
|
|
|
|
|
|
|
} // End of namespace Sword25
|