nuclear@14: nuclear@14: /* pngget.c - retrieval of values from info struct nuclear@14: * nuclear@14: * Last changed in libpng 1.2.30 [August 15, 2008] nuclear@14: * For conditions of distribution and use, see copyright notice in png.h nuclear@14: * Copyright (c) 1998-2008 Glenn Randers-Pehrson nuclear@14: * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) nuclear@14: * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) nuclear@14: */ nuclear@14: nuclear@14: #define PNG_INTERNAL nuclear@14: #include "png.h" nuclear@14: #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) nuclear@14: nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: return(info_ptr->valid & flag); nuclear@14: else nuclear@14: return(0); nuclear@14: } nuclear@14: nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: return(info_ptr->rowbytes); nuclear@14: else nuclear@14: return(0); nuclear@14: } nuclear@14: nuclear@14: #if defined(PNG_INFO_IMAGE_SUPPORTED) nuclear@14: png_bytepp PNGAPI nuclear@14: png_get_rows(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: return(info_ptr->row_pointers); nuclear@14: else nuclear@14: return(0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #ifdef PNG_EASY_ACCESS_SUPPORTED nuclear@14: /* easy access to info, added in libpng-0.99 */ nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_image_width(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: { nuclear@14: return info_ptr->width; nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_image_height(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: { nuclear@14: return info_ptr->height; nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_byte PNGAPI nuclear@14: png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: { nuclear@14: return info_ptr->bit_depth; nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_byte PNGAPI nuclear@14: png_get_color_type(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: { nuclear@14: return info_ptr->color_type; nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_byte PNGAPI nuclear@14: png_get_filter_type(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: { nuclear@14: return info_ptr->filter_type; nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_byte PNGAPI nuclear@14: png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: { nuclear@14: return info_ptr->interlace_type; nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_byte PNGAPI nuclear@14: png_get_compression_type(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: { nuclear@14: return info_ptr->compression_type; nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: #if defined(PNG_pHYs_SUPPORTED) nuclear@14: if (info_ptr->valid & PNG_INFO_pHYs) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter"); nuclear@14: if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER) nuclear@14: return (0); nuclear@14: else return (info_ptr->x_pixels_per_unit); nuclear@14: } nuclear@14: #else nuclear@14: return (0); nuclear@14: #endif nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: #if defined(PNG_pHYs_SUPPORTED) nuclear@14: if (info_ptr->valid & PNG_INFO_pHYs) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter"); nuclear@14: if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER) nuclear@14: return (0); nuclear@14: else return (info_ptr->y_pixels_per_unit); nuclear@14: } nuclear@14: #else nuclear@14: return (0); nuclear@14: #endif nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: #if defined(PNG_pHYs_SUPPORTED) nuclear@14: if (info_ptr->valid & PNG_INFO_pHYs) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter"); nuclear@14: if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER || nuclear@14: info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit) nuclear@14: return (0); nuclear@14: else return (info_ptr->x_pixels_per_unit); nuclear@14: } nuclear@14: #else nuclear@14: return (0); nuclear@14: #endif nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: #ifdef PNG_FLOATING_POINT_SUPPORTED nuclear@14: float PNGAPI nuclear@14: png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: #if defined(PNG_pHYs_SUPPORTED) nuclear@14: if (info_ptr->valid & PNG_INFO_pHYs) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio"); nuclear@14: if (info_ptr->x_pixels_per_unit == 0) nuclear@14: return ((float)0.0); nuclear@14: else nuclear@14: return ((float)((float)info_ptr->y_pixels_per_unit nuclear@14: /(float)info_ptr->x_pixels_per_unit)); nuclear@14: } nuclear@14: #else nuclear@14: return (0.0); nuclear@14: #endif nuclear@14: return ((float)0.0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: png_int_32 PNGAPI nuclear@14: png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: #if defined(PNG_oFFs_SUPPORTED) nuclear@14: if (info_ptr->valid & PNG_INFO_oFFs) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); nuclear@14: if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) nuclear@14: return (0); nuclear@14: else return (info_ptr->x_offset); nuclear@14: } nuclear@14: #else nuclear@14: return (0); nuclear@14: #endif nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_int_32 PNGAPI nuclear@14: png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: #if defined(PNG_oFFs_SUPPORTED) nuclear@14: if (info_ptr->valid & PNG_INFO_oFFs) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); nuclear@14: if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) nuclear@14: return (0); nuclear@14: else return (info_ptr->y_offset); nuclear@14: } nuclear@14: #else nuclear@14: return (0); nuclear@14: #endif nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_int_32 PNGAPI nuclear@14: png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: #if defined(PNG_oFFs_SUPPORTED) nuclear@14: if (info_ptr->valid & PNG_INFO_oFFs) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); nuclear@14: if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) nuclear@14: return (0); nuclear@14: else return (info_ptr->x_offset); nuclear@14: } nuclear@14: #else nuclear@14: return (0); nuclear@14: #endif nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_int_32 PNGAPI nuclear@14: png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: #if defined(PNG_oFFs_SUPPORTED) nuclear@14: if (info_ptr->valid & PNG_INFO_oFFs) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); nuclear@14: if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) nuclear@14: return (0); nuclear@14: else return (info_ptr->y_offset); nuclear@14: } nuclear@14: #else nuclear@14: return (0); nuclear@14: #endif nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr) nuclear@14: *.0254 +.5)); nuclear@14: } nuclear@14: nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr) nuclear@14: *.0254 +.5)); nuclear@14: } nuclear@14: nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr) nuclear@14: *.0254 +.5)); nuclear@14: } nuclear@14: nuclear@14: float PNGAPI nuclear@14: png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: return ((float)png_get_x_offset_microns(png_ptr, info_ptr) nuclear@14: *.00003937); nuclear@14: } nuclear@14: nuclear@14: float PNGAPI nuclear@14: png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: return ((float)png_get_y_offset_microns(png_ptr, info_ptr) nuclear@14: *.00003937); nuclear@14: } nuclear@14: nuclear@14: #if defined(PNG_pHYs_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) nuclear@14: { nuclear@14: png_uint_32 retval = 0; nuclear@14: nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "pHYs"); nuclear@14: if (res_x != NULL) nuclear@14: { nuclear@14: *res_x = info_ptr->x_pixels_per_unit; nuclear@14: retval |= PNG_INFO_pHYs; nuclear@14: } nuclear@14: if (res_y != NULL) nuclear@14: { nuclear@14: *res_y = info_ptr->y_pixels_per_unit; nuclear@14: retval |= PNG_INFO_pHYs; nuclear@14: } nuclear@14: if (unit_type != NULL) nuclear@14: { nuclear@14: *unit_type = (int)info_ptr->phys_unit_type; nuclear@14: retval |= PNG_INFO_pHYs; nuclear@14: if (*unit_type == 1) nuclear@14: { nuclear@14: if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); nuclear@14: if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); nuclear@14: } nuclear@14: } nuclear@14: } nuclear@14: return (retval); nuclear@14: } nuclear@14: #endif /* PNG_pHYs_SUPPORTED */ nuclear@14: #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ nuclear@14: nuclear@14: /* png_get_channels really belongs in here, too, but it's been around longer */ nuclear@14: nuclear@14: #endif /* PNG_EASY_ACCESS_SUPPORTED */ nuclear@14: nuclear@14: png_byte PNGAPI nuclear@14: png_get_channels(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: return(info_ptr->channels); nuclear@14: else nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: png_bytep PNGAPI nuclear@14: png_get_signature(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL) nuclear@14: return(info_ptr->signature); nuclear@14: else nuclear@14: return (NULL); nuclear@14: } nuclear@14: nuclear@14: #if defined(PNG_bKGD_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_bKGD(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_color_16p *background) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) nuclear@14: && background != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "bKGD"); nuclear@14: *background = &(info_ptr->background); nuclear@14: return (PNG_INFO_bKGD); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_cHRM_SUPPORTED) nuclear@14: #ifdef PNG_FLOATING_POINT_SUPPORTED nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_cHRM(png_structp png_ptr, png_infop info_ptr, nuclear@14: double *white_x, double *white_y, double *red_x, double *red_y, nuclear@14: double *green_x, double *green_y, double *blue_x, double *blue_y) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "cHRM"); nuclear@14: if (white_x != NULL) nuclear@14: *white_x = (double)info_ptr->x_white; nuclear@14: if (white_y != NULL) nuclear@14: *white_y = (double)info_ptr->y_white; nuclear@14: if (red_x != NULL) nuclear@14: *red_x = (double)info_ptr->x_red; nuclear@14: if (red_y != NULL) nuclear@14: *red_y = (double)info_ptr->y_red; nuclear@14: if (green_x != NULL) nuclear@14: *green_x = (double)info_ptr->x_green; nuclear@14: if (green_y != NULL) nuclear@14: *green_y = (double)info_ptr->y_green; nuclear@14: if (blue_x != NULL) nuclear@14: *blue_x = (double)info_ptr->x_blue; nuclear@14: if (blue_y != NULL) nuclear@14: *blue_y = (double)info_ptr->y_blue; nuclear@14: return (PNG_INFO_cHRM); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: #ifdef PNG_FIXED_POINT_SUPPORTED nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, nuclear@14: png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, nuclear@14: png_fixed_point *blue_x, png_fixed_point *blue_y) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "cHRM"); nuclear@14: if (white_x != NULL) nuclear@14: *white_x = info_ptr->int_x_white; nuclear@14: if (white_y != NULL) nuclear@14: *white_y = info_ptr->int_y_white; nuclear@14: if (red_x != NULL) nuclear@14: *red_x = info_ptr->int_x_red; nuclear@14: if (red_y != NULL) nuclear@14: *red_y = info_ptr->int_y_red; nuclear@14: if (green_x != NULL) nuclear@14: *green_x = info_ptr->int_x_green; nuclear@14: if (green_y != NULL) nuclear@14: *green_y = info_ptr->int_y_green; nuclear@14: if (blue_x != NULL) nuclear@14: *blue_x = info_ptr->int_x_blue; nuclear@14: if (blue_y != NULL) nuclear@14: *blue_y = info_ptr->int_y_blue; nuclear@14: return (PNG_INFO_cHRM); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_gAMA_SUPPORTED) nuclear@14: #ifdef PNG_FLOATING_POINT_SUPPORTED nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) nuclear@14: && file_gamma != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "gAMA"); nuclear@14: *file_gamma = (double)info_ptr->gamma; nuclear@14: return (PNG_INFO_gAMA); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: #ifdef PNG_FIXED_POINT_SUPPORTED nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_fixed_point *int_file_gamma) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) nuclear@14: && int_file_gamma != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "gAMA"); nuclear@14: *int_file_gamma = info_ptr->int_gamma; nuclear@14: return (PNG_INFO_gAMA); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_sRGB_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) nuclear@14: && file_srgb_intent != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "sRGB"); nuclear@14: *file_srgb_intent = (int)info_ptr->srgb_intent; nuclear@14: return (PNG_INFO_sRGB); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_iCCP_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_iCCP(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_charpp name, int *compression_type, nuclear@14: png_charpp profile, png_uint_32 *proflen) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) nuclear@14: && name != NULL && profile != NULL && proflen != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "iCCP"); nuclear@14: *name = info_ptr->iccp_name; nuclear@14: *profile = info_ptr->iccp_profile; nuclear@14: /* compression_type is a dummy so the API won't have to change nuclear@14: if we introduce multiple compression types later. */ nuclear@14: *proflen = (int)info_ptr->iccp_proflen; nuclear@14: *compression_type = (int)info_ptr->iccp_compression; nuclear@14: return (PNG_INFO_iCCP); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_sPLT_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_sPLT(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_sPLT_tpp spalettes) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) nuclear@14: { nuclear@14: *spalettes = info_ptr->splt_palettes; nuclear@14: return ((png_uint_32)info_ptr->splt_palettes_num); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_hIST_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) nuclear@14: && hist != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "hIST"); nuclear@14: *hist = info_ptr->hist; nuclear@14: return (PNG_INFO_hIST); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_IHDR(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_uint_32 *width, png_uint_32 *height, int *bit_depth, nuclear@14: int *color_type, int *interlace_type, int *compression_type, nuclear@14: int *filter_type) nuclear@14: nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL && nuclear@14: bit_depth != NULL && color_type != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "IHDR"); nuclear@14: *width = info_ptr->width; nuclear@14: *height = info_ptr->height; nuclear@14: *bit_depth = info_ptr->bit_depth; nuclear@14: if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16) nuclear@14: png_error(png_ptr, "Invalid bit depth"); nuclear@14: *color_type = info_ptr->color_type; nuclear@14: if (info_ptr->color_type > 6) nuclear@14: png_error(png_ptr, "Invalid color type"); nuclear@14: if (compression_type != NULL) nuclear@14: *compression_type = info_ptr->compression_type; nuclear@14: if (filter_type != NULL) nuclear@14: *filter_type = info_ptr->filter_type; nuclear@14: if (interlace_type != NULL) nuclear@14: *interlace_type = info_ptr->interlace_type; nuclear@14: nuclear@14: /* check for potential overflow of rowbytes */ nuclear@14: if (*width == 0 || *width > PNG_UINT_31_MAX) nuclear@14: png_error(png_ptr, "Invalid image width"); nuclear@14: if (*height == 0 || *height > PNG_UINT_31_MAX) nuclear@14: png_error(png_ptr, "Invalid image height"); nuclear@14: if (info_ptr->width > (PNG_UINT_32_MAX nuclear@14: >> 3) /* 8-byte RGBA pixels */ nuclear@14: - 64 /* bigrowbuf hack */ nuclear@14: - 1 /* filter byte */ nuclear@14: - 7*8 /* rounding of width to multiple of 8 pixels */ nuclear@14: - 8) /* extra max_pixel_depth pad */ nuclear@14: { nuclear@14: png_warning(png_ptr, nuclear@14: "Width too large for libpng to process image data."); nuclear@14: } nuclear@14: return (1); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: #if defined(PNG_oFFs_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_oFFs(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) nuclear@14: && offset_x != NULL && offset_y != NULL && unit_type != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "oFFs"); nuclear@14: *offset_x = info_ptr->x_offset; nuclear@14: *offset_y = info_ptr->y_offset; nuclear@14: *unit_type = (int)info_ptr->offset_unit_type; nuclear@14: return (PNG_INFO_oFFs); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_pCAL_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_pCAL(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, nuclear@14: png_charp *units, png_charpp *params) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) nuclear@14: && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && nuclear@14: nparams != NULL && units != NULL && params != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "pCAL"); nuclear@14: *purpose = info_ptr->pcal_purpose; nuclear@14: *X0 = info_ptr->pcal_X0; nuclear@14: *X1 = info_ptr->pcal_X1; nuclear@14: *type = (int)info_ptr->pcal_type; nuclear@14: *nparams = (int)info_ptr->pcal_nparams; nuclear@14: *units = info_ptr->pcal_units; nuclear@14: *params = info_ptr->pcal_params; nuclear@14: return (PNG_INFO_pCAL); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_sCAL_SUPPORTED) nuclear@14: #ifdef PNG_FLOATING_POINT_SUPPORTED nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_sCAL(png_structp png_ptr, png_infop info_ptr, nuclear@14: int *unit, double *width, double *height) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && nuclear@14: (info_ptr->valid & PNG_INFO_sCAL)) nuclear@14: { nuclear@14: *unit = info_ptr->scal_unit; nuclear@14: *width = info_ptr->scal_pixel_width; nuclear@14: *height = info_ptr->scal_pixel_height; nuclear@14: return (PNG_INFO_sCAL); nuclear@14: } nuclear@14: return(0); nuclear@14: } nuclear@14: #else nuclear@14: #ifdef PNG_FIXED_POINT_SUPPORTED nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, nuclear@14: int *unit, png_charpp width, png_charpp height) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && nuclear@14: (info_ptr->valid & PNG_INFO_sCAL)) nuclear@14: { nuclear@14: *unit = info_ptr->scal_unit; nuclear@14: *width = info_ptr->scal_s_width; nuclear@14: *height = info_ptr->scal_s_height; nuclear@14: return (PNG_INFO_sCAL); nuclear@14: } nuclear@14: return(0); nuclear@14: } nuclear@14: #endif nuclear@14: #endif nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_pHYs_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_pHYs(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) nuclear@14: { nuclear@14: png_uint_32 retval = 0; nuclear@14: nuclear@14: if (png_ptr != NULL && info_ptr != NULL && nuclear@14: (info_ptr->valid & PNG_INFO_pHYs)) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "pHYs"); nuclear@14: if (res_x != NULL) nuclear@14: { nuclear@14: *res_x = info_ptr->x_pixels_per_unit; nuclear@14: retval |= PNG_INFO_pHYs; nuclear@14: } nuclear@14: if (res_y != NULL) nuclear@14: { nuclear@14: *res_y = info_ptr->y_pixels_per_unit; nuclear@14: retval |= PNG_INFO_pHYs; nuclear@14: } nuclear@14: if (unit_type != NULL) nuclear@14: { nuclear@14: *unit_type = (int)info_ptr->phys_unit_type; nuclear@14: retval |= PNG_INFO_pHYs; nuclear@14: } nuclear@14: } nuclear@14: return (retval); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, nuclear@14: int *num_palette) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) nuclear@14: && palette != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "PLTE"); nuclear@14: *palette = info_ptr->palette; nuclear@14: *num_palette = info_ptr->num_palette; nuclear@14: png_debug1(3, "num_palette = %d\n", *num_palette); nuclear@14: return (PNG_INFO_PLTE); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: nuclear@14: #if defined(PNG_sBIT_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) nuclear@14: && sig_bit != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "sBIT"); nuclear@14: *sig_bit = &(info_ptr->sig_bit); nuclear@14: return (PNG_INFO_sBIT); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_TEXT_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, nuclear@14: int *num_text) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", nuclear@14: (png_ptr->chunk_name[0] == '\0' ? "text" nuclear@14: : (png_const_charp)png_ptr->chunk_name)); nuclear@14: if (text_ptr != NULL) nuclear@14: *text_ptr = info_ptr->text; nuclear@14: if (num_text != NULL) nuclear@14: *num_text = info_ptr->num_text; nuclear@14: return ((png_uint_32)info_ptr->num_text); nuclear@14: } nuclear@14: if (num_text != NULL) nuclear@14: *num_text = 0; nuclear@14: return(0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_tIME_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) nuclear@14: && mod_time != NULL) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "tIME"); nuclear@14: *mod_time = &(info_ptr->mod_time); nuclear@14: return (PNG_INFO_tIME); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_tRNS_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_tRNS(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_bytep *trans, int *num_trans, png_color_16p *trans_values) nuclear@14: { nuclear@14: png_uint_32 retval = 0; nuclear@14: if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) nuclear@14: { nuclear@14: png_debug1(1, "in %s retrieval function\n", "tRNS"); nuclear@14: if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) nuclear@14: { nuclear@14: if (trans != NULL) nuclear@14: { nuclear@14: *trans = info_ptr->trans; nuclear@14: retval |= PNG_INFO_tRNS; nuclear@14: } nuclear@14: if (trans_values != NULL) nuclear@14: *trans_values = &(info_ptr->trans_values); nuclear@14: } nuclear@14: else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ nuclear@14: { nuclear@14: if (trans_values != NULL) nuclear@14: { nuclear@14: *trans_values = &(info_ptr->trans_values); nuclear@14: retval |= PNG_INFO_tRNS; nuclear@14: } nuclear@14: if (trans != NULL) nuclear@14: *trans = NULL; nuclear@14: } nuclear@14: if (num_trans != NULL) nuclear@14: { nuclear@14: *num_trans = info_ptr->num_trans; nuclear@14: retval |= PNG_INFO_tRNS; nuclear@14: } nuclear@14: } nuclear@14: return (retval); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_unknown_chunkpp unknowns) nuclear@14: { nuclear@14: if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) nuclear@14: { nuclear@14: *unknowns = info_ptr->unknown_chunks; nuclear@14: return ((png_uint_32)info_ptr->unknown_chunks_num); nuclear@14: } nuclear@14: return (0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) nuclear@14: png_byte PNGAPI nuclear@14: png_get_rgb_to_gray_status (png_structp png_ptr) nuclear@14: { nuclear@14: return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_USER_CHUNKS_SUPPORTED) nuclear@14: png_voidp PNGAPI nuclear@14: png_get_user_chunk_ptr(png_structp png_ptr) nuclear@14: { nuclear@14: return (png_ptr? png_ptr->user_chunk_ptr : NULL); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #ifdef PNG_WRITE_SUPPORTED nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_compression_buffer_size(png_structp png_ptr) nuclear@14: { nuclear@14: return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L); nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #ifdef PNG_ASSEMBLER_CODE_SUPPORTED nuclear@14: #ifndef PNG_1_0_X nuclear@14: /* this function was added to libpng 1.2.0 and should exist by default */ nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_asm_flags (png_structp png_ptr) nuclear@14: { nuclear@14: /* obsolete, to be removed from libpng-1.4.0 */ nuclear@14: return (png_ptr? 0L: 0L); nuclear@14: } nuclear@14: nuclear@14: /* this function was added to libpng 1.2.0 and should exist by default */ nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_asm_flagmask (int flag_select) nuclear@14: { nuclear@14: /* obsolete, to be removed from libpng-1.4.0 */ nuclear@14: flag_select=flag_select; nuclear@14: return 0L; nuclear@14: } nuclear@14: nuclear@14: /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */ nuclear@14: /* this function was added to libpng 1.2.0 */ nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_mmx_flagmask (int flag_select, int *compilerID) nuclear@14: { nuclear@14: /* obsolete, to be removed from libpng-1.4.0 */ nuclear@14: flag_select=flag_select; nuclear@14: *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */ nuclear@14: return 0L; nuclear@14: } nuclear@14: nuclear@14: /* this function was added to libpng 1.2.0 */ nuclear@14: png_byte PNGAPI nuclear@14: png_get_mmx_bitdepth_threshold (png_structp png_ptr) nuclear@14: { nuclear@14: /* obsolete, to be removed from libpng-1.4.0 */ nuclear@14: return (png_ptr? 0: 0); nuclear@14: } nuclear@14: nuclear@14: /* this function was added to libpng 1.2.0 */ nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_mmx_rowbytes_threshold (png_structp png_ptr) nuclear@14: { nuclear@14: /* obsolete, to be removed from libpng-1.4.0 */ nuclear@14: return (png_ptr? 0L: 0L); nuclear@14: } nuclear@14: #endif /* ?PNG_1_0_X */ nuclear@14: #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ nuclear@14: nuclear@14: #ifdef PNG_SET_USER_LIMITS_SUPPORTED nuclear@14: /* these functions were added to libpng 1.2.6 */ nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_user_width_max (png_structp png_ptr) nuclear@14: { nuclear@14: return (png_ptr? png_ptr->user_width_max : 0); nuclear@14: } nuclear@14: png_uint_32 PNGAPI nuclear@14: png_get_user_height_max (png_structp png_ptr) nuclear@14: { nuclear@14: return (png_ptr? png_ptr->user_height_max : 0); nuclear@14: } nuclear@14: #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ nuclear@14: nuclear@14: nuclear@14: #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */