提交 33b25bf1 编写于 作者: G Glenn Randers-Pehrson

Imported from libpng-1.0.4f.tar

上级 18c415f5
Libpng 1.0.4e - October 10, 1999
Libpng 1.0.4f - October 12, 1999
This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version.
......@@ -80,13 +80,20 @@ version 1.0.4b September 30, 1999
a helpful compiler error if an old png.h is found in the search path.
version 1.0.4c October 1, 1999
Changed type of png_user_transform_depth|channels from int to png_byte.
version 1.0.4e [October 10, 1999]
version 1.0.4f [October 12, 1999]
Changed 0.45 to 0.45455 in png_set_sRGB()
Removed unused PLTE entries from pngnow.png
Re-enabled some parts of pngvcrd.c (png_combine_row) that work properly.
version 1.0.4e [October 10, 1999]
Fixed sign error in pngvcrd.c (Greg Roelofs)
Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P)
version 1.0.4f [October 12, 1999]
Surrounded example.c code with #if 0 .. #endif to prevent people from
inadvertently trying to compile it.
Changed png_get_header_version() from a function to a macro in png.h
Added type casting mostly in pngrtran.c and pngwtran.c
Removed some pointless "ptr = NULL" in pngmem.c
Added a "contrib" directory containing the source code from Greg's book.
Send comments/corrections/commendations to
png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
......
......@@ -467,3 +467,10 @@ version 1.0.4d [October 6, 1999]
version 1.0.4e [October 10, 1999]
Fixed sign error in pngvcrd.c (Greg Roelofs)
Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P)
version 1.0.4f [October 12, 1999]
Surrounded example.c code with #if 0 .. #endif to prevent people from
inadvertently trying to compile it.
Changed png_get_header_version() from a function to a macro in png.h
Added type casting mostly in pngrtran.c and pngwtran.c
Removed some pointless "ptr = NULL" in pngmem.c
Added a "contrib" directory containing the source code from Greg's book.
Installing libpng version 1.0.4e - October 10, 1999
Installing libpng version 1.0.4f - October 12, 1999
Before installing libpng, you must first install zlib. zlib
can usually be found wherever you got libpng. zlib can be
......@@ -10,7 +10,7 @@ zlib.h and zconf.h include files that correspond to the
version of zlib that's installed.
You can rename the directories that you downloaded (they
might be called "libpng-1.0.4e" or "lpng103" and "zlib-1.1.3"
might be called "libpng-1.0.4f" or "lpng103" and "zlib-1.1.3"
or "zlib113") so that you have directories called "zlib" and "libpng".
Your directory structure should look like this:
......@@ -47,8 +47,8 @@ include
makefile.hpux => HPUX (10.20 and 11.00) makefile
makefile.sgi => Silicon Graphics IRIX makefile
makefile.sunos => Sun makefile
makefile.solaris => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0.4e)
makefile.linux => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.4e)
makefile.solaris => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0.4f)
makefile.linux => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.4f)
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
makefile.mips => MIPS makefile
makefile.acorn => Acorn makefile
......@@ -77,7 +77,7 @@ include
Copy the file (or files) that you need from the
scripts directory into this directory, for example
MSDOS example: copy scripts\makefile.msd makefile
MSDOS example: copy scripts\makefile.msc makefile
UNIX example: cp scripts/makefile.std makefile
Read the makefile to see if you need to change any source or
......
......@@ -5,7 +5,7 @@ Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
Copyright (c) 1996, 1997 Andreas Dilger
(libpng versions 0.90, December 1996, through 0.96, May 1997)
Copyright (c) 1998, 1999 Glenn Randers-Pehrson
(libpng versions 0.97, January 1998, through 1.0.4e, October 10, 1999)
(libpng versions 0.97, January 1998, through 1.0.4f, October 12, 1999)
For the purposes of this copyright and license, "Contributing Authors"
is defined as the following set of individuals:
......@@ -54,6 +54,17 @@ supporting the PNG file format in commercial products. If you use this
source code in a product, acknowledgment is not required but would be
appreciated.
A "png_get_copyright" function is available, for convenient use in "about"
boxes and the like:
printf("%s",png_get_copyright(NULL));
Also, the PNG logo (in PNG format, of course) is supplied in the
file "pngnow.png".
Libpng is OSI Certified Open Source Software. OSI Certified is a
certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
randeg@alum.rpi.edu
October 10, 1999
October 12, 1999
README for libpng 1.0.4e - October 10, 1999 (shared library 2.1)
README for libpng 1.0.4f - October 12, 1999 (shared library 2.1)
See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng.
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 and a half years. However, it's
finally gotten to the stage where there haven't been significant
Version 0.89 was 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 since mid-1995. By late 1997 it had
finally gotten to the stage where there hadn't been significant
changes to the API in some time, and people have a bad feeling about
libraries with versions < 1.0.
libraries with versions < 1.0. Version 1.0.0 was released in
March 1998.
****
Note that some of the changes to the png_info structure render this
......@@ -28,8 +29,8 @@ directly, to avoid such problems in the future.
It is important to note that the APIs do not make current programs
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.
the new APIs (as shown in example.c and pngtest.c), and older programs
be converted to the new format, to facilitate upgrades in the future.
****
Additions since 0.90 include the ability to compile libpng as a
......@@ -50,7 +51,8 @@ critical or an ancillary chunk.
The changes made to the library, and bugs fixed are based on discussions
on the PNG implementation mailing list <png-implement@ccrc.wustl.edu>
and not on material submitted to Guy.
and not on material submitted privately to Guy, Andreas, or Glenn. They will
forward any good suggestions to the list.
For a detailed description on using libpng, read libpng.txt. For
examples of libpng in a program, see example.c and pngtest.c. For usage
......@@ -163,9 +165,9 @@ Files in this distribution:
makefile.sgi => Silicon Graphics IRIX makefile
makefile.sunos => Sun makefile
makefile.solaris => Solaris 2.X makefile
(gcc, creates libpng.so.2.1.0.4e)
(gcc, creates libpng.so.2.1.0.4f)
makefile.linux => Linux/ELF makefile
(gcc, creates libpng.so.2.1.0.4e)
(gcc, creates libpng.so.2.1.0.4f)
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
makefile.mips => MIPS makefile
makefile.acorn => Acorn makefile
......
Y2K compliance in libpng:
=========================
October 10, 1999
October 12, 1999
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.4e are Y2K compliant. It is my belief that earlier
upward through 1.0.4f 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
......
PNG: The Definitive Guide: Source Code
Chapters 13, 14 and 15 of PNG: The Definitive Guide discuss three
cross-platform demo programs that show how to use the libpng reference
library: rpng, rpng2 and wpng. rpng and rpng2 are viewers; the first is a
very simple example that that shows how a standard file-viewer might use
libpng, while the second is designed to process streaming data and shows how
a web browser might be written. wpng is a simple command-line program that
reads binary PPM files (the ``raw'' RGB subset of NetPBM) and converts them
to PNG.
The source code for all three demo programs currently compiles only under
Unix and 32-bit Windows. It has been tested with gcc 2.7.2.3 under Linux and
Solaris and with Microsoft Visual C++ 5.0 under Windows 95. Brief
instructions for compiling the programs are included at the top of the
makefiles; makefile.unx is the Unix version, and makefile.w32 is (you
guessed it!) the version for 32-bit Windows. libpng and zlib are required.
----------------------------------------------------------------------------
License
The source code to the demo programs may be used and distributed freely
(even if you didn't buy the book--but feel free to do so at any time),
subject to the terms of the following BSD-like license:
Copyright (c) 1998-1999 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
be held liable for any damages arising in any way from the use of
this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. Redistributions of source code must retain the above
copyright notice, disclaimer, and this list of conditions.
2. Redistributions in binary form must reproduce the above
copyright notice, disclaimer, and this list of conditions in
the documentation and/or other materials provided with the
distribution.
3. All advertising materials mentioning features or use of this
software must display the following acknowledgment:
This product includes software developed by Greg Roelofs
and contributors for the book, "PNG: The Definitive
Guide," published by O'Reilly and Associates.
----------------------------------------------------------
http://www.cdrom.com/pub/png/book/sources.html
# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make.
# Greg Roelofs
# Last modified: 16 February 1999
#
# The programs built by this makefile are described in the book,
# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
# Associates, 1999). Go buy a copy, eh? Buy some for friends
# and family, too. (Not that this is a blatant plug or anything.)
#
# Invoke this makefile from a shell prompt in the usual way; for example:
#
# make -f makefile.unx
#
# This makefile assumes libpng and zlib have already been built or downloaded
# and are both installed in /usr/local/{include,lib} (as indicated by the
# PNGPATH and ZPATH macros below). Edit as appropriate.
#
# This makefile builds statically linked executables (against libpng and zlib,
# that is), but that can be changed by uncommenting the appropriate PNGLIB and
# ZLIB lines.
# macros --------------------------------------------------------------------
PNGPATH = /usr/local
PNGINC = -I$(PNGPATH)/include
#PNGLIB = -L$(PNGPATH)/lib -lpng
PNGLIB = $(PNGPATH)/lib/libpng.a
ZPATH = /usr/local
ZINC = -I$(ZPATH)/include
#ZLIB = -L$(ZPATH)/lib -lz
ZLIB = $(ZPATH)/lib/libz.a
#XPATH = /usr/X11
XPATH = /usr/X11R6
XINC = -I$(XPATH)/include
XLIB = -L$(XPATH)/lib -lX11
INCS = $(PNGINC) $(ZINC) $(XINC)
RLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm
WLIBS = $(PNGLIB) $(ZLIB) -lm
CC = gcc
LD = gcc
RM = rm -f
CFLAGS = -O -Wall $(INCS)
# [note that -Wall is a gcc-specific compilation flag ("all warnings on")]
LDFLAGS =
O = .o
E =
RPNG = rpng-x
RPNG2 = rpng2-x
WPNG = wpng
ROBJS = $(RPNG)$(O) readpng$(O)
ROBJS2 = $(RPNG2)$(O) readpng2$(O)
WOBJS = $(WPNG)$(O) writepng$(O)
EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
# implicit make rules -------------------------------------------------------
.c$(O):
$(CC) -c $(CFLAGS) $<
# dependencies --------------------------------------------------------------
all: $(EXES)
$(RPNG)$(E): $(ROBJS)
$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBS)
$(RPNG2)$(E): $(ROBJS2)
$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBS)
$(WPNG)$(E): $(WOBJS)
$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBS)
$(RPNG)$(O): $(RPNG).c readpng.h
$(RPNG2)$(O): $(RPNG2).c readpng2.h
$(WPNG)$(O): $(WPNG).c writepng.h
readpng$(O): readpng.c readpng.h
readpng2$(O): readpng2.c readpng2.h
writepng$(O): writepng.c writepng.h
# maintenance ---------------------------------------------------------------
clean:
$(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
# Sample makefile for rpng-win / rpng2-win / wpng using MSVC and NMAKE.
# Greg Roelofs
# Last modified: 16 February 1999
#
# The programs built by this makefile are described in the book,
# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
# Associates, 1999). Go buy a copy, eh? Buy some for friends
# and family, too. (Not that this is a blatant plug or anything.)
#
# Invoke this makefile from a DOS prompt window via:
#
# %devstudio%\vc\bin\vcvars32.bat
# nmake -nologo -f makefile.w32
#
# where %devstudio% is the installation directory for MSVC / DevStudio. If
# you get "environment out of space" errors, create a desktop shortcut with
# "c:\windows\command.com /e:4096" as the program command line and set the
# working directory to this directory. Then double-click to open the new
# DOS-prompt window with a bigger environment and retry the commands above.
#
# This makefile assumes libpng and zlib have already been built or downloaded
# and are in subdirectories at the same level as the current subdirectory
# (as indicated by the PNGPATH and ZPATH macros below). Edit as appropriate.
#
# Note that the names of the dynamic and static libpng and zlib libraries
# used below may change in later releases of the libraries. This makefile
# builds statically linked executables, but that can be changed by uncom-
# menting the appropriate PNGLIB and ZLIB lines.
!include <ntwin32.mak>
# macros --------------------------------------------------------------------
PNGPATH = ../libpng
PNGINC = -I$(PNGPATH)
#PNGLIB = $(PNGPATH)/pngdll.lib
PNGLIB = $(PNGPATH)/libpng.lib
ZPATH = ../zlib
ZINC = -I$(ZPATH)
#ZLIB = $(ZPATH)/zlibdll.lib
ZLIB = $(ZPATH)/zlibstat.lib
WINLIBS = -defaultlib:user32.lib gdi32.lib
# ["real" apps may also need comctl32.lib, comdlg32.lib, winmm.lib, etc.]
INCS = $(PNGINC) $(ZINC)
RLIBS = $(PNGLIB) $(ZLIB) $(WINLIBS)
WLIBS = $(PNGLIB) $(ZLIB)
CC = cl
LD = link
RM = del
CFLAGS = -nologo -O -W3 $(INCS) $(cvars)
# [note that -Wall is an MSVC-specific compilation flag ("all warnings on")]
# [see %devstudio%\vc\include\win32.mak for cvars macro definition]
O = .obj
E = .exe
RLDFLAGS = -nologo -subsystem:windows
WLDFLAGS = -nologo
RPNG = rpng-win
RPNG2 = rpng2-win
WPNG = wpng
ROBJS = $(RPNG)$(O) readpng$(O)
ROBJS2 = $(RPNG2)$(O) readpng2$(O)
WOBJS = $(WPNG)$(O) writepng$(O)
EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
# implicit make rules -------------------------------------------------------
.c$(O):
$(CC) -c $(CFLAGS) $<
# dependencies --------------------------------------------------------------
all: $(EXES)
$(RPNG)$(E): $(ROBJS)
$(LD) $(RLDFLAGS) -out:$@ $(ROBJS) $(RLIBS)
$(RPNG2)$(E): $(ROBJS2)
$(LD) $(RLDFLAGS) -out:$@ $(ROBJS2) $(RLIBS)
$(WPNG)$(E): $(WOBJS)
$(LD) $(WLDFLAGS) -out:$@ $(WOBJS) $(WLIBS)
$(RPNG)$(O): $(RPNG).c readpng.h
$(RPNG2)$(O): $(RPNG2).c readpng2.h
$(WPNG)$(O): $(WPNG).c writepng.h
readpng$(O): readpng.c readpng.h
readpng2$(O): readpng2.c readpng2.h
writepng$(O): writepng.c writepng.h
# maintenance ---------------------------------------------------------------
clean:
# ideally we could just do this:
# $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
# ...but the Windows "DEL" command is none too bright, so:
$(RM) r*$(E)
$(RM) w*$(E)
$(RM) r*$(O)
$(RM) w*$(O)
/*---------------------------------------------------------------------------
rpng - simple PNG display program readpng.c
---------------------------------------------------------------------------
Copyright (c) 1998-1999 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
be held liable for any damages arising in any way from the use of
this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. Redistributions of source code must retain the above copyright
notice, disclaimer, and this list of conditions.
2. Redistributions in binary form must reproduce the above copyright
notice, disclaimer, and this list of conditions in the documenta-
tion and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this
software must display the following acknowledgment:
This product includes software developed by Greg Roelofs
and contributors for the book, "PNG: The Definitive Guide,"
published by O'Reilly and Associates.
---------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include "png.h" /* libpng header; includes zlib.h */
#include "readpng.h" /* typedefs, common macros, public prototypes */
static png_structp png_ptr = NULL;
static png_infop info_ptr = NULL;
png_uint_32 width, height;
int bit_depth, color_type;
uch *image_data = NULL;
void readpng_version_info()
{
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
PNG_LIBPNG_VER_STRING, png_libpng_ver);
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
ZLIB_VERSION, zlib_version);
}
/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */
int readpng_init(FILE *infile, long *pWidth, long *pHeight)
{
uch sig[8];
/* first do a quick check that the file really is a PNG image; could
* have used slightly more general png_sig_cmp() function instead */
fread(sig, 1, 8, infile);
if (!png_check_sig(sig, 8))
return 1; /* bad signature */
/* could pass pointers to user-defined error handlers instead of NULLs: */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
return 4; /* out of memory */
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
return 4; /* out of memory */
}
/* we could create a second info struct here (end_info), but it's only
* useful if we want to keep pre- and post-IDAT chunk info separated
* (mainly for PNG-aware image editors and converters) */
/* setjmp() must be called in every function that calls a PNG-reading
* libpng function */
if (setjmp(png_ptr->jmpbuf)) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return 2;
}
png_init_io(png_ptr, infile);
png_set_sig_bytes(png_ptr, 8); /* we already read the 8 signature bytes */
png_read_info(png_ptr, info_ptr); /* read all PNG info up to image data */
/* alternatively, could make separate calls to png_get_image_width(),
* etc., but want bit_depth and color_type for later [don't care about
* compression_type and filter_type => NULLs] */
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
NULL, NULL, NULL);
*pWidth = width;
*pHeight = height;
/* OK, that's all we need for now; return happy */
return 0;
}
/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;
* scales values to 8-bit if necessary */
int readpng_get_bgcolor(uch *red, uch *green, uch *blue)
{
png_color_16p pBackground;
/* setjmp() must be called in every function that calls a PNG-reading
* libpng function */
if (setjmp(png_ptr->jmpbuf)) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return 2;
}
if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
return 1;
/* it is not obvious from the libpng documentation, but this function
* takes a pointer to a pointer, and it always returns valid red, green
* and blue values, regardless of color_type: */
png_get_bKGD(png_ptr, info_ptr, &pBackground);
/* however, it always returns the raw bKGD data, regardless of any
* bit-depth transformations, so check depth and adjust if necessary */
if (bit_depth == 16) {
*red = pBackground->red >> 8;
*green = pBackground->green >> 8;
*blue = pBackground->blue >> 8;
} else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
if (bit_depth == 1)
*red = *green = *blue = pBackground->gray? 255 : 0;
else if (bit_depth == 2)
*red = *green = *blue = (255/3) * pBackground->gray;
else /* bit_depth == 4 */
*red = *green = *blue = (255/15) * pBackground->gray;
} else {
*red = (uch)pBackground->red;
*green = (uch)pBackground->green;
*blue = (uch)pBackground->blue;
}
return 0;
}
/* display_exponent == LUT_exponent * CRT_exponent */
uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
{
double gamma;
png_uint_32 i, rowbytes;
png_bytepp row_pointers = NULL;
/* setjmp() must be called in every function that calls a PNG-reading
* libpng function */
if (setjmp(png_ptr->jmpbuf)) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
}
/* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
* transparency chunks to full alpha channel; strip 16-bit-per-sample
* images to 8 bits per sample; and convert grayscale to RGB[A] */
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_expand(png_ptr);
if (bit_depth == 16)
png_set_strip_16(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
/* unlike the example in the libpng documentation, we have *no* idea where
* this file may have come from--so if it doesn't have a file gamma, don't
* do any correction ("do no harm") */
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
png_set_gamma(png_ptr, display_exponent, gamma);
/* all transformations have been registered; now update info_ptr data,
* get rowbytes and channels, and allocate image memory */
png_read_update_info(png_ptr, info_ptr);
*pRowbytes = rowbytes = png_get_rowbytes(png_ptr, info_ptr);
*pChannels = (int)png_get_channels(png_ptr, info_ptr);
if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
}
if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
free(image_data);
image_data = NULL;
return NULL;
}
Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height));
/* set the individual row_pointers to point at the correct offsets */
for (i = 0; i < height; ++i)
row_pointers[i] = image_data + i*rowbytes;
/* now we can go ahead and just read the whole image */
png_read_image(png_ptr, row_pointers);
/* and we're done! (png_read_end() can be omitted if no processing of
* post-IDAT text/time/etc. is desired) */
free(row_pointers);
row_pointers = NULL;
png_read_end(png_ptr, NULL);
return image_data;
}
void readpng_cleanup(int free_image_data)
{
if (free_image_data && image_data) {
free(image_data);
image_data = NULL;
}
if (png_ptr && info_ptr) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
png_ptr = NULL;
info_ptr = NULL;
}
}
/*---------------------------------------------------------------------------
rpng - simple PNG display program readpng.h
---------------------------------------------------------------------------
Copyright (c) 1998-1999 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
be held liable for any damages arising in any way from the use of
this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. Redistributions of source code must retain the above copyright
notice, disclaimer, and this list of conditions.
2. Redistributions in binary form must reproduce the above copyright
notice, disclaimer, and this list of conditions in the documenta-
tion and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this
software must display the following acknowledgment:
This product includes software developed by Greg Roelofs
and contributors for the book, "PNG: The Definitive Guide,"
published by O'Reilly and Associates.
---------------------------------------------------------------------------*/
#ifndef TRUE
# define TRUE 1
# define FALSE 0
#endif
#ifndef MAX
# define MAX(a,b) ((a) > (b)? (a) : (b))
# define MIN(a,b) ((a) < (b)? (a) : (b))
#endif
#ifdef DEBUG
# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
#else
# define Trace(x) ;
#endif
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
/* prototypes for public functions in readpng.c */
void readpng_version_info(void);
int readpng_init(FILE *infile, long *pWidth, long *pHeight);
int readpng_get_bgcolor(uch *bg_red, uch *bg_green, uch *bg_blue);
uch *readpng_get_image(double display_exponent, int *pChannels,
ulg *pRowbytes);
void readpng_cleanup(int free_image_data);
/*---------------------------------------------------------------------------
rpng2 - progressive-model PNG display program readpng2.c
---------------------------------------------------------------------------
Copyright (c) 1998-1999 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
be held liable for any damages arising in any way from the use of
this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. Redistributions of source code must retain the above copyright
notice, disclaimer, and this list of conditions.
2. Redistributions in binary form must reproduce the above copyright
notice, disclaimer, and this list of conditions in the documenta-
tion and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this
software must display the following acknowledgment:
This product includes software developed by Greg Roelofs
and contributors for the book, "PNG: The Definitive Guide,"
published by O'Reilly and Associates.
---------------------------------------------------------------------------*/
#include <stdlib.h> /* for exit() prototype */
#include "png.h" /* libpng header; includes zlib.h and setjmp.h */
#include "readpng2.h" /* typedefs, common macros, public prototypes */
/* local prototypes */
static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr);
static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass);
static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr);
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg);
void readpng2_version_info()
{
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
PNG_LIBPNG_VER_STRING, png_libpng_ver);
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
ZLIB_VERSION, zlib_version);
}
int readpng2_check_sig(uch *sig, int num)
{
return png_check_sig(sig, num);
}
/* returns 0 for success, 2 for libpng problem, 4 for out of memory */
int readpng2_init(mainprog_info *mainprog_ptr)
{
png_structp png_ptr; /* note: temporary variables! */
png_infop info_ptr;
/* could also replace libpng warning-handler (final NULL), but no need: */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
readpng2_error_handler, NULL);
if (!png_ptr)
return 4; /* out of memory */
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
return 4; /* out of memory */
}
/* we could create a second info struct here (end_info), but it's only
* useful if we want to keep pre- and post-IDAT chunk info separated
* (mainly for PNG-aware image editors and converters) */
/* setjmp() must be called in every function that calls a PNG-reading
* libpng function, unless an alternate error handler was installed--
* but compatible error handlers must either use longjmp() themselves
* (as in this program) or exit immediately, so here we are: */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return 2;
}
/* instead of doing png_init_io() here, now we set up our callback
* functions for progressive decoding */
png_set_progressive_read_fn(png_ptr, mainprog_ptr,
readpng2_info_callback, readpng2_row_callback, readpng2_end_callback);
/* make sure we save our pointers for use in readpng2_decode_data() */
mainprog_ptr->png_ptr = png_ptr;
mainprog_ptr->info_ptr = info_ptr;
/* and that's all there is to initialization */
return 0;
}
/* returns 0 for success, 2 for libpng (longjmp) problem */
int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length)
{
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
/* setjmp() must be called in every function that calls a PNG-reading
* libpng function */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
mainprog_ptr->png_ptr = NULL;
mainprog_ptr->info_ptr = NULL;
return 2;
}
/* hand off the next chunk of input data to libpng for decoding */
png_process_data(png_ptr, info_ptr, rawbuf, length);
return 0;
}
static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr)
{
mainprog_info *mainprog_ptr;
int color_type, bit_depth;
double gamma;
/* setjmp() doesn't make sense here, because we'd either have to exit(),
* longjmp() ourselves, or return control to libpng, which doesn't want
* to see us again. By not doing anything here, libpng will instead jump
* to readpng2_decode_data(), which can return an error value to the main
* program. */
/* retrieve the pointer to our special-purpose struct, using the png_ptr
* that libpng passed back to us (i.e., not a global this time--there's
* no real difference for a single image, but for a multithreaded browser
* decoding several PNG images at the same time, one needs to avoid mixing
* up different images' structs) */
mainprog_ptr = png_get_progressive_ptr(png_ptr);
if (mainprog_ptr == NULL) { /* we be hosed */
fprintf(stderr,
"readpng2 error: main struct not recoverable in info_callback.\n");
fflush(stderr);
return;
/*
* Alternatively, we could call our error-handler just like libpng
* does, which would effectively terminate the program. Since this
* can only happen if png_ptr gets redirected somewhere odd or the
* main PNG struct gets wiped, we're probably toast anyway. (If
* png_ptr itself is NULL, we would not have been called.)
*/
}
/* this is just like in the non-progressive case */
png_get_IHDR(png_ptr, info_ptr, &mainprog_ptr->width,
&mainprog_ptr->height, &bit_depth, &color_type, NULL, NULL, NULL);
/* since we know we've read all of the PNG file's "header" (i.e., up
* to IDAT), we can check for a background color here */
if (mainprog_ptr->need_bgcolor &&
png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
{
png_color_16p pBackground;
/* it is not obvious from the libpng documentation, but this function
* takes a pointer to a pointer, and it always returns valid red,
* green and blue values, regardless of color_type: */
png_get_bKGD(png_ptr, info_ptr, &pBackground);
/* however, it always returns the raw bKGD data, regardless of any
* bit-depth transformations, so check depth and adjust if necessary */
if (bit_depth == 16) {
mainprog_ptr->bg_red = pBackground->red >> 8;
mainprog_ptr->bg_green = pBackground->green >> 8;
mainprog_ptr->bg_blue = pBackground->blue >> 8;
} else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
if (bit_depth == 1)
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
mainprog_ptr->bg_blue = pBackground->gray? 255 : 0;
else if (bit_depth == 2)
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
mainprog_ptr->bg_blue = (255/3) * pBackground->gray;
else /* bit_depth == 4 */
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
mainprog_ptr->bg_blue = (255/15) * pBackground->gray;
} else {
mainprog_ptr->bg_red = (uch)pBackground->red;
mainprog_ptr->bg_green = (uch)pBackground->green;
mainprog_ptr->bg_blue = (uch)pBackground->blue;
}
}
/* as before, let libpng expand palette images to RGB, low-bit-depth
* grayscale images to 8 bits, transparency chunks to full alpha channel;
* strip 16-bit-per-sample images to 8 bits per sample; and convert
* grayscale to RGB[A] */
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_expand(png_ptr);
if (bit_depth == 16)
png_set_strip_16(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
/* Unlike the basic viewer, which was designed to operate on local files,
* this program is intended to simulate a web browser--even though we
* actually read from a local file, too. But because we are pretending
* that most of the images originate on the Internet, we follow the recom-
* mendation of the sRGB proposal and treat unlabelled images (no gAMA
* chunk) as existing in the sRGB color space. That is, we assume that
* such images have a file gamma of 0.45455, which corresponds to a PC-like
* display system. This change in assumptions will have no effect on a
* PC-like system, but on a Mac, SGI, NeXT or other system with a non-
* identity lookup table, it will darken unlabelled images, which effec-
* tively favors images from PC-like systems over those originating on
* the local platform. Note that mainprog_ptr->display_exponent is the
* "gamma" value for the entire display system, i.e., the product of
* LUT_exponent and CRT_exponent. */
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
png_set_gamma(png_ptr, mainprog_ptr->display_exponent, gamma);
else
png_set_gamma(png_ptr, mainprog_ptr->display_exponent, 0.45455);
/* we'll let libpng expand interlaced images, too */
mainprog_ptr->passes = png_set_interlace_handling(png_ptr);
/* all transformations have been registered; now update info_ptr data and
* then get rowbytes and channels */
png_read_update_info(png_ptr, info_ptr);
mainprog_ptr->rowbytes = png_get_rowbytes(png_ptr, info_ptr);
mainprog_ptr->channels = png_get_channels(png_ptr, info_ptr);
/* Call the main program to allocate memory for the image buffer and
* initialize windows and whatnot. (The old-style function-pointer
* invocation is used for compatibility with a few supposedly ANSI
* compilers that nevertheless barf on "fn_ptr()"-style syntax.) */
(*mainprog_ptr->mainprog_init)();
/* and that takes care of initialization */
return;
}
static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass)
{
mainprog_info *mainprog_ptr;
/* first check whether the row differs from the previous pass; if not,
* nothing to combine or display */
if (!new_row)
return;
/* retrieve the pointer to our special-purpose struct so we can access
* the old rows and image-display callback function */
mainprog_ptr = png_get_progressive_ptr(png_ptr);
/* have libpng either combine the new row data with the existing row data
* from previous passes (if interlaced) or else just copy the new row
* into the main program's image buffer */
png_progressive_combine_row(png_ptr, mainprog_ptr->row_pointers[row_num],
new_row);
/* finally, call the display routine in the main program with the number
* of the row we just updated */
(*mainprog_ptr->mainprog_display_row)(row_num);
/* and we're ready for more */
return;
}
static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr)
{
mainprog_info *mainprog_ptr;
/* retrieve the pointer to our special-purpose struct */
mainprog_ptr = png_get_progressive_ptr(png_ptr);
/* let the main program know that it should flush any buffered image
* data to the display now and set a "done" flag or whatever, but note
* that it SHOULD NOT DESTROY THE PNG STRUCTS YET--in other words, do
* NOT call readpng2_cleanup() either here or in the finish_display()
* routine; wait until control returns to the main program via
* readpng2_decode_data() */
(*mainprog_ptr->mainprog_finish_display)();
/* all done */
return;
}
void readpng2_cleanup(mainprog_info *mainprog_ptr)
{
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
if (png_ptr && info_ptr)
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
mainprog_ptr->png_ptr = NULL;
mainprog_ptr->info_ptr = NULL;
}
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg)
{
mainprog_info *mainprog_ptr;
/* This function, aside from the extra step of retrieving the "error
* pointer" (below) and the fact that it exists within the application
* rather than within libpng, is essentially identical to libpng's
* default error handler. The second point is critical: since both
* setjmp() and longjmp() are called from the same code, they are
* guaranteed to have compatible notions of how big a jmp_buf is,
* regardless of whether _BSD_SOURCE or anything else has (or has not)
* been defined. */
fprintf(stderr, "readpng2 libpng error: %s\n", msg);
fflush(stderr);
mainprog_ptr = png_get_error_ptr(png_ptr);
if (mainprog_ptr == NULL) { /* we are completely hosed now */
fprintf(stderr,
"readpng2 severe error: jmpbuf not recoverable; terminating.\n");
fflush(stderr);
exit(99);
}
longjmp(mainprog_ptr->jmpbuf, 1);
}
/*---------------------------------------------------------------------------
rpng2 - progressive-model PNG display program readpng2.h
---------------------------------------------------------------------------
Copyright (c) 1998-1999 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
be held liable for any damages arising in any way from the use of
this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. Redistributions of source code must retain the above copyright
notice, disclaimer, and this list of conditions.
2. Redistributions in binary form must reproduce the above copyright
notice, disclaimer, and this list of conditions in the documenta-
tion and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this
software must display the following acknowledgment:
This product includes software developed by Greg Roelofs
and contributors for the book, "PNG: The Definitive Guide,"
published by O'Reilly and Associates.
---------------------------------------------------------------------------*/
#ifndef TRUE
# define TRUE 1
# define FALSE 0
#endif
#ifndef MAX
# define MAX(a,b) ((a) > (b)? (a) : (b))
# define MIN(a,b) ((a) < (b)? (a) : (b))
#endif
#ifdef DEBUG
# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
#else
# define Trace(x) ;
#endif
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
typedef struct _mainprog_info {
double display_exponent;
ulg width;
ulg height;
void *png_ptr;
void *info_ptr;
void (*mainprog_init)(void);
void (*mainprog_display_row)(ulg row_num);
void (*mainprog_finish_display)(void);
uch *image_data;
uch **row_pointers;
jmp_buf jmpbuf;
int passes; /* not used */
int rowbytes;
int channels;
int need_bgcolor;
int done;
uch bg_red;
uch bg_green;
uch bg_blue;
} mainprog_info;
/* prototypes for public functions in readpng2.c */
void readpng2_version_info(void);
int readpng2_check_sig(uch *sig, int num);
int readpng2_init(mainprog_info *mainprog_ptr);
int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length);
void readpng2_cleanup(mainprog_info *mainprog_ptr);
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
#if 0 /* in case someone actually tries to compile this */
/* example.c - an example of using libpng */
/* This is an example of how to use libpng to read and write PNG files.
......@@ -701,3 +703,4 @@ void write_png(char *file_name /* , ... other image information ... */)
return;
}
#endif /* if 0 */
此差异已折叠。
libpng.txt - A description on how to use and modify libpng
libpng version 1.0.4e - October 10, 1999
libpng version 1.0.4f - October 12, 1999
Updated and distributed by Glenn Randers-Pehrson
<randeg@alum.rpi.edu>
Copyright (c) 1998, 1999 Glenn Randers-Pehrson
......@@ -2058,13 +2058,13 @@ the old method.
VII. Y2K Compliance in libpng
October 10, 1999
October 12, 1999
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.4e are Y2K compliant. It is my belief that earlier
upward through 1.0.4f 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 that
......
.TH LIBPNGPF 3 October 10, 1999
.TH LIBPNGPF 3 October 12, 1999
.SH NAME
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4e - October 10, 1999
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4f - October 12, 1999
(private functions)
.SH SYNOPSIS
\fB#include <png.h>\fP
......
.TH PNG 5 "October 10, 1999"
.TH PNG 5 "October 12, 1999"
.SH NAME
png \- Portable Network Graphics (PNG) format
.SH DESCRIPTION
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
/* pngget.c - retrieval of values from info struct
*
* libpng 1.0.4e - October 10, 1999
* libpng 1.0.4f - October 12, 1999
* 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
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册