blob: 41529d3b5d91489a1f29677bdfd7d5e23169f348 [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-Pehrson4be12aa2011-11-10 06:35:48 -06004 * Last changed in libpng 1.5.7 [(PENDING RELEASE)]
Glenn Randers-Pehrson64b863c2011-01-04 09:57:06 -06005 * Copyright (c) 1998-2011 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 Bowler0a5c9c02011-01-22 17:36:34 -060020png_get_valid(png_const_structp png_ptr, png_const_infop 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 Bowler0a5c9c02011-01-22 17:36:34 -060030png_get_rowbytes(png_const_structp png_ptr, png_const_infop 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 Bowler0a5c9c02011-01-22 17:36:34 -060040png_get_rows(png_const_structp png_ptr, png_const_infop 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 Bowler0a5c9c02011-01-22 17:36:34 -060052png_get_image_width(png_const_structp png_ptr, png_const_infop 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 Bowler0a5c9c02011-01-22 17:36:34 -060061png_get_image_height(png_const_structp png_ptr, png_const_infop 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 Bowler0a5c9c02011-01-22 17:36:34 -060070png_get_bit_depth(png_const_structp png_ptr, png_const_infop 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 Bowler0a5c9c02011-01-22 17:36:34 -060079png_get_color_type(png_const_structp png_ptr, png_const_infop 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 Bowler0a5c9c02011-01-22 17:36:34 -060088png_get_filter_type(png_const_structp png_ptr, png_const_infop 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 Bowler0a5c9c02011-01-22 17:36:34 -060097png_get_interlace_type(png_const_structp png_ptr, png_const_infop 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 Bowler0a5c9c02011-01-22 17:36:34 -0600106png_get_compression_type(png_const_structp png_ptr, png_const_infop 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
John Bowler0a5c9c02011-01-22 17:36:34 -0600115png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600116{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500117#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500118 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
119 {
120 png_debug1(1, "in %s retrieval function",
121 "png_get_x_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500122
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500123 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
124 return (info_ptr->x_pixels_per_unit);
125 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600126#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500127
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600128 return (0);
129}
130
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500131png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600132png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600133{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500134#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500135 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600136 {
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500137 png_debug1(1, "in %s retrieval function",
138 "png_get_y_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500139
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500140 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600141 return (info_ptr->y_pixels_per_unit);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600142 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600143#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500144
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600145 return (0);
146}
147
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500148png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600149png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600150{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500151#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500152 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600153 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500154 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500155
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500156 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
157 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600158 return (info_ptr->x_pixels_per_unit);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600159 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600160#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500161
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600162 return (0);
163}
164
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600165#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500166float PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600167png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600168{
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500169#ifdef PNG_READ_pHYs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500170 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600171 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500172 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500173
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500174 if (info_ptr->x_pixels_per_unit != 0)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500175 return ((float)((float)info_ptr->y_pixels_per_unit
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600176 /(float)info_ptr->x_pixels_per_unit));
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600177 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600178#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500179
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500180 return ((float)0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600181}
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600182#endif
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600183
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500184#ifdef PNG_FIXED_POINT_SUPPORTED
185png_fixed_point PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600186png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr,
187 png_const_infop info_ptr)
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500188{
189#ifdef PNG_READ_pHYs_SUPPORTED
190 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500191 && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
192 && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
193 && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500194 {
195 png_fixed_point res;
196
197 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
198
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500199 /* The following casts work because a PNG 4 byte integer only has a valid
200 * range of 0..2^31-1; otherwise the cast might overflow.
201 */
202 if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
203 (png_int_32)info_ptr->x_pixels_per_unit))
Glenn Randers-Pehrson3df324d2010-07-31 13:45:04 -0500204 return res;
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500205 }
206#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500207
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500208 return 0;
209}
210#endif
211
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500212png_int_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600213png_get_x_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600214{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500215#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500216 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600217 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500218 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500219
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500220 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600221 return (info_ptr->x_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600222 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600223#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500224
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600225 return (0);
226}
227
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500228png_int_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600229png_get_y_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600230{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500231#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500232 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600233 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500234 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500235
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500236 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600237 return (info_ptr->y_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600238 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600239#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500240
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600241 return (0);
242}
243
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500244png_int_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600245png_get_x_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600246{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500247#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500248 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600249 {
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500250 png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500251
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500252 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600253 return (info_ptr->x_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600254 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600255#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500256
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600257 return (0);
258}
259
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500260png_int_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600261png_get_y_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600262{
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500263#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500264 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600265 {
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500266 png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500267
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500268 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600269 return (info_ptr->y_offset);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600270 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600271#endif
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500272
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600273 return (0);
274}
275
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500276#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
277static png_uint_32
278ppi_from_ppm(png_uint_32 ppm)
279{
280#if 0
Glenn Randers-Pehrson233357e2010-07-29 21:49:38 -0500281 /* The conversion is *(2.54/100), in binary (32 digits):
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500282 * .00000110100000001001110101001001
283 */
284 png_uint_32 t1001, t1101;
285 ppm >>= 1; /* .1 */
286 t1001 = ppm + (ppm >> 3); /* .1001 */
287 t1101 = t1001 + (ppm >> 1); /* .1101 */
288 ppm >>= 20; /* .000000000000000000001 */
289 t1101 += t1101 >> 15; /* .1101000000000001101 */
290 t1001 >>= 11; /* .000000000001001 */
291 t1001 += t1001 >> 12; /* .000000000001001000000001001 */
292 ppm += t1001; /* .000000000001001000001001001 */
293 ppm += t1101; /* .110100000001001110101001001 */
294 return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
295#else
296 /* The argument is a PNG unsigned integer, so it is not permitted
297 * to be bigger than 2^31.
298 */
299 png_fixed_point result;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500300 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
301 5000))
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500302 return result;
303
304 /* Overflow. */
305 return 0;
306#endif
307}
308
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500309png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600310png_get_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600311{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500312 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600313}
314
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500315png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600316png_get_x_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600317{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500318 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600319}
320
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500321png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600322png_get_y_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600323{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500324 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600325}
326
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500327#ifdef PNG_FIXED_POINT_SUPPORTED
328static png_fixed_point
329png_fixed_inches_from_microns(png_structp png_ptr, png_int_32 microns)
330{
331 /* Convert from metres * 1,000,000 to inches * 100,000, meters to
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500332 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500333 * Notice that this can overflow - a warning is output and 0 is
334 * returned.
335 */
336 return png_muldiv_warn(png_ptr, microns, 500, 127);
337}
338
339png_fixed_point PNGAPI
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600340png_get_x_offset_inches_fixed(png_structp png_ptr,
John Bowler0a5c9c02011-01-22 17:36:34 -0600341 png_const_infop info_ptr)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500342{
343 return png_fixed_inches_from_microns(png_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500344 png_get_x_offset_microns(png_ptr, info_ptr));
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500345}
346#endif
347
348#ifdef PNG_FIXED_POINT_SUPPORTED
349png_fixed_point PNGAPI
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600350png_get_y_offset_inches_fixed(png_structp png_ptr,
John Bowler0a5c9c02011-01-22 17:36:34 -0600351 png_const_infop info_ptr)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500352{
353 return png_fixed_inches_from_microns(png_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500354 png_get_y_offset_microns(png_ptr, info_ptr));
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500355}
356#endif
357
358#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500359float PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600360png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600361{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500362 /* To avoid the overflow do the conversion directly in floating
363 * point.
364 */
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500365 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600366}
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500367#endif
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600368
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500369#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500370float PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600371png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600372{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500373 /* To avoid the overflow do the conversion directly in floating
374 * point.
375 */
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500376 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600377}
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500378#endif
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600379
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500380#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500381png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600382png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600383 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600384{
385 png_uint_32 retval = 0;
386
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600387 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600388 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500389 png_debug1(1, "in %s retrieval function", "pHYs");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500390
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600391 if (res_x != NULL)
392 {
393 *res_x = info_ptr->x_pixels_per_unit;
394 retval |= PNG_INFO_pHYs;
395 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500396
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600397 if (res_y != NULL)
398 {
399 *res_y = info_ptr->y_pixels_per_unit;
400 retval |= PNG_INFO_pHYs;
401 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500402
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600403 if (unit_type != NULL)
404 {
405 *unit_type = (int)info_ptr->phys_unit_type;
406 retval |= PNG_INFO_pHYs;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500407
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500408 if (*unit_type == 1)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600409 {
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600410 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
411 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600412 }
413 }
414 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500415
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600416 return (retval);
417}
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -0500418#endif /* PNG_pHYs_SUPPORTED */
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500419#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600420
421/* png_get_channels really belongs in here, too, but it's been around longer */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500422
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600423#endif /* PNG_EASY_ACCESS_SUPPORTED */
424
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500425png_byte PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600426png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500427{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600428 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500429 return(info_ptr->channels);
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500430
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500431 return (0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500432}
433
Glenn Randers-Pehrsone600c512010-08-18 07:25:46 -0500434png_const_bytep PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600435png_get_signature(png_const_structp png_ptr, png_infop info_ptr)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500436{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600437 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500438 return(info_ptr->signature);
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500439
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500440 return (NULL);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500441}
442
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500443#ifdef PNG_bKGD_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500444png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600445png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr,
Andreas Dilger47a0c421997-05-16 02:46:07 -0500446 png_color_16p *background)
447{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600448 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600449 && background != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500450 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500451 png_debug1(1, "in %s retrieval function", "bKGD");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500452
Andreas Dilger47a0c421997-05-16 02:46:07 -0500453 *background = &(info_ptr->background);
454 return (PNG_INFO_bKGD);
455 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500456
Andreas Dilger47a0c421997-05-16 02:46:07 -0500457 return (0);
458}
459#endif
460
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500461#ifdef PNG_cHRM_SUPPORTED
John Bowler736f40f2011-08-25 16:19:44 -0500462/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
463 * same time to correct the rgb grayscale coefficient defaults obtained from the
464 * cHRM chunk in 1.5.4
465 */
466png_uint_32 PNGFAPI
467png_get_cHRM_XYZ_fixed(png_structp png_ptr, png_const_infop info_ptr,
468 png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
469 png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
470 png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
471 png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
472 png_fixed_point *int_blue_Z)
473{
474 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
475 {
476 png_xy xy;
477 png_XYZ XYZ;
478
479 png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
480
481 xy.whitex = info_ptr->x_white;
482 xy.whitey = info_ptr->y_white;
483 xy.redx = info_ptr->x_red;
484 xy.redy = info_ptr->y_red;
485 xy.greenx = info_ptr->x_green;
486 xy.greeny = info_ptr->y_green;
487 xy.bluex = info_ptr->x_blue;
488 xy.bluey = info_ptr->y_blue;
489
490 /* The *_checked function handles error reporting, so just return 0 if
491 * there is a failure here.
492 */
493 if (png_XYZ_from_xy_checked(png_ptr, &XYZ, xy))
494 {
495 if (int_red_X != NULL)
496 *int_red_X = XYZ.redX;
497 if (int_red_Y != NULL)
498 *int_red_Y = XYZ.redY;
499 if (int_red_Z != NULL)
500 *int_red_Z = XYZ.redZ;
501 if (int_green_X != NULL)
502 *int_green_X = XYZ.greenX;
503 if (int_green_Y != NULL)
504 *int_green_Y = XYZ.greenY;
505 if (int_green_Z != NULL)
506 *int_green_Z = XYZ.greenZ;
507 if (int_blue_X != NULL)
508 *int_blue_X = XYZ.blueX;
509 if (int_blue_Y != NULL)
510 *int_blue_Y = XYZ.blueY;
511 if (int_blue_Z != NULL)
512 *int_blue_Z = XYZ.blueZ;
513
514 return (PNG_INFO_cHRM);
515 }
516 }
517
518 return (0);
519}
520
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500521# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500522png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600523png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600524 double *white_x, double *white_y, double *red_x, double *red_y,
525 double *green_x, double *green_y, double *blue_x, double *blue_y)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500526{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600527 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500528 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500529 png_debug1(1, "in %s retrieval function", "cHRM");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500530
Andreas Dilger47a0c421997-05-16 02:46:07 -0500531 if (white_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500532 *white_x = png_float(png_ptr, info_ptr->x_white, "cHRM white X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500533 if (white_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500534 *white_y = png_float(png_ptr, info_ptr->y_white, "cHRM white Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500535 if (red_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500536 *red_x = png_float(png_ptr, info_ptr->x_red, "cHRM red X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500537 if (red_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500538 *red_y = png_float(png_ptr, info_ptr->y_red, "cHRM red Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500539 if (green_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500540 *green_x = png_float(png_ptr, info_ptr->x_green, "cHRM green X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500541 if (green_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500542 *green_y = png_float(png_ptr, info_ptr->y_green, "cHRM green Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500543 if (blue_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500544 *blue_x = png_float(png_ptr, info_ptr->x_blue, "cHRM blue X");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500545 if (blue_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500546 *blue_y = png_float(png_ptr, info_ptr->y_blue, "cHRM blue Y");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500547 return (PNG_INFO_cHRM);
548 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500549
Andreas Dilger47a0c421997-05-16 02:46:07 -0500550 return (0);
551}
John Bowler736f40f2011-08-25 16:19:44 -0500552
553png_uint_32 PNGAPI
554png_get_cHRM_XYZ(png_structp png_ptr, png_const_infop info_ptr,
555 double *red_X, double *red_Y, double *red_Z, double *green_X,
556 double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
557 double *blue_Z)
558{
559 png_XYZ XYZ;
560
561 if (png_get_cHRM_XYZ_fixed(png_ptr, info_ptr,
562 &XYZ.redX, &XYZ.redY, &XYZ.redZ, &XYZ.greenX, &XYZ.greenY, &XYZ.greenZ,
563 &XYZ.blueX, &XYZ.blueY, &XYZ.blueZ) & PNG_INFO_cHRM)
564 {
565 if (red_X != NULL)
566 *red_X = png_float(png_ptr, XYZ.redX, "cHRM red X");
567 if (red_Y != NULL)
568 *red_Y = png_float(png_ptr, XYZ.redY, "cHRM red Y");
569 if (red_Z != NULL)
570 *red_Z = png_float(png_ptr, XYZ.redZ, "cHRM red Z");
571 if (green_X != NULL)
572 *green_X = png_float(png_ptr, XYZ.greenX, "cHRM green X");
573 if (green_Y != NULL)
574 *green_Y = png_float(png_ptr, XYZ.greenY, "cHRM green Y");
575 if (green_Z != NULL)
576 *green_Z = png_float(png_ptr, XYZ.greenZ, "cHRM green Z");
577 if (blue_X != NULL)
578 *blue_X = png_float(png_ptr, XYZ.blueX, "cHRM blue X");
579 if (blue_Y != NULL)
580 *blue_Y = png_float(png_ptr, XYZ.blueY, "cHRM blue Y");
581 if (blue_Z != NULL)
582 *blue_Z = png_float(png_ptr, XYZ.blueZ, "cHRM blue Z");
583 return (PNG_INFO_cHRM);
584 }
585
586 return (0);
587}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500588# endif
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500589
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500590# ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500591png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600592png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600593 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
594 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
595 png_fixed_point *blue_x, png_fixed_point *blue_y)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600596{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500597 png_debug1(1, "in %s retrieval function", "cHRM");
598
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600599 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
600 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600601 if (white_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500602 *white_x = info_ptr->x_white;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600603 if (white_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500604 *white_y = info_ptr->y_white;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600605 if (red_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500606 *red_x = info_ptr->x_red;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600607 if (red_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500608 *red_y = info_ptr->y_red;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600609 if (green_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500610 *green_x = info_ptr->x_green;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600611 if (green_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500612 *green_y = info_ptr->y_green;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600613 if (blue_x != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500614 *blue_x = info_ptr->x_blue;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600615 if (blue_y != NULL)
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500616 *blue_y = info_ptr->y_blue;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600617 return (PNG_INFO_cHRM);
618 }
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500619
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600620 return (0);
621}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500622# endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600623#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500624
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500625#ifdef PNG_gAMA_SUPPORTED
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500626png_uint_32 PNGFAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600627png_get_gAMA_fixed(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500628 png_fixed_point *file_gamma)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500629{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500630 png_debug1(1, "in %s retrieval function", "gAMA");
631
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600632 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600633 && file_gamma != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500634 {
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500635 *file_gamma = info_ptr->gamma;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500636 return (PNG_INFO_gAMA);
637 }
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500638
Andreas Dilger47a0c421997-05-16 02:46:07 -0500639 return (0);
640}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500641# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500642png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600643png_get_gAMA(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600644 double *file_gamma)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600645{
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500646 png_fixed_point igamma;
647 png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma);
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500648
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500649 if (ok)
650 *file_gamma = png_float(png_ptr, igamma, "png_get_gAMA");
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500651
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500652 return ok;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600653}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500654
655# endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500656#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500657
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500658#ifdef PNG_sRGB_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500659png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600660png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600661 int *file_srgb_intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600662{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500663 png_debug1(1, "in %s retrieval function", "sRGB");
664
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600665 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600666 && file_srgb_intent != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600667 {
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600668 *file_srgb_intent = (int)info_ptr->srgb_intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600669 return (PNG_INFO_sRGB);
670 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500671
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600672 return (0);
673}
674#endif
675
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500676#ifdef PNG_iCCP_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500677png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600678png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600679 png_charpp name, int *compression_type,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500680 png_bytepp profile, png_uint_32 *proflen)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600681{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500682 png_debug1(1, "in %s retrieval function", "iCCP");
683
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600684 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
John Bowler88bcdc22011-11-04 20:11:16 -0500685 && name != NULL && compression_type != NULL && profile != NULL &&
686 proflen != NULL)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600687 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600688 *name = info_ptr->iccp_name;
689 *profile = info_ptr->iccp_profile;
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500690 /* Compression_type is a dummy so the API won't have to change
691 * if we introduce multiple compression types later.
692 */
John Bowler88bcdc22011-11-04 20:11:16 -0500693 *proflen = info_ptr->iccp_proflen;
694 *compression_type = info_ptr->iccp_compression;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600695 return (PNG_INFO_iCCP);
696 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500697
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600698 return (0);
699}
700#endif
701
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500702#ifdef PNG_sPLT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500703png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600704png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600705 png_sPLT_tpp spalettes)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600706{
707 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500708 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600709 *spalettes = info_ptr->splt_palettes;
710 return ((png_uint_32)info_ptr->splt_palettes_num);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500711 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500712
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500713 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600714}
715#endif
716
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500717#ifdef PNG_hIST_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500718png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600719png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600720 png_uint_16p *hist)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500721{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500722 png_debug1(1, "in %s retrieval function", "hIST");
723
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600724 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600725 && hist != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500726 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500727 *hist = info_ptr->hist;
728 return (PNG_INFO_hIST);
729 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500730
Andreas Dilger47a0c421997-05-16 02:46:07 -0500731 return (0);
732}
733#endif
734
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500735png_uint_32 PNGAPI
Andreas Dilger47a0c421997-05-16 02:46:07 -0500736png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600737 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
738 int *color_type, int *interlace_type, int *compression_type,
739 int *filter_type)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600740
Andreas Dilger47a0c421997-05-16 02:46:07 -0500741{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500742 png_debug1(1, "in %s retrieval function", "IHDR");
743
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500744 if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
745 height == NULL || bit_depth == NULL || color_type == NULL)
746 return (0);
747
748 *width = info_ptr->width;
749 *height = info_ptr->height;
750 *bit_depth = info_ptr->bit_depth;
751 *color_type = info_ptr->color_type;
752
753 if (compression_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500754 *compression_type = info_ptr->compression_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500755
756 if (filter_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500757 *filter_type = info_ptr->filter_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500758
759 if (interlace_type != NULL)
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500760 *interlace_type = info_ptr->interlace_type;
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500761
Glenn Randers-Pehrsonb35a7452009-09-30 23:12:13 -0500762 /* This is redundant if we can be sure that the info_ptr values were all
763 * assigned in png_set_IHDR(). We do the check anyhow in case an
764 * application has ignored our advice not to mess with the members
765 * of info_ptr directly.
766 */
767 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
768 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
769 info_ptr->compression_type, info_ptr->filter_type);
Glenn Randers-Pehrson134bbe42009-09-24 18:10:49 -0500770
771 return (1);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500772}
773
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500774#ifdef PNG_oFFs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500775png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600776png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600777 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500778{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500779 png_debug1(1, "in %s retrieval function", "oFFs");
780
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600781 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600782 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500783 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500784 *offset_x = info_ptr->x_offset;
785 *offset_y = info_ptr->y_offset;
786 *unit_type = (int)info_ptr->offset_unit_type;
787 return (PNG_INFO_oFFs);
788 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500789
Andreas Dilger47a0c421997-05-16 02:46:07 -0500790 return (0);
791}
792#endif
793
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500794#ifdef PNG_pCAL_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500795png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600796png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600797 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
798 png_charp *units, png_charpp *params)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500799{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500800 png_debug1(1, "in %s retrieval function", "pCAL");
801
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600802 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500803 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
804 nparams != NULL && units != NULL && params != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500805 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500806 *purpose = info_ptr->pcal_purpose;
807 *X0 = info_ptr->pcal_X0;
808 *X1 = info_ptr->pcal_X1;
809 *type = (int)info_ptr->pcal_type;
810 *nparams = (int)info_ptr->pcal_nparams;
811 *units = info_ptr->pcal_units;
812 *params = info_ptr->pcal_params;
813 return (PNG_INFO_pCAL);
814 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500815
Andreas Dilger47a0c421997-05-16 02:46:07 -0500816 return (0);
817}
818#endif
819
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500820#ifdef PNG_sCAL_SUPPORTED
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500821# ifdef PNG_FIXED_POINT_SUPPORTED
822# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500823png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600824png_get_sCAL_fixed(png_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500825 int *unit, png_fixed_point *width, png_fixed_point *height)
826{
827 if (png_ptr != NULL && info_ptr != NULL &&
828 (info_ptr->valid & PNG_INFO_sCAL))
829 {
830 *unit = info_ptr->scal_unit;
Glenn Randers-Pehrson4009a762010-07-31 06:34:36 -0500831 /*TODO: make this work without FP support */
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500832 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
833 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
834 "sCAL height");
835 return (PNG_INFO_sCAL);
836 }
837
838 return(0);
839}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500840# endif /* FLOATING_ARITHMETIC */
841# endif /* FIXED_POINT */
842# ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500843png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600844png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600845 int *unit, double *width, double *height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600846{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600847 if (png_ptr != NULL && info_ptr != NULL &&
848 (info_ptr->valid & PNG_INFO_sCAL))
849 {
850 *unit = info_ptr->scal_unit;
Glenn Randers-Pehrson31aee0d2010-07-29 17:39:14 -0500851 *width = atof(info_ptr->scal_s_width);
852 *height = atof(info_ptr->scal_s_height);
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600853 return (PNG_INFO_sCAL);
854 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500855
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600856 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600857}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500858# endif /* FLOATING POINT */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500859png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600860png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -0500861 int *unit, png_charpp width, png_charpp height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600862{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600863 if (png_ptr != NULL && info_ptr != NULL &&
864 (info_ptr->valid & PNG_INFO_sCAL))
865 {
866 *unit = info_ptr->scal_unit;
867 *width = info_ptr->scal_s_width;
868 *height = info_ptr->scal_s_height;
869 return (PNG_INFO_sCAL);
870 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500871
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600872 return(0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600873}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500874#endif /* sCAL */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600875
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500876#ifdef PNG_pHYs_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500877png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600878png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600879 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500880{
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600881 png_uint_32 retval = 0;
882
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500883 png_debug1(1, "in %s retrieval function", "pHYs");
884
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600885 if (png_ptr != NULL && info_ptr != NULL &&
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600886 (info_ptr->valid & PNG_INFO_pHYs))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500887 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600888 if (res_x != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600889 {
890 *res_x = info_ptr->x_pixels_per_unit;
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600891 retval |= PNG_INFO_pHYs;
892 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500893
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600894 if (res_y != NULL)
895 {
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600896 *res_y = info_ptr->y_pixels_per_unit;
897 retval |= PNG_INFO_pHYs;
898 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500899
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600900 if (unit_type != NULL)
901 {
902 *unit_type = (int)info_ptr->phys_unit_type;
903 retval |= PNG_INFO_pHYs;
904 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500905 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500906
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600907 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500908}
Glenn Randers-Pehrson5c5f5932010-10-23 10:14:42 -0500909#endif /* pHYs */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500910
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500911png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600912png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600913 png_colorp *palette, int *num_palette)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500914{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500915 png_debug1(1, "in %s retrieval function", "PLTE");
916
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600917 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
918 && palette != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500919 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500920 *palette = info_ptr->palette;
921 *num_palette = info_ptr->num_palette;
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500922 png_debug1(3, "num_palette = %d", *num_palette);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500923 return (PNG_INFO_PLTE);
924 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500925
Andreas Dilger47a0c421997-05-16 02:46:07 -0500926 return (0);
927}
928
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500929#ifdef PNG_sBIT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500930png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600931png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600932 png_color_8p *sig_bit)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500933{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500934 png_debug1(1, "in %s retrieval function", "sBIT");
935
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600936 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600937 && sig_bit != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500938 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500939 *sig_bit = &(info_ptr->sig_bit);
940 return (PNG_INFO_sBIT);
941 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500942
Andreas Dilger47a0c421997-05-16 02:46:07 -0500943 return (0);
944}
945#endif
946
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500947#ifdef PNG_TEXT_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500948png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600949png_get_text(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrsonb86b4922011-01-21 23:12:51 -0600950 png_textp *text_ptr, int *num_text)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500951{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600952 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500953 {
Glenn Randers-Pehrsonbb5cb142011-09-22 12:41:58 -0500954 png_debug1(1, "in 0x%lx retrieval function",
955 (unsigned long)png_ptr->chunk_name);
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500956
Andreas Dilger47a0c421997-05-16 02:46:07 -0500957 if (text_ptr != NULL)
958 *text_ptr = info_ptr->text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500959
Andreas Dilger47a0c421997-05-16 02:46:07 -0500960 if (num_text != NULL)
961 *num_text = info_ptr->num_text;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500962
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600963 return ((png_uint_32)info_ptr->num_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500964 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500965
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600966 if (num_text != NULL)
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600967 *num_text = 0;
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500968
Andreas Dilger47a0c421997-05-16 02:46:07 -0500969 return(0);
970}
971#endif
972
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500973#ifdef PNG_tIME_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500974png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600975png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500976{
Glenn Randers-Pehrsonb3ce3652009-08-15 21:47:03 -0500977 png_debug1(1, "in %s retrieval function", "tIME");
978
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600979 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
980 && mod_time != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500981 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500982 *mod_time = &(info_ptr->mod_time);
983 return (PNG_INFO_tIME);
984 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -0500985
Andreas Dilger47a0c421997-05-16 02:46:07 -0500986 return (0);
987}
988#endif
989
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500990#ifdef PNG_tRNS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500991png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -0600992png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -0600993 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500994{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600995 png_uint_32 retval = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600996 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500997 {
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500998 png_debug1(1, "in %s retrieval function", "tRNS");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500999
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001000 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001001 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001002 if (trans_alpha != NULL)
1003 {
1004 *trans_alpha = info_ptr->trans_alpha;
1005 retval |= PNG_INFO_tRNS;
1006 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001007
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001008 if (trans_color != NULL)
1009 *trans_color = &(info_ptr->trans_color);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001010 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001011
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001012 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001013 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001014 if (trans_color != NULL)
1015 {
1016 *trans_color = &(info_ptr->trans_color);
1017 retval |= PNG_INFO_tRNS;
1018 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001019
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001020 if (trans_alpha != NULL)
1021 *trans_alpha = NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001022 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001023
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001024 if (num_trans != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001025 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001026 *num_trans = info_ptr->num_trans;
1027 retval |= PNG_INFO_tRNS;
Andreas Dilger47a0c421997-05-16 02:46:07 -05001028 }
Andreas Dilger47a0c421997-05-16 02:46:07 -05001029 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001030
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001031 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001032}
1033#endif
1034
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001035#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001036int PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -06001037png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr,
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001038 png_unknown_chunkpp unknowns)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001039{
1040 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001041 {
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001042 *unknowns = info_ptr->unknown_chunks;
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001043 return info_ptr->unknown_chunks_num;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001044 }
Glenn Randers-Pehrsonf24daf22010-05-06 09:44:04 -05001045
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001046 return (0);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001047}
1048#endif
1049
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001050#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001051png_byte PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -06001052png_get_rgb_to_gray_status (png_const_structp png_ptr)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001053{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001054 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001055}
1056#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001057
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001058#ifdef PNG_USER_CHUNKS_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001059png_voidp PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -06001060png_get_user_chunk_ptr(png_const_structp png_ptr)
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001061{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001062 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001063}
1064#endif
1065
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001066png_size_t PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -06001067png_get_compression_buffer_size(png_const_structp png_ptr)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001068{
John Bowler75156122011-09-09 17:21:44 -05001069 return (png_ptr ? png_ptr->zbuf_size : 0);
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001070}
Glenn Randers-Pehrsone68f5a32001-05-14 09:20:53 -05001071
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001072#ifdef PNG_SET_USER_LIMITS_SUPPORTED
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001073/* These functions were added to libpng 1.2.6 and were enabled
1074 * by default in libpng-1.4.0 */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001075png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -06001076png_get_user_width_max (png_const_structp png_ptr)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001077{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001078 return (png_ptr ? png_ptr->user_width_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001079}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001080
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001081png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -06001082png_get_user_height_max (png_const_structp png_ptr)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001083{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001084 return (png_ptr ? png_ptr->user_height_max : 0);
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001085}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001086
Glenn Randers-Pehrson17ca3402009-11-09 06:51:16 -06001087/* This function was added to libpng 1.4.0 */
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001088png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -06001089png_get_chunk_cache_max (png_const_structp png_ptr)
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001090{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001091 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001092}
Glenn Randers-Pehrson4aa2cd62010-08-19 16:52:01 -05001093
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001094/* This function was added to libpng 1.4.1 */
Glenn Randers-Pehrson7a5be532010-02-14 07:16:19 -06001095png_alloc_size_t PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -06001096png_get_chunk_malloc_max (png_const_structp png_ptr)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001097{
Glenn Randers-Pehrsona565f0e2010-03-06 08:24:45 -06001098 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
Glenn Randers-Pehrson800d1e92008-08-20 17:25:21 -05001099}
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001100#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -05001101
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -06001102/* These functions were added to libpng 1.4.0 */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001103#ifdef PNG_IO_STATE_SUPPORTED
1104png_uint_32 PNGAPI
1105png_get_io_state (png_structp png_ptr)
1106{
Glenn Randers-Pehrson16908a12010-03-06 07:34:28 -06001107 return png_ptr->io_state;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001108}
1109
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001110png_uint_32 PNGAPI
John Bowler0a5c9c02011-01-22 17:36:34 -06001111png_get_io_chunk_type (png_const_structp png_ptr)
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001112{
Glenn Randers-Pehrsonbb5cb142011-09-22 12:41:58 -05001113 return png_ptr->chunk_name;
Glenn Randers-Pehrsona63dbed2011-01-22 08:51:19 -06001114}
1115
Glenn Randers-Pehrsone600c512010-08-18 07:25:46 -05001116png_const_bytep PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001117png_get_io_chunk_name (png_structp png_ptr)
1118{
Glenn Randers-Pehrsonbb5cb142011-09-22 12:41:58 -05001119 PNG_CSTRING_FROM_CHUNK(png_ptr->io_chunk_string, png_ptr->chunk_name);
1120 return png_ptr->io_chunk_string;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001121}
1122#endif /* ?PNG_IO_STATE_SUPPORTED */
1123
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001124#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */