From 5099e2d9fc833b6cd32388e6ed32da921fb541f4 Mon Sep 17 00:00:00 2001 From: stephena Date: Tue, 15 Jun 2010 19:08:05 +0000 Subject: [PATCH] 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 --- debian/rules | 2 +- src/common/PNGLibrary.cxx | 29 ++++++++++++----------------- src/unix/stella.spec | 3 ++- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/debian/rules b/debian/rules index 09b2f3f5e..97c18f3fe 100755 --- a/debian/rules +++ b/debian/rules @@ -20,7 +20,7 @@ endif config.status: configure dh_testdir - CXXFLAGS="$(CXXFLAGS)" ./configure --prefix=/usr + CXXFLAGS="$(CXXFLAGS)" ./configure --prefix=/usr --force-builtin-libpng --force-builtin-zlib build: build-stamp diff --git a/src/common/PNGLibrary.cxx b/src/common/PNGLibrary.cxx index 884741e5c..39fdd305e 100644 --- a/src/common/PNGLibrary.cxx +++ b/src/common/PNGLibrary.cxx @@ -37,7 +37,7 @@ PNGLibrary::~PNGLibrary() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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_infop info_ptr = NULL; @@ -45,22 +45,22 @@ bool PNGLibrary::readImage(const FrameBuffer& fb, FBSurface& surface) png_uint_32 iwidth, iheight, ipitch; uInt8* buffer = NULL; 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); if(!in || !in->is_open()) - readImageERROR("No image found") + readImageERROR("No image found"); // Create the PNG loading context structure png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, png_user_error, png_user_warn); 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. info_ptr = png_create_info_struct(png_ptr); 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 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 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) ipitch = iwidth * 3; buffer = new uInt8[ipitch * iheight]; 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 row_pointers = new png_bytep[iheight]; @@ -103,22 +103,17 @@ bool PNGLibrary::readImage(const FrameBuffer& fb, FBSurface& surface) scaleImagetoSurface(iwidth, iheight, buffer, fb, surface); // Cleanup +done: if(png_ptr) png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : (png_infopp)0, (png_infopp)0); if(in) in->close(); delete[] buffer; - return true; - -error: - if(png_ptr) - 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; + if(err_message) + throw err_message; + else + return true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/unix/stella.spec b/src/unix/stella.spec index 609bceb97..820bd2166 100644 --- a/src/unix/stella.spec +++ b/src/unix/stella.spec @@ -20,7 +20,7 @@ License: GPL URL: http://stella.sourceforge.net Source: %{name}-%{version}.tar.bz2 BuildRoot: %_tmppath/%name-%version-%release-root -BuildRequires: SDL-devel MesaGLU-devel zlib-devel +BuildRequires: SDL-devel MesaGLU-devel %description The Atari 2600 Video Computer System (VCS), introduced in 1977, was the most @@ -65,6 +65,7 @@ export CXXFLAGS=$RPM_OPT_FLAGS %else --enable-shared \ %endif + --force-builtin-libpng --force-builtin-zlib \ --docdir=%{_docdir}/stella \ --x-libraries=%{_prefix}/X11R6/%{_lib}