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