Compare commits

...

6 Commits

Author SHA1 Message Date
Glenn Randers-Pehrson
66e6b07dfd Imported from pngcrush-1.3.6.tar 2009-04-16 10:46:41 -05:00
Glenn Randers-Pehrson
601daa7a76 Imported from pngcrush-1.3.5.tar 2009-04-16 10:46:40 -05:00
Glenn Randers-Pehrson
f142567725 Imported from pngcrush-1.3.4.tar 2009-04-16 10:46:40 -05:00
Glenn Randers-Pehrson
10ecaa7a20 Imported from pngcrush-1.3.3.tar 2009-04-16 10:46:39 -05:00
Glenn Randers-Pehrson
c3e8db9e59 Imported from pngcrush-1.3.2.tar 2009-04-16 10:46:38 -05:00
Glenn Randers-Pehrson
e7cba14aff Imported from pngcrush-1.3.1.tar 2009-04-16 10:46:38 -05:00
30 changed files with 2146 additions and 955 deletions

View File

@@ -1,16 +1,16 @@
There's a sample makefile.gcc for pngcrush, which you can use
There's a sample Makefile.gcc for pngcrush, which you can use
by typing
make -f makefile.gcc
make -f Makefile.gcc
However, all you should need to do is enter the pngcrush-1.3.0
However, all you should need to do is enter the pngcrush-n.n.n
directory and type
cc -O -o pngcrush *.c -lm
cp pngcrush /usr/local/bin # or wherever you want
You might want to create a makefile if you are planning to do
You might want to create your own Makefile if you are planning to do
something more complicated, like loading with your system's shared
libraries for libpng and zlib.

57
Makefile.msc Normal file
View File

@@ -0,0 +1,57 @@
# Sample makefile for pngcrush using Microsoft (Visual) C compiler.
# Author: Cosmin Truta
# Derived from Makefile.gcc by Glenn Randers-Pehrson
# Last modified: 14 January 2000
#
# Invoke this makefile from a console prompt in the usual way; for example:
#
# nmake -f Makefile.msc
#
# This makefile builds a statically linked executable.
# macros --------------------------------------------------------------------
CC = cl -nologo
LD = link -nologo
RM = del
CFLAGS = -DPNG_ZBUF_SIZE=0x080000 -DWIN32 -O2
LDFLAGS =
O = .obj
E = .exe
PNGCRUSH = pngcrush
LIBS =
OBJS = $(PNGCRUSH)$(O) adler32$(O) crc32$(O) deflate$(O) gzio$(O) \
infblock$(O) infcodes$(O) inffast$(O) inflate$(O) inftrees$(O) \
infutil$(O) png$(O) pngerror$(O) pngget$(O) pngmem$(O) \
pngpread$(O) pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) \
pngset$(O) pngtrans$(O) pngvcrd$(O) pngwio$(O) pngwrite$(O) \
pngwtran$(O) pngwutil$(O) trees$(O) zutil$(O)
EXES = $(PNGCRUSH)$(E)
# implicit make rules -------------------------------------------------------
.c$(O):
$(CC) -c $(CFLAGS) $<
# dependencies --------------------------------------------------------------
all: $(EXES)
$(PNGCRUSH)$(E): $(OBJS)
$(LD) $(LDFLAGS) -out:$@ $(OBJS) $(LIBS)
$(PNGCRUSH)$(O): $(PNGCRUSH).c png.h pngconf.h zlib.h pngcrush.h
# maintenance ---------------------------------------------------------------
clean:
$(RM) *$(O)
$(RM) $(PNGCRUSH)$(E)

View File

@@ -1,11 +1,43 @@
Pngcrush documentation
| pngcrush 1.3.0, Copyright (C) 1998, 1999, Glenn Randers-Pehrson
This is the copyright notice, disclaimer, and license:
/*
* COPYRIGHT NOTICE, DISCLAIMER, AND LICENSE:
*
* Copyright (c) 1998, 1999, Glenn Randers-Pehrson
*
* The pngcrush program is supplied "AS IS". The Author disclaims all
* warranties, expressed or implied, including, without limitation, the
* warranties of merchantability and of fitness for any purpose. The
* Author assumes no liability for direct, indirect, incidental, special,
* exemplary, or consequential damages, which may result from the use of
* the pngcrush program, even if advised of the possibility of such damage.
*
* Permission is hereby granted to use, copy, modify, and distribute this
* source code, or portions hereof, for any purpose, without fee, subject
* to the following restrictions:
*
* 1. The origin of this source code must not be misrepresented.
*
* 2. Altered versions must be plainly marked as such and must not be
* misrepresented as being the original source.
*
* 3. This Copyright notice, disclaimer, and license may not be removed
* or altered from any source or altered source distribution.
*/
This is the output of "pngcrush" and "pngcrush -help":
| pngcrush 1.3.5, Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson
| This is a free, open-source program. Permission is
| granted to everyone to use pngcrush without fee.
| This program was built with libpng version 1.0.5j,
| This program was built with libpng version 1.1.0a,
| Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc.,
| Copyright (C) 1996, 1997 Andreas Dilger,
| Copyright (C) 1998, 1999, Glenn Randers-Pehrson,
| Copyright (C) 1998, 1999, 2000 Glenn Randers-Pehrson,
| and zlib version 1.1.3, Copyright (c) 1998,
| Jean-loup Gailly and Mark Adler.
@@ -14,14 +46,15 @@ usage: pngcrush [options] infile.png outfile.png
pngcrush -e ext [other options] files.png ...
pngcrush -d dir [other options] files.png ...
options:
-brute (Use brute-force, try 114 different methods)
-brute (Use brute-force, try 114 different methods [11-124])
-c color_type of output file [0, 2, 4, or 6]
-d directory_name (where output files will go)
-double_gamma (used for fixing gamma in PhotoShop 5.0/5.02 files)
-e extension (used for creating output filename)
-f user_filter [0-5]
-force (Write a new output file even if larger than input)
-g gamma_value (float, e.g., 0.45455)
-g gamma (float or fixed*100000, e.g., 0.45455 or 45455)
-itxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
-l zlib_compression_level [0-9]
-m method [0 through 200]
-max maximum_IDAT_size [1 through 524288]
@@ -34,28 +67,19 @@ options:
-srgb [0, 1, 2, or 3]
-text b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
-trns index red green blue gray
-verbose (write more detailed information)
-v (display more detailed information)
-version (display the pngcrush version)
-w compression_window_size [32, 16, 8, 4, 2, 1, 512]
-h (help)
-p (pause)
| pngcrush 1.3.0, Copyright (C) 1998, 1999, Glenn Randers-Pehrson
| This is a free, open-source program. Permission is
| granted to everyone to use pngcrush without fee.
| This program was built with libpng version 1.0.5j,
| Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc.,
| Copyright (C) 1996, 1997 Andreas Dilger,
| Copyright (C) 1998, 1999, Glenn Randers-Pehrson,
| and zlib version 1.1.3, Copyright (c) 1998,
| Jean-loup Gailly and Mark Adler.
usage: pngcrush [options] infile.png outfile.png
pngcrush -e ext [other options] files.png ...
pngcrush -d dir [other options] files.png ...
options:
-brute (Use brute-force, try 114 different methods)
-brute (Use brute-force, try 114 different methods [11-124])
Very time-consuming and generally not worthwhile.
You can restrict this option to certain filter types,
@@ -102,12 +126,16 @@ options:
if it is smaller than any generated file and no chunk
additions, removals, or changes were requested.
-g gamma_value (float, e.g., 0.45455)
-g gamma (float or fixed*100000, e.g., 0.45455 or 45455)
Value to insert in gAMA chunk, only if the input
file has no gAMA chunk. To replace an existing
gAMA chunk, use the '-replace_gamma' option.
-itxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
Compressed iTXt chunk to insert (see -text).
-l zlib_compression_level [0-9]
zlib compression level to use with method specified
@@ -169,7 +197,7 @@ options:
tEXt chunk to insert. keyword < 80 chars,
text < 2048 chars. For now, you can only add ten
tEXt or zTXt chunks per pngcrush run.
tEXt, iTXt, or zTXt chunks per pngcrush run.
-trns index red green blue gray
@@ -177,10 +205,12 @@ options:
You must give all five parameters regardless of the
color type, scaled to the output bit depth.
-verbose (write more detailed information)
-v (display more detailed information)
Repeat the option (use "-v -v") for even more.
-version (display the pngcrush version)
-w compression_window_size [32, 16, 8, 4, 2, 1, 512]
Size of the sliding compression window, in kbytes
@@ -194,6 +224,14 @@ options:
zlib compression strategy to use with the preceding
'-m method' argument.
-zitxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
Compressed iTXt chunk to insert (see -text).
-ztxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
zTXt chunk to insert (see -text).
-h (help)
Display this information.

View File

