pngget.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. /* pngget.c - retrieval of values from info struct
  2. *
  3. * Last changed in libpng 1.2.43 [February 25, 2010]
  4. * Copyright (c) 1998-2010 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. #define PNG_INTERNAL
  14. #define PNG_NO_PEDANTIC_WARNINGS
  15. #include "png.h"
  16. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  17. png_uint_32 PNGAPI
  18. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  19. {
  20. if (png_ptr != NULL && info_ptr != NULL)
  21. return(info_ptr->valid & flag);
  22. else
  23. return(0);
  24. }
  25. png_uint_32 PNGAPI
  26. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  27. {
  28. if (png_ptr != NULL && info_ptr != NULL)
  29. return(info_ptr->rowbytes);
  30. else
  31. return(0);
  32. }
  33. #ifdef PNG_INFO_IMAGE_SUPPORTED
  34. png_bytepp PNGAPI
  35. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  36. {
  37. if (png_ptr != NULL && info_ptr != NULL)
  38. return(info_ptr->row_pointers);
  39. else
  40. return(0);
  41. }
  42. #endif
  43. #ifdef PNG_EASY_ACCESS_SUPPORTED
  44. /* Easy access to info, added in libpng-0.99 */
  45. png_uint_32 PNGAPI
  46. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  47. {
  48. if (png_ptr != NULL && info_ptr != NULL)
  49. return info_ptr->width;
  50. return (0);
  51. }
  52. png_uint_32 PNGAPI
  53. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  54. {
  55. if (png_ptr != NULL && info_ptr != NULL)
  56. return info_ptr->height;
  57. return (0);
  58. }
  59. png_byte PNGAPI
  60. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  61. {
  62. if (png_ptr != NULL && info_ptr != NULL)
  63. return info_ptr->bit_depth;
  64. return (0);
  65. }
  66. png_byte PNGAPI
  67. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  68. {
  69. if (png_ptr != NULL && info_ptr != NULL)
  70. return info_ptr->color_type;
  71. return (0);
  72. }
  73. png_byte PNGAPI
  74. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  75. {
  76. if (png_ptr != NULL && info_ptr != NULL)
  77. return info_ptr->filter_type;
  78. return (0);
  79. }
  80. png_byte PNGAPI
  81. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  82. {
  83. if (png_ptr != NULL && info_ptr != NULL)
  84. return info_ptr->interlace_type;
  85. return (0);
  86. }
  87. png_byte PNGAPI
  88. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  89. {
  90. if (png_ptr != NULL && info_ptr != NULL)
  91. return info_ptr->compression_type;
  92. return (0);
  93. }
  94. png_uint_32 PNGAPI
  95. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  96. {
  97. if (png_ptr != NULL && info_ptr != NULL)
  98. #ifdef PNG_pHYs_SUPPORTED
  99. if (info_ptr->valid & PNG_INFO_pHYs)
  100. {
  101. png_debug1(1, "in %s retrieval function", "png_get_x_pixels_per_meter");
  102. if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  103. return (0);
  104. else
  105. return (info_ptr->x_pixels_per_unit);
  106. }
  107. #else
  108. return (0);
  109. #endif
  110. return (0);
  111. }
  112. png_uint_32 PNGAPI
  113. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  114. {
  115. if (png_ptr != NULL && info_ptr != NULL)
  116. #ifdef PNG_pHYs_SUPPORTED
  117. if (info_ptr->valid & PNG_INFO_pHYs)
  118. {
  119. png_debug1(1, "in %s retrieval function", "png_get_y_pixels_per_meter");
  120. if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  121. return (0);
  122. else
  123. return (info_ptr->y_pixels_per_unit);
  124. }
  125. #else
  126. return (0);
  127. #endif
  128. return (0);
  129. }
  130. png_uint_32 PNGAPI
  131. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  132. {
  133. if (png_ptr != NULL && info_ptr != NULL)
  134. #ifdef PNG_pHYs_SUPPORTED
  135. if (info_ptr->valid & PNG_INFO_pHYs)
  136. {
  137. png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
  138. if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  139. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  140. return (0);
  141. else
  142. return (info_ptr->x_pixels_per_unit);
  143. }
  144. #else
  145. return (0);
  146. #endif
  147. return (0);
  148. }
  149. #ifdef PNG_FLOATING_POINT_SUPPORTED
  150. float PNGAPI
  151. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  152. {
  153. if (png_ptr != NULL && info_ptr != NULL)
  154. #ifdef PNG_pHYs_SUPPORTED
  155. if (info_ptr->valid & PNG_INFO_pHYs)
  156. {
  157. png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
  158. if (info_ptr->x_pixels_per_unit == 0)
  159. return ((float)0.0);
  160. else
  161. return ((float)((float)info_ptr->y_pixels_per_unit
  162. /(float)info_ptr->x_pixels_per_unit));
  163. }
  164. #else
  165. return (0.0);
  166. #endif
  167. return ((float)0.0);
  168. }
  169. #endif
  170. png_int_32 PNGAPI
  171. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  172. {
  173. if (png_ptr != NULL && info_ptr != NULL)
  174. #ifdef PNG_oFFs_SUPPORTED
  175. if (info_ptr->valid & PNG_INFO_oFFs)
  176. {
  177. png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
  178. if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  179. return (0);
  180. else
  181. return (info_ptr->x_offset);
  182. }
  183. #else
  184. return (0);
  185. #endif
  186. return (0);
  187. }
  188. png_int_32 PNGAPI
  189. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  190. {
  191. if (png_ptr != NULL && info_ptr != NULL)
  192. #ifdef PNG_oFFs_SUPPORTED
  193. if (info_ptr->valid & PNG_INFO_oFFs)
  194. {
  195. png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
  196. if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  197. return (0);
  198. else
  199. return (info_ptr->y_offset);
  200. }
  201. #else
  202. return (0);
  203. #endif
  204. return (0);
  205. }
  206. png_int_32 PNGAPI
  207. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  208. {
  209. if (png_ptr != NULL && info_ptr != NULL)
  210. #ifdef PNG_oFFs_SUPPORTED
  211. if (info_ptr->valid & PNG_INFO_oFFs)
  212. {
  213. png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
  214. if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  215. return (0);
  216. else
  217. return (info_ptr->x_offset);
  218. }
  219. #else
  220. return (0);
  221. #endif
  222. return (0);
  223. }
  224. png_int_32 PNGAPI
  225. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  226. {
  227. if (png_ptr != NULL && info_ptr != NULL)
  228. #ifdef PNG_oFFs_SUPPORTED
  229. if (info_ptr->valid & PNG_INFO_oFFs)
  230. {
  231. png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
  232. if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  233. return (0);
  234. else
  235. return (info_ptr->y_offset);
  236. }
  237. #else
  238. return (0);
  239. #endif
  240. return (0);
  241. }
  242. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  243. png_uint_32 PNGAPI
  244. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  245. {
  246. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  247. *.0254 +.5));
  248. }
  249. png_uint_32 PNGAPI
  250. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  251. {
  252. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  253. *.0254 +.5));
  254. }
  255. png_uint_32 PNGAPI
  256. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  257. {
  258. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  259. *.0254 +.5));
  260. }
  261. float PNGAPI
  262. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  263. {
  264. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  265. *.00003937);
  266. }
  267. float PNGAPI
  268. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  269. {
  270. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  271. *.00003937);
  272. }
  273. #ifdef PNG_pHYs_SUPPORTED
  274. png_uint_32 PNGAPI
  275. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  276. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  277. {
  278. png_uint_32 retval = 0;
  279. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  280. {
  281. png_debug1(1, "in %s retrieval function", "pHYs");
  282. if (res_x != NULL)
  283. {
  284. *res_x = info_ptr->x_pixels_per_unit;
  285. retval |= PNG_INFO_pHYs;
  286. }
  287. if (res_y != NULL)
  288. {
  289. *res_y = info_ptr->y_pixels_per_unit;
  290. retval |= PNG_INFO_pHYs;
  291. }
  292. if (unit_type != NULL)
  293. {
  294. *unit_type = (int)info_ptr->phys_unit_type;
  295. retval |= PNG_INFO_pHYs;
  296. if (*unit_type == 1)
  297. {
  298. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  299. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  300. }
  301. }
  302. }
  303. return (retval);
  304. }
  305. #endif /* PNG_pHYs_SUPPORTED */
  306. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  307. /* png_get_channels really belongs in here, too, but it's been around longer */
  308. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  309. png_byte PNGAPI
  310. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  311. {
  312. if (png_ptr != NULL && info_ptr != NULL)
  313. return(info_ptr->channels);
  314. else
  315. return (0);
  316. }
  317. png_bytep PNGAPI
  318. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  319. {
  320. if (png_ptr != NULL && info_ptr != NULL)
  321. return(info_ptr->signature);
  322. else
  323. return (NULL);
  324. }
  325. #ifdef PNG_bKGD_SUPPORTED
  326. png_uint_32 PNGAPI
  327. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  328. png_color_16p *background)
  329. {
  330. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  331. && background != NULL)
  332. {
  333. png_debug1(1, "in %s retrieval function", "bKGD");
  334. *background = &(info_ptr->background);
  335. return (PNG_INFO_bKGD);
  336. }
  337. return (0);
  338. }
  339. #endif
  340. #ifdef PNG_cHRM_SUPPORTED
  341. #ifdef PNG_FLOATING_POINT_SUPPORTED
  342. png_uint_32 PNGAPI
  343. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  344. double *white_x, double *white_y, double *red_x, double *red_y,
  345. double *green_x, double *green_y, double *blue_x, double *blue_y)
  346. {
  347. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  348. {
  349. png_debug1(1, "in %s retrieval function", "cHRM");
  350. if (white_x != NULL)
  351. *white_x = (double)info_ptr->x_white;
  352. if (white_y != NULL)
  353. *white_y = (double)info_ptr->y_white;
  354. if (red_x != NULL)
  355. *red_x = (double)info_ptr->x_red;
  356. if (red_y != NULL)
  357. *red_y = (double)info_ptr->y_red;
  358. if (green_x != NULL)
  359. *green_x = (double)info_ptr->x_green;
  360. if (green_y != NULL)
  361. *green_y = (double)info_ptr->y_green;
  362. if (blue_x != NULL)
  363. *blue_x = (double)info_ptr->x_blue;
  364. if (blue_y != NULL)
  365. *blue_y = (double)info_ptr->y_blue;
  366. return (PNG_INFO_cHRM);
  367. }
  368. return (0);
  369. }
  370. #endif
  371. #ifdef PNG_FIXED_POINT_SUPPORTED
  372. png_uint_32 PNGAPI
  373. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  374. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  375. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  376. png_fixed_point *blue_x, png_fixed_point *blue_y)
  377. {
  378. png_debug1(1, "in %s retrieval function", "cHRM");
  379. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  380. {
  381. if (white_x != NULL)
  382. *white_x = info_ptr->int_x_white;
  383. if (white_y != NULL)
  384. *white_y = info_ptr->int_y_white;
  385. if (red_x != NULL)
  386. *red_x = info_ptr->int_x_red;
  387. if (red_y != NULL)
  388. *red_y = info_ptr->int_y_red;
  389. if (green_x != NULL)
  390. *green_x = info_ptr->int_x_green;
  391. if (green_y != NULL)
  392. *green_y = info_ptr->int_y_green;
  393. if (blue_x != NULL)
  394. *blue_x = info_ptr->int_x_blue;
  395. if (blue_y != NULL)
  396. *blue_y = info_ptr->int_y_blue;
  397. return (PNG_INFO_cHRM);
  398. }
  399. return (0);
  400. }
  401. #endif
  402. #endif
  403. #ifdef PNG_gAMA_SUPPORTED
  404. #ifdef PNG_FLOATING_POINT_SUPPORTED
  405. png_uint_32 PNGAPI
  406. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  407. {
  408. png_debug1(1, "in %s retrieval function", "gAMA");
  409. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  410. && file_gamma != NULL)
  411. {
  412. *file_gamma = (double)info_ptr->gamma;
  413. return (PNG_INFO_gAMA);
  414. }
  415. return (0);
  416. }
  417. #endif
  418. #ifdef PNG_FIXED_POINT_SUPPORTED
  419. png_uint_32 PNGAPI
  420. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  421. png_fixed_point *int_file_gamma)
  422. {
  423. png_debug1(1, "in %s retrieval function", "gAMA");
  424. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  425. && int_file_gamma != NULL)
  426. {
  427. *int_file_gamma = info_ptr->int_gamma;
  428. return (PNG_INFO_gAMA);
  429. }
  430. return (0);
  431. }
  432. #endif
  433. #endif
  434. #ifdef PNG_sRGB_SUPPORTED
  435. png_uint_32 PNGAPI
  436. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  437. {
  438. png_debug1(1, "in %s retrieval function", "sRGB");
  439. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  440. && file_srgb_intent != NULL)
  441. {
  442. *file_srgb_intent = (int)info_ptr->srgb_intent;
  443. return (PNG_INFO_sRGB);
  444. }
  445. return (0);
  446. }
  447. #endif
  448. #ifdef PNG_iCCP_SUPPORTED
  449. png_uint_32 PNGAPI
  450. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  451. png_charpp name, int *compression_type,
  452. png_charpp profile, png_uint_32 *proflen)
  453. {
  454. png_debug1(1, "in %s retrieval function", "iCCP");
  455. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  456. && name != NULL && profile != NULL && proflen != NULL)
  457. {
  458. *name = info_ptr->iccp_name;
  459. *profile = info_ptr->iccp_profile;
  460. /* Compression_type is a dummy so the API won't have to change
  461. * if we introduce multiple compression types later.
  462. */
  463. *proflen = (int)info_ptr->iccp_proflen;
  464. *compression_type = (int)info_ptr->iccp_compression;
  465. return (PNG_INFO_iCCP);
  466. }
  467. return (0);
  468. }
  469. #endif
  470. #ifdef PNG_sPLT_SUPPORTED
  471. png_uint_32 PNGAPI
  472. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  473. png_sPLT_tpp spalettes)
  474. {
  475. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  476. {
  477. *spalettes = info_ptr->splt_palettes;
  478. return ((png_uint_32)info_ptr->splt_palettes_num);
  479. }
  480. return (0);
  481. }
  482. #endif
  483. #ifdef PNG_hIST_SUPPORTED
  484. png_uint_32 PNGAPI
  485. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  486. {
  487. png_debug1(1, "in %s retrieval function", "hIST");
  488. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  489. && hist != NULL)
  490. {
  491. *hist = info_ptr->hist;
  492. return (PNG_INFO_hIST);
  493. }
  494. return (0);
  495. }
  496. #endif
  497. png_uint_32 PNGAPI
  498. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  499. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  500. int *color_type, int *interlace_type, int *compression_type,
  501. int *filter_type)
  502. {
  503. png_debug1(1, "in %s retrieval function", "IHDR");
  504. if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
  505. height == NULL || bit_depth == NULL || color_type == NULL)
  506. return (0);
  507. *width = info_ptr->width;
  508. *height = info_ptr->height;
  509. *bit_depth = info_ptr->bit_depth;
  510. *color_type = info_ptr->color_type;
  511. if (compression_type != NULL)
  512. *compression_type = info_ptr->compression_type;
  513. if (filter_type != NULL)
  514. *filter_type = info_ptr->filter_type;
  515. if (interlace_type != NULL)
  516. *interlace_type = info_ptr->interlace_type;
  517. /* This is redundant if we can be sure that the info_ptr values were all
  518. * assigned in png_set_IHDR(). We do the check anyhow in case an
  519. * application has ignored our advice not to mess with the members
  520. * of info_ptr directly.
  521. */
  522. png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
  523. info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
  524. info_ptr->compression_type, info_ptr->filter_type);
  525. return (1);
  526. }
  527. #ifdef PNG_oFFs_SUPPORTED
  528. png_uint_32 PNGAPI
  529. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  530. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  531. {
  532. png_debug1(1, "in %s retrieval function", "oFFs");
  533. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  534. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  535. {
  536. *offset_x = info_ptr->x_offset;
  537. *offset_y = info_ptr->y_offset;
  538. *unit_type = (int)info_ptr->offset_unit_type;
  539. return (PNG_INFO_oFFs);
  540. }
  541. return (0);
  542. }
  543. #endif
  544. #ifdef PNG_pCAL_SUPPORTED
  545. png_uint_32 PNGAPI
  546. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  547. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  548. png_charp *units, png_charpp *params)
  549. {
  550. png_debug1(1, "in %s retrieval function", "pCAL");
  551. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  552. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  553. nparams != NULL && units != NULL && params != NULL)
  554. {
  555. *purpose = info_ptr->pcal_purpose;
  556. *X0 = info_ptr->pcal_X0;
  557. *X1 = info_ptr->pcal_X1;
  558. *type = (int)info_ptr->pcal_type;
  559. *nparams = (int)info_ptr->pcal_nparams;
  560. *units = info_ptr->pcal_units;
  561. *params = info_ptr->pcal_params;
  562. return (PNG_INFO_pCAL);
  563. }
  564. return (0);
  565. }
  566. #endif
  567. #ifdef PNG_sCAL_SUPPORTED
  568. #ifdef PNG_FLOATING_POINT_SUPPORTED
  569. png_uint_32 PNGAPI
  570. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  571. int *unit, double *width, double *height)
  572. {
  573. if (png_ptr != NULL && info_ptr != NULL &&
  574. (info_ptr->valid & PNG_INFO_sCAL))
  575. {
  576. *unit = info_ptr->scal_unit;
  577. *width = info_ptr->scal_pixel_width;
  578. *height = info_ptr->scal_pixel_height;
  579. return (PNG_INFO_sCAL);
  580. }
  581. return(0);
  582. }
  583. #else
  584. #ifdef PNG_FIXED_POINT_SUPPORTED
  585. png_uint_32 PNGAPI
  586. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  587. int *unit, png_charpp width, png_charpp height)
  588. {
  589. if (png_ptr != NULL && info_ptr != NULL &&
  590. (info_ptr->valid & PNG_INFO_sCAL))
  591. {
  592. *unit = info_ptr->scal_unit;
  593. *width = info_ptr->scal_s_width;
  594. *height = info_ptr->scal_s_height;
  595. return (PNG_INFO_sCAL);
  596. }
  597. return(0);
  598. }
  599. #endif
  600. #endif
  601. #endif
  602. #ifdef PNG_pHYs_SUPPORTED
  603. png_uint_32 PNGAPI
  604. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  605. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  606. {
  607. png_uint_32 retval = 0;
  608. png_debug1(1, "in %s retrieval function", "pHYs");
  609. if (png_ptr != NULL && info_ptr != NULL &&
  610. (info_ptr->valid & PNG_INFO_pHYs))
  611. {
  612. if (res_x != NULL)
  613. {
  614. *res_x = info_ptr->x_pixels_per_unit;
  615. retval |= PNG_INFO_pHYs;
  616. }
  617. if (res_y != NULL)
  618. {
  619. *res_y = info_ptr->y_pixels_per_unit;
  620. retval |= PNG_INFO_pHYs;
  621. }
  622. if (unit_type != NULL)
  623. {
  624. *unit_type = (int)info_ptr->phys_unit_type;
  625. retval |= PNG_INFO_pHYs;
  626. }
  627. }
  628. return (retval);
  629. }
  630. #endif
  631. png_uint_32 PNGAPI
  632. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  633. int *num_palette)
  634. {
  635. png_debug1(1, "in %s retrieval function", "PLTE");
  636. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  637. && palette != NULL)
  638. {
  639. *palette = info_ptr->palette;
  640. *num_palette = info_ptr->num_palette;
  641. png_debug1(3, "num_palette = %d", *num_palette);
  642. return (PNG_INFO_PLTE);
  643. }
  644. return (0);
  645. }
  646. #ifdef PNG_sBIT_SUPPORTED
  647. png_uint_32 PNGAPI
  648. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  649. {
  650. png_debug1(1, "in %s retrieval function", "sBIT");
  651. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  652. && sig_bit != NULL)
  653. {
  654. *sig_bit = &(info_ptr->sig_bit);
  655. return (PNG_INFO_sBIT);
  656. }
  657. return (0);
  658. }
  659. #endif
  660. #ifdef PNG_TEXT_SUPPORTED
  661. png_uint_32 PNGAPI
  662. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  663. int *num_text)
  664. {
  665. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  666. {
  667. png_debug1(1, "in %s retrieval function",
  668. (png_ptr->chunk_name[0] == '\0' ? "text"
  669. : (png_const_charp)png_ptr->chunk_name));
  670. if (text_ptr != NULL)
  671. *text_ptr = info_ptr->text;
  672. if (num_text != NULL)
  673. *num_text = info_ptr->num_text;
  674. return ((png_uint_32)info_ptr->num_text);
  675. }
  676. if (num_text != NULL)
  677. *num_text = 0;
  678. return(0);
  679. }
  680. #endif
  681. #ifdef PNG_tIME_SUPPORTED
  682. png_uint_32 PNGAPI
  683. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  684. {
  685. png_debug1(1, "in %s retrieval function", "tIME");
  686. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  687. && mod_time != NULL)
  688. {
  689. *mod_time = &(info_ptr->mod_time);
  690. return (PNG_INFO_tIME);
  691. }
  692. return (0);
  693. }
  694. #endif
  695. #ifdef PNG_tRNS_SUPPORTED
  696. png_uint_32 PNGAPI
  697. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  698. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  699. {
  700. png_uint_32 retval = 0;
  701. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  702. {
  703. png_debug1(1, "in %s retrieval function", "tRNS");
  704. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  705. {
  706. if (trans != NULL)
  707. {
  708. *trans = info_ptr->trans;
  709. retval |= PNG_INFO_tRNS;
  710. }
  711. if (trans_values != NULL)
  712. *trans_values = &(info_ptr->trans_values);
  713. }
  714. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  715. {
  716. if (trans_values != NULL)
  717. {
  718. *trans_values = &(info_ptr->trans_values);
  719. retval |= PNG_INFO_tRNS;
  720. }
  721. if (trans != NULL)
  722. *trans = NULL;
  723. }
  724. if (num_trans != NULL)
  725. {
  726. *num_trans = info_ptr->num_trans;
  727. retval |= PNG_INFO_tRNS;
  728. }
  729. }
  730. return (retval);
  731. }
  732. #endif
  733. #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
  734. png_uint_32 PNGAPI
  735. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  736. png_unknown_chunkpp unknowns)
  737. {
  738. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  739. {
  740. *unknowns = info_ptr->unknown_chunks;
  741. return ((png_uint_32)info_ptr->unknown_chunks_num);
  742. }
  743. return (0);
  744. }
  745. #endif
  746. #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  747. png_byte PNGAPI
  748. png_get_rgb_to_gray_status (png_structp png_ptr)
  749. {
  750. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  751. }
  752. #endif
  753. #ifdef PNG_USER_CHUNKS_SUPPORTED
  754. png_voidp PNGAPI
  755. png_get_user_chunk_ptr(png_structp png_ptr)
  756. {
  757. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  758. }
  759. #endif
  760. png_uint_32 PNGAPI
  761. png_get_compression_buffer_size(png_structp png_ptr)
  762. {
  763. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  764. }
  765. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  766. #ifndef PNG_1_0_X
  767. /* This function was added to libpng 1.2.0 and should exist by default */
  768. png_uint_32 PNGAPI
  769. png_get_asm_flags (png_structp png_ptr)
  770. {
  771. /* Obsolete, to be removed from libpng-1.4.0 */
  772. return (png_ptr? 0L: 0L);
  773. }
  774. /* This function was added to libpng 1.2.0 and should exist by default */
  775. png_uint_32 PNGAPI
  776. png_get_asm_flagmask (int flag_select)
  777. {
  778. /* Obsolete, to be removed from libpng-1.4.0 */
  779. flag_select=flag_select;
  780. return 0L;
  781. }
  782. /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
  783. /* This function was added to libpng 1.2.0 */
  784. png_uint_32 PNGAPI
  785. png_get_mmx_flagmask (int flag_select, int *compilerID)
  786. {
  787. /* Obsolete, to be removed from libpng-1.4.0 */
  788. flag_select=flag_select;
  789. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  790. return 0L;
  791. }
  792. /* This function was added to libpng 1.2.0 */
  793. png_byte PNGAPI
  794. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  795. {
  796. /* Obsolete, to be removed from libpng-1.4.0 */
  797. return (png_ptr? 0: 0);
  798. }
  799. /* This function was added to libpng 1.2.0 */
  800. png_uint_32 PNGAPI
  801. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  802. {
  803. /* Obsolete, to be removed from libpng-1.4.0 */
  804. return (png_ptr? 0L: 0L);
  805. }
  806. #endif /* ?PNG_1_0_X */
  807. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  808. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  809. /* These functions were added to libpng 1.2.6 but not enabled
  810. * by default. They will be enabled in libpng-1.4.0 */
  811. png_uint_32 PNGAPI
  812. png_get_user_width_max (png_structp png_ptr)
  813. {
  814. return (png_ptr? png_ptr->user_width_max : 0);
  815. }
  816. png_uint_32 PNGAPI
  817. png_get_user_height_max (png_structp png_ptr)
  818. {
  819. return (png_ptr? png_ptr->user_height_max : 0);
  820. }
  821. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  822. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */