libpng (3) - Linux Manuals
libpng: Portable Network Graphics (PNG) Reference Library 1.5.13
NAME
libpng - Portable Network Graphics (PNG) Reference Library 1.5.13SYNOPSIS
#include <png.h>
png_uint_32 png_access_version_number (void);
void png_benign_error (png_structp png_ptr, png_const_charp error);
void png_build_grayscale_palette (int bit_depth, png_colorp palette);
png_voidp png_calloc (png_structp png_ptr, png_alloc_size_t size);
void png_chunk_benign_error (png_structp png_ptr, png_const_charp error);
void png_chunk_error (png_structp png_ptr, png_const_charp error);
void png_chunk_warning (png_structp png_ptr, png_const_charp message);
void png_convert_from_struct_tm (png_timep ptime, struct tm FAR * ttime);
void png_convert_from_time_t (png_timep ptime, time_t ttime);
png_charp png_convert_to_rfc1123 (png_structp png_ptr, png_timep ptime);
png_infop png_create_info_struct (png_structp png_ptr);
png_structp png_create_read_struct (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn);
png_structp png_create_read_struct_2 (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn);
png_structp png_create_write_struct (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn);
png_structp png_create_write_struct_2 (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn);
void png_data_freer (png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask));
void png_destroy_info_struct (png_structp png_ptr, png_infopp info_ptr_ptr);
void png_destroy_read_struct (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
void png_destroy_write_struct (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr);
void png_err (png_structp png_ptr);
void png_error (png_structp png_ptr, png_const_charp error);
void png_free (png_structp png_ptr, png_voidp ptr);
void png_free_chunk_list (png_structp png_ptr);
void png_free_default (png_structp png_ptr, png_voidp ptr);
void png_free_data (png_structp png_ptr, png_infop info_ptr, int num);
png_byte png_get_bit_depth (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_bKGD (png_const_structp png_ptr, png_infop info_ptr, png_color_16p *background);
png_byte png_get_channels (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_cHRM (png_const_structp png_ptr, png_const_infop info_ptr, double *white_x, double *white_y, double *red_x, double *red_y, double *green_x, double *green_y, double *blue_x, double *blue_y);
png_uint_32 png_get_cHRM_fixed (png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 *white_x, png_uint_32 *white_y, png_uint_32 *red_x, png_uint_32 *red_y, png_uint_32 *green_x, png_uint_32 *green_y, png_uint_32 *blue_x, png_uint_32 *blue_y);
png_uint_32 png_get_cHRM_XYZ (png_structp png_ptr,
png_const_infop info_ptr, double *red_X, double *red_Y, double *red_Z,
double *green_X, double *green_Y, double *green_Z, double *blue_X,
double *blue_Y, double *blue_Z);
png_uint_32 png_get_cHRM_XYZ_fixed (png_structp png_ptr, png_const_infop info_ptr, png_fixed_point *int_red_X, png_fixed_point *int_red_Y, png_fixed_point *int_red_Z, png_fixed_point *int_green_X, png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, png_fixed_point *int_blue_Z);
png_uint_32 png_get_chunk_cache_max (png_const_structp png_ptr);
png_alloc_size_t png_get_chunk_malloc_max (png_const_structp png_ptr);
png_byte png_get_color_type (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_compression_buffer_size (png_const_structp png_ptr);
png_byte png_get_compression_type (png_const_structp png_ptr, png_const_infop info_ptr);
png_byte png_get_copyright (png_const_structp png_ptr);
png_uint_32 png_get_current_row_number (png_const_structp);
png_byte png_get_current_pass_number (png_const_structp);
png_voidp png_get_error_ptr (png_const_structp png_ptr);
png_byte png_get_filter_type (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_gAMA (png_const_structp png_ptr, png_const_infop info_ptr, double *file_gamma);
png_uint_32 png_get_gAMA_fixed (png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 *int_file_gamma);
png_byte png_get_header_ver (png_const_structp png_ptr);
png_byte png_get_header_version (png_const_structp png_ptr);
png_uint_32 png_get_hIST (png_const_structp png_ptr, png_const_infop info_ptr, png_uint_16p *hist);
png_uint_32 png_get_iCCP (png_const_structp png_ptr, png_const_infop info_ptr, png_charpp name, int *compression_type, png_bytepp profile, png_uint_32 *proflen);
png_uint_32 png_get_IHDR (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_type, int *compression_type, int *filter_type);
png_uint_32 png_get_image_height (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_image_width (png_const_structp png_ptr, png_const_infop info_ptr);
png_int_32 png_get_int_32 (png_bytep buf);
png_byte png_get_interlace_type (png_const_structp png_ptr, png_const_infop info_ptr);
png_const_bytep png_get_io_chunk_name (png_structp png_ptr);
png_uint_32 png_get_io_chunk_type (png_const_structp png_ptr);
png_voidp png_get_io_ptr (png_structp png_ptr);
png_uint_32 png_get_io_state (png_structp png_ptr);
png_byte png_get_libpng_ver (png_const_structp png_ptr);
png_voidp png_get_mem_ptr (png_const_structp png_ptr);
png_uint_32 png_get_oFFs (png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 *offset_x, png_uint_32 *offset_y, int *unit_type);
png_uint_32 png_get_pCAL (png_const_structp png_ptr, png_const_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, png_charp *units, png_charpp *params);
png_uint_32 png_get_pHYs (png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type);
float png_get_pixel_aspect_ratio (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_pHYs_dpi (png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type);
png_fixed_point png_get_pixel_aspect_ratio_fixed (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_pixels_per_inch (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_pixels_per_meter (png_const_structp png_ptr, png_const_infop info_ptr);
png_voidp png_get_progressive_ptr (png_const_structp png_ptr);
png_uint_32 png_get_PLTE (png_const_structp png_ptr, png_const_infop info_ptr, png_colorp *palette, int *num_palette);
png_byte png_get_rgb_to_gray_status (png_const_structp png_ptr)
png_uint_32 png_get_rowbytes (png_const_structp png_ptr, png_const_infop info_ptr);
png_bytepp png_get_rows (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_sBIT (png_const_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit);
void png_get_sCAL (png_const_structp png_ptr, png_const_infop info_ptr, int* unit, double* width, double* height);
void png_get_sCAL_fixed (png_const_structp png_ptr, png_const_infop info_ptr, int* unit, png_fixed_pointp width, png_fixed_pointp height);
void png_get_sCAL_s (png_const_structp png_ptr, png_const_infop info_ptr, int* unit, png_charpp width, png_charpp height);
png_bytep png_get_signature (png_const_structp png_ptr, png_infop info_ptr);
png_uint_32 png_get_sPLT (png_const_structp png_ptr, png_const_infop info_ptr, png_spalette_p *splt_ptr);
png_uint_32 png_get_sRGB (png_const_structp png_ptr, png_const_infop info_ptr, int *file_srgb_intent);
png_uint_32 png_get_text (png_const_structp png_ptr, png_const_infop info_ptr, png_textp *text_ptr, int *num_text);
png_uint_32 png_get_tIME (png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time);
png_uint_32 png_get_tRNS (png_const_structp png_ptr, png_infop info_ptr, png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color);
/* This function is really an inline macro. */
png_uint_16 png_get_uint_16 (png_bytep buf);
png_uint_32 png_get_uint_31 (png_structp png_ptr, png_bytep buf);
/* This function is really an inline macro. */
png_uint_32 png_get_uint_32 (png_bytep buf);
png_uint_32 png_get_unknown_chunks (png_const_structp png_ptr, png_const_infop info_ptr, png_unknown_chunkpp unknowns);
png_voidp png_get_user_chunk_ptr (png_const_structp png_ptr);
png_uint_32 png_get_user_height_max (png_const_structp png_ptr);
png_voidp png_get_user_transform_ptr (png_const_structp png_ptr);
png_uint_32 png_get_user_width_max (png_const_structp png_ptr);
png_uint_32 png_get_valid (png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 flag);
float png_get_x_offset_inches (png_const_structp png_ptr, png_const_infop info_ptr);
png_fixed_point png_get_x_offset_inches_fixed (png_structp png_ptr, png_const_infop info_ptr);
png_int_32 png_get_x_offset_microns (png_const_structp png_ptr, png_const_infop info_ptr);
png_int_32 png_get_x_offset_pixels (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_x_pixels_per_inch (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_x_pixels_per_meter (png_const_structp png_ptr, png_const_infop info_ptr);
float png_get_y_offset_inches (png_const_structp png_ptr, png_const_infop info_ptr);
png_fixed_point png_get_y_offset_inches_fixed (png_structp png_ptr, png_const_infop info_ptr);
png_int_32 png_get_y_offset_microns (png_const_structp png_ptr, png_const_infop info_ptr);
png_int_32 png_get_y_offset_pixels (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_y_pixels_per_inch (png_const_structp png_ptr, png_const_infop info_ptr);
png_uint_32 png_get_y_pixels_per_meter (png_const_structp png_ptr, png_const_infop info_ptr);
int png_handle_as_unknown (png_structp png_ptr, png_bytep chunk_name);
void png_info_init_3 (png_infopp info_ptr, png_size_t png_info_struct_size);
void png_init_io (png_structp png_ptr, FILE *fp);
void png_longjmp (png_structp png_ptr, int val);
png_voidp png_malloc (png_structp png_ptr, png_alloc_size_t size);
png_voidp png_malloc_default (png_structp png_ptr, png_alloc_size_t size);
png_voidp png_malloc_warn (png_structp png_ptr, png_alloc_size_t size);
png_uint_32 png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features_permitted);
void png_process_data (png_structp png_ptr, png_infop info_ptr, png_bytep buffer, png_size_t buffer_size);
png_size_t png_process_data_pause (png_structp, int save);
png_uint_32 png_process_data_skip (png_structp);
void png_progressive_combine_row (png_structp png_ptr, png_bytep old_row, png_bytep new_row);
void png_read_end (png_structp png_ptr, png_infop info_ptr);
void png_read_image (png_structp png_ptr, png_bytepp image);
void png_read_info (png_structp png_ptr, png_infop info_ptr);
void png_read_png (png_structp png_ptr, png_infop info_ptr, int transforms, png_voidp params);
void png_read_row (png_structp png_ptr, png_bytep row, png_bytep display_row);
void png_read_rows (png_structp png_ptr, png_bytepp row, png_bytepp display_row, png_uint_32 num_rows);
void png_read_update_info (png_structp png_ptr, png_infop info_ptr);
int png_reset_zstream (png_structp png_ptr);
void png_save_int_32 (png_bytep buf, png_int_32 i);
void png_save_uint_16 (png_bytep buf, unsigned int i);
void png_save_uint_32 (png_bytep buf, png_uint_32 i);
void png_set_add_alpha (png_structp png_ptr, png_uint_32 filler, int flags);
void png_set_alpha_mode (png_structp png_ptr, int mode, double output_gamma);
void png_set_alpha_mode_fixed (png_structp png_ptr, int mode, png_fixed_point output_gamma);
void png_set_background (png_structp png_ptr, png_color_16p background_color, int background_gamma_code, int need_expand, double background_gamma);
void png_set_background_fixed (png_structp png_ptr, png_color_16p background_color, int background_gamma_code, int need_expand, png_uint_32 background_gamma);
void png_set_benign_errors (png_structp png_ptr, int allowed);
void png_set_bgr (png_structp png_ptr);
void png_set_bKGD (png_structp png_ptr, png_infop info_ptr, png_color_16p background);
void png_set_check_for_invalid_index(png_structrp png_ptr, int allowed);
void png_set_cHRM (png_structp png_ptr, png_infop info_ptr, double white_x, double white_y, double red_x, double red_y, double green_x, double green_y, double blue_x, double blue_y);
void png_set_cHRM_fixed (png_structp png_ptr, png_infop info_ptr, png_uint_32 white_x, png_uint_32 white_y, png_uint_32 red_x, png_uint_32 red_y, png_uint_32 green_x, png_uint_32 green_y, png_uint_32 blue_x, png_uint_32 blue_y);
void png_set_cHRM_XYZ (png_structp png_ptr, png_infop info_ptr, double red_X, double red_Y, double red_Z, double green_X, double green_Y,
double green_Z, double blue_X, double blue_Y, double blue_Z);
void png_set_cHRM_XYZ_fixed (png_structp png_ptr, png_infop info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y, png_fixed_point int_red_Z, png_fixed_point int_green_X, png_fixed_point int_green_Y, png_fixed_point int_green_Z, png_fixed_point int_blue_X, png_fixed_point int_blue_Y, png_fixed_point int_blue_Z);
void png_set_chunk_cache_max (png_structp png_ptr, png_uint_32 user_chunk_cache_max);
void png_set_compression_level (png_structp png_ptr, int level);
void png_set_compression_mem_level (png_structp png_ptr, int mem_level);
void png_set_compression_method (png_structp png_ptr, int method);
void png_set_compression_strategy (png_structp png_ptr, int strategy);
void png_set_compression_window_bits (png_structp png_ptr, int window_bits);
void png_set_crc_action (png_structp png_ptr, int crit_action, int ancil_action);
void png_set_error_fn (png_structp png_ptr, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn);
void png_set_expand (png_structp png_ptr);
void png_set_expand_16 (png_structp png_ptr);
void png_set_expand_gray_1_2_4_to_8 (png_structp png_ptr);
void png_set_filler (png_structp png_ptr, png_uint_32 filler, int flags);
void png_set_filter (png_structp png_ptr, int method, int filters);
void png_set_filter_heuristics (png_structp png_ptr, int heuristic_method, int num_weights, png_doublep filter_weights, png_doublep filter_costs);
void png_set_filter_heuristics_fixed (png_structp png_ptr, int heuristic_method, int num_weights, png_fixed_point_p filter_weights, png_fixed_point_p filter_costs);
void png_set_flush (png_structp png_ptr, int nrows);
void png_set_gamma (png_structp png_ptr, double screen_gamma, double default_file_gamma);
void png_set_gamma_fixed (png_structp png_ptr, png_uint_32 screen_gamma, png_uint_32 default_file_gamma);
void png_set_gAMA (png_structp png_ptr, png_infop info_ptr, double file_gamma);
void png_set_gAMA_fixed (png_structp png_ptr, png_infop info_ptr, png_uint_32 file_gamma);
void png_set_gray_1_2_4_to_8 (png_structp png_ptr);
void png_set_gray_to_rgb (png_structp png_ptr);
void png_set_hIST (png_structp png_ptr, png_infop info_ptr, png_uint_16p hist);
void png_set_iCCP (png_structp png_ptr, png_infop info_ptr, png_const_charp name, int compression_type, png_const_bytep profile, png_uint_32 proflen);
int png_set_interlace_handling (png_structp png_ptr);
void png_set_invalid (png_structp png_ptr, png_infop info_ptr, int mask);
void png_set_invert_alpha (png_structp png_ptr);
void png_set_invert_mono (png_structp png_ptr);
void png_set_IHDR (png_structp png_ptr, png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, int filter_type);
void png_set_keep_unknown_chunks (png_structp png_ptr, int keep, png_bytep chunk_list, int num_chunks);
jmp_buf* png_set_longjmp_fn (png_structp png_ptr, png_longjmp_ptr longjmp_fn, size_t jmp_buf_size);
void png_set_chunk_malloc_max (png_structp png_ptr, png_alloc_size_t user_chunk_cache_max);
void png_set_compression_buffer_size (png_structp png_ptr, png_uint_32 size);
void png_set_mem_fn (png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn);
void png_set_oFFs (png_structp png_ptr, png_infop info_ptr, png_uint_32 offset_x, png_uint_32 offset_y, int unit_type);
void png_set_packing (png_structp png_ptr);
void png_set_packswap (png_structp png_ptr);
void png_set_palette_to_rgb (png_structp png_ptr);
void png_set_pCAL (png_structp png_ptr, png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_charp units, png_charpp params);
void png_set_pHYs (png_structp png_ptr, png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type);
void png_set_progressive_read_fn (png_structp png_ptr, png_voidp progressive_ptr, png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn);
void png_set_PLTE (png_structp png_ptr, png_infop info_ptr, png_colorp palette, int num_palette);
void png_set_quantize (png_structp png_ptr, png_colorp palette, int num_palette, int maximum_colors, png_uint_16p histogram, int full_quantize);
void png_set_read_fn (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn);
void png_set_read_status_fn (png_structp png_ptr, png_read_status_ptr read_row_fn);
void png_set_read_user_chunk_fn (png_structp png_ptr, png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn);
void png_set_read_user_transform_fn (png_structp png_ptr, png_user_transform_ptr read_user_transform_fn);
void png_set_rgb_to_gray (png_structp png_ptr, int error_action, double red, double green);
void png_set_rgb_to_gray_fixed (png_structp png_ptr, int error_action png_uint_32 red, png_uint_32 green);
void png_set_rows (png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers);
void png_set_sBIT (png_structp png_ptr, png_infop info_ptr, png_color_8p sig_bit);
void png_set_sCAL (png_structp png_ptr, png_infop info_ptr, int unit, double width, double height);
void png_set_sCAL_fixed (png_structp png_ptr, png_infop info_ptr, int unit, png_fixed_point width, png_fixed_point height);
void png_set_sCAL_s (png_structp png_ptr, png_infop info_ptr, int unit, png_charp width, png_charp height);
void png_set_scale_16 (png_structp png_ptr);
void png_set_shift (png_structp png_ptr, png_color_8p true_bits);
void png_set_sig_bytes (png_structp png_ptr, int num_bytes);
void png_set_sPLT (png_structp png_ptr, png_infop info_ptr, png_spalette_p splt_ptr, int num_spalettes);
void png_set_sRGB (png_structp png_ptr, png_infop info_ptr, int srgb_intent);
void png_set_sRGB_gAMA_and_cHRM (png_structp png_ptr, png_infop info_ptr, int srgb_intent);
void png_set_strip_16 (png_structp png_ptr);
void png_set_strip_alpha (png_structp png_ptr);
void png_set_strip_error_numbers (png_structp png_ptr, png_uint_32 strip_mode);
void png_set_swap (png_structp png_ptr);
void png_set_swap_alpha (png_structp png_ptr);
void png_set_text (png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, int num_text);
void png_set_text_compression_level (png_structp png_ptr, int level);
void png_set_text_compression_mem_level (png_structp png_ptr, int mem_level);
void png_set_text_compression_strategy (png_structp png_ptr, int strategy);
void png_set_text_compression_window_bits (png_structp png_ptr, int window_bits);
void png_set_text_compression_method, (png_structp png_ptr, int method));
void png_set_tIME (png_structp png_ptr, png_infop info_ptr, png_timep mod_time);
void png_set_tRNS (png_structp png_ptr, png_infop info_ptr, png_bytep trans_alpha, int num_trans, png_color_16p trans_color);
void png_set_tRNS_to_alpha (png_structp png_ptr);
png_uint_32 png_set_unknown_chunks (png_structp png_ptr, png_infop info_ptr, png_unknown_chunkp unknowns, int num, int location);
void png_set_unknown_chunk_location (png_structp png_ptr, png_infop info_ptr, int chunk, int location);
void png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max);
void png_set_user_transform_info (png_structp png_ptr, png_voidp user_transform_ptr, int user_transform_depth, int user_transform_channels);
void png_set_write_fn (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn);
void png_set_write_status_fn (png_structp png_ptr, png_write_status_ptr write_row_fn);
void png_set_write_user_transform_fn (png_structp png_ptr, png_user_transform_ptr write_user_transform_fn);
int png_sig_cmp (png_bytep sig, png_size_t start, png_size_t num_to_check);
void png_start_read_image (png_structp png_ptr);
void png_warning (png_structp png_ptr, png_const_charp message);
void png_write_chunk (png_structp png_ptr, png_bytep chunk_name, png_bytep data, png_size_t length);
void png_write_chunk_data (png_structp png_ptr, png_bytep data, png_size_t length);
void png_write_chunk_end (png_structp png_ptr);
void png_write_chunk_start (png_structp png_ptr, png_bytep chunk_name, png_uint_32 length);
void png_write_end (png_structp png_ptr, png_infop info_ptr);
void png_write_flush (png_structp png_ptr);
void png_write_image (png_structp png_ptr, png_bytepp image);
void png_write_info (png_structp png_ptr, png_infop info_ptr);
void png_write_info_before_PLTE (png_structp png_ptr, png_infop info_ptr);
void png_write_png (png_structp png_ptr, png_infop info_ptr, int transforms, png_voidp params);
void png_write_row (png_structp png_ptr, png_bytep row);
void png_write_rows (png_structp png_ptr, png_bytepp row, png_uint_32 num_rows);
void png_write_sig (png_structp png_ptr);
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 libpng
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.
For examples of libpng usage, see the files "example.c", "pngtest.c", and the files in the "contrib" directory, all of which are included in the libpng distribution.
Libpng was written as a companion to the PNG specification, as a way of reducing the amount of time and effort it takes to support the PNG file format in application programs.
The PNG specification (second edition), November 2003, is available as a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at <http://www.w3.org/TR/2003/REC-PNG-20031110/ The W3C and ISO documents have identical technical content.
The PNG-1.2 specification is available at <http://www.libpng.org/pub/png/documents/>. It is technically equivalent to the PNG specification (second edition) but has some additional material.
The PNG-1.0 specification is available as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
Some additional chunks are described in the special-purpose public chunks documents at <http://www.libpng.org/pub/png/documents/>.
Other information about PNG, and the latest version of libpng, can be found at the PNG home page, <http://www.libpng.org/pub/png/>.
Most users will not have to modify the library significantly; advanced users may want to modify it more. All attempts were made to make it as complete as possible, while keeping the code easy to understand. Currently, this library only supports C. Support for other languages is being considered.
Libpng has been designed to handle multiple sessions at one time, to be easily modifiable, to be portable to the vast majority of 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 its users.
Libpng uses zlib for its compression and decompression of PNG files. Further information about zlib, and the latest version of zlib, can be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>. 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 png_struct and png_info instances, and thus its own image. Libpng does not protect itself against two threads using the same instance of a structure.
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).
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 (the png_get_*() and png_set_*() functions) was developed, and direct access to the png_info fields was deprecated..
The png_struct structure is the object used by the library to decode a single image. As of 1.5.0 this structure is also not exposed.
Almost all libpng APIs require a pointer to a png_struct as the first argument. Many (in particular the png_set and png_get APIs) also require a pointer to png_info as the second argument. Some application visible macros defined in png.h designed for basic data access (reading and writing integers in the PNG format) don't take a png_info pointer, but it's almost always safe to assume that a (png_struct*) has to be passed to call an API function.
You can have more than one png_info structure associated with an image, as illustrated in pngtest.c, one for information valid prior to the IDAT chunks and another (called "end_info" below) for things after them.
The png.h header file is an invaluable reference for programming with libpng. And while I'm on the topic, make sure you include the libpng header file:
#include <png.h>
and also (as of libpng-1.5.0) the zlib header file, if you need it:
#include <zlib.h>
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.
One exception is how non-integral numbers are handled. For application convenience most APIs that take such numbers have C (double) arguments; however, internally PNG, and libpng, use 32 bit signed integers and encode the value by multiplying by 100,000. As of libpng 1.5.0 a convenience macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point) which is simply (png_int_32).
All APIs that take (double) arguments also have a matching API that takes the corresponding fixed point integer arguments. The fixed point API has the same name as the floating point one with "_fixed" appended. The actual range of values permitted in the APIs is frequently less than the full range of (png_fixed_point) (-21474 to +21474). When APIs require a non-negative argument the type is recorded as png_uint_32 above. Consult the header file and the text below for more information.
Special care must be take with sCAL chunk handling because the chunk itself uses non-integral values encoded as strings containing decimal floating point numbers. See the comments in the header file.
Configuration
The main header file function declarations are frequently protected by C preprocessing directives of the form:
The library can be built without support for these APIs, although a standard build will have all implemented APIs. Application programs should check the feature macros before using an API for maximum portability. From libpng 1.5.0 the feature macros set during the build of libpng are recorded in the header file "pnglibconf.h" and this file is always included by png.h.
If you don't need to change the library configuration from the default, skip to the next section ("Reading").
Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all of the build project files in the 'projects' directory simply copy scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build systems do not permit easy auto-configuration of the library - they only support the default configuration.
The easiest way to make minor changes to the libpng configuration when auto-configuration is supported is to add definitions to the command line using (typically) CPPFLAGS. For example:
CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC
will change the internal libpng math implementation for gamma correction and other arithmetic calculations to fixed point, avoiding the need for fast floating point support. The result can be seen in the generated pnglibconf.h - make sure it contains the changed feature macro setting.
If you need to make more extensive configuration changes - more than one or two feature macro settings - you can either add -DPNG_USER_CONFIG to the build command line and put a list of feature macro settings in pngusr.h or you can set DFA_XTRA (a makefile variable) to a file containing the same information in the form of 'option' settings.
A. Changing pnglibconf.h
A variety of methods exist to build libpng. Not all of these support reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand.
Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to pnglibconf.h and changing the lines defining the supported features, paying very close attention to the 'option' information in scripts/pnglibconf.dfa that describes those features and their requirements. This is easy to get wrong.
B. Configuration using DFA_XTRA
Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later variant such as 'nawk' or 'gawk', is available. The configure build will automatically find an appropriate awk and build pnglibconf.h. The scripts/pnglibconf.mak file contains a set of make rules for doing the same thing if configure is not used, and many of the makefiles in the scripts directory use this approach.
When rebuilding simply write a new file containing changed options and set DFA_XTRA to the name of this file. This causes the build to append the new file to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines of the following forms:
everything = off
This turns all optional features off. Include it at the start of pngusr.dfa to make it easier to build a minimal configuration. You will need to turn at least some features on afterward to enable either reading or writing code, or both.
option feature on option feature off
Enable or disable a single feature. This will automatically enable other features required by a feature that is turned on or disable other features that require a feature which is turned off. Conflicting settings will cause an error message to be emitted by awk.
setting feature default value
Changes the default value of setting 'feature' to 'value'. There are a small number of settings listed at the top of pnglibconf.h, they are documented in the source code. Most of these values have performance implications for the library but most of them have no visible effect on the API. Some can also be overridden from the API.
This method of building a customized pnglibconf.h is illustrated in contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and pngusr.dfa in these directories.
C. Configuration using PNG_USR_CONFIG
If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file pngusr.h will automatically be included before the options in scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only macro definitions turning features on or off or setting settings.
Apart from the global setting "everything = off" all the options listed above can be set using macros in pngusr.h:
#define PNG_feature_SUPPORTED
is equivalent to:
option feature on
#define PNG_NO_feature
is equivalent to:
option feature off
#define PNG_feature value
is equivalent to:
setting feature default value
Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the pngusr file you supply override the contents of scripts/pnglibconf.dfa
If confusing or incomprehensible behavior results it is possible to examine the intermediate file pnglibconf.dfn to find the full set of dependency information for each setting and option. Simply locate the feature in the file and read the C comments that precede it.
This method is also illustrated in the contrib/pngminim/* makefiles and pngusr.h.
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.
If you are intending to keep the file pointer open for use in libpng, you must ensure you don't read more than 8 bytes from the beginning of the file, and you also have to make a call to png_set_sig_bytes_read() with the number of bytes you read from the beginning. Libpng will then only check the bytes (if any) that your program didn't read.
(*): If you are not using the standard I/O functions, you will need to replace them with custom functions. See the discussion under Customizing libpng.
Next, png_struct and png_info need to be allocated and initialized. In order to ensure that the size of these structures is correct even with a dynamically linked libpng, there are functions to initialize and allocate the structures. We also pass the library version, optional pointers to error handling functions, and a pointer to a data struct for use by the error functions, if necessary (the pointer and functions can be NULL if the default error handlers are to be used). See the section on Changes to Libpng below regarding the old initialization functions. The structure allocation functions quietly return NULL if they fail to create the structure, so your application should check for that.
If you want to use your own memory allocation routines, use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use png_create_read_struct_2() instead of png_create_read_struct():
The error handling routines passed to png_create_read_struct() and the memory alloc/free routines passed to png_create_struct_2() are only necessary if you are not using the libpng supplied error handling and memory alloc/free functions.
When libpng encounters an error, it expects to longjmp back to your routine. Therefore, you will need to call setjmp and pass your png_jmpbuf(png_ptr). If you read the file from different routines, you will need to update the longjmp buffer every time you enter a new routine that will call a png_*() function.
See your documentation of setjmp/longjmp for your compiler for more information on setjmp/longjmp. See the discussion on libpng error handling in the Customizing Libpng section below for more information on the libpng error handling. If an error occurs, and libpng longjmp's back to your setjmp, you will want to call png_destroy_read_struct() to free any memory.
Pass (png_infopp)NULL instead of &end_info if you didn't create an end_info structure.
If you would rather avoid the complexity of setjmp/longjmp issues, you can compile libpng with PNG_NO_SETJMP, in which case errors will result in a call to PNG_ABORT() which defaults to abort().
You can #define PNG_ABORT() to a function that does something more useful than abort(), as long as your function does not return.
Now you need to set up the input code. The default for libpng is to use the C function fread(). If you use this, you will need to pass a valid FILE * in the function png_init_io(). Be sure that the file is opened in binary mode. If you wish to handle reading data in another way, you need not call the png_init_io() function, but you must then implement the libpng I/O methods discussed in the Customizing Libpng section below.
If you had previously opened the file and read any of the signature from the beginning in order to see if this was a PNG file, you need to let libpng know that there are some bytes missing from the start of the file.
You can change the zlib compression buffer size to be used while reading compressed data with
where the default size is 8192 bytes. Note that the buffer size is changed immediately and the buffer is reallocated immediately, instead of setting a flag to be acted upon later.
If you want CRC errors to be handled in a different manner than the default, use
The values for png_set_crc_action() say how libpng is to handle CRC errors in ancillary and critical chunks, and whether to use the data contained therein. Note that it is impossible to "discard" data in a critical chunk.
Choices for (int) crit_action are
PNG_CRC_DEFAULT
PNG_CRC_ERROR_QUIT
PNG_CRC_WARN_USE
PNG_CRC_QUIET_USE
PNG_CRC_NO_CHANGE
Choices for (int) ancil_action are
PNG_CRC_DEFAULT
PNG_CRC_ERROR_QUIT
PNG_CRC_WARN_DISCARD 2
PNG_CRC_WARN_USE
PNG_CRC_QUIET_USE
PNG_CRC_NO_CHANGE
Setting up callback code
You can set up a callback function to handle any unknown chunks in the input stream. You must supply the function
(You can give your function another name that you like instead of "read_chunk_callback")
To inform libpng about your function, use
This names not only the callback function, but also a user pointer that you can retrieve with
If you call the png_set_read_user_chunk_fn() function, then all unknown chunks will be saved when read, in case your callback function will need one or more of them. This behavior can be changed with the png_set_keep_unknown_chunks() function, described below.
At this point, you can set up a callback function that will be called after each row has been read, which you can use to control a progress meter or the like. It's demonstrated in pngtest.c. You must supply a function
/*
(You can give it another name that you like instead of "read_row_callback")
To inform libpng about your function, use
When this function is called the row has already been completely processed and the 'row' and 'pass' refer to the next row to be handled. For the non-interlaced case the row that was just handled is simply one less than the passed in row number, and pass will always be 0. For the interlaced case the same applies unless the row value is 0, in which case the row just handled was the last one from one of the preceding passes. Because interlacing may skip a pass you cannot be sure that the preceding pass is just 'pass-1', if you really need to know what the last pass is record (row,pass) from the callback and use the last recorded value each time.
As with the user transform you can find the output row using the PNG_ROW_FROM_PASS_ROW macro.
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:
Unknown chunks declared in this way will be saved as raw data onto a list of png_unknown_chunk structures. If a chunk that is normally known to libpng is named in the list, it will be handled as unknown, according to the "keep" directive. If a chunk is named in successive instances of png_set_keep_unknown_chunks(), the final instance will take precedence. The IHDR and IEND chunks should not be named in chunk_list; if they are, libpng will process them normally anyway. If you know that your application will never make use of some particular chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below.
Here is an example of the usage of png_set_keep_unknown_chunks(), where the private "vpAg" chunk will later be processed by a user chunk callback function:
png_byte unused_chunks[]=
{
};
/*
png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
/*
png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
/*
png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
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 use
png_set_user_limits(png_ptr, width_max, height_max);
to set your own limits, or use width_max = height_max = 0x7fffffffL to allow all valid dimensions (libpng may reject some very large images anyway because of potential buffer overflow conditions).
You should put this statement after you create the PNG structure and before calling png_read_info(), png_read_png(), or png_process_data().
When writing a PNG datastream, put this statement before calling png_write_info() or png_write_png().
If you need to retrieve the limits that are being applied, use
width_max
height_max
The PNG specification sets no limit on the number of ancillary chunks allowed in a PNG datastream. You can impose a limit on the total number of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
where 0x7fffffffL means unlimited. You can retrieve this limit with
chunk_cache_max
This limit also applies to the number of buffers that can be allocated by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
You can also set a limit on the amount of memory that a compressed chunk other than IDAT can occupy, with
png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
and you can retrieve the limit with
chunk_malloc_max
Any chunks that would cause either of these limits to be exceeded will be ignored.
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.
From libpng-1.5.4 this information can be set before reading the PNG file header. In earlier versions png_set_gamma() existed but behaved incorrectly if called before the PNG file header had been read and png_set_alpha_mode() did not exist.
If you need to support versions prior to libpng-1.5.4 test the version number as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures described in the appropriate manual page.
You give libpng the encoding expected by your system expressed as a 'gamma' value. You can also specify a default encoding for the PNG file in case the required information is missing from the file. By default libpng assumes that the PNG data matches your system, to keep this default call:
png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/);
or you can use the fixed point equivalent:
png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma, PNG_FP_1/screen_gamma);
If you don't know the gamma for your system it is probably 2.2 - a good approximation to the IEC standard for display systems (sRGB). If images are too contrasty or washed out you got the value wrong - check your system documentation!
Many systems permit the system gamma to be changed via a lookup table in the display driver, a few systems, including older Macs, change the response by default. As of 1.5.4 three special values are available to handle common situations:
PNG_DEFAULT_sRGB: Indicates that the system conforms to the IEC 61966-2-1
PNG_GAMMA_MAC_18: Indicates that the system is an older
PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates that the
You would use the linear (unencoded) value if you need to process the pixel values further because this avoids the need to decode and reencode each component value whenever arithmetic is performed. A lot of graphics software uses linear values for this reason, often with higher precision component values to preserve overall accuracy.
The second thing you may need to tell libpng about is how your system handles alpha channel information. Some, but not all, PNG files contain an alpha channel. To display these files correctly you need to compose the data onto a suitable background, as described in the PNG specification.
Libpng only supports composing onto a single color (using png_set_background; see below). Otherwise you must do the composition yourself and, in this case, you may need to call png_set_alpha_mode:
The screen_gamma value is the same as the argument to png_set_gamma; however, how it affects the output depends on the mode. png_set_alpha_mode() sets the file gamma default to 1/screen_gamma, so normally you don't need to call png_set_gamma. If you need different defaults call png_set_gamma() before png_set_alpha_mode() - if you call it after it will override the settings made by png_set_alpha_mode().
The mode is as follows:
You should normally use this format if you intend to perform color correction on the color values; most, maybe all, color correction software has no handling for the alpha channel and, anyway, the math to handle pre-multiplied component values is unnecessarily complex.
Before you do any arithmetic on the component values you need to remove the gamma encoding and multiply out the alpha channel. See the PNG specification for more detail. It is important to note that when an image with an alpha channel is scaled, linear encoded, pre-multiplied component values must be used!
The remaining modes assume you don't need to do any further color correction or that if you do, your color correction software knows all about alpha (it probably doesn't!)
With this format the final image must be re-encoded to match the display gamma before the image is displayed. If your system doesn't do that, yet still seems to perform arithmetic on the pixels without decoding them, it is broken - check out the modes below.
With PNG_ALPHA_STANDARD libpng always produces linear component values, whatever screen_gamma you supply. The screen_gamma value is, however, used as a default for the file gamma if the PNG file has no gamma information.
If you call png_set_gamma() after png_set_alpha_mode() you will override the linear encoding. Instead the pre-multiplied pixel values will be gamma encoded but the alpha channel will still be linear. This may actually match the requirements of some broken software, but it is unlikely.
While linear 8-bit data is often used it has insufficient precision for any image with a reasonable dynamic range. To avoid problems, and if your software supports it, use png_set_expand_16() to force all components to 16 bits.
Use this format if you have control over your compositing software and so don't do other arithmetic (such as scaling) on the data you get from libpng. Your compositing software can simply copy opaque pixels to the output but still has linear values for the non-opaque pixels.
In normal compositing, where the alpha channel encodes partial pixel coverage (as opposed to broad area translucency), the inaccuracies of the 8-bit representation of non-opaque pixels are irrelevant.
You can also try this format if your software is broken; it might look better.
In most cases of broken software or hardware the bug in the final display manifests as a subtle halo around composited parts of the image. You may not even perceive this as a halo; the composited part of the image may simply appear separate from the background, as though it had been cut out of paper and pasted on afterward.
If you don't have to deal with bugs in software or hardware, or if you can fix them, there are three recommended ways of using png_set_alpha_mode():
png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG,
You can do color correction on the result (libpng does not currently support color correction internally). When you handle the alpha channel you need to undo the gamma encoding and multiply out the alpha.
png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD,
png_set_expand_16(png_ptr);
If you are using the high level interface, don't call png_set_expand_16(); instead pass PNG_TRANSFORM_EXPAND_16 to the interface.
With this mode you can't do color correction, but you can do arithmetic, including composition and scaling, on the data without further processing.
png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,
You can avoid the expansion to 16-bit components with this mode, but you lose the ability to scale the image or perform other linear arithmetic. All you can do is compose the result onto a matching output. Since this mode is libpng-specific you also need to write your own composition software.
If you don't need, or can't handle, the alpha channel you can call png_set_background() to remove it by compositing against a fixed color. Don't call png_set_strip_alpha() to do this - it will leave spurious pixel values in transparent parts of this image.
png_set_background(png_ptr,
The background_color is an RGB or grayscale value according to the data format libpng will produce for you. Because you don't yet know the format of the PNG file, if you call png_set_background at this point you must arrange for the format produced by libpng to always have 8-bit or 16-bit components and then store the color as an 8-bit or 16-bit color as appropriate. The color contains separate gray and RGB component values, so you can let libpng produce gray or RGB output according to the input format, but low bit depth grayscale images must always be converted to at least 8-bit format. (Even though low bit depth grayscale images can't have an alpha channel they can have a transparent color!)
You set the transforms you need later, either as flags to the high level interface or libpng API calls for the low level interface. For reference the settings and API calls required are:
8-bit values:
PNG_TRANSFORM_SCALE_16 | PNG_EXPAND
png_set_expand(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.
16-bit values:
PNG_TRANSFORM_EXPAND_16
png_set_expand_16(png_ptr);
In either case palette image data will be expanded to RGB. If you just want color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr) to the list.
Calling png_set_background before the PNG file header is read will not work prior to libpng-1.5.4. Because the failure may result in unexpected warnings or errors it is therefore much safer to call png_set_background after the head has been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be used with the high level interface.
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: