LIBPNG(3) | Library Functions Manual | LIBPNG(3) |
NAME
libpng - Portable Network Graphics (PNG) Reference Library 1.5.13SYNOPSIS
DESCRIPTION
The libpng library supports encoding, decoding, and various manipulations of the Portable Network Graphics (PNG) format image files. It uses the zlib(3) compression library. Following is a copy of the libpng-manual.txt file that accompanies libpng.LIBPNG.TXT
Libpng-manual.txt - A description on how to use and modify libpnglibpng version 1.5.13 - September 27, 2012
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2012 Glenn Randers-Pehrson
This document is released under the libpng license.
For conditions of distribution and use, see the disclaimer
and license in png.h
Based on:
libpng versions 0.97, January 1998, through 1.5.13 - September 27, 2012
Updated and distributed by Glenn Randers-Pehrson
Copyright (c) 1998-2012 Glenn Randers-Pehrson
libpng 1.0 beta 6 version 0.96 May 28, 1997
Updated and distributed by Andreas Dilger
Copyright (c) 1996, 1997 Andreas Dilger
libpng 1.0 beta 2 - version 0.88 January 26, 1996
For conditions of distribution and use, see copyright
notice in png.h. Copyright (c) 1995, 1996 Guy Eric
Schalnat, Group 42, Inc.
Updated/rewritten per request in the libpng FAQ
Copyright (c) 1995, 1996 Frank J. T. Wojcik
December 18, 1995 & January 20, 1996
I. Introduction
This file describes how to use and modify the PNG reference library (known as libpng) for your own use. There are five sections to this file: introduction, structures, reading, writing, and modification and configuration notes for various special platforms. In addition to this file, example.c is a good starting point for using the library, as it is heavily commented and should include everything most people will need. We assume that libpng is already installed; see the INSTALL file for instructions on how to install libpng.II. Structures
There are two main structures that are important to libpng, png_struct and png_info. Both are internal structures that are no longer exposed in the libpng interface (as of libpng 1.5.0).Types
The png.h header file defines a number of integral types used by the APIs. Most of these are fairly obvious; for example types corresponding to integers of particular sizes and types for passing color values.Configuration
The main header file function declarations are frequently protected by C preprocessing directives of the form:#ifdef PNG_feature_SUPPORTED
declare-function
#endif
...
#ifdef PNG_feature_SUPPORTED
use-function
#endif
III. Reading
We'll now walk you through the possible functions to call when reading in a PNG file sequentially, briefly explaining the syntax and purpose of each one. See example.c and png.h for more detail. While progressive reading is covered in the next section, you will still need some of the functions discussed in this section to read a PNG file.Setup
You will want to do the I/O initialization(*) before you get into libpng, so if it doesn't work, you don't have much to undo. Of course, you will also want to insure that you are, in fact, dealing with a PNG file. Libpng provides a simple check to see if a file is a PNG file. To use it, pass in the first 1 to 8 bytes of the file to the function png_sig_cmp(), and it will return 0 (false) if the bytes match the corresponding bytes of the PNG signature, or nonzero (true) otherwise. Of course, the more bytes you pass in, the greater the accuracy of the prediction.FILE *fp = fopen(file_name, "rb");
if (!fp)
{
return (ERROR);
}
fread(header, 1, number, fp);
is_png = !png_sig_cmp(header, 0, number);
if (!is_png)
{
return (NOT_PNG);
}
png_structp png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn);
if (!png_ptr)
return (ERROR);
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr,
(png_infopp)NULL, (png_infopp)NULL);
return (ERROR);
}
png_structp png_ptr = png_create_read_struct_2
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn, (png_voidp)
user_mem_ptr, user_malloc_fn, user_free_fn);
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr,
&end_info);
fclose(fp);
return (ERROR);
}
png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, number);
png_set_compression_buffer_size(png_ptr, buffer_size);
png_set_crc_action(png_ptr, crit_action, ancil_action);
PNG_CRC_DEFAULT 0 error/quit
PNG_CRC_ERROR_QUIT 1 error/quit
PNG_CRC_WARN_USE 3 warn/use data
PNG_CRC_QUIET_USE 4 quiet/use data
PNG_CRC_NO_CHANGE 5 use the current value
PNG_CRC_DEFAULT 0 error/quit
PNG_CRC_ERROR_QUIT 1 error/quit
PNG_CRC_WARN_DISCARD 2 warn/discard data
PNG_CRC_WARN_USE 3 warn/use data
PNG_CRC_QUIET_USE 4 quiet/use data
PNG_CRC_NO_CHANGE 5 use the current value
Setting up callback code
You can set up a callback function to handle any unknown chunks in the input stream. You must supply the functionread_chunk_callback(png_structp png_ptr,
png_unknown_chunkp chunk);
{
/* The unknown chunk structure contains your
chunk data, along with similar data for any other
unknown chunks: */
png_byte name[5];
png_byte *data;
png_size_t size;
/* Note that libpng has already taken care of
the CRC handling */
/* put your code here. Search for your chunk in the
unknown chunk structure, process it, and return one
of the following: */
return (-n); /* chunk had an error */
return (0); /* did not recognize */
return (n); /* success */
}
png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
read_chunk_callback);
png_get_user_chunk_ptr(png_ptr);
void read_row_callback(png_structp png_ptr,
png_uint_32 row, int pass);
{
/* put your code here */
}
png_set_read_status_fn(png_ptr, read_row_callback);
Unknown-chunk handling
Now you get to set the way the library processes unknown chunks in the input PNG stream. Both known and unknown chunks will be read. Normal behavior is that known chunks will be parsed into information in various info_ptr members while unknown chunks will be discarded. This behavior can be wasteful if your application will never use some known chunk types. To change this, you can call:png_set_keep_unknown_chunks(png_ptr, keep,
chunk_list, num_chunks);
keep - 0: default unknown chunk handling
1: ignore; do not keep
2: keep only if safe-to-copy
3: keep even if unsafe-to-copy
You can use these definitions:
PNG_HANDLE_CHUNK_AS_DEFAULT 0
PNG_HANDLE_CHUNK_NEVER 1
PNG_HANDLE_CHUNK_IF_SAFE 2
PNG_HANDLE_CHUNK_ALWAYS 3
chunk_list - list of chunks affected (a byte string,
five bytes per chunk, NULL or ' ' if
num_chunks is 0)
num_chunks - number of chunks affected; if 0, all
unknown chunks are affected. If nonzero,
only the chunks in the list are affected
png_byte vpAg[5]={118, 112, 65, 103, (png_byte) ' '};
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
png_byte unused_chunks[]=
{
104, 73, 83, 84, (png_byte) ' ', /* hIST */
105, 84, 88, 116, (png_byte) ' ', /* iTXt */
112, 67, 65, 76, (png_byte) ' ', /* pCAL */
115, 67, 65, 76, (png_byte) ' ', /* sCAL */
115, 80, 76, 84, (png_byte) ' ', /* sPLT */
116, 73, 77, 69, (png_byte) ' ', /* tIME */
};
#endif
...
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
/* ignore all unknown chunks: */
png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
/* except for vpAg: */
png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
/* also ignore unused known chunks: */
png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
(int)sizeof(unused_chunks)/5);
#endif
User limits
The PNG specification allows the width and height of an image to be as large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns. Since very few applications really need to process such large images, we have imposed an arbitrary 1-million limit on rows and columns. Larger images will be rejected immediately with a png_error() call. If you wish to change this limit, you can usepng_set_user_limits(png_ptr, width_max, height_max);
width_max = png_get_user_width_max(png_ptr);
height_max = png_get_user_height_max(png_ptr);
png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
chunk_cache_max = png_get_chunk_cache_max(png_ptr);
png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
Information about your system
If you intend to display the PNG or to incorporate it in other image data you need to tell libpng information about your display or drawing surface so that libpng can convert the values in the image to match the display.png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/);
png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma, PNG_FP_1/screen_gamma);
PNG_DEFAULT_sRGB: Indicates that the system conforms to the IEC 61966-2-1
standard. This matches almost all systems.
PNG_GAMMA_MAC_18: Indicates that the system is an older (pre Mac OS 10.6)
Apple Macintosh system with the default settings.
PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates that the
system expects data with no gamma encoding.
#if PNG_LIBPNG_VER >= 10504
png_set_alpha_mode(png_ptr, mode, screen_gamma);
#else
png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma);
#endif
PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red, green and blue, or gray, components are gamma encoded color values and are not premultiplied by the alpha value. The alpha value is a linear measure of the contribution of the pixel to the corresponding final output pixel.
PNG_ALPHA_STANDARD: The data libpng produces is encoded in the standard way assumed by most correctly written graphics software. The gamma encoding will be removed by libpng and the linear component values will be pre-multiplied by the alpha channel.
PNG_ALPHA_OPTIMIZED: This mode is the same as PNG_ALPHA_STANDARD except that completely opaque pixels are gamma encoded according to the screen_gamma value. Pixels with alpha less than 1.0 will still have linear components.
PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD; however, all component values, including the alpha channel are gamma encoded. This is an appropriate format to try if your software, or more likely hardware, is totally broken, i.e., if it performs linear arithmetic directly on gamma encoded values.
png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG,
screen_gamma);
png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD,
screen_gamma);
png_set_expand_16(png_ptr);
png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,
screen_gamma);
png_set_background(png_ptr, &background_color,
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1);
PNG_TRANSFORM_SCALE_16 | PNG_EXPAND
png_set_expand(png_ptr); png_set_scale_16(png_ptr);
If you must get exactly the same inaccurate results
produced by default in versions prior to libpng-1.5.4,
use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr)
instead.
PNG_TRANSFORM_EXPAND_16
png_set_expand_16(png_ptr);
The high-level read interface
At this point there are two ways to proceed; through the high-level read interface, or through a sequence of low-level read operations. You can use the high-level interface if (a) you are willing to read the entire image into memory, and (b) the input transformations you want to do are limited to the following set:PNG_TRANSFORM_IDENTITY No transformation
PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to
8-bit accurately
PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to
8-bit less accurately
PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
samples to bytes
PNG_TRANSFORM_PACKSWAP Change order of packed
pixels to LSB first
PNG_TRANSFORM_EXPAND Perform set_expand()
PNG_TRANSFORM_INVERT_MONO Invert monochrome images
PNG_TRANSFORM_SHIFT Normalize pixels to the
sBIT depth
PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
to BGRA
PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
to AG
PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
to transparency
PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
to RGB (or GA to RGBA)
PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits
png_read_png(png_ptr, info_ptr, png_transforms, NULL)
row_pointers = png_get_rows(png_ptr, info_ptr);
png_bytep row_pointers[height];
if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
png_error (png_ptr,
"Image is too tall to process in memory");
if (width > PNG_UINT_32_MAX/pixel_size)
png_error (png_ptr,
"Image is too wide to process in memory");
row_pointers = png_malloc(png_ptr,
height*png_sizeof(png_bytep));
for (int i=0; i<height, i++)
row_pointers[i]=NULL; /* security precaution */
for (int i=0; i<height, i++)
row_pointers[i]=png_malloc(png_ptr,
width*pixel_size);
png_set_rows(png_ptr, info_ptr, &row_pointers);
The low-level read interface
If you are going the low-level route, 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().png_read_info(png_ptr, info_ptr);
Querying the info structure
Functions are used to get the information from the info_ptr once it has been read. Note that these fields may not be completely filled in until png_read_end() has read the chunk data following the image.png_get_IHDR(png_ptr, info_ptr, &width, &height,
&bit_depth, &color_type, &interlace_type,
&compression_type, &filter_method);
width - holds the width of the image
in pixels (up to 2^31).
height - holds the height of the image
in pixels (up to 2^31).
bit_depth - holds the bit depth of one of the
image channels. (valid values are
1, 2, 4, 8, 16 and depend also on
the color_type. See also
significant bits (sBIT) below).
color_type - describes which color/alpha channels
are present.
PNG_COLOR_TYPE_GRAY
(bit depths 1, 2, 4, 8, 16)
PNG_COLOR_TYPE_GRAY_ALPHA
(bit depths 8, 16)
PNG_COLOR_TYPE_PALETTE
(bit depths 1, 2, 4, 8)
PNG_COLOR_TYPE_RGB
(bit_depths 8, 16)
PNG_COLOR_TYPE_RGB_ALPHA
(bit_depths 8, 16)
PNG_COLOR_MASK_PALETTE
PNG_COLOR_MASK_COLOR
PNG_COLOR_MASK_ALPHA
interlace_type - (PNG_INTERLACE_NONE or
PNG_INTERLACE_ADAM7)
compression_type - (must be PNG_COMPRESSION_TYPE_BASE
for PNG 1.0)
filter_method - (must be PNG_FILTER_TYPE_BASE
for PNG 1.0, and can also be
PNG_INTRAPIXEL_DIFFERENCING if
the PNG datastream is embedded in
a MNG-1.0 datastream)
Any or all of interlace_type, compression_type, or
filter_method can be NULL if you are
not interested in their values.
Note that png_get_IHDR() returns 32-bit data into
the application's width and height variables.
This is an unsafe situation if these are 16-bit
variables. In such situations, the
png_get_image_width() and png_get_image_height()
functions described below are safer.
width = png_get_image_width(png_ptr,
info_ptr);
height = png_get_image_height(png_ptr,
info_ptr);
bit_depth = png_get_bit_depth(png_ptr,
info_ptr);
color_type = png_get_color_type(png_ptr,
info_ptr);
interlace_type = png_get_interlace_type(png_ptr,
info_ptr);
compression_type = png_get_compression_type(png_ptr,
info_ptr);
filter_method = png_get_filter_type(png_ptr,
info_ptr);
channels = png_get_channels(png_ptr, info_ptr);
channels - number of channels of info for the
color type (valid values are 1 (GRAY,
PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
4 (RGB_ALPHA or RGB + filler byte))
rowbytes = png_get_rowbytes(png_ptr, info_ptr);
rowbytes - number of bytes needed to hold a row
signature = png_get_signature(png_ptr, info_ptr);
signature - holds the signature read from the
file (if any). The data is kept in
the same offset it would be if the
whole signature were read (i.e. if an
application had already read in 4
bytes of signature before starting
libpng, the remaining 4 bytes would
be in signature[4] through signature[7]
(see png_set_sig_bytes())).
png_get_PLTE(png_ptr, info_ptr, &palette,
&num_palette);
palette - the palette for the file
(array of png_color)
num_palette - number of entries in the palette
png_get_gAMA(png_ptr, info_ptr, &file_gamma);
png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma);
file_gamma - the gamma at which the file was
written (PNG_INFO_gAMA)
int_file_gamma - 100,000 times the gamma at which the
file is written
png_get_cHRM(png_ptr, info_ptr, &white_x, &white_y, &red_x,
&red_y, &green_x, &green_y, &blue_x, &blue_y)
png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z, &green_X,
&green_Y, &green_Z, &blue_X, &blue_Y, &blue_Z)
png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x, &int_white_y,
&int_red_x, &int_red_y, &int_green_x, &int_green_y,
&int_blue_x, &int_blue_y)
png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y,
&int_red_Z, &int_green_X, &int_green_Y, &int_green_Z,
&int_blue_X, &int_blue_Y, &int_blue_Z)
{white,red,green,blue}_{x,y}
A color space encoding specified using the
chromaticities of the end points and the
white point. (PNG_INFO_cHRM)
{red,green,blue}_{X,Y,Z}
A color space encoding specified using the encoding end
points - the CIE tristimulus specification of the intended
color of the red, green and blue channels in the PNG RGB
data. The white point is simply the sum of the three end
points. (PNG_INFO_cHRM)
png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
file_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_iCCP(png_ptr, info_ptr, &name,
&compression_type, &profile, &proflen);
name - The profile name.
compression_type - The compression type; always
PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
You may give NULL to this argument to
ignore it.
profile - International Color Consortium color
profile data. May contain NULs.
proflen - length of profile data in bytes.
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
sig_bit - the number of significant bits for
(PNG_INFO_sBIT) each of the gray,
red, green, and blue channels,
whichever are appropriate for the
given color type (png_color_16)
png_get_tRNS(png_ptr, info_ptr, &trans_alpha,
&num_trans, &trans_color);
trans_alpha - array of alpha (transparency)
entries for palette (PNG_INFO_tRNS)
num_trans - number of transparent entries
(PNG_INFO_tRNS)
trans_color - graylevel or color sample values of
the single transparent color for
non-paletted images (PNG_INFO_tRNS)
png_get_hIST(png_ptr, info_ptr, &hist);
(PNG_INFO_hIST)
hist - histogram of palette (array of
png_uint_16)
png_get_tIME(png_ptr, info_ptr, &mod_time);
mod_time - time image was last modified
(PNG_VALID_tIME)
png_get_bKGD(png_ptr, info_ptr, &background);
background - background color (of type
png_color_16p) (PNG_VALID_bKGD)
valid 16-bit red, green and blue
values, regardless of color_type
num_comments = png_get_text(png_ptr, info_ptr,
&text_ptr, &num_text);
num_comments - number of comments
text_ptr - array of png_text holding image
comments
text_ptr[i].compression - type of compression used
on "text" PNG_TEXT_COMPRESSION_NONE
PNG_TEXT_COMPRESSION_zTXt
PNG_ITXT_COMPRESSION_NONE
PNG_ITXT_COMPRESSION_zTXt
text_ptr[i].key - keyword for comment. Must contain
1-79 characters.
text_ptr[i].text - text comments for current
keyword. Can be empty.
text_ptr[i].text_length - length of text string,
after decompression, 0 for iTXt
text_ptr[i].itxt_length - length of itxt string,
after decompression, 0 for tEXt/zTXt
text_ptr[i].lang - language of comment (empty
string for unknown).
text_ptr[i].lang_key - keyword in UTF-8
(empty string for unknown).
Note that the itxt_length, lang, and lang_key
members of the text_ptr structure only exist when the
library is built with iTXt chunk support. Prior to
libpng-1.4.0 the library was built by default without
iTXt support. Also note that when iTXt is supported,
they contain NULL pointers when the "compression"
field contains PNG_TEXT_COMPRESSION_NONE or
PNG_TEXT_COMPRESSION_zTXt.
num_text - number of comments (same as
num_comments; you can put NULL here
to avoid the duplication)
Note while png_set_text() will accept text, language,
and translated keywords that can be NULL pointers, the
structure returned by png_get_text will always contain
regular zero-terminated C strings. They might be
empty strings but they will never be NULL pointers.
num_spalettes = png_get_sPLT(png_ptr, info_ptr,
&palette_ptr);
num_spalettes - number of sPLT chunks read.
palette_ptr - array of palette structures holding
contents of one or more sPLT chunks
read.
png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
&unit_type);
offset_x - positive offset from the left edge
of the screen (can be negative)
offset_y - positive offset from the top edge
of the screen (can be negative)
unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
png_get_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_UNKNOWN,
PNG_RESOLUTION_METER
png_get_sCAL(png_ptr, info_ptr, &unit, &width,
&height)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are doubles)
png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
&height)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
(expressed as a string)
height - height of a pixel in physical scale units
(width and height are strings like "2.54")
num_unknown_chunks = png_get_unknown_chunks(png_ptr,
info_ptr, &unknowns)
unknowns - array of png_unknown_chunk
structures holding unknown chunks
unknowns[i].name - name of unknown chunk
unknowns[i].data - data of unknown chunk
unknowns[i].size - size of unknown chunk's data
unknowns[i].location - position of chunk in file
The value of "i" corresponds to the order in which the
chunks were read from the PNG file or inserted with the
png_set_unknown_chunks() function.
The value of "location" is a bitwise "or" of
PNG_HAVE_IHDR (0x01)
PNG_HAVE_PLTE (0x02)
PNG_AFTER_IDAT (0x08)
res_x = png_get_x_pixels_per_meter(png_ptr,
info_ptr)
res_y = png_get_y_pixels_per_meter(png_ptr,
info_ptr)
res_x_and_y = png_get_pixels_per_meter(png_ptr,
info_ptr)
res_x = png_get_x_pixels_per_inch(png_ptr,
info_ptr)
res_y = png_get_y_pixels_per_inch(png_ptr,
info_ptr)
res_x_and_y = png_get_pixels_per_inch(png_ptr,
info_ptr)
aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
info_ptr)
Each of these returns 0 [signifying "unknown"] if
the data is not present or if res_x is 0;
res_x_and_y is 0 if res_x != res_y
Note that because of the way the resolutions are
stored internally, the inch conversions won't
come out to exactly even number. For example,
72 dpi is stored as 0.28346 pixels/meter, and
when this is retrieved it is 71.9988 dpi, so
be sure to round the returned value appropriately
if you want to display a reasonable-looking result.
x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
Each of these returns 0 [signifying "unknown" if both
x and y are 0] if the data is not present or if the
chunk is present but the unit is the pixel. The
remark about inexact inch conversions applies here
as well, because a value in inches can't always be
converted to microns and back without some loss
of precision.
Input transformations
After you've read the header information, you can set up the library to handle any special transformations of the image data. The various ways to transform the data will be described in the order that they should occur. This is important, as some of these change the color type and/or bit depth of the data, and some others only work on certain color types and bit depths.if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
if (png_get_valid(png_ptr, info_ptr,
PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY &&
bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
if (bit_depth < 16)
png_set_expand_16(png_ptr);
if (bit_depth == 16) #if PNG_LIBPNG_VER >= 10504
png_set_scale_16(png_ptr); #else
png_set_strip_16(png_ptr); #endif
if (color_type & PNG_COLOR_MASK_ALPHA)
png_set_strip_alpha(png_ptr);
FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
TO
01 - [G] - - - - - - - - - - - - -
31 [Q] Q [Q] [Q] [Q] Q Q Q Q Q Q [Q] [Q] Q Q
0 1 G + . . G G G G G G B B GB GB
0T lt Gt t + . Gt G G Gt G G Bt Bt GBt GBt
0O lt Gt t . + Gt Gt G Gt Gt G Bt Bt GBt GBt
2 C P C C C + . . C - - CB CB B B
2T Ct - Ct C C t + t - - - CBt CBt Bt Bt
2O Ct - Ct C C t t + - - - CBt CBt Bt Bt
3 [Q] p [Q] [Q] [Q] Q Q Q + . . [Q] [Q] Q Q
3T [Qt] p [Qt][Q] [Q] Qt Qt Qt t + t [Qt][Qt] Qt Qt
3O [Qt] p [Qt][Q] [Q] Qt Qt Qt t t + [Qt][Qt] Qt Qt
4A lA G A T T GA GT GT GA GT GT + BA G GBA
4O lA GBA A T T GA GT GT GA GT GT BA + GBA G
6A CA PA CA C C A T tT PA P P C CBA + BA
6O CA PBA CA C C A tT T PA P P CBA C BA +
"+" identifies entries where 'from' and 'to' are the same.
"-" means the transformation is not supported.
"." means nothing is necessary (a tRNS chunk can just be ignored).
"t" means the transformation is obtained by png_set_tRNS.
"A" means the transformation is obtained by png_set_add_alpha().
"X" means the transformation is obtained by png_set_expand().
"1" means the transformation is obtained by
png_set_expand_gray_1_2_4_to_8() (and by png_set_expand()
if there is no transparency in the original or the final
format).
"C" means the transformation is obtained by png_set_gray_to_rgb().
"G" means the transformation is obtained by png_set_rgb_to_gray().
"P" means the transformation is obtained by
png_set_expand_palette_to_rgb().
"p" means the transformation is obtained by png_set_packing().
"Q" means the transformation is obtained by png_set_quantize().
"T" means the transformation is obtained by
png_set_tRNS_to_alpha().
"B" means the transformation is obtained by
png_set_background(), or png_strip_alpha().
png_set_invert_alpha(png_ptr);
if (bit_depth < 8)
png_set_packing(png_ptr);
png_color_8p sig_bit;
if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
png_set_shift(png_ptr, sig_bit);
if (color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA)
png_set_bgr(png_ptr);
if (color_type == PNG_COLOR_TYPE_RGB)
png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
if (color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_GRAY)
png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
png_set_swap_alpha(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA)
png_set_rgb_to_gray(png_ptr, error_action,
double red_weight, double green_weight);
error_action = 1: silently do the conversion
error_action = 2: issue a warning if the original
image has any pixel where
red != green or red != blue
error_action = 3: issue an error and abort the
conversion if the original
image has any pixel where
red != green or red != blue
red_weight: weight of red component
green_weight: weight of green component
If either weight is negative, default
weights are used.
png_set_rgb_to_gray(png_ptr, error_action,
png_fixed_point red_weight,
png_fixed_point green_weight);
<http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9>
Y = 0.2126 * R + 0.7152 * G + 0.0722 * B
Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
Y = (6968 * R + 23434 * G + 2366 * B)/32768
png_color_16 my_background;
png_color_16p image_background;
if (png_get_bKGD(png_ptr, info_ptr, &image_background))
png_set_background(png_ptr, image_background,
PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1);
else
png_set_background(png_ptr, &my_background,
PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1);
if (png_get_gAMA(png_ptr, info_ptr, &file_gamma))
png_set_gamma(png_ptr, screen_gamma, file_gamma);
else
png_set_gamma(png_ptr, screen_gamma, 0.45455);
if (color_type & PNG_COLOR_MASK_COLOR)
{
if (png_get_valid(png_ptr, info_ptr,
PNG_INFO_PLTE))
{
png_uint_16p histogram = NULL;
png_get_hIST(png_ptr, info_ptr,
&histogram);
png_set_quantize(png_ptr, palette, num_palette,
max_screen_colors, histogram, 1);
}
else
{
png_color std_color_cube[MAX_SCREEN_COLORS] =
{ ... colors ... };
png_set_quantize(png_ptr, std_color_cube,
MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
NULL,0);
}
}
if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
png_set_invert_mono(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_invert_mono(png_ptr);
if (bit_depth == 16)
png_set_swap(png_ptr);
if (bit_depth < 8)
png_set_packswap(png_ptr);
png_set_read_user_transform_fn(png_ptr,
read_transform_fn);
void read_transform_fn(png_structp png_ptr, png_row_infop
row_info, png_bytep data)
png_get_current_pass_number(png_structp png_ptr);
png_get_current_row_number(png_structp png_ptr);
png_set_user_transform_info(png_ptr, user_ptr,
user_depth, user_channels);
voidp read_user_transform_ptr =
png_get_user_transform_ptr(png_ptr);
number_of_passes = png_set_interlace_handling(png_ptr);
png_read_update_info(png_ptr, info_ptr);
Reading image data
After you've allocated memory, you can read the image data. The simplest way to do this is in one function call. If you are allocating enough memory to hold the whole image, you can just call png_read_image() and libpng will read in all the image data and put it in the memory area supplied. You will need to pass in an array of pointers to each row.png_read_image(png_ptr, row_pointers);
png_bytep row_pointers[height];
png_read_rows(png_ptr, row_pointers, NULL,
number_of_rows);
png_bytep row_pointer = row;
png_read_row(png_ptr, row_pointer, NULL);
if (interlace_type == PNG_INTERLACE_ADAM7)
number_of_passes
= png_set_interlace_handling(png_ptr);
png_read_rows(png_ptr, row_pointers, NULL,
number_of_rows);
png_read_rows(png_ptr, NULL, row_pointers,
number_of_rows);
png_uint_32 width = PNG_PASS_COLS(image_width, pass_number);
png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number);
png_uint_32 x = PNG_PASS_START_COL(pass);
png_uint_32 y = PNG_PASS_START_ROW(pass);
png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass);
png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass);
png_uint_32 input_y = 0;
png_uint_32 output_y = PNG_PASS_START_ROW(pass);
while (output_y < output_image_height)
{
png_uint_32 input_x = 0;
png_uint_32 output_x = PNG_PASS_START_COL(pass);
while (output_x < output_image_width)
{
image[output_y][output_x] =
subimage[pass][input_y][input_x++];
output_x += xStep;
}
++input_y;
output_y += yStep;
}
png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass);
png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass);
int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass);
int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass);
Finishing a sequential read
After you are finished reading the image through the low-level interface, you can finish reading the file. If you are interested in comments or time, which may be stored either before or after the image data, you should pass the separate png_info struct if you want to keep the comments from before and after the image separate.png_infop end_info = png_create_info_struct(png_ptr);
if (!end_info)
{
png_destroy_read_struct(&png_ptr, &info_ptr,
(png_infopp)NULL);
return (ERROR);
}
png_read_end(png_ptr, end_info);
png_read_end(png_ptr, (png_infop)NULL);
png_destroy_read_struct(&png_ptr, &info_ptr,
&end_info);
png_destroy_read_struct(&png_ptr, &info_ptr,
(png_infopp)NULL);
png_free_data(png_ptr, info_ptr, mask, seq)
mask - identifies data to be freed, a mask
containing the bitwise OR of one or
more of
PNG_FREE_PLTE, PNG_FREE_TRNS,
PNG_FREE_HIST, PNG_FREE_ICCP,
PNG_FREE_PCAL, PNG_FREE_ROWS,
PNG_FREE_SCAL, PNG_FREE_SPLT,
PNG_FREE_TEXT, PNG_FREE_UNKN,
or simply PNG_FREE_ALL
seq - sequence number of item to be freed
(-1 for all items)
png_data_freer(png_ptr, info_ptr, freer, mask)
freer - one of
PNG_DESTROY_WILL_FREE_DATA
PNG_SET_WILL_FREE_DATA
PNG_USER_WILL_FREE_DATA
mask - which data elements are affected
same choices as in png_free_data()
png_set_invalid(png_ptr, info_ptr, mask);
mask - identifies the chunks to be made invalid,
containing the bitwise OR of one or
more of
PNG_INFO_gAMA, PNG_INFO_sBIT,
PNG_INFO_cHRM, PNG_INFO_PLTE,
PNG_INFO_tRNS, PNG_INFO_bKGD,
PNG_INFO_hIST, PNG_INFO_pHYs,
PNG_INFO_oFFs, PNG_INFO_tIME,
PNG_INFO_pCAL, PNG_INFO_sRGB,
PNG_INFO_iCCP, PNG_INFO_sPLT,
PNG_INFO_sCAL, PNG_INFO_IDAT
Reading PNG files progressively
The progressive reader is slightly different then the non-progressive reader. Instead of calling png_read_info(), png_read_rows(), and png_read_end(), you make one call to png_process_data(), which calls callbacks when it has the info, a row, or the end of the image. You set up these callbacks with png_set_progressive_read_fn(). You don't have to worry about the input/output functions of libpng, as you are giving the library the data directly in png_process_data(). I will assume that you have read the section on reading PNG files above, so I will only highlight the differences (although I will show all of the code)./* An example code fragment of how you would
initialize the progressive reader in your
application. */
int
initialize_png_reader()
{
png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn);
if (!png_ptr)
return (ERROR);
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr,
(png_infopp)NULL, (png_infopp)NULL);
return (ERROR);
}
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr,
(png_infopp)NULL);
return (ERROR);
}
/* This one's new. You can provide functions
to be called when the header info is valid,
when each row is completed, and when the image
is finished. If you aren't using all functions,
you can specify NULL parameters. Even when all
three functions are NULL, you need to call
png_set_progressive_read_fn(). You can use
any struct as the user_ptr (cast to a void pointer
for the function call), and retrieve the pointer
from inside the callbacks using the function
png_get_progressive_ptr(png_ptr);
which will return a void pointer, which you have
to cast appropriately.
*/
png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
info_callback, row_callback, end_callback);
return 0;
}
/* A code fragment that you call as you receive blocks
of data */
int
process_data(png_bytep buffer, png_uint_32 length)
{
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr,
(png_infopp)NULL);
return (ERROR);
}
/* This one's new also. Simply give it a chunk
of data from the file stream (in order, of
course). On machines with segmented memory
models machines, don't give it any more than
64K. The library seems to run fine with sizes
of 4K. Although you can give it much less if
necessary (I assume you can give it chunks of
1 byte, I haven't tried less then 256 bytes
yet). When this function returns, you may
want to display any rows that were generated
in the row callback if you don't already do
so there.
*/
png_process_data(png_ptr, info_ptr, buffer, length);
/* At this point you can call png_process_data_skip if
you want to handle data the library will skip yourself;
it simply returns the number of bytes to skip (and stops
libpng skipping that number of bytes on the next
png_process_data call).
return 0;
}
/* This function is called (as set by
png_set_progressive_read_fn() above) when enough data
has been supplied so all of the header has been
read.
*/
void
info_callback(png_structp png_ptr, png_infop info)
{
/* Do any setup here, including setting any of
the transformations mentioned in the Reading
PNG files section. For now, you _must_ call
either png_start_read_image() or
png_read_update_info() after all the
transformations are set (even if you don't set
any). You may start getting rows before
png_process_data() returns, so this is your
last chance to prepare for that.
This is where you turn on interlace handling,
assuming you don't want to do it yourself.
If you need to you can stop the processing of
your original input data at this point by calling
png_process_data_pause. This returns the number
of unprocessed bytes from the last png_process_data
call - it is up to you to ensure that the next call
sees these bytes again. If you don't want to bother
with this you can get libpng to cache the unread
bytes by setting the 'save' parameter (see png.h) but
then libpng will have to copy the data internally.
*/
}
/* This function is called when each row of image
data is complete */
void
row_callback(png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass)
{
/* If the image is interlaced, and you turned
on the interlace handler, this function will
be called for every row in every pass. Some
of these rows will not be changed from the
previous pass. When the row is not changed,
the new_row variable will be NULL. The rows
and passes are called in order, so you don't
really need the row_num and pass, but I'm
supplying them because it may make your life
easier.
If you did not turn on interlace handling then
the callback is called for each row of each
sub-image when the image is interlaced. In this
case 'row_num' is the row in the sub-image, not
the row in the output image as it is in all other
cases.
For the non-NULL rows of interlaced images when
you have switched on libpng interlace handling,
you must call png_progressive_combine_row()
passing in the row and the old row. You can
call this function for NULL rows (it will just
return) and for non-interlaced images (it just
does the memcpy for you) if it will make the
code easier. Thus, you can just do this for
all cases if you switch on interlace handling;
*/
png_progressive_combine_row(png_ptr, old_row,
new_row);
/* where old_row is what was displayed for
previously for the row. Note that the first
pass (pass == 0, really) will completely cover
the old row, so the rows do not have to be
initialized. After the first pass (and only
for interlaced images), you will have to pass
the current row, and the function will combine
the old row and the new row.
You can also call png_process_data_pause in this
callback - see above.
*/
}
void
end_callback(png_structp png_ptr, png_infop info)
{
/* This function is called after the whole image
has been read, including any chunks after the
image (up to and including the IEND). You
will usually have the same info chunk as you
had in the header, although some data may have
been added to the comments and time fields.
Most people won't do much here, perhaps setting
a flag that marks the image as finished.
*/
}
IV. Writing
Much of this is very similar to reading. However, everything of importance is repeated here, so you won't have to constantly look back up in the reading section to understand writing.Setup
You will want to do the I/O initialization before you get into libpng, so if it doesn't work, you don't have anything to undo. If you are not using the standard I/O functions, you will need to replace them with custom writing functions. See the discussion under Customizing libpng.FILE *fp = fopen(file_name, "wb");
if (!fp)
return (ERROR);
png_structp png_ptr = png_create_write_struct
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn);
if (!png_ptr)
return (ERROR);
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_write_struct(&png_ptr,
(png_infopp)NULL);
return (ERROR);
}
png_structp png_ptr = png_create_write_struct_2
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
user_error_fn, user_warning_fn, (png_voidp)
user_mem_ptr, user_malloc_fn, user_free_fn);
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return (ERROR);
}
...
return;
png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, 8);
Write callbacks
At this point, you can set up a callback function that will be called after each row has been written, which you can use to control a progress meter or the like. It's demonstrated in pngtest.c. You must supply a functionvoid write_row_callback(png_structp png_ptr, png_uint_32 row,
int pass);
{
/* put your code here */
}
png_set_write_status_fn(png_ptr, write_row_callback);
/* turn on or off filtering, and/or choose
specific filters. You can use either a single
PNG_FILTER_VALUE_NAME or the bitwise OR of one
or more PNG_FILTER_NAME masks.
*/
png_set_filter(png_ptr, 0,
PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
PNG_ALL_FILTERS);
#include zlib.h
/* Set the zlib compression level */
png_set_compression_level(png_ptr,
Z_BEST_COMPRESSION);
/* Set other zlib parameters for compressing IDAT */
png_set_compression_mem_level(png_ptr, 8);
png_set_compression_strategy(png_ptr,
Z_DEFAULT_STRATEGY);
png_set_compression_window_bits(png_ptr, 15);
png_set_compression_method(png_ptr, 8);
png_set_compression_buffer_size(png_ptr, 8192)
/* Set zlib parameters for text compression
* If you don't call these, the parameters
* fall back on those defined for IDAT chunks
*/
png_set_text_compression_mem_level(png_ptr, 8);
png_set_text_compression_strategy(png_ptr,
Z_DEFAULT_STRATEGY);
png_set_text_compression_window_bits(png_ptr, 15);
png_set_text_compression_method(png_ptr, 8);
Setting the contents of info for output
You now need to fill in the png_info structure with all the data you wish to write before the actual image. Note that the only thing you are allowed to write after the image is the text chunks and the time chunk (as of PNG Specification 1.2, anyway). See png_write_end() and the latest PNG specification for more information on that. If you wish to write them before the image, fill them in now, and flag that data as being valid. If you want to wait until after the data, don't fill them until png_write_end(). For all the fields in png_info and their data types, see png.h. For explanations of what the fields contain, see the PNG specification.png_set_IHDR(png_ptr, info_ptr, width, height,
bit_depth, color_type, interlace_type,
compression_type, filter_method)
width - holds the width of the image
in pixels (up to 2^31).
height - holds the height of the image
in pixels (up to 2^31).
bit_depth - holds the bit depth of one of the
image channels.
(valid values are 1, 2, 4, 8, 16
and depend also on the
color_type. See also significant
bits (sBIT) below).
color_type - describes which color/alpha
channels are present.
PNG_COLOR_TYPE_GRAY
(bit depths 1, 2, 4, 8, 16)
PNG_COLOR_TYPE_GRAY_ALPHA
(bit depths 8, 16)
PNG_COLOR_TYPE_PALETTE
(bit depths 1, 2, 4, 8)
PNG_COLOR_TYPE_RGB
(bit_depths 8, 16)
PNG_COLOR_TYPE_RGB_ALPHA
(bit_depths 8, 16)
PNG_COLOR_MASK_PALETTE
PNG_COLOR_MASK_COLOR
PNG_COLOR_MASK_ALPHA
interlace_type - PNG_INTERLACE_NONE or
PNG_INTERLACE_ADAM7
compression_type - (must be
PNG_COMPRESSION_TYPE_DEFAULT)
filter_method - (must be PNG_FILTER_TYPE_DEFAULT
or, if you are writing a PNG to
be embedded in a MNG datastream,
can also be
PNG_INTRAPIXEL_DIFFERENCING)
png_set_PLTE(png_ptr, info_ptr, palette,
num_palette);
palette - the palette for the file
(array of png_color)
num_palette - number of entries in the palette
png_set_gAMA(png_ptr, info_ptr, file_gamma);
png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
file_gamma - the gamma at which the image was
created (PNG_INFO_gAMA)
int_file_gamma - 100,000 times the gamma at which
the image was created
png_set_cHRM(png_ptr, info_ptr, white_x, white_y, red_x, red_y,
green_x, green_y, blue_x, blue_y)
png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X,
green_Y, green_Z, blue_X, blue_Y, blue_Z)
png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y,
int_red_x, int_red_y, int_green_x, int_green_y,
int_blue_x, int_blue_y)
png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y,
int_red_Z, int_green_X, int_green_Y, int_green_Z,
int_blue_X, int_blue_Y, int_blue_Z)
{white,red,green,blue}_{x,y}
A color space encoding specified using the chromaticities
of the end points and the white point.
{red,green,blue}_{X,Y,Z}
A color space encoding specified using the encoding end
points - the CIE tristimulus specification of the intended
color of the red, green and blue channels in the PNG RGB
data. The white point is simply the sum of the three end
points.
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. Rendering
intent is the CSS-1 property that
has been defined by the International
Color Consortium
(http://www.color.org).
It can be one of
PNG_sRGB_INTENT_SATURATION,
PNG_sRGB_INTENT_PERCEPTUAL,
PNG_sRGB_INTENT_ABSOLUTE, or
PNG_sRGB_INTENT_RELATIVE.
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 function also causes gAMA and
cHRM chunks with the specific values
that are consistent with sRGB to be
written.
png_set_iCCP(png_ptr, info_ptr, name, compression_type,
profile, proflen);
name - The profile name.
compression_type - The compression type; always
PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
You may give NULL to this argument to
ignore it.
profile - International Color Consortium color
profile data. May contain NULs.
proflen - length of profile data in bytes.
png_set_sBIT(png_ptr, info_ptr, sig_bit);
sig_bit - the number of significant bits for
(PNG_INFO_sBIT) each of the gray, red,
green, and blue channels, whichever are
appropriate for the given color type
(png_color_16)
png_set_tRNS(png_ptr, info_ptr, trans_alpha,
num_trans, trans_color);
trans_alpha - array of alpha (transparency)
entries for palette (PNG_INFO_tRNS)
num_trans - number of transparent entries
(PNG_INFO_tRNS)
trans_color - graylevel or color sample values
(in order red, green, blue) of the
single transparent color for
non-paletted images (PNG_INFO_tRNS)
png_set_hIST(png_ptr, info_ptr, hist);
hist - histogram of palette (array of
png_uint_16) (PNG_INFO_hIST)
png_set_tIME(png_ptr, info_ptr, mod_time);
mod_time - time image was last modified
(PNG_VALID_tIME)
png_set_bKGD(png_ptr, info_ptr, background);
background - background color (of type
png_color_16p) (PNG_VALID_bKGD)
png_set_text(png_ptr, info_ptr, text_ptr, num_text);
text_ptr - array of png_text holding image
comments
text_ptr[i].compression - type of compression used
on "text" PNG_TEXT_COMPRESSION_NONE
PNG_TEXT_COMPRESSION_zTXt
PNG_ITXT_COMPRESSION_NONE
PNG_ITXT_COMPRESSION_zTXt
text_ptr[i].key - keyword for comment. Must contain
1-79 characters.
text_ptr[i].text - text comments for current
keyword. Can be NULL or empty.
text_ptr[i].text_length - length of text string,
after decompression, 0 for iTXt
text_ptr[i].itxt_length - length of itxt string,
after decompression, 0 for tEXt/zTXt
text_ptr[i].lang - language of comment (NULL or
empty for unknown).
text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
or empty for unknown).
Note that the itxt_length, lang, and lang_key
members of the text_ptr structure only exist when the
library is built with iTXt chunk support. Prior to
libpng-1.4.0 the library was built by default without
iTXt support. Also note that when iTXt is supported,
they contain NULL pointers when the "compression"
field contains PNG_TEXT_COMPRESSION_NONE or
PNG_TEXT_COMPRESSION_zTXt.
num_text - number of comments
png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
num_spalettes);
palette_ptr - array of png_sPLT_struct structures
to be added to the list of palettes
in the info structure.
num_spalettes - number of palette structures to be
added.
png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
unit_type);
offset_x - positive offset from the left
edge of the screen
offset_y - positive offset from the top
edge of the screen
unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
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 y direction
unit_type - PNG_RESOLUTION_UNKNOWN,
PNG_RESOLUTION_METER
png_set_sCAL(png_ptr, info_ptr, unit, width, height)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are doubles)
png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
expressed as a string
height - height of a pixel in physical scale units
(width and height are strings like "2.54")
png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
num_unknowns)
unknowns - array of png_unknown_chunk
structures holding unknown chunks
unknowns[i].name - name of unknown chunk
unknowns[i].data - data of unknown chunk
unknowns[i].size - size of unknown chunk's data
unknowns[i].location - position to write chunk in file
0: do not write chunk
PNG_HAVE_IHDR: before PLTE
PNG_HAVE_PLTE: before IDAT
PNG_AFTER_IDAT: after IDAT
Title Short (one line) title or
caption for image
Author Name of image's creator
Description Description of image (possibly long)
Copyright Copyright notice
Creation Time Time of original image creation
(usually RFC 1123 format, see below)
Software Software used to create the image
Disclaimer Legal disclaimer
Warning Warning of nature of content
Source Device used to create the image
Comment Miscellaneous comment; conversion
from other image format
Writing unknown chunks
You can use the png_set_unknown_chunks function to queue up chunks for writing. You give it a chunk name, raw data, and a size; that's all there is to it. The chunks will be written by the next following png_write_info_before_PLTE, png_write_info, or png_write_end function. Any chunks previously read into the info structure's unknown-chunk list will also be written out in a sequence that satisfies the PNG specification's ordering rules.The high-level write interface
At this point there are two ways to proceed; through the high-level write interface, or through a sequence of low-level write operations. You can use the high-level interface if your image data is present in the info structure. All defined output transformations are permitted, enabled by the following masks.PNG_TRANSFORM_IDENTITY No transformation
PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
PNG_TRANSFORM_PACKSWAP Change order of packed
pixels to LSB first
PNG_TRANSFORM_INVERT_MONO Invert monochrome images
PNG_TRANSFORM_SHIFT Normalize pixels to the
sBIT depth
PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
to BGRA
PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
to AG
PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
to transparency
PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
PNG_TRANSFORM_STRIP_FILLER Strip out filler
bytes (deprecated).
PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
filler bytes
PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing
filler bytes
png_write_png(png_ptr, info_ptr, png_transforms, NULL)
The low-level write interface
If you are going the low-level route instead, 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().png_write_info(png_ptr, info_ptr);
png_set_invert_alpha(png_ptr);
png_write_info_before_PLTE(png_ptr, info_ptr);
png_set_unknown_chunks(png_ptr, info_ptr, ...);
png_write_info(png_ptr, info_ptr);
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
png_set_packing(png_ptr);
/* Set the true bit depth of the image data */
if (color_type & PNG_COLOR_MASK_COLOR)
{
sig_bit.red = true_bit_depth;
sig_bit.green = true_bit_depth;
sig_bit.blue = true_bit_depth;
}
else
{
sig_bit.gray = true_bit_depth;
}
if (color_type & PNG_COLOR_MASK_ALPHA)
{
sig_bit.alpha = true_bit_depth;
}
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
png_set_shift(png_ptr, &sig_bit);
if (bit_depth > 8)
png_set_swap(png_ptr);
if (bit_depth < 8)
png_set_packswap(png_ptr);
png_set_bgr(png_ptr);
png_set_invert_mono(png_ptr);
png_set_write_user_transform_fn(png_ptr,
write_transform_fn);
void write_transform_fn(png_structp png_ptr, png_row_infop
row_info, png_bytep data)
png_get_current_row_number(png_ptr);
png_get_current_pass_number(png_ptr);
png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
voidp write_user_transform_ptr =
png_get_user_transform_ptr(png_ptr);
png_write_flush(png_ptr);
png_set_flush(png_ptr, nrows);
Writing the image data
That's it for the transformations. Now you can write the image data. The simplest way to do this is in one function call. If you have the whole image in memory, you can just call png_write_image() and libpng will write the image. You will need to pass in an array of pointers to each row. This function automatically handles interlacing, so you don't need to call png_set_interlace_handling() or call this function multiple times, or any of that other stuff necessary with png_write_rows().png_write_image(png_ptr, row_pointers);
png_byte *row_pointers[height];
png_write_rows(png_ptr, row_pointers,
number_of_rows);
png_bytep row_pointer = row;
png_write_row(png_ptr, row_pointer);
number_of_passes = png_set_interlace_handling(png_ptr);
png_write_rows(png_ptr, row_pointers, number_of_rows);
Finishing a sequential write
After you are finished writing the image, you should finish writing the file. If you are interested in writing comments or time, you should pass an appropriately filled png_info pointer. If you are not interested, you can pass NULL.png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
png_free_data(png_ptr, info_ptr, mask, seq)
mask - identifies data to be freed, a mask
containing the bitwise OR of one or
more of
PNG_FREE_PLTE, PNG_FREE_TRNS,
PNG_FREE_HIST, PNG_FREE_ICCP,
PNG_FREE_PCAL, PNG_FREE_ROWS,
PNG_FREE_SCAL, PNG_FREE_SPLT,
PNG_FREE_TEXT, PNG_FREE_UNKN,
or simply PNG_FREE_ALL
seq - sequence number of item to be freed
(-1 for all items)
png_data_freer(png_ptr, info_ptr, freer, mask)
freer - one of
PNG_DESTROY_WILL_FREE_DATA
PNG_SET_WILL_FREE_DATA
PNG_USER_WILL_FREE_DATA
mask - which data elements are affected
same choices as in png_free_data()
png_data_freer(read_ptr, read_info_ptr,
PNG_USER_WILL_FREE_DATA,
PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
png_data_freer(write_ptr, write_info_ptr,
PNG_DESTROY_WILL_FREE_DATA,
PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
V. Modifying/Customizing libpng:
There are two issues here. The first is changing how libpng does standard things like memory allocation, input/output, and error handling. The second deals with more complicated things like adding new chunks, adding new transformations, and generally changing how libpng works. Both of those are compile-time issues; that is, they are generally determined at the time the code is written, and there is rarely a need to provide the user with a means of changing them.mem_ptr=png_get_mem_ptr(png_ptr);
png_voidp malloc_fn(png_structp png_ptr,
png_alloc_size_t size);
void free_fn(png_structp png_ptr, png_voidp ptr);
png_set_read_fn(png_structp read_ptr,
voidp read_io_ptr, png_rw_ptr read_data_fn)
png_set_write_fn(png_structp write_ptr,
voidp write_io_ptr, png_rw_ptr write_data_fn,
png_flush_ptr output_flush_fn);
voidp read_io_ptr = png_get_io_ptr(read_ptr);
voidp write_io_ptr = png_get_io_ptr(write_ptr);
void user_read_data(png_structp png_ptr,
png_bytep data, png_size_t length);
void user_write_data(png_structp png_ptr,
png_bytep data, png_size_t length);
void user_flush_data(png_structp png_ptr);
png_set_error_fn(png_structp png_ptr,
png_voidp error_ptr, png_error_ptr error_fn,
png_error_ptr warning_fn);
png_voidp error_ptr = png_get_error_ptr(png_ptr);
void user_error_fn(png_structp png_ptr,
png_const_charp error_msg);
void user_warning_fn(png_structp png_ptr,
png_const_charp warning_msg);
Custom chunks
If you need to read or write custom chunks, you may need to get deeper into the libpng code. The library now has mechanisms for storing and writing chunks of unknown type; you can even declare callbacks for custom chunks. However, this may not be good enough if the library code itself needs to know about interactions between your chunk and existing `intrinsic' chunks.Configuring for 16-bit platforms
You will want to look into zconf.h to tell zlib (and thus libpng) that it cannot allocate more then 64K at a time. Even if you can, the memory won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.Configuring for DOS
For DOS users who only have access to the lower 640K, you will have to limit zlib's memory usage via a png_set_compression_mem_level() 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 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 the end for pointers (or at least look at them and be careful). Make note that the rows of data are defined as png_bytepp, which is an "unsigned char far * far *".Configuring for gui/windowing platforms:
You will need to write new error and warning functions that use the GUI interface, as described previously, and set them to be the error and warning functions at the time that png_create_*_struct() is called, in order to have them available during the structure initialization. They can be changed later via png_set_error_fn(). On some compilers, you may also have to change the memory allocators (png_malloc, etc.).Configuring for compiler xxx:
All includes for libpng are in pngconf.h. If you need to add, change or delete an include, this is the place to do it. The includes that are not needed outside libpng are placed in pngpriv.h, which is only used by the routines inside libpng itself. The files in libpng proper only include pngpriv.h and png.h, which %14%in turn includes pngconf.h. in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h. As of libpng-1.5.0, pngpriv.h also includes three other private header files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material that previously appeared in the public headers.Configuring zlib:
There are special functions to configure the compression. Perhaps the 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 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 compression level by calling:#include zlib.h
png_set_compression_level(png_ptr, level);
#include zlib.h
png_set_compression_mem_level(png_ptr, level);
#include zlib.h
png_set_compression_strategy(png_ptr,
strategy);
png_set_compression_window_bits(png_ptr,
window_bits);
png_set_compression_method(png_ptr, method);
png_set_compression_buffer_size(png_ptr, size);
#include zlib.h
#if PNG_LIBPNG_VER >= 10504
png_set_text_compression_level(png_ptr, level);
png_set_text_compression_mem_level(png_ptr, level);
png_set_text_compression_strategy(png_ptr,
strategy);
png_set_text_compression_window_bits(png_ptr,
window_bits);
png_set_text_compression_method(png_ptr, method);
#endif
Controlling row filtering
If you want to control whether libpng uses filtering or not, which filters are used, and how it goes about picking row filters, you can call one of these functions. The selection and configuration of row filters can have a significant impact on the size and encoding speed and a somewhat lesser impact on the decoding speed of an image. Filtering is enabled by default for RGB and grayscale images (with and without alpha), but not for paletted images nor for any images with bit depths less than 8 bits/pixel.filters = PNG_FILTER_NONE | PNG_FILTER_SUB
PNG_FILTER_UP | PNG_FILTER_AVG |
PNG_FILTER_PAETH | PNG_ALL_FILTERS;
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
filters);
The second parameter can also be
PNG_INTRAPIXEL_DIFFERENCING if you are
writing a PNG to be embedded in a MNG
datastream. This parameter must be the
same as the value of filter_method used
in png_set_IHDR().
double weights[3] = {1.5, 1.3, 1.1},
costs[PNG_FILTER_VALUE_LAST] =
{1.0, 1.3, 1.3, 1.5, 1.7};
png_set_filter_heuristics(png_ptr,
PNG_FILTER_HEURISTIC_WEIGHTED, 3,
weights, costs);
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 a capability, you can change the #define to #undef before recompiling libpng and save yourself code and data space, or you can turn off individual capabilities with defines that begin with PNG_NO_.Requesting debug printout
The macro definition PNG_DEBUG can be used to request debugging printout. Set it to an integer value in the range 0 to 3. Higher numbers result in increasing amounts of debugging information. The information is printed to the "stderr" file, unless another file name is specified in the PNG_DEBUG_FILE macro definition.png_debug(level, message)
png_debug1(level, message, p1)
png_debug2(level, message, p1, p2)
png_debug1(2, "foo=%d0, foo);
if (PNG_DEBUG > 2)
fprintf(PNG_DEBUG_FILE, "foo=%d0, foo);
#ifdef PNG_DEBUG
fprintf(stderr, ...
#endif
VI. MNG support
The MNG specification (available at http://www.libpng.org/pub/mng) allows certain extensions to PNG for PNG images that are embedded in MNG datastreams. Libpng can support some of these extensions. To enable them, use the png_permit_mng_features() function:feature_set = png_permit_mng_features(png_ptr, mask)
mask is a png_uint_32 containing the bitwise OR of the
features you want to enable. These include
PNG_FLAG_MNG_EMPTY_PLTE
PNG_FLAG_MNG_FILTER_64
PNG_ALL_MNG_FEATURES
feature_set is a png_uint_32 that is the bitwise AND of
your mask with the set of MNG features that is
supported by the version of libpng that you are using.
VII. Changes to Libpng from version 0.88
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.png_uint_32 libpng_vn = png_access_version_number();
png_uint_32 application_vn = PNG_LIBPNG_VER;
VIII. Changes to Libpng from version 1.0.x to 1.2.x
Support for user memory management was enabled by default. To accomplish this, the functions png_create_read_struct_2(), png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(), png_malloc_default(), and png_free_default() were added.PNG_ASM_FLAG_MMX_SUPPORT_COMPILED
PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
PNG_ASM_FLAG_MMX_READ_INTERLACE
PNG_ASM_FLAG_MMX_READ_FILTER_SUB
PNG_ASM_FLAG_MMX_READ_FILTER_UP
PNG_ASM_FLAG_MMX_READ_FILTER_AVG
PNG_ASM_FLAG_MMX_READ_FILTER_PAETH
PNG_ASM_FLAGS_INITIALIZED
PNG_MMX_READ_FLAGS
PNG_MMX_FLAGS
PNG_MMX_WRITE_FLAGS
PNG_MMX_FLAGS
png_get_mmx_flagmask()
png_set_mmx_thresholds()
png_get_asm_flags()
png_get_mmx_bitdepth_threshold()
png_get_mmx_rowbytes_threshold()
png_set_asm_flags()
PNG_READ_TRANSFORMS_NOT_SUPPORTED
PNG_PROGRESSIVE_READ_NOT_SUPPORTED
PNG_NO_SEQUENTIAL_READ_SUPPORTED
PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
PNG_NO_READ_TRANSFORMS
PNG_NO_PROGRESSIVE_READ
PNG_NO_SEQUENTIAL_READ
PNG_NO_WRITE_TRANSFORMS
PNG_NO_READ_ANCILLARY_CHUNKS
PNG_NO_WRITE_ANCILLARY_CHUNKS
png_check_sig(sig, num) was replaced with
!png_sig_cmp(sig, 0, num) It has been deprecated since libpng-0.90.
png_set_gray_1_2_4_to_8() which also expands tRNS to alpha was replaced with
png_set_expand_gray_1_2_4_to_8() which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
IX. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
Private libpng prototypes and macro definitions were moved from png.h and pngconf.h into a new pngpriv.h header file.#define png_voidp_NULL (png_voidp)NULL were eliminated. If you used these in your application, just use NULL instead.
png_malloc(png_structp png_ptr, png_uint_32 size) to
png_malloc(png_structp png_ptr, png_alloc_size_t size)
X. Changes to Libpng from version 1.4.x to 1.5.x
From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the function) incorrectly returned a value of type png_uint_32.png_set_check_for_invalid_index(png_ptr, allowed);
allowed - one of
0: disable
1: enable
/* code that uses the inch conversion APIs. */ #endif
default safe
png_user_width_max 0x7fffffff 1,000,000
png_user_height_max 0x7fffffff 1,000,000
png_user_chunk_cache_max 0 (unlimited) 128
png_user_chunk_malloc_max 0 (unlimited) 8,000,000
XI. Detecting libpng
The png_get_io_ptr() function has been present since libpng-0.88, has never changed, and is unaffected by conditional compilation macros. It is the best choice for use in configure scripts for detecting the presence of any libpng version since 0.88. In an autoconf "configure.in" you could useAC_CHECK_LIB(png, png_get_io_ptr, ...
XII. Source code repository
Since about February 2009, version 1.2.34, libpng has been under "git" source control. The git repository was built from old libpng-x.y.z.tar.gz files going back to version 0.70. You can access the git repository (read only) atgit://libpng.git.sourceforge.net/gitroot/libpng
http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
http://libpng.sourceforge.net
XIII. Coding style
Our coding style is similar to the "Allman" style, with curly braces on separate lines:if (condition)
{
action;
}
else if (another condition)
{
another action;
}
if (condition)
return (0);
#ifndef PNG_NO_FEATURE
# ifndef PNG_FEATURE_SUPPORTED
# define PNG_FEATURE_SUPPORTED
# endif
#endif
/* Single-line comment */
statement;
/* This is a multiple-line
* comment.
*/
statement;
statement; /* comment */
/* This is a public function that is visible to
* application programmers. It does thus-and-so.
*/
void PNGAPI
png_exported_function(png_ptr, png_info, foo)
{
body;
}
/* Maintainer: Put new public prototypes here ... */
void /* PRIVATE */
png_non_exported_function(png_ptr, png_info, foo)
{
body;
}
/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
for (i = 2; i > 0; --i)
y[i] = a(x) + (int)b;
XIV. Y2K Compliance in libpng
September 27, 2012"png_uint_16 year" in png_time_struct.
"char time_buffer[29]" in png_struct. This will no longer be used in libpng-1.6.x and will be removed from libpng-1.7.0.
png_convert_to_rfc_1123() in png.c
(formerly png_convert_to_rfc_1152() in error)
png_convert_from_struct_tm() in pngwrite.c, called
in pngwrite.c
png_convert_from_time_t() in pngwrite.c
png_get_tIME() in pngget.c
png_handle_tIME() in pngrutil.c, called in pngread.c
png_set_tIME() in pngset.c
png_write_tIME() in pngwutil.c, called in pngwrite.c
Glenn Randers-Pehrson
libpng maintainer
PNG Development Group
NOTE
Note about libpng version numbers:source png.h png.h shared-lib
version string int version
------- ------ ----- ----------
0.89c ("beta 3") 0.89 89 1.0.89
0.90 ("beta 4") 0.90 90 0.90
0.95 ("beta 5") 0.95 95 0.95
0.96 ("beta 6") 0.96 96 0.96
0.97b ("beta 7") 1.00.97 97 1.0.1
0.97c 0.97 97 2.0.97
0.98 0.98 98 2.0.98
0.99 0.99 98 2.0.99
0.99a-m 0.99 99 2.0.99
1.00 1.00 100 2.1.0
1.0.0 1.0.0 100 2.1.0
1.0.0 (from here on, the 100 2.1.0
1.0.1 png.h string is 10001 2.1.0
1.0.1a-e identical to the 10002 from here on, the
1.0.2 source version) 10002 shared library is 2.V
1.0.2a-b 10003 where V is the source
1.0.1 10001 code version except as
1.0.1a-e 10002 2.1.0.1a-e noted.
1.0.2 10002 2.1.0.2
1.0.2a-b 10003 2.1.0.2a-b
1.0.3 10003 2.1.0.3
1.0.3a-d 10004 2.1.0.3a-d
1.0.4 10004 2.1.0.4
1.0.4a-f 10005 2.1.0.4a-f
1.0.5 (+ 2 patches) 10005 2.1.0.5
1.0.5a-d 10006 2.1.0.5a-d
1.0.5e-r 10100 2.1.0.5e-r
1.0.5s-v 10006 2.1.0.5s-v
1.0.6 (+ 3 patches) 10006 2.1.0.6
1.0.6d-g 10007 2.1.0.6d-g
1.0.6h 10007 10.6h
1.0.6i 10007 10.6i
1.0.6j 10007 2.1.0.6j
1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14
1.0.7beta15-18 1 10007 2.1.0.7beta15-18
1.0.7rc1-2 1 10007 2.1.0.7rc1-2
1.0.7 1 10007 2.1.0.7
1.0.8beta1-4 1 10008 2.1.0.8beta1-4
1.0.8rc1 1 10008 2.1.0.8rc1
1.0.8 1 10008 2.1.0.8
1.0.9beta1-6 1 10009 2.1.0.9beta1-6
1.0.9rc1 1 10009 2.1.0.9rc1
1.0.9beta7-10 1 10009 2.1.0.9beta7-10
1.0.9rc2 1 10009 2.1.0.9rc2
1.0.9 1 10009 2.1.0.9
1.0.10beta1 1 10010 2.1.0.10beta1
1.0.10rc1 1 10010 2.1.0.10rc1
1.0.10 1 10010 2.1.0.10
1.0.11beta1-3 1 10011 2.1.0.11beta1-3
1.0.11rc1 1 10011 2.1.0.11rc1
1.0.11 1 10011 2.1.0.11
1.0.12beta1-2 2 10012 2.1.0.12beta1-2
1.0.12rc1 2 10012 2.1.0.12rc1
1.0.12 2 10012 2.1.0.12
1.1.0a-f - 10100 2.1.1.0a-f abandoned
1.2.0beta1-2 2 10200 2.1.2.0beta1-2
1.2.0beta3-5 3 10200 3.1.2.0beta3-5
1.2.0rc1 3 10200 3.1.2.0rc1
1.2.0 3 10200 3.1.2.0
1.2.1beta-4 3 10201 3.1.2.1beta1-4
1.2.1rc1-2 3 10201 3.1.2.1rc1-2
1.2.1 3 10201 3.1.2.1
1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
1.0.13beta1 10 10013 10.so.0.1.0.13beta1
1.0.13rc1 10 10013 10.so.0.1.0.13rc1
1.2.2rc1 12 10202 12.so.0.1.2.2rc1
1.0.13 10 10013 10.so.0.1.0.13
1.2.2 12 10202 12.so.0.1.2.2
1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
1.2.3 12 10203 12.so.0.1.2.3
1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
1.2.4rc1 13 10204 12.so.0.1.2.4rc1
1.0.14 10 10014 10.so.0.1.0.14
1.2.4 13 10204 12.so.0.1.2.4
1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
1.0.15rc1 10 10015 10.so.0.1.0.15rc1
1.0.15 10 10015 10.so.0.1.0.15
1.2.5 13 10205 12.so.0.1.2.5
1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5
1.0.16 10 10016 10.so.0.1.0.16
1.2.6 13 10206 12.so.0.1.2.6
1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
1.0.17rc1 10 10017 12.so.0.1.0.17rc1
1.2.7rc1 13 10207 12.so.0.1.2.7rc1
1.0.17 10 10017 12.so.0.1.0.17
1.2.7 13 10207 12.so.0.1.2.7
1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5
1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
1.0.18 10 10018 12.so.0.1.0.18
1.2.8 13 10208 12.so.0.1.2.8
1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
1.2.9beta4-11 13 10209 12.so.0.9[.0]
1.2.9rc1 13 10209 12.so.0.9[.0]
1.2.9 13 10209 12.so.0.9[.0]
1.2.10beta1-7 13 10210 12.so.0.10[.0]
1.2.10rc1-2 13 10210 12.so.0.10[.0]
1.2.10 13 10210 12.so.0.10[.0]
1.4.0beta1-6 14 10400 14.so.0.0[.0]
1.2.11beta1-4 13 10210 12.so.0.11[.0]
1.4.0beta7-8 14 10400 14.so.0.0[.0]
1.2.11 13 10211 12.so.0.11[.0]
1.2.12 13 10212 12.so.0.12[.0]
1.4.0beta9-14 14 10400 14.so.0.0[.0]
1.2.13 13 10213 12.so.0.13[.0]
1.4.0beta15-36 14 10400 14.so.0.0[.0]
1.4.0beta37-87 14 10400 14.so.14.0[.0]
1.4.0rc01 14 10400 14.so.14.0[.0]
1.4.0beta88-109 14 10400 14.so.14.0[.0]
1.4.0rc02-08 14 10400 14.so.14.0[.0]
1.4.0 14 10400 14.so.14.0[.0]
1.4.1beta01-03 14 10401 14.so.14.1[.0]
1.4.1rc01 14 10401 14.so.14.1[.0]
1.4.1beta04-12 14 10401 14.so.14.1[.0]
1.4.1 14 10401 14.so.14.1[.0]
1.4.2 14 10402 14.so.14.2[.0]
1.4.3 14 10403 14.so.14.3[.0]
1.4.4 14 10404 14.so.14.4[.0]
1.5.0beta01-58 15 10500 15.so.15.0[.0]
1.5.0rc01-07 15 10500 15.so.15.0[.0]
1.5.0 15 10500 15.so.15.0[.0]
1.5.1beta01-11 15 10501 15.so.15.1[.0]
1.5.1rc01-02 15 10501 15.so.15.1[.0]
1.5.1 15 10501 15.so.15.1[.0]
1.5.2beta01-03 15 10502 15.so.15.2[.0]
1.5.2rc01-03 15 10502 15.so.15.2[.0]
1.5.2 15 10502 15.so.15.2[.0]
1.5.3beta01-10 15 10503 15.so.15.3[.0]
1.5.3rc01-02 15 10503 15.so.15.3[.0]
1.5.3beta11 15 10503 15.so.15.3[.0]
1.5.3 [omitted]
1.5.4beta01-08 15 10504 15.so.15.4[.0]
1.5.4rc01 15 10504 15.so.15.4[.0]
1.5.4 15 10504 15.so.15.4[.0]
1.5.5beta01-08 15 10505 15.so.15.5[.0]
1.5.5rc01 15 10505 15.so.15.5[.0]
1.5.5 15 10505 15.so.15.5[.0]
1.5.6beta01-07 15 10506 15.so.15.6[.0]
1.5.6rc01-03 15 10506 15.so.15.6[.0]
1.5.6 15 10506 15.so.15.6[.0]
1.5.7beta01-05 15 10507 15.so.15.7[.0]
1.5.7rc01-03 15 10507 15.so.15.7[.0]
1.5.7 15 10507 15.so.15.7[.0]
1.5.8beta01 15 10508 15.so.15.8[.0]
1.5.8rc01 15 10508 15.so.15.8[.0]
1.5.8 15 10508 15.so.15.8[.0]
1.5.9beta01-02 15 10509 15.so.15.9[.0]
1.5.9rc01 15 10509 15.so.15.9[.0]
1.5.9 15 10509 15.so.15.9[.0]
1.5.10beta01-05 15 10510 15.so.15.10[.0]
1.5.10 15 10510 15.so.15.10[.0]
1.5.11beta01 15 10511 15.so.15.11[.0]
1.5.11rc01-05 15 10511 15.so.15.11[.0]
1.5.11 15 10511 15.so.15.11[.0]
1.5.12 15 10512 15.so.15.12[.0]
1.5.13beta01-02 15 10513 15.so.15.13[.0]
1.5.13rc01 15 10513 15.so.15.13[.0]
1.5.13 15 10513 15.so.15.13[.0]
SEE ALSO
png(5), libpngpf(3), zlib(3), deflate(5), and zlib(5)-
http://libpng.sourceforge.net (follow the [DOWNLOAD] link) http://www.libpng.org/pub/png
-
(generally) at the same location as libpng or at
-
(generally) at the same location as libpng or at
AUTHORS
This man page: Glenn Randers-Pehrson <glennrp at users.sourceforge.net>COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
(This copy of the libpng notices is provided for your convenience. In case of any discrepancy between this copy and the notices in the file png.h that is included in the libpng distribution, the latter shall prevail.)Cosmin Truta
Simon-Pierre Cadieux
Eric S. Raymond
Gilles Vollant
There is no warranty against interference with your
enjoyment of the library or against infringement.
There is no warranty that our efforts or the library
will fulfill any of your particular purposes or needs.
This library is provided with all faults, and the entire
risk of satisfactory quality, performance, accuracy, and
effort is with the user.
Tom Lane
Glenn Randers-Pehrson
Willem van Schaik
John Bowler
Kevin Bracey
Sam Bushell
Magnus Holmgren
Greg Roelofs
Tom Tanner
Andreas Dilger
Dave Martindale
Guy Eric Schalnat
Paul Schmidt
Tim Wegner
must not be misrepresented as being the original source.
any source or altered source distribution.
printf("%s",png_get_copyright(NULL));
September 27, 2012 |