/thirdparty/libpng/pngset.c

http://crashrpt.googlecode.com/ · C · 1219 lines · 1034 code · 122 blank · 63 comment · 268 complexity · d085639e21c2f196d18089e8f379dc96 MD5 · raw file

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