/thirdparty/libpng/pngget.c

http://crashrpt.googlecode.com/ · C · 934 lines · 842 code · 69 blank · 23 comment · 361 complexity · 1fd7b1178a895edb84e1a3d4016428e4 MD5 · raw file

  1. /* pngget.c - retrieval of values from info struct
  2. *
  3. * libpng 1.2.7 - September 12, 2004
  4. * For conditions of distribution and use, see copyright notice in png.h
  5. * Copyright (c) 1998-2004 Glenn Randers-Pehrson
  6. * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  7. * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  8. */
  9. #define PNG_INTERNAL
  10. #include "png.h"
  11. png_uint_32 PNGAPI
  12. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  13. {
  14. if (png_ptr != NULL && info_ptr != NULL)
  15. return(info_ptr->valid & flag);
  16. else
  17. return(0);
  18. }
  19. png_uint_32 PNGAPI
  20. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  21. {
  22. if (png_ptr != NULL && info_ptr != NULL)
  23. return(info_ptr->rowbytes);
  24. else
  25. return(0);
  26. }
  27. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  28. png_bytepp PNGAPI
  29. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  30. {
  31. if (png_ptr != NULL && info_ptr != NULL)
  32. return(info_ptr->row_pointers);
  33. else
  34. return(0);
  35. }
  36. #endif
  37. #ifdef PNG_EASY_ACCESS_SUPPORTED
  38. /* easy access to info, added in libpng-0.99 */
  39. png_uint_32 PNGAPI
  40. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  41. {
  42. if (png_ptr != NULL && info_ptr != NULL)
  43. {
  44. return info_ptr->width;
  45. }
  46. return (0);
  47. }
  48. png_uint_32 PNGAPI
  49. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  50. {
  51. if (png_ptr != NULL && info_ptr != NULL)
  52. {
  53. return info_ptr->height;
  54. }
  55. return (0);
  56. }
  57. png_byte PNGAPI
  58. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  59. {
  60. if (png_ptr != NULL && info_ptr != NULL)
  61. {
  62. return info_ptr->bit_depth;
  63. }
  64. return (0);
  65. }
  66. png_byte PNGAPI
  67. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  68. {
  69. if (png_ptr != NULL && info_ptr != NULL)
  70. {
  71. return info_ptr->color_type;
  72. }
  73. return (0);
  74. }
  75. png_byte PNGAPI
  76. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  77. {
  78. if (png_ptr != NULL && info_ptr != NULL)
  79. {
  80. return info_ptr->filter_type;
  81. }
  82. return (0);
  83. }
  84. png_byte PNGAPI
  85. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  86. {
  87. if (png_ptr != NULL && info_ptr != NULL)
  88. {
  89. return info_ptr->interlace_type;
  90. }
  91. return (0);
  92. }
  93. png_byte PNGAPI
  94. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  95. {
  96. if (png_ptr != NULL && info_ptr != NULL)
  97. {
  98. return info_ptr->compression_type;
  99. }
  100. return (0);
  101. }
  102. png_uint_32 PNGAPI
  103. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  104. {
  105. if (png_ptr != NULL && info_ptr != NULL)
  106. #if defined(PNG_pHYs_SUPPORTED)
  107. if (info_ptr->valid & PNG_INFO_pHYs)
  108. {
  109. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  110. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  111. return (0);
  112. else return (info_ptr->x_pixels_per_unit);
  113. }
  114. #else
  115. return (0);
  116. #endif
  117. return (0);
  118. }
  119. png_uint_32 PNGAPI
  120. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  121. {
  122. if (png_ptr != NULL && info_ptr != NULL)
  123. #if defined(PNG_pHYs_SUPPORTED)
  124. if (info_ptr->valid & PNG_INFO_pHYs)
  125. {
  126. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  127. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  128. return (0);
  129. else return (info_ptr->y_pixels_per_unit);
  130. }
  131. #else
  132. return (0);
  133. #endif
  134. return (0);
  135. }
  136. png_uint_32 PNGAPI
  137. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  138. {
  139. if (png_ptr != NULL && info_ptr != NULL)
  140. #if defined(PNG_pHYs_SUPPORTED)
  141. if (info_ptr->valid & PNG_INFO_pHYs)
  142. {
  143. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  144. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  145. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  146. return (0);
  147. else return (info_ptr->x_pixels_per_unit);
  148. }
  149. #else
  150. return (0);
  151. #endif
  152. return (0);
  153. }
  154. #ifdef PNG_FLOATING_POINT_SUPPORTED
  155. float PNGAPI
  156. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  157. {
  158. if (png_ptr != NULL && info_ptr != NULL)
  159. #if defined(PNG_pHYs_SUPPORTED)
  160. if (info_ptr->valid & PNG_INFO_pHYs)
  161. {
  162. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163. if (info_ptr->x_pixels_per_unit == 0)
  164. return ((float)0.0);
  165. else
  166. return ((float)((float)info_ptr->y_pixels_per_unit
  167. /(float)info_ptr->x_pixels_per_unit));
  168. }
  169. #else
  170. return (0.0);
  171. #endif
  172. return ((float)0.0);
  173. }
  174. #endif
  175. png_int_32 PNGAPI
  176. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  177. {
  178. if (png_ptr != NULL && info_ptr != NULL)
  179. #if defined(PNG_oFFs_SUPPORTED)
  180. if (info_ptr->valid & PNG_INFO_oFFs)
  181. {
  182. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  183. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  184. return (0);
  185. else return (info_ptr->x_offset);
  186. }
  187. #else
  188. return (0);
  189. #endif
  190. return (0);
  191. }
  192. png_int_32 PNGAPI
  193. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  194. {
  195. if (png_ptr != NULL && info_ptr != NULL)
  196. #if defined(PNG_oFFs_SUPPORTED)
  197. if (info_ptr->valid & PNG_INFO_oFFs)
  198. {
  199. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  200. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  201. return (0);
  202. else return (info_ptr->y_offset);
  203. }
  204. #else
  205. return (0);
  206. #endif
  207. return (0);
  208. }
  209. png_int_32 PNGAPI
  210. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  211. {
  212. if (png_ptr != NULL && info_ptr != NULL)
  213. #if defined(PNG_oFFs_SUPPORTED)
  214. if (info_ptr->valid & PNG_INFO_oFFs)
  215. {
  216. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  217. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  218. return (0);
  219. else return (info_ptr->x_offset);
  220. }
  221. #else
  222. return (0);
  223. #endif
  224. return (0);
  225. }
  226. png_int_32 PNGAPI
  227. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  228. {
  229. if (png_ptr != NULL && info_ptr != NULL)
  230. #if defined(PNG_oFFs_SUPPORTED)
  231. if (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. return (0);
  240. #endif
  241. return (0);
  242. }
  243. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  244. png_uint_32 PNGAPI
  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. *.0254 +.5));
  249. }
  250. png_uint_32 PNGAPI
  251. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  252. {
  253. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  254. *.0254 +.5));
  255. }
  256. png_uint_32 PNGAPI
  257. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  258. {
  259. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  260. *.0254 +.5));
  261. }
  262. float PNGAPI
  263. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  264. {
  265. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  266. *.00003937);
  267. }
  268. float PNGAPI
  269. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  270. {
  271. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  272. *.00003937);
  273. }
  274. #if defined(PNG_pHYs_SUPPORTED)
  275. png_uint_32 PNGAPI
  276. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  277. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  278. {
  279. png_uint_32 retval = 0;
  280. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  281. {
  282. png_debug1(1, "in %s retrieval function\n", "pHYs");
  283. if (res_x != NULL)
  284. {
  285. *res_x = info_ptr->x_pixels_per_unit;
  286. retval |= PNG_INFO_pHYs;
  287. }
  288. if (res_y != NULL)
  289. {
  290. *res_y = info_ptr->y_pixels_per_unit;
  291. retval |= PNG_INFO_pHYs;
  292. }
  293. if (unit_type != NULL)
  294. {
  295. *unit_type = (int)info_ptr->phys_unit_type;
  296. retval |= PNG_INFO_pHYs;
  297. if(*unit_type == 1)
  298. {
  299. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  300. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  301. }
  302. }
  303. }
  304. return (retval);
  305. }
  306. #endif /* PNG_pHYs_SUPPORTED */
  307. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  308. /* png_get_channels really belongs in here, too, but it's been around longer */
  309. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  310. png_byte PNGAPI
  311. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  312. {
  313. if (png_ptr != NULL && info_ptr != NULL)
  314. return(info_ptr->channels);
  315. else
  316. return (0);
  317. }
  318. png_bytep PNGAPI
  319. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  320. {
  321. if (png_ptr != NULL && info_ptr != NULL)
  322. return(info_ptr->signature);
  323. else
  324. return (NULL);
  325. }
  326. #if defined(PNG_bKGD_SUPPORTED)
  327. png_uint_32 PNGAPI
  328. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  329. png_color_16p *background)
  330. {
  331. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  332. && background != NULL)
  333. {
  334. png_debug1(1, "in %s retrieval function\n", "bKGD");
  335. *background = &(info_ptr->background);
  336. return (PNG_INFO_bKGD);
  337. }
  338. return (0);
  339. }
  340. #endif
  341. #if defined(PNG_cHRM_SUPPORTED)
  342. #ifdef PNG_FLOATING_POINT_SUPPORTED
  343. png_uint_32 PNGAPI
  344. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  345. double *white_x, double *white_y, double *red_x, double *red_y,
  346. double *green_x, double *green_y, double *blue_x, double *blue_y)
  347. {
  348. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  349. {
  350. png_debug1(1, "in %s retrieval function\n", "cHRM");
  351. if (white_x != NULL)
  352. *white_x = (double)info_ptr->x_white;
  353. if (white_y != NULL)
  354. *white_y = (double)info_ptr->y_white;
  355. if (red_x != NULL)
  356. *red_x = (double)info_ptr->x_red;
  357. if (red_y != NULL)
  358. *red_y = (double)info_ptr->y_red;
  359. if (green_x != NULL)
  360. *green_x = (double)info_ptr->x_green;
  361. if (green_y != NULL)
  362. *green_y = (double)info_ptr->y_green;
  363. if (blue_x != NULL)
  364. *blue_x = (double)info_ptr->x_blue;
  365. if (blue_y != NULL)
  366. *blue_y = (double)info_ptr->y_blue;
  367. return (PNG_INFO_cHRM);
  368. }
  369. return (0);
  370. }
  371. #endif
  372. #ifdef PNG_FIXED_POINT_SUPPORTED
  373. png_uint_32 PNGAPI
  374. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  375. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  376. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  377. png_fixed_point *blue_x, png_fixed_point *blue_y)
  378. {
  379. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  380. {
  381. png_debug1(1, "in %s retrieval function\n", "cHRM");
  382. if (white_x != NULL)
  383. *white_x = info_ptr->int_x_white;
  384. if (white_y != NULL)
  385. *white_y = info_ptr->int_y_white;
  386. if (red_x != NULL)
  387. *red_x = info_ptr->int_x_red;
  388. if (red_y != NULL)
  389. *red_y = info_ptr->int_y_red;
  390. if (green_x != NULL)
  391. *green_x = info_ptr->int_x_green;
  392. if (green_y != NULL)
  393. *green_y = info_ptr->int_y_green;
  394. if (blue_x != NULL)
  395. *blue_x = info_ptr->int_x_blue;
  396. if (blue_y != NULL)
  397. *blue_y = info_ptr->int_y_blue;
  398. return (PNG_INFO_cHRM);
  399. }
  400. return (0);
  401. }
  402. #endif
  403. #endif
  404. #if defined(PNG_gAMA_SUPPORTED)
  405. #ifdef PNG_FLOATING_POINT_SUPPORTED
  406. png_uint_32 PNGAPI
  407. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  408. {
  409. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  410. && file_gamma != NULL)
  411. {
  412. png_debug1(1, "in %s retrieval function\n", "gAMA");
  413. *file_gamma = (double)info_ptr->gamma;
  414. return (PNG_INFO_gAMA);
  415. }
  416. return (0);
  417. }
  418. #endif
  419. #ifdef PNG_FIXED_POINT_SUPPORTED
  420. png_uint_32 PNGAPI
  421. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  422. png_fixed_point *int_file_gamma)
  423. {
  424. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  425. && int_file_gamma != NULL)
  426. {
  427. png_debug1(1, "in %s retrieval function\n", "gAMA");
  428. *int_file_gamma = info_ptr->int_gamma;
  429. return (PNG_INFO_gAMA);
  430. }
  431. return (0);
  432. }
  433. #endif
  434. #endif
  435. #if defined(PNG_sRGB_SUPPORTED)
  436. png_uint_32 PNGAPI
  437. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  438. {
  439. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  440. && file_srgb_intent != NULL)
  441. {
  442. png_debug1(1, "in %s retrieval function\n", "sRGB");
  443. *file_srgb_intent = (int)info_ptr->srgb_intent;
  444. return (PNG_INFO_sRGB);
  445. }
  446. return (0);
  447. }
  448. #endif
  449. #if defined(PNG_iCCP_SUPPORTED)
  450. png_uint_32 PNGAPI
  451. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  452. png_charpp name, int *compression_type,
  453. png_charpp profile, png_uint_32 *proflen)
  454. {
  455. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  456. && name != NULL && profile != NULL && proflen != NULL)
  457. {
  458. png_debug1(1, "in %s retrieval function\n", "iCCP");
  459. *name = info_ptr->iccp_name;
  460. *profile = info_ptr->iccp_profile;
  461. /* compression_type is a dummy so the API won't have to change
  462. if we introduce multiple compression types later. */
  463. *proflen = (int)info_ptr->iccp_proflen;
  464. *compression_type = (int)info_ptr->iccp_compression;
  465. return (PNG_INFO_iCCP);
  466. }
  467. return (0);
  468. }
  469. #endif
  470. #if defined(PNG_sPLT_SUPPORTED)
  471. png_uint_32 PNGAPI
  472. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  473. png_sPLT_tpp spalettes)
  474. {
  475. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  476. *spalettes = info_ptr->splt_palettes;
  477. return ((png_uint_32)info_ptr->splt_palettes_num);
  478. }
  479. #endif
  480. #if defined(PNG_hIST_SUPPORTED)
  481. png_uint_32 PNGAPI
  482. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  483. {
  484. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  485. && hist != NULL)
  486. {
  487. png_debug1(1, "in %s retrieval function\n", "hIST");
  488. *hist = info_ptr->hist;
  489. return (PNG_INFO_hIST);
  490. }
  491. return (0);
  492. }
  493. #endif
  494. png_uint_32 PNGAPI
  495. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  496. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  497. int *color_type, int *interlace_type, int *compression_type,
  498. int *filter_type)
  499. {
  500. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  501. bit_depth != NULL && color_type != NULL)
  502. {
  503. png_debug1(1, "in %s retrieval function\n", "IHDR");
  504. *width = info_ptr->width;
  505. *height = info_ptr->height;
  506. *bit_depth = info_ptr->bit_depth;
  507. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  508. png_error(png_ptr, "Invalid bit depth");
  509. *color_type = info_ptr->color_type;
  510. if (info_ptr->color_type > 6)
  511. png_error(png_ptr, "Invalid color type");
  512. if (compression_type != NULL)
  513. *compression_type = info_ptr->compression_type;
  514. if (filter_type != NULL)
  515. *filter_type = info_ptr->filter_type;
  516. if (interlace_type != NULL)
  517. *interlace_type = info_ptr->interlace_type;
  518. /* check for potential overflow of rowbytes */
  519. if (width == 0 || *width > PNG_UINT_31_MAX)
  520. png_error(png_ptr, "Invalid image width");
  521. if (height == 0 || *height > PNG_UINT_31_MAX)
  522. png_error(png_ptr, "Invalid image height");
  523. if (info_ptr->width > (PNG_UINT_32_MAX
  524. >> 3) /* 8-byte RGBA pixels */
  525. - 64 /* bigrowbuf hack */
  526. - 1 /* filter byte */
  527. - 7*8 /* rounding of width to multiple of 8 pixels */
  528. - 8) /* extra max_pixel_depth pad */
  529. {
  530. png_warning(png_ptr,
  531. "Width too large for libpng to process image data.");
  532. }
  533. return (1);
  534. }
  535. return (0);
  536. }
  537. #if defined(PNG_oFFs_SUPPORTED)
  538. png_uint_32 PNGAPI
  539. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  540. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  541. {
  542. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  543. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  544. {
  545. png_debug1(1, "in %s retrieval function\n", "oFFs");
  546. *offset_x = info_ptr->x_offset;
  547. *offset_y = info_ptr->y_offset;
  548. *unit_type = (int)info_ptr->offset_unit_type;
  549. return (PNG_INFO_oFFs);
  550. }
  551. return (0);
  552. }
  553. #endif
  554. #if defined(PNG_pCAL_SUPPORTED)
  555. png_uint_32 PNGAPI
  556. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  557. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  558. png_charp *units, png_charpp *params)
  559. {
  560. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  561. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  562. nparams != NULL && units != NULL && params != NULL)
  563. {
  564. png_debug1(1, "in %s retrieval function\n", "pCAL");
  565. *purpose = info_ptr->pcal_purpose;
  566. *X0 = info_ptr->pcal_X0;
  567. *X1 = info_ptr->pcal_X1;
  568. *type = (int)info_ptr->pcal_type;
  569. *nparams = (int)info_ptr->pcal_nparams;
  570. *units = info_ptr->pcal_units;
  571. *params = info_ptr->pcal_params;
  572. return (PNG_INFO_pCAL);
  573. }
  574. return (0);
  575. }
  576. #endif
  577. #if defined(PNG_sCAL_SUPPORTED)
  578. #ifdef PNG_FLOATING_POINT_SUPPORTED
  579. png_uint_32 PNGAPI
  580. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  581. int *unit, double *width, double *height)
  582. {
  583. if (png_ptr != NULL && info_ptr != NULL &&
  584. (info_ptr->valid & PNG_INFO_sCAL))
  585. {
  586. *unit = info_ptr->scal_unit;
  587. *width = info_ptr->scal_pixel_width;
  588. *height = info_ptr->scal_pixel_height;
  589. return (PNG_INFO_sCAL);
  590. }
  591. return(0);
  592. }
  593. #else
  594. #ifdef PNG_FIXED_POINT_SUPPORTED
  595. png_uint_32 PNGAPI
  596. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  597. int *unit, png_charpp width, png_charpp height)
  598. {
  599. if (png_ptr != NULL && info_ptr != NULL &&
  600. (info_ptr->valid & PNG_INFO_sCAL))
  601. {
  602. *unit = info_ptr->scal_unit;
  603. *width = info_ptr->scal_s_width;
  604. *height = info_ptr->scal_s_height;
  605. return (PNG_INFO_sCAL);
  606. }
  607. return(0);
  608. }
  609. #endif
  610. #endif
  611. #endif
  612. #if defined(PNG_pHYs_SUPPORTED)
  613. png_uint_32 PNGAPI
  614. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  615. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  616. {
  617. png_uint_32 retval = 0;
  618. if (png_ptr != NULL && info_ptr != NULL &&
  619. (info_ptr->valid & PNG_INFO_pHYs))
  620. {
  621. png_debug1(1, "in %s retrieval function\n", "pHYs");
  622. if (res_x != NULL)
  623. {
  624. *res_x = info_ptr->x_pixels_per_unit;
  625. retval |= PNG_INFO_pHYs;
  626. }
  627. if (res_y != NULL)
  628. {
  629. *res_y = info_ptr->y_pixels_per_unit;
  630. retval |= PNG_INFO_pHYs;
  631. }
  632. if (unit_type != NULL)
  633. {
  634. *unit_type = (int)info_ptr->phys_unit_type;
  635. retval |= PNG_INFO_pHYs;
  636. }
  637. }
  638. return (retval);
  639. }
  640. #endif
  641. png_uint_32 PNGAPI
  642. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  643. int *num_palette)
  644. {
  645. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  646. && palette != NULL)
  647. {
  648. png_debug1(1, "in %s retrieval function\n", "PLTE");
  649. *palette = info_ptr->palette;
  650. *num_palette = info_ptr->num_palette;
  651. png_debug1(3, "num_palette = %d\n", *num_palette);
  652. return (PNG_INFO_PLTE);
  653. }
  654. return (0);
  655. }
  656. #if defined(PNG_sBIT_SUPPORTED)
  657. png_uint_32 PNGAPI
  658. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  659. {
  660. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  661. && sig_bit != NULL)
  662. {
  663. png_debug1(1, "in %s retrieval function\n", "sBIT");
  664. *sig_bit = &(info_ptr->sig_bit);
  665. return (PNG_INFO_sBIT);
  666. }
  667. return (0);
  668. }
  669. #endif
  670. #if defined(PNG_TEXT_SUPPORTED)
  671. png_uint_32 PNGAPI
  672. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  673. int *num_text)
  674. {
  675. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  676. {
  677. png_debug1(1, "in %s retrieval function\n",
  678. (png_ptr->chunk_name[0] == '\0' ? "text"
  679. : (png_const_charp)png_ptr->chunk_name));
  680. if (text_ptr != NULL)
  681. *text_ptr = info_ptr->text;
  682. if (num_text != NULL)
  683. *num_text = info_ptr->num_text;
  684. return ((png_uint_32)info_ptr->num_text);
  685. }
  686. if (num_text != NULL)
  687. *num_text = 0;
  688. return(0);
  689. }
  690. #endif
  691. #if defined(PNG_tIME_SUPPORTED)
  692. png_uint_32 PNGAPI
  693. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  694. {
  695. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  696. && mod_time != NULL)
  697. {
  698. png_debug1(1, "in %s retrieval function\n", "tIME");
  699. *mod_time = &(info_ptr->mod_time);
  700. return (PNG_INFO_tIME);
  701. }
  702. return (0);
  703. }
  704. #endif
  705. #if defined(PNG_tRNS_SUPPORTED)
  706. png_uint_32 PNGAPI
  707. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  708. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  709. {
  710. png_uint_32 retval = 0;
  711. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  712. {
  713. png_debug1(1, "in %s retrieval function\n", "tRNS");
  714. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  715. {
  716. if (trans != NULL)
  717. {
  718. *trans = info_ptr->trans;
  719. retval |= PNG_INFO_tRNS;
  720. }
  721. if (trans_values != NULL)
  722. *trans_values = &(info_ptr->trans_values);
  723. }
  724. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  725. {
  726. if (trans_values != NULL)
  727. {
  728. *trans_values = &(info_ptr->trans_values);
  729. retval |= PNG_INFO_tRNS;
  730. }
  731. if(trans != NULL)
  732. *trans = NULL;
  733. }
  734. if(num_trans != NULL)
  735. {
  736. *num_trans = info_ptr->num_trans;
  737. retval |= PNG_INFO_tRNS;
  738. }
  739. }
  740. return (retval);
  741. }
  742. #endif
  743. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  744. png_uint_32 PNGAPI
  745. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  746. png_unknown_chunkpp unknowns)
  747. {
  748. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  749. *unknowns = info_ptr->unknown_chunks;
  750. return ((png_uint_32)info_ptr->unknown_chunks_num);
  751. }
  752. #endif
  753. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  754. png_byte PNGAPI
  755. png_get_rgb_to_gray_status (png_structp png_ptr)
  756. {
  757. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  758. }
  759. #endif
  760. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  761. png_voidp PNGAPI
  762. png_get_user_chunk_ptr(png_structp png_ptr)
  763. {
  764. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  765. }
  766. #endif
  767. #ifdef PNG_WRITE_SUPPORTED
  768. png_uint_32 PNGAPI
  769. png_get_compression_buffer_size(png_structp png_ptr)
  770. {
  771. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  772. }
  773. #endif
  774. #ifndef PNG_1_0_X
  775. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  776. /* this function was added to libpng 1.2.0 and should exist by default */
  777. png_uint_32 PNGAPI
  778. png_get_asm_flags (png_structp png_ptr)
  779. {
  780. return (png_uint_32)(png_ptr? png_ptr->asm_flags : 0L);
  781. }
  782. /* this function was added to libpng 1.2.0 and should exist by default */
  783. png_uint_32 PNGAPI
  784. png_get_asm_flagmask (int flag_select)
  785. {
  786. png_uint_32 settable_asm_flags = 0;
  787. if (flag_select & PNG_SELECT_READ)
  788. settable_asm_flags |=
  789. PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
  790. PNG_ASM_FLAG_MMX_READ_INTERLACE |
  791. PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
  792. PNG_ASM_FLAG_MMX_READ_FILTER_UP |
  793. PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
  794. PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
  795. /* no non-MMX flags yet */
  796. #if 0
  797. /* GRR: no write-flags yet, either, but someday... */
  798. if (flag_select & PNG_SELECT_WRITE)
  799. settable_asm_flags |=
  800. PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
  801. #endif /* 0 */
  802. return settable_asm_flags; /* _theoretically_ settable capabilities only */
  803. }
  804. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  805. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  806. /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
  807. /* this function was added to libpng 1.2.0 */
  808. png_uint_32 PNGAPI
  809. png_get_mmx_flagmask (int flag_select, int *compilerID)
  810. {
  811. png_uint_32 settable_mmx_flags = 0;
  812. if (flag_select & PNG_SELECT_READ)
  813. settable_mmx_flags |=
  814. PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
  815. PNG_ASM_FLAG_MMX_READ_INTERLACE |
  816. PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
  817. PNG_ASM_FLAG_MMX_READ_FILTER_UP |
  818. PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
  819. PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
  820. #if 0
  821. /* GRR: no MMX write support yet, but someday... */
  822. if (flag_select & PNG_SELECT_WRITE)
  823. settable_mmx_flags |=
  824. PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
  825. #endif /* 0 */
  826. if (compilerID != NULL) {
  827. #ifdef PNG_USE_PNGVCRD
  828. *compilerID = 1; /* MSVC */
  829. #else
  830. #ifdef PNG_USE_PNGGCCRD
  831. *compilerID = 2; /* gcc/gas */
  832. #else
  833. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  834. #endif
  835. #endif
  836. }
  837. return settable_mmx_flags; /* _theoretically_ settable capabilities only */
  838. }
  839. /* this function was added to libpng 1.2.0 */
  840. png_byte PNGAPI
  841. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  842. {
  843. return (png_byte)(png_ptr? png_ptr->mmx_bitdepth_threshold : 0);
  844. }
  845. /* this function was added to libpng 1.2.0 */
  846. png_uint_32 PNGAPI
  847. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  848. {
  849. return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L);
  850. }
  851. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  852. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  853. /* these functions were added to libpng 1.2.6 */
  854. png_uint_32 PNGAPI
  855. png_get_user_width_max (png_structp png_ptr)
  856. {
  857. return (png_ptr? png_ptr->user_width_max : 0);
  858. }
  859. png_uint_32 PNGAPI
  860. png_get_user_height_max (png_structp png_ptr)
  861. {
  862. return (png_ptr? png_ptr->user_height_max : 0);
  863. }
  864. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  865. #endif /* ?PNG_1_0_X */