Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1 | |
| 2 | /* pngget.c - retrieval of values from info struct |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 3 | * |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame^] | 4 | * libpng 1.0.6 - March 21, 2000 |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 5 | * 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-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 8 | * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 9 | */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 10 | |
| 11 | #define PNG_INTERNAL |
| 12 | #include "png.h" |
| 13 | |
| 14 | png_uint_32 |
| 15 | png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) |
| 16 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 17 | if (png_ptr != NULL && info_ptr != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 18 | return(info_ptr->valid & flag); |
| 19 | else |
| 20 | return(0); |
| 21 | } |
| 22 | |
| 23 | png_uint_32 |
| 24 | png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) |
| 25 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 26 | if (png_ptr != NULL && info_ptr != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 27 | return(info_ptr->rowbytes); |
| 28 | else |
| 29 | return(0); |
| 30 | } |
| 31 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 32 | #if defined(PNG_INFO_IMAGE_SUPPORTED) |
| 33 | png_bytepp |
| 34 | png_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-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 43 | #ifdef PNG_EASY_ACCESS_SUPPORTED |
| 44 | /* easy access to info, added in libpng-0.99 */ |
| 45 | png_uint_32 |
| 46 | png_get_image_width(png_structp png_ptr, png_infop info_ptr) |
| 47 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 48 | if (png_ptr != NULL && info_ptr != NULL) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 49 | { |
| 50 | return info_ptr->width; |
| 51 | } |
| 52 | return (0); |
| 53 | } |
| 54 | |
| 55 | png_uint_32 |
| 56 | png_get_image_height(png_structp png_ptr, png_infop info_ptr) |
| 57 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 58 | if (png_ptr != NULL && info_ptr != NULL) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 59 | { |
| 60 | return info_ptr->height; |
| 61 | } |
| 62 | return (0); |
| 63 | } |
| 64 | |
| 65 | png_byte |
| 66 | png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) |
| 67 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 68 | if (png_ptr != NULL && info_ptr != NULL) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 69 | { |
| 70 | return info_ptr->bit_depth; |
| 71 | } |
| 72 | return (0); |
| 73 | } |
| 74 | |
| 75 | png_byte |
| 76 | png_get_color_type(png_structp png_ptr, png_infop info_ptr) |
| 77 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 78 | if (png_ptr != NULL && info_ptr != NULL) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 79 | { |
| 80 | return info_ptr->color_type; |
| 81 | } |
| 82 | return (0); |
| 83 | } |
| 84 | |
| 85 | png_byte |
| 86 | png_get_filter_type(png_structp png_ptr, png_infop info_ptr) |
| 87 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 88 | if (png_ptr != NULL && info_ptr != NULL) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 89 | { |
| 90 | return info_ptr->filter_type; |
| 91 | } |
| 92 | return (0); |
| 93 | } |
| 94 | |
| 95 | png_byte |
| 96 | png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) |
| 97 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 98 | if (png_ptr != NULL && info_ptr != NULL) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 99 | { |
| 100 | return info_ptr->interlace_type; |
| 101 | } |
| 102 | return (0); |
| 103 | } |
| 104 | |
| 105 | png_byte |
| 106 | png_get_compression_type(png_structp png_ptr, png_infop info_ptr) |
| 107 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 108 | if (png_ptr != NULL && info_ptr != NULL) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 109 | { |
| 110 | return info_ptr->compression_type; |
| 111 | } |
| 112 | return (0); |
| 113 | } |
| 114 | |
| 115 | png_uint_32 |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 116 | png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) |
| 117 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 118 | #if defined(PNG_pHYs_SUPPORTED) |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 119 | 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 | |
| 131 | png_uint_32 |
| 132 | png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) |
| 133 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 134 | #if defined(PNG_pHYs_SUPPORTED) |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 135 | 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 | |
| 147 | png_uint_32 |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 148 | png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) |
| 149 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 150 | #if defined(PNG_pHYs_SUPPORTED) |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 151 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 152 | { |
| 153 | png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter"); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 154 | if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER || |
| 155 | info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 156 | return (0); |
| 157 | else return (info_ptr->x_pixels_per_unit); |
| 158 | } |
| 159 | else |
| 160 | #endif |
| 161 | return (0); |
| 162 | } |
| 163 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 164 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 165 | float |
| 166 | png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) |
| 167 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 168 | #if defined(PNG_pHYs_SUPPORTED) |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 169 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 170 | { |
| 171 | png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio"); |
| 172 | if (info_ptr->x_pixels_per_unit == 0) |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 173 | return ((float)0.0); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 174 | else |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 175 | return ((float)info_ptr->y_pixels_per_unit |
| 176 | /(float)info_ptr->x_pixels_per_unit); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 177 | } |
| 178 | else |
| 179 | #endif |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 180 | return ((float)0.0); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 181 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 182 | #endif |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 183 | |
| 184 | png_uint_32 |
| 185 | png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) |
| 186 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 187 | #if defined(PNG_oFFs_SUPPORTED) |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 188 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 189 | { |
| 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 | |
| 200 | png_uint_32 |
| 201 | png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) |
| 202 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 203 | #if defined(PNG_oFFs_SUPPORTED) |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 204 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 205 | { |
| 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 | |
| 216 | png_uint_32 |
| 217 | png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) |
| 218 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 219 | #if defined(PNG_oFFs_SUPPORTED) |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 220 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 221 | { |
| 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 | |
| 232 | png_uint_32 |
| 233 | png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) |
| 234 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 235 | #if defined(PNG_oFFs_SUPPORTED) |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 236 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 237 | { |
| 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-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 248 | #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 249 | png_uint_32 |
| 250 | png_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-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 253 | *.0254 +.5); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | png_uint_32 |
| 257 | png_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-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 260 | *.0254 +.5); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | png_uint_32 |
| 264 | png_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-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 267 | *.0254 +.5); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | float |
| 271 | png_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-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 274 | *.00003937); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | float |
| 278 | png_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-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 281 | *.00003937) |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | #if defined(PNG_READ_pHYs_SUPPORTED) |
| 285 | png_uint_32 |
| 286 | png_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-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 291 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 292 | { |
| 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-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 310 | 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-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | } |
| 315 | return (retval); |
| 316 | } |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 317 | #endif /* PNG_READ_pHYs_SUPPORTED */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 318 | #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 319 | |
| 320 | /* png_get_channels really belongs in here, too, but it's been around longer */ |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 321 | |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 322 | #endif /* PNG_EASY_ACCESS_SUPPORTED */ |
| 323 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 324 | png_byte |
| 325 | png_get_channels(png_structp png_ptr, png_infop info_ptr) |
| 326 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 327 | if (png_ptr != NULL && info_ptr != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 328 | return(info_ptr->channels); |
| 329 | else |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 330 | return (0); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | png_bytep |
| 334 | png_get_signature(png_structp png_ptr, png_infop info_ptr) |
| 335 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 336 | if (png_ptr != NULL && info_ptr != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 337 | return(info_ptr->signature); |
| 338 | else |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 339 | return (NULL); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | #if defined(PNG_READ_bKGD_SUPPORTED) |
| 343 | png_uint_32 |
| 344 | png_get_bKGD(png_structp png_ptr, png_infop info_ptr, |
| 345 | png_color_16p *background) |
| 346 | { |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 347 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) |
| 348 | && background != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 349 | { |
| 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-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 359 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 360 | png_uint_32 |
| 361 | png_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-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 365 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 366 | { |
| 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-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 389 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 390 | png_uint_32 |
| 391 | png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 392 | 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-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 395 | { |
| 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 Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 421 | |
| 422 | #if defined(PNG_READ_gAMA_SUPPORTED) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 423 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 424 | png_uint_32 |
| 425 | png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) |
| 426 | { |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 427 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) |
| 428 | && file_gamma != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 429 | { |
| 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-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 437 | png_uint_32 |
| 438 | png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 439 | png_fixed_point *int_file_gamma) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 440 | { |
| 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 Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 451 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 452 | #if defined(PNG_READ_sRGB_SUPPORTED) |
| 453 | png_uint_32 |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 454 | png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 455 | { |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 456 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) |
| 457 | && file_srgb_intent != NULL) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 458 | { |
| 459 | png_debug1(1, "in %s retrieval function\n", "sRGB"); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 460 | *file_srgb_intent = (int)info_ptr->srgb_intent; |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 461 | return (PNG_INFO_sRGB); |
| 462 | } |
| 463 | return (0); |
| 464 | } |
| 465 | #endif |
| 466 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 467 | #if defined(PNG_READ_iCCP_SUPPORTED) |
| 468 | png_uint_32 |
| 469 | png_get_iCCP(png_structp png_ptr, png_infop info_ptr, |
| 470 | png_charpp name, int *compression_type, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 471 | png_charpp profile, png_uint_32 *proflen) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 472 | { |
| 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-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 489 | #if defined(PNG_READ_sPLT_SUPPORTED) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 490 | png_uint_32 |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 491 | png_get_sPLT(png_structp png_ptr, png_infop info_ptr, |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame^] | 492 | png_sPLT_tpp spalettes) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 493 | { |
| 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 Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 500 | #if defined(PNG_READ_hIST_SUPPORTED) |
| 501 | png_uint_32 |
| 502 | png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) |
| 503 | { |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 504 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) |
| 505 | && hist != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 506 | { |
| 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 | |
| 515 | png_uint_32 |
| 516 | png_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-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 520 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 521 | { |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 522 | if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL && |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 523 | bit_depth != NULL && color_type != NULL) |
| 524 | { |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 525 | int pixel_depth, channels; |
| 526 | png_uint_32 rowbytes_per_pixel; |
| 527 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 528 | 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-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 539 | |
| 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-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 551 | if ((*width > PNG_MAX_UINT/rowbytes_per_pixel)) |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 552 | { |
| 553 | png_warning(png_ptr, |
| 554 | "Width too large for libpng to process image data."); |
| 555 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 556 | return (1); |
| 557 | } |
| 558 | return (0); |
| 559 | } |
| 560 | |
| 561 | #if defined(PNG_READ_oFFs_SUPPORTED) |
| 562 | png_uint_32 |
| 563 | png_get_oFFs(png_structp png_ptr, png_infop info_ptr, |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 564 | png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 565 | { |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 566 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) |
| 567 | && offset_x != NULL && offset_y != NULL && unit_type != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 568 | { |
| 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) |
| 580 | png_uint_32 |
| 581 | png_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-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 585 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) |
| 586 | && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 587 | 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-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 603 | #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED) |
| 604 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 605 | png_uint_32 |
| 606 | png_get_sCAL(png_structp png_ptr, png_infop info_ptr, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 607 | int *unit, double *width, double *height) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 608 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 609 | if (png_ptr != NULL && info_ptr != NULL && |
| 610 | (info_ptr->valid & PNG_INFO_sCAL)) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 611 | { |
| 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-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 619 | #else |
| 620 | #ifdef PNG_FIXED_POINT_SUPPORTED |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 621 | png_uint_32 |
| 622 | png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 623 | int *unit, png_charpp width, png_charpp height) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 624 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 625 | if (png_ptr != NULL && info_ptr != NULL && |
| 626 | (info_ptr->valid & PNG_INFO_sCAL)) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 627 | { |
| 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-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 636 | #endif |
| 637 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 638 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 639 | #if defined(PNG_READ_pHYs_SUPPORTED) |
| 640 | png_uint_32 |
| 641 | png_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-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 644 | png_uint_32 retval = 0; |
| 645 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 646 | if (png_ptr != NULL && info_ptr != NULL && |
| 647 | (info_ptr->valid & PNG_INFO_pHYs)) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 648 | { |
| 649 | png_debug1(1, "in %s retrieval function\n", "pHYs"); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 650 | if (res_x != NULL) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 651 | { |
| 652 | *res_x = info_ptr->x_pixels_per_unit; |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 653 | retval |= PNG_INFO_pHYs; |
| 654 | } |
| 655 | if (res_y != NULL) |
| 656 | { |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 657 | *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 Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 665 | } |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 666 | return (retval); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 667 | } |
| 668 | #endif |
| 669 | |
| 670 | png_uint_32 |
| 671 | png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, |
| 672 | int *num_palette) |
| 673 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 674 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) |
| 675 | && palette != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 676 | { |
| 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) |
| 687 | png_uint_32 |
| 688 | png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) |
| 689 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 690 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) |
| 691 | && sig_bit != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 692 | { |
| 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-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 701 | #if defined(PNG_READ_TEXT_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 702 | png_uint_32 |
| 703 | png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, |
| 704 | int *num_text) |
| 705 | { |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 706 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 707 | { |
| 708 | png_debug1(1, "in %s retrieval function\n", |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 709 | (png_ptr->chunk_name[0] == '\0' ? "text" |
| 710 | : (png_const_charp)png_ptr->chunk_name)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 711 | if (text_ptr != NULL) |
| 712 | *text_ptr = info_ptr->text; |
| 713 | if (num_text != NULL) |
| 714 | *num_text = info_ptr->num_text; |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 715 | return ((png_uint_32)info_ptr->num_text); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 716 | } |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 717 | if (num_text != NULL) |
| 718 | *num_text = 0; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 719 | return(0); |
| 720 | } |
| 721 | #endif |
| 722 | |
| 723 | #if defined(PNG_READ_tIME_SUPPORTED) |
| 724 | png_uint_32 |
| 725 | png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) |
| 726 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 727 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) |
| 728 | && mod_time != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 729 | { |
| 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) |
| 739 | png_uint_32 |
| 740 | png_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-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 743 | png_uint_32 retval = 0; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 744 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 745 | { |
| 746 | png_debug1(1, "in %s retrieval function\n", "tRNS"); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 747 | if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 748 | { |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 749 | 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 Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 756 | } |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 757 | else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 758 | { |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 759 | 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 Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 766 | } |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 767 | if(num_trans != NULL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 768 | { |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 769 | *num_trans = info_ptr->num_trans; |
| 770 | retval |= PNG_INFO_tRNS; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 771 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 772 | } |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 773 | return (retval); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 774 | } |
| 775 | #endif |
| 776 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 777 | #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) |
| 778 | png_uint_32 |
| 779 | png_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-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 788 | #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) |
| 789 | png_byte |
| 790 | png_get_rgb_to_gray_status (png_structp png_ptr) |
| 791 | { |
| 792 | return png_ptr->rgb_to_gray_status; |
| 793 | } |
| 794 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 795 | |
| 796 | #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) |
| 797 | png_voidp |
| 798 | png_get_user_chunk_ptr(png_structp png_ptr) |
| 799 | { |
| 800 | return (png_ptr->user_chunk_ptr); |
| 801 | } |
| 802 | #endif |
| 803 | |