/src/compiler/android/jni/ftk/pngset.c

http://ftk.googlecode.com/ · C · 1226 lines · 1017 code · 148 blank · 61 comment · 242 complexity · 6a6bb67d8bd5f832d2f80e33c7884ebf MD5 · raw file

  1. /* pngset.c - storage of image information into 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. * The functions here are used during reads to store data from the file
  13. * into the info struct, and during writes to store application data
  14. * into the info struct for writing into the file. This abstracts the
  15. * info struct and allows us to change the structure in the future.
  16. */
  17. #define PNG_INTERNAL
  18. #define PNG_NO_PEDANTIC_WARNINGS
  19. #include "png.h"
  20. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  21. #ifdef PNG_bKGD_SUPPORTED
  22. void PNGAPI
  23. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  24. {
  25. png_debug1(1, "in %s storage function", "bKGD");
  26. if (png_ptr == NULL || info_ptr == NULL)
  27. return;
  28. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  29. info_ptr->valid |= PNG_INFO_bKGD;
  30. }
  31. #endif
  32. #ifdef PNG_cHRM_SUPPORTED
  33. #ifdef PNG_FLOATING_POINT_SUPPORTED
  34. void PNGAPI
  35. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  36. double white_x, double white_y, double red_x, double red_y,
  37. double green_x, double green_y, double blue_x, double blue_y)
  38. {
  39. png_debug1(1, "in %s storage function", "cHRM");
  40. if (png_ptr == NULL || info_ptr == NULL)
  41. return;
  42. info_ptr->x_white = (float)white_x;
  43. info_ptr->y_white = (float)white_y;
  44. info_ptr->x_red = (float)red_x;
  45. info_ptr->y_red = (float)red_y;
  46. info_ptr->x_green = (float)green_x;
  47. info_ptr->y_green = (float)green_y;
  48. info_ptr->x_blue = (float)blue_x;
  49. info_ptr->y_blue = (float)blue_y;
  50. #ifdef PNG_FIXED_POINT_SUPPORTED
  51. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  52. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  53. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  54. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  55. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  56. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  57. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  58. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  59. #endif
  60. info_ptr->valid |= PNG_INFO_cHRM;
  61. }
  62. #endif /* PNG_FLOATING_POINT_SUPPORTED */
  63. #ifdef PNG_FIXED_POINT_SUPPORTED
  64. void PNGAPI
  65. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  66. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  67. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  68. png_fixed_point blue_x, png_fixed_point blue_y)
  69. {
  70. png_debug1(1, "in %s storage function", "cHRM fixed");
  71. if (png_ptr == NULL || info_ptr == NULL)
  72. return;
  73. #ifdef PNG_CHECK_cHRM_SUPPORTED
  74. if (png_check_cHRM_fixed(png_ptr,
  75. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
  76. #endif
  77. {
  78. info_ptr->int_x_white = white_x;
  79. info_ptr->int_y_white = white_y;
  80. info_ptr->int_x_red = red_x;
  81. info_ptr->int_y_red = red_y;
  82. info_ptr->int_x_green = green_x;
  83. info_ptr->int_y_green = green_y;
  84. info_ptr->int_x_blue = blue_x;
  85. info_ptr->int_y_blue = blue_y;
  86. #ifdef PNG_FLOATING_POINT_SUPPORTED
  87. info_ptr->x_white = (float)(white_x/100000.);
  88. info_ptr->y_white = (float)(white_y/100000.);
  89. info_ptr->x_red = (float)( red_x/100000.);
  90. info_ptr->y_red = (float)( red_y/100000.);
  91. info_ptr->x_green = (float)(green_x/100000.);
  92. info_ptr->y_green = (float)(green_y/100000.);
  93. info_ptr->x_blue = (float)( blue_x/100000.);
  94. info_ptr->y_blue = (float)( blue_y/100000.);
  95. #endif
  96. info_ptr->valid |= PNG_INFO_cHRM;
  97. }
  98. }
  99. #endif /* PNG_FIXED_POINT_SUPPORTED */
  100. #endif /* PNG_cHRM_SUPPORTED */
  101. #ifdef PNG_gAMA_SUPPORTED
  102. #ifdef PNG_FLOATING_POINT_SUPPORTED
  103. void PNGAPI
  104. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  105. {
  106. double png_gamma;
  107. png_debug1(1, "in %s storage function", "gAMA");
  108. if (png_ptr == NULL || info_ptr == NULL)
  109. return;
  110. /* Check for overflow */
  111. if (file_gamma > 21474.83)
  112. {
  113. png_warning(png_ptr, "Limiting gamma to 21474.83");
  114. png_gamma=21474.83;
  115. }
  116. else
  117. png_gamma = file_gamma;
  118. info_ptr->gamma = (float)png_gamma;
  119. #ifdef PNG_FIXED_POINT_SUPPORTED
  120. info_ptr->int_gamma = (int)(png_gamma*100000.+.5);
  121. #endif
  122. info_ptr->valid |= PNG_INFO_gAMA;
  123. if (png_gamma == 0.0)
  124. png_warning(png_ptr, "Setting gamma=0");
  125. }
  126. #endif
  127. void PNGAPI
  128. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  129. int_gamma)
  130. {
  131. png_fixed_point png_gamma;
  132. png_debug1(1, "in %s storage function", "gAMA");
  133. if (png_ptr == NULL || info_ptr == NULL)
  134. return;
  135. if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX)
  136. {
  137. png_warning(png_ptr, "Limiting gamma to 21474.83");
  138. png_gamma=PNG_UINT_31_MAX;
  139. }
  140. else
  141. {
  142. if (int_gamma < 0)
  143. {
  144. png_warning(png_ptr, "Setting negative gamma to zero");
  145. png_gamma = 0;
  146. }
  147. else
  148. png_gamma = int_gamma;
  149. }
  150. #ifdef PNG_FLOATING_POINT_SUPPORTED
  151. info_ptr->gamma = (float)(png_gamma/100000.);
  152. #endif
  153. #ifdef PNG_FIXED_POINT_SUPPORTED
  154. info_ptr->int_gamma = png_gamma;
  155. #endif
  156. info_ptr->valid |= PNG_INFO_gAMA;
  157. if (png_gamma == 0)
  158. png_warning(png_ptr, "Setting gamma=0");
  159. }
  160. #endif
  161. #ifdef PNG_hIST_SUPPORTED
  162. void PNGAPI
  163. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  164. {
  165. int i;
  166. png_debug1(1, "in %s storage function", "hIST");
  167. if (png_ptr == NULL || info_ptr == NULL)
  168. return;
  169. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  170. > PNG_MAX_PALETTE_LENGTH)
  171. {
  172. png_warning(png_ptr,
  173. "Invalid palette size, hIST allocation skipped.");
  174. return;
  175. }
  176. #ifdef PNG_FREE_ME_SUPPORTED
  177. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  178. #endif
  179. /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
  180. * version 1.2.1
  181. */
  182. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  183. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)));
  184. if (png_ptr->hist == NULL)
  185. {
  186. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  187. return;
  188. }
  189. for (i = 0; i < info_ptr->num_palette; i++)
  190. png_ptr->hist[i] = hist[i];
  191. info_ptr->hist = png_ptr->hist;
  192. info_ptr->valid |= PNG_INFO_hIST;
  193. #ifdef PNG_FREE_ME_SUPPORTED
  194. info_ptr->free_me |= PNG_FREE_HIST;
  195. #else
  196. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  197. #endif
  198. }
  199. #endif
  200. void PNGAPI
  201. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  202. png_uint_32 width, png_uint_32 height, int bit_depth,
  203. int color_type, int interlace_type, int compression_type,
  204. int filter_type)
  205. {
  206. png_debug1(1, "in %s storage function", "IHDR");
  207. if (png_ptr == NULL || info_ptr == NULL)
  208. return;
  209. info_ptr->width = width;
  210. info_ptr->height = height;
  211. info_ptr->bit_depth = (png_byte)bit_depth;
  212. info_ptr->color_type = (png_byte)color_type;
  213. info_ptr->compression_type = (png_byte)compression_type;
  214. info_ptr->filter_type = (png_byte)filter_type;
  215. info_ptr->interlace_type = (png_byte)interlace_type;
  216. png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
  217. info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
  218. info_ptr->compression_type, info_ptr->filter_type);
  219. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  220. info_ptr->channels = 1;
  221. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  222. info_ptr->channels = 3;
  223. else
  224. info_ptr->channels = 1;
  225. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  226. info_ptr->channels++;
  227. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  228. /* Check for potential overflow */
  229. if (width > (PNG_UINT_32_MAX
  230. >> 3) /* 8-byte RGBA pixels */
  231. - 64 /* bigrowbuf hack */
  232. - 1 /* filter byte */
  233. - 7*8 /* rounding of width to multiple of 8 pixels */
  234. - 8) /* extra max_pixel_depth pad */
  235. info_ptr->rowbytes = (png_size_t)0;
  236. else
  237. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
  238. }
  239. #ifdef PNG_oFFs_SUPPORTED
  240. void PNGAPI
  241. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  242. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  243. {
  244. png_debug1(1, "in %s storage function", "oFFs");
  245. if (png_ptr == NULL || info_ptr == NULL)
  246. return;
  247. info_ptr->x_offset = offset_x;
  248. info_ptr->y_offset = offset_y;
  249. info_ptr->offset_unit_type = (png_byte)unit_type;
  250. info_ptr->valid |= PNG_INFO_oFFs;
  251. }
  252. #endif
  253. #ifdef PNG_pCAL_SUPPORTED
  254. void PNGAPI
  255. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  256. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  257. png_charp units, png_charpp params)
  258. {
  259. png_uint_32 length;
  260. int i;
  261. png_debug1(1, "in %s storage function", "pCAL");
  262. if (png_ptr == NULL || info_ptr == NULL)
  263. return;
  264. length = png_strlen(purpose) + 1;
  265. png_debug1(3, "allocating purpose for info (%lu bytes)",
  266. (unsigned long)length);
  267. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  268. if (info_ptr->pcal_purpose == NULL)
  269. {
  270. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  271. return;
  272. }
  273. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  274. png_debug(3, "storing X0, X1, type, and nparams in info");
  275. info_ptr->pcal_X0 = X0;
  276. info_ptr->pcal_X1 = X1;
  277. info_ptr->pcal_type = (png_byte)type;
  278. info_ptr->pcal_nparams = (png_byte)nparams;
  279. length = png_strlen(units) + 1;
  280. png_debug1(3, "allocating units for info (%lu bytes)",
  281. (unsigned long)length);
  282. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  283. if (info_ptr->pcal_units == NULL)
  284. {
  285. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  286. return;
  287. }
  288. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  289. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  290. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  291. if (info_ptr->pcal_params == NULL)
  292. {
  293. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  294. return;
  295. }
  296. png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));
  297. for (i = 0; i < nparams; i++)
  298. {
  299. length = png_strlen(params[i]) + 1;
  300. png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
  301. (unsigned long)length);
  302. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  303. if (info_ptr->pcal_params[i] == NULL)
  304. {
  305. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  306. return;
  307. }
  308. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  309. }
  310. info_ptr->valid |= PNG_INFO_pCAL;
  311. #ifdef PNG_FREE_ME_SUPPORTED
  312. info_ptr->free_me |= PNG_FREE_PCAL;
  313. #endif
  314. }
  315. #endif
  316. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  317. #ifdef PNG_FLOATING_POINT_SUPPORTED
  318. void PNGAPI
  319. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  320. int unit, double width, double height)
  321. {
  322. png_debug1(1, "in %s storage function", "sCAL");
  323. if (png_ptr == NULL || info_ptr == NULL)
  324. return;
  325. info_ptr->scal_unit = (png_byte)unit;
  326. info_ptr->scal_pixel_width = width;
  327. info_ptr->scal_pixel_height = height;
  328. info_ptr->valid |= PNG_INFO_sCAL;
  329. }
  330. #else
  331. #ifdef PNG_FIXED_POINT_SUPPORTED
  332. void PNGAPI
  333. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  334. int unit, png_charp swidth, png_charp sheight)
  335. {
  336. png_uint_32 length;
  337. png_debug1(1, "in %s storage function", "sCAL");
  338. if (png_ptr == NULL || info_ptr == NULL)
  339. return;
  340. info_ptr->scal_unit = (png_byte)unit;
  341. length = png_strlen(swidth) + 1;
  342. png_debug1(3, "allocating unit for info (%u bytes)",
  343. (unsigned int)length);
  344. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  345. if (info_ptr->scal_s_width == NULL)
  346. {
  347. png_warning(png_ptr,
  348. "Memory allocation failed while processing sCAL.");
  349. return;
  350. }
  351. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  352. length = png_strlen(sheight) + 1;
  353. png_debug1(3, "allocating unit for info (%u bytes)",
  354. (unsigned int)length);
  355. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  356. if (info_ptr->scal_s_height == NULL)
  357. {
  358. png_free (png_ptr, info_ptr->scal_s_width);
  359. info_ptr->scal_s_width = NULL;
  360. png_warning(png_ptr,
  361. "Memory allocation failed while processing sCAL.");
  362. return;
  363. }
  364. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  365. info_ptr->valid |= PNG_INFO_sCAL;
  366. #ifdef PNG_FREE_ME_SUPPORTED
  367. info_ptr->free_me |= PNG_FREE_SCAL;
  368. #endif
  369. }
  370. #endif
  371. #endif
  372. #endif
  373. #ifdef PNG_pHYs_SUPPORTED
  374. void PNGAPI
  375. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  376. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  377. {
  378. png_debug1(1, "in %s storage function", "pHYs");
  379. if (png_ptr == NULL || info_ptr == NULL)
  380. return;
  381. info_ptr->x_pixels_per_unit = res_x;
  382. info_ptr->y_pixels_per_unit = res_y;
  383. info_ptr->phys_unit_type = (png_byte)unit_type;
  384. info_ptr->valid |= PNG_INFO_pHYs;
  385. }
  386. #endif
  387. void PNGAPI
  388. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  389. png_colorp palette, int num_palette)
  390. {
  391. png_debug1(1, "in %s storage function", "PLTE");
  392. if (png_ptr == NULL || info_ptr == NULL)
  393. return;
  394. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  395. {
  396. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  397. png_error(png_ptr, "Invalid palette length");
  398. else
  399. {
  400. png_warning(png_ptr, "Invalid palette length");
  401. return;
  402. }
  403. }
  404. /* It may not actually be necessary to set png_ptr->palette here;
  405. * we do it for backward compatibility with the way the png_handle_tRNS
  406. * function used to do the allocation.
  407. */
  408. #ifdef PNG_FREE_ME_SUPPORTED
  409. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  410. #endif
  411. /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
  412. * of num_palette entries, in case of an invalid PNG file that has
  413. * too-large sample values.
  414. */
  415. png_ptr->palette = (png_colorp)png_calloc(png_ptr,
  416. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  417. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
  418. info_ptr->palette = png_ptr->palette;
  419. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  420. #ifdef PNG_FREE_ME_SUPPORTED
  421. info_ptr->free_me |= PNG_FREE_PLTE;
  422. #else
  423. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  424. #endif
  425. info_ptr->valid |= PNG_INFO_PLTE;
  426. }
  427. #ifdef PNG_sBIT_SUPPORTED
  428. void PNGAPI
  429. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  430. png_color_8p sig_bit)
  431. {
  432. png_debug1(1, "in %s storage function", "sBIT");
  433. if (png_ptr == NULL || info_ptr == NULL)
  434. return;
  435. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
  436. info_ptr->valid |= PNG_INFO_sBIT;
  437. }
  438. #endif
  439. #ifdef PNG_sRGB_SUPPORTED
  440. void PNGAPI
  441. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  442. {
  443. png_debug1(1, "in %s storage function", "sRGB");
  444. if (png_ptr == NULL || info_ptr == NULL)
  445. return;
  446. info_ptr->srgb_intent = (png_byte)intent;
  447. info_ptr->valid |= PNG_INFO_sRGB;
  448. }
  449. void PNGAPI
  450. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  451. int intent)
  452. {
  453. #ifdef PNG_gAMA_SUPPORTED
  454. #ifdef PNG_FLOATING_POINT_SUPPORTED
  455. float file_gamma;
  456. #endif
  457. #ifdef PNG_FIXED_POINT_SUPPORTED
  458. png_fixed_point int_file_gamma;
  459. #endif
  460. #endif
  461. #ifdef PNG_cHRM_SUPPORTED
  462. #ifdef PNG_FLOATING_POINT_SUPPORTED
  463. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  464. #endif
  465. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  466. int_green_y, int_blue_x, int_blue_y;
  467. #endif
  468. png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
  469. if (png_ptr == NULL || info_ptr == NULL)
  470. return;
  471. png_set_sRGB(png_ptr, info_ptr, intent);
  472. #ifdef PNG_gAMA_SUPPORTED
  473. #ifdef PNG_FLOATING_POINT_SUPPORTED
  474. file_gamma = (float).45455;
  475. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  476. #endif
  477. #ifdef PNG_FIXED_POINT_SUPPORTED
  478. int_file_gamma = 45455L;
  479. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  480. #endif
  481. #endif
  482. #ifdef PNG_cHRM_SUPPORTED
  483. int_white_x = 31270L;
  484. int_white_y = 32900L;
  485. int_red_x = 64000L;
  486. int_red_y = 33000L;
  487. int_green_x = 30000L;
  488. int_green_y = 60000L;
  489. int_blue_x = 15000L;
  490. int_blue_y = 6000L;
  491. #ifdef PNG_FLOATING_POINT_SUPPORTED
  492. white_x = (float).3127;
  493. white_y = (float).3290;
  494. red_x = (float).64;
  495. red_y = (float).33;
  496. green_x = (float).30;
  497. green_y = (float).60;
  498. blue_x = (float).15;
  499. blue_y = (float).06;
  500. #endif
  501. #ifdef PNG_FIXED_POINT_SUPPORTED
  502. png_set_cHRM_fixed(png_ptr, info_ptr,
  503. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  504. int_green_y, int_blue_x, int_blue_y);
  505. #endif
  506. #ifdef PNG_FLOATING_POINT_SUPPORTED
  507. png_set_cHRM(png_ptr, info_ptr,
  508. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  509. #endif
  510. #endif /* cHRM */
  511. }
  512. #endif /* sRGB */
  513. #ifdef PNG_iCCP_SUPPORTED
  514. void PNGAPI
  515. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  516. png_charp name, int compression_type,
  517. png_charp profile, png_uint_32 proflen)
  518. {
  519. png_charp new_iccp_name;
  520. png_charp new_iccp_profile;
  521. png_uint_32 length;
  522. png_debug1(1, "in %s storage function", "iCCP");
  523. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  524. return;
  525. length = png_strlen(name)+1;
  526. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
  527. if (new_iccp_name == NULL)
  528. {
  529. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  530. return;
  531. }
  532. png_memcpy(new_iccp_name, name, length);
  533. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  534. if (new_iccp_profile == NULL)
  535. {
  536. png_free (png_ptr, new_iccp_name);
  537. png_warning(png_ptr,
  538. "Insufficient memory to process iCCP profile.");
  539. return;
  540. }
  541. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  542. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  543. info_ptr->iccp_proflen = proflen;
  544. info_ptr->iccp_name = new_iccp_name;
  545. info_ptr->iccp_profile = new_iccp_profile;
  546. /* Compression is always zero but is here so the API and info structure
  547. * does not have to change if we introduce multiple compression types
  548. */
  549. info_ptr->iccp_compression = (png_byte)compression_type;
  550. #ifdef PNG_FREE_ME_SUPPORTED
  551. info_ptr->free_me |= PNG_FREE_ICCP;
  552. #endif
  553. info_ptr->valid |= PNG_INFO_iCCP;
  554. }
  555. #endif
  556. #ifdef PNG_TEXT_SUPPORTED
  557. void PNGAPI
  558. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  559. int num_text)
  560. {
  561. int ret;
  562. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  563. if (ret)
  564. png_error(png_ptr, "Insufficient memory to store text");
  565. }
  566. int /* PRIVATE */
  567. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  568. int num_text)
  569. {
  570. int i;
  571. png_debug1(1, "in %s storage function", ((png_ptr == NULL ||
  572. png_ptr->chunk_name[0] == '\0') ?
  573. "text" : (png_const_charp)png_ptr->chunk_name));
  574. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  575. return(0);
  576. /* Make sure we have enough space in the "text" array in info_struct
  577. * to hold all of the incoming text_ptr objects.
  578. */
  579. if (info_ptr->num_text + num_text > info_ptr->max_text)
  580. {
  581. if (info_ptr->text != NULL)
  582. {
  583. png_textp old_text;
  584. int old_max;
  585. old_max = info_ptr->max_text;
  586. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  587. old_text = info_ptr->text;
  588. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  589. (png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
  590. if (info_ptr->text == NULL)
  591. {
  592. png_free(png_ptr, old_text);
  593. return(1);
  594. }
  595. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  596. png_sizeof(png_text)));
  597. png_free(png_ptr, old_text);
  598. }
  599. else
  600. {
  601. info_ptr->max_text = num_text + 8;
  602. info_ptr->num_text = 0;
  603. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  604. (png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
  605. if (info_ptr->text == NULL)
  606. return(1);
  607. #ifdef PNG_FREE_ME_SUPPORTED
  608. info_ptr->free_me |= PNG_FREE_TEXT;
  609. #endif
  610. }
  611. png_debug1(3, "allocated %d entries for info_ptr->text",
  612. info_ptr->max_text);
  613. }
  614. for (i = 0; i < num_text; i++)
  615. {
  616. png_size_t text_length, key_len;
  617. png_size_t lang_len, lang_key_len;
  618. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  619. if (text_ptr[i].key == NULL)
  620. continue;
  621. key_len = png_strlen(text_ptr[i].key);
  622. if (text_ptr[i].compression <= 0)
  623. {
  624. lang_len = 0;
  625. lang_key_len = 0;
  626. }
  627. else
  628. #ifdef PNG_iTXt_SUPPORTED
  629. {
  630. /* Set iTXt data */
  631. if (text_ptr[i].lang != NULL)
  632. lang_len = png_strlen(text_ptr[i].lang);
  633. else
  634. lang_len = 0;
  635. if (text_ptr[i].lang_key != NULL)
  636. lang_key_len = png_strlen(text_ptr[i].lang_key);
  637. else
  638. lang_key_len = 0;
  639. }
  640. #else /* PNG_iTXt_SUPPORTED */
  641. {
  642. png_warning(png_ptr, "iTXt chunk not supported.");
  643. continue;
  644. }
  645. #endif
  646. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  647. {
  648. text_length = 0;
  649. #ifdef PNG_iTXt_SUPPORTED
  650. if (text_ptr[i].compression > 0)
  651. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  652. else
  653. #endif
  654. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  655. }
  656. else
  657. {
  658. text_length = png_strlen(text_ptr[i].text);
  659. textp->compression = text_ptr[i].compression;
  660. }
  661. textp->key = (png_charp)png_malloc_warn(png_ptr,
  662. (png_uint_32)
  663. (key_len + text_length + lang_len + lang_key_len + 4));
  664. if (textp->key == NULL)
  665. return(1);
  666. png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
  667. (png_uint_32)
  668. (key_len + lang_len + lang_key_len + text_length + 4),
  669. (int)textp->key);
  670. png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
  671. *(textp->key + key_len) = '\0';
  672. #ifdef PNG_iTXt_SUPPORTED
  673. if (text_ptr[i].compression > 0)
  674. {
  675. textp->lang = textp->key + key_len + 1;
  676. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  677. *(textp->lang + lang_len) = '\0';
  678. textp->lang_key = textp->lang + lang_len + 1;
  679. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  680. *(textp->lang_key + lang_key_len) = '\0';
  681. textp->text = textp->lang_key + lang_key_len + 1;
  682. }
  683. else
  684. #endif
  685. {
  686. #ifdef PNG_iTXt_SUPPORTED
  687. textp->lang=NULL;
  688. textp->lang_key=NULL;
  689. #endif
  690. textp->text = textp->key + key_len + 1;
  691. }
  692. if (text_length)
  693. png_memcpy(textp->text, text_ptr[i].text,
  694. (png_size_t)(text_length));
  695. *(textp->text + text_length) = '\0';
  696. #ifdef PNG_iTXt_SUPPORTED
  697. if (textp->compression > 0)
  698. {
  699. textp->text_length = 0;
  700. textp->itxt_length = text_length;
  701. }
  702. else
  703. #endif
  704. {
  705. textp->text_length = text_length;
  706. #ifdef PNG_iTXt_SUPPORTED
  707. textp->itxt_length = 0;
  708. #endif
  709. }
  710. info_ptr->num_text++;
  711. png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
  712. }
  713. return(0);
  714. }
  715. #endif
  716. #ifdef PNG_tIME_SUPPORTED
  717. void PNGAPI
  718. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  719. {
  720. png_debug1(1, "in %s storage function", "tIME");
  721. if (png_ptr == NULL || info_ptr == NULL ||
  722. (png_ptr->mode & PNG_WROTE_tIME))
  723. return;
  724. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
  725. info_ptr->valid |= PNG_INFO_tIME;
  726. }
  727. #endif
  728. #ifdef PNG_tRNS_SUPPORTED
  729. void PNGAPI
  730. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  731. png_bytep trans, int num_trans, png_color_16p trans_values)
  732. {
  733. png_debug1(1, "in %s storage function", "tRNS");
  734. if (png_ptr == NULL || info_ptr == NULL)
  735. return;
  736. if (trans != NULL)
  737. {
  738. /* It may not actually be necessary to set png_ptr->trans here;
  739. * we do it for backward compatibility with the way the png_handle_tRNS
  740. * function used to do the allocation.
  741. */
  742. #ifdef PNG_FREE_ME_SUPPORTED
  743. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  744. #endif
  745. /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
  746. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  747. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  748. if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
  749. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  750. }
  751. if (trans_values != NULL)
  752. {
  753. int sample_max = (1 << info_ptr->bit_depth);
  754. if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
  755. (int)trans_values->gray > sample_max) ||
  756. (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
  757. ((int)trans_values->red > sample_max ||
  758. (int)trans_values->green > sample_max ||
  759. (int)trans_values->blue > sample_max)))
  760. png_warning(png_ptr,
  761. "tRNS chunk has out-of-range samples for bit_depth");
  762. png_memcpy(&(info_ptr->trans_values), trans_values,
  763. png_sizeof(png_color_16));
  764. if (num_trans == 0)
  765. num_trans = 1;
  766. }
  767. info_ptr->num_trans = (png_uint_16)num_trans;
  768. if (num_trans != 0)
  769. {
  770. info_ptr->valid |= PNG_INFO_tRNS;
  771. #ifdef PNG_FREE_ME_SUPPORTED
  772. info_ptr->free_me |= PNG_FREE_TRNS;
  773. #else
  774. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  775. #endif
  776. }
  777. }
  778. #endif
  779. #ifdef PNG_sPLT_SUPPORTED
  780. void PNGAPI
  781. png_set_sPLT(png_structp png_ptr,
  782. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  783. /*
  784. * entries - array of png_sPLT_t structures
  785. * to be added to the list of palettes
  786. * in the info structure.
  787. * nentries - number of palette structures to be
  788. * added.
  789. */
  790. {
  791. png_sPLT_tp np;
  792. int i;
  793. if (png_ptr == NULL || info_ptr == NULL)
  794. return;
  795. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  796. (info_ptr->splt_palettes_num + nentries) *
  797. (png_uint_32)png_sizeof(png_sPLT_t));
  798. if (np == NULL)
  799. {
  800. png_warning(png_ptr, "No memory for sPLT palettes.");
  801. return;
  802. }
  803. png_memcpy(np, info_ptr->splt_palettes,
  804. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  805. png_free(png_ptr, info_ptr->splt_palettes);
  806. info_ptr->splt_palettes=NULL;
  807. for (i = 0; i < nentries; i++)
  808. {
  809. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  810. png_sPLT_tp from = entries + i;
  811. png_uint_32 length;
  812. length = png_strlen(from->name) + 1;
  813. to->name = (png_charp)png_malloc_warn(png_ptr, length);
  814. if (to->name == NULL)
  815. {
  816. png_warning(png_ptr,
  817. "Out of memory while processing sPLT chunk");
  818. continue;
  819. }
  820. png_memcpy(to->name, from->name, length);
  821. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  822. (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry)));
  823. if (to->entries == NULL)
  824. {
  825. png_warning(png_ptr,
  826. "Out of memory while processing sPLT chunk");
  827. png_free(png_ptr, to->name);
  828. to->name = NULL;
  829. continue;
  830. }
  831. png_memcpy(to->entries, from->entries,
  832. from->nentries * png_sizeof(png_sPLT_entry));
  833. to->nentries = from->nentries;
  834. to->depth = from->depth;
  835. }
  836. info_ptr->splt_palettes = np;
  837. info_ptr->splt_palettes_num += nentries;
  838. info_ptr->valid |= PNG_INFO_sPLT;
  839. #ifdef PNG_FREE_ME_SUPPORTED
  840. info_ptr->free_me |= PNG_FREE_SPLT;
  841. #endif
  842. }
  843. #endif /* PNG_sPLT_SUPPORTED */
  844. #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
  845. void PNGAPI
  846. png_set_unknown_chunks(png_structp png_ptr,
  847. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  848. {
  849. png_unknown_chunkp np;
  850. int i;
  851. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  852. return;
  853. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  854. (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) *
  855. png_sizeof(png_unknown_chunk)));
  856. if (np == NULL)
  857. {
  858. png_warning(png_ptr,
  859. "Out of memory while processing unknown chunk.");
  860. return;
  861. }
  862. png_memcpy(np, info_ptr->unknown_chunks,
  863. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  864. png_free(png_ptr, info_ptr->unknown_chunks);
  865. info_ptr->unknown_chunks = NULL;
  866. for (i = 0; i < num_unknowns; i++)
  867. {
  868. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  869. png_unknown_chunkp from = unknowns + i;
  870. png_memcpy((png_charp)to->name, (png_charp)from->name,
  871. png_sizeof(from->name));
  872. to->name[png_sizeof(to->name)-1] = '\0';
  873. to->size = from->size;
  874. /* Note our location in the read or write sequence */
  875. to->location = (png_byte)(png_ptr->mode & 0xff);
  876. if (from->size == 0)
  877. to->data=NULL;
  878. else
  879. {
  880. to->data = (png_bytep)png_malloc_warn(png_ptr,
  881. (png_uint_32)from->size);
  882. if (to->data == NULL)
  883. {
  884. png_warning(png_ptr,
  885. "Out of memory while processing unknown chunk.");
  886. to->size = 0;
  887. }
  888. else
  889. png_memcpy(to->data, from->data, from->size);
  890. }
  891. }
  892. info_ptr->unknown_chunks = np;
  893. info_ptr->unknown_chunks_num += num_unknowns;
  894. #ifdef PNG_FREE_ME_SUPPORTED
  895. info_ptr->free_me |= PNG_FREE_UNKN;
  896. #endif
  897. }
  898. void PNGAPI
  899. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  900. int chunk, int location)
  901. {
  902. if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  903. (int)info_ptr->unknown_chunks_num)
  904. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  905. }
  906. #endif
  907. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  908. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  909. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  910. void PNGAPI
  911. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  912. {
  913. /* This function is deprecated in favor of png_permit_mng_features()
  914. and will be removed from libpng-1.3.0 */
  915. png_debug(1, "in png_permit_empty_plte, DEPRECATED.");
  916. if (png_ptr == NULL)
  917. return;
  918. png_ptr->mng_features_permitted = (png_byte)
  919. ((png_ptr->mng_features_permitted & (~PNG_FLAG_MNG_EMPTY_PLTE)) |
  920. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  921. }
  922. #endif
  923. #endif
  924. #ifdef PNG_MNG_FEATURES_SUPPORTED
  925. png_uint_32 PNGAPI
  926. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  927. {
  928. png_debug(1, "in png_permit_mng_features");
  929. if (png_ptr == NULL)
  930. return (png_uint_32)0;
  931. png_ptr->mng_features_permitted =
  932. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  933. return (png_uint_32)png_ptr->mng_features_permitted;
  934. }
  935. #endif
  936. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  937. void PNGAPI
  938. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  939. chunk_list, int num_chunks)
  940. {
  941. png_bytep new_list, p;
  942. int i, old_num_chunks;
  943. if (png_ptr == NULL)
  944. return;
  945. if (num_chunks == 0)
  946. {
  947. if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  948. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  949. else
  950. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  951. if (keep == PNG_HANDLE_CHUNK_ALWAYS)
  952. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  953. else
  954. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  955. return;
  956. }
  957. if (chunk_list == NULL)
  958. return;
  959. old_num_chunks = png_ptr->num_chunk_list;
  960. new_list=(png_bytep)png_malloc(png_ptr,
  961. (png_uint_32)
  962. (5*(num_chunks + old_num_chunks)));
  963. if (png_ptr->chunk_list != NULL)
  964. {
  965. png_memcpy(new_list, png_ptr->chunk_list,
  966. (png_size_t)(5*old_num_chunks));
  967. png_free(png_ptr, png_ptr->chunk_list);
  968. png_ptr->chunk_list=NULL;
  969. }
  970. png_memcpy(new_list + 5*old_num_chunks, chunk_list,
  971. (png_size_t)(5*num_chunks));
  972. for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
  973. *p=(png_byte)keep;
  974. png_ptr->num_chunk_list = old_num_chunks + num_chunks;
  975. png_ptr->chunk_list = new_list;
  976. #ifdef PNG_FREE_ME_SUPPORTED
  977. png_ptr->free_me |= PNG_FREE_LIST;
  978. #endif
  979. }
  980. #endif
  981. #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
  982. void PNGAPI
  983. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  984. png_user_chunk_ptr read_user_chunk_fn)
  985. {
  986. png_debug(1, "in png_set_read_user_chunk_fn");
  987. if (png_ptr == NULL)
  988. return;
  989. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  990. png_ptr->user_chunk_ptr = user_chunk_ptr;
  991. }
  992. #endif
  993. #ifdef PNG_INFO_IMAGE_SUPPORTED
  994. void PNGAPI
  995. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  996. {
  997. png_debug1(1, "in %s storage function", "rows");
  998. if (png_ptr == NULL || info_ptr == NULL)
  999. return;
  1000. if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  1001. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  1002. info_ptr->row_pointers = row_pointers;
  1003. if (row_pointers)
  1004. info_ptr->valid |= PNG_INFO_IDAT;
  1005. }
  1006. #endif
  1007. void PNGAPI
  1008. png_set_compression_buffer_size(png_structp png_ptr,
  1009. png_uint_32 size)
  1010. {
  1011. if (png_ptr == NULL)
  1012. return;
  1013. png_free(png_ptr, png_ptr->zbuf);
  1014. png_ptr->zbuf_size = (png_size_t)size;
  1015. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  1016. png_ptr->zstream.next_out = png_ptr->zbuf;
  1017. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  1018. }
  1019. void PNGAPI
  1020. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  1021. {
  1022. if (png_ptr && info_ptr)
  1023. info_ptr->valid &= ~mask;
  1024. }
  1025. #ifndef PNG_1_0_X
  1026. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  1027. /* Function was added to libpng 1.2.0 and should always exist by default */
  1028. void PNGAPI
  1029. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  1030. {
  1031. /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
  1032. if (png_ptr != NULL)
  1033. png_ptr->asm_flags = 0;
  1034. asm_flags = asm_flags; /* Quiet the compiler */
  1035. }
  1036. /* This function was added to libpng 1.2.0 */
  1037. void PNGAPI
  1038. png_set_mmx_thresholds (png_structp png_ptr,
  1039. png_byte mmx_bitdepth_threshold,
  1040. png_uint_32 mmx_rowbytes_threshold)
  1041. {
  1042. /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
  1043. if (png_ptr == NULL)
  1044. return;
  1045. /* Quiet the compiler */
  1046. mmx_bitdepth_threshold = mmx_bitdepth_threshold;
  1047. mmx_rowbytes_threshold = mmx_rowbytes_threshold;
  1048. }
  1049. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  1050. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  1051. /* This function was added to libpng 1.2.6 */
  1052. void PNGAPI
  1053. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  1054. png_uint_32 user_height_max)
  1055. {
  1056. /* Images with dimensions larger than these limits will be
  1057. * rejected by png_set_IHDR(). To accept any PNG datastream
  1058. * regardless of dimensions, set both limits to 0x7ffffffL.
  1059. */
  1060. if (png_ptr == NULL)
  1061. return;
  1062. png_ptr->user_width_max = user_width_max;
  1063. png_ptr->user_height_max = user_height_max;
  1064. }
  1065. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  1066. #ifdef PNG_BENIGN_ERRORS_SUPPORTED
  1067. void PNGAPI
  1068. png_set_benign_errors(png_structp png_ptr, int allowed)
  1069. {
  1070. png_debug(1, "in png_set_benign_errors");
  1071. if (allowed)
  1072. png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
  1073. else
  1074. png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
  1075. }
  1076. #endif /* PNG_BENIGN_ERRORS_SUPPORTED */
  1077. #endif /* ?PNG_1_0_X */
  1078. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */