From b3ce365d911e05faae92f50597a182058878dbc4 Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Sat, 15 Aug 2009 21:47:03 -0500 Subject: [PATCH] [devel] Add some whitespace and relocate some png_debug statements. --- png.c | 22 +++++++++++++--------- pngget.c | 55 +++++++++++++++++++++++++++--------------------------- pngrtran.c | 8 +++++++- pngset.c | 4 +++- 4 files changed, 51 insertions(+), 38 deletions(-) diff --git a/png.c b/png.c index e1e9853b2..bcf2a42db 100644 --- a/png.c +++ b/png.c @@ -1,7 +1,7 @@ /* png.c - location for general purpose libpng functions * - * Last changed in libpng 1.4.0 [August 15, 2009] + * Last changed in libpng 1.4.0 [August 16, 2009] * Copyright (c) 1998-2009 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -95,11 +95,11 @@ PNG_CONST int FARDATA png_pass_dsp_mask[] void PNGAPI png_set_sig_bytes(png_structp png_ptr, int num_bytes) { + png_debug(1, "in png_set_sig_bytes"); + if (png_ptr == NULL) return; - png_debug(1, "in png_set_sig_bytes"); - if (num_bytes > 8) png_error(png_ptr, "Too many bytes for PNG signature"); @@ -217,6 +217,7 @@ png_create_info_struct(png_structp png_ptr) if (png_ptr == NULL) return (NULL); + #ifdef PNG_USER_MEM_SUPPORTED info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, png_ptr->malloc_fn, png_ptr->mem_ptr); @@ -238,11 +239,12 @@ void PNGAPI png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) { png_infop info_ptr = NULL; - if (png_ptr == NULL) - return; png_debug(1, "in png_destroy_info_struct"); + if (png_ptr == NULL) + return; + if (info_ptr_ptr != NULL) info_ptr = *info_ptr_ptr; @@ -270,11 +272,11 @@ png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size) { png_infop info_ptr = *ptr_ptr; + png_debug(1, "in png_info_init_3"); + if (info_ptr == NULL) return; - png_debug(1, "in png_info_init_3"); - if (png_sizeof(png_info) > png_info_struct_size) { png_destroy_struct(info_ptr); @@ -295,6 +297,7 @@ png_data_freer(png_structp png_ptr, png_infop info_ptr, if (png_ptr == NULL || info_ptr == NULL) return; + if (freer == PNG_DESTROY_WILL_FREE_DATA) info_ptr->free_me |= mask; else if (freer == PNG_USER_WILL_FREE_DATA) @@ -605,6 +608,7 @@ png_init_io(png_structp png_ptr, png_FILE_p fp) if (png_ptr == NULL) return; + png_ptr->io_ptr = (png_voidp)fp; } #endif @@ -659,13 +663,13 @@ png_get_copyright(png_structp png_ptr) #else #ifdef __STDC__ return ((png_charp) PNG_STRING_NEWLINE \ - "libpng version x 1.4.0beta75 - August 15, 2009" PNG_STRING_NEWLINE \ + "libpng version x 1.4.0beta75 - August 16, 2009" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2009 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ PNG_STRING_NEWLINE); #else - return ((png_charp) "libpng version 1.4.0beta75 - August 15, 2009\ + return ((png_charp) "libpng version 1.4.0beta75 - August 16, 2009\ Copyright (c) 1998-2009 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."); diff --git a/pngget.c b/pngget.c index c6a7dbd19..c4f9635ff 100644 --- a/pngget.c +++ b/pngget.c @@ -1,7 +1,7 @@ /* pngget.c - retrieval of values from info struct * - * Last changed in libpng 1.4.0 [August 15, 2009] + * Last changed in libpng 1.4.0 [August 16, 2009] * Copyright (c) 1998-2009 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -190,6 +190,7 @@ png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) if (info_ptr->x_pixels_per_unit == 0) return ((float)0.0); + else return ((float)((float)info_ptr->y_pixels_per_unit /(float)info_ptr->x_pixels_per_unit)); @@ -440,10 +441,10 @@ png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, png_fixed_point *blue_x, png_fixed_point *blue_y) { + png_debug1(1, "in %s retrieval function", "cHRM"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) { - png_debug1(1, "in %s retrieval function", "cHRM"); - if (white_x != NULL) *white_x = info_ptr->int_x_white; if (white_y != NULL) @@ -472,11 +473,11 @@ png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, png_uint_32 PNGAPI png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) { + png_debug1(1, "in %s retrieval function", "gAMA"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) && file_gamma != NULL) { - png_debug1(1, "in %s retrieval function", "gAMA"); - *file_gamma = (double)info_ptr->gamma; return (PNG_INFO_gAMA); } @@ -488,11 +489,11 @@ png_uint_32 PNGAPI png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point *int_file_gamma) { + png_debug1(1, "in %s retrieval function", "gAMA"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) && int_file_gamma != NULL) { - png_debug1(1, "in %s retrieval function", "gAMA"); - *int_file_gamma = info_ptr->int_gamma; return (PNG_INFO_gAMA); } @@ -505,11 +506,11 @@ png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_uint_32 PNGAPI png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) { + png_debug1(1, "in %s retrieval function", "sRGB"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) && file_srgb_intent != NULL) { - png_debug1(1, "in %s retrieval function", "sRGB"); - *file_srgb_intent = (int)info_ptr->srgb_intent; return (PNG_INFO_sRGB); } @@ -523,11 +524,11 @@ png_get_iCCP(png_structp png_ptr, png_infop info_ptr, png_charpp name, int *compression_type, png_charpp profile, png_uint_32 *proflen) { + png_debug1(1, "in %s retrieval function", "iCCP"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) && name != NULL && profile != NULL && proflen != NULL) { - png_debug1(1, "in %s retrieval function", "iCCP"); - *name = info_ptr->iccp_name; *profile = info_ptr->iccp_profile; /* Compression_type is a dummy so the API won't have to change @@ -559,11 +560,11 @@ png_get_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 PNGAPI png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) { + png_debug1(1, "in %s retrieval function", "hIST"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) && hist != NULL) { - png_debug1(1, "in %s retrieval function", "hIST"); - *hist = info_ptr->hist; return (PNG_INFO_hIST); } @@ -578,11 +579,11 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr, int *filter_type) { + png_debug1(1, "in %s retrieval function", "IHDR"); + if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL && bit_depth != NULL && color_type != NULL) { - png_debug1(1, "in %s retrieval function", "IHDR"); - *width = info_ptr->width; *height = info_ptr->height; *bit_depth = info_ptr->bit_depth; @@ -631,11 +632,11 @@ png_uint_32 PNGAPI png_get_oFFs(png_structp png_ptr, png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) { + png_debug1(1, "in %s retrieval function", "oFFs"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) && offset_x != NULL && offset_y != NULL && unit_type != NULL) { - png_debug1(1, "in %s retrieval function", "oFFs"); - *offset_x = info_ptr->x_offset; *offset_y = info_ptr->y_offset; *unit_type = (int)info_ptr->offset_unit_type; @@ -651,12 +652,12 @@ png_get_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) { + png_debug1(1, "in %s retrieval function", "pCAL"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && nparams != NULL && units != NULL && params != NULL) { - png_debug1(1, "in %s retrieval function", "pCAL"); - *purpose = info_ptr->pcal_purpose; *X0 = info_ptr->pcal_X0; *X1 = info_ptr->pcal_X1; @@ -713,11 +714,11 @@ png_get_pHYs(png_structp png_ptr, png_infop info_ptr, { png_uint_32 retval = 0; + png_debug1(1, "in %s retrieval function", "pHYs"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) { - png_debug1(1, "in %s retrieval function", "pHYs"); - if (res_x != NULL) { *res_x = info_ptr->x_pixels_per_unit; @@ -744,11 +745,11 @@ png_uint_32 PNGAPI png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette) { + png_debug1(1, "in %s retrieval function", "PLTE"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) && palette != NULL) { - png_debug1(1, "in %s retrieval function", "PLTE"); - *palette = info_ptr->palette; *num_palette = info_ptr->num_palette; png_debug1(3, "num_palette = %d", *num_palette); @@ -761,11 +762,11 @@ png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, png_uint_32 PNGAPI png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) { + png_debug1(1, "in %s retrieval function", "sBIT"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) && sig_bit != NULL) { - png_debug1(1, "in %s retrieval function", "sBIT"); - *sig_bit = &(info_ptr->sig_bit); return (PNG_INFO_sBIT); } @@ -802,11 +803,11 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, png_uint_32 PNGAPI png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) { + png_debug1(1, "in %s retrieval function", "tIME"); + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) && mod_time != NULL) { - png_debug1(1, "in %s retrieval function", "tIME"); - *mod_time = &(info_ptr->mod_time); return (PNG_INFO_tIME); } diff --git a/pngrtran.c b/pngrtran.c index cd52ad003..16df838bd 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1,7 +1,7 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * Last changed in libpng 1.4.0 [August 15, 2009] + * Last changed in libpng 1.4.0 [August 16, 2009] * Copyright (c) 1998-2009 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -581,6 +581,7 @@ png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) if (png_ptr == NULL) return; + if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) || (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) || (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) @@ -602,6 +603,7 @@ png_set_expand(png_structp png_ptr) if (png_ptr == NULL) return; + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); png_ptr->flags &= ~PNG_FLAG_ROW_INIT; } @@ -631,6 +633,7 @@ png_set_palette_to_rgb(png_structp png_ptr) if (png_ptr == NULL) return; + png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); png_ptr->flags &= ~PNG_FLAG_ROW_INIT; } @@ -643,6 +646,7 @@ png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) if (png_ptr == NULL) return; + png_ptr->transformations |= PNG_EXPAND; png_ptr->flags &= ~PNG_FLAG_ROW_INIT; } @@ -697,6 +701,7 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, if (png_ptr == NULL) return; + switch(error_action) { case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY; @@ -753,6 +758,7 @@ png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr if (png_ptr == NULL) return; + #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) png_ptr->transformations |= PNG_USER_TRANSFORM; png_ptr->read_user_transform_fn = read_user_transform_fn; diff --git a/pngset.c b/pngset.c index 503ea45f1..6f05c1711 100644 --- a/pngset.c +++ b/pngset.c @@ -1,7 +1,7 @@ /* pngset.c - storage of image information into info struct * - * Last changed in libpng 1.4.0 [August 15, 2009] + * Last changed in libpng 1.4.0 [August 16, 2009] * Copyright (c) 1998-2009 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -186,6 +186,7 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) if (png_ptr == NULL || info_ptr == NULL) return; + if (info_ptr->num_palette == 0 || info_ptr->num_palette > PNG_MAX_PALETTE_LENGTH) { @@ -1175,6 +1176,7 @@ png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, if (png_ptr == NULL) return; + png_ptr->read_user_chunk_fn = read_user_chunk_fn; png_ptr->user_chunk_ptr = user_chunk_ptr; }