Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1897 serge 1
 
2
 *
3
 * Last changed in libpng 1.5.1 [February 3, 2011]
4
 * Copyright (c) 1998-2011 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
18
 
19
20
 
21
22
 
23
void PNGAPI
24
png_set_bKGD(png_structp png_ptr, png_infop info_ptr,
25
    png_const_color_16p background)
26
{
27
   png_debug1(1, "in %s storage function", "bKGD");
28
29
 
30
      return;
31
32
 
33
   info_ptr->valid |= PNG_INFO_bKGD;
34
}
35
#endif
36
37
 
38
void PNGFAPI
39
png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
40
    png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
41
    png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
42
    png_fixed_point blue_x, png_fixed_point blue_y)
43
{
44
   png_debug1(1, "in %s storage function", "cHRM fixed");
45
46
 
47
      return;
48
49
 
50
   if (png_check_cHRM_fixed(png_ptr,
51
       white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
52
#  endif
53
   {
54
      info_ptr->x_white = white_x;
55
      info_ptr->y_white = white_y;
56
      info_ptr->x_red   = red_x;
57
      info_ptr->y_red   = red_y;
58
      info_ptr->x_green = green_x;
59
      info_ptr->y_green = green_y;
60
      info_ptr->x_blue  = blue_x;
61
      info_ptr->y_blue  = blue_y;
62
      info_ptr->valid |= PNG_INFO_cHRM;
63
   }
64
}
65
66
 
67
void PNGAPI
68
png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
69
    double white_x, double white_y, double red_x, double red_y,
70
    double green_x, double green_y, double blue_x, double blue_y)
71
{
72
   png_set_cHRM_fixed(png_ptr, info_ptr,
73
      png_fixed(png_ptr, white_x, "cHRM White X"),
74
      png_fixed(png_ptr, white_y, "cHRM White Y"),
75
      png_fixed(png_ptr, red_x, "cHRM Red X"),
76
      png_fixed(png_ptr, red_y, "cHRM Red Y"),
77
      png_fixed(png_ptr, green_x, "cHRM Green X"),
78
      png_fixed(png_ptr, green_y, "cHRM Green Y"),
79
      png_fixed(png_ptr, blue_x, "cHRM Blue X"),
80
      png_fixed(png_ptr, blue_y, "cHRM Blue Y"));
81
}
82
#  endif /* PNG_FLOATING_POINT_SUPPORTED */
83
84
 
85
86
 
87
void PNGFAPI
88
png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
89
    file_gamma)
90
{
91
   png_debug1(1, "in %s storage function", "gAMA");
92
93
 
94
      return;
95
96
 
97
    * wrong, therefore storing them (and setting PNG_INFO_gAMA)
98
    * must be wrong too.
99
    */
100
   if (file_gamma > (png_fixed_point)PNG_UINT_31_MAX)
101
      png_warning(png_ptr, "Gamma too large, ignored");
102
103
 
104
      png_warning(png_ptr, "Negative or zero gamma ignored");
105
106
 
107
   {
108
      info_ptr->gamma = file_gamma;
109
      info_ptr->valid |= PNG_INFO_gAMA;
110
   }
111
}
112
113
 
114
void PNGAPI
115
png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
116
{
117
   png_set_gAMA_fixed(png_ptr, info_ptr, png_fixed(png_ptr, file_gamma,
118
       "png_set_gAMA"));
119
}
120
#  endif
121
#endif
122
123
 
124
void PNGAPI
125
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_const_uint_16p hist)
126
{
127
   int i;
128
129
 
130
131
 
132
      return;
133
134
 
135
       > PNG_MAX_PALETTE_LENGTH)
136
   {
137
      png_warning(png_ptr,
138
          "Invalid palette size, hIST allocation skipped");
139
140
 
141
   }
142
143
 
144
145
 
146
    * version 1.2.1
147
    */
148
   png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
149
       PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16));
150
151
 
152
   {
153
      png_warning(png_ptr, "Insufficient memory for hIST chunk data");
154
      return;
155
   }
156
157
 
158
      png_ptr->hist[i] = hist[i];
159
160
 
161
   info_ptr->valid |= PNG_INFO_hIST;
162
   info_ptr->free_me |= PNG_FREE_HIST;
163
}
164
#endif
165
166
 
167
png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
168
    png_uint_32 width, png_uint_32 height, int bit_depth,
169
    int color_type, int interlace_type, int compression_type,
170
    int filter_type)
171
{
172
   png_debug1(1, "in %s storage function", "IHDR");
173
174
 
175
      return;
176
177
 
178
   info_ptr->height = height;
179
   info_ptr->bit_depth = (png_byte)bit_depth;
180
   info_ptr->color_type = (png_byte)color_type;
181
   info_ptr->compression_type = (png_byte)compression_type;
182
   info_ptr->filter_type = (png_byte)filter_type;
183
   info_ptr->interlace_type = (png_byte)interlace_type;
184
185
 
186
       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
187
       info_ptr->compression_type, info_ptr->filter_type);
188
189
 
190
      info_ptr->channels = 1;
191
192
 
193
      info_ptr->channels = 3;
194
195
 
196
      info_ptr->channels = 1;
197
198
 
199
      info_ptr->channels++;
200
201
 
202
203
 
204
   if (width >
205
       (PNG_UINT_32_MAX >> 3)      /* 8-byte RRGGBBAA pixels */
206
       - 48       /* bigrowbuf hack */
207
       - 1        /* filter byte */
208
       - 7*8      /* rounding of width to multiple of 8 pixels */
209
       - 8)       /* extra max_pixel_depth pad */
210
      info_ptr->rowbytes = 0;
211
   else
212
      info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
213
}
214
215
 
216
void PNGAPI
217
png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
218
    png_int_32 offset_x, png_int_32 offset_y, int unit_type)
219
{
220
   png_debug1(1, "in %s storage function", "oFFs");
221
222
 
223
      return;
224
225
 
226
   info_ptr->y_offset = offset_y;
227
   info_ptr->offset_unit_type = (png_byte)unit_type;
228
   info_ptr->valid |= PNG_INFO_oFFs;
229
}
230
#endif
231
232
 
233
void PNGAPI
234
png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
235
    png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type,
236
    int nparams, png_const_charp units, png_charpp params)
237
{
238
   png_size_t length;
239
   int i;
240
241
 
242
243
 
244
      return;
245
246
 
247
   png_debug1(3, "allocating purpose for info (%lu bytes)",
248
       (unsigned long)length);
249
250
 
251
252
 
253
   if (type < 0 || type > 3)
254
      png_error(png_ptr, "Invalid pCAL equation type");
255
256
 
257
   for (i=0; i
258
      if (!png_check_fp_string(params[i], png_strlen(params[i])))
259
         png_error(png_ptr, "Invalid format for pCAL parameter");
260
261
 
262
263
 
264
   {
265
      png_warning(png_ptr, "Insufficient memory for pCAL purpose");
266
      return;
267
   }
268
269
 
270
271
 
272
   info_ptr->pcal_X0 = X0;
273
   info_ptr->pcal_X1 = X1;
274
   info_ptr->pcal_type = (png_byte)type;
275
   info_ptr->pcal_nparams = (png_byte)nparams;
276
277
 
278
   png_debug1(3, "allocating units for info (%lu bytes)",
279
     (unsigned long)length);
280
281
 
282
283
 
284
   {
285
      png_warning(png_ptr, "Insufficient memory for pCAL units");
286
      return;
287
   }
288
289
 
290
291
 
292
       (png_size_t)((nparams + 1) * png_sizeof(png_charp)));
293
294
 
295
   {
296
      png_warning(png_ptr, "Insufficient memory for pCAL params");
297
      return;
298
   }
299
300
 
301
302
 
303
   {
304
      length = png_strlen(params[i]) + 1;
305
      png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
306
          (unsigned long)length);
307
308
 
309
310
 
311
      {
312
         png_warning(png_ptr, "Insufficient memory for pCAL parameter");
313
         return;
314
      }
315
316
 
317
   }
318
319
 
320
   info_ptr->free_me |= PNG_FREE_PCAL;
321
}
322
#endif
323
324
 
325
void PNGAPI
326
png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
327
    int unit, png_const_charp swidth, png_const_charp sheight)
328
{
329
   png_size_t lengthw = 0, lengthh = 0;
330
331
 
332
333
 
334
      return;
335
336
 
337
    * unit unless this is an API call.)
338
    */
339
   if (unit != 1 && unit != 2)
340
      png_error(png_ptr, "Invalid sCAL unit");
341
342
 
343
       swidth[0] == 45 /*'-'*/ || !png_check_fp_string(swidth, lengthw))
344
      png_error(png_ptr, "Invalid sCAL width");
345
346
 
347
       sheight[0] == 45 /*'-'*/ || !png_check_fp_string(sheight, lengthh))
348
      png_error(png_ptr, "Invalid sCAL height");
349
350
 
351
352
 
353
354
 
355
356
 
357
358
 
359
   {
360
      png_warning(png_ptr, "Memory allocation failed while processing sCAL");
361
      return;
362
   }
363
364
 
365
366
 
367
368
 
369
370
 
371
372
 
373
   {
374
      png_free (png_ptr, info_ptr->scal_s_width);
375
      info_ptr->scal_s_width = NULL;
376
377
 
378
      return;
379
   }
380
381
 
382
383
 
384
   info_ptr->free_me |= PNG_FREE_SCAL;
385
}
386
387
 
388
void PNGAPI
389
png_set_sCAL(png_structp png_ptr, png_infop info_ptr, int unit, double width,
390
    double height)
391
{
392
   png_debug1(1, "in %s storage function", "sCAL");
393
394
 
395
   if (width <= 0)
396
      png_warning(png_ptr, "Invalid sCAL width ignored");
397
398
 
399
      png_warning(png_ptr, "Invalid sCAL height ignored");
400
401
 
402
   {
403
      /* Convert 'width' and 'height' to ASCII. */
404
      char swidth[PNG_sCAL_MAX_DIGITS+1];
405
      char sheight[PNG_sCAL_MAX_DIGITS+1];
406
407
 
408
         PNG_sCAL_PRECISION);
409
      png_ascii_from_fp(png_ptr, sheight, sizeof sheight, height,
410
         PNG_sCAL_PRECISION);
411
412
 
413
   }
414
}
415
#  endif
416
417
 
418
void PNGAPI
419
png_set_sCAL_fixed(png_structp png_ptr, png_infop info_ptr, int unit,
420
    png_fixed_point width, png_fixed_point height)
421
{
422
   png_debug1(1, "in %s storage function", "sCAL");
423
424
 
425
   if (width <= 0)
426
      png_warning(png_ptr, "Invalid sCAL width ignored");
427
428
 
429
      png_warning(png_ptr, "Invalid sCAL height ignored");
430
431
 
432
   {
433
      /* Convert 'width' and 'height' to ASCII. */
434
      char swidth[PNG_sCAL_MAX_DIGITS+1];
435
      char sheight[PNG_sCAL_MAX_DIGITS+1];
436
437
 
438
      png_ascii_from_fixed(png_ptr, sheight, sizeof sheight, height);
439
440
 
441
   }
442
}
443
#  endif
444
#endif
445
446
 
447
void PNGAPI
448
png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
449
    png_uint_32 res_x, png_uint_32 res_y, int unit_type)
450
{
451
   png_debug1(1, "in %s storage function", "pHYs");
452
453
 
454
      return;
455
456
 
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
463
 
464
png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
465
    png_const_colorp palette, int num_palette)
466
{
467
468
 
469
470
 
471
      return;
472
473
 
474
   {
475
      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
476
         png_error(png_ptr, "Invalid palette length");
477
478
 
479
      {
480
         png_warning(png_ptr, "Invalid palette length");
481
         return;
482
      }
483
   }
484
485
 
486
    * we do it for backward compatibility with the way the png_handle_tRNS
487
    * function used to do the allocation.
488
    */
489
   png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
490
491
 
492
    * of num_palette entries, in case of an invalid PNG file that has
493
    * too-large sample values.
494
    */
495
   png_ptr->palette = (png_colorp)png_calloc(png_ptr,
496
       PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
497
498
 
499
   info_ptr->palette = png_ptr->palette;
500
   info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
501
502
 
503
504
 
505
}
506
507
 
508
void PNGAPI
509
png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
510
    png_const_color_8p sig_bit)
511
{
512
   png_debug1(1, "in %s storage function", "sBIT");
513
514
 
515
      return;
516
517
 
518
   info_ptr->valid |= PNG_INFO_sBIT;
519
}
520
#endif
521
522
 
523
void PNGAPI
524
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int srgb_intent)
525
{
526
   png_debug1(1, "in %s storage function", "sRGB");
527
528
 
529
      return;
530
531
 
532
   info_ptr->valid |= PNG_INFO_sRGB;
533
}
534
535
 
536
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
537
    int srgb_intent)
538
{
539
   png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
540
541
 
542
      return;
543
544
 
545
546
 
547
   png_set_gAMA_fixed(png_ptr, info_ptr, 45455L);
548
#  endif
549
550
 
551
   png_set_cHRM_fixed(png_ptr, info_ptr,
552
      /* color      x       y */
553
      /* white */ 31270L, 32900L,
554
      /* red   */ 64000L, 33000L,
555
      /* green */ 30000L, 60000L,
556
      /* blue  */ 15000L,  6000L
557
   );
558
#  endif /* cHRM */
559
}
560
#endif /* sRGB */
561
562
 
563
 
564
void PNGAPI
565
png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
566
    png_const_charp name, int compression_type,
567
    png_const_bytep profile, png_uint_32 proflen)
568
{
569
   png_charp new_iccp_name;
570
   png_bytep new_iccp_profile;
571
   png_uint_32 length;
572
573
 
574
575
 
576
      return;
577
578
 
579
   new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
580
581
 
582
   {
583
        png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
584
      return;
585
   }
586
587
 
588
   new_iccp_profile = (png_bytep)png_malloc_warn(png_ptr, proflen);
589
590
 
591
   {
592
      png_free (png_ptr, new_iccp_name);
593
      png_warning(png_ptr,
594
          "Insufficient memory to process iCCP profile");
595
      return;
596
   }
597
598
 
599
600
 
601
602
 
603
   info_ptr->iccp_name = new_iccp_name;
604
   info_ptr->iccp_profile = new_iccp_profile;
605
   /* Compression is always zero but is here so the API and info structure
606
    * does not have to change if we introduce multiple compression types
607
    */
608
   info_ptr->iccp_compression = (png_byte)compression_type;
609
   info_ptr->free_me |= PNG_FREE_ICCP;
610
   info_ptr->valid |= PNG_INFO_iCCP;
611
}
612
#endif
613
614
 
615
void PNGAPI
616
png_set_text(png_structp png_ptr, png_infop info_ptr, png_const_textp text_ptr,
617
    int num_text)
618
{
619
   int ret;
620
   ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
621
622
 
623
      png_error(png_ptr, "Insufficient memory to store text");
624
}
625
626
 
627
png_set_text_2(png_structp png_ptr, png_infop info_ptr,
628
    png_const_textp text_ptr, int num_text)
629
{
630
   int i;
631
632
 
633
       png_ptr->chunk_name[0] == '\0') ?
634
       "text" : (png_const_charp)png_ptr->chunk_name));
635
636
 
637
      return(0);
638
639
 
640
    * to hold all of the incoming text_ptr objects.
641
    */
642
   if (info_ptr->num_text + num_text > info_ptr->max_text)
643
   {
644
      if (info_ptr->text != NULL)
645
      {
646
         png_textp old_text;
647
         int old_max;
648
649
 
650
         info_ptr->max_text = info_ptr->num_text + num_text + 8;
651
         old_text = info_ptr->text;
652
         info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
653
            (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
654
655
 
656
         {
657
            png_free(png_ptr, old_text);
658
            return(1);
659
         }
660
661
 
662
             png_sizeof(png_text)));
663
         png_free(png_ptr, old_text);
664
      }
665
666
 
667
      {
668
         info_ptr->max_text = num_text + 8;
669
         info_ptr->num_text = 0;
670
         info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
671
             (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
672
         if (info_ptr->text == NULL)
673
            return(1);
674
         info_ptr->free_me |= PNG_FREE_TEXT;
675
      }
676
677
 
678
          info_ptr->max_text);
679
   }
680
   for (i = 0; i < num_text; i++)
681
   {
682
      png_size_t text_length, key_len;
683
      png_size_t lang_len, lang_key_len;
684
      png_textp textp = &(info_ptr->text[info_ptr->num_text]);
685
686
 
687
          continue;
688
689
 
690
          text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)
691
      {
692
         png_warning(png_ptr, "text compression mode is out of range");
693
         continue;
694
      }
695
696
 
697
698
 
699
      {
700
         lang_len = 0;
701
         lang_key_len = 0;
702
      }
703
704
 
