blob: 14fc7be520567d108450a02e38980d4049560153 [file] [log] [blame]
Andreas Dilger47a0c421997-05-16 02:46:07 -05001
2/* pngget.c - retrieval of values from info struct
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06003 *
Glenn Randers-Pehrsonc98f7fb2015-03-26 08:06:25 -05004 * Last changed in libpng 1.6.17 [March 26, 2015]
Glenn Randers-Pehrson4d8de332015-12-13 22:41:17 -06005 * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05006 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Glenn Randers-Pehrson3e61d792009-06-24 09:31:28 -05008 *
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -05009 * This code is released under the libpng license.
Glenn Randers-Pehrsonc332bbc2009-06-25 13:43:50 -050010 * For conditions of distribution and use, see the disclaimer
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -050011 * and license in png.h
Glenn Randers-Pehrson3e61d792009-06-24 09:31:28 -050012 *
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060013 */
Andreas Dilger47a0c421997-05-16 02:46:07 -050014
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050015#include "pngpriv.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060016
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060017#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
18
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050019png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -060020png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -060021 png_uint_32 flag)
Andreas Dilger47a0c421997-05-16 02:46:07 -050022{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060023 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050024 return(info_ptr->valid & flag);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050025
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -050026 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -050027}
28
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050029png_size_t PNGAPI
John Bowler5d567862011-12-24 09:12:00 -060030png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
Andreas Dilger47a0c421997-05-16 02:46:07 -050031{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060032 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050033 return(info_ptr->rowbytes);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050034
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -050035 return(0);
Andreas Dilger47a0c421997-05-16 02:46:07 -050036}
37
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -050038#ifdef PNG_INFO_IMAGE_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050039png_bytepp PNGAPI
John Bowler5d567862011-12-24 09:12:00 -060040png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060041{
42 if (png_ptr != NULL && info_ptr != NULL)
43 return(info_ptr->row_pointers);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050044
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -050045 return(0);
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060046}
47#endif
48
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060049#ifdef PNG_EASY_ACCESS_SUPPORTED
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050050/* Easy access to info, added in libpng-0.99 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050051png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -060052png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060053{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060054 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060055 return info_ptr->width;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050056
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060057 return (0);
58}
59
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050060png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -060061png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060062{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060063 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060064 return info_ptr->height;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050065
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060066 return (0);
67}
68
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050069png_byte PNGAPI
John Bowler5d567862011-12-24 09:12:00 -060070png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060071{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060072 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060073 return info_ptr->bit_depth;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050074
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060075 return (0);
76}
77
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050078png_byte PNGAPI
John Bowler5d567862011-12-24 09:12:00 -060079png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060080{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060081 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060082 return info_ptr->color_type;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050083
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060084 return (0);
85}
86
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050087png_byte PNGAPI
John Bowler5d567862011-12-24 09:12:00 -060088png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060089{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060090 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060091 return info_ptr->filter_type;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050092
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060093 return (0);
94}
95
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050096png_byte PNGAPI
John Bowler5d567862011-12-24 09:12:00 -060097png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060098{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060099 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600100 return info_ptr->interlace_type;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500101
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600102 return (0);
103}
104
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500105png_byte PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600106png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600107{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600108 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600109 return info_ptr->compression_type;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500110
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600111 return (0);
112}
113
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500114png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600115png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
116 info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600117{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500118#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500119 if (png_ptr != NULL && info_ptr != NULL &&
120 (info_ptr->valid & PNG_INFO_pHYs) != 0)
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500121 {
122 png_debug1(1, "in %s retrieval function",
123 "png_get_x_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500124
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500125 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
126 return (info_ptr->x_pixels_per_unit);
127 }
Cosmin Truta6572c7d2014-03-22 09:20:53 -0500128#else
129 PNG_UNUSED(png_ptr)
130 PNG_UNUSED(info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600131#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500132
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600133 return (0);
134}
135
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500136png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600137png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
138 info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600139{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500140#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500141 if (png_ptr != NULL && info_ptr != NULL &&
142 (info_ptr->valid & PNG_INFO_pHYs) != 0)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600143 {
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500144 png_debug1(1, "in %s retrieval function",
145 "png_get_y_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500146
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500147 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600148 return (info_ptr->y_pixels_per_unit);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600149 }
Cosmin Truta6572c7d2014-03-22 09:20:53 -0500150#else
151 PNG_UNUSED(png_ptr)
152 PNG_UNUSED(info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600153#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500154
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600155 return (0);
156}
157
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500158png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600159png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600160{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500161#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500162 if (png_ptr != NULL && info_ptr != NULL &&
163 (info_ptr->valid & PNG_INFO_pHYs) != 0)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600164 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500165 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500166
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500167 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
168 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600169 return (info_ptr->x_pixels_per_unit);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600170 }
Cosmin Truta6572c7d2014-03-22 09:20:53 -0500171#else
172 PNG_UNUSED(png_ptr)
173 PNG_UNUSED(info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600174#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500175
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600176 return (0);
177}
178
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600179#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500180float PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600181png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
182 info_ptr)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600183{
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500184#ifdef PNG_READ_pHYs_SUPPORTED
Glenn Randers-Pehrsonb963fee2014-11-01 13:18:36 -0500185 if (png_ptr != NULL && info_ptr != NULL &&
186 (info_ptr->valid & PNG_INFO_pHYs) != 0)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600187 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500188 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500189
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500190 if (info_ptr->x_pixels_per_unit != 0)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500191 return ((float)((float)info_ptr->y_pixels_per_unit
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600192 /(float)info_ptr->x_pixels_per_unit));
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600193 }
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600194#else
195 PNG_UNUSED(png_ptr)
196 PNG_UNUSED(info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600197#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500198
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500199 return ((float)0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600200}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600201#endif
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600202
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500203#ifdef PNG_FIXED_POINT_SUPPORTED
204png_fixed_point PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600205png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
206 png_const_inforp info_ptr)
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500207{
208#ifdef PNG_READ_pHYs_SUPPORTED
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500209 if (png_ptr != NULL && info_ptr != NULL &&
210 (info_ptr->valid & PNG_INFO_pHYs) != 0 &&
211 info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 &&
212 info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX &&
213 info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500214 {
215 png_fixed_point res;
216
217 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
218
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500219 /* The following casts work because a PNG 4 byte integer only has a valid
220 * range of 0..2^31-1; otherwise the cast might overflow.
221 */
222 if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500223 (png_int_32)info_ptr->x_pixels_per_unit) != 0)
Glenn Randers-Pehrson3df324d2010-07-31 13:45:04 -0500224 return res;
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500225 }
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600226#else
227 PNG_UNUSED(png_ptr)
228 PNG_UNUSED(info_ptr)
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500229#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500230
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500231 return 0;
232}
233#endif
234
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500235png_int_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600236png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600237{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500238#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500239 if (png_ptr != NULL && info_ptr != NULL &&
240 (info_ptr->valid & PNG_INFO_oFFs) != 0)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600241 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500242 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500243
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500244 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600245 return (info_ptr->x_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600246 }
Cosmin Truta6572c7d2014-03-22 09:20:53 -0500247#else
248 PNG_UNUSED(png_ptr)
249 PNG_UNUSED(info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600250#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500251
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600252 return (0);
253}
254
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500255png_int_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600256png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600257{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500258#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500259 if (png_ptr != NULL && info_ptr != NULL &&
260 (info_ptr->valid & PNG_INFO_oFFs) != 0)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600261 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500262 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500263
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500264 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600265 return (info_ptr->y_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600266 }
Cosmin Truta6572c7d2014-03-22 09:20:53 -0500267#else
268 PNG_UNUSED(png_ptr)
269 PNG_UNUSED(info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600270#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500271
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600272 return (0);
273}
274
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500275png_int_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600276png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600277{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500278#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500279 if (png_ptr != NULL && info_ptr != NULL &&
280 (info_ptr->valid & PNG_INFO_oFFs) != 0)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600281 {
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500282 png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500283
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500284 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600285 return (info_ptr->x_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600286 }
Cosmin Truta6572c7d2014-03-22 09:20:53 -0500287#else
288 PNG_UNUSED(png_ptr)
289 PNG_UNUSED(info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600290#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500291
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600292 return (0);
293}
294
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500295png_int_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600296png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600297{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500298#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500299 if (png_ptr != NULL && info_ptr != NULL &&
300 (info_ptr->valid & PNG_INFO_oFFs) != 0)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600301 {
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500302 png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500303
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500304 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600305 return (info_ptr->y_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600306 }
Cosmin Truta6572c7d2014-03-22 09:20:53 -0500307#else
308 PNG_UNUSED(png_ptr)
309 PNG_UNUSED(info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600310#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500311
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600312 return (0);
313}
314
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500315#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
316static png_uint_32
317ppi_from_ppm(png_uint_32 ppm)
318{
319#if 0
Glenn Randers-Pehrson233357e2010-07-29 21:49:38 -0500320 /* The conversion is *(2.54/100), in binary (32 digits):
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500321 * .00000110100000001001110101001001
322 */
323 png_uint_32 t1001, t1101;
324 ppm >>= 1; /* .1 */
325 t1001 = ppm + (ppm >> 3); /* .1001 */
326 t1101 = t1001 + (ppm >> 1); /* .1101 */
327 ppm >>= 20; /* .000000000000000000001 */
328 t1101 += t1101 >> 15; /* .1101000000000001101 */
329 t1001 >>= 11; /* .000000000001001 */
330 t1001 += t1001 >> 12; /* .000000000001001000000001001 */
331 ppm += t1001; /* .000000000001001000001001001 */
332 ppm += t1101; /* .110100000001001110101001001 */
333 return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
334#else
335 /* The argument is a PNG unsigned integer, so it is not permitted
336 * to be bigger than 2^31.
337 */
338 png_fixed_point result;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500339 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500340 5000) != 0)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500341 return result;
342
343 /* Overflow. */
344 return 0;
345#endif
346}
347
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500348png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600349png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600350{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500351 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600352}
353
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500354png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600355png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600356{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500357 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600358}
359
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500360png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600361png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600362{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500363 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600364}
365
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500366#ifdef PNG_FIXED_POINT_SUPPORTED
367static png_fixed_point
John Bowler5d567862011-12-24 09:12:00 -0600368png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500369{
370 /* Convert from metres * 1,000,000 to inches * 100,000, meters to
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500371 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500372 * Notice that this can overflow - a warning is output and 0 is
373 * returned.
374 */
375 return png_muldiv_warn(png_ptr, microns, 500, 127);
376}
377
378png_fixed_point PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600379png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
380 png_const_inforp info_ptr)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500381{
382 return png_fixed_inches_from_microns(png_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500383 png_get_x_offset_microns(png_ptr, info_ptr));
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500384}
385#endif
386
387#ifdef PNG_FIXED_POINT_SUPPORTED
388png_fixed_point PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600389png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
390 png_const_inforp info_ptr)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500391{
392 return png_fixed_inches_from_microns(png_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500393 png_get_y_offset_microns(png_ptr, info_ptr));
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500394}
395#endif
396
397#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500398float PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600399png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600400{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500401 /* To avoid the overflow do the conversion directly in floating
402 * point.
403 */
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500404 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600405}
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500406#endif
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600407
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500408#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500409float PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600410png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600411{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500412 /* To avoid the overflow do the conversion directly in floating
413 * point.
414 */
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500415 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600416}
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500417#endif
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600418
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500419#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500420png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600421png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600422 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600423{
424 png_uint_32 retval = 0;
425
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500426 if (png_ptr != NULL && info_ptr != NULL &&
427 (info_ptr->valid & PNG_INFO_pHYs) != 0)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600428 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500429 png_debug1(1, "in %s retrieval function", "pHYs");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500430
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600431 if (res_x != NULL)
432 {
433 *res_x = info_ptr->x_pixels_per_unit;
434 retval |= PNG_INFO_pHYs;
435 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500436
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600437 if (res_y != NULL)
438 {
439 *res_y = info_ptr->y_pixels_per_unit;
440 retval |= PNG_INFO_pHYs;
441 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500442
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600443 if (unit_type != NULL)
444 {
445 *unit_type = (int)info_ptr->phys_unit_type;
446 retval |= PNG_INFO_pHYs;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500447
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500448 if (*unit_type == 1)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600449 {
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600450 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
451 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600452 }
453 }
454 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500455
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600456 return (retval);
457}
Glenn Randers-Pehrsoncda68df2014-11-06 22:11:39 -0600458#endif /* pHYs */
Glenn Randers-Pehrson92952642016-03-07 07:17:28 -0600459#endif /* INCH_CONVERSIONS */
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600460
461/* png_get_channels really belongs in here, too, but it's been around longer */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500462
Glenn Randers-Pehrson92952642016-03-07 07:17:28 -0600463#endif /* EASY_ACCESS */
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600464
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600465
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500466png_byte PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600467png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500468{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600469 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500470 return(info_ptr->channels);
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500471
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500472 return (0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500473}
474
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600475#ifdef PNG_READ_SUPPORTED
Glenn Randers-Pehrsone600c512010-08-18 07:25:46 -0500476png_const_bytep PNGAPI
John Bowler4f67e402011-12-28 08:43:37 -0600477png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500478{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600479 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500480 return(info_ptr->signature);
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500481
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500482 return (NULL);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500483}
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600484#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500485
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500486#ifdef PNG_bKGD_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500487png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600488png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
Andreas Dilger47a0c421997-05-16 02:46:07 -0500489 png_color_16p *background)
490{
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500491 if (png_ptr != NULL && info_ptr != NULL &&
492 (info_ptr->valid & PNG_INFO_bKGD) != 0 &&
493 background != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500494 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500495 png_debug1(1, "in %s retrieval function", "bKGD");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500496
Andreas Dilger47a0c421997-05-16 02:46:07 -0500497 *background = &(info_ptr->background);
498 return (PNG_INFO_bKGD);
499 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500500
Andreas Dilger47a0c421997-05-16 02:46:07 -0500501 return (0);
502}
503#endif
504
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500505#ifdef PNG_cHRM_SUPPORTED
John Bowler736f40f2011-08-25 16:19:44 -0500506/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
507 * same time to correct the rgb grayscale coefficient defaults obtained from the
508 * cHRM chunk in 1.5.4
509 */
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500510# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500511png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600512png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600513 double *white_x, double *white_y, double *red_x, double *red_y,
514 double *green_x, double *green_y, double *blue_x, double *blue_y)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500515{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600516 /* Quiet API change: this code used to only return the end points if a cHRM
517 * chunk was present, but the end points can also come from iCCP or sRGB
518 * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and
519 * the png_set_ APIs merely check that set end points are mutually
520 * consistent.
521 */
522 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500523 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500524 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500525 png_debug1(1, "in %s retrieval function", "cHRM");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500526
Andreas Dilger47a0c421997-05-16 02:46:07 -0500527 if (white_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600528 *white_x = png_float(png_ptr,
529 info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500530 if (white_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600531 *white_y = png_float(png_ptr,
532 info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500533 if (red_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600534 *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
535 "cHRM red X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500536 if (red_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600537 *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
538 "cHRM red Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500539 if (green_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600540 *green_x = png_float(png_ptr,
541 info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500542 if (green_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600543 *green_y = png_float(png_ptr,
544 info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500545 if (blue_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600546 *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
547 "cHRM blue X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500548 if (blue_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600549 *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
550 "cHRM blue Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500551 return (PNG_INFO_cHRM);
552 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500553
Andreas Dilger47a0c421997-05-16 02:46:07 -0500554 return (0);
555}
John Bowler736f40f2011-08-25 16:19:44 -0500556
557png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600558png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
John Bowler736f40f2011-08-25 16:19:44 -0500559 double *red_X, double *red_Y, double *red_Z, double *green_X,
560 double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
561 double *blue_Z)
562{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600563 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500564 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
Glenn Randers-Pehrsonf3af7062012-02-02 23:11:45 -0600565 {
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600566 png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
567
John Bowler736f40f2011-08-25 16:19:44 -0500568 if (red_X != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600569 *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
570 "cHRM red X");
John Bowler736f40f2011-08-25 16:19:44 -0500571 if (red_Y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600572 *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
573 "cHRM red Y");
John Bowler736f40f2011-08-25 16:19:44 -0500574 if (red_Z != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600575 *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
576 "cHRM red Z");
John Bowler736f40f2011-08-25 16:19:44 -0500577 if (green_X != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600578 *green_X = png_float(png_ptr,
579 info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
John Bowler736f40f2011-08-25 16:19:44 -0500580 if (green_Y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600581 *green_Y = png_float(png_ptr,
582 info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
John Bowler736f40f2011-08-25 16:19:44 -0500583 if (green_Z != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600584 *green_Z = png_float(png_ptr,
585 info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
John Bowler736f40f2011-08-25 16:19:44 -0500586 if (blue_X != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600587 *blue_X = png_float(png_ptr,
588 info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
John Bowler736f40f2011-08-25 16:19:44 -0500589 if (blue_Y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600590 *blue_Y = png_float(png_ptr,
591 info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
John Bowler736f40f2011-08-25 16:19:44 -0500592 if (blue_Z != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600593 *blue_Z = png_float(png_ptr,
594 info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
John Bowler736f40f2011-08-25 16:19:44 -0500595 return (PNG_INFO_cHRM);
596 }
597
598 return (0);
599}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500600# endif
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500601
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500602# ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500603png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600604png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
605 png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
606 png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
607 png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
608 png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
609 png_fixed_point *int_blue_Z)
610{
611 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500612 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600613 {
614 png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
615
616 if (int_red_X != NULL)
617 *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;
618 if (int_red_Y != NULL)
619 *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;
620 if (int_red_Z != NULL)
621 *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;
622 if (int_green_X != NULL)
623 *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;
624 if (int_green_Y != NULL)
625 *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;
626 if (int_green_Z != NULL)
627 *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;
628 if (int_blue_X != NULL)
629 *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;
630 if (int_blue_Y != NULL)
631 *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;
632 if (int_blue_Z != NULL)
633 *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;
634 return (PNG_INFO_cHRM);
635 }
636
637 return (0);
638}
639
640png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600641png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600642 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
643 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
644 png_fixed_point *blue_x, png_fixed_point *blue_y)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600645{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500646 png_debug1(1, "in %s retrieval function", "cHRM");
647
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600648 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500649 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600650 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600651 if (white_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600652 *white_x = info_ptr->colorspace.end_points_xy.whitex;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600653 if (white_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600654 *white_y = info_ptr->colorspace.end_points_xy.whitey;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600655 if (red_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600656 *red_x = info_ptr->colorspace.end_points_xy.redx;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600657 if (red_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600658 *red_y = info_ptr->colorspace.end_points_xy.redy;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600659 if (green_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600660 *green_x = info_ptr->colorspace.end_points_xy.greenx;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600661 if (green_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600662 *green_y = info_ptr->colorspace.end_points_xy.greeny;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600663 if (blue_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600664 *blue_x = info_ptr->colorspace.end_points_xy.bluex;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600665 if (blue_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600666 *blue_y = info_ptr->colorspace.end_points_xy.bluey;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600667 return (PNG_INFO_cHRM);
668 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500669
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600670 return (0);
671}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500672# endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600673#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500674
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500675#ifdef PNG_gAMA_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600676# ifdef PNG_FIXED_POINT_SUPPORTED
677png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600678png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500679 png_fixed_point *file_gamma)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500680{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500681 png_debug1(1, "in %s retrieval function", "gAMA");
682
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600683 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500684 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600685 file_gamma != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500686 {
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600687 *file_gamma = info_ptr->colorspace.gamma;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500688 return (PNG_INFO_gAMA);
689 }
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500690
Andreas Dilger47a0c421997-05-16 02:46:07 -0500691 return (0);
692}
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600693# endif
694
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500695# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500696png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600697png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600698 double *file_gamma)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600699{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600700 png_debug1(1, "in %s retrieval function", "gAMA(float)");
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500701
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600702 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500703 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600704 file_gamma != NULL)
705 {
706 *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
707 "png_get_gAMA");
708 return (PNG_INFO_gAMA);
709 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500710
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600711 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600712}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500713# endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500714#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500715
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500716#ifdef PNG_sRGB_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500717png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600718png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600719 int *file_srgb_intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600720{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500721 png_debug1(1, "in %s retrieval function", "sRGB");
722
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500723 if (png_ptr != NULL && info_ptr != NULL &&
724 (info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600725 {
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600726 *file_srgb_intent = info_ptr->colorspace.rendering_intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600727 return (PNG_INFO_sRGB);
728 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500729
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600730 return (0);
731}
732#endif
733
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500734#ifdef PNG_iCCP_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500735png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600736png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600737 png_charpp name, int *compression_type,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500738 png_bytepp profile, png_uint_32 *proflen)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600739{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500740 png_debug1(1, "in %s retrieval function", "iCCP");
741
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500742 if (png_ptr != NULL && info_ptr != NULL &&
743 (info_ptr->valid & PNG_INFO_iCCP) != 0 &&
744 name != NULL && compression_type != NULL && profile != NULL &&
745 proflen != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600746 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600747 *name = info_ptr->iccp_name;
748 *profile = info_ptr->iccp_profile;
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600749 *proflen = png_get_uint_32(info_ptr->iccp_profile);
750 /* This is somewhat irrelevant since the profile data returned has
751 * actually been uncompressed.
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500752 */
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600753 *compression_type = PNG_COMPRESSION_TYPE_BASE;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600754 return (PNG_INFO_iCCP);
755 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500756
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600757 return (0);
758}
759#endif
760
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500761#ifdef PNG_sPLT_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600762int PNGAPI
763png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600764 png_sPLT_tpp spalettes)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600765{
766 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500767 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600768 *spalettes = info_ptr->splt_palettes;
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600769 return info_ptr->splt_palettes_num;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500770 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500771
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500772 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600773}
774#endif
775
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500776#ifdef PNG_hIST_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500777png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600778png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600779 png_uint_16p *hist)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500780{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500781 png_debug1(1, "in %s retrieval function", "hIST");
782
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500783 if (png_ptr != NULL && info_ptr != NULL &&
784 (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500785 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500786 *hist = info_ptr->hist;
787 return (PNG_INFO_hIST);
788 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500789
Andreas Dilger47a0c421997-05-16 02:46:07 -0500790 return (0);
791}
792#endif
793
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500794png_uint_32 PNGAPI
John Bowler4f67e402011-12-28 08:43:37 -0600795png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600796 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
797 int *color_type, int *interlace_type, int *compression_type,
798 int *filter_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500799{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500800 png_debug1(1, "in %s retrieval function", "IHDR");
801
Glenn Randers-Pehrson60a75062015-02-18 12:24:46 -0600802 if (png_ptr == NULL || info_ptr == NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500803 return (0);
804
Glenn Randers-Pehrson60a75062015-02-18 12:24:46 -0600805 if (width != NULL)
806 *width = info_ptr->width;
807
808 if (height != NULL)
809 *height = info_ptr->height;
810
811 if (bit_depth != NULL)
812 *bit_depth = info_ptr->bit_depth;
813
814 if (color_type != NULL)
815 *color_type = info_ptr->color_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500816
817 if (compression_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500818 *compression_type = info_ptr->compression_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500819
820 if (filter_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500821 *filter_type = info_ptr->filter_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500822
823 if (interlace_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500824 *interlace_type = info_ptr->interlace_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500825
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500826 /* This is redundant if we can be sure that the info_ptr values were all
827 * assigned in png_set_IHDR(). We do the check anyhow in case an
828 * application has ignored our advice not to mess with the members
829 * of info_ptr directly.
830 */
Glenn Randers-Pehrsonad41b882011-12-22 07:31:13 -0600831 png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500832 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
833 info_ptr->compression_type, info_ptr->filter_type);
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500834
835 return (1);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500836}
837
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500838#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500839png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600840png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600841 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500842{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500843 png_debug1(1, "in %s retrieval function", "oFFs");
844
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500845 if (png_ptr != NULL && info_ptr != NULL &&
846 (info_ptr->valid & PNG_INFO_oFFs) != 0 &&
847 offset_x != NULL && offset_y != NULL && unit_type != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500848 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500849 *offset_x = info_ptr->x_offset;
850 *offset_y = info_ptr->y_offset;
851 *unit_type = (int)info_ptr->offset_unit_type;
852 return (PNG_INFO_oFFs);
853 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500854
Andreas Dilger47a0c421997-05-16 02:46:07 -0500855 return (0);
856}
857#endif
858
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500859#ifdef PNG_pCAL_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500860png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600861png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600862 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
863 png_charp *units, png_charpp *params)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500864{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500865 png_debug1(1, "in %s retrieval function", "pCAL");
866
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500867 if (png_ptr != NULL && info_ptr != NULL &&
868 (info_ptr->valid & PNG_INFO_pCAL) != 0 &&
869 purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500870 nparams != NULL && units != NULL && params != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500871 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500872 *purpose = info_ptr->pcal_purpose;
873 *X0 = info_ptr->pcal_X0;
874 *X1 = info_ptr->pcal_X1;
875 *type = (int)info_ptr->pcal_type;
876 *nparams = (int)info_ptr->pcal_nparams;
877 *units = info_ptr->pcal_units;
878 *params = info_ptr->pcal_params;
879 return (PNG_INFO_pCAL);
880 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500881
Andreas Dilger47a0c421997-05-16 02:46:07 -0500882 return (0);
883}
884#endif
885
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500886#ifdef PNG_sCAL_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500887# ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600888# if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
889 defined(PNG_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500890png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600891png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500892 int *unit, png_fixed_point *width, png_fixed_point *height)
893{
894 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500895 (info_ptr->valid & PNG_INFO_sCAL) != 0)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500896 {
897 *unit = info_ptr->scal_unit;
John Bowler29fca0d2011-12-24 07:57:43 -0600898 /*TODO: make this work without FP support; the API is currently eliminated
899 * if neither floating point APIs nor internal floating point arithmetic
900 * are enabled.
901 */
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500902 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
903 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
904 "sCAL height");
905 return (PNG_INFO_sCAL);
906 }
907
908 return(0);
909}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500910# endif /* FLOATING_ARITHMETIC */
911# endif /* FIXED_POINT */
912# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500913png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600914png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600915 int *unit, double *width, double *height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600916{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600917 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500918 (info_ptr->valid & PNG_INFO_sCAL) != 0)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600919 {
920 *unit = info_ptr->scal_unit;
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500921 *width = atof(info_ptr->scal_s_width);
922 *height = atof(info_ptr->scal_s_height);
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600923 return (PNG_INFO_sCAL);
924 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500925
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600926 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600927}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500928# endif /* FLOATING POINT */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500929png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600930png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500931 int *unit, png_charpp width, png_charpp height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600932{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600933 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500934 (info_ptr->valid & PNG_INFO_sCAL) != 0)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600935 {
936 *unit = info_ptr->scal_unit;
937 *width = info_ptr->scal_s_width;
938 *height = info_ptr->scal_s_height;
939 return (PNG_INFO_sCAL);
940 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500941
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600942 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600943}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500944#endif /* sCAL */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600945
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500946#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500947png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600948png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600949 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500950{
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600951 png_uint_32 retval = 0;
952
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500953 png_debug1(1, "in %s retrieval function", "pHYs");
954
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600955 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500956 (info_ptr->valid & PNG_INFO_pHYs) != 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500957 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600958 if (res_x != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600959 {
960 *res_x = info_ptr->x_pixels_per_unit;
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600961 retval |= PNG_INFO_pHYs;
962 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500963
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600964 if (res_y != NULL)
965 {
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600966 *res_y = info_ptr->y_pixels_per_unit;
967 retval |= PNG_INFO_pHYs;
968 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500969
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600970 if (unit_type != NULL)
971 {
972 *unit_type = (int)info_ptr->phys_unit_type;
973 retval |= PNG_INFO_pHYs;
974 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500975 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500976
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600977 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500978}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500979#endif /* pHYs */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500980
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500981png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600982png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600983 png_colorp *palette, int *num_palette)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500984{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500985 png_debug1(1, "in %s retrieval function", "PLTE");
986
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500987 if (png_ptr != NULL && info_ptr != NULL &&
988 (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500989 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500990 *palette = info_ptr->palette;
991 *num_palette = info_ptr->num_palette;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500992 png_debug1(3, "num_palette = %d", *num_palette);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500993 return (PNG_INFO_PLTE);
994 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500995
Andreas Dilger47a0c421997-05-16 02:46:07 -0500996 return (0);
997}
998
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500999#ifdef PNG_sBIT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001000png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001001png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -06001002 png_color_8p *sig_bit)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001003{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -05001004 png_debug1(1, "in %s retrieval function", "sBIT");
1005
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -05001006 if (png_ptr != NULL && info_ptr != NULL &&
1007 (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001008 {
Andreas Dilger47a0c421997-05-16 02:46:07 -05001009 *sig_bit = &(info_ptr->sig_bit);
1010 return (PNG_INFO_sBIT);
1011 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001012
Andreas Dilger47a0c421997-05-16 02:46:07 -05001013 return (0);
1014}
1015#endif
1016
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001017#ifdef PNG_TEXT_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001018int PNGAPI
1019png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -06001020 png_textp *text_ptr, int *num_text)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001021{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001022 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001023 {
Glenn Randers-Pehrsonbb5cb142011-09-22 12:41:58 -05001024 png_debug1(1, "in 0x%lx retrieval function",
1025 (unsigned long)png_ptr->chunk_name);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001026
Andreas Dilger47a0c421997-05-16 02:46:07 -05001027 if (text_ptr != NULL)
1028 *text_ptr = info_ptr->text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001029
Andreas Dilger47a0c421997-05-16 02:46:07 -05001030 if (num_text != NULL)
1031 *num_text = info_ptr->num_text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001032
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001033 return info_ptr->num_text;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001034 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001035
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001036 if (num_text != NULL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001037 *num_text = 0;
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001038
Andreas Dilger47a0c421997-05-16 02:46:07 -05001039 return(0);
1040}
1041#endif
1042
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001043#ifdef PNG_tIME_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001044png_uint_32 PNGAPI
John Bowler4f67e402011-12-28 08:43:37 -06001045png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
1046 png_timep *mod_time)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001047{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -05001048 png_debug1(1, "in %s retrieval function", "tIME");
1049
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -05001050 if (png_ptr != NULL && info_ptr != NULL &&
1051 (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001052 {
Andreas Dilger47a0c421997-05-16 02:46:07 -05001053 *mod_time = &(info_ptr->mod_time);
1054 return (PNG_INFO_tIME);
1055 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001056
Andreas Dilger47a0c421997-05-16 02:46:07 -05001057 return (0);
1058}
1059#endif
1060
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001061#ifdef PNG_tRNS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001062png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001063png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001064 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001065{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001066 png_uint_32 retval = 0;
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -05001067 if (png_ptr != NULL && info_ptr != NULL &&
1068 (info_ptr->valid & PNG_INFO_tRNS) != 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001069 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001070 png_debug1(1, "in %s retrieval function", "tRNS");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -05001071
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001072 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001073 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001074 if (trans_alpha != NULL)
1075 {
1076 *trans_alpha = info_ptr->trans_alpha;
1077 retval |= PNG_INFO_tRNS;
1078 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001079
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001080 if (trans_color != NULL)
1081 *trans_color = &(info_ptr->trans_color);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001082 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001083
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001084 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001085 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001086 if (trans_color != NULL)
1087 {
1088 *trans_color = &(info_ptr->trans_color);
1089 retval |= PNG_INFO_tRNS;
1090 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001091
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001092 if (trans_alpha != NULL)
1093 *trans_alpha = NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001094 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001095
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001096 if (num_trans != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001097 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001098 *num_trans = info_ptr->num_trans;
1099 retval |= PNG_INFO_tRNS;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001100 }
Andreas Dilger47a0c421997-05-16 02:46:07 -05001101 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001102
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001103 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001104}
1105#endif
1106
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001107#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001108int PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001109png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001110 png_unknown_chunkpp unknowns)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001111{
1112 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001113 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001114 *unknowns = info_ptr->unknown_chunks;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001115 return info_ptr->unknown_chunks_num;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001116 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001117
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001118 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001119}
1120#endif
1121
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001122#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001123png_byte PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001124png_get_rgb_to_gray_status (png_const_structrp png_ptr)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001125{
Glenn Randers-Pehrsonc5370ed2015-03-21 11:54:32 -05001126 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001127}
1128#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001129
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001130#ifdef PNG_USER_CHUNKS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001131png_voidp PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001132png_get_user_chunk_ptr(png_const_structrp png_ptr)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001133{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001134 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001135}
1136#endif
1137
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001138png_size_t PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001139png_get_compression_buffer_size(png_const_structrp png_ptr)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001140{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001141 if (png_ptr == NULL)
1142 return 0;
1143
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001144#ifdef PNG_WRITE_SUPPORTED
Krishnaraj Bhat46c47292016-03-07 13:56:15 +05301145 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001146#endif
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001147 {
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001148#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
Krishnaraj Bhat46c47292016-03-07 13:56:15 +05301149 return png_ptr->IDAT_read_size;
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001150#else
Krishnaraj Bhat46c47292016-03-07 13:56:15 +05301151 return PNG_IDAT_READ_SIZE;
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001152#endif
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001153 }
1154
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001155#ifdef PNG_WRITE_SUPPORTED
Krishnaraj Bhat46c47292016-03-07 13:56:15 +05301156 else
1157 return png_ptr->zbuffer_size;
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001158#endif
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001159}
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001160
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001161#ifdef PNG_SET_USER_LIMITS_SUPPORTED
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001162/* These functions were added to libpng 1.2.6 and were enabled
1163 * by default in libpng-1.4.0 */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001164png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001165png_get_user_width_max (png_const_structrp png_ptr)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001166{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001167 return (png_ptr ? png_ptr->user_width_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001168}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001169
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001170png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001171png_get_user_height_max (png_const_structrp png_ptr)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001172{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001173 return (png_ptr ? png_ptr->user_height_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001174}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001175
Glenn Randers-Pehrson17ca3402009-11-09 06:51:16 -06001176/* This function was added to libpng 1.4.0 */
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001177png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001178png_get_chunk_cache_max (png_const_structrp png_ptr)
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001179{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001180 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001181}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001182
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001183/* This function was added to libpng 1.4.1 */
Glenn Randers-Pehrson7a5be532010-02-14 07:16:19 -06001184png_alloc_size_t PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001185png_get_chunk_malloc_max (png_const_structrp png_ptr)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001186{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001187 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001188}
Glenn Randers-Pehrsoncda68df2014-11-06 22:11:39 -06001189#endif /* SET_USER_LIMITS */
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05001190
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001191/* These functions were added to libpng 1.4.0 */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001192#ifdef PNG_IO_STATE_SUPPORTED
1193png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001194png_get_io_state (png_const_structrp png_ptr)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001195{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001196 return png_ptr->io_state;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001197}
1198
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001199png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001200png_get_io_chunk_type (png_const_structrp png_ptr)
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001201{
Glenn Randers-Pehrsonbb5cb142011-09-22 12:41:58 -05001202 return png_ptr->chunk_name;
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001203}
Glenn Randers-Pehrsoncda68df2014-11-06 22:11:39 -06001204#endif /* IO_STATE */
Glenn Randers-Pehrson32d6a742013-02-04 20:07:43 -06001205
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001206#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
1207# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
1208int PNGAPI
1209png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
1210{
1211 if (png_ptr != NULL && info_ptr != NULL)
1212 return png_ptr->num_palette_max;
1213
1214 return (-1);
1215}
1216# endif
1217#endif
1218
Glenn Randers-Pehrsoncda68df2014-11-06 22:11:39 -06001219#endif /* READ || WRITE */