The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

900 lines
25KB

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