pngset.c 32.8 KB
Newer Older
A
Andreas Dilger 已提交
1 2

/* pngset.c - storage of image information into info struct
3
 *
4
 * Last changed in libpng 1.5.0 [June 29, 2010]
5
 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
6 7
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8
 *
9
 * This code is released under the libpng license.
10
 * For conditions of distribution and use, see the disclaimer
11
 * and license in png.h
12
 *
13 14 15 16 17
 * The functions here are used during reads to store data from the file
 * into the info struct, and during writes to store application data
 * into the info struct for writing into the file.  This abstracts the
 * info struct and allows us to change the structure in the future.
 */
A
Andreas Dilger 已提交
18

19
#include "pngpriv.h"
20

21 22
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)

23
#ifdef PNG_bKGD_SUPPORTED
24
void PNGAPI
A
Andreas Dilger 已提交
25 26
png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
{
27
   png_debug1(1, "in %s storage function", "bKGD");
28

29
   if (png_ptr == NULL || info_ptr == NULL)
A
Andreas Dilger 已提交
30 31
      return;

32
   png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
A
Andreas Dilger 已提交
33 34 35 36
   info_ptr->valid |= PNG_INFO_bKGD;
}
#endif

37
#ifdef PNG_cHRM_SUPPORTED
38
#ifdef PNG_FLOATING_POINT_SUPPORTED
39
void PNGAPI
A
Andreas Dilger 已提交
40
png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
41 42
    double white_x, double white_y, double red_x, double red_y,
    double green_x, double green_y, double blue_x, double blue_y)
A
Andreas Dilger 已提交
43
{
44
   png_debug1(1, "in %s storage function", "cHRM");
45

46
   if (png_ptr == NULL || info_ptr == NULL)
A
Andreas Dilger 已提交
47
      return;
48

49
   /* TODO: call png_check_cHRM_fixed */
A
Andreas Dilger 已提交
50 51 52 53 54 55 56 57
   info_ptr->x_white = (float)white_x;
   info_ptr->y_white = (float)white_y;
   info_ptr->x_red   = (float)red_x;
   info_ptr->y_red   = (float)red_y;
   info_ptr->x_green = (float)green_x;
   info_ptr->y_green = (float)green_y;
   info_ptr->x_blue  = (float)blue_x;
   info_ptr->y_blue  = (float)blue_y;
58
#ifdef PNG_FIXED_POINT_SUPPORTED
59 60 61 62 63 64 65 66
   info_ptr->int_x_white = (png_fixed_point)(white_x*100000. + 0.5);
   info_ptr->int_y_white = (png_fixed_point)(white_y*100000. + 0.5);
   info_ptr->int_x_red   = (png_fixed_point)(  red_x*100000. + 0.5);
   info_ptr->int_y_red   = (png_fixed_point)(  red_y*100000. + 0.5);
   info_ptr->int_x_green = (png_fixed_point)(green_x*100000. + 0.5);
   info_ptr->int_y_green = (png_fixed_point)(green_y*100000. + 0.5);
   info_ptr->int_x_blue  = (png_fixed_point)( blue_x*100000. + 0.5);
   info_ptr->int_y_blue  = (png_fixed_point)( blue_y*100000. + 0.5);
67
#endif
A
Andreas Dilger 已提交
68 69
   info_ptr->valid |= PNG_INFO_cHRM;
}
70 71
#endif /* PNG_FLOATING_POINT_SUPPORTED */

72
#ifdef PNG_FIXED_POINT_SUPPORTED
73
void PNGAPI
74
png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
75 76 77
    png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
    png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
    png_fixed_point blue_x, png_fixed_point blue_y)
78
{
79
   png_debug1(1, "in %s storage function", "cHRM fixed");
80

81 82
   if (png_ptr == NULL || info_ptr == NULL)
      return;
A
Andreas Dilger 已提交
83

84
#ifdef PNG_CHECK_cHRM_SUPPORTED
85
   if (png_check_cHRM_fixed(png_ptr,
86
       white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
87
#endif
88
   {
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
      info_ptr->int_x_white = white_x;
      info_ptr->int_y_white = white_y;
      info_ptr->int_x_red   = red_x;
      info_ptr->int_y_red   = red_y;
      info_ptr->int_x_green = green_x;
      info_ptr->int_y_green = green_y;
      info_ptr->int_x_blue  = blue_x;
      info_ptr->int_y_blue  = blue_y;
#ifdef  PNG_FLOATING_POINT_SUPPORTED
      info_ptr->x_white = (float)(white_x/100000.);
      info_ptr->y_white = (float)(white_y/100000.);
      info_ptr->x_red   = (float)(  red_x/100000.);
      info_ptr->y_red   = (float)(  red_y/100000.);
      info_ptr->x_green = (float)(green_x/100000.);
      info_ptr->y_green = (float)(green_y/100000.);
      info_ptr->x_blue  = (float)( blue_x/100000.);
      info_ptr->y_blue  = (float)( blue_y/100000.);
106
#endif
107
      info_ptr->valid |= PNG_INFO_cHRM;
108
   }
109
}
110 111
#endif /* PNG_FIXED_POINT_SUPPORTED */
#endif /* PNG_cHRM_SUPPORTED */
112

113
#ifdef PNG_gAMA_SUPPORTED
114
#ifdef PNG_FLOATING_POINT_SUPPORTED
115
void PNGAPI
A
Andreas Dilger 已提交
116 117
png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
{
118
   double png_gamma;
119

120
   png_debug1(1, "in %s storage function", "gAMA");
121

122
   if (png_ptr == NULL || info_ptr == NULL)
A
Andreas Dilger 已提交
123 124
      return;

125 126 127 128
   /* Check for overflow */
   if (file_gamma > 21474.83)
   {
      png_warning(png_ptr, "Limiting gamma to 21474.83");
129
      png_gamma = 21474.83;
130
   }
131

132
   else
133
      png_gamma = file_gamma;
134

135
   info_ptr->gamma = (float)png_gamma;
136
#ifdef PNG_FIXED_POINT_SUPPORTED
137
   info_ptr->int_gamma = (int)(png_gamma*100000.+.5);
138 139
#endif
   info_ptr->valid |= PNG_INFO_gAMA;
140

141
   if (png_gamma == 0.0)
142
      png_warning(png_ptr, "Setting gamma = 0");
143 144
}
#endif
145
#ifdef PNG_FIXED_POINT_SUPPORTED
146
void PNGAPI
147
png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
148
    int_gamma)
149
{
150
   png_fixed_point png_gamma;
151

152
   png_debug1(1, "in %s storage function", "gAMA");
153

154 155 156
   if (png_ptr == NULL || info_ptr == NULL)
      return;

157
   if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX)
158
   {
159
      png_warning(png_ptr, "Limiting gamma to 21474.83");
160
      png_gamma = PNG_UINT_31_MAX;
161
   }
162

163 164
   else
   {
165 166 167 168 169
      if (int_gamma < 0)
      {
         png_warning(png_ptr, "Setting negative gamma to zero");
         png_gamma = 0;
      }
170

171 172
      else
         png_gamma = int_gamma;
173
   }
174
#ifdef PNG_FLOATING_POINT_SUPPORTED
175
   info_ptr->gamma = (float)(png_gamma/100000.);
176
#endif
177
   info_ptr->int_gamma = png_gamma;
A
Andreas Dilger 已提交
178
   info_ptr->valid |= PNG_INFO_gAMA;
179

180
   if (png_gamma == 0)
181
      png_warning(png_ptr, "Setting gamma = 0");
A
Andreas Dilger 已提交
182
}
183
#endif
184
#endif
A
Andreas Dilger 已提交
185

186
#ifdef PNG_hIST_SUPPORTED
187
void PNGAPI
A
Andreas Dilger 已提交
188 189
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
{
190
   int i;
191

192
   png_debug1(1, "in %s storage function", "hIST");
193

194
   if (png_ptr == NULL || info_ptr == NULL)
A
Andreas Dilger 已提交
195
      return;
196

197
   if (info_ptr->num_palette == 0 || info_ptr->num_palette
198
       > PNG_MAX_PALETTE_LENGTH)
199
   {
200
      png_warning(png_ptr,
201
          "Invalid palette size, hIST allocation skipped");
202

203
      return;
204
   }
205 206

   png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
207 208 209
   /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
    * version 1.2.1
    */
210
   png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
211
       PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16));
212
   if (png_ptr->hist == NULL)
213 214 215 216
   {
      png_warning(png_ptr, "Insufficient memory for hIST chunk data");
      return;
   }
A
Andreas Dilger 已提交
217

218
   for (i = 0; i < info_ptr->num_palette; i++)
219
      png_ptr->hist[i] = hist[i];
220

221
   info_ptr->hist = png_ptr->hist;
A
Andreas Dilger 已提交
222
   info_ptr->valid |= PNG_INFO_hIST;
223 224

   info_ptr->free_me |= PNG_FREE_HIST;
A
Andreas Dilger 已提交
225 226 227
}
#endif

228
void PNGAPI
A
Andreas Dilger 已提交
229 230 231 232 233
png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
   png_uint_32 width, png_uint_32 height, int bit_depth,
   int color_type, int interlace_type, int compression_type,
   int filter_type)
{
234
   png_debug1(1, "in %s storage function", "IHDR");
235

236
   if (png_ptr == NULL || info_ptr == NULL)
A
Andreas Dilger 已提交
237 238 239 240 241
      return;

   info_ptr->width = width;
   info_ptr->height = height;
   info_ptr->bit_depth = (png_byte)bit_depth;
242
   info_ptr->color_type = (png_byte)color_type;
A
Andreas Dilger 已提交
243 244 245
   info_ptr->compression_type = (png_byte)compression_type;
   info_ptr->filter_type = (png_byte)filter_type;
   info_ptr->interlace_type = (png_byte)interlace_type;
246 247 248 249 250

   png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
       info_ptr->compression_type, info_ptr->filter_type);

251 252
   if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
      info_ptr->channels = 1;
253

254
   else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
A
Andreas Dilger 已提交
255
      info_ptr->channels = 3;
256

A
Andreas Dilger 已提交
257 258
   else
      info_ptr->channels = 1;
259

A
Andreas Dilger 已提交
260 261
   if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
      info_ptr->channels++;
262

A
Andreas Dilger 已提交
263
   info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
