pngget.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  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_eXIf_SUPPORTED
  681. png_uint_32 PNGAPI
  682. png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
  683. png_bytep *exif)
  684. {
  685. png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1");
  686. PNG_UNUSED(info_ptr)
  687. PNG_UNUSED(exif)
  688. return 0;
  689. }
  690. png_uint_32 PNGAPI
  691. png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,
  692. png_uint_32 *num_exif, png_bytep *exif)
  693. {
  694. png_debug1(1, "in %s retrieval function", "eXIf");
  695. if (png_ptr != NULL && info_ptr != NULL &&
  696. (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL)
  697. {
  698. *num_exif = info_ptr->num_exif;
  699. *exif = info_ptr->exif;
  700. return PNG_INFO_eXIf;
  701. }
  702. return 0;
  703. }
  704. #endif
  705. #ifdef PNG_hIST_SUPPORTED
  706. png_uint_32 PNGAPI
  707. png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
  708. png_uint_16p *hist)
  709. {
  710. png_debug1(1, "in %s retrieval function", "hIST");
  711. if (png_ptr != NULL && info_ptr != NULL &&
  712. (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
  713. {
  714. *hist = info_ptr->hist;
  715. return PNG_INFO_hIST;
  716. }
  717. return 0;
  718. }
  719. #endif
  720. png_uint_32 PNGAPI
  721. png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
  722. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  723. int *color_type, int *interlace_type, int *compression_type,
  724. int *filter_type)
  725. {
  726. png_debug1(1, "in %s retrieval function", "IHDR");
  727. if (png_ptr == NULL || info_ptr == NULL)
  728. return 0;
  729. if (width != NULL)
  730. *width = info_ptr->width;
  731. if (height != NULL)
  732. *height = info_ptr->height;
  733. if (bit_depth != NULL)
  734. *bit_depth = info_ptr->bit_depth;
  735. if (color_type != NULL)
  736. *color_type = info_ptr->color_type;
  737. if (compression_type != NULL)
  738. *compression_type = info_ptr->compression_type;
  739. if (filter_type != NULL)
  740. *filter_type = info_ptr->filter_type;
  741. if (interlace_type != NULL)
  742. *interlace_type = info_ptr->interlace_type;
  743. /* This is redundant if we can be sure that the info_ptr values were all
  744. * assigned in png_set_IHDR(). We do the check anyhow in case an
  745. * application has ignored our advice not to mess with the members
  746. * of info_ptr directly.
  747. */
  748. png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  749. info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
  750. info_ptr->compression_type, info_ptr->filter_type);
  751. return 1;
  752. }
  753. #ifdef PNG_oFFs_SUPPORTED
  754. png_uint_32 PNGAPI
  755. png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
  756. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  757. {
  758. png_debug1(1, "in %s retrieval function", "oFFs");
  759. if (png_ptr != NULL && info_ptr != NULL &&
  760. (info_ptr->valid & PNG_INFO_oFFs) != 0 &&
  761. offset_x != NULL && offset_y != NULL && unit_type != NULL)
  762. {
  763. *offset_x = info_ptr->x_offset;
  764. *offset_y = info_ptr->y_offset;
  765. *unit_type = (int)info_ptr->offset_unit_type;
  766. return PNG_INFO_oFFs;
  767. }
  768. return 0;
  769. }
  770. #endif
  771. #ifdef PNG_pCAL_SUPPORTED
  772. png_uint_32 PNGAPI
  773. png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
  774. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  775. png_charp *units, png_charpp *params)
  776. {
  777. png_debug1(1, "in %s retrieval function", "pCAL");
  778. if (png_ptr != NULL && info_ptr != NULL &&
  779. (info_ptr->valid & PNG_INFO_pCAL) != 0 &&
  780. purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  781. nparams != NULL && units != NULL && params != NULL)
  782. {
  783. *purpose = info_ptr->pcal_purpose;
  784. *X0 = info_ptr->pcal_X0;
  785. *X1 = info_ptr->pcal_X1;
  786. *type = (int)info_ptr->pcal_type;
  787. *nparams = (int)info_ptr->pcal_nparams;
  788. *units = info_ptr->pcal_units;
  789. *params = info_ptr->pcal_params;
  790. return PNG_INFO_pCAL;
  791. }
  792. return 0;
  793. }
  794. #endif
  795. #ifdef PNG_sCAL_SUPPORTED
  796. # ifdef PNG_FIXED_POINT_SUPPORTED
  797. # if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
  798. defined(PNG_FLOATING_POINT_SUPPORTED)
  799. png_uint_32 PNGAPI
  800. png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
  801. int *unit, png_fixed_point *width, png_fixed_point *height)
  802. {
  803. png_debug1(1, "in %s retrieval function", "sCAL");
  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. png_debug1(1, "in %s retrieval function", "sCAL(float)");
  827. if (png_ptr != NULL && info_ptr != NULL &&
  828. (info_ptr->valid & PNG_INFO_sCAL) != 0)
  829. {
  830. *unit = info_ptr->scal_unit;
  831. *width = atof(info_ptr->scal_s_width);
  832. *height = atof(info_ptr->scal_s_height);
  833. return PNG_INFO_sCAL;
  834. }
  835. return 0;
  836. }
  837. # endif /* FLOATING POINT */
  838. png_uint_32 PNGAPI
  839. png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
  840. int *unit, png_charpp width, png_charpp height)
  841. {
  842. png_debug1(1, "in %s retrieval function", "sCAL(str)");
  843. if (png_ptr != NULL && info_ptr != NULL &&
  844. (info_ptr->valid & PNG_INFO_sCAL) != 0)
  845. {
  846. *unit = info_ptr->scal_unit;
  847. *width = info_ptr->scal_s_width;
  848. *height = info_ptr->scal_s_height;
  849. return PNG_INFO_sCAL;
  850. }
  851. return 0;
  852. }
  853. #endif /* sCAL */
  854. #ifdef PNG_pHYs_SUPPORTED
  855. png_uint_32 PNGAPI
  856. png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
  857. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  858. {
  859. png_uint_32 retval = 0;
  860. png_debug1(1, "in %s retrieval function", "pHYs");
  861. if (png_ptr != NULL && info_ptr != NULL &&
  862. (info_ptr->valid & PNG_INFO_pHYs) != 0)
  863. {
  864. if (res_x != NULL)
  865. {
  866. *res_x = info_ptr->x_pixels_per_unit;
  867. retval |= PNG_INFO_pHYs;
  868. }
  869. if (res_y != NULL)
  870. {
  871. *res_y = info_ptr->y_pixels_per_unit;
  872. retval |= PNG_INFO_pHYs;
  873. }
  874. if (unit_type != NULL)
  875. {
  876. *unit_type = (int)info_ptr->phys_unit_type;
  877. retval |= PNG_INFO_pHYs;
  878. }
  879. }
  880. return retval;
  881. }
  882. #endif /* pHYs */
  883. png_uint_32 PNGAPI
  884. png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
  885. png_colorp *palette, int *num_palette)
  886. {
  887. png_debug1(1, "in %s retrieval function", "PLTE");
  888. if (png_ptr != NULL && info_ptr != NULL &&
  889. (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
  890. {
  891. *palette = info_ptr->palette;
  892. *num_palette = info_ptr->num_palette;
  893. png_debug1(3, "num_palette = %d", *num_palette);
  894. return PNG_INFO_PLTE;
  895. }
  896. return 0;
  897. }
  898. #ifdef PNG_sBIT_SUPPORTED
  899. png_uint_32 PNGAPI
  900. png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
  901. png_color_8p *sig_bit)
  902. {
  903. png_debug1(1, "in %s retrieval function", "sBIT");
  904. if (png_ptr != NULL && info_ptr != NULL &&
  905. (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
  906. {
  907. *sig_bit = &(info_ptr->sig_bit);
  908. return PNG_INFO_sBIT;
  909. }
  910. return 0;
  911. }
  912. #endif
  913. #ifdef PNG_TEXT_SUPPORTED
  914. int PNGAPI
  915. png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
  916. png_textp *text_ptr, int *num_text)
  917. {
  918. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  919. {
  920. png_debug1(1, "in text retrieval function, chunk typeid = 0x%lx",
  921. (unsigned long)png_ptr->chunk_name);
  922. if (text_ptr != NULL)
  923. *text_ptr = info_ptr->text;
  924. if (num_text != NULL)
  925. *num_text = info_ptr->num_text;
  926. return info_ptr->num_text;
  927. }
  928. if (num_text != NULL)
  929. *num_text = 0;
  930. return 0;
  931. }
  932. #endif
  933. #ifdef PNG_tIME_SUPPORTED
  934. png_uint_32 PNGAPI
  935. png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
  936. png_timep *mod_time)
  937. {
  938. png_debug1(1, "in %s retrieval function", "tIME");
  939. if (png_ptr != NULL && info_ptr != NULL &&
  940. (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
  941. {
  942. *mod_time = &(info_ptr->mod_time);
  943. return PNG_INFO_tIME;
  944. }
  945. return 0;
  946. }
  947. #endif
  948. #ifdef PNG_tRNS_SUPPORTED
  949. png_uint_32 PNGAPI
  950. png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
  951. png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
  952. {
  953. png_uint_32 retval = 0;
  954. png_debug1(1, "in %s retrieval function", "tRNS");
  955. if (png_ptr != NULL && info_ptr != NULL &&
  956. (info_ptr->valid & PNG_INFO_tRNS) != 0)
  957. {
  958. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  959. {
  960. if (trans_alpha != NULL)
  961. {
  962. *trans_alpha = info_ptr->trans_alpha;
  963. retval |= PNG_INFO_tRNS;
  964. }
  965. if (trans_color != NULL)
  966. *trans_color = &(info_ptr->trans_color);
  967. }
  968. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  969. {
  970. if (trans_color != NULL)
  971. {
  972. *trans_color = &(info_ptr->trans_color);
  973. retval |= PNG_INFO_tRNS;
  974. }
  975. if (trans_alpha != NULL)
  976. *trans_alpha = NULL;
  977. }
  978. if (num_trans != NULL)
  979. {
  980. *num_trans = info_ptr->num_trans;
  981. retval |= PNG_INFO_tRNS;
  982. }
  983. }
  984. return retval;
  985. }
  986. #endif
  987. #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
  988. int PNGAPI
  989. png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
  990. png_unknown_chunkpp unknowns)
  991. {
  992. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  993. {
  994. *unknowns = info_ptr->unknown_chunks;
  995. return info_ptr->unknown_chunks_num;
  996. }
  997. return 0;
  998. }
  999. #endif
  1000. #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  1001. png_byte PNGAPI
  1002. png_get_rgb_to_gray_status(png_const_structrp png_ptr)
  1003. {
  1004. return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
  1005. }
  1006. #endif
  1007. #ifdef PNG_USER_CHUNKS_SUPPORTED
  1008. png_voidp PNGAPI
  1009. png_get_user_chunk_ptr(png_const_structrp png_ptr)
  1010. {
  1011. return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
  1012. }
  1013. #endif
  1014. size_t PNGAPI
  1015. png_get_compression_buffer_size(png_const_structrp png_ptr)
  1016. {
  1017. if (png_ptr == NULL)
  1018. return 0;
  1019. #ifdef PNG_WRITE_SUPPORTED
  1020. if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
  1021. #endif
  1022. {
  1023. #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
  1024. return png_ptr->IDAT_read_size;
  1025. #else
  1026. return PNG_IDAT_READ_SIZE;
  1027. #endif
  1028. }
  1029. #ifdef PNG_WRITE_SUPPORTED
  1030. else
  1031. return png_ptr->zbuffer_size;
  1032. #endif
  1033. }
  1034. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  1035. /* These functions were added to libpng 1.2.6 and were enabled
  1036. * by default in libpng-1.4.0 */
  1037. png_uint_32 PNGAPI
  1038. png_get_user_width_max(png_const_structrp png_ptr)
  1039. {
  1040. return (png_ptr ? png_ptr->user_width_max : 0);
  1041. }
  1042. png_uint_32 PNGAPI
  1043. png_get_user_height_max(png_const_structrp png_ptr)
  1044. {
  1045. return (png_ptr ? png_ptr->user_height_max : 0);
  1046. }
  1047. /* This function was added to libpng 1.4.0 */
  1048. png_uint_32 PNGAPI
  1049. png_get_chunk_cache_max(png_const_structrp png_ptr)
  1050. {
  1051. return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
  1052. }
  1053. /* This function was added to libpng 1.4.1 */
  1054. png_alloc_size_t PNGAPI
  1055. png_get_chunk_malloc_max(png_const_structrp png_ptr)
  1056. {
  1057. return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
  1058. }
  1059. #endif /* SET_USER_LIMITS */
  1060. /* These functions were added to libpng 1.4.0 */
  1061. #ifdef PNG_IO_STATE_SUPPORTED
  1062. png_uint_32 PNGAPI
  1063. png_get_io_state(png_const_structrp png_ptr)
  1064. {
  1065. return png_ptr->io_state;
  1066. }
  1067. png_uint_32 PNGAPI
  1068. png_get_io_chunk_type(png_const_structrp png_ptr)
  1069. {
  1070. return png_ptr->chunk_name;
  1071. }
  1072. #endif /* IO_STATE */
  1073. #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
  1074. # ifdef PNG_GET_PALETTE_MAX_SUPPORTED
  1075. int PNGAPI
  1076. png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
  1077. {
  1078. if (png_ptr != NULL && info_ptr != NULL)
  1079. return png_ptr->num_palette_max;
  1080. return -1;
  1081. }
  1082. # endif
  1083. #endif
  1084. #endif /* READ || WRITE */