705
#  ifdef PNG_iTXt_SUPPORTED
706
      {
707
         /* Set iTXt data */
708
709
 
710
            lang_len = png_strlen(text_ptr[i].lang);
711
712
 
713
            lang_len = 0;
714
715
 
716
            lang_key_len = png_strlen(text_ptr[i].lang_key);
717
718
 
719
            lang_key_len = 0;
720
      }
721
#  else /* PNG_iTXt_SUPPORTED */
722
      {
723
         png_warning(png_ptr, "iTXt chunk not supported");
724
         continue;
725
      }
726
#  endif
727
728
 
729
      {
730
         text_length = 0;
731
#  ifdef PNG_iTXt_SUPPORTED
732
         if (text_ptr[i].compression > 0)
733
            textp->compression = PNG_ITXT_COMPRESSION_NONE;
734
735
 
736
#  endif
737
            textp->compression = PNG_TEXT_COMPRESSION_NONE;
738
      }
739
740
 
741
      {
742
         text_length = png_strlen(text_ptr[i].text);
743
         textp->compression = text_ptr[i].compression;
744
      }
745
746
 
747
          (png_size_t)
748
          (key_len + text_length + lang_len + lang_key_len + 4));
749
750
 
751
         return(1);
752
753
 
754
          (unsigned long)(png_uint_32)
755
          (key_len + lang_len + lang_key_len + text_length + 4),
756
          textp->key);
757
758
 
759
      *(textp->key + key_len) = '\0';
760
761
 
762
      {
763
         textp->lang = textp->key + key_len + 1;
764
         png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
765
         *(textp->lang + lang_len) = '\0';
766
         textp->lang_key = textp->lang + lang_len + 1;
767
         png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
768
         *(textp->lang_key + lang_key_len) = '\0';
769
         textp->text = textp->lang_key + lang_key_len + 1;
770
      }
771
772
 
773
      {
774
         textp->lang=NULL;
775
         textp->lang_key=NULL;
776
         textp->text = textp->key + key_len + 1;
777
      }
778
779
 
780
         png_memcpy(textp->text, text_ptr[i].text,
781
             (png_size_t)(text_length));
782
783
 
784
785
 
786
      if (textp->compression > 0)
787
      {
788
         textp->text_length = 0;
789
         textp->itxt_length = text_length;
790
      }
791
792
 
793
#  endif
794
      {
795
         textp->text_length = text_length;
796
         textp->itxt_length = 0;
797
      }
798
799
 
800
      png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
801
   }
802
   return(0);
803
}
804
#endif
805
806
 
807
void PNGAPI
808
png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time)
809
{
810
   png_debug1(1, "in %s storage function", "tIME");
811
812
 
813
       (png_ptr->mode & PNG_WROTE_tIME))
814
      return;
815
816
 
817
   info_ptr->valid |= PNG_INFO_tIME;
818
}
819
#endif
820
821
 
822
void PNGAPI
823
png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
824
    png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color)
825
{
826
   png_debug1(1, "in %s storage function", "tRNS");
827
828
 
829
      return;
830
831
 
832
   {
833
       /* It may not actually be necessary to set png_ptr->trans_alpha here;
834
        * we do it for backward compatibility with the way the png_handle_tRNS
835
        * function used to do the allocation.
836
        */
837
838
 
839
840
 
841
       png_ptr->trans_alpha = info_ptr->trans_alpha =
842
           (png_bytep)png_malloc(png_ptr, (png_size_t)PNG_MAX_PALETTE_LENGTH);
843
844
 
845
          png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
846
   }
847
848
 
849
   {
850
      int sample_max = (1 << info_ptr->bit_depth);
851
852
 
853
          (int)trans_color->gray > sample_max) ||
854
          (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
855
          ((int)trans_color->red > sample_max ||
856
          (int)trans_color->green > sample_max ||
857
          (int)trans_color->blue > sample_max)))
858
         png_warning(png_ptr,
859
            "tRNS chunk has out-of-range samples for bit_depth");
860
861
 
862
         png_sizeof(png_color_16));
863
864
 
865
         num_trans = 1;
866
   }
867
868
 
869
870
 
871
   {
872
      info_ptr->valid |= PNG_INFO_tRNS;
873
      info_ptr->free_me |= PNG_FREE_TRNS;
874
   }
875
}
876
#endif
877
878
 
879
void PNGAPI
880
png_set_sPLT(png_structp png_ptr,
881
    png_infop info_ptr, png_const_sPLT_tp entries, int nentries)
