diff -ru4N libpng-1.2.25/contrib/gregbook/LICENSE libpng-1.2.26beta04/contrib/gregbook/LICENSE --- libpng-1.2.25/contrib/gregbook/LICENSE Mon Feb 18 16:31:09 2008 +++ libpng-1.2.26beta04/contrib/gregbook/LICENSE Tue Mar 18 17:37:50 2008 @@ -1,7 +1,7 @@ --------------------------------------------------------------------------- - Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of diff -ru4N libpng-1.2.25/contrib/gregbook/README libpng-1.2.26beta04/contrib/gregbook/README --- libpng-1.2.25/contrib/gregbook/README Mon Feb 18 16:31:09 2008 +++ libpng-1.2.26beta04/contrib/gregbook/README Tue Mar 18 17:37:50 2008 @@ -55,9 +55,9 @@ 13-15 of the book for detailed discussion of the three programs. Greg Roelofs http://pobox.com/~newt/greg_contact.html -2 June 2007 +16 March 2008 BUILD INSTRUCTIONS diff -ru4N libpng-1.2.25/contrib/gregbook/readpng2.h libpng-1.2.26beta04/contrib/gregbook/readpng2.h --- libpng-1.2.25/contrib/gregbook/readpng2.h Mon Feb 18 16:31:09 2008 +++ libpng-1.2.26beta04/contrib/gregbook/readpng2.h Tue Mar 18 17:37:50 2008 @@ -3,9 +3,9 @@ rpng2 - progressive-model PNG display program readpng2.h --------------------------------------------------------------------------- - Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of @@ -68,8 +68,14 @@ #else # define Trace(x) ; #endif +enum rpng2_states { + kPreInit = 0, + kWindowInit, + kDone +}; + typedef unsigned char uch; typedef unsigned short ush; typedef unsigned long ulg; @@ -94,9 +100,9 @@ int nommxfilters; int nommxcombine; int nommxinterlace; #endif - int done; + int state; uch bg_red; uch bg_green; uch bg_blue; } mainprog_info; diff -ru4N libpng-1.2.25/contrib/gregbook/rpng-win.c libpng-1.2.26beta04/contrib/gregbook/rpng-win.c --- libpng-1.2.25/contrib/gregbook/rpng-win.c Mon Feb 18 16:31:09 2008 +++ libpng-1.2.26beta04/contrib/gregbook/rpng-win.c Tue Mar 18 17:37:50 2008 @@ -22,12 +22,13 @@ - 1.02: added extra set of parentheses to png_jmpbuf() macro; fixed command-line parsing bug - 1.10: enabled "message window"/console (thanks to David Geldreich) - 2.00: dual-licensed (added GNU GPL) + - 2.01: fixed improper display of usage screen on PNG error(s) --------------------------------------------------------------------------- - Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of @@ -76,9 +77,9 @@ ---------------------------------------------------------------------------*/ #define PROGNAME "rpng-win" #define LONGNAME "Simple PNG Viewer for Windows" -#define VERSION "2.00 of 2 June 2007" +#define VERSION "2.01 of 16 March 2008" #include #include #include @@ -270,11 +271,39 @@ ++error; /* not expecting any other options */ } } - if (!filename) { + if (!filename) ++error; - } else if (!(infile = fopen(filename, "rb"))) { + + + /* print usage screen if any errors up to this point */ + + if (error) { + int ch; + + fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); + readpng_version_info(); + fprintf(stderr, "\n" + "Usage: %s [-gamma exp] [-bgcolor bg] file.png\n" + " exp \ttransfer-function exponent (``gamma'') of the display\n" + "\t\t system in floating-point format (e.g., ``%.1f''); equal\n" + "\t\t to the product of the lookup-table exponent (varies)\n" + "\t\t and the CRT exponent (usually 2.2); must be positive\n" + " bg \tdesired background color in 7-character hex RGB format\n" + "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" + "\t\t used with transparent images\n" + "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n" + "Press Q or Esc to quit this usage screen.\n" + "\n", PROGNAME, default_display_exponent); + do + ch = _getch(); + while (ch != 'q' && ch != 'Q' && ch != 0x1B); + exit(1); + } + + + if (!(infile = fopen(filename, "rb"))) { fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); ++error; } else { if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) { @@ -285,10 +314,9 @@ filename); break; case 2: fprintf(stderr, PROGNAME - ": [%s] has bad IHDR (libpng longjmp)\n", - filename); + ": [%s] has bad IHDR (libpng longjmp)\n", filename); break; case 4: fprintf(stderr, PROGNAME ": insufficient memory\n"); break; @@ -303,31 +331,16 @@ fclose(infile); } - /* usage screen */ - if (error) { int ch; - fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); - readpng_version_info(); - fprintf(stderr, "\n" - "Usage: %s [-gamma exp] [-bgcolor bg] file.png\n" - " exp \ttransfer-function exponent (``gamma'') of the display\n" - "\t\t system in floating-point format (e.g., ``%.1f''); equal\n" - "\t\t to the product of the lookup-table exponent (varies)\n" - "\t\t and the CRT exponent (usually 2.2); must be positive\n" - " bg \tdesired background color in 7-character hex RGB format\n" - "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" - "\t\t used with transparent images\n" - "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n" - "Press Q or Esc to quit this usage screen.\n" - "\n", PROGNAME, default_display_exponent); + fprintf(stderr, PROGNAME ": aborting.\n"); do ch = _getch(); while (ch != 'q' && ch != 'Q' && ch != 0x1B); - exit(1); + exit(2); } else { fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); fprintf(stderr, "\n [console window: closing this window will terminate %s]\n\n", diff -ru4N libpng-1.2.25/contrib/gregbook/rpng-x.c libpng-1.2.26beta04/contrib/gregbook/rpng-x.c --- libpng-1.2.25/contrib/gregbook/rpng-x.c Mon Feb 18 16:31:09 2008 +++ libpng-1.2.26beta04/contrib/gregbook/rpng-x.c Tue Mar 18 17:37:50 2008 @@ -24,12 +24,13 @@ - 1.12: fixed some small X memory leaks (thanks to François Petitjean) - 1.13: fixed XFreeGC() crash bug (thanks to Patrick Welche) - 1.14: added support for X resources (thanks to Gerhard Niklasch) - 2.00: dual-licensed (added GNU GPL) + - 2.01: fixed improper display of usage screen on PNG error(s) --------------------------------------------------------------------------- - Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of @@ -78,9 +79,9 @@ ---------------------------------------------------------------------------*/ #define PROGNAME "rpng-x" #define LONGNAME "Simple PNG Viewer for X" -#define VERSION "2.00 of 2 June 2007" +#define VERSION "2.01 of 16 March 2008" #define RESNAME "rpng" /* our X resource application name */ #define RESCLASS "Rpng" /* our X resource class name */ #include @@ -264,11 +265,35 @@ ++error; /* not expecting any other options */ } } - if (!filename) { + if (!filename) ++error; - } else if (!(infile = fopen(filename, "rb"))) { + + + /* print usage screen if any errors up to this point */ + + if (error) { + fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); + readpng_version_info(); + fprintf(stderr, "\n" + "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg] file.png\n" + " xdpy\tname of the target X display (e.g., ``hostname:0'')\n" + " exp \ttransfer-function exponent (``gamma'') of the display\n" + "\t\t system in floating-point format (e.g., ``%.1f''); equal\n" + "\t\t to the product of the lookup-table exponent (varies)\n" + "\t\t and the CRT exponent (usually 2.2); must be positive\n" + " bg \tdesired background color in 7-character hex RGB format\n" + "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" + "\t\t used with transparent images\n" + "\nPress Q, Esc or mouse button 1 (within image window, after image\n" + "is displayed) to quit.\n" + "\n", PROGNAME, default_display_exponent); + exit(1); + } + + + if (!(infile = fopen(filename, "rb"))) { fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); ++error; } else { if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) { @@ -279,10 +304,9 @@ filename); break; case 2: fprintf(stderr, PROGNAME - ": [%s] has bad IHDR (libpng longjmp)\n", - filename); + ": [%s] has bad IHDR (libpng longjmp)\n", filename); break; case 4: fprintf(stderr, PROGNAME ": insufficient memory\n"); break; @@ -305,27 +329,11 @@ fclose(infile); } - /* usage screen */ - if (error) { - fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); - readpng_version_info(); - fprintf(stderr, "\n" - "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg] file.png\n" - " xdpy\tname of the target X display (e.g., ``hostname:0'')\n" - " exp \ttransfer-function exponent (``gamma'') of the display\n" - "\t\t system in floating-point format (e.g., ``%.1f''); equal\n" - "\t\t to the product of the lookup-table exponent (varies)\n" - "\t\t and the CRT exponent (usually 2.2); must be positive\n" - " bg \tdesired background color in 7-character hex RGB format\n" - "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" - "\t\t used with transparent images\n" - "\nPress Q, Esc or mouse button 1 (within image window, after image\n" - "is displayed) to quit.\n" - "\n", PROGNAME, default_display_exponent); - exit(1); + fprintf(stderr, PROGNAME ": aborting.\n"); + exit(2); } /* set the title-bar string, but make sure buffer doesn't overflow */ Binary files libpng-1.2.25/contrib/gregbook/rpng-x.o and libpng-1.2.26beta04/contrib/gregbook/rpng-x.o differ diff -ru4N libpng-1.2.25/contrib/gregbook/rpng2-win.c libpng-1.2.26beta04/contrib/gregbook/rpng2-win.c --- libpng-1.2.25/contrib/gregbook/rpng2-win.c Mon Feb 18 16:31:09 2008 +++ libpng-1.2.26beta04/contrib/gregbook/rpng2-win.c Tue Mar 18 17:37:50 2008 @@ -9,9 +9,9 @@ for 32-bit Windows; it may compile under 16-bit Windows with a little tweaking (or maybe not). Thanks to Adam Costello and Pieter S. van der Meulen for the "diamond" and "radial waves" patterns, respectively. - to do: + to do (someday, maybe): - handle quoted command-line args (especially filenames with spaces) - finish resizable checkerboard-gradient (sizes 4-128?) - use %.1023s to simplify truncation of title-bar string? - have minimum window width: oh well @@ -28,12 +28,15 @@ - 1.20: added runtime MMX-enabling/disabling and new -mmx* options - 1.21: made minor tweak to usage screen to fit within 25-line console - 1.22: added AMD64/EM64T support (__x86_64__) - 2.00: dual-licensed (added GNU GPL) + - 2.01: fixed 64-bit typo in readpng2.c + - 2.02: fixed improper display of usage screen on PNG error(s); fixed + unexpected-EOF and file-read-error cases --------------------------------------------------------------------------- - Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of @@ -82,9 +85,9 @@ ---------------------------------------------------------------------------*/ #define PROGNAME "rpng2-win" #define LONGNAME "Progressive PNG Viewer for Windows" -#define VERSION "2.00 of 2 June 2007" +#define VERSION "2.02 of 16 March 2008" #include #include #include @@ -413,43 +416,13 @@ ++error; /* not expecting any other options */ } } - if (!filename) { + if (!filename) ++error; - } else if (!(infile = fopen(filename, "rb"))) { - fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); - ++error; - } else { - incount = fread(inbuf, 1, INBUFSIZE, infile); - if (incount < 8 || !readpng2_check_sig(inbuf, 8)) { - fprintf(stderr, PROGNAME - ": [%s] is not a PNG file: incorrect signature\n", - filename); - ++error; - } else if ((rc = readpng2_init(&rpng2_info)) != 0) { - switch (rc) { - case 2: - fprintf(stderr, PROGNAME - ": [%s] has bad IHDR (libpng longjmp)\n", - filename); - break; - case 4: - fprintf(stderr, PROGNAME ": insufficient memory\n"); - break; - default: - fprintf(stderr, PROGNAME - ": unknown readpng2_init() error\n"); - break; - } - ++error; - } - if (error) - fclose(infile); - } - /* usage screen */ + /* print usage screen if any errors up to this point */ if (error) { int ch; @@ -487,8 +460,50 @@ do ch = _getch(); while (ch != 'q' && ch != 'Q' && ch != 0x1B); exit(1); + } + + + if (!(infile = fopen(filename, "rb"))) { + fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); + ++error; + } else { + incount = fread(inbuf, 1, INBUFSIZE, infile); + if (incount < 8 || !readpng2_check_sig(inbuf, 8)) { + fprintf(stderr, PROGNAME + ": [%s] is not a PNG file: incorrect signature\n", + filename); + ++error; + } else if ((rc = readpng2_init(&rpng2_info)) != 0) { + switch (rc) { + case 2: + fprintf(stderr, PROGNAME + ": [%s] has bad IHDR (libpng longjmp)\n", filename); + break; + case 4: + fprintf(stderr, PROGNAME ": insufficient memory\n"); + break; + default: + fprintf(stderr, PROGNAME + ": unknown readpng2_init() error\n"); + break; + } + ++error; + } + if (error) + fclose(infile); + } + + + if (error) { + int ch; + + fprintf(stderr, PROGNAME ": aborting.\n"); + do + ch = _getch(); + while (ch != 'q' && ch != 'Q' && ch != 0x1B); + exit(2); } else { fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); fprintf(stderr, "\n [console window: closing this window will terminate %s]\n\n", @@ -518,9 +533,9 @@ rpng2_info.bg_blue = (uch)b; } else rpng2_info.need_bgcolor = TRUE; - rpng2_info.done = FALSE; + rpng2_info.state = kPreInit; rpng2_info.mainprog_init = rpng2_win_init; rpng2_info.mainprog_display_row = rpng2_win_display_row; rpng2_info.mainprog_finish_display = rpng2_win_finish_display; @@ -538,12 +553,29 @@ Trace((stderr, "about to call readpng2_decode_data()\n")) if (readpng2_decode_data(&rpng2_info, inbuf, incount)) ++error; Trace((stderr, "done with readpng2_decode_data()\n")) - if (error || feof(infile) || rpng2_info.done) + + if (error || incount != INBUFSIZE || rpng2_info.state == kDone) { + if (rpng2_info.state == kDone) { + Trace((stderr, "done decoding PNG image\n")) + } else if (ferror(infile)) { + fprintf(stderr, PROGNAME + ": error while reading PNG image file\n"); + exit(3); + } else if (feof(infile)) { + fprintf(stderr, PROGNAME ": end of file reached " + "(unexpectedly) while reading PNG image file\n"); + exit(3); + } else /* if (error) */ { + // will print error message below + } break; + } + if (timing) Sleep(1000L); + incount = fread(inbuf, 1, INBUFSIZE, infile); } @@ -588,9 +620,9 @@ ulg i; ulg rowbytes = rpng2_info.rowbytes; Trace((stderr, "beginning rpng2_win_init()\n")) - Trace((stderr, " rowbytes = %ld\n", rpng2_info.rowbytes)) + Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes)) Trace((stderr, " width = %ld\n", rpng2_info.width)) Trace((stderr, " height = %ld\n", rpng2_info.height)) rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height); @@ -618,8 +650,10 @@ if (rpng2_win_create_window()) { readpng2_cleanup(&rpng2_info); return; } + + rpng2_info.state = kWindowInit; } @@ -1113,9 +1147,9 @@ /* last row has already been displayed by rpng2_win_display_row(), so * we have nothing to do here except set a flag and let the user know * that the image is done */ - rpng2_info.done = TRUE; + rpng2_info.state = kDone; printf( "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"); fflush(stdout); } diff -ru4N libpng-1.2.25/contrib/gregbook/rpng2-x.c libpng-1.2.26beta04/contrib/gregbook/rpng2-x.c --- libpng-1.2.25/contrib/gregbook/rpng2-x.c Mon Feb 18 16:31:09 2008 +++ libpng-1.2.26beta04/contrib/gregbook/rpng2-x.c Tue Mar 18 17:37:50 2008 @@ -11,9 +11,9 @@ Thanks to Adam Costello and Pieter S. van der Meulen for the "diamond" and "radial waves" patterns, respectively. - to do: + to do (someday, maybe): - fix expose/redraw code: don't draw entire row if only part exposed - 8-bit (colormapped) X support - finish resizable checkerboard-gradient (sizes 4-128?) - use %.1023s to simplify truncation of title-bar string? @@ -35,12 +35,16 @@ - 1.31: added code to skip unused chunks (thanks to Glenn Randers-Pehrson) - 1.32: added AMD64/EM64T support (__x86_64__); added basic expose/redraw handling - 2.00: dual-licensed (added GNU GPL) + - 2.01: fixed 64-bit typo in readpng2.c; fixed -pause usage description + - 2.02: fixed improper display of usage screen on PNG error(s); fixed + unexpected-EOF and file-read-error cases; fixed Trace() cut-and- + paste bugs --------------------------------------------------------------------------- - Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of @@ -89,9 +93,9 @@ ---------------------------------------------------------------------------*/ #define PROGNAME "rpng2-x" #define LONGNAME "Progressive PNG Viewer for X" -#define VERSION "2.00 of 2 June 2007" +#define VERSION "2.02 of 16 March 2008" #define RESNAME "rpng2" /* our X resource application name */ #define RESCLASS "Rpng" /* our X resource class name */ #include @@ -452,51 +456,13 @@ ++error; /* not expecting any other options */ } } - if (!filename) { + if (!filename) ++error; - } else if (!(infile = fopen(filename, "rb"))) { - fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); - ++error; - } else { - incount = fread(inbuf, 1, INBUFSIZE, infile); - if (incount < 8 || !readpng2_check_sig(inbuf, 8)) { - fprintf(stderr, PROGNAME - ": [%s] is not a PNG file: incorrect signature\n", - filename); - ++error; - } else if ((rc = readpng2_init(&rpng2_info)) != 0) { - switch (rc) { - case 2: - fprintf(stderr, PROGNAME - ": [%s] has bad IHDR (libpng longjmp)\n", - filename); - break; - case 4: - fprintf(stderr, PROGNAME ": insufficient memory\n"); - break; - default: - fprintf(stderr, PROGNAME - ": unknown readpng2_init() error\n"); - break; - } - ++error; - } else { - display = XOpenDisplay(displayname); - if (!display) { - readpng2_cleanup(&rpng2_info); - fprintf(stderr, PROGNAME ": can't open X display [%s]\n", - displayname? displayname : "default"); - ++error; - } - } - if (error) - fclose(infile); - } - /* usage screen */ + /* print usage screen if any errors up to this point */ if (error) { fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); readpng2_version_info(); @@ -532,9 +498,9 @@ " dur \tduration in microseconds to wait after displaying each\n" "\t\t row (for demo purposes)\n" " -timing\tenables delay for every block read, to simulate modem\n" "\t\t download of image (~36 Kbps)\n" - " -pause\tpauses after displaying each pass until key pressed\n" + " -pause\tpauses after displaying each pass until mouse clicked\n" "\nPress Q, Esc or mouse button 1 (within image window, after image\n" "is displayed) to quit.\n" "\n", PROGNAME, #if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) @@ -544,8 +510,54 @@ exit(1); } + if (!(infile = fopen(filename, "rb"))) { + fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); + ++error; + } else { + incount = fread(inbuf, 1, INBUFSIZE, infile); + if (incount < 8 || !readpng2_check_sig(inbuf, 8)) { + fprintf(stderr, PROGNAME + ": [%s] is not a PNG file: incorrect signature\n", + filename); + ++error; + } else if ((rc = readpng2_init(&rpng2_info)) != 0) { + switch (rc) { + case 2: + fprintf(stderr, PROGNAME + ": [%s] has bad IHDR (libpng longjmp)\n", filename); + break; + case 4: + fprintf(stderr, PROGNAME ": insufficient memory\n"); + break; + default: + fprintf(stderr, PROGNAME + ": unknown readpng2_init() error\n"); + break; + } + ++error; + } else { + Trace((stderr, "about to call XOpenDisplay()\n")) + display = XOpenDisplay(displayname); + if (!display) { + readpng2_cleanup(&rpng2_info); + fprintf(stderr, PROGNAME ": can't open X display [%s]\n", + displayname? displayname : "default"); + ++error; + } + } + if (error) + fclose(infile); + } + + + if (error) { + fprintf(stderr, PROGNAME ": aborting.\n"); + exit(2); + } + + /* set the title-bar string, but make sure buffer doesn't overflow */ alen = strlen(appname); flen = strlen(filename); @@ -566,9 +578,9 @@ rpng2_info.bg_blue = (uch)b; } else rpng2_info.need_bgcolor = TRUE; - rpng2_info.done = FALSE; + rpng2_info.state = kPreInit; rpng2_info.mainprog_init = rpng2_x_init; rpng2_info.mainprog_display_row = rpng2_x_display_row; rpng2_info.mainprog_finish_display = rpng2_x_finish_display; @@ -586,12 +598,29 @@ Trace((stderr, "about to call readpng2_decode_data()\n")) if (readpng2_decode_data(&rpng2_info, inbuf, incount)) ++error; Trace((stderr, "done with readpng2_decode_data()\n")) - if (error || feof(infile) || rpng2_info.done) + + if (error || incount != INBUFSIZE || rpng2_info.state == kDone) { + if (rpng2_info.state == kDone) { + Trace((stderr, "done decoding PNG image\n")) + } else if (ferror(infile)) { + fprintf(stderr, PROGNAME + ": error while reading PNG image file\n"); + exit(3); + } else if (feof(infile)) { + fprintf(stderr, PROGNAME ": end of file reached " + "(unexpectedly) while reading PNG image file\n"); + exit(3); + } else /* if (error) */ { + // will print error message below + } break; + } + if (timing) sleep(1); + incount = fread(inbuf, 1, INBUFSIZE, infile); } @@ -609,8 +638,9 @@ #ifdef FEATURE_LOOP if (loop && bg_image) { + Trace((stderr, "entering -loop loop (FEATURE_LOOP)\n")) for (;;) { int i, use_sleep; struct timeval now, then; @@ -704,15 +734,22 @@ #endif /* FEATURE_LOOP */ /* wait for the user to tell us when to quit */ - do { - XNextEvent(display, &e); - if (e.type == Expose) { - XExposeEvent *ex = (XExposeEvent *)&e; - rpng2_x_redisplay_image (ex->x, ex->y, ex->width, ex->height); - } - } while (!QUIT(e,k)); + if (rpng2_info.state >= kWindowInit) { + Trace((stderr, "entering final wait-for-quit-event loop\n")) + do { + XNextEvent(display, &e); + if (e.type == Expose) { + XExposeEvent *ex = (XExposeEvent *)&e; + rpng2_x_redisplay_image (ex->x, ex->y, ex->width, ex->height); + } + } while (!QUIT(e,k)); + } else { + fprintf(stderr, PROGNAME ": init callback never called: probable " + "libpng error while decoding PNG metadata\n"); + exit(4); + } /* we're done: clean up all image and X resources and go away */ @@ -735,9 +772,9 @@ ulg i; ulg rowbytes = rpng2_info.rowbytes; Trace((stderr, "beginning rpng2_x_init()\n")) - Trace((stderr, " rowbytes = %ld\n", rpng2_info.rowbytes)) + Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes)) Trace((stderr, " width = %ld\n", rpng2_info.width)) Trace((stderr, " height = %ld\n", rpng2_info.height)) rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height); @@ -772,8 +809,10 @@ readpng2_cleanup(&rpng2_info); rpng2_x_cleanup(); exit(2); } + + rpng2_info.state = kWindowInit; } @@ -1555,9 +1594,9 @@ /* last row has already been displayed by rpng2_x_display_row(), so we * have nothing to do here except set a flag and let the user know that * the image is done */ - rpng2_info.done = TRUE; + rpng2_info.state = kDone; printf( "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"); fflush(stdout); } @@ -1580,11 +1619,11 @@ int ximage_rowbytes = ximage->bytes_per_line; Trace((stderr, "beginning display loop (image_channels == %d)\n", - image_channels)) - Trace((stderr, " (width = %ld, rowbytes = %ld, ximage_rowbytes = %d)\n", - rpng2_info.width, image_rowbytes, ximage_rowbytes)) + rpng2_info.channels)) + Trace((stderr, " (width = %ld, rowbytes = %d, ximage_rowbytes = %d)\n", + rpng2_info.width, rpng2_info.rowbytes, ximage_rowbytes)) Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel)) Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst? "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown"))) Binary files libpng-1.2.25/contrib/gregbook/toucan.png and libpng-1.2.26beta04/contrib/gregbook/toucan.png differ diff -ru4N libpng-1.2.25/png.h libpng-1.2.26beta04/png.h --- libpng-1.2.25/png.h Mon Feb 18 16:31:08 2008 +++ libpng-1.2.26beta04/png.h Tue Mar 18 17:37:50 2008 @@ -176,8 +176,11 @@ * 1.2.24rc01 13 10224 12.so.0.24[.0] * 1.2.24 13 10224 12.so.0.24[.0] * 1.2.25beta01-06 13 10225 12.so.0.25[.0] * 1.2.25rc01-02 13 10225 12.so.0.25[.0] + * 1.0.31 10 10031 10.so.0.31[.0] + * 1.2.25 13 10225 12.so.0.25[.0] + * 1.2.26beta01-04 13 10226 12.so.0.26[.0] * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be * used for changes in backward compatibility, as it is intended. The diff -ru4N libpng-1.2.25/pngmem.c libpng-1.2.26beta04/pngmem.c --- libpng-1.2.25/pngmem.c Mon Feb 18 16:31:08 2008 +++ libpng-1.2.26beta04/pngmem.c Tue Mar 18 17:37:50 2008 @@ -1,10 +1,10 @@ /* pngmem.c - stub functions for memory allocation * - * Last changed in libpng 1.2.13 November 13, 2006 + * Last changed in libpng 1.2.26 [March 18, 2008] * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2006 Glenn Randers-Pehrson + * Copyright (c) 1998-2008 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.) * * This file provides a location for all memory allocation. Users who @@ -455,9 +455,9 @@ #ifdef PNG_MAX_MALLOC_64K if (size > (png_uint_32)65536L) { #ifndef PNG_USER_MEM_SUPPORTED - if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) + if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) png_error(png_ptr, "Cannot Allocate > 64K"); else #endif return NULL; diff -ru4N libpng-1.2.25/pngpread.c libpng-1.2.26beta04/pngpread.c --- libpng-1.2.25/pngpread.c Mon Feb 18 23:27:46 2008 +++ libpng-1.2.26beta04/pngpread.c Tue Mar 18 17:37:50 2008 @@ -1,8 +1,8 @@ /* pngpread.c - read a png file in push mode * - * Last changed in libpng 1.2.25 [February 18, 2008] + * Last changed in libpng 1.2.26 [March 18, 2008] * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2008 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.) @@ -223,8 +223,10 @@ if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) { if (png_ptr->push_length + 4 > png_ptr->buffer_size) { + if (png_ptr->push_length != 13) + png_error(png_ptr, "Invalid IHDR length"); png_push_save_buffer(png_ptr); return; } png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); diff -ru4N libpng-1.2.25/pngrutil.c libpng-1.2.26beta04/pngrutil.c --- libpng-1.2.25/pngrutil.c Mon Feb 18 23:28:38 2008 +++ libpng-1.2.26beta04/pngrutil.c Tue Mar 18 17:37:50 2008 @@ -3137,17 +3137,24 @@ #ifdef PNG_MAX_MALLOC_64K if (row_bytes > (png_uint_32)65536L) png_error(png_ptr, "This image requires a row greater than 64KB"); #endif + + if (png_ptr->big_row_buf) + png_free(png_ptr,png_ptr->big_row_buf); png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64); + if (png_ptr->row_buf) + png_free(png_ptr,png_ptr->row_buf); png_ptr->row_buf = png_ptr->big_row_buf+32; #ifdef PNG_MAX_MALLOC_64K if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L) png_error(png_ptr, "This image requires a row greater than 64KB"); #endif if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1)) png_error(png_ptr, "Row has too many bytes to allocate in memory."); + if (png_ptr->prev_row) + png_free(png_ptr,png_ptr->prev_row); png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)( png_ptr->rowbytes + 1)); png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1); diff -ru4N libpng-1.2.25/pngwutil.c libpng-1.2.26beta04/pngwutil.c --- libpng-1.2.25/pngwutil.c Mon Feb 18 16:31:09 2008 +++ libpng-1.2.26beta04/pngwutil.c Tue Mar 18 17:37:50 2008 @@ -1,10 +1,10 @@ /* pngwutil.c - utilities to write a PNG file * - * Last changed in libpng 1.2.20 Septhember 3, 2007 + * Last changed in libpng 1.2.26 [March 18, 2008 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2007 Glenn Randers-Pehrson + * Copyright (c) 1998-2008 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.) */ @@ -379,8 +379,10 @@ { #ifdef PNG_USE_LOCAL_ARRAYS PNG_IHDR; #endif + int ret; + png_byte buf[13]; /* buffer to store the IHDR info */ png_debug(1, "in png_write_IHDR\n"); /* Check that we have valid input data from the application info */ @@ -522,12 +524,21 @@ if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS)) png_ptr->zlib_window_bits = 15; if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD)) png_ptr->zlib_method = 8; - if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, - png_ptr->zlib_method, png_ptr->zlib_window_bits, - png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK) - png_error(png_ptr, "zlib failed to initialize compressor"); + ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level, + png_ptr->zlib_method, png_ptr->zlib_window_bits, + png_ptr->zlib_mem_level, png_ptr->zlib_strategy); + if (ret != Z_OK) + { + if (ret == Z_VERSION_ERROR) png_error(png_ptr, + "zlib failed to initialize compressor -- version error"); + if (ret == Z_STREAM_ERROR) png_error(png_ptr, + "zlib failed to initialize compressor -- stream error"); + if (ret == Z_MEM_ERROR) png_error(png_ptr, + "zlib failed to initialize compressor -- mem error"); + png_error(png_ptr, "zlib failed to initialize compressor"); + } png_ptr->zstream.next_out = png_ptr->zbuf; png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; /* libpng is not interested in zstream.data_type */ /* set it to a predefined value, to avoid its evaluation inside zlib */