OLD | NEW |
1 | 1 |
2 /* pngget.c - retrieval of values from info struct | 2 /* pngget.c - retrieval of values from info struct |
3 * | 3 * |
4 * Last changed in libpng 1.2.43 [February 25, 2010] | 4 * Last changed in libpng 1.6.1 [March 28, 2013] |
5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson | 5 * Copyright (c) 1998-2013 Glenn Randers-Pehrson |
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
8 * | 8 * |
9 * This code is released under the libpng license. | 9 * This code is released under the libpng license. |
10 * For conditions of distribution and use, see the disclaimer | 10 * For conditions of distribution and use, see the disclaimer |
11 * and license in png.h | 11 * and license in png.h |
12 * | 12 * |
13 */ | 13 */ |
14 | 14 |
15 #define PNG_INTERNAL | 15 #include "pngpriv.h" |
16 #define PNG_NO_PEDANTIC_WARNINGS | 16 |
17 #include "png.h" | |
18 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | 17 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
19 | 18 |
20 png_uint_32 PNGAPI | 19 png_uint_32 PNGAPI |
21 png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) | 20 png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 21 png_uint_32 flag) |
22 { | 22 { |
23 if (png_ptr != NULL && info_ptr != NULL) | 23 if (png_ptr != NULL && info_ptr != NULL) |
24 return(info_ptr->valid & flag); | 24 return(info_ptr->valid & flag); |
25 | 25 |
26 else | 26 return(0); |
27 return(0); | |
28 } | 27 } |
29 | 28 |
30 png_uint_32 PNGAPI | 29 png_size_t PNGAPI |
31 png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) | 30 png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr) |
32 { | 31 { |
33 if (png_ptr != NULL && info_ptr != NULL) | 32 if (png_ptr != NULL && info_ptr != NULL) |
34 return(info_ptr->rowbytes); | 33 return(info_ptr->rowbytes); |
35 | 34 |
36 else | 35 return(0); |
37 return(0); | |
38 } | 36 } |
39 | 37 |
40 #ifdef PNG_INFO_IMAGE_SUPPORTED | 38 #ifdef PNG_INFO_IMAGE_SUPPORTED |
41 png_bytepp PNGAPI | 39 png_bytepp PNGAPI |
42 png_get_rows(png_structp png_ptr, png_infop info_ptr) | 40 png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr) |
43 { | 41 { |
44 if (png_ptr != NULL && info_ptr != NULL) | 42 if (png_ptr != NULL && info_ptr != NULL) |
45 return(info_ptr->row_pointers); | 43 return(info_ptr->row_pointers); |
46 | 44 |
47 else | 45 return(0); |
48 return(0); | |
49 } | 46 } |
50 #endif | 47 #endif |
51 | 48 |
52 #ifdef PNG_EASY_ACCESS_SUPPORTED | 49 #ifdef PNG_EASY_ACCESS_SUPPORTED |
53 /* Easy access to info, added in libpng-0.99 */ | 50 /* Easy access to info, added in libpng-0.99 */ |
54 png_uint_32 PNGAPI | 51 png_uint_32 PNGAPI |
55 png_get_image_width(png_structp png_ptr, png_infop info_ptr) | 52 png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr) |
56 { | 53 { |
57 if (png_ptr != NULL && info_ptr != NULL) | 54 if (png_ptr != NULL && info_ptr != NULL) |
58 return info_ptr->width; | 55 return info_ptr->width; |
59 | 56 |
60 return (0); | 57 return (0); |
61 } | 58 } |
62 | 59 |
63 png_uint_32 PNGAPI | 60 png_uint_32 PNGAPI |
64 png_get_image_height(png_structp png_ptr, png_infop info_ptr) | 61 png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr) |
65 { | 62 { |
66 if (png_ptr != NULL && info_ptr != NULL) | 63 if (png_ptr != NULL && info_ptr != NULL) |
67 return info_ptr->height; | 64 return info_ptr->height; |
68 | 65 |
69 return (0); | 66 return (0); |
70 } | 67 } |
71 | 68 |
72 png_byte PNGAPI | 69 png_byte PNGAPI |
73 png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) | 70 png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr) |
74 { | 71 { |
75 if (png_ptr != NULL && info_ptr != NULL) | 72 if (png_ptr != NULL && info_ptr != NULL) |
76 return info_ptr->bit_depth; | 73 return info_ptr->bit_depth; |
77 | 74 |
78 return (0); | 75 return (0); |
79 } | 76 } |
80 | 77 |
81 png_byte PNGAPI | 78 png_byte PNGAPI |
82 png_get_color_type(png_structp png_ptr, png_infop info_ptr) | 79 png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
83 { | 80 { |
84 if (png_ptr != NULL && info_ptr != NULL) | 81 if (png_ptr != NULL && info_ptr != NULL) |
85 return info_ptr->color_type; | 82 return info_ptr->color_type; |
86 | 83 |
87 return (0); | 84 return (0); |
88 } | 85 } |
89 | 86 |
90 png_byte PNGAPI | 87 png_byte PNGAPI |
91 png_get_filter_type(png_structp png_ptr, png_infop info_ptr) | 88 png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
92 { | 89 { |
93 if (png_ptr != NULL && info_ptr != NULL) | 90 if (png_ptr != NULL && info_ptr != NULL) |
94 return info_ptr->filter_type; | 91 return info_ptr->filter_type; |
95 | 92 |
96 return (0); | 93 return (0); |
97 } | 94 } |
98 | 95 |
99 png_byte PNGAPI | 96 png_byte PNGAPI |
100 png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) | 97 png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
101 { | 98 { |
102 if (png_ptr != NULL && info_ptr != NULL) | 99 if (png_ptr != NULL && info_ptr != NULL) |
103 return info_ptr->interlace_type; | 100 return info_ptr->interlace_type; |
104 | 101 |
105 return (0); | 102 return (0); |
106 } | 103 } |
107 | 104 |
108 png_byte PNGAPI | 105 png_byte PNGAPI |
109 png_get_compression_type(png_structp png_ptr, png_infop info_ptr) | 106 png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr) |
110 { | 107 { |
111 if (png_ptr != NULL && info_ptr != NULL) | 108 if (png_ptr != NULL && info_ptr != NULL) |
112 return info_ptr->compression_type; | 109 return info_ptr->compression_type; |
113 | 110 |
114 return (0); | 111 return (0); |
115 } | 112 } |
116 | 113 |
117 png_uint_32 PNGAPI | 114 png_uint_32 PNGAPI |
118 png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) | 115 png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp |
119 { | 116 info_ptr) |
120 if (png_ptr != NULL && info_ptr != NULL) | 117 { |
121 #ifdef PNG_pHYs_SUPPORTED | 118 #ifdef PNG_pHYs_SUPPORTED |
122 if (info_ptr->valid & PNG_INFO_pHYs) | 119 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
123 { | 120 { |
124 png_debug1(1, "in %s retrieval function", "png_get_x_pixels_per_meter"); | 121 png_debug1(1, "in %s retrieval function", |
125 | 122 "png_get_x_pixels_per_meter"); |
126 if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER) | 123 |
127 return (0); | 124 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) |
128 | 125 return (info_ptr->x_pixels_per_unit); |
129 else | 126 } |
130 return (info_ptr->x_pixels_per_unit); | 127 #endif |
131 } | 128 |
132 #else | 129 return (0); |
133 return (0); | 130 } |
134 #endif | 131 |
135 return (0); | 132 png_uint_32 PNGAPI |
136 } | 133 png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp |
137 | 134 info_ptr) |
138 png_uint_32 PNGAPI | 135 { |
139 png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) | 136 #ifdef PNG_pHYs_SUPPORTED |
140 { | 137 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
141 if (png_ptr != NULL && info_ptr != NULL) | 138 { |
142 #ifdef PNG_pHYs_SUPPORTED | 139 png_debug1(1, "in %s retrieval function", |
143 if (info_ptr->valid & PNG_INFO_pHYs) | 140 "png_get_y_pixels_per_meter"); |
144 { | 141 |
145 png_debug1(1, "in %s retrieval function", "png_get_y_pixels_per_meter"); | 142 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) |
146 | 143 return (info_ptr->y_pixels_per_unit); |
147 if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER) | 144 } |
148 return (0); | 145 #endif |
149 | 146 |
150 else | 147 return (0); |
151 return (info_ptr->y_pixels_per_unit); | 148 } |
152 } | 149 |
153 #else | 150 png_uint_32 PNGAPI |
154 return (0); | 151 png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr) |
155 #endif | 152 { |
156 return (0); | 153 #ifdef PNG_pHYs_SUPPORTED |
157 } | 154 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
158 | |
159 png_uint_32 PNGAPI | |
160 png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) | |
161 { | |
162 if (png_ptr != NULL && info_ptr != NULL) | |
163 #ifdef PNG_pHYs_SUPPORTED | |
164 if (info_ptr->valid & PNG_INFO_pHYs) | |
165 { | 155 { |
166 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter"); | 156 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter"); |
167 | 157 |
168 if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER || | 158 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER && |
169 info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit) | 159 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit) |
170 return (0); | 160 return (info_ptr->x_pixels_per_unit); |
171 | 161 } |
172 else | 162 #endif |
173 return (info_ptr->x_pixels_per_unit); | 163 |
174 } | |
175 #else | |
176 return (0); | |
177 #endif | |
178 return (0); | 164 return (0); |
179 } | 165 } |
180 | 166 |
181 #ifdef PNG_FLOATING_POINT_SUPPORTED | 167 #ifdef PNG_FLOATING_POINT_SUPPORTED |
182 float PNGAPI | 168 float PNGAPI |
183 png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) | 169 png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp |
184 { | 170 info_ptr) |
185 if (png_ptr != NULL && info_ptr != NULL) | 171 { |
186 #ifdef PNG_pHYs_SUPPORTED | 172 #ifdef PNG_READ_pHYs_SUPPORTED |
187 | 173 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
188 if (info_ptr->valid & PNG_INFO_pHYs) | |
189 { | 174 { |
190 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio"); | 175 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio"); |
191 | 176 |
192 if (info_ptr->x_pixels_per_unit == 0) | 177 if (info_ptr->x_pixels_per_unit != 0) |
193 return ((float)0.0); | |
194 | |
195 else | |
196 return ((float)((float)info_ptr->y_pixels_per_unit | 178 return ((float)((float)info_ptr->y_pixels_per_unit |
197 /(float)info_ptr->x_pixels_per_unit)); | 179 /(float)info_ptr->x_pixels_per_unit)); |
198 } | 180 } |
199 #else | 181 #else |
200 return (0.0); | 182 PNG_UNUSED(png_ptr) |
201 #endif | 183 PNG_UNUSED(info_ptr) |
| 184 #endif |
| 185 |
202 return ((float)0.0); | 186 return ((float)0.0); |
203 } | 187 } |
204 #endif | 188 #endif |
205 | 189 |
206 png_int_32 PNGAPI | 190 #ifdef PNG_FIXED_POINT_SUPPORTED |
207 png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) | 191 png_fixed_point PNGAPI |
208 { | 192 png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr, |
209 if (png_ptr != NULL && info_ptr != NULL) | 193 png_const_inforp info_ptr) |
210 #ifdef PNG_oFFs_SUPPORTED | 194 { |
211 | 195 #ifdef PNG_READ_pHYs_SUPPORTED |
212 if (info_ptr->valid & PNG_INFO_oFFs) | 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; |
| 202 |
| 203 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 |
| 221 png_int_32 PNGAPI |
| 222 png_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)) |
213 { | 226 { |
214 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); | 227 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); |
215 | 228 |
216 if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) | 229 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) |
217 return (0); | 230 return (info_ptr->x_offset); |
218 | 231 } |
219 else | 232 #endif |
220 return (info_ptr->x_offset); | 233 |
221 } | 234 return (0); |
| 235 } |
| 236 |
| 237 png_int_32 PNGAPI |
| 238 png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 239 { |
| 240 #ifdef PNG_oFFs_SUPPORTED |
| 241 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) |
| 242 { |
| 243 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); |
| 244 |
| 245 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) |
| 246 return (info_ptr->y_offset); |
| 247 } |
| 248 #endif |
| 249 |
| 250 return (0); |
| 251 } |
| 252 |
| 253 png_int_32 PNGAPI |
| 254 png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 255 { |
| 256 #ifdef PNG_oFFs_SUPPORTED |
| 257 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) |
| 258 { |
| 259 png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels"); |
| 260 |
| 261 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) |
| 262 return (info_ptr->x_offset); |
| 263 } |
| 264 #endif |
| 265 |
| 266 return (0); |
| 267 } |
| 268 |
| 269 png_int_32 PNGAPI |
| 270 png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr) |
| 271 { |
| 272 #ifdef PNG_oFFs_SUPPORTED |
| 273 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) |
| 274 { |
| 275 png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels"); |
| 276 |
| 277 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) |
| 278 return (info_ptr->y_offset); |
| 279 } |
| 280 #endif |
| 281 |
| 282 return (0); |
| 283 } |
| 284 |
| 285 #ifdef PNG_INCH_CONVERSIONS_SUPPORTED |
| 286 static png_uint_32 |
| 287 ppi_from_ppm(png_uint_32 ppm) |
| 288 { |
| 289 #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 */ |
222 #else | 304 #else |
223 return (0); | 305 /* The argument is a PNG unsigned integer, so it is not permitted |
224 #endif | 306 * to be bigger than 2^31. |
225 return (0); | 307 */ |
226 } | 308 png_fixed_point result; |
227 | 309 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127, |
228 png_int_32 PNGAPI | 310 5000)) |
229 png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) | 311 return result; |
230 { | 312 |
231 if (png_ptr != NULL && info_ptr != NULL) | 313 /* Overflow. */ |
232 | 314 return 0; |
233 #ifdef PNG_oFFs_SUPPORTED | 315 #endif |
234 if (info_ptr->valid & PNG_INFO_oFFs) | 316 } |
235 { | 317 |
236 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); | 318 png_uint_32 PNGAPI |
237 | 319 png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) |
238 if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) | 320 { |
239 return (0); | 321 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr)); |
240 | 322 } |
241 else | 323 |
242 return (info_ptr->y_offset); | 324 png_uint_32 PNGAPI |
243 } | 325 png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) |
244 #else | 326 { |
245 return (0); | 327 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr)); |
246 #endif | 328 } |
247 return (0); | 329 |
248 } | 330 png_uint_32 PNGAPI |
249 | 331 png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr) |
250 png_int_32 PNGAPI | 332 { |
251 png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) | 333 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr)); |
252 { | 334 } |
253 if (png_ptr != NULL && info_ptr != NULL) | 335 |
254 | 336 #ifdef PNG_FIXED_POINT_SUPPORTED |
255 #ifdef PNG_oFFs_SUPPORTED | 337 static png_fixed_point |
256 if (info_ptr->valid & PNG_INFO_oFFs) | 338 png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns) |
257 { | 339 { |
258 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); | 340 /* Convert from metres * 1,000,000 to inches * 100,000, meters to |
259 | 341 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127. |
260 if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) | 342 * Notice that this can overflow - a warning is output and 0 is |
261 return (0); | 343 * returned. |
262 | 344 */ |
263 else | 345 return png_muldiv_warn(png_ptr, microns, 500, 127); |
264 return (info_ptr->x_offset); | 346 } |
265 } | 347 |
266 #else | 348 png_fixed_point PNGAPI |
267 return (0); | 349 png_get_x_offset_inches_fixed(png_const_structrp png_ptr, |
268 #endif | 350 png_const_inforp info_ptr) |
269 return (0); | 351 { |
270 } | 352 return png_fixed_inches_from_microns(png_ptr, |
271 | 353 png_get_x_offset_microns(png_ptr, info_ptr)); |
272 png_int_32 PNGAPI | 354 } |
273 png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) | 355 #endif |
274 { | 356 |
275 if (png_ptr != NULL && info_ptr != NULL) | 357 #ifdef PNG_FIXED_POINT_SUPPORTED |
276 | 358 png_fixed_point PNGAPI |
277 #ifdef PNG_oFFs_SUPPORTED | 359 png_get_y_offset_inches_fixed(png_const_structrp png_ptr, |
278 if (info_ptr->valid & PNG_INFO_oFFs) | 360 png_const_inforp info_ptr) |
279 { | 361 { |
280 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); | 362 return png_fixed_inches_from_microns(png_ptr, |
281 | 363 png_get_y_offset_microns(png_ptr, info_ptr)); |
282 if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) | 364 } |
283 return (0); | 365 #endif |
284 | 366 |
285 else | 367 #ifdef PNG_FLOATING_POINT_SUPPORTED |
286 return (info_ptr->y_offset); | |
287 } | |
288 #else | |
289 return (0); | |
290 #endif | |
291 return (0); | |
292 } | |
293 | |
294 #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) | |
295 png_uint_32 PNGAPI | |
296 png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) | |
297 { | |
298 return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr) | |
299 *.0254 +.5)); | |
300 } | |
301 | |
302 png_uint_32 PNGAPI | |
303 png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) | |
304 { | |
305 return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr) | |
306 *.0254 +.5)); | |
307 } | |
308 | |
309 png_uint_32 PNGAPI | |
310 png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) | |
311 { | |
312 return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr) | |
313 *.0254 +.5)); | |
314 } | |
315 | |
316 float PNGAPI | 368 float PNGAPI |
317 png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr) | 369 png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr) |
318 { | 370 { |
319 return ((float)png_get_x_offset_microns(png_ptr, info_ptr) | 371 /* To avoid the overflow do the conversion directly in floating |
320 *.00003937); | 372 * point. |
321 } | 373 */ |
322 | 374 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937); |
| 375 } |
| 376 #endif |
| 377 |
| 378 #ifdef PNG_FLOATING_POINT_SUPPORTED |
323 float PNGAPI | 379 float PNGAPI |
324 png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) | 380 png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr) |
325 { | 381 { |
326 return ((float)png_get_y_offset_microns(png_ptr, info_ptr) | 382 /* To avoid the overflow do the conversion directly in floating |
327 *.00003937); | 383 * point. |
328 } | 384 */ |
329 | 385 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937); |
330 #ifdef PNG_pHYs_SUPPORTED | 386 } |
331 png_uint_32 PNGAPI | 387 #endif |
332 png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, | 388 |
333 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) | 389 #ifdef PNG_pHYs_SUPPORTED |
| 390 png_uint_32 PNGAPI |
| 391 png_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) |
334 { | 393 { |
335 png_uint_32 retval = 0; | 394 png_uint_32 retval = 0; |
336 | 395 |
337 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) | 396 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
338 { | 397 { |
339 png_debug1(1, "in %s retrieval function", "pHYs"); | 398 png_debug1(1, "in %s retrieval function", "pHYs"); |
340 | 399 |
341 if (res_x != NULL) | 400 if (res_x != NULL) |
342 { | 401 { |
343 *res_x = info_ptr->x_pixels_per_unit; | 402 *res_x = info_ptr->x_pixels_per_unit; |
344 retval |= PNG_INFO_pHYs; | 403 retval |= PNG_INFO_pHYs; |
345 } | 404 } |
| 405 |
346 if (res_y != NULL) | 406 if (res_y != NULL) |
347 { | 407 { |
348 *res_y = info_ptr->y_pixels_per_unit; | 408 *res_y = info_ptr->y_pixels_per_unit; |
349 retval |= PNG_INFO_pHYs; | 409 retval |= PNG_INFO_pHYs; |
350 } | 410 } |
| 411 |
351 if (unit_type != NULL) | 412 if (unit_type != NULL) |
352 { | 413 { |
353 *unit_type = (int)info_ptr->phys_unit_type; | 414 *unit_type = (int)info_ptr->phys_unit_type; |
354 retval |= PNG_INFO_pHYs; | 415 retval |= PNG_INFO_pHYs; |
| 416 |
355 if (*unit_type == 1) | 417 if (*unit_type == 1) |
356 { | 418 { |
357 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); | 419 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); |
358 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); | 420 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); |
359 } | 421 } |
360 } | 422 } |
361 } | 423 } |
| 424 |
362 return (retval); | 425 return (retval); |
363 } | 426 } |
364 #endif /* PNG_pHYs_SUPPORTED */ | 427 #endif /* PNG_pHYs_SUPPORTED */ |
365 #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ | 428 #endif /* PNG_INCH_CONVERSIONS_SUPPORTED */ |
366 | 429 |
367 /* png_get_channels really belongs in here, too, but it's been around longer */ | 430 /* png_get_channels really belongs in here, too, but it's been around longer */ |
368 | 431 |
369 #endif /* PNG_EASY_ACCESS_SUPPORTED */ | 432 #endif /* PNG_EASY_ACCESS_SUPPORTED */ |
370 | 433 |
| 434 |
371 png_byte PNGAPI | 435 png_byte PNGAPI |
372 png_get_channels(png_structp png_ptr, png_infop info_ptr) | 436 png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr) |
373 { | 437 { |
374 if (png_ptr != NULL && info_ptr != NULL) | 438 if (png_ptr != NULL && info_ptr != NULL) |
375 return(info_ptr->channels); | 439 return(info_ptr->channels); |
376 else | 440 |
377 return (0); | 441 return (0); |
378 } | 442 } |
379 | 443 |
380 png_bytep PNGAPI | 444 #ifdef PNG_READ_SUPPORTED |
381 png_get_signature(png_structp png_ptr, png_infop info_ptr) | 445 png_const_bytep PNGAPI |
| 446 png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr) |
382 { | 447 { |
383 if (png_ptr != NULL && info_ptr != NULL) | 448 if (png_ptr != NULL && info_ptr != NULL) |
384 return(info_ptr->signature); | 449 return(info_ptr->signature); |
385 else | 450 |
386 return (NULL); | 451 return (NULL); |
387 } | 452 } |
| 453 #endif |
388 | 454 |
389 #ifdef PNG_bKGD_SUPPORTED | 455 #ifdef PNG_bKGD_SUPPORTED |
390 png_uint_32 PNGAPI | 456 png_uint_32 PNGAPI |
391 png_get_bKGD(png_structp png_ptr, png_infop info_ptr, | 457 png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr, |
392 png_color_16p *background) | 458 png_color_16p *background) |
393 { | 459 { |
394 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) | 460 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) |
395 && background != NULL) | 461 && background != NULL) |
396 { | 462 { |
397 png_debug1(1, "in %s retrieval function", "bKGD"); | 463 png_debug1(1, "in %s retrieval function", "bKGD"); |
398 | 464 |
399 *background = &(info_ptr->background); | 465 *background = &(info_ptr->background); |
400 return (PNG_INFO_bKGD); | 466 return (PNG_INFO_bKGD); |
401 } | 467 } |
| 468 |
402 return (0); | 469 return (0); |
403 } | 470 } |
404 #endif | 471 #endif |
405 | 472 |
406 #ifdef PNG_cHRM_SUPPORTED | 473 #ifdef PNG_cHRM_SUPPORTED |
407 #ifdef PNG_FLOATING_POINT_SUPPORTED | 474 /* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the |
408 png_uint_32 PNGAPI | 475 * same time to correct the rgb grayscale coefficient defaults obtained from the |
409 png_get_cHRM(png_structp png_ptr, png_infop info_ptr, | 476 * cHRM chunk in 1.5.4 |
410 double *white_x, double *white_y, double *red_x, double *red_y, | 477 */ |
411 double *green_x, double *green_y, double *blue_x, double *blue_y) | 478 # ifdef PNG_FLOATING_POINT_SUPPORTED |
412 { | 479 png_uint_32 PNGAPI |
413 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) | 480 png_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) |
| 483 { |
| 484 /* 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)) |
414 { | 492 { |
415 png_debug1(1, "in %s retrieval function", "cHRM"); | 493 png_debug1(1, "in %s retrieval function", "cHRM"); |
416 | 494 |
417 if (white_x != NULL) | 495 if (white_x != NULL) |
418 *white_x = (double)info_ptr->x_white; | 496 *white_x = png_float(png_ptr, |
| 497 info_ptr->colorspace.end_points_xy.whitex, "cHRM white X"); |
419 if (white_y != NULL) | 498 if (white_y != NULL) |
420 *white_y = (double)info_ptr->y_white; | 499 *white_y = png_float(png_ptr, |
| 500 info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y"); |
421 if (red_x != NULL) | 501 if (red_x != NULL) |
422 *red_x = (double)info_ptr->x_red; | 502 *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx, |
| 503 "cHRM red X"); |
423 if (red_y != NULL) | 504 if (red_y != NULL) |
424 *red_y = (double)info_ptr->y_red; | 505 *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy, |
| 506 "cHRM red Y"); |
425 if (green_x != NULL) | 507 if (green_x != NULL) |
426 *green_x = (double)info_ptr->x_green; | 508 *green_x = png_float(png_ptr, |
| 509 info_ptr->colorspace.end_points_xy.greenx, "cHRM green X"); |
427 if (green_y != NULL) | 510 if (green_y != NULL) |
428 *green_y = (double)info_ptr->y_green; | 511 *green_y = png_float(png_ptr, |
| 512 info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y"); |
429 if (blue_x != NULL) | 513 if (blue_x != NULL) |
430 *blue_x = (double)info_ptr->x_blue; | 514 *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex, |
| 515 "cHRM blue X"); |
431 if (blue_y != NULL) | 516 if (blue_y != NULL) |
432 *blue_y = (double)info_ptr->y_blue; | 517 *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey, |
| 518 "cHRM blue Y"); |
433 return (PNG_INFO_cHRM); | 519 return (PNG_INFO_cHRM); |
434 } | 520 } |
435 return (0); | 521 |
436 } | 522 return (0); |
437 #endif | 523 } |
438 #ifdef PNG_FIXED_POINT_SUPPORTED | 524 |
439 png_uint_32 PNGAPI | 525 png_uint_32 PNGAPI |
440 png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, | 526 png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr, |
441 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, | 527 double *red_X, double *red_Y, double *red_Z, double *green_X, |
442 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, | 528 double *green_Y, double *green_Z, double *blue_X, double *blue_Y, |
443 png_fixed_point *blue_x, png_fixed_point *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 |
| 571 png_uint_32 PNGAPI |
| 572 png_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 |
| 608 png_uint_32 PNGAPI |
| 609 png_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) |
444 { | 613 { |
445 png_debug1(1, "in %s retrieval function", "cHRM"); | 614 png_debug1(1, "in %s retrieval function", "cHRM"); |
446 | 615 |
447 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) | 616 if (png_ptr != NULL && info_ptr != NULL && |
| 617 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS)) |
448 { | 618 { |
449 if (white_x != NULL) | 619 if (white_x != NULL) |
450 *white_x = info_ptr->int_x_white; | 620 *white_x = info_ptr->colorspace.end_points_xy.whitex; |
451 if (white_y != NULL) | 621 if (white_y != NULL) |
452 *white_y = info_ptr->int_y_white; | 622 *white_y = info_ptr->colorspace.end_points_xy.whitey; |
453 if (red_x != NULL) | 623 if (red_x != NULL) |
454 *red_x = info_ptr->int_x_red; | 624 *red_x = info_ptr->colorspace.end_points_xy.redx; |
455 if (red_y != NULL) | 625 if (red_y != NULL) |
456 *red_y = info_ptr->int_y_red; | 626 *red_y = info_ptr->colorspace.end_points_xy.redy; |
457 if (green_x != NULL) | 627 if (green_x != NULL) |
458 *green_x = info_ptr->int_x_green; | 628 *green_x = info_ptr->colorspace.end_points_xy.greenx; |
459 if (green_y != NULL) | 629 if (green_y != NULL) |
460 *green_y = info_ptr->int_y_green; | 630 *green_y = info_ptr->colorspace.end_points_xy.greeny; |
461 if (blue_x != NULL) | 631 if (blue_x != NULL) |
462 *blue_x = info_ptr->int_x_blue; | 632 *blue_x = info_ptr->colorspace.end_points_xy.bluex; |
463 if (blue_y != NULL) | 633 if (blue_y != NULL) |
464 *blue_y = info_ptr->int_y_blue; | 634 *blue_y = info_ptr->colorspace.end_points_xy.bluey; |
465 return (PNG_INFO_cHRM); | 635 return (PNG_INFO_cHRM); |
466 } | 636 } |
467 return (0); | 637 |
468 } | 638 return (0); |
469 #endif | 639 } |
| 640 # endif |
470 #endif | 641 #endif |
471 | 642 |
472 #ifdef PNG_gAMA_SUPPORTED | 643 #ifdef PNG_gAMA_SUPPORTED |
473 #ifdef PNG_FLOATING_POINT_SUPPORTED | 644 # ifdef PNG_FIXED_POINT_SUPPORTED |
474 png_uint_32 PNGAPI | 645 png_uint_32 PNGAPI |
475 png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) | 646 png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 647 png_fixed_point *file_gamma) |
476 { | 648 { |
477 png_debug1(1, "in %s retrieval function", "gAMA"); | 649 png_debug1(1, "in %s retrieval function", "gAMA"); |
478 | 650 |
479 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) | 651 if (png_ptr != NULL && info_ptr != NULL && |
480 && file_gamma != NULL) | 652 (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) && |
481 { | 653 file_gamma != NULL) |
482 *file_gamma = (double)info_ptr->gamma; | 654 { |
| 655 *file_gamma = info_ptr->colorspace.gamma; |
483 return (PNG_INFO_gAMA); | 656 return (PNG_INFO_gAMA); |
484 } | 657 } |
485 return (0); | 658 |
486 } | 659 return (0); |
487 #endif | 660 } |
488 #ifdef PNG_FIXED_POINT_SUPPORTED | 661 # endif |
489 png_uint_32 PNGAPI | 662 |
490 png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, | 663 # ifdef PNG_FLOATING_POINT_SUPPORTED |
491 png_fixed_point *int_file_gamma) | 664 png_uint_32 PNGAPI |
492 { | 665 png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr, |
493 png_debug1(1, "in %s retrieval function", "gAMA"); | 666 double *file_gamma) |
494 | 667 { |
495 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) | 668 png_debug1(1, "in %s retrieval function", "gAMA(float)"); |
496 && int_file_gamma != NULL) | 669 |
497 { | 670 if (png_ptr != NULL && info_ptr != NULL && |
498 *int_file_gamma = info_ptr->int_gamma; | 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"); |
499 return (PNG_INFO_gAMA); | 676 return (PNG_INFO_gAMA); |
500 } | 677 } |
501 return (0); | 678 |
502 } | 679 return (0); |
503 #endif | 680 } |
| 681 # endif |
504 #endif | 682 #endif |
505 | 683 |
506 #ifdef PNG_sRGB_SUPPORTED | 684 #ifdef PNG_sRGB_SUPPORTED |
507 png_uint_32 PNGAPI | 685 png_uint_32 PNGAPI |
508 png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) | 686 png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr, |
| 687 int *file_srgb_intent) |
509 { | 688 { |
510 png_debug1(1, "in %s retrieval function", "sRGB"); | 689 png_debug1(1, "in %s retrieval function", "sRGB"); |
511 | 690 |
512 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) | 691 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) |
513 && file_srgb_intent != NULL) | 692 && file_srgb_intent != NULL) |
514 { | 693 { |
515 *file_srgb_intent = (int)info_ptr->srgb_intent; | 694 *file_srgb_intent = info_ptr->colorspace.rendering_intent; |
516 return (PNG_INFO_sRGB); | 695 return (PNG_INFO_sRGB); |
517 } | 696 } |
| 697 |
518 return (0); | 698 return (0); |
519 } | 699 } |
520 #endif | 700 #endif |
521 | 701 |
522 #ifdef PNG_iCCP_SUPPORTED | 702 #ifdef PNG_iCCP_SUPPORTED |
523 png_uint_32 PNGAPI | 703 png_uint_32 PNGAPI |
524 png_get_iCCP(png_structp png_ptr, png_infop info_ptr, | 704 png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, |
525 png_charpp name, int *compression_type, | 705 png_charpp name, int *compression_type, |
526 png_charpp profile, png_uint_32 *proflen) | 706 png_bytepp profile, png_uint_32 *proflen) |
527 { | 707 { |
528 png_debug1(1, "in %s retrieval function", "iCCP"); | 708 png_debug1(1, "in %s retrieval function", "iCCP"); |
529 | 709 |
530 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) | 710 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) |
531 && name != NULL && profile != NULL && proflen != NULL) | 711 && name != NULL && compression_type != NULL && profile != NULL && |
| 712 » » proflen != NULL) |
532 { | 713 { |
533 *name = info_ptr->iccp_name; | 714 *name = info_ptr->iccp_name; |
534 *profile = info_ptr->iccp_profile; | 715 *profile = info_ptr->iccp_profile; |
535 /* Compression_type is a dummy so the API won't have to change | 716 *proflen = png_get_uint_32(info_ptr->iccp_profile); |
536 * if we introduce multiple compression types later. | 717 /* This is somewhat irrelevant since the profile data returned has |
| 718 * actually been uncompressed. |
537 */ | 719 */ |
538 *proflen = (int)info_ptr->iccp_proflen; | 720 *compression_type = PNG_COMPRESSION_TYPE_BASE; |
539 *compression_type = (int)info_ptr->iccp_compression; | |
540 return (PNG_INFO_iCCP); | 721 return (PNG_INFO_iCCP); |
541 } | 722 } |
| 723 |
542 return (0); | 724 return (0); |
543 } | 725 } |
544 #endif | 726 #endif |
545 | 727 |
546 #ifdef PNG_sPLT_SUPPORTED | 728 #ifdef PNG_sPLT_SUPPORTED |
547 png_uint_32 PNGAPI | 729 int PNGAPI |
548 png_get_sPLT(png_structp png_ptr, png_infop info_ptr, | 730 png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr, |
549 png_sPLT_tpp spalettes) | 731 png_sPLT_tpp spalettes) |
550 { | 732 { |
551 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) | 733 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) |
552 { | 734 { |
553 *spalettes = info_ptr->splt_palettes; | 735 *spalettes = info_ptr->splt_palettes; |
554 return ((png_uint_32)info_ptr->splt_palettes_num); | 736 return info_ptr->splt_palettes_num; |
555 } | 737 } |
| 738 |
556 return (0); | 739 return (0); |
557 } | 740 } |
558 #endif | 741 #endif |
559 | 742 |
560 #ifdef PNG_hIST_SUPPORTED | 743 #ifdef PNG_hIST_SUPPORTED |
561 png_uint_32 PNGAPI | 744 png_uint_32 PNGAPI |
562 png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) | 745 png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr, |
| 746 png_uint_16p *hist) |
563 { | 747 { |
564 png_debug1(1, "in %s retrieval function", "hIST"); | 748 png_debug1(1, "in %s retrieval function", "hIST"); |
565 | 749 |
566 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) | 750 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) |
567 && hist != NULL) | 751 && hist != NULL) |
568 { | 752 { |
569 *hist = info_ptr->hist; | 753 *hist = info_ptr->hist; |
570 return (PNG_INFO_hIST); | 754 return (PNG_INFO_hIST); |
571 } | 755 } |
572 return (0); | 756 |
573 } | 757 return (0); |
574 #endif | 758 } |
575 | 759 #endif |
576 png_uint_32 PNGAPI | 760 |
577 png_get_IHDR(png_structp png_ptr, png_infop info_ptr, | 761 png_uint_32 PNGAPI |
578 png_uint_32 *width, png_uint_32 *height, int *bit_depth, | 762 png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr, |
579 int *color_type, int *interlace_type, int *compression_type, | 763 png_uint_32 *width, png_uint_32 *height, int *bit_depth, |
580 int *filter_type) | 764 int *color_type, int *interlace_type, int *compression_type, |
581 | 765 int *filter_type) |
582 { | 766 { |
583 png_debug1(1, "in %s retrieval function", "IHDR"); | 767 png_debug1(1, "in %s retrieval function", "IHDR"); |
584 | 768 |
585 if (png_ptr == NULL || info_ptr == NULL || width == NULL || | 769 if (png_ptr == NULL || info_ptr == NULL || width == NULL || |
586 height == NULL || bit_depth == NULL || color_type == NULL) | 770 height == NULL || bit_depth == NULL || color_type == NULL) |
587 return (0); | 771 return (0); |
588 | 772 |
589 *width = info_ptr->width; | 773 *width = info_ptr->width; |
590 *height = info_ptr->height; | 774 *height = info_ptr->height; |
591 *bit_depth = info_ptr->bit_depth; | 775 *bit_depth = info_ptr->bit_depth; |
592 *color_type = info_ptr->color_type; | 776 *color_type = info_ptr->color_type; |
593 | 777 |
594 if (compression_type != NULL) | 778 if (compression_type != NULL) |
595 *compression_type = info_ptr->compression_type; | 779 *compression_type = info_ptr->compression_type; |
596 | 780 |
597 if (filter_type != NULL) | 781 if (filter_type != NULL) |
598 *filter_type = info_ptr->filter_type; | 782 *filter_type = info_ptr->filter_type; |
599 | 783 |
600 if (interlace_type != NULL) | 784 if (interlace_type != NULL) |
601 *interlace_type = info_ptr->interlace_type; | 785 *interlace_type = info_ptr->interlace_type; |
602 | 786 |
603 /* This is redundant if we can be sure that the info_ptr values were all | 787 /* This is redundant if we can be sure that the info_ptr values were all |
604 * assigned in png_set_IHDR(). We do the check anyhow in case an | 788 * assigned in png_set_IHDR(). We do the check anyhow in case an |
605 * application has ignored our advice not to mess with the members | 789 * application has ignored our advice not to mess with the members |
606 * of info_ptr directly. | 790 * of info_ptr directly. |
607 */ | 791 */ |
608 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, | 792 png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height, |
609 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, | 793 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, |
610 info_ptr->compression_type, info_ptr->filter_type); | 794 info_ptr->compression_type, info_ptr->filter_type); |
611 | 795 |
612 return (1); | 796 return (1); |
613 } | 797 } |
614 | 798 |
615 #ifdef PNG_oFFs_SUPPORTED | 799 #ifdef PNG_oFFs_SUPPORTED |
616 png_uint_32 PNGAPI | 800 png_uint_32 PNGAPI |
617 png_get_oFFs(png_structp png_ptr, png_infop info_ptr, | 801 png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr, |
618 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) | 802 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) |
619 { | 803 { |
620 png_debug1(1, "in %s retrieval function", "oFFs"); | 804 png_debug1(1, "in %s retrieval function", "oFFs"); |
621 | 805 |
622 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) | 806 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) |
623 && offset_x != NULL && offset_y != NULL && unit_type != NULL) | 807 && offset_x != NULL && offset_y != NULL && unit_type != NULL) |
624 { | 808 { |
625 *offset_x = info_ptr->x_offset; | 809 *offset_x = info_ptr->x_offset; |
626 *offset_y = info_ptr->y_offset; | 810 *offset_y = info_ptr->y_offset; |
627 *unit_type = (int)info_ptr->offset_unit_type; | 811 *unit_type = (int)info_ptr->offset_unit_type; |
628 return (PNG_INFO_oFFs); | 812 return (PNG_INFO_oFFs); |
629 } | 813 } |
| 814 |
630 return (0); | 815 return (0); |
631 } | 816 } |
632 #endif | 817 #endif |
633 | 818 |
634 #ifdef PNG_pCAL_SUPPORTED | 819 #ifdef PNG_pCAL_SUPPORTED |
635 png_uint_32 PNGAPI | 820 png_uint_32 PNGAPI |
636 png_get_pCAL(png_structp png_ptr, png_infop info_ptr, | 821 png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr, |
637 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, | 822 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, |
638 png_charp *units, png_charpp *params) | 823 png_charp *units, png_charpp *params) |
639 { | 824 { |
640 png_debug1(1, "in %s retrieval function", "pCAL"); | 825 png_debug1(1, "in %s retrieval function", "pCAL"); |
641 | 826 |
642 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) | 827 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) |
643 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && | 828 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && |
644 nparams != NULL && units != NULL && params != NULL) | 829 nparams != NULL && units != NULL && params != NULL) |
645 { | 830 { |
646 *purpose = info_ptr->pcal_purpose; | 831 *purpose = info_ptr->pcal_purpose; |
647 *X0 = info_ptr->pcal_X0; | 832 *X0 = info_ptr->pcal_X0; |
648 *X1 = info_ptr->pcal_X1; | 833 *X1 = info_ptr->pcal_X1; |
649 *type = (int)info_ptr->pcal_type; | 834 *type = (int)info_ptr->pcal_type; |
650 *nparams = (int)info_ptr->pcal_nparams; | 835 *nparams = (int)info_ptr->pcal_nparams; |
651 *units = info_ptr->pcal_units; | 836 *units = info_ptr->pcal_units; |
652 *params = info_ptr->pcal_params; | 837 *params = info_ptr->pcal_params; |
653 return (PNG_INFO_pCAL); | 838 return (PNG_INFO_pCAL); |
654 } | 839 } |
| 840 |
655 return (0); | 841 return (0); |
656 } | 842 } |
657 #endif | 843 #endif |
658 | 844 |
659 #ifdef PNG_sCAL_SUPPORTED | 845 #ifdef PNG_sCAL_SUPPORTED |
660 #ifdef PNG_FLOATING_POINT_SUPPORTED | 846 # ifdef PNG_FIXED_POINT_SUPPORTED |
| 847 # if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \ |
| 848 defined(PNG_FLOATING_POINT_SUPPORTED) |
661 png_uint_32 PNGAPI | 849 png_uint_32 PNGAPI |
662 png_get_sCAL(png_structp png_ptr, png_infop info_ptr, | 850 png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr, |
663 int *unit, double *width, double *height) | 851 int *unit, png_fixed_point *width, png_fixed_point *height) |
664 { | 852 { |
665 if (png_ptr != NULL && info_ptr != NULL && | 853 if (png_ptr != NULL && info_ptr != NULL && |
666 (info_ptr->valid & PNG_INFO_sCAL)) | 854 (info_ptr->valid & PNG_INFO_sCAL)) |
667 { | 855 { |
668 *unit = info_ptr->scal_unit; | 856 *unit = info_ptr->scal_unit; |
669 *width = info_ptr->scal_pixel_width; | 857 /*TODO: make this work without FP support; the API is currently eliminated |
670 *height = info_ptr->scal_pixel_height; | 858 * if neither floating point APIs nor internal floating point arithmetic |
671 return (PNG_INFO_sCAL); | 859 * are enabled. |
672 } | 860 */ |
673 return(0); | 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); |
674 } | 868 } |
675 #else | 869 # endif /* FLOATING_ARITHMETIC */ |
676 #ifdef PNG_FIXED_POINT_SUPPORTED | 870 # endif /* FIXED_POINT */ |
| 871 # ifdef PNG_FLOATING_POINT_SUPPORTED |
677 png_uint_32 PNGAPI | 872 png_uint_32 PNGAPI |
678 png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, | 873 png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr, |
679 int *unit, png_charpp width, png_charpp height) | 874 int *unit, double *width, double *height) |
680 { | 875 { |
681 if (png_ptr != NULL && info_ptr != NULL && | 876 if (png_ptr != NULL && info_ptr != NULL && |
682 (info_ptr->valid & PNG_INFO_sCAL)) | 877 (info_ptr->valid & PNG_INFO_sCAL)) |
683 { | 878 { |
684 *unit = info_ptr->scal_unit; | 879 *unit = info_ptr->scal_unit; |
685 *width = info_ptr->scal_s_width; | 880 *width = atof(info_ptr->scal_s_width); |
686 *height = info_ptr->scal_s_height; | 881 *height = atof(info_ptr->scal_s_height); |
687 return (PNG_INFO_sCAL); | 882 return (PNG_INFO_sCAL); |
688 } | 883 } |
689 return(0); | 884 |
| 885 return(0); |
690 } | 886 } |
691 #endif | 887 # endif /* FLOATING POINT */ |
692 #endif | 888 png_uint_32 PNGAPI |
693 #endif | 889 png_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 */ |
694 | 904 |
695 #ifdef PNG_pHYs_SUPPORTED | 905 #ifdef PNG_pHYs_SUPPORTED |
696 png_uint_32 PNGAPI | 906 png_uint_32 PNGAPI |
697 png_get_pHYs(png_structp png_ptr, png_infop info_ptr, | 907 png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr, |
698 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) | 908 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) |
699 { | 909 { |
700 png_uint_32 retval = 0; | 910 png_uint_32 retval = 0; |
701 | 911 |
702 png_debug1(1, "in %s retrieval function", "pHYs"); | 912 png_debug1(1, "in %s retrieval function", "pHYs"); |
703 | 913 |
704 if (png_ptr != NULL && info_ptr != NULL && | 914 if (png_ptr != NULL && info_ptr != NULL && |
705 (info_ptr->valid & PNG_INFO_pHYs)) | 915 (info_ptr->valid & PNG_INFO_pHYs)) |
706 { | 916 { |
707 if (res_x != NULL) | 917 if (res_x != NULL) |
708 { | 918 { |
709 *res_x = info_ptr->x_pixels_per_unit; | 919 *res_x = info_ptr->x_pixels_per_unit; |
710 retval |= PNG_INFO_pHYs; | 920 retval |= PNG_INFO_pHYs; |
711 } | 921 } |
712 | 922 |
713 if (res_y != NULL) | 923 if (res_y != NULL) |
714 { | 924 { |
715 *res_y = info_ptr->y_pixels_per_unit; | 925 *res_y = info_ptr->y_pixels_per_unit; |
716 retval |= PNG_INFO_pHYs; | 926 retval |= PNG_INFO_pHYs; |
717 } | 927 } |
718 | 928 |
719 if (unit_type != NULL) | 929 if (unit_type != NULL) |
720 { | 930 { |
721 *unit_type = (int)info_ptr->phys_unit_type; | 931 *unit_type = (int)info_ptr->phys_unit_type; |
722 retval |= PNG_INFO_pHYs; | 932 retval |= PNG_INFO_pHYs; |
723 } | 933 } |
724 } | 934 } |
| 935 |
725 return (retval); | 936 return (retval); |
726 } | 937 } |
727 #endif | 938 #endif /* pHYs */ |
728 | 939 |
729 png_uint_32 PNGAPI | 940 png_uint_32 PNGAPI |
730 png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, | 941 png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr, |
731 int *num_palette) | 942 png_colorp *palette, int *num_palette) |
732 { | 943 { |
733 png_debug1(1, "in %s retrieval function", "PLTE"); | 944 png_debug1(1, "in %s retrieval function", "PLTE"); |
734 | 945 |
735 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) | 946 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) |
736 && palette != NULL) | 947 && palette != NULL) |
737 { | 948 { |
738 *palette = info_ptr->palette; | 949 *palette = info_ptr->palette; |
739 *num_palette = info_ptr->num_palette; | 950 *num_palette = info_ptr->num_palette; |
740 png_debug1(3, "num_palette = %d", *num_palette); | 951 png_debug1(3, "num_palette = %d", *num_palette); |
741 return (PNG_INFO_PLTE); | 952 return (PNG_INFO_PLTE); |
742 } | 953 } |
| 954 |
743 return (0); | 955 return (0); |
744 } | 956 } |
745 | 957 |
746 #ifdef PNG_sBIT_SUPPORTED | 958 #ifdef PNG_sBIT_SUPPORTED |
747 png_uint_32 PNGAPI | 959 png_uint_32 PNGAPI |
748 png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) | 960 png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr, |
| 961 png_color_8p *sig_bit) |
749 { | 962 { |
750 png_debug1(1, "in %s retrieval function", "sBIT"); | 963 png_debug1(1, "in %s retrieval function", "sBIT"); |
751 | 964 |
752 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) | 965 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) |
753 && sig_bit != NULL) | 966 && sig_bit != NULL) |
754 { | 967 { |
755 *sig_bit = &(info_ptr->sig_bit); | 968 *sig_bit = &(info_ptr->sig_bit); |
756 return (PNG_INFO_sBIT); | 969 return (PNG_INFO_sBIT); |
757 } | 970 } |
| 971 |
758 return (0); | 972 return (0); |
759 } | 973 } |
760 #endif | 974 #endif |
761 | 975 |
762 #ifdef PNG_TEXT_SUPPORTED | 976 #ifdef PNG_TEXT_SUPPORTED |
763 png_uint_32 PNGAPI | 977 int PNGAPI |
764 png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, | 978 png_get_text(png_const_structrp png_ptr, png_inforp info_ptr, |
765 int *num_text) | 979 png_textp *text_ptr, int *num_text) |
766 { | 980 { |
767 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) | 981 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) |
768 { | 982 { |
769 png_debug1(1, "in %s retrieval function", | 983 png_debug1(1, "in 0x%lx retrieval function", |
770 (png_ptr->chunk_name[0] == '\0' ? "text" | 984 (unsigned long)png_ptr->chunk_name); |
771 : (png_const_charp)png_ptr->chunk_name)); | |
772 | 985 |
773 if (text_ptr != NULL) | 986 if (text_ptr != NULL) |
774 *text_ptr = info_ptr->text; | 987 *text_ptr = info_ptr->text; |
775 | 988 |
776 if (num_text != NULL) | 989 if (num_text != NULL) |
777 *num_text = info_ptr->num_text; | 990 *num_text = info_ptr->num_text; |
778 | 991 |
779 return ((png_uint_32)info_ptr->num_text); | 992 return info_ptr->num_text; |
780 } | 993 } |
| 994 |
781 if (num_text != NULL) | 995 if (num_text != NULL) |
782 *num_text = 0; | 996 *num_text = 0; |
| 997 |
783 return(0); | 998 return(0); |
784 } | 999 } |
785 #endif | 1000 #endif |
786 | 1001 |
787 #ifdef PNG_tIME_SUPPORTED | 1002 #ifdef PNG_tIME_SUPPORTED |
788 png_uint_32 PNGAPI | 1003 png_uint_32 PNGAPI |
789 png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) | 1004 png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr, |
| 1005 png_timep *mod_time) |
790 { | 1006 { |
791 png_debug1(1, "in %s retrieval function", "tIME"); | 1007 png_debug1(1, "in %s retrieval function", "tIME"); |
792 | 1008 |
793 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) | 1009 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) |
794 && mod_time != NULL) | 1010 && mod_time != NULL) |
795 { | 1011 { |
796 *mod_time = &(info_ptr->mod_time); | 1012 *mod_time = &(info_ptr->mod_time); |
797 return (PNG_INFO_tIME); | 1013 return (PNG_INFO_tIME); |
798 } | 1014 } |
| 1015 |
799 return (0); | 1016 return (0); |
800 } | 1017 } |
801 #endif | 1018 #endif |
802 | 1019 |
803 #ifdef PNG_tRNS_SUPPORTED | 1020 #ifdef PNG_tRNS_SUPPORTED |
804 png_uint_32 PNGAPI | 1021 png_uint_32 PNGAPI |
805 png_get_tRNS(png_structp png_ptr, png_infop info_ptr, | 1022 png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr, |
806 png_bytep *trans, int *num_trans, png_color_16p *trans_values) | 1023 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) |
807 { | 1024 { |
808 png_uint_32 retval = 0; | 1025 png_uint_32 retval = 0; |
809 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) | 1026 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) |
810 { | 1027 { |
811 png_debug1(1, "in %s retrieval function", "tRNS"); | 1028 png_debug1(1, "in %s retrieval function", "tRNS"); |
812 | 1029 |
813 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | 1030 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
814 { | 1031 { |
815 if (trans != NULL) | 1032 if (trans_alpha != NULL) |
816 { | 1033 { |
817 *trans = info_ptr->trans; | 1034 *trans_alpha = info_ptr->trans_alpha; |
818 retval |= PNG_INFO_tRNS; | 1035 retval |= PNG_INFO_tRNS; |
819 } | 1036 } |
820 | 1037 |
821 if (trans_values != NULL) | 1038 if (trans_color != NULL) |
822 *trans_values = &(info_ptr->trans_values); | 1039 *trans_color = &(info_ptr->trans_color); |
823 } | 1040 } |
| 1041 |
824 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ | 1042 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ |
825 { | 1043 { |
826 if (trans_values != NULL) | 1044 if (trans_color != NULL) |
827 { | 1045 { |
828 *trans_values = &(info_ptr->trans_values); | 1046 *trans_color = &(info_ptr->trans_color); |
829 retval |= PNG_INFO_tRNS; | 1047 retval |= PNG_INFO_tRNS; |
830 } | 1048 } |
831 | 1049 |
832 if (trans != NULL) | 1050 if (trans_alpha != NULL) |
833 *trans = NULL; | 1051 *trans_alpha = NULL; |
834 } | 1052 } |
| 1053 |
835 if (num_trans != NULL) | 1054 if (num_trans != NULL) |
836 { | 1055 { |
837 *num_trans = info_ptr->num_trans; | 1056 *num_trans = info_ptr->num_trans; |
838 retval |= PNG_INFO_tRNS; | 1057 retval |= PNG_INFO_tRNS; |
839 } | 1058 } |
840 } | 1059 } |
| 1060 |
841 return (retval); | 1061 return (retval); |
842 } | 1062 } |
843 #endif | 1063 #endif |
844 | 1064 |
845 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED | 1065 #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED |
846 png_uint_32 PNGAPI | 1066 int PNGAPI |
847 png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, | 1067 png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr, |
848 png_unknown_chunkpp unknowns) | 1068 png_unknown_chunkpp unknowns) |
849 { | 1069 { |
850 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) | 1070 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) |
851 { | 1071 { |
852 *unknowns = info_ptr->unknown_chunks; | 1072 *unknowns = info_ptr->unknown_chunks; |
853 return ((png_uint_32)info_ptr->unknown_chunks_num); | 1073 return info_ptr->unknown_chunks_num; |
854 } | 1074 } |
| 1075 |
855 return (0); | 1076 return (0); |
856 } | 1077 } |
857 #endif | 1078 #endif |
858 | 1079 |
859 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED | 1080 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED |
860 png_byte PNGAPI | 1081 png_byte PNGAPI |
861 png_get_rgb_to_gray_status (png_structp png_ptr) | 1082 png_get_rgb_to_gray_status (png_const_structrp png_ptr) |
862 { | 1083 { |
863 return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0); | 1084 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0); |
864 } | 1085 } |
865 #endif | 1086 #endif |
866 | 1087 |
867 #ifdef PNG_USER_CHUNKS_SUPPORTED | 1088 #ifdef PNG_USER_CHUNKS_SUPPORTED |
868 png_voidp PNGAPI | 1089 png_voidp PNGAPI |
869 png_get_user_chunk_ptr(png_structp png_ptr) | 1090 png_get_user_chunk_ptr(png_const_structrp png_ptr) |
870 { | 1091 { |
871 return (png_ptr? png_ptr->user_chunk_ptr : NULL); | 1092 return (png_ptr ? png_ptr->user_chunk_ptr : NULL); |
872 } | 1093 } |
873 #endif | 1094 #endif |
874 | 1095 |
875 png_uint_32 PNGAPI | 1096 png_size_t PNGAPI |
876 png_get_compression_buffer_size(png_structp png_ptr) | 1097 png_get_compression_buffer_size(png_const_structrp png_ptr) |
877 { | 1098 { |
878 return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L); | 1099 if (png_ptr == NULL) |
| 1100 return 0; |
| 1101 |
| 1102 # ifdef PNG_WRITE_SUPPORTED |
| 1103 if (png_ptr->mode & PNG_IS_READ_STRUCT) |
| 1104 # endif |
| 1105 { |
| 1106 # ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
| 1107 return png_ptr->IDAT_read_size; |
| 1108 # else |
| 1109 return PNG_IDAT_READ_SIZE; |
| 1110 # endif |
| 1111 } |
| 1112 |
| 1113 # ifdef PNG_WRITE_SUPPORTED |
| 1114 else |
| 1115 return png_ptr->zbuffer_size; |
| 1116 # endif |
879 } | 1117 } |
880 | 1118 |
881 #ifdef PNG_ASSEMBLER_CODE_SUPPORTED | 1119 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
882 #ifndef PNG_1_0_X | 1120 /* These functions were added to libpng 1.2.6 and were enabled |
883 /* This function was added to libpng 1.2.0 and should exist by default */ | 1121 * by default in libpng-1.4.0 */ |
884 png_uint_32 PNGAPI | 1122 png_uint_32 PNGAPI |
885 png_get_asm_flags (png_structp png_ptr) | 1123 png_get_user_width_max (png_const_structrp png_ptr) |
886 { | 1124 { |
887 /* Obsolete, to be removed from libpng-1.4.0 */ | 1125 return (png_ptr ? png_ptr->user_width_max : 0); |
888 return (png_ptr? 0L: 0L); | |
889 } | 1126 } |
890 | 1127 |
891 /* This function was added to libpng 1.2.0 and should exist by default */ | |
892 png_uint_32 PNGAPI | 1128 png_uint_32 PNGAPI |
893 png_get_asm_flagmask (int flag_select) | 1129 png_get_user_height_max (png_const_structrp png_ptr) |
894 { | 1130 { |
895 /* Obsolete, to be removed from libpng-1.4.0 */ | 1131 return (png_ptr ? png_ptr->user_height_max : 0); |
896 flag_select=flag_select; | |
897 return 0L; | |
898 } | 1132 } |
899 | 1133 |
900 /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */ | 1134 /* This function was added to libpng 1.4.0 */ |
901 /* This function was added to libpng 1.2.0 */ | |
902 png_uint_32 PNGAPI | 1135 png_uint_32 PNGAPI |
903 png_get_mmx_flagmask (int flag_select, int *compilerID) | 1136 png_get_chunk_cache_max (png_const_structrp png_ptr) |
904 { | 1137 { |
905 /* Obsolete, to be removed from libpng-1.4.0 */ | 1138 return (png_ptr ? png_ptr->user_chunk_cache_max : 0); |
906 flag_select=flag_select; | |
907 *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */ | |
908 return 0L; | |
909 } | 1139 } |
910 | 1140 |
911 /* This function was added to libpng 1.2.0 */ | 1141 /* This function was added to libpng 1.4.1 */ |
912 png_byte PNGAPI | 1142 png_alloc_size_t PNGAPI |
913 png_get_mmx_bitdepth_threshold (png_structp png_ptr) | 1143 png_get_chunk_malloc_max (png_const_structrp png_ptr) |
914 { | 1144 { |
915 /* Obsolete, to be removed from libpng-1.4.0 */ | 1145 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0); |
916 return (png_ptr? 0: 0); | |
917 } | |
918 | |
919 /* This function was added to libpng 1.2.0 */ | |
920 png_uint_32 PNGAPI | |
921 png_get_mmx_rowbytes_threshold (png_structp png_ptr) | |
922 { | |
923 /* Obsolete, to be removed from libpng-1.4.0 */ | |
924 return (png_ptr? 0L: 0L); | |
925 } | |
926 #endif /* ?PNG_1_0_X */ | |
927 #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ | |
928 | |
929 #ifdef PNG_SET_USER_LIMITS_SUPPORTED | |
930 /* These functions were added to libpng 1.2.6 but not enabled | |
931 * by default. They will be enabled in libpng-1.4.0 */ | |
932 png_uint_32 PNGAPI | |
933 png_get_user_width_max (png_structp png_ptr) | |
934 { | |
935 return (png_ptr? png_ptr->user_width_max : 0); | |
936 } | |
937 png_uint_32 PNGAPI | |
938 png_get_user_height_max (png_structp png_ptr) | |
939 { | |
940 return (png_ptr? png_ptr->user_height_max : 0); | |
941 } | 1146 } |
942 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ | 1147 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ |
943 | 1148 |
| 1149 /* These functions were added to libpng 1.4.0 */ |
| 1150 #ifdef PNG_IO_STATE_SUPPORTED |
| 1151 png_uint_32 PNGAPI |
| 1152 png_get_io_state (png_const_structrp png_ptr) |
| 1153 { |
| 1154 return png_ptr->io_state; |
| 1155 } |
| 1156 |
| 1157 png_uint_32 PNGAPI |
| 1158 png_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 |
| 1166 int PNGAPI |
| 1167 png_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 |
944 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ | 1177 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ |
OLD | NEW |