pngget.c 38 KB

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