264

265
   /* Check for potential overflow */
266
   if (width > (PNG_UINT_32_MAX
267
                 >> 3)      /* 8-byte RRGGBBAA pixels */
268 269 270 271
                 - 64       /* bigrowbuf hack */
                 - 1        /* filter byte */
                 - 7*8      /* rounding of width to multiple of 8 pixels */
                 - 8)       /* extra max_pixel_depth pad */
272
      info_ptr->rowbytes = 0;
273
   else
274
      info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
A
Andreas Dilger 已提交
275 276
}

277
#ifdef PNG_oFFs_SUPPORTED
278
void PNGAPI
A
Andreas Dilger 已提交
279
png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
280
    png_int_32 offset_x, png_int_32 offset_y, int unit_type)
A
Andreas Dilger 已提交
281
{
282
   png_debug1(1, "in %s storage function", "oFFs");
283

284
   if (png_ptr == NULL || info_ptr == NULL)
A
Andreas Dilger 已提交
285 286 287 288 289 290 291 292 293
      return;

   info_ptr->x_offset = offset_x;
   info_ptr->y_offset = offset_y;
   info_ptr->offset_unit_type = (png_byte)unit_type;
   info_ptr->valid |= PNG_INFO_oFFs;
}
#endif

294
#ifdef PNG_pCAL_SUPPORTED
295
void PNGAPI
A
Andreas Dilger 已提交
296
png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
297 298
    png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
    png_charp units, png_charpp params)
A
Andreas Dilger 已提交
299
{
300
   png_size_t length;
301
   int i;
A
Andreas Dilger 已提交
302

303
   png_debug1(1, "in %s storage function", "pCAL");
304

305
   if (png_ptr == NULL || info_ptr == NULL)
A
Andreas Dilger 已提交
306 307 308
      return;

   length = png_strlen(purpose) + 1;
309
   png_debug1(3, "allocating purpose for info (%lu bytes)",
310
       (unsigned long)length);
311

312 313
   info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
   if (info_ptr->pcal_purpose == NULL)
314
   {
315
      png_warning(png_ptr, "Insufficient memory for pCAL purpose");
316 317
      return;
   }
318

319
   png_memcpy(info_ptr->pcal_purpose, purpose, length);
A
Andreas Dilger 已提交
320

321
   png_debug(3, "storing X0, X1, type, and nparams in info");
A
Andreas Dilger 已提交
322 323 324 325 326 327
   info_ptr->pcal_X0 = X0;
   info_ptr->pcal_X1 = X1;
   info_ptr->pcal_type = (png_byte)type;
   info_ptr->pcal_nparams = (png_byte)nparams;

   length = png_strlen(units) + 1;
328
   png_debug1(3, "allocating units for info (%lu bytes)",
329
     (unsigned long)length);
330

331 332
   info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
   if (info_ptr->pcal_units == NULL)
333
   {
334
      png_warning(png_ptr, "Insufficient memory for pCAL units");
335 336 337
      return;
   }
   png_memcpy(info_ptr->pcal_units, units, length);
A
Andreas Dilger 已提交
338

339
   info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
340
      (png_size_t)((nparams + 1) * png_sizeof(png_charp)));
341

342
   if (info_ptr->pcal_params == NULL)
343
   {
344
      png_warning(png_ptr, "Insufficient memory for pCAL params");
345 346
      return;
   }
347

348
   png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));
A
Andreas Dilger 已提交
349 350 351 352

   for (i = 0; i < nparams; i++)
   {
      length = png_strlen(params[i]) + 1;
353
      png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
354
        (unsigned long)length);
355

356
      info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
357

358
      if (info_ptr->pcal_params[i] == NULL)
359
      {
360 361
         png_warning(png_ptr, "Insufficient memory for pCAL parameter");
         return;
362
      }
363

364
      png_memcpy(info_ptr->pcal_params[i], params[i], length);
A
Andreas Dilger 已提交
365 366 367
   }

   info_ptr->valid |= PNG_INFO_pCAL;
368
   info_ptr->free_me |= PNG_FREE_PCAL;
A
Andreas Dilger 已提交
369 370 371
}
#endif

372
#ifdef PNG_sCAL_SUPPORTED
373
#ifdef PNG_FLOATING_POINT_SUPPORTED
374
void PNGAPI
375
png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
376
    int unit, double width, double height)
377
{
378
   png_debug1(1, "in %s storage function", "sCAL");
379

380 381 382
   if (png_ptr == NULL || info_ptr == NULL)
      return;

383
   info_ptr->scal_unit = (png_byte)unit;
384 385 386 387 388
   info_ptr->scal_pixel_width = width;
   info_ptr->scal_pixel_height = height;

   info_ptr->valid |= PNG_INFO_sCAL;
}
389
#endif
390
#ifdef PNG_FIXED_POINT_SUPPORTED
391
void PNGAPI
392
png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
393
    int unit, png_charp swidth, png_charp sheight)
394
{
395
   png_size_t length;
396

397
   png_debug1(1, "in %s storage function", "sCAL");
398

399 400 401
   if (png_ptr == NULL || info_ptr == NULL)
      return;

402
   info_ptr->scal_unit = (png_byte)unit;
403 404

   length = png_strlen(swidth) + 1;
405

406
   png_debug1(3, "allocating unit for info (%u bytes)",
407
       (unsigned int)length);
408

409
   info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
410

411 412
   if (info_ptr->scal_s_width == NULL)
   {
413
      png_warning(png_ptr,
414
         "Memory allocation failed while processing sCAL");
415
      return;
416
   }
417

418
   png_memcpy(info_ptr->scal_s_width, swidth, length);
419 420

   length = png_strlen(sheight) + 1;
421

422
   png_debug1(3, "allocating unit for info (%u bytes)",
423
      (unsigned int)length);
424

425
   info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
426

427 428 429
   if (info_ptr->scal_s_height == NULL)
   {
      png_free (png_ptr, info_ptr->scal_s_width);
430
      info_ptr->scal_s_width = NULL;
431

432
      png_warning(png_ptr,
433
         "Memory allocation failed while processing sCAL");
434

435
      return;
436
   }
437

438
   png_memcpy(info_ptr->scal_s_height, sheight, length);
439
   info_ptr->valid |= PNG_INFO_sCAL;
440
   info_ptr->free_me |= PNG_FREE_SCAL;
441 442
}
#endif
443
#endif
444

445
#ifdef PNG_pHYs_SUPPORTED
446
void PNGAPI
A
Andreas Dilger 已提交
447
png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
448
    png_uint_32 res_x, png_uint_32 res_y, int unit_type)
A
Andreas Dilger 已提交
449
{
450
   png_debug1(1, "in %s storage function", "pHYs");
451

452
   if (png_ptr == NULL || info_ptr == NULL)
A
Andreas Dilger 已提交
453 454 455 456 457 458 459 460 461
      return;

   info_ptr->x_pixels_per_unit = res_x;
   info_ptr->y_pixels_per_unit = res_y;
   info_ptr->phys_unit_type = (png_byte)unit_type;
   info_ptr->valid |= PNG_INFO_pHYs;
}
#endif

462
void PNGAPI
A
Andreas Dilger 已提交
463
png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
464
    png_colorp palette, int num_palette)
A
Andreas Dilger 已提交
465
{
466

467
   png_debug1(1, "in %s storage function", "PLTE");
468

469
   if (png_ptr == NULL || info_ptr == NULL)
A
Andreas Dilger 已提交
470 471
      return;

472
   if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
473 474
   {
      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
475
         png_error(png_ptr, "Invalid palette length");
476

477 478
      else
      {
479 480
         png_warning(png_ptr, "Invalid palette length");
         return;
481 482
      }
   }
483

484
   /* It may not actually be necessary to set png_ptr->palette here;
485 486 487 488
    * we do it for backward compatibility with the way the png_handle_tRNS
    * function used to do the allocation.
    */
   png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
489

490
   /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
491 492 493
    * of num_palette entries, in case of an invalid PNG file that has
    * too-large sample values.
    */
494
   png_ptr->palette = (png_colorp)png_calloc(png_ptr,
495
       PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
496

497
   png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
498 499 500 501
   info_ptr->palette = png_ptr->palette;
   info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;

   info_ptr->free_me |= PNG_FREE_PLTE;
502

503
   info_ptr->valid |= PNG_INFO_PLTE;
A
Andreas Dilger 已提交
504 505
}

506
#ifdef PNG_sBIT_SUPPORTED
507
void PNGAPI
A
Andreas Dilger 已提交
508
png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
509
    png_color_8p sig_bit)
A
Andreas Dilger 已提交
510
{
511
   png_debug1(1, "in %s storage function", "sBIT");
512

513
   if (png_ptr == NULL || info_ptr == NULL)
A
Andreas Dilger 已提交
514 515
      return;

516
   png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
A
Andreas Dilger 已提交
517 518 519 520
   info_ptr->valid |= PNG_INFO_sBIT;
}
#endif

521
#ifdef PNG_sRGB_SUPPORTED
522
void PNGAPI
523
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
524
{
525
   png_debug1(1, "in %s storage function", "sRGB");
526

527
   if (png_ptr == NULL || info_ptr == NULL)
528 529
      return;

530
   info_ptr->srgb_intent = (png_byte)intent;
531 532
   info_ptr->valid |= PNG_INFO_sRGB;
}
533

534
void PNGAPI
535
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
536
    int intent)
537
{
538
   png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
539

540
   if (png_ptr == NULL || info_ptr == NULL)
541 542 543 544
      return;

   png_set_sRGB(png_ptr, info_ptr, intent);

545
#ifdef PNG_gAMA_SUPPORTED
546
#ifdef PNG_FIXED_POINT_SUPPORTED
547 548
   png_set_gAMA_fixed(png_ptr, info_ptr, 45455L);
#else
549
   /* Floating point must be set! */
550
   png_set_gAMA(png_ptr, info_ptr, .45455);
551 552
#endif
#endif
553

554
#ifdef PNG_cHRM_SUPPORTED
555
#ifdef PNG_FIXED_POINT_SUPPORTED
556
   png_set_cHRM_fixed(png_ptr, info_ptr,
557 558 559 560 561 562 563 564
      /* color      x       y */
      /* white */ 31270L, 32900L,
      /* red   */ 64000L, 33000L,
      /* green */ 30000L, 60000L,
      /* blue  */ 15000L,  6000L
   );
#else
   /* Floating point must be supported! */
565
   png_set_cHRM(png_ptr, info_ptr,
566 567 568 569 570 571
      /* color      x      y */
      /* while */ .3127, .3290,
      /* red   */ .64,   .33,
      /* green */ .30,   .60,
      /* blue  */ .15,   .06
   );
572
#endif
573
#endif /* cHRM */
574
}
575
#endif /* sRGB */
576

577

578
#ifdef PNG_iCCP_SUPPORTED
579
void PNGAPI
580
png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
581 582
    png_charp name, int compression_type,
    png_charp profile, png_uint_32 proflen)
583
{
584 585
   png_charp new_iccp_name;
   png_charp new_iccp_profile;
586
   png_uint_32 length;
587

588
   png_debug1(1, "in %s storage function", "iCCP");
589

590 591 592
   if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
      return;

593 594
   length = png_strlen(name)+1;
   new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
595 596
   if (new_iccp_name == NULL)
   {
597
        png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
598 599
      return;
   }
600
   png_memcpy(new_iccp_name, name, length);
601
   new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
602

603 604 605
   if (new_iccp_profile == NULL)
   {
      png_free (png_ptr, new_iccp_name);
606
      png_warning(png_ptr,
607
          "Insufficient memory to process iCCP profile");
608 609
      return;
   }
610

611 612
   png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);

613
   png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
614

615
   info_ptr->iccp_proflen = proflen;
616 617
   info_ptr->iccp_name = new_iccp_name;
   info_ptr->iccp_profile = new_iccp_profile;
618
   /* Compression is always zero but is here so the API and info structure
619 620
    * does not have to change if we introduce multiple compression types
    */
621
   info_ptr->iccp_compression = (png_byte)compression_type;
622
   info_ptr->free_me |= PNG_FREE_ICCP;
623 624 625 626
   info_ptr->valid |= PNG_INFO_iCCP;
}
#endif

627
#ifdef PNG_TEXT_SUPPORTED
628
void PNGAPI
A
Andreas Dilger 已提交
629
png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
630
    int num_text)
631 632
{
   int ret;
633
   ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
634

635
   if (ret)
636
      png_error(png_ptr, "Insufficient memory to store text");
637 638 639 640
}

int /* PRIVATE */
png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
641
    int num_text)
A
Andreas Dilger 已提交
642 643 644
{
   int i;

645 646
   png_debug1(1, "in %s storage function", ((png_ptr == NULL ||
      png_ptr->chunk_name[0] == '\0') ?
647
      "text" : (png_const_charp)png_ptr->chunk_name));
A
Andreas Dilger 已提交
648

649
   if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
650
      return(0);
A
Andreas Dilger 已提交
651 652 653 654 655 656 657 658 659 660 661 662 663 664

   /* Make sure we have enough space in the "text" array in info_struct
    * to hold all of the incoming text_ptr objects.
    */
   if (info_ptr->num_text + num_text > info_ptr->max_text)
   {
      if (info_ptr->text != NULL)
      {
         png_textp old_text;
         int old_max;

         old_max = info_ptr->max_text;
         info_ptr->max_text = info_ptr->num_text + num_text + 8;
         old_text = info_ptr->text;
665
         info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
666
            (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
667

668
         if (info_ptr->text == NULL)
669 670 671 672
         {
            png_free(png_ptr, old_text);
            return(1);
         }
673

674
         png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
675
             png_sizeof(png_text)));
A
Andreas Dilger 已提交
676 677
         png_free(png_ptr, old_text);
      }
678

A
Andreas Dilger 已提交
679 680 681 682
      else
      {
         info_ptr->max_text = num_text + 8;
         info_ptr->num_text = 0;
683
         info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
684
             (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
685
         if (info_ptr->text == NULL)
686
            return(1);
687
         info_ptr->free_me |= PNG_FREE_TEXT;
A
Andreas Dilger 已提交
688
      }
689

690
      png_debug1(3, "allocated %d entries for info_ptr->text",
691
          info_ptr->max_text);
A
Andreas Dilger 已提交
692 693 694
   }
   for (i = 0; i < num_text; i++)
   {
695 696
      png_size_t text_length, key_len;
      png_size_t lang_len, lang_key_len;
A
Andreas Dilger 已提交
697 698
      png_textp textp = &(info_ptr->text[info_ptr->num_text]);

699
      if (text_ptr[i].key == NULL)
700 701
          continue;

702 703
      key_len = png_strlen(text_ptr[i].key);

704
      if (text_ptr[i].compression <= 0)
705
      {
706 707
         lang_len = 0;
         lang_key_len = 0;
708
      }
709

710
      else
711
#ifdef PNG_iTXt_SUPPORTED
712
      {
713
         /* Set iTXt data */
714

715 716
         if (text_ptr[i].lang != NULL)
            lang_len = png_strlen(text_ptr[i].lang);
717

718 719
         else
            lang_len = 0;
720

721 722
         if (text_ptr[i].lang_key != NULL)
            lang_key_len = png_strlen(text_ptr[i].lang_key);
723

724 725
         else
            lang_key_len = 0;
726
      }
727
#else /* PNG_iTXt_SUPPORTED */
728
      {
729 730
         png_warning(png_ptr, "iTXt chunk not supported");
         continue;
731 732
      }
#endif
A
Andreas Dilger 已提交
733

734
      if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
A
Andreas Dilger 已提交
735
      {
736
         text_length = 0;
737
#ifdef PNG_iTXt_SUPPORTED
738
         if (text_ptr[i].compression > 0)
739
            textp->compression = PNG_ITXT_COMPRESSION_NONE;
740

741
         else
742
#endif
743
            textp->compression = PNG_TEXT_COMPRESSION_NONE;
A
Andreas Dilger 已提交
744
      }
745

A
Andreas Dilger 已提交
746 747
      else
      {
748
         text_length = png_strlen(text_ptr[i].text);
A
Andreas Dilger 已提交
749 750
         textp->compression = text_ptr[i].compression;
      }
751

752
      textp->key = (png_charp)png_malloc_warn(png_ptr,
753 754
          (png_size_t)
          (key_len + text_length + lang_len + lang_key_len + 4));
755

756
      if (textp->key == NULL)
757
         return(1);
758

759
      png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
760 761 762
          (unsigned long)(png_uint_32)
          (key_len + lang_len + lang_key_len + text_length + 4),
          (int)textp->key);
763

764
      png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
765
      *(textp->key + key_len) = '\0';
766

767 768
      if (text_ptr[i].compression > 0)
      {
769
         textp->lang = textp->key + key_len + 1;
770
         png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
771
         *(textp->lang + lang_len) = '\0';
772
         textp->lang_key = textp->lang + lang_len + 1;
773
         png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
774
         *(textp->lang_key + lang_key_len) = '\0';
775
         textp->text = textp->lang_key + lang_key_len + 1;
776
      }
777

778 779
      else
      {
780 781
         textp->lang=NULL;
         textp->lang_key=NULL;
782
         textp->text = textp->key + key_len + 1;
783
      }
784

785
      if (text_length)
786
         png_memcpy(textp->text, text_ptr[i].text,
787
             (png_size_t)(text_length));
788

789
      *(textp->text + text_length) = '\0';
790

791
#ifdef PNG_iTXt_SUPPORTED
792
      if (textp->compression > 0)
793 794 795 796
      {
         textp->text_length = 0;
         textp->itxt_length = text_length;
      }
797

798
      else
799
#endif
800 801 802 803
      {
         textp->text_length = text_length;
         textp->itxt_length = 0;
      }
804

A
Andreas Dilger 已提交
805
      info_ptr->num_text++;
806
      png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
A
Andreas Dilger 已提交
807
   }
