diff options
author | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2000-02-19 14:58:52 -0600 |
---|---|---|
committer | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2009-04-16 10:46:40 -0500 |
commit | 601daa7a76cc5375118683607a9c384c5131c72e (patch) | |
tree | 04ecf6d220e275b87a2f7ecf76848e7d0d1fb7ab | |
parent | f1425677258ee297b861e26a4e92450087649848 (diff) | |
download | libpng-601daa7a76cc5375118683607a9c384c5131c72e.tar.gz |
Imported from pngcrush-1.3.5.tarv1.3.5
-rw-r--r-- | Makefile.msc | 57 | ||||
-rw-r--r-- | README.txt | 13 | ||||
-rw-r--r-- | deflate.c | 11 | ||||
-rw-r--r-- | name_to_int.c | 35 | ||||
-rw-r--r-- | png.c | 195 | ||||
-rw-r--r-- | png.h | 177 | ||||
-rw-r--r-- | pngasmrd.h | 27 | ||||
-rw-r--r-- | pngconf.h | 67 | ||||
-rw-r--r-- | pngcrush.c | 497 | ||||
-rw-r--r-- | pngcrush.h | 11 | ||||
-rw-r--r-- | pngerror.c | 25 | ||||
-rw-r--r-- | pngerror.h | 65 | ||||
-rw-r--r-- | pnggccrd.c | 4 | ||||
-rw-r--r-- | pngget.c | 31 | ||||
-rw-r--r-- | pngmem.c | 2 | ||||
-rw-r--r-- | pngpread.c | 14 | ||||
-rw-r--r-- | pngread.c | 68 | ||||
-rw-r--r-- | pngrio.c | 2 | ||||
-rw-r--r-- | pngrtran.c | 21 | ||||
-rw-r--r-- | pngrutil.c | 42 | ||||
-rw-r--r-- | pngset.c | 43 | ||||
-rw-r--r-- | pngtrans.c | 2 | ||||
-rw-r--r-- | pngtypes.h | 2 | ||||
-rw-r--r-- | pngvcrd.c | 9 | ||||
-rw-r--r-- | pngwio.c | 2 | ||||
-rw-r--r-- | pngwrite.c | 61 | ||||
-rw-r--r-- | pngwtran.c | 2 | ||||
-rw-r--r-- | pngwutil.c | 4 |
28 files changed, 971 insertions, 518 deletions
diff --git a/Makefile.msc b/Makefile.msc new file mode 100644 index 000000000..acd73fb1d --- /dev/null +++ b/Makefile.msc @@ -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) + diff --git a/README.txt b/README.txt index cec2ae962..eec2e6b3a 100644 --- a/README.txt +++ b/README.txt @@ -30,13 +30,14 @@ This is the copyright notice, disclaimer, and license: This is the output of "pngcrush" and "pngcrush -help": - | pngcrush 1.3.4, Copyright (C) 1998, 1999, 2000, Glenn Randers-Pehrson + + | 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.5m, + | 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. @@ -44,7 +45,6 @@ This is the output of "pngcrush" and "pngcrush -help": 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 [11-124]) -c color_type of output file [0, 2, 4, or 6] @@ -73,6 +73,11 @@ options: -h (help) -p (pause) + +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 [11-124]) @@ -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. diff --git a/name_to_int.c b/name_to_int.c new file mode 100644 index 000000000..1c3bcb320 --- /dev/null +++ b/name_to_int.c @@ -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"); +} + @@ -1,7 +1,7 @@ /* png.c - location for general purpose libpng functions * - * libpng version 1.0.5m - January 7, 2000 + * libpng version 1.0.5s - February 18, 2000 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson @@ -19,7 +19,7 @@ #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.5m"; +char png_libpng_ver[12] = "1.0.5s"; /* png_sig was changed to a function in version 1.0.5c */ /* Place to hold the signature string for a PNG file. */ @@ -62,10 +62,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 +259,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,13 +280,10 @@ 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; } } @@ -291,14 +291,12 @@ png_free_text(png_structp png_ptr, png_infop info_ptr, int num) #if defined(PNG_tRNS_SUPPORTED) /* free any tRNS entry */ -void -png_free_tRNS(png_structp png_ptr, png_infop info_ptr) +if (mask & PNG_FREE_TRNS) { - if (png_ptr == NULL || info_ptr == NULL) - return; if (info_ptr->valid & PNG_INFO_tRNS) { - png_free(png_ptr, info_ptr->trans); + if (info_ptr->free_me & PNG_FREE_TRNS) + png_free(png_ptr, info_ptr->trans); info_ptr->valid &= ~PNG_INFO_tRNS; } } @@ -306,19 +304,13 @@ png_free_tRNS(png_structp png_ptr, png_infop info_ptr) #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) 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; } @@ -327,11 +319,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); @@ -352,15 +341,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; } } @@ -368,39 +357,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 == 0) - return; - - for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) - png_free_spalettes(png_ptr, info_ptr, 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); - 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); @@ -410,62 +392,60 @@ png_free_unknown_chunks(png_structp png_ptr, png_infop info_ptr, int num) { int i; - if(info_ptr->unknown_chunks_num == 0) - return; - - for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++) - png_free_unknown_chunks(png_ptr, info_ptr, i); + 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); - png_free(png_ptr, info_ptr->unknown_chunks); - info_ptr->unknown_chunks_num = 0; - } -} -void -png_free_chunk_list(png_structp png_ptr) -{ - if (png_ptr == NULL) - return; - if (png_ptr->num_chunk_list) - { - png_free(png_ptr, png_ptr->chunk_list); - png_ptr->num_chunk_list=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 */ -void -png_free_pixels(png_structp png_ptr, png_infop info_ptr) +if (mask & PNG_FREE_ROWS) { - if (png_ptr == NULL || info_ptr == NULL) - return; - if (info_ptr->valid & PNG_INFO_IDAT) + 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[row]); png_free(png_ptr, info_ptr->row_pointers); - info_ptr->valid &= ~PNG_INFO_IDAT; } } #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 @@ -475,34 +455,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_tRNS_SUPPORTED) - png_free_tRNS(png_ptr, info_ptr); -#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); - png_free_chunk_list(png_ptr); -#endif -#if defined(PNG_hIST_SUPPORTED) - png_free_hIST(png_ptr, info_ptr); -#endif -#if defined(PNG_INFO_IMAGE_SUPPORTED) - png_free_pixels(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); } @@ -580,7 +543,7 @@ 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.5m - January 7, 2000\n\ + return ("\n libpng version 1.0.5s - February 18, 2000\n\ Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\ Copyright (c) 1996, 1997 Andreas Dilger\n\ Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson\n"); @@ -598,8 +561,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.5m"); - return("1.0.5m"); + return("1.0.5s"); + return("1.0.5s"); } png_charp @@ -623,9 +586,9 @@ png_get_header_version(png_structp png_ptr) /* Generate a compiler error if there is an old png.h in the search path. */ void png_check_version - (version_1_0_5m png_h_is_not_version_1_0_5m) + (version_1_0_5s png_h_is_not_version_1_0_5s) { - if(png_h_is_not_version_1_0_5m == NULL) + if(png_h_is_not_version_1_0_5s == NULL) return; } @@ -1,7 +1,7 @@ /* png.h - header file for PNG reference library * - * libpng version 1.0.5m - January 7, 2000 + * libpng version 1.0.5s - February 18, 2000 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1996, 1997 Andreas Dilger * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson @@ -9,19 +9,19 @@ * 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.5m - January 7, 2000: Glenn + * libpng versions 0.97, January 1998, through 1.0.5s - February 18, 2000: Glenn * See also "Contributing Authors", below. * * Y2K compliance in libpng: * ========================= * - * January 7, 2000 + * February 18, 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.5m are Y2K compliant. It is my belief that earlier + * upward through 1.0.5s 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,9 @@ * 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-m 1.0.5e-m 10100 2.1.0.5e-m - * 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 1.0.5s 10006 2.1.0.5s (compatible) + * 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 @@ -123,7 +124,7 @@ * Copyright (c) 1996, 1997 Andreas Dilger * (libpng versions 0.90, December 1996, through 0.96, May 1997) * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson - * (libpng versions 0.97, January 1998, through 1.0.5m, January 7, 2000) + * (libpng versions 0.97, January 1998, through 1.0.5s, February 18, 2000) * * For the purposes of this copyright and license, "Contributing Authors" * is defined as the following set of individuals: @@ -212,6 +213,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 +230,14 @@ extern "C" { */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.0.5m" +#define PNG_LIBPNG_VER_STRING "1.0.5s" /* 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 +261,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 @@ -418,9 +426,8 @@ typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp; * The following members may have allocated storage attached that should be * 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. Of these, the text, pcal_*, - * hist, iccp_*, splt_*, scal_unit, and row_pointers members are automatically - * freed when the info structure is deallocated. The palette member is not. + * 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 +454,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 +465,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]. @@ -657,8 +666,9 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) #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 */ + png_bytepp row_pointers; /* the image bits */ #endif } png_info; @@ -748,7 +758,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 0x8000 /* 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 @@ -803,19 +813,19 @@ 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 */ +#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)); @@ -829,8 +839,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 */ @@ -860,6 +871,7 @@ struct png_struct_def 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) */ @@ -1044,16 +1056,16 @@ struct png_struct_def }; /* This prevents a compiler error in png_get_copyright() in png.c if png.c -and png.h are both at * version 1.0.5m +and png.h are both at * version 1.0.5s */ -typedef png_structp version_1_0_5m; +typedef png_structp version_1_0_5s; 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. @@ -1576,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)); @@ -1630,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)); @@ -1795,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)); @@ -1848,26 +1883,16 @@ extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr, 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, png_uint_32 proflen)); -extern PNG_EXPORT(void,png_free_iCCP) PNGARG((png_structp png_ptr, - png_infop info_ptr)); #endif #if defined(PNG_READ_sPLT_SUPPORTED) -extern PNG_EXPORT(png_uint_32,png_get_spalettes) PNGARG((png_structp png_ptr, +extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr, png_infop info_ptr, png_spalette_pp entries)); #endif #if defined(PNG_sPLT_SUPPORTED) -extern PNG_EXPORT(void,png_set_spalettes) PNGARG((png_structp png_ptr, +extern PNG_EXPORT(void,png_set_sPLT) 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)); #endif #if defined(PNG_TEXT_SUPPORTED) @@ -1885,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) @@ -1912,15 +1935,13 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr, #endif #if defined(PNG_tRNS_SUPPORTED) -extern PNG_EXPORT(void,png_free_tRNS) PNGARG((png_structp png_ptr, - png_infop info_ptr)); #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)); @@ -1939,11 +1960,6 @@ 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 @@ -1958,24 +1974,19 @@ 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(void,png_free_chunk_list) PNGARG((png_structp png_ptr)); #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)); + 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)); -extern PNG_EXPORT(void, png_free_pixels) PNGARG((png_structp png_ptr, - png_infop info_ptr)); + png_infop info_ptr, + int transforms, + voidp params)); #endif /* Define PNG_DEBUG at compile time for debugging information. Higher @@ -2018,7 +2029,7 @@ 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.5m - January 7, 2000 (header)\n" + " libpng version 1.0.5s - February 18, 2000 (header)\n" #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED /* With these routines we avoid an integer divide, which will be slower on @@ -2135,16 +2146,13 @@ 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_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 | \ @@ -2414,11 +2422,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, diff --git a/pngasmrd.h b/pngasmrd.h index 07a8d736e..63b4aefe8 100644 --- a/pngasmrd.h +++ b/pngasmrd.h @@ -1,6 +1,6 @@ /* pngasmrd.h - assembler version of utilities to read a PNG file * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1999, 2000 Glenn Randers-Pehrson * @@ -9,24 +9,27 @@ #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.5m). +/* 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 @@ -1,7 +1,7 @@ /* pngconf.h - machine configurable file for libpng * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 @@ -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 @@ -706,8 +713,8 @@ __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 image_bits member +/* 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 @@ -843,8 +850,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 @@ -853,7 +865,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 @@ -873,6 +885,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 @@ -895,6 +910,14 @@ 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_jmp_env(png_ptr) png_ptr->jmpbuf +#endif + #if defined(USE_FAR_KEYWORD) /* memory model independent fns */ /* use this to make far-to-near assignments */ # define CHECK 1 diff --git a/pngcrush.c b/pngcrush.c index c55a63783..184e899fc 100644 --- a/pngcrush.c +++ b/pngcrush.c @@ -15,7 +15,7 @@ * occasionally creating Linux executables. */ -#define PNGCRUSH_VERSION "1.3.4" +#define PNGCRUSH_VERSION "1.3.5" /* * COPYRIGHT NOTICE, DISCLAIMER, AND LICENSE: @@ -54,6 +54,26 @@ * * Change log: * + * Version 1.3.5 (built with libpng-1.0.5s) + * + * Add test on stat_buf.st_size to verify fpin==fpout, because stat in + * MSVC++6.0 standard version returns stat_buf.st_ino=0 for all files. + * + * Revised pngcrush.h to make it easier to control PNG_ZBUF_SIZE and + * PNG_NO_FLOATING_POINT_SUPPORTED from a makefile. + * + * Restored ability to enter "replace_gamma" value as a float even when + * floating point arithmetic is not enabled. + * + * Enabled removing tEXt, zTXt, or iTXt chunks by chunk type, i.e., + * "-rem tEXt" only removes tEXt chunks, while "-rem text" removes all + * three types of text chunk. + * + * Removed definition of TOO_FAR from pngcrush.h + * + * Uses new libpng error handler; if a file has errors, pngcrush now will + * continue on and compress the remaining files instead of bailing out. + * * Version 1.3.4 (built with libpng-1.0.5m) * * Do not allow pngcrush to overwrite the input file. @@ -142,7 +162,7 @@ #else # define SLASH "/" #endif -#if !defined(__BORLANDC__) && !defined(_MBCS) +#if !defined(__TURBOC__) && !defined(_MSC_VER) && !defined(_MBCS) # include <unistd.h> #endif #include <sys/types.h> @@ -151,7 +171,7 @@ #include <stdlib.h> #include <time.h> #include <assert.h> -#ifdef _MBCS +#if defined(_MBCS) || defined(WIN32) || defined(__WIN32__) # include <direct.h> #endif @@ -160,6 +180,7 @@ #define EXTENSION_MODE 2 #define FOPEN(file, how) fopen(file, how) #define FCLOSE(file) {fclose(file); file=NULL;--number_of_open_files;}; +#define P2 if(verbose > 2)printf /* we don't need the extra libpng tranformations * so they are ifdef'ed out in a special version of pngconf.h */ @@ -179,9 +200,6 @@ static PNG_CONST char *progname = "pngtest.png"; static PNG_CONST char *inname = "pngtest.png"; static PNG_CONST char *outname = "pngout.png"; -#if 0 -static PNG_CONST char *tmpname = "pngtmp.png"; -#endif static PNG_CONST char *directory_name = "pngcrush.bak"; static PNG_CONST char *extension = "_C.png"; @@ -210,7 +228,12 @@ int best; char buffer[256]; char *str_return; +#ifndef PNG_JMPBUF_SUPPORTED +#ifndef PNG_SETJMP_NOT_SUPPORTED +/* Old setjmp interface */ jmp_buf jmpbuf; +#endif +#endif static png_uint_32 total_input_length = 0; static png_uint_32 total_output_length = 0; @@ -224,6 +247,7 @@ static int force_output_bit_depth=0; static int input_color_type; static int input_bit_depth; static int trial; +static int first_trial=0; static int verbose=1; static int help=0; static int things_have_changed=0; @@ -414,18 +438,17 @@ void png_crush_pause(void) png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); \ FCLOSE(fpin); \ if(verbose > 1) \ - fprintf(STDERR, "returning after longjump\n"); \ - exit(1); + fprintf(STDERR, "returning after longjump\n"); int keep_chunk(png_const_charp name, char *argv[]); int keep_chunk(png_const_charp name, char *argv[]) { int i; - if(verbose > 2 && trial == 1) + if(verbose > 2 && first_trial) fprintf(STDERR, " Read the %s chunk.\n", name); if(remove_chunks == 0) return 1; - if(verbose > 1 && trial == 1) + if(verbose > 1 && first_trial) fprintf(STDERR, " Check for removal of the %s chunk.\n", name); for (i=1; i<=remove_chunks; i++) { @@ -462,13 +485,13 @@ int keep_chunk(png_const_charp name, char *argv[]) (!strncmp(name,"zTXt",4) && (!strncmp(argv[i],"text",4) ))) { things_have_changed=1; - if(verbose > 0 && trial == 1) + if(verbose > 0 && first_trial) fprintf(STDERR, " Removed the %s chunk.\n", name); return 0; } } } - if(verbose > 1 && trial == 1) + if(verbose > 1 && first_trial) fprintf(STDERR, " Preserving the %s chunk.\n", name); return 1; } @@ -534,10 +557,6 @@ main(int argc, char *argv[]) png_fixed_point file_gamma=0; #endif char *cp; -#if 0 - FILE *tmpfile (void); -#endif - int i; row_buf = (png_bytep)NULL; number_of_open_files=0; @@ -593,7 +612,7 @@ main(int argc, char *argv[]) } } } - +#define BUMP_I i++;if(i >= argc) {printf("insufficient parameters\n");exit(1);} names=1; for (i=1; i<argc; i++) { @@ -647,12 +666,14 @@ main(int argc, char *argv[]) else if(!strncmp(argv[i],"-bit_depth",10)) { names++; - force_output_bit_depth=atoi(argv[++i]); + BUMP_I; + force_output_bit_depth=atoi(argv[i]); } else if(!strncmp(argv[i],"-c",2)) { names++; - force_output_color_type=atoi(argv[++i]); + BUMP_I; + force_output_color_type=atoi(argv[i]); } #ifdef PNG_gAMA_SUPPORTED else if(!strncmp(argv[i],"-dou",4)) @@ -663,13 +684,13 @@ main(int argc, char *argv[]) #endif else if(!strncmp(argv[i],"-d",2)) { - i++; + BUMP_I; pngcrush_mode=DIRECTORY_MODE; directory_name= argv[names++]; } else if(!strncmp(argv[i],"-e",2)) { - i++; + BUMP_I; pngcrush_mode=EXTENSION_MODE; extension= argv[names++]; } @@ -755,7 +776,7 @@ main(int argc, char *argv[]) else if(!strncmp(argv[i],"-g",2)) { names++; - i++; + BUMP_I; if (intent < 0) { int c; @@ -790,13 +811,15 @@ main(int argc, char *argv[]) else if(!strncmp(argv[i],"-max",4)) { names++; - max_idat_size = atoi(argv[++i]); + BUMP_I; + max_idat_size = atoi(argv[i]); if (max_idat_size > PNG_ZBUF_SIZE) max_idat_size=PNG_ZBUF_SIZE; } else if(!strncmp(argv[i],"-m",2)) { names++; - method=atoi(argv[++i]); + BUMP_I; + method=atoi(argv[i]); methods_specified=1; brute_force=0; try_method[method]=0; @@ -810,13 +833,15 @@ main(int argc, char *argv[]) else if(!strncmp(argv[i],"-plte_len",9)) { names++; - plte_len=atoi(argv[++i]); + BUMP_I; + plte_len=atoi(argv[i]); } - else if(!strncmp(argv[i],"-pplt",9)) + else if(!strncmp(argv[i],"-pplt",3)) { names++; do_pplt++; - strcpy(pplt_string,argv[++i]); + BUMP_I; + strcpy(pplt_string,argv[i]); things_have_changed=1; } else if(!strncmp(argv[i],"-p",2)) @@ -827,7 +852,30 @@ main(int argc, char *argv[]) else if(!strncmp(argv[i],"-rep",4)) { names++; - force_specified_gamma=atoi(argv[++i]); + BUMP_I; + { + int c; + char number[16]; + char *n=number; + int nzeroes=-1; + int length=strlen(argv[i]); + for (c=0; c<length; c++) + { + if( *(argv[i]+c) == '.') + { + nzeroes=5; + } + else if (nzeroes != 0) + { + *n++=*(argv[i]+c); + nzeroes--; + } + } + for (c=0; c<nzeroes; c++) + *n++='0'; + *n='\0'; + force_specified_gamma=atoi(number); + } things_have_changed=1; } #endif @@ -835,14 +883,15 @@ main(int argc, char *argv[]) else if(!strncmp(argv[i],"-res",4)) { names++; - resolution=atoi(argv[++i]); + BUMP_I; + resolution=atoi(argv[i]); } #endif else if(!strncmp(argv[i],"-r",2)) { remove_chunks=i; names++; - i++; + BUMP_I; } else if( !strncmp(argv[i],"-save",5)) all_chunks_are_safe++; @@ -854,7 +903,7 @@ main(int argc, char *argv[]) specified_gamma=45455L; #endif intent=0; - i++; + BUMP_I; if(!strncmp(argv[i],"0",1) || !strncmp(argv[i],"1",1) || !strncmp(argv[i],"2",1) || @@ -874,6 +923,7 @@ main(int argc, char *argv[]) !strncmp(argv[i],"-zitxt",6) || !strncmp(argv[i],"-ziTXt",6) || !strncmp(argv[i],"-itxt",5) || !strncmp(argv[i],"-iTXt",5)) { + i+=2; BUMP_I; i-=3; if(strlen(argv[i+2]) < 80 && strlen(argv[i+3]) < 2048 && text_inputs < 10) { @@ -925,7 +975,8 @@ main(int argc, char *argv[]) names+=3; if( !strncmp(argv[i],"-i",2) || !strncmp(argv[i],"-zi",3)) { - i+=2; + i++; + BUMP_I; names+=2; } } @@ -1264,13 +1315,13 @@ main(int argc, char *argv[]) fprintf(STDERR, " document) can be named with all lower-case letters,\n"); fprintf(STDERR, - " so \"-rem bkgd\" is equivalent to \"-rem bKGD\".\n"); + " so \"-rem bkgd\" is equivalent to \"-rem bKGD\". But\n"); fprintf(STDERR, - " Exact case is required to remove unknown chunks.\n"); + " note: \"-rem text\" removes all forms of text chunks;\n"); fprintf(STDERR, - " \"-rem text\" also removes zTXt. If you like to do\n"); + " Exact case is required to remove unknown chunks.\n"); fprintf(STDERR, - " surgery with a chain-saw, \"-rem alla\" removes\n"); + " To do surgery with a chain-saw, \"-rem alla\" removes\n"); fprintf(STDERR, " all known ancillary chunks except for tRNS, and\n"); fprintf(STDERR, @@ -1278,7 +1329,7 @@ main(int argc, char *argv[]) } png_crush_pause(); fprintf(STDERR, - "-replace_gamma gamma_value (float) even when file has a gAMA chunk.\n"); + "-replace_gamma gamma (float or fixed*100000) even if gAMA is present.\n"); if(verbose > 1) fprintf(STDERR,"\n"); fprintf(STDERR, @@ -1288,7 +1339,7 @@ main(int argc, char *argv[]) fprintf(STDERR, "\n Write a pHYs chunk with the given resolution.\n\n"); } -/* +#if 0 fprintf(STDERR, " -save (keep all copy-unsafe chunks)\n"); if(verbose > 1) @@ -1301,7 +1352,7 @@ main(int argc, char *argv[]) " all chunks 'known' to %s, so they can be copied.\n\n", progname); } -*/ +#endif png_crush_pause(); fprintf(STDERR, @@ -1400,20 +1451,17 @@ main(int argc, char *argv[]) for (ia=0; ia<255; ia++) trns_array[ia]=255; - for(;;) + for(;;) /* loop on input files */ { + first_trial = 1; if(png_row_filters != NULL) { free(png_row_filters); png_row_filters=NULL; } - output_color_type=force_output_color_type; - output_bit_depth=force_output_bit_depth; - - if(pngcrush_mode == DIRECTORY_MODE || pngcrush_mode == EXTENSION_MODE) - inname=argv[names++]; + inname=argv[names++]; if(inname == NULL) { @@ -1453,7 +1501,7 @@ main(int argc, char *argv[]) struct stat stat_buf; if(stat(directory_name, &stat_buf) != 0) { -#if defined(_MBCS) || defined(__WIN32__) +#if defined(_MBCS) || defined(WIN32) || defined(__WIN32__) if(_mkdir(directory_name) != 0) #else if(mkdir(directory_name, 0x1ed) != 0) @@ -1480,6 +1528,8 @@ main(int argc, char *argv[]) outname=out_string; } + output_color_type=force_output_color_type; + output_bit_depth=force_output_bit_depth; if(nosave < 2) { @@ -1488,7 +1538,7 @@ main(int argc, char *argv[]) if ((fpin = FOPEN(inname, "rb")) == NULL) { fprintf(STDERR, "Could not find file: %s\n", inname); - return 1; + continue; } number_of_open_files++; @@ -1503,13 +1553,7 @@ main(int argc, char *argv[]) fflush(STDERR); } - if(idat_length[0] == 0) return 1; - -#if 0 - fpin = FOPEN(inname, "rb"); - number_of_open_files++; -#endif - + if(idat_length[0] == 0) continue; } else idat_length[0]=1; @@ -1544,14 +1588,13 @@ main(int argc, char *argv[]) struct stat stat_in, stat_out; /* just copy input to output */ - if(verbose > 2) - printf("prepare to copy input to output\n"); + P2("prepare to copy input to output\n"); png_crush_pause(); if ((fpin = FOPEN(inname, "rb")) == NULL) { fprintf(STDERR, "Could not find input file %s\n", inname); - return 1; + continue; } number_of_open_files++; @@ -1563,12 +1606,12 @@ main(int argc, char *argv[]) } number_of_open_files++; - if(verbose > 2) - printf("copying input to output..."); + P2("copying input to output..."); stat(inname, &stat_in); stat(outname, &stat_out); - if(stat_in.st_ino != stat_out.st_ino) + if((stat_in.st_ino != stat_out.st_ino) || + (stat_in.st_size != stat_out.st_size)) { for(;;) { @@ -1581,8 +1624,7 @@ main(int argc, char *argv[]) } } - if(verbose > 2) - printf("copy complete.\n"); + P2("copy complete.\n"); png_crush_pause(); FCLOSE(fpin); FCLOSE(fpout); @@ -1620,19 +1662,18 @@ main(int argc, char *argv[]) if(zs[trial] == 1)z_strategy=Z_FILTERED; if(zs[trial] == 2)z_strategy=Z_HUFFMAN_ONLY; final_method=trial; - if(verbose > 2 && nosave == 0) - printf(" Begin trial %d, filter %d, strategy %d, level %d\n", + if(nosave == 0) + P2(" Begin trial %d, filter %d, strategy %d, level %d\n", trial, filter_method, z_strategy, zlib_level); } - if(verbose > 2) - printf("prepare to open files.\n"); + P2("prepare to open files.\n"); png_crush_pause(); if ((fpin = FOPEN(inname, "rb")) == NULL) { fprintf(STDERR, "Could not find input file %s\n", inname); - return 1; + continue; } number_of_open_files++; if(nosave == 0) @@ -1641,7 +1682,13 @@ main(int argc, char *argv[]) stat(inname, &stat_in); stat(outname, &stat_out); if(stat_in.st_ino == stat_out.st_ino) + if((stat_in.st_ino == stat_out.st_ino) && + (stat_in.st_size == stat_out.st_size)) { + /* MSVC++6.0 will erroneously return 0 for both files, so + it is possible that we will erroneously reject the attempt + when inputsize and outputsize are equal, for different files + */ fprintf(STDERR, "Cannot overwrite input file %s\n", inname); FCLOSE(fpin); return 1; @@ -1657,8 +1704,7 @@ main(int argc, char *argv[]) number_of_open_files++; } - if(verbose > 2) - printf("files are opened.\n"); + P2("files are opened.\n"); png_crush_pause(); png_debug(0, "Allocating read and write structures\n"); @@ -1701,31 +1747,52 @@ main(int argc, char *argv[]) write_end_info_ptr = png_create_info_struct(write_ptr); } - if(verbose > 2) - printf("structures created.\n"); + P2("structures created.\n"); png_crush_pause(); png_debug(0, "Setting jmpbuf for read and write structs\n"); -#if defined(USE_FAR_KEYWORD) - if (setjmp(jmpbuf)) -#else - if (setjmp(read_ptr->jmpbuf)) -#endif +#ifndef PNG_SETJMP_NOT_SUPPORTED +# ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) +# else +# ifdef PNG_JMPBUF_SUPPORTED + /* New setjmp interface */ + if (setjmp(png_jmp_env(read_ptr))) +# else + /* old interface */ + if (setjmp(read_ptr->jmpbuf)) +# endif +# endif { PNG_CRUSH_CLEANUP + continue; } #if defined(USE_FAR_KEYWORD) - png_memcpy(read_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf)); + png_memcpy(png_jmp_env(read_ptr),jmpbuf,sizeof(jmp_buf)); #endif - - if(nosave == 0) - png_memcpy(write_ptr->jmpbuf,read_ptr->jmpbuf,sizeof(jmp_buf)); - - if(verbose > 2) - printf("jmp_buf has been set.\n"); - + if(nosave == 0) +# ifdef USE_FAR_KEYWORD + if (setjmp(jmpbuf)) +# else +# ifdef PNG_JMPBUF_SUPPORTED + /* New setjmp interface */ + if (setjmp(png_jmp_env(write_ptr))) +# else + /* Old interface */ + if (setjmp(write_ptr->jmpbuf)) +# endif +# endif + { + PNG_CRUSH_CLEANUP + continue; + } +#if defined(USE_FAR_KEYWORD) + png_memcpy(png_jmp_env(write_ptr),jmpbuf,sizeof(jmp_buf)); +#endif + P2("jmp_buf has been set.\n"); png_crush_pause(); +#endif png_debug(0, "Initializing input and output streams\n"); #if !defined(PNG_NO_STDIO) @@ -1743,8 +1810,7 @@ main(int argc, char *argv[]) #endif #endif - if(verbose > 2) - printf("io has been initialized.\n"); + P2("io has been initialized.\n"); png_crush_pause(); /* We don't need to check CRC's because they were already checked @@ -1758,36 +1824,37 @@ main(int argc, char *argv[]) if(read_ptr->zbuf_size < (png_size_t)max_idat_size) { - if(verbose > 2) - printf("reinitializing read zbuf.\n"); + P2("reinitializing read zbuf.\n"); png_free(read_ptr, read_ptr->zbuf); read_ptr->zbuf_size = (png_size_t)max_idat_size; read_ptr->zbuf = (png_bytep)png_malloc(read_ptr, (png_uint_32)read_ptr->zbuf_size); } if(nosave == 0) + { if(write_ptr->zbuf_size > (png_size_t)max_idat_size) { - if (verbose > 2) - printf("reinitializing write zbuf.\n"); + P2("reinitializing write zbuf.\n"); png_free(write_ptr, write_ptr->zbuf); write_ptr->zbuf_size = (png_size_t)max_idat_size; write_ptr->zbuf = (png_bytep)png_malloc(write_ptr, (png_uint_32)write_ptr->zbuf_size); } - + } #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) png_set_keep_unknown_chunks(read_ptr, HANDLE_CHUNK_ALWAYS, (png_bytep)NULL, 0); #endif #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) if(nosave == 0) + { if(all_chunks_are_safe != 0) png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, (png_bytep)NULL, 0); else { +#ifndef PNG_UINT_IHDR #ifdef PNG_USE_LOCAL_ARRAYS #if !defined(PNG_cHRM_SUPPORTED) PNG_cHRM; @@ -1841,7 +1908,51 @@ main(int argc, char *argv[]) png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, (png_bytep)png_tIME, 1); #endif +#else /* !PNG_UINT_IHDR */ + + png_byte chunk_name[5]; + chunk_name[4]='\0'; + + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE, + NULL, 0); +#if !defined(PNG_cHRM_SUPPORTED) + png_save_uint_32(chunk_name, PNG_UINT_cHRM); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); +#endif +#if !defined(PNG_hIST_SUPPORTED) + png_save_uint_32(chunk_name, PNG_UINT_hIST); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); +#endif +#if !defined(PNG_iCCP_SUPPORTED) + png_save_uint_32(chunk_name, PNG_UINT_iCCP); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); +#endif +#if !defined(PNG_sCAL_SUPPORTED) + png_save_uint_32(chunk_name, PNG_UINT_sCAL); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); +#endif +#if !defined(PNG_pCAL_SUPPORTED) + png_save_uint_32(chunk_name, PNG_UINT_pCAL); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); +#endif +#if !defined(PNG_sPLT_SUPPORTED) + png_save_uint_32(chunk_name, PNG_UINT_sPLT); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); +#endif +#if !defined(PNG_tIME_SUPPORTED) + png_save_uint_32(chunk_name, PNG_UINT_tIME); + png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_ALWAYS, + chunk_name, 1); +#endif +#endif /* !PNG_UINT_IHDR */ } + } #endif png_debug(0, "Reading info struct\n"); @@ -1858,7 +1969,7 @@ main(int argc, char *argv[]) int need_expand = 0; input_color_type=color_type; input_bit_depth=bit_depth; - if(verbose > 1 && trial == 1) + if(verbose > 1 && first_trial) { fprintf(STDERR, " IHDR chunk data:\n"); fprintf(STDERR, " Width=%ld, height=%ld\n", width, height); @@ -1911,7 +2022,7 @@ main(int argc, char *argv[]) if((color_type == 4 || color_type == 6) && (output_color_type != 4 && output_color_type != 6)) { - if(verbose > 0 && trial == 1) + if(verbose > 0 && first_trial) fprintf(STDERR, " Stripping existing alpha channel.\n"); #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED png_set_strip_alpha(read_ptr); @@ -1921,7 +2032,7 @@ main(int argc, char *argv[]) if((output_color_type == 4 || output_color_type == 6) && (color_type != 4 && color_type != 6)) { - if(verbose > 0 && trial == 1) + if(verbose > 0 && first_trial) fprintf(STDERR, " Adding an alpha channel.\n"); #ifdef PNG_READ_FILLER_SUPPORTED png_set_filler(read_ptr, (png_uint_32)65535, PNG_FILLER_AFTER); @@ -1935,7 +2046,7 @@ main(int argc, char *argv[]) if((output_color_type == 2 || output_color_type == 6) && color_type == 3) { - if(verbose > 0 && trial == 1) + if(verbose > 0 && first_trial) fprintf(STDERR, " Expanding indexed color file.\n"); need_expand = 1; } @@ -1977,7 +2088,7 @@ main(int argc, char *argv[]) force_compression_window) compression_window = default_compression_window; - if(verbose > 1 && trial == 1 && (compression_window != 15 || + if(verbose > 1 && first_trial && (compression_window != 15 || force_compression_window)) fprintf(STDERR, " Compression window for output= %d\n", 1 << compression_window); @@ -2039,7 +2150,7 @@ main(int argc, char *argv[]) { if(force_specified_gamma > 0) { - if(trial == 1) + if(first_trial) { things_have_changed=1; if(verbose > 0) @@ -2055,7 +2166,7 @@ main(int argc, char *argv[]) { if(keep_chunk("gAMA",argv)) { - if(verbose > 1 && trial == 1) + if(verbose > 1 && first_trial) fprintf(STDERR, " gamma=(%d/100000)\n", (int)file_gamma); if(double_gamma) file_gamma+=file_gamma; @@ -2064,7 +2175,7 @@ main(int argc, char *argv[]) } else if(specified_gamma > 0) { - if(trial == 1) + if(first_trial) { things_have_changed=1; if(verbose > 0) @@ -2092,7 +2203,7 @@ main(int argc, char *argv[]) if(file_gamma > 45000L && file_gamma < 46000L) { things_have_changed=1; - if(trial == 1) + if(first_trial) fprintf(STDERR, " Inserting sRGB chunk with intent=%d\n",intent); png_set_sRGB(write_ptr, write_info_ptr, intent); } @@ -2103,7 +2214,7 @@ main(int argc, char *argv[]) } else { - if(trial == 1) + if(first_trial) { fprintf(STDERR, " Ignoring sRGB request; gamma=(%lu/100000) is not approx. 0.455\n", @@ -2139,7 +2250,7 @@ main(int argc, char *argv[]) { if(offset_x == 0 && offset_y == 0) { - if(verbose > 0 && trial == 1) + if(verbose > 0 && first_trial) fprintf(STDERR, " Deleting useless oFFs 0 0 chunk\n"); } else @@ -2186,7 +2297,7 @@ main(int argc, char *argv[]) unit_type=1; res_x = res_y = (png_uint_32)((resolution/.0254 + 0.5)); png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); - if(verbose > 0 && trial == 1) + if(verbose > 0 && first_trial) fprintf(STDERR, " Added pHYs %lu %lu 1 chunk\n",res_x,res_y); } } @@ -2204,7 +2315,7 @@ main(int argc, char *argv[]) png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); else if(keep_chunk("PLTE",argv)) png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); - if(verbose > 1 && trial == 1) + if(verbose > 1 && first_trial) { int i; png_colorp p = palette; @@ -2308,7 +2419,7 @@ main(int argc, char *argv[]) for (i=0 ; ia<256; ia++) trns_array[ia]=255; } - if (verbose > 1 && trial == 1) + if (verbose > 1 && first_trial) { int last=-1; for (i=0 ; ia<num_palette; ia++) @@ -2380,7 +2491,7 @@ main(int argc, char *argv[]) #endif #if defined(PNG_sPLT_SUPPORTED) { - png_spalette_p entries; + png_sPLT_tp entries; int num_entries; num_entries = (int)png_get_spalettes(read_ptr, read_info_ptr, &entries); @@ -2404,7 +2515,7 @@ main(int argc, char *argv[]) int ntext; png_debug1(0, "Handling %d tEXt/zTXt chunks\n", num_text); - if (verbose > 1 && trial == 1 && num_text > 0) + if (verbose > 1 && first_trial && num_text > 0) { for (ntext = 0; ntext < num_text; ntext++) { @@ -2426,7 +2537,43 @@ main(int argc, char *argv[]) if(num_text > 0) { if(keep_chunk("text",argv)) - png_set_text(write_ptr, write_info_ptr, text_ptr, num_text); + { + int num_to_write=num_text; + for (ntext = 0; ntext < num_text; ntext++) + { + if (first_trial) + P2("Text chunk before IDAT, compression=%d\n", + text_ptr[ntext].compression); + if(text_ptr[ntext].compression==PNG_TEXT_COMPRESSION_NONE) + { + if(!keep_chunk("tEXt",argv)) + { + text_ptr[ntext].key[0]='\0'; + num_to_write--; + } + } + if(text_ptr[ntext].compression==PNG_TEXT_COMPRESSION_zTXt) + { + if(!keep_chunk("zTXt",argv)) + { + text_ptr[ntext].key[0]='\0'; + num_to_write--; + } + } + if(text_ptr[ntext].compression==PNG_ITXT_COMPRESSION_NONE + ||text_ptr[ntext].compression==PNG_ITXT_COMPRESSION_zTXt) + { + if(!keep_chunk("iTXt",argv)) + { + text_ptr[ntext].key[0]='\0'; + num_to_write--; + } + } + } + if (num_to_write > 0) + png_set_text(write_ptr, write_info_ptr, text_ptr, + num_text); + } } for (ntext=0; ntext<text_inputs; ntext++) { @@ -2441,7 +2588,6 @@ main(int argc, char *argv[]) added_text[0].text = &text_text[ntext*2048]; added_text[0].compression = text_compression[ntext]; png_set_text(write_ptr, write_info_ptr, added_text, 1); - png_free(write_ptr,added_text); if(added_text[0].compression < 0) printf(" Added a tEXt chunk.\n"); else if(added_text[0].compression == 0) @@ -2450,6 +2596,7 @@ main(int argc, char *argv[]) printf(" Added an uncompressed iTXt chunk.\n"); else printf(" Added a compressed iTXt chunk.\n"); + png_free(write_ptr,added_text); } } } @@ -2499,15 +2646,13 @@ main(int argc, char *argv[]) } #endif - if(verbose > 2) - printf("writing info structure.\n"); + P2("writing info structure.\n"); png_crush_pause(); png_debug(0, "\nWriting info struct\n"); png_write_info(write_ptr, write_info_ptr); png_debug(0, "\nWrote info struct\n"); - if(verbose > 2) - printf("wrote info structure.\n"); + P2("wrote info structure.\n"); png_crush_pause(); #ifdef PNG_WRITE_PACK_SUPPORTED @@ -2577,7 +2722,7 @@ main(int argc, char *argv[]) */ } - if(verbose > 2) printf("allocated rowbuf.\n"); + P2("allocated rowbuf.\n"); png_crush_pause(); num_pass = png_set_interlace_handling(read_ptr); @@ -2620,16 +2765,25 @@ main(int argc, char *argv[]) (output_color_type == 0 || output_color_type == 4)) { png_byte rgb_error = png_get_rgb_to_gray_status(read_ptr); - if((trial == 1) && rgb_error) + if((first_trial) && rgb_error) printf(" **** Converted non-gray image to gray. **** \n"); } #endif -#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) +#ifdef PNG_FREE_UNKN +# if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) + png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1); +# endif +# if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) + png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1); +# endif +#else +# if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) png_free_unknown_chunks(read_ptr, read_info_ptr, -1); -#endif -#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) +# endif +# if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) png_free_unknown_chunks(write_ptr, write_info_ptr, -1); +# endif #endif png_debug(0, "Reading and writing end_info data\n"); @@ -2647,7 +2801,7 @@ main(int argc, char *argv[]) int ntext; png_debug1(0, "Handling %d tEXt/zTXt chunks\n", num_text); - if (verbose > 1 && trial == 1 && num_text > 0) + if (verbose > 1 && first_trial && num_text > 0) { for (ntext = 0; ntext < num_text; ntext++) { @@ -2669,8 +2823,43 @@ main(int argc, char *argv[]) if(num_text > 0) { if(keep_chunk("text",argv)) - png_set_text(write_ptr, write_end_info_ptr, text_ptr, - num_text); + { + int num_to_write=num_text; + for (ntext = 0; ntext < num_text; ntext++) + { + if (first_trial) + P2("Text chunk after IDAT, compression=%d\n", + text_ptr[ntext].compression); + if(text_ptr[ntext].compression==PNG_TEXT_COMPRESSION_NONE) + { + if(!keep_chunk("tEXt",argv)) + { + text_ptr[ntext].key[0]='\0'; + num_to_write--; + } + } + if(text_ptr[ntext].compression==PNG_TEXT_COMPRESSION_zTXt) + { + if(!keep_chunk("zTXt",argv)) + { + text_ptr[ntext].key[0]='\0'; + num_to_write--; + } + } + if(text_ptr[ntext].compression==PNG_ITXT_COMPRESSION_NONE + ||text_ptr[ntext].compression==PNG_ITXT_COMPRESSION_zTXt) + { + if(!keep_chunk("iTXt",argv)) + { + text_ptr[ntext].key[0]='\0'; + num_to_write--; + } + } + } + if (num_to_write > 0) + png_set_text(write_ptr, write_end_info_ptr, text_ptr, + num_text); + } } for (ntext=0; ntext<text_inputs; ntext++) { @@ -2678,23 +2867,22 @@ main(int argc, char *argv[]) { png_textp added_text; added_text = (png_textp) - png_malloc(write_ptr, (png_uint_32)sizeof(png_text)); + png_malloc(write_ptr, (png_uint_32)sizeof(png_text)); added_text[0].key = &text_keyword[ntext*80]; added_text[0].lang = &text_lang[ntext*80]; added_text[0].lang_key = &text_lang_key[ntext*80]; added_text[0].text = &text_text[ntext*2048]; added_text[0].compression = text_compression[ntext]; png_set_text(write_ptr, write_end_info_ptr, added_text, 1); - png_free(write_ptr,added_text); if(added_text[0].compression < 0) - printf(" Added a tEXt chunk after IDAT.\n"); + printf(" Added a tEXt chunk.\n"); else if(added_text[0].compression == 0) - printf(" Added a zTXt chunk after IDAT.\n"); + printf(" Added a zTXt chunk.\n"); else if(added_text[0].compression == 1) - printf( - " Added an uncompressed iTXt chunk after IDAT.\n"); + printf(" Added an uncompressed iTXt chunk.\n"); else - printf(" Added a compressed iTXt chunk after IDAT.\n"); + printf(" Added a compressed iTXt chunk.\n"); + png_free(write_ptr,added_text); } } } @@ -2780,6 +2968,7 @@ main(int argc, char *argv[]) fflush(STDERR); } + first_trial=0; } /* end of trial-loop */ if (fpin) @@ -2830,15 +3019,14 @@ main(int argc, char *argv[]) if(verbose > 0) show_result(); return 0; } - } + } /* end of loop on input files */ } png_uint_32 measure_idats(FILE *fpin) { png_uint_32 measured_idat_length; - if(verbose > 2) - printf("measure_idats:\n"); + P2("measure_idats:\n"); png_debug(0, "Allocating read structure\n"); read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, (png_error_ptr)NULL, (png_error_ptr)NULL); @@ -2849,19 +3037,28 @@ measure_idats(FILE *fpin) read_info_ptr = png_create_info_struct(read_ptr); end_info_ptr = png_create_info_struct(read_ptr); png_debug(0, "Setting jmpbuf for read struct\n"); -#if defined(USE_FAR_KEYWORD) + +#ifndef PNG_SETJMP_NOT_SUPPORTED +# ifdef USE_FAR_KEYWORD if (setjmp(jmpbuf)) -#else +# else +# ifdef PNG_JMPBUF_SUPPORTED + /* New setjmp interface */ + if (setjmp(png_jmp_env(read_ptr))) +# else + /* old interface */ if (setjmp(read_ptr->jmpbuf)) -#endif - { - PNG_CRUSH_CLEANUP - if(verbose > 2) - fprintf(STDERR, "returning from measure_idats after longjump\n"); - return 0; - } -#if defined(USE_FAR_KEYWORD) - png_memcpy(read_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf)); +# endif +# endif + { + PNG_CRUSH_CLEANUP + P2("returning from measure_idats after longjump\n"); + return 0; + } + +# if defined(USE_FAR_KEYWORD) + png_memcpy(png_jmp_env(read_ptr),jmpbuf,sizeof(jmp_buf)); +# endif #endif #if !defined(PNG_NO_STDIO) @@ -2873,8 +3070,7 @@ measure_idats(FILE *fpin) measured_idat_length=0; read_ptr->sig_bytes=0; measured_idat_length=png_measure_idat(read_ptr, read_info_ptr); - if(verbose > 2) - printf("measure_idats: IDAT length=%lu\n",measured_idat_length); + P2("measure_idats: IDAT length=%lu\n",measured_idat_length); png_debug(0, "Destroying data structs\n"); png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); return measured_idat_length; @@ -2908,12 +3104,14 @@ png_measure_idat(png_structp png_ptr, png_infop info_ptr) for(;;) { +#ifndef PNG_UINT_IDAT #ifdef PNG_USE_LOCAL_ARRAYS PNG_IDAT; PNG_IEND; #endif - png_byte chunk_length[4]; +#endif png_byte chunk_name[5]; + png_byte chunk_length[4]; png_uint_32 length; png_read_data(png_ptr, chunk_length, 4); @@ -2922,7 +3120,12 @@ png_measure_idat(png_structp png_ptr, png_infop info_ptr) png_reset_crc(png_ptr); png_crc_read(png_ptr, chunk_name, 4); + +#ifdef PNG_UINT_IDAT + if (png_get_uint_32(chunk_name) == PNG_UINT_IDAT) +#else if (!png_memcmp(chunk_name, png_IDAT, 4)) +#endif sum_idat_length += length; if(verbose > 1) @@ -2932,7 +3135,11 @@ png_measure_idat(png_structp png_ptr, png_infop info_ptr) } png_crc_finish(png_ptr, length); +#ifdef PNG_UINT_IEND + if (png_get_uint_32(chunk_name) == PNG_UINT_IEND) +#else if (!png_memcmp(chunk_name, png_IEND, 4)) +#endif return sum_idat_length; } } diff --git a/pngcrush.h b/pngcrush.h index d063f7356..3e464c7d2 100644 --- a/pngcrush.h +++ b/pngcrush.h @@ -3,8 +3,9 @@ /* 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 */ +#ifndef PNG_FLOATING_POINT_SUPPORTED /* define this if you want to be */ +# define PNG_NO_FLOATING_POINT_SUPPORTED /* able to reduce color to gray */ +#endif #define PNG_NO_READ_cHRM #define PNG_NO_WRITE_cHRM #define PNG_NO_READ_hIST @@ -39,6 +40,6 @@ #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 diff --git a/pngerror.c b/pngerror.c index b7d87bcaf..512aeb2fe 100644 --- a/pngerror.c +++ b/pngerror.c @@ -1,7 +1,7 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 @@ -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 & 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 } diff --git a/pngerror.h b/pngerror.h new file mode 100644 index 000000000..a002caa8e --- /dev/null +++ b/pngerror.h @@ -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 */ diff --git a/pnggccrd.c b/pnggccrd.c index 6e9db58d1..504111caf 100644 --- a/pnggccrd.c +++ b/pnggccrd.c @@ -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.5s - February 18, 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. @@ -1,7 +1,7 @@ /* pngget.c - retrieval of values from info struct * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 @@ -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) @@ -296,8 +307,8 @@ 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); } } } @@ -477,7 +488,7 @@ 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_get_sPLT(png_structp png_ptr, png_infop info_ptr, png_spalette_pp spalettes) { if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) @@ -703,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 @@ -1,7 +1,7 @@ /* pngmem.c - stub functions for memory allocation * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 diff --git a/pngpread.c b/pngpread.c index bf7e3b2b2..9da074346 100644 --- a/pngpread.c +++ b/pngpread.c @@ -1,7 +1,7 @@ /* pngpread.c - read a png file in push mode * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 @@ -1325,15 +1325,13 @@ 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)) @@ -1389,8 +1387,8 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 len } else #endif - - png_push_crc_skip(png_ptr, length); + skip=length; + png_push_crc_skip(png_ptr, skip); } void @@ -1,7 +1,7 @@ /* pngread.c - read a PNG file * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 @@ -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; @@ -627,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.5m. + * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5s. */ void @@ -676,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.5m. + * [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5s. */ void png_read_image(png_structp png_ptr, png_bytepp image) @@ -802,10 +816,10 @@ png_read_end(png_structp png_ptr, png_infop info_ptr) 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); @@ -929,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 @@ -943,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); @@ -968,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; @@ -998,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) @@ -1055,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; @@ -1073,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 @@ -1084,8 +1108,8 @@ png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr 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 transforms, + voidp params) { int row; @@ -1119,7 +1143,7 @@ void png_read_png(png_structp png_ptr, png_infop info_ptr, png_set_strip_alpha(png_ptr); #endif -#if defined(PNG_READ_PACK_SUPPORTED) +#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). */ @@ -1141,8 +1165,10 @@ void png_read_png(png_structp png_ptr, png_infop info_ptr, * channels so the data will be available as RGBA quartets. */ if (transforms & PNG_TRANSFORM_EXPAND) - if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) - png_set_expand(png_ptr); + 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. */ @@ -1196,11 +1222,15 @@ void png_read_png(png_structp png_ptr, png_infop info_ptr, /* -------------- image transformations end here ------------------- */ - info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, - info_ptr->height * sizeof(png_bytep)); + 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)); + 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; @@ -1,7 +1,7 @@ /* pngrio.c - functions for data input * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 diff --git a/pngrtran.c b/pngrtran.c index 111454736..6037574c0 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1,7 +1,7 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 @@ -658,7 +658,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 */ { @@ -1674,9 +1675,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 +1697,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 +1738,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; } } } diff --git a/pngrutil.c b/pngrutil.c index fc353d150..9da17fa43 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -1,7 +1,7 @@ /* pngrutil.c - utilities to read a PNG file * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 @@ -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 @@ -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; } @@ -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"); @@ -928,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); @@ -1058,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); @@ -1107,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; } @@ -1287,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]; @@ -1553,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); @@ -1916,10 +1913,6 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) #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) @@ -1935,7 +1928,6 @@ 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); @@ -1960,11 +1952,14 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } 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. @@ -2804,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; } @@ -1,7 +1,7 @@ /* pngset.c - storage of image information into info struct * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 @@ -135,9 +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); - png_memcpy(info_ptr->hist, hist, sizeof(png_uint_16) * info_ptr->num_palette); + info_ptr->hist = hist; info_ptr->valid |= PNG_INFO_hIST; } #endif @@ -309,11 +307,15 @@ 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; + png_debug1(3, "allocating PLTE for info (%d bytes)\n", length); + info_ptr->palette = palette; + info_ptr->num_palette = (png_uint_16)num_palette; info_ptr->valid |= PNG_INFO_PLTE; } @@ -433,6 +435,7 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr, /* 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 @@ -518,8 +521,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); @@ -565,6 +566,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); } } @@ -594,10 +596,7 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr, return; if (trans != NULL) - { - info_ptr->trans = png_malloc(png_ptr, num_trans); - png_memcpy(info_ptr->trans, trans, num_trans); - } + info_ptr->trans = trans; if (trans_values != NULL) { @@ -613,7 +612,7 @@ 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_set_sPLT(png_structp png_ptr, png_infop info_ptr, png_spalette_p entries, int nentries) { png_spalette_p np; @@ -638,13 +637,14 @@ png_set_spalettes(png_structp png_ptr, from->nentries * sizeof(png_spalette)); png_memcpy(to->entries, from->entries, from->nentries * sizeof(png_spalette)); - to->nentries = from->nentries; - to->depth = from->depth; + 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 */ @@ -683,6 +683,7 @@ 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 @@ -724,13 +725,14 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep if(png_ptr->chunk_list != (png_bytep)NULL) { png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks); - png_free_chunk_list(png_ptr); + 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 @@ -745,3 +747,16 @@ png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp 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 + diff --git a/pngtrans.c b/pngtrans.c index 1818ace32..86c0dfd99 100644 --- a/pngtrans.c +++ b/pngtrans.c @@ -1,7 +1,7 @@ /* pngtrans.c - transforms the data in a row (used by both readers and writers) * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 diff --git a/pngtypes.h b/pngtypes.h index f79120299..756d8e2fb 100644 --- a/pngtypes.h +++ b/pngtypes.h @@ -1,6 +1,6 @@ /* pngtypes.h - array of chunk-types for libpng * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 @@ -2,7 +2,7 @@ * * For Intel x86 CPU and Microsoft Visual C++ compiler * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 2000 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998, Intel Corporation * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson @@ -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 @@ -1,7 +1,7 @@ /* pngwio.c - functions for data output * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 diff --git a/pngwrite.c b/pngwrite.c index f6925e490..ab68a1e44 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -1,7 +1,7 @@ /* pngwrite.c - general routines to write a PNG file * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 @@ -416,9 +416,11 @@ 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 if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, @@ -429,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 @@ -442,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 */ @@ -478,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; @@ -787,34 +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_tRNS_SUPPORTED) - png_free_tRNS(png_ptr, info_ptr); -#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_WRITE_UNKNOWN_CHUNKS_SUPPORTED) - png_free_unknown_chunks(png_ptr, info_ptr, -1); - png_free_chunk_list(png_ptr); -#endif -#if defined(PNG_hIST_SUPPORTED) - png_free_hIST(png_ptr, info_ptr); -#endif -#if defined(PNG_INFO_IMAGE_SUPPORTED) - png_free_pixels(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); @@ -841,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; @@ -874,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; @@ -893,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. */ @@ -1187,8 +1184,8 @@ png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr #if defined(PNG_INFO_IMAGE_SUPPORTED) void png_write_png(png_structp png_ptr, png_infop info_ptr, - int transforms, - voidp params) + int transforms, + voidp params) { if(transforms == 0 || params == (voidp)NULL) /* quiet compiler warnings */ ; @@ -1215,7 +1212,7 @@ void png_write_png(png_structp png_ptr, png_infop info_ptr, * as appropriate to correctly scale the image. */ if ((transforms & PNG_TRANSFORM_SHIFT) - && (info_ptr->valid & PNG_INFO_sBIT)) + && (info_ptr->valid & PNG_INFO_sBIT)) png_set_shift(png_ptr, &info_ptr->sig_bit); #endif diff --git a/pngwtran.c b/pngwtran.c index ff5fd2e9c..4092834ed 100644 --- a/pngwtran.c +++ b/pngwtran.c @@ -1,7 +1,7 @@ /* pngwtran.c - transforms the data in a row for PNG writers * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 diff --git a/pngwutil.c b/pngwutil.c index 0cdb90edd..437a53503 100644 --- a/pngwutil.c +++ b/pngwutil.c @@ -1,7 +1,7 @@ /* pngwutil.c - utilities to write a PNG file * - * libpng 1.0.5m - January 7, 2000 + * libpng 1.0.5s - February 18, 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 @@ -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); |