Imported from libpng-0.81.tar
This commit is contained in:
parent
0d5805822f
commit
51f0eb4584
488
ansi2knr.c
488
ansi2knr.c
@ -1,488 +0,0 @@
|
|||||||
/* Copyright (C) 1989, 1991, 1993 Aladdin Enterprises. All rights reserved. */
|
|
||||||
|
|
||||||
/* ansi2knr.c */
|
|
||||||
/* Convert ANSI function declarations to K&R syntax */
|
|
||||||
|
|
||||||
/*
|
|
||||||
ansi2knr is distributed in the hope that it will be useful, but
|
|
||||||
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
|
|
||||||
to anyone for the consequences of using it or for whether it serves any
|
|
||||||
particular purpose or works at all, unless he says so in writing. Refer
|
|
||||||
to the GNU General Public License for full details.
|
|
||||||
|
|
||||||
Everyone is granted permission to copy, modify and redistribute
|
|
||||||
ansi2knr, but only under the conditions described in the GNU
|
|
||||||
General Public License. A copy of this license is supposed to have been
|
|
||||||
given to you along with ansi2knr so you can know your rights and
|
|
||||||
responsibilities. It should be in a file named COPYING. Among other
|
|
||||||
things, the copyright notice and this notice must be preserved on all
|
|
||||||
copies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
---------- Here is the GNU GPL file COPYING, referred to above ----------
|
|
||||||
----- These terms do NOT apply to the JPEG software itself; see README ------
|
|
||||||
|
|
||||||
GHOSTSCRIPT GENERAL PUBLIC LICENSE
|
|
||||||
(Clarified 11 Feb 1988)
|
|
||||||
|
|
||||||
Copyright (C) 1988 Richard M. Stallman
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies of this
|
|
||||||
license, but changing it is not allowed. You can also use this wording
|
|
||||||
to make the terms for other programs.
|
|
||||||
|
|
||||||
The license agreements of most software companies keep you at the
|
|
||||||
mercy of those companies. By contrast, our general public license is
|
|
||||||
intended to give everyone the right to share Ghostscript. To make sure
|
|
||||||
that you get the rights we want you to have, we need to make
|
|
||||||
restrictions that forbid anyone to deny you these rights or to ask you
|
|
||||||
to surrender the rights. Hence this license agreement.
|
|
||||||
|
|
||||||
Specifically, we want to make sure that you have the right to give
|
|
||||||
away copies of Ghostscript, that you receive source code or else can get
|
|
||||||
it if you want it, that you can change Ghostscript or use pieces of it
|
|
||||||
in new free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To make sure that everyone has such rights, we have to forbid you to
|
|
||||||
deprive anyone else of these rights. For example, if you distribute
|
|
||||||
copies of Ghostscript, you must give the recipients all the rights that
|
|
||||||
you have. You must make sure that they, too, receive or can get the
|
|
||||||
source code. And you must tell them their rights.
|
|
||||||
|
|
||||||
Also, for our own protection, we must make certain that everyone finds
|
|
||||||
out that there is no warranty for Ghostscript. If Ghostscript is
|
|
||||||
modified by someone else and passed on, we want its recipients to know
|
|
||||||
that what they have is not what we distributed, so that any problems
|
|
||||||
introduced by others will not reflect on our reputation.
|
|
||||||
|
|
||||||
Therefore we (Richard M. Stallman and the Free Software Foundation,
|
|
||||||
Inc.) make the following terms which say what you must do to be allowed
|
|
||||||
to distribute or change Ghostscript.
|
|
||||||
|
|
||||||
|
|
||||||
COPYING POLICIES
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of Ghostscript source
|
|
||||||
code as you receive it, in any medium, provided that you conspicuously
|
|
||||||
and appropriately publish on each copy a valid copyright and license
|
|
||||||
notice "Copyright (C) 1989 Aladdin Enterprises. All rights reserved.
|
|
||||||
Distributed by Free Software Foundation, Inc." (or with whatever year is
|
|
||||||
appropriate); keep intact the notices on all files that refer to this
|
|
||||||
License Agreement and to the absence of any warranty; and give any other
|
|
||||||
recipients of the Ghostscript program a copy of this License Agreement
|
|
||||||
along with the program. You may charge a distribution fee for the
|
|
||||||
physical act of transferring a copy.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of Ghostscript or any portion of
|
|
||||||
it, and copy and distribute such modifications under the terms of
|
|
||||||
Paragraph 1 above, provided that you also do the following:
|
|
||||||
|
|
||||||
a) cause the modified files to carry prominent notices stating
|
|
||||||
that you changed the files and the date of any change; and
|
|
||||||
|
|
||||||
b) cause the whole of any work that you distribute or publish,
|
|
||||||
that in whole or in part contains or is a derivative of Ghostscript
|
|
||||||
or any part thereof, to be licensed at no charge to all third
|
|
||||||
parties on terms identical to those contained in this License
|
|
||||||
Agreement (except that you may choose to grant more extensive
|
|
||||||
warranty protection to some or all third parties, at your option).
|
|
||||||
|
|
||||||
c) You may charge a distribution fee for the physical act of
|
|
||||||
transferring a copy, and you may at your option offer warranty
|
|
||||||
protection in exchange for a fee.
|
|
||||||
|
|
||||||
Mere aggregation of another unrelated program with this program (or its
|
|
||||||
derivative) on a volume of a storage or distribution medium does not bring
|
|
||||||
the other program under the scope of these terms.
|
|
||||||
|
|
||||||
3. You may copy and distribute Ghostscript (or a portion or derivative
|
|
||||||
of it, under Paragraph 2) in object code or executable form under the
|
|
||||||
terms of Paragraphs 1 and 2 above provided that you also do one of the
|
|
||||||
following:
|
|
||||||
|
|
||||||
a) accompany it with the complete corresponding machine-readable
|
|
||||||
source code, which must be distributed under the terms of
|
|
||||||
Paragraphs 1 and 2 above; or,
|
|
||||||
|
|
||||||
b) accompany it with a written offer, valid for at least three
|
|
||||||
years, to give any third party free (except for a nominal
|
|
||||||
shipping charge) a complete machine-readable copy of the
|
|
||||||
corresponding source code, to be distributed under the terms of
|
|
||||||
Paragraphs 1 and 2 above; or,
|
|
||||||
|
|
||||||
c) accompany it with the information you received as to where the
|
|
||||||
corresponding source code may be obtained. (This alternative is
|
|
||||||
allowed only for noncommercial distribution and only if you
|
|
||||||
received the program in object code or executable form alone.)
|
|
||||||
|
|
||||||
For an executable file, complete source code means all the source code for
|
|
||||||
all modules it contains; but, as a special exception, it need not include
|
|
||||||
source code for modules which are standard libraries that accompany the
|
|
||||||
operating system on which the executable file runs.
|
|
||||||
|
|
||||||
4. You may not copy, sublicense, distribute or transfer Ghostscript
|
|
||||||
except as expressly provided under this License Agreement. Any attempt
|
|
||||||
otherwise to copy, sublicense, distribute or transfer Ghostscript is
|
|
||||||
void and your rights to use the program under this License agreement
|
|
||||||
shall be automatically terminated. However, parties who have received
|
|
||||||
computer software programs from you with this License Agreement will not
|
|
||||||
have their licenses terminated so long as such parties remain in full
|
|
||||||
compliance.
|
|
||||||
|
|
||||||
5. If you wish to incorporate parts of Ghostscript into other free
|
|
||||||
programs whose distribution conditions are different, write to the Free
|
|
||||||
Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not
|
|
||||||
yet worked out a simple rule that can be stated here, but we will often
|
|
||||||
permit this. We will be guided by the two goals of preserving the free
|
|
||||||
status of all derivatives of our free software and of promoting the
|
|
||||||
sharing and reuse of software.
|
|
||||||
|
|
||||||
Your comments and suggestions about our licensing policies and our
|
|
||||||
software are welcome! Please contact the Free Software Foundation,
|
|
||||||
Inc., 675 Mass Ave, Cambridge, MA 02139, or call (617) 876-3296.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
BECAUSE GHOSTSCRIPT IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
|
|
||||||
NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
|
|
||||||
WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC, RICHARD
|
|
||||||
M. STALLMAN, ALADDIN ENTERPRISES, L. PETER DEUTSCH, AND/OR OTHER PARTIES
|
|
||||||
PROVIDE GHOSTSCRIPT "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
|
|
||||||
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
|
||||||
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF GHOSTSCRIPT IS WITH
|
|
||||||
YOU. SHOULD GHOSTSCRIPT PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
|
|
||||||
NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
|
|
||||||
STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., L. PETER DEUTSCH, ALADDIN
|
|
||||||
ENTERPRISES, AND/OR ANY OTHER PARTY WHO MAY MODIFY AND REDISTRIBUTE
|
|
||||||
GHOSTSCRIPT AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING
|
|
||||||
ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, INCIDENTAL OR
|
|
||||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
|
|
||||||
(INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
|
|
||||||
INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE
|
|
||||||
PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) GHOSTSCRIPT, EVEN IF YOU
|
|
||||||
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM
|
|
||||||
BY ANY OTHER PARTY.
|
|
||||||
|
|
||||||
-------------------- End of file COPYING ------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#ifdef BSD
|
|
||||||
#include <strings.h>
|
|
||||||
#else
|
|
||||||
#ifdef VMS
|
|
||||||
extern int strlen(), strncmp();
|
|
||||||
#else
|
|
||||||
#include <string.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* malloc and free should be declared in stdlib.h, */
|
|
||||||
/* but if you've got a K&R compiler, they probably aren't. */
|
|
||||||
#ifdef MSDOS
|
|
||||||
#include <malloc.h>
|
|
||||||
#else
|
|
||||||
#ifdef VMS
|
|
||||||
extern char *malloc();
|
|
||||||
extern void free();
|
|
||||||
#else
|
|
||||||
extern char *malloc();
|
|
||||||
extern int free();
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Usage:
|
|
||||||
ansi2knr input_file [output_file]
|
|
||||||
* If no output_file is supplied, output goes to stdout.
|
|
||||||
* There are no error messages.
|
|
||||||
*
|
|
||||||
* ansi2knr recognizes functions by seeing a non-keyword identifier
|
|
||||||
* at the left margin, followed by a left parenthesis,
|
|
||||||
* with a right parenthesis as the last character on the line.
|
|
||||||
* It will recognize a multi-line header provided that the last character
|
|
||||||
* of the last line of the header is a right parenthesis,
|
|
||||||
* and no intervening line ends with a left brace or a semicolon.
|
|
||||||
* These algorithms ignore whitespace and comments, except that
|
|
||||||
* the function name must be the first thing on the line.
|
|
||||||
* The following constructs will confuse it:
|
|
||||||
* - Any other construct that starts at the left margin and
|
|
||||||
* follows the above syntax (such as a macro or function call).
|
|
||||||
* - Macros that tinker with the syntax of the function header.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Scanning macros */
|
|
||||||
#define isidchar(ch) (isalnum(ch) || (ch) == '_')
|
|
||||||
#define isidfirstchar(ch) (isalpha(ch) || (ch) == '_')
|
|
||||||
|
|
||||||
/* Forward references */
|
|
||||||
char *skipspace();
|
|
||||||
int writeblanks();
|
|
||||||
int test1();
|
|
||||||
int convert1();
|
|
||||||
|
|
||||||
/* The main program */
|
|
||||||
main(argc, argv)
|
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
{ FILE *in, *out;
|
|
||||||
#define bufsize 5000 /* arbitrary size */
|
|
||||||
char *buf;
|
|
||||||
char *line;
|
|
||||||
switch ( argc )
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
printf("Usage: ansi2knr input_file [output_file]\n");
|
|
||||||
exit(0);
|
|
||||||
case 2:
|
|
||||||
out = stdout; break;
|
|
||||||
case 3:
|
|
||||||
out = fopen(argv[2], "w");
|
|
||||||
if ( out == NULL )
|
|
||||||
{ fprintf(stderr, "Cannot open %s\n", argv[2]);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
in = fopen(argv[1], "r");
|
|
||||||
if ( in == NULL )
|
|
||||||
{ fprintf(stderr, "Cannot open %s\n", argv[1]);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
fprintf(out, "#line 1 \"%s\"\n", argv[1]);
|
|
||||||
buf = malloc(bufsize);
|
|
||||||
line = buf;
|
|
||||||
while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
|
|
||||||
{ switch ( test1(buf) )
|
|
||||||
{
|
|
||||||
case 1: /* a function */
|
|
||||||
convert1(buf, out);
|
|
||||||
break;
|
|
||||||
case -1: /* maybe the start of a function */
|
|
||||||
line = buf + strlen(buf);
|
|
||||||
if ( line != buf + (bufsize - 1) ) /* overflow check */
|
|
||||||
continue;
|
|
||||||
/* falls through */
|
|
||||||
default: /* not a function */
|
|
||||||
fputs(buf, out);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
line = buf;
|
|
||||||
}
|
|
||||||
if ( line != buf ) fputs(buf, out);
|
|
||||||
free(buf);
|
|
||||||
fclose(out);
|
|
||||||
fclose(in);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Skip over space and comments, in either direction. */
|
|
||||||
char *
|
|
||||||
skipspace(p, dir)
|
|
||||||
register char *p;
|
|
||||||
register int dir; /* 1 for forward, -1 for backward */
|
|
||||||
{ for ( ; ; )
|
|
||||||
{ while ( isspace(*p) ) p += dir;
|
|
||||||
if ( !(*p == '/' && p[dir] == '*') ) break;
|
|
||||||
p += dir; p += dir;
|
|
||||||
while ( !(*p == '*' && p[dir] == '/') )
|
|
||||||
{ if ( *p == 0 ) return p; /* multi-line comment?? */
|
|
||||||
p += dir;
|
|
||||||
}
|
|
||||||
p += dir; p += dir;
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write blanks over part of a string.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
writeblanks(start, end)
|
|
||||||
char *start;
|
|
||||||
char *end;
|
|
||||||
{ char *p;
|
|
||||||
for ( p = start; p < end; p++ ) *p = ' ';
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test whether the string in buf is a function definition.
|
|
||||||
* The string may contain and/or end with a newline.
|
|
||||||
* Return as follows:
|
|
||||||
* 0 - definitely not a function definition;
|
|
||||||
* 1 - definitely a function definition;
|
|
||||||
* -1 - may be the beginning of a function definition,
|
|
||||||
* append another line and look again.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
test1(buf)
|
|
||||||
char *buf;
|
|
||||||
{ register char *p = buf;
|
|
||||||
char *bend;
|
|
||||||
char *endfn;
|
|
||||||
int contin;
|
|
||||||
if ( !isidfirstchar(*p) )
|
|
||||||
return 0; /* no name at left margin */
|
|
||||||
bend = skipspace(buf + strlen(buf) - 1, -1);
|
|
||||||
switch ( *bend )
|
|
||||||
{
|
|
||||||
case ')': contin = 1; break;
|
|
||||||
case '{':
|
|
||||||
case ';': return 0; /* not a function */
|
|
||||||
default: contin = -1;
|
|
||||||
}
|
|
||||||
while ( isidchar(*p) ) p++;
|
|
||||||
endfn = p;
|
|
||||||
p = skipspace(p, 1);
|
|
||||||
if ( *p++ != '(' )
|
|
||||||
return 0; /* not a function */
|
|
||||||
p = skipspace(p, 1);
|
|
||||||
if ( *p == ')' )
|
|
||||||
return 0; /* no parameters */
|
|
||||||
/* Check that the apparent function name isn't a keyword. */
|
|
||||||
/* We only need to check for keywords that could be followed */
|
|
||||||
/* by a left parenthesis (which, unfortunately, is most of them). */
|
|
||||||
{ static char *words[] =
|
|
||||||
{ "asm", "auto", "case", "char", "const", "double",
|
|
||||||
"extern", "float", "for", "if", "int", "long",
|
|
||||||
"register", "return", "short", "signed", "sizeof",
|
|
||||||
"static", "switch", "typedef", "unsigned",
|
|
||||||
"void", "volatile", "while", 0
|
|
||||||
};
|
|
||||||
char **key = words;
|
|
||||||
char *kp;
|
|
||||||
int len = endfn - buf;
|
|
||||||
while ( (kp = *key) != 0 )
|
|
||||||
{ if ( strlen(kp) == len && !strncmp(kp, buf, len) )
|
|
||||||
return 0; /* name is a keyword */
|
|
||||||
key++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return contin;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
convert1(buf, out)
|
|
||||||
char *buf;
|
|
||||||
FILE *out;
|
|
||||||
{ char *endfn;
|
|
||||||
register char *p;
|
|
||||||
char **breaks;
|
|
||||||
unsigned num_breaks = 2; /* for testing */
|
|
||||||
char **btop;
|
|
||||||
char **bp;
|
|
||||||
char **ap;
|
|
||||||
/* Pre-ANSI implementations don't agree on whether strchr */
|
|
||||||
/* is called strchr or index, so we open-code it here. */
|
|
||||||
for ( endfn = buf; *(endfn++) != '('; ) ;
|
|
||||||
top: p = endfn;
|
|
||||||
breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
|
|
||||||
if ( breaks == 0 )
|
|
||||||
{ /* Couldn't allocate break table, give up */
|
|
||||||
fprintf(stderr, "Unable to allocate break table!\n");
|
|
||||||
fputs(buf, out);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
btop = breaks + num_breaks * 2 - 2;
|
|
||||||
bp = breaks;
|
|
||||||
/* Parse the argument list */
|
|
||||||
do
|
|
||||||
{ int level = 0;
|
|
||||||
char *end = NULL;
|
|
||||||
if ( bp >= btop )
|
|
||||||
{ /* Filled up break table. */
|
|
||||||
/* Allocate a bigger one and start over. */
|
|
||||||
free((char *)breaks);
|
|
||||||
num_breaks <<= 1;
|
|
||||||
goto top;
|
|
||||||
}
|
|
||||||
*bp++ = p;
|
|
||||||
/* Find the end of the argument */
|
|
||||||
for ( ; end == NULL; p++ )
|
|
||||||
{ switch(*p)
|
|
||||||
{
|
|
||||||
case ',': if ( !level ) end = p; break;
|
|
||||||
case '(': level++; break;
|
|
||||||
case ')': if ( --level < 0 ) end = p; break;
|
|
||||||
case '/': p = skipspace(p, 1) - 1; break;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p--; /* back up over terminator */
|
|
||||||
/* Find the name being declared. */
|
|
||||||
/* This is complicated because of procedure and */
|
|
||||||
/* array modifiers. */
|
|
||||||
for ( ; ; )
|
|
||||||
{ p = skipspace(p - 1, -1);
|
|
||||||
switch ( *p )
|
|
||||||
{
|
|
||||||
case ']': /* skip array dimension(s) */
|
|
||||||
case ')': /* skip procedure args OR name */
|
|
||||||
{ int level = 1;
|
|
||||||
while ( level )
|
|
||||||
switch ( *--p )
|
|
||||||
{
|
|
||||||
case ']': case ')': level++; break;
|
|
||||||
case '[': case '(': level--; break;
|
|
||||||
case '/': p = skipspace(p, -1) + 1; break;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( *p == '(' && *skipspace(p + 1, 1) == '*' )
|
|
||||||
{ /* We found the name being declared */
|
|
||||||
while ( !isidfirstchar(*p) )
|
|
||||||
p = skipspace(p, 1) + 1;
|
|
||||||
goto found;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default: goto found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
|
|
||||||
{ p++;
|
|
||||||
if ( bp == breaks + 1 ) /* sole argument */
|
|
||||||
writeblanks(breaks[0], p);
|
|
||||||
else
|
|
||||||
writeblanks(bp[-1] - 1, p);
|
|
||||||
bp--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ while ( isidchar(*p) ) p--;
|
|
||||||
*bp++ = p+1;
|
|
||||||
}
|
|
||||||
p = end;
|
|
||||||
}
|
|
||||||
while ( *p++ == ',' );
|
|
||||||
*bp = p;
|
|
||||||
/* Make a special check for 'void' arglist */
|
|
||||||
if ( bp == breaks+2 )
|
|
||||||
{ p = skipspace(breaks[0], 1);
|
|
||||||
if ( !strncmp(p, "void", 4) )
|
|
||||||
{ p = skipspace(p+4, 1);
|
|
||||||
if ( p == breaks[2] - 1 )
|
|
||||||
{ bp = breaks; /* yup, pretend arglist is empty */
|
|
||||||
writeblanks(breaks[0], p + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Put out the function name */
|
|
||||||
p = buf;
|
|
||||||
while ( p != endfn ) putc(*p, out), p++;
|
|
||||||
/* Put out the declaration */
|
|
||||||
for ( ap = breaks+1; ap < bp; ap += 2 )
|
|
||||||
{ p = *ap;
|
|
||||||
while ( isidchar(*p) ) putc(*p, out), p++;
|
|
||||||
if ( ap < bp - 1 ) fputs(", ", out);
|
|
||||||
}
|
|
||||||
fputs(") ", out);
|
|
||||||
/* Put out the argument declarations */
|
|
||||||
for ( ap = breaks+2; ap <= bp; ap += 2 ) (*ap)[-1] = ';';
|
|
||||||
fputs(breaks[0], out);
|
|
||||||
free((char *)breaks);
|
|
||||||
return 0;
|
|
||||||
}
|
|
63
example.c
63
example.c
@ -6,6 +6,10 @@
|
|||||||
designed to be a starting point of an implementation.
|
designed to be a starting point of an implementation.
|
||||||
This is not officially part of libpng, and therefore
|
This is not officially part of libpng, and therefore
|
||||||
does not require a copyright notice.
|
does not require a copyright notice.
|
||||||
|
|
||||||
|
This file does not currently compile, because it is missing
|
||||||
|
certain parts, like allocating memory to hold an image.
|
||||||
|
You will have to supply these parts to get it to compile.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
@ -81,15 +85,11 @@ void read_png(char *file_name)
|
|||||||
/* read the file information */
|
/* read the file information */
|
||||||
png_read_info(png_ptr, info_ptr);
|
png_read_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
/* allocate the memory to hold the image using the fields
|
|
||||||
of png_info. */
|
|
||||||
|
|
||||||
/* set up the transformations you want. Note that these are
|
/* set up the transformations you want. Note that these are
|
||||||
all optional. Only call them if you want them */
|
all optional. Only call them if you want them */
|
||||||
|
|
||||||
/* expand paletted colors into true rgb */
|
/* expand paletted colors into true rgb */
|
||||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
|
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||||
info_ptr->bit_depth < 8)
|
|
||||||
png_set_expand(png_ptr);
|
png_set_expand(png_ptr);
|
||||||
|
|
||||||
/* expand grayscale images to the full 8 bits */
|
/* expand grayscale images to the full 8 bits */
|
||||||
@ -163,26 +163,32 @@ void read_png(char *file_name)
|
|||||||
if (info_ptr->bit_depth == 16)
|
if (info_ptr->bit_depth == 16)
|
||||||
png_set_swap(png_ptr);
|
png_set_swap(png_ptr);
|
||||||
|
|
||||||
/* add a filler byte to store rgb files as rgbx */
|
/* add a filler byte to rgb files */
|
||||||
if (info_ptr->bit_depth == 8 &&
|
if (info_ptr->bit_depth == 8 &&
|
||||||
info_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
info_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
||||||
png_set_rgbx(png_ptr);
|
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
|
||||||
|
|
||||||
/* optional call to update palette with transformations */
|
/* turn on interlace handling if you are not using png_read_image() */
|
||||||
png_start_read_image(png_ptr);
|
|
||||||
|
|
||||||
/* the easiest way to read the image */
|
|
||||||
void *row_pointers[height];
|
|
||||||
png_read_image(png_ptr, row_pointers);
|
|
||||||
|
|
||||||
/* the other way to read images - deal with interlacing */
|
|
||||||
|
|
||||||
/* turn on interlace handling */
|
|
||||||
if (info_ptr->interlace_type)
|
if (info_ptr->interlace_type)
|
||||||
number_passes = png_set_interlace_handling(png_ptr);
|
number_passes = png_set_interlace_handling(png_ptr);
|
||||||
else
|
else
|
||||||
number_passes = 1;
|
number_passes = 1;
|
||||||
|
|
||||||
|
/* optional call to update palette with transformations */
|
||||||
|
png_start_read_image(png_ptr);
|
||||||
|
|
||||||
|
/* optional call to update the info structure */
|
||||||
|
png_read_update_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
/* allocate the memory to hold the image using the fields
|
||||||
|
of png_info. */
|
||||||
|
|
||||||
|
/* the easiest way to read the image */
|
||||||
|
png_bytef *row_pointers[height];
|
||||||
|
png_read_image(png_ptr, row_pointers);
|
||||||
|
|
||||||
|
/* the other way to read images - deal with interlacing */
|
||||||
|
|
||||||
for (pass = 0; pass < number_passes; pass++)
|
for (pass = 0; pass < number_passes; pass++)
|
||||||
{
|
{
|
||||||
/* Read the image using the "sparkle" effect. */
|
/* Read the image using the "sparkle" effect. */
|
||||||
@ -191,7 +197,7 @@ void read_png(char *file_name)
|
|||||||
/* If you are only reading on row at a time, this works */
|
/* If you are only reading on row at a time, this works */
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
char *row_pointers = row[y];
|
png_bytef *row_pointers = row[y];
|
||||||
png_read_rows(png_ptr, &row_pointers, NULL, 1);
|
png_read_rows(png_ptr, &row_pointers, NULL, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,21 +315,22 @@ void write_png(char *file_name, ... other image information ...)
|
|||||||
/* swap bytes of 16 bit files to most significant bit first */
|
/* swap bytes of 16 bit files to most significant bit first */
|
||||||
png_set_swap(png_ptr);
|
png_set_swap(png_ptr);
|
||||||
|
|
||||||
/* get rid of filler bytes, pack rgb into 3 bytes */
|
/* get rid of filler bytes, pack rgb into 3 bytes. The
|
||||||
png_set_rgbx(png_ptr);
|
filler number is not used. */
|
||||||
|
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||||
|
|
||||||
/* the easiest way to write the image */
|
/* turn on interlace handling if you are not using png_write_image() */
|
||||||
void *row_pointers[height];
|
|
||||||
png_write_image(png_ptr, row_pointers);
|
|
||||||
|
|
||||||
/* the other way to write the image - deal with interlacing */
|
|
||||||
|
|
||||||
/* turn on interlace handling */
|
|
||||||
if (interlacing)
|
if (interlacing)
|
||||||
number_passes = png_set_interlace_handling(png_ptr);
|
number_passes = png_set_interlace_handling(png_ptr);
|
||||||
else
|
else
|
||||||
number_passes = 1;
|
number_passes = 1;
|
||||||
|
|
||||||
|
/* the easiest way to write the image */
|
||||||
|
png_bytef *row_pointers[height];
|
||||||
|
png_write_image(png_ptr, row_pointers);
|
||||||
|
|
||||||
|
/* the other way to write the image - deal with interlacing */
|
||||||
|
|
||||||
for (pass = 0; pass < number_passes; pass++)
|
for (pass = 0; pass < number_passes; pass++)
|
||||||
{
|
{
|
||||||
/* Write a few rows at a time. */
|
/* Write a few rows at a time. */
|
||||||
@ -332,7 +339,7 @@ void write_png(char *file_name, ... other image information ...)
|
|||||||
/* If you are only writing one row at a time, this works */
|
/* If you are only writing one row at a time, this works */
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
char *row_pointers = row[y];
|
png_bytef *row_pointers = row[y];
|
||||||
png_write_rows(png_ptr, &row_pointers, 1);
|
png_write_rows(png_ptr, &row_pointers, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
82
libpng.txt
82
libpng.txt
@ -1,9 +1,9 @@
|
|||||||
libpng.txt - a description on how to use and modify libpng
|
libpng.txt - a description on how to use and modify libpng
|
||||||
|
|
||||||
libpng 1.0 beta 1 - version 0.71
|
libpng 1.0 beta 2 - version 0.8
|
||||||
For conditions of distribution and use, see copyright notice in png.h
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
June 26, 1995
|
August 20, 1995
|
||||||
|
|
||||||
This file describes how to use and modify the PNG reference library
|
This file describes how to use and modify the PNG reference library
|
||||||
(known as libpng) for your own use. There are four sections to this
|
(known as libpng) for your own use. There are four sections to this
|
||||||
@ -325,17 +325,21 @@ PC's store them, for example), call this:
|
|||||||
png_set_swap(png_ptr);
|
png_set_swap(png_ptr);
|
||||||
|
|
||||||
PNG files store rgb pixels packed into 3 bytes. If you would rather
|
PNG files store rgb pixels packed into 3 bytes. If you would rather
|
||||||
pack them into 4 bytes, with the filler byte last, call this:
|
pack them into 4 bytes, call this:
|
||||||
|
|
||||||
if (info_ptr->bit_depth == 8 &&
|
if (info_ptr->bit_depth == 8 &&
|
||||||
info_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
info_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
||||||
png_set_rgbx(png_ptr);
|
png_set_filler(png_ptr, filler_byte, PNG_FILLER_BEFORE);
|
||||||
|
|
||||||
If you need the filler byte first, call this:
|
where filler_byte is the number to fill with, and the location is
|
||||||
|
either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
|
||||||
|
you want the filler before the rgb or after.
|
||||||
|
|
||||||
if (info_ptr->bit_depth == 8 &&
|
Finally, if you need the interlacing as discussed below, call
|
||||||
info_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
this here:
|
||||||
png_set_xrgb(png_ptr);
|
|
||||||
|
if (info_ptr->interlace_type)
|
||||||
|
number_passes = png_set_interlace_handling(png_ptr);
|
||||||
|
|
||||||
After setting the transformations, you can update your palette by
|
After setting the transformations, you can update your palette by
|
||||||
calling png_start_read_image(). This function is provided for those
|
calling png_start_read_image(). This function is provided for those
|
||||||
@ -345,7 +349,22 @@ before it reads the first row.
|
|||||||
|
|
||||||
png_start_read_image(png_ptr);
|
png_start_read_image(png_ptr);
|
||||||
|
|
||||||
That's it for the transformations. Now you can read the image data.
|
If you want, libpng will update your png_info structure to reflect
|
||||||
|
any transformations you've requested with this call. This is most
|
||||||
|
useful to update the info structures rowbytes field, so you can
|
||||||
|
use it to allocate your image memory. This function calls
|
||||||
|
png_start_read_image(), so you don't have to call both of them.
|
||||||
|
|
||||||
|
png_read_update_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
After you call png_read_update_info(), you can allocate any
|
||||||
|
memory you need to hold the image. As the actual allocation
|
||||||
|
varies among applications, no example will be given. If you
|
||||||
|
are allocating one large chunk, you may find it useful to
|
||||||
|
build an array of pointers to each row, as it will be needed
|
||||||
|
for some of the functions below.
|
||||||
|
|
||||||
|
After you've allocated memory, you can read the image data.
|
||||||
The simplest way to do this is in one function call. If you are
|
The simplest way to do this is in one function call. If you are
|
||||||
allocating enough memory to hold the whole image, you can just
|
allocating enough memory to hold the whole image, you can just
|
||||||
call png_read_image() and libpng will read in all the image data
|
call png_read_image() and libpng will read in all the image data
|
||||||
@ -399,7 +418,7 @@ call png_read_rows() the correct number of times to read in all
|
|||||||
seven images. See the PNG specification for more details on the
|
seven images. See the PNG specification for more details on the
|
||||||
interlacing scheme.
|
interlacing scheme.
|
||||||
|
|
||||||
If you want libpng to expand the images, call this:
|
If you want libpng to expand the images, call this above:
|
||||||
|
|
||||||
if (info_ptr->interlace_type)
|
if (info_ptr->interlace_type)
|
||||||
number_passes = png_set_interlace_handling(png_ptr);
|
number_passes = png_set_interlace_handling(png_ptr);
|
||||||
@ -521,6 +540,25 @@ Customizing Libpng section below.
|
|||||||
|
|
||||||
png_init_io(png_ptr, fp);
|
png_init_io(png_ptr, fp);
|
||||||
|
|
||||||
|
You now have the option of modifying how the compression library
|
||||||
|
will run. The following functions are mainly for testing, but
|
||||||
|
may be useful in certain special cases, like if you need to
|
||||||
|
write png files extremely fast and are willing to give up some
|
||||||
|
compression, or if you want to get the maximum possible compression
|
||||||
|
at the expense of slower writing. If you have no special needs
|
||||||
|
in this area, let the library do what it wants, as it has been
|
||||||
|
carefully tuned to deliver the best speed/compression ratio.
|
||||||
|
See the compression library for more details.
|
||||||
|
|
||||||
|
/* turn on or off filtering (1 or 0) */
|
||||||
|
png_set_filtering(png_struct *png_ptr, 1);
|
||||||
|
|
||||||
|
png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION);
|
||||||
|
png_set_compression_mem_level(png_ptr, 8);
|
||||||
|
png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY);
|
||||||
|
png_set_compression_window_bits(png_ptr, 15);
|
||||||
|
png_set_compression_method(png_ptr, 8);
|
||||||
|
|
||||||
You now need to fill in the png_info structure with all the data
|
You now need to fill in the png_info structure with all the data
|
||||||
you wish to write before the actual image. Note that the only thing
|
you wish to write before the actual image. Note that the only thing
|
||||||
you are allowed to write after the image is the text chunks and the
|
you are allowed to write after the image is the text chunks and the
|
||||||
@ -600,14 +638,13 @@ make sure to only enable a transformation if it will be valid for
|
|||||||
the data. For example, don't swap red and blue on grayscale data.
|
the data. For example, don't swap red and blue on grayscale data.
|
||||||
|
|
||||||
PNG files store rgb pixels packed into 3 bytes. If you would rather
|
PNG files store rgb pixels packed into 3 bytes. If you would rather
|
||||||
supply the pixels as 4 bytes per pixel, with the filler byte last,
|
supply the pixels as 4 bytes per pixel, call this:
|
||||||
call this:
|
|
||||||
|
|
||||||
png_set_rgbx(png_ptr);
|
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||||
|
|
||||||
If your filler byte goes first, call this:
|
where the 0 is not used for writing, and the location is either
|
||||||
|
PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether you
|
||||||
png_set_xrgb(png_ptr);
|
want the filler before the rgb or after.
|
||||||
|
|
||||||
PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
|
PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
|
||||||
they can, resulting in, for example, 8 pixels per byte for 1 bit files.
|
they can, resulting in, for example, 8 pixels per byte for 1 bit files.
|
||||||
@ -819,3 +856,16 @@ needed outside libpng are protected by the PNG_INTERNAL definition,
|
|||||||
which is only defined for those routines inside libpng itself. The
|
which is only defined for those routines inside libpng itself. The
|
||||||
files in libpng proper only include png.h.
|
files in libpng proper only include png.h.
|
||||||
|
|
||||||
|
Removing unwanted object code:
|
||||||
|
|
||||||
|
There are a bunch of #define's in png.h that control what parts of
|
||||||
|
libpng are compiled. All the defines end in _SUPPORT. If you are
|
||||||
|
not using an ability, you can change the #define to #undef and
|
||||||
|
save yourself code and data space. All the reading and writing
|
||||||
|
specific code are in seperate files, so the linker should only grab
|
||||||
|
the files it needs. However, if you want to make sure, or if you
|
||||||
|
are building a stand alone library, all the reading files start with
|
||||||
|
pngr and all the writing files start with pngw. The files that
|
||||||
|
don't match either (like png.c, pngtrans.c, etc.) are used for
|
||||||
|
both reading and writing, and always need to be included.
|
||||||
|
|
||||||
|
43
makefile
43
makefile
@ -2,18 +2,19 @@
|
|||||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
# For conditions of distribution and use, see copyright notice in png.h
|
# For conditions of distribution and use, see copyright notice in png.h
|
||||||
|
|
||||||
CC=gcc
|
CC=cc
|
||||||
CFLAGS=-I../zlib -O3
|
CFLAGS=-I../zlib -O
|
||||||
LDFLAGS=-L. -L../zlib/ -lpng -lgz -lm
|
LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
|
||||||
|
|
||||||
RANLIB=ranlib
|
#RANLIB=ranlib
|
||||||
#RANLIB=echo
|
RANLIB=echo
|
||||||
|
|
||||||
# where make install puts libpng.a and png.h
|
# where make install puts libpng.a and png.h
|
||||||
prefix=/usr/local
|
prefix=/usr/local
|
||||||
|
|
||||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
||||||
pngread.o pngstub.o pngwrite.o pngrtran.o pngwtran.o
|
pngread.o pngio.o pngwrite.o pngrtran.o pngwtran.o \
|
||||||
|
pngmem.o pngerror.o
|
||||||
|
|
||||||
all: libpng.a pngtest
|
all: libpng.a pngtest
|
||||||
|
|
||||||
@ -22,13 +23,18 @@ libpng.a: $(OBJS)
|
|||||||
$(RANLIB) $@
|
$(RANLIB) $@
|
||||||
|
|
||||||
pngtest: pngtest.o libpng.a
|
pngtest: pngtest.o libpng.a
|
||||||
cc -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
|
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
|
||||||
|
|
||||||
|
test: pngtest
|
||||||
|
./pngtest
|
||||||
|
|
||||||
install: libpng.a
|
install: libpng.a
|
||||||
-@mkdir $(prefix)/include
|
-@mkdir $(prefix)/include
|
||||||
-@mkdir $(prefix)/lib
|
-@mkdir $(prefix)/lib
|
||||||
cp png.h $(prefix)/include
|
cp png.h $(prefix)/include
|
||||||
|
cp pngconf.h $(prefix)/include
|
||||||
chmod 644 $(prefix)/include/png.h
|
chmod 644 $(prefix)/include/png.h
|
||||||
|
chmod 644 $(prefix)/include/pngconf.h
|
||||||
cp libpng.a $(prefix)/lib
|
cp libpng.a $(prefix)/lib
|
||||||
chmod 644 $(prefix)/lib/libpng.a
|
chmod 644 $(prefix)/lib/libpng.a
|
||||||
|
|
||||||
@ -37,13 +43,16 @@ clean:
|
|||||||
|
|
||||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||||
|
|
||||||
pngrcb.o: png.h
|
png.o: png.h pngconf.h
|
||||||
pngread.o: png.h
|
pngerror.o: png.h pngconf.h
|
||||||
pngrtran.o: png.h
|
pngio.o: png.h pngconf.h
|
||||||
pngrutil.o: png.h
|
pngmem.o: png.h pngconf.h
|
||||||
pngstub.o: png.h
|
pngrcb.o: png.h pngconf.h
|
||||||
pngtest.o: png.h
|
pngread.o: png.h pngconf.h
|
||||||
pngtrans.o: png.h
|
pngrtran.o: png.h pngconf.h
|
||||||
pngwrite.o: png.h
|
pngrutil.o: png.h pngconf.h
|
||||||
pngwtran.o: png.h
|
pngtest.o: png.h pngconf.h
|
||||||
pngwutil.o: png.h
|
pngtrans.o: png.h pngconf.h
|
||||||
|
pngwrite.o: png.h pngconf.h
|
||||||
|
pngwtran.o: png.h pngconf.h
|
||||||
|
pngwutil.o: png.h pngconf.h
|
||||||
|
61
makefile.knr
61
makefile.knr
@ -1,61 +0,0 @@
|
|||||||
# makefile for libpng
|
|
||||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
|
||||||
# For conditions of distribution and use, see copyright notice in png.h
|
|
||||||
|
|
||||||
CC=cc
|
|
||||||
CFLAGS=-I../zlib -O
|
|
||||||
LDFLAGS=-L. -L../zlib/ -lpng -lgz -lm
|
|
||||||
# flags for ansi2knr
|
|
||||||
ANSI2KNRFLAGS=
|
|
||||||
|
|
||||||
RANLIB=ranlib
|
|
||||||
#RANLIB=echo
|
|
||||||
|
|
||||||
# where make install puts libpng.a and png.h
|
|
||||||
prefix=/usr/local
|
|
||||||
|
|
||||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
|
||||||
pngread.o pngstub.o pngwrite.o pngrtran.o pngwtran.o
|
|
||||||
|
|
||||||
all: ansi2knr libpng.a pngtest
|
|
||||||
|
|
||||||
# general rule to allow ansi2knr to work
|
|
||||||
.c.o:
|
|
||||||
./ansi2knr $*.c T$*.c
|
|
||||||
$(CC) $(CFLAGS) -c T$*.c
|
|
||||||
rm -f T$*.c $*.o
|
|
||||||
mv T$*.o $*.o
|
|
||||||
|
|
||||||
ansi2knr: ansi2knr.c
|
|
||||||
$(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr ansi2knr.c
|
|
||||||
|
|
||||||
libpng.a: ansi2knr $(OBJS)
|
|
||||||
ar rc $@ $(OBJS)
|
|
||||||
$(RANLIB) $@
|
|
||||||
|
|
||||||
pngtest: pngtest.o libpng.a ansi2knr
|
|
||||||
cc -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
|
|
||||||
|
|
||||||
install: libpng.a
|
|
||||||
-@mkdir $(prefix)/include
|
|
||||||
-@mkdir $(prefix)/lib
|
|
||||||
cp png.h $(prefix)/include
|
|
||||||
chmod 644 $(prefix)/include/png.h
|
|
||||||
cp libpng.a $(prefix)/lib
|
|
||||||
chmod 644 $(prefix)/lib/libpng.a
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.o libpng.a pngtest pngout.png ansi2knr
|
|
||||||
|
|
||||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
|
||||||
|
|
||||||
pngrcb.o: png.h
|
|
||||||
pngread.o: png.h
|
|
||||||
pngrtran.o: png.h
|
|
||||||
pngrutil.o: png.h
|
|
||||||
pngstub.o: png.h
|
|
||||||
pngtest.o: png.h
|
|
||||||
pngtrans.o: png.h
|
|
||||||
pngwrite.o: png.h
|
|
||||||
pngwtran.o: png.h
|
|
||||||
pngwutil.o: png.h
|
|
50
makefile.mip
50
makefile.mip
@ -1,50 +0,0 @@
|
|||||||
# makefile for libpng
|
|
||||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
|
||||||
# For conditions of distribution and use, see copyright notice in png.h
|
|
||||||
|
|
||||||
CC=cc
|
|
||||||
CFLAGS=-I../zlib -O -systype sysv -DSYSV -w -Dmips
|
|
||||||
#CFLAGS=-O
|
|
||||||
LDFLAGS=-L. -L../zlib/ -lpng -lgz -lm
|
|
||||||
|
|
||||||
#RANLIB=ranlib
|
|
||||||
RANLIB=echo
|
|
||||||
|
|
||||||
# where make install puts libpng.a and png.h
|
|
||||||
prefix=/usr/local
|
|
||||||
|
|
||||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
|
||||||
pngread.o pngstub.o pngwrite.o pngrtran.o pngwtran.o
|
|
||||||
|
|
||||||
all: libpng.a pngtest
|
|
||||||
|
|
||||||
libpng.a: $(OBJS)
|
|
||||||
ar rc $@ $(OBJS)
|
|
||||||
$(RANLIB) $@
|
|
||||||
|
|
||||||
pngtest: pngtest.o libpng.a
|
|
||||||
cc -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
|
|
||||||
|
|
||||||
install: libpng.a
|
|
||||||
-@mkdir $(prefix)/include
|
|
||||||
-@mkdir $(prefix)/lib
|
|
||||||
cp png.h $(prefix)/include
|
|
||||||
chmod 644 $(prefix)/include/png.h
|
|
||||||
cp libpng.a $(prefix)/lib
|
|
||||||
chmod 644 $(prefix)/lib/libpng.a
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.o libpng.a pngtest pngout.png
|
|
||||||
|
|
||||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
|
||||||
|
|
||||||
pngrcb.o: png.h
|
|
||||||
pngread.o: png.h
|
|
||||||
pngrtran.o: png.h
|
|
||||||
pngrutil.o: png.h
|
|
||||||
pngstub.o: png.h
|
|
||||||
pngtest.o: png.h
|
|
||||||
pngtrans.o: png.h
|
|
||||||
pngwrite.o: png.h
|
|
||||||
pngwtran.o: png.h
|
|
||||||
pngwutil.o: png.h
|
|
49
makefile.std
49
makefile.std
@ -1,49 +0,0 @@
|
|||||||
# makefile for libpng
|
|
||||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
|
||||||
# For conditions of distribution and use, see copyright notice in png.h
|
|
||||||
|
|
||||||
CC=cc
|
|
||||||
CFLAGS=-I../zlib -O
|
|
||||||
LDFLAGS=-L. -L../zlib/ -lpng -lgz -lm
|
|
||||||
|
|
||||||
#RANLIB=ranlib
|
|
||||||
RANLIB=echo
|
|
||||||
|
|
||||||
# where make install puts libpng.a and png.h
|
|
||||||
prefix=/usr/local
|
|
||||||
|
|
||||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
|
||||||
pngread.o pngstub.o pngwrite.o pngrtran.o pngwtran.o
|
|
||||||
|
|
||||||
all: libpng.a pngtest
|
|
||||||
|
|
||||||
libpng.a: $(OBJS)
|
|
||||||
ar rc $@ $(OBJS)
|
|
||||||
$(RANLIB) $@
|
|
||||||
|
|
||||||
pngtest: pngtest.o libpng.a
|
|
||||||
cc -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
|
|
||||||
|
|
||||||
install: libpng.a
|
|
||||||
-@mkdir $(prefix)/include
|
|
||||||
-@mkdir $(prefix)/lib
|
|
||||||
cp png.h $(prefix)/include
|
|
||||||
chmod 644 $(prefix)/include/png.h
|
|
||||||
cp libpng.a $(prefix)/lib
|
|
||||||
chmod 644 $(prefix)/lib/libpng.a
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.o libpng.a pngtest pngout.png
|
|
||||||
|
|
||||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
|
||||||
|
|
||||||
pngrcb.o: png.h
|
|
||||||
pngread.o: png.h
|
|
||||||
pngrtran.o: png.h
|
|
||||||
pngrutil.o: png.h
|
|
||||||
pngstub.o: png.h
|
|
||||||
pngtest.o: png.h
|
|
||||||
pngtrans.o: png.h
|
|
||||||
pngwrite.o: png.h
|
|
||||||
pngwtran.o: png.h
|
|
||||||
pngwutil.o: png.h
|
|
53
png.c
53
png.c
@ -1,16 +1,20 @@
|
|||||||
|
|
||||||
/* png.c - location for general purpose png functions
|
/* png.c - location for general purpose png functions
|
||||||
|
|
||||||
libpng 1.0 beta 1 - version 0.71
|
libpng 1.0 beta 2 - version 0.81
|
||||||
For conditions of distribution and use, see copyright notice in png.h
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
June 26, 1995
|
August 24, 1995
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PNG_INTERNAL
|
#define PNG_INTERNAL
|
||||||
#define PNG_NO_EXTERN
|
#define PNG_NO_EXTERN
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
|
|
||||||
|
/* version information for c files. This better match the version
|
||||||
|
string defined in png.h */
|
||||||
|
char png_libpng_ver[] = "0.81";
|
||||||
|
|
||||||
/* place to hold the signiture string for a png file. */
|
/* place to hold the signiture string for a png file. */
|
||||||
png_byte png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
png_byte png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||||
|
|
||||||
@ -21,17 +25,39 @@ png_byte png_IHDR[4] = { 73, 72, 68, 82};
|
|||||||
png_byte png_IDAT[4] = { 73, 68, 65, 84};
|
png_byte png_IDAT[4] = { 73, 68, 65, 84};
|
||||||
png_byte png_IEND[4] = { 73, 69, 78, 68};
|
png_byte png_IEND[4] = { 73, 69, 78, 68};
|
||||||
png_byte png_PLTE[4] = { 80, 76, 84, 69};
|
png_byte png_PLTE[4] = { 80, 76, 84, 69};
|
||||||
|
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||||
png_byte png_gAMA[4] = {103, 65, 77, 65};
|
png_byte png_gAMA[4] = {103, 65, 77, 65};
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||||
png_byte png_sBIT[4] = {115, 66, 73, 84};
|
png_byte png_sBIT[4] = {115, 66, 73, 84};
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||||
png_byte png_cHRM[4] = { 99, 72, 82, 77};
|
png_byte png_cHRM[4] = { 99, 72, 82, 77};
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||||
png_byte png_tRNS[4] = {116, 82, 78, 83};
|
png_byte png_tRNS[4] = {116, 82, 78, 83};
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
|
||||||
png_byte png_bKGD[4] = { 98, 75, 71, 68};
|
png_byte png_bKGD[4] = { 98, 75, 71, 68};
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
|
||||||
png_byte png_hIST[4] = {104, 73, 83, 84};
|
png_byte png_hIST[4] = {104, 73, 83, 84};
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED)
|
||||||
png_byte png_tEXt[4] = {116, 69, 88, 116};
|
png_byte png_tEXt[4] = {116, 69, 88, 116};
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||||
png_byte png_zTXt[4] = {122, 84, 88, 116};
|
png_byte png_zTXt[4] = {122, 84, 88, 116};
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||||
png_byte png_pHYs[4] = {112, 72, 89, 115};
|
png_byte png_pHYs[4] = {112, 72, 89, 115};
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||||
png_byte png_oFFs[4] = {111, 70, 70, 115};
|
png_byte png_oFFs[4] = {111, 70, 70, 115};
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
|
||||||
png_byte png_tIME[4] = {116, 73, 77, 69};
|
png_byte png_tIME[4] = {116, 73, 77, 69};
|
||||||
|
#endif
|
||||||
|
|
||||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||||
|
|
||||||
@ -78,18 +104,18 @@ png_check_sig(png_byte *sig, int num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Function to allocate memory for zlib. */
|
/* Function to allocate memory for zlib. */
|
||||||
voidp
|
voidpf
|
||||||
png_zalloc(voidp png_ptr, uInt items, uInt size)
|
png_zalloc(voidpf png_ptr, uInt items, uInt size)
|
||||||
{
|
{
|
||||||
return ((voidp)png_large_malloc((png_struct *)png_ptr,
|
return ((voidpf)png_large_malloc((png_struct FAR *)png_ptr,
|
||||||
(png_uint_32)items * (png_uint_32)size));
|
(png_uint_32)items * (png_uint_32)size));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* function to free memory for zlib */
|
/* function to free memory for zlib */
|
||||||
void
|
void
|
||||||
png_zfree(voidp png_ptr, voidp ptr)
|
png_zfree(voidpf png_ptr, voidpf ptr)
|
||||||
{
|
{
|
||||||
png_large_free((png_struct *)png_ptr, (void *)ptr);
|
png_large_free((png_struct FAR *)png_ptr, (voidpf)ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reset the crc variable to 32 bits of 1's. Care must be taken
|
/* reset the crc variable to 32 bits of 1's. Care must be taken
|
||||||
@ -135,10 +161,10 @@ make_crc_table(void)
|
|||||||
initialized to all 1's, and the transmitted value is the 1's complement
|
initialized to all 1's, and the transmitted value is the 1's complement
|
||||||
of the final running crc. */
|
of the final running crc. */
|
||||||
static png_uint_32
|
static png_uint_32
|
||||||
update_crc(png_uint_32 crc, png_byte *buf, png_uint_32 len)
|
update_crc(png_uint_32 crc, png_bytef *buf, png_uint_32 len)
|
||||||
{
|
{
|
||||||
png_uint_32 c;
|
png_uint_32 c;
|
||||||
png_byte *p;
|
png_bytef *p;
|
||||||
png_uint_32 n;
|
png_uint_32 n;
|
||||||
|
|
||||||
c = crc;
|
c = crc;
|
||||||
@ -163,10 +189,15 @@ update_crc(png_uint_32 crc, png_byte *buf, png_uint_32 len)
|
|||||||
would need to use huge pointers to access all that data. If you
|
would need to use huge pointers to access all that data. If you
|
||||||
need this, put huge here and above. */
|
need this, put huge here and above. */
|
||||||
void
|
void
|
||||||
png_calculate_crc(png_struct *png_ptr, png_byte *ptr,
|
png_calculate_crc(png_struct *png_ptr, png_bytef *ptr,
|
||||||
png_uint_32 length)
|
png_uint_32 length)
|
||||||
{
|
{
|
||||||
png_ptr->crc = update_crc(png_ptr->crc, ptr, length);
|
png_ptr->crc = update_crc(png_ptr->crc, ptr, length);
|
||||||
}
|
}
|
||||||
|
void
|
||||||
|
png_info_init(png_info *info)
|
||||||
|
{
|
||||||
|
/* set everything to 0 */
|
||||||
|
memset(info, 0, sizeof (png_info));
|
||||||
|
}
|
||||||
|
|
||||||
|
16
pngchang.txt
16
pngchang.txt
@ -40,5 +40,21 @@ version 0.7
|
|||||||
version 0.71
|
version 0.71
|
||||||
changed pngtest.png for zlib 0.93
|
changed pngtest.png for zlib 0.93
|
||||||
fixed error in libpng.txt and example.c
|
fixed error in libpng.txt and example.c
|
||||||
|
version 0.8
|
||||||
|
cleaned up some bugs
|
||||||
|
added png_set_filler()
|
||||||
|
split up pngstub.c into pngmem.c, pngio.c, and pngerror.c
|
||||||
|
added #define's to remove unwanted code
|
||||||
|
moved png_info_init() to png.c
|
||||||
|
added old_size into png_realloc()
|
||||||
|
added functions to manually set filtering and compression info
|
||||||
|
changed compression parameters based on image type
|
||||||
|
optimized filter selection code
|
||||||
|
added version info
|
||||||
|
changed external functions passing floats to doubles (k&r problems?)
|
||||||
|
put all the configurable stuff in pngconf.h
|
||||||
|
enabled png_set_shift to work with paletted images on read
|
||||||
|
added png_read_update_info() - updates info structure with transformations
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
256
pngconf.h
Normal file
256
pngconf.h
Normal file
@ -0,0 +1,256 @@
|
|||||||
|
|
||||||
|
/* pngconf.c - machine configurable file for libpng
|
||||||
|
|
||||||
|
libpng 1.0 beta 2 - version 0.81
|
||||||
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
|
August 24, 1995
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Any machine specific code is near the front of this file, so if you
|
||||||
|
are configuring libpng for a machine, you may want to read the section
|
||||||
|
starting here down to where it starts to typedef png_color, png_text,
|
||||||
|
and png_info */
|
||||||
|
|
||||||
|
#ifndef PNGCONF_H
|
||||||
|
#define PNGCONF_H
|
||||||
|
|
||||||
|
/* this is the size of the compression buffer, and thus the size of
|
||||||
|
an IDAT chunk. Make this whatever size you feel is best for your
|
||||||
|
machine. One of these will be allocated per png_struct. When this
|
||||||
|
is full, it writes the data to the disk, and does some other
|
||||||
|
calculations. Making this an extreamly small size will slow
|
||||||
|
the library down, but you may want to experiment to determine
|
||||||
|
where it becomes significant, if you are concerned with memory
|
||||||
|
usage. Note that zlib allocates at least 32Kb also. For readers,
|
||||||
|
this describes the size of the buffer available to read the data in.
|
||||||
|
Unless this gets smaller then the size of a row (compressed),
|
||||||
|
it should not make much difference how big this is. */
|
||||||
|
|
||||||
|
#define PNG_ZBUF_SIZE 8192
|
||||||
|
|
||||||
|
/* While libpng currently uses zlib for it's compression, it has been designed
|
||||||
|
to stand on it's own. Towards this end, there are two defines that are
|
||||||
|
used to help portability between machines. To make it simpler to
|
||||||
|
setup libpng on a machine, this currently uses zlib's definitions, so
|
||||||
|
any changes should be made in zlib. Libpng will check zlib's settings
|
||||||
|
and adjust it's own accordingly. */
|
||||||
|
|
||||||
|
/* if you are running on a machine where you cannot allocate more then
|
||||||
|
64K of memory, uncomment this. While libpng will not normally need
|
||||||
|
that much memory in a chunk (unless you load up a very large file),
|
||||||
|
zlib needs to know how big of a chunk it can use, and libpng thus
|
||||||
|
makes sure to check any memory allocation to verify it will fit
|
||||||
|
into memory.
|
||||||
|
#define PNG_MAX_ALLOC_64K
|
||||||
|
*/
|
||||||
|
#ifdef MAXSEG_64K
|
||||||
|
#define PNG_MAX_ALLOC_64K
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* this macro protects us against machines that don't have function
|
||||||
|
prototypes. If your compiler does not handle function prototypes,
|
||||||
|
define this macro. I've always been able to use _NO_PROTO as the
|
||||||
|
indicator, but you may need to drag the empty declaration out in
|
||||||
|
front of here, or change the ifdef to suit your own needs. */
|
||||||
|
#ifndef PNGARG
|
||||||
|
|
||||||
|
#ifdef OF
|
||||||
|
#define PNGARG(arglist) OF(arglist)
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifdef _NO_PROTO
|
||||||
|
#define PNGARG(arglist)
|
||||||
|
#else
|
||||||
|
#define PNGARG(arglist) arglist
|
||||||
|
#endif /* _NO_PROTO */
|
||||||
|
|
||||||
|
#endif /* OF */
|
||||||
|
|
||||||
|
#endif /* PNGARG */
|
||||||
|
|
||||||
|
/* enough people need this for various reasons to include it here */
|
||||||
|
#ifndef MACOS
|
||||||
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
/* need the time information for reading tIME chunks */
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
/* for FILE. If you are not using standard io, you don't need this */
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* include setjmp.h for error handling */
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
#ifdef BSD
|
||||||
|
#include <strings.h>
|
||||||
|
#else
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* other defines for things like memory and the like can go here. These
|
||||||
|
are the only files included in libpng, so if you need to change them,
|
||||||
|
change them here. They are only included if PNG_INTERNAL is defined. */
|
||||||
|
#ifdef PNG_INTERNAL
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/* other defines specific to compilers can go here. Try to keep
|
||||||
|
them inside an appropriate ifdef/endif pair for portability */
|
||||||
|
|
||||||
|
/* for some reason, Borland C++ defines memcmp, etc. in mem.h, not
|
||||||
|
stdlib.h like it should (I think). Or perhaps this is a C++
|
||||||
|
feature */
|
||||||
|
#ifdef __TURBOC__
|
||||||
|
#include <mem.h>
|
||||||
|
#include "alloc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* this controls how fine the dithering gets. As this allocates
|
||||||
|
a largish chunk of memory (32K), those who are not as concerned
|
||||||
|
with dithering quality can decrease some or all of these */
|
||||||
|
#define PNG_DITHER_RED_BITS 5
|
||||||
|
#define PNG_DITHER_GREEN_BITS 5
|
||||||
|
#define PNG_DITHER_BLUE_BITS 5
|
||||||
|
|
||||||
|
/* this controls how fine the gamma correction becomes when you
|
||||||
|
are only interested in 8 bits anyway. Increasing this value
|
||||||
|
results in more memory being used, and more pow() functions
|
||||||
|
being called to fill in the gamma tables. Don't get this
|
||||||
|
value less then 8, and even that may not work (I haven't tested
|
||||||
|
it). */
|
||||||
|
|
||||||
|
#define PNG_MAX_GAMMA_8 11
|
||||||
|
|
||||||
|
#endif /* PNG_INTERNAL */
|
||||||
|
|
||||||
|
/* The following defines give you the ability to remove code
|
||||||
|
from the library that you will not be using. I wish I
|
||||||
|
could figure out how to automate this, but I can't do
|
||||||
|
that without making it seriously hard on the users. So
|
||||||
|
if you are not using an ability, change the #define to
|
||||||
|
and #undef, and that part of the library will not be
|
||||||
|
compiled. If your linker can't find a function, you
|
||||||
|
may want to make sure the ability is defined here.
|
||||||
|
Some of these depend upon some others being defined.
|
||||||
|
I haven't figured out all the interactions here, so
|
||||||
|
you may have to experiment awhile to get everything
|
||||||
|
to compile.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Any transformations you will not be using can be undef'ed here */
|
||||||
|
|
||||||
|
#define PNG_READ_INTERLACING_SUPPORTED
|
||||||
|
#define PNG_READ_EXPAND_SUPPORTED
|
||||||
|
#define PNG_READ_SHIFT_SUPPORTED
|
||||||
|
#define PNG_READ_PACK_SUPPORTED
|
||||||
|
#define PNG_READ_BGR_SUPPORTED
|
||||||
|
#define PNG_READ_SWAP_SUPPORTED
|
||||||
|
#define PNG_READ_INVERT_SUPPORTED
|
||||||
|
#define PNG_READ_DITHER_SUPPORTED
|
||||||
|
#define PNG_READ_BACKGROUND_SUPPORTED
|
||||||
|
#define PNG_READ_16_TO_8_SUPPORTED
|
||||||
|
#define PNG_READ_FILLER_SUPPORTED
|
||||||
|
#define PNG_READ_GAMMA_SUPPORTED
|
||||||
|
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
|
||||||
|
|
||||||
|
#define PNG_WRITE_INTERLACING_SUPPORTED
|
||||||
|
#define PNG_WRITE_SHIFT_SUPPORTED
|
||||||
|
#define PNG_WRITE_PACK_SUPPORTED
|
||||||
|
#define PNG_WRITE_BGR_SUPPORTED
|
||||||
|
#define PNG_WRITE_SWAP_SUPPORTED
|
||||||
|
#define PNG_WRITE_INVERT_SUPPORTED
|
||||||
|
#define PNG_WRITE_FILLER_SUPPORTED
|
||||||
|
|
||||||
|
/* any chunks you are not interested in, you can undef here. The
|
||||||
|
ones that allocate memory may be expecially important (hIST,
|
||||||
|
tEXt, zTXt, tRNS) Others will just save time and make png_info
|
||||||
|
smaller. OPT_PLTE only disables the optional palette in RGB
|
||||||
|
and RGB Alpha images. */
|
||||||
|
|
||||||
|
#define PNG_READ_gAMA_SUPPORTED
|
||||||
|
#define PNG_READ_sBIT_SUPPORTED
|
||||||
|
#define PNG_READ_cHRM_SUPPORTED
|
||||||
|
#define PNG_READ_tRNS_SUPPORTED
|
||||||
|
#define PNG_READ_bKGD_SUPPORTED
|
||||||
|
#define PNG_READ_hIST_SUPPORTED
|
||||||
|
#define PNG_READ_pHYs_SUPPORTED
|
||||||
|
#define PNG_READ_oFFs_SUPPORTED
|
||||||
|
#define PNG_READ_tIME_SUPPORTED
|
||||||
|
#define PNG_READ_tEXt_SUPPORTED
|
||||||
|
#define PNG_READ_zTXt_SUPPORTED
|
||||||
|
#define PNG_READ_OPT_PLTE_SUPPORTED
|
||||||
|
|
||||||
|
#define PNG_WRITE_gAMA_SUPPORTED
|
||||||
|
#define PNG_WRITE_sBIT_SUPPORTED
|
||||||
|
#define PNG_WRITE_cHRM_SUPPORTED
|
||||||
|
#define PNG_WRITE_tRNS_SUPPORTED
|
||||||
|
#define PNG_WRITE_bKGD_SUPPORTED
|
||||||
|
#define PNG_WRITE_hIST_SUPPORTED
|
||||||
|
#define PNG_WRITE_pHYs_SUPPORTED
|
||||||
|
#define PNG_WRITE_oFFs_SUPPORTED
|
||||||
|
#define PNG_WRITE_tIME_SUPPORTED
|
||||||
|
#define PNG_WRITE_tEXt_SUPPORTED
|
||||||
|
#define PNG_WRITE_zTXt_SUPPORTED
|
||||||
|
|
||||||
|
/* some typedefs to get us started. These should be safe on most of the
|
||||||
|
common platforms. The typedefs should be at least as large
|
||||||
|
as the numbers suggest (a png_uint_32 must be at least 32 bits long),
|
||||||
|
but they don't have to be exactly that size. */
|
||||||
|
|
||||||
|
typedef unsigned long png_uint_32;
|
||||||
|
typedef long png_int_32;
|
||||||
|
typedef unsigned short png_uint_16;
|
||||||
|
typedef short png_int_16;
|
||||||
|
typedef unsigned char png_byte;
|
||||||
|
|
||||||
|
/* this is usually size_t. it is typedef'ed just in case you need it to
|
||||||
|
change (I'm not sure if you will or not, so I thought I'd be safe) */
|
||||||
|
typedef size_t png_size_t;
|
||||||
|
|
||||||
|
/* The following is needed for medium model support. It cannot be in the
|
||||||
|
PNG_INTERNAL section. Needs modification for other compilers besides
|
||||||
|
MSC. Model independent support declares all arrays that might be very
|
||||||
|
large using the far keyword. The Zlib version used must also support
|
||||||
|
model independent data. As of version Zlib .95, the necessary changes
|
||||||
|
have been made in Zlib. The USE_FAR_KEYWORD define triggers other
|
||||||
|
changes that are needed. Most of the far keyword changes are hidden
|
||||||
|
inside typedefs with suffix "f". Tim Wegner */
|
||||||
|
|
||||||
|
#if defined(FAR) && defined(M_I86MM) /* MSC Medium model */
|
||||||
|
# define USE_FAR_KEYWORD
|
||||||
|
#else
|
||||||
|
# define FAR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef unsigned char FAR png_bytef;
|
||||||
|
|
||||||
|
/* End medium model changes to be in zconf.h */
|
||||||
|
|
||||||
|
/* User may want to use these so not in PNG_INTERNAL. Any library functions
|
||||||
|
that are passed far data must be model independent. */
|
||||||
|
#if defined(USE_FAR_KEYWORD) /* memory model independent fns */
|
||||||
|
# define png_strcpy _fstrcpy
|
||||||
|
# define png_strcat _fstrcat
|
||||||
|
# define png_strlen _fstrlen
|
||||||
|
# define png_strcmp _fstrcmp
|
||||||
|
# define png_memcpy _fmemcpy
|
||||||
|
# define png_memset _fmemset
|
||||||
|
#else /* use the usual functions */
|
||||||
|
# define png_strcpy strcpy
|
||||||
|
# define png_strcat strcat
|
||||||
|
# define png_strlen strlen
|
||||||
|
# define png_strcmp strcmp
|
||||||
|
# define png_memcpy memcpy
|
||||||
|
# define png_memset memset
|
||||||
|
#endif
|
||||||
|
/* End of memory model independent support */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* PNGCONF_H */
|
||||||
|
|
46
pngerror.c
Normal file
46
pngerror.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
/* pngstub.c - stub functions for i/o and memory allocation
|
||||||
|
|
||||||
|
libpng 1.0 beta 2 - version 0.81
|
||||||
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
|
August 24, 1995
|
||||||
|
|
||||||
|
This file provides a location for all error handling. Users which
|
||||||
|
need special error handling are expected to modify the code in this
|
||||||
|
file to meet their needs. See the instructions at each function. */
|
||||||
|
|
||||||
|
#define PNG_INTERNAL
|
||||||
|
#include "png.h"
|
||||||
|
|
||||||
|
/* This function is called whenever there is an error. Replace with
|
||||||
|
however you wish to handle the error. Note that this function
|
||||||
|
MUST NOT return, or the program will crash */
|
||||||
|
void
|
||||||
|
png_error(png_structf *png_ptr, char *message)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "libpng error: %s\n", message);
|
||||||
|
#ifdef USE_FAR_KEYWORD
|
||||||
|
{
|
||||||
|
jmp_buf jmpbuf;
|
||||||
|
png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf));
|
||||||
|
longjmp(jmpbuf, 1);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
longjmp(png_ptr->jmpbuf, 1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This function is called when there is a warning, but the library
|
||||||
|
thinks it can continue anyway. You don't have to do anything here
|
||||||
|
if you don't want to. In the default configuration, png_ptr is
|
||||||
|
not used, but it is passed in case it may be useful. */
|
||||||
|
void
|
||||||
|
png_warning(png_struct *png_ptr, char *message)
|
||||||
|
{
|
||||||
|
if (!png_ptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fprintf(stderr, "libpng warning: %s\n", message);
|
||||||
|
}
|
||||||
|
|
180
pngio.c
Normal file
180
pngio.c
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
|
||||||
|
/* pngstub.c - stub functions for i/o and memory allocation
|
||||||
|
|
||||||
|
libpng 1.0 beta 2 - version 0.81
|
||||||
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
|
August 24, 1995
|
||||||
|
|
||||||
|
This file provides a location for all input/output. Users which need
|
||||||
|
special handling are expected to modify the code in this file to meet
|
||||||
|
their needs. See the instructions at each function. */
|
||||||
|
|
||||||
|
#define PNG_INTERNAL
|
||||||
|
#include "png.h"
|
||||||
|
|
||||||
|
/* Write the data to whatever output you are using. The default
|
||||||
|
routine writes to a file pointer. If you need to write to something
|
||||||
|
else, this is the place to do it. We suggest saving the old code
|
||||||
|
for future use, possibly in a #define. Note that this routine sometimes
|
||||||
|
gets called with very small lengths, so you should implement some kind
|
||||||
|
of simple buffering if you are using unbuffered writes. This should
|
||||||
|
never be asked to write more then 64K on a 16 bit machine. The cast
|
||||||
|
to png_size_t is there for insurance, but if you are having problems
|
||||||
|
with it, you can take it out. Just be sure to cast length to whatever
|
||||||
|
fwrite needs in that spot if you don't have a function prototype for
|
||||||
|
it. */
|
||||||
|
|
||||||
|
#ifndef USE_FAR_KEYWORD
|
||||||
|
void
|
||||||
|
png_write_data(png_struct *png_ptr, png_bytef *data, png_uint_32 length)
|
||||||
|
{
|
||||||
|
png_uint_32 check;
|
||||||
|
|
||||||
|
check = fwrite(data, 1, (png_size_t)length, png_ptr->fp);
|
||||||
|
if (check != length)
|
||||||
|
{
|
||||||
|
png_error(png_ptr, "Write Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* this is the model-independent version. Since the standard I/O library
|
||||||
|
can't handle far buffers in the medium and small models, we have to copy
|
||||||
|
the data.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define NEAR_BUF_SIZE 1024
|
||||||
|
#define MIN(a,b) (a <= b ? a : b)
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/* for FP_OFF */
|
||||||
|
#include <dos.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
png_write_data(png_struct *png_ptr, png_bytef *data, png_uint_32 length)
|
||||||
|
{
|
||||||
|
png_uint_32 check;
|
||||||
|
png_byte *n_data;
|
||||||
|
|
||||||
|
/* Check if data really is near. If so, use usual code. */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/* do it this way just to quiet warning */
|
||||||
|
FP_OFF(n_data) = FP_OFF(data);
|
||||||
|
if(FP_SEG(n_data) == FP_SEG(data))
|
||||||
|
#else
|
||||||
|
/* this works in MSC also but with lost segment warning */
|
||||||
|
n_data = (png_byte *)data;
|
||||||
|
if((png_bytef *)n_data == data)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
check = fwrite(n_data, 1, (png_size_t)length, png_ptr->fp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
png_byte buf[NEAR_BUF_SIZE];
|
||||||
|
png_size_t written, remaining, err;
|
||||||
|
check = 0;
|
||||||
|
remaining = (png_size_t)length;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
written = MIN(NEAR_BUF_SIZE,remaining);
|
||||||
|
png_memcpy(buf,data,written); /* copy far buffer to near buffer */
|
||||||
|
err = fwrite(buf, 1, written, png_ptr->fp);
|
||||||
|
if(err != written)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
check += err;
|
||||||
|
data += written;
|
||||||
|
remaining -= written;
|
||||||
|
}
|
||||||
|
while(remaining != 0);
|
||||||
|
}
|
||||||
|
if (check != length)
|
||||||
|
{
|
||||||
|
png_error(png_ptr, "Write Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Read the data from whatever input you are using. The default
|
||||||
|
routine reads from a file pointer. If you need to read from something
|
||||||
|
else, this is the place to do it. We suggest saving the old code
|
||||||
|
for future use. Note that this routine sometimes gets called with
|
||||||
|
very small lengths, so you should implement some kind of simple
|
||||||
|
buffering if you are using unbuffered reads. This should
|
||||||
|
never be asked to read more then 64K on a 16 bit machine. The cast
|
||||||
|
to png_size_t is there for insurance, but if you are having problems
|
||||||
|
with it, you can take it out. Just be sure to cast length to whatever
|
||||||
|
fread needs in that spot if you don't have a function prototype for
|
||||||
|
it. */
|
||||||
|
#ifndef USE_FAR_KEYWORD
|
||||||
|
void
|
||||||
|
png_read_data(png_struct *png_ptr, png_bytef *data, png_uint_32 length)
|
||||||
|
{
|
||||||
|
png_uint_32 check;
|
||||||
|
|
||||||
|
check = fread(data, 1, (size_t)length, png_ptr->fp);
|
||||||
|
if (check != length)
|
||||||
|
{
|
||||||
|
png_error(png_ptr, "Read Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void
|
||||||
|
png_read_data(png_struct *png_ptr, png_bytef *data, png_uint_32 length)
|
||||||
|
{
|
||||||
|
png_uint_32 check;
|
||||||
|
png_byte *n_data;
|
||||||
|
|
||||||
|
/* Check if data really is near. If so, use usual code. */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/* do it this way just to quiet warning */
|
||||||
|
FP_OFF(n_data) = FP_OFF(data);
|
||||||
|
if(FP_SEG(n_data) == FP_SEG(data))
|
||||||
|
#else
|
||||||
|
/* this works in MSC also but with lost segment warning */
|
||||||
|
n_data = (png_byte *)data;
|
||||||
|
if((png_bytef *)n_data == data)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
check = fread(n_data, 1, (size_t)length, png_ptr->fp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
png_byte buf[NEAR_BUF_SIZE];
|
||||||
|
png_size_t read, remaining, err;
|
||||||
|
check = 0;
|
||||||
|
remaining = (png_size_t)length;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
read = MIN(NEAR_BUF_SIZE,remaining);
|
||||||
|
err = fread(buf, 1, read, png_ptr->fp);
|
||||||
|
png_memcpy(data,buf,read); /* copy far buffer to near buffer */
|
||||||
|
if(err != read)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
check += err;
|
||||||
|
data += read;
|
||||||
|
remaining -= read;
|
||||||
|
}
|
||||||
|
while(remaining != 0);
|
||||||
|
}
|
||||||
|
if (check != length)
|
||||||
|
{
|
||||||
|
png_error(png_ptr, "read Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Initialize the input/output for the png file. If you change
|
||||||
|
the read and write routines, you will probably need to change
|
||||||
|
this routine (or write your own). If you change the parameters
|
||||||
|
of this routine, remember to change png.h also. */
|
||||||
|
void
|
||||||
|
png_init_io(png_struct *png_ptr, FILE *fp)
|
||||||
|
{
|
||||||
|
png_ptr->fp = fp;
|
||||||
|
}
|
||||||
|
|
@ -1,75 +1,18 @@
|
|||||||
|
|
||||||
/* pngstub.c - stub functions for i/o and memory allocation
|
/* pngstub.c - stub functions for i/o and memory allocation
|
||||||
|
|
||||||
libpng 1.0 beta 1 - version 0.71
|
libpng 1.0 beta 2 - version 0.81
|
||||||
For conditions of distribution and use, see copyright notice in png.h
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
June 26, 1995
|
August 24, 1995
|
||||||
|
|
||||||
This file provides a location for all input/output, memory location,
|
This file provides a location for all memory allocation. Users which
|
||||||
and error handling. Users which need special handling in these areas
|
need special memory handling are expected to modify the code in this file
|
||||||
are expected to modify the code in this file to meet their needs. See
|
to meet their needs. See the instructions at each function. */
|
||||||
the instructions at each function. */
|
|
||||||
|
|
||||||
#define PNG_INTERNAL
|
#define PNG_INTERNAL
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
|
|
||||||
/* Write the data to whatever output you are using. The default
|
|
||||||
routine writes to a file pointer. If you need to write to something
|
|
||||||
else, this is the place to do it. We suggest saving the old code
|
|
||||||
for future use, possibly in a #define. Note that this routine sometimes
|
|
||||||
gets called with very small lengths, so you should implement some kind
|
|
||||||
of simple buffering if you are using unbuffered writes. This should
|
|
||||||
never be asked to write more then 64K on a 16 bit machine. The cast
|
|
||||||
to png_size_t is there for insurance, but if you are having problems
|
|
||||||
with it, you can take it out. Just be sure to cast length to whatever
|
|
||||||
fwrite needs in that spot if you don't have a function prototype for
|
|
||||||
it. */
|
|
||||||
void
|
|
||||||
png_write_data(png_struct *png_ptr, png_byte *data, png_uint_32 length)
|
|
||||||
{
|
|
||||||
png_uint_32 check;
|
|
||||||
|
|
||||||
check = fwrite(data, 1, (png_size_t)length, png_ptr->fp);
|
|
||||||
if (check != length)
|
|
||||||
{
|
|
||||||
png_error(png_ptr, "Write Error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read the data from whatever input you are using. The default
|
|
||||||
routine reads from a file pointer. If you need to read from something
|
|
||||||
else, this is the place to do it. We suggest saving the old code
|
|
||||||
for future use. Note that this routine sometimes gets called with
|
|
||||||
very small lengths, so you should implement some kind of simple
|
|
||||||
buffering if you are using unbuffered reads. This should
|
|
||||||
never be asked to read more then 64K on a 16 bit machine. The cast
|
|
||||||
to png_size_t is there for insurance, but if you are having problems
|
|
||||||
with it, you can take it out. Just be sure to cast length to whatever
|
|
||||||
fread needs in that spot if you don't have a function prototype for
|
|
||||||
it. */
|
|
||||||
void
|
|
||||||
png_read_data(png_struct *png_ptr, png_byte *data, png_uint_32 length)
|
|
||||||
{
|
|
||||||
png_uint_32 check;
|
|
||||||
|
|
||||||
check = fread(data, 1, (size_t)length, png_ptr->fp);
|
|
||||||
if (check != length)
|
|
||||||
{
|
|
||||||
png_error(png_ptr, "Read Error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize the input/output for the png file. If you change
|
|
||||||
the read and write routines, you will probably need to change
|
|
||||||
this routine (or write your own). If you change the parameters
|
|
||||||
of this routine, remember to change png.h also. */
|
|
||||||
void
|
|
||||||
png_init_io(png_struct *png_ptr, FILE *fp)
|
|
||||||
{
|
|
||||||
png_ptr->fp = fp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate memory. For reasonable files, size should never exceed
|
/* Allocate memory. For reasonable files, size should never exceed
|
||||||
64K. However, zlib may allocate more then 64K if you don't tell
|
64K. However, zlib may allocate more then 64K if you don't tell
|
||||||
it not to. See zconf.h and png.h for more information. zlib does
|
it not to. See zconf.h and png.h for more information. zlib does
|
||||||
@ -89,6 +32,7 @@ png_init_io(png_struct *png_ptr, FILE *fp)
|
|||||||
*/
|
*/
|
||||||
#ifdef __TURBOC__
|
#ifdef __TURBOC__
|
||||||
#ifndef __WIN32__
|
#ifndef __WIN32__
|
||||||
|
#ifndef __FLAT__
|
||||||
|
|
||||||
/* NUM_SEG is the number of segments allocated at once */
|
/* NUM_SEG is the number of segments allocated at once */
|
||||||
#define NUM_SEG 4
|
#define NUM_SEG 4
|
||||||
@ -104,13 +48,16 @@ borland_seg *save_array;
|
|||||||
int num_save_array;
|
int num_save_array;
|
||||||
int max_save_array;
|
int max_save_array;
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *
|
voidpf
|
||||||
png_large_malloc(png_struct *png_ptr, png_uint_32 size)
|
png_large_malloc(png_structf *png_ptr, png_uint_32 size)
|
||||||
{
|
{
|
||||||
void *ret;
|
voidpf ret;
|
||||||
|
if (!png_ptr || !size)
|
||||||
|
return ((void *)0);
|
||||||
|
|
||||||
#ifdef PNG_MAX_MALLOC_64K
|
#ifdef PNG_MAX_MALLOC_64K
|
||||||
if (size > (png_uint_32)65536L)
|
if (size > (png_uint_32)65536L)
|
||||||
@ -118,8 +65,8 @@ png_large_malloc(png_struct *png_ptr, png_uint_32 size)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __TURBOC__
|
#ifdef __TURBOC__
|
||||||
# ifdef __WIN32__
|
# if defined(__WIN32__) || defined(__FLAT__)
|
||||||
ret = farmalloc(size);
|
ret = malloc(size);
|
||||||
# else
|
# else
|
||||||
|
|
||||||
if (size == 65536L)
|
if (size == 65536L)
|
||||||
@ -152,11 +99,11 @@ png_large_malloc(png_struct *png_ptr, png_uint_32 size)
|
|||||||
num_save_array = 1;
|
num_save_array = 1;
|
||||||
save_array = malloc(num_save_array * sizeof (borland_seg));
|
save_array = malloc(num_save_array * sizeof (borland_seg));
|
||||||
if (!save_array)
|
if (!save_array)
|
||||||
png_error(png_ptr, "Out of Memory");
|
png_error(png_ptr, "Out of Memory 1");
|
||||||
save_array->mem_ptr = farmalloc(
|
save_array->mem_ptr = farmalloc(
|
||||||
(unsigned long)(NUM_SEG) * 65536L + 65528L);
|
(unsigned long)(NUM_SEG) * 65536L + 65532L);
|
||||||
if (!save_array->mem_ptr)
|
if (!save_array->mem_ptr)
|
||||||
png_error(png_ptr, "Out of Memory");
|
png_error(png_ptr, "Out of Memory 2");
|
||||||
offset = (unsigned long)(ret);
|
offset = (unsigned long)(ret);
|
||||||
offset &= 0xffffL;
|
offset &= 0xffffL;
|
||||||
ptr = save_array->mem_ptr;
|
ptr = save_array->mem_ptr;
|
||||||
@ -194,11 +141,11 @@ png_large_malloc(png_struct *png_ptr, png_uint_32 size)
|
|||||||
save_array = realloc(save_array,
|
save_array = realloc(save_array,
|
||||||
(num_save_array + 1) * sizeof (borland_seg));
|
(num_save_array + 1) * sizeof (borland_seg));
|
||||||
if (!save_array)
|
if (!save_array)
|
||||||
png_error(png_ptr, "Out of Memory");
|
png_error(png_ptr, "Out of Memory 3");
|
||||||
save_array[num_save_array].mem_ptr = farmalloc(
|
save_array[num_save_array].mem_ptr = farmalloc(
|
||||||
(unsigned long)(NUM_SEG) * 65536L + 65528L);
|
(unsigned long)(NUM_SEG) * 65536L + 65532L);
|
||||||
if (!save_array[num_save_array].mem_ptr)
|
if (!save_array[num_save_array].mem_ptr)
|
||||||
png_error(png_ptr, "Out of Memory");
|
png_error(png_ptr, "Out of Memory 4");
|
||||||
offset = (unsigned long)(ret);
|
offset = (unsigned long)(ret);
|
||||||
offset &= 0xffffL;
|
offset &= 0xffffL;
|
||||||
ptr = save_array[num_save_array].mem_ptr;
|
ptr = save_array[num_save_array].mem_ptr;
|
||||||
@ -231,7 +178,7 @@ png_large_malloc(png_struct *png_ptr, png_uint_32 size)
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!ret)
|
if (ret == NULL)
|
||||||
{
|
{
|
||||||
png_error(png_ptr, "Out of Memory");
|
png_error(png_ptr, "Out of Memory");
|
||||||
}
|
}
|
||||||
@ -243,7 +190,7 @@ png_large_malloc(png_struct *png_ptr, png_uint_32 size)
|
|||||||
configuration, png_ptr is not used, but is passed in case it
|
configuration, png_ptr is not used, but is passed in case it
|
||||||
is needed. If ptr is NULL, return without taking any action. */
|
is needed. If ptr is NULL, return without taking any action. */
|
||||||
void
|
void
|
||||||
png_large_free(png_struct *png_ptr, void *ptr)
|
png_large_free(png_structf *png_ptr, voidpf ptr)
|
||||||
{
|
{
|
||||||
if (!png_ptr)
|
if (!png_ptr)
|
||||||
return;
|
return;
|
||||||
@ -251,7 +198,10 @@ png_large_free(png_struct *png_ptr, void *ptr)
|
|||||||
if (ptr != (void *)0)
|
if (ptr != (void *)0)
|
||||||
{
|
{
|
||||||
#ifdef __TURBOC__
|
#ifdef __TURBOC__
|
||||||
# ifndef __WIN32__
|
# if defined(__WIN32__) || defined(__FLAT__)
|
||||||
|
if (ptr)
|
||||||
|
free(ptr);
|
||||||
|
# else
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
for (i = 0; i < num_save_array; i++)
|
for (i = 0; i < num_save_array; i++)
|
||||||
@ -260,14 +210,13 @@ png_large_free(png_struct *png_ptr, void *ptr)
|
|||||||
{
|
{
|
||||||
if (ptr == save_array[i].seg_ptr[j])
|
if (ptr == save_array[i].seg_ptr[j])
|
||||||
{
|
{
|
||||||
printf("freeing pointer: i, j: %d, %d\n", i, j);
|
|
||||||
save_array[i].seg_used[j] = 0;
|
save_array[i].seg_used[j] = 0;
|
||||||
ptr = 0;
|
ptr = 0;
|
||||||
save_array[i].num_used--;
|
save_array[i].num_used--;
|
||||||
if (!save_array[i].num_used)
|
if (!save_array[i].num_used)
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
printf("freeing array: %d\n", i);
|
|
||||||
num_save_array--;
|
num_save_array--;
|
||||||
farfree(save_array[i].mem_ptr);
|
farfree(save_array[i].mem_ptr);
|
||||||
for (k = i; k < num_save_array; k++)
|
for (k = i; k < num_save_array; k++)
|
||||||
@ -285,9 +234,9 @@ printf("freeing array: %d\n", i);
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
# endif
|
|
||||||
if (ptr)
|
if (ptr)
|
||||||
farfree(ptr);
|
farfree(ptr);
|
||||||
|
# endif
|
||||||
#else
|
#else
|
||||||
# ifdef _MSC_VER
|
# ifdef _MSC_VER
|
||||||
hfree(ptr);
|
hfree(ptr);
|
||||||
@ -305,7 +254,7 @@ png_malloc(png_struct *png_ptr, png_uint_32 size)
|
|||||||
{
|
{
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
if (!png_ptr)
|
if (!png_ptr || !size)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
|
|
||||||
#ifdef PNG_MAX_MALLOC_64K
|
#ifdef PNG_MAX_MALLOC_64K
|
||||||
@ -317,7 +266,7 @@ png_malloc(png_struct *png_ptr, png_uint_32 size)
|
|||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
png_error(png_ptr, "Out of Memory");
|
png_error(png_ptr, "Out of Memory 6");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -326,11 +275,12 @@ png_malloc(png_struct *png_ptr, png_uint_32 size)
|
|||||||
/* Reallocate memory. This will not get near 64K on a
|
/* Reallocate memory. This will not get near 64K on a
|
||||||
even marginally reasonable file. */
|
even marginally reasonable file. */
|
||||||
void *
|
void *
|
||||||
png_realloc(png_struct *png_ptr, void *ptr, png_uint_32 size)
|
png_realloc(png_struct *png_ptr, void *ptr, png_uint_32 size,
|
||||||
|
png_uint_32 old_size)
|
||||||
{
|
{
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
if (!png_ptr)
|
if (!png_ptr || !old_size || !ptr || !size)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
|
|
||||||
#ifdef PNG_MAX_MALLOC_64K
|
#ifdef PNG_MAX_MALLOC_64K
|
||||||
@ -342,7 +292,7 @@ png_realloc(png_struct *png_ptr, void *ptr, png_uint_32 size)
|
|||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
png_error(png_ptr, "Out of Memory");
|
png_error(png_ptr, "Out of Memory 7");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -361,27 +311,3 @@ png_free(png_struct *png_ptr, void *ptr)
|
|||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is called whenever there is an error. Replace with
|
|
||||||
however you wish to handle the error. Note that this function
|
|
||||||
MUST NOT return, or the program will crash */
|
|
||||||
void
|
|
||||||
png_error(png_struct *png_ptr, char *message)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "libpng error: %s\n", message);
|
|
||||||
|
|
||||||
longjmp(png_ptr->jmpbuf, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This function is called when there is a warning, but the library
|
|
||||||
thinks it can continue anyway. You don't have to do anything here
|
|
||||||
if you don't want to. In the default configuration, png_ptr is
|
|
||||||
not used, but it is passed in case it may be useful. */
|
|
||||||
void
|
|
||||||
png_warning(png_struct *png_ptr, char *message)
|
|
||||||
{
|
|
||||||
if (!png_ptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fprintf(stderr, "libpng warning: %s\n", message);
|
|
||||||
}
|
|
||||||
|
|
37
pngrcb.c
37
pngrcb.c
@ -1,9 +1,9 @@
|
|||||||
/* pngrcb.c - callbacks while reading a png file
|
/* pngrcb.c - callbacks while reading a png file
|
||||||
|
|
||||||
libpng 1.0 beta 1 - version 0.71
|
libpng 1.0 beta 2 - version 0.81
|
||||||
For conditions of distribution and use, see copyright notice in png.h
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
June 26, 1995
|
August 24, 1995
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PNG_INTERNAL
|
#define PNG_INTERNAL
|
||||||
@ -49,6 +49,7 @@ png_read_PLTE(png_struct *png_ptr, png_info *info,
|
|||||||
info->valid |= PNG_INFO_PLTE;
|
info->valid |= PNG_INFO_PLTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_read_gAMA(png_struct *png_ptr, png_info *info, float gamma)
|
png_read_gAMA(png_struct *png_ptr, png_info *info, float gamma)
|
||||||
{
|
{
|
||||||
@ -58,7 +59,9 @@ png_read_gAMA(png_struct *png_ptr, png_info *info, float gamma)
|
|||||||
info->gamma = gamma;
|
info->gamma = gamma;
|
||||||
info->valid |= PNG_INFO_gAMA;
|
info->valid |= PNG_INFO_gAMA;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_read_sBIT(png_struct *png_ptr, png_info *info,
|
png_read_sBIT(png_struct *png_ptr, png_info *info,
|
||||||
png_color_8 *sig_bit)
|
png_color_8 *sig_bit)
|
||||||
@ -69,7 +72,9 @@ png_read_sBIT(png_struct *png_ptr, png_info *info,
|
|||||||
memcpy(&(info->sig_bit), sig_bit, sizeof (png_color_8));
|
memcpy(&(info->sig_bit), sig_bit, sizeof (png_color_8));
|
||||||
info->valid |= PNG_INFO_sBIT;
|
info->valid |= PNG_INFO_sBIT;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_read_cHRM(png_struct *png_ptr, png_info *info,
|
png_read_cHRM(png_struct *png_ptr, png_info *info,
|
||||||
float white_x, float white_y, float red_x, float red_y,
|
float white_x, float white_y, float red_x, float red_y,
|
||||||
@ -88,7 +93,9 @@ png_read_cHRM(png_struct *png_ptr, png_info *info,
|
|||||||
info->y_blue = blue_y;
|
info->y_blue = blue_y;
|
||||||
info->valid |= PNG_INFO_cHRM;
|
info->valid |= PNG_INFO_cHRM;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_read_tRNS(png_struct *png_ptr, png_info *info,
|
png_read_tRNS(png_struct *png_ptr, png_info *info,
|
||||||
png_byte *trans, int num_trans, png_color_16 *trans_values)
|
png_byte *trans, int num_trans, png_color_16 *trans_values)
|
||||||
@ -108,7 +115,9 @@ png_read_tRNS(png_struct *png_ptr, png_info *info,
|
|||||||
info->num_trans = num_trans;
|
info->num_trans = num_trans;
|
||||||
info->valid |= PNG_INFO_tRNS;
|
info->valid |= PNG_INFO_tRNS;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_read_bKGD(png_struct *png_ptr, png_info *info,
|
png_read_bKGD(png_struct *png_ptr, png_info *info,
|
||||||
png_color_16 *background)
|
png_color_16 *background)
|
||||||
@ -119,7 +128,9 @@ png_read_bKGD(png_struct *png_ptr, png_info *info,
|
|||||||
memcpy(&(info->background), background, sizeof(png_color_16));
|
memcpy(&(info->background), background, sizeof(png_color_16));
|
||||||
info->valid |= PNG_INFO_bKGD;
|
info->valid |= PNG_INFO_bKGD;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_read_hIST(png_struct *png_ptr, png_info *info, png_uint_16 *hist)
|
png_read_hIST(png_struct *png_ptr, png_info *info, png_uint_16 *hist)
|
||||||
{
|
{
|
||||||
@ -129,7 +140,9 @@ png_read_hIST(png_struct *png_ptr, png_info *info, png_uint_16 *hist)
|
|||||||
info->hist = hist;
|
info->hist = hist;
|
||||||
info->valid |= PNG_INFO_hIST;
|
info->valid |= PNG_INFO_hIST;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_read_pHYs(png_struct *png_ptr, png_info *info,
|
png_read_pHYs(png_struct *png_ptr, png_info *info,
|
||||||
png_uint_32 res_x, png_uint_32 res_y, int unit_type)
|
png_uint_32 res_x, png_uint_32 res_y, int unit_type)
|
||||||
@ -142,7 +155,9 @@ png_read_pHYs(png_struct *png_ptr, png_info *info,
|
|||||||
info->phys_unit_type = unit_type;
|
info->phys_unit_type = unit_type;
|
||||||
info->valid |= PNG_INFO_pHYs;
|
info->valid |= PNG_INFO_pHYs;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_read_oFFs(png_struct *png_ptr, png_info *info,
|
png_read_oFFs(png_struct *png_ptr, png_info *info,
|
||||||
png_uint_32 offset_x, png_uint_32 offset_y, int unit_type)
|
png_uint_32 offset_x, png_uint_32 offset_y, int unit_type)
|
||||||
@ -155,7 +170,9 @@ png_read_oFFs(png_struct *png_ptr, png_info *info,
|
|||||||
info->offset_unit_type = unit_type;
|
info->offset_unit_type = unit_type;
|
||||||
info->valid |= PNG_INFO_oFFs;
|
info->valid |= PNG_INFO_oFFs;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_read_tIME(png_struct *png_ptr, png_info *info,
|
png_read_tIME(png_struct *png_ptr, png_info *info,
|
||||||
png_time *mod_time)
|
png_time *mod_time)
|
||||||
@ -166,10 +183,12 @@ png_read_tIME(png_struct *png_ptr, png_info *info,
|
|||||||
memcpy(&(info->mod_time), mod_time, sizeof (png_time));
|
memcpy(&(info->mod_time), mod_time, sizeof (png_time));
|
||||||
info->valid |= PNG_INFO_tIME;
|
info->valid |= PNG_INFO_tIME;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_read_zTXt(png_struct *png_ptr, png_info *info,
|
png_read_zTXt(png_struct *png_ptr, png_info *info,
|
||||||
char *key, char *text, png_uint_32 text_len, int compression)
|
charf *key, charf *text, png_uint_32 text_len, int compression)
|
||||||
{
|
{
|
||||||
if (!png_ptr || !info)
|
if (!png_ptr || !info)
|
||||||
return;
|
return;
|
||||||
@ -178,10 +197,14 @@ png_read_zTXt(png_struct *png_ptr, png_info *info,
|
|||||||
{
|
{
|
||||||
if (info->text)
|
if (info->text)
|
||||||
{
|
{
|
||||||
|
png_uint_32 old_max;
|
||||||
|
|
||||||
|
old_max = info->max_text;
|
||||||
info->max_text = info->num_text + 16;
|
info->max_text = info->num_text + 16;
|
||||||
info->text = (png_text *)png_realloc(png_ptr,
|
info->text = (png_text *)png_realloc(png_ptr,
|
||||||
info->text,
|
info->text,
|
||||||
info->max_text * sizeof (png_text));
|
info->max_text * sizeof (png_text),
|
||||||
|
old_max * sizeof (png_text));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -198,15 +221,17 @@ png_read_zTXt(png_struct *png_ptr, png_info *info,
|
|||||||
info->text[info->num_text].compression = compression;
|
info->text[info->num_text].compression = compression;
|
||||||
info->num_text++;
|
info->num_text++;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_read_tEXt(png_struct *png_ptr, png_info *info,
|
png_read_tEXt(png_struct *png_ptr, png_info *info,
|
||||||
char *key, char *text, png_uint_32 text_len)
|
charf *key, charf *text, png_uint_32 text_len)
|
||||||
{
|
{
|
||||||
if (!png_ptr || !info)
|
if (!png_ptr || !info)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
png_read_zTXt(png_ptr, info, key, text, text_len, -1);
|
png_read_zTXt(png_ptr, info, key, text, text_len, -1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
135
pngread.c
135
pngread.c
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
/* pngread.c - read a png file
|
/* pngread.c - read a png file
|
||||||
|
|
||||||
libpng 1.0 beta 1 - version 0.71
|
libpng 1.0 beta 2 - version 0.81
|
||||||
For conditions of distribution and use, see copyright notice in png.h
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
June 26, 1995
|
August 24, 1995
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PNG_INTERNAL
|
#define PNG_INTERNAL
|
||||||
@ -16,9 +16,9 @@ png_read_init(png_struct *png_ptr)
|
|||||||
{
|
{
|
||||||
jmp_buf tmp_jmp;
|
jmp_buf tmp_jmp;
|
||||||
|
|
||||||
memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||||
memset(png_ptr, 0, sizeof (png_struct));
|
png_memset(png_ptr, 0, sizeof (png_struct));
|
||||||
memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||||
|
|
||||||
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
||||||
png_ptr->zbuf = png_large_malloc(png_ptr, png_ptr->zbuf_size);
|
png_ptr->zbuf = png_large_malloc(png_ptr, png_ptr->zbuf_size);
|
||||||
@ -63,9 +63,28 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
if (png_ptr->mode != PNG_HAVE_IHDR)
|
if (png_ptr->mode != PNG_HAVE_IHDR)
|
||||||
png_error(png_ptr, "Missing IHDR");
|
png_error(png_ptr, "Missing IHDR");
|
||||||
|
|
||||||
|
#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
|
||||||
|
if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||||
|
png_crc_skip(png_ptr, length);
|
||||||
|
else
|
||||||
|
#else
|
||||||
|
{
|
||||||
png_handle_PLTE(png_ptr, info, length);
|
png_handle_PLTE(png_ptr, info, length);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
png_ptr->mode = PNG_HAVE_PLTE;
|
png_ptr->mode = PNG_HAVE_PLTE;
|
||||||
}
|
}
|
||||||
|
else if (!memcmp(chunk_start + 4, png_IDAT, 4))
|
||||||
|
{
|
||||||
|
png_ptr->idat_size = length;
|
||||||
|
png_ptr->mode = PNG_HAVE_IDAT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (!memcmp(chunk_start + 4, png_IEND, 4))
|
||||||
|
{
|
||||||
|
png_error(png_ptr, "No Image in File");
|
||||||
|
}
|
||||||
|
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_gAMA, 4))
|
else if (!memcmp(chunk_start + 4, png_gAMA, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode != PNG_HAVE_IHDR)
|
if (png_ptr->mode != PNG_HAVE_IHDR)
|
||||||
@ -73,6 +92,8 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
|
|
||||||
png_handle_gAMA(png_ptr, info, length);
|
png_handle_gAMA(png_ptr, info, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_sBIT, 4))
|
else if (!memcmp(chunk_start + 4, png_sBIT, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode != PNG_HAVE_IHDR)
|
if (png_ptr->mode != PNG_HAVE_IHDR)
|
||||||
@ -80,6 +101,8 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
|
|
||||||
png_handle_sBIT(png_ptr, info, length);
|
png_handle_sBIT(png_ptr, info, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_cHRM, 4))
|
else if (!memcmp(chunk_start + 4, png_cHRM, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode != PNG_HAVE_IHDR)
|
if (png_ptr->mode != PNG_HAVE_IHDR)
|
||||||
@ -87,6 +110,8 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
|
|
||||||
png_handle_cHRM(png_ptr, info, length);
|
png_handle_cHRM(png_ptr, info, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_tRNS, 4))
|
else if (!memcmp(chunk_start + 4, png_tRNS, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode != PNG_HAVE_IHDR &&
|
if (png_ptr->mode != PNG_HAVE_IHDR &&
|
||||||
@ -95,6 +120,8 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
|
|
||||||
png_handle_tRNS(png_ptr, info, length);
|
png_handle_tRNS(png_ptr, info, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_bKGD, 4))
|
else if (!memcmp(chunk_start + 4, png_bKGD, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode != PNG_HAVE_IHDR &&
|
if (png_ptr->mode != PNG_HAVE_IHDR &&
|
||||||
@ -103,6 +130,8 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
|
|
||||||
png_handle_bKGD(png_ptr, info, length);
|
png_handle_bKGD(png_ptr, info, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_hIST, 4))
|
else if (!memcmp(chunk_start + 4, png_hIST, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode != PNG_HAVE_PLTE)
|
if (png_ptr->mode != PNG_HAVE_PLTE)
|
||||||
@ -110,12 +139,8 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
|
|
||||||
png_handle_hIST(png_ptr, info, length);
|
png_handle_hIST(png_ptr, info, length);
|
||||||
}
|
}
|
||||||
else if (!memcmp(chunk_start + 4, png_IDAT, 4))
|
#endif
|
||||||
{
|
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||||
png_ptr->idat_size = length;
|
|
||||||
png_ptr->mode = PNG_HAVE_IDAT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (!memcmp(chunk_start + 4, png_pHYs, 4))
|
else if (!memcmp(chunk_start + 4, png_pHYs, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode != PNG_HAVE_IHDR &&
|
if (png_ptr->mode != PNG_HAVE_IHDR &&
|
||||||
@ -124,6 +149,8 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
|
|
||||||
png_handle_pHYs(png_ptr, info, length);
|
png_handle_pHYs(png_ptr, info, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_oFFs, 4))
|
else if (!memcmp(chunk_start + 4, png_oFFs, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode != PNG_HAVE_IHDR &&
|
if (png_ptr->mode != PNG_HAVE_IHDR &&
|
||||||
@ -132,6 +159,8 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
|
|
||||||
png_handle_oFFs(png_ptr, info, length);
|
png_handle_oFFs(png_ptr, info, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_tIME, 4))
|
else if (!memcmp(chunk_start + 4, png_tIME, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
||||||
@ -140,6 +169,8 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
|
|
||||||
png_handle_tIME(png_ptr, info, length);
|
png_handle_tIME(png_ptr, info, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_tEXt, 4))
|
else if (!memcmp(chunk_start + 4, png_tEXt, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
||||||
@ -148,6 +179,8 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
|
|
||||||
png_handle_tEXt(png_ptr, info, length);
|
png_handle_tEXt(png_ptr, info, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_zTXt, 4))
|
else if (!memcmp(chunk_start + 4, png_zTXt, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
||||||
@ -156,13 +189,10 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
|
|
||||||
png_handle_zTXt(png_ptr, info, length);
|
png_handle_zTXt(png_ptr, info, length);
|
||||||
}
|
}
|
||||||
else if (!memcmp(chunk_start + 4, png_IEND, 4))
|
#endif
|
||||||
{
|
|
||||||
png_error(png_ptr, "No Image in File");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (isupper(chunk_start[4]))
|
if ((chunk_start[4] & 0x20) == 0)
|
||||||
png_error(png_ptr, "Unknown Critical Chunk");
|
png_error(png_ptr, "Unknown Critical Chunk");
|
||||||
|
|
||||||
png_crc_skip(png_ptr, length);
|
png_crc_skip(png_ptr, length);
|
||||||
@ -175,6 +205,15 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* optional call to update the users info structure */
|
||||||
|
void
|
||||||
|
png_read_update_info(png_struct *png_ptr, png_info *info_ptr)
|
||||||
|
{
|
||||||
|
if (!(png_ptr->row_init))
|
||||||
|
png_read_start_row(png_ptr);
|
||||||
|
png_read_transform_info(png_ptr, info_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
/* initialize palette, background, etc, after transformations
|
/* initialize palette, background, etc, after transformations
|
||||||
are set, but before any reading takes place. This allows
|
are set, but before any reading takes place. This allows
|
||||||
the user to obtail a gamma corrected palette, for example.
|
the user to obtail a gamma corrected palette, for example.
|
||||||
@ -182,17 +221,18 @@ png_read_info(png_struct *png_ptr, png_info *info)
|
|||||||
void
|
void
|
||||||
png_start_read_image(png_struct *png_ptr)
|
png_start_read_image(png_struct *png_ptr)
|
||||||
{
|
{
|
||||||
|
if (!(png_ptr->row_init))
|
||||||
png_read_start_row(png_ptr);
|
png_read_start_row(png_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
png_read_row(png_struct *png_ptr, png_byte *row, png_byte *dsp_row)
|
png_read_row(png_struct *png_ptr, png_bytef *row, png_byte *dsp_row)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!(png_ptr->row_init))
|
if (!(png_ptr->row_init))
|
||||||
png_read_start_row(png_ptr);
|
png_read_start_row(png_ptr);
|
||||||
|
|
||||||
|
#if defined(PNG_READ_INTERLACING_SUPPORTED)
|
||||||
/* if interlaced and we do not need a new row, combine row and return */
|
/* if interlaced and we do not need a new row, combine row and return */
|
||||||
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
||||||
{
|
{
|
||||||
@ -267,6 +307,7 @@ png_read_row(png_struct *png_ptr, png_byte *row, png_byte *dsp_row)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (png_ptr->mode != PNG_HAVE_IDAT)
|
if (png_ptr->mode != PNG_HAVE_IDAT)
|
||||||
png_error(png_ptr, "invalid attempt to read row data");
|
png_error(png_ptr, "invalid attempt to read row data");
|
||||||
@ -334,11 +375,12 @@ png_read_row(png_struct *png_ptr, png_byte *row, png_byte *dsp_row)
|
|||||||
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
|
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
|
||||||
(int)(png_ptr->row_buf[0]));
|
(int)(png_ptr->row_buf[0]));
|
||||||
|
|
||||||
memcpy(png_ptr->prev_row, png_ptr->row_buf, (png_size_t)png_ptr->rowbytes + 1);
|
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, (png_size_t)png_ptr->rowbytes + 1);
|
||||||
|
|
||||||
if (png_ptr->transformations)
|
if (png_ptr->transformations)
|
||||||
png_do_read_transformations(png_ptr);
|
png_do_read_transformations(png_ptr);
|
||||||
|
|
||||||
|
#if defined(PNG_READ_INTERLACING_SUPPORTED)
|
||||||
/* blow up interlaced rows to full size */
|
/* blow up interlaced rows to full size */
|
||||||
if (png_ptr->interlaced &&
|
if (png_ptr->interlaced &&
|
||||||
(png_ptr->transformations & PNG_INTERLACE))
|
(png_ptr->transformations & PNG_INTERLACE))
|
||||||
@ -355,6 +397,7 @@ png_read_row(png_struct *png_ptr, png_byte *row, png_byte *dsp_row)
|
|||||||
png_pass_mask[png_ptr->pass]);
|
png_pass_mask[png_ptr->pass]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
if (row)
|
if (row)
|
||||||
png_combine_row(png_ptr, row, 0xff);
|
png_combine_row(png_ptr, row, 0xff);
|
||||||
@ -383,18 +426,18 @@ png_read_row(png_struct *png_ptr, png_byte *row, png_byte *dsp_row)
|
|||||||
not called png_set_interlace_handling(), the display_row buffer will
|
not called png_set_interlace_handling(), the display_row buffer will
|
||||||
be ignored, so pass NULL to it. */
|
be ignored, so pass NULL to it. */
|
||||||
void
|
void
|
||||||
png_read_rows(png_struct *png_ptr, png_byte **row,
|
png_read_rows(png_struct *png_ptr, png_bytef **row,
|
||||||
png_byte **display_row, png_uint_32 num_rows)
|
png_byte **display_row, png_uint_32 num_rows)
|
||||||
{
|
{
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
png_byte **rp;
|
png_bytef **rp;
|
||||||
png_byte **dp;
|
png_byte **dp;
|
||||||
|
|
||||||
rp = row;
|
rp = row;
|
||||||
dp = display_row;
|
dp = display_row;
|
||||||
for (i = 0; i < num_rows; i++)
|
for (i = 0; i < num_rows; i++)
|
||||||
{
|
{
|
||||||
png_byte *rptr;
|
png_bytef *rptr;
|
||||||
png_byte *dptr;
|
png_byte *dptr;
|
||||||
|
|
||||||
if (rp)
|
if (rp)
|
||||||
@ -420,11 +463,11 @@ png_read_rows(png_struct *png_ptr, png_byte **row,
|
|||||||
You only need to call this function once. If you desire to have
|
You only need to call this function once. If you desire to have
|
||||||
an image for each pass of a interlaced image, use png_read_rows() */
|
an image for each pass of a interlaced image, use png_read_rows() */
|
||||||
void
|
void
|
||||||
png_read_image(png_struct *png_ptr, png_byte **image)
|
png_read_image(png_struct *png_ptr, png_bytef **image)
|
||||||
{
|
{
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
int pass, j;
|
int pass, j;
|
||||||
png_byte **rp;
|
png_bytef **rp;
|
||||||
|
|
||||||
pass = png_set_interlace_handling(png_ptr);
|
pass = png_set_interlace_handling(png_ptr);
|
||||||
for (j = 0; j < pass; j++)
|
for (j = 0; j < pass; j++)
|
||||||
@ -506,6 +549,7 @@ png_read_end(png_struct *png_ptr, png_info *info)
|
|||||||
{
|
{
|
||||||
png_error(png_ptr, "invalid chunk after IDAT");
|
png_error(png_ptr, "invalid chunk after IDAT");
|
||||||
}
|
}
|
||||||
|
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_tIME, 4))
|
else if (!memcmp(chunk_start + 4, png_tIME, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
||||||
@ -517,6 +561,8 @@ png_read_end(png_struct *png_ptr, png_info *info)
|
|||||||
else
|
else
|
||||||
png_crc_skip(png_ptr, length);
|
png_crc_skip(png_ptr, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_tEXt, 4))
|
else if (!memcmp(chunk_start + 4, png_tEXt, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
||||||
@ -528,6 +574,8 @@ png_read_end(png_struct *png_ptr, png_info *info)
|
|||||||
else
|
else
|
||||||
png_crc_skip(png_ptr, length);
|
png_crc_skip(png_ptr, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||||
else if (!memcmp(chunk_start + 4, png_zTXt, 4))
|
else if (!memcmp(chunk_start + 4, png_zTXt, 4))
|
||||||
{
|
{
|
||||||
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
if (png_ptr->mode == PNG_BEFORE_IHDR ||
|
||||||
@ -539,13 +587,14 @@ png_read_end(png_struct *png_ptr, png_info *info)
|
|||||||
else
|
else
|
||||||
png_crc_skip(png_ptr, length);
|
png_crc_skip(png_ptr, length);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
else if (!memcmp(chunk_start + 4, png_IEND, 4))
|
else if (!memcmp(chunk_start + 4, png_IEND, 4))
|
||||||
{
|
{
|
||||||
png_ptr->mode = PNG_AFTER_IEND;
|
png_ptr->mode = PNG_AFTER_IEND;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (isupper(chunk_start[4]))
|
if ((chunk_start[4] & 0x20) == 0)
|
||||||
png_error(png_ptr, "Unknown Critical Chunk");
|
png_error(png_ptr, "Unknown Critical Chunk");
|
||||||
|
|
||||||
png_crc_skip(png_ptr, length);
|
png_crc_skip(png_ptr, length);
|
||||||
@ -569,40 +618,58 @@ png_read_destroy(png_struct *png_ptr, png_info *info, png_info *end_info)
|
|||||||
|
|
||||||
if (info)
|
if (info)
|
||||||
{
|
{
|
||||||
|
/* I'm not sure I should be freeing this */
|
||||||
if (info->palette != png_ptr->palette)
|
if (info->palette != png_ptr->palette)
|
||||||
png_free(png_ptr, info->palette);
|
png_free(png_ptr, info->palette);
|
||||||
|
/* I'm not sure I should be freeing this */
|
||||||
|
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_bKGD_SUPPORTED)
|
||||||
if (info->trans != png_ptr->trans)
|
if (info->trans != png_ptr->trans)
|
||||||
png_free(png_ptr, info->trans);
|
png_free(png_ptr, info->trans);
|
||||||
|
#endif
|
||||||
|
/* I'm not sure I should be freeing this */
|
||||||
|
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||||
if (info->hist != png_ptr->hist)
|
if (info->hist != png_ptr->hist)
|
||||||
png_free(png_ptr, info->hist);
|
png_free(png_ptr, info->hist);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||||
for (i = 0; i < info->num_text; i++)
|
for (i = 0; i < info->num_text; i++)
|
||||||
{
|
{
|
||||||
png_large_free(png_ptr, info->text[i].key);
|
png_large_free(png_ptr, info->text[i].key);
|
||||||
}
|
}
|
||||||
|
|
||||||
png_free(png_ptr, info->text);
|
png_free(png_ptr, info->text);
|
||||||
memset(info, 0, sizeof(png_info));
|
#endif
|
||||||
|
png_memset(info, 0, sizeof(png_info));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end_info)
|
if (end_info)
|
||||||
{
|
{
|
||||||
|
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||||
for (i = 0; i < end_info->num_text; i++)
|
for (i = 0; i < end_info->num_text; i++)
|
||||||
{
|
{
|
||||||
png_large_free(png_ptr, end_info->text[i].key);
|
png_large_free(png_ptr, end_info->text[i].key);
|
||||||
}
|
}
|
||||||
|
|
||||||
png_free(png_ptr, end_info->text);
|
png_free(png_ptr, end_info->text);
|
||||||
memset(end_info, 0, sizeof(png_info));
|
#endif
|
||||||
|
png_memset(end_info, 0, sizeof(png_info));
|
||||||
}
|
}
|
||||||
|
|
||||||
png_large_free(png_ptr, png_ptr->zbuf);
|
png_large_free(png_ptr, png_ptr->zbuf);
|
||||||
png_large_free(png_ptr, png_ptr->row_buf);
|
png_large_free(png_ptr, png_ptr->row_buf);
|
||||||
png_large_free(png_ptr, png_ptr->prev_row);
|
png_large_free(png_ptr, png_ptr->prev_row);
|
||||||
|
#if defined(PNG_READ_DITHER_SUPPORTED)
|
||||||
png_large_free(png_ptr, png_ptr->palette_lookup);
|
png_large_free(png_ptr, png_ptr->palette_lookup);
|
||||||
png_free(png_ptr, png_ptr->dither_index);
|
png_free(png_ptr, png_ptr->dither_index);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||||
png_free(png_ptr, png_ptr->gamma_table);
|
png_free(png_ptr, png_ptr->gamma_table);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||||
png_free(png_ptr, png_ptr->gamma_from_1);
|
png_free(png_ptr, png_ptr->gamma_from_1);
|
||||||
png_free(png_ptr, png_ptr->gamma_to_1);
|
png_free(png_ptr, png_ptr->gamma_to_1);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||||
if (png_ptr->gamma_16_table)
|
if (png_ptr->gamma_16_table)
|
||||||
{
|
{
|
||||||
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
|
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
|
||||||
@ -610,6 +677,8 @@ png_read_destroy(png_struct *png_ptr, png_info *info, png_info *end_info)
|
|||||||
png_free(png_ptr, png_ptr->gamma_16_table[i]);
|
png_free(png_ptr, png_ptr->gamma_16_table[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||||
png_free(png_ptr, png_ptr->gamma_16_table);
|
png_free(png_ptr, png_ptr->gamma_16_table);
|
||||||
if (png_ptr->gamma_16_from_1)
|
if (png_ptr->gamma_16_from_1)
|
||||||
{
|
{
|
||||||
@ -627,16 +696,20 @@ png_read_destroy(png_struct *png_ptr, png_info *info, png_info *end_info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
png_free(png_ptr, png_ptr->gamma_16_to_1);
|
png_free(png_ptr, png_ptr->gamma_16_to_1);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||||
png_free(png_ptr, png_ptr->trans);
|
png_free(png_ptr, png_ptr->trans);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_READ_DITHER_SUPPORTED)
|
||||||
png_free(png_ptr, png_ptr->hist);
|
png_free(png_ptr, png_ptr->hist);
|
||||||
|
#endif
|
||||||
if (!png_ptr->user_palette)
|
if (!png_ptr->user_palette)
|
||||||
png_free(png_ptr, png_ptr->palette);
|
png_free(png_ptr, png_ptr->palette);
|
||||||
|
|
||||||
inflateEnd(png_ptr->zstream);
|
inflateEnd(png_ptr->zstream);
|
||||||
|
|
||||||
memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||||
memset(png_ptr, 0, sizeof (png_struct));
|
png_memset(png_ptr, 0, sizeof (png_struct));
|
||||||
memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
595
pngrtran.c
595
pngrtran.c
File diff suppressed because it is too large
Load Diff
137
pngrutil.c
137
pngrutil.c
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
/* pngrutil.c - utilities to read a png file
|
/* pngrutil.c - utilities to read a png file
|
||||||
|
|
||||||
libpng 1.0 beta 1 - version 0.71
|
libpng 1.0 beta 2 - version 0.81
|
||||||
For conditions of distribution and use, see copyright notice in png.h
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
June 26, 1995
|
August 24, 1995
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PNG_INTERNAL
|
#define PNG_INTERNAL
|
||||||
@ -38,7 +38,7 @@ png_get_uint_16(png_byte *buf)
|
|||||||
|
|
||||||
/* read data, and run it through the crc */
|
/* read data, and run it through the crc */
|
||||||
void
|
void
|
||||||
png_crc_read(png_struct *png_ptr, png_byte *buf, png_uint_32 length)
|
png_crc_read(png_struct *png_ptr, png_bytef *buf, png_uint_32 length)
|
||||||
{
|
{
|
||||||
png_read_data(png_ptr, buf, length);
|
png_read_data(png_ptr, buf, length);
|
||||||
png_calculate_crc(png_ptr, buf, length);
|
png_calculate_crc(png_ptr, buf, length);
|
||||||
@ -179,6 +179,7 @@ png_handle_PLTE(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
png_read_PLTE(png_ptr, info, palette, num);
|
png_read_PLTE(png_ptr, info, palette, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_handle_gAMA(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
png_handle_gAMA(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
||||||
{
|
{
|
||||||
@ -202,7 +203,9 @@ png_handle_gAMA(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
png_read_gAMA(png_ptr, info, gamma);
|
png_read_gAMA(png_ptr, info, gamma);
|
||||||
png_ptr->gamma = gamma;
|
png_ptr->gamma = gamma;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_handle_sBIT(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
png_handle_sBIT(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
||||||
{
|
{
|
||||||
@ -235,7 +238,9 @@ png_handle_sBIT(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
}
|
}
|
||||||
png_read_sBIT(png_ptr, info, &(png_ptr->sig_bit));
|
png_read_sBIT(png_ptr, info, &(png_ptr->sig_bit));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_handle_cHRM(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
png_handle_cHRM(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
||||||
{
|
{
|
||||||
@ -284,7 +289,9 @@ png_handle_cHRM(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
png_read_cHRM(png_ptr, info,
|
png_read_cHRM(png_ptr, info,
|
||||||
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
|
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_handle_tRNS(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
png_handle_tRNS(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
||||||
{
|
{
|
||||||
@ -336,7 +343,9 @@ png_handle_tRNS(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
png_read_tRNS(png_ptr, info, png_ptr->trans, png_ptr->num_trans,
|
png_read_tRNS(png_ptr, info, png_ptr->trans, png_ptr->num_trans,
|
||||||
&(png_ptr->trans_values));
|
&(png_ptr->trans_values));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_handle_bKGD(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
png_handle_bKGD(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
||||||
{
|
{
|
||||||
@ -370,7 +379,9 @@ png_handle_bKGD(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
|
|
||||||
png_read_bKGD(png_ptr, info, &(png_ptr->background));
|
png_read_bKGD(png_ptr, info, &(png_ptr->background));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_handle_hIST(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
png_handle_hIST(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
||||||
{
|
{
|
||||||
@ -393,7 +404,9 @@ png_handle_hIST(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
}
|
}
|
||||||
png_read_hIST(png_ptr, info, png_ptr->hist);
|
png_read_hIST(png_ptr, info, png_ptr->hist);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_handle_pHYs(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
png_handle_pHYs(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
||||||
{
|
{
|
||||||
@ -414,7 +427,9 @@ png_handle_pHYs(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
unit_type = buf[8];
|
unit_type = buf[8];
|
||||||
png_read_pHYs(png_ptr, info, res_x, res_y, unit_type);
|
png_read_pHYs(png_ptr, info, res_x, res_y, unit_type);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_handle_oFFs(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
png_handle_oFFs(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
||||||
{
|
{
|
||||||
@ -435,7 +450,9 @@ png_handle_oFFs(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
unit_type = buf[8];
|
unit_type = buf[8];
|
||||||
png_read_oFFs(png_ptr, info, offset_x, offset_y, unit_type);
|
png_read_oFFs(png_ptr, info, offset_x, offset_y, unit_type);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_handle_tIME(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
png_handle_tIME(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
||||||
{
|
{
|
||||||
@ -459,17 +476,20 @@ png_handle_tIME(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
|
|
||||||
png_read_tIME(png_ptr, info, &mod_time);
|
png_read_tIME(png_ptr, info, &mod_time);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||||
/* note: this does not correctly handle chunks that are > 64K */
|
/* note: this does not correctly handle chunks that are > 64K */
|
||||||
void
|
void
|
||||||
png_handle_tEXt(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
png_handle_tEXt(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
||||||
{
|
{
|
||||||
char *key, *text;
|
charf *key;
|
||||||
|
charf *text;
|
||||||
|
|
||||||
text = NULL;
|
text = NULL;
|
||||||
|
|
||||||
key = (char *)png_large_malloc(png_ptr, length + 1);
|
key = (charf *)png_large_malloc(png_ptr, length + 1);
|
||||||
png_crc_read(png_ptr, (png_byte *)key, length);
|
png_crc_read(png_ptr, (png_bytef *)key, length);
|
||||||
key[(png_size_t)length] = '\0';
|
key[(png_size_t)length] = '\0';
|
||||||
|
|
||||||
for (text = key; *text; text++)
|
for (text = key; *text; text++)
|
||||||
@ -480,19 +500,22 @@ png_handle_tEXt(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
|
|
||||||
png_read_tEXt(png_ptr, info, key, text, length - (text - key));
|
png_read_tEXt(png_ptr, info, key, text, length - (text - key));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||||
/* note: this does not correctly handle chunks that are > 64K compressed */
|
/* note: this does not correctly handle chunks that are > 64K compressed */
|
||||||
void
|
void
|
||||||
png_handle_zTXt(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
png_handle_zTXt(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
||||||
{
|
{
|
||||||
char *key, *text;
|
charf *key;
|
||||||
|
charf *text;
|
||||||
int ret;
|
int ret;
|
||||||
png_uint_32 text_size, key_size;
|
png_uint_32 text_size, key_size;
|
||||||
|
|
||||||
text = NULL;
|
text = NULL;
|
||||||
|
|
||||||
key = png_large_malloc(png_ptr, length + 1);
|
key = png_large_malloc(png_ptr, length + 1);
|
||||||
png_crc_read(png_ptr, (png_byte *)key, length);
|
png_crc_read(png_ptr, (png_bytef *)key, length);
|
||||||
key[(png_size_t)length] = '\0';
|
key[(png_size_t)length] = '\0';
|
||||||
|
|
||||||
for (text = key; *text; text++)
|
for (text = key; *text; text++)
|
||||||
@ -515,7 +538,7 @@ png_handle_zTXt(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
|
|
||||||
text++;
|
text++;
|
||||||
|
|
||||||
png_ptr->zstream->next_in = (png_byte *)text;
|
png_ptr->zstream->next_in = (png_bytef *)text;
|
||||||
png_ptr->zstream->avail_in = (uInt)(length - (text - key));
|
png_ptr->zstream->avail_in = (uInt)(length - (text - key));
|
||||||
png_ptr->zstream->next_out = png_ptr->zbuf;
|
png_ptr->zstream->next_out = png_ptr->zbuf;
|
||||||
png_ptr->zstream->avail_out = (png_size_t)png_ptr->zbuf_size;
|
png_ptr->zstream->avail_out = (png_size_t)png_ptr->zbuf_size;
|
||||||
@ -542,23 +565,23 @@ png_handle_zTXt(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
text = png_malloc(png_ptr,
|
text = png_malloc(png_ptr,
|
||||||
png_ptr->zbuf_size - png_ptr->zstream->avail_out +
|
png_ptr->zbuf_size - png_ptr->zstream->avail_out +
|
||||||
key_size + 1);
|
key_size + 1);
|
||||||
memcpy(text + (png_size_t)key_size, png_ptr->zbuf,
|
png_memcpy(text + (png_size_t)key_size, png_ptr->zbuf,
|
||||||
(png_size_t)(png_ptr->zbuf_size - png_ptr->zstream->avail_out));
|
(png_size_t)(png_ptr->zbuf_size - png_ptr->zstream->avail_out));
|
||||||
memcpy(text, key, (png_size_t)key_size);
|
png_memcpy(text, key, (png_size_t)key_size);
|
||||||
text_size = key_size + (png_size_t)png_ptr->zbuf_size -
|
text_size = key_size + (png_size_t)png_ptr->zbuf_size -
|
||||||
png_ptr->zstream->avail_out;
|
png_ptr->zstream->avail_out;
|
||||||
*(text + (png_size_t)text_size) = '\0';
|
*(text + (png_size_t)text_size) = '\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *tmp;
|
charf *tmp;
|
||||||
|
|
||||||
tmp = text;
|
tmp = text;
|
||||||
text = png_large_malloc(png_ptr, text_size +
|
text = png_large_malloc(png_ptr, text_size +
|
||||||
png_ptr->zbuf_size - png_ptr->zstream->avail_out + 1);
|
png_ptr->zbuf_size - png_ptr->zstream->avail_out + 1);
|
||||||
memcpy(text, tmp, (png_size_t)text_size);
|
png_memcpy(text, tmp, (png_size_t)text_size);
|
||||||
png_large_free(png_ptr, tmp);
|
png_large_free(png_ptr, tmp);
|
||||||
memcpy(text + (png_size_t)text_size, png_ptr->zbuf,
|
png_memcpy(text + (png_size_t)text_size, png_ptr->zbuf,
|
||||||
(png_size_t)(png_ptr->zbuf_size - png_ptr->zstream->avail_out));
|
(png_size_t)(png_ptr->zbuf_size - png_ptr->zstream->avail_out));
|
||||||
text_size += png_ptr->zbuf_size - png_ptr->zstream->avail_out;
|
text_size += png_ptr->zbuf_size - png_ptr->zstream->avail_out;
|
||||||
*(text + (png_size_t)text_size) = '\0';
|
*(text + (png_size_t)text_size) = '\0';
|
||||||
@ -595,6 +618,7 @@ png_handle_zTXt(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
|
|
||||||
png_read_zTXt(png_ptr, info, key, text, text_size, 0);
|
png_read_zTXt(png_ptr, info, key, text, text_size, 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Combines the row recently read in with the previous row.
|
/* Combines the row recently read in with the previous row.
|
||||||
This routine takes care of alpha and transparency if requested.
|
This routine takes care of alpha and transparency if requested.
|
||||||
@ -608,12 +632,12 @@ png_handle_zTXt(png_struct *png_ptr, png_info *info, png_uint_32 length)
|
|||||||
you want all pixels to be combined, pass 0xff (255) in mask.
|
you want all pixels to be combined, pass 0xff (255) in mask.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
png_combine_row(png_struct *png_ptr, png_byte *row,
|
png_combine_row(png_struct *png_ptr, png_bytef *row,
|
||||||
int mask)
|
int mask)
|
||||||
{
|
{
|
||||||
if (mask == 0xff)
|
if (mask == 0xff)
|
||||||
{
|
{
|
||||||
memcpy(row, png_ptr->row_buf + 1,
|
png_memcpy(row, png_ptr->row_buf + 1,
|
||||||
(png_size_t)((png_ptr->width *
|
(png_size_t)((png_ptr->width *
|
||||||
png_ptr->row_info.pixel_depth + 7) >> 3));
|
png_ptr->row_info.pixel_depth + 7) >> 3));
|
||||||
}
|
}
|
||||||
@ -623,8 +647,8 @@ png_combine_row(png_struct *png_ptr, png_byte *row,
|
|||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
png_byte *sp;
|
png_bytef *sp;
|
||||||
png_byte *dp;
|
png_bytef *dp;
|
||||||
int m;
|
int m;
|
||||||
int shift;
|
int shift;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
@ -661,8 +685,8 @@ png_combine_row(png_struct *png_ptr, png_byte *row,
|
|||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
png_byte *sp;
|
png_bytef *sp;
|
||||||
png_byte *dp;
|
png_bytef *dp;
|
||||||
int m;
|
int m;
|
||||||
int shift;
|
int shift;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
@ -698,8 +722,8 @@ png_combine_row(png_struct *png_ptr, png_byte *row,
|
|||||||
}
|
}
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
png_byte *sp;
|
png_bytef *sp;
|
||||||
png_byte *dp;
|
png_bytef *dp;
|
||||||
int m;
|
int m;
|
||||||
int shift;
|
int shift;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
@ -735,8 +759,8 @@ png_combine_row(png_struct *png_ptr, png_byte *row,
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
png_byte *sp;
|
png_bytef *sp;
|
||||||
png_byte *dp;
|
png_bytef *dp;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
int pixel_bytes, m;
|
int pixel_bytes, m;
|
||||||
|
|
||||||
@ -749,7 +773,7 @@ png_combine_row(png_struct *png_ptr, png_byte *row,
|
|||||||
{
|
{
|
||||||
if (m & mask)
|
if (m & mask)
|
||||||
{
|
{
|
||||||
memcpy(dp, sp, pixel_bytes);
|
png_memcpy(dp, sp, pixel_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
sp += pixel_bytes;
|
sp += pixel_bytes;
|
||||||
@ -766,8 +790,9 @@ png_combine_row(png_struct *png_ptr, png_byte *row,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PNG_READ_INTERLACING_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_do_read_interlace(png_row_info *row_info, png_byte *row, int pass)
|
png_do_read_interlace(png_row_info *row_info, png_bytef *row, int pass)
|
||||||
{
|
{
|
||||||
if (row && row_info)
|
if (row && row_info)
|
||||||
{
|
{
|
||||||
@ -779,7 +804,7 @@ png_do_read_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
png_byte *sp, *dp;
|
png_bytef *sp, *dp;
|
||||||
int sshift, dshift;
|
int sshift, dshift;
|
||||||
png_byte v;
|
png_byte v;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
@ -816,7 +841,7 @@ png_do_read_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
png_byte *sp, *dp;
|
png_bytef *sp, *dp;
|
||||||
int sshift, dshift;
|
int sshift, dshift;
|
||||||
png_byte v;
|
png_byte v;
|
||||||
png_uint_32 i, j;
|
png_uint_32 i, j;
|
||||||
@ -852,7 +877,7 @@ png_do_read_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
}
|
}
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
png_byte *sp, *dp;
|
png_bytef *sp, *dp;
|
||||||
int sshift, dshift;
|
int sshift, dshift;
|
||||||
png_byte v;
|
png_byte v;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
@ -889,7 +914,7 @@ png_do_read_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
png_byte *sp, *dp;
|
png_bytef *sp, *dp;
|
||||||
png_byte v[8];
|
png_byte v[8];
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
int j;
|
int j;
|
||||||
@ -901,10 +926,10 @@ png_do_read_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
dp = row + (png_size_t)((final_width - 1) * pixel_bytes);
|
dp = row + (png_size_t)((final_width - 1) * pixel_bytes);
|
||||||
for (i = row_info->width; i; i--)
|
for (i = row_info->width; i; i--)
|
||||||
{
|
{
|
||||||
memcpy(v, sp, pixel_bytes);
|
png_memcpy(v, sp, pixel_bytes);
|
||||||
for (j = 0; j < png_pass_inc[pass]; j++)
|
for (j = 0; j < png_pass_inc[pass]; j++)
|
||||||
{
|
{
|
||||||
memcpy(dp, v, pixel_bytes);
|
png_memcpy(dp, v, pixel_bytes);
|
||||||
dp -= pixel_bytes;
|
dp -= pixel_bytes;
|
||||||
}
|
}
|
||||||
sp -= pixel_bytes;
|
sp -= pixel_bytes;
|
||||||
@ -917,10 +942,11 @@ png_do_read_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
(png_uint_32)row_info->pixel_depth + 7) >> 3);
|
(png_uint_32)row_info->pixel_depth + 7) >> 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
png_read_filter_row(png_row_info *row_info, png_byte *row,
|
png_read_filter_row(png_row_info *row_info, png_bytef *row,
|
||||||
png_byte *prev_row, int filter)
|
png_bytef *prev_row, int filter)
|
||||||
{
|
{
|
||||||
switch (filter)
|
switch (filter)
|
||||||
{
|
{
|
||||||
@ -930,8 +956,8 @@ png_read_filter_row(png_row_info *row_info, png_byte *row,
|
|||||||
{
|
{
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
int bpp;
|
int bpp;
|
||||||
png_byte *rp;
|
png_bytef *rp;
|
||||||
png_byte *lp;
|
png_bytef *lp;
|
||||||
|
|
||||||
bpp = (row_info->pixel_depth + 7) / 8;
|
bpp = (row_info->pixel_depth + 7) / 8;
|
||||||
for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
|
for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
|
||||||
@ -944,8 +970,8 @@ png_read_filter_row(png_row_info *row_info, png_byte *row,
|
|||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
png_byte *rp;
|
png_bytef *rp;
|
||||||
png_byte *pp;
|
png_bytef *pp;
|
||||||
|
|
||||||
for (i = 0, rp = row, pp = prev_row;
|
for (i = 0, rp = row, pp = prev_row;
|
||||||
i < row_info->rowbytes; i++, rp++, pp++)
|
i < row_info->rowbytes; i++, rp++, pp++)
|
||||||
@ -958,9 +984,9 @@ png_read_filter_row(png_row_info *row_info, png_byte *row,
|
|||||||
{
|
{
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
int bpp;
|
int bpp;
|
||||||
png_byte *rp;
|
png_bytef *rp;
|
||||||
png_byte *pp;
|
png_bytef *pp;
|
||||||
png_byte *lp;
|
png_bytef *lp;
|
||||||
|
|
||||||
bpp = (row_info->pixel_depth + 7) / 8;
|
bpp = (row_info->pixel_depth + 7) / 8;
|
||||||
for (i = 0, rp = row, pp = prev_row;
|
for (i = 0, rp = row, pp = prev_row;
|
||||||
@ -980,10 +1006,10 @@ png_read_filter_row(png_row_info *row_info, png_byte *row,
|
|||||||
{
|
{
|
||||||
int bpp;
|
int bpp;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
png_byte *rp;
|
png_bytef *rp;
|
||||||
png_byte *pp;
|
png_bytef *pp;
|
||||||
png_byte *lp;
|
png_bytef *lp;
|
||||||
png_byte *cp;
|
png_bytef *cp;
|
||||||
|
|
||||||
bpp = (row_info->pixel_depth + 7) / 8;
|
bpp = (row_info->pixel_depth + 7) / 8;
|
||||||
for (i = 0, rp = row, pp = prev_row,
|
for (i = 0, rp = row, pp = prev_row,
|
||||||
@ -1033,7 +1059,7 @@ png_read_finish_row(png_struct *png_ptr)
|
|||||||
if (png_ptr->interlaced)
|
if (png_ptr->interlaced)
|
||||||
{
|
{
|
||||||
png_ptr->row_number = 0;
|
png_ptr->row_number = 0;
|
||||||
memset(png_ptr->prev_row, 0, (png_size_t)png_ptr->rowbytes + 1);
|
png_memset(png_ptr->prev_row, 0, (png_size_t)png_ptr->rowbytes + 1);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
png_ptr->pass++;
|
png_ptr->pass++;
|
||||||
@ -1054,6 +1080,8 @@ png_read_finish_row(png_struct *png_ptr)
|
|||||||
if (!(png_ptr->num_rows))
|
if (!(png_ptr->num_rows))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (png_ptr->transformations & PNG_INTERLACE)
|
||||||
|
break;
|
||||||
} while (png_ptr->iwidth == 0);
|
} while (png_ptr->iwidth == 0);
|
||||||
|
|
||||||
if (png_ptr->pass < 7)
|
if (png_ptr->pass < 7)
|
||||||
@ -1157,11 +1185,14 @@ png_read_start_row(png_struct *png_ptr)
|
|||||||
|
|
||||||
max_pixel_depth = png_ptr->pixel_depth;
|
max_pixel_depth = png_ptr->pixel_depth;
|
||||||
|
|
||||||
|
#if defined(PNG_READ_PACK_SUPPORTED)
|
||||||
if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
|
if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
|
||||||
{
|
{
|
||||||
max_pixel_depth = 8;
|
max_pixel_depth = 8;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_PACK_SUPPORTED)
|
||||||
if (png_ptr->transformations & (PNG_EXPAND | PNG_PACK))
|
if (png_ptr->transformations & (PNG_EXPAND | PNG_PACK))
|
||||||
{
|
{
|
||||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||||
@ -1187,13 +1218,17 @@ png_read_start_row(png_struct *png_ptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (png_ptr->transformations & PNG_RGBA)
|
#if defined(PNG_READ_FILLER_SUPPORTED)
|
||||||
|
if (png_ptr->transformations & (PNG_FILLER))
|
||||||
{
|
{
|
||||||
if (max_pixel_depth < 32)
|
if (max_pixel_depth < 32)
|
||||||
max_pixel_depth = 32;
|
max_pixel_depth = 32;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
|
||||||
if (png_ptr->transformations & PNG_GRAY_TO_RGB)
|
if (png_ptr->transformations & PNG_GRAY_TO_RGB)
|
||||||
{
|
{
|
||||||
if ((png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
|
if ((png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
|
||||||
@ -1212,6 +1247,7 @@ png_read_start_row(png_struct *png_ptr)
|
|||||||
max_pixel_depth = 48;
|
max_pixel_depth = 48;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* align the width on the next larger 8 pixels. Mainly used
|
/* align the width on the next larger 8 pixels. Mainly used
|
||||||
for interlacing */
|
for interlacing */
|
||||||
@ -1224,7 +1260,7 @@ png_read_start_row(png_struct *png_ptr)
|
|||||||
if (rowbytes > 65536L)
|
if (rowbytes > 65536L)
|
||||||
png_error(png_ptr, "This image requires a row greater then 64KB");
|
png_error(png_ptr, "This image requires a row greater then 64KB");
|
||||||
#endif
|
#endif
|
||||||
png_ptr->row_buf = (png_byte *)png_large_malloc(png_ptr, rowbytes);
|
png_ptr->row_buf = (png_bytef *)png_large_malloc(png_ptr, rowbytes);
|
||||||
|
|
||||||
#ifdef PNG_MAX_MALLOC_64K
|
#ifdef PNG_MAX_MALLOC_64K
|
||||||
if (png_ptr->rowbytes + 1 > 65536L)
|
if (png_ptr->rowbytes + 1 > 65536L)
|
||||||
@ -1233,11 +1269,8 @@ png_read_start_row(png_struct *png_ptr)
|
|||||||
png_ptr->prev_row = png_large_malloc(png_ptr,
|
png_ptr->prev_row = png_large_malloc(png_ptr,
|
||||||
png_ptr->rowbytes + 1);
|
png_ptr->rowbytes + 1);
|
||||||
|
|
||||||
memset(png_ptr->prev_row, 0, (png_size_t)png_ptr->rowbytes + 1);
|
png_memset(png_ptr->prev_row, 0, (png_size_t)png_ptr->rowbytes + 1);
|
||||||
|
|
||||||
png_ptr->row_init = 1;
|
png_ptr->row_init = 1;
|
||||||
|
|
||||||
/* if we have to do any modifications of values for the transformations,
|
|
||||||
do them here */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
39
pngtest.c
39
pngtest.c
@ -1,9 +1,9 @@
|
|||||||
/* pngtest.c - a simple test program to test libpng
|
/* pngtest.c - a simple test program to test libpng
|
||||||
|
|
||||||
libpng 1.0 beta 1 - version 0.71
|
libpng 1.0 beta 2 - version 0.81
|
||||||
For conditions of distribution and use, see copyright notice in png.h
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
June 26, 1995
|
August 24, 1995
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -38,19 +38,29 @@ int main()
|
|||||||
|
|
||||||
row_buf = (png_byte *)0;
|
row_buf = (png_byte *)0;
|
||||||
|
|
||||||
|
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
|
||||||
|
|
||||||
|
if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
|
||||||
|
{
|
||||||
|
fprintf(STDERR,
|
||||||
|
"Warning: versions are different between png.h and png.c\n");
|
||||||
|
fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
|
||||||
|
fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
|
||||||
|
}
|
||||||
|
|
||||||
fpin = fopen(inname, "rb");
|
fpin = fopen(inname, "rb");
|
||||||
if (!fpin)
|
if (!fpin)
|
||||||
{
|
{
|
||||||
fprintf(STDERR, "Could not find input file %s\n", inname);
|
fprintf(STDERR, "Could not find input file %s\n", inname);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fpout = fopen(outname, "wb");
|
fpout = fopen(outname, "wb");
|
||||||
if (!fpin)
|
if (!fpout)
|
||||||
{
|
{
|
||||||
fprintf(STDERR, "could not open output file %s\n", outname);
|
fprintf(STDERR, "could not open output file %s\n", outname);
|
||||||
fclose(fpin);
|
fclose(fpin);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setjmp(read_ptr.jmpbuf))
|
if (setjmp(read_ptr.jmpbuf))
|
||||||
@ -58,7 +68,7 @@ int main()
|
|||||||
fprintf(STDERR, "libpng read error\n");
|
fprintf(STDERR, "libpng read error\n");
|
||||||
fclose(fpin);
|
fclose(fpin);
|
||||||
fclose(fpout);
|
fclose(fpout);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setjmp(write_ptr.jmpbuf))
|
if (setjmp(write_ptr.jmpbuf))
|
||||||
@ -66,7 +76,7 @@ int main()
|
|||||||
fprintf(STDERR, "libpng write error\n");
|
fprintf(STDERR, "libpng write error\n");
|
||||||
fclose(fpin);
|
fclose(fpin);
|
||||||
fclose(fpout);
|
fclose(fpout);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_read_init(&read_ptr);
|
png_read_init(&read_ptr);
|
||||||
@ -96,7 +106,7 @@ int main()
|
|||||||
png_write_destroy(&write_ptr);
|
png_write_destroy(&write_ptr);
|
||||||
fclose(fpin);
|
fclose(fpin);
|
||||||
fclose(fpout);
|
fclose(fpout);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info_ptr.interlace_type)
|
if (info_ptr.interlace_type)
|
||||||
@ -113,8 +123,8 @@ int main()
|
|||||||
{
|
{
|
||||||
for (y = 0; y < info_ptr.height; y++)
|
for (y = 0; y < info_ptr.height; y++)
|
||||||
{
|
{
|
||||||
png_read_rows(&read_ptr, &row_buf, (png_byte **)0, 1);
|
png_read_rows(&read_ptr, (png_bytef **)&row_buf, (png_bytef **)0, 1);
|
||||||
png_write_rows(&write_ptr, &row_buf, 1);
|
png_write_rows(&write_ptr, (png_bytef **)&row_buf, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +144,7 @@ int main()
|
|||||||
if (!fpin)
|
if (!fpin)
|
||||||
{
|
{
|
||||||
fprintf(STDERR, "could not find file %s\n", inname);
|
fprintf(STDERR, "could not find file %s\n", inname);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fpout = fopen(outname, "rb");
|
fpout = fopen(outname, "rb");
|
||||||
@ -142,7 +152,7 @@ int main()
|
|||||||
{
|
{
|
||||||
fprintf(STDERR, "could not find file %s\n", outname);
|
fprintf(STDERR, "could not find file %s\n", outname);
|
||||||
fclose(fpin);
|
fclose(fpin);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
@ -157,7 +167,7 @@ int main()
|
|||||||
fprintf(STDERR, "files are of a different size\n");
|
fprintf(STDERR, "files are of a different size\n");
|
||||||
fclose(fpin);
|
fclose(fpin);
|
||||||
fclose(fpout);
|
fclose(fpout);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!num_in)
|
if (!num_in)
|
||||||
@ -168,7 +178,7 @@ int main()
|
|||||||
fprintf(STDERR, "files are different\n");
|
fprintf(STDERR, "files are different\n");
|
||||||
fclose(fpin);
|
fclose(fpin);
|
||||||
fclose(fpout);
|
fclose(fpout);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,3 +188,4 @@ int main()
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
pngtest.png
BIN
pngtest.png
Binary file not shown.
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.0 KiB |
15
pngtodo.txt
15
pngtodo.txt
@ -1,7 +1,13 @@
|
|||||||
pngtodo.txt - list of things to do for libpng
|
pngtodo.txt - list of things to do for libpng
|
||||||
|
|
||||||
allow user to #define out unused transformations
|
for 0.9
|
||||||
medium memory model support
|
medium memory model
|
||||||
|
improved dithering?
|
||||||
|
|
||||||
|
for 1.1
|
||||||
|
push reader
|
||||||
|
|
||||||
|
for 1.1 or later
|
||||||
overlaying one image on top of another
|
overlaying one image on top of another
|
||||||
optional palette creation
|
optional palette creation
|
||||||
histogram creation
|
histogram creation
|
||||||
@ -9,14 +15,13 @@ pngtodo.txt - list of things to do for libpng
|
|||||||
cHRM transformation
|
cHRM transformation
|
||||||
support for other chunks being defined (sCAl, the gIF series,
|
support for other chunks being defined (sCAl, the gIF series,
|
||||||
and others that people come up with).
|
and others that people come up with).
|
||||||
push reader
|
|
||||||
pull writer
|
pull writer
|
||||||
better dithering
|
better dithering
|
||||||
keep up with public chunks
|
keep up with public chunks
|
||||||
other compression libraries
|
other compression libraries
|
||||||
more exotic interlace handling
|
more exotic interlace handling
|
||||||
better filtering
|
better filtering (counting huffman bits? filter type inertia?)
|
||||||
C++ wrapper
|
C++ wrapper
|
||||||
other languages
|
other languages (pascal, for one)
|
||||||
comments of > 64K
|
comments of > 64K
|
||||||
|
|
||||||
|
63
pngtrans.c
63
pngtrans.c
@ -2,22 +2,25 @@
|
|||||||
/* pngtrans.c - transforms the data in a row
|
/* pngtrans.c - transforms the data in a row
|
||||||
routines used by both readers and writers
|
routines used by both readers and writers
|
||||||
|
|
||||||
libpng 1.0 beta 1 - version 0.71
|
libpng 1.0 beta 2 - version 0.81
|
||||||
For conditions of distribution and use, see copyright notice in png.h
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
June 26, 1995
|
August 24, 1995
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PNG_INTERNAL
|
#define PNG_INTERNAL
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
|
|
||||||
|
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||||
/* turn on bgr to rgb mapping */
|
/* turn on bgr to rgb mapping */
|
||||||
void
|
void
|
||||||
png_set_bgr(png_struct *png_ptr)
|
png_set_bgr(png_struct *png_ptr)
|
||||||
{
|
{
|
||||||
png_ptr->transformations |= PNG_BGR;
|
png_ptr->transformations |= PNG_BGR;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||||
/* turn on 16 bit byte swapping */
|
/* turn on 16 bit byte swapping */
|
||||||
void
|
void
|
||||||
png_set_swap(png_struct *png_ptr)
|
png_set_swap(png_struct *png_ptr)
|
||||||
@ -25,7 +28,9 @@ png_set_swap(png_struct *png_ptr)
|
|||||||
if (png_ptr->bit_depth == 16)
|
if (png_ptr->bit_depth == 16)
|
||||||
png_ptr->transformations |= PNG_SWAP_BYTES;
|
png_ptr->transformations |= PNG_SWAP_BYTES;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||||
/* turn on pixel packing */
|
/* turn on pixel packing */
|
||||||
void
|
void
|
||||||
png_set_packing(png_struct *png_ptr)
|
png_set_packing(png_struct *png_ptr)
|
||||||
@ -36,14 +41,18 @@ png_set_packing(png_struct *png_ptr)
|
|||||||
png_ptr->usr_bit_depth = 8;
|
png_ptr->usr_bit_depth = 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_set_shift(png_struct *png_ptr, png_color_8 *true_bits)
|
png_set_shift(png_struct *png_ptr, png_color_8 *true_bits)
|
||||||
{
|
{
|
||||||
png_ptr->transformations |= PNG_SHIFT;
|
png_ptr->transformations |= PNG_SHIFT;
|
||||||
png_ptr->shift = *true_bits;
|
png_ptr->shift = *true_bits;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_INTERLACING_SUPPORTED) || defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||||
int
|
int
|
||||||
png_set_interlace_handling(png_struct *png_ptr)
|
png_set_interlace_handling(png_struct *png_ptr)
|
||||||
{
|
{
|
||||||
@ -55,25 +64,35 @@ png_set_interlace_handling(png_struct *png_ptr)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_set_rgbx(png_struct *png_ptr)
|
png_set_filler(png_struct *png_ptr, int filler, int filler_loc)
|
||||||
{
|
{
|
||||||
png_ptr->transformations |= PNG_RGBA;
|
png_ptr->transformations |= PNG_FILLER;
|
||||||
|
png_ptr->filler = (png_byte)filler;
|
||||||
|
png_ptr->filler_loc = (png_byte)filler_loc;
|
||||||
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB &&
|
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB &&
|
||||||
png_ptr->bit_depth == 8)
|
png_ptr->bit_depth == 8)
|
||||||
png_ptr->usr_channels = 4;
|
png_ptr->usr_channels = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* old functions kept around for compatability purposes */
|
||||||
|
void
|
||||||
|
png_set_rgbx(png_struct *png_ptr)
|
||||||
|
{
|
||||||
|
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
png_set_xrgb(png_struct *png_ptr)
|
png_set_xrgb(png_struct *png_ptr)
|
||||||
{
|
{
|
||||||
png_ptr->transformations |= PNG_XRGB;
|
png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE);
|
||||||
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB &&
|
|
||||||
png_ptr->bit_depth == 8)
|
|
||||||
png_ptr->usr_channels = 4;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
|
||||||
void
|
void
|
||||||
png_set_invert_mono(png_struct *png_ptr)
|
png_set_invert_mono(png_struct *png_ptr)
|
||||||
{
|
{
|
||||||
@ -82,12 +101,12 @@ png_set_invert_mono(png_struct *png_ptr)
|
|||||||
|
|
||||||
/* invert monocrome grayscale data */
|
/* invert monocrome grayscale data */
|
||||||
void
|
void
|
||||||
png_do_invert(png_row_info *row_info, png_byte *row)
|
png_do_invert(png_row_info *row_info, png_bytef *row)
|
||||||
{
|
{
|
||||||
if (row && row_info && row_info->bit_depth == 1 &&
|
if (row && row_info && row_info->bit_depth == 1 &&
|
||||||
row_info->color_type == PNG_COLOR_TYPE_GRAY)
|
row_info->color_type == PNG_COLOR_TYPE_GRAY)
|
||||||
{
|
{
|
||||||
png_byte *rp;
|
png_bytef *rp;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
|
|
||||||
for (i = 0, rp = row;
|
for (i = 0, rp = row;
|
||||||
@ -98,14 +117,17 @@ png_do_invert(png_row_info *row_info, png_byte *row)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||||
/* swaps byte order on 16 bit depth images */
|
/* swaps byte order on 16 bit depth images */
|
||||||
void
|
void
|
||||||
png_do_swap(png_row_info *row_info, png_byte *row)
|
png_do_swap(png_row_info *row_info, png_bytef *row)
|
||||||
{
|
{
|
||||||
if (row && row_info && row_info->bit_depth == 16)
|
if (row && row_info && row_info->bit_depth == 16)
|
||||||
{
|
{
|
||||||
png_byte *rp, t;
|
png_bytef *rp;
|
||||||
|
png_byte t;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
|
|
||||||
for (i = 0, rp = row;
|
for (i = 0, rp = row;
|
||||||
@ -118,16 +140,19 @@ png_do_swap(png_row_info *row_info, png_byte *row)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||||
/* swaps red and blue */
|
/* swaps red and blue */
|
||||||
void
|
void
|
||||||
png_do_bgr(png_row_info *row_info, png_byte *row)
|
png_do_bgr(png_row_info *row_info, png_bytef *row)
|
||||||
{
|
{
|
||||||
if (row && row_info && (row_info->color_type & 2))
|
if (row && row_info && (row_info->color_type & 2))
|
||||||
{
|
{
|
||||||
if (row_info->color_type == 2 && row_info->bit_depth == 8)
|
if (row_info->color_type == 2 && row_info->bit_depth == 8)
|
||||||
{
|
{
|
||||||
png_byte *rp, t;
|
png_bytef *rp;
|
||||||
|
png_byte t;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
|
|
||||||
for (i = 0, rp = row;
|
for (i = 0, rp = row;
|
||||||
@ -141,7 +166,8 @@ png_do_bgr(png_row_info *row_info, png_byte *row)
|
|||||||
}
|
}
|
||||||
else if (row_info->color_type == 6 && row_info->bit_depth == 8)
|
else if (row_info->color_type == 6 && row_info->bit_depth == 8)
|
||||||
{
|
{
|
||||||
png_byte *rp, t;
|
png_bytef *rp;
|
||||||
|
png_byte t;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
|
|
||||||
for (i = 0, rp = row;
|
for (i = 0, rp = row;
|
||||||
@ -155,7 +181,8 @@ png_do_bgr(png_row_info *row_info, png_byte *row)
|
|||||||
}
|
}
|
||||||
else if (row_info->color_type == 2 && row_info->bit_depth == 16)
|
else if (row_info->color_type == 2 && row_info->bit_depth == 16)
|
||||||
{
|
{
|
||||||
png_byte *rp, t[2];
|
png_bytef *rp;
|
||||||
|
png_byte t[2];
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
|
|
||||||
for (i = 0, rp = row;
|
for (i = 0, rp = row;
|
||||||
@ -172,7 +199,8 @@ png_do_bgr(png_row_info *row_info, png_byte *row)
|
|||||||
}
|
}
|
||||||
else if (row_info->color_type == 6 && row_info->bit_depth == 16)
|
else if (row_info->color_type == 6 && row_info->bit_depth == 16)
|
||||||
{
|
{
|
||||||
png_byte *rp, t[2];
|
png_bytef *rp;
|
||||||
|
png_byte t[2];
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
|
|
||||||
for (i = 0, rp = row;
|
for (i = 0, rp = row;
|
||||||
@ -189,4 +217,5 @@ png_do_bgr(png_row_info *row_info, png_byte *row)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
140
pngwrite.c
140
pngwrite.c
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
/* pngwrite.c - general routines to write a png file
|
/* pngwrite.c - general routines to write a png file
|
||||||
|
|
||||||
libpng 1.0 beta 1 - version 0.71
|
libpng 1.0 beta 2 - version 0.81
|
||||||
For conditions of distribution and use, see copyright notice in png.h
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
June 26, 1995
|
August 24, 1995
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* get internal access to png.h */
|
/* get internal access to png.h */
|
||||||
@ -30,34 +30,53 @@ png_write_info(png_struct *png_ptr, png_info *info)
|
|||||||
info->interlace_type);
|
info->interlace_type);
|
||||||
/* the rest of these check to see if the valid field has the appropriate
|
/* the rest of these check to see if the valid field has the appropriate
|
||||||
flag set, and if it does, writes the chunk. */
|
flag set, and if it does, writes the chunk. */
|
||||||
|
#if defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||||
if (info->valid & PNG_INFO_gAMA)
|
if (info->valid & PNG_INFO_gAMA)
|
||||||
png_write_gAMA(png_ptr, info->gamma);
|
png_write_gAMA(png_ptr, info->gamma);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||||
if (info->valid & PNG_INFO_sBIT)
|
if (info->valid & PNG_INFO_sBIT)
|
||||||
png_write_sBIT(png_ptr, &(info->sig_bit), info->color_type);
|
png_write_sBIT(png_ptr, &(info->sig_bit), info->color_type);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||||
if (info->valid & PNG_INFO_cHRM)
|
if (info->valid & PNG_INFO_cHRM)
|
||||||
png_write_cHRM(png_ptr,
|
png_write_cHRM(png_ptr,
|
||||||
info->x_white, info->y_white,
|
info->x_white, info->y_white,
|
||||||
info->x_red, info->y_red,
|
info->x_red, info->y_red,
|
||||||
info->x_green, info->y_green,
|
info->x_green, info->y_green,
|
||||||
info->x_blue, info->y_blue);
|
info->x_blue, info->y_blue);
|
||||||
|
#endif
|
||||||
if (info->valid & PNG_INFO_PLTE)
|
if (info->valid & PNG_INFO_PLTE)
|
||||||
png_write_PLTE(png_ptr, info->palette, info->num_palette);
|
png_write_PLTE(png_ptr, info->palette, info->num_palette);
|
||||||
|
#if defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||||
if (info->valid & PNG_INFO_tRNS)
|
if (info->valid & PNG_INFO_tRNS)
|
||||||
png_write_tRNS(png_ptr, info->trans, &(info->trans_values),
|
png_write_tRNS(png_ptr, info->trans, &(info->trans_values),
|
||||||
info->num_trans, info->color_type);
|
info->num_trans, info->color_type);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_bKGD_SUPPORTED)
|
||||||
if (info->valid & PNG_INFO_bKGD)
|
if (info->valid & PNG_INFO_bKGD)
|
||||||
png_write_bKGD(png_ptr, &(info->background), info->color_type);
|
png_write_bKGD(png_ptr, &(info->background), info->color_type);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_hIST_SUPPORTED)
|
||||||
if (info->valid & PNG_INFO_hIST)
|
if (info->valid & PNG_INFO_hIST)
|
||||||
png_write_hIST(png_ptr, info->hist, info->num_palette);
|
png_write_hIST(png_ptr, info->hist, info->num_palette);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||||
if (info->valid & PNG_INFO_pHYs)
|
if (info->valid & PNG_INFO_pHYs)
|
||||||
png_write_pHYs(png_ptr, info->x_pixels_per_unit,
|
png_write_pHYs(png_ptr, info->x_pixels_per_unit,
|
||||||
info->y_pixels_per_unit, info->phys_unit_type);
|
info->y_pixels_per_unit, info->phys_unit_type);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||||
if (info->valid & PNG_INFO_oFFs)
|
if (info->valid & PNG_INFO_oFFs)
|
||||||
png_write_oFFs(png_ptr, info->x_offset, info->y_offset,
|
png_write_oFFs(png_ptr, info->x_offset, info->y_offset,
|
||||||
info->offset_unit_type);
|
info->offset_unit_type);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||||
if (info->valid & PNG_INFO_tIME)
|
if (info->valid & PNG_INFO_tIME)
|
||||||
png_write_tIME(png_ptr, &(info->mod_time));
|
png_write_tIME(png_ptr, &(info->mod_time));
|
||||||
/* Check to see if we need to write text chunks */
|
/* Check to see if we need to write text chunks */
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||||
if (info->num_text)
|
if (info->num_text)
|
||||||
{
|
{
|
||||||
int i; /* local counter */
|
int i; /* local counter */
|
||||||
@ -68,19 +87,24 @@ png_write_info(png_struct *png_ptr, png_info *info)
|
|||||||
/* if chunk is compressed */
|
/* if chunk is compressed */
|
||||||
if (info->text[i].compression >= 0)
|
if (info->text[i].compression >= 0)
|
||||||
{
|
{
|
||||||
|
#if defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||||
/* write compressed chunk */
|
/* write compressed chunk */
|
||||||
png_write_zTXt(png_ptr, info->text[i].key,
|
png_write_zTXt(png_ptr, info->text[i].key,
|
||||||
info->text[i].text, info->text[i].text_length,
|
info->text[i].text, info->text[i].text_length,
|
||||||
info->text[i].compression);
|
info->text[i].compression);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if defined(PNG_WRITE_tEXt_SUPPORTED)
|
||||||
/* write uncompressed chunk */
|
/* write uncompressed chunk */
|
||||||
png_write_tEXt(png_ptr, info->text[i].key,
|
png_write_tEXt(png_ptr, info->text[i].key,
|
||||||
info->text[i].text, info->text[i].text_length);
|
info->text[i].text, info->text[i].text_length);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* writes the end of the png file. If you don't want to write comments or
|
/* writes the end of the png file. If you don't want to write comments or
|
||||||
@ -93,9 +117,12 @@ png_write_end(png_struct *png_ptr, png_info *info)
|
|||||||
/* see if user wants us to write information chunks */
|
/* see if user wants us to write information chunks */
|
||||||
if (info)
|
if (info)
|
||||||
{
|
{
|
||||||
|
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||||
/* check to see if user has supplied a time chunk */
|
/* check to see if user has supplied a time chunk */
|
||||||
if (info->valid & PNG_INFO_tIME)
|
if (info->valid & PNG_INFO_tIME)
|
||||||
png_write_tIME(png_ptr, &(info->mod_time));
|
png_write_tIME(png_ptr, &(info->mod_time));
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||||
/* check to see if we need to write comment chunks */
|
/* check to see if we need to write comment chunks */
|
||||||
if (info->num_text)
|
if (info->num_text)
|
||||||
{
|
{
|
||||||
@ -107,32 +134,30 @@ png_write_end(png_struct *png_ptr, png_info *info)
|
|||||||
/* check to see if comment is to be compressed */
|
/* check to see if comment is to be compressed */
|
||||||
if (info->text[i].compression >= 0)
|
if (info->text[i].compression >= 0)
|
||||||
{
|
{
|
||||||
|
#if defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||||
/* write compressed chunk */
|
/* write compressed chunk */
|
||||||
png_write_zTXt(png_ptr, info->text[i].key,
|
png_write_zTXt(png_ptr, info->text[i].key,
|
||||||
info->text[i].text, info->text[i].text_length,
|
info->text[i].text, info->text[i].text_length,
|
||||||
info->text[i].compression);
|
info->text[i].compression);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if defined(PNG_WRITE_tEXt_SUPPORTED)
|
||||||
/* write uncompressed chunk */
|
/* write uncompressed chunk */
|
||||||
png_write_tEXt(png_ptr, info->text[i].key,
|
png_write_tEXt(png_ptr, info->text[i].key,
|
||||||
info->text[i].text, info->text[i].text_length);
|
info->text[i].text, info->text[i].text_length);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
/* write end of png file */
|
/* write end of png file */
|
||||||
png_write_IEND(png_ptr);
|
png_write_IEND(png_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize the info structure */
|
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||||
void
|
|
||||||
png_info_init(png_info *info)
|
|
||||||
{
|
|
||||||
/* set everything to 0 */
|
|
||||||
memset(info, 0, sizeof (png_info));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
png_convert_from_struct_tm(png_time *ptime, struct tm *ttime)
|
png_convert_from_struct_tm(png_time *ptime, struct tm *ttime)
|
||||||
{
|
{
|
||||||
@ -152,6 +177,7 @@ png_convert_from_time_t(png_time *ptime, time_t ttime)
|
|||||||
tbuf = gmtime(&ttime);
|
tbuf = gmtime(&ttime);
|
||||||
png_convert_from_struct_tm(ptime, tbuf);
|
png_convert_from_struct_tm(ptime, tbuf);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* initialize png structure, and allocate any memory needed */
|
/* initialize png structure, and allocate any memory needed */
|
||||||
void
|
void
|
||||||
@ -160,23 +186,15 @@ png_write_init(png_struct *png_ptr)
|
|||||||
jmp_buf tmp_jmp; /* to save current jump buffer */
|
jmp_buf tmp_jmp; /* to save current jump buffer */
|
||||||
|
|
||||||
/* save jump buffer */
|
/* save jump buffer */
|
||||||
memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||||
/* reset all variables to 0 */
|
/* reset all variables to 0 */
|
||||||
memset(png_ptr, 0, sizeof (png_struct));
|
png_memset(png_ptr, 0, sizeof (png_struct));
|
||||||
/* restore jump buffer */
|
/* restore jump buffer */
|
||||||
memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||||
|
|
||||||
/* initialize zbuf - compression buffer */
|
/* initialize zbuf - compression buffer */
|
||||||
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
||||||
png_ptr->zbuf = png_large_malloc(png_ptr, png_ptr->zbuf_size);
|
png_ptr->zbuf = png_large_malloc(png_ptr, png_ptr->zbuf_size);
|
||||||
/* initialize zlib */
|
|
||||||
png_ptr->zstream = &(png_ptr->zstream_struct);
|
|
||||||
png_ptr->zstream->zalloc = png_zalloc;
|
|
||||||
png_ptr->zstream->zfree = png_zfree;
|
|
||||||
png_ptr->zstream->opaque = (voidp)png_ptr;
|
|
||||||
deflateInit(png_ptr->zstream, Z_BEST_COMPRESSION);
|
|
||||||
png_ptr->zstream->next_out = png_ptr->zbuf;
|
|
||||||
png_ptr->zstream->avail_out = (uInt)png_ptr->zbuf_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write a few rows of image data. If the image is interlaced,
|
/* write a few rows of image data. If the image is interlaced,
|
||||||
@ -184,11 +202,11 @@ png_write_init(png_struct *png_ptr)
|
|||||||
have called png_set_interlace_handling(), you will have to
|
have called png_set_interlace_handling(), you will have to
|
||||||
"write" the image seven times */
|
"write" the image seven times */
|
||||||
void
|
void
|
||||||
png_write_rows(png_struct *png_ptr, png_byte **row,
|
png_write_rows(png_struct *png_ptr, png_bytef **row,
|
||||||
png_uint_32 num_rows)
|
png_uint_32 num_rows)
|
||||||
{
|
{
|
||||||
png_uint_32 i; /* row counter */
|
png_uint_32 i; /* row counter */
|
||||||
png_byte **rp; /* row pointer */
|
png_bytef **rp; /* row pointer */
|
||||||
|
|
||||||
/* loop through the rows */
|
/* loop through the rows */
|
||||||
for (i = 0, rp = row; i < num_rows; i++, rp++)
|
for (i = 0, rp = row; i < num_rows; i++, rp++)
|
||||||
@ -200,11 +218,11 @@ png_write_rows(png_struct *png_ptr, png_byte **row,
|
|||||||
/* write the image. You only need to call this function once, even
|
/* write the image. You only need to call this function once, even
|
||||||
if you are writing an interlaced image. */
|
if you are writing an interlaced image. */
|
||||||
void
|
void
|
||||||
png_write_image(png_struct *png_ptr, png_byte **image)
|
png_write_image(png_struct *png_ptr, png_bytef **image)
|
||||||
{
|
{
|
||||||
png_uint_32 i; /* row index */
|
png_uint_32 i; /* row index */
|
||||||
int pass, num_pass; /* pass variables */
|
int pass, num_pass; /* pass variables */
|
||||||
png_byte **rp; /* points to current row */
|
png_bytef **rp; /* points to current row */
|
||||||
|
|
||||||
/* intialize interlace handling. If image is not interlaced,
|
/* intialize interlace handling. If image is not interlaced,
|
||||||
this will set pass to 1 */
|
this will set pass to 1 */
|
||||||
@ -222,7 +240,7 @@ png_write_image(png_struct *png_ptr, png_byte **image)
|
|||||||
|
|
||||||
/* write a row of image data */
|
/* write a row of image data */
|
||||||
void
|
void
|
||||||
png_write_row(png_struct *png_ptr, png_byte *row)
|
png_write_row(png_struct *png_ptr, png_bytef *row)
|
||||||
{
|
{
|
||||||
/* initialize transformations and other stuff if first time */
|
/* initialize transformations and other stuff if first time */
|
||||||
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
|
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
|
||||||
@ -230,6 +248,7 @@ png_write_row(png_struct *png_ptr, png_byte *row)
|
|||||||
png_write_start_row(png_ptr);
|
png_write_start_row(png_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||||
/* if interlaced and not interested in row, return */
|
/* if interlaced and not interested in row, return */
|
||||||
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
||||||
{
|
{
|
||||||
@ -286,6 +305,7 @@ png_write_row(png_struct *png_ptr, png_byte *row)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* set up row info for transformations */
|
/* set up row info for transformations */
|
||||||
png_ptr->row_info.color_type = png_ptr->color_type;
|
png_ptr->row_info.color_type = png_ptr->color_type;
|
||||||
@ -298,8 +318,9 @@ png_write_row(png_struct *png_ptr, png_byte *row)
|
|||||||
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
|
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
|
||||||
|
|
||||||
/* copy users row into buffer, leaving room for filter byte */
|
/* copy users row into buffer, leaving room for filter byte */
|
||||||
memcpy(png_ptr->row_buf + 1, row, (png_size_t)png_ptr->row_info.rowbytes);
|
png_memcpy(png_ptr->row_buf + 1, row, (png_size_t)png_ptr->row_info.rowbytes);
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||||
/* handle interlacing */
|
/* handle interlacing */
|
||||||
if (png_ptr->interlaced && png_ptr->pass < 6 &&
|
if (png_ptr->interlaced && png_ptr->pass < 6 &&
|
||||||
(png_ptr->transformations & PNG_INTERLACE))
|
(png_ptr->transformations & PNG_INTERLACE))
|
||||||
@ -313,16 +334,17 @@ png_write_row(png_struct *png_ptr, png_byte *row)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* handle other transformations */
|
/* handle other transformations */
|
||||||
if (png_ptr->transformations)
|
if (png_ptr->transformations)
|
||||||
png_do_write_transformations(png_ptr);
|
png_do_write_transformations(png_ptr);
|
||||||
|
|
||||||
/* filter rows that have been proved to help */
|
/* filter rows that have been proved to help */
|
||||||
if (png_ptr->bit_depth >= 8 && png_ptr->color_type != 3)
|
if (png_ptr->do_filter)
|
||||||
{
|
{
|
||||||
/* save row to previous row */
|
/* save row to previous row */
|
||||||
memcpy(png_ptr->save_row, png_ptr->row_buf,
|
png_memcpy(png_ptr->save_row, png_ptr->row_buf,
|
||||||
(png_size_t)png_ptr->row_info.rowbytes + 1);
|
(png_size_t)png_ptr->row_info.rowbytes + 1);
|
||||||
|
|
||||||
/* filter row */
|
/* filter row */
|
||||||
@ -331,7 +353,7 @@ png_write_row(png_struct *png_ptr, png_byte *row)
|
|||||||
|
|
||||||
/* trade saved pointer and prev pointer so next row references are correctly */
|
/* trade saved pointer and prev pointer so next row references are correctly */
|
||||||
{ /* scope limiter */
|
{ /* scope limiter */
|
||||||
png_byte *tptr;
|
png_bytef *tptr;
|
||||||
|
|
||||||
tptr = png_ptr->prev_row;
|
tptr = png_ptr->prev_row;
|
||||||
png_ptr->prev_row = png_ptr->save_row;
|
png_ptr->prev_row = png_ptr->save_row;
|
||||||
@ -345,17 +367,6 @@ png_write_row(png_struct *png_ptr, png_byte *row)
|
|||||||
/* set up the zlib input buffer */
|
/* set up the zlib input buffer */
|
||||||
png_ptr->zstream->next_in = png_ptr->row_buf;
|
png_ptr->zstream->next_in = png_ptr->row_buf;
|
||||||
png_ptr->zstream->avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
|
png_ptr->zstream->avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
|
||||||
|
|
||||||
#ifdef zlibinout
|
|
||||||
/* temp zlib problem */
|
|
||||||
{
|
|
||||||
extern FILE *fpzlibin;
|
|
||||||
|
|
||||||
fwrite(png_ptr->row_buf, 1, png_ptr->zstream->avail_in, fpzlibin);
|
|
||||||
}
|
|
||||||
/* end temp zlib problem */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* repeat until we have compressed all the data */
|
/* repeat until we have compressed all the data */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -401,8 +412,49 @@ png_write_destroy(png_struct *png_ptr)
|
|||||||
png_large_free(png_ptr, png_ptr->prev_row);
|
png_large_free(png_ptr, png_ptr->prev_row);
|
||||||
png_large_free(png_ptr, png_ptr->save_row);
|
png_large_free(png_ptr, png_ptr->save_row);
|
||||||
/* reset structure */
|
/* reset structure */
|
||||||
memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||||
memset(png_ptr, 0, sizeof (png_struct));
|
png_memset(png_ptr, 0, sizeof (png_struct));
|
||||||
memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||||
|
}
|
||||||
|
void
|
||||||
|
png_set_filtering(png_struct *png_ptr, int filter)
|
||||||
|
{
|
||||||
|
png_ptr->do_custom_filter = 1;
|
||||||
|
png_ptr->do_filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
png_set_compression_level(png_struct *png_ptr, int level)
|
||||||
|
{
|
||||||
|
png_ptr->zlib_custom_level = 1;
|
||||||
|
png_ptr->zlib_level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
png_set_compression_mem_level(png_struct *png_ptr, int mem_level)
|
||||||
|
{
|
||||||
|
png_ptr->zlib_custom_mem_level = 1;
|
||||||
|
png_ptr->zlib_mem_level = mem_level;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
png_set_compression_strategy(png_struct *png_ptr, int strategy)
|
||||||
|
{
|
||||||
|
png_ptr->zlib_custom_strategy = 1;
|
||||||
|
png_ptr->zlib_strategy = strategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
png_set_compression_window_bits(png_struct *png_ptr, int window_bits)
|
||||||
|
{
|
||||||
|
png_ptr->zlib_custom_window_bits = 1;
|
||||||
|
png_ptr->zlib_window_bits = window_bits;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
png_set_compression_method(png_struct *png_ptr, int method)
|
||||||
|
{
|
||||||
|
png_ptr->zlib_custom_method = 1;
|
||||||
|
png_ptr->zlib_method = method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
72
pngwtran.c
72
pngwtran.c
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
/* pngwtran.c - transforms the data in a row for png writers
|
/* pngwtran.c - transforms the data in a row for png writers
|
||||||
|
|
||||||
libpng 1.0 beta 1 - version 0.71
|
libpng 1.0 beta 2 - version 0.81
|
||||||
For conditions of distribution and use, see copyright notice in png.h
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
June 26, 1995
|
August 24, 1995
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PNG_INTERNAL
|
#define PNG_INTERNAL
|
||||||
@ -15,29 +15,41 @@
|
|||||||
void
|
void
|
||||||
png_do_write_transformations(png_struct *png_ptr)
|
png_do_write_transformations(png_struct *png_ptr)
|
||||||
{
|
{
|
||||||
|
#if defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||||
if (png_ptr->transformations & PNG_RGBA)
|
if (png_ptr->transformations & PNG_RGBA)
|
||||||
png_do_write_rgbx(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
png_do_write_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||||
if (png_ptr->transformations & PNG_XRGB)
|
png_ptr->filler_loc);
|
||||||
png_do_write_xrgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
#endif
|
||||||
|
#if defined(PNG_WRITE_PACK_SUPPORTED)
|
||||||
if (png_ptr->transformations & PNG_PACK)
|
if (png_ptr->transformations & PNG_PACK)
|
||||||
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||||
png_ptr->bit_depth);
|
png_ptr->bit_depth);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||||
if (png_ptr->transformations & PNG_SHIFT)
|
if (png_ptr->transformations & PNG_SHIFT)
|
||||||
png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||||
&(png_ptr->shift));
|
&(png_ptr->shift));
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||||
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_BGR_SUPPORTED)
|
||||||
if (png_ptr->transformations & PNG_BGR)
|
if (png_ptr->transformations & PNG_BGR)
|
||||||
png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||||
|
#endif
|
||||||
|
#if defined(PNG_WRITE_INVERT_SUPPORTED)
|
||||||
if (png_ptr->transformations & PNG_INVERT_MONO)
|
if (png_ptr->transformations & PNG_INVERT_MONO)
|
||||||
png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_PACK_SUPPORTED)
|
||||||
/* pack pixels into bytes. Pass the true bit depth in bit_depth. The
|
/* pack pixels into bytes. Pass the true bit depth in bit_depth. The
|
||||||
row_info bit depth should be 8 (one pixel per byte). The channels
|
row_info bit depth should be 8 (one pixel per byte). The channels
|
||||||
should be 1 (this only happens on grayscale and paletted images) */
|
should be 1 (this only happens on grayscale and paletted images) */
|
||||||
void
|
void
|
||||||
png_do_pack(png_row_info *row_info, png_byte *row, png_byte bit_depth)
|
png_do_pack(png_row_info *row_info, png_bytef *row, png_byte bit_depth)
|
||||||
{
|
{
|
||||||
if (row_info && row && row_info->bit_depth == 8 &&
|
if (row_info && row && row_info->bit_depth == 8 &&
|
||||||
row_info->channels == 1)
|
row_info->channels == 1)
|
||||||
@ -46,8 +58,8 @@ png_do_pack(png_row_info *row_info, png_byte *row, png_byte bit_depth)
|
|||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
png_byte *sp;
|
png_bytef *sp;
|
||||||
png_byte *dp;
|
png_bytef *dp;
|
||||||
int mask;
|
int mask;
|
||||||
png_int_32 i;
|
png_int_32 i;
|
||||||
int v;
|
int v;
|
||||||
@ -77,8 +89,8 @@ png_do_pack(png_row_info *row_info, png_byte *row, png_byte bit_depth)
|
|||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
png_byte *sp;
|
png_bytef *sp;
|
||||||
png_byte *dp;
|
png_bytef *dp;
|
||||||
int shift;
|
int shift;
|
||||||
png_int_32 i;
|
png_int_32 i;
|
||||||
int v;
|
int v;
|
||||||
@ -109,8 +121,8 @@ png_do_pack(png_row_info *row_info, png_byte *row, png_byte bit_depth)
|
|||||||
}
|
}
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
png_byte *sp;
|
png_bytef *sp;
|
||||||
png_byte *dp;
|
png_bytef *dp;
|
||||||
int shift;
|
int shift;
|
||||||
png_int_32 i;
|
png_int_32 i;
|
||||||
int v;
|
int v;
|
||||||
@ -148,7 +160,9 @@ png_do_pack(png_row_info *row_info, png_byte *row, png_byte bit_depth)
|
|||||||
((row_info->width * row_info->pixel_depth + 7) >> 3);
|
((row_info->width * row_info->pixel_depth + 7) >> 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||||
/* shift pixel values to take advantage of whole range. Pass the
|
/* shift pixel values to take advantage of whole range. Pass the
|
||||||
true number of bits in bit_depth. The row should be packed
|
true number of bits in bit_depth. The row should be packed
|
||||||
according to row_info->bit_depth. Thus, if you had a row of
|
according to row_info->bit_depth. Thus, if you had a row of
|
||||||
@ -156,7 +170,7 @@ png_do_pack(png_row_info *row_info, png_byte *row, png_byte bit_depth)
|
|||||||
would pass 3 as bit_depth, and this routine would translate the
|
would pass 3 as bit_depth, and this routine would translate the
|
||||||
data to 0 to 15. */
|
data to 0 to 15. */
|
||||||
void
|
void
|
||||||
png_do_shift(png_row_info *row_info, png_byte *row, png_color_8 *bit_depth)
|
png_do_shift(png_row_info *row_info, png_bytef *row, png_color_8 *bit_depth)
|
||||||
{
|
{
|
||||||
if (row && row_info &&
|
if (row && row_info &&
|
||||||
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
|
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||||
@ -193,7 +207,7 @@ png_do_shift(png_row_info *row_info, png_byte *row, png_color_8 *bit_depth)
|
|||||||
/* with low row dephts, could only be grayscale, so one channel */
|
/* with low row dephts, could only be grayscale, so one channel */
|
||||||
if (row_info->bit_depth < 8)
|
if (row_info->bit_depth < 8)
|
||||||
{
|
{
|
||||||
png_byte *bp;
|
png_bytef *bp;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
int j;
|
int j;
|
||||||
png_byte mask;
|
png_byte mask;
|
||||||
@ -222,7 +236,7 @@ png_do_shift(png_row_info *row_info, png_byte *row, png_color_8 *bit_depth)
|
|||||||
}
|
}
|
||||||
else if (row_info->bit_depth == 8)
|
else if (row_info->bit_depth == 8)
|
||||||
{
|
{
|
||||||
png_byte *bp;
|
png_bytef *bp;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
@ -248,7 +262,7 @@ png_do_shift(png_row_info *row_info, png_byte *row, png_color_8 *bit_depth)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
png_byte *bp;
|
png_bytef *bp;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
@ -278,15 +292,20 @@ png_do_shift(png_row_info *row_info, png_byte *row, png_color_8 *bit_depth)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* remove filler byte after rgb */
|
#ifdef PNG_WRITE_FILLER_SUPPORTED
|
||||||
|
/* remove filler byte */
|
||||||
void
|
void
|
||||||
png_do_write_rgbx(png_row_info *row_info, png_byte *row)
|
png_do_write_filler(png_row_info *row_info, png_bytef *row,
|
||||||
|
png_byte filler_loc)
|
||||||
{
|
{
|
||||||
if (row && row_info && row_info->color_type == PNG_COLOR_TYPE_RGB &&
|
if (row && row_info && row_info->color_type == PNG_COLOR_TYPE_RGB &&
|
||||||
row_info->bit_depth == 8)
|
row_info->bit_depth == 8)
|
||||||
{
|
{
|
||||||
png_byte *sp, *dp;
|
if (filler_loc == PNG_FILLER_AFTER)
|
||||||
|
{
|
||||||
|
png_bytef *sp, *dp;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
|
|
||||||
for (i = 1, sp = row + 4, dp = row + 3;
|
for (i = 1, sp = row + 4, dp = row + 3;
|
||||||
@ -302,19 +321,12 @@ png_do_write_rgbx(png_row_info *row_info, png_byte *row)
|
|||||||
row_info->pixel_depth = 24;
|
row_info->pixel_depth = 24;
|
||||||
row_info->rowbytes = row_info->width * 3;
|
row_info->rowbytes = row_info->width * 3;
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
|
||||||
/* remove filler byte before rgb */
|
|
||||||
void
|
|
||||||
png_do_write_xrgb(png_row_info *row_info, png_byte *row)
|
|
||||||
{
|
|
||||||
if (row && row_info && row_info->color_type == PNG_COLOR_TYPE_RGB &&
|
|
||||||
row_info->bit_depth == 8)
|
|
||||||
{
|
{
|
||||||
png_byte *sp, *dp;
|
png_bytef *sp, *dp;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
|
|
||||||
for (i = 0, sp = row, dp = row;
|
for (i = 1, sp = row + 4, dp = row + 3;
|
||||||
i < row_info->width;
|
i < row_info->width;
|
||||||
i++)
|
i++)
|
||||||
{
|
{
|
||||||
@ -327,5 +339,7 @@ png_do_write_xrgb(png_row_info *row_info, png_byte *row)
|
|||||||
row_info->pixel_depth = 24;
|
row_info->pixel_depth = 24;
|
||||||
row_info->rowbytes = row_info->width * 3;
|
row_info->rowbytes = row_info->width * 3;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
317
pngwutil.c
317
pngwutil.c
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
/* pngwutil.c - utilities to write a png file
|
/* pngwutil.c - utilities to write a png file
|
||||||
|
|
||||||
libpng 1.0 beta 1 - version 0.71
|
libpng 1.0 beta 2 - version 0.81
|
||||||
For conditions of distribution and use, see copyright notice in png.h
|
For conditions of distribution and use, see copyright notice in png.h
|
||||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||||
June 26, 1995
|
August 24, 1995
|
||||||
*/
|
*/
|
||||||
#define PNG_INTERNAL
|
#define PNG_INTERNAL
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
@ -63,7 +63,7 @@ png_write_uint_16(png_struct *png_ptr, png_uint_16 i)
|
|||||||
functions instead. */
|
functions instead. */
|
||||||
void
|
void
|
||||||
png_write_chunk(png_struct *png_ptr, png_byte *type,
|
png_write_chunk(png_struct *png_ptr, png_byte *type,
|
||||||
png_byte *data, png_uint_32 length)
|
png_bytef *data, png_uint_32 length)
|
||||||
{
|
{
|
||||||
/* write length */
|
/* write length */
|
||||||
png_write_uint_32(png_ptr, length);
|
png_write_uint_32(png_ptr, length);
|
||||||
@ -103,7 +103,7 @@ png_write_chunk_start(png_struct *png_ptr, png_byte *type,
|
|||||||
sum of the lengths from these calls *must* add up to the total_length
|
sum of the lengths from these calls *must* add up to the total_length
|
||||||
given to png_write_chunk_start() */
|
given to png_write_chunk_start() */
|
||||||
void
|
void
|
||||||
png_write_chunk_data(png_struct *png_ptr, png_byte *data, png_uint_32 length)
|
png_write_chunk_data(png_struct *png_ptr, png_bytef *data, png_uint_32 length)
|
||||||
{
|
{
|
||||||
/* write the data, and run the crc over it */
|
/* write the data, and run the crc over it */
|
||||||
if (length)
|
if (length)
|
||||||
@ -179,6 +179,42 @@ png_write_IHDR(png_struct *png_ptr, png_uint_32 width, png_uint_32 height,
|
|||||||
|
|
||||||
/* write the chunk */
|
/* write the chunk */
|
||||||
png_write_chunk(png_ptr, png_IHDR, buf, (png_uint_32)13);
|
png_write_chunk(png_ptr, png_IHDR, buf, (png_uint_32)13);
|
||||||
|
|
||||||
|
/* initialize zlib with png info */
|
||||||
|
png_ptr->zstream = &(png_ptr->zstream_struct);
|
||||||
|
png_ptr->zstream->zalloc = png_zalloc;
|
||||||
|
png_ptr->zstream->zfree = png_zfree;
|
||||||
|
png_ptr->zstream->opaque = (voidp)png_ptr;
|
||||||
|
if (!png_ptr->do_custom_filter)
|
||||||
|
{
|
||||||
|
if (png_ptr->color_type == 3 || png_ptr->bit_depth < 8)
|
||||||
|
png_ptr->do_filter = 0;
|
||||||
|
else
|
||||||
|
png_ptr->do_filter = 1;
|
||||||
|
}
|
||||||
|
if (!png_ptr->zlib_custom_strategy)
|
||||||
|
{
|
||||||
|
if (png_ptr->do_filter)
|
||||||
|
png_ptr->zlib_strategy = Z_FILTERED;
|
||||||
|
else
|
||||||
|
png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
|
||||||
|
}
|
||||||
|
if (!png_ptr->zlib_custom_level)
|
||||||
|
png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
|
||||||
|
if (!png_ptr->zlib_custom_mem_level)
|
||||||
|
png_ptr->zlib_mem_level = 8;
|
||||||
|
if (!png_ptr->zlib_custom_window_bits)
|
||||||
|
png_ptr->zlib_window_bits = 15;
|
||||||
|
if (!png_ptr->zlib_custom_method)
|
||||||
|
png_ptr->zlib_method = 8;
|
||||||
|
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);
|
||||||
|
png_ptr->zstream->next_out = png_ptr->zbuf;
|
||||||
|
png_ptr->zstream->avail_out = (uInt)png_ptr->zbuf_size;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write the palette. We are careful not to trust png_color to be in the
|
/* write the palette. We are careful not to trust png_color to be in the
|
||||||
@ -206,18 +242,8 @@ png_write_PLTE(png_struct *png_ptr, png_color *palette, int number)
|
|||||||
|
|
||||||
/* write an IDAT chunk */
|
/* write an IDAT chunk */
|
||||||
void
|
void
|
||||||
png_write_IDAT(png_struct *png_ptr, png_byte *data, png_uint_32 length)
|
png_write_IDAT(png_struct *png_ptr, png_bytef *data, png_uint_32 length)
|
||||||
{
|
{
|
||||||
#ifdef zlibinout
|
|
||||||
/* temp zlib problem */
|
|
||||||
{
|
|
||||||
extern FILE *fpzlibout;
|
|
||||||
|
|
||||||
fwrite(data, 1, length, fpzlibout);
|
|
||||||
}
|
|
||||||
/* end temp zlib problem */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
png_write_chunk(png_ptr, png_IDAT, data, length);
|
png_write_chunk(png_ptr, png_IDAT, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,6 +254,7 @@ png_write_IEND(png_struct *png_ptr)
|
|||||||
png_write_chunk(png_ptr, png_IEND, NULL, (png_uint_32)0);
|
png_write_chunk(png_ptr, png_IEND, NULL, (png_uint_32)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||||
/* write a gAMA chunk */
|
/* write a gAMA chunk */
|
||||||
void
|
void
|
||||||
png_write_gAMA(png_struct *png_ptr, float gamma)
|
png_write_gAMA(png_struct *png_ptr, float gamma)
|
||||||
@ -240,7 +267,9 @@ png_write_gAMA(png_struct *png_ptr, float gamma)
|
|||||||
png_save_uint_32(buf, igamma);
|
png_save_uint_32(buf, igamma);
|
||||||
png_write_chunk(png_ptr, png_gAMA, buf, (png_uint_32)4);
|
png_write_chunk(png_ptr, png_gAMA, buf, (png_uint_32)4);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||||
/* write the sBIT chunk */
|
/* write the sBIT chunk */
|
||||||
void
|
void
|
||||||
png_write_sBIT(png_struct *png_ptr, png_color_8 *sbit, int color_type)
|
png_write_sBIT(png_struct *png_ptr, png_color_8 *sbit, int color_type)
|
||||||
@ -269,7 +298,9 @@ png_write_sBIT(png_struct *png_ptr, png_color_8 *sbit, int color_type)
|
|||||||
|
|
||||||
png_write_chunk(png_ptr, png_sBIT, buf, (png_uint_32)size);
|
png_write_chunk(png_ptr, png_sBIT, buf, (png_uint_32)size);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||||
/* write the cHRM chunk */
|
/* write the cHRM chunk */
|
||||||
void
|
void
|
||||||
png_write_cHRM(png_struct *png_ptr, float white_x, float white_y,
|
png_write_cHRM(png_struct *png_ptr, float white_x, float white_y,
|
||||||
@ -298,7 +329,9 @@ png_write_cHRM(png_struct *png_ptr, float white_x, float white_y,
|
|||||||
png_save_uint_32(buf + 28, itemp);
|
png_save_uint_32(buf + 28, itemp);
|
||||||
png_write_chunk(png_ptr, png_cHRM, buf, (png_uint_32)32);
|
png_write_chunk(png_ptr, png_cHRM, buf, (png_uint_32)32);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||||
/* write the tRNS chunk */
|
/* write the tRNS chunk */
|
||||||
void
|
void
|
||||||
png_write_tRNS(png_struct *png_ptr, png_byte *trans, png_color_16 *tran,
|
png_write_tRNS(png_struct *png_ptr, png_byte *trans, png_color_16 *tran,
|
||||||
@ -326,7 +359,9 @@ png_write_tRNS(png_struct *png_ptr, png_byte *trans, png_color_16 *tran,
|
|||||||
png_write_chunk(png_ptr, png_tRNS, buf, (png_uint_32)6);
|
png_write_chunk(png_ptr, png_tRNS, buf, (png_uint_32)6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_bKGD_SUPPORTED)
|
||||||
/* write the background chunk */
|
/* write the background chunk */
|
||||||
void
|
void
|
||||||
png_write_bKGD(png_struct *png_ptr, png_color_16 *back, int color_type)
|
png_write_bKGD(png_struct *png_ptr, png_color_16 *back, int color_type)
|
||||||
@ -351,7 +386,9 @@ png_write_bKGD(png_struct *png_ptr, png_color_16 *back, int color_type)
|
|||||||
png_write_chunk(png_ptr, png_bKGD, buf, (png_uint_32)2);
|
png_write_chunk(png_ptr, png_bKGD, buf, (png_uint_32)2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_hIST_SUPPORTED)
|
||||||
/* write the histogram */
|
/* write the histogram */
|
||||||
void
|
void
|
||||||
png_write_hIST(png_struct *png_ptr, png_uint_16 *hist, int number)
|
png_write_hIST(png_struct *png_ptr, png_uint_16 *hist, int number)
|
||||||
@ -367,38 +404,42 @@ png_write_hIST(png_struct *png_ptr, png_uint_16 *hist, int number)
|
|||||||
}
|
}
|
||||||
png_write_chunk_end(png_ptr);
|
png_write_chunk_end(png_ptr);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_tEXt_SUPPORTED)
|
||||||
/* write a tEXt chunk */
|
/* write a tEXt chunk */
|
||||||
void
|
void
|
||||||
png_write_tEXt(png_struct *png_ptr, char *key, char *text,
|
png_write_tEXt(png_struct *png_ptr, charf *key, charf *text,
|
||||||
png_uint_32 text_len)
|
png_uint_32 text_len)
|
||||||
{
|
{
|
||||||
int key_len;
|
int key_len;
|
||||||
|
|
||||||
key_len = strlen(key);
|
key_len = png_strlen(key);
|
||||||
/* make sure we count the 0 after the key */
|
/* make sure we count the 0 after the key */
|
||||||
png_write_chunk_start(png_ptr, png_tEXt,
|
png_write_chunk_start(png_ptr, png_tEXt,
|
||||||
(png_uint_32)(key_len + text_len + 1));
|
(png_uint_32)(key_len + text_len + 1));
|
||||||
/* key has an 0 at the end. How nice */
|
/* key has an 0 at the end. How nice */
|
||||||
png_write_chunk_data(png_ptr, (png_byte *)key, (png_uint_32)(key_len + 1));
|
png_write_chunk_data(png_ptr, (png_bytef *)key, (png_uint_32)(key_len + 1));
|
||||||
if (text && text_len)
|
if (text && text_len)
|
||||||
png_write_chunk_data(png_ptr, (png_byte *)text, (png_uint_32)text_len);
|
png_write_chunk_data(png_ptr, (png_bytef *)text, (png_uint_32)text_len);
|
||||||
png_write_chunk_end(png_ptr);
|
png_write_chunk_end(png_ptr);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||||
/* write a compressed chunk */
|
/* write a compressed chunk */
|
||||||
void
|
void
|
||||||
png_write_zTXt(png_struct *png_ptr, char *key, char *text,
|
png_write_zTXt(png_struct *png_ptr, charf *key, charf *text,
|
||||||
png_uint_32 text_len, int compression)
|
png_uint_32 text_len, int compression)
|
||||||
{
|
{
|
||||||
int key_len;
|
int key_len;
|
||||||
char buf[1];
|
char buf[1];
|
||||||
int i, ret;
|
int i, ret;
|
||||||
char **output_ptr = NULL; /* array of pointers to output */
|
charf **output_ptr = NULL; /* array of pointers to output */
|
||||||
int num_output_ptr = 0; /* number of output pointers used */
|
int num_output_ptr = 0; /* number of output pointers used */
|
||||||
int max_output_ptr = 0; /* size of output_ptr */
|
int max_output_ptr = 0; /* size of output_ptr */
|
||||||
|
|
||||||
key_len = strlen(key);
|
key_len = png_strlen(key);
|
||||||
|
|
||||||
/* we can't write the chunk until we find out how much data we have,
|
/* we can't write the chunk until we find out how much data we have,
|
||||||
which means we need to run the compresser first, and save the
|
which means we need to run the compresser first, and save the
|
||||||
@ -408,9 +449,9 @@ png_write_zTXt(png_struct *png_ptr, char *key, char *text,
|
|||||||
|
|
||||||
/* set up the compression buffers */
|
/* set up the compression buffers */
|
||||||
png_ptr->zstream->avail_in = (uInt)text_len;
|
png_ptr->zstream->avail_in = (uInt)text_len;
|
||||||
png_ptr->zstream->next_in = (Byte *)text;
|
png_ptr->zstream->next_in = (Bytef *)text;
|
||||||
png_ptr->zstream->avail_out = (uInt)png_ptr->zbuf_size;
|
png_ptr->zstream->avail_out = (uInt)png_ptr->zbuf_size;
|
||||||
png_ptr->zstream->next_out = (Byte *)png_ptr->zbuf;
|
png_ptr->zstream->next_out = (Bytef *)png_ptr->zbuf;
|
||||||
|
|
||||||
/* this is the same compression loop as in png_write_row() */
|
/* this is the same compression loop as in png_write_row() */
|
||||||
do
|
do
|
||||||
@ -431,10 +472,14 @@ png_write_zTXt(png_struct *png_ptr, char *key, char *text,
|
|||||||
/* make sure the output array has room */
|
/* make sure the output array has room */
|
||||||
if (num_output_ptr >= max_output_ptr)
|
if (num_output_ptr >= max_output_ptr)
|
||||||
{
|
{
|
||||||
|
png_uint_32 old_max;
|
||||||
|
|
||||||
|
old_max = max_output_ptr;
|
||||||
max_output_ptr = num_output_ptr + 4;
|
max_output_ptr = num_output_ptr + 4;
|
||||||
if (output_ptr)
|
if (output_ptr)
|
||||||
output_ptr = png_realloc(png_ptr, output_ptr,
|
output_ptr = png_realloc(png_ptr, output_ptr,
|
||||||
max_output_ptr * sizeof (char *));
|
max_output_ptr * sizeof (char *),
|
||||||
|
old_max * sizeof (char *));
|
||||||
else
|
else
|
||||||
output_ptr = png_malloc(png_ptr,
|
output_ptr = png_malloc(png_ptr,
|
||||||
max_output_ptr * sizeof (char *));
|
max_output_ptr * sizeof (char *));
|
||||||
@ -443,7 +488,7 @@ png_write_zTXt(png_struct *png_ptr, char *key, char *text,
|
|||||||
/* save the data */
|
/* save the data */
|
||||||
output_ptr[num_output_ptr] = png_large_malloc(png_ptr,
|
output_ptr[num_output_ptr] = png_large_malloc(png_ptr,
|
||||||
png_ptr->zbuf_size);
|
png_ptr->zbuf_size);
|
||||||
memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
|
png_memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
|
||||||
(png_size_t)png_ptr->zbuf_size);
|
(png_size_t)png_ptr->zbuf_size);
|
||||||
num_output_ptr++;
|
num_output_ptr++;
|
||||||
|
|
||||||
@ -474,10 +519,14 @@ png_write_zTXt(png_struct *png_ptr, char *key, char *text,
|
|||||||
/* check to make sure our output array has room */
|
/* check to make sure our output array has room */
|
||||||
if (num_output_ptr >= max_output_ptr)
|
if (num_output_ptr >= max_output_ptr)
|
||||||
{
|
{
|
||||||
|
png_uint_32 old_max;
|
||||||
|
|
||||||
|
old_max = max_output_ptr;
|
||||||
max_output_ptr = num_output_ptr + 4;
|
max_output_ptr = num_output_ptr + 4;
|
||||||
if (output_ptr)
|
if (output_ptr)
|
||||||
output_ptr = png_realloc(png_ptr, output_ptr,
|
output_ptr = png_realloc(png_ptr, output_ptr,
|
||||||
max_output_ptr * sizeof (char *));
|
max_output_ptr * sizeof (char *),
|
||||||
|
old_max * sizeof (char *));
|
||||||
else
|
else
|
||||||
output_ptr = png_malloc(png_ptr,
|
output_ptr = png_malloc(png_ptr,
|
||||||
max_output_ptr * sizeof (char *));
|
max_output_ptr * sizeof (char *));
|
||||||
@ -486,7 +535,7 @@ png_write_zTXt(png_struct *png_ptr, char *key, char *text,
|
|||||||
/* save off the data */
|
/* save off the data */
|
||||||
output_ptr[num_output_ptr] = png_large_malloc(png_ptr,
|
output_ptr[num_output_ptr] = png_large_malloc(png_ptr,
|
||||||
png_ptr->zbuf_size);
|
png_ptr->zbuf_size);
|
||||||
memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
|
png_memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
|
||||||
(png_size_t)png_ptr->zbuf_size);
|
(png_size_t)png_ptr->zbuf_size);
|
||||||
num_output_ptr++;
|
num_output_ptr++;
|
||||||
|
|
||||||
@ -506,7 +555,7 @@ png_write_zTXt(png_struct *png_ptr, char *key, char *text,
|
|||||||
png_write_chunk_start(png_ptr, png_zTXt,
|
png_write_chunk_start(png_ptr, png_zTXt,
|
||||||
(png_uint_32)(key_len + text_len + 2));
|
(png_uint_32)(key_len + text_len + 2));
|
||||||
/* write key */
|
/* write key */
|
||||||
png_write_chunk_data(png_ptr, (png_byte *)key, (png_uint_32)(key_len + 1));
|
png_write_chunk_data(png_ptr, (png_bytef *)key, (png_uint_32)(key_len + 1));
|
||||||
buf[0] = compression;
|
buf[0] = compression;
|
||||||
/* write compression */
|
/* write compression */
|
||||||
png_write_chunk_data(png_ptr, (png_byte *)buf, (png_uint_32)1);
|
png_write_chunk_data(png_ptr, (png_byte *)buf, (png_uint_32)1);
|
||||||
@ -514,7 +563,7 @@ png_write_zTXt(png_struct *png_ptr, char *key, char *text,
|
|||||||
/* write saved output buffers, if any */
|
/* write saved output buffers, if any */
|
||||||
for (i = 0; i < num_output_ptr; i++)
|
for (i = 0; i < num_output_ptr; i++)
|
||||||
{
|
{
|
||||||
png_write_chunk_data(png_ptr, (png_byte *)output_ptr[i], png_ptr->zbuf_size);
|
png_write_chunk_data(png_ptr, (png_bytef *)output_ptr[i], png_ptr->zbuf_size);
|
||||||
png_large_free(png_ptr, output_ptr[i]);
|
png_large_free(png_ptr, output_ptr[i]);
|
||||||
}
|
}
|
||||||
if (max_output_ptr)
|
if (max_output_ptr)
|
||||||
@ -527,11 +576,11 @@ png_write_zTXt(png_struct *png_ptr, char *key, char *text,
|
|||||||
png_write_chunk_end(png_ptr);
|
png_write_chunk_end(png_ptr);
|
||||||
|
|
||||||
/* reset zlib for another zTXt or the image data */
|
/* reset zlib for another zTXt or the image data */
|
||||||
/* deflateReset(png_ptr->zstream); */
|
deflateReset(png_ptr->zstream);
|
||||||
deflateEnd(png_ptr->zstream);
|
|
||||||
deflateInit(png_ptr->zstream, -1);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||||
/* write the pHYs chunk */
|
/* write the pHYs chunk */
|
||||||
void
|
void
|
||||||
png_write_pHYs(png_struct *png_ptr, png_uint_32 x_pixels_per_unit,
|
png_write_pHYs(png_struct *png_ptr, png_uint_32 x_pixels_per_unit,
|
||||||
@ -546,7 +595,9 @@ png_write_pHYs(png_struct *png_ptr, png_uint_32 x_pixels_per_unit,
|
|||||||
|
|
||||||
png_write_chunk(png_ptr, png_pHYs, buf, (png_uint_32)9);
|
png_write_chunk(png_ptr, png_pHYs, buf, (png_uint_32)9);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||||
/* write the oFFs chunk */
|
/* write the oFFs chunk */
|
||||||
void
|
void
|
||||||
png_write_oFFs(png_struct *png_ptr, png_uint_32 x_offset,
|
png_write_oFFs(png_struct *png_ptr, png_uint_32 x_offset,
|
||||||
@ -561,9 +612,11 @@ png_write_oFFs(png_struct *png_ptr, png_uint_32 x_offset,
|
|||||||
|
|
||||||
png_write_chunk(png_ptr, png_oFFs, buf, (png_uint_32)9);
|
png_write_chunk(png_ptr, png_oFFs, buf, (png_uint_32)9);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* two time chunks are given. This chunk assumes you have a gmtime()
|
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||||
function. If you don't have that, use the other tIME function */
|
/* write the tIME chunk. Use either png_convert_from_struct_tm()
|
||||||
|
or png_convert_from_time_t(), or fill in the structure yourself */
|
||||||
void
|
void
|
||||||
png_write_tIME(png_struct *png_ptr, png_time *mod_time)
|
png_write_tIME(png_struct *png_ptr, png_time *mod_time)
|
||||||
{
|
{
|
||||||
@ -578,25 +631,26 @@ png_write_tIME(png_struct *png_ptr, png_time *mod_time)
|
|||||||
|
|
||||||
png_write_chunk(png_ptr, png_tIME, buf, (png_uint_32)7);
|
png_write_chunk(png_ptr, png_tIME, buf, (png_uint_32)7);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* initializes the row writing capability of libpng */
|
/* initializes the row writing capability of libpng */
|
||||||
void
|
void
|
||||||
png_write_start_row(png_struct *png_ptr)
|
png_write_start_row(png_struct *png_ptr)
|
||||||
{
|
{
|
||||||
/* set up row buffer */
|
/* set up row buffer */
|
||||||
png_ptr->row_buf = (png_byte *)png_large_malloc(png_ptr,
|
png_ptr->row_buf = (png_bytef *)png_large_malloc(png_ptr,
|
||||||
(((png_uint_32)png_ptr->usr_channels *
|
(((png_uint_32)png_ptr->usr_channels *
|
||||||
(png_uint_32)png_ptr->usr_bit_depth *
|
(png_uint_32)png_ptr->usr_bit_depth *
|
||||||
png_ptr->width) >> 3) + 1);
|
png_ptr->width) >> 3) + 1);
|
||||||
/* set up filtering buffers, if filtering */
|
/* set up filtering buffers, if filtering */
|
||||||
if (png_ptr->bit_depth >= 8 && png_ptr->color_type != 3)
|
if (png_ptr->do_filter)
|
||||||
{
|
{
|
||||||
png_ptr->prev_row = (png_byte *)png_large_malloc(png_ptr,
|
png_ptr->prev_row = (png_bytef *)png_large_malloc(png_ptr,
|
||||||
png_ptr->rowbytes + 1);
|
png_ptr->rowbytes + 1);
|
||||||
memset(png_ptr->prev_row, 0, (png_size_t)png_ptr->rowbytes + 1);
|
png_memset(png_ptr->prev_row, 0, (png_size_t)png_ptr->rowbytes + 1);
|
||||||
png_ptr->save_row = (png_byte *)png_large_malloc(png_ptr,
|
png_ptr->save_row = (png_bytef *)png_large_malloc(png_ptr,
|
||||||
png_ptr->rowbytes + 1);
|
png_ptr->rowbytes + 1);
|
||||||
memset(png_ptr->save_row, 0, (png_size_t)png_ptr->rowbytes + 1);
|
png_memset(png_ptr->save_row, 0, (png_size_t)png_ptr->rowbytes + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if interlaced, we need to set up width and height of pass */
|
/* if interlaced, we need to set up width and height of pass */
|
||||||
@ -662,13 +716,15 @@ png_write_finish_row(png_struct *png_ptr)
|
|||||||
png_pass_yinc[png_ptr->pass] - 1 -
|
png_pass_yinc[png_ptr->pass] - 1 -
|
||||||
png_pass_ystart[png_ptr->pass]) /
|
png_pass_ystart[png_ptr->pass]) /
|
||||||
png_pass_yinc[png_ptr->pass];
|
png_pass_yinc[png_ptr->pass];
|
||||||
|
if (png_ptr->transformations & PNG_INTERLACE)
|
||||||
|
break;
|
||||||
} while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
|
} while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reset filter row */
|
/* reset filter row */
|
||||||
if (png_ptr->prev_row)
|
if (png_ptr->prev_row)
|
||||||
memset(png_ptr->prev_row, 0, (png_size_t)png_ptr->rowbytes + 1);
|
png_memset(png_ptr->prev_row, 0, (png_size_t)png_ptr->rowbytes + 1);
|
||||||
/* if we have more data to get, go get it */
|
/* if we have more data to get, go get it */
|
||||||
if (png_ptr->pass < 7)
|
if (png_ptr->pass < 7)
|
||||||
return;
|
return;
|
||||||
@ -704,12 +760,10 @@ png_write_finish_row(png_struct *png_ptr)
|
|||||||
png_ptr->zstream->avail_out);
|
png_ptr->zstream->avail_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* deflateReset(png_ptr->zstream); */
|
deflateReset(png_ptr->zstream);
|
||||||
deflateEnd(png_ptr->zstream);
|
|
||||||
deflateInit(png_ptr->zstream, -1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||||
/* pick out the correct pixels for the interlace pass.
|
/* pick out the correct pixels for the interlace pass.
|
||||||
|
|
||||||
The basic idea here is to go through the row with a source
|
The basic idea here is to go through the row with a source
|
||||||
@ -719,7 +773,7 @@ png_write_finish_row(png_struct *png_ptr)
|
|||||||
See the default: case for the easiest code to understand.
|
See the default: case for the easiest code to understand.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
png_do_write_interlace(png_row_info *row_info, png_byte *row, int pass)
|
png_do_write_interlace(png_row_info *row_info, png_bytef *row, int pass)
|
||||||
{
|
{
|
||||||
/* we don't have to do anything on the last pass (6) */
|
/* we don't have to do anything on the last pass (6) */
|
||||||
if (row && row_info && pass < 6)
|
if (row && row_info && pass < 6)
|
||||||
@ -729,8 +783,8 @@ png_do_write_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
png_byte *sp;
|
png_bytef *sp;
|
||||||
png_byte *dp;
|
png_bytef *dp;
|
||||||
int shift;
|
int shift;
|
||||||
int d;
|
int d;
|
||||||
int value;
|
int value;
|
||||||
@ -763,8 +817,8 @@ png_do_write_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
png_byte *sp;
|
png_bytef *sp;
|
||||||
png_byte *dp;
|
png_bytef *dp;
|
||||||
int shift;
|
int shift;
|
||||||
int d;
|
int d;
|
||||||
int value;
|
int value;
|
||||||
@ -796,8 +850,8 @@ png_do_write_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
}
|
}
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
png_byte *sp;
|
png_bytef *sp;
|
||||||
png_byte *dp;
|
png_bytef *dp;
|
||||||
int shift;
|
int shift;
|
||||||
int d;
|
int d;
|
||||||
int value;
|
int value;
|
||||||
@ -829,8 +883,8 @@ png_do_write_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
png_byte *sp;
|
png_bytef *sp;
|
||||||
png_byte *dp;
|
png_bytef *dp;
|
||||||
png_uint_32 i;
|
png_uint_32 i;
|
||||||
int pixel_bytes;
|
int pixel_bytes;
|
||||||
|
|
||||||
@ -848,7 +902,7 @@ png_do_write_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
sp = row + (png_size_t)(i * pixel_bytes);
|
sp = row + (png_size_t)(i * pixel_bytes);
|
||||||
/* move the pixel */
|
/* move the pixel */
|
||||||
if (dp != sp)
|
if (dp != sp)
|
||||||
memcpy(dp, sp, pixel_bytes);
|
png_memcpy(dp, sp, pixel_bytes);
|
||||||
/* next pixel */
|
/* next pixel */
|
||||||
dp += pixel_bytes;
|
dp += pixel_bytes;
|
||||||
}
|
}
|
||||||
@ -865,17 +919,18 @@ png_do_write_interlace(png_row_info *row_info, png_byte *row, int pass)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* this filters the row. Both row and prev_row have space at the
|
/* this filters the row. Both row and prev_row have space at the
|
||||||
first byte for the filter byte. */
|
first byte for the filter byte. */
|
||||||
void
|
void
|
||||||
png_write_filter_row(png_row_info *row_info, png_byte *row,
|
png_write_filter_row(png_row_info *row_info, png_bytef *row,
|
||||||
png_byte *prev_row)
|
png_bytef *prev_row)
|
||||||
{
|
{
|
||||||
int minf, bpp;
|
int minf, bpp;
|
||||||
png_uint_32 i, v;
|
png_uint_32 i, v;
|
||||||
png_uint_32 s, mins;
|
png_uint_32 s0, s1, s2, s3, s4, mins;
|
||||||
png_byte *rp, *pp, *cp, *lp;
|
png_bytef *rp, *pp, *cp, *lp;
|
||||||
|
|
||||||
/* find out how many bytes offset each pixel is */
|
/* find out how many bytes offset each pixel is */
|
||||||
bpp = (row_info->pixel_depth + 7) / 8;
|
bpp = (row_info->pixel_depth + 7) / 8;
|
||||||
@ -885,95 +940,79 @@ png_write_filter_row(png_row_info *row_info, png_byte *row,
|
|||||||
/* the prediction method we use is to find which method provides
|
/* the prediction method we use is to find which method provides
|
||||||
the smallest value when summing the abs of the distances from
|
the smallest value when summing the abs of the distances from
|
||||||
zero using anything >= 128 as negitive numbers. */
|
zero using anything >= 128 as negitive numbers. */
|
||||||
for (i = 0, s = 0, rp = row + 1; i < row_info->rowbytes; i++, rp++)
|
s0 = s1 = s2 = s3 = s4 = 0;
|
||||||
|
|
||||||
|
for (i = 0, rp = row + 1, pp = prev_row + 1, lp = row + 1 - bpp,
|
||||||
|
cp = prev_row + 1 - bpp;
|
||||||
|
i < bpp; i++, rp++, pp++, lp++, cp++)
|
||||||
{
|
{
|
||||||
|
/* check none filter */
|
||||||
v = *rp;
|
v = *rp;
|
||||||
if (v < 128)
|
if (v < 128)
|
||||||
s += v;
|
s0 += v;
|
||||||
else
|
else
|
||||||
s += 256 - (png_int_32)v;
|
s0 += 256 - v;
|
||||||
}
|
|
||||||
|
|
||||||
mins = s;
|
|
||||||
minf = 0;
|
|
||||||
|
|
||||||
/* check sub filter */
|
|
||||||
for (i = 0, s = 0, rp = row + 1, lp = row + 1 - bpp;
|
|
||||||
i < row_info->rowbytes; i++, rp++, lp++)
|
|
||||||
{
|
|
||||||
if (i >= bpp)
|
|
||||||
v = (png_byte)(((int)*rp - (int)*lp) & 0xff);
|
|
||||||
else
|
|
||||||
v = *rp;
|
|
||||||
|
|
||||||
if (v < 128)
|
|
||||||
s += v;
|
|
||||||
else
|
|
||||||
s += 256 - v;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s < mins)
|
|
||||||
{
|
|
||||||
mins = s;
|
|
||||||
minf = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check up filter */
|
/* check up filter */
|
||||||
for (i = 0, s = 0, rp = row + 1, pp = prev_row + 1;
|
|
||||||
i < row_info->rowbytes; i++, rp++, pp++)
|
|
||||||
{
|
|
||||||
v = (png_byte)(((int)*rp - (int)*pp) & 0xff);
|
v = (png_byte)(((int)*rp - (int)*pp) & 0xff);
|
||||||
|
|
||||||
if (v < 128)
|
if (v < 128)
|
||||||
s += v;
|
s2 += v;
|
||||||
else
|
else
|
||||||
s += 256 - v;
|
s2 += 256 - v;
|
||||||
}
|
|
||||||
|
|
||||||
if (s < mins)
|
|
||||||
{
|
|
||||||
mins = s;
|
|
||||||
minf = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check avg filter */
|
/* check avg filter */
|
||||||
for (i = 0, s = 0, rp = row + 1, pp = prev_row + 1, lp = row + 1 - bpp;
|
|
||||||
i < row_info->rowbytes; i++, rp++, pp++, lp++)
|
|
||||||
{
|
|
||||||
if (i >= bpp)
|
|
||||||
v = (png_byte)(((int)*rp - (((int)*pp + (int)*lp) / 2)) & 0xff);
|
|
||||||
else
|
|
||||||
v = (png_byte)(((int)*rp - ((int)*pp / 2)) & 0xff);
|
v = (png_byte)(((int)*rp - ((int)*pp / 2)) & 0xff);
|
||||||
|
|
||||||
if (v < 128)
|
if (v < 128)
|
||||||
s += v;
|
s3 += v;
|
||||||
else
|
else
|
||||||
s += 256 - v;
|
s3 += 256 - v;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s < mins)
|
/* some filters are same until we get past bpp */
|
||||||
{
|
s1 = s0;
|
||||||
mins = s;
|
s4 = s2;
|
||||||
minf = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check paeth filter */
|
for (; i < row_info->rowbytes; i++, rp++, pp++, lp++, cp++)
|
||||||
for (i = 0, s = 0, rp = row + 1, pp = prev_row + 1, lp = row + 1 - bpp,
|
|
||||||
cp = prev_row + 1 - bpp;
|
|
||||||
i < row_info->rowbytes; i++, rp++, pp++, lp++, cp++)
|
|
||||||
{
|
{
|
||||||
int a, b, c, pa, pb, pc, p;
|
int a, b, c, pa, pb, pc, p;
|
||||||
|
|
||||||
|
/* check none filter */
|
||||||
|
v = *rp;
|
||||||
|
if (v < 128)
|
||||||
|
s0 += v;
|
||||||
|
else
|
||||||
|
s0 += 256 - v;
|
||||||
|
|
||||||
|
/* check sub filter */
|
||||||
|
v = (png_byte)(((int)*rp - (int)*lp) & 0xff);
|
||||||
|
|
||||||
|
if (v < 128)
|
||||||
|
s1 += v;
|
||||||
|
else
|
||||||
|
s1 += 256 - v;
|
||||||
|
|
||||||
|
/* check up filter */
|
||||||
|
v = (png_byte)(((int)*rp - (int)*pp) & 0xff);
|
||||||
|
|
||||||
|
if (v < 128)
|
||||||
|
s2 += v;
|
||||||
|
else
|
||||||
|
s2 += 256 - v;
|
||||||
|
|
||||||
|
/* check avg filter */
|
||||||
|
v = (png_byte)(((int)*rp - (((int)*pp + (int)*lp) / 2)) & 0xff);
|
||||||
|
|
||||||
|
if (v < 128)
|
||||||
|
s3 += v;
|
||||||
|
else
|
||||||
|
s3 += 256 - v;
|
||||||
|
|
||||||
|
/* check paeth filter */
|
||||||
b = *pp;
|
b = *pp;
|
||||||
if (i >= bpp)
|
|
||||||
{
|
|
||||||
c = *cp;
|
c = *cp;
|
||||||
a = *lp;
|
a = *lp;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
a = c = 0;
|
|
||||||
}
|
|
||||||
p = a + b - c;
|
p = a + b - c;
|
||||||
pa = abs(p - a);
|
pa = abs(p - a);
|
||||||
pb = abs(p - b);
|
pb = abs(p - b);
|
||||||
@ -989,14 +1028,35 @@ png_write_filter_row(png_row_info *row_info, png_byte *row,
|
|||||||
v = (png_byte)(((int)*rp - p) & 0xff);
|
v = (png_byte)(((int)*rp - p) & 0xff);
|
||||||
|
|
||||||
if (v < 128)
|
if (v < 128)
|
||||||
s += v;
|
s4 += v;
|
||||||
else
|
else
|
||||||
s += 256 - v;
|
s4 += 256 - v;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s < mins)
|
mins = s0;
|
||||||
|
minf = 0;
|
||||||
|
|
||||||
|
if (s1 < mins)
|
||||||
{
|
{
|
||||||
mins = s;
|
mins = s1;
|
||||||
|
minf = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s2 < mins)
|
||||||
|
{
|
||||||
|
mins = s2;
|
||||||
|
minf = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s3 < mins)
|
||||||
|
{
|
||||||
|
mins = s3;
|
||||||
|
minf = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s4 < mins)
|
||||||
|
{
|
||||||
|
mins = s4;
|
||||||
minf = 4;
|
minf = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1078,3 +1138,4 @@ png_write_filter_row(png_row_info *row_info, png_byte *row,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
57
readme.txt
57
readme.txt
@ -1,25 +1,40 @@
|
|||||||
readme.txt - for libpng 0.71
|
readme.txt - for libpng 0.8
|
||||||
|
|
||||||
This is the first beta version of libpng 1.0. By beta, I mean that
|
This is the second beta version of libpng 1.0. I've updated most
|
||||||
all the code for 1.0 is there, and it works on all the machines
|
of the stuff I want to before the final 1.0 version. Remaining
|
||||||
I have running all the tests I have devised. However, there is
|
to do are the medium memory model support (which I'll put in
|
||||||
always one more bug (at least), and I don't have many #define's in
|
as soon as we test this version), better dithering, and any bug
|
||||||
the code (yet) for various platforms that I do not have. Also, I'd
|
fixes and makefile/include additions. I expect a third (and
|
||||||
like to see if I can get the code to compile with as few warnings
|
perhaps final) beta after zlib is officially 1.0.
|
||||||
as possible. Finally, as people use my code, they may have
|
|
||||||
suggestions for additions that will make pnglib easier to port.
|
I've tried to incorporate all the changes and makefiles everyone
|
||||||
|
sent me. However, I may of lost some in the flood. If you sent
|
||||||
|
me a change and I didn't put it in, send it again. Sorry.
|
||||||
|
|
||||||
|
Updates from libpng 0.71 include a new transformation,
|
||||||
|
png_set_filler(), which replaces png_set_rgbx() and
|
||||||
|
png_set_xrgb(). The old functions will be supported for
|
||||||
|
awhile, but I'd suggest changing to the new function. Also,
|
||||||
|
I've added defines in png.h to remove unwanted code from the
|
||||||
|
compiled library. I've added a new field to png_realloc(), and
|
||||||
|
fixed various bugs. I've also split up pngstub.c into pngmem.c,
|
||||||
|
pngio.c, and pngerror.c, in case you need to just change some of
|
||||||
|
these. I've pulled pngconf.h out of png.h, so you don't have to
|
||||||
|
remake your changes every new release. I've added a function to
|
||||||
|
update the png_info structure after you're done setting up your
|
||||||
|
transformations (png_read_update_info()). The complete list of
|
||||||
|
changes is in pngchang.txt. Most of you won't be much affected
|
||||||
|
by any of this. Some of you will want to use the new features.
|
||||||
|
|
||||||
For a detailed description on using libpng, read libpng.txt. For
|
For a detailed description on using libpng, read libpng.txt. For
|
||||||
usage information and restrictions (what little they are) on libpng,
|
usage information and restrictions (what little they are) on libpng,
|
||||||
see png.h. For a description on using zlib (the compression library
|
see png.h. For a description on using zlib (the compression library
|
||||||
used by libpng) and zlib's restrictions, see zlib.h
|
used by libpng) and zlib's restrictions, see zlib.h
|
||||||
|
|
||||||
I have included a make file, but you will probably have to modify it
|
I have included a general makefile, but you may have to modify it
|
||||||
for your own needs. I'm using Borland C++, running large memory
|
for your own needs.
|
||||||
model on Windows 3.11, but it should work on almost anything. Support
|
|
||||||
for medium memory model is planned, but is not in 1.0 (probably in 1.1).
|
|
||||||
|
|
||||||
You will need zlib 0.93 to run this. zlib is a compression
|
You will need zlib 0.95 or later to run this. zlib is a compression
|
||||||
library that is useful for more things then just png files. If
|
library that is useful for more things then just png files. If
|
||||||
you need a compression library, check out zlib.h
|
you need a compression library, check out zlib.h
|
||||||
|
|
||||||
@ -32,10 +47,10 @@ be available at the same place you picked up libpng. If it is
|
|||||||
not there, try ftp.uu.net in the /graphics/png directory.
|
not there, try ftp.uu.net in the /graphics/png directory.
|
||||||
|
|
||||||
This code is currently being archived at ftp.uu.net in the
|
This code is currently being archived at ftp.uu.net in the
|
||||||
/graphics/png directory, and at ftp.group42.com in the /pub/png
|
/graphics/png directory, and at ftp.group42.com (204.94.158.25)
|
||||||
directory, and on CompuServe, Lib 20 (PNG) at GO GRAPHSUP.
|
in the /pub/png directory, and on CompuServe, Lib 20 (PNG SUPPORT)
|
||||||
If you can't find it in any of those places, e-mail me, and I'll
|
at GO GRAPHSUP. If you can't find it in any of those places,
|
||||||
tell you where it is.
|
e-mail me, and I'll help you find it.
|
||||||
|
|
||||||
If you have any code changes, requests, problems, etc., please e-mail
|
If you have any code changes, requests, problems, etc., please e-mail
|
||||||
them to me. Also, I'd appreciate any make files or project files,
|
them to me. Also, I'd appreciate any make files or project files,
|
||||||
@ -50,7 +65,7 @@ fix. Please mention "libpng" somewhere in the subject line. Thanks.
|
|||||||
|
|
||||||
You can reach me at:
|
You can reach me at:
|
||||||
|
|
||||||
internet: schalnat&group42.com
|
internet: schalnat@group42.com
|
||||||
CompuServe: 75501,1625
|
CompuServe: 75501,1625
|
||||||
|
|
||||||
Please do not send me general questions about PNG. Send them to
|
Please do not send me general questions about PNG. Send them to
|
||||||
@ -63,7 +78,7 @@ and ...". If in doubt, send questions to me. I'll bounce them
|
|||||||
to others, if necessary.
|
to others, if necessary.
|
||||||
|
|
||||||
Please do not send suggestions on how to change PNG. We have
|
Please do not send suggestions on how to change PNG. We have
|
||||||
been discussing PNG for 6 months now, and it is official and
|
been discussing PNG for 9 months now, and it is official and
|
||||||
finished. If you have suggestions for libpng, however, I'll
|
finished. If you have suggestions for libpng, however, I'll
|
||||||
gladly listen. Even if your suggestion is not used for version
|
gladly listen. Even if your suggestion is not used for version
|
||||||
1.0, it may be used later.
|
1.0, it may be used later.
|
||||||
@ -75,5 +90,5 @@ Good luck, and happy coding.
|
|||||||
Internet: schalnat@group42.com
|
Internet: schalnat@group42.com
|
||||||
CompuServe: 75501,1625
|
CompuServe: 75501,1625
|
||||||
Web: www.group42.com
|
Web: www.group42.com
|
||||||
FTP: ftp.group42.com
|
FTP: ftp.group42.com (204.94.158.25)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user