| 1 | /* |
|---|
| 2 | * $Id: //suprahd/releases/suprahd_163/suprahd_ztvapp640_163/drivers/graphics/PNG/lpng102/pngget.c#1 $ |
|---|
| 3 | * $Revision: #1 $ |
|---|
| 4 | * $DateTime: 2006/02/24 17:51:46 $ |
|---|
| 5 | * $Change: 42566 $ |
|---|
| 6 | * $Author: pryush.sharma $ |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | /* pngget.c - retrieval of values from info struct |
|---|
| 11 | * |
|---|
| 12 | * libpng 1.0.2 - June 14, 1998 |
|---|
| 13 | * For conditions of distribution and use, see copyright notice in png.h |
|---|
| 14 | * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. |
|---|
| 15 | * Copyright (c) 1996, 1997 Andreas Dilger |
|---|
| 16 | * Copyright (c) 1998, Glenn Randers-Pehrson |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | #define PNG_INTERNAL |
|---|
| 20 | #include "png.h" |
|---|
| 21 | |
|---|
| 22 | png_uint_32 |
|---|
| 23 | png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) |
|---|
| 24 | { |
|---|
| 25 | if (png_ptr != NULL && info_ptr != NULL) |
|---|
| 26 | return(info_ptr->valid & flag); |
|---|
| 27 | else |
|---|
| 28 | return(0); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | png_uint_32 |
|---|
| 32 | png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) |
|---|
| 33 | { |
|---|
| 34 | if (png_ptr != NULL && info_ptr != NULL) |
|---|
| 35 | return(info_ptr->rowbytes); |
|---|
| 36 | else |
|---|
| 37 | return(0); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | #ifdef PNG_EASY_ACCESS_SUPPORTED |
|---|
| 41 | /* easy access to info, added in libpng-0.99 */ |
|---|
| 42 | png_uint_32 |
|---|
| 43 | png_get_image_width(png_structp png_ptr, png_infop info_ptr) |
|---|
| 44 | { |
|---|
| 45 | if (png_ptr != NULL && info_ptr != NULL) |
|---|
| 46 | { |
|---|
| 47 | return info_ptr->width; |
|---|
| 48 | } |
|---|
| 49 | return (0); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | png_uint_32 |
|---|
| 53 | png_get_image_height(png_structp png_ptr, png_infop info_ptr) |
|---|
| 54 | { |
|---|
| 55 | if (png_ptr != NULL && info_ptr != NULL) |
|---|
| 56 | { |
|---|
| 57 | return info_ptr->height; |
|---|
| 58 | } |
|---|
| 59 | return (0); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | png_byte |
|---|
| 63 | png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) |
|---|
| 64 | { |
|---|
| 65 | if (png_ptr != NULL && info_ptr != NULL) |
|---|
| 66 | { |
|---|
| 67 | return info_ptr->bit_depth; |
|---|
| 68 | } |
|---|
| 69 | return (0); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | png_byte |
|---|
| 73 | png_get_color_type(png_structp png_ptr, png_infop info_ptr) |
|---|
| 74 | { |
|---|
| 75 | if (png_ptr != NULL && info_ptr != NULL) |
|---|
| 76 | { |
|---|
| 77 | return info_ptr->color_type; |
|---|
| 78 | } |
|---|
| 79 | return (0); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | png_byte |
|---|
| 83 | png_get_filter_type(png_structp png_ptr, png_infop info_ptr) |
|---|
| 84 | { |
|---|
| 85 | if (png_ptr != NULL && info_ptr != NULL) |
|---|
| 86 | { |
|---|
| 87 | return info_ptr->filter_type; |
|---|
| 88 | } |
|---|
| 89 | return (0); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | png_byte |
|---|
| 93 | png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) |
|---|
| 94 | { |
|---|
| 95 | if (png_ptr != NULL && info_ptr != NULL) |
|---|
| 96 | { |
|---|
| 97 | return info_ptr->interlace_type; |
|---|
| 98 | } |
|---|
| 99 | return (0); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | png_byte |
|---|
| 103 | png_get_compression_type(png_structp png_ptr, png_infop info_ptr) |
|---|
| 104 | { |
|---|
| 105 | if (png_ptr != NULL && info_ptr != NULL) |
|---|
| 106 | { |
|---|
| 107 | return info_ptr->compression_type; |
|---|
| 108 | } |
|---|
| 109 | return (0); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | png_uint_32 |
|---|
| 113 | png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) |
|---|
| 114 | { |
|---|
| 115 | #if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED) |
|---|
| 116 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
|---|
| 117 | { |
|---|
| 118 | png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter"); |
|---|
| 119 | if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER) |
|---|
| 120 | return (0); |
|---|
| 121 | else return (info_ptr->x_pixels_per_unit); |
|---|
| 122 | } |
|---|
| 123 | else |
|---|
| 124 | #endif |
|---|
| 125 | return (0); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | png_uint_32 |
|---|
| 129 | png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) |
|---|
| 130 | { |
|---|
| 131 | #if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED) |
|---|
| 132 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
|---|
| 133 | { |
|---|
| 134 | png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter"); |
|---|
| 135 | if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER) |
|---|
| 136 | return (0); |
|---|
| 137 | else return (info_ptr->y_pixels_per_unit); |
|---|
| 138 | } |
|---|
| 139 | else |
|---|
| 140 | #endif |
|---|
| 141 | return (0); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | png_uint_32 |
|---|
| 145 | png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) |
|---|
| 146 | { |
|---|
| 147 | #if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED) |
|---|
| 148 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
|---|
| 149 | { |
|---|
| 150 | png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter"); |
|---|
| 151 | if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER || |
|---|
| 152 | info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit) |
|---|
| 153 | return (0); |
|---|
| 154 | else return (info_ptr->x_pixels_per_unit); |
|---|
| 155 | } |
|---|
| 156 | else |
|---|
| 157 | #endif |
|---|
| 158 | return (0); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | float |
|---|
| 162 | png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) |
|---|
| 163 | { |
|---|
| 164 | #if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED) |
|---|
| 165 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) |
|---|
| 166 | { |
|---|
| 167 | png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio"); |
|---|
| 168 | if (info_ptr->x_pixels_per_unit == 0) |
|---|
| 169 | return ((float)0.0); |
|---|
| 170 | else |
|---|
| 171 | return ((float)info_ptr->y_pixels_per_unit |
|---|
| 172 | /(float)info_ptr->x_pixels_per_unit); |
|---|
| 173 | } |
|---|
| 174 | else |
|---|
| 175 | #endif |
|---|
| 176 | return ((float)0.0); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | png_uint_32 |
|---|
| 180 | png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) |
|---|
| 181 | { |
|---|
| 182 | #if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED) |
|---|
| 183 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) |
|---|
| 184 | { |
|---|
| 185 | png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); |
|---|
| 186 | if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) |
|---|
| 187 | return (0); |
|---|
| 188 | else return (info_ptr->x_offset); |
|---|
| 189 | } |
|---|
| 190 | else |
|---|
| 191 | #endif |
|---|
| 192 | return (0); |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | png_uint_32 |
|---|
| 196 | png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) |
|---|
| 197 | { |
|---|
| 198 | #if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED) |
|---|
| 199 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) |
|---|
| 200 | { |
|---|
| 201 | png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); |
|---|
| 202 | if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) |
|---|
| 203 | return (0); |
|---|
| 204 | else return (info_ptr->y_offset); |
|---|
| 205 | } |
|---|
| 206 | else |
|---|
| 207 | #endif |
|---|
| 208 | return (0); |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | png_uint_32 |
|---|
| 212 | png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) |
|---|
| 213 | { |
|---|
| 214 | #if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED) |
|---|
| 215 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) |
|---|
| 216 | { |
|---|
| 217 | png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); |
|---|
| 218 | if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) |
|---|
| 219 | return (0); |
|---|
| 220 | else return (info_ptr->x_offset); |
|---|
| 221 | } |
|---|
| 222 | else |
|---|
| 223 | #endif |
|---|
| 224 | return (0); |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | png_uint_32 |
|---|
| 228 | png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) |
|---|
| 229 | { |
|---|
| 230 | #if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED) |
|---|
| 231 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) |
|---|
| 232 | { |
|---|
| 233 | png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); |
|---|
| 234 | if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) |
|---|
| 235 | return (0); |
|---|
| 236 | else return (info_ptr->y_offset); |
|---|
| 237 | } |
|---|
| 238 | else |
|---|
| 239 | #endif |
|---|
| 240 | return (0); |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | #ifdef PNG_INCH_CONVERSIONS |
|---|
| 244 | png_uint_32 |
|---|
| 245 | png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) |
|---|
| 246 | { |
|---|
| 247 | return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr) |
|---|
| 248 | *.03937 +.5) |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | png_uint_32 |
|---|
| 252 | png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) |
|---|
| 253 | { |
|---|
| 254 | return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr) |
|---|
| 255 | *.03937 +.5) |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | png_uint_32 |
|---|
| 259 | png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) |
|---|
| 260 | { |
|---|
| 261 | return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr) |
|---|
| 262 | *.03937 +.5) |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | float |
|---|
| 266 | png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr) |
|---|
| 267 | { |
|---|
| 268 | return ((float)png_get_x_offset_microns(png_ptr, info_ptr) |
|---|
| 269 | *.03937/1000000. +.5) |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | float |
|---|
| 273 | png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) |
|---|
| 274 | { |
|---|
| 275 | return ((float)png_get_y_offset_microns(png_ptr, info_ptr) |
|---|
| 276 | *.03937/1000000. +.5) |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | #if defined(PNG_READ_pHYs_SUPPORTED) |
|---|
| 280 | png_uint_32 |
|---|
| 281 | png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, |
|---|
| 282 | png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) |
|---|
| 283 | { |
|---|
| 284 | png_uint_32 retval = 0; |
|---|
| 285 | |
|---|
| 286 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs) |
|---|
| 287 | { |
|---|
| 288 | png_debug1(1, "in %s retrieval function\n", "pHYs"); |
|---|
| 289 | if (res_x != NULL) |
|---|
| 290 | { |
|---|
| 291 | *res_x = info_ptr->x_pixels_per_unit; |
|---|
| 292 | retval |= PNG_INFO_pHYs; |
|---|
| 293 | } |
|---|
| 294 | if (res_y != NULL) |
|---|
| 295 | { |
|---|
| 296 | *res_y = info_ptr->y_pixels_per_unit; |
|---|
| 297 | retval |= PNG_INFO_pHYs; |
|---|
| 298 | } |
|---|
| 299 | if (unit_type != NULL) |
|---|
| 300 | { |
|---|
| 301 | *unit_type = (int)info_ptr->phys_unit_type; |
|---|
| 302 | retval |= PNG_INFO_pHYs; |
|---|
| 303 | if(unit_type == 1) |
|---|
| 304 | { |
|---|
| 305 | if (res_x != NULL) *res_x = (png_uint_32)(*res_x * 39.37 + .50); |
|---|
| 306 | if (res_y != NULL) *res_y = (png_uint_32)(*res_y * 39.37 + .50); |
|---|
| 307 | } |
|---|
| 308 | } |
|---|
| 309 | } |
|---|
| 310 | return (retval); |
|---|
| 311 | } |
|---|
| 312 | #endif /* PNG_READ_pHYs_SUPPORTED */ |
|---|
| 313 | #endif /* PNG_INCH_CONVERSIONS */ |
|---|
| 314 | |
|---|
| 315 | /* png_get_channels really belongs in here, too, but it's been around longer */ |
|---|
| 316 | |
|---|
| 317 | #endif /* PNG_EASY_ACCESS_SUPPORTED */ |
|---|
| 318 | |
|---|
| 319 | png_byte |
|---|
| 320 | png_get_channels(png_structp png_ptr, png_infop info_ptr) |
|---|
| 321 | { |
|---|
| 322 | if (png_ptr != NULL && info_ptr != NULL) |
|---|
| 323 | return(info_ptr->channels); |
|---|
| 324 | else |
|---|
| 325 | return (0); |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | png_bytep |
|---|
| 329 | png_get_signature(png_structp png_ptr, png_infop info_ptr) |
|---|
| 330 | { |
|---|
| 331 | if (png_ptr != NULL && info_ptr != NULL) |
|---|
| 332 | return(info_ptr->signature); |
|---|
| 333 | else |
|---|
| 334 | return (NULL); |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | #if defined(PNG_READ_bKGD_SUPPORTED) |
|---|
| 338 | png_uint_32 |
|---|
| 339 | png_get_bKGD(png_structp png_ptr, png_infop info_ptr, |
|---|
| 340 | png_color_16p *background) |
|---|
| 341 | { |
|---|
| 342 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) |
|---|
| 343 | && background != NULL) |
|---|
| 344 | { |
|---|
| 345 | png_debug1(1, "in %s retrieval function\n", "bKGD"); |
|---|
| 346 | *background = &(info_ptr->background); |
|---|
| 347 | return (PNG_INFO_bKGD); |
|---|
| 348 | } |
|---|
| 349 | return (0); |
|---|
| 350 | } |
|---|
| 351 | #endif |
|---|
| 352 | |
|---|
| 353 | #if defined(PNG_READ_cHRM_SUPPORTED) |
|---|
| 354 | png_uint_32 |
|---|
| 355 | png_get_cHRM(png_structp png_ptr, png_infop info_ptr, |
|---|
| 356 | double *white_x, double *white_y, double *red_x, double *red_y, |
|---|
| 357 | double *green_x, double *green_y, double *blue_x, double *blue_y) |
|---|
| 358 | { |
|---|
| 359 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) |
|---|
| 360 | { |
|---|
| 361 | png_debug1(1, "in %s retrieval function\n", "cHRM"); |
|---|
| 362 | if (white_x != NULL) |
|---|
| 363 | *white_x = (double)info_ptr->x_white; |
|---|
| 364 | if (white_y != NULL) |
|---|
| 365 | *white_y = (double)info_ptr->y_white; |
|---|
| 366 | if (red_x != NULL) |
|---|
| 367 | *red_x = (double)info_ptr->x_red; |
|---|
| 368 | if (red_y != NULL) |
|---|
| 369 | *red_y = (double)info_ptr->y_red; |
|---|
| 370 | if (green_x != NULL) |
|---|
| 371 | *green_x = (double)info_ptr->x_green; |
|---|
| 372 | if (green_y != NULL) |
|---|
| 373 | *green_y = (double)info_ptr->y_green; |
|---|
| 374 | if (blue_x != NULL) |
|---|
| 375 | *blue_x = (double)info_ptr->x_blue; |
|---|
| 376 | if (blue_y != NULL) |
|---|
| 377 | *blue_y = (double)info_ptr->y_blue; |
|---|
| 378 | return (PNG_INFO_cHRM); |
|---|
| 379 | } |
|---|
| 380 | return (0); |
|---|
| 381 | } |
|---|
| 382 | #endif |
|---|
| 383 | |
|---|
| 384 | #if defined(PNG_READ_gAMA_SUPPORTED) |
|---|
| 385 | png_uint_32 |
|---|
| 386 | png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) |
|---|
| 387 | { |
|---|
| 388 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) |
|---|
| 389 | && file_gamma != NULL) |
|---|
| 390 | { |
|---|
| 391 | png_debug1(1, "in %s retrieval function\n", "gAMA"); |
|---|
| 392 | *file_gamma = (double)info_ptr->gamma; |
|---|
| 393 | return (PNG_INFO_gAMA); |
|---|
| 394 | } |
|---|
| 395 | return (0); |
|---|
| 396 | } |
|---|
| 397 | #endif |
|---|
| 398 | |
|---|
| 399 | #if defined(PNG_READ_sRGB_SUPPORTED) |
|---|
| 400 | png_uint_32 |
|---|
| 401 | png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) |
|---|
| 402 | { |
|---|
| 403 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) |
|---|
| 404 | && file_srgb_intent != NULL) |
|---|
| 405 | { |
|---|
| 406 | png_debug1(1, "in %s retrieval function\n", "sRGB"); |
|---|
| 407 | *file_srgb_intent = (int)info_ptr->srgb_intent; |
|---|
| 408 | return (PNG_INFO_sRGB); |
|---|
| 409 | } |
|---|
| 410 | return (0); |
|---|
| 411 | } |
|---|
| 412 | #endif |
|---|
| 413 | |
|---|
| 414 | #if defined(PNG_READ_hIST_SUPPORTED) |
|---|
| 415 | png_uint_32 |
|---|
| 416 | png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) |
|---|
| 417 | { |
|---|
| 418 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) |
|---|
| 419 | && hist != NULL) |
|---|
| 420 | { |
|---|
| 421 | png_debug1(1, "in %s retrieval function\n", "hIST"); |
|---|
| 422 | *hist = info_ptr->hist; |
|---|
| 423 | return (PNG_INFO_hIST); |
|---|
| 424 | } |
|---|
| 425 | return (0); |
|---|
| 426 | } |
|---|
| 427 | #endif |
|---|
| 428 | |
|---|
| 429 | png_uint_32 |
|---|
| 430 | png_get_IHDR(png_structp png_ptr, png_infop info_ptr, |
|---|
| 431 | png_uint_32 *width, png_uint_32 *height, int *bit_depth, |
|---|
| 432 | int *color_type, int *interlace_type, int *compression_type, |
|---|
| 433 | int *filter_type) |
|---|
| 434 | |
|---|
| 435 | { |
|---|
| 436 | if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL && |
|---|
| 437 | bit_depth != NULL && color_type != NULL) |
|---|
| 438 | { |
|---|
| 439 | int pixel_depth, channels; |
|---|
| 440 | png_uint_32 rowbytes_per_pixel; |
|---|
| 441 | |
|---|
| 442 | png_debug1(1, "in %s retrieval function\n", "IHDR"); |
|---|
| 443 | *width = info_ptr->width; |
|---|
| 444 | *height = info_ptr->height; |
|---|
| 445 | *bit_depth = info_ptr->bit_depth; |
|---|
| 446 | *color_type = info_ptr->color_type; |
|---|
| 447 | if (compression_type != NULL) |
|---|
| 448 | *compression_type = info_ptr->compression_type; |
|---|
| 449 | if (filter_type != NULL) |
|---|
| 450 | *filter_type = info_ptr->filter_type; |
|---|
| 451 | if (interlace_type != NULL) |
|---|
| 452 | *interlace_type = info_ptr->interlace_type; |
|---|
| 453 | |
|---|
| 454 | /* check for potential overflow of rowbytes */ |
|---|
| 455 | if (*color_type == PNG_COLOR_TYPE_PALETTE) |
|---|
| 456 | channels = 1; |
|---|
| 457 | else if (*color_type & PNG_COLOR_MASK_COLOR) |
|---|
| 458 | channels = 3; |
|---|
| 459 | else |
|---|
| 460 | channels = 1; |
|---|
| 461 | if (*color_type & PNG_COLOR_MASK_ALPHA) |
|---|
| 462 | channels++; |
|---|
| 463 | pixel_depth = *bit_depth * channels; |
|---|
| 464 | rowbytes_per_pixel = (pixel_depth + 7) >> 3; |
|---|
| 465 | if ((*width > (png_uint_32)2147483647L/rowbytes_per_pixel)) |
|---|
| 466 | { |
|---|
| 467 | png_warning(png_ptr, |
|---|
| 468 | "Width too large for libpng to process image data."); |
|---|
| 469 | } |
|---|
| 470 | return (1); |
|---|
| 471 | } |
|---|
| 472 | return (0); |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | #if defined(PNG_READ_oFFs_SUPPORTED) |
|---|
| 476 | png_uint_32 |
|---|
| 477 | png_get_oFFs(png_structp png_ptr, png_infop info_ptr, |
|---|
| 478 | png_uint_32 *offset_x, png_uint_32 *offset_y, int *unit_type) |
|---|
| 479 | { |
|---|
| 480 | if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) |
|---|
| 481 | && offset_x != NULL && offset_y != NULL && unit_type != NULL) |
|---|
| 482 | { |
|---|
| 483 | png_debug1(1, "in %s retrieval function\n", "oFFs"); |
|---|
| 484 | *offset_x = info_ptr->x_offset; |
|---|
| 485 | *offset_y = info_ptr->y_offset; |
|---|
| 486 | *unit_type = (int)info_ptr->offset_unit_type; |
|---|
| 487 | return (PNG_INFO_oFFs); |
|---|
| 488 | } |
|---|
| 489 | return (0); |
|---|
| 490 | } |
|---|
| 491 | #endif |
|---|
| 492 | |
|---|
| 493 | #if defined(PNG_READ_pCAL_SUPPORTED) |
|---|
| 494 | png_uint_32 |
|---|
| 495 | png_get_pCAL(png_structp png_ptr, png_infop info_ptr, |
|---|
| 496 | png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, |
|---|
| 497 | png_charp *units, png_charpp *params) |
|---|
| 498 | { |
|---|
| 499 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL && |
|---|
| 500 | purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && |
|---|
| 501 | nparams != NULL && units != NULL && params != NULL) |
|---|
| 502 | { |
|---|
| 503 | png_debug1(1, "in %s retrieval function\n", "pCAL"); |
|---|
| 504 | *purpose = info_ptr->pcal_purpose; |
|---|
| 505 | *X0 = info_ptr->pcal_X0; |
|---|
| 506 | *X1 = info_ptr->pcal_X1; |
|---|
| 507 | *type = (int)info_ptr->pcal_type; |
|---|
| 508 | *nparams = (int)info_ptr->pcal_nparams; |
|---|
| 509 | *units = info_ptr->pcal_units; |
|---|
| 510 | *params = info_ptr->pcal_params; |
|---|
| 511 | return (PNG_INFO_pCAL); |
|---|
| 512 | } |
|---|
| 513 | return (0); |
|---|
| 514 | } |
|---|
| 515 | #endif |
|---|
| 516 | |
|---|
| 517 | #if defined(PNG_READ_pHYs_SUPPORTED) |
|---|
| 518 | png_uint_32 |
|---|
| 519 | png_get_pHYs(png_structp png_ptr, png_infop info_ptr, |
|---|
| 520 | png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) |
|---|
| 521 | { |
|---|
| 522 | png_uint_32 retval = 0; |
|---|
| 523 | |
|---|
| 524 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs) |
|---|
| 525 | { |
|---|
| 526 | png_debug1(1, "in %s retrieval function\n", "pHYs"); |
|---|
| 527 | if (res_x != NULL) |
|---|
| 528 | { |
|---|
| 529 | *res_x = info_ptr->x_pixels_per_unit; |
|---|
| 530 | retval |= PNG_INFO_pHYs; |
|---|
| 531 | } |
|---|
| 532 | if (res_y != NULL) |
|---|
| 533 | { |
|---|
| 534 | *res_y = info_ptr->y_pixels_per_unit; |
|---|
| 535 | retval |= PNG_INFO_pHYs; |
|---|
| 536 | } |
|---|
| 537 | if (unit_type != NULL) |
|---|
| 538 | { |
|---|
| 539 | *unit_type = (int)info_ptr->phys_unit_type; |
|---|
| 540 | retval |= PNG_INFO_pHYs; |
|---|
| 541 | } |
|---|
| 542 | } |
|---|
| 543 | return (retval); |
|---|
| 544 | } |
|---|
| 545 | #endif |
|---|
| 546 | |
|---|
| 547 | png_uint_32 |
|---|
| 548 | png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, |
|---|
| 549 | int *num_palette) |
|---|
| 550 | { |
|---|
| 551 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_PLTE && |
|---|
| 552 | palette != NULL) |
|---|
| 553 | { |
|---|
| 554 | png_debug1(1, "in %s retrieval function\n", "PLTE"); |
|---|
| 555 | *palette = info_ptr->palette; |
|---|
| 556 | *num_palette = info_ptr->num_palette; |
|---|
| 557 | png_debug1(3, "num_palette = %d\n", *num_palette); |
|---|
| 558 | return (PNG_INFO_PLTE); |
|---|
| 559 | } |
|---|
| 560 | return (0); |
|---|
| 561 | } |
|---|
| 562 | |
|---|
| 563 | #if defined(PNG_READ_sBIT_SUPPORTED) |
|---|
| 564 | png_uint_32 |
|---|
| 565 | png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) |
|---|
| 566 | { |
|---|
| 567 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT && |
|---|
| 568 | sig_bit != NULL) |
|---|
| 569 | { |
|---|
| 570 | png_debug1(1, "in %s retrieval function\n", "sBIT"); |
|---|
| 571 | *sig_bit = &(info_ptr->sig_bit); |
|---|
| 572 | return (PNG_INFO_sBIT); |
|---|
| 573 | } |
|---|
| 574 | return (0); |
|---|
| 575 | } |
|---|
| 576 | #endif |
|---|
| 577 | |
|---|
| 578 | #if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED) |
|---|
| 579 | png_uint_32 |
|---|
| 580 | png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, |
|---|
| 581 | int *num_text) |
|---|
| 582 | { |
|---|
| 583 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) |
|---|
| 584 | { |
|---|
| 585 | png_debug1(1, "in %s retrieval function\n", |
|---|
| 586 | (png_ptr->chunk_name[0] == '\0' ? "text" |
|---|
| 587 | : (png_const_charp)png_ptr->chunk_name)); |
|---|
| 588 | if (text_ptr != NULL) |
|---|
| 589 | *text_ptr = info_ptr->text; |
|---|
| 590 | if (num_text != NULL) |
|---|
| 591 | *num_text = info_ptr->num_text; |
|---|
| 592 | return ((png_uint_32)info_ptr->num_text); |
|---|
| 593 | } |
|---|
| 594 | return(0); |
|---|
| 595 | } |
|---|
| 596 | #endif |
|---|
| 597 | |
|---|
| 598 | #if defined(PNG_READ_tIME_SUPPORTED) |
|---|
| 599 | png_uint_32 |
|---|
| 600 | png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) |
|---|
| 601 | { |
|---|
| 602 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME && |
|---|
| 603 | mod_time != NULL) |
|---|
| 604 | { |
|---|
| 605 | png_debug1(1, "in %s retrieval function\n", "tIME"); |
|---|
| 606 | *mod_time = &(info_ptr->mod_time); |
|---|
| 607 | return (PNG_INFO_tIME); |
|---|
| 608 | } |
|---|
| 609 | return (0); |
|---|
| 610 | } |
|---|
| 611 | #endif |
|---|
| 612 | |
|---|
| 613 | #if defined(PNG_READ_tRNS_SUPPORTED) |
|---|
| 614 | png_uint_32 |
|---|
| 615 | png_get_tRNS(png_structp png_ptr, png_infop info_ptr, |
|---|
| 616 | png_bytep *trans, int *num_trans, png_color_16p *trans_values) |
|---|
| 617 | { |
|---|
| 618 | png_uint_32 retval = 0; |
|---|
| 619 | if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS) |
|---|
| 620 | { |
|---|
| 621 | png_debug1(1, "in %s retrieval function\n", "tRNS"); |
|---|
| 622 | if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
|---|
| 623 | { |
|---|
| 624 | if (trans != NULL) |
|---|
| 625 | { |
|---|
| 626 | *trans = info_ptr->trans; |
|---|
| 627 | retval |= PNG_INFO_tRNS; |
|---|
| 628 | } |
|---|
| 629 | if (trans_values != NULL) |
|---|
| 630 | *trans_values = &(info_ptr->trans_values); |
|---|
| 631 | } |
|---|
| 632 | else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ |
|---|
| 633 | { |
|---|
| 634 | if (trans_values != NULL) |
|---|
| 635 | { |
|---|
| 636 | *trans_values = &(info_ptr->trans_values); |
|---|
| 637 | retval |= PNG_INFO_tRNS; |
|---|
| 638 | } |
|---|
| 639 | if(trans != NULL) |
|---|
| 640 | *trans = NULL; |
|---|
| 641 | } |
|---|
| 642 | if(num_trans != NULL) |
|---|
| 643 | { |
|---|
| 644 | *num_trans = info_ptr->num_trans; |
|---|
| 645 | retval |= PNG_INFO_tRNS; |
|---|
| 646 | } |
|---|
| 647 | } |
|---|
| 648 | return (retval); |
|---|
| 649 | } |
|---|
| 650 | #endif |
|---|
| 651 | |
|---|