blob: aca63a9589ce022367deddabef46e42b3b4db444 [file] [log] [blame]
The Android Open Source Project893912b2009-03-03 19:30:05 -08001
2/* pngget.c - retrieval of values from info struct
3 *
Chris Craikca2bf812013-07-29 15:28:30 -07004 * Last changed in libpng 1.6.1 [March 28, 2013]
5 * Copyright (c) 1998-2013 Glenn Randers-Pehrson
The Android Open Source Project893912b2009-03-03 19:30:05 -08006 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Patrick Scotta0bb96c2009-07-22 11:50:02 -04008 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
The Android Open Source Project893912b2009-03-03 19:30:05 -080013 */
14
Chris Craikca2bf812013-07-29 15:28:30 -070015#include "pngpriv.h"
16
The Android Open Source Project893912b2009-03-03 19:30:05 -080017#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
18
19png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -070020png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
21 png_uint_32 flag)
The Android Open Source Project893912b2009-03-03 19:30:05 -080022{
23 if (png_ptr != NULL && info_ptr != NULL)
24 return(info_ptr->valid & flag);
Patrick Scotta0bb96c2009-07-22 11:50:02 -040025
Chris Craikca2bf812013-07-29 15:28:30 -070026 return(0);
The Android Open Source Project893912b2009-03-03 19:30:05 -080027}
28
Chris Craikca2bf812013-07-29 15:28:30 -070029png_size_t PNGAPI
30png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -080031{
32 if (png_ptr != NULL && info_ptr != NULL)
33 return(info_ptr->rowbytes);
Patrick Scotta0bb96c2009-07-22 11:50:02 -040034
Chris Craikca2bf812013-07-29 15:28:30 -070035 return(0);
The Android Open Source Project893912b2009-03-03 19:30:05 -080036}
37
Patrick Scott5f6bd842010-06-28 16:55:16 -040038#ifdef PNG_INFO_IMAGE_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -080039png_bytepp PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -070040png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -080041{
42 if (png_ptr != NULL && info_ptr != NULL)
43 return(info_ptr->row_pointers);
Patrick Scotta0bb96c2009-07-22 11:50:02 -040044
Chris Craikca2bf812013-07-29 15:28:30 -070045 return(0);
The Android Open Source Project893912b2009-03-03 19:30:05 -080046}
47#endif
48
49#ifdef PNG_EASY_ACCESS_SUPPORTED
Patrick Scotta0bb96c2009-07-22 11:50:02 -040050/* Easy access to info, added in libpng-0.99 */
The Android Open Source Project893912b2009-03-03 19:30:05 -080051png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -070052png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -080053{
54 if (png_ptr != NULL && info_ptr != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -080055 return info_ptr->width;
Patrick Scotta0bb96c2009-07-22 11:50:02 -040056
The Android Open Source Project893912b2009-03-03 19:30:05 -080057 return (0);
58}
59
60png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -070061png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -080062{
63 if (png_ptr != NULL && info_ptr != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -080064 return info_ptr->height;
Patrick Scotta0bb96c2009-07-22 11:50:02 -040065
The Android Open Source Project893912b2009-03-03 19:30:05 -080066 return (0);
67}
68
69png_byte PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -070070png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -080071{
72 if (png_ptr != NULL && info_ptr != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -080073 return info_ptr->bit_depth;
Patrick Scotta0bb96c2009-07-22 11:50:02 -040074
The Android Open Source Project893912b2009-03-03 19:30:05 -080075 return (0);
76}
77
78png_byte PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -070079png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -080080{
81 if (png_ptr != NULL && info_ptr != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -080082 return info_ptr->color_type;
Patrick Scotta0bb96c2009-07-22 11:50:02 -040083
The Android Open Source Project893912b2009-03-03 19:30:05 -080084 return (0);
85}
86
87png_byte PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -070088png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -080089{
90 if (png_ptr != NULL && info_ptr != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -080091 return info_ptr->filter_type;
Patrick Scotta0bb96c2009-07-22 11:50:02 -040092
The Android Open Source Project893912b2009-03-03 19:30:05 -080093 return (0);
94}
95
96png_byte PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -070097png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -080098{
99 if (png_ptr != NULL && info_ptr != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800100 return info_ptr->interlace_type;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400101
The Android Open Source Project893912b2009-03-03 19:30:05 -0800102 return (0);
103}
104
105png_byte PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700106png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800107{
108 if (png_ptr != NULL && info_ptr != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800109 return info_ptr->compression_type;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400110
The Android Open Source Project893912b2009-03-03 19:30:05 -0800111 return (0);
112}
113
114png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700115png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
116 info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800117{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400118#ifdef PNG_pHYs_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -0700119 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");
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400123
Chris Craikca2bf812013-07-29 15:28:30 -0700124 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
125 return (info_ptr->x_pixels_per_unit);
126 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800127#endif
Chris Craikca2bf812013-07-29 15:28:30 -0700128
The Android Open Source Project893912b2009-03-03 19:30:05 -0800129 return (0);
130}
131
132png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700133png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
134 info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800135{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400136#ifdef PNG_pHYs_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -0700137 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
The Android Open Source Project893912b2009-03-03 19:30:05 -0800138 {
Chris Craikca2bf812013-07-29 15:28:30 -0700139 png_debug1(1, "in %s retrieval function",
140 "png_get_y_pixels_per_meter");
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400141
Chris Craikca2bf812013-07-29 15:28:30 -0700142 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
143 return (info_ptr->y_pixels_per_unit);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800144 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800145#endif
Chris Craikca2bf812013-07-29 15:28:30 -0700146
The Android Open Source Project893912b2009-03-03 19:30:05 -0800147 return (0);
148}
149
150png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700151png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800152{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400153#ifdef PNG_pHYs_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -0700154 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
The Android Open Source Project893912b2009-03-03 19:30:05 -0800155 {
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700156 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400157
Chris Craikca2bf812013-07-29 15:28:30 -0700158 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
159 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
160 return (info_ptr->x_pixels_per_unit);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800161 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800162#endif
Chris Craikca2bf812013-07-29 15:28:30 -0700163
The Android Open Source Project893912b2009-03-03 19:30:05 -0800164 return (0);
165}
166
167#ifdef PNG_FLOATING_POINT_SUPPORTED
168float PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700169png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
170 info_ptr)
171{
172#ifdef PNG_READ_pHYs_SUPPORTED
173 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
The Android Open Source Project893912b2009-03-03 19:30:05 -0800174 {
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700175 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400176
Chris Craikca2bf812013-07-29 15:28:30 -0700177 if (info_ptr->x_pixels_per_unit != 0)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800178 return ((float)((float)info_ptr->y_pixels_per_unit
Chris Craikca2bf812013-07-29 15:28:30 -0700179 /(float)info_ptr->x_pixels_per_unit));
The Android Open Source Project893912b2009-03-03 19:30:05 -0800180 }
181#else
Chris Craikca2bf812013-07-29 15:28:30 -0700182 PNG_UNUSED(png_ptr)
183 PNG_UNUSED(info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800184#endif
Chris Craikca2bf812013-07-29 15:28:30 -0700185
The Android Open Source Project893912b2009-03-03 19:30:05 -0800186 return ((float)0.0);
187}
188#endif
189
Chris Craikca2bf812013-07-29 15:28:30 -0700190#ifdef PNG_FIXED_POINT_SUPPORTED
191png_fixed_point PNGAPI
192png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
193 png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800194{
Chris Craikca2bf812013-07-29 15:28:30 -0700195#ifdef PNG_READ_pHYs_SUPPORTED
196 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
197 && 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)
200 {
201 png_fixed_point res;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400202
Chris Craikca2bf812013-07-29 15:28:30 -0700203 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
204
205 /* 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))
210 return res;
211 }
212#else
213 PNG_UNUSED(png_ptr)
214 PNG_UNUSED(info_ptr)
215#endif
216
217 return 0;
218}
219#endif
220
221png_int_32 PNGAPI
222png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
223{
224#ifdef PNG_oFFs_SUPPORTED
225 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
The Android Open Source Project893912b2009-03-03 19:30:05 -0800226 {
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700227 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400228
Chris Craikca2bf812013-07-29 15:28:30 -0700229 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
230 return (info_ptr->x_offset);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800231 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800232#endif
Chris Craikca2bf812013-07-29 15:28:30 -0700233
The Android Open Source Project893912b2009-03-03 19:30:05 -0800234 return (0);
235}
236
237png_int_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700238png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800239{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400240#ifdef PNG_oFFs_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -0700241 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
The Android Open Source Project893912b2009-03-03 19:30:05 -0800242 {
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700243 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400244
Chris Craikca2bf812013-07-29 15:28:30 -0700245 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
246 return (info_ptr->y_offset);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800247 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800248#endif
Chris Craikca2bf812013-07-29 15:28:30 -0700249
The Android Open Source Project893912b2009-03-03 19:30:05 -0800250 return (0);
251}
252
253png_int_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700254png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800255{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400256#ifdef PNG_oFFs_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -0700257 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
The Android Open Source Project893912b2009-03-03 19:30:05 -0800258 {
Chris Craikca2bf812013-07-29 15:28:30 -0700259 png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400260
Chris Craikca2bf812013-07-29 15:28:30 -0700261 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
262 return (info_ptr->x_offset);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800263 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800264#endif
Chris Craikca2bf812013-07-29 15:28:30 -0700265
The Android Open Source Project893912b2009-03-03 19:30:05 -0800266 return (0);
267}
268
269png_int_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700270png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800271{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400272#ifdef PNG_oFFs_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -0700273 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
The Android Open Source Project893912b2009-03-03 19:30:05 -0800274 {
Chris Craikca2bf812013-07-29 15:28:30 -0700275 png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400276
Chris Craikca2bf812013-07-29 15:28:30 -0700277 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
278 return (info_ptr->y_offset);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800279 }
The Android Open Source Project893912b2009-03-03 19:30:05 -0800280#endif
Chris Craikca2bf812013-07-29 15:28:30 -0700281
The Android Open Source Project893912b2009-03-03 19:30:05 -0800282 return (0);
283}
284
Chris Craikca2bf812013-07-29 15:28:30 -0700285#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
286static png_uint_32
287ppi_from_ppm(png_uint_32 ppm)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800288{
Chris Craikca2bf812013-07-29 15:28:30 -0700289#if 0
290 /* The conversion is *(2.54/100), in binary (32 digits):
291 * .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;
309 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
310 5000))
311 return result;
312
313 /* Overflow. */
314 return 0;
315#endif
The Android Open Source Project893912b2009-03-03 19:30:05 -0800316}
317
318png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700319png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800320{
Chris Craikca2bf812013-07-29 15:28:30 -0700321 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
The Android Open Source Project893912b2009-03-03 19:30:05 -0800322}
323
324png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700325png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800326{
Chris Craikca2bf812013-07-29 15:28:30 -0700327 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
The Android Open Source Project893912b2009-03-03 19:30:05 -0800328}
329
Chris Craikca2bf812013-07-29 15:28:30 -0700330png_uint_32 PNGAPI
331png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
332{
333 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
334}
335
336#ifdef PNG_FIXED_POINT_SUPPORTED
337static png_fixed_point
338png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
339{
340 /* Convert from metres * 1,000,000 to inches * 100,000, meters to
341 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
342 * 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
349png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
350 png_const_inforp info_ptr)
351{
352 return png_fixed_inches_from_microns(png_ptr,
353 png_get_x_offset_microns(png_ptr, info_ptr));
354}
355#endif
356
357#ifdef PNG_FIXED_POINT_SUPPORTED
358png_fixed_point PNGAPI
359png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
360 png_const_inforp info_ptr)
361{
362 return png_fixed_inches_from_microns(png_ptr,
363 png_get_y_offset_microns(png_ptr, info_ptr));
364}
365#endif
366
367#ifdef PNG_FLOATING_POINT_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800368float PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700369png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800370{
Chris Craikca2bf812013-07-29 15:28:30 -0700371 /* To avoid the overflow do the conversion directly in floating
372 * point.
373 */
374 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800375}
Chris Craikca2bf812013-07-29 15:28:30 -0700376#endif
The Android Open Source Project893912b2009-03-03 19:30:05 -0800377
Chris Craikca2bf812013-07-29 15:28:30 -0700378#ifdef PNG_FLOATING_POINT_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800379float PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700380png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800381{
Chris Craikca2bf812013-07-29 15:28:30 -0700382 /* To avoid the overflow do the conversion directly in floating
383 * point.
384 */
385 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800386}
Chris Craikca2bf812013-07-29 15:28:30 -0700387#endif
The Android Open Source Project893912b2009-03-03 19:30:05 -0800388
Patrick Scott5f6bd842010-06-28 16:55:16 -0400389#ifdef PNG_pHYs_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800390png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700391png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
392 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800393{
394 png_uint_32 retval = 0;
395
396 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
397 {
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700398 png_debug1(1, "in %s retrieval function", "pHYs");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400399
The Android Open Source Project893912b2009-03-03 19:30:05 -0800400 if (res_x != NULL)
401 {
402 *res_x = info_ptr->x_pixels_per_unit;
403 retval |= PNG_INFO_pHYs;
404 }
Chris Craikca2bf812013-07-29 15:28:30 -0700405
The Android Open Source Project893912b2009-03-03 19:30:05 -0800406 if (res_y != NULL)
407 {
408 *res_y = info_ptr->y_pixels_per_unit;
409 retval |= PNG_INFO_pHYs;
410 }
Chris Craikca2bf812013-07-29 15:28:30 -0700411
The Android Open Source Project893912b2009-03-03 19:30:05 -0800412 if (unit_type != NULL)
413 {
414 *unit_type = (int)info_ptr->phys_unit_type;
415 retval |= PNG_INFO_pHYs;
Chris Craikca2bf812013-07-29 15:28:30 -0700416
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700417 if (*unit_type == 1)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800418 {
419 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);
421 }
422 }
423 }
Chris Craikca2bf812013-07-29 15:28:30 -0700424
The Android Open Source Project893912b2009-03-03 19:30:05 -0800425 return (retval);
426}
427#endif /* PNG_pHYs_SUPPORTED */
Chris Craikca2bf812013-07-29 15:28:30 -0700428#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
The Android Open Source Project893912b2009-03-03 19:30:05 -0800429
430/* png_get_channels really belongs in here, too, but it's been around longer */
431
432#endif /* PNG_EASY_ACCESS_SUPPORTED */
433
Chris Craikca2bf812013-07-29 15:28:30 -0700434
The Android Open Source Project893912b2009-03-03 19:30:05 -0800435png_byte PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700436png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800437{
438 if (png_ptr != NULL && info_ptr != NULL)
439 return(info_ptr->channels);
Chris Craikca2bf812013-07-29 15:28:30 -0700440
441 return (0);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800442}
443
Chris Craikca2bf812013-07-29 15:28:30 -0700444#ifdef PNG_READ_SUPPORTED
445png_const_bytep PNGAPI
446png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800447{
448 if (png_ptr != NULL && info_ptr != NULL)
449 return(info_ptr->signature);
Chris Craikca2bf812013-07-29 15:28:30 -0700450
451 return (NULL);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800452}
Chris Craikca2bf812013-07-29 15:28:30 -0700453#endif
The Android Open Source Project893912b2009-03-03 19:30:05 -0800454
Patrick Scott5f6bd842010-06-28 16:55:16 -0400455#ifdef PNG_bKGD_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800456png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700457png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
The Android Open Source Project893912b2009-03-03 19:30:05 -0800458 png_color_16p *background)
459{
460 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
Chris Craikca2bf812013-07-29 15:28:30 -0700461 && background != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800462 {
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700463 png_debug1(1, "in %s retrieval function", "bKGD");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400464
The Android Open Source Project893912b2009-03-03 19:30:05 -0800465 *background = &(info_ptr->background);
466 return (PNG_INFO_bKGD);
467 }
Chris Craikca2bf812013-07-29 15:28:30 -0700468
The Android Open Source Project893912b2009-03-03 19:30:05 -0800469 return (0);
470}
471#endif
472
Patrick Scott5f6bd842010-06-28 16:55:16 -0400473#ifdef PNG_cHRM_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -0700474/* 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 */
478# ifdef PNG_FLOATING_POINT_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800479png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700480png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
481 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)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800483{
Chris Craikca2bf812013-07-29 15:28:30 -0700484 /* 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))
The Android Open Source Project893912b2009-03-03 19:30:05 -0800492 {
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700493 png_debug1(1, "in %s retrieval function", "cHRM");
Patrick Scott5f6bd842010-06-28 16:55:16 -0400494
The Android Open Source Project893912b2009-03-03 19:30:05 -0800495 if (white_x != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700496 *white_x = png_float(png_ptr,
497 info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800498 if (white_y != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700499 *white_y = png_float(png_ptr,
500 info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800501 if (red_x != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700502 *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
503 "cHRM red X");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800504 if (red_y != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700505 *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
506 "cHRM red Y");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800507 if (green_x != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700508 *green_x = png_float(png_ptr,
509 info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800510 if (green_y != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700511 *green_y = png_float(png_ptr,
512 info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800513 if (blue_x != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700514 *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
515 "cHRM blue X");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800516 if (blue_y != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700517 *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
518 "cHRM blue Y");
The Android Open Source Project893912b2009-03-03 19:30:05 -0800519 return (PNG_INFO_cHRM);
520 }
Chris Craikca2bf812013-07-29 15:28:30 -0700521
The Android Open Source Project893912b2009-03-03 19:30:05 -0800522 return (0);
523}
Chris Craikca2bf812013-07-29 15:28:30 -0700524
The Android Open Source Project893912b2009-03-03 19:30:05 -0800525png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700526png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
527 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{
531 if (png_ptr != NULL && info_ptr != NULL &&
532 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
533 {
534 png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
535
536 if (red_X != NULL)
537 *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
538 "cHRM red X");
539 if (red_Y != NULL)
540 *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
541 "cHRM red Y");
542 if (red_Z != NULL)
543 *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
544 "cHRM red Z");
545 if (green_X != NULL)
546 *green_X = png_float(png_ptr,
547 info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
548 if (green_Y != NULL)
549 *green_Y = png_float(png_ptr,
550 info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
551 if (green_Z != NULL)
552 *green_Z = png_float(png_ptr,
553 info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
554 if (blue_X != NULL)
555 *blue_X = png_float(png_ptr,
556 info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
557 if (blue_Y != NULL)
558 *blue_Y = png_float(png_ptr,
559 info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
560 if (blue_Z != NULL)
561 *blue_Z = png_float(png_ptr,
562 info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
563 return (PNG_INFO_cHRM);
564 }
565
566 return (0);
567}
568# endif
569
570# ifdef PNG_FIXED_POINT_SUPPORTED
571png_uint_32 PNGAPI
572png_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
609png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
610 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)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800613{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400614 png_debug1(1, "in %s retrieval function", "cHRM");
615
Chris Craikca2bf812013-07-29 15:28:30 -0700616 if (png_ptr != NULL && info_ptr != NULL &&
617 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
The Android Open Source Project893912b2009-03-03 19:30:05 -0800618 {
The Android Open Source Project893912b2009-03-03 19:30:05 -0800619 if (white_x != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700620 *white_x = info_ptr->colorspace.end_points_xy.whitex;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800621 if (white_y != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700622 *white_y = info_ptr->colorspace.end_points_xy.whitey;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800623 if (red_x != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700624 *red_x = info_ptr->colorspace.end_points_xy.redx;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800625 if (red_y != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700626 *red_y = info_ptr->colorspace.end_points_xy.redy;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800627 if (green_x != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700628 *green_x = info_ptr->colorspace.end_points_xy.greenx;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800629 if (green_y != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700630 *green_y = info_ptr->colorspace.end_points_xy.greeny;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800631 if (blue_x != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700632 *blue_x = info_ptr->colorspace.end_points_xy.bluex;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800633 if (blue_y != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700634 *blue_y = info_ptr->colorspace.end_points_xy.bluey;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800635 return (PNG_INFO_cHRM);
636 }
Chris Craikca2bf812013-07-29 15:28:30 -0700637
The Android Open Source Project893912b2009-03-03 19:30:05 -0800638 return (0);
639}
Chris Craikca2bf812013-07-29 15:28:30 -0700640# endif
The Android Open Source Project893912b2009-03-03 19:30:05 -0800641#endif
642
Patrick Scott5f6bd842010-06-28 16:55:16 -0400643#ifdef PNG_gAMA_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -0700644# ifdef PNG_FIXED_POINT_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800645png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700646png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
647 png_fixed_point *file_gamma)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800648{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400649 png_debug1(1, "in %s retrieval function", "gAMA");
650
Chris Craikca2bf812013-07-29 15:28:30 -0700651 if (png_ptr != NULL && info_ptr != NULL &&
652 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
653 file_gamma != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800654 {
Chris Craikca2bf812013-07-29 15:28:30 -0700655 *file_gamma = info_ptr->colorspace.gamma;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800656 return (PNG_INFO_gAMA);
657 }
Patrick Scott5f6bd842010-06-28 16:55:16 -0400658
The Android Open Source Project893912b2009-03-03 19:30:05 -0800659 return (0);
660}
Chris Craikca2bf812013-07-29 15:28:30 -0700661# endif
662
663# ifdef PNG_FLOATING_POINT_SUPPORTED
664png_uint_32 PNGAPI
665png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
666 double *file_gamma)
667{
668 png_debug1(1, "in %s retrieval function", "gAMA(float)");
669
670 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 }
678
679 return (0);
680}
681# endif
The Android Open Source Project893912b2009-03-03 19:30:05 -0800682#endif
683
Patrick Scott5f6bd842010-06-28 16:55:16 -0400684#ifdef PNG_sRGB_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800685png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700686png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
687 int *file_srgb_intent)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800688{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400689 png_debug1(1, "in %s retrieval function", "sRGB");
690
The Android Open Source Project893912b2009-03-03 19:30:05 -0800691 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
Chris Craikca2bf812013-07-29 15:28:30 -0700692 && file_srgb_intent != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800693 {
Chris Craikca2bf812013-07-29 15:28:30 -0700694 *file_srgb_intent = info_ptr->colorspace.rendering_intent;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800695 return (PNG_INFO_sRGB);
696 }
Chris Craikca2bf812013-07-29 15:28:30 -0700697
The Android Open Source Project893912b2009-03-03 19:30:05 -0800698 return (0);
699}
700#endif
701
Patrick Scott5f6bd842010-06-28 16:55:16 -0400702#ifdef PNG_iCCP_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800703png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700704png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
705 png_charpp name, int *compression_type,
706 png_bytepp profile, png_uint_32 *proflen)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800707{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400708 png_debug1(1, "in %s retrieval function", "iCCP");
709
The Android Open Source Project893912b2009-03-03 19:30:05 -0800710 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
Chris Craikca2bf812013-07-29 15:28:30 -0700711 && name != NULL && compression_type != NULL && profile != NULL &&
712 proflen != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800713 {
The Android Open Source Project893912b2009-03-03 19:30:05 -0800714 *name = info_ptr->iccp_name;
715 *profile = info_ptr->iccp_profile;
Chris Craikca2bf812013-07-29 15:28:30 -0700716 *proflen = png_get_uint_32(info_ptr->iccp_profile);
717 /* This is somewhat irrelevant since the profile data returned has
718 * actually been uncompressed.
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400719 */
Chris Craikca2bf812013-07-29 15:28:30 -0700720 *compression_type = PNG_COMPRESSION_TYPE_BASE;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800721 return (PNG_INFO_iCCP);
722 }
Chris Craikca2bf812013-07-29 15:28:30 -0700723
The Android Open Source Project893912b2009-03-03 19:30:05 -0800724 return (0);
725}
726#endif
727
Patrick Scott5f6bd842010-06-28 16:55:16 -0400728#ifdef PNG_sPLT_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -0700729int PNGAPI
730png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
731 png_sPLT_tpp spalettes)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800732{
733 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
734 {
Chris Craikca2bf812013-07-29 15:28:30 -0700735 *spalettes = info_ptr->splt_palettes;
736 return info_ptr->splt_palettes_num;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800737 }
Chris Craikca2bf812013-07-29 15:28:30 -0700738
The Android Open Source Project893912b2009-03-03 19:30:05 -0800739 return (0);
740}
741#endif
742
Patrick Scott5f6bd842010-06-28 16:55:16 -0400743#ifdef PNG_hIST_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800744png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700745png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
746 png_uint_16p *hist)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800747{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400748 png_debug1(1, "in %s retrieval function", "hIST");
749
The Android Open Source Project893912b2009-03-03 19:30:05 -0800750 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
Chris Craikca2bf812013-07-29 15:28:30 -0700751 && hist != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800752 {
The Android Open Source Project893912b2009-03-03 19:30:05 -0800753 *hist = info_ptr->hist;
754 return (PNG_INFO_hIST);
755 }
Chris Craikca2bf812013-07-29 15:28:30 -0700756
The Android Open Source Project893912b2009-03-03 19:30:05 -0800757 return (0);
758}
759#endif
760
761png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700762png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
763 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)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800766{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400767 png_debug1(1, "in %s retrieval function", "IHDR");
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400768
Patrick Scott5f6bd842010-06-28 16:55:16 -0400769 if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
770 height == NULL || bit_depth == NULL || color_type == NULL)
771 return (0);
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400772
Patrick Scott5f6bd842010-06-28 16:55:16 -0400773 *width = info_ptr->width;
774 *height = info_ptr->height;
775 *bit_depth = info_ptr->bit_depth;
776 *color_type = info_ptr->color_type;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400777
Patrick Scott5f6bd842010-06-28 16:55:16 -0400778 if (compression_type != NULL)
779 *compression_type = info_ptr->compression_type;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400780
Patrick Scott5f6bd842010-06-28 16:55:16 -0400781 if (filter_type != NULL)
782 *filter_type = info_ptr->filter_type;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400783
Patrick Scott5f6bd842010-06-28 16:55:16 -0400784 if (interlace_type != NULL)
785 *interlace_type = info_ptr->interlace_type;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800786
Patrick Scott5f6bd842010-06-28 16:55:16 -0400787 /* 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 */
Chris Craikca2bf812013-07-29 15:28:30 -0700792 png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
Patrick Scott5f6bd842010-06-28 16:55:16 -0400793 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
794 info_ptr->compression_type, info_ptr->filter_type);
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400795
Patrick Scott5f6bd842010-06-28 16:55:16 -0400796 return (1);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800797}
798
Patrick Scott5f6bd842010-06-28 16:55:16 -0400799#ifdef PNG_oFFs_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800800png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700801png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
802 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800803{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400804 png_debug1(1, "in %s retrieval function", "oFFs");
805
The Android Open Source Project893912b2009-03-03 19:30:05 -0800806 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
Chris Craikca2bf812013-07-29 15:28:30 -0700807 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800808 {
The Android Open Source Project893912b2009-03-03 19:30:05 -0800809 *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 }
Chris Craikca2bf812013-07-29 15:28:30 -0700814
The Android Open Source Project893912b2009-03-03 19:30:05 -0800815 return (0);
816}
817#endif
818
Patrick Scott5f6bd842010-06-28 16:55:16 -0400819#ifdef PNG_pCAL_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800820png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700821png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
822 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
823 png_charp *units, png_charpp *params)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800824{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400825 png_debug1(1, "in %s retrieval function", "pCAL");
826
The Android Open Source Project893912b2009-03-03 19:30:05 -0800827 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400828 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
829 nparams != NULL && units != NULL && params != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800830 {
The Android Open Source Project893912b2009-03-03 19:30:05 -0800831 *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 }
Chris Craikca2bf812013-07-29 15:28:30 -0700840
The Android Open Source Project893912b2009-03-03 19:30:05 -0800841 return (0);
842}
843#endif
844
Patrick Scott5f6bd842010-06-28 16:55:16 -0400845#ifdef PNG_sCAL_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -0700846# ifdef PNG_FIXED_POINT_SUPPORTED
847# if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
848 defined(PNG_FLOATING_POINT_SUPPORTED)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800849png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700850png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
851 int *unit, png_fixed_point *width, png_fixed_point *height)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800852{
Chris Craikca2bf812013-07-29 15:28:30 -0700853 if (png_ptr != NULL && info_ptr != NULL &&
854 (info_ptr->valid & PNG_INFO_sCAL))
855 {
856 *unit = info_ptr->scal_unit;
857 /*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 */
861 *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);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800868}
Chris Craikca2bf812013-07-29 15:28:30 -0700869# endif /* FLOATING_ARITHMETIC */
870# endif /* FIXED_POINT */
871# ifdef PNG_FLOATING_POINT_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800872png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700873png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
874 int *unit, double *width, double *height)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800875{
Chris Craikca2bf812013-07-29 15:28:30 -0700876 if (png_ptr != NULL && info_ptr != NULL &&
877 (info_ptr->valid & PNG_INFO_sCAL))
878 {
879 *unit = info_ptr->scal_unit;
880 *width = atof(info_ptr->scal_s_width);
881 *height = atof(info_ptr->scal_s_height);
882 return (PNG_INFO_sCAL);
883 }
884
885 return(0);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800886}
Chris Craikca2bf812013-07-29 15:28:30 -0700887# endif /* FLOATING POINT */
888png_uint_32 PNGAPI
889png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
890 int *unit, png_charpp width, png_charpp height)
891{
892 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 }
900
901 return(0);
902}
903#endif /* sCAL */
The Android Open Source Project893912b2009-03-03 19:30:05 -0800904
Patrick Scott5f6bd842010-06-28 16:55:16 -0400905#ifdef PNG_pHYs_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800906png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700907png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
908 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800909{
910 png_uint_32 retval = 0;
911
Patrick Scott5f6bd842010-06-28 16:55:16 -0400912 png_debug1(1, "in %s retrieval function", "pHYs");
913
The Android Open Source Project893912b2009-03-03 19:30:05 -0800914 if (png_ptr != NULL && info_ptr != NULL &&
Chris Craikca2bf812013-07-29 15:28:30 -0700915 (info_ptr->valid & PNG_INFO_pHYs))
The Android Open Source Project893912b2009-03-03 19:30:05 -0800916 {
The Android Open Source Project893912b2009-03-03 19:30:05 -0800917 if (res_x != NULL)
918 {
919 *res_x = info_ptr->x_pixels_per_unit;
920 retval |= PNG_INFO_pHYs;
921 }
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400922
The Android Open Source Project893912b2009-03-03 19:30:05 -0800923 if (res_y != NULL)
924 {
925 *res_y = info_ptr->y_pixels_per_unit;
926 retval |= PNG_INFO_pHYs;
927 }
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400928
The Android Open Source Project893912b2009-03-03 19:30:05 -0800929 if (unit_type != NULL)
930 {
931 *unit_type = (int)info_ptr->phys_unit_type;
932 retval |= PNG_INFO_pHYs;
933 }
934 }
Chris Craikca2bf812013-07-29 15:28:30 -0700935
The Android Open Source Project893912b2009-03-03 19:30:05 -0800936 return (retval);
937}
Chris Craikca2bf812013-07-29 15:28:30 -0700938#endif /* pHYs */
The Android Open Source Project893912b2009-03-03 19:30:05 -0800939
940png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700941png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
942 png_colorp *palette, int *num_palette)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800943{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400944 png_debug1(1, "in %s retrieval function", "PLTE");
945
The Android Open Source Project893912b2009-03-03 19:30:05 -0800946 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
947 && palette != NULL)
948 {
The Android Open Source Project893912b2009-03-03 19:30:05 -0800949 *palette = info_ptr->palette;
950 *num_palette = info_ptr->num_palette;
The Android Open Source Project4215dd12009-03-09 11:52:12 -0700951 png_debug1(3, "num_palette = %d", *num_palette);
The Android Open Source Project893912b2009-03-03 19:30:05 -0800952 return (PNG_INFO_PLTE);
953 }
Chris Craikca2bf812013-07-29 15:28:30 -0700954
The Android Open Source Project893912b2009-03-03 19:30:05 -0800955 return (0);
956}
957
Patrick Scott5f6bd842010-06-28 16:55:16 -0400958#ifdef PNG_sBIT_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -0800959png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -0700960png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
961 png_color_8p *sig_bit)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800962{
Patrick Scott5f6bd842010-06-28 16:55:16 -0400963 png_debug1(1, "in %s retrieval function", "sBIT");
964
The Android Open Source Project893912b2009-03-03 19:30:05 -0800965 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
Chris Craikca2bf812013-07-29 15:28:30 -0700966 && sig_bit != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800967 {
The Android Open Source Project893912b2009-03-03 19:30:05 -0800968 *sig_bit = &(info_ptr->sig_bit);
969 return (PNG_INFO_sBIT);
970 }
Chris Craikca2bf812013-07-29 15:28:30 -0700971
The Android Open Source Project893912b2009-03-03 19:30:05 -0800972 return (0);
973}
974#endif
975
Patrick Scott5f6bd842010-06-28 16:55:16 -0400976#ifdef PNG_TEXT_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -0700977int PNGAPI
978png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
979 png_textp *text_ptr, int *num_text)
The Android Open Source Project893912b2009-03-03 19:30:05 -0800980{
981 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
982 {
Chris Craikca2bf812013-07-29 15:28:30 -0700983 png_debug1(1, "in 0x%lx retrieval function",
984 (unsigned long)png_ptr->chunk_name);
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400985
The Android Open Source Project893912b2009-03-03 19:30:05 -0800986 if (text_ptr != NULL)
987 *text_ptr = info_ptr->text;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400988
The Android Open Source Project893912b2009-03-03 19:30:05 -0800989 if (num_text != NULL)
990 *num_text = info_ptr->num_text;
Patrick Scotta0bb96c2009-07-22 11:50:02 -0400991
Chris Craikca2bf812013-07-29 15:28:30 -0700992 return info_ptr->num_text;
The Android Open Source Project893912b2009-03-03 19:30:05 -0800993 }
Chris Craikca2bf812013-07-29 15:28:30 -0700994
The Android Open Source Project893912b2009-03-03 19:30:05 -0800995 if (num_text != NULL)
Chris Craikca2bf812013-07-29 15:28:30 -0700996 *num_text = 0;
997
The Android Open Source Project893912b2009-03-03 19:30:05 -0800998 return(0);
999}
1000#endif
1001
Patrick Scott5f6bd842010-06-28 16:55:16 -04001002#ifdef PNG_tIME_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -08001003png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -07001004png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
1005 png_timep *mod_time)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001006{
Patrick Scott5f6bd842010-06-28 16:55:16 -04001007 png_debug1(1, "in %s retrieval function", "tIME");
1008
The Android Open Source Project893912b2009-03-03 19:30:05 -08001009 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
1010 && mod_time != NULL)
1011 {
The Android Open Source Project893912b2009-03-03 19:30:05 -08001012 *mod_time = &(info_ptr->mod_time);
1013 return (PNG_INFO_tIME);
1014 }
Chris Craikca2bf812013-07-29 15:28:30 -07001015
The Android Open Source Project893912b2009-03-03 19:30:05 -08001016 return (0);
1017}
1018#endif
1019
Patrick Scott5f6bd842010-06-28 16:55:16 -04001020#ifdef PNG_tRNS_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -08001021png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -07001022png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
1023 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001024{
1025 png_uint_32 retval = 0;
1026 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
1027 {
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001028 png_debug1(1, "in %s retrieval function", "tRNS");
Patrick Scott5f6bd842010-06-28 16:55:16 -04001029
The Android Open Source Project893912b2009-03-03 19:30:05 -08001030 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1031 {
Chris Craikca2bf812013-07-29 15:28:30 -07001032 if (trans_alpha != NULL)
1033 {
1034 *trans_alpha = info_ptr->trans_alpha;
1035 retval |= PNG_INFO_tRNS;
1036 }
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001037
Chris Craikca2bf812013-07-29 15:28:30 -07001038 if (trans_color != NULL)
1039 *trans_color = &(info_ptr->trans_color);
The Android Open Source Project893912b2009-03-03 19:30:05 -08001040 }
Chris Craikca2bf812013-07-29 15:28:30 -07001041
The Android Open Source Project893912b2009-03-03 19:30:05 -08001042 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
1043 {
Chris Craikca2bf812013-07-29 15:28:30 -07001044 if (trans_color != NULL)
1045 {
1046 *trans_color = &(info_ptr->trans_color);
1047 retval |= PNG_INFO_tRNS;
1048 }
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001049
Chris Craikca2bf812013-07-29 15:28:30 -07001050 if (trans_alpha != NULL)
1051 *trans_alpha = NULL;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001052 }
Chris Craikca2bf812013-07-29 15:28:30 -07001053
The Android Open Source Project4215dd12009-03-09 11:52:12 -07001054 if (num_trans != NULL)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001055 {
1056 *num_trans = info_ptr->num_trans;
1057 retval |= PNG_INFO_tRNS;
1058 }
1059 }
Chris Craikca2bf812013-07-29 15:28:30 -07001060
The Android Open Source Project893912b2009-03-03 19:30:05 -08001061 return (retval);
1062}
1063#endif
1064
Chris Craikca2bf812013-07-29 15:28:30 -07001065#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
1066int PNGAPI
1067png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
1068 png_unknown_chunkpp unknowns)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001069{
1070 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
1071 {
Chris Craikca2bf812013-07-29 15:28:30 -07001072 *unknowns = info_ptr->unknown_chunks;
1073 return info_ptr->unknown_chunks_num;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001074 }
Chris Craikca2bf812013-07-29 15:28:30 -07001075
The Android Open Source Project893912b2009-03-03 19:30:05 -08001076 return (0);
1077}
1078#endif
1079
Patrick Scott5f6bd842010-06-28 16:55:16 -04001080#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -08001081png_byte PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -07001082png_get_rgb_to_gray_status (png_const_structrp png_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001083{
Chris Craikca2bf812013-07-29 15:28:30 -07001084 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
The Android Open Source Project893912b2009-03-03 19:30:05 -08001085}
1086#endif
1087
Patrick Scott5f6bd842010-06-28 16:55:16 -04001088#ifdef PNG_USER_CHUNKS_SUPPORTED
The Android Open Source Project893912b2009-03-03 19:30:05 -08001089png_voidp PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -07001090png_get_user_chunk_ptr(png_const_structrp png_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001091{
Chris Craikca2bf812013-07-29 15:28:30 -07001092 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
The Android Open Source Project893912b2009-03-03 19:30:05 -08001093}
1094#endif
1095
Chris Craikca2bf812013-07-29 15:28:30 -07001096png_size_t PNGAPI
1097png_get_compression_buffer_size(png_const_structrp png_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001098{
Chris Craikca2bf812013-07-29 15:28:30 -07001099 if (png_ptr == NULL)
1100 return 0;
The Android Open Source Project893912b2009-03-03 19:30:05 -08001101
Chris Craikca2bf812013-07-29 15:28:30 -07001102# 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 }
The Android Open Source Project893912b2009-03-03 19:30:05 -08001112
Chris Craikca2bf812013-07-29 15:28:30 -07001113# ifdef PNG_WRITE_SUPPORTED
1114 else
1115 return png_ptr->zbuffer_size;
1116# endif
The Android Open Source Project893912b2009-03-03 19:30:05 -08001117}
1118
The Android Open Source Project893912b2009-03-03 19:30:05 -08001119#ifdef PNG_SET_USER_LIMITS_SUPPORTED
Chris Craikca2bf812013-07-29 15:28:30 -07001120/* These functions were added to libpng 1.2.6 and were enabled
1121 * by default in libpng-1.4.0 */
The Android Open Source Project893912b2009-03-03 19:30:05 -08001122png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -07001123png_get_user_width_max (png_const_structrp png_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001124{
Chris Craikca2bf812013-07-29 15:28:30 -07001125 return (png_ptr ? png_ptr->user_width_max : 0);
The Android Open Source Project893912b2009-03-03 19:30:05 -08001126}
Chris Craikca2bf812013-07-29 15:28:30 -07001127
The Android Open Source Project893912b2009-03-03 19:30:05 -08001128png_uint_32 PNGAPI
Chris Craikca2bf812013-07-29 15:28:30 -07001129png_get_user_height_max (png_const_structrp png_ptr)
The Android Open Source Project893912b2009-03-03 19:30:05 -08001130{
Chris Craikca2bf812013-07-29 15:28:30 -07001131 return (png_ptr ? png_ptr->user_height_max : 0);
1132}
1133
1134/* This function was added to libpng 1.4.0 */
1135png_uint_32 PNGAPI
1136png_get_chunk_cache_max (png_const_structrp png_ptr)
1137{
1138 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
1139}
1140
1141/* This function was added to libpng 1.4.1 */
1142png_alloc_size_t PNGAPI
1143png_get_chunk_malloc_max (png_const_structrp png_ptr)
1144{
1145 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
The Android Open Source Project893912b2009-03-03 19:30:05 -08001146}
1147#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
Patrick Scotta0bb96c2009-07-22 11:50:02 -04001148
Chris Craikca2bf812013-07-29 15:28:30 -07001149/* These functions were added to libpng 1.4.0 */
1150#ifdef PNG_IO_STATE_SUPPORTED
1151png_uint_32 PNGAPI
1152png_get_io_state (png_const_structrp png_ptr)
1153{
1154 return png_ptr->io_state;
1155}
1156
1157png_uint_32 PNGAPI
1158png_get_io_chunk_type (png_const_structrp png_ptr)
1159{
1160 return png_ptr->chunk_name;
1161}
1162#endif /* ?PNG_IO_STATE_SUPPORTED */
1163
1164#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
The Android Open Source Project893912b2009-03-03 19:30:05 -08001177#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */