diff --git a/CHANGES b/CHANGES index 4a25c7ca..c067808b 100644 --- a/CHANGES +++ b/CHANGES @@ -167,21 +167,23 @@ version 0.96 [May, 1997] added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul) added typecasts to quiet compiler errors added more debugging info -version 1.00 [not distributed, but Andreas handed off to G&G] - skipped version 1.00 to avoid potential problems with shared libraries - created with version 0.89 +version 0.97 [January, 1998] removed PNG_USE_OWN_CRC capability relocated png_set_crc_action from pngrutil.c to pngrtran.c - fixed typecasts of "new_key" etc. + fixed typecasts of "new_key", etc. added RFC 1152 date support -version 1.00.97 [Dec 1997] fixed bug in gamma handling of 4-bit grayscale added more typecasts. 65536L becomes (png_uint_32)65536L, etc. minor corrections in libpng.txt added simple sRGB support - make it simpler to do conditional compiling + make it simpler to do conditional compiling: PNG_READ_NOT_FULLY_SUPPORTED fixed memory leak in pngwrite.c (free info_ptr->text) added more conditions for png_do_background, to avoid changing black pixels to background when a background is supplied and no pixels are transparent - include stdio.h in pngconf.h even when PNG_NO_STDIO is defined. + repaired PNG_NO_STDIO behaviour + tested NODIV support and made it default behaviour + added "-m" option to pngtest + [anything else? 2-bit grayscale gamma bug?] + regularized version numbering scheme and bumped shared-library major + version number to 2 to avoid potential problems with libpng 0.89 apps diff --git a/README b/README index 75bb2dc6..5fe91204 100644 --- a/README +++ b/README @@ -1,23 +1,22 @@ -README for libpng 1.10 +[NOTE: this is still beta version 0.97c; the text below has already + been updated in anticipation of the imminent 1.0 release.] -This first official release of libpng. Don't let the fact that + +README for libpng 1.0 + +This is the first official release of libpng. Don't let the fact that it's the first release fool you. The libpng library has been in extensive use and testing for about two years. However, it's finally gotten to the stage where there haven't been significant changes to the API in some time, and people have a bad feeling about libraries with versions < 1.0. -Note that the version number is 1.10 to avoid potential problems -with shared libraries created for Linux ELF under version 0.89, -which mistakenly used 1.0.89 as the library version number in -false anticipation of an imminent 1.0 release. - **** Note that some of the changes to the png_info structure render this version of the library binary incompatible with libpng-0.89 or earlier versions if you are using a shared library. The type of the "filler" parameter for png_set_filler() has changed from png_byte to -png_uint_32, which will affect shared-library applications which use +png_uint_32, which will affect shared-library applications that use this function. To avoid problems with changes to the internals of png_info_struct, @@ -28,7 +27,7 @@ accessing/storing the info_struct data, rather than manipulating it directly, to avoid such problems in the future. It is important to note that the APIs do not make current programs -which access the info struct directly incompatible with the new +that access the info struct directly incompatible with the new library. However, it is strongly suggested that new programs use the new APIs (as shown in example.c), and older programs be converted to the new format, to facilitate upgrades in the future. diff --git a/makefile b/makefile deleted file mode 100644 index ebe000b4..00000000 --- a/makefile +++ /dev/null @@ -1,68 +0,0 @@ -# makefile for libpng -# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc. -# For conditions of distribution and use, see copyright notice in png.h - -# Where the zlib library and include files are located -#ZLIBLIB=/usr/local/lib -#ZLIBINC=/usr/local/include -ZLIBLIB=../zlib -ZLIBINC=../zlib - -CC=cc -CFLAGS=-I$(ZLIBINC) -O # -g -DPNG_DEBUG=1 -LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm - -#RANLIB=echo -RANLIB=ranlib - -# where make install puts libpng.a and png.h -prefix=/usr/local - -OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ - pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ - pngwtran.o pngmem.o pngerror.o pngpread.o - -all: libpng.a pngtest - -libpng.a: $(OBJS) - ar rc $@ $(OBJS) - $(RANLIB) $@ - -pngtest: pngtest.o libpng.a - $(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS) - -test: pngtest - ./pngtest - -install: libpng.a - -@mkdir $(prefix)/include - -@mkdir $(prefix)/lib - cp png.h $(prefix)/include - cp pngconf.h $(prefix)/include - chmod 644 $(prefix)/include/png.h - chmod 644 $(prefix)/include/pngconf.h - cp libpng.a $(prefix)/lib - chmod 644 $(prefix)/lib/libpng.a - -clean: - rm -f *.o libpng.a pngtest pngout.png - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -png.o: png.h pngconf.h -pngerror.o: png.h pngconf.h -pngrio.o: png.h pngconf.h -pngwio.o: png.h pngconf.h -pngmem.o: png.h pngconf.h -pngset.o: png.h pngconf.h -pngget.o: png.h pngconf.h -pngread.o: png.h pngconf.h -pngrtran.o: png.h pngconf.h -pngrutil.o: png.h pngconf.h -pngtest.o: png.h pngconf.h -pngtrans.o: png.h pngconf.h -pngwrite.o: png.h pngconf.h -pngwtran.o: png.h pngconf.h -pngwutil.o: png.h pngconf.h -pngpread.o: png.h pngconf.h - diff --git a/makefile.elf b/makefile.elf index d949b3e2..1a873788 100644 --- a/makefile.elf +++ b/makefile.elf @@ -1,5 +1,6 @@ -# makefile for libpng on (linux) ELF +# makefile for libpng on Linux ELF with gcc # Copyright (C) 1996, 1997 Andreas Dilger +# Copyright (C) 1998 Glenn Randers-Pehrson # For conditions of distribution and use, see copyright notice in png.h CC=gcc @@ -13,14 +14,15 @@ ZLIBINC=../zlib WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \ -Wmissing-declarations -Wtraditional -Wcast-align \ -Wstrict-prototypes -Wmissing-prototypes #-Wconversion -CFLAGS=-I$(ZLIBINC) -Wall -O3 -funroll-loops -malign-loops=2 -malign-functions=2 -fPIC #$(WARNMORE) -g -DPNG_DEBUG=5 +CFLAGS=-I$(ZLIBINC) -Wall -O3 -funroll-loops -malign-loops=2 \ + -malign-functions=2 #$(WARNMORE) -g -DPNG_DEBUG=5 LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz -lm RANLIB=ranlib #RANLIB=echo -PNGMAJ = 1 -PNGMIN = 1.0 +PNGMAJ = 2 +PNGMIN = 0.97 PNGVER = $(PNGMAJ).$(PNGMIN) # where make install puts libpng.a, libpng.so*, and png.h @@ -32,10 +34,17 @@ OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \ pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \ pngwtran.o pngmem.o pngerror.o pngpread.o -all: libpng.so pngtest +OBJSDLL = $(OBJS:.o=.pic.o) + +.SUFFIXES: .c .o .pic.o + +.c.pic.o: + $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c + +all: libpng.a libpng.so pngtest libpng.a: $(OBJS) - ar rc $@ $(OBJS) + ar rc $@ $(OBJS) $(RANLIB) $@ libpng.so: libpng.so.$(PNGMAJ) @@ -44,43 +53,45 @@ libpng.so: libpng.so.$(PNGMAJ) libpng.so.$(PNGMAJ): libpng.so.$(PNGVER) ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ) -libpng.so.$(PNGVER): $(OBJS) - gcc -shared -Wl,-soname,libpng.so.$(PNGMAJ) $(OBJS) -o libpng.so.$(PNGVER) +libpng.so.$(PNGVER): $(OBJSDLL) + gcc -shared -Wl,-soname,libpng.so.$(PNGMAJ) -o libpng.so.$(PNGVER) \ + $(OBJSDLL) pngtest: pngtest.o libpng.so - $(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS) + $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS) test: pngtest ./pngtest -install: libpng.so.$(PNGVER) +install: libpng.a libpng.so.$(PNGVER) -@mkdir $(INCPATH) $(LIBPATH) cp png.h pngconf.h $(INCPATH) chmod 644 $(INCPATH)/png.h $(INCPATH)/pngconf.h - cp libpng.so.$(PNGVER) $(LIBPATH) + cp libpng.a libpng.so.$(PNGVER) $(LIBPATH) chmod 755 $(LIBPATH)/libpng.so.$(PNGVER) - -@/bin/rm $(LIBPATH)/libpng.so.$(PNGMAJ) $(LIBPATH)/libpng.so + -@/bin/rm -f $(LIBPATH)/libpng.so.$(PNGMAJ) $(LIBPATH)/libpng.so (cd $(LIBPATH); ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ); \ ln -sf libpng.so.$(PNGMAJ) libpng.so) clean: - rm -f *.o libpng.a libpng.so* pngtest pngout.png + /bin/rm -f *.o libpng.a libpng.so* pngtest pngout.png # DO NOT DELETE THIS LINE -- make depend depends on it. -png.o: png.h pngconf.h -pngerror.o: png.h pngconf.h -pngrio.o: png.h pngconf.h -pngwio.o: png.h pngconf.h -pngmem.o: png.h pngconf.h -pngset.o: png.h pngconf.h -pngget.o: png.h pngconf.h -pngread.o: png.h pngconf.h -pngrtran.o: png.h pngconf.h -pngrutil.o: png.h pngconf.h +png.o png.pic.o: png.h pngconf.h +pngerror.o pngerror.pic.o: png.h pngconf.h +pngrio.o pngrio.pic.o: png.h pngconf.h +pngwio.o pngwio.pic.o: png.h pngconf.h +pngmem.o pngmem.pic.o: png.h pngconf.h +pngset.o pngset.pic.o: png.h pngconf.h +pngget.o pngget.pic.o: png.h pngconf.h +pngread.o pngread.pic.o: png.h pngconf.h +pngrtran.o pngrtran.pic.o: png.h pngconf.h +pngrutil.o pngrutil.pic.o: png.h pngconf.h +pngtrans.o pngtrans.pic.o: png.h pngconf.h +pngwrite.o pngwrite.pic.o: png.h pngconf.h +pngwtran.o pngwtran.pic.o: png.h pngconf.h +pngwutil.o pngwutil.pic.o: png.h pngconf.h +pngpread.o pngpread.pic.o: png.h pngconf.h + pngtest.o: png.h pngconf.h -pngtrans.o: png.h pngconf.h -pngwrite.o: png.h pngconf.h -pngwtran.o: png.h pngconf.h -pngwutil.o: png.h pngconf.h -pngpread.o: png.h pngconf.h diff --git a/png.c b/png.c index 8db79d08..1fd3713a 100644 --- a/png.c +++ b/png.c @@ -1,11 +1,12 @@ /* png.c - location for general purpose libpng functions * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 */ #define PNG_INTERNAL @@ -15,7 +16,7 @@ /* Version information for C files. This had better match the version * string defined in png.h. */ -char png_libpng_ver[] = "1.00.97"; +char png_libpng_ver[] = "0.97"; /* Place to hold the signiture string for a PNG file. */ png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; diff --git a/png.h b/png.h index ae7ddf08..e3eaeba4 100644 --- a/png.h +++ b/png.h @@ -1,11 +1,12 @@ /* png.h - header file for PNG reference library * - * libpng 1.00.97 beta 7 + * libpng 0.97 beta * 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 - * Dec 31, 1997 + * Copyright (c) 1998 Glenn Randers-Pehrson + * January 7, 1998 * * BETA NOTICE: * This is a beta version. It reads and writes valid files on the @@ -93,7 +94,7 @@ extern "C" { */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.00.97" +#define PNG_LIBPNG_VER_STRING "0.97" /* careful here. At one time, I wanted to use 082, but that would be octal. * Version 1.0 will be 100 here, etc. @@ -107,6 +108,33 @@ extern "C" { */ extern char png_libpng_ver[]; +/* + * Note about libpng version numbers: + * + * Due to various miscommunications, unforeseen code incompatibilities + * and occasional factors outside the authors' control, version numbering + * on the library has not always been consistent and straightforward. + * The following table summarizes matters since version 0.89c, which was + * the first widely used release: + * + * source png.h shared-lib + * version string version + * ------- ------ ---------- + * 0.89c ("1.0 beta 3") 0.89 1.0.89 + * 0.90 ("1.0 beta 4") 0.90 0.90 [should have been 2.0.90] + * 0.95 ("1.0 beta 5") 0.95 0.95 [should have been 2.0.95] + * 0.96 ("1.0 beta 6") 0.96 0.96 [should have been 2.0.96] + * 0.97b ("1.00.97 beta 7") 1.00.97 1.0.0 [should have been 2.0.97] + * 0.97c 0.97 2.0.97 + * 0.98 0.98 2.0.98 + * 0.99 0.99 2.0.99 + * 1.0 1.00 2.1.0 + * + * Henceforth the source version will match the shared-library minor + * and patch numbers; the shared-library major version number will be + * used for changes in backward compatibility, as it is intended. + */ + /* Structures to facilitate easy interlacing. See png.c for more details */ extern int FARDATA png_pass_start[]; extern int FARDATA png_pass_inc[]; diff --git a/pngconf.h b/pngconf.h index 81f21fcc..56df5563 100644 --- a/pngconf.h +++ b/pngconf.h @@ -1,11 +1,12 @@ /* pngconf.c - machine configurable file for libpng * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 */ /* Any machine specific code is near the front of this file, so if you @@ -259,6 +260,7 @@ __dont__ include it again #define PNG_READ_GRAY_TO_RGB_SUPPORTED #define PNG_READ_SWAP_ALPHA_SUPPORTED #define PNG_READ_STRIP_ALPHA_SUPPORTED +#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel */ #endif /* PNG_READ_FULLY_SUPPORTED */ #define PNG_READ_INTERLACING_SUPPORTED @@ -274,7 +276,7 @@ __dont__ include it again #define PNG_WRITE_FLUSH_SUPPORTED #define PNG_WRITE_SWAP_ALPHA_SUPPORTED #define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED -#endif /*PNG_WRITE_FULLY_SUPPORTED */ +#endif /* PNG_WRITE_FULLY_SUPPORTED */ #if !defined(PNG_NO_STDIO) #define PNG_TIME_RFC1152_SUPPORTED @@ -282,7 +284,6 @@ __dont__ include it again /* These are currently experimental features */ #undef PNG_READ_16_TO_8_ACCURATE_SHIFT_SUPPORTED /* very little testing */ -#undef PNG_READ_COMPOSITE_NODIV_SUPPORTED /* very little testing */ /* This is only for PowerPC big-endian and 680x0 systems */ #undef PNG_READ_BIG_ENDIAN_SUPPORTED /* some testing */ diff --git a/pngerror.c b/pngerror.c index 77232d7e..30576283 100644 --- a/pngerror.c +++ b/pngerror.c @@ -1,11 +1,12 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 * * This file provides a location for all error handling. Users which * need special error handling are expected to write replacement functions @@ -84,7 +85,7 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message else { buffer[iout++] = ':'; buffer[iout++] = ' '; - strncpy(buffer+iout, message, 64); + png_memcpy(buffer+iout, message, 64); buffer[iout+63] = 0; } } diff --git a/pngget.c b/pngget.c index f06dde0c..5ff2be64 100644 --- a/pngget.c +++ b/pngget.c @@ -1,11 +1,12 @@ /* pngget.c - retrieval of values from info struct * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 */ #define PNG_INTERNAL diff --git a/pngmem.c b/pngmem.c index fa649dae..88a6319c 100644 --- a/pngmem.c +++ b/pngmem.c @@ -1,11 +1,12 @@ /* pngmem.c - stub functions for memory allocation * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 * * This file provides a location for all memory allocation. Users which * need special memory handling are expected to modify the code in this file diff --git a/pngpread.c b/pngpread.c index e892a620..b721f919 100644 --- a/pngpread.c +++ b/pngpread.c @@ -1,11 +1,12 @@ /* pngpread.c - read a png file in push mode * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 */ #define PNG_INTERNAL diff --git a/pngread.c b/pngread.c index ff70b3c0..d116fd6a 100644 --- a/pngread.c +++ b/pngread.c @@ -1,11 +1,12 @@ /* pngread.c - read a PNG file * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 * * This file contains routines that an application calls directly to * read a PNG file or stream. diff --git a/pngrio.c b/pngrio.c index 1f4865a4..d45a71bd 100644 --- a/pngrio.c +++ b/pngrio.c @@ -1,11 +1,12 @@ /* pngrio.c - functions for data input * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 * * This file provides a location for all input. Users which need * special handling are expected to write a function which has the same diff --git a/pngrtran.c b/pngrtran.c index b72f0afe..fd1800ec 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1,11 +1,12 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 * * This file contains functions optionally called by an application * in order to tell libpng how to handle data when reading a PNG. @@ -21,35 +22,40 @@ * many machines. However, it does take more operations than the corresponding * divide method, so it may be slower on some RISC systems. There are two * shifts (by 8 or 16 bits) and an addition, versus a single integer divide. - * The results may also be off by one for certain values. + * + * Note that the rounding factors are NOT supposed to be the same! 128 and + * 32768 are correct for the NODIV code; 127 and 32767 are correct for the + * standard method. + * + * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ] */ -/* pixel and background should be in gamma 1.0 space */ -#define png_composite(composite, pixel, trans, background) \ - { png_uint_16 temp = ((png_uint_16)(pixel) * (png_uint_16)(trans) + \ - (png_uint_16)(background)*(png_uint_16)(255 - \ - (png_uint_16)(trans)) + (png_uint_16)127); \ - (composite) = (png_byte)(((temp >> 8) + temp) >> 8); } + /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */ +# define png_composite(composite, fg, alpha, bg) \ + { png_uint_16 temp = ((png_uint_16)(fg) * (png_uint_16)(alpha) + \ + (png_uint_16)(bg)*(png_uint_16)(255 - \ + (png_uint_16)(alpha)) + (png_uint_16)128); \ + (composite) = (png_byte)((temp + (temp >> 8)) >> 8); } +# define png_composite_16(composite, fg, alpha, bg) \ + { png_uint_32 temp = ((png_uint_32)(fg) * (png_uint_32)(alpha) + \ + (png_uint_32)(bg)*(png_uint_32)(65535L - \ + (png_uint_32)(alpha)) + (png_uint_32)32768L); \ + (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); } + +#else /* standard method using integer division */ + + /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */ +# define png_composite(composite, fg, alpha, bg) \ + (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \ + (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \ + (png_uint_16)127) / 255) +# define png_composite_16(composite, fg, alpha, bg) \ + (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \ + (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \ + (png_uint_32)32767) / (png_uint_32)65535L) + +#endif /* ?PNG_READ_COMPOSITE_NODIV_SUPPORTED */ -/* pixel and background should be in gamma 1.0 space */ -#define png_composite_16(composite, pixel, trans, background) \ - { png_uint_32 temp = ((png_uint_32)(pixel) * (png_uint_32)(trans) + \ - (png_uint_32)(background)*(png_uint_32)(65535L - \ - (png_uint_32)(trans)) + (png_uint_32)32767); \ - (composite) = (png_uint_16)(((temp >> 16) + temp) >> 16); } -#else -/* pixel and background should be in gamma 1.0 space */ -#define png_composite(composite, pixel, trans, background) \ - (composite) = (png_byte)(((png_uint_16)(pixel) * (png_uint_16)(trans) + \ - (png_uint_16)(background) * (png_uint_16)(255 - (png_uint_16)(trans)) + \ - (png_uint_16)127) / 255) - -/* pixel and background should be in gamma 1.0 space */ -#define png_composite_16(composite, pixel, trans, background) \ - (composite) = (png_uint_16)(((png_uint_32)(pixel) * (png_uint_32)(trans) + \ - (png_uint_32)(background)*(png_uint_32)(65535L - (png_uint_32)(trans)) + \ - (png_uint_32)32767) / (png_uint_32)65535L) -#endif /* Set the action on getting a CRC error for an ancillary or critical chunk. */ void @@ -1344,6 +1350,16 @@ png_do_chop(png_row_infop row_info, png_bytep row) *dp = (((((png_uint_32)(*sp) << 8) | (png_uint_32)(*(sp + 1))) * 255 + 127) / (png_uint_32)65535L; + + * GRR: no, I think this is what it really should be: + *dp = (((((png_uint_32)(*sp) << 8) | + (png_uint_32)(*(sp + 1))) + 128L) / (png_uint_32)257L; + + * GRR: here's the exact calculation with shifts: + temp = (((png_uint_32)(*sp) << 8) | (png_uint_32)(*(sp + 1))) + 128L; + *dp = (temp - (temp >> 8)) >> 8; + + * Approximate calculation with shift/add instead of multiply/divide: *dp = ((((png_uint_32)(*sp) << 8) | (png_uint_32)((int)(*(sp + 1)) - *sp)) + 128) >> 8; @@ -2558,6 +2574,22 @@ png_do_gamma(png_row_infop row_info, png_bytep row, } case PNG_COLOR_TYPE_GRAY: { + if (row_info->bit_depth == 2) + { + for (i = 0, sp = row; i < row_info->width; i += 4) + { + int a = *sp & 0xc0; + int b = *sp & 0x30; + int c = *sp & 0x0c; + int d = *sp & 0x03; + + *sp = ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)| + ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)| + ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)| + ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ); + sp++; + } + } if (row_info->bit_depth == 4) { for (i = 0, sp = row; i < row_info->width; i += 2) diff --git a/pngrutil.c b/pngrutil.c index 4fe7a4d4..7c86fb02 100644 --- a/pngrutil.c +++ b/pngrutil.c @@ -1,11 +1,12 @@ /* pngrutil.c - utilities to read a PNG file * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 * * This file contains routines which are only called from within * libpng itself during the course of reading an image. @@ -373,7 +374,12 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) else if (png_ptr->mode & PNG_HAVE_PLTE) /* Should be an error, but we can cope with it */ png_warning(png_ptr, "Out of place gAMA chunk"); - else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_gAMA) + + else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_gAMA +#if defined(PNG_READ_sRGB_SUPPORTED) + && !(info_ptr->valid & PNG_INFO_sRGB) +#endif + ) { png_warning(png_ptr, "Duplicate gAMA chunk"); png_crc_finish(png_ptr, length); @@ -397,21 +403,14 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) return; #if defined(PNG_READ_sRGB_SUPPORTED) - if ((png_ptr->mode & PNG_HAVE_sRGB)) - if(igamma != (png_uint_32)50000L) - { - png_warning(png_ptr, - "Ignoring incorrect gAMA value when sRGB is also present"); - return; - } -#endif /* PNG_READ_sRGB_SUPPORTED */ - -#if defined(PNG_READ_sRGB_SUPPORTED) - if (png_ptr->mode & PNG_HAVE_sRGB) - if(igamma != (png_uint_32)50000L) + if (info_ptr->valid & PNG_INFO_sRGB) + if(igamma != (png_uint_32)45000L) { png_warning(png_ptr, "Ignoring incorrect gAMA value when sRGB is also present"); +#ifndef PNG_NO_STDIO + fprintf(stderr, "igamma = %lu\n", igamma); +#endif return; } #endif /* PNG_READ_sRGB_SUPPORTED */ @@ -506,8 +505,12 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) else if (png_ptr->mode & PNG_HAVE_PLTE) /* Should be an error, but we can cope with it */ png_warning(png_ptr, "Missing PLTE before cHRM"); + else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_cHRM - && !(info_ptr->valid & PNG_INFO_sRGB)) +#if defined(PNG_READ_sRGB_SUPPORTED) + && !(info_ptr->valid & PNG_INFO_sRGB) +#endif + ) { png_warning(png_ptr, "Duplicate cHRM chunk"); png_crc_finish(png_ptr, length); @@ -589,7 +592,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) return; #if defined(PNG_READ_sRGB_SUPPORTED) - if (png_ptr->mode & PNG_HAVE_sRGB) + if (info_ptr->valid & PNG_INFO_sRGB) { if (fabs(white_x - (float).3127) > (float).001 || fabs(white_y - (float).3290) > (float).001 || @@ -598,10 +601,17 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) fabs(green_x - (float).3000) > (float).001 || fabs(green_y - (float).6000) > (float).001 || fabs( blue_x - (float).1500) > (float).001 || - fabs( blue_y - (float).6000) > (float).001) + fabs( blue_y - (float).0600) > (float).001) { + png_warning(png_ptr, "Ignoring incorrect cHRM value when sRGB is also present"); +#ifndef PNG_NO_STDIO + fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n", + white_x, white_y, red_x, red_y); + fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n", + green_x, green_y, blue_x, blue_y); +#endif } return; } @@ -618,8 +628,6 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { png_byte intent; png_byte buf[1]; - float file_gamma; - float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; png_debug(1, "in png_handle_sRGB\n"); @@ -634,6 +642,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) else if (png_ptr->mode & PNG_HAVE_PLTE) /* Should be an error, but we can cope with it */ png_warning(png_ptr, "Out of place sRGB chunk"); + else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sRGB) { png_warning(png_ptr, "Duplicate sRGB chunk"); @@ -660,28 +669,38 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) return; } - /* if we really want to be paranoid we could check for - already defined gamma and chrm with values that are - inconsistent with sRGB -- for now, just ignore them */ - - file_gamma = (float)45000./(float)100000.; - png_set_gAMA(png_ptr, info_ptr, file_gamma); - - white_x = (float)31270./(float)100000.; - white_y = (float)32900./(float)100000.; - red_x = (float)64000./(float)100000.; - red_y = (float)33000./(float)100000.; - green_x = (float)30000./(float)100000.; - green_y = (float)60000./(float)100000.; - blue_x = (float)15000./(float)100000.; - blue_y = (float) 6000./(float)100000.; - - png_set_cHRM(png_ptr, info_ptr, - white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); - - png_set_sRGB(png_ptr, info_ptr, intent); -} +#ifdef PNG_READ_gAMA_SUPPORTED + if ((info_ptr->valid & PNG_INFO_gAMA)) + if((png_uint_32)(png_ptr->gamma*(float)100000.+.5) != (png_uint_32)45000L) + { + png_warning(png_ptr, + "Ignoring incorrect gAMA value when sRGB is also present"); +#ifndef PNG_NO_STDIO + fprintf(stderr,"gamma=%f\n",png_ptr->gamma); #endif + } +#endif /* PNG_READ_gAMA_SUPPORTED */ + +#ifdef PNG_READ_cHRM_SUPPORTED + if (info_ptr->valid & PNG_INFO_cHRM) + if (fabs(info_ptr->x_white - (float).3127) > (float).001 || + fabs(info_ptr->y_white - (float).3290) > (float).001 || + fabs( info_ptr->x_red - (float).6400) > (float).001 || + fabs( info_ptr->y_red - (float).3300) > (float).001 || + fabs(info_ptr->x_green - (float).3000) > (float).001 || + fabs(info_ptr->y_green - (float).6000) > (float).001 || + fabs( info_ptr->x_blue - (float).1500) > (float).001 || + fabs( info_ptr->y_blue - (float).0600) > (float).001) + { + png_warning(png_ptr, + "Ignoring incorrect cHRM value when sRGB is also present"); + } +#endif /* PNG_READ_cHRM_SUPPORTED */ + + png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent); +} +#endif /* PNG_READ_sRGB_SUPPORTED */ + #if defined(PNG_READ_tRNS_SUPPORTED) void png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) diff --git a/pngset.c b/pngset.c index 2652b760..ea38d613 100644 --- a/pngset.c +++ b/pngset.c @@ -1,11 +1,12 @@ /* pngset.c - storage of image information into info struct * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 * * The functions here are used during reads to store data from the file * into the info struct, and during writes to store application data diff --git a/pngtest.c b/pngtest.c index cea4c8ed..c23df9da 100644 --- a/pngtest.c +++ b/pngtest.c @@ -1,11 +1,12 @@ /* pngtest.c - a simple test program to test libpng * - * libpng 1.00.97 + * libpng 0.97 * 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 - * May 28, 1997 + * Copyright (c) 1998, Glenn Randers-Pehrson + * January 7, 1998 * * This program reads in a PNG image, writes it out again, and then * compares the two files. If the files are identical, this shows that @@ -620,7 +621,10 @@ main(int argc, char *argv[]) { int i; for (i=2; i