@@ -101,7 +101,7 @@ local void check_match OF((deflate_state *s, IPos start, IPos match,
/* Tail of hash chains */
#ifndef TOO_FAR
# define TOO_FAR 4096
# define TOO_FAR 32767
#endif
/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
@@ -1279,9 +1279,12 @@ local block_state deflate_slow(s, flush)
}
/* longest_match() sets match_start */
if (s->match_length <= 5 && (s->strategy == Z_FILTERED ||
(s->match_length == MIN_MATCH &&
s->strstart - s->match_start > TOO_FAR))) {
if (s->match_length <= 5 && (s->strategy == Z_FILTERED
#if (TOO_FAR > 0 && TOO_FAR < 32767)
|| (s->match_length == MIN_MATCH &&
s->strstart - s->match_start > TOO_FAR)
#endif
)) {
/* If prev_match is also MIN_MATCH, match_start is garbage
* but we will ignore the current match anyway.

35
name_to_int.c Normal file
View File

@@ -0,0 +1,35 @@
#include <stdio.h>
convert(char * name)
{
unsigned long number;
number=name[3]+name[2]*256+name[1]*256*256+name[0]*256*256*256;
printf(" #define PNG_%s 0x%xL\n",name, number);
}
main()
{
convert("AAAA");
convert("IDAT");
convert("IEND");
convert("IHDR");
convert("PLTE");
convert("bKGD");
convert("cHRM");
convert("gAMA");
convert("hIST");
convert("iCCP");
convert("iTXt");
convert("oFFs");
convert("pCAL");
convert("pHYs");
convert("sBIT");
convert("sCAL");
convert("sPLT");
convert("sRGB");
convert("tEXt");
convert("tIME");
convert("tRNS");
convert("zTXt");
convert("zzzz");
}

215
png.c
View File

@@ -1,10 +1,10 @@
/* png.c - location for general purpose libpng functions
*
* libpng version 1.0.5j - December 21, 1999
* libpng version 1.0.5v - March 11, 2000
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
*/
@@ -13,13 +13,15 @@
#include <assert.h>
#include "png.h"
/* Generate a compiler error if there is an old png.h in the search path. */
typedef version_1_0_5v Your_png_h_is_not_version_1_0_5v;
/* Version information for C files. This had better match the version
* string defined in png.h.
*/
* string defined in png.h. */
#ifdef PNG_USE_GLOBAL_ARRAYS
/* png_libpng_ver was changed to a function in version 1.0.5c */
char png_libpng_ver[12] = "1.0.5j";
char png_libpng_ver[12] = "1.0.5v";
/* png_sig was changed to a function in version 1.0.5c */
/* Place to hold the signature string for a PNG file. */
@@ -62,10 +64,10 @@ int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
/* offset to next interlace block in the y direction */
int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
/* Width of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
/* width of interlace block (used in assembler routines only) */
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
*/
#endif
/* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
@@ -259,13 +261,16 @@ png_info_init(png_infop info_ptr)
png_memset(info_ptr, 0, sizeof (png_info));
}
#if defined(PNG_TEXT_SUPPORTED)
/* free text item num or (if num == -1) all text items */
void
png_free_text(png_structp png_ptr, png_infop info_ptr, int num)
png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, int num)
{
if (png_ptr == NULL || info_ptr == NULL)
return;
#if defined(PNG_TEXT_SUPPORTED)
/* free text item num or (if num == -1) all text items */
if (mask & PNG_FREE_TEXT)
{
if (num != -1)
{
if (info_ptr->text[num].key)
@@ -277,33 +282,37 @@ png_free_text(png_structp png_ptr, png_infop info_ptr, int num)
else if (info_ptr->text != NULL)
{
int i;
if(info_ptr->text != NULL)
{
for (i = 0; i < info_ptr->num_text; i++)
png_free_text(png_ptr, info_ptr, i);
png_free(png_ptr, info_ptr->text);
info_ptr->text = NULL;
}
for (i = 0; i < info_ptr->num_text; i++)
png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
png_free(png_ptr, info_ptr->text);
info_ptr->text = NULL;
info_ptr->num_text=0;
}
}
#endif
#if defined(PNG_tRNS_SUPPORTED)
/* free any tRNS entry */
if (mask & PNG_FREE_TRNS)
{
if (info_ptr->valid & PNG_INFO_tRNS)
{
if (info_ptr->free_me & PNG_FREE_TRNS)
png_free(png_ptr, info_ptr->trans);
info_ptr->valid &= ~PNG_INFO_tRNS;
}
}
#endif
#if defined(PNG_sCAL_SUPPORTED)
/* free any sCAL entry */
void
png_free_sCAL(png_structp png_ptr, png_infop info_ptr)
if (mask & PNG_FREE_SCAL)
{
if (png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->valid & PNG_INFO_sCAL)
{
#if defined(PNG_FIXED_POINT_SUPPORTED)&& !defined(PNG_FLOATING_POINT_SUPPORTED)
#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
png_free(png_ptr, info_ptr->scal_s_width);
png_free(png_ptr, info_ptr->scal_s_height);
#else
if(png_ptr != NULL)
/* silence a compiler warning */ ;
#endif
info_ptr->valid &= ~PNG_INFO_sCAL;
}
@@ -312,11 +321,8 @@ png_free_sCAL(png_structp png_ptr, png_infop info_ptr)
#if defined(PNG_pCAL_SUPPORTED)
/* free any pCAL entry */
void
png_free_pCAL(png_structp png_ptr, png_infop info_ptr)
if (mask & PNG_FREE_PCAL)
{
if (png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->valid & PNG_INFO_pCAL)
{
png_free(png_ptr, info_ptr->pcal_purpose);
@@ -337,15 +343,15 @@ png_free_pCAL(png_structp png_ptr, png_infop info_ptr)
#if defined(PNG_iCCP_SUPPORTED)
/* free any iCCP entry */
void
png_free_iCCP(png_structp png_ptr, png_infop info_ptr)
if (mask & PNG_FREE_ICCP)
{
if (png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->valid & PNG_INFO_iCCP)
{
png_free(png_ptr, info_ptr->iccp_name);
png_free(png_ptr, info_ptr->iccp_profile);
if (info_ptr->free_me & PNG_FREE_ICCP)
{
png_free(png_ptr, info_ptr->iccp_name);
png_free(png_ptr, info_ptr->iccp_profile);
}
info_ptr->valid &= ~PNG_INFO_iCCP;
}
}
@@ -353,39 +359,32 @@ png_free_iCCP(png_structp png_ptr, png_infop info_ptr)
#if defined(PNG_sPLT_SUPPORTED)
/* free a given sPLT entry, or (if num == -1) all sPLT entries */
void
png_free_spalettes(png_structp png_ptr, png_infop info_ptr, int num)
if (mask & PNG_FREE_SPLT)
{
if (png_ptr == NULL || info_ptr == NULL)
return;
if (num != -1)
{
png_free(png_ptr, info_ptr->splt_palettes[num].name);
png_free(png_ptr, info_ptr->splt_palettes[num].entries);
info_ptr->valid &=~ PNG_INFO_sPLT;
info_ptr->valid &= ~PNG_INFO_sPLT;
}
else
{
int i;
if(info_ptr->splt_palettes_num)
{
int i;
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
if(info_ptr->splt_palettes_num == 0)
return;
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
png_free_spalettes(png_ptr, info_ptr, i);
png_free(png_ptr, info_ptr->splt_palettes);
info_ptr->splt_palettes_num = 0;
png_free(png_ptr, info_ptr->splt_palettes);
info_ptr->splt_palettes_num = 0;
}
}
}
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
void
png_free_unknown_chunks(png_structp png_ptr, png_infop info_ptr, int num)
if (mask & PNG_FREE_UNKN)
{
if (png_ptr == NULL || info_ptr == NULL)
return;
if (num != -1)
{
png_free(png_ptr, info_ptr->unknown_chunks[num].data);
@@ -395,33 +394,61 @@ png_free_unknown_chunks(png_structp png_ptr, png_infop info_ptr, int num)
{
int i;
if(info_ptr->unknown_chunks_num == 0)
return;
if(info_ptr->unknown_chunks_num)
{
for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
png_free_unknown_chunks(png_ptr, info_ptr, i);
png_free(png_ptr, info_ptr->unknown_chunks);
info_ptr->unknown_chunks_num = 0;
png_free(png_ptr, info_ptr->unknown_chunks);
info_ptr->unknown_chunks_num = 0;
}
}
}
#endif
#if defined(PNG_hIST_SUPPORTED)
/* free any hIST entry */
void
png_free_hIST(png_structp png_ptr, png_infop info_ptr)
if (mask & PNG_FREE_HIST)
{
if (png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->valid & PNG_INFO_hIST)
{
png_free(png_ptr, info_ptr->hist);
if (info_ptr->free_me & PNG_FREE_HIST)
png_free(png_ptr, info_ptr->hist);
info_ptr->valid &= ~PNG_INFO_hIST;
}
}
#endif
/* free any PLTE entry that was internally allocated */
if (mask & PNG_FREE_PLTE)
{
if (info_ptr->valid & PNG_INFO_PLTE)
{
if (info_ptr->free_me & PNG_FREE_PLTE)
png_zfree(png_ptr, info_ptr->palette);
info_ptr->valid &= ~(PNG_INFO_PLTE);
info_ptr->num_palette = 0;
}
}
#if defined(PNG_INFO_IMAGE_SUPPORTED)
/* free any image bits attached to the info structure */
if (mask & PNG_FREE_ROWS)
{
if (info_ptr->free_me & PNG_FREE_ROWS)
{
int row;
for (row = 0; row < (int)info_ptr->height; row++)
png_free(png_ptr, info_ptr->row_pointers[row]);
png_free(png_ptr, info_ptr->row_pointers);
}
}
#endif
if(num == -1)
info_ptr->free_me &= ~mask;
}
/* This is an internal routine to free any memory that the info struct is
* pointing to before re-using it or freeing the struct itself. Recall
* that png_free() checks for NULL pointers for us.
@@ -430,27 +457,17 @@ void
png_info_destroy(png_structp png_ptr, png_infop info_ptr)
{
png_debug(1, "in png_info_destroy\n");
#if defined(PNG_READ_TEXT_SUPPORTED)
png_free_text(png_ptr, info_ptr, -1);
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
png_free_sCAL(png_ptr, info_ptr);
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
png_free_pCAL(png_ptr, info_ptr);
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
png_free_iCCP(png_ptr, info_ptr);
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
png_free_spalettes(png_ptr, info_ptr, -1);
#endif
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
png_free_unknown_chunks(png_ptr, info_ptr, -1);
#endif
#if defined(PNG_hIST_SUPPORTED)
png_free_hIST(png_ptr, info_ptr);
if (png_ptr->num_chunk_list)
{
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->num_chunk_list=0;
}
#endif
png_info_init(info_ptr);
}
@@ -528,10 +545,10 @@ png_charp
png_get_copyright(png_structp png_ptr)
{
if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
return ("\n libpng version 1.0.5j - December 21, 1999\n\
return ("\n libpng version 1.0.5v - March 11, 2000\n\
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\
Copyright (c) 1996, 1997 Andreas Dilger\n\
Copyright (c) 1998, 1999 Glenn Randers-Pehrson\n");
Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson\n");
return ("");
}
@@ -546,8 +563,8 @@ png_get_libpng_ver(png_structp png_ptr)
{
/* Version of *.c files used when building libpng */
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
return("1.0.5j");
return("1.0.5j");
return("1.0.5v");
return("1.0.5v");
}
png_charp
@@ -568,11 +585,19 @@ png_get_header_version(png_structp png_ptr)
return(PNG_HEADER_VERSION_STRING);
}
/* Generate a compiler error if there is an old png.h in the search path. */
void
png_check_version
(version_1_0_5j png_h_is_not_version_1_0_5j)
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
int
png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
{
if(png_h_is_not_version_1_0_5j == NULL)
return;
/* check chunk_name and return "keep" value if it's on the list, else 0 */
int i;
png_bytep p;
if((png_ptr == NULL && chunk_name == NULL) || png_ptr->num_chunk_list<=0)
return 0;
p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
for (i = png_ptr->num_chunk_list; i; i--, p-=5)
if (!png_memcmp(chunk_name, p, 4))
return ((int)*(p+4));
return 0;
}
#endif

364
png.h
View File

@@ -1,27 +1,27 @@
/* png.h - header file for PNG reference library
*
* libpng version 1.0.5j - December 21, 1999
* libpng version 1.0.5v - March 11, 2000
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
* Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.89c, May 1996: Guy Schalnat
* libpng versions 0.90, December 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.0.5j - December 21, 1999: Glenn
* libpng versions 0.97, January 1998, through 1.0.5v - March 11, 2000: Glenn
* See also "Contributing Authors", below.
*
* Y2K compliance in libpng:
* =========================
*
* December 21, 1999
* March 11, 2000
*
* Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration.
*
* This is your unofficial assurance that libpng from version 0.71 and
* upward through 1.0.5j are Y2K compliant. It is my belief that earlier
* upward through 1.0.5v are Y2K compliant. It is my belief that earlier
* versions were also Y2K compliant.
*
* Libpng only has three year fields. One is a 2-byte unsigned integer
@@ -98,8 +98,10 @@
* 1.0.4a-f 1.0.4a-f 10005 2.1.0.4a-f
* 1.0.5 1.0.5 10005 2.1.0.5
* 1.0.5a-d 1.0.5a-d 10006 2.1.0.5a-d
* 1.0.5e-j 1.0.5e-j 10100 2.1.0.5e-j
* 1.1.0 1.1.0 10100 3.1.0.0
* 1.0.5e-r 1.0.5e-r 10100 2.1.0.5e-r (not compatible)
* 1.0.5s-v 1.0.5s-v 10006 2.1.0.5s-v (compatible)
* 1.0.6 1.0.6 10006 2.1.0.6
* 1.3.0 1.3.0 10300 3.1.3.0
*
* Henceforth the source version will match the shared-library minor
* and patch numbers; the shared-library major version number will be
@@ -122,8 +124,8 @@
* (libpng versions 0.5, May 1995, through 0.89c, May 1996)
* Copyright (c) 1996, 1997 Andreas Dilger
* (libpng versions 0.90, December 1996, through 0.96, May 1997)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* (libpng versions 0.97, January 1998, through 1.0.5j, December 21, 1999)
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (libpng versions 0.97, January 1998, through 1.0.5v, March 11, 2000)
*
* For the purposes of this copyright and license, "Contributing Authors"
* is defined as the following set of individuals:
@@ -156,16 +158,13 @@
* source code, or portions hereof, for any purpose, without fee, subject
* to the following restrictions:
*
* 1. The origin of this source code must not be
* misrepresented.
* 1. The origin of this source code must not be misrepresented.
*
* 2. Altered versions must be plainly marked as such
* and must not be misrepresented as being the
* original source.
* 2. Altered versions must be plainly marked as such and must not
* be misrepresented as being the original source.
*
* 3. This Copyright notice may not be removed or
* altered from any source or altered source
* distribution.
* 3. This Copyright notice may not be removed or altered from any
* source or altered source distribution.
*
* The Contributing Authors and Group 42, Inc. specifically permit, without
* fee, and encourage the use of this source code as a component to
@@ -212,6 +211,11 @@
/* include all user configurable info */
#include "pngconf.h"
/* macros for optional assembler routines */
#if defined(PNG_INTERNAL) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
# include "pngasmrd.h"
#endif
/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
#ifdef __cplusplus
extern "C" {
@@ -224,14 +228,14 @@ extern "C" {
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.0.5j"
#define PNG_LIBPNG_VER_STRING "1.0.5v"
/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
* We must not include leading zeros.
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
* version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=bugfix */
#define PNG_LIBPNG_VER 10100 /* 1.1.0 */
#define PNG_LIBPNG_VER 10006 /* 1.0.6 */
/* Note to maintainer: update this number in scripts/pngdef.pas as well */
@@ -255,9 +259,11 @@ PNG_EXPORT_VAR (int FARDATA) png_pass_ystart[7];
PNG_EXPORT_VAR (int FARDATA) png_pass_yinc[7];
PNG_EXPORT_VAR (int FARDATA) png_pass_mask[7];
PNG_EXPORT_VAR (int FARDATA) png_pass_dsp_mask[7];
/* These aren't currently used. If you need them, see png.c for more details
PNG_EXPORT_VAR (int FARDATA) png_pass_width[7];
PNG_EXPORT_VAR (int FARDATA) png_pass_height[7];
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
extern int FARDATA png_pass_width[7]; /* now used in pngvcrd.c, pnggccrd.c */
#endif
/* This isn't currently used. If you need it, see png.c for more details.
extern int FARDATA png_pass_height[7];
*/
#endif
@@ -302,26 +308,26 @@ typedef png_color_8 FAR * FAR * png_color_8pp;
* The following two structures are used for the in-core representation
* of sPLT chunks.
*/
typedef struct png_spalette_entry_struct
typedef struct png_sPLT_entry_struct
{
png_uint_16 red;
png_uint_16 green;
png_uint_16 blue;
png_uint_16 alpha;
png_uint_16 frequency;
} png_spalette_entry;
typedef png_spalette_entry FAR * png_spalette_entryp;
typedef png_spalette_entry FAR * FAR * png_spalette_entrypp;
} png_sPLT_entry;
typedef png_sPLT_entry FAR * png_sPLT_entryp;
typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
typedef struct png_spalette_struct
typedef struct png_sPLT_struct
{
png_charp name; /* palette name */
png_byte depth; /* depth of palette samples */
png_spalette_entryp entries; /* palette entries */
png_sPLT_entryp entries; /* palette entries */
png_int_32 nentries; /* number of palette entries */
} png_spalette;
typedef png_spalette FAR * png_spalette_p;
typedef png_spalette FAR * FAR * png_spalette_pp;
} png_sPLT_t;
typedef png_sPLT_t FAR * png_sPLT_tp;
typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
#ifdef PNG_TEXT_SUPPORTED
/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file,
@@ -416,11 +422,10 @@ typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
* that use the old direct-access method with png_info_struct.
*
* The following members may have allocated storage attached that should be
* cleaned up before the structure is discarded: palette, text, pcal_purpose,
* pcal_units, pcal_params, hist, iccp_name, iccp_profile, splt_palettes, and
* scal_unit. Of these, the text, pcal_*, hist, iccp_*, splt_*, and scal_unit
* members are automatically freed when the info structure is deallocated.
* The palette member is not.
* cleaned up before the structure is discarded: palette, trans, text,
* pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile,
* splt_palettes, scal_unit, and row_pointers. These are automatically
* freed when the info structure is deallocated.
*
* More allocation details: all the chunk-reading functions that change these
* members go through the corresponding png_set_* functions. Functions to
@@ -447,7 +452,7 @@ typedef struct png_info_struct
png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
/* The following is informational only on read, and not used on writes. */
png_byte channels; /* number of data channels per pixel (1, 3, 4)*/
png_byte channels; /* number of data channels per pixel (1, 2, 3, 4)*/
png_byte pixel_depth; /* number of bits per pixel */
png_byte spare_byte; /* to align the data, and for future use */
png_byte signature[8]; /* magic bytes read by libpng from start of file */
@@ -458,6 +463,8 @@ typedef struct png_info_struct
* and initialize the appropriate fields below.
*/
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#if defined(PNG_gAMA_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
/* The gAMA chunk describes the gamma characteristics of the system
* on which the image was created, normally in the range [1.0, 2.5].
@@ -466,10 +473,8 @@ typedef struct png_info_struct
#ifdef PNG_FLOATING_POINT_SUPPORTED
float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
png_fixed_point int_gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
#endif
#endif
#if defined(PNG_sRGB_SUPPORTED)
/* GR-P, 0.96a */
@@ -628,7 +633,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
#if defined(PNG_sPLT_SUPPORTED)
/* data on sPLT chunks (there may be more than one). */
png_spalette_p splt_palettes;
png_sPLT_tp splt_palettes;
png_uint_32 splt_palettes_num;
#endif
@@ -657,6 +662,12 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
png_unknown_chunkp unknown_chunks;
png_size_t unknown_chunks_num;
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED)
/* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) non-zero */
/* Data valid if (valid & PNG_INFO_IDAT) non-zero */
png_bytepp row_pointers; /* the image bits */
#endif
} png_info;
typedef png_info FAR * png_infop;
@@ -745,6 +756,7 @@ typedef png_info FAR * FAR * png_infopp;
#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
#define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
/* This is used for the transformation routines, as some of them
* change these values for the row. It also should enable using
@@ -791,6 +803,28 @@ typedef void (*png_user_transform_ptr) PNGARG((png_structp,
png_row_infop, png_bytep));
#endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
typedef int (*png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
#endif
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
typedef void (*png_unknown_chunk_ptr) PNGARG((png_structp));
#endif
/* Transform masks for the high-level interface */
#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
#define PNG_TRANSFORM_BGR 0x0080 /* read and write */
#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
#define PNG_TRANSFORM_INVERT_ALPHA 0x0200 /* read and write */
#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
@@ -803,8 +837,9 @@ typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
struct png_struct_def
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf jmpbuf; /* used in png_error */
#endif
png_error_ptr error_fn; /* function for printing errors and aborting */
png_error_ptr warning_fn; /* function for printing warnings */
png_voidp error_ptr; /* user supplied struct for error functions */
@@ -827,8 +862,14 @@ struct png_struct_def
png_byte user_transform_channels; /* channels in user transformed pixels */
#endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
png_voidp user_chunk_ptr;
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
#endif
png_uint_32 mode; /* tells us where we are in the PNG file */
png_uint_32 flags; /* flags indicating various things to libpng */
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
png_uint_32 transformations; /* which transformations to perform */
z_stream zstream; /* pointer to decompression structure (below) */
@@ -902,10 +943,8 @@ struct png_struct_def
float gamma; /* file gamma value */
float screen_gamma; /* screen gamma value (display_exponent) */
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
png_fixed_point int_gamma;
#endif
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
png_bytep gamma_table; /* gamma table for 8-bit depth files */
@@ -998,28 +1037,33 @@ struct png_struct_def
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
png_byte rgb_to_gray_status;
png_byte rgb_to_gray_red_coeff;
png_byte rgb_to_gray_green_coeff;
png_byte rgb_to_gray_blue_coeff;
png_uint_16 rgb_to_gray_red_coeff;
png_uint_16 rgb_to_gray_green_coeff;
png_uint_16 rgb_to_gray_blue_coeff;
#endif
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
png_byte empty_plte_permitted;
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
int num_chunk_list;
png_bytep chunk_list;
#endif
};
/* This prevents a compiler error in png_get_copyright() in png.c if png.c
and png.h are both at * version 1.0.5j
and png.h are both at * version 1.0.5v
*/
typedef png_structp version_1_0_5j;
typedef png_structp version_1_0_5v;
typedef png_struct FAR * FAR * png_structpp;
/* Here are the function definitions most commonly used. This is not
* the place to find out how to use libpng. See libpng.txt for the
* full explanation, see example.c for the summary. This just provides
* a simple one line of the use of each function.
* a simple one line description of the use of each function.
*/
/* Tell lib we have already handled the first <num_bytes> magic bytes.
@@ -1133,6 +1177,8 @@ extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
int error_action, double red, double green ));
#endif
extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
int error_action, png_fixed_point red, png_fixed_point green ));
extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
png_ptr));
#endif
@@ -1505,6 +1551,13 @@ extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
PNGARG((png_structp png_ptr));
#endif
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
png_ptr));
#endif
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
/* Sets the function callbacks for the push reader, and a pointer to a
* user-defined structure available to the callback functions.
@@ -1535,6 +1588,23 @@ extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
/* frees a pointer allocated by png_malloc() */
extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
/* free data that was allocated internally */
extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_uint_32 free_me, int num));
/* flags for png_ptr->free_me and info_ptr->free_me */
#define PNG_FREE_PLTE 0x0001
#define PNG_FREE_TRNS 0x0002
#define PNG_FREE_TEXT 0x0004
#define PNG_FREE_HIST 0x0008
#define PNG_FREE_ICCP 0x0010
#define PNG_FREE_SPLT 0x0020
#define PNG_FREE_ROWS 0x0040
#define PNG_FREE_PCAL 0x0080
#define PNG_FREE_SCAL 0x0100
#define PNG_FREE_UNKN 0x0200
#define PNG_FREE_LIST 0x0400
#define PNG_FREE_ALL 0x07ff
#ifdef PNG_USER_MEM_SUPPORTED
extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
png_uint_32 size));
@@ -1589,6 +1659,17 @@ png_infop info_ptr, png_uint_32 flag));
extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
png_infop info_ptr));
#if defined(PNG_INFO_IMAGE_SUPPORTED)
/* Returns row_pointers, which is an array of pointers to scanlines that was
returned from png_read_png(). */
extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
png_infop info_ptr));
/* Set row_pointers, which is an array of pointers to scanlines for use
by png_write_png(). */
extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_bytepp row_pointers));
#endif
/* Returns number of color channels in image. */
extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
png_infop info_ptr));
@@ -1698,22 +1779,18 @@ extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
png_infop info_ptr, double *file_gamma));
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_fixed_point *int_file_gamma));
#endif
#endif
#if defined(PNG_gAMA_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
png_infop info_ptr, double file_gamma));
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_fixed_point int_file_gamma));
#endif
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
@@ -1758,11 +1835,6 @@ extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
int type, int nparams, png_charp units, png_charpp params));
#endif
#if defined(PNG_pCAL_SUPPORTED)
extern PNG_EXPORT(void,png_free_pCAL) PNGARG((png_structp png_ptr,
png_infop info_ptr));
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
@@ -1804,33 +1876,23 @@ extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
#if defined(PNG_READ_iCCP_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_charpp name, int *compression_type,
png_charpp profile, png_int_32 *proflen));
png_charpp profile, png_uint_32 *proflen));
#endif
#if defined(PNG_iCCP_SUPPORTED)
extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_charp name, int compression_type,
png_charp profile, int proflen));
extern PNG_EXPORT(void,png_free_iCCP) PNGARG((png_structp png_ptr,
png_infop info_ptr));
png_charp profile, png_uint_32 proflen));
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_spalettes) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_spalette_pp entries));
extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_sPLT_tpp entries));
#endif
#if defined(PNG_sPLT_SUPPORTED)
extern PNG_EXPORT(void,png_set_spalettes) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_spalette_p entries, int nentries));
extern PNG_EXPORT(void,png_free_spalettes) PNGARG((png_structp png_ptr,
png_infop info_ptr, int num));
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
/* png_get_itxt also returns the number of text chunks in *num_text */
extern PNG_EXPORT(png_uint_32,png_get_itxt) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_textp *text_ptr, int *num_text));
extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_sPLT_tp entries, int nentries));
#endif
#if defined(PNG_TEXT_SUPPORTED)
@@ -1848,8 +1910,6 @@ extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
#if defined(PNG_TEXT_SUPPORTED)
extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_textp text_ptr, int num_text));
extern PNG_EXPORT(void,png_free_text) PNGARG((png_structp png_ptr,
png_infop info_ptr, int num_text_old));
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
@@ -1874,11 +1934,14 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
png_color_16p trans_values));
#endif
#if defined(PNG_tRNS_SUPPORTED)
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
png_infop info_ptr, int *unit, double *width, double *height));
#else
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
@@ -1897,20 +1960,33 @@ extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
#endif
#endif /* PNG_READ_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
extern PNG_EXPORT(void,png_free_sCAL) PNGARG((png_structp png_ptr,
png_infop info_ptr));
#endif /* PNG_READ_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
/* provide a list of chunks and how they are to be handled, if the built-in
handling or default unknown chunk handling is not desired. Any chunks not
listed will be handled in the default manner. The IHDR and IEND chunks
must not be listed.
keep = 0: follow default behavour
= 1: do not keep
= 2: keep only if safe-to-copy
= 3: keep even if unsafe-to-copy
*/
extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
png_ptr, int keep, png_bytep chunk_list, int num_chunks));
extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
extern PNG_EXPORT(void,png_free_unknown_chunks) PNGARG((png_structp png_ptr,
png_infop info_ptr, int num));
extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_unknown_chunkpp entries));
extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED)
extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
png_infop info_ptr,
int transforms,
voidp params));
extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
png_infop info_ptr,
int transforms,
voidp params));
#endif
/* Define PNG_DEBUG at compile time for debugging information. Higher
@@ -1952,7 +2028,8 @@ extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
#define PNG_HEADER_VERSION_STRING " libpng version 1.0.5j - December 21, 1999 (header)\n"
#define PNG_HEADER_VERSION_STRING \
" libpng version 1.0.5v - March 11, 2000 (header)\n"
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
/* With these routines we avoid an integer divide, which will be slower on
@@ -2006,7 +2083,6 @@ extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
/* Various modes of operation. Note that after an init, mode is set to
* zero automatically when the structure is created.
*/
#define PNG_BEFORE_IHDR 0x00
#define PNG_HAVE_IHDR 0x01
#define PNG_HAVE_PLTE 0x02
#define PNG_HAVE_IDAT 0x04
@@ -2069,12 +2145,14 @@ extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
#define PNG_FLAG_CRC_CRITICAL_USE 0x0400
#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
#define PNG_FLAG_FREE_PALETTE 0x1000
#define PNG_FLAG_FREE_TRANS 0x2000
#define PNG_FLAG_FREE_HIST 0x4000
#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x1000
#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x2000
/* For use in png_set_keep_unknown, png_handle_as_unknown */
#define HANDLE_CHUNK_AS_DEFAULT 0
#define HANDLE_CHUNK_NEVER 1
#define HANDLE_CHUNK_IF_SAFE 2
#define HANDLE_CHUNK_ALWAYS 3
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
PNG_FLAG_CRC_ANCILLARY_NOWARN)
@@ -2160,18 +2238,18 @@ PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5];
* values, which is almost certainly true.
*/
#if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
#if defined(PNG_READ_pCAL_SUPPORTED)
#define png_get_int_32(buf) ( *((png_int_32p) (buf)))
#endif /* PNG_READ_pCAL_SUPPORTED */
#define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
#define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
# if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_oFFs_SUPPORTED)
# define png_get_int_32(buf) ( *((png_int_32p) (buf)))
# endif
# define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
# define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
#else
#if defined(PNG_READ_pCAL_SUPPORTED)
# if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_oFFs_SUPPORTED)
PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf));
#endif /* PNG_READ_pCAL_SUPPORTED */
# endif
PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
#endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
/* Initialize png_ptr struct for reading, and allocate any other memory.
* (old interface - NOT DLL EXPORTED).
@@ -2325,7 +2403,7 @@ PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
#if defined(PNG_WRITE_sPLT_SUPPORTED)
PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
png_spalette_p palette));
png_sPLT_tp palette));
#endif
#if defined(PNG_WRITE_tRNS_SUPPORTED)
@@ -2343,11 +2421,6 @@ PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
int num_hist));
#endif
#if defined(PNG_hIST_SUPPORTED)
extern PNG_EXPORT(void,png_free_hIST) PNGARG((png_structp png_ptr,
png_infop info_ptr));
#endif
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
@@ -2575,13 +2648,8 @@ PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#if defined(PNG_READ_gAMA_SUPPORTED)
PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
#if defined(PNG_READ_bKGD_SUPPORTED)
PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
@@ -2590,8 +2658,13 @@ PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
#if defined(PNG_READ_gAMA_SUPPORTED)
PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
@@ -2600,23 +2673,8 @@ extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif /* PNG_READ_iCCP_SUPPORTED */
#if defined(PNG_READ_sPLT_SUPPORTED)
extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif /* PNG_READ_sPLT_SUPPORTED */
#if defined(PNG_READ_tRNS_SUPPORTED)
PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_bKGD_SUPPORTED)
PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
#if defined(PNG_READ_iTXt_SUPPORTED)
PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
@@ -2630,18 +2688,28 @@ PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
#if defined(PNG_READ_sBIT_SUPPORTED)
PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif /* PNG_READ_sPLT_SUPPORTED */
#if defined(PNG_READ_sRGB_SUPPORTED)
PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
@@ -2650,14 +2718,24 @@ PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
PNG_EXTERN int png_handle_as_unknown PNGARG((png_structp png_ptr, png_bytep
chunk_name));
#endif
PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,

