Changeset 103316 in vbox for trunk/src/libs/libpng-1.6.42/contrib
- Timestamp:
- Feb 12, 2024 3:57:56 PM (12 months ago)
- Location:
- trunk/src/libs/libpng-1.6.42/contrib
- Files:
-
- 8 deleted
- 35 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/libpng-1.6.42/contrib/arm-neon/android-ndk.c
r96425 r103316 3 3 * Copyright (c) 2014 Glenn Randers-Pehrson 4 4 * Written by John Bowler, 2014. 5 * Last changed in libpng 1.6.10 [March 6, 2014]6 5 * 7 6 * This code is released under the libpng license. … … 25 24 * only the header files exist in the NDK. 26 25 */ 26 27 27 #include <cpu-features.h> 28 28 -
trunk/src/libs/libpng-1.6.42/contrib/arm-neon/linux-auxv.c
r96425 r103316 3 3 * Copyright (c) 2014 Glenn Randers-Pehrson 4 4 * Written by Mans Rullgard, 2011. 5 * Last changed in libpng 1.6.10 [March 6, 2014]6 5 * 7 6 * This code is released under the libpng license. … … 23 22 * looking at each element for one that records NEON capabilities. 24 23 */ 24 25 25 #include <unistd.h> /* for POSIX 1003.1 */ 26 26 #include <errno.h> /* for EINTR */ -
trunk/src/libs/libpng-1.6.42/contrib/arm-neon/linux.c
r96425 r103316 1 1 /* contrib/arm-neon/linux.c 2 2 * 3 * Last changed in libpng 1.6.31 [July 27, 2017]4 3 * Copyright (c) 2014, 2017 Glenn Randers-Pehrson 5 4 * Written by John Bowler, 2014, 2017. … … 20 19 * however use <stdio.h> and it assumes that /proc/cpuinfo is never localized. 21 20 */ 21 22 22 #include <stdio.h> 23 23 -
trunk/src/libs/libpng-1.6.42/contrib/examples/pngtopng.c
r96425 r103316 5 5 * related or neighboring rights to this work. This work is published from: 6 6 * United States. 7 *8 * Last changed in libpng 1.6.29 [March 16, 2017]9 7 * 10 8 * Read a PNG and write it out in a fixed format, using the 'simplified API' -
trunk/src/libs/libpng-1.6.42/contrib/libtests/gentests.sh
r96425 r103316 2 2 # 3 3 # Copyright (c) 2013 John Cunningham Bowler 4 #5 # Last changed in libpng 1.6.0 [February 14, 2013]6 4 # 7 5 # This code is released under the libpng license. -
trunk/src/libs/libpng-1.6.42/contrib/libtests/makepng.c
r96425 r103316 4 4 #define COPYRIGHT "\251 2013,2015 John Cunningham Bowler" 5 5 /* 6 * Last changed in libpng 1.6.20 [November 24, 2015]7 *8 6 * This code is released under the libpng license. 9 7 * For conditions of distribution and use, see the disclaimer … … 300 298 volatile unsigned int ip = 0; 301 299 302 for (x=0; x<size; ++x) for (y=0; y<size; ++y)300 for (x=0; x<size; ++x) 303 301 { 304 ip = x + (size * y); 305 306 /* size is at most 16, so the scaled value below fits in 16 bits 307 */ 308 # define interp(pos, c1, c2) ((pos * c1) + ((size-pos) * c2)) 309 # define xyinterp(x, y, c1, c2, c3, c4) (((size * size / 2) +\ 310 (interp(x, c1, c2) * y + (size-y) * interp(x, c3, c4))) /\ 311 (size*size)) 312 313 set_color(palette+ip, trans+ip, 314 /* color: green, red,blue,white */ 315 xyinterp(x, y, 0, 255, 0, 255), 316 xyinterp(x, y, 255, 0, 0, 255), 317 xyinterp(x, y, 0, 0, 255, 255), 318 /* alpha: 0, 102, 204, 255) */ 319 xyinterp(x, y, 0, 102, 204, 255), 320 gamma_table); 302 for (y=0; y<size; ++y) 303 { 304 ip = x + (size * y); 305 306 /* size is at most 16, so the scaled value below fits in 16 bits 307 */ 308 # define interp(pos, c1, c2) ((pos * c1) + ((size-pos) * c2)) 309 # define xyinterp(x, y, c1, c2, c3, c4) (((size * size / 2) +\ 310 (interp(x, c1, c2) * y + (size-y) * interp(x, c3, c4))) /\ 311 (size*size)) 312 313 set_color(palette+ip, trans+ip, 314 /* color: green, red,blue,white */ 315 xyinterp(x, y, 0, 255, 0, 255), 316 xyinterp(x, y, 255, 0, 0, 255), 317 xyinterp(x, y, 0, 0, 255, 255), 318 /* alpha: 0, 102, 204, 255) */ 319 xyinterp(x, y, 0, 102, 204, 255), 320 gamma_table); 321 } 321 322 } 322 323 … … 397 398 png_uint_32 depth_max = (1U << bit_depth)-1; /* up to 65536 */ 398 399 399 if (colors[0] == 0 ) if (small)400 if (colors[0] == 0 && small) 400 401 { 401 402 unsigned int pixel_depth = pixel_depth_of_type(color_type, bit_depth); … … 496 497 case 48: 497 498 case 64: 498 /* The rows are filled by an al ogorithm similar to the above, in the499 /* The rows are filled by an algorithm similar to the above, in the 499 500 * first row pixel bytes are all equal, increasing from 0 by 1 for 500 501 * each pixel. In the second row the bytes within a pixel are … … 859 860 unsigned int i; 860 861 861 if (real_gamma == 45455) for (i=0; i<256; ++i) 862 { 863 gamma_table[i] = (png_byte)i; 864 conv = 1.; 862 if (real_gamma == 45455) 863 { 864 for (i=0; i<256; ++i) 865 { 866 gamma_table[i] = (png_byte)i; 867 conv = 1.; 868 } 865 869 } 866 870 … … 1431 1435 { 1432 1436 list[i] = param; 1433 while (*++param) if (*param == '\n' || *param == ':') 1434 { 1435 *param++ = 0; /* Terminate last parameter */ 1436 break; /* And start a new one. */ 1437 while (*++param) 1438 { 1439 if (*param == '\n' || *param == ':') 1440 { 1441 *param++ = 0; /* Terminate last parameter */ 1442 break; /* And start a new one. */ 1443 } 1437 1444 } 1438 1445 } … … 1870 1877 } 1871 1878 1872 /* small and colors are incompa rible (will probably crash if both are used at1879 /* small and colors are incompatible (will probably crash if both are used at 1873 1880 * the same time!) 1874 1881 */ -
trunk/src/libs/libpng-1.6.42/contrib/libtests/pngimage.c
r96425 r103316 1 1 2 /* pngimage.c 2 3 * 4 * Copyright (c) 2021 Cosmin Truta 3 5 * Copyright (c) 2015,2016 John Cunningham Bowler 4 *5 * Last changed in libpng 1.6.24 [August 4, 2016]6 6 * 7 7 * This code is released under the libpng license. … … 13 13 * transforms. 14 14 */ 15 15 16 #include <stdarg.h> 16 17 #include <stdlib.h> … … 318 319 t &= -t; /* first set bit */ 319 320 320 for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL) 321 { 322 if ((transform_info[i].transform & t) != 0) 323 return transform_info[i].name; 324 } 321 for (i=0; i<TTABLE_SIZE; ++i) 322 if (transform_info[i].name != NULL) 323 if ((transform_info[i].transform & t) != 0) 324 return transform_info[i].name; 325 325 326 326 return "invalid transform"; … … 339 339 unsigned int i; 340 340 341 for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL) 342 { 343 if (transform_info[i].when & TRANSFORM_R) 344 read_transforms |= transform_info[i].transform; 345 346 if (transform_info[i].when & TRANSFORM_W) 347 write_transforms |= transform_info[i].transform; 341 for (i=0; i<TTABLE_SIZE; ++i) 342 { 343 if (transform_info[i].name != NULL) 344 { 345 if (transform_info[i].when & TRANSFORM_R) 346 read_transforms |= transform_info[i].transform; 347 348 if (transform_info[i].when & TRANSFORM_W) 349 write_transforms |= transform_info[i].transform; 350 } 348 351 } 349 352 … … 963 966 unsigned int i; 964 967 965 for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)968 for (i=0; i<TTABLE_SIZE; ++i) 966 969 { 967 int transform = transform_info[i].transform; 968 969 if ((transform_info[i].valid_chunks == 0 || 970 (transform_info[i].valid_chunks & chunks) != 0) && 971 (transform_info[i].color_mask_required & ct) == 972 transform_info[i].color_mask_required && 973 (transform_info[i].color_mask_absent & ct) == 0 && 974 (transform_info[i].bit_depths & bd) != 0 && 975 (transform_info[i].when & TRANSFORM_R) != 0) 976 active |= transform; 977 978 else if ((transform_info[i].when & TRANSFORM_R) != 0) 979 inactive |= transform; 970 if (transform_info[i].name != NULL) 971 { 972 int transform = transform_info[i].transform; 973 974 if ((transform_info[i].valid_chunks == 0 || 975 (transform_info[i].valid_chunks & chunks) != 0) && 976 (transform_info[i].color_mask_required & ct) == 977 transform_info[i].color_mask_required && 978 (transform_info[i].color_mask_absent & ct) == 0 && 979 (transform_info[i].bit_depths & bd) != 0 && 980 (transform_info[i].when & TRANSFORM_R) != 0) 981 active |= transform; 982 983 else if ((transform_info[i].when & TRANSFORM_R) != 0) 984 inactive |= transform; 985 } 980 986 } 981 987 … … 1001 1007 const char *e = NULL; 1002 1008 1003 png_get_IHDR(dp->read_pp, dp->read_ip, &width, &height, &bit_depth, 1004 &color_type, &interlace_method, &compression_method, &filter_method); 1009 if (!png_get_IHDR(dp->read_pp, dp->read_ip, &width, &height, &bit_depth, 1010 &color_type, &interlace_method, &compression_method, &filter_method)) 1011 display_log(dp, LIBPNG_BUG, "png_get_IHDR failed"); 1005 1012 1006 1013 # define C(item) if (item != dp->item) \ … … 1082 1089 1083 1090 /* Find the first error */ 1084 for (x=0; x<rowbytes-1; ++x) if (row[x] != orig[x]) 1085 break; 1091 for (x=0; x<rowbytes-1; ++x) 1092 if (row[x] != orig[x]) 1093 break; 1086 1094 1087 1095 display_log(dp, APP_FAIL, … … 1138 1146 color_type); 1139 1147 /*NOTREACHED*/ 1148 memset(sig_bits, 0, sizeof(sig_bits)); 1140 1149 bpp = 0; 1141 1150 break; … … 1199 1208 break; 1200 1209 1201 case 4: /* Re licate twice */1210 case 4: /* Replicate twice */ 1202 1211 /* Value is 1, 2, 3 or 4 */ 1203 1212 b = 0xf & ((0xf << 4) >> sig_bits[0]); … … 1687 1696 printf("%s: pngimage ", pass ? "PASS" : "FAIL"); 1688 1697 1689 for (j=1; j<option_end; ++j) if (j != ilog) 1690 printf("%s ", argv[j]); 1698 for (j=1; j<option_end; ++j) 1699 if (j != ilog) 1700 printf("%s ", argv[j]); 1691 1701 1692 1702 printf("%s\n", d.filename); -
trunk/src/libs/libpng-1.6.42/contrib/libtests/pngstest.c
r96425 r103316 1 /*- 2 1 2 /* pngstest.c 3 3 * 4 * Last changed in libpng 1.6.31 [July 27, 2017]4 * Copyright (c) 2021 Cosmin Truta 5 5 * Copyright (c) 2013-2017 John Cunningham Bowler 6 6 * … … 11 11 * Test for the PNG 'simplified' APIs. 12 12 */ 13 13 14 #define _ISOC90_SOURCE 1 14 #define MALLOC_CHECK_ 2 /*glibc facility: turn on debugging*/15 #define MALLOC_CHECK_ 2 /*glibc facility: turn on debugging*/ 15 16 16 17 #include <stddef.h> … … 1151 1152 * 2) Remove color by mapping to grayscale. (Grayscale to color is a no-op.) 1152 1153 * 1153 * 3) Convert between 8-bit and 16-bit components. (Both direct tions are1154 * 3) Convert between 8-bit and 16-bit components. (Both directions are 1154 1155 * relevant.) 1155 1156 * … … 2702 2703 if ((a->opts & ACCUMULATE) == 0) 2703 2704 { 2704 char pindex[ 9];2705 char pindex[16]; 2705 2706 sprintf(pindex, "%lu[%lu]", (unsigned long)y, 2706 2707 (unsigned long)a->image.colormap_entries); … … 2713 2714 { 2714 2715 if ((b->opts & ACCUMULATE) == 0) 2715 2716 char pindex[ 9];2716 { 2717 char pindex[16]; 2717 2718 sprintf(pindex, "%lu[%lu]", (unsigned long)y, 2718 2719 (unsigned long)b->image.colormap_entries); 2719 2720 logerror(b, b->file_name, ": bad pixel index: ", pindex); 2720 2721 } 2721 2722 result = 0; 2722 2723 } … … 2821 2822 2822 2823 /* Hence the btoa array. */ 2823 for (i=0; i<4; ++i) if (bloc[i] < 4) 2824 btoa[bloc[i]] = aloc[i]; /* may be '4' for alpha */ 2824 for (i=0; i<4; ++i) 2825 { 2826 if (bloc[i] < 4) 2827 btoa[bloc[i]] = aloc[i]; /* may be '4' for alpha */ 2828 } 2825 2829 2826 2830 if (alpha_added) … … 3210 3214 { 3211 3215 #ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED 3212 static int counter = 0;3216 static unsigned int counter = 0; 3213 3217 char name[32]; 3214 3218 3215 sprintf(name, "%s% d.png", tmpf, ++counter);3219 sprintf(name, "%s%u.png", tmpf, ++counter); 3216 3220 3217 3221 if (png_image_write_to_file(&image->image, name, convert_to_8bit, -
trunk/src/libs/libpng-1.6.42/contrib/libtests/pngunknown.c
r96425 r103316 2 2 /* pngunknown.c - test the read side unknown chunk handling 3 3 * 4 * Last changed in libpng 1.6.32 [August 24, 2017]4 * Copyright (c) 2021 Cosmin Truta 5 5 * Copyright (c) 2015,2017 Glenn Randers-Pehrson 6 6 * Written by John Cunningham Bowler … … 371 371 int i = NINFO; 372 372 373 while (--i >= 0) if (chunk_info[i].flag == flag) return i; 373 while (--i >= 0) 374 if (chunk_info[i].flag == flag) 375 return i; 374 376 375 377 fprintf(stderr, "pngunknown: internal error\n"); … … 548 550 case PNG_HANDLE_CHUNK_AS_DEFAULT: 549 551 case PNG_HANDLE_CHUNK_NEVER: 550 discard = 1 /*handled; discard*/;552 discard = 1; /*handled; discard*/ 551 553 break; 552 554 553 555 case PNG_HANDLE_CHUNK_IF_SAFE: 554 556 case PNG_HANDLE_CHUNK_ALWAYS: 555 discard = 0 /*not handled; keep*/;557 discard = 0; /*not handled; keep*/ 556 558 break; 557 559 } … … 560 562 * is set if the chunk is to be kept ('not handled'.) 561 563 */ 562 if (chunk >= 0) if (!discard) /* stupidity to stop a GCC warning */ 563 { 564 png_uint_32 flag = chunk_info[chunk].flag; 565 566 if (pc->location & PNG_AFTER_IDAT) 567 d->after_IDAT |= flag; 568 569 else 570 d->before_IDAT |= flag; 564 if (chunk >= 0) 565 { 566 if (!discard) /* stupidity to stop a GCC warning */ 567 { 568 png_uint_32 flag = chunk_info[chunk].flag; 569 570 if (pc->location & PNG_AFTER_IDAT) 571 d->after_IDAT |= flag; 572 573 else 574 d->before_IDAT |= flag; 575 } 571 576 } 572 577 … … 842 847 png_uint_32 y; 843 848 844 for (y=0; y<height; ++y) if (PNG_ROW_IN_INTERLACE_PASS(y, ipass)) 845 png_read_row(d->png_ptr, NULL, NULL); 849 for (y=0; y<height; ++y) 850 if (PNG_ROW_IN_INTERLACE_PASS(y, ipass)) 851 png_read_row(d->png_ptr, NULL, NULL); 846 852 } 847 853 } … … 1092 1098 static const char *standard_tests[] = 1093 1099 { 1094 "discard", "default=discard", 0,1095 "save", "default=save", 0,1096 "if-safe", "default=if-safe", 0,1097 "vpAg", "vpAg=if-safe", 0,1098 "sTER", "sTER=if-safe", 0,1099 "IDAT", "default=discard", "IDAT=save", 0,1100 "sAPI", "bKGD=save", "cHRM=save", "gAMA=save", "all=discard", "iCCP=save",1101 "sBIT=save", "sRGB=save", "eXIf=save", 0,1102 0/*end*/1100 "discard", "default=discard", NULL, 1101 "save", "default=save", NULL, 1102 "if-safe", "default=if-safe", NULL, 1103 "vpAg", "vpAg=if-safe", NULL, 1104 "sTER", "sTER=if-safe", NULL, 1105 "IDAT", "default=discard", "IDAT=save", NULL, 1106 "sAPI", "bKGD=save", "cHRM=save", "gAMA=save", "all=discard", "iCCP=save", 1107 "sBIT=save", "sRGB=save", "eXIf=save", NULL, 1108 NULL /*end*/ 1103 1109 }; 1104 1110 … … 1116 1122 { 1117 1123 FILE *fp; 1118 png_uint_32 default_flags[4 /*valid,unknown{before,after}*/];1124 png_uint_32 default_flags[4]; /*valid,unknown{before,after}*/ 1119 1125 int strict = 0, default_tests = 0; 1120 1126 const char *count_argv = "default=save"; … … 1154 1160 * optimization which causes warnings with -Wstrict-overflow! 1155 1161 */ 1156 else if (default_tests) if (argc != 1) 1157 usage(d.program, "extra arguments"); 1162 else if (default_tests) 1163 if (argc != 1) 1164 usage(d.program, "extra arguments"); 1158 1165 1159 1166 /* The name of the test file is the last argument; remove it. */ … … 1217 1224 int arg_count = 0; 1218 1225 1219 while (*next) ++next, ++arg_count; 1226 while (*next != NULL) 1227 { 1228 ++next; 1229 ++arg_count; 1230 } 1220 1231 1221 1232 perform_one_test_safe(fp, arg_count, test, default_flags, &d, -
trunk/src/libs/libpng-1.6.42/contrib/libtests/pngvalid.c
r96425 r103316 2 2 /* pngvalid.c - validate libpng by constructing then reading png files. 3 3 * 4 * Last changed in libpng 1.6.31 [July 27, 2017]4 * Copyright (c) 2021 Cosmin Truta 5 5 * Copyright (c) 2014-2017 John Cunningham Bowler 6 6 * … … 23 23 #define _GNU_SOURCE 1 /* For the floating point exception extension */ 24 24 #define _BSD_SOURCE 1 /* For the floating point exception extension */ 25 #define _DEFAULT_SOURCE 1 /* For the floating point exception extension */ 25 26 26 27 #include <signal.h> … … 5823 5824 interlace_type < INTERLACE_LAST; ++interlace_type) 5824 5825 { 5825 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/, 5826 interlace_type, 0, 0, 0), do_read_interlace, pm->use_update_info); 5826 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 5827 0/*palette*/, interlace_type, 0, 0, 0), do_read_interlace, 5828 pm->use_update_info); 5827 5829 5828 5830 if (fail(pm)) … … 5877 5879 png_uint_32 h, w; 5878 5880 5879 for (h=1; h<=16; h+=hinc[bdlo]) for (w=1; w<=16; w+=winc[bdlo]) 5880 { 5881 /* First test all the 'size' images against the sequential 5882 * reader using libpng to deinterlace (where required.) This 5883 * validates the write side of libpng. There are four possibilities 5884 * to validate. 5885 */ 5886 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/, 5887 PNG_INTERLACE_NONE, w, h, 0), 0/*do_interlace*/, 5888 pm->use_update_info); 5889 5890 if (fail(pm)) 5891 return 0; 5892 5893 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/, 5894 PNG_INTERLACE_NONE, w, h, 1), 0/*do_interlace*/, 5895 pm->use_update_info); 5896 5897 if (fail(pm)) 5898 return 0; 5899 5900 /* Now validate the interlaced read side - do_interlace true, 5901 * in the progressive case this does actually make a difference 5902 * to the code used in the non-interlaced case too. 5903 */ 5904 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/, 5905 PNG_INTERLACE_NONE, w, h, 0), 1/*do_interlace*/, 5906 pm->use_update_info); 5907 5908 if (fail(pm)) 5909 return 0; 5910 5911 # if CAN_WRITE_INTERLACE 5912 /* Validate the pngvalid code itself: */ 5913 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/, 5914 PNG_INTERLACE_ADAM7, w, h, 1), 1/*do_interlace*/, 5915 pm->use_update_info); 5916 5917 if (fail(pm)) 5918 return 0; 5919 # endif 5881 for (h=1; h<=16; h+=hinc[bdlo]) 5882 { 5883 for (w=1; w<=16; w+=winc[bdlo]) 5884 { 5885 /* First test all the 'size' images against the sequential 5886 * reader using libpng to deinterlace (where required.) This 5887 * validates the write side of libpng. There are four possibilities 5888 * to validate. 5889 */ 5890 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 5891 0/*palette*/, PNG_INTERLACE_NONE, w, h, 0), 0/*do_interlace*/, 5892 pm->use_update_info); 5893 5894 if (fail(pm)) 5895 return 0; 5896 5897 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 5898 0/*palette*/, PNG_INTERLACE_NONE, w, h, 1), 0/*do_interlace*/, 5899 pm->use_update_info); 5900 5901 if (fail(pm)) 5902 return 0; 5903 5904 /* Now validate the interlaced read side - do_interlace true, 5905 * in the progressive case this does actually make a difference 5906 * to the code used in the non-interlaced case too. 5907 */ 5908 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 5909 0/*palette*/, PNG_INTERLACE_NONE, w, h, 0), 1/*do_interlace*/, 5910 pm->use_update_info); 5911 5912 if (fail(pm)) 5913 return 0; 5914 5915 # if CAN_WRITE_INTERLACE 5916 /* Validate the pngvalid code itself: */ 5917 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 5918 0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 1), 1/*do_interlace*/, 5919 pm->use_update_info); 5920 5921 if (fail(pm)) 5922 return 0; 5923 # endif 5924 } 5920 5925 } 5921 5926 } … … 5928 5933 png_uint_32 h, w; 5929 5934 5930 for (h=1; h<=16; h+=hinc[bdlo]) for (w=1; w<=16; w+=winc[bdlo]) 5931 { 5932 # ifdef PNG_READ_INTERLACING_SUPPORTED 5933 /* Test with pngvalid generated interlaced images first; we have 5934 * already verify these are ok (unless pngvalid has self-consistent 5935 * read/write errors, which is unlikely), so this detects errors in the 5936 * read side first: 5937 */ 5938 # if CAN_WRITE_INTERLACE 5939 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/, 5940 PNG_INTERLACE_ADAM7, w, h, 1), 0/*do_interlace*/, 5941 pm->use_update_info); 5942 5943 if (fail(pm)) 5944 return 0; 5945 # endif 5946 # endif /* READ_INTERLACING */ 5947 5948 # ifdef PNG_WRITE_INTERLACING_SUPPORTED 5949 /* Test the libpng write side against the pngvalid read side: */ 5950 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/, 5951 PNG_INTERLACE_ADAM7, w, h, 0), 1/*do_interlace*/, 5952 pm->use_update_info); 5953 5954 if (fail(pm)) 5955 return 0; 5956 # endif 5957 5958 # ifdef PNG_READ_INTERLACING_SUPPORTED 5959 # ifdef PNG_WRITE_INTERLACING_SUPPORTED 5960 /* Test both together: */ 5961 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/, 5962 PNG_INTERLACE_ADAM7, w, h, 0), 0/*do_interlace*/, 5963 pm->use_update_info); 5964 5965 if (fail(pm)) 5966 return 0; 5967 # endif 5968 # endif /* READ_INTERLACING */ 5935 for (h=1; h<=16; h+=hinc[bdlo]) 5936 { 5937 for (w=1; w<=16; w+=winc[bdlo]) 5938 { 5939 # ifdef PNG_READ_INTERLACING_SUPPORTED 5940 /* Test with pngvalid generated interlaced images first; we have 5941 * already verify these are ok (unless pngvalid has self-consistent 5942 * read/write errors, which is unlikely), so this detects errors in 5943 * the read side first: 5944 */ 5945 # if CAN_WRITE_INTERLACE 5946 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 5947 0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 1), 0/*do_interlace*/, 5948 pm->use_update_info); 5949 5950 if (fail(pm)) 5951 return 0; 5952 # endif 5953 # endif /* READ_INTERLACING */ 5954 5955 # ifdef PNG_WRITE_INTERLACING_SUPPORTED 5956 /* Test the libpng write side against the pngvalid read side: */ 5957 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 5958 0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 0), 1/*do_interlace*/, 5959 pm->use_update_info); 5960 5961 if (fail(pm)) 5962 return 0; 5963 # endif 5964 5965 # ifdef PNG_READ_INTERLACING_SUPPORTED 5966 # ifdef PNG_WRITE_INTERLACING_SUPPORTED 5967 /* Test both together: */ 5968 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 5969 0/*palette*/, PNG_INTERLACE_ADAM7, w, h, 0), 0/*do_interlace*/, 5970 pm->use_update_info); 5971 5972 if (fail(pm)) 5973 return 0; 5974 # endif 5975 # endif /* READ_INTERLACING */ 5976 } 5969 5977 } 5970 5978 } … … 6712 6720 const char *name, double digitization_error) 6713 6721 { 6714 /* Compare the scaled, digit zed, values of our local calculation (in+-err)6722 /* Compare the scaled, digitized, values of our local calculation (in+-err) 6715 6723 * with the digitized values libpng produced; 'sample_depth' is the actual 6716 6724 * digitization depth of the libpng output colors (the bit depth except for … … 7636 7644 else 7637 7645 { 7638 /* The default (built in) coeff cients, as above: */7646 /* The default (built in) coefficients, as above: */ 7639 7647 # if PNG_LIBPNG_VER < 10700 7640 7648 data.red_coefficient = 6968 / 32768.; … … 9058 9066 image_transform_test_counter(png_uint_32 counter, unsigned int max) 9059 9067 { 9060 /* Test the list to see if there is any point contin ing, given a current9068 /* Test the list to see if there is any point continuing, given a current 9061 9069 * counter and a 'max' value. 9062 9070 */ … … 10650 10658 unsigned int i, j; 10651 10659 10652 for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j) 10653 if (i != j) 10660 for (i=0; i<pm->ngamma_tests; ++i) 10661 { 10662 for (j=0; j<pm->ngamma_tests; ++j) 10654 10663 { 10655 gamma_transform_test(pm, colour_type, bit_depth, palette_number, 10656 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], 0/*sBIT*/, 10657 pm->use_input_precision, 0 /*do not scale16*/); 10658 10659 if (fail(pm)) 10660 return; 10664 if (i != j) 10665 { 10666 gamma_transform_test(pm, colour_type, bit_depth, palette_number, 10667 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], 10668 0/*sBIT*/, pm->use_input_precision, 0/*do not scale16*/); 10669 10670 if (fail(pm)) 10671 return; 10672 } 10661 10673 } 10674 } 10662 10675 } 10663 10676 } … … 10688 10701 unsigned int j; 10689 10702 10690 for (j=0; j<pm->ngamma_tests; ++j) if (i != j)10703 for (j=0; j<pm->ngamma_tests; ++j) 10691 10704 { 10692 gamma_transform_test(pm, colour_type, bit_depth, npalette, 10693 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], 10694 sbit, pm->use_input_precision_sbit, 0 /*scale16*/); 10695 10696 if (fail(pm)) 10697 return; 10705 if (i != j) 10706 { 10707 gamma_transform_test(pm, colour_type, bit_depth, npalette, 10708 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], 10709 sbit, pm->use_input_precision_sbit, 0 /*scale16*/); 10710 10711 if (fail(pm)) 10712 return; 10713 } 10698 10714 } 10699 10715 } … … 10947 10963 10948 10964 /* Don't skip the i==j case here - it's relevant. */ 10949 for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j) 10950 { 10951 gamma_composition_test(pm, colour_type, bit_depth, palette_number, 10952 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], 10953 pm->use_input_precision, do_background, expand_16); 10954 10955 if (fail(pm)) 10956 return; 10965 for (i=0; i<pm->ngamma_tests; ++i) 10966 { 10967 for (j=0; j<pm->ngamma_tests; ++j) 10968 { 10969 gamma_composition_test(pm, colour_type, bit_depth, palette_number, 10970 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], 10971 pm->use_input_precision, do_background, expand_16); 10972 10973 if (fail(pm)) 10974 return; 10975 } 10957 10976 } 10958 10977 } … … 11057 11076 11058 11077 if (summary) 11059 summarize_gamma_errors(pm, 0/*who*/, 1/*low bit depth*/, 1/*indexed*/);11078 summarize_gamma_errors(pm, NULL/*who*/, 1/*low bit depth*/, 1/*indexed*/); 11060 11079 11061 11080 if (fail(pm)) … … 11183 11202 int x, y; 11184 11203 ++pass; 11185 for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass) 11186 return y; 11204 for (y=0; y<8; ++y) 11205 for (x=0; x<8; ++x) 11206 if (adam7[y][x] == pass) 11207 return y; 11187 11208 return 0xf; 11188 11209 } … … 11193 11214 int x, y; 11194 11215 ++pass; 11195 for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass) 11196 return x; 11216 for (x=0; x<8; ++x) 11217 for (y=0; y<8; ++y) 11218 if (adam7[y][x] == pass) 11219 return x; 11197 11220 return 0xf; 11198 11221 } … … 11203 11226 int x, y, base=(-1), inc=8; 11204 11227 ++pass; 11205 for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass) 11206 { 11207 if (base == (-1)) 11208 base = y; 11209 else if (base == y) 11210 {} 11211 else if (inc == y-base) 11212 base=y; 11213 else if (inc == 8) 11214 inc = y-base, base=y; 11215 else if (inc != y-base) 11216 return 0xff; /* error - more than one 'inc' value! */ 11228 for (y=0; y<8; ++y) 11229 { 11230 for (x=0; x<8; ++x) 11231 { 11232 if (adam7[y][x] == pass) 11233 { 11234 if (base == (-1)) 11235 base = y; 11236 else if (base == y) 11237 {} 11238 else if (inc == y-base) 11239 base=y; 11240 else if (inc == 8) 11241 inc = y-base, base=y; 11242 else if (inc != y-base) 11243 return 0xff; /* error - more than one 'inc' value! */ 11244 } 11245 } 11217 11246 } 11218 11247 … … 11237 11266 int x, y, base=(-1), inc=8; 11238 11267 ++pass; 11239 for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass) 11240 { 11241 if (base == (-1)) 11242 base = x; 11243 else if (base == x) 11244 {} 11245 else if (inc == x-base) 11246 base=x; 11247 else if (inc == 8) 11248 inc = x-base, base=x; 11249 else if (inc != x-base) 11250 return 0xff; /* error - more than one 'inc' value! */ 11268 for (x=0; x<8; ++x) 11269 { 11270 for (y=0; y<8; ++y) 11271 { 11272 if (adam7[y][x] == pass) 11273 { 11274 if (base == (-1)) 11275 base = x; 11276 else if (base == x) 11277 {} 11278 else if (inc == x-base) 11279 base=x; 11280 else if (inc == 8) 11281 inc = x-base, base=x; 11282 else if (inc != x-base) 11283 return 0xff; /* error - more than one 'inc' value! */ 11284 } 11285 } 11251 11286 } 11252 11287 … … 11312 11347 y &= 7; 11313 11348 ++pass; 11314 for (x=0; x<8; ++x) if (adam7[y][x] == pass) 11315 return 1; 11349 for (x=0; x<8; ++x) 11350 if (adam7[y][x] == pass) 11351 return 1; 11316 11352 11317 11353 return 0; … … 11325 11361 x &= 7; 11326 11362 ++pass; 11327 for (y=0; y<8; ++y) if (adam7[y][x] == pass) 11328 return 1; 11363 for (y=0; y<8; ++y) 11364 if (adam7[y][x] == pass) 11365 return 1; 11329 11366 11330 11367 return 0; … … 11340 11377 height &= 7; 11341 11378 ++pass; 11342 for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass) 11343 { 11344 rows += tiles; 11345 if (y < height) ++rows; 11346 break; /* i.e. break the 'x', column, loop. */ 11379 for (y=0; y<8; ++y) 11380 { 11381 for (x=0; x<8; ++x) 11382 { 11383 if (adam7[y][x] == pass) 11384 { 11385 rows += tiles; 11386 if (y < height) ++rows; 11387 break; /* i.e. break the 'x', column, loop. */ 11388 } 11389 } 11347 11390 } 11348 11391 … … 11359 11402 width &= 7; 11360 11403 ++pass; 11361 for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass) 11362 { 11363 cols += tiles; 11364 if (x < width) ++cols; 11365 break; /* i.e. break the 'y', row, loop. */ 11404 for (x=0; x<8; ++x) 11405 { 11406 for (y=0; y<8; ++y) 11407 { 11408 if (adam7[y][x] == pass) 11409 { 11410 cols += tiles; 11411 if (x < width) ++cols; 11412 break; /* i.e. break the 'y', row, loop. */ 11413 } 11414 } 11366 11415 } 11367 11416 … … 11720 11769 /* The following allows results to pass if they correspond to anything in the 11721 11770 * transformed range [input-.5,input+.5]; this is is required because of the 11722 * way libpng treat es the 16_TO_8 flag when building the gamma tables in11771 * way libpng treats the 16_TO_8 flag when building the gamma tables in 11723 11772 * releases up to 1.6.0. 11724 11773 * … … 11811 11860 else if (strncmp(*argv, "--transform-disable=", 11812 11861 sizeof "--transform-disable") == 0) 11813 11862 { 11814 11863 pm.test_transform = 1; 11815 11864 transform_disable(*argv + sizeof "--transform-disable"); 11816 11865 } 11817 11866 11818 11867 else if (strncmp(*argv, "--transform-enable=", 11819 11868 sizeof "--transform-enable") == 0) 11820 11869 { 11821 11870 pm.test_transform = 1; 11822 11871 transform_enable(*argv + sizeof "--transform-enable"); 11823 11872 } 11824 11873 #endif /* PNG_READ_TRANSFORMS_SUPPORTED */ 11825 11874 11826 11875 else if (strcmp(*argv, "--gamma") == 0) 11827 11876 { 11828 11877 /* Just do two gamma tests here (2.2 and linear) for speed: */ 11829 11878 pm.ngamma_tests = 2U; … … 11834 11883 pm.test_gamma_background = 1; /* composition */ 11835 11884 pm.test_gamma_alpha_mode = 1; 11836 11885 } 11837 11886 11838 11887 else if (strcmp(*argv, "--nogamma") == 0) -
trunk/src/libs/libpng-1.6.42/contrib/libtests/readpng.c
r96425 r103316 1 1 2 /* readpng.c 2 3 * 3 4 * Copyright (c) 2013 John Cunningham Bowler 4 *5 * Last changed in libpng 1.6.1 [March 28, 2013]6 5 * 7 6 * This code is released under the libpng license. -
trunk/src/libs/libpng-1.6.42/contrib/libtests/tarith.c
r96425 r103316 2 2 /* tarith.c 3 3 * 4 * Copyright (c) 2021 Cosmin Truta 4 5 * Copyright (c) 2011-2013 John Cunningham Bowler 5 *6 * Last changed in libpng 1.6.0 [February 14, 2013]7 6 * 8 7 * This code is released under the libpng license. … … 89 88 90 89 while (--argc > 0) 90 { 91 91 if (strcmp(*++argv, "-a") == 0) 92 92 showall = 1; … … 106 106 return 1; 107 107 } 108 } 108 109 109 110 do … … 131 132 if (buffer[precision+7] != 71) 132 133 { 133 fprintf(stderr, "%g[%d] -> '%s'[%lu] buffer overflow\n", test,134 precision, buffer, (unsigned long)strlen(buffer));134 fprintf(stderr, "%g[%d] -> '%s'[%lu] buffer overflow\n", 135 test, precision, buffer, (unsigned long)strlen(buffer)); 135 136 failed = 1; 136 137 } … … 147 148 test < 0 && strcmp(buffer, "-inf")) 148 149 { 149 fprintf(stderr, "%g[%d] -> '%s' but expected 'inf'\n", test,150 precision, buffer);150 fprintf(stderr, "%g[%d] -> '%s' but expected 'inf'\n", 151 test, precision, buffer); 151 152 failed = 1; 152 153 } … … 155 156 buffer[index] != 0) 156 157 { 157 fprintf(stderr, "%g[%d] -> '%s' but has bad format ('%c')\n", test,158 precision, buffer, buffer[index]);158 fprintf(stderr, "%g[%d] -> '%s' but has bad format ('%c')\n", 159 test, precision, buffer, buffer[index]); 159 160 failed = 1; 160 161 } … … 188 189 double out = atof(buffer); 189 190 double change = fabs((out - test)/test); 190 double allow = .5 /pow(10,191 double allow = .5 / pow(10, 191 192 (precision >= DBL_DIG) ? DBL_DIG-1 : precision-1); 192 193 … … 258 259 while (--count); 259 260 260 printf("Tested %d finite values, %d non-finite, %d OK (%d failed) %d minor " 261 "arithmetic errors\n", finite, nonfinite, ok, failcount, minorarith); 261 printf("Tested %d finite values, %d non-finite, %d OK (%d failed) " 262 "%d minor arithmetic errors\n", 263 finite, nonfinite, ok, failcount, minorarith); 262 264 printf(" Error with >=%d digit precision %.2f%%\n", DBL_DIG, max_abs); 263 265 printf(" Error with < %d digit precision %.2f%%\n", DBL_DIG, max); … … 372 374 if (index != 0 && index != 1) 373 375 { 374 fprintf(stderr, "%s: read beyond end of string (%lu)\n", co->number,375 (unsigned long)index);376 fprintf(stderr, "%s: read beyond end of string (%lu)\n", 377 co->number, (unsigned long)index); 376 378 return 0; 377 379 } … … 504 506 { 505 507 fprintf(stderr, 506 "%s: character '%c' [0x%.2x] changed number validity\n", co->number,507 c h, ch);508 "%s: character '%c' [0x%.2x] changed number validity\n", 509 co->number, ch, ch); 508 510 return 0; 509 511 } … … 522 524 int ch; 523 525 524 if (c.cnumber+4 < sizeof co->number) for (ch=0; ch<256; ++ch) 525 { 526 if (!check_one_character(co, c, ch)) 527 return 0; 526 if (c.cnumber+4 < sizeof co->number) 527 { 528 for (ch=0; ch<256; ++ch) 529 { 530 if (!check_one_character(co, c, ch)) 531 return 0; 532 } 528 533 } 529 534 … … 540 545 if (c.cnumber+4 < sizeof co->number && c.limit >= 0) 541 546 { 542 if (c.limit > 0) for (i=0; tests[i]; ++i) 543 { 544 if (!check_one_character(co, c, tests[i])) 545 return 0; 547 if (c.limit > 0) 548 { 549 for (i=0; tests[i]; ++i) 550 { 551 if (!check_one_character(co, c, tests[i])) 552 return 0; 553 } 546 554 } 547 555 … … 617 625 618 626 while (--argc > 0) 619 620 621 622 627 { 628 fprintf(stderr, "unknown argument %s\n", *++argv); 629 return 1; 630 } 623 631 624 632 /* Find out about the random number generator. */ … … 688 696 689 697 if (verbose) 690 fprintf(stderr, "TEST %d * %d / %d -> %lld (%s)\n", a, times, div,691 fp, ok ? "ok" : "overflow");698 fprintf(stderr, "TEST %d * %d / %d -> %lld (%s)\n", 699 a, times, div, fp, ok ? "ok" : "overflow"); 692 700 693 701 ++tested; … … 696 704 ++error; 697 705 if (ok) 698 fprintf(stderr, "%d * %d / %d -> overflow (expected %lld)\n", a,699 times, div, fp);706 fprintf(stderr, "%d * %d / %d -> overflow (expected %lld)\n", 707 a, times, div, fp); 700 708 else 701 fprintf(stderr, "%d * %d / %d -> %d (expected overflow %lld)\n", a,702 times, div, result, fp);709 fprintf(stderr, "%d * %d / %d -> %d (expected overflow %lld)\n", 710 a, times, div, result, fp); 703 711 } 704 712 else if (ok && result != fpround) 705 713 { 706 714 ++error; 707 fprintf(stderr, "%d * %d / %d -> %d not %lld\n", a, times, div, result,708 fp);715 fprintf(stderr, "%d * %d / %d -> %d not %lld\n", 716 a, times, div, result, fp); 709 717 } 710 718 else … … 722 730 while (--count > 0); 723 731 724 printf("%d tests including %d overflows, %d passed, %d failed (%d 64-bit"725 " errors)\n", tested, overflow, passed, error, error64);732 printf("%d tests including %d overflows, %d passed, %d failed " 733 "(%d 64-bit errors)\n", tested, overflow, passed, error, error64); 726 734 return 0; 727 735 } … … 822 830 if (error > .68) /* By experiment error is less than .68 */ 823 831 { 824 fprintf(stderr, "16-bit log error: %d: got %u, expected %f" 825 " error: %f\n", i, png_log16bit(i), correct, error); 832 fprintf(stderr, 833 "16-bit log error: %d: got %u, expected %f error: %f\n", 834 i, png_log16bit(i), correct, error); 826 835 } 827 836 } … … 842 851 if (fabs(error) > 1883) /* By experiment. */ 843 852 { 844 fprintf(stderr, "32-bit exp error: %d: got %u, expected %f" 845 " error: %f\n", i, png_exp(i), correct, error); 853 fprintf(stderr, 854 "32-bit exp error: %d: got %u, expected %f error: %f\n", 855 i, png_exp(i), correct, error); 846 856 } 847 857 } … … 860 870 if (fabs(error) > .50002) /* By experiment */ 861 871 { 862 fprintf(stderr, "8-bit exp error: %d: got %u, expected %f" 863 " error: %f\n", i, png_exp8bit(i), correct, error); 872 fprintf(stderr, 873 "8-bit exp error: %d: got %u, expected %f error: %f\n", 874 i, png_exp8bit(i), correct, error); 864 875 } 865 876 } … … 878 889 if (fabs(error) > .524) /* By experiment */ 879 890 { 880 fprintf(stderr, "16-bit exp error: %d: got %u, expected %f" 881 " error: %f\n", i, png_exp16bit(i), correct, error); 891 fprintf(stderr, 892 "16-bit exp error: %d: got %u, expected %f error: %f\n", 893 i, png_exp16bit(i), correct, error); 882 894 } 883 895 } … … 941 953 /**************************** VALIDATION TESTS ********************************/ 942 954 /* Various validation routines are included herein, they require some 943 * definition for png_warning and png_error, se etings of VALIDATION:955 * definition for png_warning and png_error, settings of VALIDATION: 944 956 * 945 957 * 1: validates the ASCII to floating point conversions -
trunk/src/libs/libpng-1.6.42/contrib/libtests/timepng.c
r96425 r103316 1 1 2 /* timepng.c 2 3 * 3 4 * Copyright (c) 2013,2016 John Cunningham Bowler 4 *5 * Last changed in libpng 1.6.22 [May 26, 2016]6 5 * 7 6 * This code is released under the libpng license. … … 529 528 } 530 529 531 else if (nfiles == 0) /* Read from stdin witho out --dissemble */530 else if (nfiles == 0) /* Read from stdin without --dissemble */ 532 531 { 533 532 char filename[FILENAME_MAX+1]; -
trunk/src/libs/libpng-1.6.42/contrib/mips-msa/linux.c
r96425 r103316 1 1 2 /* contrib/mips-msa/linux.c 2 3 * 4 * Copyright (c) 2020-2023 Cosmin Truta 3 5 * Copyright (c) 2016 Glenn Randers-Pehrson 4 6 * Written by Mandar Sahastrabuddhe, 2016. 5 * Last changed in libpng 1.6.25beta03 [August 29, 2016]7 * Updated by Sui Jingfeng, 2021. 6 8 * 7 9 * This code is released under the libpng license. … … 9 11 * and license in png.h 10 12 * 11 * SEE contrib/mips-msa/README before reporting bugs 13 * On Linux, png_have_msa is implemented by reading the pseudo-file 14 * "/proc/self/auxv". 15 * 16 * See contrib/mips-msa/README before reporting bugs. 12 17 * 13 18 * STATUS: SUPPORTED 14 19 * BUG REPORTS: [email protected] 15 *16 * png_have_msa implemented for Linux by reading the widely available17 * pseudo-file /proc/cpuinfo.18 *19 * This code is strict ANSI-C and is probably moderately portable; it does20 * however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.21 20 */ 22 21 23 #include < stdio.h>24 #include < string.h>22 #include <elf.h> 23 #include <fcntl.h> 25 24 #include <stdlib.h> 25 #include <unistd.h> 26 26 27 27 static int 28 28 png_have_msa(png_structp png_ptr) 29 29 { 30 FILE *f = fopen("/proc/cpuinfo", "rb"); 30 Elf64_auxv_t aux; 31 int fd; 32 int has_msa = 0; 31 33 32 char *string = "msa"; 33 char word[10]; 34 fd = open("/proc/self/auxv", O_RDONLY); 35 if (fd >= 0) 36 { 37 while (read(fd, &aux, sizeof(Elf64_auxv_t)) == sizeof(Elf64_auxv_t)) 38 { 39 if (aux.a_type == AT_HWCAP) 40 { 41 uint64_t hwcap = aux.a_un.a_val; 34 42 35 if (f != NULL) 36 { 37 while(!feof(f)) 38 { 39 int ch = fgetc(f); 40 static int i = 0; 41 42 while(!(ch <= 32)) 43 { 44 word[i++] = ch; 45 ch = fgetc(f); 43 has_msa = (hwcap >> 1) & 1; 44 break; 46 45 } 47 48 int val = strcmp(string, word);49 50 if (val == 0)51 return 1;52 53 i = 0;54 memset(word, 0, 10);55 46 } 56 57 fclose(f); 47 close(fd); 58 48 } 59 49 #ifdef PNG_WARNINGS_SUPPORTED 60 50 else 61 png_warning(png_ptr, "/proc/ cpuinfoopen failed");51 png_warning(png_ptr, "/proc/self/auxv open failed"); 62 52 #endif 63 return 0; 53 54 return has_msa; 64 55 } -
trunk/src/libs/libpng-1.6.42/contrib/oss-fuzz/README.txt
r96425 r103316 1 Last changed in libpng 1.6.33 [September 28, 2017]2 1 Copyright (c) 2017 Glenn Randers-Pehrson 3 2 -
trunk/src/libs/libpng-1.6.42/contrib/oss-fuzz/build.sh
r96425 r103316 1 1 #!/bin/bash -eu 2 2 3 # Copyright 2017-2018 Glenn Randers-Pehrson 3 4 # Copyright 2016 Google Inc. … … 14 15 # See the License for the specific language governing permissions and 15 16 # limitations under the License. 16 #17 # Last changed in libpng 1.6.35 [July 15, 2018]18 17 # 19 18 # Revisions by Glenn Randers-Pehrson, 2017: -
trunk/src/libs/libpng-1.6.42/contrib/oss-fuzz/libpng_read_fuzzer.cc
r96425 r103316 5 5 // Use of this source code is governed by a BSD-style license that may 6 6 // be found in the LICENSE file https://cs.chromium.org/chromium/src/LICENSE 7 8 // Last changed in libpng 1.6.35 [July 15, 2018]9 7 10 8 // The modifications in 2017 by Glenn Randers-Pehrson include … … 18 16 #include <stddef.h> 19 17 #include <stdint.h> 18 #include <stdlib.h> 20 19 #include <string.h> 21 20 … … 61 60 if (end_info_ptr) 62 61 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info_ptr); 63 else if (info_ptr) 62 else if (info_ptr) 64 63 png_destroy_read_struct(&png_ptr, &info_ptr, nullptr); 65 64 else … … 77 76 buf_state->bytes_left -= length; 78 77 buf_state->data += length; 78 } 79 80 void* limited_malloc(png_structp, png_alloc_size_t size) { 81 // libpng may allocate large amounts of memory that the fuzzer reports as 82 // an error. In order to silence these errors, make libpng fail when trying 83 // to allocate a large amount. This allocator used to be in the Chromium 84 // version of this fuzzer. 85 // This number is chosen to match the default png_user_chunk_malloc_max. 86 if (size > 8000000) 87 return nullptr; 88 89 return malloc(size); 90 } 91 92 void default_free(png_structp, png_voidp ptr) { 93 return free(ptr); 79 94 } 80 95 … … 118 133 return 0; 119 134 } 135 136 // Use a custom allocator that fails for large allocations to avoid OOM. 137 png_set_mem_fn(png_handler.png_ptr, nullptr, limited_malloc, default_free); 120 138 121 139 png_set_crc_action(png_handler.png_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE); -
trunk/src/libs/libpng-1.6.42/contrib/pngminus/CHANGES.txt
r96425 r103316 4 4 5 5 version 1.0 - 1999.10.15 - First version. 6 1.1 - 2015.07.29 - Fix edleaks (Glenn Randers-Pehrson)6 1.1 - 2015.07.29 - Fix memory leaks (Glenn Randers-Pehrson) 7 7 1.2 - 2017.04.22 - Add buffer-size check 8 8 1.3 - 2017.08.24 - Fix potential overflow in buffer-size check … … 12 12 1.6 - 2018.08.05 - Improve portability and fix style (Cosmin Truta) 13 13 1.7 - 2019.01.22 - Change license to MIT (Willem van Schaik) 14 1.8 - 2024.01.09 - Fix, improve, modernize (Cosmin Truta) -
trunk/src/libs/libpng-1.6.42/contrib/pngminus/CMakeLists.txt
r96425 r103316 1 cmake_minimum_required(VERSION 3.1) 2 cmake_policy(VERSION 3.1) 1 # Copyright (c) 2018-2024 Cosmin Truta 2 # 3 # This software is released under the MIT license. For conditions of 4 # distribution and use, see the LICENSE file part of this package. 5 6 cmake_minimum_required(VERSION 3.5) 3 7 4 8 project(PNGMINUS C) 5 9 6 option(PNGMINUS_USE_STATIC_LIBRARIES "Use the static library builds" ON) 10 option(PNGMINUS_USE_SYSTEM_PNG 11 "Use the libpng build found in the system" OFF) 7 12 8 # libpng 9 add_subdirectory(../.. libpng) 10 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../..) 11 include_directories(${CMAKE_CURRENT_BINARY_DIR}/libpng) 12 if(PNGMINUS_USE_STATIC_LIBRARIES) 13 set(PNGMINUS_PNG_LIBRARY png_static) 13 add_executable(png2pnm png2pnm.c) 14 add_executable(pnm2png pnm2png.c) 15 16 if(PNGMINUS_USE_SYSTEM_PNG) 17 # Use the system libpng. 18 find_package(PNG REQUIRED) 19 target_link_libraries(png2pnm PRIVATE PNG::PNG) 20 target_link_libraries(pnm2png PRIVATE PNG::PNG) 14 21 else() 15 set(PNGMINUS_PNG_LIBRARY png) 22 # Build and use the internal libpng. 23 # Configure libpng for static linking, to produce single-file executables. 24 set(PNG_STATIC ON 25 CACHE STRING "Build the internal libpng as a static library" FORCE) 26 set(PNG_SHARED OFF 27 CACHE STRING "Build the internal libpng as a shared library" FORCE) 28 set(PNG_FRAMEWORK OFF 29 CACHE STRING "Build the internal libpng as a framework bundle" FORCE) 30 add_subdirectory(../.. libpng) 31 target_include_directories(png2pnm PRIVATE 32 "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>" 33 "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/libpng>" 34 ) 35 target_include_directories(pnm2png PRIVATE 36 "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>" 37 "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/libpng>" 38 ) 39 target_link_libraries(png2pnm PRIVATE png_static) 40 target_link_libraries(pnm2png PRIVATE png_static) 16 41 endif() 17 18 # png2pnm19 add_executable(png2pnm png2pnm.c)20 target_link_libraries(png2pnm ${PNGMINUS_PNG_LIBRARY})21 22 # pnm2png23 add_executable(pnm2png pnm2png.c)24 target_link_libraries(pnm2png ${PNGMINUS_PNG_LIBRARY}) -
trunk/src/libs/libpng-1.6.42/contrib/pngminus/LICENSE.txt
r96425 r103316 17 17 implied, including but not limited to the warranties of merchantability, 18 18 fitness for a particular purpose and noninfringement. In no event shall the 19 authors or copy ight holders be liable for any claim, damages or other19 authors or copyright holders be liable for any claim, damages or other 20 20 liability, whether in an action of contract, tort or otherwise, arising from, 21 21 out of or in connection with the software or the use or other dealings in the -
trunk/src/libs/libpng-1.6.42/contrib/pngminus/png2pnm.c
r96425 r103316 15 15 #endif 16 16 #ifndef TRUE 17 #define TRUE ( BOOL) 117 #define TRUE ((BOOL) 1) 18 18 #endif 19 19 #ifndef FALSE 20 #define FALSE (BOOL) 0 21 #endif 22 23 /* make png2pnm verbose so we can find problems (needs to be before png.h) */ 24 #ifndef PNG_DEBUG 25 #define PNG_DEBUG 0 20 #define FALSE ((BOOL) 0) 26 21 #endif 27 22 … … 34 29 BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, 35 30 BOOL raw, BOOL alpha); 31 BOOL do_png2pnm (png_struct *png_ptr, png_info *info_ptr, 32 FILE *pnm_file, FILE *alpha_file, 33 BOOL raw, BOOL alpha); 36 34 37 35 /* … … 44 42 FILE *fp_wr = stdout; 45 43 FILE *fp_al = NULL; 44 const char *fname_wr = NULL; 45 const char *fname_al = NULL; 46 46 BOOL raw = TRUE; 47 47 BOOL alpha = FALSE; 48 48 int argi; 49 int ret; 49 50 50 51 for (argi = 1; argi < argc; argi++) … … 65 66 if ((fp_al = fopen (argv[argi], "wb")) == NULL) 66 67 { 68 fname_al = argv[argi]; 67 69 fprintf (stderr, "PNM2PNG\n"); 68 70 fprintf (stderr, "Error: cannot create alpha-channel file %s\n", … … 95 97 else if (fp_wr == stdout) 96 98 { 99 fname_wr = argv[argi]; 97 100 if ((fp_wr = fopen (argv[argi], "wb")) == NULL) 98 101 { … … 120 123 121 124 /* call the conversion program itself */ 122 if (png2pnm (fp_rd, fp_wr, fp_al, raw, alpha) == FALSE) 123 { 124 fprintf (stderr, "PNG2PNM\n"); 125 fprintf (stderr, "Error: unsuccessful conversion of PNG-image\n"); 126 exit (1); 127 } 125 ret = png2pnm (fp_rd, fp_wr, fp_al, raw, alpha); 128 126 129 127 /* close input file */ … … 134 132 if (alpha) 135 133 fclose (fp_al); 134 135 if (!ret) 136 { 137 fprintf (stderr, "PNG2PNM\n"); 138 fprintf (stderr, "Error: unsuccessful conversion of PNG-image\n"); 139 if (fname_wr) 140 remove (fname_wr); /* no broken output file shall remain behind */ 141 if (fname_al) 142 remove (fname_al); /* ditto */ 143 exit (1); 144 } 136 145 137 146 return 0; … … 164 173 BOOL raw, BOOL alpha) 165 174 { 166 png_struct *png_ptr = NULL; 167 png_info *info_ptr = NULL; 168 png_byte buf[8]; 169 png_byte *png_pixels = NULL; 170 png_byte **row_pointers = NULL; 171 png_byte *pix_ptr = NULL; 172 png_uint_32 row_bytes; 173 175 png_struct *png_ptr; 176 png_info *info_ptr; 177 BOOL ret; 178 179 /* initialize the libpng context for reading from png_file */ 180 181 png_ptr = png_create_read_struct (png_get_libpng_ver(NULL), 182 NULL, NULL, NULL); 183 if (!png_ptr) 184 return FALSE; /* out of memory */ 185 186 info_ptr = png_create_info_struct (png_ptr); 187 if (!info_ptr) 188 { 189 png_destroy_read_struct (&png_ptr, NULL, NULL); 190 return FALSE; /* out of memory */ 191 } 192 193 if (setjmp (png_jmpbuf (png_ptr))) 194 { 195 png_destroy_read_struct (&png_ptr, &info_ptr, NULL); 196 return FALSE; /* generic libpng error */ 197 } 198 199 png_init_io (png_ptr, png_file); 200 201 /* do the actual conversion */ 202 ret = do_png2pnm (png_ptr, info_ptr, pnm_file, alpha_file, raw, alpha); 203 204 /* clean up the libpng structures and their internally-managed data */ 205 png_destroy_read_struct (&png_ptr, &info_ptr, NULL); 206 207 return ret; 208 } 209 210 /* 211 * do_png2pnm - does the conversion in a fully-initialized libpng context 212 */ 213 214 BOOL do_png2pnm (png_struct *png_ptr, png_info *info_ptr, 215 FILE *pnm_file, FILE *alpha_file, 216 BOOL raw, BOOL alpha) 217 { 218 png_byte **row_pointers; 219 png_byte *pix_ptr; 174 220 png_uint_32 width; 175 221 png_uint_32 height; … … 178 224 int color_type; 179 225 int alpha_present; 180 int row, col; 181 int ret; 182 int i; 226 png_uint_32 row, col, i; 183 227 long dep_16; 184 228 185 /* read and check signature in PNG file */ 186 ret = fread (buf, 1, 8, png_file); 187 if (ret != 8) 188 return FALSE; 189 190 ret = png_sig_cmp (buf, 0, 8); 191 if (ret != 0) 192 return FALSE; 193 194 /* create png and info structures */ 195 196 png_ptr = png_create_read_struct (png_get_libpng_ver(NULL), 197 NULL, NULL, NULL); 198 if (!png_ptr) 199 return FALSE; /* out of memory */ 200 201 info_ptr = png_create_info_struct (png_ptr); 202 if (!info_ptr) 203 { 204 png_destroy_read_struct (&png_ptr, NULL, NULL); 205 return FALSE; /* out of memory */ 206 } 207 208 if (setjmp (png_jmpbuf (png_ptr))) 209 { 210 png_destroy_read_struct (&png_ptr, &info_ptr, NULL); 211 return FALSE; 212 } 213 214 /* set up the input control for C streams */ 215 png_init_io (png_ptr, png_file); 216 png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */ 217 218 /* read the file information */ 219 png_read_info (png_ptr, info_ptr); 220 221 /* get size and bit-depth of the PNG-image */ 222 png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 223 NULL, NULL, NULL); 224 225 /* set-up the transformations */ 226 227 /* transform paletted images into full-color rgb */ 228 if (color_type == PNG_COLOR_TYPE_PALETTE) 229 png_set_expand (png_ptr); 230 /* expand images to bit-depth 8 (only applicable for grayscale images) */ 231 if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) 232 png_set_expand (png_ptr); 233 /* transform transparency maps into full alpha-channel */ 234 if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) 235 png_set_expand (png_ptr); 229 /* set up the image transformations that are necessary for the PNM format */ 230 231 /* set up (if applicable) the expansion of paletted images to full-color rgb, 232 * and the expansion of transparency maps to full alpha-channel */ 233 png_set_expand (png_ptr); 234 235 /* set up (if applicable) the expansion of grayscale images to bit-depth 8 */ 236 png_set_expand_gray_1_2_4_to_8 (png_ptr); 236 237 237 238 #ifdef NJET … … 243 244 color_type == PNG_COLOR_TYPE_GRAY_ALPHA) 244 245 png_set_gray_to_rgb (png_ptr); 245 /* only if file has a file gamma, we do a correction */ 246 if (png_get_gAMA (png_ptr, info_ptr, &file_gamma)) 247 png_set_gamma (png_ptr, (double) 2.2, file_gamma); 248 #endif 249 250 /* all transformations have been registered; now update info_ptr data, 251 * get rowbytes and channels, and allocate image memory */ 252 253 png_read_update_info (png_ptr, info_ptr); 254 255 /* get the new color-type and bit-depth (after expansion/stripping) */ 246 /* if the PNG image has a gAMA chunk then gamma-correct the output image */ 247 { 248 double file_gamma; 249 if (png_get_gAMA (png_ptr, info_ptr, &file_gamma)) 250 png_set_gamma (png_ptr, (double) 2.2, file_gamma); 251 } 252 #endif 253 254 /* read the image file, with all of the above image transforms applied */ 255 png_read_png (png_ptr, info_ptr, 0, NULL); 256 257 /* get the image size, bit-depth and color-type */ 256 258 png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 257 259 NULL, NULL, NULL); 258 260 259 /* check for 16-bit files */ 260 if (bit_depth == 16) 261 { 262 raw = FALSE; 263 #if defined(O_BINARY) && (O_BINARY != 0) 264 setmode (fileno (pnm_file), O_BINARY); 265 #endif 266 } 267 268 /* calculate new number of channels and store alpha-presence */ 261 /* calculate the number of channels and store alpha-presence */ 269 262 if (color_type == PNG_COLOR_TYPE_GRAY) 270 263 channels = 1; … … 283 276 { 284 277 fprintf (stderr, "PNG2PNM\n"); 285 fprintf (stderr, "Error: PNG-file doesn't contain alpha channel\n"); 286 exit (1); 287 } 288 289 /* row_bytes is the width x number of channels x (bit-depth / 8) */ 290 row_bytes = png_get_rowbytes (png_ptr, info_ptr); 291 292 if ((row_bytes == 0) || 293 ((size_t) height > (size_t) (-1) / (size_t) row_bytes)) 294 { 295 /* too big */ 296 png_destroy_read_struct (&png_ptr, &info_ptr, NULL); 278 fprintf (stderr, "Warning: no alpha channel in PNG file\n"); 297 279 return FALSE; 298 280 } 299 if ((png_pixels = (png_byte *) 300 malloc ((size_t) row_bytes * (size_t) height)) == NULL) 301 { 302 png_destroy_read_struct (&png_ptr, &info_ptr, NULL); 303 return FALSE; 304 } 305 306 if ((row_pointers = (png_byte **) 307 malloc ((size_t) height * sizeof (png_byte *))) == NULL) 308 { 309 png_destroy_read_struct (&png_ptr, &info_ptr, NULL); 310 free (png_pixels); 311 return FALSE; 312 } 313 314 /* set the individual row_pointers to point at the correct offsets */ 315 for (i = 0; i < ((int) height); i++) 316 row_pointers[i] = png_pixels + i * row_bytes; 317 318 /* now we can go ahead and just read the whole image */ 319 png_read_image (png_ptr, row_pointers); 320 321 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ 322 png_read_end (png_ptr, info_ptr); 323 324 /* clean up after the read, and free any memory allocated - REQUIRED */ 325 png_destroy_read_struct (&png_ptr, &info_ptr, NULL); 281 282 /* get address of internally-allocated image data */ 283 row_pointers = png_get_rows (png_ptr, info_ptr); 326 284 327 285 /* write header of PNM file */ … … 354 312 355 313 /* write data to PNM file */ 356 pix_ptr = png_pixels; 357 358 for (row = 0; row < (int) height; row++)359 {360 for (col = 0; col < (int)width; col++)361 { 362 for (i = 0; i < ( channels - alpha_present); i++)314 315 for (row = 0; row < height; row++) 316 { 317 pix_ptr = row_pointers[row]; 318 for (col = 0; col < width; col++) 319 { 320 for (i = 0; i < (png_uint_32) (channels - alpha_present); i++) 363 321 { 364 322 if (raw) 365 323 { 366 324 fputc ((int) *pix_ptr++, pnm_file); 325 if (bit_depth == 16) 326 fputc ((int) *pix_ptr++, pnm_file); 367 327 } 368 328 else … … 370 330 if (bit_depth == 16) 371 331 { 372 dep_16 = (long) *pix_ptr++; 373 fprintf (pnm_file, "%ld ", (dep_16 << 8) + ((long) *pix_ptr++)); 332 dep_16 = ((long) *pix_ptr++) << 8; 333 dep_16 += ((long) *pix_ptr++); 334 fprintf (pnm_file, "%ld ", dep_16); 374 335 } 375 336 else … … 383 344 if (!alpha) 384 345 { 385 pix_ptr++; /* alpha */ 346 /* skip the alpha-channel */ 347 pix_ptr++; 386 348 if (bit_depth == 16) 387 349 pix_ptr++; 388 350 } 389 else /* output alpha-channel as pgm file */351 else 390 352 { 353 /* output the alpha-channel as pgm file */ 391 354 if (raw) 392 355 { 393 356 fputc ((int) *pix_ptr++, alpha_file); 357 if (bit_depth == 16) 358 fputc ((int) *pix_ptr++, alpha_file); 394 359 } 395 360 else … … 397 362 if (bit_depth == 16) 398 363 { 399 dep_16 = (long) *pix_ptr++; 400 fprintf (alpha_file, "%ld ", (dep_16 << 8) + (long) *pix_ptr++); 364 dep_16 = ((long) *pix_ptr++) << 8; 365 dep_16 += ((long) *pix_ptr++); 366 fprintf (alpha_file, "%ld ", dep_16); 401 367 } 402 368 else … … 418 384 } /* end for row */ 419 385 420 if (row_pointers != NULL)421 free (row_pointers);422 if (png_pixels != NULL)423 free (png_pixels);424 425 386 return TRUE; 426 427 387 } /* end of source */ -
trunk/src/libs/libpng-1.6.42/contrib/pngminus/pnm2png.c
r96425 r103316 7 7 */ 8 8 9 #include <limits.h> 9 10 #include <stdio.h> 10 11 #include <stdlib.h> … … 15 16 #endif 16 17 #ifndef TRUE 17 #define TRUE ( BOOL) 118 #define TRUE ((BOOL) 1) 18 19 #endif 19 20 #ifndef FALSE 20 #define FALSE (BOOL) 0 21 #endif 22 23 /* make pnm2png verbose so we can find problems (needs to be before png.h) */ 24 #ifndef PNG_DEBUG 25 #define PNG_DEBUG 0 21 #define FALSE ((BOOL) 0) 26 22 #endif 27 23 … … 34 30 BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, 35 31 BOOL interlace, BOOL alpha); 36 void get_token (FILE *pnm_file, char *token_buf, size_t token_buf_size); 37 png_uint_32 get_data (FILE *pnm_file, int depth); 38 png_uint_32 get_value (FILE *pnm_file, int depth); 32 BOOL do_pnm2png (png_struct *png_ptr, png_info *info_ptr, 33 FILE *pnm_file, FILE *alpha_file, 34 BOOL interlace, BOOL alpha); 35 int fscan_pnm_magic (FILE *pnm_file, char *magic_buf, size_t magic_buf_size); 36 int fscan_pnm_token (FILE *pnm_file, char *token_buf, size_t token_buf_size); 37 int fscan_pnm_uint_32 (FILE *pnm_file, png_uint_32 *num_ptr); 38 png_uint_32 get_pnm_data (FILE *pnm_file, int depth); 39 png_uint_32 get_pnm_value (FILE *pnm_file, int depth); 39 40 40 41 /* … … 47 48 FILE *fp_al = NULL; 48 49 FILE *fp_wr = stdout; 50 const char *fname_wr = NULL; 49 51 BOOL interlace = FALSE; 50 52 BOOL alpha = FALSE; 51 53 int argi; 54 int ret; 52 55 53 56 for (argi = 1; argi < argc; argi++) … … 95 98 else if (fp_wr == stdout) 96 99 { 100 fname_wr = argv[argi]; 97 101 if ((fp_wr = fopen (argv[argi], "wb")) == NULL) 98 102 { … … 122 126 123 127 /* call the conversion program itself */ 124 if (pnm2png (fp_rd, fp_wr, fp_al, interlace, alpha) == FALSE) 125 { 126 fprintf (stderr, "PNM2PNG\n"); 127 fprintf (stderr, "Error: unsuccessful converting to PNG-image\n"); 128 exit (1); 129 } 128 ret = pnm2png (fp_rd, fp_wr, fp_al, interlace, alpha); 130 129 131 130 /* close input file */ … … 136 135 if (alpha) 137 136 fclose (fp_al); 137 138 if (!ret) 139 { 140 fprintf (stderr, "PNM2PNG\n"); 141 fprintf (stderr, "Error: unsuccessful converting to PNG-image\n"); 142 if (fname_wr) 143 remove (fname_wr); /* no broken output file shall remain behind */ 144 exit (1); 145 } 138 146 139 147 return 0; … … 164 172 BOOL interlace, BOOL alpha) 165 173 { 166 png_struct *png_ptr = NULL; 167 png_info *info_ptr = NULL; 168 png_byte *png_pixels = NULL; 169 png_byte **row_pointers = NULL; 170 png_byte *pix_ptr = NULL; 171 volatile png_uint_32 row_bytes; 172 173 char type_token[16]; 174 char width_token[16]; 175 char height_token[16]; 176 char maxval_token[16]; 177 volatile int color_type = 1; 178 unsigned long ul_width = 0, ul_alpha_width = 0; 179 unsigned long ul_height = 0, ul_alpha_height = 0; 180 unsigned long ul_maxval = 0; 181 volatile png_uint_32 width = 0, height = 0; 182 volatile png_uint_32 alpha_width = 0, alpha_height = 0; 183 png_uint_32 maxval; 184 volatile int bit_depth = 0; 185 int channels = 0; 186 int alpha_depth = 0; 187 int alpha_present = 0; 188 int row, col; 189 BOOL raw, alpha_raw = FALSE; 190 #if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) 174 png_struct *png_ptr; 175 png_info *info_ptr; 176 BOOL ret; 177 178 /* initialize the libpng context for writing to png_file */ 179 180 png_ptr = png_create_write_struct (png_get_libpng_ver(NULL), 181 NULL, NULL, NULL); 182 if (!png_ptr) 183 return FALSE; /* out of memory */ 184 185 info_ptr = png_create_info_struct (png_ptr); 186 if (!info_ptr) 187 { 188 png_destroy_write_struct (&png_ptr, NULL); 189 return FALSE; /* out of memory */ 190 } 191 192 if (setjmp (png_jmpbuf (png_ptr))) 193 { 194 png_destroy_write_struct (&png_ptr, &info_ptr); 195 return FALSE; /* generic libpng error */ 196 } 197 198 png_init_io (png_ptr, png_file); 199 200 /* do the actual conversion */ 201 ret = do_pnm2png (png_ptr, info_ptr, pnm_file, alpha_file, interlace, alpha); 202 203 /* clean up the libpng structures and their internally-managed data */ 204 png_destroy_write_struct (&png_ptr, &info_ptr); 205 206 return ret; 207 } 208 209 /* 210 * do_pnm2png - does the conversion in a fully-initialized libpng context 211 */ 212 213 BOOL do_pnm2png (png_struct *png_ptr, png_info *info_ptr, 214 FILE *pnm_file, FILE *alpha_file, 215 BOOL interlace, BOOL alpha) 216 { 217 png_byte **row_pointers; 218 png_byte *pix_ptr; 219 int bit_depth; 220 int color_type; 221 int channels; 222 char magic_token[4]; 223 BOOL raw; 224 png_uint_32 width, height, maxval; 225 png_uint_32 row_bytes; 226 png_uint_32 row, col; 227 png_uint_32 val16, i; 228 png_uint_32 alpha_width = 0, alpha_height = 0; 229 int alpha_depth = 0, alpha_present = 0; 230 BOOL alpha_raw = FALSE; 191 231 BOOL packed_bitmap = FALSE; 192 #endif193 png_uint_32 tmp16;194 int i;195 232 196 233 /* read header of PNM file */ 197 234 198 get_token (pnm_file, type_token, sizeof (type_token)); 199 if (type_token[0] != 'P') 200 { 201 return FALSE; 202 } 203 else if ((type_token[1] == '1') || (type_token[1] == '4')) 204 { 205 #if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) 206 raw = (type_token[1] == '4'); 235 if (fscan_pnm_magic (pnm_file, magic_token, sizeof (magic_token)) != 1) 236 return FALSE; /* not a PNM file */ 237 238 if ((magic_token[1] == '1') || (magic_token[1] == '4')) 239 { 240 if ((fscan_pnm_uint_32 (pnm_file, &width) != 1) || 241 (fscan_pnm_uint_32 (pnm_file, &height) != 1)) 242 return FALSE; /* bad PBM file header */ 243 } else if ((magic_token[1] == '2') || (magic_token[1] == '5') || 244 (magic_token[1] == '3') || (magic_token[1] == '6')) 245 { 246 if ((fscan_pnm_uint_32 (pnm_file, &width) != 1) || 247 (fscan_pnm_uint_32 (pnm_file, &height) != 1) || 248 (fscan_pnm_uint_32 (pnm_file, &maxval) != 1)) 249 return FALSE; /* bad PGM/PPM file header */ 250 } 251 252 if ((magic_token[1] == '1') || (magic_token[1] == '4')) 253 { 254 raw = (magic_token[1] == '4'); 255 bit_depth = 1; 207 256 color_type = PNG_COLOR_TYPE_GRAY; 208 get_token (pnm_file, width_token, sizeof (width_token));209 sscanf (width_token, "%lu", &ul_width);210 width = (png_uint_32) ul_width;211 get_token (pnm_file, height_token, sizeof (height_token));212 sscanf (height_token, "%lu", &ul_height);213 height = (png_uint_32) ul_height;214 bit_depth = 1;215 257 packed_bitmap = TRUE; 216 #else 217 fprintf (stderr, "PNM2PNG built without PNG_WRITE_INVERT_SUPPORTED and\n"); 218 fprintf (stderr, "PNG_WRITE_PACK_SUPPORTED can't read PBM (P1,P4) files\n"); 219 return FALSE; 220 #endif 221 } 222 else if ((type_token[1] == '2') || (type_token[1] == '5')) 223 { 224 raw = (type_token[1] == '5'); 258 } 259 else if ((magic_token[1] == '2') || (magic_token[1] == '5')) 260 { 261 raw = (magic_token[1] == '5'); 225 262 color_type = PNG_COLOR_TYPE_GRAY; 226 get_token (pnm_file, width_token, sizeof (width_token)); 227 sscanf (width_token, "%lu", &ul_width); 228 width = (png_uint_32) ul_width; 229 get_token (pnm_file, height_token, sizeof (height_token)); 230 sscanf (height_token, "%lu", &ul_height); 231 height = (png_uint_32) ul_height; 232 get_token (pnm_file, maxval_token, sizeof (maxval_token)); 233 sscanf (maxval_token, "%lu", &ul_maxval); 234 maxval = (png_uint_32) ul_maxval; 235 236 if (maxval <= 1) 263 if (maxval == 0) 264 return FALSE; 265 else if (maxval == 1) 237 266 bit_depth = 1; 238 267 else if (maxval <= 3) … … 247 276 return FALSE; 248 277 } 249 else if (( type_token[1] == '3') || (type_token[1] == '6'))250 { 251 raw = ( type_token[1] == '6');278 else if ((magic_token[1] == '3') || (magic_token[1] == '6')) 279 { 280 raw = (magic_token[1] == '6'); 252 281 color_type = PNG_COLOR_TYPE_RGB; 253 get_token (pnm_file, width_token, sizeof (width_token)); 254 sscanf (width_token, "%lu", &ul_width); 255 width = (png_uint_32) ul_width; 256 get_token (pnm_file, height_token, sizeof (height_token)); 257 sscanf (height_token, "%lu", &ul_height); 258 height = (png_uint_32) ul_height; 259 get_token (pnm_file, maxval_token, sizeof (maxval_token)); 260 sscanf (maxval_token, "%lu", &ul_maxval); 261 maxval = (png_uint_32) ul_maxval; 262 if (maxval <= 1) 282 if (maxval == 0) 283 return FALSE; 284 else if (maxval == 1) 263 285 bit_depth = 1; 264 286 else if (maxval <= 3) … … 273 295 return FALSE; 274 296 } 297 else if (magic_token[1] == '7') 298 { 299 fprintf (stderr, "PNM2PNG can't read PAM (P7) files\n"); 300 return FALSE; 301 } 275 302 else 276 303 { … … 282 309 if (alpha) 283 310 { 284 if (color_type == PNG_COLOR_TYPE_GRAY) 285 color_type = PNG_COLOR_TYPE_GRAY_ALPHA; 286 if (color_type == PNG_COLOR_TYPE_RGB) 287 color_type = PNG_COLOR_TYPE_RGB_ALPHA; 288 289 get_token (alpha_file, type_token, sizeof (type_token)); 290 if (type_token[0] != 'P') 291 { 311 if ((fscan_pnm_magic (alpha_file, magic_token, sizeof (magic_token)) != 1) 312 || ((magic_token[1] != '2') && (magic_token[1] != '5'))) 313 return FALSE; /* not a PGM file */ 314 315 if ((fscan_pnm_uint_32 (alpha_file, &alpha_width) != 1) || 316 (fscan_pnm_uint_32 (alpha_file, &alpha_height) != 1) || 317 (fscan_pnm_uint_32 (alpha_file, &maxval) != 1)) 318 return FALSE; /* bad PGM file header */ 319 320 if ((alpha_width != width) || (alpha_height != height)) 321 return FALSE; /* mismatched PGM dimensions */ 322 323 alpha_raw = (magic_token[1] == '5'); 324 color_type |= PNG_COLOR_MASK_ALPHA; 325 if (maxval == 0) 292 326 return FALSE; 293 } 294 else if ((type_token[1] == '2') || (type_token[1] == '5')) 295 { 296 alpha_raw = (type_token[1] == '5'); 297 get_token (alpha_file, width_token, sizeof (width_token)); 298 sscanf (width_token, "%lu", &ul_alpha_width); 299 alpha_width = (png_uint_32) ul_alpha_width; 300 if (alpha_width != width) 301 return FALSE; 302 get_token (alpha_file, height_token, sizeof (height_token)); 303 sscanf (height_token, "%lu", &ul_alpha_height); 304 alpha_height = (png_uint_32) ul_alpha_height; 305 if (alpha_height != height) 306 return FALSE; 307 get_token (alpha_file, maxval_token, sizeof (maxval_token)); 308 sscanf (maxval_token, "%lu", &ul_maxval); 309 maxval = (png_uint_32) ul_maxval; 310 if (maxval <= 1) 311 alpha_depth = 1; 312 else if (maxval <= 3) 313 alpha_depth = 2; 314 else if (maxval <= 15) 315 alpha_depth = 4; 316 else if (maxval <= 255) 317 alpha_depth = 8; 318 else if (maxval <= 65535U) 319 alpha_depth = 16; 320 else /* maxval > 65535U */ 321 return FALSE; 322 if (alpha_depth != bit_depth) 323 return FALSE; 324 } 325 else 326 { 327 else if (maxval == 1) 328 alpha_depth = 1; 329 else if (maxval <= 3) 330 alpha_depth = 2; 331 else if (maxval <= 15) 332 alpha_depth = 4; 333 else if (maxval <= 255) 334 alpha_depth = 8; 335 else if (maxval <= 65535U) 336 alpha_depth = 16; 337 else /* maxval > 65535U */ 327 338 return FALSE; 328 } 339 if (alpha_depth != bit_depth) 340 return FALSE; 329 341 } /* end if alpha */ 330 342 … … 338 350 else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) 339 351 channels = 4; 340 #if 0341 352 else 342 channels = 0; /* cannot happen */ 343 #endif 353 return FALSE; /* NOTREACHED */ 344 354 345 355 alpha_present = (channels - 1) % 2; 346 356 347 #if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)348 357 if (packed_bitmap) 349 358 { … … 352 361 } 353 362 else 354 #endif355 363 { 356 364 /* row_bytes is the width x number of channels x (bit-depth / 8) */ … … 364 372 return FALSE; 365 373 } 366 if ((png_pixels = (png_byte *) 367 malloc ((size_t) row_bytes * (size_t) height)) == NULL) 368 { 369 /* out of memory */ 370 return FALSE; 371 } 372 373 /* read data from PNM file */ 374 pix_ptr = png_pixels; 375 376 for (row = 0; row < (int) height; row++) 377 { 378 #if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) 374 375 /* allocate the rows using the same memory layout as libpng, and transfer 376 * their ownership to libpng, with the responsibility to clean everything up; 377 * please note the use of png_calloc instead of png_malloc */ 378 row_pointers = (png_byte **) 379 png_calloc (png_ptr, height * sizeof (png_byte *)); 380 png_set_rows (png_ptr, info_ptr, row_pointers); 381 png_data_freer (png_ptr, info_ptr, PNG_DESTROY_WILL_FREE_DATA, PNG_FREE_ALL); 382 for (row = 0; row < height; row++) 383 { 384 /* the individual rows should only be allocated after all the previous 385 * steps completed successfully, because libpng must handle correctly 386 * any image allocation left incomplete after an out-of-memory error */ 387 row_pointers[row] = (png_byte *) png_malloc (png_ptr, row_bytes); 388 } 389 390 /* read the data from PNM file */ 391 392 for (row = 0; row < height; row++) 393 { 394 pix_ptr = row_pointers[row]; 379 395 if (packed_bitmap) 380 396 { 381 for (i = 0; i < (int)row_bytes; i++)397 for (i = 0; i < row_bytes; i++) 382 398 { 383 399 /* png supports this format natively so no conversion is needed */ 384 *pix_ptr++ = get_ data (pnm_file, 8);400 *pix_ptr++ = get_pnm_data (pnm_file, 8); 385 401 } 386 402 } 387 403 else 388 #endif 389 { 390 for (col = 0; col < (int) width; col++) 404 { 405 for (col = 0; col < width; col++) 391 406 { 392 for (i = 0; i < ( channels - alpha_present); i++)407 for (i = 0; i < (png_uint_32) (channels - alpha_present); i++) 393 408 { 394 409 if (raw) 395 410 { 396 *pix_ptr++ = get_data (pnm_file, bit_depth); 411 *pix_ptr++ = get_pnm_data (pnm_file, bit_depth); 412 if (bit_depth == 16) 413 *pix_ptr++ = get_pnm_data (pnm_file, bit_depth); 397 414 } 398 415 else … … 400 417 if (bit_depth <= 8) 401 418 { 402 *pix_ptr++ = get_ value (pnm_file, bit_depth);419 *pix_ptr++ = get_pnm_value (pnm_file, bit_depth); 403 420 } 404 421 else 405 422 { 406 tmp16 = get_value (pnm_file, bit_depth);407 *pix_ptr = (png_byte) (( tmp16 >> 8) & 0xFF);423 val16 = get_pnm_value (pnm_file, bit_depth); 424 *pix_ptr = (png_byte) ((val16 >> 8) & 0xFF); 408 425 pix_ptr++; 409 *pix_ptr = (png_byte) ( tmp16 & 0xFF);426 *pix_ptr = (png_byte) (val16 & 0xFF); 410 427 pix_ptr++; 411 428 } … … 417 434 if (alpha_raw) 418 435 { 419 *pix_ptr++ = get_data (alpha_file, alpha_depth); 436 *pix_ptr++ = get_pnm_data (alpha_file, alpha_depth); 437 if (alpha_depth == 16) 438 *pix_ptr++ = get_pnm_data (alpha_file, alpha_depth); 420 439 } 421 440 else … … 423 442 if (alpha_depth <= 8) 424 443 { 425 *pix_ptr++ = get_ value (alpha_file, bit_depth);444 *pix_ptr++ = get_pnm_value (alpha_file, bit_depth); 426 445 } 427 446 else 428 447 { 429 tmp16 = get_value (alpha_file, bit_depth);430 *pix_ptr++ = (png_byte) (( tmp16 >> 8) & 0xFF);431 *pix_ptr++ = (png_byte) ( tmp16 & 0xFF);448 val16 = get_pnm_value (alpha_file, bit_depth); 449 *pix_ptr++ = (png_byte) ((val16 >> 8) & 0xFF); 450 *pix_ptr++ = (png_byte) (val16 & 0xFF); 432 451 } 433 452 } … … 437 456 } /* end for row */ 438 457 439 /* prepare the standard PNG structures */440 png_ptr = png_create_write_struct (png_get_libpng_ver(NULL),441 NULL, NULL, NULL);442 if (!png_ptr)443 {444 free (png_pixels);445 return FALSE;446 }447 info_ptr = png_create_info_struct (png_ptr);448 if (!info_ptr)449 {450 png_destroy_write_struct (&png_ptr, NULL);451 free (png_pixels);452 return FALSE;453 }454 455 #if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)456 if (packed_bitmap == TRUE)457 {458 png_set_packing (png_ptr);459 png_set_invert_mono (png_ptr);460 }461 #endif462 463 if (setjmp (png_jmpbuf (png_ptr)))464 {465 png_destroy_write_struct (&png_ptr, &info_ptr);466 free (png_pixels);467 return FALSE;468 }469 470 /* initialize the png structure */471 png_init_io (png_ptr, png_file);472 473 458 /* we're going to write more or less the same PNG as the input file */ 474 459 png_set_IHDR (png_ptr, info_ptr, width, height, bit_depth, color_type, … … 476 461 PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); 477 462 463 if (packed_bitmap == TRUE) 464 { 465 png_set_packing (png_ptr); 466 png_set_invert_mono (png_ptr); 467 } 468 478 469 /* write the file header information */ 479 470 png_write_info (png_ptr, info_ptr); 480 471 481 /* if needed we will allocate memory for an new array of row-pointers */482 if (row_pointers == NULL)483 {484 if ((row_pointers = (png_byte **)485 malloc (height * sizeof (png_byte *))) == NULL)486 {487 png_destroy_write_struct (&png_ptr, &info_ptr);488 free (png_pixels);489 return FALSE;490 }491 }492 493 /* set the individual row_pointers to point at the correct offsets */494 for (i = 0; i < (int) height; i++)495 row_pointers[i] = png_pixels + i * row_bytes;496 497 472 /* write out the entire image data in one call */ 498 473 png_write_image (png_ptr, row_pointers); … … 501 476 png_write_end (png_ptr, info_ptr); 502 477 503 /* clean up after the write, and free any memory allocated */504 png_destroy_write_struct (&png_ptr, &info_ptr);505 506 if (row_pointers != NULL)507 free (row_pointers);508 if (png_pixels != NULL)509 free (png_pixels);510 511 478 return TRUE; 512 479 } /* end of pnm2png */ 513 480 514 481 /* 515 * get_token - gets the first string after whitespace 516 */ 517 518 void get_token (FILE *pnm_file, char *token_buf, size_t token_buf_size) 482 * fscan_pnm_magic - like fscan_pnm_token below, but expects the magic string 483 * to start immediately, without any comment or whitespace, 484 * and to match the regex /^P[1-9]$/ 485 */ 486 487 int fscan_pnm_magic (FILE *pnm_file, char *magic_buf, size_t magic_buf_size) 488 { 489 int ret; 490 491 ret = fgetc (pnm_file); 492 if (ret == EOF) return 0; 493 ungetc (ret, pnm_file); 494 if (ret != 'P') return 0; 495 496 /* the string buffer must be at least four bytes long, i.e., the capacity 497 * required for strings of at least three characters long, i.e., the minimum 498 * required for ensuring that our magic string is exactly two characters long 499 */ 500 if (magic_buf_size < 4) return -1; 501 502 ret = fscan_pnm_token (pnm_file, magic_buf, magic_buf_size); 503 if (ret < 1) return ret; 504 505 if ((magic_buf[1] < '1') || (magic_buf[1] > '9')) return 0; 506 if (magic_buf[2] != '\0') return 0; 507 508 return 1; 509 } 510 511 /* 512 * fscan_pnm_token - extracts the first string token after whitespace, 513 * and (like fscanf) returns the number of successful 514 * extractions, which can be either 0 or 1 515 */ 516 517 int fscan_pnm_token (FILE *pnm_file, char *token_buf, size_t token_buf_size) 519 518 { 520 519 size_t i = 0; … … 544 543 ret = fgetc (pnm_file); 545 544 if (ret == EOF) break; 545 if (ret == '0') 546 { 547 /* avoid storing more than one leading '0' in the token buffer, 548 * to ensure that all valid (in-range) numeric inputs can fit in. */ 549 if ((i == 0) && (token_buf[i] == '0')) continue; 550 } 546 551 if (++i == token_buf_size - 1) break; 547 552 token_buf[i] = (char) ret; … … 550 555 551 556 token_buf[i] = '\0'; 552 553 return; 554 } 555 556 /* 557 * get_data - takes first byte and converts into next pixel value, 558 * taking as much bits as defined by bit-depth and 559 * using the bit-depth to fill up a byte (0Ah -> AAh) 560 */ 561 562 png_uint_32 get_data (FILE *pnm_file, int depth) 557 return (i > 0) ? 1 : 0; 558 } 559 560 /* 561 * fscan_pnm_uint_32 - like fscan_token above, but expects the extracted token 562 * to be numeric, and converts it to an unsigned 32-bit int 563 */ 564 565 int fscan_pnm_uint_32 (FILE *pnm_file, png_uint_32 *num_ptr) 566 { 567 char token[16]; 568 unsigned long token_value; 569 int ret; 570 571 ret = fscan_pnm_token (pnm_file, token, sizeof (token)); 572 if (ret < 1) return ret; 573 574 if ((token[0] < '0') && (token[0] > '9')) 575 return 0; /* the token starts with junk, or a +/- sign, which is invalid */ 576 577 ret = sscanf (token, "%lu%*c", &token_value); 578 if (ret != 1) 579 return 0; /* the token ends with junk */ 580 581 *num_ptr = (png_uint_32) token_value; 582 583 #if ULONG_MAX > 0xFFFFFFFFUL 584 /* saturate the converted number, following the fscanf convention */ 585 if (token_value > 0xFFFFFFFFUL) 586 *num_ptr = 0xFFFFFFFFUL; 587 #endif 588 589 return 1; 590 } 591 592 /* 593 * get_pnm_data - takes first byte and converts into next pixel value, 594 * taking as many bits as defined by bit-depth and 595 * using the bit-depth to fill up a byte (0x0A -> 0xAA) 596 */ 597 598 png_uint_32 get_pnm_data (FILE *pnm_file, int depth) 563 599 { 564 600 static int bits_left = 0; 565 601 static int old_value = 0; 566 602 static int mask = 0; 603 png_uint_32 ret_value; 567 604 int i; 568 png_uint_32 ret_value;569 605 570 606 if (mask == 0) … … 574 610 if (bits_left <= 0) 575 611 { 612 /* FIXME: 613 * signal the premature end of file, instead of pretending to read zeroes 614 */ 576 615 old_value = fgetc (pnm_file); 616 if (old_value == EOF) return 0; 577 617 bits_left = 8; 578 618 } … … 589 629 590 630 /* 591 * get_ value - takes first (numeric) string and converts into number,592 * using the bit-depth to fill up a byte (0Ah -> AAh)593 */ 594 595 png_uint_32 get_ value (FILE *pnm_file, int depth)631 * get_pnm_value - takes first (numeric) string and converts into number, 632 * using the bit-depth to fill up a byte (0x0A -> 0xAA) 633 */ 634 635 png_uint_32 get_pnm_value (FILE *pnm_file, int depth) 596 636 { 597 637 static png_uint_32 mask = 0; 598 char token[16];599 unsigned long ul_ret_value;600 638 png_uint_32 ret_value; 601 int i = 0;639 int i; 602 640 603 641 if (mask == 0) … … 605 643 mask = (mask << 1) | 0x01; 606 644 607 get_token (pnm_file, token, sizeof (token)); 608 sscanf (token, "%lu", &ul_ret_value); 609 ret_value = (png_uint_32) ul_ret_value; 645 if (fscan_pnm_uint_32 (pnm_file, &ret_value) != 1) 646 { 647 /* FIXME: 648 * signal the invalid numeric tokens or the premature end of file, 649 * instead of pretending to read zeroes 650 */ 651 return 0; 652 } 610 653 611 654 ret_value &= mask; -
trunk/src/libs/libpng-1.6.42/contrib/powerpc-vsx/linux.c
r96425 r103316 3 3 * Copyright (c) 2017 Glenn Randers-Pehrson 4 4 * Written by Vadim Barkov, 2017. 5 * Last changed in libpng 1.6.29 [March 16, 2017]6 5 * 7 6 * This code is released under the libpng license. … … 13 12 * 14 13 * png_have_vsx implemented for Linux by reading the widely available 15 * pseudo-file /proc/cpuinfo. 14 * pseudo-file /proc/cpuinfo. 16 15 * 17 16 * This code is strict ANSI-C and is probably moderately portable; it does -
trunk/src/libs/libpng-1.6.42/contrib/powerpc-vsx/linux_aux.c
r96425 r103316 3 3 * Copyright (c) 2017 Glenn Randers-Pehrson 4 4 * Written by Vadim Barkov, 2017. 5 * Last changed in libpng 1.6.29 [March 16, 2017]6 5 * 7 6 * This code is released under the libpng license. -
trunk/src/libs/libpng-1.6.42/contrib/testpngs/makepngs.sh
r96425 r103316 1 #!/ bin/sh2 # 1 #!/usr/bin/env bash 2 3 3 # Make a set of test PNG files, MAKEPNG is the name of the makepng executable 4 4 # built from contrib/libtests/makepng.c 5 5 6 6 # Copyright (c) 2015 John Cunningham Bowler 7 8 # Last changed in libpng 1.6.20 [December 3, 2015]9 7 10 8 # This code is released under the libpng license. -
trunk/src/libs/libpng-1.6.42/contrib/tools/checksum-icc.c
r96425 r103316 2 2 * 3 3 * Copyright (c) 2013 John Cunningham Bowler 4 *5 * Last changed in libpng 1.6.0 [February 14, 2013]6 4 * 7 5 * This code is released under the libpng license. … … 12 10 * generate check-codes for use when matching ICC profiles within libpng. 13 11 */ 12 14 13 #include <stdio.h> 15 16 14 #include <zlib.h> 17 15 -
trunk/src/libs/libpng-1.6.42/contrib/tools/cvtcolor.c
r96425 r103316 1 /*- 2 * convert.c 3 * 4 * Last changed in libpng 1.6.0 [February 14, 2013] 1 /* convert.c 5 2 * 6 3 * COPYRIGHT: Written by John Cunningham Bowler, 2013. … … 11 8 * Convert 8-bit sRGB or 16-bit linear values to another format. 12 9 */ 10 13 11 #define _ISOC99_SOURCE 1 14 12 -
trunk/src/libs/libpng-1.6.42/contrib/tools/genpng.c
r96425 r103316 1 /* -genpng1 /* genpng 2 2 * 3 3 * COPYRIGHT: Written by John Cunningham Bowler, 2015. … … 70 70 * intersection. 71 71 */ 72 72 73 #include <stddef.h> 73 74 #include <stdlib.h> … … 454 455 * { inside_circle, check_circle } 455 456 * 456 * The functions here are analog uous to the square ones; however, they check457 * The functions here are analogous to the square ones; however, they check 457 458 * the corresponding ellipse as opposed to the rectangle. 458 459 */ -
trunk/src/libs/libpng-1.6.42/contrib/tools/intgamma.sh
r96425 r103316 1 1 #!/bin/sh 2 # 2 3 3 # intgamma.sh 4 #5 # Last changed in libpng 1.6.0 [February 14, 2013]6 4 # 7 5 # COPYRIGHT: Written by John Cunningham Bowler, 2013. 8 6 # To the extent possible under law, the author has waived all copyright and 9 # related or neighboring rights to this work. Th is work is published from:10 # United States.7 # related or neighboring rights to this work. The author published this work 8 # from the United States. 11 9 # 12 10 # Shell script to generate png.c 8-bit and 16-bit log tables (see the code in … … 18 16 # 19 17 # "bc" must be on the path when the script is executed, and the math library 20 # (-lm) must be available 21 # 22 # function to print out a list of numbers as integers; the function truncates23 # the integers which must be one-per-line 24 functionprint(){18 # (-lm) must be available. 19 20 # Function to print out a list of numbers as integers; the function truncates 21 # the integers which must be one-per-line. 22 print(){ 25 23 awk 'BEGIN{ 26 24 str = "" -
trunk/src/libs/libpng-1.6.42/contrib/tools/makesRGB.c
r96425 r103316 1 1 /* makesRGB.c -- build sRGB-to-linear and linear-to-sRGB conversion tables 2 *3 * Last changed in libpng 1.6.0 [February 14, 2013]4 2 * 5 3 * COPYRIGHT: Written by John Cunningham Bowler, 2013. … … 15 13 * tables and display it. 16 14 */ 15 17 16 #define _C99_SOURCE 1 18 17 #include <stdio.h> -
trunk/src/libs/libpng-1.6.42/contrib/tools/png-fix-itxt.c
r96425 r103316 1 2 /* png-fix-itxt version 1.0.0 1 /* png-fix-itxt 3 2 * 4 3 * Copyright 2015 Glenn Randers-Pehrson 5 * Last changed in libpng 1.6.18 [July 23, 2015]6 4 * 7 5 * This code is released under the libpng license. … … 11 9 * Usage: 12 10 * 13 * png-fix-itxt .exe< bad.png > good.png11 * png-fix-itxt < bad.png > good.png 14 12 * 15 13 * Fixes a PNG file written with libpng-1.6.0 or 1.6.1 that has one or more -
trunk/src/libs/libpng-1.6.42/contrib/tools/pngcp.c
r96425 r103316 1 1 /* pngcp.c 2 2 * 3 * Copyright (c) 2016 John Cunningham Bowler 4 * 5 * Last changed in libpng 1.6.24 [August 4, 2016] 3 * Copyright (c) 2016,2022,2024 John Cunningham Bowler 6 4 * 7 5 * This code is released under the libpng license. … … 15 13 * For a more extensive example that uses the transforms see 16 14 * contrib/libtests/pngimage.c in the libpng distribution. 15 * 16 * This code is not intended for installation in a release system; the command 17 * line options are not documented and most of the behavior is intended for 18 * testing libpng performance, both speed and compression. 17 19 */ 20 18 21 #include "pnglibconf.h" /* To find how libpng was configured. */ 19 22 … … 85 88 # define voidcast(type, value) (value) 86 89 #endif /* __cplusplus */ 87 88 #ifdef __GNUC__89 /* Many versions of GCC erroneously report that local variables unmodified90 * within the scope of a setjmp may be clobbered. This hacks round the91 * problem (sometimes) without harming other compilers.92 */93 # define gv volatile94 #else95 # define gv96 #endif97 90 98 91 /* 'CLOCK_PROCESS_CPUTIME_ID' is one of the clock timers for clock_gettime. It … … 337 330 338 331 # ifdef PNG_SW_COMPRESS_png_level 339 /* The libpng compression level isn't searched because it just ssets the332 /* The libpng compression level isn't searched because it just sets the 340 333 * other things that are searched! 341 334 */ … … 393 386 jmp_buf error_return; /* Where to go to on error */ 394 387 unsigned int errset; /* error_return is set */ 388 int errlevel; /* error level from longjmp */ 395 389 396 390 const char *operation; /* What is happening */ … … 504 498 505 499 static void 506 display_clean_read(struct display *dp )500 display_clean_read(struct display *dp, int freeinfo) 507 501 { 508 502 if (dp->read_pp != NULL) 509 png_destroy_read_struct(&dp->read_pp, NULL, NULL);503 png_destroy_read_struct(&dp->read_pp, freeinfo ? &dp->ip : NULL, NULL); 510 504 511 505 if (dp->fp != NULL) … … 518 512 519 513 static void 520 display_clean_write(struct display *dp )514 display_clean_write(struct display *dp, int freeinfo) 521 515 { 522 516 if (dp->fp != NULL) … … 528 522 529 523 if (dp->write_pp != NULL) 530 png_destroy_write_struct(&dp->write_pp, dp->tsp > 0 ? NULL : &dp->ip);524 png_destroy_write_struct(&dp->write_pp, freeinfo ? &dp->ip : NULL); 531 525 } 532 526 … … 534 528 display_clean(struct display *dp) 535 529 { 536 display_clean_read(dp );537 display_clean_write(dp );530 display_clean_read(dp, 1/*freeinfo*/); 531 display_clean_write(dp, 1/*freeinfo*/); 538 532 dp->output_file = NULL; 539 533 … … 632 626 { 633 627 if (dp->errset) 628 { 629 dp->errlevel = level; 634 630 longjmp(dp->error_return, level); 631 } 635 632 636 633 else … … 779 776 /* Add the appropriate option string to dp->curr. */ 780 777 { 781 dp->stack[sp].opt_string_end = set_opt_string_(dp, sp, dp->stack[sp].opt, 778 dp->stack[sp].opt_string_end = set_opt_string_(dp, sp, dp->stack[sp].opt, 782 779 options[dp->stack[sp].opt].values[dp->stack[sp].entry].name); 783 780 } … … 1746 1743 read_png(struct display *dp, const char *filename) 1747 1744 { 1748 display_clean_read(dp); /* safety */ 1745 /* This is an assumption of the code; it may happen if a previous write fails 1746 * and there is a bug in the cleanup handling below (look for setjmp). 1747 * Passing freeinfo==1 to display_clean_read below avoids a second error 1748 * on dp->ip != NULL below. 1749 */ 1750 if (dp->read_pp != NULL) 1751 { 1752 display_log(dp, APP_FAIL, "unexpected png_read_struct"); 1753 display_clean_read(dp, 1/*freeinfo*/); /* recovery */ 1754 } 1755 1749 1756 display_start_read(dp, filename); 1750 1757 … … 1770 1777 # endif /* IGNORE_INDEX */ 1771 1778 1779 if (dp->ip != NULL) 1780 { 1781 /* UNEXPECTED: some problem in the display_clean function calls! */ 1782 display_log(dp, APP_FAIL, "read_png: freeing old info struct"); 1783 png_destroy_info_struct(dp->read_pp, &dp->ip); 1784 } 1785 1772 1786 /* The png_read_png API requires us to make the info struct, but it does the 1773 1787 * call to png_read_info. … … 1849 1863 #endif /* FIX_INDEX */ 1850 1864 1851 display_clean_read(dp); 1865 /* NOTE: dp->ip is where all the information about the PNG that was just read 1866 * is stored. It can be used to write and write again a single PNG file, 1867 * however be aware that prior to libpng 1.7 text chunks could only be 1868 * written once; this is a bug which would require a significant code rewrite 1869 * to fix, it has been there in several versions of libpng (it was introduced 1870 * to fix another bug involving duplicate writes of the text chunks.) 1871 */ 1872 display_clean_read(dp, 0/*freeiinfo*/); 1852 1873 dp->operation = "none"; 1853 1874 } … … 1976 1997 write_png(struct display *dp, const char *destname) 1977 1998 { 1978 display_clean_write(dp); /* safety */ 1999 /* If this test fails png_write_png would fail *silently* below; this 2000 * is not helpful, so catch the problem now and give up: 2001 */ 2002 if (dp->ip == NULL) 2003 display_log(dp, INTERNAL_ERROR, "missing png_info"); 2004 2005 /* This is an assumption of the code; it may happen if a previous 2006 * write fails and there is a bug in the cleanup handling below. 2007 */ 2008 if (dp->write_pp != NULL) 2009 { 2010 display_log(dp, APP_FAIL, "unexpected png_write_struct"); 2011 display_clean_write(dp, 0/*!freeinfo*/); 2012 } 2013 1979 2014 display_start_write(dp, destname); 1980 2015 … … 2074 2109 } 2075 2110 2076 /* Clean it on the way out - if control returns to the caller then the2077 * written_file contains the required data.2078 */2079 display_clean_write(dp);2080 2111 dp->operation = "none"; 2081 2112 } … … 2244 2275 do 2245 2276 { 2277 /* Clean before each write_png; this just removes *dp->write_pp which 2278 * cannot be reused. 2279 */ 2280 display_clean_write(dp, 0/*!freeinfo*/); 2246 2281 write_png(dp, tmpname); 2247 2282 … … 2273 2308 dp->write_size = dp->best_size; 2274 2309 } 2310 2311 display_clean_write(dp, 1/*freeinfo*/); 2275 2312 } 2276 2313 2277 2314 static int 2278 cppng(struct display *dp, const char *file, const char *gv dest) 2279 /* Exists solely to isolate the setjmp clobbers which some versions of GCC 2280 * erroneously generate. 2281 */ 2282 { 2283 int ret = setjmp(dp->error_return); 2284 2285 if (ret == 0) 2315 cppng(struct display *dp, const char *file, const char *dest) 2316 { 2317 if (setjmp(dp->error_return) == 0) 2286 2318 { 2287 2319 dp->errset = 1; … … 2295 2327 dp->errset = 0; 2296 2328 2297 if (ret < ERRORS) /* shouldn't longjmp on warnings */ 2298 display_log(dp, INTERNAL_ERROR, "unexpected return code %d", ret); 2299 2300 return ret; 2329 if (dp->errlevel < ERRORS) /* shouldn't longjmp on warnings */ 2330 display_log(dp, INTERNAL_ERROR, "unexpected return code %d", 2331 dp->errlevel); 2332 2333 return dp->errlevel; 2301 2334 } 2302 2335 } -
trunk/src/libs/libpng-1.6.42/contrib/tools/pngfix.c
r96425 r103316 1 1 /* pngfix.c 2 2 * 3 * Last changed in libpng 1.6.31 [July 27, 2017] 4 * Copyright (c) 2014-2017 John Cunningham Bowler 3 * Copyright (c) 2014-2017,2024 John Cunningham Bowler 5 4 * 6 5 * This code is released under the libpng license. … … 11 10 * See the usage message for more information. 12 11 */ 12 13 13 #include <stdlib.h> 14 14 #include <stdio.h> … … 20 20 21 21 #define implies(x,y) assert(!(x) || (y)) 22 23 #ifdef __GNUC__24 /* This is used to fix the error:25 *26 * pngfix.c:27 * In function 'zlib_advance':28 * pngfix.c:181:13: error: assuming signed overflow does not29 * occur when simplifying conditional to constant [-Werror=strict-overflow]30 */31 # define FIX_GCC volatile32 #else33 # define FIX_GCC34 #endif35 22 36 23 #define PROGRAM_NAME "pngfix" … … 219 206 */ 220 207 { 221 FIX_GCCint out_digits = 0;208 int out_digits = 0; 222 209 223 210 while (out_digits < in_digits) … … 264 251 265 252 static int 266 uarb_mult_digit(uarb acc, int a_digits, uarb num, FIX_GCCint n_digits,253 uarb_mult_digit(uarb acc, int a_digits, uarb num, int n_digits, 267 254 png_uint_16 val) 268 255 /* Primitive one-digit multiply - 'val' must be 0..65535. Note that this … … 337 324 */ 338 325 { 339 FIX_GCCint i = ndigits;326 int i = ndigits; 340 327 png_uint_16 carry = 0; 341 328 … … 352 339 353 340 /* The shift may reduce ndigits */ 354 if (i == ndigits-1&& temp == 0)341 if (i+1 == ndigits && temp == 0) 355 342 ndigits = i; 356 343 } … … 868 855 * 869 856 * When a chunk control structure is instantiated these values are copied 870 * into the structure and can then be over ritten with the data for the next857 * into the structure and can then be overwritten with the data for the next 871 858 * chunk. 872 859 */ … … 1006 993 if (file->out != NULL) 1007 994 { 1008 /* NOTE: this is bitwise |, all the following functions must execute and 1009 * must succeed. 995 /* On some systems 'fclose' deletes the FILE struct (making it 996 * inaccessbile). There is no guarantee that fclose returns an error 997 * code from fflush or, indeed, from the FILE error indicator. There is 998 * also no explicit (or clear) guarantee in the standard that anything 999 * other than a read or write operation sets the error indicator; fflush 1000 * is not a read or write operation, so both conditions must be checked 1001 * to ensure the close succeeded and in ANSI-C conformant code they must 1002 * be checked before the fclose call. 1010 1003 */ 1011 if (ferror(file->out) | fflush(file->out) | fclose(file->out)) 1004 const int err = fflush(file->out) || ferror(file->out); 1005 1006 if (fclose(file->out) || err) 1012 1007 { 1013 1008 perror(file->out_name); … … 1599 1594 chunk->chunk_type = file->type; 1600 1595 1601 /* Compress sed/uncompressed size information (from the zlib control structure1596 /* Compressed/uncompressed size information (from the zlib control structure 1602 1597 * that is used to check the compressed data in a chunk.) 1603 1598 */ … … 2930 2925 2931 2926 /* Control reaches this point if the chunk must be skipped. For chunks other 2932 * than IDAT this means that the zlib compressed data is fatally dama nged and2927 * than IDAT this means that the zlib compressed data is fatally damaged and 2933 2928 * the chunk will not be passed to libpng. For IDAT it means that the end of 2934 2929 * the IDAT stream has not yet been reached and we must handle the next … … 3962 3957 size_t outlen = strlen(*argv); 3963 3958 3959 if (outlen > FILENAME_MAX) 3960 { 3961 fprintf(stderr, "%s: output file name too long: %s%s%s\n", 3962 prog, prefix, *argv, suffix ? suffix : ""); 3963 global.status_code |= WRITE_ERROR; 3964 continue; 3965 } 3966 3964 3967 if (outfile == NULL) /* else this takes precedence */ 3965 3968 { … … 4047 4050 } 4048 4051 #endif /* PNG_SETJMP_SUPPORTED */ 4049 4052 /* vi: set textwidth=80 shiftwidth=3 softtabstop=-1 expandtab: */ -
trunk/src/libs/libpng-1.6.42/contrib/tools/sRGB.h
r96425 r103316 1 /*- 2 * sRGB.h 3 * 4 * Last changed in libpng 1.6.0 [February 14, 2013] 1 /* sRGB.h 5 2 * 6 3 * COPYRIGHT: Written by John Cunningham Bowler, 2013. … … 17 14 * https://en.wikipedia.org/wiki/SRGB). 18 15 */ 16 19 17 static double 20 18 sRGB_from_linear(double l) -
trunk/src/libs/libpng-1.6.42/contrib/visupng/VisualPng.c
r96425 r103316 104 104 } 105 105 106 /* if filename given on command line, store it */106 /* if filename given on command line, store it */ 107 107 if ((szCmdLine != NULL) && (*szCmdLine != '\0')) 108 108 if (szCmdLine[0] == '"')
Note:
See TracChangeset
for help on using the changeset viewer.