pngget.c 26 KB

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