aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/gfx/screenshot.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sword25/gfx/screenshot.cpp')
-rw-r--r--engines/sword25/gfx/screenshot.cpp55
1 files changed, 24 insertions, 31 deletions
diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp
index 941efbdf3c..74174cbcd9 100644
--- a/engines/sword25/gfx/screenshot.cpp
+++ b/engines/sword25/gfx/screenshot.cpp
@@ -34,10 +34,6 @@
#define BS_LOG_PREFIX "SCREENSHOT"
-// -----------------------------------------------------------------------------
-// Includes
-// -----------------------------------------------------------------------------
-
#include "common/system.h"
#include "common/savefile.h"
#include "sword25/gfx/screenshot.h"
@@ -46,13 +42,11 @@
namespace Sword25 {
-// -----------------------------------------------------------------------------
-
#include "common/pack-start.h"
struct RGB_PIXEL {
- byte Red;
- byte Green;
- byte Blue;
+ byte red;
+ byte green;
+ byte blue;
} PACKED_STRUCT;
#include "common/pack-end.h"
@@ -63,22 +57,21 @@ void userWriteFn(png_structp png_ptr, png_bytep data, png_size_t length) {
void userFlushFn(png_structp png_ptr) {
}
-
-bool Screenshot::SaveToFile(Graphics::Surface *Data, Common::WriteStream *Stream) {
+bool Screenshot::saveToFile(Graphics::Surface *data, Common::WriteStream *stream) {
// Reserve buffer space
- RGB_PIXEL *pixelBuffer = new RGB_PIXEL[Data->w * Data->h];
+ RGB_PIXEL *pixelBuffer = new RGB_PIXEL[data->w * data->h];
// Convert the RGBA data to RGB
- const byte *pSrc = (const byte *)Data->getBasePtr(0, 0);
+ const byte *pSrc = (const byte *)data->getBasePtr(0, 0);
RGB_PIXEL *pDest = pixelBuffer;
- for (uint y = 0; y < Data->h; y++) {
- for (uint x = 0; x < Data->w; x++) {
+ for (uint y = 0; y < data->h; y++) {
+ for (uint x = 0; x < data->w; x++) {
uint32 srcPixel = READ_LE_UINT32(pSrc);
pSrc += sizeof(uint32);
- pDest->Red = (srcPixel >> 16) & 0xff;
- pDest->Green = (srcPixel >> 8) & 0xff;
- pDest->Blue = srcPixel & 0xff;
+ pDest->red = (srcPixel >> 16) & 0xff;
+ pDest->green = (srcPixel >> 8) & 0xff;
+ pDest->blue = srcPixel & 0xff;
++pDest;
}
}
@@ -91,30 +84,30 @@ bool Screenshot::SaveToFile(Graphics::Surface *Data, Common::WriteStream *Stream
if (!info_ptr)
error("Could not create PNG info-struct.");
- // The compression buffer must be large enough to the entire image.
+ // The compression buffer must be large enough to the entire image.
// This ensures that only an IDAT chunk is created.
// When buffer size is used 110% of the raw data size to be sure.
- png_set_compression_buffer_size(png_ptr, (Data->w * Data->h * 3 * 110) / 100);
+ png_set_compression_buffer_size(png_ptr, (data->w * data->h * 3 * 110) / 100);
// Initialise PNG-Info structure
png_set_IHDR(png_ptr, info_ptr,
- Data->w, // Width
- Data->h, // Height
- 8, // Bits depth
+ data->w, // Width
+ data->h, // Height
+ 8, // Bits depth
PNG_COLOR_TYPE_RGB, // Colour type
PNG_INTERLACE_NONE, // No interlacing
PNG_COMPRESSION_TYPE_DEFAULT, // Compression type
PNG_FILTER_TYPE_DEFAULT); // Filter Type
// Rowpointer erstellen
- png_bytep *rowPointers = new png_bytep[Data->h];
- for (uint i = 0; i < Data->h; i++) {
- rowPointers[i] = (png_bytep)&pixelBuffer[Data->w * i];
+ png_bytep *rowPointers = new png_bytep[data->h];
+ for (uint i = 0; i < data->h; i++) {
+ rowPointers[i] = (png_bytep)&pixelBuffer[data->w * i];
}
png_set_rows(png_ptr, info_ptr, &rowPointers[0]);
// Write out the png data to the file
- png_set_write_fn(png_ptr, (void *)Stream, userWriteFn, userFlushFn);
+ png_set_write_fn(png_ptr, (void *)stream, userWriteFn, userFlushFn);
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
png_destroy_write_struct(&png_ptr, &info_ptr);
@@ -127,14 +120,14 @@ bool Screenshot::SaveToFile(Graphics::Surface *Data, Common::WriteStream *Stream
// -----------------------------------------------------------------------------
-Common::MemoryReadStream *Screenshot::createThumbnail(Graphics::Surface *Data) {
+Common::MemoryReadStream *Screenshot::createThumbnail(Graphics::Surface *data) {
// This method takes a screen image with a dimension of 800x600, and creates a screenshot with a dimension of 200x125.
// 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
// 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.
- if (Data->w != 800 || Data->h != 600 || Data->bytesPerPixel != 4) {
+ if (data->w != 800 || data->h != 600 || data->bytesPerPixel != 4) {
BS_LOG_ERRORLN("The sreenshot dimensions have to be 800x600 in order to be saved as a thumbnail.");
return false;
}
@@ -152,7 +145,7 @@ Common::MemoryReadStream *Screenshot::createThumbnail(Graphics::Surface *Data) {
int alpha, red, green, blue;
alpha = red = green = blue = 0;
for (int j = 0; j < 4; ++j) {
- const uint32 *srcP = (const uint32 *)Data->getBasePtr(x * 4, y * 4 + j + 50);
+ const uint32 *srcP = (const uint32 *)data->getBasePtr(x * 4, y * 4 + j + 50);
for (int i = 0; i < 4; ++i) {
uint32 pixel = READ_LE_UINT32(srcP + i);
alpha += (pixel >> 24);
@@ -178,7 +171,7 @@ Common::MemoryReadStream *Screenshot::createThumbnail(Graphics::Surface *Data) {
// Create a PNG representation of the thumbnail data
Common::MemoryWriteStreamDynamic *stream = new Common::MemoryWriteStreamDynamic();
- SaveToFile(&thumbnail, stream);
+ saveToFile(&thumbnail, stream);
// Output a MemoryReadStream that encompasses the written data
Common::MemoryReadStream *result = new Common::MemoryReadStream(stream->getData(), stream->size(),