Changeset 1165 for libpng/vendor/current/contrib/tools/png-fix-itxt.c
- Timestamp:
- Sep 15, 2015, 12:22:09 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified libpng/vendor/current/contrib/tools/png-fix-itxt.c ¶
r922 r1165 2 2 /* png-fix-itxt version 1.0.0 3 3 * 4 * Copyright 201 3Glenn Randers-Pehrson5 * Last changed in libpng 1.6. 3 [July 18, 2013]4 * Copyright 2015 Glenn Randers-Pehrson 5 * Last changed in libpng 1.6.18 [July 23, 2015] 6 6 * 7 7 * This code is released under the libpng license. … … 35 35 #define MAX_LENGTH 500000 36 36 37 #define GETBREAK ((unsigned char)(inchar=getchar())); if (inchar == EOF) break 38 37 /* Read one character (inchar), also return octet (c), break if EOF */ 38 #define GETBREAK inchar=getchar(); \ 39 c=(inchar & 0xffU);\ 40 if (inchar != c) break 39 41 int 40 42 main(void) … … 49 51 for (i=8; i; i--) 50 52 { 51 c=GETBREAK;53 GETBREAK; 52 54 putchar(c); 53 55 } 54 56 55 if (inchar != EOF)57 if (inchar == c) /* !EOF */ 56 58 for (;;) 57 59 { 58 60 /* Read the length */ 59 61 unsigned long length; /* must be 32 bits! */ 60 c=GETBREAK; buf[0] = c; length = c; length <<= 8;61 c=GETBREAK; buf[1] = c; length += c; length <<= 8;62 c=GETBREAK; buf[2] = c; length += c; length <<= 8;63 c=GETBREAK; buf[3] = c; length += c;62 GETBREAK; buf[0] = c; length = c; length <<= 8; 63 GETBREAK; buf[1] = c; length += c; length <<= 8; 64 GETBREAK; buf[2] = c; length += c; length <<= 8; 65 GETBREAK; buf[3] = c; length += c; 64 66 65 67 /* Read the chunkname */ 66 c=GETBREAK; buf[4] = c;67 c=GETBREAK; buf[5] = c;68 c=GETBREAK; buf[6] = c;69 c=GETBREAK; buf[7] = c;68 GETBREAK; buf[4] = c; 69 GETBREAK; buf[5] = c; 70 GETBREAK; buf[6] = c; 71 GETBREAK; buf[7] = c; 70 72 71 73 … … 82 84 for (i=8; i < length + 12; i++) 83 85 { 84 c=GETBREAK; buf[i] = c;86 GETBREAK; buf[i] = c; 85 87 } 88 89 if (inchar != c) /* EOF */ 90 break; 86 91 87 92 /* Calculate the CRC */ … … 91 96 { 92 97 /* Check the CRC */ 93 if (((crc >> 24) & 0xff ) == buf[length+8] &&94 ((crc >> 16) & 0xff ) == buf[length+9] &&95 ((crc >> 8) & 0xff ) == buf[length+10] &&96 ((crc ) & 0xff ) == buf[length+11])98 if (((crc >> 24) & 0xffU) == buf[length+8] && 99 ((crc >> 16) & 0xffU) == buf[length+9] && 100 ((crc >> 8) & 0xffU) == buf[length+10] && 101 ((crc ) & 0xffU) == buf[length+11]) 97 102 break; 98 103 … … 102 107 break; 103 108 104 c=GETBREAK;105 buf[length+11] =c;109 GETBREAK; 110 buf[length+11] = c; 106 111 107 112 /* Update the CRC */ … … 109 114 } 110 115 116 if (inchar != c) /* EOF */ 117 break; 118 111 119 /* Update length bytes */ 112 buf[0] = (unsigned char)((length << 24) & 0xff);113 buf[1] = (unsigned char)((length << 16) & 0xff);114 buf[2] = (unsigned char)((length << 8) & 0xff);115 buf[3] = (unsigned char)((length ) & 0xff );120 buf[0] = (unsigned char)((length >> 24) & 0xffU); 121 buf[1] = (unsigned char)((length >> 16) & 0xffU); 122 buf[2] = (unsigned char)((length >> 8) & 0xffU); 123 buf[3] = (unsigned char)((length ) & 0xffU); 116 124 117 125 /* Write the fixed iTXt chunk (length, name, data, crc) */ … … 122 130 else 123 131 { 132 if (inchar != c) /* EOF */ 133 break; 134 124 135 /* Copy bytes that were already read (length and chunk name) */ 125 136 for (i=0; i<8; i++) … … 129 140 for (i=8; i< length+12; i++) 130 141 { 131 c=GETBREAK;142 GETBREAK; 132 143 putchar(c); 133 144 } 134 145 135 if (inchar == EOF)146 if (inchar != c) /* EOF */ 136 147 { 137 148 break; … … 143 154 } 144 155 145 if (inchar == EOF)156 if (inchar != c) /* EOF */ 146 157 break; 147 158
Note:
See TracChangeset
for help on using the changeset viewer.