View File

@@ -1,32 +1,35 @@
/* pngasmrd.h - assembler version of utilities to read a PNG file
*
* libpng 1.0.4e - October 10, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1999 Glenn Randers-Pehrson
* Copyright (c) 1999, 2000 Glenn Randers-Pehrson
*
*/
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
/* Set this in the makefile for VC++ on Pentium, not in pngconf.h */
#ifdef PNG_USE_PNGVCRD
/* Platform must be Pentium. Makefile must assemble and load pngvcrd.c .
* MMX will be detected at run time and used if present.
*/
#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
#ifdef PNG_USE_PNGVCRD
# define PNG_HAVE_ASSEMBLER_COMBINE_ROW
# define PNG_HAVE_ASSEMBLER_READ_INTERLACE
# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
#endif
/* Set this in the makefile for gcc on Pentium, not in pngconf.h */
#ifdef PNG_USE_PNGGCCRD
/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c
* (not available in libpng 1.0.4e).
/* Set this in the makefile for gcc/as on Pentium, not in pngconf.h */
/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c .
* MMX will be detected at run time and used if present.
*/
#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
#ifdef PNG_USE_PNGGCCRD
# define PNG_HAVE_ASSEMBLER_COMBINE_ROW
# define PNG_HAVE_ASSEMBLER_READ_INTERLACE
# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
#endif
/*
GRR notes:
- see pnggccrd.c for info about what is currently enabled
*/
#endif

105
pngconf.h
View File

