blob: 36c97f18f0b79da0a43f1b8d3ad073b757987858 [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-Pehrson520a7642000-03-21 05:13:06 -06004 * libpng 1.0.6 - March 21, 2000
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06005 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
7 * Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06008 * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06009 */
Andreas Dilger47a0c421997-05-16 02:46:07 -050010
11#define PNG_INTERNAL
12#include "png.h"
13
14png_uint_32
15png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
16{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060017 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050018 return(info_ptr->valid & flag);
19 else
20 return(0);
21}
22
23png_uint_32
24png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
25{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060026 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -050027 return(info_ptr->rowbytes);
28 else
29 return(0);
30}
31
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -060032#if defined(PNG_INFO_IMAGE_SUPPORTED)
33png_bytepp
34png_get_rows(png_structp png_ptr, png_infop info_ptr)
35{
36 if (png_ptr != NULL && info_ptr != NULL)
37 return(info_ptr->row_pointers);
38 else
39 return(0);
40}
41#endif
42
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060043#ifdef PNG_EASY_ACCESS_SUPPORTED
44/* easy access to info, added in libpng-0.99 */
45png_uint_32
46png_get_image_width(png_structp png_ptr, png_infop info_ptr)
47{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060048 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060049 {
50 return info_ptr->width;
51 }
52 return (0);
53}
54
55png_uint_32
56png_get_image_height(png_structp png_ptr, png_infop info_ptr)
57{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060058 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060059 {
60 return info_ptr->height;
61 }
62 return (0);
63}
64
65png_byte
66png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
67{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060068 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060069 {
70 return info_ptr->bit_depth;
71 }
72 return (0);
73}
74
75png_byte
76png_get_color_type(png_structp png_ptr, png_infop info_ptr)
77{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060078 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060079 {
80 return info_ptr->color_type;
81 }
82 return (0);
83}
84
85png_byte
86png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
87{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060088 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060089 {
90 return info_ptr->filter_type;
91 }
92 return (0);
93}
94
95png_byte
96png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
97{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -060098 if (png_ptr != NULL && info_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060099 {
100 return info_ptr->interlace_type;
101 }
102 return (0);
103}
104
105png_byte
106png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
107{
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 {
110 return info_ptr->compression_type;
111 }
112 return (0);
113}
114
115png_uint_32
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600116png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
117{
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600118#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600119 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
120 {
121 png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
122 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
123 return (0);
124 else return (info_ptr->x_pixels_per_unit);
125 }
126 else
127#endif
128 return (0);
129}
130
131png_uint_32
132png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
133{
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600134#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600135 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
136 {
137 png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
138 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
139 return (0);
140 else return (info_ptr->y_pixels_per_unit);
141 }
142 else
143#endif
144 return (0);
145}
146
147png_uint_32
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600148png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
149{
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600150#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600151 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600152 {
153 png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600154 if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
155 info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600156 return (0);
157 else return (info_ptr->x_pixels_per_unit);
158 }
159 else
160#endif
161 return (0);
162}
163
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600164#ifdef PNG_FLOATING_POINT_SUPPORTED
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600165float
166png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
167 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600168#if defined(PNG_pHYs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600169 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600170 {
171 png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
172 if (info_ptr->x_pixels_per_unit == 0)
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600173 return ((float)0.0);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600174 else
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600175 return ((float)info_ptr->y_pixels_per_unit
176 /(float)info_ptr->x_pixels_per_unit);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600177 }
178 else
179#endif
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600180 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
184png_uint_32
185png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
186{
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600187#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600188 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600189 {
190 png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
191 if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
192 return (0);
193 else return (info_ptr->x_offset);
194 }
195 else
196#endif
197 return (0);
198}
199
200png_uint_32
201png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
202{
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600203#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600204 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600205 {
206 png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
207 if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
208 return (0);
209 else return (info_ptr->y_offset);
210 }
211 else
212#endif
213 return (0);
214}
215
216png_uint_32
217png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
218{
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600219#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600220 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600221 {
222 png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
223 if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
224 return (0);
225 else return (info_ptr->x_offset);
226 }
227 else
228#endif
229 return (0);
230}
231
232png_uint_32
233png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
234{
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600235#if defined(PNG_oFFs_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600236 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600237 {
238 png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
239 if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
240 return (0);
241 else return (info_ptr->y_offset);
242 }
243 else
244#endif
245 return (0);
246}
247
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600248#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600249png_uint_32
250png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
251{
252 return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600253 *.0254 +.5);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600254}
255
256png_uint_32
257png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
258{
259 return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600260 *.0254 +.5);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600261}
262
263png_uint_32
264png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
265{
266 return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600267 *.0254 +.5);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600268}
269
270float
271png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
272{
273 return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600274 *.00003937);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600275}
276
277float
278png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
279{
280 return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600281 *.00003937)
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600282}
283
284#if defined(PNG_READ_pHYs_SUPPORTED)
285png_uint_32
286png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
287 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
288{
289 png_uint_32 retval = 0;
290
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600291 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600292 {
293 png_debug1(1, "in %s retrieval function\n", "pHYs");
294 if (res_x != NULL)
295 {
296 *res_x = info_ptr->x_pixels_per_unit;
297 retval |= PNG_INFO_pHYs;
298 }
299 if (res_y != NULL)
300 {
301 *res_y = info_ptr->y_pixels_per_unit;
302 retval |= PNG_INFO_pHYs;
303 }
304 if (unit_type != NULL)
305 {
306 *unit_type = (int)info_ptr->phys_unit_type;
307 retval |= PNG_INFO_pHYs;
308 if(unit_type == 1)
309 {
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600310 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
311 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600312 }
313 }
314 }
315 return (retval);
316}
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500317#endif /* PNG_READ_pHYs_SUPPORTED */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600318#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600319
320/* png_get_channels really belongs in here, too, but it's been around longer */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500321
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600322#endif /* PNG_EASY_ACCESS_SUPPORTED */
323
Andreas Dilger47a0c421997-05-16 02:46:07 -0500324png_byte
325png_get_channels(png_structp png_ptr, png_infop info_ptr)
326{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600327 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500328 return(info_ptr->channels);
329 else
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600330 return (0);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500331}
332
333png_bytep
334png_get_signature(png_structp png_ptr, png_infop info_ptr)
335{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600336 if (png_ptr != NULL && info_ptr != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500337 return(info_ptr->signature);
338 else
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600339 return (NULL);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500340}
341
342#if defined(PNG_READ_bKGD_SUPPORTED)
343png_uint_32
344png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
345 png_color_16p *background)
346{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600347 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
348 && background != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500349 {
350 png_debug1(1, "in %s retrieval function\n", "bKGD");
351 *background = &(info_ptr->background);
352 return (PNG_INFO_bKGD);
353 }
354 return (0);
355}
356#endif
357
358#if defined(PNG_READ_cHRM_SUPPORTED)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600359#ifdef PNG_FLOATING_POINT_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -0500360png_uint_32
361png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
362 double *white_x, double *white_y, double *red_x, double *red_y,
363 double *green_x, double *green_y, double *blue_x, double *blue_y)
364{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600365 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500366 {
367 png_debug1(1, "in %s retrieval function\n", "cHRM");
368 if (white_x != NULL)
369 *white_x = (double)info_ptr->x_white;
370 if (white_y != NULL)
371 *white_y = (double)info_ptr->y_white;
372 if (red_x != NULL)
373 *red_x = (double)info_ptr->x_red;
374 if (red_y != NULL)
375 *red_y = (double)info_ptr->y_red;
376 if (green_x != NULL)
377 *green_x = (double)info_ptr->x_green;
378 if (green_y != NULL)
379 *green_y = (double)info_ptr->y_green;
380 if (blue_x != NULL)
381 *blue_x = (double)info_ptr->x_blue;
382 if (blue_y != NULL)
383 *blue_y = (double)info_ptr->y_blue;
384 return (PNG_INFO_cHRM);
385 }
386 return (0);
387}
388#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600389#ifdef PNG_FIXED_POINT_SUPPORTED
390png_uint_32
391png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600392 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
393 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
394 png_fixed_point *blue_x, png_fixed_point *blue_y)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600395{
396 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
397 {
398 png_debug1(1, "in %s retrieval function\n", "cHRM");
399 if (white_x != NULL)
400 *white_x = info_ptr->int_x_white;
401 if (white_y != NULL)
402 *white_y = info_ptr->int_y_white;
403 if (red_x != NULL)
404 *red_x = info_ptr->int_x_red;
405 if (red_y != NULL)
406 *red_y = info_ptr->int_y_red;
407 if (green_x != NULL)
408 *green_x = info_ptr->int_x_green;
409 if (green_y != NULL)
410 *green_y = info_ptr->int_y_green;
411 if (blue_x != NULL)
412 *blue_x = info_ptr->int_x_blue;
413 if (blue_y != NULL)
414 *blue_y = info_ptr->int_y_blue;
415 return (PNG_INFO_cHRM);
416 }
417 return (0);
418}
419#endif
420#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500421
422#if defined(PNG_READ_gAMA_SUPPORTED)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600423#ifdef PNG_FLOATING_POINT_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -0500424png_uint_32
425png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
426{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600427 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
428 && file_gamma != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500429 {
430 png_debug1(1, "in %s retrieval function\n", "gAMA");
431 *file_gamma = (double)info_ptr->gamma;
432 return (PNG_INFO_gAMA);
433 }
434 return (0);
435}
436#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600437png_uint_32
438png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600439 png_fixed_point *int_file_gamma)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600440{
441 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
442 && int_file_gamma != NULL)
443 {
444 png_debug1(1, "in %s retrieval function\n", "gAMA");
445 *int_file_gamma = info_ptr->int_gamma;
446 return (PNG_INFO_gAMA);
447 }
448 return (0);
449}
450#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500451
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600452#if defined(PNG_READ_sRGB_SUPPORTED)
453png_uint_32
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600454png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600455{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600456 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
457 && file_srgb_intent != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600458 {
459 png_debug1(1, "in %s retrieval function\n", "sRGB");
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600460 *file_srgb_intent = (int)info_ptr->srgb_intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600461 return (PNG_INFO_sRGB);
462 }
463 return (0);
464}
465#endif
466
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600467#if defined(PNG_READ_iCCP_SUPPORTED)
468png_uint_32
469png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
470 png_charpp name, int *compression_type,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600471 png_charpp profile, png_uint_32 *proflen)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600472{
473 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
474 && name != NULL && profile != NULL && proflen != NULL)
475 {
476 png_debug1(1, "in %s retrieval function\n", "iCCP");
477 *name = info_ptr->iccp_name;
478 *profile = info_ptr->iccp_profile;
479 /* compression_type is a dummy so the API won't have to change
480 if we introduce multiple compression types later. */
481 *proflen = (int)info_ptr->iccp_proflen;
482 *compression_type = (int)info_ptr->iccp_compression;
483 return (PNG_INFO_iCCP);
484 }
485 return (0);
486}
487#endif
488
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600489#if defined(PNG_READ_sPLT_SUPPORTED)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600490png_uint_32
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600491png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600492 png_sPLT_tpp spalettes)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600493{
494 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
495 *spalettes = info_ptr->splt_palettes;
496 return ((png_uint_32)info_ptr->splt_palettes_num);
497}
498#endif
499
Andreas Dilger47a0c421997-05-16 02:46:07 -0500500#if defined(PNG_READ_hIST_SUPPORTED)
501png_uint_32
502png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
503{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600504 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
505 && hist != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500506 {
507 png_debug1(1, "in %s retrieval function\n", "hIST");
508 *hist = info_ptr->hist;
509 return (PNG_INFO_hIST);
510 }
511 return (0);
512}
513#endif
514
515png_uint_32
516png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
517 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
518 int *color_type, int *interlace_type, int *compression_type,
519 int *filter_type)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600520
Andreas Dilger47a0c421997-05-16 02:46:07 -0500521{
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -0600522 if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
Andreas Dilger47a0c421997-05-16 02:46:07 -0500523 bit_depth != NULL && color_type != NULL)
524 {
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600525 int pixel_depth, channels;
526 png_uint_32 rowbytes_per_pixel;
527
Andreas Dilger47a0c421997-05-16 02:46:07 -0500528 png_debug1(1, "in %s retrieval function\n", "IHDR");
529 *width = info_ptr->width;
530 *height = info_ptr->height;
531 *bit_depth = info_ptr->bit_depth;
532 *color_type = info_ptr->color_type;
533 if (compression_type != NULL)
534 *compression_type = info_ptr->compression_type;
535 if (filter_type != NULL)
536 *filter_type = info_ptr->filter_type;
537 if (interlace_type != NULL)
538 *interlace_type = info_ptr->interlace_type;
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600539
540 /* check for potential overflow of rowbytes */
541 if (*color_type == PNG_COLOR_TYPE_PALETTE)
542 channels = 1;
543 else if (*color_type & PNG_COLOR_MASK_COLOR)
544 channels = 3;
545 else
546 channels = 1;
547 if (*color_type & PNG_COLOR_MASK_ALPHA)
548 channels++;
549 pixel_depth = *bit_depth * channels;
550 rowbytes_per_pixel = (pixel_depth + 7) >> 3;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500551 if ((*width > PNG_MAX_UINT/rowbytes_per_pixel))
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600552 {
553 png_warning(png_ptr,
554 "Width too large for libpng to process image data.");
555 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500556 return (1);
557 }
558 return (0);
559}
560
561#if defined(PNG_READ_oFFs_SUPPORTED)
562png_uint_32
563png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600564 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500565{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600566 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
567 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500568 {
569 png_debug1(1, "in %s retrieval function\n", "oFFs");
570 *offset_x = info_ptr->x_offset;
571 *offset_y = info_ptr->y_offset;
572 *unit_type = (int)info_ptr->offset_unit_type;
573 return (PNG_INFO_oFFs);
574 }
575 return (0);
576}
577#endif
578
579#if defined(PNG_READ_pCAL_SUPPORTED)
580png_uint_32
581png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
582 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
583 png_charp *units, png_charpp *params)
584{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600585 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
586 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
Andreas Dilger47a0c421997-05-16 02:46:07 -0500587 nparams != NULL && units != NULL && params != NULL)
588 {
589 png_debug1(1, "in %s retrieval function\n", "pCAL");
590 *purpose = info_ptr->pcal_purpose;
591 *X0 = info_ptr->pcal_X0;
592 *X1 = info_ptr->pcal_X1;
593 *type = (int)info_ptr->pcal_type;
594 *nparams = (int)info_ptr->pcal_nparams;
595 *units = info_ptr->pcal_units;
596 *params = info_ptr->pcal_params;
597 return (PNG_INFO_pCAL);
598 }
599 return (0);
600}
601#endif
602
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600603#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
604#ifdef PNG_FLOATING_POINT_SUPPORTED
605png_uint_32
606png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600607 int *unit, double *width, double *height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600608{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600609 if (png_ptr != NULL && info_ptr != NULL &&
610 (info_ptr->valid & PNG_INFO_sCAL))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600611 {
612 *unit = info_ptr->scal_unit;
613 *width = info_ptr->scal_pixel_width;
614 *height = info_ptr->scal_pixel_height;
615 return (PNG_INFO_sCAL);
616 }
617 return(0);
618}
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600619#else
620#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600621png_uint_32
622png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600623 int *unit, png_charpp width, png_charpp height)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600624{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600625 if (png_ptr != NULL && info_ptr != NULL &&
626 (info_ptr->valid & PNG_INFO_sCAL))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600627 {
628 *unit = info_ptr->scal_unit;
629 *width = info_ptr->scal_s_width;
630 *height = info_ptr->scal_s_height;
631 return (PNG_INFO_sCAL);
632 }
633 return(0);
634}
635#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600636#endif
637#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600638
Andreas Dilger47a0c421997-05-16 02:46:07 -0500639#if defined(PNG_READ_pHYs_SUPPORTED)
640png_uint_32
641png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
642 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
643{
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600644 png_uint_32 retval = 0;
645
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600646 if (png_ptr != NULL && info_ptr != NULL &&
647 (info_ptr->valid & PNG_INFO_pHYs))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500648 {
649 png_debug1(1, "in %s retrieval function\n", "pHYs");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600650 if (res_x != NULL)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600651 {
652 *res_x = info_ptr->x_pixels_per_unit;
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600653 retval |= PNG_INFO_pHYs;
654 }
655 if (res_y != NULL)
656 {
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600657 *res_y = info_ptr->y_pixels_per_unit;
658 retval |= PNG_INFO_pHYs;
659 }
660 if (unit_type != NULL)
661 {
662 *unit_type = (int)info_ptr->phys_unit_type;
663 retval |= PNG_INFO_pHYs;
664 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500665 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600666 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500667}
668#endif
669
670png_uint_32
671png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
672 int *num_palette)
673{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600674 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
675 && palette != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500676 {
677 png_debug1(1, "in %s retrieval function\n", "PLTE");
678 *palette = info_ptr->palette;
679 *num_palette = info_ptr->num_palette;
680 png_debug1(3, "num_palette = %d\n", *num_palette);
681 return (PNG_INFO_PLTE);
682 }
683 return (0);
684}
685
686#if defined(PNG_READ_sBIT_SUPPORTED)
687png_uint_32
688png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
689{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600690 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
691 && sig_bit != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500692 {
693 png_debug1(1, "in %s retrieval function\n", "sBIT");
694 *sig_bit = &(info_ptr->sig_bit);
695 return (PNG_INFO_sBIT);
696 }
697 return (0);
698}
699#endif
700
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600701#if defined(PNG_READ_TEXT_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500702png_uint_32
703png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
704 int *num_text)
705{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600706 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500707 {
708 png_debug1(1, "in %s retrieval function\n",
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600709 (png_ptr->chunk_name[0] == '\0' ? "text"
710 : (png_const_charp)png_ptr->chunk_name));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500711 if (text_ptr != NULL)
712 *text_ptr = info_ptr->text;
713 if (num_text != NULL)
714 *num_text = info_ptr->num_text;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600715 return ((png_uint_32)info_ptr->num_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500716 }
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -0600717 if (num_text != NULL)
718 *num_text = 0;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500719 return(0);
720}
721#endif
722
723#if defined(PNG_READ_tIME_SUPPORTED)
724png_uint_32
725png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
726{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600727 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
728 && mod_time != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500729 {
730 png_debug1(1, "in %s retrieval function\n", "tIME");
731 *mod_time = &(info_ptr->mod_time);
732 return (PNG_INFO_tIME);
733 }
734 return (0);
735}
736#endif
737
738#if defined(PNG_READ_tRNS_SUPPORTED)
739png_uint_32
740png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
741 png_bytep *trans, int *num_trans, png_color_16p *trans_values)
742{
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600743 png_uint_32 retval = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600744 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500745 {
746 png_debug1(1, "in %s retrieval function\n", "tRNS");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600747 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500748 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600749 if (trans != NULL)
750 {
751 *trans = info_ptr->trans;
752 retval |= PNG_INFO_tRNS;
753 }
754 if (trans_values != NULL)
755 *trans_values = &(info_ptr->trans_values);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500756 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600757 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500758 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600759 if (trans_values != NULL)
760 {
761 *trans_values = &(info_ptr->trans_values);
762 retval |= PNG_INFO_tRNS;
763 }
764 if(trans != NULL)
765 *trans = NULL;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500766 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600767 if(num_trans != NULL)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500768 {
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600769 *num_trans = info_ptr->num_trans;
770 retval |= PNG_INFO_tRNS;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500771 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500772 }
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600773 return (retval);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500774}
775#endif
776
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600777#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
778png_uint_32
779png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
780 png_unknown_chunkpp unknowns)
781{
782 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
783 *unknowns = info_ptr->unknown_chunks;
784 return ((png_uint_32)info_ptr->unknown_chunks_num);
785}
786#endif
787
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600788#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
789png_byte
790png_get_rgb_to_gray_status (png_structp png_ptr)
791{
792 return png_ptr->rgb_to_gray_status;
793}
794#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600795
796#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
797png_voidp
798png_get_user_chunk_ptr(png_structp png_ptr)
799{
800 return (png_ptr->user_chunk_ptr);
801}
802#endif
803