blob: ed00f8b4b9d52bb9a856f326823d754933a10621 [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-Pehrson5d713fe2014-10-31 20:48:55 -05004 * Last changed in libpng 1.6.15 [(PENDING RELEASE)]
Cosmin Truta6572c7d2014-03-22 09:20:53 -05005 * Copyright (c) 1998-2014 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-Pehrson3097f612001-05-07 14:52:45 -0500458#endif /* PNG_pHYs_SUPPORTED */
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500459#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
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-Pehrsoncbe52d81998-02-28 07:00:24 -0600463#endif /* PNG_EASY_ACCESS_SUPPORTED */
464
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-Pehrson134bbe42009-09-24 18:10:49 -0500802 if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
803 height == NULL || bit_depth == NULL || color_type == NULL)
804 return (0);
805
806 *width = info_ptr->width;
807 *height = info_ptr->height;
808 *bit_depth = info_ptr->bit_depth;
809 *color_type = info_ptr->color_type;
810
811 if (compression_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500812 *compression_type = info_ptr->compression_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500813
814 if (filter_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500815 *filter_type = info_ptr->filter_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500816
817 if (interlace_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500818 *interlace_type = info_ptr->interlace_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500819
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500820 /* This is redundant if we can be sure that the info_ptr values were all
821 * assigned in png_set_IHDR(). We do the check anyhow in case an
822 * application has ignored our advice not to mess with the members
823 * of info_ptr directly.
824 */
Glenn Randers-Pehrsonad41b882011-12-22 07:31:13 -0600825 png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500826 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
827 info_ptr->compression_type, info_ptr->filter_type);
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500828
829 return (1);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500830}
831
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500832#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500833png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600834png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600835 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500836{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500837 png_debug1(1, "in %s retrieval function", "oFFs");
838
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500839 if (png_ptr != NULL && info_ptr != NULL &&
840 (info_ptr->valid & PNG_INFO_oFFs) != 0 &&
841 offset_x != NULL && offset_y != NULL && unit_type != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500842 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500843 *offset_x = info_ptr->x_offset;
844 *offset_y = info_ptr->y_offset;
845 *unit_type = (int)info_ptr->offset_unit_type;
846 return (PNG_INFO_oFFs);
847 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500848
Andreas Dilger47a0c421997-05-16 02:46:07 -0500849 return (0);
850}
851#endif
852
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500853#ifdef PNG_pCAL_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500854png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600855png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600856 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
857 png_charp *units, png_charpp *params)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500858{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500859 png_debug1(1, "in %s retrieval function", "pCAL");
860
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500861 if (png_ptr != NULL && info_ptr != NULL &&
862 (info_ptr->valid & PNG_INFO_pCAL) != 0 &&
863 purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500864 nparams != NULL && units != NULL && params != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500865 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500866 *purpose = info_ptr->pcal_purpose;
867 *X0 = info_ptr->pcal_X0;
868 *X1 = info_ptr->pcal_X1;
869 *type = (int)info_ptr->pcal_type;
870 *nparams = (int)info_ptr->pcal_nparams;
871 *units = info_ptr->pcal_units;
872 *params = info_ptr->pcal_params;
873 return (PNG_INFO_pCAL);
874 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500875
Andreas Dilger47a0c421997-05-16 02:46:07 -0500876 return (0);
877}
878#endif
879
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500880#ifdef PNG_sCAL_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500881# ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600882# if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
883 defined(PNG_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500884png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600885png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500886 int *unit, png_fixed_point *width, png_fixed_point *height)
887{
888 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500889 (info_ptr->valid & PNG_INFO_sCAL) != 0)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500890 {
891 *unit = info_ptr->scal_unit;
John Bowler29fca0d2011-12-24 07:57:43 -0600892 /*TODO: make this work without FP support; the API is currently eliminated
893 * if neither floating point APIs nor internal floating point arithmetic
894 * are enabled.
895 */
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500896 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
897 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
898 "sCAL height");
899 return (PNG_INFO_sCAL);
900 }
901
902 return(0);
903}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500904# endif /* FLOATING_ARITHMETIC */
905# endif /* FIXED_POINT */
906# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500907png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600908png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600909 int *unit, double *width, double *height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600910{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600911 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500912 (info_ptr->valid & PNG_INFO_sCAL) != 0)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600913 {
914 *unit = info_ptr->scal_unit;
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500915 *width = atof(info_ptr->scal_s_width);
916 *height = atof(info_ptr->scal_s_height);
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600917 return (PNG_INFO_sCAL);
918 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500919
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600920 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600921}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500922# endif /* FLOATING POINT */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500923png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600924png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500925 int *unit, png_charpp width, png_charpp height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600926{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600927 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500928 (info_ptr->valid & PNG_INFO_sCAL) != 0)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600929 {
930 *unit = info_ptr->scal_unit;
931 *width = info_ptr->scal_s_width;
932 *height = info_ptr->scal_s_height;
933 return (PNG_INFO_sCAL);
934 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500935
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600936 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600937}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500938#endif /* sCAL */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600939
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500940#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500941png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600942png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600943 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500944{
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600945 png_uint_32 retval = 0;
946
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500947 png_debug1(1, "in %s retrieval function", "pHYs");
948
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600949 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500950 (info_ptr->valid & PNG_INFO_pHYs) != 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500951 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600952 if (res_x != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600953 {
954 *res_x = info_ptr->x_pixels_per_unit;
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600955 retval |= PNG_INFO_pHYs;
956 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500957
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600958 if (res_y != NULL)
959 {
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600960 *res_y = info_ptr->y_pixels_per_unit;
961 retval |= PNG_INFO_pHYs;
962 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500963
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600964 if (unit_type != NULL)
965 {
966 *unit_type = (int)info_ptr->phys_unit_type;
967 retval |= PNG_INFO_pHYs;
968 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500969 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500970
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600971 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500972}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500973#endif /* pHYs */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500974
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500975png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600976png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600977 png_colorp *palette, int *num_palette)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500978{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500979 png_debug1(1, "in %s retrieval function", "PLTE");
980
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500981 if (png_ptr != NULL && info_ptr != NULL &&
982 (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500983 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500984 *palette = info_ptr->palette;
985 *num_palette = info_ptr->num_palette;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500986 png_debug1(3, "num_palette = %d", *num_palette);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500987 return (PNG_INFO_PLTE);
988 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500989
Andreas Dilger47a0c421997-05-16 02:46:07 -0500990 return (0);
991}
992
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500993#ifdef PNG_sBIT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500994png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600995png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600996 png_color_8p *sig_bit)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500997{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500998 png_debug1(1, "in %s retrieval function", "sBIT");
999
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -05001000 if (png_ptr != NULL && info_ptr != NULL &&
1001 (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001002 {
Andreas Dilger47a0c421997-05-16 02:46:07 -05001003 *sig_bit = &(info_ptr->sig_bit);
1004 return (PNG_INFO_sBIT);
1005 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001006
Andreas Dilger47a0c421997-05-16 02:46:07 -05001007 return (0);
1008}
1009#endif
1010
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001011#ifdef PNG_TEXT_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001012int PNGAPI
1013png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -06001014 png_textp *text_ptr, int *num_text)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001015{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001016 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001017 {
Glenn Randers-Pehrsonbb5cb142011-09-22 12:41:58 -05001018 png_debug1(1, "in 0x%lx retrieval function",
1019 (unsigned long)png_ptr->chunk_name);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001020
Andreas Dilger47a0c421997-05-16 02:46:07 -05001021 if (text_ptr != NULL)
1022 *text_ptr = info_ptr->text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001023
Andreas Dilger47a0c421997-05-16 02:46:07 -05001024 if (num_text != NULL)
1025 *num_text = info_ptr->num_text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001026
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001027 return info_ptr->num_text;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001028 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001029
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001030 if (num_text != NULL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001031 *num_text = 0;
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001032
Andreas Dilger47a0c421997-05-16 02:46:07 -05001033 return(0);
1034}
1035#endif
1036
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001037#ifdef PNG_tIME_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001038png_uint_32 PNGAPI
John Bowler4f67e402011-12-28 08:43:37 -06001039png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
1040 png_timep *mod_time)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001041{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -05001042 png_debug1(1, "in %s retrieval function", "tIME");
1043
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -05001044 if (png_ptr != NULL && info_ptr != NULL &&
1045 (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001046 {
Andreas Dilger47a0c421997-05-16 02:46:07 -05001047 *mod_time = &(info_ptr->mod_time);
1048 return (PNG_INFO_tIME);
1049 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001050
Andreas Dilger47a0c421997-05-16 02:46:07 -05001051 return (0);
1052}
1053#endif
1054
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001055#ifdef PNG_tRNS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001056png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001057png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001058 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001059{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001060 png_uint_32 retval = 0;
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -05001061 if (png_ptr != NULL && info_ptr != NULL &&
1062 (info_ptr->valid & PNG_INFO_tRNS) != 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001063 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001064 png_debug1(1, "in %s retrieval function", "tRNS");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -05001065
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001066 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001067 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001068 if (trans_alpha != NULL)
1069 {
1070 *trans_alpha = info_ptr->trans_alpha;
1071 retval |= PNG_INFO_tRNS;
1072 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001073
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001074 if (trans_color != NULL)
1075 *trans_color = &(info_ptr->trans_color);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001076 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001077
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001078 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001079 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001080 if (trans_color != NULL)
1081 {
1082 *trans_color = &(info_ptr->trans_color);
1083 retval |= PNG_INFO_tRNS;
1084 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001085
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001086 if (trans_alpha != NULL)
1087 *trans_alpha = NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001088 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001089
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001090 if (num_trans != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001091 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001092 *num_trans = info_ptr->num_trans;
1093 retval |= PNG_INFO_tRNS;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001094 }
Andreas Dilger47a0c421997-05-16 02:46:07 -05001095 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001096
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001097 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001098}
1099#endif
1100
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001101#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001102int PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001103png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001104 png_unknown_chunkpp unknowns)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001105{
1106 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001107 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001108 *unknowns = info_ptr->unknown_chunks;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001109 return info_ptr->unknown_chunks_num;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001110 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001111
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001112 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001113}
1114#endif
1115
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001116#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001117png_byte PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001118png_get_rgb_to_gray_status (png_const_structrp png_ptr)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001119{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001120 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001121}
1122#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001123
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001124#ifdef PNG_USER_CHUNKS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001125png_voidp PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001126png_get_user_chunk_ptr(png_const_structrp png_ptr)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001127{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001128 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001129}
1130#endif
1131
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001132png_size_t PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001133png_get_compression_buffer_size(png_const_structrp png_ptr)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001134{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001135 if (png_ptr == NULL)
1136 return 0;
1137
1138# ifdef PNG_WRITE_SUPPORTED
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -05001139 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001140# endif
1141 {
1142# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1143 return png_ptr->IDAT_read_size;
1144# else
1145 return PNG_IDAT_READ_SIZE;
1146# endif
1147 }
1148
1149# ifdef PNG_WRITE_SUPPORTED
1150 else
1151 return png_ptr->zbuffer_size;
1152# endif
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001153}
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001154
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001155#ifdef PNG_SET_USER_LIMITS_SUPPORTED
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001156/* These functions were added to libpng 1.2.6 and were enabled
1157 * by default in libpng-1.4.0 */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001158png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001159png_get_user_width_max (png_const_structrp png_ptr)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001160{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001161 return (png_ptr ? png_ptr->user_width_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001162}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001163
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001164png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001165png_get_user_height_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_height_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001168}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001169
Glenn Randers-Pehrson17ca3402009-11-09 06:51:16 -06001170/* This function was added to libpng 1.4.0 */
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001171png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001172png_get_chunk_cache_max (png_const_structrp png_ptr)
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001173{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001174 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001175}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001176
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001177/* This function was added to libpng 1.4.1 */
Glenn Randers-Pehrson7a5be532010-02-14 07:16:19 -06001178png_alloc_size_t PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001179png_get_chunk_malloc_max (png_const_structrp png_ptr)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001180{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001181 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001182}
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001183#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05001184
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001185/* These functions were added to libpng 1.4.0 */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001186#ifdef PNG_IO_STATE_SUPPORTED
1187png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001188png_get_io_state (png_const_structrp png_ptr)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001189{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001190 return png_ptr->io_state;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001191}
1192
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001193png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001194png_get_io_chunk_type (png_const_structrp png_ptr)
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001195{
Glenn Randers-Pehrsonbb5cb142011-09-22 12:41:58 -05001196 return png_ptr->chunk_name;
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001197}
Glenn Randers-Pehrsonf3af7062012-02-02 23:11:45 -06001198#endif /* ?PNG_IO_STATE_SUPPORTED */
Glenn Randers-Pehrson32d6a742013-02-04 20:07:43 -06001199
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001200#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
1201# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
1202int PNGAPI
1203png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
1204{
1205 if (png_ptr != NULL && info_ptr != NULL)
1206 return png_ptr->num_palette_max;
1207
1208 return (-1);
1209}
1210# endif
1211#endif
1212
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001213#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */