Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenpngget.c
Go to the documentation of this file.
00001 00002 /* pngget.c - retrieval of values from info struct 00003 * 00004 * Last changed in libpng 1.5.7 [December 15, 2011] 00005 * Copyright (c) 1998-2011 Glenn Randers-Pehrson 00006 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 00007 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 00008 * 00009 * This code is released under the libpng license. 00010 * For conditions of distribution and use, see the disclaimer 00011 * and license in png.h 00012 * 00013 */ 00014 00015 #include "pngpriv.h" 00016 00017 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 00018 00019 png_uint_32 PNGAPI 00020 png_get_valid(png_const_structp png_ptr, png_const_infop info_ptr, 00021 png_uint_32 flag) 00022 { 00023 if (png_ptr != NULL && info_ptr != NULL) 00024 return(info_ptr->valid & flag); 00025 00026 return(0); 00027 } 00028 00029 png_size_t PNGAPI 00030 png_get_rowbytes(png_const_structp png_ptr, png_const_infop info_ptr) 00031 { 00032 if (png_ptr != NULL && info_ptr != NULL) 00033 return(info_ptr->rowbytes); 00034 00035 return(0); 00036 } 00037 00038 #ifdef PNG_INFO_IMAGE_SUPPORTED 00039 png_bytepp PNGAPI 00040 png_get_rows(png_const_structp png_ptr, png_const_infop info_ptr) 00041 { 00042 if (png_ptr != NULL && info_ptr != NULL) 00043 return(info_ptr->row_pointers); 00044 00045 return(0); 00046 } 00047 #endif 00048 00049 #ifdef PNG_EASY_ACCESS_SUPPORTED 00050 /* Easy access to info, added in libpng-0.99 */ 00051 png_uint_32 PNGAPI 00052 png_get_image_width(png_const_structp png_ptr, png_const_infop info_ptr) 00053 { 00054 if (png_ptr != NULL && info_ptr != NULL) 00055 return info_ptr->width; 00056 00057 return (0); 00058 } 00059 00060 png_uint_32 PNGAPI 00061 png_get_image_height(png_const_structp png_ptr, png_const_infop info_ptr) 00062 { 00063 if (png_ptr != NULL && info_ptr != NULL) 00064 return info_ptr->height; 00065 00066 return (0); 00067 } 00068 00069 png_byte PNGAPI 00070 png_get_bit_depth(png_const_structp png_ptr, png_const_infop info_ptr) 00071 { 00072 if (png_ptr != NULL && info_ptr != NULL) 00073 return info_ptr->bit_depth; 00074 00075 return (0); 00076 } 00077 00078 png_byte PNGAPI 00079 png_get_color_type(png_const_structp png_ptr, png_const_infop info_ptr) 00080 { 00081 if (png_ptr != NULL && info_ptr != NULL) 00082 return info_ptr->color_type; 00083 00084 return (0); 00085 } 00086 00087 png_byte PNGAPI 00088 png_get_filter_type(png_const_structp png_ptr, png_const_infop info_ptr) 00089 { 00090 if (png_ptr != NULL && info_ptr != NULL) 00091 return info_ptr->filter_type; 00092 00093 return (0); 00094 } 00095 00096 png_byte PNGAPI 00097 png_get_interlace_type(png_const_structp png_ptr, png_const_infop info_ptr) 00098 { 00099 if (png_ptr != NULL && info_ptr != NULL) 00100 return info_ptr->interlace_type; 00101 00102 return (0); 00103 } 00104 00105 png_byte PNGAPI 00106 png_get_compression_type(png_const_structp png_ptr, png_const_infop info_ptr) 00107 { 00108 if (png_ptr != NULL && info_ptr != NULL) 00109 return info_ptr->compression_type; 00110 00111 return (0); 00112 } 00113 00114 png_uint_32 PNGAPI 00115 png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) 00116 { 00117 #ifdef PNG_pHYs_SUPPORTED 00118 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) 00119 { 00120 png_debug1(1, "in %s retrieval function", 00121 "png_get_x_pixels_per_meter"); 00122 00123 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) 00124 return (info_ptr->x_pixels_per_unit); 00125 } 00126 #endif 00127 00128 return (0); 00129 } 00130 00131 png_uint_32 PNGAPI 00132 png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) 00133 { 00134 #ifdef PNG_pHYs_SUPPORTED 00135 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) 00136 { 00137 png_debug1(1, "in %s retrieval function", 00138 "png_get_y_pixels_per_meter"); 00139 00140 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER) 00141 return (info_ptr->y_pixels_per_unit); 00142 } 00143 #endif 00144 00145 return (0); 00146 } 00147 00148 png_uint_32 PNGAPI 00149 png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) 00150 { 00151 #ifdef PNG_pHYs_SUPPORTED 00152 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) 00153 { 00154 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter"); 00155 00156 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER && 00157 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit) 00158 return (info_ptr->x_pixels_per_unit); 00159 } 00160 #endif 00161 00162 return (0); 00163 } 00164 00165 #ifdef PNG_FLOATING_POINT_SUPPORTED 00166 float PNGAPI 00167 png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr) 00168 { 00169 #ifdef PNG_READ_pHYs_SUPPORTED 00170 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) 00171 { 00172 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio"); 00173 00174 if (info_ptr->x_pixels_per_unit != 0) 00175 return ((float)((float)info_ptr->y_pixels_per_unit 00176 /(float)info_ptr->x_pixels_per_unit)); 00177 } 00178 #endif 00179 00180 return ((float)0.0); 00181 } 00182 #endif 00183 00184 #ifdef PNG_FIXED_POINT_SUPPORTED 00185 png_fixed_point PNGAPI 00186 png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr, 00187 png_const_infop info_ptr) 00188 { 00189 #ifdef PNG_READ_pHYs_SUPPORTED 00190 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs) 00191 && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 00192 && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX 00193 && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX) 00194 { 00195 png_fixed_point res; 00196 00197 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed"); 00198 00199 /* The following casts work because a PNG 4 byte integer only has a valid 00200 * range of 0..2^31-1; otherwise the cast might overflow. 00201 */ 00202 if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1, 00203 (png_int_32)info_ptr->x_pixels_per_unit)) 00204 return res; 00205 } 00206 #endif 00207 00208 return 0; 00209 } 00210 #endif 00211 00212 png_int_32 PNGAPI 00213 png_get_x_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) 00214 { 00215 #ifdef PNG_oFFs_SUPPORTED 00216 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) 00217 { 00218 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns"); 00219 00220 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) 00221 return (info_ptr->x_offset); 00222 } 00223 #endif 00224 00225 return (0); 00226 } 00227 00228 png_int_32 PNGAPI 00229 png_get_y_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) 00230 { 00231 #ifdef PNG_oFFs_SUPPORTED 00232 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) 00233 { 00234 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns"); 00235 00236 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER) 00237 return (info_ptr->y_offset); 00238 } 00239 #endif 00240 00241 return (0); 00242 } 00243 00244 png_int_32 PNGAPI 00245 png_get_x_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) 00246 { 00247 #ifdef PNG_oFFs_SUPPORTED 00248 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) 00249 { 00250 png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels"); 00251 00252 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) 00253 return (info_ptr->x_offset); 00254 } 00255 #endif 00256 00257 return (0); 00258 } 00259 00260 png_int_32 PNGAPI 00261 png_get_y_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) 00262 { 00263 #ifdef PNG_oFFs_SUPPORTED 00264 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) 00265 { 00266 png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels"); 00267 00268 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL) 00269 return (info_ptr->y_offset); 00270 } 00271 #endif 00272 00273 return (0); 00274 } 00275 00276 #ifdef PNG_INCH_CONVERSIONS_SUPPORTED 00277 static png_uint_32 00278 ppi_from_ppm(png_uint_32 ppm) 00279 { 00280 #if 0 00281 /* The conversion is *(2.54/100), in binary (32 digits): 00282 * .00000110100000001001110101001001 00283 */ 00284 png_uint_32 t1001, t1101; 00285 ppm >>= 1; /* .1 */ 00286 t1001 = ppm + (ppm >> 3); /* .1001 */ 00287 t1101 = t1001 + (ppm >> 1); /* .1101 */ 00288 ppm >>= 20; /* .000000000000000000001 */ 00289 t1101 += t1101 >> 15; /* .1101000000000001101 */ 00290 t1001 >>= 11; /* .000000000001001 */ 00291 t1001 += t1001 >> 12; /* .000000000001001000000001001 */ 00292 ppm += t1001; /* .000000000001001000001001001 */ 00293 ppm += t1101; /* .110100000001001110101001001 */ 00294 return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */ 00295 #else 00296 /* The argument is a PNG unsigned integer, so it is not permitted 00297 * to be bigger than 2^31. 00298 */ 00299 png_fixed_point result; 00300 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127, 00301 5000)) 00302 return result; 00303 00304 /* Overflow. */ 00305 return 0; 00306 #endif 00307 } 00308 00309 png_uint_32 PNGAPI 00310 png_get_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) 00311 { 00312 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr)); 00313 } 00314 00315 png_uint_32 PNGAPI 00316 png_get_x_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) 00317 { 00318 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr)); 00319 } 00320 00321 png_uint_32 PNGAPI 00322 png_get_y_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) 00323 { 00324 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr)); 00325 } 00326 00327 #ifdef PNG_FIXED_POINT_SUPPORTED 00328 static png_fixed_point 00329 png_fixed_inches_from_microns(png_structp png_ptr, png_int_32 microns) 00330 { 00331 /* Convert from metres * 1,000,000 to inches * 100,000, meters to 00332 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127. 00333 * Notice that this can overflow - a warning is output and 0 is 00334 * returned. 00335 */ 00336 return png_muldiv_warn(png_ptr, microns, 500, 127); 00337 } 00338 00339 png_fixed_point PNGAPI 00340 png_get_x_offset_inches_fixed(png_structp png_ptr, 00341 png_const_infop info_ptr) 00342 { 00343 return png_fixed_inches_from_microns(png_ptr, 00344 png_get_x_offset_microns(png_ptr, info_ptr)); 00345 } 00346 #endif 00347 00348 #ifdef PNG_FIXED_POINT_SUPPORTED 00349 png_fixed_point PNGAPI 00350 png_get_y_offset_inches_fixed(png_structp png_ptr, 00351 png_const_infop info_ptr) 00352 { 00353 return png_fixed_inches_from_microns(png_ptr, 00354 png_get_y_offset_microns(png_ptr, info_ptr)); 00355 } 00356 #endif 00357 00358 #ifdef PNG_FLOATING_POINT_SUPPORTED 00359 float PNGAPI 00360 png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) 00361 { 00362 /* To avoid the overflow do the conversion directly in floating 00363 * point. 00364 */ 00365 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937); 00366 } 00367 #endif 00368 00369 #ifdef PNG_FLOATING_POINT_SUPPORTED 00370 float PNGAPI 00371 png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) 00372 { 00373 /* To avoid the overflow do the conversion directly in floating 00374 * point. 00375 */ 00376 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937); 00377 } 00378 #endif 00379 00380 #ifdef PNG_pHYs_SUPPORTED 00381 png_uint_32 PNGAPI 00382 png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr, 00383 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) 00384 { 00385 png_uint_32 retval = 0; 00386 00387 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) 00388 { 00389 png_debug1(1, "in %s retrieval function", "pHYs"); 00390 00391 if (res_x != NULL) 00392 { 00393 *res_x = info_ptr->x_pixels_per_unit; 00394 retval |= PNG_INFO_pHYs; 00395 } 00396 00397 if (res_y != NULL) 00398 { 00399 *res_y = info_ptr->y_pixels_per_unit; 00400 retval |= PNG_INFO_pHYs; 00401 } 00402 00403 if (unit_type != NULL) 00404 { 00405 *unit_type = (int)info_ptr->phys_unit_type; 00406 retval |= PNG_INFO_pHYs; 00407 00408 if (*unit_type == 1) 00409 { 00410 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50); 00411 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50); 00412 } 00413 } 00414 } 00415 00416 return (retval); 00417 } 00418 #endif /* PNG_pHYs_SUPPORTED */ 00419 #endif /* PNG_INCH_CONVERSIONS_SUPPORTED */ 00420 00421 /* png_get_channels really belongs in here, too, but it's been around longer */ 00422 00423 #endif /* PNG_EASY_ACCESS_SUPPORTED */ 00424 00425 png_byte PNGAPI 00426 png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr) 00427 { 00428 if (png_ptr != NULL && info_ptr != NULL) 00429 return(info_ptr->channels); 00430 00431 return (0); 00432 } 00433 00434 png_const_bytep PNGAPI 00435 png_get_signature(png_const_structp png_ptr, png_infop info_ptr) 00436 { 00437 if (png_ptr != NULL && info_ptr != NULL) 00438 return(info_ptr->signature); 00439 00440 return (NULL); 00441 } 00442 00443 #ifdef PNG_bKGD_SUPPORTED 00444 png_uint_32 PNGAPI 00445 png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr, 00446 png_color_16p *background) 00447 { 00448 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) 00449 && background != NULL) 00450 { 00451 png_debug1(1, "in %s retrieval function", "bKGD"); 00452 00453 *background = &(info_ptr->background); 00454 return (PNG_INFO_bKGD); 00455 } 00456 00457 return (0); 00458 } 00459 #endif 00460 00461 #ifdef PNG_cHRM_SUPPORTED 00462 /* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the 00463 * same time to correct the rgb grayscale coefficient defaults obtained from the 00464 * cHRM chunk in 1.5.4 00465 */ 00466 png_uint_32 PNGFAPI 00467 png_get_cHRM_XYZ_fixed(png_structp png_ptr, png_const_infop info_ptr, 00468 png_fixed_point *int_red_X, png_fixed_point *int_red_Y, 00469 png_fixed_point *int_red_Z, png_fixed_point *int_green_X, 00470 png_fixed_point *int_green_Y, png_fixed_point *int_green_Z, 00471 png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y, 00472 png_fixed_point *int_blue_Z) 00473 { 00474 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) 00475 { 00476 png_xy xy; 00477 png_XYZ XYZ; 00478 00479 png_debug1(1, "in %s retrieval function", "cHRM_XYZ"); 00480 00481 xy.whitex = info_ptr->x_white; 00482 xy.whitey = info_ptr->y_white; 00483 xy.redx = info_ptr->x_red; 00484 xy.redy = info_ptr->y_red; 00485 xy.greenx = info_ptr->x_green; 00486 xy.greeny = info_ptr->y_green; 00487 xy.bluex = info_ptr->x_blue; 00488 xy.bluey = info_ptr->y_blue; 00489 00490 /* The *_checked function handles error reporting, so just return 0 if 00491 * there is a failure here. 00492 */ 00493 if (png_XYZ_from_xy_checked(png_ptr, &XYZ, xy)) 00494 { 00495 if (int_red_X != NULL) 00496 *int_red_X = XYZ.redX; 00497 if (int_red_Y != NULL) 00498 *int_red_Y = XYZ.redY; 00499 if (int_red_Z != NULL) 00500 *int_red_Z = XYZ.redZ; 00501 if (int_green_X != NULL) 00502 *int_green_X = XYZ.greenX; 00503 if (int_green_Y != NULL) 00504 *int_green_Y = XYZ.greenY; 00505 if (int_green_Z != NULL) 00506 *int_green_Z = XYZ.greenZ; 00507 if (int_blue_X != NULL) 00508 *int_blue_X = XYZ.blueX; 00509 if (int_blue_Y != NULL) 00510 *int_blue_Y = XYZ.blueY; 00511 if (int_blue_Z != NULL) 00512 *int_blue_Z = XYZ.blueZ; 00513 00514 return (PNG_INFO_cHRM); 00515 } 00516 } 00517 00518 return (0); 00519 } 00520 00521 # ifdef PNG_FLOATING_POINT_SUPPORTED 00522 png_uint_32 PNGAPI 00523 png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr, 00524 double *white_x, double *white_y, double *red_x, double *red_y, 00525 double *green_x, double *green_y, double *blue_x, double *blue_y) 00526 { 00527 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) 00528 { 00529 png_debug1(1, "in %s retrieval function", "cHRM"); 00530 00531 if (white_x != NULL) 00532 *white_x = png_float(png_ptr, info_ptr->x_white, "cHRM white X"); 00533 if (white_y != NULL) 00534 *white_y = png_float(png_ptr, info_ptr->y_white, "cHRM white Y"); 00535 if (red_x != NULL) 00536 *red_x = png_float(png_ptr, info_ptr->x_red, "cHRM red X"); 00537 if (red_y != NULL) 00538 *red_y = png_float(png_ptr, info_ptr->y_red, "cHRM red Y"); 00539 if (green_x != NULL) 00540 *green_x = png_float(png_ptr, info_ptr->x_green, "cHRM green X"); 00541 if (green_y != NULL) 00542 *green_y = png_float(png_ptr, info_ptr->y_green, "cHRM green Y"); 00543 if (blue_x != NULL) 00544 *blue_x = png_float(png_ptr, info_ptr->x_blue, "cHRM blue X"); 00545 if (blue_y != NULL) 00546 *blue_y = png_float(png_ptr, info_ptr->y_blue, "cHRM blue Y"); 00547 return (PNG_INFO_cHRM); 00548 } 00549 00550 return (0); 00551 } 00552 00553 png_uint_32 PNGAPI 00554 png_get_cHRM_XYZ(png_structp png_ptr, png_const_infop info_ptr, 00555 double *red_X, double *red_Y, double *red_Z, double *green_X, 00556 double *green_Y, double *green_Z, double *blue_X, double *blue_Y, 00557 double *blue_Z) 00558 { 00559 png_XYZ XYZ; 00560 00561 if (png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, 00562 &XYZ.redX, &XYZ.redY, &XYZ.redZ, &XYZ.greenX, &XYZ.greenY, &XYZ.greenZ, 00563 &XYZ.blueX, &XYZ.blueY, &XYZ.blueZ) & PNG_INFO_cHRM) 00564 { 00565 if (red_X != NULL) 00566 *red_X = png_float(png_ptr, XYZ.redX, "cHRM red X"); 00567 if (red_Y != NULL) 00568 *red_Y = png_float(png_ptr, XYZ.redY, "cHRM red Y"); 00569 if (red_Z != NULL) 00570 *red_Z = png_float(png_ptr, XYZ.redZ, "cHRM red Z"); 00571 if (green_X != NULL) 00572 *green_X = png_float(png_ptr, XYZ.greenX, "cHRM green X"); 00573 if (green_Y != NULL) 00574 *green_Y = png_float(png_ptr, XYZ.greenY, "cHRM green Y"); 00575 if (green_Z != NULL) 00576 *green_Z = png_float(png_ptr, XYZ.greenZ, "cHRM green Z"); 00577 if (blue_X != NULL) 00578 *blue_X = png_float(png_ptr, XYZ.blueX, "cHRM blue X"); 00579 if (blue_Y != NULL) 00580 *blue_Y = png_float(png_ptr, XYZ.blueY, "cHRM blue Y"); 00581 if (blue_Z != NULL) 00582 *blue_Z = png_float(png_ptr, XYZ.blueZ, "cHRM blue Z"); 00583 return (PNG_INFO_cHRM); 00584 } 00585 00586 return (0); 00587 } 00588 # endif 00589 00590 # ifdef PNG_FIXED_POINT_SUPPORTED 00591 png_uint_32 PNGAPI 00592 png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr, 00593 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, 00594 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, 00595 png_fixed_point *blue_x, png_fixed_point *blue_y) 00596 { 00597 png_debug1(1, "in %s retrieval function", "cHRM"); 00598 00599 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) 00600 { 00601 if (white_x != NULL) 00602 *white_x = info_ptr->x_white; 00603 if (white_y != NULL) 00604 *white_y = info_ptr->y_white; 00605 if (red_x != NULL) 00606 *red_x = info_ptr->x_red; 00607 if (red_y != NULL) 00608 *red_y = info_ptr->y_red; 00609 if (green_x != NULL) 00610 *green_x = info_ptr->x_green; 00611 if (green_y != NULL) 00612 *green_y = info_ptr->y_green; 00613 if (blue_x != NULL) 00614 *blue_x = info_ptr->x_blue; 00615 if (blue_y != NULL) 00616 *blue_y = info_ptr->y_blue; 00617 return (PNG_INFO_cHRM); 00618 } 00619 00620 return (0); 00621 } 00622 # endif 00623 #endif 00624 00625 #ifdef PNG_gAMA_SUPPORTED 00626 png_uint_32 PNGFAPI 00627 png_get_gAMA_fixed(png_const_structp png_ptr, png_const_infop info_ptr, 00628 png_fixed_point *file_gamma) 00629 { 00630 png_debug1(1, "in %s retrieval function", "gAMA"); 00631 00632 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) 00633 && file_gamma != NULL) 00634 { 00635 *file_gamma = info_ptr->gamma; 00636 return (PNG_INFO_gAMA); 00637 } 00638 00639 return (0); 00640 } 00641 # ifdef PNG_FLOATING_POINT_SUPPORTED 00642 png_uint_32 PNGAPI 00643 png_get_gAMA(png_const_structp png_ptr, png_const_infop info_ptr, 00644 double *file_gamma) 00645 { 00646 png_fixed_point igamma; 00647 png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma); 00648 00649 if (ok) 00650 *file_gamma = png_float(png_ptr, igamma, "png_get_gAMA"); 00651 00652 return ok; 00653 } 00654 00655 # endif 00656 #endif 00657 00658 #ifdef PNG_sRGB_SUPPORTED 00659 png_uint_32 PNGAPI 00660 png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr, 00661 int *file_srgb_intent) 00662 { 00663 png_debug1(1, "in %s retrieval function", "sRGB"); 00664 00665 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) 00666 && file_srgb_intent != NULL) 00667 { 00668 *file_srgb_intent = (int)info_ptr->srgb_intent; 00669 return (PNG_INFO_sRGB); 00670 } 00671 00672 return (0); 00673 } 00674 #endif 00675 00676 #ifdef PNG_iCCP_SUPPORTED 00677 png_uint_32 PNGAPI 00678 png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr, 00679 png_charpp name, int *compression_type, 00680 png_bytepp profile, png_uint_32 *proflen) 00681 { 00682 png_debug1(1, "in %s retrieval function", "iCCP"); 00683 00684 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) 00685 && name != NULL && compression_type != NULL && profile != NULL && 00686 proflen != NULL) 00687 { 00688 *name = info_ptr->iccp_name; 00689 *profile = info_ptr->iccp_profile; 00690 /* Compression_type is a dummy so the API won't have to change 00691 * if we introduce multiple compression types later. 00692 */ 00693 *proflen = info_ptr->iccp_proflen; 00694 *compression_type = info_ptr->iccp_compression; 00695 return (PNG_INFO_iCCP); 00696 } 00697 00698 return (0); 00699 } 00700 #endif 00701 00702 #ifdef PNG_sPLT_SUPPORTED 00703 png_uint_32 PNGAPI 00704 png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr, 00705 png_sPLT_tpp spalettes) 00706 { 00707 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) 00708 { 00709 *spalettes = info_ptr->splt_palettes; 00710 return ((png_uint_32)info_ptr->splt_palettes_num); 00711 } 00712 00713 return (0); 00714 } 00715 #endif 00716 00717 #ifdef PNG_hIST_SUPPORTED 00718 png_uint_32 PNGAPI 00719 png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr, 00720 png_uint_16p *hist) 00721 { 00722 png_debug1(1, "in %s retrieval function", "hIST"); 00723 00724 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) 00725 && hist != NULL) 00726 { 00727 *hist = info_ptr->hist; 00728 return (PNG_INFO_hIST); 00729 } 00730 00731 return (0); 00732 } 00733 #endif 00734 00735 png_uint_32 PNGAPI 00736 png_get_IHDR(png_structp png_ptr, png_infop info_ptr, 00737 png_uint_32 *width, png_uint_32 *height, int *bit_depth, 00738 int *color_type, int *interlace_type, int *compression_type, 00739 int *filter_type) 00740 00741 { 00742 png_debug1(1, "in %s retrieval function", "IHDR"); 00743 00744 if (png_ptr == NULL || info_ptr == NULL || width == NULL || 00745 height == NULL || bit_depth == NULL || color_type == NULL) 00746 return (0); 00747 00748 *width = info_ptr->width; 00749 *height = info_ptr->height; 00750 *bit_depth = info_ptr->bit_depth; 00751 *color_type = info_ptr->color_type; 00752 00753 if (compression_type != NULL) 00754 *compression_type = info_ptr->compression_type; 00755 00756 if (filter_type != NULL) 00757 *filter_type = info_ptr->filter_type; 00758 00759 if (interlace_type != NULL) 00760 *interlace_type = info_ptr->interlace_type; 00761 00762 /* This is redundant if we can be sure that the info_ptr values were all 00763 * assigned in png_set_IHDR(). We do the check anyhow in case an 00764 * application has ignored our advice not to mess with the members 00765 * of info_ptr directly. 00766 */ 00767 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, 00768 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, 00769 info_ptr->compression_type, info_ptr->filter_type); 00770 00771 return (1); 00772 } 00773 00774 #ifdef PNG_oFFs_SUPPORTED 00775 png_uint_32 PNGAPI 00776 png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr, 00777 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) 00778 { 00779 png_debug1(1, "in %s retrieval function", "oFFs"); 00780 00781 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) 00782 && offset_x != NULL && offset_y != NULL && unit_type != NULL) 00783 { 00784 *offset_x = info_ptr->x_offset; 00785 *offset_y = info_ptr->y_offset; 00786 *unit_type = (int)info_ptr->offset_unit_type; 00787 return (PNG_INFO_oFFs); 00788 } 00789 00790 return (0); 00791 } 00792 #endif 00793 00794 #ifdef PNG_pCAL_SUPPORTED 00795 png_uint_32 PNGAPI 00796 png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr, 00797 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, 00798 png_charp *units, png_charpp *params) 00799 { 00800 png_debug1(1, "in %s retrieval function", "pCAL"); 00801 00802 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) 00803 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && 00804 nparams != NULL && units != NULL && params != NULL) 00805 { 00806 *purpose = info_ptr->pcal_purpose; 00807 *X0 = info_ptr->pcal_X0; 00808 *X1 = info_ptr->pcal_X1; 00809 *type = (int)info_ptr->pcal_type; 00810 *nparams = (int)info_ptr->pcal_nparams; 00811 *units = info_ptr->pcal_units; 00812 *params = info_ptr->pcal_params; 00813 return (PNG_INFO_pCAL); 00814 } 00815 00816 return (0); 00817 } 00818 #endif 00819 00820 #ifdef PNG_sCAL_SUPPORTED 00821 # ifdef PNG_FIXED_POINT_SUPPORTED 00822 # ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED 00823 png_uint_32 PNGAPI 00824 png_get_sCAL_fixed(png_structp png_ptr, png_const_infop info_ptr, 00825 int *unit, png_fixed_point *width, png_fixed_point *height) 00826 { 00827 if (png_ptr != NULL && info_ptr != NULL && 00828 (info_ptr->valid & PNG_INFO_sCAL)) 00829 { 00830 *unit = info_ptr->scal_unit; 00831 /*TODO: make this work without FP support */ 00832 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width"); 00833 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height), 00834 "sCAL height"); 00835 return (PNG_INFO_sCAL); 00836 } 00837 00838 return(0); 00839 } 00840 # endif /* FLOATING_ARITHMETIC */ 00841 # endif /* FIXED_POINT */ 00842 # ifdef PNG_FLOATING_POINT_SUPPORTED 00843 png_uint_32 PNGAPI 00844 png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr, 00845 int *unit, double *width, double *height) 00846 { 00847 if (png_ptr != NULL && info_ptr != NULL && 00848 (info_ptr->valid & PNG_INFO_sCAL)) 00849 { 00850 *unit = info_ptr->scal_unit; 00851 *width = atof(info_ptr->scal_s_width); 00852 *height = atof(info_ptr->scal_s_height); 00853 return (PNG_INFO_sCAL); 00854 } 00855 00856 return(0); 00857 } 00858 # endif /* FLOATING POINT */ 00859 png_uint_32 PNGAPI 00860 png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr, 00861 int *unit, png_charpp width, png_charpp height) 00862 { 00863 if (png_ptr != NULL && info_ptr != NULL && 00864 (info_ptr->valid & PNG_INFO_sCAL)) 00865 { 00866 *unit = info_ptr->scal_unit; 00867 *width = info_ptr->scal_s_width; 00868 *height = info_ptr->scal_s_height; 00869 return (PNG_INFO_sCAL); 00870 } 00871 00872 return(0); 00873 } 00874 #endif /* sCAL */ 00875 00876 #ifdef PNG_pHYs_SUPPORTED 00877 png_uint_32 PNGAPI 00878 png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr, 00879 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) 00880 { 00881 png_uint_32 retval = 0; 00882 00883 png_debug1(1, "in %s retrieval function", "pHYs"); 00884 00885 if (png_ptr != NULL && info_ptr != NULL && 00886 (info_ptr->valid & PNG_INFO_pHYs)) 00887 { 00888 if (res_x != NULL) 00889 { 00890 *res_x = info_ptr->x_pixels_per_unit; 00891 retval |= PNG_INFO_pHYs; 00892 } 00893 00894 if (res_y != NULL) 00895 { 00896 *res_y = info_ptr->y_pixels_per_unit; 00897 retval |= PNG_INFO_pHYs; 00898 } 00899 00900 if (unit_type != NULL) 00901 { 00902 *unit_type = (int)info_ptr->phys_unit_type; 00903 retval |= PNG_INFO_pHYs; 00904 } 00905 } 00906 00907 return (retval); 00908 } 00909 #endif /* pHYs */ 00910 00911 png_uint_32 PNGAPI 00912 png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr, 00913 png_colorp *palette, int *num_palette) 00914 { 00915 png_debug1(1, "in %s retrieval function", "PLTE"); 00916 00917 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) 00918 && palette != NULL) 00919 { 00920 *palette = info_ptr->palette; 00921 *num_palette = info_ptr->num_palette; 00922 png_debug1(3, "num_palette = %d", *num_palette); 00923 return (PNG_INFO_PLTE); 00924 } 00925 00926 return (0); 00927 } 00928 00929 #ifdef PNG_sBIT_SUPPORTED 00930 png_uint_32 PNGAPI 00931 png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr, 00932 png_color_8p *sig_bit) 00933 { 00934 png_debug1(1, "in %s retrieval function", "sBIT"); 00935 00936 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) 00937 && sig_bit != NULL) 00938 { 00939 *sig_bit = &(info_ptr->sig_bit); 00940 return (PNG_INFO_sBIT); 00941 } 00942 00943 return (0); 00944 } 00945 #endif 00946 00947 #ifdef PNG_TEXT_SUPPORTED 00948 png_uint_32 PNGAPI 00949 png_get_text(png_const_structp png_ptr, png_const_infop info_ptr, 00950 png_textp *text_ptr, int *num_text) 00951 { 00952 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) 00953 { 00954 png_debug1(1, "in 0x%lx retrieval function", 00955 (unsigned long)png_ptr->chunk_name); 00956 00957 if (text_ptr != NULL) 00958 *text_ptr = info_ptr->text; 00959 00960 if (num_text != NULL) 00961 *num_text = info_ptr->num_text; 00962 00963 return ((png_uint_32)info_ptr->num_text); 00964 } 00965 00966 if (num_text != NULL) 00967 *num_text = 0; 00968 00969 return(0); 00970 } 00971 #endif 00972 00973 #ifdef PNG_tIME_SUPPORTED 00974 png_uint_32 PNGAPI 00975 png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time) 00976 { 00977 png_debug1(1, "in %s retrieval function", "tIME"); 00978 00979 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) 00980 && mod_time != NULL) 00981 { 00982 *mod_time = &(info_ptr->mod_time); 00983 return (PNG_INFO_tIME); 00984 } 00985 00986 return (0); 00987 } 00988 #endif 00989 00990 #ifdef PNG_tRNS_SUPPORTED 00991 png_uint_32 PNGAPI 00992 png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr, 00993 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) 00994 { 00995 png_uint_32 retval = 0; 00996 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) 00997 { 00998 png_debug1(1, "in %s retrieval function", "tRNS"); 00999 01000 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 01001 { 01002 if (trans_alpha != NULL) 01003 { 01004 *trans_alpha = info_ptr->trans_alpha; 01005 retval |= PNG_INFO_tRNS; 01006 } 01007 01008 if (trans_color != NULL) 01009 *trans_color = &(info_ptr->trans_color); 01010 } 01011 01012 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */ 01013 { 01014 if (trans_color != NULL) 01015 { 01016 *trans_color = &(info_ptr->trans_color); 01017 retval |= PNG_INFO_tRNS; 01018 } 01019 01020 if (trans_alpha != NULL) 01021 *trans_alpha = NULL; 01022 } 01023 01024 if (num_trans != NULL) 01025 { 01026 *num_trans = info_ptr->num_trans; 01027 retval |= PNG_INFO_tRNS; 01028 } 01029 } 01030 01031 return (retval); 01032 } 01033 #endif 01034 01035 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED 01036 int PNGAPI 01037 png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr, 01038 png_unknown_chunkpp unknowns) 01039 { 01040 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) 01041 { 01042 *unknowns = info_ptr->unknown_chunks; 01043 return info_ptr->unknown_chunks_num; 01044 } 01045 01046 return (0); 01047 } 01048 #endif 01049 01050 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED 01051 png_byte PNGAPI 01052 png_get_rgb_to_gray_status (png_const_structp png_ptr) 01053 { 01054 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0); 01055 } 01056 #endif 01057 01058 #ifdef PNG_USER_CHUNKS_SUPPORTED 01059 png_voidp PNGAPI 01060 png_get_user_chunk_ptr(png_const_structp png_ptr) 01061 { 01062 return (png_ptr ? png_ptr->user_chunk_ptr : NULL); 01063 } 01064 #endif 01065 01066 png_size_t PNGAPI 01067 png_get_compression_buffer_size(png_const_structp png_ptr) 01068 { 01069 return (png_ptr ? png_ptr->zbuf_size : 0); 01070 } 01071 01072 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 01073 /* These functions were added to libpng 1.2.6 and were enabled 01074 * by default in libpng-1.4.0 */ 01075 png_uint_32 PNGAPI 01076 png_get_user_width_max (png_const_structp png_ptr) 01077 { 01078 return (png_ptr ? png_ptr->user_width_max : 0); 01079 } 01080 01081 png_uint_32 PNGAPI 01082 png_get_user_height_max (png_const_structp png_ptr) 01083 { 01084 return (png_ptr ? png_ptr->user_height_max : 0); 01085 } 01086 01087 /* This function was added to libpng 1.4.0 */ 01088 png_uint_32 PNGAPI 01089 png_get_chunk_cache_max (png_const_structp png_ptr) 01090 { 01091 return (png_ptr ? png_ptr->user_chunk_cache_max : 0); 01092 } 01093 01094 /* This function was added to libpng 1.4.1 */ 01095 png_alloc_size_t PNGAPI 01096 png_get_chunk_malloc_max (png_const_structp png_ptr) 01097 { 01098 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0); 01099 } 01100 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ 01101 01102 /* These functions were added to libpng 1.4.0 */ 01103 #ifdef PNG_IO_STATE_SUPPORTED 01104 png_uint_32 PNGAPI 01105 png_get_io_state (png_structp png_ptr) 01106 { 01107 return png_ptr->io_state; 01108 } 01109 01110 png_uint_32 PNGAPI 01111 png_get_io_chunk_type (png_const_structp png_ptr) 01112 { 01113 return png_ptr->chunk_name; 01114 } 01115 01116 png_const_bytep PNGAPI 01117 png_get_io_chunk_name (png_structp png_ptr) 01118 { 01119 PNG_CSTRING_FROM_CHUNK(png_ptr->io_chunk_string, png_ptr->chunk_name); 01120 return png_ptr->io_chunk_string; 01121 } 01122 #endif /* ?PNG_IO_STATE_SUPPORTED */ 01123 01124 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ Generated on Sat May 26 2012 04:18:16 for ReactOS by
1.7.6.1
|