From a683a420a9e43705c972b5e74d55e319729e1a81 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 29 Jul 2010 19:53:02 +0000 Subject: SWORD25: Importing original sources svn-id: r53171 --- engines/sword25/gfx/screenshot.cpp | 202 +++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100755 engines/sword25/gfx/screenshot.cpp (limited to 'engines/sword25/gfx/screenshot.cpp') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp new file mode 100755 index 0000000000..82ba4a9374 --- /dev/null +++ b/engines/sword25/gfx/screenshot.cpp @@ -0,0 +1,202 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 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. +// +// Broken Sword 2.5 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 Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +#define BS_LOG_PREFIX "SCREENSHOT" + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "screenshot.h" +#include "util/libpng/png.h" + +using namespace std; + +// ----------------------------------------------------------------------------- + +struct RGB_PIXEL +{ + RGB_PIXEL(unsigned char _Red, unsigned char _Green, unsigned char _Blue) : + Red(_Red), + Green(_Green), + Blue(_Blue) + {}; + + unsigned char Red; + unsigned char Green; + unsigned char Blue; +}; + +bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const vector & Data, const string & Filename) +{ + BS_ASSERT(Data.size() == Width * Height); + + // Buffer für Bildschirminhalt in RGB reservieren + vector PixelBuffer; + PixelBuffer.reserve(Width * Height); + + // Framebufferdaten pixelweise von RGBA nach RGB konvertieren + vector::const_iterator it = Data.begin(); + for (unsigned int y = 0; y < Height; y++) + { + for (unsigned int x = 0; x < Width; x++) + { + unsigned int SrcPixel = *it++; + PixelBuffer.push_back(RGB_PIXEL((SrcPixel >> 16) & 0xff, (SrcPixel >> 8) & 0xff, SrcPixel & 0xff)); + } + } + BS_ASSERT(it == Data.end()); + BS_ASSERT(Data.size() == PixelBuffer.size()); + + // Variablen für die PNG-Erstellung + FILE * OutFile = 0; + png_structp png_ptr = 0; + png_infop info_ptr = 0; + + try + { + OutFile = fopen(Filename.c_str(), "wb"); + if (!OutFile) + { + BS_LOG_ERRORLN("Could not create screenshot-file \"%s\".", Filename.c_str()); + throw(0); + } + + png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) + { + BS_LOG_ERRORLN("Could not create PNG write-struct."); + throw(0); + } + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + BS_LOG_ERRORLN("Could not create PNG info-struct."); + throw(0); + } + + // Der Kompressionsbuffer muss groß genug sein um das gesamte Bild zu beinhalten. + // Dieses stellt sicher, dass nur ein IDAT Chunk erstellt wird. + // Als Buffergröße wird 110% der Rohdatengröße verwandt, um sicher zu gehen. + png_set_compression_buffer_size(png_ptr, (Width * Height * 3 * 110) / 100); + + // PNG-Info Struktur initialisieren + png_set_IHDR(png_ptr, info_ptr, + Width, // Breite + Height, // Höhe + 8, // Bittiefe pro Kanal + PNG_COLOR_TYPE_RGB, // Farbformat + PNG_INTERLACE_NONE, // Interlacing-Typ + PNG_COMPRESSION_TYPE_DEFAULT, // Kompressions-Typ + PNG_FILTER_TYPE_DEFAULT); // Filter-Typ + + // Rowpointer erstellen + vector RowPointers; + RowPointers.reserve(Height); + for (unsigned int i = 0; i < Height; i++) + { + RowPointers.push_back((png_bytep)(&PixelBuffer[Width * i])); + } + png_set_rows(png_ptr, info_ptr, &RowPointers[0]); + + png_init_io(png_ptr, OutFile); + + // Bild schreiben + png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); + + png_destroy_write_struct(&png_ptr, &info_ptr); + fclose(OutFile); + } + + catch (int) + { + // Wenn die Datei bereits erstellt wurde, Datei schließen und löschen. + if (OutFile) + { + fclose(OutFile); + remove(Filename.c_str()); + } + + if (info_ptr) png_destroy_write_struct(0, &info_ptr); + if (png_ptr) png_destroy_write_struct(&png_ptr, (png_infopp) 0); + + BS_LOG_ERRORLN("Could not create screenshot (\"%s\").", Filename.c_str()); + return false; + } + + return true; +} + +// ----------------------------------------------------------------------------- + +bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const vector & Data, const string & Filename) +{ + // + // Diese Methode nimmt ein Screenshot mit den Maßen von 800x600 und erzeugt einen Screenshot mit den Maßen von 200x125. + // Dabei werden je 50 Pixel oben und unten abgeschnitten (die Interface-Leisten im Spiel). Das verbleibende Bild von 800x500 wird auf + // ein 16tel seiner Größe reduziert, indem es in 4x4 Pixelblöcke ausgeteilt wird und der Durchschnitt jedes Blockes einen Pixel des Zielbildes generiert. + // Abschließend wird das Ergebnis als PNG-Datei unter dem übergebenen Dateinamen gespeichert. + // + + // Die Ausgangsgröße muss 800x600 sein. + if (Width != 800 || Height != 600) + { + BS_LOG_ERRORLN("The sreenshot dimensions have to be 800x600 in order to be saved as a thumbnail."); + return false; + } + + // Buffer für die Zieldaten erstellen (RGBA Bild mit den Maßen 200x125). + vector ThumbnailData(200 * 125); + + // Über das Zielbild iterieren und einen Pixel zur Zeit berechnen. + unsigned int x, y; + x = y = 0; + for(vector::iterator Iter = ThumbnailData.begin(); Iter != ThumbnailData.end(); ++Iter) + { + // Durchschnitt über 4x4 Pixelblock im Quellbild bilden. + unsigned int Alpha, Red, Green, Blue; + Alpha = Red = Green = Blue = 0; + for (unsigned int j = 0; j < 4; ++j) + { + for (unsigned int i = 0; i < 4; ++i) + { + unsigned int Pixel = Data[((y * 4) + j + 50) * 800 + ((x * 4) + i)]; + Alpha += (Pixel >> 24); + Red += (Pixel >> 16) & 0xff; + Green += (Pixel >> 8) & 0xff; + Blue += Pixel & 0xff; + } + } + + // Zielpixel schreiben. + *Iter = ((Alpha / 16) << 24) | ((Red / 16) << 16) | ((Green / 16) << 8) | (Blue / 16); + + // Mitzählen an welcher Stelle im Zielbild wir uns befinden. + ++x; + if (x == 200) + { + x = 0; + ++y; + } + } + + // Bild als PNG Speichern. + return SaveToFile(200, 125, ThumbnailData, Filename); +} -- cgit v1.2.3 From e8bca8b8fe0f80e0d5053b190840b034f50ae163 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 30 Jul 2010 09:02:39 +0000 Subject: SWORD25: Fixed rest of the include paths svn-id: r53181 --- engines/sword25/gfx/screenshot.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/sword25/gfx/screenshot.cpp') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 82ba4a9374..75e86d0105 100755 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -23,8 +23,8 @@ // Includes // ----------------------------------------------------------------------------- -#include "screenshot.h" -#include "util/libpng/png.h" +#include "sword25/gfx/screenshot.h" +#include using namespace std; -- cgit v1.2.3 From 293bf95c01f76c8d812a300eb038854f1246ab3d Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 31 Jul 2010 09:53:02 +0000 Subject: SWORD25: Replacing headers with ScummVM ones plus original (C) svn-id: r53188 --- engines/sword25/gfx/screenshot.cpp | 51 ++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 18 deletions(-) mode change 100755 => 100644 engines/sword25/gfx/screenshot.cpp (limited to 'engines/sword25/gfx/screenshot.cpp') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp old mode 100755 new mode 100644 index 75e86d0105..563835ad11 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 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. -// -// Broken Sword 2.5 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 Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* 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. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ #define BS_LOG_PREFIX "SCREENSHOT" -- cgit v1.2.3 From de0fe1db4939bbb787de60231dd30a7b5391f269 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 5 Aug 2010 12:48:19 +0000 Subject: SWORD25: Mass-putting of all files in gfx/ into Sword25 namespace svn-id: r53214 --- engines/sword25/gfx/screenshot.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/sword25/gfx/screenshot.cpp') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 563835ad11..3e2f0f27b2 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -41,6 +41,8 @@ #include "sword25/gfx/screenshot.h" #include +namespace Sword25 { + using namespace std; // ----------------------------------------------------------------------------- @@ -215,3 +217,5 @@ bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, // Bild als PNG Speichern. return SaveToFile(200, 125, ThumbnailData, Filename); } + +} // End of namespace Sword25 -- cgit v1.2.3 From 47904bc7b2992189bb554833f00a79ff0fea9fb8 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 6 Aug 2010 13:13:25 +0000 Subject: SWORD25: Mass-astyle. svn-id: r53222 --- engines/sword25/gfx/screenshot.cpp | 75 +++++++++++++++----------------------- 1 file changed, 29 insertions(+), 46 deletions(-) (limited to 'engines/sword25/gfx/screenshot.cpp') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 3e2f0f27b2..59e52e1ab4 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -47,21 +47,19 @@ using namespace std; // ----------------------------------------------------------------------------- -struct RGB_PIXEL -{ +struct RGB_PIXEL { RGB_PIXEL(unsigned char _Red, unsigned char _Green, unsigned char _Blue) : Red(_Red), Green(_Green), Blue(_Blue) - {}; + {}; unsigned char Red; unsigned char Green; unsigned char Blue; }; -bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const vector & Data, const string & Filename) -{ +bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const vector & Data, const string &Filename) { BS_ASSERT(Data.size() == Width * Height); // Buffer für Bildschirminhalt in RGB reservieren @@ -70,10 +68,8 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve // Framebufferdaten pixelweise von RGBA nach RGB konvertieren vector::const_iterator it = Data.begin(); - for (unsigned int y = 0; y < Height; y++) - { - for (unsigned int x = 0; x < Width; x++) - { + for (unsigned int y = 0; y < Height; y++) { + for (unsigned int x = 0; x < Width; x++) { unsigned int SrcPixel = *it++; PixelBuffer.push_back(RGB_PIXEL((SrcPixel >> 16) & 0xff, (SrcPixel >> 8) & 0xff, SrcPixel & 0xff)); } @@ -82,29 +78,25 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve BS_ASSERT(Data.size() == PixelBuffer.size()); // Variablen für die PNG-Erstellung - FILE * OutFile = 0; + FILE *OutFile = 0; png_structp png_ptr = 0; png_infop info_ptr = 0; - try - { + try { OutFile = fopen(Filename.c_str(), "wb"); - if (!OutFile) - { + if (!OutFile) { BS_LOG_ERRORLN("Could not create screenshot-file \"%s\".", Filename.c_str()); throw(0); } png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png_ptr) - { + if (!png_ptr) { BS_LOG_ERRORLN("Could not create PNG write-struct."); throw(0); } png_infop info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { + if (!info_ptr) { BS_LOG_ERRORLN("Could not create PNG info-struct."); throw(0); } @@ -115,20 +107,19 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve png_set_compression_buffer_size(png_ptr, (Width * Height * 3 * 110) / 100); // PNG-Info Struktur initialisieren - png_set_IHDR(png_ptr, info_ptr, - Width, // Breite - Height, // Höhe - 8, // Bittiefe pro Kanal - PNG_COLOR_TYPE_RGB, // Farbformat - PNG_INTERLACE_NONE, // Interlacing-Typ - PNG_COMPRESSION_TYPE_DEFAULT, // Kompressions-Typ - PNG_FILTER_TYPE_DEFAULT); // Filter-Typ + png_set_IHDR(png_ptr, info_ptr, + Width, // Breite + Height, // Höhe + 8, // Bittiefe pro Kanal + PNG_COLOR_TYPE_RGB, // Farbformat + PNG_INTERLACE_NONE, // Interlacing-Typ + PNG_COMPRESSION_TYPE_DEFAULT, // Kompressions-Typ + PNG_FILTER_TYPE_DEFAULT); // Filter-Typ // Rowpointer erstellen vector RowPointers; RowPointers.reserve(Height); - for (unsigned int i = 0; i < Height; i++) - { + for (unsigned int i = 0; i < Height; i++) { RowPointers.push_back((png_bytep)(&PixelBuffer[Width * i])); } png_set_rows(png_ptr, info_ptr, &RowPointers[0]); @@ -142,11 +133,9 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve fclose(OutFile); } - catch (int) - { + catch (int) { // Wenn die Datei bereits erstellt wurde, Datei schließen und löschen. - if (OutFile) - { + if (OutFile) { fclose(OutFile); remove(Filename.c_str()); } @@ -163,8 +152,7 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve // ----------------------------------------------------------------------------- -bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const vector & Data, const string & Filename) -{ +bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const vector & Data, const string &Filename) { // // Diese Methode nimmt ein Screenshot mit den Maßen von 800x600 und erzeugt einen Screenshot mit den Maßen von 200x125. // Dabei werden je 50 Pixel oben und unten abgeschnitten (die Interface-Leisten im Spiel). Das verbleibende Bild von 800x500 wird auf @@ -173,27 +161,23 @@ bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, // // Die Ausgangsgröße muss 800x600 sein. - if (Width != 800 || Height != 600) - { + if (Width != 800 || Height != 600) { BS_LOG_ERRORLN("The sreenshot dimensions have to be 800x600 in order to be saved as a thumbnail."); return false; } - + // Buffer für die Zieldaten erstellen (RGBA Bild mit den Maßen 200x125). vector ThumbnailData(200 * 125); // Über das Zielbild iterieren und einen Pixel zur Zeit berechnen. unsigned int x, y; x = y = 0; - for(vector::iterator Iter = ThumbnailData.begin(); Iter != ThumbnailData.end(); ++Iter) - { + for (vector::iterator Iter = ThumbnailData.begin(); Iter != ThumbnailData.end(); ++Iter) { // Durchschnitt über 4x4 Pixelblock im Quellbild bilden. unsigned int Alpha, Red, Green, Blue; Alpha = Red = Green = Blue = 0; - for (unsigned int j = 0; j < 4; ++j) - { - for (unsigned int i = 0; i < 4; ++i) - { + for (unsigned int j = 0; j < 4; ++j) { + for (unsigned int i = 0; i < 4; ++i) { unsigned int Pixel = Data[((y * 4) + j + 50) * 800 + ((x * 4) + i)]; Alpha += (Pixel >> 24); Red += (Pixel >> 16) & 0xff; @@ -207,8 +191,7 @@ bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, // Mitzählen an welcher Stelle im Zielbild wir uns befinden. ++x; - if (x == 200) - { + if (x == 200) { x = 0; ++y; } -- cgit v1.2.3 From ab85540a1bb59d7f69b89868805d1fe2a2adc89c Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 7 Aug 2010 20:09:40 +0000 Subject: SWORD25: More compilation fixes Now almost everything compiles fine. Several files were tricked and there are references to tinyxml.h and of course fmod and agg. OpenGL gfx renderer removed from the project, we need to create our own from the scratch. svn-id: r53224 --- engines/sword25/gfx/screenshot.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'engines/sword25/gfx/screenshot.cpp') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 59e52e1ab4..0c48966d0b 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -59,7 +59,8 @@ struct RGB_PIXEL { unsigned char Blue; }; -bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const vector & Data, const string &Filename) { +bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const byte *Data, const Common::String &Filename) { +#if 0 BS_ASSERT(Data.size() == Width * Height); // Buffer für Bildschirminhalt in RGB reservieren @@ -146,13 +147,17 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve BS_LOG_ERRORLN("Could not create screenshot (\"%s\").", Filename.c_str()); return false; } +#else + warning("STUB: BS_Screenshot::SaveToFile(%d, %d, .., %s)", Width, Height, Filename.c_str()); +#endif return true; } // ----------------------------------------------------------------------------- -bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const vector & Data, const string &Filename) { +bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const byte *Data, const Common::String &Filename) { +#if 0 // // Diese Methode nimmt ein Screenshot mit den Maßen von 800x600 und erzeugt einen Screenshot mit den Maßen von 200x125. // Dabei werden je 50 Pixel oben und unten abgeschnitten (die Interface-Leisten im Spiel). Das verbleibende Bild von 800x500 wird auf @@ -199,6 +204,11 @@ bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, // Bild als PNG Speichern. return SaveToFile(200, 125, ThumbnailData, Filename); +#else + warning("STUB: BS_Screenshot::SaveThumbnailToFile(%d, %d, .., %s)", Width, Height, Filename.c_str()); + + return true; +#endif } } // End of namespace Sword25 -- cgit v1.2.3 From 485ff15d23b3ae9545f5c9df794f1326185eae7a Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 18 Aug 2010 10:52:24 +0000 Subject: SWORD25: Mass-eliminating of BS_ prefix in fmv/ and gfx/ svn-id: r53258 --- engines/sword25/gfx/screenshot.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/sword25/gfx/screenshot.cpp') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 0c48966d0b..67273cc876 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -59,7 +59,7 @@ struct RGB_PIXEL { unsigned char Blue; }; -bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const byte *Data, const Common::String &Filename) { +bool Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const byte *Data, const Common::String &Filename) { #if 0 BS_ASSERT(Data.size() == Width * Height); @@ -156,7 +156,7 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const by // ----------------------------------------------------------------------------- -bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const byte *Data, const Common::String &Filename) { +bool Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const byte *Data, const Common::String &Filename) { #if 0 // // Diese Methode nimmt ein Screenshot mit den Maßen von 800x600 und erzeugt einen Screenshot mit den Maßen von 200x125. -- cgit v1.2.3 From 9efd8bac2681d8078b08c0136f450cd7fdd55795 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 19 Aug 2010 00:47:59 +0000 Subject: SWORD25: Removed now redundant 'using namespace std' lines svn-id: r53263 --- engines/sword25/gfx/screenshot.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines/sword25/gfx/screenshot.cpp') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 67273cc876..383f1f8fb8 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -43,8 +43,6 @@ namespace Sword25 { -using namespace std; - // ----------------------------------------------------------------------------- struct RGB_PIXEL { -- cgit v1.2.3 From 0cdb2ded85d17150cb108a5d63dd8957c29af2a5 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 2 Sep 2010 11:54:44 +0000 Subject: SWORD25: unsigned char -> byte svn-id: r53308 --- engines/sword25/gfx/screenshot.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/sword25/gfx/screenshot.cpp') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 383f1f8fb8..f48e73b1f6 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -46,15 +46,15 @@ namespace Sword25 { // ----------------------------------------------------------------------------- struct RGB_PIXEL { - RGB_PIXEL(unsigned char _Red, unsigned char _Green, unsigned char _Blue) : + RGB_PIXEL(byte _Red, byte _Green, byte _Blue) : Red(_Red), Green(_Green), Blue(_Blue) {}; - unsigned char Red; - unsigned char Green; - unsigned char Blue; + byte Red; + byte Green; + byte Blue; }; bool Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const byte *Data, const Common::String &Filename) { -- cgit v1.2.3 From 086f5961b6575c50bb386750b6e9a3ed1efdd8cd Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 2 Sep 2010 12:14:04 +0000 Subject: SWORD25: unsigned int -> uint svn-id: r53309 --- engines/sword25/gfx/screenshot.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'engines/sword25/gfx/screenshot.cpp') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index f48e73b1f6..ce1f98797c 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -57,7 +57,7 @@ struct RGB_PIXEL { byte Blue; }; -bool Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const byte *Data, const Common::String &Filename) { +bool Screenshot::SaveToFile(uint Width, uint Height, const byte *Data, const Common::String &Filename) { #if 0 BS_ASSERT(Data.size() == Width * Height); @@ -66,10 +66,10 @@ bool Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const byte PixelBuffer.reserve(Width * Height); // Framebufferdaten pixelweise von RGBA nach RGB konvertieren - vector::const_iterator it = Data.begin(); - for (unsigned int y = 0; y < Height; y++) { - for (unsigned int x = 0; x < Width; x++) { - unsigned int SrcPixel = *it++; + vector::const_iterator it = Data.begin(); + for (uint y = 0; y < Height; y++) { + for (uint x = 0; x < Width; x++) { + uint SrcPixel = *it++; PixelBuffer.push_back(RGB_PIXEL((SrcPixel >> 16) & 0xff, (SrcPixel >> 8) & 0xff, SrcPixel & 0xff)); } } @@ -118,7 +118,7 @@ bool Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const byte // Rowpointer erstellen vector RowPointers; RowPointers.reserve(Height); - for (unsigned int i = 0; i < Height; i++) { + for (uint i = 0; i < Height; i++) { RowPointers.push_back((png_bytep)(&PixelBuffer[Width * i])); } png_set_rows(png_ptr, info_ptr, &RowPointers[0]); @@ -154,7 +154,7 @@ bool Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const byte // ----------------------------------------------------------------------------- -bool Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const byte *Data, const Common::String &Filename) { +bool Screenshot::SaveThumbnailToFile(uint Width, uint Height, const byte *Data, const Common::String &Filename) { #if 0 // // Diese Methode nimmt ein Screenshot mit den Maßen von 800x600 und erzeugt einen Screenshot mit den Maßen von 200x125. @@ -170,18 +170,18 @@ bool Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, co } // Buffer für die Zieldaten erstellen (RGBA Bild mit den Maßen 200x125). - vector ThumbnailData(200 * 125); + vector ThumbnailData(200 * 125); // Über das Zielbild iterieren und einen Pixel zur Zeit berechnen. - unsigned int x, y; + uint x, y; x = y = 0; - for (vector::iterator Iter = ThumbnailData.begin(); Iter != ThumbnailData.end(); ++Iter) { + for (vector::iterator Iter = ThumbnailData.begin(); Iter != ThumbnailData.end(); ++Iter) { // Durchschnitt über 4x4 Pixelblock im Quellbild bilden. - unsigned int Alpha, Red, Green, Blue; + uint Alpha, Red, Green, Blue; Alpha = Red = Green = Blue = 0; - for (unsigned int j = 0; j < 4; ++j) { - for (unsigned int i = 0; i < 4; ++i) { - unsigned int Pixel = Data[((y * 4) + j + 50) * 800 + ((x * 4) + i)]; + for (uint j = 0; j < 4; ++j) { + for (uint i = 0; i < 4; ++i) { + uint Pixel = Data[((y * 4) + j + 50) * 800 + ((x * 4) + i)]; Alpha += (Pixel >> 24); Red += (Pixel >> 16) & 0xff; Green += (Pixel >> 8) & 0xff; -- cgit v1.2.3 From 80521ed5dd279316d0534fc3cc4b61c27d19ef4e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 19 Sep 2010 05:00:45 +0000 Subject: SWORD25: Further savegame work, including savegame screenshots This handles saving (but not yet re-loaded display) of screenshots into savegame files. It also changes the original engine behaviour of temporarily saving the screenshots in a file 'tmp.png' to keeping the raw PNG file data in a memory block. svn-id: r53373 --- engines/sword25/gfx/screenshot.cpp | 223 +++++++++++++++++-------------------- 1 file changed, 100 insertions(+), 123 deletions(-) (limited to 'engines/sword25/gfx/screenshot.cpp') diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index ce1f98797c..9eea2ec422 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -38,175 +38,152 @@ // Includes // ----------------------------------------------------------------------------- +#include "common/system.h" +#include "common/savefile.h" #include "sword25/gfx/screenshot.h" +#include "sword25/kernel/filesystemutil.h" #include namespace Sword25 { // ----------------------------------------------------------------------------- +#include "common/pack-start.h" struct RGB_PIXEL { - RGB_PIXEL(byte _Red, byte _Green, byte _Blue) : - Red(_Red), - Green(_Green), - Blue(_Blue) - {}; - byte Red; byte Green; byte Blue; -}; - -bool Screenshot::SaveToFile(uint Width, uint Height, const byte *Data, const Common::String &Filename) { -#if 0 - BS_ASSERT(Data.size() == Width * Height); - - // Buffer für Bildschirminhalt in RGB reservieren - vector PixelBuffer; - PixelBuffer.reserve(Width * Height); - - // Framebufferdaten pixelweise von RGBA nach RGB konvertieren - vector::const_iterator it = Data.begin(); - for (uint y = 0; y < Height; y++) { - for (uint x = 0; x < Width; x++) { - uint SrcPixel = *it++; - PixelBuffer.push_back(RGB_PIXEL((SrcPixel >> 16) & 0xff, (SrcPixel >> 8) & 0xff, SrcPixel & 0xff)); - } - } - BS_ASSERT(it == Data.end()); - BS_ASSERT(Data.size() == PixelBuffer.size()); - - // Variablen für die PNG-Erstellung - FILE *OutFile = 0; - png_structp png_ptr = 0; - png_infop info_ptr = 0; - - try { - OutFile = fopen(Filename.c_str(), "wb"); - if (!OutFile) { - BS_LOG_ERRORLN("Could not create screenshot-file \"%s\".", Filename.c_str()); - throw(0); - } +} PACKED_STRUCT; +#include "common/pack-end.h" - png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png_ptr) { - BS_LOG_ERRORLN("Could not create PNG write-struct."); - throw(0); - } +void userWriteFn(png_structp png_ptr, png_bytep data, png_size_t length) { + static_cast(png_ptr->io_ptr)->write(data, length); +} - png_infop info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) { - BS_LOG_ERRORLN("Could not create PNG info-struct."); - throw(0); - } +void userFlushFn(png_structp png_ptr) { +} - // Der Kompressionsbuffer muss groß genug sein um das gesamte Bild zu beinhalten. - // Dieses stellt sicher, dass nur ein IDAT Chunk erstellt wird. - // Als Buffergröße wird 110% der Rohdatengröße verwandt, um sicher zu gehen. - png_set_compression_buffer_size(png_ptr, (Width * Height * 3 * 110) / 100); - - // PNG-Info Struktur initialisieren - png_set_IHDR(png_ptr, info_ptr, - Width, // Breite - Height, // Höhe - 8, // Bittiefe pro Kanal - PNG_COLOR_TYPE_RGB, // Farbformat - PNG_INTERLACE_NONE, // Interlacing-Typ - PNG_COMPRESSION_TYPE_DEFAULT, // Kompressions-Typ - PNG_FILTER_TYPE_DEFAULT); // Filter-Typ - - // Rowpointer erstellen - vector RowPointers; - RowPointers.reserve(Height); - for (uint i = 0; i < Height; i++) { - RowPointers.push_back((png_bytep)(&PixelBuffer[Width * i])); - } - png_set_rows(png_ptr, info_ptr, &RowPointers[0]); - png_init_io(png_ptr, OutFile); +bool Screenshot::SaveToFile(Graphics::Surface *Data, Common::WriteStream *Stream) { + // Reserve buffer space + RGB_PIXEL *pixelBuffer = new RGB_PIXEL[Data->w * Data->h]; - // Bild schreiben - png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); + // Convert the RGBA data to RGB + const byte *pSrc = (const byte *)Data->getBasePtr(0, 0); + RGB_PIXEL *pDest = pixelBuffer; - png_destroy_write_struct(&png_ptr, &info_ptr); - fclose(OutFile); + 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; + } } - catch (int) { - // Wenn die Datei bereits erstellt wurde, Datei schließen und löschen. - if (OutFile) { - fclose(OutFile); - remove(Filename.c_str()); - } + png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) + error("Could not create PNG write-struct."); + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + error("Could not create PNG info-struct."); + + // 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); + + // Initialise PNG-Info structure + png_set_IHDR(png_ptr, info_ptr, + 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_set_rows(png_ptr, info_ptr, &rowPointers[0]); - if (info_ptr) png_destroy_write_struct(0, &info_ptr); - if (png_ptr) png_destroy_write_struct(&png_ptr, (png_infopp) 0); + // Write out the png data to the file + png_set_write_fn(png_ptr, (void *)Stream, userWriteFn, userFlushFn); + png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); - BS_LOG_ERRORLN("Could not create screenshot (\"%s\").", Filename.c_str()); - return false; - } -#else - warning("STUB: BS_Screenshot::SaveToFile(%d, %d, .., %s)", Width, Height, Filename.c_str()); -#endif + png_destroy_write_struct(&png_ptr, &info_ptr); + + delete[] pixelBuffer; + delete[] rowPointers; return true; } // ----------------------------------------------------------------------------- -bool Screenshot::SaveThumbnailToFile(uint Width, uint Height, const byte *Data, const Common::String &Filename) { -#if 0 - // - // Diese Methode nimmt ein Screenshot mit den Maßen von 800x600 und erzeugt einen Screenshot mit den Maßen von 200x125. - // Dabei werden je 50 Pixel oben und unten abgeschnitten (die Interface-Leisten im Spiel). Das verbleibende Bild von 800x500 wird auf - // ein 16tel seiner Größe reduziert, indem es in 4x4 Pixelblöcke ausgeteilt wird und der Durchschnitt jedes Blockes einen Pixel des Zielbildes generiert. - // Abschließend wird das Ergebnis als PNG-Datei unter dem übergebenen Dateinamen gespeichert. - // - - // Die Ausgangsgröße muss 800x600 sein. - if (Width != 800 || Height != 600) { +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) { BS_LOG_ERRORLN("The sreenshot dimensions have to be 800x600 in order to be saved as a thumbnail."); return false; } - // Buffer für die Zieldaten erstellen (RGBA Bild mit den Maßen 200x125). - vector ThumbnailData(200 * 125); + // Buffer for the output thumbnail + Graphics::Surface thumbnail; + thumbnail.create(200, 125, 4); // Über das Zielbild iterieren und einen Pixel zur Zeit berechnen. uint x, y; x = y = 0; - for (vector::iterator Iter = ThumbnailData.begin(); Iter != ThumbnailData.end(); ++Iter) { - // Durchschnitt über 4x4 Pixelblock im Quellbild bilden. - uint Alpha, Red, Green, Blue; - Alpha = Red = Green = Blue = 0; - for (uint j = 0; j < 4; ++j) { - for (uint i = 0; i < 4; ++i) { - uint Pixel = Data[((y * 4) + j + 50) * 800 + ((x * 4) + i)]; - Alpha += (Pixel >> 24); - Red += (Pixel >> 16) & 0xff; - Green += (Pixel >> 8) & 0xff; - Blue += Pixel & 0xff; + + 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) { + 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); + red += (pixel >> 16) & 0xff; + green += (pixel >> 8) & 0xff; + blue += pixel & 0xff; } } - // Zielpixel schreiben. - *Iter = ((Alpha / 16) << 24) | ((Red / 16) << 16) | ((Green / 16) << 8) | (Blue / 16); + // Write target pixel + *pDest++ = blue / 16; + *pDest++ = green / 16; + *pDest++ = red / 16; + *pDest++ = alpha / 16; - // Mitzählen an welcher Stelle im Zielbild wir uns befinden. + // Move to next block ++x; - if (x == 200) { + if (x == thumbnail.w) { x = 0; ++y; } } - // Bild als PNG Speichern. - return SaveToFile(200, 125, ThumbnailData, Filename); -#else - warning("STUB: BS_Screenshot::SaveThumbnailToFile(%d, %d, .., %s)", Width, Height, Filename.c_str()); + // Create a PNG representation of the thumbnail data + Common::MemoryWriteStreamDynamic *stream = new Common::MemoryWriteStreamDynamic(); + SaveToFile(&thumbnail, stream); - return true; -#endif + // Output a MemoryReadStream that encompasses the written data + Common::MemoryReadStream *result = new Common::MemoryReadStream(stream->getData(), stream->size(), + DisposeAfterUse::YES); + return result; } } // End of namespace Sword25 -- cgit v1.2.3