Counter Strike : Global Offensive Source Code
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.

1032 lines
27 KiB

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