Imported from libpng-1.2.26beta03.tar

This commit is contained in:
Glenn Randers-Pehrson
2008-03-16 17:23:05 -05:00
parent c13f8f10e6
commit 3236beddf8
57 changed files with 380 additions and 272 deletions

View File

@@ -12,7 +12,7 @@
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?)
@@ -36,10 +36,14 @@
- 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
@@ -90,7 +94,7 @@
#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 */
@@ -453,49 +457,11 @@ int main(int argc, char **argv)
}
}
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);
@@ -533,7 +499,7 @@ int main(int argc, char **argv)
"\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,
@@ -545,6 +511,52 @@ int main(int argc, char **argv)
}
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);
@@ -567,7 +579,7 @@ int main(int argc, char **argv)
} 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;
@@ -587,10 +599,27 @@ int main(int argc, char **argv)
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);
}
@@ -610,6 +639,7 @@ int main(int argc, char **argv)
#ifdef FEATURE_LOOP
if (loop && bg_image) {
Trace((stderr, "entering -loop loop (FEATURE_LOOP)\n"))
for (;;) {
int i, use_sleep;
struct timeval now, then;
@@ -705,13 +735,20 @@ int main(int argc, char **argv)
/* 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 */
@@ -736,7 +773,7 @@ static void rpng2_x_init(void)
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))
@@ -773,6 +810,8 @@ static void rpng2_x_init(void)
rpng2_x_cleanup();
exit(2);
}
rpng2_info.state = kWindowInit;
}
@@ -1556,7 +1595,7 @@ static void rpng2_x_finish_display(void)
* 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);
@@ -1581,9 +1620,9 @@ static void rpng2_x_redisplay_image(ulg startcol, ulg startrow,
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")))