808
   return(0);
A
Andreas Dilger 已提交
809 810 811
}
#endif

812
#ifdef PNG_tIME_SUPPORTED
813
void PNGAPI
A
Andreas Dilger 已提交
814 815
png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
{
816
   png_debug1(1, "in %s storage function", "tIME");
817

818
   if (png_ptr == NULL || info_ptr == NULL ||
819
       (png_ptr->mode & PNG_WROTE_tIME))
A
Andreas Dilger 已提交
820 821
      return;

822
   png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
A
Andreas Dilger 已提交
823 824 825 826
   info_ptr->valid |= PNG_INFO_tIME;
}
#endif

827
#ifdef PNG_tRNS_SUPPORTED
828
void PNGAPI
A
Andreas Dilger 已提交
829
png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
830
    png_bytep trans_alpha, int num_trans, png_color_16p trans_color)
A
Andreas Dilger 已提交
831
{
832
   png_debug1(1, "in %s storage function", "tRNS");
833

834
   if (png_ptr == NULL || info_ptr == NULL)
A
Andreas Dilger 已提交
835 836
      return;

837
   if (trans_alpha != NULL)
838
   {
839
       /* It may not actually be necessary to set png_ptr->trans_alpha here;
840 841 842
        * we do it for backward compatibility with the way the png_handle_tRNS
        * function used to do the allocation.
        */
843

844
       png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
845

846
       /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
847
       png_ptr->trans_alpha = info_ptr->trans_alpha = (png_bytep)png_malloc(png_ptr,
848
           (png_size_t)PNG_MAX_PALETTE_LENGTH);
849

850
       if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
851
          png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
852
   }
A
Andreas Dilger 已提交
853

854
   if (trans_color != NULL)
A
Andreas Dilger 已提交
855
   {
856
      int sample_max = (1 << info_ptr->bit_depth);
857

858
      if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
859
          (int)trans_color->gray > sample_max) ||
860
          (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
861 862 863
          ((int)trans_color->red > sample_max ||
          (int)trans_color->green > sample_max ||
          (int)trans_color->blue > sample_max)))
864 865
         png_warning(png_ptr,
            "tRNS chunk has out-of-range samples for bit_depth");
866 867 868

      png_memcpy(&(info_ptr->trans_color), trans_color, png_sizeof(png_color_16));

869
      if (num_trans == 0)
870
         num_trans = 1;
A
Andreas Dilger 已提交
871
   }
872

A
Andreas Dilger 已提交
873
   info_ptr->num_trans = (png_uint_16)num_trans;
874