@@ -1,11 +1,11 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*/
/* Any machine specific code is near the front of this file, so if you
@@ -113,29 +113,35 @@
#include <sys/types.h>
#endif
#ifndef PNG_SETJMP_NOT_SUPPORTED
# define PNG_SETJMP_SUPPORTED
#endif
#ifdef PNG_SETJMP_SUPPORTED
/* This is an attempt to force a single setjmp behaviour on Linux. If
* the X config stuff didn't define _BSD_SOURCE we wouldn't need this.
*/
#ifdef __linux__
#ifdef _BSD_SOURCE
#define _PNG_SAVE_BSD_SOURCE
#undef _BSD_SOURCE
#endif
#ifdef _SETJMP_H
__png.h__ already includes setjmp.h
__dont__ include it again
#endif
# ifdef __linux__
# ifdef _BSD_SOURCE
# define _PNG_SAVE_BSD_SOURCE
# undef _BSD_SOURCE
# endif
# ifdef _SETJMP_H
__png.h__ already includes setjmp.h
__dont__ include it again
# endif
#endif /* __linux__ */
/* include setjmp.h for error handling */
#include <setjmp.h>
#ifdef __linux__
#ifdef _PNG_SAVE_BSD_SOURCE
#define _BSD_SOURCE
#undef _PNG_SAVE_BSD_SOURCE
#endif
#endif /* __linux__ */
# ifdef __linux__
# ifdef _PNG_SAVE_BSD_SOURCE
# define _BSD_SOURCE
# undef _PNG_SAVE_BSD_SOURCE
# endif
# endif /* __linux__ */
#endif /* PNG_SETJMP_SUPPORTED */
#ifdef BSD
#include <strings.h>
@@ -419,7 +425,8 @@ __dont__ include it again
#define PNG_EASY_ACCESS_SUPPORTED
#endif
#ifndef PNG_NO_ASSEMBLER_CODE
#if defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD) && \
!defined(PNG_NO_ASSEMBLER_CODE)
#define PNG_ASSEMBLER_CODE_SUPPORTED
#endif
@@ -436,9 +443,14 @@ __dont__ include it again
* but might be required for some pre-1.0.5c applications.
*/
#ifdef PNG_NO_GLOBAL_ARRAYS
#define PNG_USE_LOCAL_ARRAYS
# define PNG_USE_LOCAL_ARRAYS
#else
#define PNG_USE_GLOBAL_ARRAYS
# if defined(__GNUC__) && defined(WIN32)
# define PNG_NO_GLOBAL_ARRAYS
# define PNG_USE_LOCAL_ARRAYS
# else
# define PNG_USE_GLOBAL_ARRAYS
# endif
#endif
/* These are currently experimental features, define them if you want */
@@ -551,9 +563,22 @@ __dont__ include it again
# define PNG_READ_zTXt_SUPPORTED
# define PNG_zTXt_SUPPORTED
#endif
#ifndef PNG_NO_READ_USER_CHUNKS
# define PNG_READ_USER_CHUNKS_SUPPORTED
# define PNG_USER_CHUNKS_SUPPORTED
# ifdef PNG_NO_READ_UNKNOWN_CHUNKS
# undef PNG_NO_READ_UNKNOWN_CHUNKS
# endif
# ifdef PNG_NO_HANDLE_AS_UNKNOWN
# undef PNG_NO_HANDLE_AS_UNKNOWN
# endif
#endif
#ifndef PNG_NO_READ_UNKNOWN_CHUNKS
# define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
# define PNG_UNKNOWN_CHUNKS_SUPPORTED
# ifndef PNG_NO_HANDLE_AS_UNKNOWN
# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
# endif
#endif
#ifndef PNG_NO_READ_OPT_PLTE
# define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
@@ -678,6 +703,11 @@ __dont__ include it again
# ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
# define PNG_UNKNOWN_CHUNKS_SUPPORTED
# endif
# ifndef PNG_NO_HANDLE_AS_UNKNOWN
# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
# endif
# endif
#endif
#if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
defined(PNG_WRITE_zTXt_SUPPORTED)
@@ -688,8 +718,16 @@ __dont__ include it again
#endif
#endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
/* Turn this off to disable png_read_png() and
* png_write_png() and leave the row_pointers member
* out of the info structure.
*/
#ifndef PNG_NO_INFO_IMAGE
# define PNG_INFO_IMAGE_SUPPORTED
#endif
/* need the time information for reading tIME chunks */
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
#if defined(PNG_tIME_SUPPORTED)
# include <time.h>
#endif
@@ -817,8 +855,13 @@ typedef z_stream FAR * png_zstreamp;
#ifndef PNG_EXPORT
/* allow for compilation as dll under MS Windows */
# ifdef __WIN32DLL__
/* GRR 20000206: based on zconf.h and MSVC 5.0 docs */
# if defined(_MSC_VER) && defined(_DLL)
# define PNG_EXPORT(type,symbol) type __declspec(dllexport) symbol
# endif
/* allow for compilation as a DLL under MS Windows */
# ifdef __WIN32DLL__ /* Borland? */
# define PNG_EXPORT(type,symbol) __declspec(dllexport) type symbol
# endif
@@ -827,7 +870,7 @@ typedef z_stream FAR * png_zstreamp;
# define PNG_EXPORT(type,symbol) type __attribute__((dllexport)) symbol
# endif
/* allow for compilation as dll with Borland C++ 5.0 */
/* allow for compilation as a DLL with Borland C++ 5.0 */
# if defined(__BORLANDC__) && defined(_Windows) && defined(__DLL__)
# define PNG_EXPORT(type,symbol) type _export symbol
# endif
@@ -847,6 +890,9 @@ typedef z_stream FAR * png_zstreamp;
#endif
#ifndef PNG_EXPORT_VAR
# if defined(_MSC_VER) && defined(_DLL) /* GRR 20000206 */
# define PNG_EXPORT_VAR(type) extern type __declspec(dllexport)
# endif
# ifdef PNG_DECL_DLLEXP
# define PNG_EXPORT_VAR(type) extern __declspec(dllexport) type
# endif
@@ -869,6 +915,17 @@ typedef z_stream FAR * png_zstreamp;
* that are passed far data must be model independent.
*/
#ifndef PNG_ABORT
# define PNG_ABORT() abort()
#endif
#ifdef PNG_SETJMP_SUPPORTED
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
#else
# define png_jmpbuf(png_ptr) \
(LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
#endif
#if defined(USE_FAR_KEYWORD) /* memory model independent fns */
/* use this to make far-to-near assignments */
# define CHECK 1

File diff suppressed because it is too large Load Diff

View File

@@ -3,9 +3,25 @@
/* Special defines for pngcrush, mostly just to reduce the size of the
static executable. */
#define PNG_NO_FLOATING_POINT_SUPPORTED /* undef this if you want to be able
to reduce color to gray */
#define PNG_NO_READ_cHRM
#define PNG_NO_WRITE_cHRM
#define PNG_NO_READ_hIST
#define PNG_NO_WRITE_hIST
#define PNG_NO_READ_iCCP
#define PNG_NO_WRITE_iCCP
#define PNG_NO_READ_pCAL
#define PNG_NO_WRITE_pCAL
#define PNG_NO_READ_sCAL
#define PNG_NO_WRITE_sCAL
#define PNG_NO_READ_sPLT
#define PNG_NO_WRITE_sPLT
#define PNG_NO_READ_tIME
#define PNG_NO_WRITE_tIME
#define PNG_NO_INFO_IMAGE
#define PNG_NO_READ_USER_CHUNKS
#define PNG_NO_EASY_ACCESS
#define PNG_NO_READ_DITHER
#define PNG_NO_READ_EMPTY_PLTE
#define PNG_NO_WRITE_TRANSFORMS
#define PNG_NO_PROGRESSIVE_READ
@@ -14,17 +30,14 @@
#define PNG_READ_STRIP_ALPHA_SUPPORTED
#define PNG_READ_EXPAND_SUPPORTED
#define PNG_READ_FILLER_SUPPORTED
#define PNG_READ_RGB_TO_GRAY_SUPPORTED
#ifndef PNG_NO_FLOATING_POINT_SUPPORTED
# define PNG_READ_GRAY_TO_RGB_SUPPORTED
# define PNG_READ_RGB_TO_GRAY_SUPPORTED
# define PNG_READ_BACKGROUND_SUPPORTED
# define PNG_READ_GAMMA_SUPPORTED
#else
# define PNG_NO_READ_RGB_TO_GRAY
#endif
#define PNG_ZBUF_SIZE 524288 /* increases the IDAT size */
/*
#define PNG_NO_GLOBAL_ARRAYS
*/
#define TOO_FAR 32767 /* Improves zlib/deflate compression */
#ifndef PNG_ZBUF_SIZE
# define PNG_ZBUF_SIZE 524288 /* increases the IDAT size */
#endif

View File

@@ -1,11 +1,11 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
* This file provides a location for all error handling. Users who
* need special error handling are expected to write replacement functions
@@ -67,21 +67,26 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message
{
int iout = 0, iin = 0;
while (iin < 4) {
while (iin < 4)
{
int c = png_ptr->chunk_name[iin++];
if (isnonalpha(c)) {
if (isnonalpha(c))
{
buffer[iout++] = '[';
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
buffer[iout++] = png_digit[c & 0xf];
buffer[iout++] = png_digit[c & 0x0f];
buffer[iout++] = ']';
} else {
}
else
{
buffer[iout++] = (png_byte)c;
}
}
if (message == NULL)
buffer[iout] = 0;
else {
else
{
buffer[iout++] = ':';
buffer[iout++] = ' ';
png_memcpy(buffer+iout, message, 64);
@@ -117,14 +122,20 @@ png_default_error(png_structp png_ptr, png_const_charp message)
fprintf(stderr, "libpng error: %s\n", message);
#endif
#ifdef USE_FAR_KEYWORD
#ifdef PNG_SETJMP_SUPPORTED
# ifdef USE_FAR_KEYWORD
{
jmp_buf jmpbuf;
png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf));
longjmp(jmpbuf, 1);
}
#else
# else
longjmp(png_ptr->jmpbuf, 1);
# endif
#else
if (png_ptr == NULL)
/* make compiler happy */ ;
PNG_ABORT();
#endif
}

65
pngerror.h Normal file
View File

@@ -0,0 +1,65 @@
/* This linked list implements a stack structure where jmpbuf context
* is to be saved. It will allow multiple, nested calls of setjmp/longjmp...
*/
#ifndef _PNGERROR_H
#define _PNGERROR_H
#ifndef PNG_ABORT
# define PNG_ABORT() abort()
#endif
#ifndef PNG_SETJMP_NOT_SUPPORTED
# define PNG_SETJMP_SUPPORTED
#endif
#ifdef PNG_SETJMP_SUPPORTED
/* New feature in version 1.1.0d. Don't undefine this; it's here just so
* applications can test for the new version. */
#define PNG_JMPBUF_SUPPORTED
/* This is an attempt to force a single setjmp behaviour on Linux. If
* the X config stuff didn't define _BSD_SOURCE we wouldn't need this.
*/
#ifdef __linux__
# ifdef _BSD_SOURCE
# define _PNG_SAVE_BSD_SOURCE
# undef _BSD_SOURCE
# endif
# ifdef _SETJMP_H
__png.h__ already includes setjmp.h
__dont__ include it again
# endif
#endif /* __linux__ */
/* include setjmp.h for error handling */
#include <setjmp.h>
#ifdef __linux__
# ifdef _PNG_SAVE_BSD_SOURCE
# define _BSD_SOURCE
# undef _PNG_SAVE_BSD_SOURCE
# endif
#endif /* __linux__ */
typedef struct png_jmpbuf_struct
{
jmp_buf env;
struct png_jmpbuf_struct FAR * link;
} png_jmpbuf;
typedef png_jmpbuf FAR * png_jmpbufp;
typedef png_jmpbuf FAR * FAR * png_jmpbufpp;
#define png_jmp_env(png_ptr) png_get_jmpbuf(png_ptr)->env
extern PNG_EXPORT(png_jmpbufp,png_get_jmpbuf)
PNGARG((png_structp));
#define png_setjmp(png_ptr) setjmp(png_get_jmpbuf(png_ptr)->env)
#define png_longjmp(png_ptr,val) longjmp(png_get_jmpbuf(png_ptr)->env,val)
#endif /* PNG_SETJMP_SUPPORTED */
#endif /* _PNGERROR_H */

View File

@@ -6,10 +6,10 @@
* and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
* for Intel's performance analysis of the MMX vs. non-MMX code.
*
* libpng 1.0.5 - October 15, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, Intel Corporation
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
* Based on MSVC code contributed by Nirav Chhatrapati, Intel Corp., 1998.
* Interface to libpng contributed by Gilles Vollant, 1999.

View File

@@ -1,11 +1,11 @@
/* pngget.c - retrieval of values from info struct
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*/
#define PNG_INTERNAL
@@ -29,6 +29,17 @@ png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
return(0);
}
#if defined(PNG_INFO_IMAGE_SUPPORTED)
png_bytepp
png_get_rows(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->row_pointers);
else
return(0);
}
#endif
#ifdef PNG_EASY_ACCESS_SUPPORTED
/* easy access to info, added in libpng-0.99 */
png_uint_32
@@ -239,35 +250,35 @@ png_uint_32
png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5)
*.0254 +.5);
}
png_uint_32
png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5)
*.0254 +.5);
}
png_uint_32
png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5)
*.0254 +.5);
}
float
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
*.03937/1000000. +.5)
*.00003937);
}
float
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
*.03937/1000000. +.5)
*.00003937)
}
#if defined(PNG_READ_pHYs_SUPPORTED)
@@ -277,7 +288,7 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
{
png_uint_32 retval = 0;
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
{
png_debug1(1, "in %s retrieval function\n", "pHYs");
if (res_x != NULL)
@@ -296,15 +307,15 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
retval |= PNG_INFO_pHYs;
if(unit_type == 1)
{
if (res_x != NULL) *res_x = (png_uint_32)(*res_x * 39.37 + .50);
if (res_y != NULL) *res_y = (png_uint_32)(*res_y * 39.37 + .50);
if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
}
}
}
return (retval);
}
#endif /* PNG_READ_pHYs_SUPPORTED */
#endif /* PNG_INCH_CONVERSIONS $$ PNG_FLOATING_POINT_SUPPORTED */
#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
/* png_get_channels really belongs in here, too, but it's been around longer */
@@ -423,7 +434,6 @@ png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
return (0);
}
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
png_uint_32
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
png_fixed_point *int_file_gamma)
@@ -438,7 +448,6 @@ png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
return (0);
}
#endif
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
png_uint_32
@@ -459,7 +468,7 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
png_uint_32
png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
png_charpp name, int *compression_type,
png_charpp profile, png_int_32 *proflen)
png_charpp profile, png_uint_32 *proflen)
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
&& name != NULL && profile != NULL && proflen != NULL)
@@ -479,8 +488,8 @@ png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
#if defined(PNG_READ_sPLT_SUPPORTED)
png_uint_32
png_get_spalettes(png_structp png_ptr, png_infop info_ptr,
png_spalette_pp spalettes)
png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
png_sPLT_tpp spalettes)
{
if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
*spalettes = info_ptr->splt_palettes;
@@ -573,8 +582,8 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
png_charp *units, png_charpp *params)
{
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL &&
purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
&& purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
nparams != NULL && units != NULL && params != NULL)
{
png_debug1(1, "in %s retrieval function\n", "pCAL");
@@ -597,7 +606,8 @@ png_uint_32
png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
int *unit, double *width, double *height)
{
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sCAL)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_sCAL))
{
*unit = info_ptr->scal_unit;
*width = info_ptr->scal_pixel_width;
@@ -612,7 +622,8 @@ png_uint_32
png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
int *unit, png_charpp width, png_charpp height)
{
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sCAL)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_sCAL))
{
*unit = info_ptr->scal_unit;
*width = info_ptr->scal_s_width;
@@ -632,7 +643,8 @@ png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
{
png_uint_32 retval = 0;
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
if (png_ptr != NULL && info_ptr != NULL &&
(info_ptr->valid & PNG_INFO_pHYs))
{
png_debug1(1, "in %s retrieval function\n", "pHYs");
if (res_x != NULL)
@@ -659,8 +671,8 @@ png_uint_32
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
int *num_palette)
{
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_PLTE &&
palette != NULL)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
&& palette != NULL)
{
png_debug1(1, "in %s retrieval function\n", "PLTE");
*palette = info_ptr->palette;
@@ -675,8 +687,8 @@ png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
png_uint_32
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
{
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT &&
sig_bit != NULL)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
&& sig_bit != NULL)
{
png_debug1(1, "in %s retrieval function\n", "sBIT");
*sig_bit = &(info_ptr->sig_bit);
@@ -702,6 +714,8 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
*num_text = info_ptr->num_text;
return ((png_uint_32)info_ptr->num_text);
}
if (num_text != NULL)
*num_text = 0;
return(0);
}
#endif
@@ -710,8 +724,8 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
png_uint_32
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
{
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME &&
mod_time != NULL)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
&& mod_time != NULL)
{
png_debug1(1, "in %s retrieval function\n", "tIME");
*mod_time = &(info_ptr->mod_time);
@@ -727,7 +741,7 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep *trans, int *num_trans, png_color_16p *trans_values)
{
png_uint_32 retval = 0;
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
{
png_debug1(1, "in %s retrieval function\n", "tRNS");
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
@@ -778,3 +792,12 @@ png_get_rgb_to_gray_status (png_structp png_ptr)
return png_ptr->rgb_to_gray_status;
}
#endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
png_voidp
png_get_user_chunk_ptr(png_structp png_ptr)
{
return (png_ptr->user_chunk_ptr);
}
#endif

View File

@@ -1,11 +1,11 @@
/* pngmem.c - stub functions for memory allocation
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
* This file provides a location for all memory allocation. Users who
* need special memory handling are expected to supply replacement

View File

@@ -1,11 +1,11 @@
/* pngpread.c - read a png file in push mode
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*/
#define PNG_INTERNAL
@@ -952,7 +952,7 @@ png_read_push_finish_row(png_structp png_ptr)
void
png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND)
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{
png_error(png_ptr, "Out of place tEXt");
/* to quiet some compiler warnings */
@@ -1040,7 +1040,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
void
png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND)
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{
png_error(png_ptr, "Out of place zTXt");
/* to quiet some compiler warnings */
@@ -1221,7 +1221,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
void
png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND)
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{
png_error(png_ptr, "Out of place iTXt");
/* to quiet some compiler warnings */
@@ -1268,7 +1268,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
{
png_textp text_ptr;
png_charp key;
int comp_flag = 0;
int comp_flag;
png_charp lang;
png_charp lang_key;
png_charp text;
@@ -1325,22 +1325,28 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
#endif
/* This function is called when we haven't found a handler for this
* chunk. In the future we will have code here that can handle
* user-defined callback functions for unknown chunks before they are
* ignored or cause an error. If there isn't a problem with the
* chunk itself (ie a bad chunk name or a critical chunk), the chunk
* is (currently) silently ignored.
* chunk. If there isn't a problem with the chunk itself (ie a bad chunk
* name or a critical chunk), the chunk is (currently) silently ignored.
*/
void
png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_uint_32 skip=0;
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
if (!(png_ptr->chunk_name[0] & 0x20))
{
png_chunk_error(png_ptr, "unknown critical chunk");
/* to quiet some compiler warnings */
if(info_ptr == NULL) return;
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
HANDLE_CHUNK_ALWAYS
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
&& png_ptr->read_user_chunk_fn == (png_user_chunk_ptr)NULL
#endif
)
png_chunk_error(png_ptr, "unknown critical chunk");
/* to quiet compiler warnings about unused info_ptr */
if (info_ptr == NULL)
return;
}
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
@@ -1361,13 +1367,28 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 len
chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_crc_read(png_ptr, chunk.data, length);
chunk.size = length;
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
if(png_ptr->read_user_chunk_fn != (png_user_chunk_ptr)NULL)
{
/* callback to user unknown chunk handler */
if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0)
{
if (!(png_ptr->chunk_name[0] & 0x20))
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
HANDLE_CHUNK_ALWAYS)
png_chunk_error(png_ptr, "unknown critical chunk");
}
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
}
else
#endif
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
png_free(png_ptr, chunk.data);
}
else
#endif
png_push_crc_skip(png_ptr, length);
skip=length;
png_push_crc_skip(png_ptr, skip);
}
void

226
pngread.c
View File