882
/*
883
 *  entries        - array of png_sPLT_t structures
884
 *                   to be added to the list of palettes
885
 *                   in the info structure.
886
 *
887
 *  nentries       - number of palette structures to be
888
 *                   added.
889
 */
890
{
891
   png_sPLT_tp np;
892
   int i;
893
894
 
895
      return;
896
897
 
898
       (info_ptr->splt_palettes_num + nentries) *
899
       (png_size_t)png_sizeof(png_sPLT_t));
900
901
 
902
   {
903
      png_warning(png_ptr, "No memory for sPLT palettes");
904
      return;
905
   }
906
907
 
908
       info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
909
910
 
911
   info_ptr->splt_palettes=NULL;
912
913
 
914
   {
915
      png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
916
      png_const_sPLT_tp from = entries + i;
917
      png_uint_32 length;
918
919
 
920
      to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length);
921
922
 
923
      {
924
         png_warning(png_ptr,
925
             "Out of memory while processing sPLT chunk");
926
         continue;
927
      }
928
929
 
930
      to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
931
          (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry)));
932
933
 
934
      {
935
         png_warning(png_ptr,
936
             "Out of memory while processing sPLT chunk");
937
         png_free(png_ptr, to->name);
938
         to->name = NULL;
939
         continue;
940
      }
941
942
 
943
          from->nentries * png_sizeof(png_sPLT_entry));
944
945
 
946
      to->depth = from->depth;
947
   }
948
949
 
950
   info_ptr->splt_palettes_num += nentries;
951
   info_ptr->valid |= PNG_INFO_sPLT;
952
   info_ptr->free_me |= PNG_FREE_SPLT;
953
}
954
#endif /* PNG_sPLT_SUPPORTED */
955
956
 
957
void PNGAPI
958
png_set_unknown_chunks(png_structp png_ptr,
959
   png_infop info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
960
{
961
   png_unknown_chunkp np;
962
   int i;
963
964
 
965
      return;
966
967
 
968
       (png_size_t)(info_ptr->unknown_chunks_num + num_unknowns) *
969
       png_sizeof(png_unknown_chunk));
970
971
 
972
   {
973
      png_warning(png_ptr,
974
          "Out of memory while processing unknown chunk");
975
      return;
976
   }
977
978
 
979
       (png_size_t)info_ptr->unknown_chunks_num *
980
       png_sizeof(png_unknown_chunk));
981
982
 
983
   info_ptr->unknown_chunks = NULL;
984
985
 
986
   {
987
      png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
988
      png_const_unknown_chunkp from = unknowns + i;
989
990
 
991
      to->name[png_sizeof(to->name)-1] = '\0';
992
      to->size = from->size;
993
994
 
995
      to->location = (png_byte)(png_ptr->mode & 0xff);
996
997
 
998
         to->data=NULL;
999
1000
 
1001
      {
1002
         to->data = (png_bytep)png_malloc_warn(png_ptr,
1003
             (png_size_t)from->size);
1004
1005
 
1006
         {
1007
            png_warning(png_ptr,
1008
                "Out of memory while processing unknown chunk");
1009
            to->size = 0;
1010
         }
1011
1012
 
1013
            png_memcpy(to->data, from->data, from->size);
1014
      }
1015
   }
1016
1017
 
1018
   info_ptr->unknown_chunks_num += num_unknowns;
1019
   info_ptr->free_me |= PNG_FREE_UNKN;
1020
}
1021
1022
 
1023
png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
1024
    int chunk, int location)
1025
{
1026
   if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
1027
       info_ptr->unknown_chunks_num)
1028
      info_ptr->unknown_chunks[chunk].location = (png_byte)location;
1029
}
1030
#endif
1031
1032
 
1033
 
1034
png_uint_32 PNGAPI
1035
png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
1036
{
1037
   png_debug(1, "in png_permit_mng_features");
1038
1039
 
1040
      return (png_uint_32)0;
1041
1042
 
1043
       (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
1044
1045
 
1046
}
1047
#endif
1048
1049
 
1050
void PNGAPI
1051
png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_const_bytep
1052
    chunk_list, int num_chunks)
1053
{
1054
   png_bytep new_list, p;
1055
   int i, old_num_chunks;
1056
   if (png_ptr == NULL)
1057
      return;
1058
1059
 
1060
   {
1061
      if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
1062
         png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1063
1064
 
1065
         png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1066
1067
 
1068
         png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1069
1070
 
1071
         png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1072
1073
 
1074
   }
1075
1076
 
1077
      return;
1078
1079
 
1080
   new_list=(png_bytep)png_malloc(png_ptr,
1081
       (png_size_t)(5*(num_chunks + old_num_chunks)));
1082
1083
 
1084
   {
1085
      png_memcpy(new_list, png_ptr->chunk_list,
1086
          (png_size_t)(5*old_num_chunks));
1087
      png_free(png_ptr, png_ptr->chunk_list);
1088
      png_ptr->chunk_list=NULL;
1089
   }
1090
1091
 
1092
       (png_size_t)(5*num_chunks));
1093
1094
 
1095
      *p=(png_byte)keep;
1096
1097
 
1098
   png_ptr->chunk_list = new_list;
1099
   png_ptr->free_me |= PNG_FREE_LIST;
1100
}
1101
#endif
1102
1103
 
1104
void PNGAPI
1105
png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
1106
    png_user_chunk_ptr read_user_chunk_fn)
1107
{
1108
   png_debug(1, "in png_set_read_user_chunk_fn");
1109
1110
 
1111
      return;
1112
1113
 
1114
   png_ptr->user_chunk_ptr = user_chunk_ptr;
1115
}
1116
#endif
1117
1118
 
1119
void PNGAPI
1120
png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
1121
{
1122
   png_debug1(1, "in %s storage function", "rows");
1123
1124
 
1125
      return;
1126
1127
 
1128
      png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
1129
1130
 
1131
1132
 
1133
      info_ptr->valid |= PNG_INFO_IDAT;
1134
}
1135
#endif
1136
1137
 
1138
png_set_compression_buffer_size(png_structp png_ptr, png_size_t size)
1139
{
1140
    if (png_ptr == NULL)
1141
       return;
1142
1143
 
1144
1145
 
1146
    {
1147
       png_warning(png_ptr, "Attempt to set buffer size beyond max ignored");
1148
       png_ptr->zbuf_size = ZLIB_IO_MAX;
1149
       size = ZLIB_IO_MAX; /* must fit */
1150
    }
1151
1152
 
1153
       png_ptr->zbuf_size = (uInt)size;
1154
1155
 
1156
1157
 
1158
     * the buffer is actually in use.
1159
     */
1160
    png_ptr->zstream.next_out = png_ptr->zbuf;
1161
    png_ptr->zstream.avail_out = 0;
1162
    png_ptr->zstream.avail_in = 0;
1163
}
1164
1165
 
1166
png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
1167
{
1168
   if (png_ptr && info_ptr)
1169
      info_ptr->valid &= ~mask;
1170
}
1171
1172
 
1173
 
1174
 
1175
/* This function was added to libpng 1.2.6 */
1176
void PNGAPI
1177
png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
1178
    png_uint_32 user_height_max)
1179
{
1180
   /* Images with dimensions larger than these limits will be
1181
    * rejected by png_set_IHDR().  To accept any PNG datastream
1182
    * regardless of dimensions, set both limits to 0x7ffffffL.
1183
    */
1184
   if (png_ptr == NULL)
1185
      return;
1186
1187
 
1188
   png_ptr->user_height_max = user_height_max;
1189
}
1190
1191
 
1192
void PNGAPI
1193
png_set_chunk_cache_max (png_structp png_ptr,
1194
   png_uint_32 user_chunk_cache_max)
1195
{
1196
    if (png_ptr)
1197
       png_ptr->user_chunk_cache_max = user_chunk_cache_max;
1198
}
1199
1200
 
1201
void PNGAPI
1202
png_set_chunk_malloc_max (png_structp png_ptr,
1203
    png_alloc_size_t user_chunk_malloc_max)
1204
{
1205
   if (png_ptr)
1206
      png_ptr->user_chunk_malloc_max = user_chunk_malloc_max;
1207
}
1208
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1209
1210
 
1211
 
1212
void PNGAPI
1213
png_set_benign_errors(png_structp png_ptr, int allowed)
1214
{
1215
   png_debug(1, "in png_set_benign_errors");
1216
1217
 
1218
      png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
1219
1220
 
1221
      png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
1222
}
1223
#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
1224
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
1225
>