mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Imported from libpng-1.4.0beta25.tar
This commit is contained in:
@@ -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?
|
||||
@@ -27,16 +27,28 @@
|
||||
- 1.10: enabled "message window"/console (thanks to David Geldreich)
|
||||
- 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-2001 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
|
||||
this software.
|
||||
|
||||
The contents of this file are DUAL-LICENSED. You may modify and/or
|
||||
redistribute this software according to the terms of one of the
|
||||
following two licenses (at your option):
|
||||
|
||||
|
||||
LICENSE 1 ("BSD-like with advertising clause"):
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
@@ -53,11 +65,28 @@
|
||||
and contributors for the book, "PNG: The Definitive Guide,"
|
||||
published by O'Reilly and Associates.
|
||||
|
||||
|
||||
LICENSE 2 (GNU GPL v2 or later):
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#define PROGNAME "rpng2-win"
|
||||
#define LONGNAME "Progressive PNG Viewer for Windows"
|
||||
#define VERSION "1.21 of 29 June 2001"
|
||||
#define VERSION "2.02 of 16 March 2008"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -119,10 +148,9 @@ static void rpng2_win_cleanup(void);
|
||||
LRESULT CALLBACK rpng2_win_wndproc(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
|
||||
static char titlebar[1024], *window_name = titlebar;
|
||||
static char titlebar[1024];
|
||||
static char *progname = PROGNAME;
|
||||
static char *appname = LONGNAME;
|
||||
static char *icon_name = PROGNAME; /* GRR: not (yet) used */
|
||||
static char *filename;
|
||||
static FILE *infile;
|
||||
|
||||
@@ -367,7 +395,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||
}
|
||||
} else if (!strncmp(*argv, "-timing", 2)) {
|
||||
timing = TRUE;
|
||||
#if (defined(__i386__) || defined(_M_IX86))
|
||||
#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__))
|
||||
} else if (!strncmp(*argv, "-nommxfilters", 7)) {
|
||||
rpng2_info.nommxfilters = TRUE;
|
||||
} else if (!strncmp(*argv, "-nommxcombine", 7)) {
|
||||
@@ -389,9 +417,54 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
readpng2_version_info();
|
||||
fprintf(stderr, "\n"
|
||||
"Usage: %s [-gamma exp] [-bgcolor bg | -bgpat pat] [-timing]\n"
|
||||
#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__))
|
||||
" %*s [[-nommxfilters] [-nommxcombine] [-nommxinterlace] | -nommx]\n"
|
||||
#endif
|
||||
" %*s file.png\n\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; overrides -bgpat option\n"
|
||||
" pat \tdesired background pattern number (1-%d); used with\n"
|
||||
"\t\t transparent images; overrides -bgcolor option\n"
|
||||
" -timing\tenables delay for every block read, to simulate modem\n"
|
||||
"\t\t download of image (~36 Kbps)\n"
|
||||
#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__))
|
||||
" -nommx*\tdisable optimized MMX routines for decoding row filters,\n"
|
||||
"\t\t combining rows, and expanding interlacing, respectively\n"
|
||||
#endif
|
||||
"\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n"
|
||||
"Press Q or Esc to quit this usage screen. ",
|
||||
PROGNAME,
|
||||
#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__))
|
||||
(int)strlen(PROGNAME), " ",
|
||||
#endif
|
||||
(int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat);
|
||||
fflush(stderr);
|
||||
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 {
|
||||
@@ -405,8 +478,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||
switch (rc) {
|
||||
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");
|
||||
@@ -423,46 +495,14 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||
}
|
||||
|
||||
|
||||
/* usage screen */
|
||||
|
||||
if (error) {
|
||||
int ch;
|
||||
|
||||
fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname);
|
||||
readpng2_version_info();
|
||||
fprintf(stderr, "\n"
|
||||
"Usage: %s [-gamma exp] [-bgcolor bg | -bgpat pat] [-timing]\n"
|
||||
#if (defined(__i386__) || defined(_M_IX86))
|
||||
" %*s [[-nommxfilters] [-nommxcombine] [-nommxinterlace] | -nommx]\n"
|
||||
#endif
|
||||
" %*s file.png\n\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; overrides -bgpat option\n"
|
||||
" pat \tdesired background pattern number (1-%d); used with\n"
|
||||
"\t\t transparent images; overrides -bgcolor option\n"
|
||||
" -timing\tenables delay for every block read, to simulate modem\n"
|
||||
"\t\t download of image (~36 Kbps)\n"
|
||||
#if (defined(__i386__) || defined(_M_IX86))
|
||||
" -nommx*\tdisable optimized MMX routines for decoding row filters,\n"
|
||||
"\t\t combining rows, and expanding interlacing, respectively\n"
|
||||
#endif
|
||||
"\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n"
|
||||
"Press Q or Esc to quit this usage screen. ",
|
||||
PROGNAME,
|
||||
#if (defined(__i386__) || defined(_M_IX86))
|
||||
strlen(PROGNAME), " ",
|
||||
#endif
|
||||
strlen(PROGNAME), " ", default_display_exponent, num_bgpat);
|
||||
fflush(stderr);
|
||||
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,
|
||||
@@ -494,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;
|
||||
@@ -514,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);
|
||||
}
|
||||
|
||||
@@ -564,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))
|
||||
|
||||
@@ -594,6 +651,8 @@ static void rpng2_win_init()
|
||||
readpng2_cleanup(&rpng2_info);
|
||||
return;
|
||||
}
|
||||
|
||||
rpng2_info.state = kWindowInit;
|
||||
}
|
||||
|
||||
|
||||
@@ -1089,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);
|
||||
|
||||
Reference in New Issue
Block a user