875 876 877 878 879
   if (num_trans != 0)
   {
      info_ptr->valid |= PNG_INFO_tRNS;
      info_ptr->free_me |= PNG_FREE_TRNS;
   }
A
Andreas Dilger 已提交
880 881 882
}
#endif

883
#ifdef PNG_sPLT_SUPPORTED
884
void PNGAPI
885
png_set_sPLT(png_structp png_ptr,
886
    png_infop info_ptr, png_sPLT_tp entries, int nentries)
887 888 889 890 891 892 893
/*
 *  entries        - array of png_sPLT_t structures
 *                   to be added to the list of palettes
 *                   in the info structure.
 *  nentries       - number of palette structures to be
 *                   added.
 */
894
{
895 896
   png_sPLT_tp np;
   int i;
897

898 899
   if (png_ptr == NULL || info_ptr == NULL)
      return;
900

901 902
   np = (png_sPLT_tp)png_malloc_warn(png_ptr,
       (info_ptr->splt_palettes_num + nentries) *
903
        (png_size_t)png_sizeof(png_sPLT_t));
904

905 906
   if (np == NULL)
   {
907
      png_warning(png_ptr, "No memory for sPLT palettes");
908
      return;
909
   }
910

911
   png_memcpy(np, info_ptr->splt_palettes,
912
       info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
913

914 915
   png_free(png_ptr, info_ptr->splt_palettes);
   info_ptr->splt_palettes=NULL;
916

917 918 919 920 921
   for (i = 0; i < nentries; i++)
   {
      png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
      png_sPLT_tp from = entries + i;
      png_uint_32 length;
922

923
      length = png_strlen(from->name) + 1;
924
      to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length);
925

926 927 928
      if (to->name == NULL)
      {
         png_warning(png_ptr,
929
             "Out of memory while processing sPLT chunk");
930 931
         continue;
      }
932

933 934
      png_memcpy(to->name, from->name, length);
      to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
935
          (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry)));
936

937 938 939
      if (to->entries == NULL)
      {
         png_warning(png_ptr,
940
             "Out of memory while processing sPLT chunk");
941 942 943 944
         png_free(png_ptr, to->name);
         to->name = NULL;
         continue;
      }
945

946 947
      png_memcpy(to->entries, from->entries,
          from->nentries * png_sizeof(png_sPLT_entry));
948

949 950 951 952 953 954 955 956
      to->nentries = from->nentries;
      to->depth = from->depth;
   }

   info_ptr->splt_palettes = np;
   info_ptr->splt_palettes_num += nentries;
   info_ptr->valid |= PNG_INFO_sPLT;
   info_ptr->free_me |= PNG_FREE_SPLT;
957 958 959
}
#endif /* PNG_sPLT_SUPPORTED */

960
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
961
void PNGAPI
962
png_set_unknown_chunks(png_structp png_ptr,
963
   png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
964
{
965 966 967 968
   png_unknown_chunkp np;
   int i;

   if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
969
      return;
970 971 972 973

   np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
       (png_size_t)((info_ptr->unknown_chunks_num + num_unknowns) *
       png_sizeof(png_unknown_chunk)));
974

975 976 977
   if (np == NULL)
   {
      png_warning(png_ptr,
978
          "Out of memory while processing unknown chunk");
979 980 981 982
      return;
   }

   png_memcpy(np, info_ptr->unknown_chunks,
983
       info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
984

985
   png_free(png_ptr, info_ptr->unknown_chunks);
986
   info_ptr->unknown_chunks = NULL;
987 988 989 990 991 992

   for (i = 0; i < num_unknowns; i++)
   {
      png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
      png_unknown_chunkp from = unknowns + i;

993 994
      png_memcpy((png_charp)to->name, (png_charp)from->name,
          png_sizeof(from->name));
995 996
      to->name[png_sizeof(to->name)-1] = '\0';
      to->size = from->size;
997
      /* Note our location in the read or write sequence */
998 999 1000 1001
      to->location = (png_byte)(png_ptr->mode & 0xff);

      if (from->size == 0)
         to->data=NULL;
1002

1003 1004 1005
      else
      {
         to->data = (png_bytep)png_malloc_warn(png_ptr,
1006
             (png_size_t)from->size);
1007

1008 1009 1010
         if (to->data == NULL)
         {
            png_warning(png_ptr,
1011
                "Out of memory while processing unknown chunk");
1012 1013
            to->size = 0;
         }
1014

1015 1016 1017 1018 1019 1020 1021 1022
         else
            png_memcpy(to->data, from->data, from->size);
      }
   }

   info_ptr->unknown_chunks = np;
   info_ptr->unknown_chunks_num += num_unknowns;
   info_ptr->free_me |= PNG_FREE_UNKN;
1023
}
1024
void PNGAPI
1025
png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
1026
    int chunk, int location)
1027
{
1028
   if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
1029
       (int)info_ptr->unknown_chunks_num)
1030 1031
      info_ptr->unknown_chunks[chunk].location = (png_byte)location;
}
1032 1033
#endif

1034

