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.
|
||||
This is not officially part of libpng, and therefore
|
||||
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>
|
||||
@ -81,15 +85,11 @@ void read_png(char *file_name)
|
||||
/* read the file information */
|
||||
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
|
||||
all optional. Only call them if you want them */
|
||||
|
||||
/* expand paletted colors into true rgb */
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
|
||||
info_ptr->bit_depth < 8)
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_expand(png_ptr);
|
||||
|
||||
/* expand grayscale images to the full 8 bits */
|
||||
@ -163,26 +163,32 @@ void read_png(char *file_name)
|
||||
if (info_ptr->bit_depth == 16)
|
||||
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 &&
|
||||
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 */
|
||||
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 */
|
||||
/* turn on interlace handling if you are not using png_read_image() */
|
||||
if (info_ptr->interlace_type)
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
else
|
||||
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++)
|
||||
{
|
||||
/* 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 */
|
||||
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);
|
||||
}
|
||||
|
||||
@ -309,21 +315,22 @@ void write_png(char *file_name, ... other image information ...)
|
||||
/* swap bytes of 16 bit files to most significant bit first */
|
||||
png_set_swap(png_ptr);
|
||||
|
||||
/* get rid of filler bytes, pack rgb into 3 bytes */
|
||||
png_set_rgbx(png_ptr);
|
||||
/* get rid of filler bytes, pack rgb into 3 bytes. The
|
||||
filler number is not used. */
|
||||
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||
|
||||
/* the easiest way to write the 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 */
|
||||
/* turn on interlace handling if you are not using png_write_image() */
|
||||
if (interlacing)
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
else
|
||||
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++)
|
||||
{
|
||||
/* 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 */
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
82
libpng.txt
82
libpng.txt
@ -1,9 +1,9 @@
|
||||
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
|
||||
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
|
||||
(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 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 &&
|
||||
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 &&
|
||||
info_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
||||
png_set_xrgb(png_ptr);
|
||||
Finally, if you need the interlacing as discussed below, call
|
||||
this here:
|
||||
|
||||
if (info_ptr->interlace_type)
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
|
||||
After setting the transformations, you can update your palette by
|
||||
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);
|
||||
|
||||
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
|
||||
allocating enough memory to hold the whole image, you can just
|
||||
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
|
||||
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)
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
@ -521,6 +540,25 @@ Customizing Libpng section below.
|
||||
|
||||
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 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
|
||||
@ -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.
|
||||
|
||||
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,
|
||||
call this:
|
||||
supply the pixels as 4 bytes per pixel, call this:
|
||||
|
||||
png_set_rgbx(png_ptr);
|
||||
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||
|
||||
If your filler byte goes first, call this:
|
||||
|
||||
png_set_xrgb(png_ptr);
|
||||
where the 0 is not used for writing, and the location is either
|
||||
PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether you
|
||||
want the filler before the rgb or after.
|
||||
|
||||
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.
|
||||
@ -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
|
||||
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.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-I../zlib -O3
|
||||
LDFLAGS=-L. -L../zlib/ -lpng -lgz -lm
|
||||
CC=cc
|
||||
CFLAGS=-I../zlib -O
|
||||
LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
|
||||
|
||||
RANLIB=ranlib
|
||||
#RANLIB=echo
|
||||
#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
|
||||
pngread.o pngio.o pngwrite.o pngrtran.o pngwtran.o \
|
||||
pngmem.o pngerror.o
|
||||
|
||||
all: libpng.a pngtest
|
||||
|
||||
@ -22,13 +23,18 @@ libpng.a: $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
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
|
||||
-@mkdir $(prefix)/include
|
||||
-@mkdir $(prefix)/lib
|
||||
cp png.h $(prefix)/include
|
||||
cp pngconf.h $(prefix)/include
|
||||
chmod 644 $(prefix)/include/png.h
|
||||
chmod 644 $(prefix)/include/pngconf.h
|
||||
cp libpng.a $(prefix)/lib
|
||||
chmod 644 $(prefix)/lib/libpng.a
|
||||
|
||||
@ -37,13 +43,16 @@ clean:
|
||||
|
||||
# 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
|
||||
png.o: png.h pngconf.h
|
||||
pngerror.o: png.h pngconf.h
|
||||
pngio.o: png.h pngconf.h
|
||||
pngmem.o: png.h pngconf.h
|
||||
pngrcb.o: png.h pngconf.h
|
||||
pngread.o: png.h pngconf.h
|
||||
pngrtran.o: png.h pngconf.h
|
||||
pngrutil.o: png.h pngconf.h
|
||||
pngtest.o: png.h pngconf.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
|
||||
|
||||
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
|
||||
Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
June 26, 1995
|
||||
August 24, 1995
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_EXTERN
|
||||
#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. */
|
||||
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_IEND[4] = { 73, 69, 78, 68};
|
||||
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};
|
||||
#endif
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||
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};
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
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};
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
|
||||
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};
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
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};
|
||||
#endif
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
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};
|
||||
#endif
|
||||
|
||||
/* 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. */
|
||||
voidp
|
||||
png_zalloc(voidp png_ptr, uInt items, uInt size)
|
||||
voidpf
|
||||
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));
|
||||
}
|
||||
|
||||
/* function to free memory for zlib */
|
||||
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
|
||||
@ -135,10 +161,10 @@ make_crc_table(void)
|
||||
initialized to all 1's, and the transmitted value is the 1's complement
|
||||
of the final running crc. */
|
||||
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_byte *p;
|
||||
png_bytef *p;
|
||||
png_uint_32 n;
|
||||
|
||||
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
|
||||
need this, put huge here and above. */
|
||||
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_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
|
||||
changed pngtest.png for zlib 0.93
|
||||
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);
|
||||
}
|
||||
|