blob: aca63a9589ce022367deddabef46e42b3b4db444 [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-Pehrson50878052013-03-27 20:31:36 -05004 * Last changed in libpng 1.6.1 [March 28, 2013]
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06005 * Copyright (c) 1998-2013 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-Pehrson5c5f5932010-10-23 10:14:42 -0500119 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
120 {
121 png_debug1(1, "in %s retrieval function",
122 "png_get_x_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500123
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500124 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
125 return (info_ptr->x_pixels_per_unit);
126 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600127#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500128
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600129 return (0);
130}
131
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500132png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600133png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
134 info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600135{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500136#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500137 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600138 {
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500139 png_debug1(1, "in %s retrieval function",
140 "png_get_y_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500141
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500142 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600143 return (info_ptr->y_pixels_per_unit);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600144 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600145#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500146
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600147 return (0);
148}
149
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500150png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600151png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600152{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500153#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500154 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600155 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500156 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500157
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500158 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
159 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600160 return (info_ptr->x_pixels_per_unit);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600161 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600162#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500163
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600164 return (0);
165}
166
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600167#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500168float PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600169png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
170 info_ptr)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600171{
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500172#ifdef PNG_READ_pHYs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500173 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600174 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500175 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500176
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500177 if (info_ptr->x_pixels_per_unit != 0)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500178 return ((float)((float)info_ptr->y_pixels_per_unit
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600179 /(float)info_ptr->x_pixels_per_unit));
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600180 }
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600181#else
182 PNG_UNUSED(png_ptr)
183 PNG_UNUSED(info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600184#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500185
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500186 return ((float)0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600187}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600188#endif
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600189
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500190#ifdef PNG_FIXED_POINT_SUPPORTED
191png_fixed_point PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600192png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
193 png_const_inforp info_ptr)
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500194{
195#ifdef PNG_READ_pHYs_SUPPORTED
196 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500197 && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
198 && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
199 && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500200 {
201 png_fixed_point res;
202
203 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
204
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500205 /* The following casts work because a PNG 4 byte integer only has a valid
206 * range of 0..2^31-1; otherwise the cast might overflow.
207 */
208 if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
209 (png_int_32)info_ptr->x_pixels_per_unit))
Glenn Randers-Pehrson3df324d2010-07-31 13:45:04 -0500210 return res;
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500211 }
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600212#else
213 PNG_UNUSED(png_ptr)
214 PNG_UNUSED(info_ptr)
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500215#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500216
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500217 return 0;
218}
219#endif
220
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500221png_int_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600222png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600223{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500224#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500225 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600226 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500227 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500228
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500229 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600230 return (info_ptr->x_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600231 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600232#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500233
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600234 return (0);
235}
236
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500237png_int_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600238png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600239{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500240#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500241 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600242 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500243 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500244
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500245 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600246 return (info_ptr->y_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600247 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600248#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500249
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600250 return (0);
251}
252
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500253png_int_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600254png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600255{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500256#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500257 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600258 {
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500259 png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500260
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500261 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600262 return (info_ptr->x_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600263 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600264#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500265
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600266 return (0);
267}
268
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500269png_int_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600270png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600271{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500272#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500273 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600274 {
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500275 png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500276
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500277 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600278 return (info_ptr->y_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600279 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600280#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500281
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600282 return (0);
283}
284
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500285#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
286static png_uint_32
287ppi_from_ppm(png_uint_32 ppm)
288{
289#if 0
Glenn Randers-Pehrson233357e2010-07-29 21:49:38 -0500290 /* The conversion is *(2.54/100), in binary (32 digits):
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500291 * .00000110100000001001110101001001
292 */
293 png_uint_32 t1001, t1101;
294 ppm >>= 1; /* .1 */
295 t1001 = ppm + (ppm >> 3); /* .1001 */
296 t1101 = t1001 + (ppm >> 1); /* .1101 */
297 ppm >>= 20; /* .000000000000000000001 */
298 t1101 += t1101 >> 15; /* .1101000000000001101 */
299 t1001 >>= 11; /* .000000000001001 */
300 t1001 += t1001 >> 12; /* .000000000001001000000001001 */
301 ppm += t1001; /* .000000000001001000001001001 */
302 ppm += t1101; /* .110100000001001110101001001 */
303 return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
304#else
305 /* The argument is a PNG unsigned integer, so it is not permitted
306 * to be bigger than 2^31.
307 */
308 png_fixed_point result;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500309 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
310 5000))
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500311 return result;
312
313 /* Overflow. */
314 return 0;
315#endif
316}
317
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500318png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600319png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600320{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500321 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600322}
323
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500324png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600325png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600326{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500327 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600328}
329
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500330png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600331png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600332{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500333 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600334}
335
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500336#ifdef PNG_FIXED_POINT_SUPPORTED
337static png_fixed_point
John Bowler5d567862011-12-24 09:12:00 -0600338png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500339{
340 /* Convert from metres * 1,000,000 to inches * 100,000, meters to
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500341 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500342 * Notice that this can overflow - a warning is output and 0 is
343 * returned.
344 */
345 return png_muldiv_warn(png_ptr, microns, 500, 127);
346}
347
348png_fixed_point PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600349png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
350 png_const_inforp info_ptr)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500351{
352 return png_fixed_inches_from_microns(png_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500353 png_get_x_offset_microns(png_ptr, info_ptr));
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500354}
355#endif
356
357#ifdef PNG_FIXED_POINT_SUPPORTED
358png_fixed_point PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600359png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
360 png_const_inforp info_ptr)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500361{
362 return png_fixed_inches_from_microns(png_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500363 png_get_y_offset_microns(png_ptr, info_ptr));
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500364}
365#endif
366
367#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500368float PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600369png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600370{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500371 /* To avoid the overflow do the conversion directly in floating
372 * point.
373 */
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500374 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600375}
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500376#endif
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600377
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500378#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500379float PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600380png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600381{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500382 /* To avoid the overflow do the conversion directly in floating
383 * point.
384 */
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500385 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600386}
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500387#endif
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600388
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500389#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500390png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600391png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600392 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600393{
394 png_uint_32 retval = 0;
395
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600396 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600397 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500398 png_debug1(1, "in %s retrieval function", "pHYs");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500399
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600400 if (res_x != NULL)
401 {
402 *res_x = info_ptr->x_pixels_per_unit;
403 retval |= PNG_INFO_pHYs;
404 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500405
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600406 if (res_y != NULL)
407 {
408 *res_y = info_ptr->y_pixels_per_unit;
409 retval |= PNG_INFO_pHYs;
410 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500411
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600412 if (unit_type != NULL)
413 {
414 *unit_type = (int)info_ptr->phys_unit_type;
415 retval |= PNG_INFO_pHYs;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500416
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500417 if (*unit_type == 1)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600418 {
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600419 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
420 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600421 }
422 }
423 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500424
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600425 return (retval);
426}
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500427#endif /* PNG_pHYs_SUPPORTED */
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500428#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600429
430/* png_get_channels really belongs in here, too, but it's been around longer */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500431
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600432#endif /* PNG_EASY_ACCESS_SUPPORTED */
433
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600434
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500435png_byte PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600436png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500437{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600438 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500439 return(info_ptr->channels);
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500440
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500441 return (0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500442}
443
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600444#ifdef PNG_READ_SUPPORTED
Glenn Randers-Pehrsone600c512010-08-18 07:25:46 -0500445png_const_bytep PNGAPI
John Bowler4f67e402011-12-28 08:43:37 -0600446png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500447{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600448 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500449 return(info_ptr->signature);
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500450
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500451 return (NULL);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500452}
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600453#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500454
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500455#ifdef PNG_bKGD_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500456png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600457png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
Andreas Dilger47a0c421997-05-16 02:46:07 -0500458 png_color_16p *background)
459{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600460 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600461 && background != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500462 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500463 png_debug1(1, "in %s retrieval function", "bKGD");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500464
Andreas Dilger47a0c421997-05-16 02:46:07 -0500465 *background = &(info_ptr->background);
466 return (PNG_INFO_bKGD);
467 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500468
Andreas Dilger47a0c421997-05-16 02:46:07 -0500469 return (0);
470}
471#endif
472
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500473#ifdef PNG_cHRM_SUPPORTED
John Bowler736f40f2011-08-25 16:19:44 -0500474/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
475 * same time to correct the rgb grayscale coefficient defaults obtained from the
476 * cHRM chunk in 1.5.4
477 */
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500478# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500479png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600480png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600481 double *white_x, double *white_y, double *red_x, double *red_y,
482 double *green_x, double *green_y, double *blue_x, double *blue_y)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500483{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600484 /* Quiet API change: this code used to only return the end points if a cHRM
485 * chunk was present, but the end points can also come from iCCP or sRGB
486 * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and
487 * the png_set_ APIs merely check that set end points are mutually
488 * consistent.
489 */
490 if (png_ptr != NULL && info_ptr != NULL &&
491 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500492 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500493 png_debug1(1, "in %s retrieval function", "cHRM");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500494
Andreas Dilger47a0c421997-05-16 02:46:07 -0500495 if (white_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600496 *white_x = png_float(png_ptr,
497 info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500498 if (white_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600499 *white_y = png_float(png_ptr,
500 info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500501 if (red_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600502 *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
503 "cHRM red X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500504 if (red_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600505 *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
506 "cHRM red Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500507 if (green_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600508 *green_x = png_float(png_ptr,
509 info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500510 if (green_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600511 *green_y = png_float(png_ptr,
512 info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500513 if (blue_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600514 *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
515 "cHRM blue X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500516 if (blue_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600517 *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
518 "cHRM blue Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500519 return (PNG_INFO_cHRM);
520 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500521
Andreas Dilger47a0c421997-05-16 02:46:07 -0500522 return (0);
523}
John Bowler736f40f2011-08-25 16:19:44 -0500524
525png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600526png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
John Bowler736f40f2011-08-25 16:19:44 -0500527 double *red_X, double *red_Y, double *red_Z, double *green_X,
528 double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
529 double *blue_Z)
530{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600531 if (png_ptr != NULL && info_ptr != NULL &&
532 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
Glenn Randers-Pehrsonf3af7062012-02-02 23:11:45 -0600533 {
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600534 png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
535
John Bowler736f40f2011-08-25 16:19:44 -0500536 if (red_X != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600537 *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
538 "cHRM red X");
John Bowler736f40f2011-08-25 16:19:44 -0500539 if (red_Y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600540 *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
541 "cHRM red Y");
John Bowler736f40f2011-08-25 16:19:44 -0500542 if (red_Z != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600543 *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
544 "cHRM red Z");
John Bowler736f40f2011-08-25 16:19:44 -0500545 if (green_X != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600546 *green_X = png_float(png_ptr,
547 info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
John Bowler736f40f2011-08-25 16:19:44 -0500548 if (green_Y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600549 *green_Y = png_float(png_ptr,
550 info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
John Bowler736f40f2011-08-25 16:19:44 -0500551 if (green_Z != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600552 *green_Z = png_float(png_ptr,
553 info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
John Bowler736f40f2011-08-25 16:19:44 -0500554 if (blue_X != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600555 *blue_X = png_float(png_ptr,
556 info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
John Bowler736f40f2011-08-25 16:19:44 -0500557 if (blue_Y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600558 *blue_Y = png_float(png_ptr,
559 info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
John Bowler736f40f2011-08-25 16:19:44 -0500560 if (blue_Z != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600561 *blue_Z = png_float(png_ptr,
562 info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
John Bowler736f40f2011-08-25 16:19:44 -0500563 return (PNG_INFO_cHRM);
564 }
565
566 return (0);
567}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500568# endif
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500569
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500570# ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500571png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600572png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
573 png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
574 png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
575 png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
576 png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
577 png_fixed_point *int_blue_Z)
578{
579 if (png_ptr != NULL && info_ptr != NULL &&
580 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
581 {
582 png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
583
584 if (int_red_X != NULL)
585 *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;
586 if (int_red_Y != NULL)
587 *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;
588 if (int_red_Z != NULL)
589 *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;
590 if (int_green_X != NULL)
591 *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;
592 if (int_green_Y != NULL)
593 *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;
594 if (int_green_Z != NULL)
595 *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;
596 if (int_blue_X != NULL)
597 *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;
598 if (int_blue_Y != NULL)
599 *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;
600 if (int_blue_Z != NULL)
601 *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;
602 return (PNG_INFO_cHRM);
603 }
604
605 return (0);
606}
607
608png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600609png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600610 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
611 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
612 png_fixed_point *blue_x, png_fixed_point *blue_y)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600613{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500614 png_debug1(1, "in %s retrieval function", "cHRM");
615
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600616 if (png_ptr != NULL && info_ptr != NULL &&
617 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600618 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600619 if (white_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600620 *white_x = info_ptr->colorspace.end_points_xy.whitex;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600621 if (white_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600622 *white_y = info_ptr->colorspace.end_points_xy.whitey;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600623 if (red_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600624 *red_x = info_ptr->colorspace.end_points_xy.redx;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600625 if (red_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600626 *red_y = info_ptr->colorspace.end_points_xy.redy;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600627 if (green_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600628 *green_x = info_ptr->colorspace.end_points_xy.greenx;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600629 if (green_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600630 *green_y = info_ptr->colorspace.end_points_xy.greeny;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600631 if (blue_x != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600632 *blue_x = info_ptr->colorspace.end_points_xy.bluex;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600633 if (blue_y != NULL)
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600634 *blue_y = info_ptr->colorspace.end_points_xy.bluey;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600635 return (PNG_INFO_cHRM);
636 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500637
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600638 return (0);
639}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500640# endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600641#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500642
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500643#ifdef PNG_gAMA_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600644# ifdef PNG_FIXED_POINT_SUPPORTED
645png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600646png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500647 png_fixed_point *file_gamma)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500648{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500649 png_debug1(1, "in %s retrieval function", "gAMA");
650
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600651 if (png_ptr != NULL && info_ptr != NULL &&
652 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
653 file_gamma != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500654 {
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600655 *file_gamma = info_ptr->colorspace.gamma;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500656 return (PNG_INFO_gAMA);
657 }
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500658
Andreas Dilger47a0c421997-05-16 02:46:07 -0500659 return (0);
660}
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600661# endif
662
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500663# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500664png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600665png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600666 double *file_gamma)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600667{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600668 png_debug1(1, "in %s retrieval function", "gAMA(float)");
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500669
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600670 if (png_ptr != NULL && info_ptr != NULL &&
671 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
672 file_gamma != NULL)
673 {
674 *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
675 "png_get_gAMA");
676 return (PNG_INFO_gAMA);
677 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500678
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600679 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600680}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500681# endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500682#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500683
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500684#ifdef PNG_sRGB_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500685png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600686png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600687 int *file_srgb_intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600688{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500689 png_debug1(1, "in %s retrieval function", "sRGB");
690
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600691 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600692 && file_srgb_intent != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600693 {
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600694 *file_srgb_intent = info_ptr->colorspace.rendering_intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600695 return (PNG_INFO_sRGB);
696 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500697
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600698 return (0);
699}
700#endif
701
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500702#ifdef PNG_iCCP_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500703png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600704png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600705 png_charpp name, int *compression_type,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500706 png_bytepp profile, png_uint_32 *proflen)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600707{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500708 png_debug1(1, "in %s retrieval function", "iCCP");
709
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600710 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
John Bowler88bcdc22011-11-04 20:11:16 -0500711 && name != NULL && compression_type != NULL && profile != NULL &&
712 proflen != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600713 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600714 *name = info_ptr->iccp_name;
715 *profile = info_ptr->iccp_profile;
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600716 *proflen = png_get_uint_32(info_ptr->iccp_profile);
717 /* This is somewhat irrelevant since the profile data returned has
718 * actually been uncompressed.
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500719 */
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600720 *compression_type = PNG_COMPRESSION_TYPE_BASE;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600721 return (PNG_INFO_iCCP);
722 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500723
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600724 return (0);
725}
726#endif
727
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500728#ifdef PNG_sPLT_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600729int PNGAPI
730png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600731 png_sPLT_tpp spalettes)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600732{
733 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500734 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600735 *spalettes = info_ptr->splt_palettes;
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600736 return info_ptr->splt_palettes_num;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500737 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500738
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500739 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600740}
741#endif
742
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500743#ifdef PNG_hIST_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500744png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600745png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600746 png_uint_16p *hist)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500747{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500748 png_debug1(1, "in %s retrieval function", "hIST");
749
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600750 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600751 && hist != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500752 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500753 *hist = info_ptr->hist;
754 return (PNG_INFO_hIST);
755 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500756
Andreas Dilger47a0c421997-05-16 02:46:07 -0500757 return (0);
758}
759#endif
760
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500761png_uint_32 PNGAPI
John Bowler4f67e402011-12-28 08:43:37 -0600762png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600763 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
764 int *color_type, int *interlace_type, int *compression_type,
765 int *filter_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500766{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500767 png_debug1(1, "in %s retrieval function", "IHDR");
768
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500769 if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
770 height == NULL || bit_depth == NULL || color_type == NULL)
771 return (0);
772
773 *width = info_ptr->width;
774 *height = info_ptr->height;
775 *bit_depth = info_ptr->bit_depth;
776 *color_type = info_ptr->color_type;
777
778 if (compression_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500779 *compression_type = info_ptr->compression_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500780
781 if (filter_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500782 *filter_type = info_ptr->filter_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500783
784 if (interlace_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500785 *interlace_type = info_ptr->interlace_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500786
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500787 /* This is redundant if we can be sure that the info_ptr values were all
788 * assigned in png_set_IHDR(). We do the check anyhow in case an
789 * application has ignored our advice not to mess with the members
790 * of info_ptr directly.
791 */
Glenn Randers-Pehrsonad41b882011-12-22 07:31:13 -0600792 png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500793 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
794 info_ptr->compression_type, info_ptr->filter_type);
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500795
796 return (1);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500797}
798
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500799#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500800png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600801png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600802 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500803{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500804 png_debug1(1, "in %s retrieval function", "oFFs");
805
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600806 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600807 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500808 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500809 *offset_x = info_ptr->x_offset;
810 *offset_y = info_ptr->y_offset;
811 *unit_type = (int)info_ptr->offset_unit_type;
812 return (PNG_INFO_oFFs);
813 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500814
Andreas Dilger47a0c421997-05-16 02:46:07 -0500815 return (0);
816}
817#endif
818
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500819#ifdef PNG_pCAL_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500820png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600821png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600822 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
823 png_charp *units, png_charpp *params)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500824{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500825 png_debug1(1, "in %s retrieval function", "pCAL");
826
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600827 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500828 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
829 nparams != NULL && units != NULL && params != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500830 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500831 *purpose = info_ptr->pcal_purpose;
832 *X0 = info_ptr->pcal_X0;
833 *X1 = info_ptr->pcal_X1;
834 *type = (int)info_ptr->pcal_type;
835 *nparams = (int)info_ptr->pcal_nparams;
836 *units = info_ptr->pcal_units;
837 *params = info_ptr->pcal_params;
838 return (PNG_INFO_pCAL);
839 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500840
Andreas Dilger47a0c421997-05-16 02:46:07 -0500841 return (0);
842}
843#endif
844
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500845#ifdef PNG_sCAL_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500846# ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600847# if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
848 defined(PNG_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500849png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600850png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500851 int *unit, png_fixed_point *width, png_fixed_point *height)
852{
853 if (png_ptr != NULL && info_ptr != NULL &&
854 (info_ptr->valid & PNG_INFO_sCAL))
855 {
856 *unit = info_ptr->scal_unit;
John Bowler29fca0d2011-12-24 07:57:43 -0600857 /*TODO: make this work without FP support; the API is currently eliminated
858 * if neither floating point APIs nor internal floating point arithmetic
859 * are enabled.
860 */
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500861 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
862 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
863 "sCAL height");
864 return (PNG_INFO_sCAL);
865 }
866
867 return(0);
868}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500869# endif /* FLOATING_ARITHMETIC */
870# endif /* FIXED_POINT */
871# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500872png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600873png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600874 int *unit, double *width, double *height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600875{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600876 if (png_ptr != NULL && info_ptr != NULL &&
877 (info_ptr->valid & PNG_INFO_sCAL))
878 {
879 *unit = info_ptr->scal_unit;
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500880 *width = atof(info_ptr->scal_s_width);
881 *height = atof(info_ptr->scal_s_height);
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600882 return (PNG_INFO_sCAL);
883 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500884
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600885 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600886}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500887# endif /* FLOATING POINT */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500888png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600889png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500890 int *unit, png_charpp width, png_charpp height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600891{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600892 if (png_ptr != NULL && info_ptr != NULL &&
893 (info_ptr->valid & PNG_INFO_sCAL))
894 {
895 *unit = info_ptr->scal_unit;
896 *width = info_ptr->scal_s_width;
897 *height = info_ptr->scal_s_height;
898 return (PNG_INFO_sCAL);
899 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500900
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600901 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600902}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500903#endif /* sCAL */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600904
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500905#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500906png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600907png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600908 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500909{
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600910 png_uint_32 retval = 0;
911
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500912 png_debug1(1, "in %s retrieval function", "pHYs");
913
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600914 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600915 (info_ptr->valid & PNG_INFO_pHYs))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500916 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600917 if (res_x != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600918 {
919 *res_x = info_ptr->x_pixels_per_unit;
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600920 retval |= PNG_INFO_pHYs;
921 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500922
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600923 if (res_y != NULL)
924 {
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600925 *res_y = info_ptr->y_pixels_per_unit;
926 retval |= PNG_INFO_pHYs;
927 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500928
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600929 if (unit_type != NULL)
930 {
931 *unit_type = (int)info_ptr->phys_unit_type;
932 retval |= PNG_INFO_pHYs;
933 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500934 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500935
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600936 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500937}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500938#endif /* pHYs */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500939
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500940png_uint_32 PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600941png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600942 png_colorp *palette, int *num_palette)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500943{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500944 png_debug1(1, "in %s retrieval function", "PLTE");
945
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600946 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
947 && palette != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500948 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500949 *palette = info_ptr->palette;
950 *num_palette = info_ptr->num_palette;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500951 png_debug1(3, "num_palette = %d", *num_palette);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500952 return (PNG_INFO_PLTE);
953 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500954
Andreas Dilger47a0c421997-05-16 02:46:07 -0500955 return (0);
956}
957
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500958#ifdef PNG_sBIT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500959png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -0600960png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600961 png_color_8p *sig_bit)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500962{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500963 png_debug1(1, "in %s retrieval function", "sBIT");
964
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600965 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600966 && sig_bit != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500967 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500968 *sig_bit = &(info_ptr->sig_bit);
969 return (PNG_INFO_sBIT);
970 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500971
Andreas Dilger47a0c421997-05-16 02:46:07 -0500972 return (0);
973}
974#endif
975
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500976#ifdef PNG_TEXT_SUPPORTED
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600977int PNGAPI
978png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600979 png_textp *text_ptr, int *num_text)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500980{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600981 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500982 {
Glenn Randers-Pehrsonbb5cb142011-09-22 12:41:58 -0500983 png_debug1(1, "in 0x%lx retrieval function",
984 (unsigned long)png_ptr->chunk_name);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500985
Andreas Dilger47a0c421997-05-16 02:46:07 -0500986 if (text_ptr != NULL)
987 *text_ptr = info_ptr->text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500988
Andreas Dilger47a0c421997-05-16 02:46:07 -0500989 if (num_text != NULL)
990 *num_text = info_ptr->num_text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500991
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600992 return info_ptr->num_text;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500993 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500994
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600995 if (num_text != NULL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600996 *num_text = 0;
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500997
Andreas Dilger47a0c421997-05-16 02:46:07 -0500998 return(0);
999}
1000#endif
1001
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001002#ifdef PNG_tIME_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001003png_uint_32 PNGAPI
John Bowler4f67e402011-12-28 08:43:37 -06001004png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
1005 png_timep *mod_time)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001006{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -05001007 png_debug1(1, "in %s retrieval function", "tIME");
1008
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001009 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
1010 && mod_time != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001011 {
Andreas Dilger47a0c421997-05-16 02:46:07 -05001012 *mod_time = &(info_ptr->mod_time);
1013 return (PNG_INFO_tIME);
1014 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001015
Andreas Dilger47a0c421997-05-16 02:46:07 -05001016 return (0);
1017}
1018#endif
1019
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001020#ifdef PNG_tRNS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001021png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001022png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001023 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001024{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001025 png_uint_32 retval = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001026 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
Andreas Dilger47a0c421997-05-16 02:46:07 -05001027 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001028 png_debug1(1, "in %s retrieval function", "tRNS");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -05001029
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001030 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001031 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001032 if (trans_alpha != NULL)
1033 {
1034 *trans_alpha = info_ptr->trans_alpha;
1035 retval |= PNG_INFO_tRNS;
1036 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001037
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001038 if (trans_color != NULL)
1039 *trans_color = &(info_ptr->trans_color);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001040 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001041
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001042 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001043 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001044 if (trans_color != NULL)
1045 {
1046 *trans_color = &(info_ptr->trans_color);
1047 retval |= PNG_INFO_tRNS;
1048 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001049
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001050 if (trans_alpha != NULL)
1051 *trans_alpha = NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001052 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001053
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001054 if (num_trans != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001055 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001056 *num_trans = info_ptr->num_trans;
1057 retval |= PNG_INFO_tRNS;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001058 }
Andreas Dilger47a0c421997-05-16 02:46:07 -05001059 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001060
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001061 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001062}
1063#endif
1064
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001065#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001066int PNGAPI
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001067png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001068 png_unknown_chunkpp unknowns)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001069{
1070 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001071 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001072 *unknowns = info_ptr->unknown_chunks;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001073 return info_ptr->unknown_chunks_num;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001074 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001075
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001076 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001077}
1078#endif
1079
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001080#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001081png_byte PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001082png_get_rgb_to_gray_status (png_const_structrp png_ptr)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001083{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001084 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001085}
1086#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001087
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001088#ifdef PNG_USER_CHUNKS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001089png_voidp PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001090png_get_user_chunk_ptr(png_const_structrp png_ptr)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001091{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001092 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001093}
1094#endif
1095
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001096png_size_t PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001097png_get_compression_buffer_size(png_const_structrp png_ptr)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001098{
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001099 if (png_ptr == NULL)
1100 return 0;
1101
1102# ifdef PNG_WRITE_SUPPORTED
1103 if (png_ptr->mode & PNG_IS_READ_STRUCT)
1104# endif
1105 {
1106# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1107 return png_ptr->IDAT_read_size;
1108# else
1109 return PNG_IDAT_READ_SIZE;
1110# endif
1111 }
1112
1113# ifdef PNG_WRITE_SUPPORTED
1114 else
1115 return png_ptr->zbuffer_size;
1116# endif
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001117}
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001118
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001119#ifdef PNG_SET_USER_LIMITS_SUPPORTED
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001120/* These functions were added to libpng 1.2.6 and were enabled
1121 * by default in libpng-1.4.0 */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001122png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001123png_get_user_width_max (png_const_structrp png_ptr)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001124{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001125 return (png_ptr ? png_ptr->user_width_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001126}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001127
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001128png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001129png_get_user_height_max (png_const_structrp png_ptr)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001130{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001131 return (png_ptr ? png_ptr->user_height_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001132}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001133
Glenn Randers-Pehrson17ca3402009-11-09 06:51:16 -06001134/* This function was added to libpng 1.4.0 */
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001135png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001136png_get_chunk_cache_max (png_const_structrp png_ptr)
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001137{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001138 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001139}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001140
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001141/* This function was added to libpng 1.4.1 */
Glenn Randers-Pehrson7a5be532010-02-14 07:16:19 -06001142png_alloc_size_t PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001143png_get_chunk_malloc_max (png_const_structrp png_ptr)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001144{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001145 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001146}
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001147#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05001148
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001149/* These functions were added to libpng 1.4.0 */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001150#ifdef PNG_IO_STATE_SUPPORTED
1151png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001152png_get_io_state (png_const_structrp png_ptr)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001153{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001154 return png_ptr->io_state;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001155}
1156
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001157png_uint_32 PNGAPI
John Bowler5d567862011-12-24 09:12:00 -06001158png_get_io_chunk_type (png_const_structrp png_ptr)
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001159{
Glenn Randers-Pehrsonbb5cb142011-09-22 12:41:58 -05001160 return png_ptr->chunk_name;
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001161}
Glenn Randers-Pehrsonf3af7062012-02-02 23:11:45 -06001162#endif /* ?PNG_IO_STATE_SUPPORTED */
Glenn Randers-Pehrson32d6a742013-02-04 20:07:43 -06001163
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -06001164#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
1165# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
1166int PNGAPI
1167png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
1168{
1169 if (png_ptr != NULL && info_ptr != NULL)
1170 return png_ptr->num_palette_max;
1171
1172 return (-1);
1173}
1174# endif
1175#endif
1176
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001177#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */