pngget.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. /* pngget.c - retrieval of values from info struct
  2. *
  3. * Copyright (c) 2018 Cosmin Truta
  4. * Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
  5. * Copyright (c) 1996-1997 Andreas Dilger
  6. * 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_structrp png_ptr, png_const_inforp 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. size_t PNGAPI
  24. png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp 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_structrp png_ptr, png_const_inforp 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_structrp png_ptr, png_const_inforp 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_structrp png_ptr, png_const_inforp 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_structrp png_ptr, png_const_inforp 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_structrp png_ptr, png_const_inforp 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_structrp png_ptr, png_const_inforp 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_structrp png_ptr, png_const_inforp 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_structrp png_ptr, png_const_inforp 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_structrp png_ptr, png_const_inforp
  92. info_ptr)
  93. {
  94. #ifdef PNG_pHYs_SUPPORTED
  95. if (png_ptr != NULL && info_ptr != NULL &&
  96. (info_ptr->valid & PNG_INFO_pHYs) != 0)
  97. {
  98. png_debug1(1, "in %s retrieval function",
  99. "png_get_x_pixels_per_meter");
  100. if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
  101. return (info_ptr->x_pixels_per_unit);
  102. }
  103. #else
  104. PNG_UNUSED(png_ptr)
  105. PNG_UNUSED(info_ptr)
  106. #endif
  107. return (0);
  108. }
  109. png_uint_32 PNGAPI
  110. png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
  111. info_ptr)
  112. {
  113. #ifdef PNG_pHYs_SUPPORTED
  114. if (png_ptr != NULL && info_ptr != NULL &&
  115. (info_ptr->valid & PNG_INFO_pHYs) != 0)
  116. {
  117. png_debug1(1, "in %s retrieval function",
  118. "png_get_y_pixels_per_meter");
  119. if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
  120. return (info_ptr->y_pixels_per_unit);
  121. }
  122. #else
  123. PNG_UNUSED(png_ptr)
  124. PNG_UNUSED(info_ptr)
  125. #endif
  126. return (0);
  127. }
  128. png_uint_32 PNGAPI
  129. png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
  130. {
  131. #ifdef PNG_pHYs_SUPPORTED
  132. if (png_ptr != NULL && info_ptr != NULL &&
  133. (info_ptr->valid & PNG_INFO_pHYs) != 0)
  134. {
  135. png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
  136. if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
  137. info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
  138. return (info_ptr->x_pixels_per_unit);
  139. }
  140. #else
  141. PNG_UNUSED(png_ptr)
  142. PNG_UNUSED(info_ptr)
  143. #endif
  144. return (0);
  145. }
  146. #ifdef PNG_FLOATING_POINT_SUPPORTED
  147. float PNGAPI
  148. png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
  149. info_ptr)
  150. {
  151. #ifdef PNG_READ_pHYs_SUPPORTED
  152. if (png_ptr != NULL && info_ptr != NULL &&
  153. (info_ptr->valid & PNG_INFO_pHYs) != 0)
  154. {
  155. png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
  156. if (info_ptr->x_pixels_per_unit != 0)
  157. return ((float)((float)info_ptr->y_pixels_per_unit
  158. /(float)info_ptr->x_pixels_per_unit));
  159. }
  160. #else
  161. PNG_UNUSED(png_ptr)
  162. PNG_UNUSED(info_ptr)
  163. #endif
  164. return ((float)0.0);
  165. }
  166. #endif
  167. #ifdef PNG_FIXED_POINT_SUPPORTED
  168. png_fixed_point PNGAPI
  169. png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
  170. png_const_inforp info_ptr)
  171. {
  172. #ifdef PNG_READ_pHYs_SUPPORTED
  173. if (png_ptr != NULL && info_ptr != NULL &&
  174. (info_ptr->valid & PNG_INFO_pHYs) != 0 &&
  175. info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 &&
  176. info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX &&
  177. info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
  178. {
  179. png_fixed_point res;
  180. png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
  181. /* The following casts work because a PNG 4 byte integer only has a valid
  182. * range of 0..2^31-1; otherwise the cast might overflow.
  183. */
  184. if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
  185. (png_int_32)info_ptr->x_pixels_per_unit) != 0)
  186. return res;
  187. }
  188. #else
  189. PNG_UNUSED(png_ptr)
  190. PNG_UNUSED(info_ptr)
  191. #endif
  192. return 0;
  193. }
  194. #endif
  195. png_int_32 PNGAPI
  196. png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
  197. {
  198. #ifdef PNG_oFFs_SUPPORTED
  199. if (png_ptr != NULL && info_ptr != NULL &&
  200. (info_ptr->valid & PNG_INFO_oFFs) != 0)
  201. {
  202. png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
  203. if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
  204. return (info_ptr->x_offset);
  205. }
  206. #else
  207. PNG_UNUSED(png_ptr)
  208. PNG_UNUSED(info_ptr)
  209. #endif
  210. return (0);
  211. }
  212. png_int_32 PNGAPI
  213. png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
  214. {
  215. #ifdef PNG_oFFs_SUPPORTED
  216. if (png_ptr != NULL && info_ptr != NULL &&
  217. (info_ptr->valid & PNG_INFO_oFFs) != 0)
  218. {
  219. png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
  220. if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
  221. return (info_ptr->y_offset);
  222. }
  223. #else
  224. PNG_UNUSED(png_ptr)
  225. PNG_UNUSED(info_ptr)
  226. #endif
  227. return (0);
  228. }
  229. png_int_32 PNGAPI
  230. png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
  231. {
  232. #ifdef PNG_oFFs_SUPPORTED
  233. if (png_ptr != NULL && info_ptr != NULL &&
  234. (info_ptr->valid & PNG_INFO_oFFs) != 0)
  235. {
  236. png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
  237. if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
  238. return (info_ptr->x_offset);
  239. }
  240. #else
  241. PNG_UNUSED(png_ptr)
  242. PNG_UNUSED(info_ptr)
  243. #endif
  244. return (0);
  245. }
  246. png_int_32 PNGAPI
  247. png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
  248. {
  249. #ifdef PNG_oFFs_SUPPORTED
  250. if (png_ptr != NULL && info_ptr != NULL &&
  251. (info_ptr->valid & PNG_INFO_oFFs) != 0)
  252. {
  253. png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
  254. if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
  255. return (info_ptr->y_offset);
  256. }
  257. #else
  258. PNG_UNUSED(png_ptr)
  259. PNG_UNUSED(info_ptr)
  260. #endif
  261. return (0);
  262. }
  263. #ifdef PNG_INCH_CONVERSIONS_SUPPORTED
  264. static png_uint_32
  265. ppi_from_ppm(png_uint_32 ppm)
  266. {
  267. #if 0
  268. /* The conversion is *(2.54/100), in binary (32 digits):
  269. * .00000110100000001001110101001001
  270. */
  271. png_uint_32 t1001, t1101;
  272. ppm >>= 1; /* .1 */
  273. t1001 = ppm + (ppm >> 3); /* .1001 */
  274. t1101 = t1001 + (ppm >> 1); /* .1101 */
  275. ppm >>= 20; /* .000000000000000000001 */
  276. t1101 += t1101 >> 15; /* .1101000000000001101 */
  277. t1001 >>= 11; /* .000000000001001 */
  278. t1001 += t1001 >> 12; /* .000000000001001000000001001 */
  279. ppm += t1001; /* .000000000001001000001001001 */
  280. ppm += t1101; /* .110100000001001110101001001 */
  281. return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
  282. #else
  283. /* The argument is a PNG unsigned integer, so it is not permitted
  284. * to be bigger than 2^31.
  285. */
  286. png_fixed_point result;
  287. if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
  288. 5000) != 0)
  289. return (png_uint_32)result;
  290. /* Overflow. */
  291. return 0;
  292. #endif
  293. }
  294. png_uint_32 PNGAPI
  295. png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
  296. {
  297. return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
  298. }
  299. png_uint_32 PNGAPI
  300. png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
  301. {
  302. return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
  303. }
  304. png_uint_32 PNGAPI
  305. png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
  306. {
  307. return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
  308. }
  309. #ifdef PNG_FIXED_POINT_SUPPORTED
  310. static png_fixed_point
  311. png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
  312. {
  313. /* Convert from meters * 1,000,000 to inches * 100,000, meters to
  314. * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
  315. * Notice that this can overflow - a warning is output and 0 is
  316. * returned.
  317. */
  318. return png_muldiv_warn(png_ptr, microns, 500, 127);
  319. }
  320. png_fixed_point PNGAPI
  321. png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
  322. png_const_inforp info_ptr)
  323. {
  324. return png_fixed_inches_from_microns(png_ptr,
  325. png_get_x_offset_microns(png_ptr, info_ptr));
  326. }
  327. #endif
  328. #ifdef PNG_FIXED_POINT_SUPPORTED
  329. png_fixed_point PNGAPI
  330. png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
  331. png_const_inforp info_ptr)
  332. {
  333. return png_fixed_inches_from_microns(png_ptr,
  334. png_get_y_offset_microns(png_ptr, info_ptr));
  335. }
  336. #endif
  337. #ifdef PNG_FLOATING_POINT_SUPPORTED
  338. float PNGAPI
  339. png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
  340. {
  341. /* To avoid the overflow do the conversion directly in floating
  342. * point.
  343. */
  344. return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
  345. }
  346. #endif
  347. #ifdef PNG_FLOATING_POINT_SUPPORTED
  348. float PNGAPI
  349. png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
  350. {
  351. /* To avoid the overflow do the conversion directly in floating
  352. * point.
  353. */
  354. return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
  355. }
  356. #endif
  357. #ifdef PNG_pHYs_SUPPORTED
  358. png_uint_32 PNGAPI
  359. png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
  360. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  361. {
  362. png_uint_32 retval = 0;
  363. if (png_ptr != NULL && info_ptr != NULL &&
  364. (info_ptr->valid & PNG_INFO_pHYs) != 0)
  365. {
  366. png_debug1(1, "in %s retrieval function", "pHYs");
  367. if (res_x != NULL)
  368. {
  369. *res_x = info_ptr->x_pixels_per_unit;
  370. retval |= PNG_INFO_pHYs;
  371. }
  372. if (res_y != NULL)
  373. {
  374. *res_y = info_ptr->y_pixels_per_unit;
  375. retval |= PNG_INFO_pHYs;
  376. }
  377. if (unit_type != NULL)
  378. {
  379. *unit_type = (int)info_ptr->phys_unit_type;
  380. retval |= PNG_INFO_pHYs;
  381. if (*unit_type == 1)
  382. {
  383. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  384. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  385. }
  386. }
  387. }
  388. return (retval);
  389. }
  390. #endif /* pHYs */
  391. #endif /* INCH_CONVERSIONS */
  392. /* png_get_channels really belongs in here, too, but it's been around longer */
  393. #endif /* EASY_ACCESS */
  394. png_byte PNGAPI
  395. png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
  396. {
  397. if (png_ptr != NULL && info_ptr != NULL)
  398. return(info_ptr->channels);
  399. return (0);
  400. }
  401. #ifdef PNG_READ_SUPPORTED
  402. png_const_bytep PNGAPI
  403. png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
  404. {
  405. if (png_ptr != NULL && info_ptr != NULL)
  406. return(info_ptr->signature);
  407. return (NULL);
  408. }
  409. #endif
  410. #ifdef PNG_bKGD_SUPPORTED
  411. png_uint_32 PNGAPI
  412. png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
  413. png_color_16p *background)
  414. {
  415. if (png_ptr != NULL && info_ptr != NULL &&
  416. (info_ptr->valid & PNG_INFO_bKGD) != 0 &&
  417. background != NULL)
  418. {
  419. png_debug1(1, "in %s retrieval function", "bKGD");
  420. *background = &(info_ptr->background);
  421. return (PNG_INFO_bKGD);
  422. }
  423. return (0);
  424. }
  425. #endif
  426. #ifdef PNG_cHRM_SUPPORTED
  427. /* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
  428. * same time to correct the rgb grayscale coefficient defaults obtained from the
  429. * cHRM chunk in 1.5.4
  430. */
  431. # ifdef PNG_FLOATING_POINT_SUPPORTED
  432. png_uint_32 PNGAPI
  433. png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
  434. double *white_x, double *white_y, double *red_x, double *red_y,
  435. double *green_x, double *green_y, double *blue_x, double *blue_y)
  436. {
  437. /* Quiet API change: this code used to only return the end points if a cHRM
  438. * chunk was present, but the end points can also come from iCCP or sRGB
  439. * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and
  440. * the png_set_ APIs merely check that set end points are mutually
  441. * consistent.
  442. */
  443. if (png_ptr != NULL && info_ptr != NULL &&
  444. (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
  445. {
  446. png_debug1(1, "in %s retrieval function", "cHRM");
  447. if (white_x != NULL)
  448. *white_x = png_float(png_ptr,
  449. info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
  450. if (white_y != NULL)
  451. *white_y = png_float(png_ptr,
  452. info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
  453. if (red_x != NULL)
  454. *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
  455. "cHRM red X");
  456. if (red_y != NULL)
  457. *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
  458. "cHRM red Y");
  459. if (green_x != NULL)
  460. *green_x = png_float(png_ptr,
  461. info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
  462. if (green_y != NULL)
  463. *green_y = png_float(png_ptr,
  464. info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
  465. if (blue_x != NULL)
  466. *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
  467. "cHRM blue X");
  468. if (blue_y != NULL)
  469. *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
  470. "cHRM blue Y");
  471. return (PNG_INFO_cHRM);
  472. }
  473. return (0);
  474. }
  475. png_uint_32 PNGAPI
  476. png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
  477. double *red_X, double *red_Y, double *red_Z, double *green_X,
  478. double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
  479. double *blue_Z)
  480. {
  481. if (png_ptr != NULL && info_ptr != NULL &&
  482. (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
  483. {
  484. png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
  485. if (red_X != NULL)
  486. *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
  487. "cHRM red X");
  488. if (red_Y != NULL)
  489. *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
  490. "cHRM red Y");
  491. if (red_Z != NULL)
  492. *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
  493. "cHRM red Z");
  494. if (green_X != NULL)
  495. *green_X = png_float(png_ptr,
  496. info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
  497. if (green_Y != NULL)
  498. *green_Y = png_float(png_ptr,
  499. info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
  500. if (green_Z != NULL)
  501. *green_Z = png_float(png_ptr,
  502. info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
  503. if (blue_X != NULL)
  504. *blue_X = png_float(png_ptr,
  505. info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
  506. if (blue_Y != NULL)
  507. *blue_Y = png_float(png_ptr,
  508. info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
  509. if (blue_Z != NULL)
  510. *blue_Z = png_float(png_ptr,
  511. info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
  512. return (PNG_INFO_cHRM);
  513. }
  514. return (0);
  515. }
  516. # endif
  517. # ifdef PNG_FIXED_POINT_SUPPORTED
  518. png_uint_32 PNGAPI
  519. png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
  520. png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
  521. png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
  522. png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
  523. png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
  524. png_fixed_point *int_blue_Z)
  525. {
  526. if (png_ptr != NULL && info_ptr != NULL &&
  527. (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
  528. {
  529. png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
  530. if (int_red_X != NULL)
  531. *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;
  532. if (int_red_Y != NULL)
  533. *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;
  534. if (int_red_Z != NULL)
  535. *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;
  536. if (int_green_X != NULL)
  537. *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;
  538. if (int_green_Y != NULL)
  539. *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;
  540. if (int_green_Z != NULL)
  541. *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;
  542. if (int_blue_X != NULL)
  543. *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;
  544. if (int_blue_Y != NULL)
  545. *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;
  546. if (int_blue_Z != NULL)
  547. *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;
  548. return (PNG_INFO_cHRM);
  549. }
  550. return (0);
  551. }
  552. png_uint_32 PNGAPI
  553. png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
  554. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  555. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  556. png_fixed_point *blue_x, png_fixed_point *blue_y)
  557. {
  558. png_debug1(1, "in %s retrieval function", "cHRM");
  559. if (png_ptr != NULL && info_ptr != NULL &&
  560. (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
  561. {
  562. if (white_x != NULL)
  563. *white_x = info_ptr->colorspace.end_points_xy.whitex;
  564. if (white_y != NULL)
  565. *white_y = info_ptr->colorspace.end_points_xy.whitey;
  566. if (red_x != NULL)
  567. *red_x = info_ptr->colorspace.end_points_xy.redx;
  568. if (red_y != NULL)
  569. *red_y = info_ptr->colorspace.end_points_xy.redy;
  570. if (green_x != NULL)
  571. *green_x = info_ptr->colorspace.end_points_xy.greenx;
  572. if (green_y != NULL)
  573. *green_y = info_ptr->colorspace.end_points_xy.greeny;
  574. if (blue_x != NULL)
  575. *blue_x = info_ptr->colorspace.end_points_xy.bluex;
  576. if (blue_y != NULL)
  577. *blue_y = info_ptr->colorspace.end_points_xy.bluey;
  578. return (PNG_INFO_cHRM);
  579. }
  580. return (0);
  581. }
  582. # endif
  583. #endif
  584. #ifdef PNG_gAMA_SUPPORTED
  585. # ifdef PNG_FIXED_POINT_SUPPORTED
  586. png_uint_32 PNGAPI
  587. png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
  588. png_fixed_point *file_gamma)
  589. {
  590. png_debug1(1, "in %s retrieval function", "gAMA");
  591. if (png_ptr != NULL && info_ptr != NULL &&
  592. (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
  593. file_gamma != NULL)
  594. {
  595. *file_gamma = info_ptr->colorspace.gamma;
  596. return (PNG_INFO_gAMA);
  597. }
  598. return (0);
  599. }
  600. # endif
  601. # ifdef PNG_FLOATING_POINT_SUPPORTED
  602. png_uint_32 PNGAPI
  603. png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
  604. double *file_gamma)
  605. {
  606. png_debug1(1, "in %s retrieval function", "gAMA(float)");
  607. if (png_ptr != NULL && info_ptr != NULL &&
  608. (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
  609. file_gamma != NULL)
  610. {
  611. *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
  612. "png_get_gAMA");
  613. return (PNG_INFO_gAMA);
  614. }
  615. return (0);
  616. }
  617. # endif
  618. #endif
  619. #ifdef PNG_sRGB_SUPPORTED
  620. png_uint_32 PNGAPI
  621. png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
  622. int *file_srgb_intent)
  623. {
  624. png_debug1(1, "in %s retrieval function", "sRGB");
  625. if (png_ptr != NULL && info_ptr != NULL &&
  626. (info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)
  627. {
  628. *file_srgb_intent = info_ptr->colorspace.rendering_intent;
  629. return (PNG_INFO_sRGB);
  630. }
  631. return (0);
  632. }
  633. #endif
  634. #ifdef PNG_iCCP_SUPPORTED
  635. png_uint_32 PNGAPI
  636. png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
  637. png_charpp name, int *compression_type,
  638. png_bytepp profile, png_uint_32 *proflen)
  639. {
  640. png_debug1(1, "in %s retrieval function", "iCCP");
  641. if (png_ptr != NULL && info_ptr != NULL &&
  642. (info_ptr->valid & PNG_INFO_iCCP) != 0 &&
  643. name != NULL && profile != NULL && proflen != NULL)
  644. {
  645. *name = info_ptr->iccp_name;
  646. *profile = info_ptr->iccp_profile;
  647. *proflen = png_get_uint_32(info_ptr->iccp_profile);
  648. /* This is somewhat irrelevant since the profile data returned has
  649. * actually been uncompressed.
  650. */
  651. if (compression_type != NULL)
  652. *compression_type = PNG_COMPRESSION_TYPE_BASE;
  653. return (PNG_INFO_iCCP);
  654. }
  655. return (0);
  656. }
  657. #endif
  658. #ifdef PNG_sPLT_SUPPORTED
  659. int PNGAPI
  660. png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
  661. png_sPLT_tpp spalettes)
  662. {
  663. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  664. {
  665. *spalettes = info_ptr->splt_palettes;
  666. return info_ptr->splt_palettes_num;
  667. }
  668. return (0);
  669. }
  670. #endif
  671. #ifdef PNG_eXIf_SUPPORTED
  672. png_uint_32 PNGAPI
  673. png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
  674. png_bytep *exif)
  675. {
  676. png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1");
  677. PNG_UNUSED(info_ptr)
  678. PNG_UNUSED(exif)
  679. return 0;
  680. }
  681. png_uint_32 PNGAPI
  682. png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,
  683. png_uint_32 *num_exif, png_bytep *exif)
  684. {
  685. png_debug1(1, "in %s retrieval function", "eXIf");
  686. if (png_ptr != NULL && info_ptr != NULL &&
  687. (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL)
  688. {
  689. *num_exif = info_ptr->num_exif;
  690. *exif = info_ptr->exif;
  691. return (PNG_INFO_eXIf);
  692. }
  693. return (0);
  694. }
  695. #endif
  696. #ifdef PNG_hIST_SUPPORTED
  697. png_uint_32 PNGAPI
  698. png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
  699. png_uint_16p *hist)
  700. {
  701. png_debug1(1, "in %s retrieval function", "hIST");
  702. if (png_ptr != NULL && info_ptr != NULL &&
  703. (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
  704. {
  705. *hist = info_ptr->hist;
  706. return (PNG_INFO_hIST);
  707. }
  708. return (0);
  709. }
  710. #endif
  711. png_uint_32 PNGAPI
  712. png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
  713. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  714. int *color_type, int *interlace_type, int *compression_type,
  715. int *filter_type)
  716. {
  717. png_debug1(1, "in %s retrieval function", "IHDR");
  718. if (png_ptr == NULL || info_ptr == NULL)
  719. return (0);
  720. if (width != NULL)
  721. *width = info_ptr->width;
  722. if (height != NULL)
  723. *height = info_ptr->height;
  724. if (bit_depth != NULL)
  725. *bit_depth = info_ptr->bit_depth;
  726. if (color_type != NULL)
  727. *color_type = info_ptr->color_type;
  728. if (compression_type != NULL)
  729. *compression_type = info_ptr->compression_type;
  730. if (filter_type != NULL)
  731. *filter_type = info_ptr->filter_type;
  732. if (interlace_type != NULL)
  733. *interlace_type = info_ptr->interlace_type;
  734. /* This is redundant if we can be sure that the info_ptr values were all
  735. * assigned in png_set_IHDR(). We do the check anyhow in case an
  736. * application has ignored our advice not to mess with the members
  737. * of info_ptr directly.
  738. */
  739. png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  740. info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
  741. info_ptr->compression_type, info_ptr->filter_type);
  742. return (1);
  743. }
  744. #ifdef PNG_oFFs_SUPPORTED
  745. png_uint_32 PNGAPI
  746. png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
  747. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  748. {
  749. png_debug1(1, "in %s retrieval function", "oFFs");
  750. if (png_ptr != NULL && info_ptr != NULL &&
  751. (info_ptr->valid & PNG_INFO_oFFs) != 0 &&
  752. offset_x != NULL && offset_y != NULL && unit_type != NULL)
  753. {
  754. *offset_x = info_ptr->x_offset;
  755. *offset_y = info_ptr->y_offset;
  756. *unit_type = (int)info_ptr->offset_unit_type;
  757. return (PNG_INFO_oFFs);
  758. }
  759. return (0);
  760. }
  761. #endif
  762. #ifdef PNG_pCAL_SUPPORTED
  763. png_uint_32 PNGAPI
  764. png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
  765. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  766. png_charp *units, png_charpp *params)
  767. {
  768. png_debug1(1, "in %s retrieval function", "pCAL");
  769. if (png_ptr != NULL && info_ptr != NULL &&
  770. (info_ptr->valid & PNG_INFO_pCAL) != 0 &&
  771. purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  772. nparams != NULL && units != NULL && params != NULL)
  773. {
  774. *purpose = info_ptr->pcal_purpose;
  775. *X0 = info_ptr->pcal_X0;
  776. *X1 = info_ptr->pcal_X1;
  777. *type = (int)info_ptr->pcal_type;
  778. *nparams = (int)info_ptr->pcal_nparams;
  779. *units = info_ptr->pcal_units;
  780. *params = info_ptr->pcal_params;
  781. return (PNG_INFO_pCAL);
  782. }
  783. return (0);
  784. }
  785. #endif
  786. #ifdef PNG_sCAL_SUPPORTED
  787. # ifdef PNG_FIXED_POINT_SUPPORTED
  788. # if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
  789. defined(PNG_FLOATING_POINT_SUPPORTED)
  790. png_uint_32 PNGAPI
  791. png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
  792. int *unit, png_fixed_point *width, png_fixed_point *height)
  793. {
  794. if (png_ptr != NULL && info_ptr != NULL &&
  795. (info_ptr->valid & PNG_INFO_sCAL) != 0)
  796. {
  797. *unit = info_ptr->scal_unit;
  798. /*TODO: make this work without FP support; the API is currently eliminated
  799. * if neither floating point APIs nor internal floating point arithmetic
  800. * are enabled.
  801. */
  802. *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
  803. *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
  804. "sCAL height");
  805. return (PNG_INFO_sCAL);
  806. }
  807. return(0);
  808. }
  809. # endif /* FLOATING_ARITHMETIC */
  810. # endif /* FIXED_POINT */
  811. # ifdef PNG_FLOATING_POINT_SUPPORTED
  812. png_uint_32 PNGAPI
  813. png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
  814. int *unit, double *width, double *height)
  815. {
  816. if (png_ptr != NULL && info_ptr != NULL &&
  817. (info_ptr->valid & PNG_INFO_sCAL) != 0)
  818. {
  819. *unit = info_ptr->scal_unit;
  820. *width = atof(info_ptr->scal_s_width);
  821. *height = atof(info_ptr->scal_s_height);
  822. return (PNG_INFO_sCAL);
  823. }
  824. return(0);
  825. }
  826. # endif /* FLOATING POINT */
  827. png_uint_32 PNGAPI
  828. png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
  829. int *unit, png_charpp width, png_charpp height)
  830. {
  831. if (png_ptr != NULL && info_ptr != NULL &&
  832. (info_ptr->valid & PNG_INFO_sCAL) != 0)
  833. {
  834. *unit = info_ptr->scal_unit;
  835. *width = info_ptr->scal_s_width;
  836. *height = info_ptr->scal_s_height;
  837. return (PNG_INFO_sCAL);
  838. }
  839. return(0);
  840. }
  841. #endif /* sCAL */
  842. #ifdef PNG_pHYs_SUPPORTED
  843. png_uint_32 PNGAPI
  844. png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
  845. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  846. {
  847. png_uint_32 retval = 0;
  848. png_debug1(1, "in %s retrieval function", "pHYs");
  849. if (png_ptr != NULL && info_ptr != NULL &&
  850. (info_ptr->valid & PNG_INFO_pHYs) != 0)
  851. {
  852. if (res_x != NULL)
  853. {
  854. *res_x = info_ptr->x_pixels_per_unit;
  855. retval |= PNG_INFO_pHYs;
  856. }
  857. if (res_y != NULL)
  858. {
  859. *res_y = info_ptr->y_pixels_per_unit;
  860. retval |= PNG_INFO_pHYs;
  861. }
  862. if (unit_type != NULL)
  863. {
  864. *unit_type = (int)info_ptr->phys_unit_type;
  865. retval |= PNG_INFO_pHYs;
  866. }
  867. }
  868. return (retval);
  869. }
  870. #endif /* pHYs */
  871. png_uint_32 PNGAPI
  872. png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
  873. png_colorp *palette, int *num_palette)
  874. {
  875. png_debug1(1, "in %s retrieval function", "PLTE");
  876. if (png_ptr != NULL && info_ptr != NULL &&
  877. (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
  878. {
  879. *palette = info_ptr->palette;
  880. *num_palette = info_ptr->num_palette;
  881. png_debug1(3, "num_palette = %d", *num_palette);
  882. return (PNG_INFO_PLTE);
  883. }
  884. return (0);
  885. }
  886. #ifdef PNG_sBIT_SUPPORTED
  887. png_uint_32 PNGAPI
  888. png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
  889. png_color_8p *sig_bit)
  890. {
  891. png_debug1(1, "in %s retrieval function", "sBIT");
  892. if (png_ptr != NULL && info_ptr != NULL &&
  893. (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
  894. {
  895. *sig_bit = &(info_ptr->sig_bit);
  896. return (PNG_INFO_sBIT);
  897. }
  898. return (0);
  899. }
  900. #endif
  901. #ifdef PNG_TEXT_SUPPORTED
  902. int PNGAPI
  903. png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
  904. png_textp *text_ptr, int *num_text)
  905. {
  906. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  907. {
  908. png_debug1(1, "in 0x%lx retrieval function",
  909. (unsigned long)png_ptr->chunk_name);
  910. if (text_ptr != NULL)
  911. *text_ptr = info_ptr->text;
  912. if (num_text != NULL)
  913. *num_text = info_ptr->num_text;
  914. return info_ptr->num_text;
  915. }
  916. if (num_text != NULL)
  917. *num_text = 0;
  918. return(0);
  919. }
  920. #endif
  921. #ifdef PNG_tIME_SUPPORTED
  922. png_uint_32 PNGAPI
  923. png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
  924. png_timep *mod_time)
  925. {
  926. png_debug1(1, "in %s retrieval function", "tIME");
  927. if (png_ptr != NULL && info_ptr != NULL &&
  928. (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
  929. {
  930. *mod_time = &(info_ptr->mod_time);
  931. return (PNG_INFO_tIME);
  932. }
  933. return (0);
  934. }
  935. #endif
  936. #ifdef PNG_tRNS_SUPPORTED
  937. png_uint_32 PNGAPI
  938. png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
  939. png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
  940. {
  941. png_uint_32 retval = 0;
  942. if (png_ptr != NULL && info_ptr != NULL &&
  943. (info_ptr->valid & PNG_INFO_tRNS) != 0)
  944. {
  945. png_debug1(1, "in %s retrieval function", "tRNS");
  946. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  947. {
  948. if (trans_alpha != NULL)
  949. {
  950. *trans_alpha = info_ptr->trans_alpha;
  951. retval |= PNG_INFO_tRNS;
  952. }
  953. if (trans_color != NULL)
  954. *trans_color = &(info_ptr->trans_color);
  955. }
  956. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  957. {
  958. if (trans_color != NULL)
  959. {
  960. *trans_color = &(info_ptr->trans_color);
  961. retval |= PNG_INFO_tRNS;
  962. }
  963. if (trans_alpha != NULL)
  964. *trans_alpha = NULL;
  965. }
  966. if (num_trans != NULL)
  967. {
  968. *num_trans = info_ptr->num_trans;
  969. retval |= PNG_INFO_tRNS;
  970. }
  971. }
  972. return (retval);
  973. }
  974. #endif
  975. #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
  976. int PNGAPI
  977. png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
  978. png_unknown_chunkpp unknowns)
  979. {
  980. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  981. {
  982. *unknowns = info_ptr->unknown_chunks;
  983. return info_ptr->unknown_chunks_num;
  984. }
  985. return (0);
  986. }
  987. #endif
  988. #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  989. png_byte PNGAPI
  990. png_get_rgb_to_gray_status (png_const_structrp png_ptr)
  991. {
  992. return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
  993. }
  994. #endif
  995. #ifdef PNG_USER_CHUNKS_SUPPORTED
  996. png_voidp PNGAPI
  997. png_get_user_chunk_ptr(png_const_structrp png_ptr)
  998. {
  999. return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
  1000. }
  1001. #endif
  1002. size_t PNGAPI
  1003. png_get_compression_buffer_size(png_const_structrp png_ptr)
  1004. {
  1005. if (png_ptr == NULL)
  1006. return 0;
  1007. #ifdef PNG_WRITE_SUPPORTED
  1008. if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
  1009. #endif
  1010. {
  1011. #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
  1012. return png_ptr->IDAT_read_size;
  1013. #else
  1014. return PNG_IDAT_READ_SIZE;
  1015. #endif
  1016. }
  1017. #ifdef PNG_WRITE_SUPPORTED
  1018. else
  1019. return png_ptr->zbuffer_size;
  1020. #endif
  1021. }
  1022. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  1023. /* These functions were added to libpng 1.2.6 and were enabled
  1024. * by default in libpng-1.4.0 */
  1025. png_uint_32 PNGAPI
  1026. png_get_user_width_max (png_const_structrp png_ptr)
  1027. {
  1028. return (png_ptr ? png_ptr->user_width_max : 0);
  1029. }
  1030. png_uint_32 PNGAPI
  1031. png_get_user_height_max (png_const_structrp png_ptr)
  1032. {
  1033. return (png_ptr ? png_ptr->user_height_max : 0);
  1034. }
  1035. /* This function was added to libpng 1.4.0 */
  1036. png_uint_32 PNGAPI
  1037. png_get_chunk_cache_max (png_const_structrp png_ptr)
  1038. {
  1039. return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
  1040. }
  1041. /* This function was added to libpng 1.4.1 */
  1042. png_alloc_size_t PNGAPI
  1043. png_get_chunk_malloc_max (png_const_structrp png_ptr)
  1044. {
  1045. return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
  1046. }
  1047. #endif /* SET_USER_LIMITS */
  1048. /* These functions were added to libpng 1.4.0 */
  1049. #ifdef PNG_IO_STATE_SUPPORTED
  1050. png_uint_32 PNGAPI
  1051. png_get_io_state (png_const_structrp png_ptr)
  1052. {
  1053. return png_ptr->io_state;
  1054. }
  1055. png_uint_32 PNGAPI
  1056. png_get_io_chunk_type (png_const_structrp png_ptr)
  1057. {
  1058. return png_ptr->chunk_name;
  1059. }
  1060. #endif /* IO_STATE */
  1061. #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
  1062. # ifdef PNG_GET_PALETTE_MAX_SUPPORTED
  1063. int PNGAPI
  1064. png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
  1065. {
  1066. if (png_ptr != NULL && info_ptr != NULL)
  1067. return png_ptr->num_palette_max;
  1068. return (-1);
  1069. }
  1070. # endif
  1071. #endif
  1072. #endif /* READ || WRITE */