2010-06-11 15:38:17 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// SSSS tt lll lll
|
|
|
|
// SS SS tt ll ll
|
|
|
|
// SS tttttt eeee ll ll aaaa
|
|
|
|
// SSSS tt ee ee ll ll aa
|
|
|
|
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
|
|
|
// SS SS tt ee ll ll aa aa
|
|
|
|
// SSSS ttt eeeee llll llll aaaaa
|
|
|
|
//
|
2013-01-04 19:49:01 +00:00
|
|
|
// Copyright (c) 1995-2013 by Bradford W. Mott, Stephen Anthony
|
2010-06-11 15:38:17 +00:00
|
|
|
// and the Stella Team
|
|
|
|
//
|
|
|
|
// See the file "License.txt" for information on usage and redistribution of
|
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#ifndef PNGLIBRARY_HXX
|
|
|
|
#define PNGLIBRARY_HXX
|
|
|
|
|
|
|
|
#include <png.h>
|
|
|
|
|
2010-10-18 18:39:57 +00:00
|
|
|
class FrameBuffer;
|
|
|
|
class FBSurface;
|
2013-01-28 20:39:50 +00:00
|
|
|
class Properties;
|
|
|
|
class TIA;
|
2010-10-18 18:39:57 +00:00
|
|
|
|
2013-01-28 20:39:50 +00:00
|
|
|
#include <fstream>
|
2010-06-11 15:38:17 +00:00
|
|
|
#include "bspf.hxx"
|
|
|
|
|
|
|
|
/**
|
|
|
|
This class implements a thin wrapper around the libpng library, and
|
|
|
|
abstracts all the irrelevant details other loading and saving an
|
|
|
|
actual image.
|
|
|
|
|
|
|
|
@author Stephen Anthony
|
|
|
|
*/
|
|
|
|
class PNGLibrary
|
|
|
|
{
|
|
|
|
public:
|
2011-07-03 21:52:33 +00:00
|
|
|
PNGLibrary();
|
2013-01-28 20:39:50 +00:00
|
|
|
virtual ~PNGLibrary();
|
2010-06-11 15:38:17 +00:00
|
|
|
|
|
|
|
/**
|
2011-07-03 21:52:33 +00:00
|
|
|
Read a PNG image from the specified file into a FBSurface structure,
|
|
|
|
scaling the image to the surface bounds.
|
2010-06-11 15:38:17 +00:00
|
|
|
|
2013-01-28 20:39:50 +00:00
|
|
|
@param filename The filename to load the PNG image
|
2011-07-03 21:52:33 +00:00
|
|
|
@param fb The main framebuffer of the application
|
|
|
|
@param surface The FBSurface into which to place the PNG data
|
2010-06-11 15:38:17 +00:00
|
|
|
|
2010-06-15 15:40:11 +00:00
|
|
|
@return On success, the FBSurface containing image data and a
|
2011-07-03 21:52:33 +00:00
|
|
|
result of true, otherwise a const char* exception is thrown
|
|
|
|
containing a more detailed error message.
|
2010-06-11 15:38:17 +00:00
|
|
|
*/
|
2013-01-28 20:39:50 +00:00
|
|
|
bool loadImage(const string& filename, const FrameBuffer& fb, FBSurface& surface);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Save the current TIA image to a PNG file using data from the Framebuffer.
|
|
|
|
Any postprocessing/filtering will be included.
|
|
|
|
|
|
|
|
@param filename The filename to save the PNG image
|
|
|
|
@param framebuffer The framebuffer containing the image data
|
|
|
|
@param props The properties object containing info about the ROM
|
|
|
|
*/
|
|
|
|
string saveImage(const string& filename, const FrameBuffer& framebuffer,
|
|
|
|
const Properties& props);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Save the current TIA image to a PNG file using data directly from
|
|
|
|
the TIA framebuffer. No filtering or scaling will be included.
|
|
|
|
|
|
|
|
@param filename The filename to save the PNG image
|
|
|
|
@param framebuffer The framebuffer containing the image data
|
|
|
|
@param mediasrc Source of the raw TIA data
|
|
|
|
@param props The properties object containing info about the ROM
|
|
|
|
*/
|
|
|
|
string saveImage(const string& filename, const FrameBuffer& framebuffer,
|
|
|
|
const TIA& tia, const Properties& props);
|
2010-06-15 15:40:11 +00:00
|
|
|
|
|
|
|
private:
|
2011-07-03 21:52:33 +00:00
|
|
|
// The following data remains between invocations of allocateStorage,
|
|
|
|
// and is only changed when absolutely necessary.
|
|
|
|
typedef struct {
|
|
|
|
uInt8* buffer;
|
|
|
|
png_bytep* row_pointers;
|
|
|
|
png_uint_32 width, height, pitch;
|
|
|
|
uInt32* line;
|
|
|
|
uInt32 buffer_size, line_size, row_size;
|
|
|
|
} ReadInfoType;
|
|
|
|
static ReadInfoType ReadInfo;
|
|
|
|
|
2010-06-15 15:40:11 +00:00
|
|
|
/**
|
2011-07-03 21:52:33 +00:00
|
|
|
Allocate memory for PNG read operations. This is used to provide a
|
|
|
|
basic memory manager, so that we don't constantly allocate and deallocate
|
|
|
|
memory for each image loaded.
|
|
|
|
|
|
|
|
The method fills the 'ReadInfo' struct with valid memory locations
|
|
|
|
dependent on the given dimensions. If memory has been previously
|
|
|
|
allocated and it can accommodate the given dimensions, it is used directly.
|
|
|
|
*/
|
|
|
|
bool allocateStorage(png_uint_32 iwidth, png_uint_32 iheight);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Scale the PNG data from 'ReadInfo' into the FBSurface. For now, scaling
|
2010-06-15 15:40:11 +00:00
|
|
|
is done on integer boundaries only (ie, 1x, 2x, etc up or down).
|
|
|
|
|
|
|
|
@param fb The main framebuffer of the application
|
|
|
|
@param surface The FBSurface into which to place the PNG data
|
|
|
|
*/
|
2011-07-03 21:52:33 +00:00
|
|
|
void scaleImagetoSurface(const FrameBuffer& fb, FBSurface& surface);
|
2010-06-15 15:40:11 +00:00
|
|
|
|
2013-01-28 20:39:50 +00:00
|
|
|
string saveBufferToPNG(ofstream& out, uInt8* buffer,
|
|
|
|
uInt32 width, uInt32 height,
|
|
|
|
const Properties& props,
|
|
|
|
const string& effectsInfo);
|
|
|
|
void writePNGChunk(ofstream& out, const char* type, uInt8* data, int size);
|
|
|
|
void writePNGText(ofstream& out, const string& key, const string& text);
|
|
|
|
|
2010-06-15 15:40:11 +00:00
|
|
|
static void png_read_data(png_structp ctx, png_bytep area, png_size_t size);
|
|
|
|
static void png_write_data(png_structp ctx, png_bytep area, png_size_t size);
|
|
|
|
static void png_io_flush(png_structp ctx);
|
|
|
|
static void png_user_warn(png_structp ctx, png_const_charp str);
|
|
|
|
static void png_user_error(png_structp ctx, png_const_charp str);
|
2010-06-11 15:38:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|