pngget.c 39 KB

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