1
2
3
4
5
6
7
8
9
10
11
12
13
14#define PNG_INTERNAL
15#define PNG_NO_EXTERN
16#define PNG_NO_PEDANTIC_WARNINGS
17#include "png.h"
18
19
20typedef version_1_2_44 Your_png_h_is_not_version_1_2_44;
21
22
23
24
25
26#ifdef PNG_USE_GLOBAL_ARRAYS
27
28PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
29
30#ifdef PNG_READ_SUPPORTED
31
32
33
34PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
35#endif
36
37
38PNG_IHDR;
39PNG_IDAT;
40PNG_IEND;
41PNG_PLTE;
42PNG_bKGD;
43PNG_cHRM;
44PNG_gAMA;
45PNG_hIST;
46PNG_iCCP;
47PNG_iTXt;
48PNG_oFFs;
49PNG_pCAL;
50PNG_sCAL;
51PNG_pHYs;
52PNG_sBIT;
53PNG_sPLT;
54PNG_sRGB;
55PNG_tEXt;
56PNG_tIME;
57PNG_tRNS;
58PNG_zTXt;
59
60#ifdef PNG_READ_SUPPORTED
61
62
63
64PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
65
66
67PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
68
69
70PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
71
72
73PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
74
75
76
77
78
79
80
81PNG_CONST int FARDATA png_pass_mask[] =
82 {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
83
84
85PNG_CONST int FARDATA png_pass_dsp_mask[]
86 = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
87
88#endif
89#endif
90
91
92
93
94
95
96
97#ifdef PNG_READ_SUPPORTED
98void PNGAPI
99png_set_sig_bytes(png_structp png_ptr, int num_bytes)
100{
101 png_debug(1, "in png_set_sig_bytes");
102
103 if (png_ptr == NULL)
104 return;
105
106 if (num_bytes > 8)
107 png_error(png_ptr, "Too many bytes for PNG signature.");
108
109 png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
110}
111
112
113
114
115
116
117
118
119
120int PNGAPI
121png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
122{
123 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
124 if (num_to_check > 8)
125 num_to_check = 8;
126 else if (num_to_check < 1)
127 return (-1);
128
129 if (start > 7)
130 return (-1);
131
132 if (start + num_to_check > 8)
133 num_to_check = 8 - start;
134
135 return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
136}
137
138#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
139
140
141
142
143int PNGAPI
144png_check_sig(png_bytep sig, int num)
145{
146 return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
147}
148#endif
149#endif
150
151#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
152
153#ifdef PNG_1_0_X
154voidpf PNGAPI
155#else
156voidpf
157#endif
158png_zalloc(voidpf png_ptr, uInt items, uInt size)
159{
160 png_voidp ptr;
161 png_structp p=(png_structp)png_ptr;
162 png_uint_32 save_flags=p->flags;
163 png_uint_32 num_bytes;
164
165 if (png_ptr == NULL)
166 return (NULL);
167 if (items > PNG_UINT_32_MAX/size)
168 {
169 png_warning (p, "Potential overflow in png_zalloc()");
170 return (NULL);
171 }
172 num_bytes = (png_uint_32)items * size;
173
174 p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
175 ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
176 p->flags=save_flags;
177
178#if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
179 if (ptr == NULL)
180 return ((voidpf)ptr);
181
182 if (num_bytes > (png_uint_32)0x8000L)
183 {
184 png_memset(ptr, 0, (png_size_t)0x8000L);
185 png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
186 (png_size_t)(num_bytes - (png_uint_32)0x8000L));
187 }
188 else
189 {
190 png_memset(ptr, 0, (png_size_t)num_bytes);
191 }
192#endif
193 return ((voidpf)ptr);
194}
195
196
197#ifdef PNG_1_0_X
198void PNGAPI
199#else
200void
201#endif
202png_zfree(voidpf png_ptr, voidpf ptr)
203{
204 png_free((png_structp)png_ptr, (png_voidp)ptr);
205}
206
207
208
209
210void
211png_reset_crc(png_structp png_ptr)
212{
213 png_ptr->crc = crc32(0, Z_NULL, 0);
214}
215
216
217
218
219
220
221void
222png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
223{
224 int need_crc = 1;
225
226 if (png_ptr->chunk_name[0] & 0x20)
227 {
228 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
229 (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
230 need_crc = 0;
231 }
232 else
233 {
234 if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
235 need_crc = 0;
236 }
237
238 if (need_crc)
239 png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
240}
241
242
243
244
245
246
247
248png_infop PNGAPI
249png_create_info_struct(png_structp png_ptr)
250{
251 png_infop info_ptr;
252
253 png_debug(1, "in png_create_info_struct");
254
255 if (png_ptr == NULL)
256 return (NULL);
257
258#ifdef PNG_USER_MEM_SUPPORTED
259 info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
260 png_ptr->malloc_fn, png_ptr->mem_ptr);
261#else
262 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
263#endif
264 if (info_ptr != NULL)
265 png_info_init_3(&info_ptr, png_sizeof(png_info));
266
267 return (info_ptr);
268}
269
270
271
272
273
274
275void PNGAPI
276png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
277{
278 png_infop info_ptr = NULL;
279
280 png_debug(1, "in png_destroy_info_struct");
281
282 if (png_ptr == NULL)
283 return;
284
285 if (info_ptr_ptr != NULL)
286 info_ptr = *info_ptr_ptr;
287
288 if (info_ptr != NULL)
289 {
290 png_info_destroy(png_ptr, info_ptr);
291
292#ifdef PNG_USER_MEM_SUPPORTED
293 png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
294 png_ptr->mem_ptr);
295#else
296 png_destroy_struct((png_voidp)info_ptr);
297#endif
298 *info_ptr_ptr = NULL;
299 }
300}
301
302
303
304
305
306#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
307#undef png_info_init
308void PNGAPI
309png_info_init(png_infop info_ptr)
310{
311
312 png_info_init_3(&info_ptr, 0);
313}
314#endif
315
316void PNGAPI
317png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
318{
319 png_infop info_ptr = *ptr_ptr;
320
321 png_debug(1, "in png_info_init_3");
322
323 if (info_ptr == NULL)
324 return;
325
326 if (png_sizeof(png_info) > png_info_struct_size)
327 {
328 png_destroy_struct(info_ptr);
329 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
330 *ptr_ptr = info_ptr;
331 }
332
333
334 png_memset(info_ptr, 0, png_sizeof(png_info));
335}
336
337#ifdef PNG_FREE_ME_SUPPORTED
338void PNGAPI
339png_data_freer(png_structp png_ptr, png_infop info_ptr,
340 int freer, png_uint_32 mask)
341{
342 png_debug(1, "in png_data_freer");
343
344 if (png_ptr == NULL || info_ptr == NULL)
345 return;
346
347 if (freer == PNG_DESTROY_WILL_FREE_DATA)
348 info_ptr->free_me |= mask;
349 else if (freer == PNG_USER_WILL_FREE_DATA)
350 info_ptr->free_me &= ~mask;
351 else
352 png_warning(png_ptr,
353 "Unknown freer parameter in png_data_freer.");
354}
355#endif
356
357void PNGAPI
358png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
359 int num)
360{
361 png_debug(1, "in png_free_data");
362
363 if (png_ptr == NULL || info_ptr == NULL)
364 return;
365
366#ifdef PNG_TEXT_SUPPORTED
367
368#ifdef PNG_FREE_ME_SUPPORTED
369 if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
370#else
371 if (mask & PNG_FREE_TEXT)
372#endif
373 {
374 if (num != -1)
375 {
376 if (info_ptr->text && info_ptr->text[num].key)
377 {
378 png_free(png_ptr, info_ptr->text[num].key);
379 info_ptr->text[num].key = NULL;
380 }
381 }
382 else
383 {
384 int i;
385 for (i = 0; i < info_ptr->num_text; i++)
386 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
387 png_free(png_ptr, info_ptr->text);
388 info_ptr->text = NULL;
389 info_ptr->num_text=0;
390 }
391 }
392#endif
393
394#ifdef PNG_tRNS_SUPPORTED
395
396#ifdef PNG_FREE_ME_SUPPORTED
397 if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
398#else
399 if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
400#endif
401 {
402 png_free(png_ptr, info_ptr->trans);
403 info_ptr->trans = NULL;
404 info_ptr->valid &= ~PNG_INFO_tRNS;
405#ifndef PNG_FREE_ME_SUPPORTED
406 png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
407#endif
408 }
409#endif
410
411#ifdef PNG_sCAL_SUPPORTED
412
413#ifdef PNG_FREE_ME_SUPPORTED
414 if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
415#else
416 if (mask & PNG_FREE_SCAL)
417#endif
418 {
419#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
420 png_free(png_ptr, info_ptr->scal_s_width);
421 png_free(png_ptr, info_ptr->scal_s_height);
422 info_ptr->scal_s_width = NULL;
423 info_ptr->scal_s_height = NULL;
424#endif
425 info_ptr->valid &= ~PNG_INFO_sCAL;
426 }
427#endif
428
429#ifdef PNG_pCAL_SUPPORTED
430
431#ifdef PNG_FREE_ME_SUPPORTED
432 if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
433#else
434 if (mask & PNG_FREE_PCAL)
435#endif
436 {
437 png_free(png_ptr, info_ptr->pcal_purpose);
438 png_free(png_ptr, info_ptr->pcal_units);
439 info_ptr->pcal_purpose = NULL;
440 info_ptr->pcal_units = NULL;
441 if (info_ptr->pcal_params != NULL)
442 {
443 int i;
444 for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
445 {
446 png_free(png_ptr, info_ptr->pcal_params[i]);
447 info_ptr->pcal_params[i] = NULL;
448 }
449 png_free(png_ptr, info_ptr->pcal_params);
450 info_ptr->pcal_params = NULL;
451 }
452 info_ptr->valid &= ~PNG_INFO_pCAL;
453 }
454#endif
455
456#ifdef PNG_iCCP_SUPPORTED
457
458#ifdef PNG_FREE_ME_SUPPORTED
459 if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
460#else
461 if (mask & PNG_FREE_ICCP)
462#endif
463 {
464 png_free(png_ptr, info_ptr->iccp_name);
465 png_free(png_ptr, info_ptr->iccp_profile);
466 info_ptr->iccp_name = NULL;
467 info_ptr->iccp_profile = NULL;
468 info_ptr->valid &= ~PNG_INFO_iCCP;
469 }
470#endif
471
472#ifdef PNG_sPLT_SUPPORTED
473
474#ifdef PNG_FREE_ME_SUPPORTED
475 if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
476#else
477 if (mask & PNG_FREE_SPLT)
478#endif
479 {
480 if (num != -1)
481 {
482 if (info_ptr->splt_palettes)
483 {
484 png_free(png_ptr, info_ptr->splt_palettes[num].name);
485 png_free(png_ptr, info_ptr->splt_palettes[num].entries);
486 info_ptr->splt_palettes[num].name = NULL;
487 info_ptr->splt_palettes[num].entries = NULL;
488 }
489 }
490 else
491 {
492 if (info_ptr->splt_palettes_num)
493 {
494 int i;
495 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
496 png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
497
498 png_free(png_ptr, info_ptr->splt_palettes);
499 info_ptr->splt_palettes = NULL;
500 info_ptr->splt_palettes_num = 0;
501 }
502 info_ptr->valid &= ~PNG_INFO_sPLT;
503 }
504 }
505#endif
506
507#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
508 if (png_ptr->unknown_chunk.data)
509 {
510 png_free(png_ptr, png_ptr->unknown_chunk.data);
511 png_ptr->unknown_chunk.data = NULL;
512 }
513
514#ifdef PNG_FREE_ME_SUPPORTED
515 if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
516#else
517 if (mask & PNG_FREE_UNKN)
518#endif
519 {
520 if (num != -1)
521 {
522 if (info_ptr->unknown_chunks)
523 {
524 png_free(png_ptr, info_ptr->unknown_chunks[num].data);
525 info_ptr->unknown_chunks[num].data = NULL;
526 }
527 }
528 else
529 {
530 int i;
531
532 if (info_ptr->unknown_chunks_num)
533 {
534 for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
535 png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
536
537 png_free(png_ptr, info_ptr->unknown_chunks);
538 info_ptr->unknown_chunks = NULL;
539 info_ptr->unknown_chunks_num = 0;
540 }
541 }
542 }
543#endif
544
545#ifdef PNG_hIST_SUPPORTED
546
547#ifdef PNG_FREE_ME_SUPPORTED
548 if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
549#else
550 if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
551#endif
552 {
553 png_free(png_ptr, info_ptr->hist);
554 info_ptr->hist = NULL;
555 info_ptr->valid &= ~PNG_INFO_hIST;
556#ifndef PNG_FREE_ME_SUPPORTED
557 png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
558#endif
559 }
560#endif
561
562
563#ifdef PNG_FREE_ME_SUPPORTED
564 if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
565#else
566 if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
567#endif
568 {
569 png_zfree(png_ptr, info_ptr->palette);
570 info_ptr->palette = NULL;
571 info_ptr->valid &= ~PNG_INFO_PLTE;
572#ifndef PNG_FREE_ME_SUPPORTED
573 png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
574#endif
575 info_ptr->num_palette = 0;
576 }
577
578#ifdef PNG_INFO_IMAGE_SUPPORTED
579
580#ifdef PNG_FREE_ME_SUPPORTED
581 if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
582#else
583 if (mask & PNG_FREE_ROWS)
584#endif
585 {
586 if (info_ptr->row_pointers)
587 {
588 int row;
589 for (row = 0; row < (int)info_ptr->height; row++)
590 {
591 png_free(png_ptr, info_ptr->row_pointers[row]);
592 info_ptr->row_pointers[row] = NULL;
593 }
594 png_free(png_ptr, info_ptr->row_pointers);
595 info_ptr->row_pointers = NULL;
596 }
597 info_ptr->valid &= ~PNG_INFO_IDAT;
598 }
599#endif
600
601#ifdef PNG_FREE_ME_SUPPORTED
602 if (num == -1)
603 info_ptr->free_me &= ~mask;
604 else
605 info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
606#endif
607}
608
609
610
611
612
613void
614png_info_destroy(png_structp png_ptr, png_infop info_ptr)
615{
616 png_debug(1, "in png_info_destroy");
617
618 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
619
620#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
621 if (png_ptr->num_chunk_list)
622 {
623 png_free(png_ptr, png_ptr->chunk_list);
624 png_ptr->chunk_list = NULL;
625 png_ptr->num_chunk_list = 0;
626 }
627#endif
628
629 png_info_init_3(&info_ptr, png_sizeof(png_info));
630}
631#endif
632
633
634
635
636
637png_voidp PNGAPI
638png_get_io_ptr(png_structp png_ptr)
639{
640 if (png_ptr == NULL)
641 return (NULL);
642 return (png_ptr->io_ptr);
643}
644
645#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
646#ifdef PNG_STDIO_SUPPORTED
647
648
649
650
651
652
653void PNGAPI
654png_init_io(png_structp png_ptr, png_FILE_p fp)
655{
656 png_debug(1, "in png_init_io");
657
658 if (png_ptr == NULL)
659 return;
660
661 png_ptr->io_ptr = (png_voidp)fp;
662}
663#endif
664
665#ifdef PNG_TIME_RFC1123_SUPPORTED
666
667
668
669png_charp PNGAPI
670png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
671{
672 static PNG_CONST char short_months[12][4] =
673 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
674 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
675
676 if (png_ptr == NULL)
677 return (NULL);
678 if (png_ptr->time_buffer == NULL)
679 {
680 png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
681 png_sizeof(char)));
682 }
683
684#ifdef _WIN32_WCE
685 {
686 wchar_t time_buf[29];
687 wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
688 ptime->day % 32, short_months[(ptime->month - 1) % 12],
689 ptime->year, ptime->hour % 24, ptime->minute % 60,
690 ptime->second % 61);
691 WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer,
692 29, NULL, NULL);
693 }
694#else
695#ifdef USE_FAR_KEYWORD
696 {
697 char near_time_buf[29];
698 png_snprintf6(near_time_buf, 29, "%d %s %d %02d:%02d:%02d +0000",
699 ptime->day % 32, short_months[(ptime->month - 1) % 12],
700 ptime->year, ptime->hour % 24, ptime->minute % 60,
701 ptime->second % 61);
702 png_memcpy(png_ptr->time_buffer, near_time_buf,
703 29*png_sizeof(char));
704 }
705#else
706 png_snprintf6(png_ptr->time_buffer, 29, "%d %s %d %02d:%02d:%02d +0000",
707 ptime->day % 32, short_months[(ptime->month - 1) % 12],
708 ptime->year, ptime->hour % 24, ptime->minute % 60,
709 ptime->second % 61);
710#endif
711#endif
712 return ((png_charp)png_ptr->time_buffer);
713}
714#endif
715
716#endif
717
718png_charp PNGAPI
719png_get_copyright(png_structp png_ptr)
720{
721 png_ptr = png_ptr;
722#ifdef PNG_STRING_COPYRIGHT
723 return PNG_STRING_COPYRIGHT
724#else
725#ifdef __STDC__
726 return ((png_charp) PNG_STRING_NEWLINE \
727 "libpng version 1.2.44 - June 26, 2010" PNG_STRING_NEWLINE \
728 "Copyright (c) 1998-2010 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
729 "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
730 "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
731 PNG_STRING_NEWLINE);
732#else
733 return ((png_charp) "libpng version 1.2.44 - June 26, 2010\
734 Copyright (c) 1998-2010 Glenn Randers-Pehrson\
735 Copyright (c) 1996-1997 Andreas Dilger\
736 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.");
737#endif
738#endif
739}
740
741
742
743
744
745
746
747
748
749png_charp PNGAPI
750png_get_libpng_ver(png_structp png_ptr)
751{
752
753 png_ptr = png_ptr;
754 return ((png_charp) PNG_LIBPNG_VER_STRING);
755}
756
757png_charp PNGAPI
758png_get_header_ver(png_structp png_ptr)
759{
760
761 png_ptr = png_ptr;
762 return ((png_charp) PNG_LIBPNG_VER_STRING);
763}
764
765png_charp PNGAPI
766png_get_header_version(png_structp png_ptr)
767{
768
769 png_ptr = png_ptr;
770#ifdef __STDC__
771 return ((png_charp) PNG_HEADER_VERSION_STRING
772#ifndef PNG_READ_SUPPORTED
773 " (NO READ SUPPORT)"
774#endif
775 PNG_STRING_NEWLINE);
776#else
777 return ((png_charp) PNG_HEADER_VERSION_STRING);
778#endif
779}
780
781#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
782#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
783int PNGAPI
784png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
785{
786
787 int i;
788 png_bytep p;
789 if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
790 return 0;
791 p = png_ptr->chunk_list + png_ptr->num_chunk_list*5 - 5;
792 for (i = png_ptr->num_chunk_list; i; i--, p -= 5)
793 if (!png_memcmp(chunk_name, p, 4))
794 return ((int)*(p + 4));
795 return 0;
796}
797#endif
798
799
800int PNGAPI
801png_reset_zstream(png_structp png_ptr)
802{
803 if (png_ptr == NULL)
804 return Z_STREAM_ERROR;
805 return (inflateReset(&png_ptr->zstream));
806}
807#endif
808
809
810png_uint_32 PNGAPI
811png_access_version_number(void)
812{
813
814 return((png_uint_32) PNG_LIBPNG_VER);
815}
816
817
818#if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
819#ifndef PNG_1_0_X
820
821int PNGAPI
822png_mmx_support(void)
823{
824
825 return -1;
826}
827#endif
828#endif
829
830#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
831#ifdef PNG_SIZE_T
832
833 PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
834png_size_t PNGAPI
835png_convert_size(size_t size)
836{
837 if (size > (png_size_t)-1)
838 PNG_ABORT();
839 return ((png_size_t)size);
840}
841#endif
842
843
844#ifdef PNG_cHRM_SUPPORTED
845#ifdef PNG_CHECK_cHRM_SUPPORTED
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862void
863png_64bit_product (long v1, long v2, unsigned long *hi_product,
864 unsigned long *lo_product)
865{
866 int a, b, c, d;
867 long lo, hi, x, y;
868
869 a = (v1 >> 16) & 0xffff;
870 b = v1 & 0xffff;
871 c = (v2 >> 16) & 0xffff;
872 d = v2 & 0xffff;
873
874 lo = b * d;
875 x = a * d + c * b;
876 y = ((lo >> 16) & 0xffff) + x;
877
878 lo = (lo & 0xffff) | ((y & 0xffff) << 16);
879 hi = (y >> 16) & 0xffff;
880
881 hi += a * c;
882
883 *hi_product = (unsigned long)hi;
884 *lo_product = (unsigned long)lo;
885}
886
887int
888png_check_cHRM_fixed(png_structp png_ptr,
889 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
890 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
891 png_fixed_point blue_x, png_fixed_point blue_y)
892{
893 int ret = 1;
894 unsigned long xy_hi,xy_lo,yx_hi,yx_lo;
895
896 png_debug(1, "in function png_check_cHRM_fixed");
897
898 if (png_ptr == NULL)
899 return 0;
900
901 if (white_x < 0 || white_y <= 0 ||
902 red_x < 0 || red_y < 0 ||
903 green_x < 0 || green_y < 0 ||
904 blue_x < 0 || blue_y < 0)
905 {
906 png_warning(png_ptr,
907 "Ignoring attempt to set negative chromaticity value");
908 ret = 0;
909 }
910 if (white_x > (png_fixed_point) PNG_UINT_31_MAX ||
911 white_y > (png_fixed_point) PNG_UINT_31_MAX ||
912 red_x > (png_fixed_point) PNG_UINT_31_MAX ||
913 red_y > (png_fixed_point) PNG_UINT_31_MAX ||
914 green_x > (png_fixed_point) PNG_UINT_31_MAX ||
915 green_y > (png_fixed_point) PNG_UINT_31_MAX ||
916 blue_x > (png_fixed_point) PNG_UINT_31_MAX ||
917 blue_y > (png_fixed_point) PNG_UINT_31_MAX )
918 {
919 png_warning(png_ptr,
920 "Ignoring attempt to set chromaticity value exceeding 21474.83");
921 ret = 0;
922 }
923 if (white_x > 100000L - white_y)
924 {
925 png_warning(png_ptr, "Invalid cHRM white point");
926 ret = 0;
927 }
928 if (red_x > 100000L - red_y)
929 {
930 png_warning(png_ptr, "Invalid cHRM red point");
931 ret = 0;
932 }
933 if (green_x > 100000L - green_y)
934 {
935 png_warning(png_ptr, "Invalid cHRM green point");
936 ret = 0;
937 }
938 if (blue_x > 100000L - blue_y)
939 {
940 png_warning(png_ptr, "Invalid cHRM blue point");
941 ret = 0;
942 }
943
944 png_64bit_product(green_x - red_x, blue_y - red_y, &xy_hi, &xy_lo);
945 png_64bit_product(green_y - red_y, blue_x - red_x, &yx_hi, &yx_lo);
946
947 if (xy_hi == yx_hi && xy_lo == yx_lo)
948 {
949 png_warning(png_ptr,
950 "Ignoring attempt to set cHRM RGB triangle with zero area");
951 ret = 0;
952 }
953
954 return ret;
955}
956#endif
957#endif
958
959void
960png_check_IHDR(png_structp png_ptr,
961 png_uint_32 width, png_uint_32 height, int bit_depth,
962 int color_type, int interlace_type, int compression_type,
963 int filter_type)
964{
965 int error = 0;
966
967
968 if (width == 0)
969 {
970 png_warning(png_ptr, "Image width is zero in IHDR");
971 error = 1;
972 }
973
974 if (height == 0)
975 {
976 png_warning(png_ptr, "Image height is zero in IHDR");
977 error = 1;
978 }
979
980#ifdef PNG_SET_USER_LIMITS_SUPPORTED
981 if (width > png_ptr->user_width_max || width > PNG_USER_WIDTH_MAX)
982#else
983 if (width > PNG_USER_WIDTH_MAX)
984#endif
985 {
986 png_warning(png_ptr, "Image width exceeds user limit in IHDR");
987 error = 1;
988 }
989
990#ifdef PNG_SET_USER_LIMITS_SUPPORTED
991 if (height > png_ptr->user_height_max || height > PNG_USER_HEIGHT_MAX)
992#else
993 if (height > PNG_USER_HEIGHT_MAX)
994#endif
995 {
996 png_warning(png_ptr, "Image height exceeds user limit in IHDR");
997 error = 1;
998 }
999
1000 if (width > PNG_UINT_31_MAX)
1001 {
1002 png_warning(png_ptr, "Invalid image width in IHDR");
1003 error = 1;
1004 }
1005
1006 if ( height > PNG_UINT_31_MAX)
1007 {
1008 png_warning(png_ptr, "Invalid image height in IHDR");
1009 error = 1;
1010 }
1011
1012 if ( width > (PNG_UINT_32_MAX
1013 >> 3)
1014 - 64
1015 - 1
1016 - 7*8
1017 - 8)
1018 png_warning(png_ptr, "Width is too large for libpng to process pixels");
1019
1020
1021 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
1022 bit_depth != 8 && bit_depth != 16)
1023 {
1024 png_warning(png_ptr, "Invalid bit depth in IHDR");
1025 error = 1;
1026 }
1027
1028 if (color_type < 0 || color_type == 1 ||
1029 color_type == 5 || color_type > 6)
1030 {
1031 png_warning(png_ptr, "Invalid color type in IHDR");
1032 error = 1;
1033 }
1034
1035 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
1036 ((color_type == PNG_COLOR_TYPE_RGB ||
1037 color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
1038 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
1039 {
1040 png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR");
1041 error = 1;
1042 }
1043
1044 if (interlace_type >= PNG_INTERLACE_LAST)
1045 {
1046 png_warning(png_ptr, "Unknown interlace method in IHDR");
1047 error = 1;
1048 }
1049
1050 if (compression_type != PNG_COMPRESSION_TYPE_BASE)
1051 {
1052 png_warning(png_ptr, "Unknown compression method in IHDR");
1053 error = 1;
1054 }
1055
1056#ifdef PNG_MNG_FEATURES_SUPPORTED
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066 if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) &&
1067 png_ptr->mng_features_permitted)
1068 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
1069
1070 if (filter_type != PNG_FILTER_TYPE_BASE)
1071 {
1072 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
1073 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
1074 ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) &&
1075 (color_type == PNG_COLOR_TYPE_RGB ||
1076 color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
1077 {
1078 png_warning(png_ptr, "Unknown filter method in IHDR");
1079 error = 1;
1080 }
1081
1082 if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE)
1083 {
1084 png_warning(png_ptr, "Invalid filter method in IHDR");
1085 error = 1;
1086 }
1087 }
1088
1089#else
1090 if (filter_type != PNG_FILTER_TYPE_BASE)
1091 {
1092 png_warning(png_ptr, "Unknown filter method in IHDR");
1093 error = 1;
1094 }
1095#endif
1096
1097 if (error == 1)
1098 png_error(png_ptr, "Invalid IHDR data");
1099}
1100#endif
1101