mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Imported from libpng-1.2.26beta03.tar
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
|
||||
@@ -56,7 +56,7 @@ mation and links to the latest version of the source code, and Chapters
|
||||
|
||||
Greg Roelofs
|
||||
http://pobox.com/~newt/greg_contact.html
|
||||
2 June 2007
|
||||
16 March 2008
|
||||
|
||||
|
||||
BUILD INSTRUCTIONS
|
||||
|
||||
@@ -4,7 +4,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
|
||||
@@ -69,6 +69,12 @@
|
||||
# define Trace(x) ;
|
||||
#endif
|
||||
|
||||
enum rpng2_states {
|
||||
kPreInit = 0,
|
||||
kWindowInit,
|
||||
kDone
|
||||
};
|
||||
|
||||
typedef unsigned char uch;
|
||||
typedef unsigned short ush;
|
||||
typedef unsigned long ulg;
|
||||
@@ -95,7 +101,7 @@ typedef struct _mainprog_info {
|
||||
int nommxcombine;
|
||||
int nommxinterlace;
|
||||
#endif
|
||||
int done;
|
||||
int state;
|
||||
uch bg_red;
|
||||
uch bg_green;
|
||||
uch bg_blue;
|
||||
|
||||
@@ -23,10 +23,11 @@
|
||||
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
|
||||
@@ -77,7 +78,7 @@
|
||||
|
||||
#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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -271,40 +272,11 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||
}
|
||||
}
|
||||
|
||||
if (!filename) {
|
||||
if (!filename)
|
||||
++error;
|
||||
} else 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) {
|
||||
switch (rc) {
|
||||
case 1:
|
||||
fprintf(stderr, PROGNAME
|
||||
": [%s] is not a PNG file: incorrect signature\n",
|
||||
filename);
|
||||
break;
|
||||
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 readpng_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;
|
||||
@@ -327,6 +299,47 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||
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) {
|
||||
switch (rc) {
|
||||
case 1:
|
||||
fprintf(stderr, PROGNAME
|
||||
": [%s] is not a PNG file: incorrect signature\n",
|
||||
filename);
|
||||
break;
|
||||
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 readpng_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,
|
||||
|
||||
@@ -25,10 +25,11 @@
|
||||
- 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
|
||||
@@ -79,7 +80,7 @@
|
||||
|
||||
#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 */
|
||||
|
||||
@@ -265,9 +266,33 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -280,8 +305,7 @@ int main(int argc, char **argv)
|
||||
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");
|
||||
@@ -306,25 +330,9 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
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?
|
||||
@@ -29,10 +29,13 @@
|
||||
- 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
|
||||
@@ -83,7 +86,7 @@
|
||||
|
||||
#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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -414,41 +417,11 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -488,6 +461,48 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||
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,
|
||||
@@ -519,7 +534,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||
} 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;
|
||||
@@ -539,10 +554,27 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -589,7 +621,7 @@ static void rpng2_win_init()
|
||||
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))
|
||||
|
||||
@@ -619,6 +651,8 @@ static void rpng2_win_init()
|
||||
readpng2_cleanup(&rpng2_info);
|
||||
return;
|
||||
}
|
||||
|
||||
rpng2_info.state = kWindowInit;
|
||||
}
|
||||
|
||||
|
||||
@@ -1114,7 +1148,7 @@ static void rpng2_win_finish_display()
|
||||
* 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);
|
||||
|
||||
@@ -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")))
|
||||
|
||||
Reference in New Issue
Block a user