Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. /* pngget.c - retrieval of values from info struct
  3.  *
  4.  * Last changed in libpng 1.5.1 [February 3, 2011]
  5.  * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  6.  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  7.  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  8.  *
  9.  * This code is released under the libpng license.
  10.  * For conditions of distribution and use, see the disclaimer
  11.  * and license in png.h
  12.  *
  13.  */
  14.  
  15. #include "pngpriv.h"
  16.  
  17. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  18.  
  19. png_uint_32 PNGAPI
  20. png_get_valid(png_const_structp png_ptr, png_const_infop info_ptr,
  21.     png_uint_32 flag)
  22. {
  23.    if (png_ptr != NULL && info_ptr != NULL)
  24.       return(info_ptr->valid & flag);
  25.  
  26.    return(0);
  27. }
  28.  
  29. png_size_t PNGAPI
  30. png_get_rowbytes(png_const_structp png_ptr, png_const_infop info_ptr)
  31. {
  32.    if (png_ptr != NULL && info_ptr != NULL)
  33.       return(info_ptr->rowbytes);
  34.  
  35.    return(0);
  36. }
  37.  
  38. #ifdef PNG_INFO_IMAGE_SUPPORTED
  39. png_bytepp PNGAPI
  40. png_get_rows(png_const_structp png_ptr, png_const_infop info_ptr)
  41. {
  42.    if (png_ptr != NULL && info_ptr != NULL)
  43.       return(info_ptr->row_pointers);
  44.  
  45.    return(0);
  46. }
  47. #endif
  48.  
  49. #ifdef PNG_EASY_ACCESS_SUPPORTED
  50. /* Easy access to info, added in libpng-0.99 */
  51. png_uint_32 PNGAPI
  52. png_get_image_width(png_const_structp png_ptr, png_const_infop info_ptr)
  53. {
  54.    if (png_ptr != NULL && info_ptr != NULL)
  55.       return info_ptr->width;
  56.  
  57.    return (0);
  58. }
  59.  
  60. png_uint_32 PNGAPI
  61. png_get_image_height(png_const_structp png_ptr, png_const_infop info_ptr)
  62. {
  63.    if (png_ptr != NULL && info_ptr != NULL)
  64.       return info_ptr->height;
  65.  
  66.    return (0);
  67. }
  68.  
  69. png_byte PNGAPI
  70. png_get_bit_depth(png_const_structp png_ptr, png_const_infop info_ptr)
  71. {
  72.    if (png_ptr != NULL && info_ptr != NULL)
  73.       return info_ptr->bit_depth;
  74.  
  75.    return (0);
  76. }
  77.  
  78. png_byte PNGAPI
  79. png_get_color_type(png_const_structp png_ptr, png_const_infop info_ptr)
  80. {
  81.    if (png_ptr != NULL && info_ptr != NULL)
  82.       return info_ptr->color_type;
  83.  
  84.    return (0);
  85. }
  86.  
  87. png_byte PNGAPI
  88. png_get_filter_type(png_const_structp png_ptr, png_const_infop info_ptr)
  89. {
  90.    if (png_ptr != NULL && info_ptr != NULL)
  91.       return info_ptr->filter_type;
  92.  
  93.    return (0);
  94. }
  95.  
  96. png_byte PNGAPI
  97. png_get_interlace_type(png_const_structp png_ptr, png_const_infop info_ptr)
  98. {
  99.    if (png_ptr != NULL && info_ptr != NULL)
  100.       return info_ptr->interlace_type;
  101.  
  102.    return (0);
  103. }
  104.  
  105. png_byte PNGAPI
  106. png_get_compression_type(png_const_structp png_ptr, png_const_infop info_ptr)
  107. {
  108.    if (png_ptr != NULL && info_ptr != NULL)
  109.       return info_ptr->compression_type;
  110.  
  111.    return (0);
  112. }
  113.  
  114. png_uint_32 PNGAPI
  115. png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
  116. {
  117. #ifdef PNG_pHYs_SUPPORTED
  118.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  119.       {
  120.          png_debug1(1, "in %s retrieval function",
  121.              "png_get_x_pixels_per_meter");
  122.  
  123.          if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
  124.             return (info_ptr->x_pixels_per_unit);
  125.       }
  126. #endif
  127.  
  128.    return (0);
  129. }
  130.  
  131. png_uint_32 PNGAPI
  132. png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
  133. {
  134. #ifdef PNG_pHYs_SUPPORTED
  135.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  136.    {
  137.       png_debug1(1, "in %s retrieval function",
  138.           "png_get_y_pixels_per_meter");
  139.  
  140.       if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
  141.          return (info_ptr->y_pixels_per_unit);
  142.    }
  143. #endif
  144.  
  145.    return (0);
  146. }
  147.  
  148. png_uint_32 PNGAPI
  149. png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
  150. {
  151. #ifdef PNG_pHYs_SUPPORTED
  152.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  153.    {
  154.       png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
  155.  
  156.       if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
  157.           info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
  158.          return (info_ptr->x_pixels_per_unit);
  159.    }
  160. #endif
  161.  
  162.    return (0);
  163. }
  164.  
  165. #ifdef PNG_FLOATING_POINT_SUPPORTED
  166. float PNGAPI
  167. png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr)
  168. {
  169. #ifdef PNG_READ_pHYs_SUPPORTED
  170.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171.    {
  172.       png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
  173.  
  174.       if (info_ptr->x_pixels_per_unit != 0)
  175.          return ((float)((float)info_ptr->y_pixels_per_unit
  176.              /(float)info_ptr->x_pixels_per_unit));
  177.    }
  178. #endif
  179.  
  180.    return ((float)0.0);
  181. }
  182. #endif
  183.  
  184. #ifdef PNG_FIXED_POINT_SUPPORTED
  185. png_fixed_point PNGAPI
  186. png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr,
  187.     png_const_infop info_ptr)
  188. {
  189. #ifdef PNG_READ_pHYs_SUPPORTED
  190.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
  191.        && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
  192.        && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
  193.        && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
  194.    {
  195.       png_fixed_point res;
  196.  
  197.       png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
  198.  
  199.       /* The following casts work because a PNG 4 byte integer only has a valid
  200.        * range of 0..2^31-1; otherwise the cast might overflow.
  201.        */
  202.       if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
  203.           (png_int_32)info_ptr->x_pixels_per_unit))
  204.          return res;
  205.    }
  206. #endif
  207.  
  208.    return 0;
  209. }
  210. #endif
  211.  
  212. png_int_32 PNGAPI
  213. png_get_x_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr)
  214. {
  215. #ifdef PNG_oFFs_SUPPORTED
  216.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  217.    {
  218.       png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
  219.  
  220.       if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
  221.          return (info_ptr->x_offset);
  222.    }
  223. #endif
  224.  
  225.    return (0);
  226. }
  227.  
  228. png_int_32 PNGAPI
  229. png_get_y_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr)
  230. {
  231. #ifdef PNG_oFFs_SUPPORTED
  232.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  233.    {
  234.       png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
  235.  
  236.       if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
  237.          return (info_ptr->y_offset);
  238.    }
  239. #endif
  240.  
  241.    return (0);
  242. }
  243.  
  244. png_int_32 PNGAPI
  245. png_get_x_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr)
  246. {
  247. #ifdef PNG_oFFs_SUPPORTED
  248.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  249.    {
  250.       png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
  251.  
  252.       if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
  253.          return (info_ptr->x_offset);
  254.    }
  255. #endif
  256.  
  257.    return (0);
  258. }
  259.  
  260. png_int_32 PNGAPI
  261. png_get_y_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr)
  262. {
  263. #ifdef PNG_oFFs_SUPPORTED
  264.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  265.    {
  266.       png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
  267.  
  268.       if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
  269.          return (info_ptr->y_offset);
  270.    }
  271. #endif
  272.  
  273.    return (0);
  274. }
  275.  
  276. #ifdef PNG_INCH_CONVERSIONS_SUPPORTED
  277. static png_uint_32
  278. ppi_from_ppm(png_uint_32 ppm)
  279. {
  280. #if 0
  281.    /* The conversion is *(2.54/100), in binary (32 digits):
  282.     * .00000110100000001001110101001001
  283.     */
  284.    png_uint_32 t1001, t1101;
  285.    ppm >>= 1;                  /* .1 */
  286.    t1001 = ppm + (ppm >> 3);   /* .1001 */
  287.    t1101 = t1001 + (ppm >> 1); /* .1101 */
  288.    ppm >>= 20;                 /* .000000000000000000001 */
  289.    t1101 += t1101 >> 15;       /* .1101000000000001101 */
  290.    t1001 >>= 11;               /* .000000000001001 */
  291.    t1001 += t1001 >> 12;       /* .000000000001001000000001001 */
  292.    ppm += t1001;               /* .000000000001001000001001001 */
  293.    ppm += t1101;               /* .110100000001001110101001001 */
  294.    return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
  295. #else
  296.    /* The argument is a PNG unsigned integer, so it is not permitted
  297.     * to be bigger than 2^31.
  298.     */
  299.    png_fixed_point result;
  300.    if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
  301.        5000))
  302.       return result;
  303.  
  304.    /* Overflow. */
  305.    return 0;
  306. #endif
  307. }
  308.  
  309. png_uint_32 PNGAPI
  310. png_get_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
  311. {
  312.    return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
  313. }
  314.  
  315. png_uint_32 PNGAPI
  316. png_get_x_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
  317. {
  318.    return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
  319. }
  320.  
  321. png_uint_32 PNGAPI
  322. png_get_y_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
  323. {
  324.    return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
  325. }
  326.  
  327. #ifdef PNG_FIXED_POINT_SUPPORTED
  328. static png_fixed_point
  329. png_fixed_inches_from_microns(png_structp png_ptr, png_int_32 microns)
  330. {
  331.    /* Convert from metres * 1,000,000 to inches * 100,000, meters to
  332.     * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
  333.     * Notice that this can overflow - a warning is output and 0 is
  334.     * returned.
  335.     */
  336.    return png_muldiv_warn(png_ptr, microns, 500, 127);
  337. }
  338.  
  339. png_fixed_point PNGAPI
  340. png_get_x_offset_inches_fixed(png_structp png_ptr,
  341.     png_const_infop info_ptr)
  342. {
  343.    return png_fixed_inches_from_microns(png_ptr,
  344.        png_get_x_offset_microns(png_ptr, info_ptr));
  345. }
  346. #endif
  347.  
  348. #ifdef PNG_FIXED_POINT_SUPPORTED
  349. png_fixed_point PNGAPI
  350. png_get_y_offset_inches_fixed(png_structp png_ptr,
  351.     png_const_infop info_ptr)
  352. {
  353.    return png_fixed_inches_from_microns(png_ptr,
  354.        png_get_y_offset_microns(png_ptr, info_ptr));
  355. }
  356. #endif
  357.  
  358. #ifdef PNG_FLOATING_POINT_SUPPORTED
  359. float PNGAPI
  360. png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr)
  361. {
  362.    /* To avoid the overflow do the conversion directly in floating
  363.     * point.
  364.     */
  365.    return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
  366. }
  367. #endif
  368.  
  369. #ifdef PNG_FLOATING_POINT_SUPPORTED
  370. float PNGAPI
  371. png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr)
  372. {
  373.    /* To avoid the overflow do the conversion directly in floating
  374.     * point.
  375.     */
  376.    return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
  377. }
  378. #endif
  379.  
  380. #ifdef PNG_pHYs_SUPPORTED
  381. png_uint_32 PNGAPI
  382. png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr,
  383.     png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  384. {
  385.    png_uint_32 retval = 0;
  386.  
  387.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  388.    {
  389.       png_debug1(1, "in %s retrieval function", "pHYs");
  390.  
  391.       if (res_x != NULL)
  392.       {
  393.          *res_x = info_ptr->x_pixels_per_unit;
  394.          retval |= PNG_INFO_pHYs;
  395.       }
  396.  
  397.       if (res_y != NULL)
  398.       {
  399.          *res_y = info_ptr->y_pixels_per_unit;
  400.          retval |= PNG_INFO_pHYs;
  401.       }
  402.  
  403.       if (unit_type != NULL)
  404.       {
  405.          *unit_type = (int)info_ptr->phys_unit_type;
  406.          retval |= PNG_INFO_pHYs;
  407.  
  408.          if (*unit_type == 1)
  409.          {
  410.             if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  411.             if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  412.          }
  413.       }
  414.    }
  415.  
  416.    return (retval);
  417. }
  418. #endif /* PNG_pHYs_SUPPORTED */
  419. #endif  /* PNG_INCH_CONVERSIONS_SUPPORTED */
  420.  
  421. /* png_get_channels really belongs in here, too, but it's been around longer */
  422.  
  423. #endif  /* PNG_EASY_ACCESS_SUPPORTED */
  424.  
  425. png_byte PNGAPI
  426. png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr)
  427. {
  428.    if (png_ptr != NULL && info_ptr != NULL)
  429.       return(info_ptr->channels);
  430.  
  431.    return (0);
  432. }
  433.  
  434. png_const_bytep PNGAPI
  435. png_get_signature(png_const_structp png_ptr, png_infop info_ptr)
  436. {
  437.    if (png_ptr != NULL && info_ptr != NULL)
  438.       return(info_ptr->signature);
  439.  
  440.    return (NULL);
  441. }
  442.  
  443. #ifdef PNG_bKGD_SUPPORTED
  444. png_uint_32 PNGAPI
  445. png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr,
  446.    png_color_16p *background)
  447. {
  448.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  449.        && background != NULL)
  450.    {
  451.       png_debug1(1, "in %s retrieval function", "bKGD");
  452.  
  453.       *background = &(info_ptr->background);
  454.       return (PNG_INFO_bKGD);
  455.    }
  456.  
  457.    return (0);
  458. }
  459. #endif
  460.  
  461. #ifdef PNG_cHRM_SUPPORTED
  462. #  ifdef PNG_FLOATING_POINT_SUPPORTED
  463. png_uint_32 PNGAPI
  464. png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr,
  465.     double *white_x, double *white_y, double *red_x, double *red_y,
  466.     double *green_x, double *green_y, double *blue_x, double *blue_y)
  467. {
  468.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  469.    {
  470.       png_debug1(1, "in %s retrieval function", "cHRM");
  471.  
  472.       if (white_x != NULL)
  473.          *white_x = png_float(png_ptr, info_ptr->x_white, "cHRM white X");
  474.       if (white_y != NULL)
  475.          *white_y = png_float(png_ptr, info_ptr->y_white, "cHRM white Y");
  476.       if (red_x != NULL)
  477.          *red_x = png_float(png_ptr, info_ptr->x_red, "cHRM red X");
  478.       if (red_y != NULL)
  479.          *red_y = png_float(png_ptr, info_ptr->y_red, "cHRM red Y");
  480.       if (green_x != NULL)
  481.          *green_x = png_float(png_ptr, info_ptr->x_green, "cHRM green X");
  482.       if (green_y != NULL)
  483.          *green_y = png_float(png_ptr, info_ptr->y_green, "cHRM green Y");
  484.       if (blue_x != NULL)
  485.          *blue_x = png_float(png_ptr, info_ptr->x_blue, "cHRM blue X");
  486.       if (blue_y != NULL)
  487.          *blue_y = png_float(png_ptr, info_ptr->y_blue, "cHRM blue Y");
  488.       return (PNG_INFO_cHRM);
  489.    }
  490.  
  491.    return (0);
  492. }
  493. #  endif
  494.  
  495. #  ifdef PNG_FIXED_POINT_SUPPORTED
  496. png_uint_32 PNGAPI
  497. png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr,
  498.     png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  499.     png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  500.     png_fixed_point *blue_x, png_fixed_point *blue_y)
  501. {
  502.    png_debug1(1, "in %s retrieval function", "cHRM");
  503.  
  504.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  505.    {
  506.       if (white_x != NULL)
  507.          *white_x = info_ptr->x_white;
  508.       if (white_y != NULL)
  509.          *white_y = info_ptr->y_white;
  510.       if (red_x != NULL)
  511.          *red_x = info_ptr->x_red;
  512.       if (red_y != NULL)
  513.          *red_y = info_ptr->y_red;
  514.       if (green_x != NULL)
  515.          *green_x = info_ptr->x_green;
  516.       if (green_y != NULL)
  517.          *green_y = info_ptr->y_green;
  518.       if (blue_x != NULL)
  519.          *blue_x = info_ptr->x_blue;
  520.       if (blue_y != NULL)
  521.          *blue_y = info_ptr->y_blue;
  522.       return (PNG_INFO_cHRM);
  523.    }
  524.  
  525.    return (0);
  526. }
  527. #  endif
  528. #endif
  529.  
  530. #ifdef PNG_gAMA_SUPPORTED
  531. png_uint_32 PNGFAPI
  532. png_get_gAMA_fixed(png_const_structp png_ptr, png_const_infop info_ptr,
  533.     png_fixed_point *file_gamma)
  534. {
  535.    png_debug1(1, "in %s retrieval function", "gAMA");
  536.  
  537.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  538.        && file_gamma != NULL)
  539.    {
  540.       *file_gamma = info_ptr->gamma;
  541.       return (PNG_INFO_gAMA);
  542.    }
  543.  
  544.    return (0);
  545. }
  546. #  ifdef PNG_FLOATING_POINT_SUPPORTED
  547. png_uint_32 PNGAPI
  548. png_get_gAMA(png_const_structp png_ptr, png_const_infop info_ptr,
  549.     double *file_gamma)
  550. {
  551.    png_fixed_point igamma;
  552.    png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma);
  553.  
  554.    if (ok)
  555.       *file_gamma = png_float(png_ptr, igamma, "png_get_gAMA");
  556.  
  557.    return ok;
  558. }
  559.  
  560. #  endif
  561. #endif
  562.  
  563. #ifdef PNG_sRGB_SUPPORTED
  564. png_uint_32 PNGAPI
  565. png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr,
  566.     int *file_srgb_intent)
  567. {
  568.    png_debug1(1, "in %s retrieval function", "sRGB");
  569.  
  570.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  571.        && file_srgb_intent != NULL)
  572.    {
  573.       *file_srgb_intent = (int)info_ptr->srgb_intent;
  574.       return (PNG_INFO_sRGB);
  575.    }
  576.  
  577.    return (0);
  578. }
  579. #endif
  580.  
  581. #ifdef PNG_iCCP_SUPPORTED
  582. png_uint_32 PNGAPI
  583. png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr,
  584.     png_charpp name, int *compression_type,
  585.     png_bytepp profile, png_uint_32 *proflen)
  586. {
  587.    png_debug1(1, "in %s retrieval function", "iCCP");
  588.  
  589.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  590.        && name != NULL && profile != NULL && proflen != NULL)
  591.    {
  592.       *name = info_ptr->iccp_name;
  593.       *profile = info_ptr->iccp_profile;
  594.       /* Compression_type is a dummy so the API won't have to change
  595.        * if we introduce multiple compression types later.
  596.        */
  597.       *proflen = (int)info_ptr->iccp_proflen;
  598.       *compression_type = (int)info_ptr->iccp_compression;
  599.       return (PNG_INFO_iCCP);
  600.    }
  601.  
  602.    return (0);
  603. }
  604. #endif
  605.  
  606. #ifdef PNG_sPLT_SUPPORTED
  607. png_uint_32 PNGAPI
  608. png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr,
  609.     png_sPLT_tpp spalettes)
  610. {
  611.    if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  612.    {
  613.       *spalettes = info_ptr->splt_palettes;
  614.       return ((png_uint_32)info_ptr->splt_palettes_num);
  615.    }
  616.  
  617.    return (0);
  618. }
  619. #endif
  620.  
  621. #ifdef PNG_hIST_SUPPORTED
  622. png_uint_32 PNGAPI
  623. png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr,
  624.     png_uint_16p *hist)
  625. {
  626.    png_debug1(1, "in %s retrieval function", "hIST");
  627.  
  628.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  629.        && hist != NULL)
  630.    {
  631.       *hist = info_ptr->hist;
  632.       return (PNG_INFO_hIST);
  633.    }
  634.  
  635.    return (0);
  636. }
  637. #endif
  638.  
  639. png_uint_32 PNGAPI
  640. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  641.     png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  642.     int *color_type, int *interlace_type, int *compression_type,
  643.     int *filter_type)
  644.  
  645. {
  646.    png_debug1(1, "in %s retrieval function", "IHDR");
  647.  
  648.    if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
  649.        height == NULL || bit_depth == NULL || color_type == NULL)
  650.       return (0);
  651.  
  652.    *width = info_ptr->width;
  653.    *height = info_ptr->height;
  654.    *bit_depth = info_ptr->bit_depth;
  655.    *color_type = info_ptr->color_type;
  656.  
  657.    if (compression_type != NULL)
  658.       *compression_type = info_ptr->compression_type;
  659.  
  660.    if (filter_type != NULL)
  661.       *filter_type = info_ptr->filter_type;
  662.  
  663.    if (interlace_type != NULL)
  664.       *interlace_type = info_ptr->interlace_type;
  665.  
  666.    /* This is redundant if we can be sure that the info_ptr values were all
  667.     * assigned in png_set_IHDR().  We do the check anyhow in case an
  668.     * application has ignored our advice not to mess with the members
  669.     * of info_ptr directly.
  670.     */
  671.    png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
  672.        info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
  673.        info_ptr->compression_type, info_ptr->filter_type);
  674.  
  675.    return (1);
  676. }
  677.  
  678. #ifdef PNG_oFFs_SUPPORTED
  679. png_uint_32 PNGAPI
  680. png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr,
  681.     png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  682. {
  683.    png_debug1(1, "in %s retrieval function", "oFFs");
  684.  
  685.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  686.        && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  687.    {
  688.       *offset_x = info_ptr->x_offset;
  689.       *offset_y = info_ptr->y_offset;
  690.       *unit_type = (int)info_ptr->offset_unit_type;
  691.       return (PNG_INFO_oFFs);
  692.    }
  693.  
  694.    return (0);
  695. }
  696. #endif
  697.  
  698. #ifdef PNG_pCAL_SUPPORTED
  699. png_uint_32 PNGAPI
  700. png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr,
  701.     png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  702.     png_charp *units, png_charpp *params)
  703. {
  704.    png_debug1(1, "in %s retrieval function", "pCAL");
  705.  
  706.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  707.        && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  708.        nparams != NULL && units != NULL && params != NULL)
  709.    {
  710.       *purpose = info_ptr->pcal_purpose;
  711.       *X0 = info_ptr->pcal_X0;
  712.       *X1 = info_ptr->pcal_X1;
  713.       *type = (int)info_ptr->pcal_type;
  714.       *nparams = (int)info_ptr->pcal_nparams;
  715.       *units = info_ptr->pcal_units;
  716.       *params = info_ptr->pcal_params;
  717.       return (PNG_INFO_pCAL);
  718.    }
  719.  
  720.    return (0);
  721. }
  722. #endif
  723.  
  724. #ifdef PNG_sCAL_SUPPORTED
  725. #  ifdef PNG_FIXED_POINT_SUPPORTED
  726. #    ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
  727. png_uint_32 PNGAPI
  728. png_get_sCAL_fixed(png_structp png_ptr, png_const_infop info_ptr,
  729.     int *unit, png_fixed_point *width, png_fixed_point *height)
  730. {
  731.    if (png_ptr != NULL && info_ptr != NULL &&
  732.        (info_ptr->valid & PNG_INFO_sCAL))
  733.    {
  734.       *unit = info_ptr->scal_unit;
  735.       /*TODO: make this work without FP support */
  736.       *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
  737.       *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
  738.          "sCAL height");
  739.       return (PNG_INFO_sCAL);
  740.    }
  741.  
  742.    return(0);
  743. }
  744. #    endif /* FLOATING_ARITHMETIC */
  745. #  endif /* FIXED_POINT */
  746. #  ifdef PNG_FLOATING_POINT_SUPPORTED
  747. png_uint_32 PNGAPI
  748. png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr,
  749.     int *unit, double *width, double *height)
  750. {
  751.    if (png_ptr != NULL && info_ptr != NULL &&
  752.        (info_ptr->valid & PNG_INFO_sCAL))
  753.    {
  754.       *unit = info_ptr->scal_unit;
  755.       *width = atof(info_ptr->scal_s_width);
  756.       *height = atof(info_ptr->scal_s_height);
  757.       return (PNG_INFO_sCAL);
  758.    }
  759.  
  760.    return(0);
  761. }
  762. #  endif /* FLOATING POINT */
  763. png_uint_32 PNGAPI
  764. png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr,
  765.     int *unit, png_charpp width, png_charpp height)
  766. {
  767.    if (png_ptr != NULL && info_ptr != NULL &&
  768.        (info_ptr->valid & PNG_INFO_sCAL))
  769.    {
  770.       *unit = info_ptr->scal_unit;
  771.       *width = info_ptr->scal_s_width;
  772.       *height = info_ptr->scal_s_height;
  773.       return (PNG_INFO_sCAL);
  774.    }
  775.  
  776.    return(0);
  777. }
  778. #endif /* sCAL */
  779.  
  780. #ifdef PNG_pHYs_SUPPORTED
  781. png_uint_32 PNGAPI
  782. png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr,
  783.     png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  784. {
  785.    png_uint_32 retval = 0;
  786.  
  787.    png_debug1(1, "in %s retrieval function", "pHYs");
  788.  
  789.    if (png_ptr != NULL && info_ptr != NULL &&
  790.        (info_ptr->valid & PNG_INFO_pHYs))
  791.    {
  792.       if (res_x != NULL)
  793.       {
  794.          *res_x = info_ptr->x_pixels_per_unit;
  795.          retval |= PNG_INFO_pHYs;
  796.       }
  797.  
  798.       if (res_y != NULL)
  799.       {
  800.          *res_y = info_ptr->y_pixels_per_unit;
  801.          retval |= PNG_INFO_pHYs;
  802.       }
  803.  
  804.       if (unit_type != NULL)
  805.       {
  806.          *unit_type = (int)info_ptr->phys_unit_type;
  807.          retval |= PNG_INFO_pHYs;
  808.       }
  809.    }
  810.  
  811.    return (retval);
  812. }
  813. #endif /* pHYs */
  814.  
  815. png_uint_32 PNGAPI
  816. png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr,
  817.     png_colorp *palette, int *num_palette)
  818. {
  819.    png_debug1(1, "in %s retrieval function", "PLTE");
  820.  
  821.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  822.        && palette != NULL)
  823.    {
  824.       *palette = info_ptr->palette;
  825.       *num_palette = info_ptr->num_palette;
  826.       png_debug1(3, "num_palette = %d", *num_palette);
  827.       return (PNG_INFO_PLTE);
  828.    }
  829.  
  830.    return (0);
  831. }
  832.  
  833. #ifdef PNG_sBIT_SUPPORTED
  834. png_uint_32 PNGAPI
  835. png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr,
  836.     png_color_8p *sig_bit)
  837. {
  838.    png_debug1(1, "in %s retrieval function", "sBIT");
  839.  
  840.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  841.        && sig_bit != NULL)
  842.    {
  843.       *sig_bit = &(info_ptr->sig_bit);
  844.       return (PNG_INFO_sBIT);
  845.    }
  846.  
  847.    return (0);
  848. }
  849. #endif
  850.  
  851. #ifdef PNG_TEXT_SUPPORTED
  852. png_uint_32 PNGAPI
  853. png_get_text(png_const_structp png_ptr, png_const_infop info_ptr,
  854.     png_textp *text_ptr, int *num_text)
  855. {
  856.    if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  857.    {
  858.       png_debug1(1, "in %s retrieval function",
  859.           (png_ptr->chunk_name[0] == '\0' ? "text" :
  860.           (png_const_charp)png_ptr->chunk_name));
  861.  
  862.       if (text_ptr != NULL)
  863.          *text_ptr = info_ptr->text;
  864.  
  865.       if (num_text != NULL)
  866.          *num_text = info_ptr->num_text;
  867.  
  868.       return ((png_uint_32)info_ptr->num_text);
  869.    }
  870.  
  871.    if (num_text != NULL)
  872.       *num_text = 0;
  873.  
  874.    return(0);
  875. }
  876. #endif
  877.  
  878. #ifdef PNG_tIME_SUPPORTED
  879. png_uint_32 PNGAPI
  880. png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  881. {
  882.    png_debug1(1, "in %s retrieval function", "tIME");
  883.  
  884.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  885.        && mod_time != NULL)
  886.    {
  887.       *mod_time = &(info_ptr->mod_time);
  888.       return (PNG_INFO_tIME);
  889.    }
  890.  
  891.    return (0);
  892. }
  893. #endif
  894.  
  895. #ifdef PNG_tRNS_SUPPORTED
  896. png_uint_32 PNGAPI
  897. png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr,
  898.     png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
  899. {
  900.    png_uint_32 retval = 0;
  901.    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  902.    {
  903.       png_debug1(1, "in %s retrieval function", "tRNS");
  904.  
  905.       if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  906.       {
  907.          if (trans_alpha != NULL)
  908.          {
  909.             *trans_alpha = info_ptr->trans_alpha;
  910.             retval |= PNG_INFO_tRNS;
  911.          }
  912.  
  913.          if (trans_color != NULL)
  914.             *trans_color = &(info_ptr->trans_color);
  915.       }
  916.  
  917.       else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  918.       {
  919.          if (trans_color != NULL)
  920.          {
  921.             *trans_color = &(info_ptr->trans_color);
  922.             retval |= PNG_INFO_tRNS;
  923.          }
  924.  
  925.          if (trans_alpha != NULL)
  926.             *trans_alpha = NULL;
  927.       }
  928.  
  929.       if (num_trans != NULL)
  930.       {
  931.          *num_trans = info_ptr->num_trans;
  932.          retval |= PNG_INFO_tRNS;
  933.       }
  934.    }
  935.  
  936.    return (retval);
  937. }
  938. #endif
  939.  
  940. #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
  941. int PNGAPI
  942. png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr,
  943.     png_unknown_chunkpp unknowns)
  944. {
  945.    if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  946.    {
  947.       *unknowns = info_ptr->unknown_chunks;
  948.       return info_ptr->unknown_chunks_num;
  949.    }
  950.  
  951.    return (0);
  952. }
  953. #endif
  954.  
  955. #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  956. png_byte PNGAPI
  957. png_get_rgb_to_gray_status (png_const_structp png_ptr)
  958. {
  959.    return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
  960. }
  961. #endif
  962.  
  963. #ifdef PNG_USER_CHUNKS_SUPPORTED
  964. png_voidp PNGAPI
  965. png_get_user_chunk_ptr(png_const_structp png_ptr)
  966. {
  967.    return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
  968. }
  969. #endif
  970.  
  971. png_size_t PNGAPI
  972. png_get_compression_buffer_size(png_const_structp png_ptr)
  973. {
  974.    return (png_ptr ? png_ptr->zbuf_size : 0L);
  975. }
  976.  
  977.  
  978. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  979. /* These functions were added to libpng 1.2.6 and were enabled
  980.  * by default in libpng-1.4.0 */
  981. png_uint_32 PNGAPI
  982. png_get_user_width_max (png_const_structp png_ptr)
  983. {
  984.    return (png_ptr ? png_ptr->user_width_max : 0);
  985. }
  986.  
  987. png_uint_32 PNGAPI
  988. png_get_user_height_max (png_const_structp png_ptr)
  989. {
  990.    return (png_ptr ? png_ptr->user_height_max : 0);
  991. }
  992.  
  993. /* This function was added to libpng 1.4.0 */
  994. png_uint_32 PNGAPI
  995. png_get_chunk_cache_max (png_const_structp png_ptr)
  996. {
  997.    return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
  998. }
  999.  
  1000. /* This function was added to libpng 1.4.1 */
  1001. png_alloc_size_t PNGAPI
  1002. png_get_chunk_malloc_max (png_const_structp png_ptr)
  1003. {
  1004.    return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
  1005. }
  1006. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  1007.  
  1008. /* These functions were added to libpng 1.4.0 */
  1009. #ifdef PNG_IO_STATE_SUPPORTED
  1010. png_uint_32 PNGAPI
  1011. png_get_io_state (png_structp png_ptr)
  1012. {
  1013.    return png_ptr->io_state;
  1014. }
  1015.  
  1016. png_uint_32 PNGAPI
  1017. png_get_io_chunk_type (png_const_structp png_ptr)
  1018. {
  1019.    return ((png_ptr->chunk_name[0] << 24) +
  1020.            (png_ptr->chunk_name[1] << 16) +
  1021.            (png_ptr->chunk_name[2] <<  8) +
  1022.            (png_ptr->chunk_name[3]));
  1023. }
  1024.  
  1025. png_const_bytep PNGAPI
  1026. png_get_io_chunk_name (png_structp png_ptr)
  1027. {
  1028.    return png_ptr->chunk_name;
  1029. }
  1030. #endif /* ?PNG_IO_STATE_SUPPORTED */
  1031.  
  1032. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  1033.