media/libpng/pngget.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libpng/pngget.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1339 @@
     1.4 +
     1.5 +/* pngget.c - retrieval of values from info struct
     1.6 + *
     1.7 + * Last changed in libpng 1.6.1 [March 28, 2013]
     1.8 + * Copyright (c) 1998-2013 Glenn Randers-Pehrson
     1.9 + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    1.10 + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
    1.11 + *
    1.12 + * This code is released under the libpng license.
    1.13 + * For conditions of distribution and use, see the disclaimer
    1.14 + * and license in png.h
    1.15 + *
    1.16 + */
    1.17 +
    1.18 +#include "pngpriv.h"
    1.19 +
    1.20 +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
    1.21 +
    1.22 +png_uint_32 PNGAPI
    1.23 +png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
    1.24 +    png_uint_32 flag)
    1.25 +{
    1.26 +   if (png_ptr != NULL && info_ptr != NULL)
    1.27 +      return(info_ptr->valid & flag);
    1.28 +
    1.29 +   return(0);
    1.30 +}
    1.31 +
    1.32 +png_size_t PNGAPI
    1.33 +png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
    1.34 +{
    1.35 +   if (png_ptr != NULL && info_ptr != NULL)
    1.36 +      return(info_ptr->rowbytes);
    1.37 +
    1.38 +   return(0);
    1.39 +}
    1.40 +
    1.41 +#ifdef PNG_INFO_IMAGE_SUPPORTED
    1.42 +png_bytepp PNGAPI
    1.43 +png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)
    1.44 +{
    1.45 +   if (png_ptr != NULL && info_ptr != NULL)
    1.46 +      return(info_ptr->row_pointers);
    1.47 +
    1.48 +   return(0);
    1.49 +}
    1.50 +#endif
    1.51 +
    1.52 +#ifdef PNG_EASY_ACCESS_SUPPORTED
    1.53 +/* Easy access to info, added in libpng-0.99 */
    1.54 +png_uint_32 PNGAPI
    1.55 +png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)
    1.56 +{
    1.57 +   if (png_ptr != NULL && info_ptr != NULL)
    1.58 +      return info_ptr->width;
    1.59 +
    1.60 +   return (0);
    1.61 +}
    1.62 +
    1.63 +png_uint_32 PNGAPI
    1.64 +png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)
    1.65 +{
    1.66 +   if (png_ptr != NULL && info_ptr != NULL)
    1.67 +      return info_ptr->height;
    1.68 +
    1.69 +   return (0);
    1.70 +}
    1.71 +
    1.72 +png_byte PNGAPI
    1.73 +png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)
    1.74 +{
    1.75 +   if (png_ptr != NULL && info_ptr != NULL)
    1.76 +      return info_ptr->bit_depth;
    1.77 +
    1.78 +   return (0);
    1.79 +}
    1.80 +
    1.81 +png_byte PNGAPI
    1.82 +png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
    1.83 +{
    1.84 +   if (png_ptr != NULL && info_ptr != NULL)
    1.85 +      return info_ptr->color_type;
    1.86 +
    1.87 +   return (0);
    1.88 +}
    1.89 +
    1.90 +png_byte PNGAPI
    1.91 +png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
    1.92 +{
    1.93 +   if (png_ptr != NULL && info_ptr != NULL)
    1.94 +      return info_ptr->filter_type;
    1.95 +
    1.96 +   return (0);
    1.97 +}
    1.98 +
    1.99 +png_byte PNGAPI
   1.100 +png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.101 +{
   1.102 +   if (png_ptr != NULL && info_ptr != NULL)
   1.103 +      return info_ptr->interlace_type;
   1.104 +
   1.105 +   return (0);
   1.106 +}
   1.107 +
   1.108 +png_byte PNGAPI
   1.109 +png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.110 +{
   1.111 +   if (png_ptr != NULL && info_ptr != NULL)
   1.112 +      return info_ptr->compression_type;
   1.113 +
   1.114 +   return (0);
   1.115 +}
   1.116 +
   1.117 +png_uint_32 PNGAPI
   1.118 +png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
   1.119 +   info_ptr)
   1.120 +{
   1.121 +#ifdef PNG_pHYs_SUPPORTED
   1.122 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
   1.123 +      {
   1.124 +         png_debug1(1, "in %s retrieval function",
   1.125 +             "png_get_x_pixels_per_meter");
   1.126 +
   1.127 +         if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
   1.128 +            return (info_ptr->x_pixels_per_unit);
   1.129 +      }
   1.130 +#endif
   1.131 +
   1.132 +   return (0);
   1.133 +}
   1.134 +
   1.135 +png_uint_32 PNGAPI
   1.136 +png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
   1.137 +    info_ptr)
   1.138 +{
   1.139 +#ifdef PNG_pHYs_SUPPORTED
   1.140 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
   1.141 +   {
   1.142 +      png_debug1(1, "in %s retrieval function",
   1.143 +          "png_get_y_pixels_per_meter");
   1.144 +
   1.145 +      if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
   1.146 +         return (info_ptr->y_pixels_per_unit);
   1.147 +   }
   1.148 +#endif
   1.149 +
   1.150 +   return (0);
   1.151 +}
   1.152 +
   1.153 +png_uint_32 PNGAPI
   1.154 +png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.155 +{
   1.156 +#ifdef PNG_pHYs_SUPPORTED
   1.157 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
   1.158 +   {
   1.159 +      png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
   1.160 +
   1.161 +      if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
   1.162 +          info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
   1.163 +         return (info_ptr->x_pixels_per_unit);
   1.164 +   }
   1.165 +#endif
   1.166 +
   1.167 +   return (0);
   1.168 +}
   1.169 +
   1.170 +#ifdef PNG_FLOATING_POINT_SUPPORTED
   1.171 +float PNGAPI
   1.172 +png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
   1.173 +   info_ptr)
   1.174 +{
   1.175 +#ifdef PNG_READ_pHYs_SUPPORTED
   1.176 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
   1.177 +   {
   1.178 +      png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
   1.179 +
   1.180 +      if (info_ptr->x_pixels_per_unit != 0)
   1.181 +         return ((float)((float)info_ptr->y_pixels_per_unit
   1.182 +             /(float)info_ptr->x_pixels_per_unit));
   1.183 +   }
   1.184 +#else
   1.185 +   PNG_UNUSED(png_ptr)
   1.186 +   PNG_UNUSED(info_ptr)
   1.187 +#endif
   1.188 +
   1.189 +   return ((float)0.0);
   1.190 +}
   1.191 +#endif
   1.192 +
   1.193 +#ifdef PNG_FIXED_POINT_SUPPORTED
   1.194 +png_fixed_point PNGAPI
   1.195 +png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
   1.196 +    png_const_inforp info_ptr)
   1.197 +{
   1.198 +#ifdef PNG_READ_pHYs_SUPPORTED
   1.199 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
   1.200 +       && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
   1.201 +       && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
   1.202 +       && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
   1.203 +   {
   1.204 +      png_fixed_point res;
   1.205 +
   1.206 +      png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
   1.207 +
   1.208 +      /* The following casts work because a PNG 4 byte integer only has a valid
   1.209 +       * range of 0..2^31-1; otherwise the cast might overflow.
   1.210 +       */
   1.211 +      if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
   1.212 +          (png_int_32)info_ptr->x_pixels_per_unit))
   1.213 +         return res;
   1.214 +   }
   1.215 +#else
   1.216 +   PNG_UNUSED(png_ptr)
   1.217 +   PNG_UNUSED(info_ptr)
   1.218 +#endif
   1.219 +
   1.220 +   return 0;
   1.221 +}
   1.222 +#endif
   1.223 +
   1.224 +png_int_32 PNGAPI
   1.225 +png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.226 +{
   1.227 +#ifdef PNG_oFFs_SUPPORTED
   1.228 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
   1.229 +   {
   1.230 +      png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
   1.231 +
   1.232 +      if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
   1.233 +         return (info_ptr->x_offset);
   1.234 +   }
   1.235 +#endif
   1.236 +
   1.237 +   return (0);
   1.238 +}
   1.239 +
   1.240 +png_int_32 PNGAPI
   1.241 +png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.242 +{
   1.243 +#ifdef PNG_oFFs_SUPPORTED
   1.244 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
   1.245 +   {
   1.246 +      png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
   1.247 +
   1.248 +      if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
   1.249 +         return (info_ptr->y_offset);
   1.250 +   }
   1.251 +#endif
   1.252 +
   1.253 +   return (0);
   1.254 +}
   1.255 +
   1.256 +png_int_32 PNGAPI
   1.257 +png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.258 +{
   1.259 +#ifdef PNG_oFFs_SUPPORTED
   1.260 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
   1.261 +   {
   1.262 +      png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
   1.263 +
   1.264 +      if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
   1.265 +         return (info_ptr->x_offset);
   1.266 +   }
   1.267 +#endif
   1.268 +
   1.269 +   return (0);
   1.270 +}
   1.271 +
   1.272 +png_int_32 PNGAPI
   1.273 +png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.274 +{
   1.275 +#ifdef PNG_oFFs_SUPPORTED
   1.276 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
   1.277 +   {
   1.278 +      png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
   1.279 +
   1.280 +      if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
   1.281 +         return (info_ptr->y_offset);
   1.282 +   }
   1.283 +#endif
   1.284 +
   1.285 +   return (0);
   1.286 +}
   1.287 +
   1.288 +#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
   1.289 +static png_uint_32
   1.290 +ppi_from_ppm(png_uint_32 ppm)
   1.291 +{
   1.292 +#if 0
   1.293 +   /* The conversion is *(2.54/100), in binary (32 digits):
   1.294 +    * .00000110100000001001110101001001
   1.295 +    */
   1.296 +   png_uint_32 t1001, t1101;
   1.297 +   ppm >>= 1;                  /* .1 */
   1.298 +   t1001 = ppm + (ppm >> 3);   /* .1001 */
   1.299 +   t1101 = t1001 + (ppm >> 1); /* .1101 */
   1.300 +   ppm >>= 20;                 /* .000000000000000000001 */
   1.301 +   t1101 += t1101 >> 15;       /* .1101000000000001101 */
   1.302 +   t1001 >>= 11;               /* .000000000001001 */
   1.303 +   t1001 += t1001 >> 12;       /* .000000000001001000000001001 */
   1.304 +   ppm += t1001;               /* .000000000001001000001001001 */
   1.305 +   ppm += t1101;               /* .110100000001001110101001001 */
   1.306 +   return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
   1.307 +#else
   1.308 +   /* The argument is a PNG unsigned integer, so it is not permitted
   1.309 +    * to be bigger than 2^31.
   1.310 +    */
   1.311 +   png_fixed_point result;
   1.312 +   if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
   1.313 +       5000))
   1.314 +      return result;
   1.315 +
   1.316 +   /* Overflow. */
   1.317 +   return 0;
   1.318 +#endif
   1.319 +}
   1.320 +
   1.321 +png_uint_32 PNGAPI
   1.322 +png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.323 +{
   1.324 +   return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
   1.325 +}
   1.326 +
   1.327 +png_uint_32 PNGAPI
   1.328 +png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.329 +{
   1.330 +   return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
   1.331 +}
   1.332 +
   1.333 +png_uint_32 PNGAPI
   1.334 +png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.335 +{
   1.336 +   return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
   1.337 +}
   1.338 +
   1.339 +#ifdef PNG_FIXED_POINT_SUPPORTED
   1.340 +static png_fixed_point
   1.341 +png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
   1.342 +{
   1.343 +   /* Convert from metres * 1,000,000 to inches * 100,000, meters to
   1.344 +    * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
   1.345 +    * Notice that this can overflow - a warning is output and 0 is
   1.346 +    * returned.
   1.347 +    */
   1.348 +   return png_muldiv_warn(png_ptr, microns, 500, 127);
   1.349 +}
   1.350 +
   1.351 +png_fixed_point PNGAPI
   1.352 +png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
   1.353 +    png_const_inforp info_ptr)
   1.354 +{
   1.355 +   return png_fixed_inches_from_microns(png_ptr,
   1.356 +       png_get_x_offset_microns(png_ptr, info_ptr));
   1.357 +}
   1.358 +#endif
   1.359 +
   1.360 +#ifdef PNG_FIXED_POINT_SUPPORTED
   1.361 +png_fixed_point PNGAPI
   1.362 +png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
   1.363 +    png_const_inforp info_ptr)
   1.364 +{
   1.365 +   return png_fixed_inches_from_microns(png_ptr,
   1.366 +       png_get_y_offset_microns(png_ptr, info_ptr));
   1.367 +}
   1.368 +#endif
   1.369 +
   1.370 +#ifdef PNG_FLOATING_POINT_SUPPORTED
   1.371 +float PNGAPI
   1.372 +png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.373 +{
   1.374 +   /* To avoid the overflow do the conversion directly in floating
   1.375 +    * point.
   1.376 +    */
   1.377 +   return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
   1.378 +}
   1.379 +#endif
   1.380 +
   1.381 +#ifdef PNG_FLOATING_POINT_SUPPORTED
   1.382 +float PNGAPI
   1.383 +png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.384 +{
   1.385 +   /* To avoid the overflow do the conversion directly in floating
   1.386 +    * point.
   1.387 +    */
   1.388 +   return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
   1.389 +}
   1.390 +#endif
   1.391 +
   1.392 +#ifdef PNG_pHYs_SUPPORTED
   1.393 +png_uint_32 PNGAPI
   1.394 +png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.395 +    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
   1.396 +{
   1.397 +   png_uint_32 retval = 0;
   1.398 +
   1.399 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
   1.400 +   {
   1.401 +      png_debug1(1, "in %s retrieval function", "pHYs");
   1.402 +
   1.403 +      if (res_x != NULL)
   1.404 +      {
   1.405 +         *res_x = info_ptr->x_pixels_per_unit;
   1.406 +         retval |= PNG_INFO_pHYs;
   1.407 +      }
   1.408 +
   1.409 +      if (res_y != NULL)
   1.410 +      {
   1.411 +         *res_y = info_ptr->y_pixels_per_unit;
   1.412 +         retval |= PNG_INFO_pHYs;
   1.413 +      }
   1.414 +
   1.415 +      if (unit_type != NULL)
   1.416 +      {
   1.417 +         *unit_type = (int)info_ptr->phys_unit_type;
   1.418 +         retval |= PNG_INFO_pHYs;
   1.419 +
   1.420 +         if (*unit_type == 1)
   1.421 +         {
   1.422 +            if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
   1.423 +            if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
   1.424 +         }
   1.425 +      }
   1.426 +   }
   1.427 +
   1.428 +   return (retval);
   1.429 +}
   1.430 +#endif /* PNG_pHYs_SUPPORTED */
   1.431 +#endif  /* PNG_INCH_CONVERSIONS_SUPPORTED */
   1.432 +
   1.433 +/* png_get_channels really belongs in here, too, but it's been around longer */
   1.434 +
   1.435 +#endif  /* PNG_EASY_ACCESS_SUPPORTED */
   1.436 +
   1.437 +
   1.438 +png_byte PNGAPI
   1.439 +png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.440 +{
   1.441 +   if (png_ptr != NULL && info_ptr != NULL)
   1.442 +      return(info_ptr->channels);
   1.443 +
   1.444 +   return (0);
   1.445 +}
   1.446 +
   1.447 +#ifdef PNG_READ_SUPPORTED
   1.448 +png_const_bytep PNGAPI
   1.449 +png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
   1.450 +{
   1.451 +   if (png_ptr != NULL && info_ptr != NULL)
   1.452 +      return(info_ptr->signature);
   1.453 +
   1.454 +   return (NULL);
   1.455 +}
   1.456 +#endif
   1.457 +
   1.458 +#ifdef PNG_bKGD_SUPPORTED
   1.459 +png_uint_32 PNGAPI
   1.460 +png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
   1.461 +   png_color_16p *background)
   1.462 +{
   1.463 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
   1.464 +       && background != NULL)
   1.465 +   {
   1.466 +      png_debug1(1, "in %s retrieval function", "bKGD");
   1.467 +
   1.468 +      *background = &(info_ptr->background);
   1.469 +      return (PNG_INFO_bKGD);
   1.470 +   }
   1.471 +
   1.472 +   return (0);
   1.473 +}
   1.474 +#endif
   1.475 +
   1.476 +#ifdef PNG_cHRM_SUPPORTED
   1.477 +/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
   1.478 + * same time to correct the rgb grayscale coefficient defaults obtained from the
   1.479 + * cHRM chunk in 1.5.4
   1.480 + */
   1.481 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
   1.482 +png_uint_32 PNGAPI
   1.483 +png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.484 +    double *white_x, double *white_y, double *red_x, double *red_y,
   1.485 +    double *green_x, double *green_y, double *blue_x, double *blue_y)
   1.486 +{
   1.487 +   /* Quiet API change: this code used to only return the end points if a cHRM
   1.488 +    * chunk was present, but the end points can also come from iCCP or sRGB
   1.489 +    * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and
   1.490 +    * the png_set_ APIs merely check that set end points are mutually
   1.491 +    * consistent.
   1.492 +    */
   1.493 +   if (png_ptr != NULL && info_ptr != NULL &&
   1.494 +      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
   1.495 +   {
   1.496 +      png_debug1(1, "in %s retrieval function", "cHRM");
   1.497 +
   1.498 +      if (white_x != NULL)
   1.499 +         *white_x = png_float(png_ptr,
   1.500 +            info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
   1.501 +      if (white_y != NULL)
   1.502 +         *white_y = png_float(png_ptr,
   1.503 +            info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
   1.504 +      if (red_x != NULL)
   1.505 +         *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
   1.506 +            "cHRM red X");
   1.507 +      if (red_y != NULL)
   1.508 +         *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
   1.509 +            "cHRM red Y");
   1.510 +      if (green_x != NULL)
   1.511 +         *green_x = png_float(png_ptr,
   1.512 +            info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
   1.513 +      if (green_y != NULL)
   1.514 +         *green_y = png_float(png_ptr,
   1.515 +            info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
   1.516 +      if (blue_x != NULL)
   1.517 +         *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
   1.518 +            "cHRM blue X");
   1.519 +      if (blue_y != NULL)
   1.520 +         *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
   1.521 +            "cHRM blue Y");
   1.522 +      return (PNG_INFO_cHRM);
   1.523 +   }
   1.524 +
   1.525 +   return (0);
   1.526 +}
   1.527 +
   1.528 +png_uint_32 PNGAPI
   1.529 +png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.530 +   double *red_X, double *red_Y, double *red_Z, double *green_X,
   1.531 +   double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
   1.532 +   double *blue_Z)
   1.533 +{
   1.534 +   if (png_ptr != NULL && info_ptr != NULL &&
   1.535 +      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
   1.536 +   {
   1.537 +      png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
   1.538 +
   1.539 +      if (red_X != NULL)
   1.540 +         *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
   1.541 +            "cHRM red X");
   1.542 +      if (red_Y != NULL)
   1.543 +         *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
   1.544 +            "cHRM red Y");
   1.545 +      if (red_Z != NULL)
   1.546 +         *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
   1.547 +            "cHRM red Z");
   1.548 +      if (green_X != NULL)
   1.549 +         *green_X = png_float(png_ptr,
   1.550 +            info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
   1.551 +      if (green_Y != NULL)
   1.552 +         *green_Y = png_float(png_ptr,
   1.553 +            info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
   1.554 +      if (green_Z != NULL)
   1.555 +         *green_Z = png_float(png_ptr,
   1.556 +            info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
   1.557 +      if (blue_X != NULL)
   1.558 +         *blue_X = png_float(png_ptr,
   1.559 +            info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
   1.560 +      if (blue_Y != NULL)
   1.561 +         *blue_Y = png_float(png_ptr,
   1.562 +            info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
   1.563 +      if (blue_Z != NULL)
   1.564 +         *blue_Z = png_float(png_ptr,
   1.565 +            info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
   1.566 +      return (PNG_INFO_cHRM);
   1.567 +   }
   1.568 +
   1.569 +   return (0);
   1.570 +}
   1.571 +#  endif
   1.572 +
   1.573 +#  ifdef PNG_FIXED_POINT_SUPPORTED
   1.574 +png_uint_32 PNGAPI
   1.575 +png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.576 +    png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
   1.577 +    png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
   1.578 +    png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
   1.579 +    png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
   1.580 +    png_fixed_point *int_blue_Z)
   1.581 +{
   1.582 +   if (png_ptr != NULL && info_ptr != NULL &&
   1.583 +      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
   1.584 +   {
   1.585 +      png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
   1.586 +
   1.587 +      if (int_red_X != NULL)
   1.588 +         *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;
   1.589 +      if (int_red_Y != NULL)
   1.590 +         *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;
   1.591 +      if (int_red_Z != NULL)
   1.592 +         *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;
   1.593 +      if (int_green_X != NULL)
   1.594 +         *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;
   1.595 +      if (int_green_Y != NULL)
   1.596 +         *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;
   1.597 +      if (int_green_Z != NULL)
   1.598 +         *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;
   1.599 +      if (int_blue_X != NULL)
   1.600 +         *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;
   1.601 +      if (int_blue_Y != NULL)
   1.602 +         *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;
   1.603 +      if (int_blue_Z != NULL)
   1.604 +         *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;
   1.605 +      return (PNG_INFO_cHRM);
   1.606 +   }
   1.607 +
   1.608 +   return (0);
   1.609 +}
   1.610 +
   1.611 +png_uint_32 PNGAPI
   1.612 +png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.613 +    png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
   1.614 +    png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
   1.615 +    png_fixed_point *blue_x, png_fixed_point *blue_y)
   1.616 +{
   1.617 +   png_debug1(1, "in %s retrieval function", "cHRM");
   1.618 +
   1.619 +   if (png_ptr != NULL && info_ptr != NULL &&
   1.620 +      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
   1.621 +   {
   1.622 +      if (white_x != NULL)
   1.623 +         *white_x = info_ptr->colorspace.end_points_xy.whitex;
   1.624 +      if (white_y != NULL)
   1.625 +         *white_y = info_ptr->colorspace.end_points_xy.whitey;
   1.626 +      if (red_x != NULL)
   1.627 +         *red_x = info_ptr->colorspace.end_points_xy.redx;
   1.628 +      if (red_y != NULL)
   1.629 +         *red_y = info_ptr->colorspace.end_points_xy.redy;
   1.630 +      if (green_x != NULL)
   1.631 +         *green_x = info_ptr->colorspace.end_points_xy.greenx;
   1.632 +      if (green_y != NULL)
   1.633 +         *green_y = info_ptr->colorspace.end_points_xy.greeny;
   1.634 +      if (blue_x != NULL)
   1.635 +         *blue_x = info_ptr->colorspace.end_points_xy.bluex;
   1.636 +      if (blue_y != NULL)
   1.637 +         *blue_y = info_ptr->colorspace.end_points_xy.bluey;
   1.638 +      return (PNG_INFO_cHRM);
   1.639 +   }
   1.640 +
   1.641 +   return (0);
   1.642 +}
   1.643 +#  endif
   1.644 +#endif
   1.645 +
   1.646 +#ifdef PNG_gAMA_SUPPORTED
   1.647 +#  ifdef PNG_FIXED_POINT_SUPPORTED
   1.648 +png_uint_32 PNGAPI
   1.649 +png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.650 +    png_fixed_point *file_gamma)
   1.651 +{
   1.652 +   png_debug1(1, "in %s retrieval function", "gAMA");
   1.653 +
   1.654 +   if (png_ptr != NULL && info_ptr != NULL &&
   1.655 +      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
   1.656 +      file_gamma != NULL)
   1.657 +   {
   1.658 +      *file_gamma = info_ptr->colorspace.gamma;
   1.659 +      return (PNG_INFO_gAMA);
   1.660 +   }
   1.661 +
   1.662 +   return (0);
   1.663 +}
   1.664 +#  endif
   1.665 +
   1.666 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
   1.667 +png_uint_32 PNGAPI
   1.668 +png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.669 +    double *file_gamma)
   1.670 +{
   1.671 +   png_debug1(1, "in %s retrieval function", "gAMA(float)");
   1.672 +
   1.673 +   if (png_ptr != NULL && info_ptr != NULL &&
   1.674 +      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
   1.675 +      file_gamma != NULL)
   1.676 +   {
   1.677 +      *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
   1.678 +         "png_get_gAMA");
   1.679 +      return (PNG_INFO_gAMA);
   1.680 +   }
   1.681 +
   1.682 +   return (0);
   1.683 +}
   1.684 +#  endif
   1.685 +#endif
   1.686 +
   1.687 +#ifdef PNG_sRGB_SUPPORTED
   1.688 +png_uint_32 PNGAPI
   1.689 +png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.690 +    int *file_srgb_intent)
   1.691 +{
   1.692 +   png_debug1(1, "in %s retrieval function", "sRGB");
   1.693 +
   1.694 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
   1.695 +       && file_srgb_intent != NULL)
   1.696 +   {
   1.697 +      *file_srgb_intent = info_ptr->colorspace.rendering_intent;
   1.698 +      return (PNG_INFO_sRGB);
   1.699 +   }
   1.700 +
   1.701 +   return (0);
   1.702 +}
   1.703 +#endif
   1.704 +
   1.705 +#ifdef PNG_iCCP_SUPPORTED
   1.706 +png_uint_32 PNGAPI
   1.707 +png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
   1.708 +    png_charpp name, int *compression_type,
   1.709 +    png_bytepp profile, png_uint_32 *proflen)
   1.710 +{
   1.711 +   png_debug1(1, "in %s retrieval function", "iCCP");
   1.712 +
   1.713 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
   1.714 +       && name != NULL && compression_type != NULL && profile != NULL &&
   1.715 +		 proflen != NULL)
   1.716 +   {
   1.717 +      *name = info_ptr->iccp_name;
   1.718 +      *profile = info_ptr->iccp_profile;
   1.719 +      *proflen = png_get_uint_32(info_ptr->iccp_profile);
   1.720 +      /* This is somewhat irrelevant since the profile data returned has
   1.721 +       * actually been uncompressed.
   1.722 +       */
   1.723 +      *compression_type = PNG_COMPRESSION_TYPE_BASE;
   1.724 +      return (PNG_INFO_iCCP);
   1.725 +   }
   1.726 +
   1.727 +   return (0);
   1.728 +}
   1.729 +#endif
   1.730 +
   1.731 +#ifdef PNG_sPLT_SUPPORTED
   1.732 +int PNGAPI
   1.733 +png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
   1.734 +    png_sPLT_tpp spalettes)
   1.735 +{
   1.736 +   if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
   1.737 +   {
   1.738 +      *spalettes = info_ptr->splt_palettes;
   1.739 +      return info_ptr->splt_palettes_num;
   1.740 +   }
   1.741 +
   1.742 +   return (0);
   1.743 +}
   1.744 +#endif
   1.745 +
   1.746 +#ifdef PNG_hIST_SUPPORTED
   1.747 +png_uint_32 PNGAPI
   1.748 +png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
   1.749 +    png_uint_16p *hist)
   1.750 +{
   1.751 +   png_debug1(1, "in %s retrieval function", "hIST");
   1.752 +
   1.753 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
   1.754 +       && hist != NULL)
   1.755 +   {
   1.756 +      *hist = info_ptr->hist;
   1.757 +      return (PNG_INFO_hIST);
   1.758 +   }
   1.759 +
   1.760 +   return (0);
   1.761 +}
   1.762 +#endif
   1.763 +
   1.764 +png_uint_32 PNGAPI
   1.765 +png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.766 +    png_uint_32 *width, png_uint_32 *height, int *bit_depth,
   1.767 +    int *color_type, int *interlace_type, int *compression_type,
   1.768 +    int *filter_type)
   1.769 +{
   1.770 +   png_debug1(1, "in %s retrieval function", "IHDR");
   1.771 +
   1.772 +   if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
   1.773 +       height == NULL || bit_depth == NULL || color_type == NULL)
   1.774 +      return (0);
   1.775 +
   1.776 +   *width = info_ptr->width;
   1.777 +   *height = info_ptr->height;
   1.778 +   *bit_depth = info_ptr->bit_depth;
   1.779 +   *color_type = info_ptr->color_type;
   1.780 +
   1.781 +   if (compression_type != NULL)
   1.782 +      *compression_type = info_ptr->compression_type;
   1.783 +
   1.784 +   if (filter_type != NULL)
   1.785 +      *filter_type = info_ptr->filter_type;
   1.786 +
   1.787 +   if (interlace_type != NULL)
   1.788 +      *interlace_type = info_ptr->interlace_type;
   1.789 +
   1.790 +   /* This is redundant if we can be sure that the info_ptr values were all
   1.791 +    * assigned in png_set_IHDR().  We do the check anyhow in case an
   1.792 +    * application has ignored our advice not to mess with the members
   1.793 +    * of info_ptr directly.
   1.794 +    */
   1.795 +   png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
   1.796 +       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
   1.797 +       info_ptr->compression_type, info_ptr->filter_type);
   1.798 +
   1.799 +   return (1);
   1.800 +}
   1.801 +
   1.802 +#ifdef PNG_oFFs_SUPPORTED
   1.803 +png_uint_32 PNGAPI
   1.804 +png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.805 +    png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
   1.806 +{
   1.807 +   png_debug1(1, "in %s retrieval function", "oFFs");
   1.808 +
   1.809 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
   1.810 +       && offset_x != NULL && offset_y != NULL && unit_type != NULL)
   1.811 +   {
   1.812 +      *offset_x = info_ptr->x_offset;
   1.813 +      *offset_y = info_ptr->y_offset;
   1.814 +      *unit_type = (int)info_ptr->offset_unit_type;
   1.815 +      return (PNG_INFO_oFFs);
   1.816 +   }
   1.817 +
   1.818 +   return (0);
   1.819 +}
   1.820 +#endif
   1.821 +
   1.822 +#ifdef PNG_pCAL_SUPPORTED
   1.823 +png_uint_32 PNGAPI
   1.824 +png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
   1.825 +    png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
   1.826 +    png_charp *units, png_charpp *params)
   1.827 +{
   1.828 +   png_debug1(1, "in %s retrieval function", "pCAL");
   1.829 +
   1.830 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
   1.831 +       && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
   1.832 +       nparams != NULL && units != NULL && params != NULL)
   1.833 +   {
   1.834 +      *purpose = info_ptr->pcal_purpose;
   1.835 +      *X0 = info_ptr->pcal_X0;
   1.836 +      *X1 = info_ptr->pcal_X1;
   1.837 +      *type = (int)info_ptr->pcal_type;
   1.838 +      *nparams = (int)info_ptr->pcal_nparams;
   1.839 +      *units = info_ptr->pcal_units;
   1.840 +      *params = info_ptr->pcal_params;
   1.841 +      return (PNG_INFO_pCAL);
   1.842 +   }
   1.843 +
   1.844 +   return (0);
   1.845 +}
   1.846 +#endif
   1.847 +
   1.848 +#ifdef PNG_sCAL_SUPPORTED
   1.849 +#  ifdef PNG_FIXED_POINT_SUPPORTED
   1.850 +#    if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
   1.851 +         defined(PNG_FLOATING_POINT_SUPPORTED)
   1.852 +png_uint_32 PNGAPI
   1.853 +png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.854 +    int *unit, png_fixed_point *width, png_fixed_point *height)
   1.855 +{
   1.856 +   if (png_ptr != NULL && info_ptr != NULL &&
   1.857 +       (info_ptr->valid & PNG_INFO_sCAL))
   1.858 +   {
   1.859 +      *unit = info_ptr->scal_unit;
   1.860 +      /*TODO: make this work without FP support; the API is currently eliminated
   1.861 +       * if neither floating point APIs nor internal floating point arithmetic
   1.862 +       * are enabled.
   1.863 +       */
   1.864 +      *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
   1.865 +      *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
   1.866 +         "sCAL height");
   1.867 +      return (PNG_INFO_sCAL);
   1.868 +   }
   1.869 +
   1.870 +   return(0);
   1.871 +}
   1.872 +#    endif /* FLOATING_ARITHMETIC */
   1.873 +#  endif /* FIXED_POINT */
   1.874 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
   1.875 +png_uint_32 PNGAPI
   1.876 +png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.877 +    int *unit, double *width, double *height)
   1.878 +{
   1.879 +   if (png_ptr != NULL && info_ptr != NULL &&
   1.880 +       (info_ptr->valid & PNG_INFO_sCAL))
   1.881 +   {
   1.882 +      *unit = info_ptr->scal_unit;
   1.883 +      *width = atof(info_ptr->scal_s_width);
   1.884 +      *height = atof(info_ptr->scal_s_height);
   1.885 +      return (PNG_INFO_sCAL);
   1.886 +   }
   1.887 +
   1.888 +   return(0);
   1.889 +}
   1.890 +#  endif /* FLOATING POINT */
   1.891 +png_uint_32 PNGAPI
   1.892 +png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.893 +    int *unit, png_charpp width, png_charpp height)
   1.894 +{
   1.895 +   if (png_ptr != NULL && info_ptr != NULL &&
   1.896 +       (info_ptr->valid & PNG_INFO_sCAL))
   1.897 +   {
   1.898 +      *unit = info_ptr->scal_unit;
   1.899 +      *width = info_ptr->scal_s_width;
   1.900 +      *height = info_ptr->scal_s_height;
   1.901 +      return (PNG_INFO_sCAL);
   1.902 +   }
   1.903 +
   1.904 +   return(0);
   1.905 +}
   1.906 +#endif /* sCAL */
   1.907 +
   1.908 +#ifdef PNG_pHYs_SUPPORTED
   1.909 +png_uint_32 PNGAPI
   1.910 +png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
   1.911 +    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
   1.912 +{
   1.913 +   png_uint_32 retval = 0;
   1.914 +
   1.915 +   png_debug1(1, "in %s retrieval function", "pHYs");
   1.916 +
   1.917 +   if (png_ptr != NULL && info_ptr != NULL &&
   1.918 +       (info_ptr->valid & PNG_INFO_pHYs))
   1.919 +   {
   1.920 +      if (res_x != NULL)
   1.921 +      {
   1.922 +         *res_x = info_ptr->x_pixels_per_unit;
   1.923 +         retval |= PNG_INFO_pHYs;
   1.924 +      }
   1.925 +
   1.926 +      if (res_y != NULL)
   1.927 +      {
   1.928 +         *res_y = info_ptr->y_pixels_per_unit;
   1.929 +         retval |= PNG_INFO_pHYs;
   1.930 +      }
   1.931 +
   1.932 +      if (unit_type != NULL)
   1.933 +      {
   1.934 +         *unit_type = (int)info_ptr->phys_unit_type;
   1.935 +         retval |= PNG_INFO_pHYs;
   1.936 +      }
   1.937 +   }
   1.938 +
   1.939 +   return (retval);
   1.940 +}
   1.941 +#endif /* pHYs */
   1.942 +
   1.943 +png_uint_32 PNGAPI
   1.944 +png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
   1.945 +    png_colorp *palette, int *num_palette)
   1.946 +{
   1.947 +   png_debug1(1, "in %s retrieval function", "PLTE");
   1.948 +
   1.949 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
   1.950 +       && palette != NULL)
   1.951 +   {
   1.952 +      *palette = info_ptr->palette;
   1.953 +      *num_palette = info_ptr->num_palette;
   1.954 +      png_debug1(3, "num_palette = %d", *num_palette);
   1.955 +      return (PNG_INFO_PLTE);
   1.956 +   }
   1.957 +
   1.958 +   return (0);
   1.959 +}
   1.960 +
   1.961 +#ifdef PNG_sBIT_SUPPORTED
   1.962 +png_uint_32 PNGAPI
   1.963 +png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
   1.964 +    png_color_8p *sig_bit)
   1.965 +{
   1.966 +   png_debug1(1, "in %s retrieval function", "sBIT");
   1.967 +
   1.968 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
   1.969 +       && sig_bit != NULL)
   1.970 +   {
   1.971 +      *sig_bit = &(info_ptr->sig_bit);
   1.972 +      return (PNG_INFO_sBIT);
   1.973 +   }
   1.974 +
   1.975 +   return (0);
   1.976 +}
   1.977 +#endif
   1.978 +
   1.979 +#ifdef PNG_TEXT_SUPPORTED
   1.980 +int PNGAPI
   1.981 +png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
   1.982 +    png_textp *text_ptr, int *num_text)
   1.983 +{
   1.984 +   if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
   1.985 +   {
   1.986 +      png_debug1(1, "in 0x%lx retrieval function",
   1.987 +         (unsigned long)png_ptr->chunk_name);
   1.988 +
   1.989 +      if (text_ptr != NULL)
   1.990 +         *text_ptr = info_ptr->text;
   1.991 +
   1.992 +      if (num_text != NULL)
   1.993 +         *num_text = info_ptr->num_text;
   1.994 +
   1.995 +      return info_ptr->num_text;
   1.996 +   }
   1.997 +
   1.998 +   if (num_text != NULL)
   1.999 +      *num_text = 0;
  1.1000 +
  1.1001 +   return(0);
  1.1002 +}
  1.1003 +#endif
  1.1004 +
  1.1005 +#ifdef PNG_tIME_SUPPORTED
  1.1006 +png_uint_32 PNGAPI
  1.1007 +png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
  1.1008 +    png_timep *mod_time)
  1.1009 +{
  1.1010 +   png_debug1(1, "in %s retrieval function", "tIME");
  1.1011 +
  1.1012 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  1.1013 +       && mod_time != NULL)
  1.1014 +   {
  1.1015 +      *mod_time = &(info_ptr->mod_time);
  1.1016 +      return (PNG_INFO_tIME);
  1.1017 +   }
  1.1018 +
  1.1019 +   return (0);
  1.1020 +}
  1.1021 +#endif
  1.1022 +
  1.1023 +#ifdef PNG_tRNS_SUPPORTED
  1.1024 +png_uint_32 PNGAPI
  1.1025 +png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
  1.1026 +    png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
  1.1027 +{
  1.1028 +   png_uint_32 retval = 0;
  1.1029 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  1.1030 +   {
  1.1031 +      png_debug1(1, "in %s retrieval function", "tRNS");
  1.1032 +
  1.1033 +      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  1.1034 +      {
  1.1035 +         if (trans_alpha != NULL)
  1.1036 +         {
  1.1037 +            *trans_alpha = info_ptr->trans_alpha;
  1.1038 +            retval |= PNG_INFO_tRNS;
  1.1039 +         }
  1.1040 +
  1.1041 +         if (trans_color != NULL)
  1.1042 +            *trans_color = &(info_ptr->trans_color);
  1.1043 +      }
  1.1044 +
  1.1045 +      else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  1.1046 +      {
  1.1047 +         if (trans_color != NULL)
  1.1048 +         {
  1.1049 +            *trans_color = &(info_ptr->trans_color);
  1.1050 +            retval |= PNG_INFO_tRNS;
  1.1051 +         }
  1.1052 +
  1.1053 +         if (trans_alpha != NULL)
  1.1054 +            *trans_alpha = NULL;
  1.1055 +      }
  1.1056 +
  1.1057 +      if (num_trans != NULL)
  1.1058 +      {
  1.1059 +         *num_trans = info_ptr->num_trans;
  1.1060 +         retval |= PNG_INFO_tRNS;
  1.1061 +      }
  1.1062 +   }
  1.1063 +
  1.1064 +   return (retval);
  1.1065 +}
  1.1066 +#endif
  1.1067 +
  1.1068 +#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
  1.1069 +int PNGAPI
  1.1070 +png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
  1.1071 +    png_unknown_chunkpp unknowns)
  1.1072 +{
  1.1073 +   if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  1.1074 +   {
  1.1075 +      *unknowns = info_ptr->unknown_chunks;
  1.1076 +      return info_ptr->unknown_chunks_num;
  1.1077 +   }
  1.1078 +
  1.1079 +   return (0);
  1.1080 +}
  1.1081 +#endif
  1.1082 +
  1.1083 +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  1.1084 +png_byte PNGAPI
  1.1085 +png_get_rgb_to_gray_status (png_const_structrp png_ptr)
  1.1086 +{
  1.1087 +   return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
  1.1088 +}
  1.1089 +#endif
  1.1090 +
  1.1091 +#ifdef PNG_USER_CHUNKS_SUPPORTED
  1.1092 +png_voidp PNGAPI
  1.1093 +png_get_user_chunk_ptr(png_const_structrp png_ptr)
  1.1094 +{
  1.1095 +   return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
  1.1096 +}
  1.1097 +#endif
  1.1098 +
  1.1099 +png_size_t PNGAPI
  1.1100 +png_get_compression_buffer_size(png_const_structrp png_ptr)
  1.1101 +{
  1.1102 +   if (png_ptr == NULL)
  1.1103 +      return 0;
  1.1104 +
  1.1105 +#  ifdef PNG_WRITE_SUPPORTED
  1.1106 +      if (png_ptr->mode & PNG_IS_READ_STRUCT)
  1.1107 +#  endif
  1.1108 +   {
  1.1109 +#     ifdef PNG_SEQUENTIAL_READ_SUPPORTED
  1.1110 +         return png_ptr->IDAT_read_size;
  1.1111 +#     else
  1.1112 +         return PNG_IDAT_READ_SIZE;
  1.1113 +#     endif
  1.1114 +   }
  1.1115 +
  1.1116 +#  ifdef PNG_WRITE_SUPPORTED
  1.1117 +      else
  1.1118 +         return png_ptr->zbuffer_size;
  1.1119 +#  endif
  1.1120 +}
  1.1121 +
  1.1122 +#ifdef PNG_SET_USER_LIMITS_SUPPORTED
  1.1123 +/* These functions were added to libpng 1.2.6 and were enabled
  1.1124 + * by default in libpng-1.4.0 */
  1.1125 +png_uint_32 PNGAPI
  1.1126 +png_get_user_width_max (png_const_structrp png_ptr)
  1.1127 +{
  1.1128 +   return (png_ptr ? png_ptr->user_width_max : 0);
  1.1129 +}
  1.1130 +
  1.1131 +png_uint_32 PNGAPI
  1.1132 +png_get_user_height_max (png_const_structrp png_ptr)
  1.1133 +{
  1.1134 +   return (png_ptr ? png_ptr->user_height_max : 0);
  1.1135 +}
  1.1136 +
  1.1137 +/* This function was added to libpng 1.4.0 */
  1.1138 +png_uint_32 PNGAPI
  1.1139 +png_get_chunk_cache_max (png_const_structrp png_ptr)
  1.1140 +{
  1.1141 +   return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
  1.1142 +}
  1.1143 +
  1.1144 +/* This function was added to libpng 1.4.1 */
  1.1145 +png_alloc_size_t PNGAPI
  1.1146 +png_get_chunk_malloc_max (png_const_structrp png_ptr)
  1.1147 +{
  1.1148 +   return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
  1.1149 +}
  1.1150 +#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  1.1151 +
  1.1152 +/* These functions were added to libpng 1.4.0 */
  1.1153 +#ifdef PNG_IO_STATE_SUPPORTED
  1.1154 +png_uint_32 PNGAPI
  1.1155 +png_get_io_state (png_const_structrp png_ptr)
  1.1156 +{
  1.1157 +   return png_ptr->io_state;
  1.1158 +}
  1.1159 +
  1.1160 +png_uint_32 PNGAPI
  1.1161 +png_get_io_chunk_type (png_const_structrp png_ptr)
  1.1162 +{
  1.1163 +   return png_ptr->chunk_name;
  1.1164 +}
  1.1165 +#endif /* ?PNG_IO_STATE_SUPPORTED */
  1.1166 +
  1.1167 +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
  1.1168 +#  ifdef PNG_GET_PALETTE_MAX_SUPPORTED
  1.1169 +int PNGAPI
  1.1170 +png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
  1.1171 +{
  1.1172 +   if (png_ptr != NULL && info_ptr != NULL)
  1.1173 +      return png_ptr->num_palette_max;
  1.1174 +
  1.1175 +   return (-1);
  1.1176 +}
  1.1177 +#  endif
  1.1178 +#endif
  1.1179 +
  1.1180 +#ifdef PNG_APNG_SUPPORTED
  1.1181 +png_uint_32 PNGAPI
  1.1182 +png_get_acTL(png_structp png_ptr, png_infop info_ptr,
  1.1183 +             png_uint_32 *num_frames, png_uint_32 *num_plays)
  1.1184 +{
  1.1185 +    png_debug1(1, "in %s retrieval function", "acTL");
  1.1186 +
  1.1187 +    if (png_ptr != NULL && info_ptr != NULL &&
  1.1188 +        (info_ptr->valid & PNG_INFO_acTL) &&
  1.1189 +        num_frames != NULL && num_plays != NULL)
  1.1190 +    {
  1.1191 +        *num_frames = info_ptr->num_frames;
  1.1192 +        *num_plays = info_ptr->num_plays;
  1.1193 +        return (1);
  1.1194 +    }
  1.1195 +
  1.1196 +    return (0);
  1.1197 +}
  1.1198 +
  1.1199 +png_uint_32 PNGAPI
  1.1200 +png_get_num_frames(png_structp png_ptr, png_infop info_ptr)
  1.1201 +{
  1.1202 +    png_debug(1, "in png_get_num_frames()");
  1.1203 +
  1.1204 +    if (png_ptr != NULL && info_ptr != NULL)
  1.1205 +        return (info_ptr->num_frames);
  1.1206 +    return (0);
  1.1207 +}
  1.1208 +
  1.1209 +png_uint_32 PNGAPI
  1.1210 +png_get_num_plays(png_structp png_ptr, png_infop info_ptr)
  1.1211 +{
  1.1212 +    png_debug(1, "in png_get_num_plays()");
  1.1213 +
  1.1214 +    if (png_ptr != NULL && info_ptr != NULL)
  1.1215 +        return (info_ptr->num_plays);
  1.1216 +    return (0);
  1.1217 +}
  1.1218 +
  1.1219 +png_uint_32 PNGAPI
  1.1220 +png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr,
  1.1221 +             png_uint_32 *width, png_uint_32 *height,
  1.1222 +             png_uint_32 *x_offset, png_uint_32 *y_offset,
  1.1223 +             png_uint_16 *delay_num, png_uint_16 *delay_den,
  1.1224 +             png_byte *dispose_op, png_byte *blend_op)
  1.1225 +{
  1.1226 +    png_debug1(1, "in %s retrieval function", "fcTL");
  1.1227 +
  1.1228 +    if (png_ptr != NULL && info_ptr != NULL &&
  1.1229 +        (info_ptr->valid & PNG_INFO_fcTL) &&
  1.1230 +        width != NULL && height != NULL &&
  1.1231 +        x_offset != NULL && y_offset != NULL &&
  1.1232 +        delay_num != NULL && delay_den != NULL &&
  1.1233 +        dispose_op != NULL && blend_op != NULL)
  1.1234 +    {
  1.1235 +        *width = info_ptr->next_frame_width;
  1.1236 +        *height = info_ptr->next_frame_height;
  1.1237 +        *x_offset = info_ptr->next_frame_x_offset;
  1.1238 +        *y_offset = info_ptr->next_frame_y_offset;
  1.1239 +        *delay_num = info_ptr->next_frame_delay_num;
  1.1240 +        *delay_den = info_ptr->next_frame_delay_den;
  1.1241 +        *dispose_op = info_ptr->next_frame_dispose_op;
  1.1242 +        *blend_op = info_ptr->next_frame_blend_op;
  1.1243 +        return (1);
  1.1244 +    }
  1.1245 +
  1.1246 +    return (0);
  1.1247 +}
  1.1248 +
  1.1249 +png_uint_32 PNGAPI
  1.1250 +png_get_next_frame_width(png_structp png_ptr, png_infop info_ptr)
  1.1251 +{
  1.1252 +    png_debug(1, "in png_get_next_frame_width()");
  1.1253 +
  1.1254 +    if (png_ptr != NULL && info_ptr != NULL)
  1.1255 +        return (info_ptr->next_frame_width);
  1.1256 +    return (0);
  1.1257 +}
  1.1258 +
  1.1259 +png_uint_32 PNGAPI
  1.1260 +png_get_next_frame_height(png_structp png_ptr, png_infop info_ptr)
  1.1261 +{
  1.1262 +    png_debug(1, "in png_get_next_frame_height()");
  1.1263 +
  1.1264 +    if (png_ptr != NULL && info_ptr != NULL)
  1.1265 +        return (info_ptr->next_frame_height);
  1.1266 +    return (0);
  1.1267 +}
  1.1268 +
  1.1269 +png_uint_32 PNGAPI
  1.1270 +png_get_next_frame_x_offset(png_structp png_ptr, png_infop info_ptr)
  1.1271 +{
  1.1272 +    png_debug(1, "in png_get_next_frame_x_offset()");
  1.1273 +
  1.1274 +    if (png_ptr != NULL && info_ptr != NULL)
  1.1275 +        return (info_ptr->next_frame_x_offset);
  1.1276 +    return (0);
  1.1277 +}
  1.1278 +
  1.1279 +png_uint_32 PNGAPI
  1.1280 +png_get_next_frame_y_offset(png_structp png_ptr, png_infop info_ptr)
  1.1281 +{
  1.1282 +    png_debug(1, "in png_get_next_frame_y_offset()");
  1.1283 +
  1.1284 +    if (png_ptr != NULL && info_ptr != NULL)
  1.1285 +        return (info_ptr->next_frame_y_offset);
  1.1286 +    return (0);
  1.1287 +}
  1.1288 +
  1.1289 +png_uint_16 PNGAPI
  1.1290 +png_get_next_frame_delay_num(png_structp png_ptr, png_infop info_ptr)
  1.1291 +{
  1.1292 +    png_debug(1, "in png_get_next_frame_delay_num()");
  1.1293 +
  1.1294 +    if (png_ptr != NULL && info_ptr != NULL)
  1.1295 +        return (info_ptr->next_frame_delay_num);
  1.1296 +    return (0);
  1.1297 +}
  1.1298 +
  1.1299 +png_uint_16 PNGAPI
  1.1300 +png_get_next_frame_delay_den(png_structp png_ptr, png_infop info_ptr)
  1.1301 +{
  1.1302 +    png_debug(1, "in png_get_next_frame_delay_den()");
  1.1303 +
  1.1304 +    if (png_ptr != NULL && info_ptr != NULL)
  1.1305 +        return (info_ptr->next_frame_delay_den);
  1.1306 +    return (0);
  1.1307 +}
  1.1308 +
  1.1309 +png_byte PNGAPI
  1.1310 +png_get_next_frame_dispose_op(png_structp png_ptr, png_infop info_ptr)
  1.1311 +{
  1.1312 +    png_debug(1, "in png_get_next_frame_dispose_op()");
  1.1313 +
  1.1314 +    if (png_ptr != NULL && info_ptr != NULL)
  1.1315 +        return (info_ptr->next_frame_dispose_op);
  1.1316 +    return (0);
  1.1317 +}
  1.1318 +
  1.1319 +png_byte PNGAPI
  1.1320 +png_get_next_frame_blend_op(png_structp png_ptr, png_infop info_ptr)
  1.1321 +{
  1.1322 +    png_debug(1, "in png_get_next_frame_blend_op()");
  1.1323 +
  1.1324 +    if (png_ptr != NULL && info_ptr != NULL)
  1.1325 +        return (info_ptr->next_frame_blend_op);
  1.1326 +    return (0);
  1.1327 +}
  1.1328 +
  1.1329 +png_byte PNGAPI
  1.1330 +png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr)
  1.1331 +{
  1.1332 +    png_debug(1, "in png_first_frame_is_hidden()");
  1.1333 +
  1.1334 +    if (png_ptr != NULL)
  1.1335 +       return (png_byte)(png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN);
  1.1336 +
  1.1337 +    PNG_UNUSED(info_ptr)
  1.1338 +
  1.1339 +    return 0;
  1.1340 +}
  1.1341 +#endif /* PNG_APNG_SUPPORTED */
  1.1342 +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */

mercurial