@@ -1,11 +1,11 @@
/* pngread.c - read a PNG file
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
* This file contains routines that an application calls directly to
* read a PNG file or stream.
@@ -34,9 +34,13 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#endif /* PNG_USER_MEM_SUPPORTED */
png_structp png_ptr;
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
jmp_buf jmpbuf;
#endif
#endif
png_debug(1, "in png_create_read_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
@@ -47,6 +51,8 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
{
return (png_structp)NULL;
}
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
#else
@@ -60,6 +66,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#endif
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
@@ -110,17 +117,24 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
void
png_read_init(png_structp png_ptr)
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* to save current jump buffer */
#endif
png_debug(1, "in png_read_init\n");
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
#endif
/* reset all variables to 0 */
png_memset(png_ptr, 0, sizeof (png_struct));
#ifdef PNG_SETJMP_SUPPORTED
/* restore jump buffer */
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
#endif
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
@@ -253,10 +267,29 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
*/
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
png_handle_IHDR(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
png_handle_PLTE(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
png_handle_IEND(png_ptr, info_ptr, length);
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
{
if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
png_ptr->mode |= PNG_HAVE_IDAT;
png_handle_unknown(png_ptr, info_ptr, length);
if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
png_ptr->mode |= PNG_HAVE_PLTE;
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
{
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before IDAT");
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
!(png_ptr->mode & PNG_HAVE_PLTE))
png_error(png_ptr, "Missing PLTE before IDAT");
break;
}
}
#endif
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
png_handle_PLTE(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
{
if (!(png_ptr->mode & PNG_HAVE_IHDR))
@@ -421,7 +454,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
switch (png_ptr->pass)
{
case 0:
if (png_ptr->row_number & 7)
if (png_ptr->row_number & 0x07)
{
if (dsp_row != NULL)
png_combine_row(png_ptr, dsp_row,
@@ -431,7 +464,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
}
break;
case 1:
if ((png_ptr->row_number & 7) || png_ptr->width < 5)
if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
{
if (dsp_row != NULL)
png_combine_row(png_ptr, dsp_row,
@@ -441,7 +474,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
}
break;
case 2:
if ((png_ptr->row_number & 7) != 4)
if ((png_ptr->row_number & 0x07) != 4)
{
if (dsp_row != NULL && (png_ptr->row_number & 4))
png_combine_row(png_ptr, dsp_row,
@@ -546,6 +579,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
if(png_ptr->row_buf[0])
png_read_filter_row(png_ptr, &(png_ptr->row_info),
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
(int)(png_ptr->row_buf[0]));
@@ -607,7 +641,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
* not called png_set_interlace_handling(), the display_row buffer will
* be ignored, so pass NULL to it.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5j.
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5v.
*/
void
@@ -656,7 +690,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
* only call this function once. If you desire to have an image for
* each pass of a interlaced image, use png_read_rows() instead.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5j.
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5v.
*/
void
png_read_image(png_structp png_ptr, png_bytepp image)
@@ -776,6 +810,23 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
png_handle_IHDR(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
png_handle_IEND(png_ptr, info_ptr, length);
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
{
if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
{
if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT)
png_error(png_ptr, "Too many IDAT's found");
}
else
png_ptr->mode |= PNG_AFTER_IDAT;
png_handle_unknown(png_ptr, info_ptr, length);
if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
png_ptr->mode |= PNG_HAVE_PLTE;
}
#endif
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
{
/* Zero length IDATs are legal after the last IDAT has been
@@ -788,8 +839,6 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
}
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
png_handle_PLTE(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
png_handle_IEND(png_ptr, info_ptr, length);
#if defined(PNG_READ_bKGD_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
png_handle_bKGD(png_ptr, info_ptr, length);
@@ -894,7 +943,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
if (info_ptr != NULL)
{
#if defined(PNG_TEXT_SUPPORTED)
png_free(png_ptr, info_ptr->text);
png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
#endif
#ifdef PNG_USER_MEM_SUPPORTED
@@ -908,7 +957,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
if (end_info_ptr != NULL)
{
#if defined(PNG_READ_TEXT_SUPPORTED)
png_free(png_ptr, end_info_ptr->text);
png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)end_info_ptr, free_fn);
@@ -933,7 +982,9 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
void
png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp;
#endif
png_error_ptr error_fn;
png_error_ptr warning_fn;
png_voidp error_ptr;
@@ -963,16 +1014,19 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->gamma_from_1);
png_free(png_ptr, png_ptr->gamma_to_1);
#endif
if (png_ptr->flags & PNG_FLAG_FREE_PALETTE)
if (png_ptr->free_me & PNG_FREE_PLTE)
png_zfree(png_ptr, png_ptr->palette);
png_ptr->free_me &= ~PNG_FREE_PLTE;
#if defined(PNG_tRNS_SUPPORTED) || \
defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
if (png_ptr->flags & PNG_FLAG_FREE_TRANS)
if (png_ptr->free_me & PNG_FREE_TRNS)
png_free(png_ptr, png_ptr->trans);
png_ptr->free_me &= ~PNG_FREE_TRNS;
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
if (png_ptr->flags & PNG_FLAG_FREE_HIST)
if (png_ptr->free_me & PNG_FREE_HIST)
png_free(png_ptr, png_ptr->hist);
png_ptr->free_me &= ~PNG_FREE_HIST;
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
if (png_ptr->gamma_16_table != NULL)
@@ -1020,7 +1074,9 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
/* Save the important info out of the png_struct, in case it is
* being used again.
*/
#ifdef PNG_SETJMP_SUPPORTED
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
#endif
error_fn = png_ptr->error_fn;
warning_fn = png_ptr->warning_fn;
@@ -1038,7 +1094,10 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_ptr->free_fn = free_fn;
#endif
#ifdef PNG_SETJMP_SUPPORTED
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
#endif
}
void
@@ -1046,3 +1105,138 @@ png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
{
png_ptr->read_row_fn = read_row_fn;
}
#if defined(PNG_INFO_IMAGE_SUPPORTED)
void png_read_png(png_structp png_ptr, png_infop info_ptr,
int transforms,
voidp params)
{
int row;
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
/* invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
png_set_invert_alpha(png_ptr);
#endif
/* The call to png_read_info() gives us all of the information from the
* PNG file before the first IDAT (image data chunk).
*/
png_read_info(png_ptr, info_ptr);
/* -------------- image transformations start here ------------------- */
#if defined(PNG_READ_16_TO_8_SUPPORTED)
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
if (transforms & PNG_TRANSFORM_STRIP_16)
png_set_strip_16(png_ptr);
#endif
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
/* Strip alpha bytes from the input data without combining with the
* background (not recommended).
*/
if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
png_set_strip_alpha(png_ptr);
#endif
#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
if (transforms & PNG_TRANSFORM_PACKING)
png_set_packing(png_ptr);
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
/* Change the order of packed pixels to least significant bit first
* (not useful if you are using png_set_packing). */
if (transforms & PNG_TRANSFORM_PACKSWAP)
png_set_packswap(png_ptr);
#endif
#if defined(PNG_READ_EXPAND_SUPPORTED)
/* Expand paletted colors into true RGB triplets
* Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
* Expand paletted or RGB images with transparency to full alpha
* channels so the data will be available as RGBA quartets.
*/
if (transforms & PNG_TRANSFORM_EXPAND)
if ((png_ptr->bit_depth < 8) ||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
png_set_expand(png_ptr);
#endif
/* We don't handle background color or gamma transformation or dithering. */
#if defined(PNG_READ_INVERT_SUPPORTED)
/* invert monochrome files to have 0 as white and 1 as black */
if (transforms & PNG_TRANSFORM_INVERT_MONO)
png_set_invert_mono(png_ptr);
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED)
/* If you want to shift the pixel values from the range [0,255] or
* [0,65535] to the original [0,7] or [0,31], or whatever range the
* colors were originally in:
*/
if ((transforms & PNG_TRANSFORM_SHIFT)
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
{
png_color_8p sig_bit;
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
png_set_shift(png_ptr, sig_bit);
}
#endif
#if defined(PNG_READ_BGR_SUPPORTED)
/* flip the RGB pixels to BGR (or RGBA to BGRA) */
if (transforms & PNG_TRANSFORM_BGR)
png_set_bgr(png_ptr);
#endif
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
/* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
png_set_swap_alpha(png_ptr);
#endif
#if defined(PNG_READ_SWAP_SUPPORTED)
/* swap bytes of 16 bit files to least significant byte first */
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
png_set_swap(png_ptr);
#endif
/* We don't handle adding filler bytes */
/* Optional call to gamma correct and add the background to the palette
* and update info structure. REQUIRED if you are expecting libpng to
* update the palette for you (ie you selected such a transform above).
*/
png_read_update_info(png_ptr, info_ptr);
/* -------------- image transformations end here ------------------- */
if(info_ptr->row_pointers == NULL)
{
info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
info_ptr->height * sizeof(png_bytep));
info_ptr->free_me |= PNG_FREE_ROWS;
}
for (row = 0; row < (int)info_ptr->height; row++)
info_ptr->row_pointers[row] = png_malloc(png_ptr,
png_get_rowbytes(png_ptr, info_ptr));
png_read_image(png_ptr, info_ptr->row_pointers);
info_ptr->valid |= PNG_INFO_IDAT;
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
if(transforms == 0 || params == (voidp)NULL)
/* quiet compiler warnings */ return;
}
#endif

View File

@@ -1,11 +1,11 @@
/* pngrio.c - functions for data input
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
* This file provides a location for all input. Users who need
* special handling are expected to write a function that has the same

View File

@@ -1,11 +1,11 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
* This file contains functions optionally called by an application
* in order to tell libpng how to handle data when reading a PNG.
@@ -367,7 +367,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
{
int j, next_j;
if (num_new_palette & 1)
if (num_new_palette & 0x01)
{
j = p->left;
next_j = p->right;
@@ -582,14 +582,25 @@ png_set_gray_to_rgb(png_structp png_ptr)
}
#endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) && \
defined(PNG_FLOATING_POINT_SUPPORTED)
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
#if defined(PNG_FLOATING_POINT_SUPPORTED)
/* Convert a RGB image to a grayscale of the same width. This allows us,
* for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image.
*/
void
png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
double green)
double green)
{
int red_fixed = (int)((float)red*100000.0 + 0.5);
int green_fixed = (int)((float)green*100000.0 + 0.5);
png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
}
#endif
void
png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
png_fixed_point red, png_fixed_point green)
{
png_debug(1, "in png_set_rgb_to_gray\n");
switch(error_action)
@@ -610,22 +621,26 @@ png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
}
#endif
{
png_byte red_byte = (png_byte)((float)red*255.0 + 0.5);
png_byte green_byte = (png_byte)((float)green*255.0 + 0.5);
if(red < 0.0 || green < 0.0)
png_uint_16 red_int, green_int;
if(red > 0 && green > 0)
{
red_byte = 54;
green_byte = 183;
red_int = 6968; /* .212671 * 32768 + .5 */
green_int = 23434; /* .715160 * 32768 + .5 */
}
else if(red_byte + green_byte > 255)
else if(red + green < 100000L)
{
red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
}
else
{
png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
red_byte = 54;
green_byte = 183;
red_int = 6968;
green_int = 23434;
}
png_ptr->rgb_to_gray_red_coeff = red_byte;
png_ptr->rgb_to_gray_green_coeff = green_byte;
png_ptr->rgb_to_gray_blue_coeff = (png_byte)(255-red_byte-green_byte);
png_ptr->rgb_to_gray_red_coeff = red_int;
png_ptr->rgb_to_gray_green_coeff = green_int;
png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
}
}
#endif
@@ -658,7 +673,8 @@ png_init_read_transformations(png_structp png_ptr)
#endif
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
if (png_ptr->transformations & PNG_BACKGROUND_EXPAND)
if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
(png_ptr->transformations & PNG_EXPAND))
{
if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
{
@@ -897,8 +913,8 @@ png_init_read_transformations(png_structp png_ptr)
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
/* No GAMMA transformation */
if (png_ptr->transformations & PNG_BACKGROUND &&
color_type == PNG_COLOR_TYPE_PALETTE)
if ((png_ptr->transformations & PNG_BACKGROUND) &&
(color_type == PNG_COLOR_TYPE_PALETTE))
{
int i;
int istop = (int)png_ptr->num_trans;
@@ -931,7 +947,7 @@ png_init_read_transformations(png_structp png_ptr)
#if defined(PNG_READ_SHIFT_SUPPORTED)
if ((png_ptr->transformations & PNG_SHIFT) &&
color_type == PNG_COLOR_TYPE_PALETTE)
(color_type == PNG_COLOR_TYPE_PALETTE))
{
png_uint_16 i;
png_uint_16 istop = png_ptr->num_palette;
@@ -1009,7 +1025,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
#endif
#if defined(PNG_READ_16_TO_8_SUPPORTED)
if ((png_ptr->transformations & PNG_16_TO_8) && info_ptr->bit_depth == 16)
if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
info_ptr->bit_depth = 8;
#endif
@@ -1026,7 +1042,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
#endif
#if defined(PNG_READ_PACK_SUPPORTED)
if ((png_ptr->transformations & PNG_PACK) && info_ptr->bit_depth < 8)
if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
info_ptr->bit_depth = 8;
#endif
@@ -1057,9 +1073,9 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
#if defined(PNG_READ_FILLER_SUPPORTED)
/* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */
if (png_ptr->transformations & PNG_FILLER &&
(info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
info_ptr->color_type == PNG_COLOR_TYPE_GRAY))
if ((png_ptr->transformations & PNG_FILLER) &&
((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
(info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
info_ptr->channels++;
#endif
@@ -1177,7 +1193,7 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
/* if gray -> RGB, do so now only if background is non-gray; else do later
* for performance reasons */
if (png_ptr->transformations & PNG_GRAY_TO_RGB &&
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
!(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
@@ -1251,8 +1267,8 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
/* if gray -> RGB, do so now only if we did not do so above */
if (png_ptr->transformations & PNG_GRAY_TO_RGB &&
png_ptr->mode & PNG_BACKGROUND_IS_GRAY)
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
@@ -1330,10 +1346,10 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
{
png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
png_bytep dp = row + (png_size_t)row_width - 1;
png_uint_32 shift = 7 - (int)((row_width + 7) & 7);
png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0x1);
*dp = (png_byte)((*sp >> shift) & 0x01);
if (shift == 7)
{
shift = 0;
@@ -1351,10 +1367,10 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
png_bytep dp = row + (png_size_t)row_width - 1;
png_uint_32 shift = (int)((3 - ((row_width + 3) & 3)) << 1);
png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0x3);
*dp = (png_byte)((*sp >> shift) & 0x03);
if (shift == 6)
{
shift = 0;
@@ -1371,10 +1387,10 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
{
png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
png_bytep dp = row + (png_size_t)row_width - 1;
png_uint_32 shift = (int)((1 - ((row_width + 1) & 1)) << 2);
png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
for (i = 0; i < row_width; i++)
{
*dp = (png_byte)((*sp >> shift) & 0xf);
*dp = (png_byte)((*sp >> shift) & 0x0f);
if (shift == 4)
{
shift = 0;
@@ -1674,9 +1690,15 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
for (i = 0; i < row_width; i++)
{
*(--dp) = (png_byte)(255 - *(--sp));
/* This does nothing:
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
We can replace it with:
*/
sp-=3;
dp=sp;
}
}
/* This inverts the alpha channel in RRGGBBAA */
@@ -1690,12 +1712,18 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
{
*(--dp) = (png_byte)(255 - *(--sp));
*(--dp) = (png_byte)(255 - *(--sp));
/* This does nothing:
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
We can replace it with:
*/
sp-=6;
dp=sp;
}
}
}
@@ -1725,8 +1753,12 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
{
*(--dp) = (png_byte)(255 - *(--sp));
*(--dp) = (png_byte)(255 - *(--sp));
/*
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*/
sp-=2;
dp=sp;
}
}
}
@@ -2004,11 +2036,11 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
*
* We approximate this with
*
* Y = 0.211 * R + 0.715 * G + 0.074 * B
* Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
*
* which can be expressed with integers as
*
* Y = (54 * R + 183 * G + 19 * B)/256
* Y = (6969 * R + 23434 * G + 2365 * B)/32768
*
* The calculation is to be done in a linear colorspace.
*
@@ -2030,9 +2062,9 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
#endif
(row_info->color_type & PNG_COLOR_MASK_COLOR))
{
png_byte rc = png_ptr->rgb_to_gray_red_coeff;
png_byte gc = png_ptr->rgb_to_gray_green_coeff;
png_byte bc = png_ptr->rgb_to_gray_blue_coeff;
png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
{
@@ -2053,7 +2085,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
{
rgb_error |= 1;
*(dp++) = png_ptr->gamma_from_1[
(rc*red+gc*green+bc*blue)>>8];
(rc*red+gc*green+bc*blue)>>15];
}
else
*(dp++) = *(sp-1);
@@ -2072,7 +2104,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
if(red != green || red != blue)
{
rgb_error |= 1;
*(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>8);
*(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
}
else
*(dp++) = *(sp-1);
@@ -2107,7 +2139,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
png_ptr->gamma_shift][blue>>8];
png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
+ bc*blue_1)>>8);
+ bc*blue_1)>>15);
w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
png_ptr->gamma_shift][gray16 >> 8];
rgb_error |= 1;
@@ -2132,7 +2164,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
if(red != green || red != blue)
rgb_error |= 1;
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>8);
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
*(dp++) = (png_byte)((gray16>>8) & 0xff);
*(dp++) = (png_byte)(gray16 & 0xff);
}
@@ -2156,7 +2188,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
if(red != green || red != blue)
rgb_error |= 1;
*(dp++) = png_ptr->gamma_from_1
[(rc*red + gc*green + bc*blue)>>8];
[(rc*red + gc*green + bc*blue)>>15];
*(dp++) = *(sp++); /* alpha */
}
}
@@ -2204,7 +2236,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
png_ptr->gamma_shift][blue>>8];
png_uint_16 gray16 = (png_uint_16)((rc * red_1
+ gc * green_1 + bc * blue_1)>>8);
+ gc * green_1 + bc * blue_1)>>15);
w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
png_ptr->gamma_shift][gray16 >> 8];
rgb_error |= 1;
@@ -2229,7 +2261,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
if(red != green || red != blue)
rgb_error |= 1;
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>8);
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
*(dp++) = (png_byte)((gray16>>8) & 0xff);
*(dp++) = (png_byte)(gray16 & 0xff);
*(dp++) = *(sp++); /* alpha */
@@ -2518,7 +2550,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
shift = 7;
for (i = 0; i < row_width; i++)
{
if ((png_uint_16)((*sp >> shift) & 0x1)
if ((png_uint_16)((*sp >> shift) & 0x01)
== trans_values->gray)
{
*sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
@@ -2543,7 +2575,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
shift = 6;
for (i = 0; i < row_width; i++)
{
if ((png_uint_16)((*sp >> shift) & 0x3)
if ((png_uint_16)((*sp >> shift) & 0x03)
== trans_values->gray)
{
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
@@ -2551,9 +2583,9 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
else
{
png_byte p = (png_byte)((*sp >> shift) & 0x3);
png_byte p = (png_byte)((*sp >> shift) & 0x03);
png_byte g = (png_byte)((gamma_table [p | (p << 2) |
(p << 4) | (p << 6)] >> 6) & 0x3);
(p << 4) | (p << 6)] >> 6) & 0x03);
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
*sp |= (png_byte)(g << shift);
}
@@ -2573,7 +2605,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
shift = 6;
for (i = 0; i < row_width; i++)
{
if ((png_uint_16)((*sp >> shift) & 0x3)
if ((png_uint_16)((*sp >> shift) & 0x03)
== trans_values->gray)
{
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
@@ -2599,7 +2631,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
shift = 4;
for (i = 0; i < row_width; i++)
{
if ((png_uint_16)((*sp >> shift) & 0xf)
if ((png_uint_16)((*sp >> shift) & 0x0f)
== trans_values->gray)
{
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
@@ -2607,9 +2639,9 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
else
{
png_byte p = (png_byte)((*sp >> shift) & 0xf);
png_byte p = (png_byte)((*sp >> shift) & 0x0f);
png_byte g = (png_byte)((gamma_table[p |
(p << 4)] >> 4) & 0xf);
(p << 4)] >> 4) & 0x0f);
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
*sp |= (png_byte)(g << shift);
}
@@ -2629,7 +2661,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
shift = 4;
for (i = 0; i < row_width; i++)
{
if ((png_uint_16)((*sp >> shift) & 0xf)
if ((png_uint_16)((*sp >> shift) & 0x0f)
== trans_values->gray)
{
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
@@ -3362,10 +3394,10 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
{
sp = row + (png_size_t)((row_width - 1) >> 3);
dp = row + (png_size_t)row_width - 1;
shift = 7 - (int)((row_width + 7) & 7);
shift = 7 - (int)((row_width + 7) & 0x07);
for (i = 0; i < row_width; i++)
{
if ((*sp >> shift) & 0x1)
if ((*sp >> shift) & 0x01)
*dp = 1;
else
*dp = 0;
@@ -3385,10 +3417,10 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
{
sp = row + (png_size_t)((row_width - 1) >> 2);
dp = row + (png_size_t)row_width - 1;
shift = (int)((3 - ((row_width + 3) & 3)) << 1);
shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
for (i = 0; i < row_width; i++)
{
value = (*sp >> shift) & 0x3;
value = (*sp >> shift) & 0x03;
*dp = (png_byte)value;
if (shift == 6)
{
@@ -3406,10 +3438,10 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
{
sp = row + (png_size_t)((row_width - 1) >> 1);
dp = row + (png_size_t)row_width - 1;
shift = (int)((row_width & 1) << 2);
shift = (int)((row_width & 0x01) << 2);
for (i = 0; i < row_width; i++)
{
value = (*sp >> shift) & 0xf;
value = (*sp >> shift) & 0x0f;
*dp = (png_byte)value;
if (shift == 4)
{
@@ -3508,10 +3540,10 @@ png_do_expand(png_row_infop row_info, png_bytep row,
gray = (png_uint_16)(gray*0xff);
sp = row + (png_size_t)((row_width - 1) >> 3);
dp = row + (png_size_t)row_width - 1;
shift = 7 - (int)((row_width + 7) & 7);
shift = 7 - (int)((row_width + 7) & 0x07);
for (i = 0; i < row_width; i++)
{
if ((*sp >> shift) & 0x1)
if ((*sp >> shift) & 0x01)
*dp = 0xff;
else
*dp = 0;
@@ -3532,10 +3564,10 @@ png_do_expand(png_row_infop row_info, png_bytep row,
gray = (png_uint_16)(gray*0x55);
sp = row + (png_size_t)((row_width - 1) >> 2);
dp = row + (png_size_t)row_width - 1;
shift = (int)((3 - ((row_width + 3) & 3)) << 1);
shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
for (i = 0; i < row_width; i++)
{
value = (*sp >> shift) & 0x3;
value = (*sp >> shift) & 0x03;
*dp = (png_byte)(value | (value << 2) | (value << 4) |
(value << 6));
if (shift == 6)
@@ -3555,10 +3587,10 @@ png_do_expand(png_row_infop row_info, png_bytep row,
gray = (png_uint_16)(gray*0x11);
sp = row + (png_size_t)((row_width - 1) >> 1);
dp = row + (png_size_t)row_width - 1;
shift = (int)((1 - ((row_width + 1) & 1)) << 2);
shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
for (i = 0; i < row_width; i++)
{
value = (*sp >> shift) & 0xf;
value = (*sp >> shift) & 0x0f;
*dp = (png_byte)(value | (value << 4));
if (shift == 4)
{
@@ -3809,7 +3841,7 @@ png_build_gamma_table(png_structp png_ptr)
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
{
g = 1.0 / (png_ptr->gamma);

View File

@@ -1,11 +1,11 @@
/* pngrutil.c - utilities to read a PNG file
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
* This file contains routines that are only called from within
* libpng itself during the course of reading an image.
@@ -14,10 +14,6 @@
#define PNG_INTERNAL
#include "png.h"
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
#include "pngasmrd.h"
#endif
#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
png_uint_32
@@ -31,7 +27,7 @@ png_get_uint_32(png_bytep buf)
return (i);
}
#if defined(PNG_READ_pCAL_SUPPORTED)
#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_oFFs_SUPPORTED)
/* Grab a signed 32-bit integer from a buffer in big-endian format. The
* data is stored in the PNG file in two's complement format, and it is
* assumed that the machine format for signed integers is the same. */
@@ -87,10 +83,10 @@ png_crc_finish(png_structp png_ptr, png_uint_32 skip)
if (png_crc_error(png_ptr))
{
if ((png_ptr->chunk_name[0] & 0x20 && /* Ancillary */
if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
(!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))
(png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
{
png_chunk_warning(png_ptr, "CRC error");
}
@@ -151,7 +147,7 @@ png_charp png_decompress_chunk(png_structp png_ptr, int comp_type,
{
static char msg[] = "Error decoding compressed text";
png_charp text = NULL;
png_size_t text_size = (chunklength - prefix_size);
png_size_t text_size;
if (comp_type == PNG_TEXT_COMPRESSION_zTXt)
{
@@ -266,7 +262,7 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_IHDR\n");
if (png_ptr->mode != PNG_BEFORE_IHDR)
if (png_ptr->mode & PNG_HAVE_IHDR)
png_error(png_ptr, "Out of place IHDR");
/* check the length */
@@ -398,7 +394,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
num = (int)length / 3;
palette = (png_colorp)png_zalloc(png_ptr, (uInt)num, sizeof (png_color));
png_ptr->flags |= PNG_FLAG_FREE_PALETTE;
png_ptr->free_me |= PNG_FREE_PLTE;
for (i = 0; i < num; i++)
{
png_byte buf[3];
@@ -436,7 +432,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
else
{
png_chunk_warning(png_ptr, "CRC error");
png_ptr->flags &= ~PNG_FLAG_FREE_PALETTE;
png_ptr->free_me &= ~PNG_FREE_PLTE;
png_zfree(png_ptr, palette);
return;
}
@@ -455,7 +451,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#if defined (PNG_READ_tRNS_SUPPORTED)
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
{
if (png_ptr->num_trans > png_ptr->num_palette)
{
@@ -482,7 +478,7 @@ png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
return;
}
png_ptr->mode |= PNG_AFTER_IDAT | PNG_HAVE_IEND;
png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
if (length != 0)
{
@@ -515,7 +511,7 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Should be an error, but we can cope with it */
png_warning(png_ptr, "Out of place gAMA chunk");
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_gAMA
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
#if defined(PNG_READ_sRGB_SUPPORTED)
&& !(info_ptr->valid & PNG_INFO_sRGB)
#endif
@@ -549,7 +545,7 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_warning(png_ptr,
"Ignoring incorrect gAMA value when sRGB is also present");
#ifndef PNG_NO_CONSOLE_IO
fprintf(stderr, "igamma = %lu\n", igamma);
fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
#endif
return;
}
@@ -557,10 +553,10 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#ifdef PNG_FLOATING_POINT_SUPPORTED
file_gamma = (float)igamma / (float)100000.0;
#ifdef PNG_READ_GAMMA_SUPPORTED
png_ptr->gamma = file_gamma;
#endif
png_set_gAMA(png_ptr, info_ptr, file_gamma);
# ifdef PNG_READ_GAMMA_SUPPORTED
png_ptr->gamma = file_gamma;
# endif
png_set_gAMA(png_ptr, info_ptr, file_gamma);
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
@@ -592,7 +588,7 @@ png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Should be an error, but we can cope with it */
png_warning(png_ptr, "Out of place sBIT chunk");
}
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT)
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
{
png_warning(png_ptr, "Duplicate sBIT chunk");
png_crc_finish(png_ptr, length);
@@ -648,7 +644,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_cHRM\n");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before sBIT");
png_error(png_ptr, "Missing IHDR before cHRM");
else if (png_ptr->mode & PNG_HAVE_IDAT)
{
png_warning(png_ptr, "Invalid cHRM after IDAT");
@@ -659,7 +655,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Should be an error, but we can cope with it */
png_warning(png_ptr, "Missing PLTE before cHRM");
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_cHRM
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
#if defined(PNG_READ_sRGB_SUPPORTED)
&& !(info_ptr->valid & PNG_INFO_sRGB)
#endif
@@ -796,9 +792,6 @@ void
png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
int intent;
#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
int igamma;
#endif
png_byte buf[1];
png_debug(1, "in png_handle_sRGB\n");
@@ -815,7 +808,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Should be an error, but we can cope with it */
png_warning(png_ptr, "Out of place sRGB chunk");
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sRGB)
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
{
png_warning(png_ptr, "Duplicate sRGB chunk");
png_crc_finish(png_ptr, length);
@@ -842,26 +835,31 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
igamma=png_ptr->gamma * 100000.;
if ((info_ptr->valid & PNG_INFO_gAMA))
{
int igamma;
#ifdef PNG_FIXED_POINT_SUPPORTED
igamma=(int)info_ptr->int_gamma;
#else
# ifdef PNG_FIXED_POINT_SUPPORTED
igamma=(int)png_ptr->int_gamma;
# ifdef PNG_FLOATING_POINT_SUPPORTED
igamma=info_ptr->gamma * 100000.;
# endif
#endif
if ((info_ptr->valid & PNG_INFO_gAMA))
if(igamma < 45000L || igamma > 46000L)
{
png_warning(png_ptr,
"Ignoring incorrect gAMA value when sRGB is also present");
#ifndef PNG_NO_CONSOLE_IO
#ifdef PNG_FLOATING_POINT_SUPPORTED
fprintf(stderr,"gamma=%f\n",png_ptr->gamma);
#else
fprintf(stderr,"gamma=(%lu/100000)\n",png_ptr->int_gamma);
#endif
# ifdef PNG_FIXED_POINT_SUPPORTED
fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
# else
# ifdef PNG_FLOATING_POINT_SUPPORTED
fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
# endif
# endif
#endif
}
}
#endif /* PNG_READ_gAMA_SUPPORTED */
#ifdef PNG_READ_cHRM_SUPPORTED
@@ -909,7 +907,7 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Should be an error, but we can cope with it */
png_warning(png_ptr, "Out of place iCCP chunk");
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_iCCP)
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
{
png_warning(png_ptr, "Duplicate iCCP chunk");
png_crc_finish(png_ptr, length);
@@ -926,6 +924,7 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif
chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
png_ptr->free_me |= PNG_FREE_ICCP;
slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
@@ -969,7 +968,7 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_bytep chunkdata;
png_bytep entry_start;
png_spalette new_palette;
png_sPLT_t new_palette;
int data_length, entry_size, i;
png_uint_32 skip = 0;
png_size_t slength;
@@ -984,16 +983,6 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, length);
return;
}
else if (png_ptr->mode & PNG_HAVE_PLTE)
/* Should be an error, but we can cope with it */
png_warning(png_ptr, "Out of place sPLT chunk");
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sPLT)
{
png_warning(png_ptr, "Duplicate sPLT chunk");
png_crc_finish(png_ptr, length);
return;
}
#ifdef PNG_MAX_MALLOC_64K
if (length > (png_uint_32)65535L)
@@ -1039,12 +1028,12 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
new_palette.nentries = data_length / entry_size;
new_palette.entries = (png_spalette_entryp)png_malloc(
png_ptr, new_palette.nentries * sizeof(png_spalette_entry));
new_palette.entries = (png_sPLT_entryp)png_malloc(
png_ptr, new_palette.nentries * sizeof(png_sPLT_entry));
for (i = 0; i < new_palette.nentries; i++)
{
png_spalette_entryp pp = new_palette.entries + i;
png_sPLT_entryp pp = new_palette.entries + i;
if (new_palette.depth == 8)
{
@@ -1066,7 +1055,7 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* discard all chunk data except the name and stash that */
new_palette.name = (png_charp)chunkdata;
png_set_spalettes(png_ptr, info_ptr, &new_palette, 1);
png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
png_free(png_ptr, chunkdata);
png_free(png_ptr, new_palette.entries);
@@ -1087,7 +1076,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, length);
return;
}
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
{
png_warning(png_ptr, "Duplicate tRNS chunk");
png_crc_finish(png_ptr, length);
@@ -1101,7 +1090,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Should be an error, but we can cope with it */
png_warning(png_ptr, "Missing PLTE before tRNS");
}
else if (length > png_ptr->num_palette)
else if (length > (png_uint_32)png_ptr->num_palette)
{
png_warning(png_ptr, "Incorrect tRNS chunk length");
png_crc_finish(png_ptr, length);
@@ -1115,7 +1104,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
png_ptr->trans = (png_bytep)png_malloc(png_ptr, length);
png_ptr->flags |= PNG_FLAG_FREE_TRANS;
png_ptr->free_me |= PNG_FREE_TRNS;
png_crc_read(png_ptr, png_ptr->trans, (png_size_t)length);
png_ptr->num_trans = (png_uint_16)length;
}
@@ -1190,7 +1179,7 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, length);
return;
}
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_bKGD)
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
{
png_warning(png_ptr, "Duplicate bKGD chunk");
png_crc_finish(png_ptr, length);
@@ -1278,7 +1267,7 @@ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, length);
return;
}
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_hIST)
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
{
png_warning(png_ptr, "Duplicate hIST chunk");
png_crc_finish(png_ptr, length);
@@ -1295,7 +1284,7 @@ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
num = (int)length / 2 ;
png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(num * sizeof (png_uint_16)));
png_ptr->flags |= PNG_FLAG_FREE_HIST;
png_ptr->free_me |= PNG_FREE_HIST;
for (i = 0; i < num; i++)
{
png_byte buf[2];
@@ -1329,7 +1318,7 @@ png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, length);
return;
}
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
{
png_warning(png_ptr, "Duplicate pHYS chunk");
png_crc_finish(png_ptr, length);
@@ -1372,7 +1361,7 @@ png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, length);
return;
}
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_oFFs)
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
{
png_warning(png_ptr, "Duplicate oFFs chunk");
png_crc_finish(png_ptr, length);
@@ -1420,7 +1409,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, length);
return;
}
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL)
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
{
png_warning(png_ptr, "Duplicate pCAL chunk");
png_crc_finish(png_ptr, length);
@@ -1521,7 +1510,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_charp buffer, ep;
#ifdef PNG_FLOATING_POINT_SUPPORTED
double width=0., height=0.;
double width, height;
png_charp vp;
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
@@ -1540,7 +1529,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, length);
return;
}
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sCAL)
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
{
png_warning(png_ptr, "Duplicate sCAL chunk");
png_crc_finish(png_ptr, length);
@@ -1561,7 +1550,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
buffer[slength] = 0x00; /* null terminate the last string */
ep = buffer + 1; /* skip unit byte */
ep = buffer + 1; /* skip unit byte */
#ifdef PNG_FLOATING_POINT_SUPPORTED
width = strtod(ep, &vp);
@@ -1597,7 +1586,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_warning(png_ptr, "Invalid sCAL data");
png_free(png_ptr, buffer);
#if defined(PNG_FIXED_POINT_SUPPORTED)&& !defined(PNG_FLOATING_POINT_SUPPORTED)
#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
png_free(png_ptr, swidth);
png_free(png_ptr, sheight);
#endif
@@ -1614,7 +1603,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif
png_free(png_ptr, buffer);
#if defined(PNG_FIXED_POINT_SUPPORTED)&& !defined(PNG_FLOATING_POINT_SUPPORTED)
#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
png_free(png_ptr, swidth);
png_free(png_ptr, sheight);
#endif
@@ -1632,7 +1621,7 @@ png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Out of place tIME chunk");
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME)
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
{
png_warning(png_ptr, "Duplicate tIME chunk");
png_crc_finish(png_ptr, length);
@@ -1734,7 +1723,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_textp text_ptr;
png_charp chunkdata;
png_charp text;
int comp_type = PNG_TEXT_COMPRESSION_NONE;
int comp_type;
png_size_t slength, prefix_len;
png_debug(1, "in png_handle_zTXt\n");
@@ -1809,7 +1798,7 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_textp text_ptr;
png_charp chunkdata;
png_charp key, lang, text, lang_key;
int comp_flag = PNG_TEXT_COMPRESSION_NONE;
int comp_flag;
int comp_type = 0;
png_size_t slength, prefix_len;
@@ -1905,21 +1894,25 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug(1, "in png_handle_unknown\n");
if (png_ptr->mode & PNG_HAVE_IDAT)
png_ptr->mode |= PNG_AFTER_IDAT;
{
#ifdef PNG_USE_LOCAL_ARRAYS
PNG_IDAT;
#endif
if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
png_ptr->mode |= PNG_AFTER_IDAT;
}
/* In the future we can have code here that calls user-supplied
* callback functions for unknown chunks before they are ignored or
* cause an error.
*/
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
if (!(png_ptr->chunk_name[0] & 0x20))
{
png_chunk_error(png_ptr, "unknown critical chunk");
/* to quiet compiler warnings about unused info_ptr */
if (info_ptr == NULL)
return;
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
HANDLE_CHUNK_ALWAYS
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
&& png_ptr->read_user_chunk_fn == (png_user_chunk_ptr)NULL
#endif
)
png_chunk_error(png_ptr, "unknown critical chunk");
}
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
@@ -1927,7 +1920,6 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_unknown_chunk chunk;
#ifdef PNG_MAX_MALLOC_64K
if (length > (png_uint_32)65535L)
{
@@ -1936,19 +1928,38 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
length = (png_uint_32)65535L;
}
#endif
strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_crc_read(png_ptr, chunk.data, length);
chunk.size = length;
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
if(png_ptr->read_user_chunk_fn != (png_user_chunk_ptr)NULL)
{
/* callback to user unknown chunk handler */
if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0)
{
if (!(png_ptr->chunk_name[0] & 0x20))
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
HANDLE_CHUNK_ALWAYS)
png_chunk_error(png_ptr, "unknown critical chunk");
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
}
}
else
#endif
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
png_free(png_ptr, chunk.data);
}
else
#endif
skip = length;
skip = length;
png_crc_finish(png_ptr, skip);
#if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
if (info_ptr == NULL)
/* quiet compiler warnings about unused info_ptr */ ;
#endif
}
/* This function is called to verify that a chunk name is valid.
@@ -2032,7 +2043,7 @@ png_combine_row
{
int value;
value = (*sp >> shift) & 0x1;
value = (*sp >> shift) & 0x01;
*dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
*dp |= (png_byte)(value << shift);
}
@@ -2085,7 +2096,7 @@ png_combine_row
{
if (m & mask)
{
value = (*sp >> shift) & 0x3;
value = (*sp >> shift) & 0x03;
*dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
*dp |= (png_byte)(value << shift);
}
@@ -2227,8 +2238,8 @@ png_do_read_interlace
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP)
{
sshift = (int)((row_info->width + 7) & 7);
dshift = (int)((final_width + 7) & 7);
sshift = (int)((row_info->width + 7) & 0x07);
dshift = (int)((final_width + 7) & 0x07);
s_start = 7;
s_end = 0;
s_inc = -1;
@@ -2236,8 +2247,8 @@ png_do_read_interlace
else
#endif
{
sshift = 7 - (int)((row_info->width + 7) & 7);
dshift = 7 - (int)((final_width + 7) & 7);
sshift = 7 - (int)((row_info->width + 7) & 0x07);
dshift = 7 - (int)((final_width + 7) & 0x07);
s_start = 0;
s_end = 7;
s_inc = 1;
@@ -2245,7 +2256,7 @@ png_do_read_interlace
for (i = 0; i < row_info->width; i++)
{
v = (png_byte)((*sp >> sshift) & 0x1);
v = (png_byte)((*sp >> sshift) & 0x01);
for (j = 0; j < jstop; j++)
{
*dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
@@ -2280,8 +2291,8 @@ png_do_read_interlace
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP)
{
sshift = (int)(((row_info->width + 3) & 3) << 1);
dshift = (int)(((final_width + 3) & 3) << 1);
sshift = (int)(((row_info->width + 3) & 0x03) << 1);
dshift = (int)(((final_width + 3) & 0x03) << 1);
s_start = 6;
s_end = 0;
s_inc = -2;
@@ -2289,8 +2300,8 @@ png_do_read_interlace
else
#endif
{
sshift = (int)((3 - ((row_info->width + 3) & 3)) << 1);
dshift = (int)((3 - ((final_width + 3) & 3)) << 1);
sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
s_start = 0;
s_end = 6;
s_inc = 2;
@@ -2301,7 +2312,7 @@ png_do_read_interlace
png_byte v;
int j;
v = (png_byte)((*sp >> sshift) & 0x3);
v = (png_byte)((*sp >> sshift) & 0x03);
for (j = 0; j < jstop; j++)
{
*dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
@@ -2336,8 +2347,8 @@ png_do_read_interlace
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
if (transformations & PNG_PACKSWAP)
{
sshift = (int)(((row_info->width + 1) & 1) << 2);
dshift = (int)(((final_width + 1) & 1) << 2);
sshift = (int)(((row_info->width + 1) & 0x01) << 2);
dshift = (int)(((final_width + 1) & 0x01) << 2);
s_start = 4;
s_end = 0;
s_inc = -4;
@@ -2345,8 +2356,8 @@ png_do_read_interlace
else
#endif
{
sshift = (int)((1 - ((row_info->width + 1) & 1)) << 2);
dshift = (int)((1 - ((final_width + 1) & 1)) << 2);
sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
s_start = 0;
s_end = 4;
s_inc = 4;
@@ -2788,7 +2799,14 @@ png_read_start_row(png_structp png_ptr)
else
{
if (max_pixel_depth <= 8)
max_pixel_depth = 24;
{
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
max_pixel_depth = 32;
else
max_pixel_depth = 24;
}
else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
max_pixel_depth = 64;
else
max_pixel_depth = 48;
}

150
pngset.c
View File

@@ -1,11 +1,11 @@
/* pngset.c - storage of image information into info struct
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
* The functions here are used during reads to store data from the file
* into the info struct, and during writes to store application data
@@ -81,14 +81,14 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
info_ptr->int_x_blue = blue_x;
info_ptr->int_y_blue = blue_y;
#ifdef PNG_FLOATING_POINT_SUPPORTED
info_ptr->x_white = (float)white_x/100000.;
info_ptr->y_white = (float)white_y/100000.;
info_ptr->x_red = (float)red_x/100000.;
info_ptr->y_red = (float)red_y/100000.;
info_ptr->x_green = (float)green_x/100000.;
info_ptr->y_green = (float)green_y/100000.;
info_ptr->x_blue = (float)blue_x/100000.;
info_ptr->y_blue = (float)blue_y/100000.;
info_ptr->x_white = (float)(white_x/100000.);
info_ptr->y_white = (float)(white_y/100000.);
info_ptr->x_red = (float)(red_x/100000.);
info_ptr->y_red = (float)(red_y/100000.);
info_ptr->x_green = (float)(green_x/100000.);
info_ptr->y_green = (float)(green_y/100000.);
info_ptr->x_blue = (float)(blue_x/100000.);
info_ptr->y_blue = (float)(blue_y/100000.);
#endif
info_ptr->valid |= PNG_INFO_cHRM;
}
@@ -112,7 +112,6 @@ png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
}
#endif
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
void
png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
int_gamma)
@@ -122,12 +121,11 @@ png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
return;
#ifdef PNG_FLOATING_POINT_SUPPORTED
info_ptr->gamma = (float)int_gamma/100000.;
info_ptr->gamma = (float)(int_gamma/100000.);
#endif
info_ptr->int_gamma = int_gamma;
info_ptr->valid |= PNG_INFO_gAMA;
}
#endif
#if defined(PNG_hIST_SUPPORTED)
void
@@ -137,8 +135,7 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->hist = png_malloc(png_ptr, sizeof(png_uint_16) * info_ptr->num_palette);
memcpy(info_ptr->hist, hist, sizeof(png_uint_16) * info_ptr->num_palette);
info_ptr->hist = hist;
info_ptr->valid |= PNG_INFO_hIST;
}
#endif
@@ -310,11 +307,13 @@ void
png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
png_colorp palette, int num_palette)
{
png_debug1(1, "in %s storage function\n", "PLTE");
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->palette = palette;
info_ptr->num_palette = (png_uint_16)num_palette;
info_ptr->valid |= PNG_INFO_PLTE;
}
@@ -420,7 +419,7 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
void
png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
png_charp name, int compression_type,
png_charp profile, int proflen)
png_charp profile, png_uint_32 proflen)
{
png_debug1(1, "in %s storage function\n", "iCCP");
if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
@@ -429,11 +428,12 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
info_ptr->iccp_name = png_malloc(png_ptr, png_strlen(name)+1);
strcpy(info_ptr->iccp_name, name);
info_ptr->iccp_profile = png_malloc(png_ptr, proflen);
memcpy(info_ptr->iccp_profile, profile, proflen);
info_ptr->iccp_proflen = (png_uint_32)proflen;
png_memcpy(info_ptr->iccp_profile, profile, (png_size_t)proflen);
info_ptr->iccp_proflen = proflen;
/* Compression is always zero but is here so the API and info structure
* does not have to change * if we introduce multiple compression types */
info_ptr->iccp_compression = (png_byte)compression_type;
info_ptr->free_me |= PNG_FREE_ICCP;
info_ptr->valid |= PNG_INFO_iCCP;
}
#endif
@@ -519,8 +519,6 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
textp->key = (png_charp)png_malloc(png_ptr,
(png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4));
/* Caution: the calling program, not libpng, is responsible for
freeing this, if libpng wasn't the caller. */
png_debug2(2, "Allocated %d bytes at %x in png_set_text\n",
key_len + lang_len + lang_key_len + text_length + 4, textp->key);
@@ -566,6 +564,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
info_ptr->text[info_ptr->num_text]= *textp;
info_ptr->num_text++;
info_ptr->free_me |= PNG_FREE_TEXT;
png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
}
}
@@ -595,9 +594,7 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
return;
if (trans != NULL)
{
info_ptr->trans = trans;
}
if (trans_values != NULL)
{
@@ -613,38 +610,39 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
#if defined(PNG_sPLT_SUPPORTED)
void
png_set_spalettes(png_structp png_ptr,
png_infop info_ptr, png_spalette_p entries, int nentries)
png_set_sPLT(png_structp png_ptr,
png_infop info_ptr, png_sPLT_tp entries, int nentries)
{
png_spalette_p np;
png_sPLT_tp np;
int i;
np = (png_spalette_p)png_malloc(png_ptr,
(info_ptr->splt_palettes_num + nentries) * sizeof(png_spalette));
np = (png_sPLT_tp)png_malloc(png_ptr,
(info_ptr->splt_palettes_num + nentries) * sizeof(png_sPLT_t));
memcpy(np, info_ptr->splt_palettes,
info_ptr->splt_palettes_num * sizeof(png_spalette));
png_memcpy(np, info_ptr->splt_palettes,
info_ptr->splt_palettes_num * sizeof(png_sPLT_t));
png_free(png_ptr, info_ptr->splt_palettes);
for (i = 0; i < nentries; i++)
{
png_spalette_p to = np + info_ptr->splt_palettes_num + i;
png_spalette_p from = entries + i;
png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
png_sPLT_tp from = entries + i;
to->name = (png_charp)png_malloc(png_ptr,
png_strlen(from->name) + 1);
png_strcpy(to->name, from->name);
to->entries = (png_spalette_entryp)png_malloc(png_ptr,
from->nentries * sizeof(png_spalette));
memcpy(to->entries, from->entries,
from->nentries * sizeof(png_spalette));
to->nentries = from->nentries;
to->depth = from->depth;
to->entries = (png_sPLT_entryp)png_malloc(png_ptr,
from->nentries * sizeof(png_sPLT_t));
png_memcpy(to->entries, from->entries,
from->nentries * sizeof(png_sPLT_t));
to->nentries = from->nentries;
to->depth = from->depth;
}
info_ptr->splt_palettes = np;
info_ptr->splt_palettes_num += nentries;
info_ptr->valid |= PNG_INFO_sPLT;
info_ptr->free_me |= PNG_FREE_SPLT;
}
#endif /* PNG_sPLT_SUPPORTED */
@@ -663,7 +661,7 @@ png_set_unknown_chunks(png_structp png_ptr,
(info_ptr->unknown_chunks_num + num_unknowns) *
sizeof(png_unknown_chunk));
memcpy(np, info_ptr->unknown_chunks,
png_memcpy(np, info_ptr->unknown_chunks,
info_ptr->unknown_chunks_num * sizeof(png_unknown_chunk));
png_free(png_ptr, info_ptr->unknown_chunks);
@@ -674,7 +672,7 @@ png_set_unknown_chunks(png_structp png_ptr,
png_strcpy((png_charp)to->name, (png_charp)from->name);
to->data = (png_bytep)png_malloc(png_ptr, from->size);
memcpy(to->data, from->data, from->size);
png_memcpy(to->data, from->data, from->size);
to->size = from->size;
/* note our location in the read or write sequence */
@@ -683,10 +681,12 @@ png_set_unknown_chunks(png_structp png_ptr,
info_ptr->unknown_chunks = np;
info_ptr->unknown_chunks_num += num_unknowns;
info_ptr->free_me |= PNG_FREE_UNKN;
}
#endif
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED)
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
void
png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
{
@@ -699,43 +699,63 @@ png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
void
png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep chunk_list,
int num_chunks)
png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
chunk_list, int num_chunks)
{
/*
png_set_keep_unknown_chunks(png_ptr, keep, chunk_list,
num_chunks);
keep - 0: do not keep
1: keep only if safe-to-copy
2: keep even if unsafe-to-copy
The following are not yet implemented
in libpng version 1.0.5j:
chunk_list - list of chunks affected, NULL if
num_chunks is 0.
num_chunks - number of chunks affected. If 0, all
unknown chunks are affected.
*/
png_bytep new_list, p;
int i, old_num_chunks;
if (num_chunks == 0)
{
if(keep)
if(keep == HANDLE_CHUNK_ALWAYS || keep == HANDLE_CHUNK_IF_SAFE)
png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
else
png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
if(keep == 2)
if(keep == HANDLE_CHUNK_ALWAYS)
png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
else
png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
return;
}
else
if (chunk_list == NULL)
return;
old_num_chunks=png_ptr->num_chunk_list;
new_list=png_malloc(png_ptr,5*(num_chunks+old_num_chunks));
if(png_ptr->chunk_list != (png_bytep)NULL)
{
/* to do: set up chunk_list processing */
png_warning(png_ptr,
"chunk_list not yet implemented in png_set_keep_unknown_chunks");
if (chunk_list == NULL || num_chunks == 0)
/* do nothing right now */ ;
png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks);
png_free(png_ptr, png_ptr->chunk_list);
}
png_memcpy(new_list+5*old_num_chunks, chunk_list, 5*num_chunks);
for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
*p=(png_byte)keep;
png_ptr->num_chunk_list=old_num_chunks+num_chunks;
png_ptr->chunk_list=new_list;
png_ptr->free_me |= PNG_FREE_LIST;
}
#endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
void
png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
png_user_chunk_ptr read_user_chunk_fn)
{
png_debug(1, "in png_set_read_user_chunk_fn\n");
png_ptr->read_user_chunk_fn = read_user_chunk_fn;
png_ptr->user_chunk_ptr = user_chunk_ptr;
}
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED)
void
png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
{
png_debug1(1, "in %s storage function\n", "rows");
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->row_pointers = row_pointers;
info_ptr->free_me |= PNG_FREE_ROWS;
}
#endif

View File

@@ -1,11 +1,11 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*/
#define PNG_INTERNAL

View File

@@ -1,10 +1,10 @@
/* pngtypes.h - array of chunk-types for libpng
*
* libpng 1.0.5d - November 28, 1999
* libpng 1.0.5u - March 4, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*/
/* Constant strings for known chunk types. If you need to add a chunk,
@@ -19,10 +19,14 @@ PNG_bKGD;
PNG_cHRM;
PNG_gAMA;
PNG_hIST;
PNG_iCCP;
PNG_iTXt;
PNG_oFFs;
PNG_pCAL;
PNG_pHYs;
PNG_sBIT;
PNG_sCAL;
PNG_sPLT;
PNG_sRGB;
PNG_tEXt;
PNG_tIME;

View File

@@ -2,10 +2,10 @@
*
* For Intel x86 CPU and Microsoft Visual C++ compiler
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, Intel Corporation
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
* Contributed by Nirav Chhatrapati, Intel Corporation, 1998
* Interface to libpng contributed by Gilles Vollant, 1999
@@ -33,6 +33,9 @@ static int mmxsupport()
{
int mmx_supported_local = 0;
_asm {
push ebx //CPUID will trash these
push ecx
push edx
pushfd //Save Eflag to stack
pop eax //Get Eflag from stack into eax
mov ecx, eax //Make another copy of Eflag in ecx
@@ -70,7 +73,9 @@ static int mmxsupport()
NOT_SUPPORTED:
mov eax, mmx_supported_local //move return value to eax
pop edx //CPUID trashed these
pop ecx
pop ebx
}
//mmx_supported_local=0; // test code for force don't support MMX

View File

@@ -1,11 +1,11 @@
/* pngwio.c - functions for data output
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*
* This file provides a location for all output. Users who need
* special handling are expected to write functions that have the same

View File

@@ -1,11 +1,11 @@
/* pngwrite.c - general routines to write a PNG file
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*/
/* get internal access to png.h */
@@ -95,9 +95,11 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
up++)
{
if (up->location && (!(up->location & PNG_HAVE_PLTE)) &&
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS ||
up->name[3] & 0x20))
int keep=png_handle_as_unknown(png_ptr, up->name);
if (keep != HANDLE_CHUNK_NEVER &&
up->location && (!(up->location & PNG_HAVE_PLTE)) &&
((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS ||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
{
png_write_chunk(png_ptr, up->name, up->data, up->size);
}
@@ -130,7 +132,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
/* invert the alpha channel (in tRNS) */
if (png_ptr->transformations & PNG_INVERT_ALPHA &&
if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
int j;
@@ -253,10 +255,12 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
up++)
{
if (up->location && (up->location& PNG_HAVE_PLTE) &&
!(up->location& PNG_HAVE_IDAT) &&
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS ||
up->name[3] & 0x20))
int keep=png_handle_as_unknown(png_ptr, up->name);
if (keep != HANDLE_CHUNK_NEVER &&
up->location && (up->location & PNG_HAVE_PLTE) &&
!(up->location & PNG_HAVE_IDAT) &&
((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS ||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
{
png_write_chunk(png_ptr, up->name, up->data, up->size);
}
@@ -285,7 +289,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
#endif
#if defined(PNG_WRITE_tIME_SUPPORTED)
/* check to see if user has supplied a time chunk */
if (info_ptr->valid & PNG_INFO_tIME &&
if ((info_ptr->valid & PNG_INFO_tIME) &&
!(png_ptr->mode & PNG_WROTE_tIME))
png_write_tIME(png_ptr, &(info_ptr->mod_time));
#endif
@@ -351,9 +355,11 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
up++)
{
if ((up->location && (up->location & PNG_AFTER_IDAT)) &&
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS ||
up->name[3] & 0x20))
int keep=png_handle_as_unknown(png_ptr, up->name);
if (keep != HANDLE_CHUNK_NEVER &&
up->location && (up->location & PNG_AFTER_IDAT) &&
((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS ||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
{
png_write_chunk(png_ptr, up->name, up->data, up->size);
}
@@ -410,8 +416,10 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_structp png_ptr;
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
jmp_buf jmpbuf;
#endif
#endif
png_debug(1, "in png_create_write_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED
@@ -423,6 +431,8 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
{
return ((png_structp)NULL);
}
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
#else
@@ -436,6 +446,8 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#endif
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
#endif /* PNG_USER_MEM_SUPPORTED */
@@ -472,17 +484,23 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
void
png_write_init(png_structp png_ptr)
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* to save current jump buffer */
#endif
png_debug(1, "in png_write_init\n");
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
#endif
/* reset all variables to 0 */
png_memset(png_ptr, 0, sizeof (png_struct));
#ifdef PNG_SETJMP_SUPPORTED
/* restore jump buffer */
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
#endif
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
@@ -594,49 +612,49 @@ png_write_row(png_structp png_ptr, png_bytep row)
switch (png_ptr->pass)
{
case 0:
if (png_ptr->row_number & 7)
if (png_ptr->row_number & 0x07)
{
png_write_finish_row(png_ptr);
return;
}
break;
case 1:
if ((png_ptr->row_number & 7) || png_ptr->width < 5)
if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
{
png_write_finish_row(png_ptr);
return;
}
break;
case 2:
if ((png_ptr->row_number & 7) != 4)
if ((png_ptr->row_number & 0x07) != 4)
{
png_write_finish_row(png_ptr);
return;
}
break;
case 3:
if ((png_ptr->row_number & 3) || png_ptr->width < 3)
if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
{
png_write_finish_row(png_ptr);
return;
}
break;
case 4:
if ((png_ptr->row_number & 3) != 2)
if ((png_ptr->row_number & 0x03) != 2)
{
png_write_finish_row(png_ptr);
return;
}
break;
case 5:
if ((png_ptr->row_number & 1) || png_ptr->width < 2)
if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
{
png_write_finish_row(png_ptr);
return;
}
break;
case 6:
if (!(png_ptr->row_number & 1))
if (!(png_ptr->row_number & 0x01))
{
png_write_finish_row(png_ptr);
return;
@@ -781,27 +799,13 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
if (info_ptr != NULL)
{
#if defined(PNG_WRITE_TEXT_SUPPORTED)
png_free_text(png_ptr, info_ptr, -1);
#endif
#if defined(PNG_WRITE_sCAL_SUPPORTED)
png_free_sCAL(png_ptr, info_ptr);
#endif
#if defined(PNG_WRITE_pCAL_SUPPORTED)
png_free_pCAL(png_ptr, info_ptr);
#endif
#if defined(PNG_WRITE_iCCP_SUPPORTED)
png_free_iCCP(png_ptr, info_ptr);
#endif
#if defined(PNG_WRITE_sPLT_SUPPORTED)
png_free_spalettes(png_ptr, info_ptr, -1);
#endif
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
png_free_unknown_chunks(png_ptr, info_ptr, -1);
#endif
#if defined(PNG_hIST_SUPPORTED)
png_free_hIST(png_ptr, info_ptr);
#endif
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
if (png_ptr->num_chunk_list)
{
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->num_chunk_list=0;
}
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, free_fn);
@@ -828,7 +832,9 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
void
png_write_destroy(png_structp png_ptr)
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* save jump buffer */
#endif
png_error_ptr error_fn;
png_error_ptr warning_fn;
png_voidp error_ptr;
@@ -861,8 +867,10 @@ png_write_destroy(png_structp png_ptr)
png_free(png_ptr, png_ptr->inv_filter_costs);
#endif
#ifdef PNG_SETJMP_SUPPORTED
/* reset structure */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
#endif
error_fn = png_ptr->error_fn;
warning_fn = png_ptr->warning_fn;
@@ -880,7 +888,9 @@ png_write_destroy(png_structp png_ptr)
png_ptr->free_fn = free_fn;
#endif
#ifdef PNG_SETJMP_SUPPORTED
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
#endif
}
/* Allow the application to select one or more row filters to use. */
@@ -915,14 +925,14 @@ png_set_filter(png_structp png_ptr, int method, int filters)
*/
if (png_ptr->row_buf != NULL)
{
if (png_ptr->do_filter & PNG_FILTER_SUB && png_ptr->sub_row == NULL)
if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
{
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
}
if (png_ptr->do_filter & PNG_FILTER_UP && png_ptr->up_row == NULL)
if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
{
if (png_ptr->prev_row == NULL)
{
@@ -937,7 +947,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
}
}
if (png_ptr->do_filter & PNG_FILTER_AVG && png_ptr->avg_row == NULL)
if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
{
if (png_ptr->prev_row == NULL)
{
@@ -952,7 +962,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
}
}
if (png_ptr->do_filter & PNG_FILTER_PAETH &&
if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
png_ptr->paeth_row == NULL)
{
if (png_ptr->prev_row == NULL)
@@ -1170,3 +1180,87 @@ png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
png_ptr->write_user_transform_fn = write_user_transform_fn;
}
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED)
void png_write_png(png_structp png_ptr, png_infop info_ptr,
int transforms,
voidp params)
{
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
/* invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
png_set_invert_alpha(png_ptr);
#endif
/* Write the file header information. */
png_write_info(png_ptr, info_ptr);
/* ------ these transformations don't touch the info structure ------- */
#if defined(PNG_WRITE_INVERT_SUPPORTED)
/* invert monochrome pixels */
if (transforms & PNG_TRANSFORM_INVERT_MONO)
png_set_invert_mono(png_ptr);
#endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
/* Shift the pixels up to a legal bit depth and fill in
* as appropriate to correctly scale the image.
*/
if ((transforms & PNG_TRANSFORM_SHIFT)
&& (info_ptr->valid & PNG_INFO_sBIT))
png_set_shift(png_ptr, &info_ptr->sig_bit);
#endif
#if defined(PNG_WRITE_PACK_SUPPORTED)
/* pack pixels into bytes */
if (transforms & PNG_TRANSFORM_PACKING)
png_set_packing(png_ptr);
#endif
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
/* swap location of alpha bytes from ARGB to RGBA */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
png_set_swap_alpha(png_ptr);
#endif
#if defined(PNG_WRITE_FILLER_SUPPORTED)
/* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
* RGB (4 channels -> 3 channels). The second parameter is not used.
*/
if (transforms & PNG_TRANSFORM_STRIP_FILLER)
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
#endif
#if defined(PNG_WRITE_BGR_SUPPORTED)
/* flip BGR pixels to RGB */
if (transforms & PNG_TRANSFORM_BGR)
png_set_bgr(png_ptr);
#endif
#if defined(PNG_WRITE_SWAP_SUPPORTED)
/* swap bytes of 16-bit files to most significant byte first */
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
png_set_swap(png_ptr);
#endif
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
/* swap bits of 1, 2, 4 bit packed pixel formats */
if (transforms & PNG_TRANSFORM_PACKSWAP)
png_set_packswap(png_ptr);
#endif
/* ----------------------- end of transformations ------------------- */
/* write the bits */
if (info_ptr->valid & PNG_INFO_IDAT)
png_write_image(png_ptr, info_ptr->row_pointers);
/* It is REQUIRED to call this to finish writing the rest of the file */
png_write_end(png_ptr, info_ptr);
if(transforms == 0 || params == (voidp)NULL)
/* quiet compiler warnings */ return;
}
#endif

View File

@@ -1,11 +1,11 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*/
#define PNG_INTERNAL
@@ -140,7 +140,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{
png_byte value;
value = (png_byte)(*sp & 0x3);
value = (png_byte)(*sp & 0x03);
v |= (value << shift);
if (shift == 0)
{
@@ -172,7 +172,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{
png_byte value;
value = (png_byte)(*sp & 0xf);
value = (png_byte)(*sp & 0x0f);
v |= (value << shift);
if (shift == 0)

View File

@@ -1,11 +1,11 @@
/* pngwutil.c - utilities to write a PNG file
*
* libpng 1.0.5j - December 21, 1999
* libpng 1.0.5v - March 11, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
*/
#define PNG_INTERNAL
@@ -179,7 +179,6 @@ png_text_compress(png_structp png_ptr,
#else
png_warning(png_ptr, "Unknown compression type");
#endif
compression = PNG_TEXT_COMPRESSION_zTXt;
}
/* We can't write the chunk until we find out how much data we have,
@@ -584,8 +583,8 @@ png_write_gAMA(png_structp png_ptr, double file_gamma)
png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
}
#endif
void
#ifdef PNG_FIXED_POINT_SUPPORTED
void
png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
{
#ifdef PNG_USE_LOCAL_ARRAYS
@@ -642,7 +641,7 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
}
if (compression_type)
/* ignore */ ;
png_warning(png_ptr, "Unknown compression type in iCCP chunk");
if (profile == NULL || *profile == '\0')
profile_len = 0;
@@ -667,7 +666,7 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
#if defined(PNG_WRITE_sPLT_SUPPORTED)
/* write a sPLT chunk */
void
png_write_sPLT(png_structp png_ptr, png_spalette_p spalette)
png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
{
#ifdef PNG_USE_LOCAL_ARRAYS
PNG_sPLT;
@@ -677,10 +676,11 @@ png_write_sPLT(png_structp png_ptr, png_spalette_p spalette)
png_byte entrybuf[10];
int entry_size = (spalette->depth == 8 ? 6 : 10);
int palette_size = entry_size * spalette->nentries;
png_spalette_entryp ep;
png_sPLT_entryp ep;
png_debug(1, "in png_write_sPLT\n");
if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr, spalette->name, &new_name))==0)
if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
spalette->name, &new_name))==0)
{
png_warning(png_ptr, "Empty keyword in sPLT chunk");
return;
@@ -1194,7 +1194,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
png_free(png_ptr, new_key);
return;
}
text_len = png_strlen(text);
png_free(png_ptr, new_key);
@@ -1741,7 +1741,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
i += png_pass_inc[pass])
{
sp = row + (png_size_t)(i >> 3);
value = (int)(*sp >> (7 - (int)(i & 7))) & 0x1;
value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
d |= (value << shift);
if (shift == 0)
@@ -1775,7 +1775,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
i += png_pass_inc[pass])
{
sp = row + (png_size_t)(i >> 2);
value = (*sp >> ((3 - (int)(i & 3)) << 1)) & 0x3;
value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
d |= (value << shift);
if (shift == 0)
@@ -1808,7 +1808,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
i += png_pass_inc[pass])
{
sp = row + (png_size_t)(i >> 1);
value = (*sp >> ((1 - (int)(i & 1)) << 2)) & 0xf;
value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
d |= (value << shift);
if (shift == 0)
@@ -1915,7 +1915,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
/* We don't need to test the 'no filter' case if this is the only filter
* that has been chosen, as it doesn't actually do anything to the data.
*/
if (filter_to_do & PNG_FILTER_NONE &&
if ((filter_to_do & PNG_FILTER_NONE) &&
filter_to_do != PNG_FILTER_NONE)
{
png_bytep rp;