From 13c3ca9964f156e53aaed053dc96af7d3aa4bdb2 Mon Sep 17 00:00:00 2001 From: stephena Date: Fri, 19 Jul 2013 13:43:42 +0000 Subject: [PATCH] TIA position counters (POSP0, POSM0, etc) in the debugger now show values in decimal, not hex. All DataGridWidgets (ie, most of the inputs in the debugger) have more strict input filtering, allowing to use $,#,\ specifiers for different bases, as well as restricting input based on the specifier used (ie, if you've entered a '\', only '0' and '1' are allowed, etc). Updated libpng to latest version. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2767 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- Changes.txt | 8 ++ src/debugger/DebuggerParser.cxx | 4 +- src/debugger/gui/DataGridWidget.cxx | 60 +++++++++-- src/debugger/gui/PromptWidget.cxx | 1 + src/debugger/gui/TiaWidget.cxx | 45 ++++---- src/debugger/gui/ToggleWidget.cxx | 1 + src/emucore/CompuMate.cxx | 3 +- src/gui/EditableWidget.cxx | 1 + src/libpng/png.c | 6 +- src/libpng/png.h | 28 +++-- src/libpng/pngconf.h | 3 +- src/libpng/pngpread.c | 2 +- src/libpng/pngpriv.h | 153 ++++++++++++++++++++++------ src/libpng/pngrutil.c | 48 +++++---- src/libpng/pngset.c | 13 +-- src/libpng/pngwrite.c | 65 ++++++------ 16 files changed, 300 insertions(+), 141 deletions(-) diff --git a/Changes.txt b/Changes.txt index 6ac231868..c1459467e 100644 --- a/Changes.txt +++ b/Changes.txt @@ -18,6 +18,12 @@ PC didn't match the mirror for the current bank. In this case, the disassembler became confused and didn't properly track the PC address. + * Changed display for various TIA position counters to decimal + (from hex) in the debugger TIA tab. Related to this, all data input + widgets in the debugger UI now have the ability to enter binary, + decimal or hex values by using the proper leading character (\, #, $, + respectively). + * Added ability to modify 'tiadriven' commandline argument to the debugger 'TIA' tab, and 'ramrandom' to the debugger 'I/O' tab. These options were available for quite some time, but they weren't exposed @@ -27,6 +33,8 @@ present in the window title bar. Stella could not be expanded in this way, so the button was removed. + * Updated included PNG library to latest stable version. + -Have fun! diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index b800b2998..724c9ec61 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -175,7 +175,7 @@ void DebuggerParser::getCompletions(const char* in, StringList& completions) con // they're valid, or -1 if they're not. // decipher_arg may be called by the GUI as needed. It is also called // internally by DebuggerParser::run() -int DebuggerParser::decipher_arg(const string &str) +int DebuggerParser::decipher_arg(const string& str) { bool derefByte=false, derefWord=false, lobyte=false, hibyte=false, bin=false, dec=false; int result; @@ -205,7 +205,7 @@ int DebuggerParser::decipher_arg(const string &str) arg.erase(0, 1); } - if(arg.substr(0, 1) == "%") { + if(arg.substr(0, 1) == "\\") { bin = true; dec = false; arg.erase(0, 1); diff --git a/src/debugger/gui/DataGridWidget.cxx b/src/debugger/gui/DataGridWidget.cxx index 0f590709c..4a1668089 100644 --- a/src/debugger/gui/DataGridWidget.cxx +++ b/src/debugger/gui/DataGridWidget.cxx @@ -306,6 +306,7 @@ bool DataGridWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii) switch(key) { case KBDK_RETURN: + case KBDK_KP_ENTER: if (_currentRow >= 0 && _currentCol >= 0) { dirty = true; @@ -649,10 +650,33 @@ void DataGridWidget::endEditMode() if (!_editMode) return; - // send a message that editing finished with a return/enter key press _editMode = false; // Update the both the string representation and the real data + if(_editString.size() > 0 && !(_editString[0] == '$' || + _editString[0] == '#' || _editString[0] == '\\')) + { + switch(_base) + { + case kBASE_16: + case kBASE_16_1: + case kBASE_16_2: + case kBASE_16_4: + case kBASE_16_8: + _editString.insert(0, 1, '$'); + break; + case kBASE_2: + case kBASE_2_8: + case kBASE_2_16: + _editString.insert(0, 1, '\\'); + break; + case kBASE_10: + _editString.insert(0, 1, '#'); + break; + case kBASE_DEFAULT: + break; + } + } int value = instance().debugger().stringToValue(_editString); if(value < _lowerBound || value >= _upperBound) { @@ -674,16 +698,34 @@ void DataGridWidget::abortEditMode() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool DataGridWidget::tryInsertChar(char c, int pos) { - // Not sure how efficient this is, or should we even care? + // Input is very strict here, to eliminate time-consuming error checking + // elsewhere, and includes the following restrictions: + // Cannot contain spaces + // Starts with leading specifier ($, #, \), or with a base character + // Only one specifier is allowed + // If starting with a specifier, only allow numbers applicable to that + // base to follow + c = tolower(c); - if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || - c == '\\' || c == '#' || c == '$') - { + bool isBin = c == '0' || c == '1', + isDec = c >= '0' && c <= '9', + isHex = isDec || (c >= 'a' && c <= 'f'), + isOp = c == '$' || c == '#' || c == '\\', + insert = false; + + if(BSPF_startsWithIgnoreCase(_editString, "$")) + insert = isHex && pos > 0; + else if(BSPF_startsWithIgnoreCase(_editString, "#")) + insert = isDec && pos > 0; + else if(BSPF_startsWithIgnoreCase(_editString, "\\")) + insert = isBin && pos > 0; + else + insert = isHex || isDec || isBin || isOp; + + if(insert) _editString.insert(pos, 1, c); - return true; - } - else - return false; + + return insert; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/gui/PromptWidget.cxx b/src/debugger/gui/PromptWidget.cxx index ff404d861..b3a9a2d11 100644 --- a/src/debugger/gui/PromptWidget.cxx +++ b/src/debugger/gui/PromptWidget.cxx @@ -147,6 +147,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii) switch(key) { case KBDK_RETURN: + case KBDK_KP_ENTER: { nextLine(); diff --git a/src/debugger/gui/TiaWidget.cxx b/src/debugger/gui/TiaWidget.cxx index 87fec1f23..44b42cef6 100644 --- a/src/debugger/gui/TiaWidget.cxx +++ b/src/debugger/gui/TiaWidget.cxx @@ -196,13 +196,14 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& font, // posP0 xpos += myGRP0->getWidth() + 8; t = new StaticTextWidget(boss, font, xpos, ypos+2, - 4*fontWidth, fontHeight, - "Pos:", kTextAlignLeft); - xpos += 4*fontWidth + 5; + 6*fontWidth, fontHeight, + "Pos: #", kTextAlignLeft); + xpos += t->getWidth() + 2; myPosP0 = new DataGridWidget(boss, font, xpos, ypos, - 1, 1, 2, 8, kBASE_16); + 1, 1, 3, 8, kBASE_10); myPosP0->setTarget(this); myPosP0->setID(kPosP0ID); + myPosP0->setRange(0, 160); addFocusWidget(myPosP0); // hmP0 @@ -264,13 +265,14 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& font, // posP1 xpos += myGRP1->getWidth() + 8; - t = new StaticTextWidget(boss, font, xpos, ypos+2, 4*fontWidth, fontHeight, - "Pos:", kTextAlignLeft); - xpos += 4*fontWidth + 5; + t = new StaticTextWidget(boss, font, xpos, ypos+2, 6*fontWidth, fontHeight, + "Pos: #", kTextAlignLeft); + xpos += t->getWidth() + 2; myPosP1 = new DataGridWidget(boss, font, xpos, ypos, - 1, 1, 2, 8, kBASE_16); + 1, 1, 3, 8, kBASE_10); myPosP1->setTarget(this); myPosP1->setID(kPosP1ID); + myPosP1->setRange(0, 160); addFocusWidget(myPosP1); // hmP1 @@ -331,13 +333,14 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& font, // posM0 xpos += myEnaM0->getWidth() + 12; - t = new StaticTextWidget(boss, font, xpos, ypos+2, 4*fontWidth, fontHeight, - "Pos:", kTextAlignLeft); - xpos += 4*fontWidth + 5; + t = new StaticTextWidget(boss, font, xpos, ypos+2, 6*fontWidth, fontHeight, + "Pos: #", kTextAlignLeft); + xpos += t->getWidth() + 2; myPosM0 = new DataGridWidget(boss, font, xpos, ypos, - 1, 1, 2, 8, kBASE_16); + 1, 1, 3, 8, kBASE_10); myPosM0->setTarget(this); myPosM0->setID(kPosM0ID); + myPosM0->setRange(0, 160); addFocusWidget(myPosM0); // hmM0 @@ -386,13 +389,14 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& font, // posM0 xpos += myEnaM1->getWidth() + 12; - t = new StaticTextWidget(boss, font, xpos, ypos+2, 4*fontWidth, fontHeight, - "Pos:", kTextAlignLeft); - xpos += 4*fontWidth + 5; + t = new StaticTextWidget(boss, font, xpos, ypos+2, 6*fontWidth, fontHeight, + "Pos: #", kTextAlignLeft); + xpos += t->getWidth() + 2; myPosM1 = new DataGridWidget(boss, font, xpos, ypos, - 1, 1, 2, 8, kBASE_16); + 1, 1, 3, 8, kBASE_10); myPosM1->setTarget(this); myPosM1->setID(kPosM1ID); + myPosM1->setRange(0, 160); addFocusWidget(myPosM1); // hmM0 @@ -441,13 +445,14 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& font, // posBL xpos += myEnaBL->getWidth() + 12; - t = new StaticTextWidget(boss, font, xpos, ypos+2, 4*fontWidth, fontHeight, - "Pos:", kTextAlignLeft); - xpos += 4*fontWidth + 5; + t = new StaticTextWidget(boss, font, xpos, ypos+2, 6*fontWidth, fontHeight, + "Pos: #", kTextAlignLeft); + xpos += t->getWidth() + 2; myPosBL = new DataGridWidget(boss, font, xpos, ypos, - 1, 1, 2, 8, kBASE_16); + 1, 1, 3, 8, kBASE_10); myPosBL->setTarget(this); myPosBL->setID(kPosBLID); + myPosBL->setRange(0, 160); addFocusWidget(myPosBL); // hmBL diff --git a/src/debugger/gui/ToggleWidget.cxx b/src/debugger/gui/ToggleWidget.cxx index 8a3c1b8de..ba61de73c 100644 --- a/src/debugger/gui/ToggleWidget.cxx +++ b/src/debugger/gui/ToggleWidget.cxx @@ -107,6 +107,7 @@ bool ToggleWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii) switch(key) { case KBDK_RETURN: + case KBDK_KP_ENTER: if (_currentRow >= 0 && _currentCol >= 0) { dirty = true; diff --git a/src/emucore/CompuMate.cxx b/src/emucore/CompuMate.cxx index 92a0f3d8b..52674b45a 100644 --- a/src/emucore/CompuMate.cxx +++ b/src/emucore/CompuMate.cxx @@ -145,7 +145,8 @@ void CompuMate::update() lp.myDigitalPinState[Controller::Six] = false; } if (myKeyTable[KBDK_p]) rp.myDigitalPinState[Controller::Three] = false; - if (myKeyTable[KBDK_RETURN]) rp.myDigitalPinState[Controller::Six] = false; + if (myKeyTable[KBDK_RETURN] || myKeyTable[KBDK_KP_ENTER]) + rp.myDigitalPinState[Controller::Six] = false; if (myKeyTable[KBDK_SPACE]) rp.myDigitalPinState[Controller::Four] = false; // Emulate Ctrl-space (aka backspace) with the actual Backspace key if (myKeyTable[KBDK_BACKSPACE]) diff --git a/src/gui/EditableWidget.cxx b/src/gui/EditableWidget.cxx index 396932b3f..6b7ca69cd 100644 --- a/src/gui/EditableWidget.cxx +++ b/src/gui/EditableWidget.cxx @@ -102,6 +102,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii) switch(key) { case KBDK_RETURN: + case KBDK_KP_ENTER: // confirm edit and exit editmode endEditMode(); sendCommand(EditableWidget::kAcceptCmd, 0, _id); diff --git a/src/libpng/png.c b/src/libpng/png.c index d429c527c..734188189 100644 --- a/src/libpng/png.c +++ b/src/libpng/png.c @@ -14,7 +14,7 @@ #include "pngpriv.h" /* Generate a compiler error if there is an old png.h in the search path. */ -typedef png_libpng_version_1_6_2 Your_png_h_is_not_version_1_6_2; +typedef png_libpng_version_1_6_3 Your_png_h_is_not_version_1_6_3; /* Tells libpng that we have already handled the first "num_bytes" bytes * of the PNG file signature. If the PNG data is embedded into another @@ -768,13 +768,13 @@ png_get_copyright(png_const_structrp png_ptr) #else # ifdef __STDC__ return PNG_STRING_NEWLINE \ - "libpng version 1.6.2 - April 25, 2013" PNG_STRING_NEWLINE \ + "libpng version 1.6.3 - July 18, 2013" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2013 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ PNG_STRING_NEWLINE; # else - return "libpng version 1.6.2 - April 25, 2013\ + return "libpng version 1.6.3 - July 18, 2013\ Copyright (c) 1998-2013 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; diff --git a/src/libpng/png.h b/src/libpng/png.h index 0b5053fcf..cf1a27ced 100644 --- a/src/libpng/png.h +++ b/src/libpng/png.h @@ -1,7 +1,7 @@ /* png.h - header file for PNG reference library * - * libpng version 1.6.2 - April 25, 2013 + * libpng version 1.6.3 - July 18, 2013 * Copyright (c) 1998-2013 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -11,7 +11,7 @@ * Authors and maintainers: * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.6.2 - April 25, 2013: Glenn + * libpng versions 0.97, January 1998, through 1.6.3 - July 18, 2013: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -175,6 +175,9 @@ * 1.6.2beta01 16 10602 16.so.16.2[.0] * 1.6.2rc01-06 16 10602 16.so.16.2[.0] * 1.6.2 16 10602 16.so.16.2[.0] + * 1.6.3beta01-11 16 10603 16.so.16.3[.0] + * 1.6.3rc01 16 10603 16.so.16.3[.0] + * 1.6.3 16 10603 16.so.16.3[.0] * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be @@ -206,7 +209,7 @@ * * This code is released under the libpng license. * - * libpng versions 1.2.6, August 15, 2004, through 1.6.2, April 25, 2013, are + * libpng versions 1.2.6, August 15, 2004, through 1.6.3, July 18, 2013, are * Copyright (c) 2004, 2006-2013 Glenn Randers-Pehrson, and are * distributed according to the same disclaimer and license as libpng-1.2.5 * with the following individual added to the list of Contributing Authors: @@ -318,13 +321,13 @@ * Y2K compliance in libpng: * ========================= * - * April 25, 2013 + * July 18, 2013 * * Since the PNG Development group is an ad-hoc body, we can't make * an official declaration. * * This is your unofficial assurance that libpng from version 0.71 and - * upward through 1.6.2 are Y2K compliant. It is my belief that + * upward through 1.6.3 are Y2K compliant. It is my belief that * earlier versions were also Y2K compliant. * * Libpng only has two year fields. One is a 2-byte unsigned integer @@ -384,9 +387,9 @@ */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.6.2" +#define PNG_LIBPNG_VER_STRING "1.6.3" #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.6.2 - April 25, 2013\n" + " libpng version 1.6.3 - July 18, 2013\n" #define PNG_LIBPNG_VER_SONUM 16 #define PNG_LIBPNG_VER_DLLNUM 16 @@ -394,7 +397,7 @@ /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ #define PNG_LIBPNG_VER_MAJOR 1 #define PNG_LIBPNG_VER_MINOR 6 -#define PNG_LIBPNG_VER_RELEASE 2 +#define PNG_LIBPNG_VER_RELEASE 3 /* This should match the numeric part of the final component of * PNG_LIBPNG_VER_STRING, omitting any leading zero: @@ -425,7 +428,7 @@ * version 1.0.0 was mis-numbered 100 instead of 10000). From * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */ -#define PNG_LIBPNG_VER 10602 /* 1.6.2 */ +#define PNG_LIBPNG_VER 10603 /* 1.6.3 */ /* Library configuration: these options cannot be changed after * the library has been built. @@ -530,7 +533,7 @@ extern "C" { /* This triggers a compiler error in png.c, if png.c and png.h * do not agree upon the version number. */ -typedef char* png_libpng_version_1_6_2; +typedef char* png_libpng_version_1_6_3; /* Basic control structions. Read libpng-manual.txt or libpng.3 for more info. * @@ -3186,6 +3189,7 @@ PNG_EXPORT(238, void, png_image_free, (png_imagep image)); #endif /* PNG_SIMPLIFIED_READ_SUPPORTED */ #ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED +#ifdef PNG_STDIO_SUPPORTED /* WRITE APIS * ---------- * For write you must initialize a png_image structure to describe the image to @@ -3228,6 +3232,7 @@ PNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file, * * Note that the write API does not support interlacing or sub-8-bit pixels. */ +#endif /* PNG_STDIO_SUPPORTED */ #endif /* PNG_SIMPLIFIED_WRITE_SUPPORTED */ /******************************************************************************* * END OF SIMPLIFIED API @@ -3267,7 +3272,8 @@ PNG_EXPORT(243, int, png_get_palette_max, (png_const_structp png_ptr, #ifdef PNG_ARM_NEON_API_SUPPORTED # define PNG_ARM_NEON 0 /* HARDWARE: ARM Neon SIMD instructions supported */ #endif -#define PNG_OPTION_NEXT 2 /* Next option - numbers must be even */ +#define PNG_MAXIMUM_INFLATE_WINDOW 2 /* SOFTWARE: force maximum window */ +#define PNG_OPTION_NEXT 4 /* Next option - numbers must be even */ /* Return values: NOTE: there are four values and 'off' is *not* zero */ #define PNG_OPTION_UNSET 0 /* Unset - defaults to off */ diff --git a/src/libpng/pngconf.h b/src/libpng/pngconf.h index 31f996757..0808c1ced 100644 --- a/src/libpng/pngconf.h +++ b/src/libpng/pngconf.h @@ -1,7 +1,7 @@ /* pngconf.h - machine configurable file for libpng * - * libpng version 1.6.2 - April 25, 2013 + * libpng version 1.6.3 - July 18, 2013 * * Copyright (c) 1998-2013 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -238,6 +238,7 @@ # define PNGAPI _stdcall # endif # endif /* compiler/api */ + /* NOTE: PNGCBAPI always defaults to PNGCAPI. */ # if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD) diff --git a/src/libpng/pngpread.c b/src/libpng/pngpread.c index f132ce600..0169ecb2c 100644 --- a/src/libpng/pngpread.c +++ b/src/libpng/pngpread.c @@ -151,7 +151,7 @@ png_process_some_data(png_structrp png_ptr, png_inforp info_ptr) void /* PRIVATE */ png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr) { - png_size_t num_checked = png_ptr->sig_bytes, + png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */ num_to_check = 8 - num_checked; if (png_ptr->buffer_size < num_to_check) diff --git a/src/libpng/pngpriv.h b/src/libpng/pngpriv.h index d06284d1e..4d8051f92 100644 --- a/src/libpng/pngpriv.h +++ b/src/libpng/pngpriv.h @@ -6,7 +6,7 @@ * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * - * Last changed in libpng 1.6.2 [April 25, 2013] + * Last changed in libpng 1.6.3 [July 18, 2013] * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer @@ -88,6 +88,46 @@ # endif #endif +/* Compile time options. + * ===================== + * In a multi-arch build the compiler may compile the code several times for the + * same object module, producing different binaries for different architectures. + * When this happens configure-time setting of the target host options cannot be + * done and this interferes with the handling of the ARM NEON optimizations, and + * possibly other similar optimizations. Put additional tests here; in general + * this is needed when the same option can be changed at both compile time and + * run time depending on the target OS (i.e. iOS vs Android.) + * + * NOTE: symbol prefixing does not pass $(CFLAGS) to the preprocessor, because + * this is not possible with certain compilers (Oracle SUN OS CC), as a result + * it is necessary to ensure that all extern functions that *might* be used + * regardless of $(CFLAGS) get declared in this file. The test on __ARM_NEON__ + * below is one example of this behavior because it is controlled by the + * presence or not of -mfpu=neon on the GCC command line, it is possible to do + * this in $(CC), e.g. "CC=gcc -mfpu=neon", but people who build libpng rarely + * do this. + */ +#ifndef PNG_ARM_NEON_OPT + /* ARM NEON optimizations are being controlled by the compiler settings, + * typically the target FPU. If the FPU has been set to NEON (-mfpu=neon + * with GCC) then the compiler will define __ARM_NEON__ and we can rely + * unconditionally on NEON instructions not crashing, otherwise we must + * disable use of NEON instructions: + */ +# ifdef __ARM_NEON__ +# define PNG_ARM_NEON_OPT 2 +# else +# define PNG_ARM_NEON_OPT 0 +# endif +#endif + +#if PNG_ARM_NEON_OPT > 0 + /* NEON optimizations are to be at least considered by libpng, so enable the + * callbacks to do this. + */ +# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_neon +#endif + /* Is this a build of a DLL where compilation of the object modules requires * different preprocessor settings to those required for a simple library? If * so PNG_BUILD_DLL must be set. @@ -630,37 +670,64 @@ * architectures where (int) is only 16 bits. */ #define PNG_32b(b,s) ((png_uint_32)(b) << (s)) -#define PNG_CHUNK(b1,b2,b3,b4) \ +#define PNG_U32(b1,b2,b3,b4) \ (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0)) -#define png_IHDR PNG_CHUNK( 73, 72, 68, 82) -#define png_IDAT PNG_CHUNK( 73, 68, 65, 84) -#define png_IEND PNG_CHUNK( 73, 69, 78, 68) -#define png_PLTE PNG_CHUNK( 80, 76, 84, 69) -#define png_bKGD PNG_CHUNK( 98, 75, 71, 68) -#define png_cHRM PNG_CHUNK( 99, 72, 82, 77) -#define png_gAMA PNG_CHUNK(103, 65, 77, 65) -#define png_hIST PNG_CHUNK(104, 73, 83, 84) -#define png_iCCP PNG_CHUNK(105, 67, 67, 80) -#define png_iTXt PNG_CHUNK(105, 84, 88, 116) -#define png_oFFs PNG_CHUNK(111, 70, 70, 115) -#define png_pCAL PNG_CHUNK(112, 67, 65, 76) -#define png_sCAL PNG_CHUNK(115, 67, 65, 76) -#define png_pHYs PNG_CHUNK(112, 72, 89, 115) -#define png_sBIT PNG_CHUNK(115, 66, 73, 84) -#define png_sPLT PNG_CHUNK(115, 80, 76, 84) -#define png_sRGB PNG_CHUNK(115, 82, 71, 66) -#define png_sTER PNG_CHUNK(115, 84, 69, 82) -#define png_tEXt PNG_CHUNK(116, 69, 88, 116) -#define png_tIME PNG_CHUNK(116, 73, 77, 69) -#define png_tRNS PNG_CHUNK(116, 82, 78, 83) -#define png_zTXt PNG_CHUNK(122, 84, 88, 116) +/* Constants for known chunk types. + * + * MAINTAINERS: If you need to add a chunk, define the name here. + * For historical reasons these constants have the form png_; i.e. + * the prefix is lower case. Please use decimal values as the parameters to + * match the ISO PNG specification and to avoid relying on the C locale + * interpretation of character values. Please keep the list sorted. + * + * Notice that PNG_U32 is used to define a 32-bit value for the 4 byte chunk + * type. In fact the specification does not express chunk types this way, + * however using a 32-bit value means that the chunk type can be read from the + * stream using exactly the same code as used for a 32-bit unsigned value and + * can be examined far more efficiently (using one arithmetic compare). + * + * Prior to 1.5.6 the chunk type constants were expressed as C strings. The + * libpng API still uses strings for 'unknown' chunks and a macro, + * PNG_STRING_FROM_CHUNK, allows a string to be generated if required. Notice + * that for portable code numeric values must still be used; the string "IHDR" + * is not portable and neither is PNG_U32('I', 'H', 'D', 'R'). + * + * In 1.7.0 the definitions will be made public in png.h to avoid having to + * duplicate the same definitions in application code. + */ +#define png_IDAT PNG_U32( 73, 68, 65, 84) +#define png_IEND PNG_U32( 73, 69, 78, 68) +#define png_IHDR PNG_U32( 73, 72, 68, 82) +#define png_PLTE PNG_U32( 80, 76, 84, 69) +#define png_bKGD PNG_U32( 98, 75, 71, 68) +#define png_cHRM PNG_U32( 99, 72, 82, 77) +#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */ +#define png_gAMA PNG_U32(103, 65, 77, 65) +#define png_gIFg PNG_U32(103, 73, 70, 103) +#define png_gIFt PNG_U32(103, 73, 70, 116) /* deprecated */ +#define png_gIFx PNG_U32(103, 73, 70, 120) +#define png_hIST PNG_U32(104, 73, 83, 84) +#define png_iCCP PNG_U32(105, 67, 67, 80) +#define png_iTXt PNG_U32(105, 84, 88, 116) +#define png_oFFs PNG_U32(111, 70, 70, 115) +#define png_pCAL PNG_U32(112, 67, 65, 76) +#define png_pHYs PNG_U32(112, 72, 89, 115) +#define png_sBIT PNG_U32(115, 66, 73, 84) +#define png_sCAL PNG_U32(115, 67, 65, 76) +#define png_sPLT PNG_U32(115, 80, 76, 84) +#define png_sRGB PNG_U32(115, 82, 71, 66) +#define png_sTER PNG_U32(115, 84, 69, 82) +#define png_tEXt PNG_U32(116, 69, 88, 116) +#define png_tIME PNG_U32(116, 73, 77, 69) +#define png_tRNS PNG_U32(116, 82, 78, 83) +#define png_zTXt PNG_U32(122, 84, 88, 116) /* The following will work on (signed char*) strings, whereas the get_uint_32 * macro will fail on top-bit-set values because of the sign extension. */ #define PNG_CHUNK_FROM_STRING(s)\ - PNG_CHUNK(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3]) + PNG_U32(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3]) /* This uses (char), not (png_byte) to avoid warnings on systems where (char) is * signed and the argument is a (char[]) This macro will fail miserably on @@ -694,6 +761,24 @@ #include "pngstruct.h" #include "pnginfo.h" +/* Validate the include paths - the include path used to generate pnglibconf.h + * must match that used in the build, or we must be using pnglibconf.h.prebuilt: + */ +#if PNG_ZLIB_VERNUM != 0 && PNG_ZLIB_VERNUM != ZLIB_VERNUM +# error ZLIB_VERNUM != PNG_ZLIB_VERNUM \ + "-I (include path) error: see the notes in pngpriv.h" + /* This means that when pnglibconf.h was built the copy of zlib.h that it + * used is not the same as the one being used here. Because the build of + * libpng makes decisions to use inflateInit2 and inflateReset2 based on the + * zlib version number and because this affects handling of certain broken + * PNG files the -I directives must match. + * + * The most likely explanation is that you passed a -I in CFLAGS, this will + * not work; all the preprocessor directories and in particular all the -I + * directives must be in CPPFLAGS. + */ +#endif + /* This is used for 16 bit gamma tables -- only the top level pointers are * const; this could be changed: */ @@ -1891,14 +1976,22 @@ PNG_INTERNAL_FUNCTION(void, png_image_free, (png_imagep image), PNG_EMPTY); #endif /* SIMPLIFIED READ/WRITE */ +/* These are initialization functions for hardware specific PNG filter + * optimizations; list these here then select the appropriate one at compile + * time using the macro PNG_FILTER_OPTIMIZATIONS. If the macro is not defined + * the generic code is used. + */ #ifdef PNG_FILTER_OPTIMIZATIONS PNG_INTERNAL_FUNCTION(void, PNG_FILTER_OPTIMIZATIONS, (png_structp png_ptr, - unsigned int bpp), PNG_EMPTY); - /* This is the initialization function for hardware specific optimizations, - * one implementation (for ARM NEON machines) is contained in - * arm/filter_neon.c. It need not be defined - the generic code will be used - * if not. + unsigned int bpp), PNG_EMPTY); + /* Just declare the optimization that will be used */ +#else + /* List *all* the possible optimizations here - this branch is required if + * the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in + * CFLAGS in place of CPPFLAGS *and* uses symbol prefixing. */ +PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon, + (png_structp png_ptr, unsigned int bpp), PNG_EMPTY); #endif /* Maintainer: Put new private prototypes here ^ */ diff --git a/src/libpng/pngrutil.c b/src/libpng/pngrutil.c index 01c3679df..0a75cd81c 100644 --- a/src/libpng/pngrutil.c +++ b/src/libpng/pngrutil.c @@ -1,7 +1,7 @@ /* pngrutil.c - utilities to read a PNG file * - * Last changed in libpng 1.6.2 [April 25, 2013] + * Last changed in libpng 1.6.3 [July 18, 2013] * Copyright (c) 1998-2013 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -18,8 +18,6 @@ #ifdef PNG_READ_SUPPORTED -#define png_strtod(p,a,b) strtod(a,b) - png_uint_32 PNGAPI png_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf) { @@ -334,7 +332,7 @@ png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn) * chunk apparently owns the stream. Prior to release it does a png_error. */ static int -png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits) +png_inflate_claim(png_structrp png_ptr, png_uint_32 owner) { if (png_ptr->zowner != 0) { @@ -369,6 +367,22 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits) */ { int ret; /* zlib return code */ +# if PNG_ZLIB_VERNUM >= 0x1240 + +# if defined(PNG_SET_OPTION_SUPPORTED) && \ + defined(PNG_MAXIMUM_INFLATE_WINDOW) + int window_bits; + + if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) == + PNG_OPTION_ON) + window_bits = 15; + + else + window_bits = 0; +# else +# define window_bits 0 +# endif +# endif /* Set this for safety, just in case the previous owner left pointers to * memory allocations. @@ -380,8 +394,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits) if (png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) { -# if ZLIB_VERNUM < 0x1240 - PNG_UNUSED(window_bits) +# if PNG_ZLIB_VERNUM < 0x1240 ret = inflateReset(&png_ptr->zstream); # else ret = inflateReset2(&png_ptr->zstream, window_bits); @@ -390,7 +403,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits) else { -# if ZLIB_VERNUM < 0x1240 +# if PNG_ZLIB_VERNUM < 0x1240 ret = inflateInit(&png_ptr->zstream); # else ret = inflateInit2(&png_ptr->zstream, window_bits); @@ -408,6 +421,10 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner, int window_bits) return ret; } + +# ifdef window_bits +# undef window_bits +# endif } #ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED @@ -580,14 +597,8 @@ png_decompress_chunk(png_structrp png_ptr, if (limit < *newlength) *newlength = limit; - /* Now try to claim the stream; the 'warn' setting causes zlib to be told - * to use the maximum window size during inflate; this hides errors in the - * deflate header window bits value which is used if '0' is passed. In - * fact this only has an effect with zlib versions 1.2.4 and later - see - * the comments in png_inflate_claim above. - */ - ret = png_inflate_claim(png_ptr, png_ptr->chunk_name, - png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN ? 15 : 0); + /* Now try to claim the stream. */ + ret = png_inflate_claim(png_ptr, png_ptr->chunk_name); if (ret == Z_OK) { @@ -1357,8 +1368,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { read_length -= keyword_length+2; - if (png_inflate_claim(png_ptr, png_iCCP, - png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN ? 15 : 0) == Z_OK) + if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK) { Byte profile_header[132]; Byte local_buffer[PNG_INFLATE_BUF_SIZE]; @@ -3684,7 +3694,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, for (i = 0; i < row_info->width; i++) { - png_byte v[8]; + png_byte v[8]; /* SAFE; pixel_depth does not exceed 64 */ int j; memcpy(v, sp, pixel_bytes); @@ -4454,7 +4464,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) * IDAT stream has a bogus deflate header window_bits value, but this should * not be happening any longer!) */ - if (png_inflate_claim(png_ptr, png_IDAT, 0) != Z_OK) + if (png_inflate_claim(png_ptr, png_IDAT) != Z_OK) png_error(png_ptr, png_ptr->zstream.msg); png_ptr->flags |= PNG_FLAG_ROW_INIT; diff --git a/src/libpng/pngset.c b/src/libpng/pngset.c index fcb077913..7e355d1f4 100644 --- a/src/libpng/pngset.c +++ b/src/libpng/pngset.c @@ -1,7 +1,7 @@ /* pngset.c - storage of image information into info struct * - * Last changed in libpng 1.6.2 [April 25, 2013] + * Last changed in libpng 1.6.3 [July 18, 2013] * Copyright (c) 1998-2013 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -238,16 +238,7 @@ png_set_IHDR(png_const_structrp png_ptr, png_inforp info_ptr, info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); - /* Check for potential overflow */ - if (width > - (PNG_UINT_32_MAX >> 3) /* 8-byte RRGGBBAA pixels */ - - 48 /* bigrowbuf hack */ - - 1 /* filter byte */ - - 7*8 /* rounding of width to multiple of 8 pixels */ - - 8) /* extra max_pixel_depth pad */ - info_ptr->rowbytes = 0; - else - info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); + info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); } #ifdef PNG_oFFs_SUPPORTED diff --git a/src/libpng/pngwrite.c b/src/libpng/pngwrite.c index 33924aac0..b71a3d345 100644 --- a/src/libpng/pngwrite.c +++ b/src/libpng/pngwrite.c @@ -494,51 +494,50 @@ png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, png_structrp png_ptr = png_create_png_struct(user_png_ver, error_ptr, error_fn, warn_fn, mem_ptr, malloc_fn, free_fn); #endif /* PNG_USER_MEM_SUPPORTED */ + if (png_ptr != NULL) + { + /* Set the zlib control values to defaults; they can be overridden by the + * application after the struct has been created. + */ + png_ptr->zbuffer_size = PNG_ZBUF_SIZE; - /* Set the zlib control values to defaults; they can be overridden by the - * application after the struct has been created. - */ - png_ptr->zbuffer_size = PNG_ZBUF_SIZE; - - /* The 'zlib_strategy' setting is irrelevant because png_default_claim in - * pngwutil.c defaults it according to whether or not filters will be used, - * and ignores this setting. - */ - png_ptr->zlib_strategy = PNG_Z_DEFAULT_STRATEGY; - png_ptr->zlib_level = PNG_Z_DEFAULT_COMPRESSION; - png_ptr->zlib_mem_level = 8; - png_ptr->zlib_window_bits = 15; - png_ptr->zlib_method = 8; + /* The 'zlib_strategy' setting is irrelevant because png_default_claim in + * pngwutil.c defaults it according to whether or not filters will be + * used, and ignores this setting. + */ + png_ptr->zlib_strategy = PNG_Z_DEFAULT_STRATEGY; + png_ptr->zlib_level = PNG_Z_DEFAULT_COMPRESSION; + png_ptr->zlib_mem_level = 8; + png_ptr->zlib_window_bits = 15; + png_ptr->zlib_method = 8; #ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED - png_ptr->zlib_text_strategy = PNG_TEXT_Z_DEFAULT_STRATEGY; - png_ptr->zlib_text_level = PNG_TEXT_Z_DEFAULT_COMPRESSION; - png_ptr->zlib_text_mem_level = 8; - png_ptr->zlib_text_window_bits = 15; - png_ptr->zlib_text_method = 8; + png_ptr->zlib_text_strategy = PNG_TEXT_Z_DEFAULT_STRATEGY; + png_ptr->zlib_text_level = PNG_TEXT_Z_DEFAULT_COMPRESSION; + png_ptr->zlib_text_mem_level = 8; + png_ptr->zlib_text_window_bits = 15; + png_ptr->zlib_text_method = 8; #endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */ - /* This is a highly dubious configuration option; by default it is off, but - * it may be appropriate for private builds that are testing extensions not - * conformant to the current specification, or of applications that must not - * fail to write at all costs! - */ -# ifdef PNG_BENIGN_WRITE_ERRORS_SUPPORTED + /* This is a highly dubious configuration option; by default it is off, + * but it may be appropriate for private builds that are testing + * extensions not conformant to the current specification, or of + * applications that must not fail to write at all costs! + */ +#ifdef PNG_BENIGN_WRITE_ERRORS_SUPPORTED png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; /* In stable builds only warn if an application error can be completely * handled. */ -# endif +#endif - /* App warnings are warnings in release (or release candidate) builds but - * are errors during development. - */ -# if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC + /* App warnings are warnings in release (or release candidate) builds but + * are errors during development. + */ +#if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN; -# endif +#endif - if (png_ptr != NULL) - { /* TODO: delay this, it can be done in png_init_io() (if the app doesn't * do it itself) avoiding setting the default function if it is not * required.