pngget.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370
  1. /* pngget.c - retrieval of values from info struct
  2. *
  3. * Copyright (c) 2018-2025 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. png_fixed_point result;
  327. if (png_muldiv(&result, microns, 500, 127) != 0)
  328. return result;
  329. png_warning(png_ptr, "fixed point overflow ignored");
  330. return 0;
  331. }
  332. png_fixed_point PNGAPI
  333. png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
  334. png_const_inforp info_ptr)
  335. {
  336. return png_fixed_inches_from_microns(png_ptr,
  337. png_get_x_offset_microns(png_ptr, info_ptr));
  338. }
  339. #endif /* FIXED_POINT */
  340. #ifdef PNG_FIXED_POINT_SUPPORTED
  341. png_fixed_point PNGAPI
  342. png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
  343. png_const_inforp info_ptr)
  344. {
  345. return png_fixed_inches_from_microns(png_ptr,
  346. png_get_y_offset_microns(png_ptr, info_ptr));
  347. }
  348. #endif
  349. #ifdef PNG_FLOATING_POINT_SUPPORTED
  350. float PNGAPI
  351. png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
  352. {
  353. /* To avoid the overflow do the conversion directly in floating
  354. * point.
  355. */
  356. return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
  357. }
  358. #endif
  359. #ifdef PNG_FLOATING_POINT_SUPPORTED
  360. float PNGAPI
  361. png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)
  362. {
  363. /* To avoid the overflow do the conversion directly in floating
  364. * point.
  365. */
  366. return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
  367. }
  368. #endif
  369. #ifdef PNG_pHYs_SUPPORTED
  370. png_uint_32 PNGAPI
  371. png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
  372. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  373. {
  374. png_uint_32 retval = 0;
  375. png_debug1(1, "in %s retrieval function", "pHYs");
  376. if (png_ptr != NULL && info_ptr != NULL &&
  377. (info_ptr->valid & PNG_INFO_pHYs) != 0)
  378. {
  379. if (res_x != NULL)
  380. {
  381. *res_x = info_ptr->x_pixels_per_unit;
  382. retval |= PNG_INFO_pHYs;
  383. }
  384. if (res_y != NULL)
  385. {
  386. *res_y = info_ptr->y_pixels_per_unit;
  387. retval |= PNG_INFO_pHYs;
  388. }
  389. if (unit_type != NULL)
  390. {
  391. *unit_type = (int)info_ptr->phys_unit_type;
  392. retval |= PNG_INFO_pHYs;
  393. if (*unit_type == 1)
  394. {
  395. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  396. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  397. }
  398. }
  399. }
  400. return retval;
  401. }
  402. #endif /* pHYs */
  403. #endif /* INCH_CONVERSIONS */
  404. /* png_get_channels really belongs in here, too, but it's been around longer */
  405. #endif /* EASY_ACCESS */
  406. png_byte PNGAPI
  407. png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
  408. {
  409. if (png_ptr != NULL && info_ptr != NULL)
  410. return info_ptr->channels;
  411. return 0;
  412. }
  413. #ifdef PNG_READ_SUPPORTED
  414. png_const_bytep PNGAPI
  415. png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
  416. {
  417. if (png_ptr != NULL && info_ptr != NULL)
  418. return info_ptr->signature;
  419. return NULL;
  420. }
  421. #endif
  422. #ifdef PNG_bKGD_SUPPORTED
  423. png_uint_32 PNGAPI
  424. png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
  425. png_color_16p *background)
  426. {
  427. png_debug1(1, "in %s retrieval function", "bKGD");
  428. if (png_ptr != NULL && info_ptr != NULL &&
  429. (info_ptr->valid & PNG_INFO_bKGD) != 0 &&
  430. background != NULL)
  431. {
  432. *background = &(info_ptr->background);
  433. return PNG_INFO_bKGD;
  434. }
  435. return 0;
  436. }
  437. #endif
  438. #ifdef PNG_cHRM_SUPPORTED
  439. /* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
  440. * same time to correct the rgb grayscale coefficient defaults obtained from the
  441. * cHRM chunk in 1.5.4
  442. */
  443. # ifdef PNG_FLOATING_POINT_SUPPORTED
  444. png_uint_32 PNGAPI
  445. png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
  446. double *whitex, double *whitey, double *redx, double *redy,
  447. double *greenx, double *greeny, double *bluex, double *bluey)
  448. {
  449. png_debug1(1, "in %s retrieval function", "cHRM");
  450. /* PNGv3: this just returns the values store from the cHRM, if any. */
  451. if (png_ptr != NULL && info_ptr != NULL &&
  452. (info_ptr->valid & PNG_INFO_cHRM) != 0)
  453. {
  454. if (whitex != NULL)
  455. *whitex = png_float(png_ptr, info_ptr->cHRM.whitex, "cHRM wx");
  456. if (whitey != NULL)
  457. *whitey = png_float(png_ptr, info_ptr->cHRM.whitey, "cHRM wy");
  458. if (redx != NULL)
  459. *redx = png_float(png_ptr, info_ptr->cHRM.redx, "cHRM rx");
  460. if (redy != NULL)
  461. *redy = png_float(png_ptr, info_ptr->cHRM.redy, "cHRM ry");
  462. if (greenx != NULL)
  463. *greenx = png_float(png_ptr, info_ptr->cHRM.greenx, "cHRM gx");
  464. if (greeny != NULL)
  465. *greeny = png_float(png_ptr, info_ptr->cHRM.greeny, "cHRM gy");
  466. if (bluex != NULL)
  467. *bluex = png_float(png_ptr, info_ptr->cHRM.bluex, "cHRM bx");
  468. if (bluey != NULL)
  469. *bluey = png_float(png_ptr, info_ptr->cHRM.bluey, "cHRM by");
  470. return PNG_INFO_cHRM;
  471. }
  472. return 0;
  473. }
  474. png_uint_32 PNGAPI
  475. png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
  476. double *red_X, double *red_Y, double *red_Z, double *green_X,
  477. double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
  478. double *blue_Z)
  479. {
  480. png_XYZ XYZ;
  481. png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
  482. if (png_ptr != NULL && info_ptr != NULL &&
  483. (info_ptr->valid & PNG_INFO_cHRM) != 0 &&
  484. png_XYZ_from_xy(&XYZ, &info_ptr->cHRM) == 0)
  485. {
  486. if (red_X != NULL)
  487. *red_X = png_float(png_ptr, XYZ.red_X, "cHRM red X");
  488. if (red_Y != NULL)
  489. *red_Y = png_float(png_ptr, XYZ.red_Y, "cHRM red Y");
  490. if (red_Z != NULL)
  491. *red_Z = png_float(png_ptr, XYZ.red_Z, "cHRM red Z");
  492. if (green_X != NULL)
  493. *green_X = png_float(png_ptr, XYZ.green_X, "cHRM green X");
  494. if (green_Y != NULL)
  495. *green_Y = png_float(png_ptr, XYZ.green_Y, "cHRM green Y");
  496. if (green_Z != NULL)
  497. *green_Z = png_float(png_ptr, XYZ.green_Z, "cHRM green Z");
  498. if (blue_X != NULL)
  499. *blue_X = png_float(png_ptr, XYZ.blue_X, "cHRM blue X");
  500. if (blue_Y != NULL)
  501. *blue_Y = png_float(png_ptr, XYZ.blue_Y, "cHRM blue Y");
  502. if (blue_Z != NULL)
  503. *blue_Z = png_float(png_ptr, XYZ.blue_Z, "cHRM blue Z");
  504. return PNG_INFO_cHRM;
  505. }
  506. return 0;
  507. }
  508. # endif
  509. # ifdef PNG_FIXED_POINT_SUPPORTED
  510. png_uint_32 PNGAPI
  511. png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
  512. png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
  513. png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
  514. png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
  515. png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
  516. png_fixed_point *int_blue_Z)
  517. {
  518. png_XYZ XYZ;
  519. png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
  520. if (png_ptr != NULL && info_ptr != NULL &&
  521. (info_ptr->valid & PNG_INFO_cHRM) != 0U &&
  522. png_XYZ_from_xy(&XYZ, &info_ptr->cHRM) == 0)
  523. {
  524. if (int_red_X != NULL) *int_red_X = XYZ.red_X;
  525. if (int_red_Y != NULL) *int_red_Y = XYZ.red_Y;
  526. if (int_red_Z != NULL) *int_red_Z = XYZ.red_Z;
  527. if (int_green_X != NULL) *int_green_X = XYZ.green_X;
  528. if (int_green_Y != NULL) *int_green_Y = XYZ.green_Y;
  529. if (int_green_Z != NULL) *int_green_Z = XYZ.green_Z;
  530. if (int_blue_X != NULL) *int_blue_X = XYZ.blue_X;
  531. if (int_blue_Y != NULL) *int_blue_Y = XYZ.blue_Y;
  532. if (int_blue_Z != NULL) *int_blue_Z = XYZ.blue_Z;
  533. return PNG_INFO_cHRM;
  534. }
  535. return 0;
  536. }
  537. png_uint_32 PNGAPI
  538. png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
  539. png_fixed_point *whitex, png_fixed_point *whitey, png_fixed_point *redx,
  540. png_fixed_point *redy, png_fixed_point *greenx, png_fixed_point *greeny,
  541. png_fixed_point *bluex, png_fixed_point *bluey)
  542. {
  543. png_debug1(1, "in %s retrieval function", "cHRM");
  544. /* PNGv3: this just returns the values store from the cHRM, if any. */
  545. if (png_ptr != NULL && info_ptr != NULL &&
  546. (info_ptr->valid & PNG_INFO_cHRM) != 0)
  547. {
  548. if (whitex != NULL) *whitex = info_ptr->cHRM.whitex;
  549. if (whitey != NULL) *whitey = info_ptr->cHRM.whitey;
  550. if (redx != NULL) *redx = info_ptr->cHRM.redx;
  551. if (redy != NULL) *redy = info_ptr->cHRM.redy;
  552. if (greenx != NULL) *greenx = info_ptr->cHRM.greenx;
  553. if (greeny != NULL) *greeny = info_ptr->cHRM.greeny;
  554. if (bluex != NULL) *bluex = info_ptr->cHRM.bluex;
  555. if (bluey != NULL) *bluey = info_ptr->cHRM.bluey;
  556. return PNG_INFO_cHRM;
  557. }
  558. return 0;
  559. }
  560. # endif
  561. #endif
  562. #ifdef PNG_gAMA_SUPPORTED
  563. # ifdef PNG_FIXED_POINT_SUPPORTED
  564. png_uint_32 PNGAPI
  565. png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
  566. png_fixed_point *file_gamma)
  567. {
  568. png_debug1(1, "in %s retrieval function", "gAMA");
  569. /* PNGv3 compatibility: only report gAMA if it is really present. */
  570. if (png_ptr != NULL && info_ptr != NULL &&
  571. (info_ptr->valid & PNG_INFO_gAMA) != 0)
  572. {
  573. if (file_gamma != NULL) *file_gamma = info_ptr->gamma;
  574. return PNG_INFO_gAMA;
  575. }
  576. return 0;
  577. }
  578. # endif
  579. # ifdef PNG_FLOATING_POINT_SUPPORTED
  580. png_uint_32 PNGAPI
  581. png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
  582. double *file_gamma)
  583. {
  584. png_debug1(1, "in %s retrieval function", "gAMA(float)");
  585. /* PNGv3 compatibility: only report gAMA if it is really present. */
  586. if (png_ptr != NULL && info_ptr != NULL &&
  587. (info_ptr->valid & PNG_INFO_gAMA) != 0)
  588. {
  589. if (file_gamma != NULL)
  590. *file_gamma = png_float(png_ptr, info_ptr->gamma, "gAMA");
  591. return PNG_INFO_gAMA;
  592. }
  593. return 0;
  594. }
  595. # endif
  596. #endif
  597. #ifdef PNG_sRGB_SUPPORTED
  598. png_uint_32 PNGAPI
  599. png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
  600. int *file_srgb_intent)
  601. {
  602. png_debug1(1, "in %s retrieval function", "sRGB");
  603. if (png_ptr != NULL && info_ptr != NULL &&
  604. (info_ptr->valid & PNG_INFO_sRGB) != 0)
  605. {
  606. if (file_srgb_intent != NULL)
  607. *file_srgb_intent = info_ptr->rendering_intent;
  608. return PNG_INFO_sRGB;
  609. }
  610. return 0;
  611. }
  612. #endif
  613. #ifdef PNG_iCCP_SUPPORTED
  614. png_uint_32 PNGAPI
  615. png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
  616. png_charpp name, int *compression_type,
  617. png_bytepp profile, png_uint_32 *proflen)
  618. {
  619. png_debug1(1, "in %s retrieval function", "iCCP");
  620. if (png_ptr != NULL && info_ptr != NULL &&
  621. (info_ptr->valid & PNG_INFO_iCCP) != 0 &&
  622. name != NULL && profile != NULL && proflen != NULL)
  623. {
  624. *name = info_ptr->iccp_name;
  625. *profile = info_ptr->iccp_profile;
  626. *proflen = png_get_uint_32(info_ptr->iccp_profile);
  627. /* This is somewhat irrelevant since the profile data returned has
  628. * actually been uncompressed.
  629. */
  630. if (compression_type != NULL)
  631. *compression_type = PNG_COMPRESSION_TYPE_BASE;
  632. return PNG_INFO_iCCP;
  633. }
  634. return 0;
  635. }
  636. #endif
  637. #ifdef PNG_sPLT_SUPPORTED
  638. int PNGAPI
  639. png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
  640. png_sPLT_tpp spalettes)
  641. {
  642. png_debug1(1, "in %s retrieval function", "sPLT");
  643. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  644. {
  645. *spalettes = info_ptr->splt_palettes;
  646. return info_ptr->splt_palettes_num;
  647. }
  648. return 0;
  649. }
  650. #endif
  651. #ifdef PNG_cICP_SUPPORTED
  652. png_uint_32 PNGAPI
  653. png_get_cICP(png_const_structrp png_ptr,
  654. png_const_inforp info_ptr, png_bytep colour_primaries,
  655. png_bytep transfer_function, png_bytep matrix_coefficients,
  656. png_bytep video_full_range_flag)
  657. {
  658. png_debug1(1, "in %s retrieval function", "cICP");
  659. if (png_ptr != NULL && info_ptr != NULL &&
  660. (info_ptr->valid & PNG_INFO_cICP) != 0 &&
  661. colour_primaries != NULL && transfer_function != NULL &&
  662. matrix_coefficients != NULL && video_full_range_flag != NULL)
  663. {
  664. *colour_primaries = info_ptr->cicp_colour_primaries;
  665. *transfer_function = info_ptr->cicp_transfer_function;
  666. *matrix_coefficients = info_ptr->cicp_matrix_coefficients;
  667. *video_full_range_flag = info_ptr->cicp_video_full_range_flag;
  668. return (PNG_INFO_cICP);
  669. }
  670. return 0;
  671. }
  672. #endif
  673. #ifdef PNG_cLLI_SUPPORTED
  674. # ifdef PNG_FIXED_POINT_SUPPORTED
  675. png_uint_32 PNGAPI
  676. png_get_cLLI_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
  677. png_uint_32p maxCLL,
  678. png_uint_32p maxFALL)
  679. {
  680. png_debug1(1, "in %s retrieval function", "cLLI");
  681. if (png_ptr != NULL && info_ptr != NULL &&
  682. (info_ptr->valid & PNG_INFO_cLLI) != 0)
  683. {
  684. if (maxCLL != NULL) *maxCLL = info_ptr->maxCLL;
  685. if (maxFALL != NULL) *maxFALL = info_ptr->maxFALL;
  686. return PNG_INFO_cLLI;
  687. }
  688. return 0;
  689. }
  690. # endif
  691. # ifdef PNG_FLOATING_POINT_SUPPORTED
  692. png_uint_32 PNGAPI
  693. png_get_cLLI(png_const_structrp png_ptr, png_const_inforp info_ptr,
  694. double *maxCLL, double *maxFALL)
  695. {
  696. png_debug1(1, "in %s retrieval function", "cLLI(float)");
  697. if (png_ptr != NULL && info_ptr != NULL &&
  698. (info_ptr->valid & PNG_INFO_cLLI) != 0)
  699. {
  700. if (maxCLL != NULL) *maxCLL = info_ptr->maxCLL * .0001;
  701. if (maxFALL != NULL) *maxFALL = info_ptr->maxFALL * .0001;
  702. return PNG_INFO_cLLI;
  703. }
  704. return 0;
  705. }
  706. # endif
  707. #endif /* cLLI */
  708. #ifdef PNG_mDCV_SUPPORTED
  709. # ifdef PNG_FIXED_POINT_SUPPORTED
  710. png_uint_32 PNGAPI
  711. png_get_mDCV_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
  712. png_fixed_point *white_x, png_fixed_point *white_y,
  713. png_fixed_point *red_x, png_fixed_point *red_y,
  714. png_fixed_point *green_x, png_fixed_point *green_y,
  715. png_fixed_point *blue_x, png_fixed_point *blue_y,
  716. png_uint_32p mastering_maxDL, png_uint_32p mastering_minDL)
  717. {
  718. png_debug1(1, "in %s retrieval function", "mDCV");
  719. if (png_ptr != NULL && info_ptr != NULL &&
  720. (info_ptr->valid & PNG_INFO_mDCV) != 0)
  721. {
  722. if (white_x != NULL) *white_x = info_ptr->mastering_white_x * 2;
  723. if (white_y != NULL) *white_y = info_ptr->mastering_white_y * 2;
  724. if (red_x != NULL) *red_x = info_ptr->mastering_red_x * 2;
  725. if (red_y != NULL) *red_y = info_ptr->mastering_red_y * 2;
  726. if (green_x != NULL) *green_x = info_ptr->mastering_green_x * 2;
  727. if (green_y != NULL) *green_y = info_ptr->mastering_green_y * 2;
  728. if (blue_x != NULL) *blue_x = info_ptr->mastering_blue_x * 2;
  729. if (blue_y != NULL) *blue_y = info_ptr->mastering_blue_y * 2;
  730. if (mastering_maxDL != NULL) *mastering_maxDL = info_ptr->mastering_maxDL;
  731. if (mastering_minDL != NULL) *mastering_minDL = info_ptr->mastering_minDL;
  732. return PNG_INFO_mDCV;
  733. }
  734. return 0;
  735. }
  736. # endif
  737. # ifdef PNG_FLOATING_POINT_SUPPORTED
  738. png_uint_32 PNGAPI
  739. png_get_mDCV(png_const_structrp png_ptr, png_const_inforp info_ptr,
  740. double *white_x, double *white_y, double *red_x, double *red_y,
  741. double *green_x, double *green_y, double *blue_x, double *blue_y,
  742. double *mastering_maxDL, double *mastering_minDL)
  743. {
  744. png_debug1(1, "in %s retrieval function", "mDCV(float)");
  745. if (png_ptr != NULL && info_ptr != NULL &&
  746. (info_ptr->valid & PNG_INFO_mDCV) != 0)
  747. {
  748. if (white_x != NULL) *white_x = info_ptr->mastering_white_x * .00002;
  749. if (white_y != NULL) *white_y = info_ptr->mastering_white_y * .00002;
  750. if (red_x != NULL) *red_x = info_ptr->mastering_red_x * .00002;
  751. if (red_y != NULL) *red_y = info_ptr->mastering_red_y * .00002;
  752. if (green_x != NULL) *green_x = info_ptr->mastering_green_x * .00002;
  753. if (green_y != NULL) *green_y = info_ptr->mastering_green_y * .00002;
  754. if (blue_x != NULL) *blue_x = info_ptr->mastering_blue_x * .00002;
  755. if (blue_y != NULL) *blue_y = info_ptr->mastering_blue_y * .00002;
  756. if (mastering_maxDL != NULL)
  757. *mastering_maxDL = info_ptr->mastering_maxDL * .0001;
  758. if (mastering_minDL != NULL)
  759. *mastering_minDL = info_ptr->mastering_minDL * .0001;
  760. return PNG_INFO_mDCV;
  761. }
  762. return 0;
  763. }
  764. # endif /* FLOATING_POINT */
  765. #endif /* mDCV */
  766. #ifdef PNG_eXIf_SUPPORTED
  767. png_uint_32 PNGAPI
  768. png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
  769. png_bytep *exif)
  770. {
  771. png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1");
  772. PNG_UNUSED(info_ptr)
  773. PNG_UNUSED(exif)
  774. return 0;
  775. }
  776. png_uint_32 PNGAPI
  777. png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,
  778. png_uint_32 *num_exif, png_bytep *exif)
  779. {
  780. png_debug1(1, "in %s retrieval function", "eXIf");
  781. if (png_ptr != NULL && info_ptr != NULL &&
  782. (info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL)
  783. {
  784. *num_exif = info_ptr->num_exif;
  785. *exif = info_ptr->exif;
  786. return PNG_INFO_eXIf;
  787. }
  788. return 0;
  789. }
  790. #endif
  791. #ifdef PNG_hIST_SUPPORTED
  792. png_uint_32 PNGAPI
  793. png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
  794. png_uint_16p *hist)
  795. {
  796. png_debug1(1, "in %s retrieval function", "hIST");
  797. if (png_ptr != NULL && info_ptr != NULL &&
  798. (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
  799. {
  800. *hist = info_ptr->hist;
  801. return PNG_INFO_hIST;
  802. }
  803. return 0;
  804. }
  805. #endif
  806. png_uint_32 PNGAPI
  807. png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
  808. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  809. int *color_type, int *interlace_type, int *compression_type,
  810. int *filter_type)
  811. {
  812. png_debug1(1, "in %s retrieval function", "IHDR");
  813. if (png_ptr == NULL || info_ptr == NULL)
  814. return 0;
  815. if (width != NULL)
  816. *width = info_ptr->width;
  817. if (height != NULL)
  818. *height = info_ptr->height;
  819. if (bit_depth != NULL)
  820. *bit_depth = info_ptr->bit_depth;
  821. if (color_type != NULL)
  822. *color_type = info_ptr->color_type;
  823. if (compression_type != NULL)
  824. *compression_type = info_ptr->compression_type;
  825. if (filter_type != NULL)
  826. *filter_type = info_ptr->filter_type;
  827. if (interlace_type != NULL)
  828. *interlace_type = info_ptr->interlace_type;
  829. /* This is redundant if we can be sure that the info_ptr values were all
  830. * assigned in png_set_IHDR(). We do the check anyhow in case an
  831. * application has ignored our advice not to mess with the members
  832. * of info_ptr directly.
  833. */
  834. png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  835. info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
  836. info_ptr->compression_type, info_ptr->filter_type);
  837. return 1;
  838. }
  839. #ifdef PNG_oFFs_SUPPORTED
  840. png_uint_32 PNGAPI
  841. png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
  842. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  843. {
  844. png_debug1(1, "in %s retrieval function", "oFFs");
  845. if (png_ptr != NULL && info_ptr != NULL &&
  846. (info_ptr->valid & PNG_INFO_oFFs) != 0 &&
  847. offset_x != NULL && offset_y != NULL && unit_type != NULL)
  848. {
  849. *offset_x = info_ptr->x_offset;
  850. *offset_y = info_ptr->y_offset;
  851. *unit_type = (int)info_ptr->offset_unit_type;
  852. return PNG_INFO_oFFs;
  853. }
  854. return 0;
  855. }
  856. #endif
  857. #ifdef PNG_pCAL_SUPPORTED
  858. png_uint_32 PNGAPI
  859. png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
  860. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  861. png_charp *units, png_charpp *params)
  862. {
  863. png_debug1(1, "in %s retrieval function", "pCAL");
  864. if (png_ptr != NULL && info_ptr != NULL &&
  865. (info_ptr->valid & PNG_INFO_pCAL) != 0 &&
  866. purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  867. nparams != NULL && units != NULL && params != NULL)
  868. {
  869. *purpose = info_ptr->pcal_purpose;
  870. *X0 = info_ptr->pcal_X0;
  871. *X1 = info_ptr->pcal_X1;
  872. *type = (int)info_ptr->pcal_type;
  873. *nparams = (int)info_ptr->pcal_nparams;
  874. *units = info_ptr->pcal_units;
  875. *params = info_ptr->pcal_params;
  876. return PNG_INFO_pCAL;
  877. }
  878. return 0;
  879. }
  880. #endif
  881. #ifdef PNG_sCAL_SUPPORTED
  882. # ifdef PNG_FIXED_POINT_SUPPORTED
  883. # if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
  884. defined(PNG_FLOATING_POINT_SUPPORTED)
  885. png_uint_32 PNGAPI
  886. png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
  887. int *unit, png_fixed_point *width, png_fixed_point *height)
  888. {
  889. png_debug1(1, "in %s retrieval function", "sCAL");
  890. if (png_ptr != NULL && info_ptr != NULL &&
  891. (info_ptr->valid & PNG_INFO_sCAL) != 0)
  892. {
  893. *unit = info_ptr->scal_unit;
  894. /*TODO: make this work without FP support; the API is currently eliminated
  895. * if neither floating point APIs nor internal floating point arithmetic
  896. * are enabled.
  897. */
  898. *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
  899. *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
  900. "sCAL height");
  901. return PNG_INFO_sCAL;
  902. }
  903. return 0;
  904. }
  905. # endif /* FLOATING_ARITHMETIC */
  906. # endif /* FIXED_POINT */
  907. # ifdef PNG_FLOATING_POINT_SUPPORTED
  908. png_uint_32 PNGAPI
  909. png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
  910. int *unit, double *width, double *height)
  911. {
  912. png_debug1(1, "in %s retrieval function", "sCAL(float)");
  913. if (png_ptr != NULL && info_ptr != NULL &&
  914. (info_ptr->valid & PNG_INFO_sCAL) != 0)
  915. {
  916. *unit = info_ptr->scal_unit;
  917. *width = atof(info_ptr->scal_s_width);
  918. *height = atof(info_ptr->scal_s_height);
  919. return PNG_INFO_sCAL;
  920. }
  921. return 0;
  922. }
  923. # endif /* FLOATING POINT */
  924. png_uint_32 PNGAPI
  925. png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
  926. int *unit, png_charpp width, png_charpp height)
  927. {
  928. png_debug1(1, "in %s retrieval function", "sCAL(str)");
  929. if (png_ptr != NULL && info_ptr != NULL &&
  930. (info_ptr->valid & PNG_INFO_sCAL) != 0)
  931. {
  932. *unit = info_ptr->scal_unit;
  933. *width = info_ptr->scal_s_width;
  934. *height = info_ptr->scal_s_height;
  935. return PNG_INFO_sCAL;
  936. }
  937. return 0;
  938. }
  939. #endif /* sCAL */
  940. #ifdef PNG_pHYs_SUPPORTED
  941. png_uint_32 PNGAPI
  942. png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
  943. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  944. {
  945. png_uint_32 retval = 0;
  946. png_debug1(1, "in %s retrieval function", "pHYs");
  947. if (png_ptr != NULL && info_ptr != NULL &&
  948. (info_ptr->valid & PNG_INFO_pHYs) != 0)
  949. {
  950. if (res_x != NULL)
  951. {
  952. *res_x = info_ptr->x_pixels_per_unit;
  953. retval |= PNG_INFO_pHYs;
  954. }
  955. if (res_y != NULL)
  956. {
  957. *res_y = info_ptr->y_pixels_per_unit;
  958. retval |= PNG_INFO_pHYs;
  959. }
  960. if (unit_type != NULL)
  961. {
  962. *unit_type = (int)info_ptr->phys_unit_type;
  963. retval |= PNG_INFO_pHYs;
  964. }
  965. }
  966. return retval;
  967. }
  968. #endif /* pHYs */
  969. png_uint_32 PNGAPI
  970. png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
  971. png_colorp *palette, int *num_palette)
  972. {
  973. png_debug1(1, "in %s retrieval function", "PLTE");
  974. if (png_ptr != NULL && info_ptr != NULL &&
  975. (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
  976. {
  977. *palette = info_ptr->palette;
  978. *num_palette = info_ptr->num_palette;
  979. png_debug1(3, "num_palette = %d", *num_palette);
  980. return PNG_INFO_PLTE;
  981. }
  982. return 0;
  983. }
  984. #ifdef PNG_sBIT_SUPPORTED
  985. png_uint_32 PNGAPI
  986. png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
  987. png_color_8p *sig_bit)
  988. {
  989. png_debug1(1, "in %s retrieval function", "sBIT");
  990. if (png_ptr != NULL && info_ptr != NULL &&
  991. (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
  992. {
  993. *sig_bit = &(info_ptr->sig_bit);
  994. return PNG_INFO_sBIT;
  995. }
  996. return 0;
  997. }
  998. #endif
  999. #ifdef PNG_TEXT_SUPPORTED
  1000. int PNGAPI
  1001. png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
  1002. png_textp *text_ptr, int *num_text)
  1003. {
  1004. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  1005. {
  1006. png_debug1(1, "in text retrieval function, chunk typeid = 0x%lx",
  1007. (unsigned long)png_ptr->chunk_name);
  1008. if (text_ptr != NULL)
  1009. *text_ptr = info_ptr->text;
  1010. if (num_text != NULL)
  1011. *num_text = info_ptr->num_text;
  1012. return info_ptr->num_text;
  1013. }
  1014. if (num_text != NULL)
  1015. *num_text = 0;
  1016. return 0;
  1017. }
  1018. #endif
  1019. #ifdef PNG_tIME_SUPPORTED
  1020. png_uint_32 PNGAPI
  1021. png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
  1022. png_timep *mod_time)
  1023. {
  1024. png_debug1(1, "in %s retrieval function", "tIME");
  1025. if (png_ptr != NULL && info_ptr != NULL &&
  1026. (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
  1027. {
  1028. *mod_time = &(info_ptr->mod_time);
  1029. return PNG_INFO_tIME;
  1030. }
  1031. return 0;
  1032. }
  1033. #endif
  1034. #ifdef PNG_tRNS_SUPPORTED
  1035. png_uint_32 PNGAPI
  1036. png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
  1037. png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
  1038. {
  1039. png_uint_32 retval = 0;
  1040. png_debug1(1, "in %s retrieval function", "tRNS");
  1041. if (png_ptr != NULL && info_ptr != NULL &&
  1042. (info_ptr->valid & PNG_INFO_tRNS) != 0)
  1043. {
  1044. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  1045. {
  1046. if (trans_alpha != NULL)
  1047. {
  1048. *trans_alpha = info_ptr->trans_alpha;
  1049. retval |= PNG_INFO_tRNS;
  1050. }
  1051. if (trans_color != NULL)
  1052. *trans_color = &(info_ptr->trans_color);
  1053. }
  1054. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  1055. {
  1056. if (trans_color != NULL)
  1057. {
  1058. *trans_color = &(info_ptr->trans_color);
  1059. retval |= PNG_INFO_tRNS;
  1060. }
  1061. if (trans_alpha != NULL)
  1062. *trans_alpha = NULL;
  1063. }
  1064. if (num_trans != NULL)
  1065. {
  1066. *num_trans = info_ptr->num_trans;
  1067. retval |= PNG_INFO_tRNS;
  1068. }
  1069. }
  1070. return retval;
  1071. }
  1072. #endif
  1073. #ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
  1074. int PNGAPI
  1075. png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
  1076. png_unknown_chunkpp unknowns)
  1077. {
  1078. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  1079. {
  1080. *unknowns = info_ptr->unknown_chunks;
  1081. return info_ptr->unknown_chunks_num;
  1082. }
  1083. return 0;
  1084. }
  1085. #endif
  1086. #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  1087. png_byte PNGAPI
  1088. png_get_rgb_to_gray_status(png_const_structrp png_ptr)
  1089. {
  1090. return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
  1091. }
  1092. #endif
  1093. #ifdef PNG_USER_CHUNKS_SUPPORTED
  1094. png_voidp PNGAPI
  1095. png_get_user_chunk_ptr(png_const_structrp png_ptr)
  1096. {
  1097. return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
  1098. }
  1099. #endif
  1100. size_t PNGAPI
  1101. png_get_compression_buffer_size(png_const_structrp png_ptr)
  1102. {
  1103. if (png_ptr == NULL)
  1104. return 0;
  1105. #ifdef PNG_WRITE_SUPPORTED
  1106. if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
  1107. #endif
  1108. {
  1109. #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
  1110. return png_ptr->IDAT_read_size;
  1111. #else
  1112. return PNG_IDAT_READ_SIZE;
  1113. #endif
  1114. }
  1115. #ifdef PNG_WRITE_SUPPORTED
  1116. else
  1117. return png_ptr->zbuffer_size;
  1118. #endif
  1119. }
  1120. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  1121. /* These functions were added to libpng 1.2.6 and were enabled
  1122. * by default in libpng-1.4.0 */
  1123. png_uint_32 PNGAPI
  1124. png_get_user_width_max(png_const_structrp png_ptr)
  1125. {
  1126. return (png_ptr ? png_ptr->user_width_max : 0);
  1127. }
  1128. png_uint_32 PNGAPI
  1129. png_get_user_height_max(png_const_structrp png_ptr)
  1130. {
  1131. return (png_ptr ? png_ptr->user_height_max : 0);
  1132. }
  1133. /* This function was added to libpng 1.4.0 */
  1134. png_uint_32 PNGAPI
  1135. png_get_chunk_cache_max(png_const_structrp png_ptr)
  1136. {
  1137. return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
  1138. }
  1139. /* This function was added to libpng 1.4.1 */
  1140. png_alloc_size_t PNGAPI
  1141. png_get_chunk_malloc_max(png_const_structrp png_ptr)
  1142. {
  1143. return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
  1144. }
  1145. #endif /* SET_USER_LIMITS */
  1146. /* These functions were added to libpng 1.4.0 */
  1147. #ifdef PNG_IO_STATE_SUPPORTED
  1148. png_uint_32 PNGAPI
  1149. png_get_io_state(png_const_structrp png_ptr)
  1150. {
  1151. return png_ptr->io_state;
  1152. }
  1153. png_uint_32 PNGAPI
  1154. png_get_io_chunk_type(png_const_structrp png_ptr)
  1155. {
  1156. return png_ptr->chunk_name;
  1157. }
  1158. #endif /* IO_STATE */
  1159. #ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
  1160. # ifdef PNG_GET_PALETTE_MAX_SUPPORTED
  1161. int PNGAPI
  1162. png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
  1163. {
  1164. if (png_ptr != NULL && info_ptr != NULL)
  1165. return png_ptr->num_palette_max;
  1166. return -1;
  1167. }
  1168. # endif
  1169. #endif
  1170. #endif /* READ || WRITE */