pngget.c 33 KB

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