mirror of https://github.com/stella-emu/stella.git
Some minor cleanups in the PNGLibrary class.
The UNIX builds for Debian and Redhat/RPM now default to using the builtin PNG and zlib libraries. This will ease issues at release time, since we don't need to worry about those libraries being present on the destination systems. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2054 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
ad83d21a69
commit
5099e2d9fc
|
@ -20,7 +20,7 @@ endif
|
||||||
|
|
||||||
config.status: configure
|
config.status: configure
|
||||||
dh_testdir
|
dh_testdir
|
||||||
CXXFLAGS="$(CXXFLAGS)" ./configure --prefix=/usr
|
CXXFLAGS="$(CXXFLAGS)" ./configure --prefix=/usr --force-builtin-libpng --force-builtin-zlib
|
||||||
|
|
||||||
build: build-stamp
|
build: build-stamp
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ PNGLibrary::~PNGLibrary()
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool PNGLibrary::readImage(const FrameBuffer& fb, FBSurface& surface)
|
bool PNGLibrary::readImage(const FrameBuffer& fb, FBSurface& surface)
|
||||||
{
|
{
|
||||||
#define readImageERROR(s) { err_message = s; goto error; }
|
#define readImageERROR(s) { err_message = s; goto done; }
|
||||||
|
|
||||||
png_structp png_ptr = NULL;
|
png_structp png_ptr = NULL;
|
||||||
png_infop info_ptr = NULL;
|
png_infop info_ptr = NULL;
|
||||||
|
@ -45,22 +45,22 @@ bool PNGLibrary::readImage(const FrameBuffer& fb, FBSurface& surface)
|
||||||
png_uint_32 iwidth, iheight, ipitch;
|
png_uint_32 iwidth, iheight, ipitch;
|
||||||
uInt8* buffer = NULL;
|
uInt8* buffer = NULL;
|
||||||
int bit_depth, color_type, interlace_type;
|
int bit_depth, color_type, interlace_type;
|
||||||
const char* err_message;
|
const char* err_message = NULL;
|
||||||
|
|
||||||
ifstream* in = new ifstream(myFilename.c_str(), ios_base::binary);
|
ifstream* in = new ifstream(myFilename.c_str(), ios_base::binary);
|
||||||
if(!in || !in->is_open())
|
if(!in || !in->is_open())
|
||||||
readImageERROR("No image found")
|
readImageERROR("No image found");
|
||||||
|
|
||||||
// Create the PNG loading context structure
|
// Create the PNG loading context structure
|
||||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
|
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
|
||||||
png_user_error, png_user_warn);
|
png_user_error, png_user_warn);
|
||||||
if(png_ptr == NULL)
|
if(png_ptr == NULL)
|
||||||
readImageERROR("Couldn't allocate memory for PNG file")
|
readImageERROR("Couldn't allocate memory for PNG file");
|
||||||
|
|
||||||
// Allocate/initialize the memory for image information. REQUIRED.
|
// Allocate/initialize the memory for image information. REQUIRED.
|
||||||
info_ptr = png_create_info_struct(png_ptr);
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
if(info_ptr == NULL)
|
if(info_ptr == NULL)
|
||||||
readImageERROR("Couldn't create image information for PNG file")
|
readImageERROR("Couldn't create image information for PNG file");
|
||||||
|
|
||||||
// Set up the input control
|
// Set up the input control
|
||||||
png_set_read_fn(png_ptr, in, png_read_data);
|
png_set_read_fn(png_ptr, in, png_read_data);
|
||||||
|
@ -79,13 +79,13 @@ bool PNGLibrary::readImage(const FrameBuffer& fb, FBSurface& surface)
|
||||||
|
|
||||||
// Greyscale mode not supported
|
// Greyscale mode not supported
|
||||||
if(color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
if(color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
readImageERROR("Greyscale PNG images not supported")
|
readImageERROR("Greyscale PNG images not supported");
|
||||||
|
|
||||||
// Create space for the entire image (3 bytes per pixel in RGB format)
|
// Create space for the entire image (3 bytes per pixel in RGB format)
|
||||||
ipitch = iwidth * 3;
|
ipitch = iwidth * 3;
|
||||||
buffer = new uInt8[ipitch * iheight];
|
buffer = new uInt8[ipitch * iheight];
|
||||||
if(buffer == NULL)
|
if(buffer == NULL)
|
||||||
readImageERROR("Not enough memory to read PNG file")
|
readImageERROR("Not enough memory to read PNG file");
|
||||||
|
|
||||||
// The PNG read function expects an array of rows, not a single 1-D array
|
// The PNG read function expects an array of rows, not a single 1-D array
|
||||||
row_pointers = new png_bytep[iheight];
|
row_pointers = new png_bytep[iheight];
|
||||||
|
@ -103,22 +103,17 @@ bool PNGLibrary::readImage(const FrameBuffer& fb, FBSurface& surface)
|
||||||
scaleImagetoSurface(iwidth, iheight, buffer, fb, surface);
|
scaleImagetoSurface(iwidth, iheight, buffer, fb, surface);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
done:
|
||||||
if(png_ptr)
|
if(png_ptr)
|
||||||
png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : (png_infopp)0, (png_infopp)0);
|
png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : (png_infopp)0, (png_infopp)0);
|
||||||
if(in)
|
if(in)
|
||||||
in->close();
|
in->close();
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
|
|
||||||
return true;
|
if(err_message)
|
||||||
|
throw err_message;
|
||||||
error:
|
else
|
||||||
if(png_ptr)
|
return true;
|
||||||
png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : (png_infopp)0, (png_infopp)0);
|
|
||||||
if(in)
|
|
||||||
in->close();
|
|
||||||
delete[] buffer;
|
|
||||||
|
|
||||||
throw err_message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -20,7 +20,7 @@ License: GPL
|
||||||
URL: http://stella.sourceforge.net
|
URL: http://stella.sourceforge.net
|
||||||
Source: %{name}-%{version}.tar.bz2
|
Source: %{name}-%{version}.tar.bz2
|
||||||
BuildRoot: %_tmppath/%name-%version-%release-root
|
BuildRoot: %_tmppath/%name-%version-%release-root
|
||||||
BuildRequires: SDL-devel MesaGLU-devel zlib-devel
|
BuildRequires: SDL-devel MesaGLU-devel
|
||||||
|
|
||||||
%description
|
%description
|
||||||
The Atari 2600 Video Computer System (VCS), introduced in 1977, was the most
|
The Atari 2600 Video Computer System (VCS), introduced in 1977, was the most
|
||||||
|
@ -65,6 +65,7 @@ export CXXFLAGS=$RPM_OPT_FLAGS
|
||||||
%else
|
%else
|
||||||
--enable-shared \
|
--enable-shared \
|
||||||
%endif
|
%endif
|
||||||
|
--force-builtin-libpng --force-builtin-zlib \
|
||||||
--docdir=%{_docdir}/stella \
|
--docdir=%{_docdir}/stella \
|
||||||
--x-libraries=%{_prefix}/X11R6/%{_lib}
|
--x-libraries=%{_prefix}/X11R6/%{_lib}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue