Imported from libpng-0.98.tar
This commit is contained in:
parent
2687fcc7b5
commit
c4a2ae6cac
33
CHANGES
33
CHANGES
@ -170,20 +170,33 @@ version 0.96 [May, 1997]
|
||||
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.
|
||||
added RFC 1152 date support
|
||||
fixed typecasts of "new_key", etc. (Andreas Dilger)
|
||||
added RFC 1152 [sic] date support
|
||||
fixed bug in gamma handling of 4-bit grayscale
|
||||
added more typecasts. 65536L becomes (png_uint_32)65536L, etc.
|
||||
added 2-bit grayscale gamma handling (Glenn R-P)
|
||||
added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P)
|
||||
minor corrections in libpng.txt
|
||||
added simple sRGB support
|
||||
make it simpler to do conditional compiling: PNG_READ_NOT_FULLY_SUPPORTED
|
||||
fixed memory leak in pngwrite.c (free info_ptr->text)
|
||||
added simple sRGB support (Glenn R-P)
|
||||
easier conditional compiling, e.g. define PNG_READ/WRITE_NOT_FULLY_SUPPORTED;
|
||||
all configurable options can be selected from command-line instead
|
||||
of having to edit pngconf.h (Glenn R-P)
|
||||
fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P)
|
||||
added more conditions for png_do_background, to avoid changing
|
||||
black pixels to background when a background is supplied and
|
||||
no pixels are transparent
|
||||
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?]
|
||||
tested NODIV support and made it default behaviour (Greg Roelofs)
|
||||
added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler)
|
||||
regularized version numbering scheme and bumped shared-library major
|
||||
version number to 2 to avoid potential problems with libpng 0.89 apps
|
||||
version number to 2 to avoid problems with libpng 0.89 apps (Greg Roelofs)
|
||||
version 0.98 [January, 1998]
|
||||
cleaned up some typos in libpng.txt and in code documentation
|
||||
fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler)
|
||||
cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c
|
||||
changed recommendation about file_gamma for PC images to .51 from .45,
|
||||
in example.c and libpng.txt, added comments to distinguish between
|
||||
screen_gamma, viewing_gamma, and display_gamma.
|
||||
changed all references to RFC1152 to read RFC1123 and changed the
|
||||
PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED
|
||||
added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent)
|
||||
changed srgb_intent from png_byte to int to avoid compiler bugs
|
||||
|
34
README
34
README
@ -1,4 +1,4 @@
|
||||
[NOTE: this is still beta version 0.97c; the text below has already
|
||||
[NOTE: this is still beta version 0.97d; the text below has already
|
||||
been updated in anticipation of the imminent 1.0 release.]
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ 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
|
||||
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
|
||||
changes to the API in some time, and people have a bad feeling about
|
||||
libraries with versions < 1.0.
|
||||
@ -77,7 +77,7 @@ If not, it should be at ftp.uu.net in /graphics/png
|
||||
Eventually, it will be at ftp.uu.net in /pub/archiving/zip/zlib
|
||||
|
||||
You may also want a copy of the PNG specification. It is available
|
||||
as an Internet Draft, and RFC, and a W3C Recommendation. Failing
|
||||
as an RFC and a W3C Recommendation. Failing
|
||||
these resources you can try ftp.uu.net in the /graphics/png directory.
|
||||
|
||||
This code is currently being archived at ftp.uu.net in the
|
||||
@ -97,19 +97,19 @@ Finally, if you get any warning messages when compiling libpng
|
||||
fix. Please mention "libpng" somewhere in the subject line. Thanks.
|
||||
|
||||
This release was created and will be supported by myself (of course
|
||||
based in a large way on Guy's earlier work), and the PNG group.
|
||||
based in a large way on Guy's and Andreas' earlier work), and the PNG group.
|
||||
|
||||
adilger@enel.ucalgary.ca
|
||||
png-implement@dworkin.wustl.edu
|
||||
|
||||
You can reach Guy, the original libpng author, at (internet preferred):
|
||||
|
||||
internet: schalnat@group42.com
|
||||
CompuServe: 75501,1625
|
||||
You can't reach Guy, the original libpng author, at the addresses
|
||||
given in previous versions of this document. He will read mail
|
||||
addressed to the png-implement list, however.
|
||||
|
||||
Please do not send general questions about PNG. Send them to
|
||||
the address in the specification. At the same time, please do
|
||||
not send libpng questions to that address, send them to me. I'll
|
||||
the address in the specification (png-group@w3.org). At the same
|
||||
time, please do not send libpng questions to that address, send them to me
|
||||
or to png-implement@dworkin.wustl.edu. I'll
|
||||
get them in the end anyway. If you have a question about something
|
||||
in the PNG specification that is related to using libpng, send it
|
||||
to me. Send me any questions that start with "I was using libpng,
|
||||
@ -132,18 +132,20 @@ Files in this distribution:
|
||||
descrip.mms => VMS project file
|
||||
example.c => Example code for using libpng functions
|
||||
libpng.txt => Description of libpng and its functions
|
||||
makefile => Default Unixish makefile
|
||||
makefile.aco => ACORN makefile
|
||||
makefile.ama => Amiga makefile
|
||||
makefile.atr => Atari makefile
|
||||
makefile.bor => Borland makefile
|
||||
makefile.dec => DEC makefile
|
||||
makefile.dj2 => DJGPP 2 makefile
|
||||
makefile.elf => Unix ELF makefile
|
||||
makefile.knr => Makefile which calls ansi2knr to convert files
|
||||
makefile.mip => MIPS makefile
|
||||
makefile.msc => Microsoft C makefile
|
||||
makefile.sgi => Silicon Graphics Irix makefile
|
||||
makefile.std => Standard Unix makefile
|
||||
makefile.tc => Turbo C makefile
|
||||
makefile.sun => SUN makefile
|
||||
makefile.tc3 => Turbo C 3.0 makefile
|
||||
makevms.com => VMS make program
|
||||
png.c => Basic interface functions common to library
|
||||
png.h => Library function and interface declarations
|
||||
@ -166,13 +168,15 @@ Files in this distribution:
|
||||
|
||||
Good luck, and happy coding.
|
||||
|
||||
-Glenn Randers-Pehrson
|
||||
Internet: randeg@alumni.rpi.edu
|
||||
Web: http://www.rpi.edu/~randeg/index.html
|
||||
|
||||
-Andreas Eric Dilger
|
||||
Internet: adilger@enel.ucalgary.ca
|
||||
Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/
|
||||
|
||||
-Guy Eric Schalnat
|
||||
Group 42, Inc.
|
||||
Internet: schalnat@group42.com
|
||||
CompuServe: 75501,1625
|
||||
(formerly of Group 42, Inc)
|
||||
Web: http://www.group42.com/
|
||||
|
||||
|
2
TODO
2
TODO
@ -5,7 +5,7 @@ improved dithering
|
||||
multi-lingual error and warning message support
|
||||
sPLT chunk handling
|
||||
cHRM transformation
|
||||
complete sRGB transformation (presently it simply uses gamma=0.5)
|
||||
complete sRGB transformation (presently it simply uses gamma=0.51)
|
||||
man pages for function calls
|
||||
high-level API for reading images
|
||||
final bug fixes
|
||||
|
16
example.c
16
example.c
@ -190,19 +190,22 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
|
||||
|
||||
/* Some suggestions as to how to get a screen gamma value */
|
||||
|
||||
/* Note that screen gamma is (display_gamma/viewing_gamma)
|
||||
if (/* We have a user-defined screen gamma value */)
|
||||
{
|
||||
screen_gamma = user-defined screen_gamma;
|
||||
}
|
||||
/* This is one way that applications share the same screen gamma value */
|
||||
else if ((gamma_str = getenv("DISPLAY_GAMMA")) != NULL)
|
||||
else if ((gamma_str = getenv("SCREEN_GAMMA")) != NULL)
|
||||
{
|
||||
screen_gamma = atof(gamma_str);
|
||||
}
|
||||
/* If we don't have another value */
|
||||
else
|
||||
{
|
||||
screen_gamma = 2.2; /* A good guess for PC monitors */
|
||||
screen_gamma = 2.2; /* A good guess for a PC monitors in a brightly
|
||||
lit room */
|
||||
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
|
||||
}
|
||||
|
||||
@ -211,13 +214,16 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
* by the user at run time by the user. It is strongly suggested that
|
||||
* your application support gamma correction.
|
||||
*/
|
||||
if (png_get_sRGB(png_ptr, info_ptr, &srgb_intent)
|
||||
png_set_sRGB(png_ptr, srgb_intent, 0);
|
||||
|
||||
int intent;
|
||||
|
||||
if (png_get_sRGB(png_ptr, info_ptr, &intent)
|
||||
png_set_sRGB(png_ptr, intent, 0);
|
||||
else
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma)
|
||||
png_set_gamma(png_ptr, screen_gamma, image_gamma);
|
||||
else
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45);
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.51);
|
||||
|
||||
/* Dither RGB files down to 8 bit palette or reduce palettes
|
||||
* to the number of colors available on your screen.
|
||||
|
161
libpng.txt
161
libpng.txt
@ -1,10 +1,13 @@
|
||||
libpng.txt - a description on how to use and modify libpng
|
||||
|
||||
libpng version 1.00 version 0.97
|
||||
libpng version 0.98
|
||||
Updated and distributed by Glenn Randers-Pehrson <randeg@alumni.rpi.edu>
|
||||
Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
January 16, 1998
|
||||
|
||||
based on:
|
||||
|
||||
libpng version 1.00 version 0.96
|
||||
libpng 1.0 beta 6 version 0.96
|
||||
Updated and distributed by Andreas Dilger <adilger@enel.ucalgary.ca>,
|
||||
Copyright (c) 1996, 1997 Andreas Dilger
|
||||
May 28, 1997
|
||||
@ -29,7 +32,7 @@ it is heavily commented and should include everything most people
|
||||
will need.
|
||||
|
||||
Libpng was written as a companion to the PNG specification, as a way
|
||||
to reduce the amount of time and effort it takes to support the PNG
|
||||
of reducing the amount of time and effort it takes to support the PNG
|
||||
file format in application programs. The PNG specification is available
|
||||
as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/> and as a
|
||||
W3C Recommendation <http://www.w3.org/pub/WWW/TR/REC.png.html>. Some
|
||||
@ -49,12 +52,14 @@ machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
|
||||
to use. The ultimate goal of libpng is to promote the acceptance of
|
||||
the PNG file format in whatever way possible. While there is still
|
||||
work to be done (see the TODO file), libpng should cover the
|
||||
majority of the needs of it's users.
|
||||
majority of the needs of its users.
|
||||
|
||||
Libpng uses zlib for its compression and decompression of PNG files.
|
||||
The zlib compression utility is a general purpose utility that is
|
||||
useful for more than PNG files, and can be used without libpng.
|
||||
See the documentation delivered with zlib for more details.
|
||||
You can usually find the source files for the zlib utility wherever you
|
||||
find the libpng source files.
|
||||
|
||||
Libpng is thread safe, provided the threads are using different
|
||||
instances of the structures. Each thread should have its own
|
||||
@ -69,13 +74,15 @@ II. Structures
|
||||
There are two main structures that are important to libpng, png_struct
|
||||
and png_info. The first, png_struct, is an internal structure that
|
||||
will not, for the most part, be used by a user except as the first
|
||||
variable passed to every libpng function call.
|
||||
variable passed to every libpng function call. It is not actually
|
||||
used in many of the functions; do not be alarmed about compiler
|
||||
warnings that say something to the effect that "png_ptr is not used."
|
||||
|
||||
The png_info structure is designed to provide information about the
|
||||
PNG file. At one time, the fields of png_info were intended to be
|
||||
directly accessible to the user. However, this tended to cause problems
|
||||
with applications using dynamically loaded libraries, and as a result
|
||||
a set of interface functions for png_info were delevoped. The fields
|
||||
a set of interface functions for png_info was developed. The fields
|
||||
of png_info are still available for older applications, but it is
|
||||
suggested that applications use the new interfaces if at all possible.
|
||||
|
||||
@ -193,6 +200,19 @@ libpng know that there are some bytes missing from the start of the file.
|
||||
|
||||
png_set_sig_bytes(png_ptr, number);
|
||||
|
||||
In PNG files, the alpha channel in an image is the level of opacity.
|
||||
If you need the alpha channel in an image to be the level of transparency
|
||||
instead of opacity, you can invert the alpha channel (or the tRNS chunk
|
||||
data) after it's read, so that 0 is fully opaque and 255 (in 8-bit or
|
||||
paletted images) or 65535 (in 16-bit images) is fully transparent, with
|
||||
|
||||
png_set_invert_alpha(png_ptr);
|
||||
|
||||
This has to appear here rather than later with the other transformations
|
||||
because the tRNS chunk data must be modified in the case of paletted images.
|
||||
If your image is not a paletted image, the tRNS data (which in such cases
|
||||
represents a single color to be rendered as transparent) won't be changed.
|
||||
|
||||
You are now ready to read all the file information up to the actual
|
||||
image data. You do this with a call to png_read_info().
|
||||
|
||||
@ -252,6 +272,12 @@ into the info_ptr is returned for any complex types.
|
||||
png_get_gAMA(png_ptr, info_ptr, &gamma);
|
||||
gamma - the gamma the file is written at (PNG_INFO_gAMA)
|
||||
|
||||
png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
|
||||
srgb_intent - the rendering intent (PNG_INFO_sRGB)
|
||||
The presence of the sRGB chunk means that the pixel
|
||||
data is in the sRGB color space. This chunk also
|
||||
implies specific values of gAMA and cHRM.
|
||||
|
||||
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||
sig_bit - the number of significant bits for (PNG_INFO_sBIT)
|
||||
the gray, red, green, and blue channels, whichever
|
||||
@ -301,9 +327,9 @@ keyword/text pairs, one pair per chunk, with no limit on the number
|
||||
of text chunks, and a 2^31 byte limit on their size. While there are
|
||||
suggested keywords, there is no requirement to restrict the use to these
|
||||
strings. It is strongly suggested that keywords and text be sensible
|
||||
to humans (that's the point), so don't use abbreviations or non-printing
|
||||
symbols. See the PNG specification for more details. There is also
|
||||
no requirement to have text after the keyword.
|
||||
to humans (that's the point), so don't use abbreviations. Non-printing
|
||||
symbols are not allowed. See the PNG specification for more details.
|
||||
There is also no requirement to have text after the keyword.
|
||||
|
||||
Keywords should be limited to 79 Latin-1 characters without leading or
|
||||
trailing spaces, but non-consecutive spaces are allowed within the
|
||||
@ -381,7 +407,7 @@ values of the pixels:
|
||||
png_set_packing(png_ptr);
|
||||
|
||||
PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
|
||||
stored in a PNG image whave been "scaled" or "shifted" up to the next
|
||||
stored in a PNG image have been "scaled" or "shifted" up to the next
|
||||
higher possible bit depth (eg from 5 bits/sample in the range [0,31] to
|
||||
8 bits/sample in the range [0, 255]). However, it is also possible to
|
||||
convert the PNG pixel data back to the original bit depth of the image.
|
||||
@ -429,7 +455,7 @@ color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
|
||||
you may use this color, or supply another color more suitable for
|
||||
the current display (e.g., the background color from a web page). You
|
||||
need to tell libpng whether the color is in the gamma space of the
|
||||
dispay (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
|
||||
display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
|
||||
(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
|
||||
that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
|
||||
know why anyone would use this, but it's here).
|
||||
@ -457,28 +483,39 @@ To properly display PNG images on any kind of system, the application needs
|
||||
to know what the display gamma is. Ideally, the user will know this, and
|
||||
the application will allow them to set it. One method of allowing the user
|
||||
to set the display gamma separately for each system is to check for the
|
||||
DISPLAY_GAMMA environment variable, which will hopefully be correctly set.
|
||||
DISPLAY_GAMMA and VIEWING_GAMMA environment variables or for a SCREEN_GAMMA
|
||||
environment variable, which will hopefully be correctly set.
|
||||
|
||||
Note that display_gamma is the gamma of your display, while screen_gamma is
|
||||
the overall gamma correction required to produce pleasing results,
|
||||
which depends on the lighting conditions in the surrounding environment.
|
||||
Screen_gamma is display_gamma/viewing_gamma, where viewing_gamma is
|
||||
the amount of additional gamma correction needed to compensate for
|
||||
a dim (viewing_gamma=1.125) or dark (viewing_gamma=1.25) environment.
|
||||
In a brightly lit room, no compensation other than the display_gamma
|
||||
is needed (viewing_gamma=1.0).
|
||||
|
||||
if (/* We have a user-defined screen gamma value */)
|
||||
{
|
||||
screen_gamma = user_defined_screen_gamma;
|
||||
}
|
||||
/* One way that applications can share the same screen gamma value */
|
||||
else if ((gamma_str = getenv("DISPLAY_GAMMA")) != NULL)
|
||||
else if ((gamma_str = getenv("SCREEN_GAMMA")) != NULL)
|
||||
{
|
||||
screen_gamma = atof(gamma_str);
|
||||
}
|
||||
/* If we don't have another value */
|
||||
else
|
||||
{
|
||||
screen_gamma = 2.2; /* A good guess for PC monitors */
|
||||
screen_gamma = 2.2; /* A good guess for a PC monitor in a bright office */
|
||||
screen_gamma = 1.956; /* A good guess for a PC monitor in a dim room */
|
||||
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
|
||||
}
|
||||
|
||||
The png_set_gamma() function handles gamma transformations of the data.
|
||||
Pass both the file gamma and the current screen_gamma. If the file does
|
||||
not have a gamma value, you can pass one anyway if you have an idea what
|
||||
it is (usually 0.45 is a good guess for GIF images on PCs). Note
|
||||
it is (usually 0.51 is a good guess for GIF images on PCs). Note
|
||||
that file gammas are inverted from screen gammas. See the discussions
|
||||
on gamma in the PNG specification for an excellent description of what
|
||||
gamma is, and why all applications should support it. It is strongly
|
||||
@ -487,7 +524,7 @@ recommended that PNG viewers support gamma correction.
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
|
||||
png_set_gamma(png_ptr, screen_gamma, gamma);
|
||||
else
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45);
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.51);
|
||||
|
||||
If you need to reduce an RGB file to a paletted file, or if a paletted
|
||||
file has more entries then will fit on your screen, png_set_dither()
|
||||
@ -544,7 +581,7 @@ need to change the order the pixels are packed into bytes, you can use:
|
||||
The last thing to handle is interlacing; this is covered in detail below,
|
||||
but you must call the function here.
|
||||
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
number_of_passes = png_set_interlace_handling(png_ptr);
|
||||
|
||||
After setting the transformations, libpng can update your png_info
|
||||
structure to reflect any transformations you've requested with this
|
||||
@ -582,7 +619,7 @@ where row_pointers is:
|
||||
|
||||
You can point to void or char or whatever you use for pixels.
|
||||
|
||||
If you don't want to read int the whole image at once, you can
|
||||
If you don't want to read in the whole image at once, you can
|
||||
use png_read_rows() instead. If there is no interlacing (check
|
||||
interlace_type == PNG_INTERLACE_TYPE_NONE), this is simple:
|
||||
|
||||
@ -599,24 +636,24 @@ row_pointers:
|
||||
If the file is interlaced (info_ptr->interlace_type != 0), things get
|
||||
somewhat harder. The only current (PNG Specification version 1.0)
|
||||
interlacing type for PNG is (interlace_type == PNG_INTERLACE_TYPE_ADAM7)
|
||||
is a someewhat complicated 2D interlace scheme, known as Adam7, that
|
||||
is a somewhat complicated 2D interlace scheme, known as Adam7, that
|
||||
breaks down an image into seven smaller images of varying size, based
|
||||
on an 8x8 grid.
|
||||
|
||||
libpng can fill out those images or it can give them to you "as is".
|
||||
If you want them filled out, there are two ways to do that. The one
|
||||
mentioned in the PNG specification is to expand each pixel to cover
|
||||
those pixels that have not been read yet. This results in a blocky
|
||||
image for the first pass, which gradually smoothes out as more pixels
|
||||
are read. The other method is the "sparkle" method, where pixels are
|
||||
draw only in their final locations, with the rest of the image remaining
|
||||
whatever colors they were initialized to before the start of the read.
|
||||
The first method usually looks better, but tends to be slower, as there
|
||||
are more pixels to put in the rows.
|
||||
those pixels that have not been read yet (the "rectangle" method).
|
||||
This results in a blocky image for the first pass, which gradually
|
||||
smooths out as more pixels are read. The other method is the "sparkle"
|
||||
method, where pixels are drawn only in their final locations, with the
|
||||
rest of the image remaining whatever colors they were initialized to
|
||||
before the start of the read. The first method usually looks better,
|
||||
but tends to be slower, as there are more pixels to put in the rows.
|
||||
|
||||
If you don't want libpng to handle the interlacing details, just call
|
||||
png_read_rows() seven times to read in all seven images. Each of the
|
||||
images are valid images by themselves, or they can be combined on an
|
||||
images is a valid image by itself, or they can all be combined on an
|
||||
8x8 grid to form a single image (although if you intend to combine them
|
||||
you would be far better off using the libpng interlace handling).
|
||||
|
||||
@ -638,7 +675,7 @@ If you want libpng to expand the images, call this before calling
|
||||
png_start_read_image() or png_read_update_info():
|
||||
|
||||
if (interlace_type == PNG_INTERLACE_TYPE_ADAM7)
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
number_of_passes = png_set_interlace_handling(png_ptr);
|
||||
|
||||
This will return the number of passes needed. Currently, this
|
||||
is seven, but may change if another interlace type is added.
|
||||
@ -649,12 +686,12 @@ If you are not going to display the image after each pass, but are
|
||||
going to wait until the entire image is read in, use the sparkle
|
||||
effect. This effect is faster and the end result of either method
|
||||
is exactly the same. If you are planning on displaying the image
|
||||
after each pass, the rectangle effect is generally considered the
|
||||
after each pass, the "rectangle" effect is generally considered the
|
||||
better looking one.
|
||||
|
||||
If you only want the "sparkle" effect, just call png_read_rows() as
|
||||
normal, with the third parameter NULL. Make sure you make pass over
|
||||
the image number_passes times, and you don't change the data in the
|
||||
the image number_of_passes times, and you don't change the data in the
|
||||
rows between calls. You can change the locations of the data, just
|
||||
not the data. Each pass only writes the pixels appropriate for that
|
||||
pass, and assumes the data from previous passes is still valid.
|
||||
@ -963,6 +1000,19 @@ Some of the more important parts of the png_info are:
|
||||
png_set_gAMA(png_ptr, info_ptr, gamma);
|
||||
gamma - the gamma the image was created at (PNG_INFO_gAMA)
|
||||
|
||||
png_set_sRGB(png_ptr, info_ptr, srgb_intent);
|
||||
srgb_intent - the rendering intent (PNG_INFO_sRGB)
|
||||
The presence of the sRGB chunk means that the pixel
|
||||
data is in the sRGB color space. This chunk also
|
||||
implies specific values of gAMA and cHRM.
|
||||
|
||||
png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, srgb_intent);
|
||||
srgb_intent - the rendering intent (PNG_INFO_sRGB)
|
||||
The presence of the sRGB chunk means that the pixel
|
||||
data is in the sRGB color space. This chunk also
|
||||
causes gAMA and cHRM chunks with the specific values
|
||||
that are consistent with sRGB to be written.
|
||||
|
||||
png_set_sBIT(png_ptr, info_ptr, sig_bit);
|
||||
sig_bit - the number of significant bits for (PNG_INFO_sBIT)
|
||||
the gray, red, green, and blue channels, whichever
|
||||
@ -996,11 +1046,25 @@ Some of the more important parts of the png_info are:
|
||||
offset_y - positive offset from the top edge of the screen
|
||||
unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
|
||||
|
||||
png_get_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
|
||||
png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
|
||||
res_x - pixels/unit physical resolution in x direction
|
||||
res_y - pixels/unit physical resolution in x direction
|
||||
unit_type - PNG_RESOLUTION_UNKOWN, PNG_RESOLUTION_METER
|
||||
|
||||
In PNG files, the alpha channel in an image is the level of opacity.
|
||||
If your data is supplied as a level of transparency, you can invert the
|
||||
alpha channel before you write it, so that 0 is fully transparent and 255
|
||||
(in 8-bit or paletted images) or 65535 (in 16-bit images) is fully opaque,
|
||||
with
|
||||
|
||||
png_set_invert_alpha(png_ptr);
|
||||
|
||||
This must appear here instead of later with the other transformations
|
||||
because in the case of paletted images the tRNS chunk data has to
|
||||
be inverted before the tRNS chunk is written. If your image is not a
|
||||
paletted image, the tRNS data (which in such cases represents a single
|
||||
color to be rendered as transparent) won't be changed.
|
||||
|
||||
A quick word about text and num_text. text is an array of png_text
|
||||
structures. num_text is the number of valid structures in the array.
|
||||
If you want, you can use max_text to hold the size of the array, but
|
||||
@ -1072,8 +1136,8 @@ tEXt chunk use RFC 1123 format dates (eg 22 May 1997 18:07:10 GMT"),
|
||||
although this isn't a requirement. Unlike the tIME chunk, the
|
||||
"Creation Time" tEXt chunk is not expected to be automatically changed
|
||||
by the software. To facilitate the use of RFC 1123 dates, a function
|
||||
png_convert_to_rfc1152(png_timep) is provided to convert from PNG
|
||||
time to an RFC 1152 format string.
|
||||
png_convert_to_rfc1123(png_timep) is provided to convert from PNG
|
||||
time to an RFC 1123 format string.
|
||||
|
||||
You are now ready to write all the file information up to the actual
|
||||
image data. You do this with a call to png_write_info().
|
||||
@ -1229,12 +1293,12 @@ correct number of times to write all seven sub-images.
|
||||
If you want libpng to build the sub-images, call this before you start
|
||||
writing any rows:
|
||||
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
number_of_passes = png_set_interlace_handling(png_ptr);
|
||||
|
||||
This will return the number of passes needed. Currently, this
|
||||
is seven, but may change if another interlace type is added.
|
||||
|
||||
Then write the complete image number_passes times.
|
||||
Then write the complete image number_of_passes times.
|
||||
|
||||
png_write_rows(png_ptr, row_pointers, number_of_rows);
|
||||
|
||||
@ -1280,7 +1344,7 @@ MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling
|
||||
memory allocation on a platform will change between applications, these
|
||||
functions must be modified in the library at compile time.
|
||||
|
||||
Input/Output in libpng is done throught png_read() and png_write(),
|
||||
Input/Output in libpng is done through png_read() and png_write(),
|
||||
which currently just call fread() and fwrite(). The FILE * is stored in
|
||||
png_struct and is initialized via png_init_io(). If you wish to change
|
||||
the method of I/O, the library supplies callbacks that you can set
|
||||
@ -1378,7 +1442,7 @@ call. See zlib.h or zconf.h in the zlib library for more information.
|
||||
Configuring for Medium Model:
|
||||
|
||||
Libpng's support for medium model has been tested on most of the popular
|
||||
complers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
|
||||
compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
|
||||
defined, and FAR gets defined to far in pngconf.h, and you should be
|
||||
all set. Everything in the library (except for zlib's structure) is
|
||||
expecting far data. You must use the typedefs with the p or pp on
|
||||
@ -1410,8 +1474,8 @@ most useful one changes the compression level, which currently uses
|
||||
input compression values in the range 0 - 9. The library normally
|
||||
uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
|
||||
have shown that for a large majority of images, compression values in
|
||||
the range 3-6 compress as well as higher levels, and do so much faster.
|
||||
For online applications it may be desirable to have maximum speed
|
||||
the range 3-6 compress nearly as well as higher levels, and do so much
|
||||
faster. For online applications it may be desirable to have maximum speed
|
||||
(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
|
||||
specify no compression (Z_NO_COMPRESSION = 0), but this would create
|
||||
files larger than just storing the raw bitmap. You can specify the
|
||||
@ -1495,8 +1559,13 @@ Removing unwanted object code:
|
||||
There are a bunch of #define's in pngconf.h that control what parts of
|
||||
libpng are compiled. All the defines end in _SUPPORTED. If you are
|
||||
never going to use an ability, you can change the #define to #undef
|
||||
before recompiling libpng and save yourself code and data space. All
|
||||
the reading and writing specific code are in seperate files, so the
|
||||
before recompiling libpng and save yourself code and data space.
|
||||
You can also turn them off en masse with a compiler directive to
|
||||
define PNG_READ_NOT_FULLY_SUPPORTED or PNG_WRITE_NOT_FULLY_SUPPORTED,
|
||||
along with directives to turn on any of the capabilities that you do
|
||||
want.
|
||||
|
||||
All the reading and writing specific code are in separate files, so the
|
||||
linker should only grab the files it needs. However, if you want to
|
||||
make sure, or if you are building a stand alone library, all the
|
||||
reading files start with pngr and all the writing files start with
|
||||
@ -1514,10 +1583,12 @@ those sections which are actually used will be loaded into memory.
|
||||
|
||||
Changes to Libpng from version 0.88
|
||||
|
||||
It should be noted that versions of libpng later than 0.88 are not
|
||||
distributed by the original libpng author, Guy Schalnat, but rather
|
||||
another member of the original PNG Group, Andreas Dilger. Guy is still
|
||||
alive and well, but he has moved on to other things.
|
||||
It should be noted that versions of libpng later than 0.96 are not
|
||||
distributed by the original libpng author, Guy Schalnat, nor by
|
||||
Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
|
||||
distributed versions 0.89 through 0.96, but rather by another member
|
||||
of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
|
||||
still alive and well, but they have moved on to other things.
|
||||
|
||||
The old libpng functions png_read_init(), png_write_init(),
|
||||
png_info_init(), png_read_destroy(), and png_write_destory() have been
|
||||
|
@ -1,6 +1,6 @@
|
||||
# makefile for libpng on Linux ELF with gcc
|
||||
# Copyright (C) 1996, 1997 Andreas Dilger
|
||||
# Copyright (C) 1998 Glenn Randers-Pehrson
|
||||
# Copyright (C) 1998 Greg Roelofs
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
CC=gcc
|
||||
@ -22,7 +22,7 @@ RANLIB=ranlib
|
||||
#RANLIB=echo
|
||||
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 0.97
|
||||
PNGMIN = 0.98
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
# where make install puts libpng.a, libpng.so*, and png.h
|
||||
|
69
makefile.sgi
Normal file
69
makefile.sgi
Normal file
@ -0,0 +1,69 @@
|
||||
# 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 -fullwarn # -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
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Makefile for libpng
|
||||
# TurboC++ 3.0 (Note: All modules are compiled in C mode)
|
||||
|
||||
# To use, do "make -fmakefile.tc"
|
||||
# To use, do "make -fmakefile.tc3"
|
||||
|
||||
# ------------- Turbo C++ 3.0 -------------
|
||||
MODEL=-ml
|
6
png.c
6
png.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* png.c - location for general purpose libpng functions
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@ -16,7 +16,7 @@
|
||||
/* Version information for C files. This had better match the version
|
||||
* string defined in png.h.
|
||||
*/
|
||||
char png_libpng_ver[] = "0.97";
|
||||
char png_libpng_ver[] = "0.98";
|
||||
|
||||
/* Place to hold the signiture string for a PNG file. */
|
||||
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
|
108
png.h
108
png.h
@ -1,12 +1,37 @@
|
||||
|
||||
/* png.h - header file for PNG reference library
|
||||
*
|
||||
* libpng 0.97 beta
|
||||
* libpng 0.98 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
|
||||
* Copyright (c) 1998 Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* BETA NOTICE:
|
||||
* This is a beta version. It reads and writes valid files on the
|
||||
@ -94,12 +119,12 @@ extern "C" {
|
||||
*/
|
||||
|
||||
/* Version information for png.h - this should match the version in png.c */
|
||||
#define PNG_LIBPNG_VER_STRING "0.97"
|
||||
#define PNG_LIBPNG_VER_STRING "0.98"
|
||||
|
||||
/* careful here. At one time, I wanted to use 082, but that would be octal.
|
||||
* Version 1.0 will be 100 here, etc.
|
||||
*/
|
||||
#define PNG_LIBPNG_VER 97
|
||||
#define PNG_LIBPNG_VER 98
|
||||
|
||||
/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
|
||||
#ifndef PNG_NO_EXTERN
|
||||
@ -108,33 +133,6 @@ 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[];
|
||||
@ -582,9 +580,9 @@ struct png_struct_def
|
||||
png_uint_32 flush_rows; /* number of rows written since last flush */
|
||||
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
|
||||
float gamma; /* file gamma value */
|
||||
float display_gamma; /* display gamma value */
|
||||
int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
|
||||
float gamma; /* file gamma value */
|
||||
float screen_gamma; /* screen gamma value (display_gamma/viewing_gamma */
|
||||
#endif /* PNG_READ_GAMMA_SUPPORTED */
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_bytep gamma_table; /* gamma table for 8 bit depth files */
|
||||
@ -626,6 +624,7 @@ struct png_struct_def
|
||||
png_charp current_text; /* current text chunk buffer */
|
||||
png_charp current_text_ptr; /* current location in current_text */
|
||||
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_READ_tEXt/zTXt_SUPPORTED */
|
||||
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
|
||||
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
||||
/* for the Borland special 64K segment handler */
|
||||
png_bytepp offset_table_ptr;
|
||||
@ -633,8 +632,7 @@ struct png_struct_def
|
||||
png_uint_16 offset_table_number;
|
||||
png_uint_16 offset_table_count;
|
||||
png_uint_16 offset_table_count_free;
|
||||
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED&&__TURBOC__&&!_Windows&&!__FLAT__ */
|
||||
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
|
||||
#endif /* __TURBOC__&&!_Windows&&!__FLAT__ */
|
||||
#if defined(PNG_READ_DITHER_SUPPORTED)
|
||||
png_bytep palette_lookup; /* lookup table for dithering */
|
||||
png_bytep dither_index; /* index translation for palette files */
|
||||
@ -649,9 +647,9 @@ struct png_struct_def
|
||||
png_uint_16p filter_costs; /* relative filter calculation cost */
|
||||
png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
|
||||
#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
|
||||
#if defined(PNG_TIME_RFC1152_SUPPORTED)
|
||||
png_charp time_buffer; /* String to hold RFC 1152 time text */
|
||||
#endif /* PNG_TIME_RFC1152_SUPPORTED */
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
png_charp time_buffer; /* String to hold RFC 1123 time text */
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
};
|
||||
|
||||
typedef png_struct FAR * FAR * png_structpp;
|
||||
@ -706,10 +704,10 @@ extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
|
||||
extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr));
|
||||
|
||||
#if defined(PNG_TIME_RFC1152_SUPPORTED)
|
||||
extern PNG_EXPORT(png_charp,png_convert_to_rfc1152)
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
|
||||
PNGARG((png_structp png_ptr, png_timep ptime));
|
||||
#endif /* PNG_TIME_RFC1152_SUPPORTED */
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
/* convert from a struct tm to png_time */
|
||||
@ -753,6 +751,11 @@ extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
|
||||
extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
|
||||
#endif /* PNG_READ_SWAP_ALPHA_SUPPORTED || PNG_WRITE_SWAP_ALPHA_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
|
||||
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
|
||||
#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED || PNG_WRITE_INVERT_ALPHA_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
/* Add a filler byte to 24-bit RGB images. */
|
||||
extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
|
||||
@ -819,7 +822,7 @@ extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
|
||||
#endif /* PNG_READ_DITHER_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
/* Handle gamma correction. */
|
||||
/* Handle gamma correction. Screen_gamma=(display_gamma/viewing_gamma) */
|
||||
extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
|
||||
double screen_gamma, double default_file_gamma));
|
||||
#endif /* PNG_READ_GAMMA_SUPPORTED */
|
||||
@ -1240,14 +1243,14 @@ extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr, png_bytep srgb_intent));
|
||||
png_infop info_ptr, int *intent));
|
||||
#endif /* PNG_READ_sRGB_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr, png_byte srgb_intent));
|
||||
png_infop info_ptr, int intent));
|
||||
extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr, png_byte srgb_intent));
|
||||
png_infop info_ptr, int intent));
|
||||
#endif /* PNG_READ_sRGB_SUPPORTED || PNG_WRITE_sRGB_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||
@ -1361,6 +1364,7 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
#define PNG_PACKSWAP 0x10000
|
||||
#define PNG_SWAP_ALPHA 0x20000
|
||||
#define PNG_STRIP_ALPHA 0x40000
|
||||
#define PNG_INVERT_ALPHA 0x80000
|
||||
|
||||
/* flags for png_create_struct */
|
||||
#define PNG_STRUCT_PNG 0x0001
|
||||
@ -1585,7 +1589,7 @@ PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
|
||||
|
||||
#if defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
|
||||
png_byte srgb_intent));
|
||||
int intent));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
@ -1702,6 +1706,16 @@ PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
|
||||
png_bytep row));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
|
||||
PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
|
||||
png_bytep row));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
|
||||
png_bytep row));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
|
||||
defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
||||
PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
|
||||
|
38
pngconf.h
38
pngconf.h
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngconf.c - machine configurable file for libpng
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*/
|
||||
|
||||
/* Any machine specific code is near the front of this file, so if you
|
||||
@ -191,24 +191,25 @@ __dont__ include it again
|
||||
* less then 8, and even that may not work (I haven't tested it).
|
||||
*/
|
||||
|
||||
#ifndef PNG_MAX_GAMMA_8
|
||||
#define PNG_MAX_GAMMA_8 11
|
||||
#endif
|
||||
|
||||
/* This controls how much a difference in gamma we can tolerate before
|
||||
* we actually start doing gamma conversion.
|
||||
*/
|
||||
#ifndef PNG_GAMMA_THRESHOLD
|
||||
#define PNG_GAMMA_THRESHOLD 0.05
|
||||
#endif
|
||||
|
||||
#endif /* PNG_INTERNAL */
|
||||
|
||||
/* The following uses const char * instead of char * for error
|
||||
* and warning message functions, so some compilers won't complain.
|
||||
* If you want to use const, define PNG_USE_CONST here. It is not
|
||||
* normally defined to make configuration easier, as it is not a
|
||||
* critical part of the code.
|
||||
* If you do not want to use const, define PNG_NO_CONST here.
|
||||
*/
|
||||
#define PNG_USE_CONST
|
||||
|
||||
#ifdef PNG_USE_CONST
|
||||
#ifndef PNG_NO_CONST
|
||||
# define PNG_CONST const
|
||||
#else
|
||||
# define PNG_CONST
|
||||
@ -259,6 +260,7 @@ __dont__ include it again
|
||||
#define PNG_READ_GAMMA_SUPPORTED
|
||||
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
|
||||
#define PNG_READ_SWAP_ALPHA_SUPPORTED
|
||||
#define PNG_READ_INVERT_ALPHA_SUPPORTED
|
||||
#define PNG_READ_STRIP_ALPHA_SUPPORTED
|
||||
#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel */
|
||||
#endif /* PNG_READ_FULLY_SUPPORTED */
|
||||
@ -275,22 +277,32 @@ __dont__ include it again
|
||||
#define PNG_WRITE_FILLER_SUPPORTED /* This is the same as WRITE_STRIP_ALPHA */
|
||||
#define PNG_WRITE_FLUSH_SUPPORTED
|
||||
#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
#endif /* PNG_WRITE_FULLY_SUPPORTED */
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
#define PNG_TIME_RFC1152_SUPPORTED
|
||||
#define PNG_TIME_RFC1123_SUPPORTED
|
||||
#endif
|
||||
|
||||
/* These are currently experimental features */
|
||||
#undef PNG_READ_16_TO_8_ACCURATE_SHIFT_SUPPORTED /* very little testing */
|
||||
/* These are currently experimental features, define them if you want */
|
||||
|
||||
/* very little testing */
|
||||
/*
|
||||
#define PNG_READ_16_TO_8_ACCURATE_SHIFT_SUPPORTED
|
||||
*/
|
||||
|
||||
/* This is only for PowerPC big-endian and 680x0 systems */
|
||||
#undef PNG_READ_BIG_ENDIAN_SUPPORTED /* some testing */
|
||||
/* some testing */
|
||||
/*
|
||||
#define PNG_READ_BIG_ENDIAN_SUPPORTED
|
||||
*/
|
||||
|
||||
/* These functions are turned off by default, as they will be phased out. */
|
||||
#undef PNG_USELESS_TESTS_SUPPORTED
|
||||
#undef PNG_CORRECT_PALETTE_SUPPORTED
|
||||
/*
|
||||
#define PNG_USELESS_TESTS_SUPPORTED
|
||||
#define PNG_CORRECT_PALETTE_SUPPORTED
|
||||
*/
|
||||
|
||||
/* Any chunks you are not interested in, you can undef here. The
|
||||
* ones that allocate memory may be expecially important (hIST,
|
||||
|
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*
|
||||
* This file provides a location for all error handling. Users which
|
||||
* need special error handling are expected to write replacement functions
|
||||
|
12
pngget.c
12
pngget.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@ -112,14 +112,13 @@ png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, png_bytep
|
||||
file_srgb_intent)
|
||||
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sRGB &&
|
||||
file_srgb_intent != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "sRGB");
|
||||
*file_srgb_intent = info_ptr->srgb_intent;
|
||||
*file_srgb_intent = (int)info_ptr->srgb_intent;
|
||||
return (PNG_INFO_sRGB);
|
||||
}
|
||||
return (0);
|
||||
@ -272,7 +271,8 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
|
||||
if ((info_ptr != NULL) || (info_ptr->num_text > 0))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n",
|
||||
(png_ptr->chunk_name[0] == '\0' ? "text" : png_ptr->chunk_name));
|
||||
(png_ptr->chunk_name[0] == '\0' ? "text"
|
||||
: (png_const_charp)png_ptr->chunk_name));
|
||||
if (text_ptr != NULL)
|
||||
*text_ptr = info_ptr->text;
|
||||
if (num_text != NULL)
|
||||
|
27
pngmem.c
27
pngmem.c
@ -1,12 +1,11 @@
|
||||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 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
|
||||
@ -16,6 +15,16 @@
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
/* The following "hides" PNG_MALLOC and PNG_FREE thus allowing the pngtest
|
||||
application to put a wrapper on top of them. */
|
||||
#ifdef PNGTEST_MEMORY_DEBUG
|
||||
#define PNG_MALLOC png_debug_malloc
|
||||
#define PNG_FREE png_debug_free
|
||||
#else
|
||||
#define PNG_MALLOC png_malloc
|
||||
#define PNG_FREE png_free
|
||||
#endif
|
||||
|
||||
/* Borland DOS special memory handler */
|
||||
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
||||
/* if you change this, be sure to change the one in png.h also */
|
||||
@ -72,7 +81,7 @@ png_destroy_struct(png_voidp struct_ptr)
|
||||
* (which should cause a fatal error) and introducing major problems.
|
||||
*/
|
||||
png_voidp
|
||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
if (png_ptr == NULL || size == 0)
|
||||
@ -166,11 +175,11 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* free a pointer allocated by png_malloc(). In the default
|
||||
/* free a pointer allocated by PNG_MALLOC(). In the default
|
||||
configuration, png_ptr is not used, but is passed in case it
|
||||
is needed. If ptr is NULL, return without taking any action. */
|
||||
void
|
||||
png_free(png_structp png_ptr, png_voidp ptr)
|
||||
PNG_FREE(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
@ -260,7 +269,7 @@ png_destroy_struct(png_voidp struct_ptr)
|
||||
have the ability to do that. */
|
||||
|
||||
png_voidp
|
||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
if (png_ptr == NULL || size == 0)
|
||||
@ -289,11 +298,11 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Free a pointer allocated by png_malloc(). In the default
|
||||
/* Free a pointer allocated by PNG_MALLOC(). In the default
|
||||
configuration, png_ptr is not used, but is passed in case it
|
||||
is needed. If ptr is NULL, return without taking any action. */
|
||||
void
|
||||
png_free(png_structp png_ptr, png_voidp ptr)
|
||||
PNG_FREE(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
|
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
|
10
pngread.c
10
pngread.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngread.c - read a PNG file
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*
|
||||
* This file contains routines that an application calls directly to
|
||||
* read a PNG file or stream.
|
||||
@ -655,12 +655,18 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
#endif
|
||||
png_destroy_struct((png_voidp)info_ptr);
|
||||
*info_ptr_ptr = (png_infop)NULL;
|
||||
}
|
||||
|
||||
if (end_info_ptr != NULL)
|
||||
{
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
#endif
|
||||
png_destroy_struct((png_voidp)end_info_ptr);
|
||||
*end_info_ptr_ptr = (png_infop)NULL;
|
||||
}
|
||||
|
4
pngrio.c
4
pngrio.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngrio.c - functions for data input
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*
|
||||
* This file provides a location for all input. Users which need
|
||||
* special handling are expected to write a function which has the same
|
||||
|
134
pngrtran.c
134
pngrtran.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngrtran.c - transforms the data in a row for PNG readers
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*
|
||||
* This file contains functions optionally called by an application
|
||||
* in order to tell libpng how to handle data when reading a PNG.
|
||||
@ -549,13 +549,13 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
|
||||
* also needlessly introduces small errors.
|
||||
*/
|
||||
void
|
||||
png_set_gamma(png_structp png_ptr, double screen_gamma, double file_gamma)
|
||||
png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
|
||||
{
|
||||
png_debug(1, "in png_set_gamma\n");
|
||||
if (fabs(screen_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD)
|
||||
if (fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD)
|
||||
png_ptr->transformations |= PNG_GAMMA;
|
||||
png_ptr->gamma = (float)file_gamma;
|
||||
png_ptr->display_gamma = (float)screen_gamma;
|
||||
png_ptr->screen_gamma = (float)scrn_gamma;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -592,6 +592,7 @@ png_set_rgb_to_gray(png_structp png_ptr, int gray_bits)
|
||||
png_debug(1, "in png_set_rgb_to_gray\n");
|
||||
png_ptr->transformations |= PNG_RGB_TO_GRAY;
|
||||
/* Need to do something with gray_bits here. */
|
||||
png_warning(png_ptr, "RGB to GRAY transformation is not yet implemented.");
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -644,6 +645,23 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
png_ptr->palette[png_ptr->background.index].green;
|
||||
png_ptr->background.blue =
|
||||
png_ptr->palette[png_ptr->background.index].blue;
|
||||
|
||||
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA)
|
||||
{
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
if (png_ptr->transformations & !PNG_EXPAND)
|
||||
#endif
|
||||
{
|
||||
/* invert the alpha channel (in tRNS) unless the pixels are
|
||||
going to be expanded, in which case leave it for later */
|
||||
int i;
|
||||
for (i=0; i<png_ptr->num_trans; i++)
|
||||
png_ptr->trans[i] = 255 - png_ptr->trans[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -681,7 +699,7 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
{
|
||||
double g;
|
||||
|
||||
g = 1.0 / (png_ptr->background_gamma * png_ptr->display_gamma);
|
||||
g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
|
||||
|
||||
if (png_ptr->background_gamma_type==PNG_BACKGROUND_GAMMA_SCREEN||
|
||||
fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
|
||||
@ -761,17 +779,17 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
switch (png_ptr->background_gamma_type)
|
||||
{
|
||||
case PNG_BACKGROUND_GAMMA_SCREEN:
|
||||
g = (png_ptr->display_gamma);
|
||||
g = (png_ptr->screen_gamma);
|
||||
gs = 1.0;
|
||||
break;
|
||||
case PNG_BACKGROUND_GAMMA_FILE:
|
||||
g = 1.0 / (png_ptr->gamma);
|
||||
gs = 1.0 / (png_ptr->gamma * png_ptr->display_gamma);
|
||||
gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
|
||||
break;
|
||||
case PNG_BACKGROUND_GAMMA_UNIQUE:
|
||||
g = 1.0 / (png_ptr->background_gamma);
|
||||
gs = 1.0 / (png_ptr->background_gamma *
|
||||
png_ptr->display_gamma);
|
||||
png_ptr->screen_gamma);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -954,7 +972,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
|
||||
else
|
||||
info_ptr->channels = 1;
|
||||
|
||||
#if defined(PNG_STRIP_ALPHA_SUPPORTED)
|
||||
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
||||
if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
|
||||
info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
{
|
||||
@ -1112,6 +1130,11 @@ png_do_read_transformations(png_structp png_ptr)
|
||||
png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA)
|
||||
png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
@ -1468,6 +1491,87 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
|
||||
void
|
||||
png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_read_invert_alpha\n");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL)
|
||||
#endif
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
/* This inverts the alpha channel in RGBA */
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row + row_info->rowbytes;
|
||||
i < row_info->width; i++)
|
||||
{
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = 255 - *(--sp);
|
||||
}
|
||||
}
|
||||
/* This inverts the alpha channel in RRGGBBAA */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row + row_info->rowbytes;
|
||||
i < row_info->width; i++)
|
||||
{
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = 255 - *(--sp);
|
||||
*(--dp) = 255 - *(--sp);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
{
|
||||
/* This inverts the alpha channel in AG */
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row + row_info->rowbytes;
|
||||
i < row_info->width; i++)
|
||||
{
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = 255 - *(--sp);
|
||||
}
|
||||
}
|
||||
/* This inverts the alpha channel in AAGG */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row + row_info->rowbytes;
|
||||
i < row_info->width; i++)
|
||||
{
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = 255 - *(--sp);
|
||||
*(--dp) = 255 - *(--sp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED)
|
||||
/* Add filler channel if we have RGB color */
|
||||
void
|
||||
@ -1693,7 +1797,7 @@ png_correct_palette(png_structp png_ptr, png_colorp palette,
|
||||
{
|
||||
double g;
|
||||
|
||||
g = 1.0 / (png_ptr->background_gamma * png_ptr->display_gamma);
|
||||
g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
|
||||
|
||||
if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
|
||||
fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
|
||||
@ -3082,7 +3186,7 @@ png_build_gamma_table(png_structp png_ptr)
|
||||
int i;
|
||||
double g;
|
||||
|
||||
g = 1.0 / (png_ptr->gamma * png_ptr->display_gamma);
|
||||
g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
|
||||
|
||||
png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)256);
|
||||
@ -3107,7 +3211,7 @@ png_build_gamma_table(png_structp png_ptr)
|
||||
g) * 255.0 + .5);
|
||||
}
|
||||
|
||||
g = 1.0 / (png_ptr->display_gamma);
|
||||
g = 1.0 / (png_ptr->screen_gamma);
|
||||
|
||||
png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)256);
|
||||
@ -3160,7 +3264,7 @@ png_build_gamma_table(png_structp png_ptr)
|
||||
|
||||
num = (1 << (8 - shift));
|
||||
|
||||
g = 1.0 / (png_ptr->gamma * png_ptr->display_gamma);
|
||||
g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
|
||||
|
||||
png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
|
||||
num * sizeof (png_uint_16p));
|
||||
@ -3238,7 +3342,7 @@ png_build_gamma_table(png_structp png_ptr)
|
||||
65535.0, g) * 65535.0 + .5);
|
||||
}
|
||||
}
|
||||
g = 1.0 / (png_ptr->display_gamma);
|
||||
g = 1.0 / (png_ptr->screen_gamma);
|
||||
|
||||
png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
|
||||
num * sizeof (png_uint_16p));
|
||||
|
16
pngrutil.c
16
pngrutil.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngrutil.c - utilities to read a PNG file
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*
|
||||
* This file contains routines which are only called from within
|
||||
* libpng itself during the course of reading an image.
|
||||
@ -106,7 +106,7 @@ png_crc_finish(png_structp png_ptr, png_uint_32 skip)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Compare the CRC stored in the PNG file with that calulated by libpng from
|
||||
/* Compare the CRC stored in the PNG file with that calculated by libpng from
|
||||
the data it has read thus far. */
|
||||
int
|
||||
png_crc_error(png_structp png_ptr)
|
||||
@ -281,7 +281,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, num, sizeof (png_color));
|
||||
palette = (png_colorp)png_zalloc(png_ptr, (uInt)num, sizeof (png_color));
|
||||
png_ptr->flags |= PNG_FLAG_FREE_PALETTE;
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
@ -318,7 +318,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
png_chunk_warning(png_ptr, "CRC error");
|
||||
png_ptr->flags &= ~PNG_FLAG_FREE_PALETTE;
|
||||
png_free(png_ptr, palette);
|
||||
png_zfree(png_ptr, palette);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -404,7 +404,7 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sRGB)
|
||||
if(igamma != (png_uint_32)45000L)
|
||||
if(igamma != (png_uint_32)51000L)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect gAMA value when sRGB is also present");
|
||||
@ -626,7 +626,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
void
|
||||
png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
png_byte intent;
|
||||
int intent;
|
||||
png_byte buf[1];
|
||||
|
||||
png_debug(1, "in png_handle_sRGB\n");
|
||||
@ -671,7 +671,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
#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)
|
||||
if((png_uint_32)(png_ptr->gamma*(float)100000.+.5) != (png_uint_32)51000L)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect gAMA value when sRGB is also present");
|
||||
|
16
pngset.c
16
pngset.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngset.c - storage of image information into info struct
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 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
|
||||
@ -213,18 +213,18 @@ png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
void
|
||||
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, png_byte intent)
|
||||
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "sRGB");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->srgb_intent = intent;
|
||||
info_ptr->srgb_intent = (png_byte)intent;
|
||||
info_ptr->valid |= PNG_INFO_sRGB;
|
||||
}
|
||||
void
|
||||
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
png_byte intent)
|
||||
int intent)
|
||||
{
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
float file_gamma;
|
||||
@ -239,7 +239,7 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
png_set_sRGB(png_ptr, info_ptr, intent);
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
file_gamma = (float).45;
|
||||
file_gamma = (float).51;
|
||||
png_set_gAMA(png_ptr, info_ptr, file_gamma);
|
||||
#endif
|
||||
|
||||
@ -269,7 +269,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
int i;
|
||||
|
||||
png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
|
||||
"text" : png_ptr->chunk_name));
|
||||
"text" : (png_const_charp)png_ptr->chunk_name));
|
||||
|
||||
if (info_ptr == NULL || num_text == 0)
|
||||
return;
|
||||
@ -308,7 +308,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
|
||||
|
||||
if (text_ptr[i].text == NULL)
|
||||
text_ptr[i].text = "";
|
||||
text_ptr[i].text = (png_charp)"";
|
||||
|
||||
if (text_ptr[i].text[0] == '\0')
|
||||
{
|
||||
|
68
pngtest.c
68
pngtest.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngtest.c - a simple test program to test libpng
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 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
|
||||
@ -37,6 +37,8 @@
|
||||
|
||||
#include "png.h"
|
||||
|
||||
int test_one_file(PNG_CONST char *inname, PNG_CONST char *outname);
|
||||
|
||||
#ifdef __TURBOC__
|
||||
#include <mem.h>
|
||||
#endif
|
||||
@ -45,10 +47,10 @@
|
||||
/* #define STDERR stderr */
|
||||
#define STDERR stdout /* for DOS */
|
||||
|
||||
#if defined(PNG_NO_STDIO)
|
||||
/* START of code to validate stdio-free compilation */
|
||||
/* These copies of the default read/write functions come from pngrio.c and */
|
||||
/* pngwio.c. They allow "don't include stdio" testing of the library. */
|
||||
#if defined(PNG_NO_STDIO)
|
||||
/* This is the function which does the actual reading of data. If you are
|
||||
not reading from a standard C stream, you should create a replacement
|
||||
read_data function and use it at run time with png_set_read_fn(), rather
|
||||
@ -118,7 +120,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
png_error(png_ptr, "read Error");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* USE_FAR_KEYWORD */
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
static void
|
||||
@ -196,7 +198,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* USE_FAR_KEYWORD */
|
||||
|
||||
/* This function is called when there is a warning, but the library thinks
|
||||
* it can continue anyway. Replacement functions don't have to do anything
|
||||
@ -224,13 +226,13 @@ png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
/* We can return because png_error calls the default handler which is
|
||||
* actually ok in this case. */
|
||||
}
|
||||
#endif
|
||||
#endif /* PNG_NO_STDIO */
|
||||
/* END of code to validate stdio-free compilation */
|
||||
|
||||
/* Test one file */
|
||||
int test(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
int test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
FILE *fpin, *fpout;
|
||||
static FILE *fpin, *fpout; /* "static" prevents setjmp corruption */
|
||||
png_structp read_ptr, write_ptr;
|
||||
png_infop read_info_ptr, write_info_ptr, end_info_ptr;
|
||||
png_bytep row_buf;
|
||||
@ -263,16 +265,18 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
|
||||
(png_error_ptr)NULL, (png_error_ptr)NULL);
|
||||
#if defined(PNG_NO_STDIO)
|
||||
png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error, png_default_warning);
|
||||
png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error,
|
||||
png_default_warning);
|
||||
#endif
|
||||
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
|
||||
(png_error_ptr)NULL, (png_error_ptr)NULL);
|
||||
#if defined(PNG_NO_STDIO)
|
||||
png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error, png_default_warning);
|
||||
png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error,
|
||||
png_default_warning);
|
||||
#endif
|
||||
png_debug(0, "Allocating read_info, write_info and end_info structures\n");
|
||||
read_info_ptr = png_create_info_struct(read_ptr);
|
||||
write_info_ptr = png_create_info_struct(read_ptr);
|
||||
write_info_ptr = png_create_info_struct(write_ptr);
|
||||
end_info_ptr = png_create_info_struct(read_ptr);
|
||||
|
||||
png_debug(0, "Setting jmpbuf for read struct\n");
|
||||
@ -371,7 +375,7 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED) && defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
{
|
||||
png_byte intent;
|
||||
int intent;
|
||||
|
||||
if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
|
||||
{
|
||||
@ -515,14 +519,13 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_write_end(write_ptr, end_info_ptr);
|
||||
|
||||
png_debug(0, "Destroying data structs\n");
|
||||
png_free(read_ptr, row_buf);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
|
||||
png_free(read_ptr, row_buf);
|
||||
|
||||
png_debug(0, "Opening files for comparison\n");
|
||||
if ((fpin = fopen(inname, "rb")) == NULL)
|
||||
{
|
||||
@ -576,8 +579,8 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
PNG_CONST char *inname = "pngtest_png";
|
||||
PNG_CONST char *outname = "pngout_png";
|
||||
#else
|
||||
PNG_CONST char *inname = "pngtest.png";
|
||||
PNG_CONST char *outname = "pngout.png";
|
||||
static char *inname = "pngtest.png";
|
||||
static char *outname = "pngout.png";
|
||||
#endif
|
||||
|
||||
int
|
||||
@ -608,12 +611,15 @@ main(int argc, char *argv[])
|
||||
if (!multiple && argc == 3)
|
||||
outname = argv[2];
|
||||
|
||||
if (!multiple && argc > 3 || multiple && argc < 2)
|
||||
if ((!multiple && argc > 3) || (multiple && argc < 2))
|
||||
{
|
||||
fprintf(STDERR, "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
|
||||
fprintf(STDERR,
|
||||
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
|
||||
argv[0], argv[0]);
|
||||
fprintf(STDERR, " reads/writes one PNG file (without -m) or multiple files (-m)\n");
|
||||
fprintf(STDERR, " with -m %s is used as a temporary file\n", outname);
|
||||
fprintf(STDERR,
|
||||
" reads/writes one PNG file (without -m) or multiple files (-m)\n");
|
||||
fprintf(STDERR,
|
||||
" with -m %s is used as a temporary file\n", outname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -622,13 +628,29 @@ main(int argc, char *argv[])
|
||||
int i;
|
||||
for (i=2; i<argc; ++i)
|
||||
{
|
||||
fprintf(STDERR, "Testing %s:\n",argv[i]);
|
||||
ierror += test(argv[i], outname);
|
||||
int kerror;
|
||||
fprintf(STDERR, "Testing %s:",argv[i]);
|
||||
kerror = test_one_file(argv[i], outname);
|
||||
if (kerror == 0) fprintf(STDERR, " PASS\n");
|
||||
else {
|
||||
fprintf(STDERR, " FAIL\n");
|
||||
ierror += kerror;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ierror += test(inname, outname);
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
int kerror;
|
||||
fprintf(STDERR, "Testing %s:",inname);
|
||||
kerror = test_one_file(inname, outname);
|
||||
if (kerror == 0) fprintf(STDERR, " PASS\n");
|
||||
else {
|
||||
fprintf(STDERR, " FAIL\n");
|
||||
ierror += kerror;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ierror == 0)
|
||||
|
14
pngtrans.c
14
pngtrans.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@ -118,6 +118,16 @@ png_set_swap_alpha(png_structp png_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
|
||||
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
void
|
||||
png_set_invert_alpha(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_invert_alpha\n");
|
||||
png_ptr->transformations |= PNG_INVERT_ALPHA;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
|
||||
void
|
||||
png_set_invert_mono(png_structp png_ptr)
|
||||
|
4
pngwio.c
4
pngwio.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngwio.c - functions for data output
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*
|
||||
* This file provides a location for all output. Users which need
|
||||
* special handling are expected to write functions which have the same
|
||||
|
44
pngwrite.c
44
pngwrite.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngwrite.c - general routines to write a PNG file
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*/
|
||||
|
||||
/* get internal access to png.h */
|
||||
@ -43,7 +43,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
#endif
|
||||
#if defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sRGB)
|
||||
png_write_sRGB(png_ptr, info_ptr->srgb_intent);
|
||||
png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sBIT)
|
||||
@ -62,10 +62,23 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
(png_uint_32)info_ptr->num_palette);
|
||||
else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_error(png_ptr, "Valid palette required for paletted images\n");
|
||||
|
||||
#if defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_tRNS)
|
||||
{
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
/* invert the alpha channel (in tRNS) */
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA &&
|
||||
info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<info_ptr->num_trans; i++)
|
||||
info_ptr->trans[i] = 255 - info_ptr->trans[i];
|
||||
}
|
||||
#endif
|
||||
png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
|
||||
info_ptr->num_trans, info_ptr->color_type);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_bKGD_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_bKGD)
|
||||
@ -200,12 +213,12 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
png_write_IEND(png_ptr);
|
||||
}
|
||||
|
||||
#if defined(PNG_TIME_RFC1152_SUPPORTED)
|
||||
/* Convert the supplied time into an RFC 1152 string suitable for use in
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
/* Convert the supplied time into an RFC 1123 string suitable for use in
|
||||
* a "Creation Time" or other text-based time string.
|
||||
*/
|
||||
png_charp
|
||||
png_convert_to_rfc1152(png_structp png_ptr, png_timep ptime)
|
||||
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
|
||||
{
|
||||
const char *short_months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
@ -233,7 +246,7 @@ png_convert_to_rfc1152(png_structp png_ptr, png_timep ptime)
|
||||
#endif
|
||||
return png_ptr->time_buffer;
|
||||
}
|
||||
#endif /* PNG_TIME_RFC1152_SUPPORTED */
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
void
|
||||
@ -582,6 +595,19 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
|
||||
{
|
||||
#ifdef PNG_WRITE_tEXt_SUPPORTED
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
png_free(png_ptr, info_ptr->pcal_purpose);
|
||||
png_free(png_ptr, info_ptr->pcal_units);
|
||||
if (info_ptr->pcal_params != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < info_ptr->pcal_nparams; i++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->pcal_params[i]);
|
||||
}
|
||||
png_free(png_ptr, info_ptr->pcal_params);
|
||||
}
|
||||
#endif
|
||||
png_destroy_struct((png_voidp)info_ptr);
|
||||
*info_ptr_ptr = (png_infop)NULL;
|
||||
@ -617,9 +643,9 @@ png_write_destroy(png_structp png_ptr)
|
||||
png_free(png_ptr, png_ptr->up_row);
|
||||
png_free(png_ptr, png_ptr->avg_row);
|
||||
png_free(png_ptr, png_ptr->paeth_row);
|
||||
#if defined(PNG_TIME_RFC1152_SUPPORTED)
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
png_free(png_ptr, png_ptr->time_buffer);
|
||||
#endif /* PNG_TIME_RFC1152_SUPPORTED */
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
png_free(png_ptr, png_ptr->prev_filters);
|
||||
png_free(png_ptr, png_ptr->filter_weights);
|
||||
|
84
pngwtran.c
84
pngwtran.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@ -42,6 +42,10 @@ png_do_write_transformations(png_structp png_ptr)
|
||||
if (png_ptr->transformations & PNG_SWAP_ALPHA)
|
||||
png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA)
|
||||
png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_BGR)
|
||||
png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
@ -394,3 +398,79 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
void
|
||||
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_write_invert_alpha\n");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL)
|
||||
#endif
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
/* This inverts the alpha channel in RGBA */
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
}
|
||||
}
|
||||
/* This inverts the alpha channel in RRGGBBAA */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
{
|
||||
/* This inverts the alpha channel in GA */
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
}
|
||||
}
|
||||
/* This inverts the alpha channel in GGAA */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
13
pngwutil.c
13
pngwutil.c
@ -1,12 +1,12 @@
|
||||
|
||||
/* pngwutil.c - utilities to write a PNG file
|
||||
*
|
||||
* libpng 0.97
|
||||
* libpng 0.98
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
* January 16, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@ -346,7 +346,7 @@ png_write_gAMA(png_structp png_ptr, double file_gamma)
|
||||
#if defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
/* write a sRGB chunk */
|
||||
void
|
||||
png_write_sRGB(png_structp png_ptr, png_byte srgb_intent)
|
||||
png_write_sRGB(png_structp png_ptr, int srgb_intent)
|
||||
{
|
||||
png_byte buf[1];
|
||||
|
||||
@ -354,7 +354,7 @@ png_write_sRGB(png_structp png_ptr, png_byte srgb_intent)
|
||||
if(srgb_intent > 3)
|
||||
png_warning(png_ptr,
|
||||
"Invalid sRGB rendering intent specified");
|
||||
buf[0]=srgb_intent;
|
||||
buf[0]=(png_byte)srgb_intent;
|
||||
png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
|
||||
}
|
||||
#endif
|
||||
@ -506,7 +506,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
|
||||
}
|
||||
else
|
||||
{
|
||||
png_warning(png_ptr, "Can't write tRNS with and alpha channel");
|
||||
png_warning(png_ptr, "Can't write tRNS with an alpha channel");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -992,6 +992,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
|
||||
(png_size_t)params_len[i]);
|
||||
}
|
||||
|
||||
png_free(png_ptr, params_len);
|
||||
png_write_chunk_end(png_ptr);
|
||||
}
|
||||
#endif
|
||||
@ -1395,7 +1396,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
* smallest value when summing the absolute values of the distances
|
||||
* from zero using anything >= 128 as negative numbers. This is known
|
||||
* as the "minimum sum of absolute differences" heuristic. Other
|
||||
* heruistics are the "weighted minumum sum of absolute differences"
|
||||
* heuristics are the "weighted minumum sum of absolute differences"
|
||||
* (experimental and can in theory improve compression), and the "zlib
|
||||
* predictive" method (not implemented in libpng 0.95), which does test
|
||||
* compressions of lines using different filter methods, and then chooses
|
||||
|
Reference in New Issue
Block a user