1035
#ifdef PNG_MNG_FEATURES_SUPPORTED
1036 1037 1038
png_uint_32 PNGAPI
png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
{
1039
   png_debug(1, "in png_permit_mng_features");
1040

1041 1042
   if (png_ptr == NULL)
      return (png_uint_32)0;
1043

1044
   png_ptr->mng_features_permitted =
1045
       (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
1046

1047
   return (png_uint_32)png_ptr->mng_features_permitted;
1048 1049
}
#endif
1050

1051
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
1052
void PNGAPI
1053
png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
1054
    chunk_list, int num_chunks)
1055
{
1056 1057 1058 1059
   png_bytep new_list, p;
   int i, old_num_chunks;
   if (png_ptr == NULL)
      return;
1060

1061 1062
   if (num_chunks == 0)
   {
1063
      if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
1064
         png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1065

1066
      else
1067
         png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1068

1069
      if (keep == PNG_HANDLE_CHUNK_ALWAYS)
1070
         png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1071

1072
      else
1073
         png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1074

1075
      return;
1076 1077
   }
   if (chunk_list == NULL)
1078
      return;
1079 1080
   old_num_chunks = png_ptr->num_chunk_list;
   new_list=(png_bytep)png_malloc(png_ptr,
1081
       (png_size_t)
1082
       (5*(num_chunks + old_num_chunks)));
1083

1084 1085 1086
   if (png_ptr->chunk_list != NULL)
   {
      png_memcpy(new_list, png_ptr->chunk_list,
1087
          (png_size_t)(5*old_num_chunks));
1088 1089 1090
      png_free(png_ptr, png_ptr->chunk_list);
      png_ptr->chunk_list=NULL;
   }
1091

1092
   png_memcpy(new_list + 5*old_num_chunks, chunk_list,
1093
       (png_size_t)(5*num_chunks));
1094

1095 1096
   for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
      *p=(png_byte)keep;
1097

1098 1099 1100
   png_ptr->num_chunk_list = old_num_chunks + num_chunks;
   png_ptr->chunk_list = new_list;
   png_ptr->free_me |= PNG_FREE_LIST;
1101 1102
}
#endif
1103

1104
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
1105
void PNGAPI
1106
png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
1107
    png_user_chunk_ptr read_user_chunk_fn)
1108
{
1109
   png_debug(1, "in png_set_read_user_chunk_fn");
1110

1111 1112
   if (png_ptr == NULL)
      return;
1113

1114 1115 1116 1117
   png_ptr->read_user_chunk_fn = read_user_chunk_fn;
   png_ptr->user_chunk_ptr = user_chunk_ptr;
}
#endif
1118

1119
#ifdef PNG_INFO_IMAGE_SUPPORTED
1120
void PNGAPI
1121 1122
png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
{
1123
   png_debug1(1, "in %s storage function", "rows");
1124

1125 1126 1127
   if (png_ptr == NULL || info_ptr == NULL)
      return;

1128
   if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
1129
      png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
1130

1131
   info_ptr->row_pointers = row_pointers;
1132

1133
   if (row_pointers)
1134
      info_ptr->valid |= PNG_INFO_IDAT;
1135 1136 1137
}
#endif

1138
void PNGAPI
1139 1140
png_set_compression_buffer_size(png_structp png_ptr,
    png_size_t size)
1141
{
1142 1143
    if (png_ptr == NULL)
       return;
1144

1145
    png_free(png_ptr, png_ptr->zbuf);
1146
    png_ptr->zbuf_size = size;
1147 1148 1149 1150
    png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
    png_ptr->zstream.next_out = png_ptr->zbuf;
    png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
}
1151 1152 1153 1154 1155

void PNGAPI
png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
{
   if (png_ptr && info_ptr)
1156
      info_ptr->valid &= ~mask;
1157
}
1158

1159

1160 1161

#ifdef PNG_SET_USER_LIMITS_SUPPORTED
1162
/* This function was added to libpng 1.2.6 */
1163 1164 1165 1166
void PNGAPI
png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
    png_uint_32 user_height_max)
{
1167 1168 1169 1170 1171 1172
   /* Images with dimensions larger than these limits will be
    * rejected by png_set_IHDR().  To accept any PNG datastream
    * regardless of dimensions, set both limits to 0x7ffffffL.
    */
   if (png_ptr == NULL)
      return;
1173

1174 1175
   png_ptr->user_width_max = user_width_max;
   png_ptr->user_height_max = user_height_max;
1176
}
1177

1178
/* This function was added to libpng 1.4.0 */
1179 1180 1181 1182
void PNGAPI
png_set_chunk_cache_max (png_structp png_ptr,
   png_uint_32 user_chunk_cache_max)
{
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
    if (png_ptr)
       png_ptr->user_chunk_cache_max = user_chunk_cache_max;
}

/* This function was added to libpng 1.4.1 */
void PNGAPI
png_set_chunk_malloc_max (png_structp png_ptr,
   png_alloc_size_t user_chunk_malloc_max)
{
    if (png_ptr)
       png_ptr->user_chunk_malloc_max =
          (png_size_t)user_chunk_malloc_max;
1195
}
1196 1197
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */

1198

1199
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
1200 1201 1202
void PNGAPI
png_set_benign_errors(png_structp png_ptr, int allowed)
{
1203
   png_debug(1, "in png_set_benign_errors");
1204

1205
   if (allowed)
1206
      png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
1207

1208
   else
1209
      png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
1210 1211
}
#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
1212
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */