blob: 5abf1efd9f73bffbc5561eab4057bc0f29465e62 [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 *
Cosmin Trutaa8738932018-07-28 18:47:21 -04004 * Copyright (c) 2018 Cosmin Truta
Glenn Randers-Pehrson7784cd32018-03-28 18:02:32 -05005 * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
Cosmin Trutaa8738932018-07-28 18:47:21 -04006 * Copyright (c) 1996-1997 Andreas Dilger
7 * 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
Cosmin Trutaa74aa9a2018-06-17 22:37:44 -040029size_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-Pehrson3875d9a2016-10-02 17:08:46 -0500341 return (png_uint_32)result;
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500342
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{
luz.pazeb91c0e2018-02-09 06:57:29 -0500370 /* Convert from meters * 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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500489 png_color_16p *background)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500490{
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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500529 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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500532 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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500535 "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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500538 "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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500541 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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500544 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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500547 "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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500550 "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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -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)
John Bowler736f40f2011-08-25 16:19:44 -0500562{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600563 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500570 "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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500573 "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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500576 "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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500579 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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500582 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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500585 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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500588 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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500591 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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500594 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-Pehrsondd706042016-07-15 11:20:46 -0500684 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
685 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,
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500707 "png_get_gAMA");
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600708 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 &&
Glenn Randers-Pehrson7784cd32018-03-28 18:02:32 -0500744 name != NULL && profile != NULL && proflen != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600745 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600746 *name = info_ptr->iccp_name;
747 *profile = info_ptr->iccp_profile;
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600748 *proflen = png_get_uint_32(info_ptr->iccp_profile);
749 /* This is somewhat irrelevant since the profile data returned has
750 * actually been uncompressed.
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500751 */
Glenn Randers-Pehrson916117d2018-03-29 10:37:12 -0500752 if (compression_type != NULL)
753 *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);
Glenn Randers-Pehrson7784cd32018-03-28 18:02:32 -0500758
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600759}
760#endif
761
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500762#ifdef PNG_sPLT_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600763int PNGAPI
764png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600765 png_sPLT_tpp spalettes)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600766{
767 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500768 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600769 *spalettes = info_ptr->splt_palettes;
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600770 return info_ptr->splt_palettes_num;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500771 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500772
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500773 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600774}
775#endif
776
Glenn Randers-Pehrson68cb0aa2017-07-13 11:19:53 -0500777#ifdef PNG_eXIf_SUPPORTED
778png_uint_32 PNGAPI
Glenn Randers-Pehrson7c709f02017-08-02 16:48:11 -0500779png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
780 png_bytep *exif)
781{
Glenn Randers-Pehrsond930d362017-08-03 10:29:10 -0500782 png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1");
783 PNG_UNUSED(info_ptr)
784 PNG_UNUSED(exif)
785 return 0;
786}
787
788png_uint_32 PNGAPI
Glenn Randers-Pehrson554d4402017-08-04 15:38:41 -0500789png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrsond930d362017-08-03 10:29:10 -0500790 png_uint_32 *num_exif, png_bytep *exif)
791{
Glenn Randers-Pehrson68cb0aa2017-07-13 11:19:53 -0500792 png_debug1(1, "in %s retrieval function", "eXIf");
793
794 if (png_ptr != NULL && info_ptr != NULL &&
795 (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL)
796 {
Glenn Randers-Pehrsond930d362017-08-03 10:29:10 -0500797 *num_exif = info_ptr->num_exif;
Glenn Randers-Pehrson68cb0aa2017-07-13 11:19:53 -0500798 *exif = info_ptr->exif;
799 return (PNG_INFO_eXIf);
800 }
801
802 return (0);
803}
804#endif
805
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500806#ifdef PNG_hIST_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500807png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600808png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600809 png_uint_16p *hist)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500810{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500811 png_debug1(1, "in %s retrieval function", "hIST");
812
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500813 if (png_ptr != NULL && info_ptr != NULL &&
814 (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500815 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500816 *hist = info_ptr->hist;
817 return (PNG_INFO_hIST);
818 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500819
Andreas Dilger47a0c421997-05-16 02:46:07 -0500820 return (0);
821}
822#endif
823
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500824png_uint_32 PNGAPI
John Bowler4f67e402011-12-28 08:43:37 -0600825png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600826 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
827 int *color_type, int *interlace_type, int *compression_type,
828 int *filter_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500829{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500830 png_debug1(1, "in %s retrieval function", "IHDR");
831
Glenn Randers-Pehrson60a75062015-02-18 12:24:46 -0600832 if (png_ptr == NULL || info_ptr == NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500833 return (0);
834
Glenn Randers-Pehrson60a75062015-02-18 12:24:46 -0600835 if (width != NULL)
836 *width = info_ptr->width;
837
838 if (height != NULL)
839 *height = info_ptr->height;
840
841 if (bit_depth != NULL)
842 *bit_depth = info_ptr->bit_depth;
843
844 if (color_type != NULL)
845 *color_type = info_ptr->color_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500846
847 if (compression_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500848 *compression_type = info_ptr->compression_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500849
850 if (filter_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500851 *filter_type = info_ptr->filter_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500852
853 if (interlace_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500854 *interlace_type = info_ptr->interlace_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500855
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500856 /* This is redundant if we can be sure that the info_ptr values were all
857 * assigned in png_set_IHDR(). We do the check anyhow in case an
858 * application has ignored our advice not to mess with the members
859 * of info_ptr directly.
860 */
Glenn Randers-Pehrsonad41b882011-12-22 07:31:13 -0600861 png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500862 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
863 info_ptr->compression_type, info_ptr->filter_type);
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500864
865 return (1);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500866}
867
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500868#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500869png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600870png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600871 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500872{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500873 png_debug1(1, "in %s retrieval function", "oFFs");
874
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500875 if (png_ptr != NULL && info_ptr != NULL &&
876 (info_ptr->valid & PNG_INFO_oFFs) != 0 &&
877 offset_x != NULL && offset_y != NULL && unit_type != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500878 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500879 *offset_x = info_ptr->x_offset;
880 *offset_y = info_ptr->y_offset;
881 *unit_type = (int)info_ptr->offset_unit_type;
882 return (PNG_INFO_oFFs);
883 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500884
Andreas Dilger47a0c421997-05-16 02:46:07 -0500885 return (0);
886}
887#endif
888
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500889#ifdef PNG_pCAL_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500890png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600891png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600892 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
893 png_charp *units, png_charpp *params)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500894{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500895 png_debug1(1, "in %s retrieval function", "pCAL");
896
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500897 if (png_ptr != NULL && info_ptr != NULL &&
898 (info_ptr->valid & PNG_INFO_pCAL) != 0 &&
899 purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500900 nparams != NULL && units != NULL && params != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500901 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500902 *purpose = info_ptr->pcal_purpose;
903 *X0 = info_ptr->pcal_X0;
904 *X1 = info_ptr->pcal_X1;
905 *type = (int)info_ptr->pcal_type;
906 *nparams = (int)info_ptr->pcal_nparams;
907 *units = info_ptr->pcal_units;
908 *params = info_ptr->pcal_params;
909 return (PNG_INFO_pCAL);
910 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500911
Andreas Dilger47a0c421997-05-16 02:46:07 -0500912 return (0);
913}
914#endif
915
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500916#ifdef PNG_sCAL_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500917# ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600918# if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
919 defined(PNG_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500920png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600921png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500922 int *unit, png_fixed_point *width, png_fixed_point *height)
923{
924 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500925 (info_ptr->valid & PNG_INFO_sCAL) != 0)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500926 {
927 *unit = info_ptr->scal_unit;
John Bowler29fca0d2011-12-24 07:57:43 -0600928 /*TODO: make this work without FP support; the API is currently eliminated
929 * if neither floating point APIs nor internal floating point arithmetic
930 * are enabled.
931 */
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500932 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
933 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
Glenn Randers-Pehrsondd706042016-07-15 11:20:46 -0500934 "sCAL height");
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500935 return (PNG_INFO_sCAL);
936 }
937
938 return(0);
939}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500940# endif /* FLOATING_ARITHMETIC */
941# endif /* FIXED_POINT */
942# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500943png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600944png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600945 int *unit, double *width, double *height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600946{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600947 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500948 (info_ptr->valid & PNG_INFO_sCAL) != 0)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600949 {
950 *unit = info_ptr->scal_unit;
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500951 *width = atof(info_ptr->scal_s_width);
952 *height = atof(info_ptr->scal_s_height);
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600953 return (PNG_INFO_sCAL);
954 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500955
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600956 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600957}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500958# endif /* FLOATING POINT */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500959png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600960png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500961 int *unit, png_charpp width, png_charpp height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600962{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600963 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500964 (info_ptr->valid & PNG_INFO_sCAL) != 0)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600965 {
966 *unit = info_ptr->scal_unit;
967 *width = info_ptr->scal_s_width;
968 *height = info_ptr->scal_s_height;
969 return (PNG_INFO_sCAL);
970 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500971
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600972 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600973}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500974#endif /* sCAL */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600975
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500976#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500977png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600978png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600979 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500980{
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600981 png_uint_32 retval = 0;
982
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500983 png_debug1(1, "in %s retrieval function", "pHYs");
984
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600985 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -0500986 (info_ptr->valid & PNG_INFO_pHYs) != 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500987 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600988 if (res_x != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600989 {
990 *res_x = info_ptr->x_pixels_per_unit;
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600991 retval |= PNG_INFO_pHYs;
992 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500993
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600994 if (res_y != NULL)
995 {
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600996 *res_y = info_ptr->y_pixels_per_unit;
997 retval |= PNG_INFO_pHYs;
998 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500999
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001000 if (unit_type != NULL)
1001 {
1002 *unit_type = (int)info_ptr->phys_unit_type;
1003 retval |= PNG_INFO_pHYs;
1004 }
Andreas Dilger47a0c421997-05-16 02:46:07 -05001005 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001006
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001007 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001008}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -05001009#endif /* pHYs */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001010
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001011png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001012png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -06001013 png_colorp *palette, int *num_palette)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001014{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -05001015 png_debug1(1, "in %s retrieval function", "PLTE");
1016
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -05001017 if (png_ptr != NULL && info_ptr != NULL &&
1018 (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001019 {
Andreas Dilger47a0c421997-05-16 02:46:07 -05001020 *palette = info_ptr->palette;
1021 *num_palette = info_ptr->num_palette;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001022 png_debug1(3, "num_palette = %d", *num_palette);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001023 return (PNG_INFO_PLTE);
1024 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001025
Andreas Dilger47a0c421997-05-16 02:46:07 -05001026 return (0);
1027}
1028
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001029#ifdef PNG_sBIT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001030png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001031png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -06001032 png_color_8p *sig_bit)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001033{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -05001034 png_debug1(1, "in %s retrieval function", "sBIT");
1035
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -05001036 if (png_ptr != NULL && info_ptr != NULL &&
1037 (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001038 {
Andreas Dilger47a0c421997-05-16 02:46:07 -05001039 *sig_bit = &(info_ptr->sig_bit);
1040 return (PNG_INFO_sBIT);
1041 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001042
Andreas Dilger47a0c421997-05-16 02:46:07 -05001043 return (0);
1044}
1045#endif
1046
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001047#ifdef PNG_TEXT_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001048int PNGAPI
1049png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -06001050 png_textp *text_ptr, int *num_text)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001051{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001052 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001053 {
Glenn Randers-Pehrsonbb5cb142011-09-22 12:41:58 -05001054 png_debug1(1, "in 0x%lx retrieval function",
1055 (unsigned long)png_ptr->chunk_name);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001056
Andreas Dilger47a0c421997-05-16 02:46:07 -05001057 if (text_ptr != NULL)
1058 *text_ptr = info_ptr->text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001059
Andreas Dilger47a0c421997-05-16 02:46:07 -05001060 if (num_text != NULL)
1061 *num_text = info_ptr->num_text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001062
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001063 return info_ptr->num_text;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001064 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001065
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001066 if (num_text != NULL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001067 *num_text = 0;
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001068
Andreas Dilger47a0c421997-05-16 02:46:07 -05001069 return(0);
1070}
1071#endif
1072
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001073#ifdef PNG_tIME_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001074png_uint_32 PNGAPI
John Bowler4f67e402011-12-28 08:43:37 -06001075png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
1076 png_timep *mod_time)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001077{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -05001078 png_debug1(1, "in %s retrieval function", "tIME");
1079
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -05001080 if (png_ptr != NULL && info_ptr != NULL &&
1081 (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001082 {
Andreas Dilger47a0c421997-05-16 02:46:07 -05001083 *mod_time = &(info_ptr->mod_time);
1084 return (PNG_INFO_tIME);
1085 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001086
Andreas Dilger47a0c421997-05-16 02:46:07 -05001087 return (0);
1088}
1089#endif
1090
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001091#ifdef PNG_tRNS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001092png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001093png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001094 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001095{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001096 png_uint_32 retval = 0;
Glenn Randers-Pehrson5d713fe2014-10-31 20:48:55 -05001097 if (png_ptr != NULL && info_ptr != NULL &&
1098 (info_ptr->valid & PNG_INFO_tRNS) != 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001099 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001100 png_debug1(1, "in %s retrieval function", "tRNS");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -05001101
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001102 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001103 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001104 if (trans_alpha != NULL)
1105 {
1106 *trans_alpha = info_ptr->trans_alpha;
1107 retval |= PNG_INFO_tRNS;
1108 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001109
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001110 if (trans_color != NULL)
1111 *trans_color = &(info_ptr->trans_color);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001112 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001113
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001114 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001115 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001116 if (trans_color != NULL)
1117 {
1118 *trans_color = &(info_ptr->trans_color);
1119 retval |= PNG_INFO_tRNS;
1120 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001121
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001122 if (trans_alpha != NULL)
1123 *trans_alpha = NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001124 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001125
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001126 if (num_trans != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001127 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001128 *num_trans = info_ptr->num_trans;
1129 retval |= PNG_INFO_tRNS;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001130 }
Andreas Dilger47a0c421997-05-16 02:46:07 -05001131 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001132
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001133 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001134}
1135#endif
1136
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001137#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001138int PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001139png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001140 png_unknown_chunkpp unknowns)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001141{
1142 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001143 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001144 *unknowns = info_ptr->unknown_chunks;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001145 return info_ptr->unknown_chunks_num;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001146 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001147
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001148 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001149}
1150#endif
1151
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001152#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001153png_byte PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001154png_get_rgb_to_gray_status (png_const_structrp png_ptr)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001155{
Glenn Randers-Pehrsonc5370ed2015-03-21 11:54:32 -05001156 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001157}
1158#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001159
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001160#ifdef PNG_USER_CHUNKS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001161png_voidp PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001162png_get_user_chunk_ptr(png_const_structrp png_ptr)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001163{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001164 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001165}
1166#endif
1167
Cosmin Trutaa74aa9a2018-06-17 22:37:44 -04001168size_t PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001169png_get_compression_buffer_size(png_const_structrp png_ptr)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001170{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001171 if (png_ptr == NULL)
1172 return 0;
1173
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001174#ifdef PNG_WRITE_SUPPORTED
Krishnaraj Bhat46c47292016-03-07 13:56:15 +05301175 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001176#endif
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001177 {
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001178#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
Krishnaraj Bhat46c47292016-03-07 13:56:15 +05301179 return png_ptr->IDAT_read_size;
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001180#else
Krishnaraj Bhat46c47292016-03-07 13:56:15 +05301181 return PNG_IDAT_READ_SIZE;
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001182#endif
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001183 }
1184
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001185#ifdef PNG_WRITE_SUPPORTED
Krishnaraj Bhat46c47292016-03-07 13:56:15 +05301186 else
1187 return png_ptr->zbuffer_size;
Glenn Randers-Pehrson6ef579d2015-01-27 07:02:46 -06001188#endif
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001189}
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001190
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001191#ifdef PNG_SET_USER_LIMITS_SUPPORTED
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001192/* These functions were added to libpng 1.2.6 and were enabled
1193 * by default in libpng-1.4.0 */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001194png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001195png_get_user_width_max (png_const_structrp png_ptr)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001196{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001197 return (png_ptr ? png_ptr->user_width_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001198}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001199
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001200png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001201png_get_user_height_max (png_const_structrp png_ptr)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001202{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001203 return (png_ptr ? png_ptr->user_height_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001204}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001205
Glenn Randers-Pehrson17ca3402009-11-09 06:51:16 -06001206/* This function was added to libpng 1.4.0 */
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001207png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001208png_get_chunk_cache_max (png_const_structrp png_ptr)
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001209{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001210 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001211}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001212
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001213/* This function was added to libpng 1.4.1 */
Glenn Randers-Pehrson7a5be532010-02-14 07:16:19 -06001214png_alloc_size_t PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001215png_get_chunk_malloc_max (png_const_structrp png_ptr)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001216{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001217 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001218}
Glenn Randers-Pehrsoncda68df2014-11-06 22:11:39 -06001219#endif /* SET_USER_LIMITS */
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05001220
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001221/* These functions were added to libpng 1.4.0 */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001222#ifdef PNG_IO_STATE_SUPPORTED
1223png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001224png_get_io_state (png_const_structrp png_ptr)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001225{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001226 return png_ptr->io_state;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001227}
1228
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001229png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001230png_get_io_chunk_type (png_const_structrp png_ptr)
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001231{
Glenn Randers-Pehrsonbb5cb142011-09-22 12:41:58 -05001232 return png_ptr->chunk_name;
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001233}
Glenn Randers-Pehrsoncda68df2014-11-06 22:11:39 -06001234#endif /* IO_STATE */
Glenn Randers-Pehrson32d6a742013-02-04 20:07:43 -06001235
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001236#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
1237# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
1238int PNGAPI
1239png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
1240{
1241 if (png_ptr != NULL && info_ptr != NULL)
1242 return png_ptr->num_palette_max;
1243
1244 return (-1);
1245}
1246# endif
1247#endif
1248
Glenn Randers-Pehrsoncda68df2014-11-06 22:11:39 -06001249#endif /* READ || WRITE */