Skip to content

Commit 859fe49

Browse files
committed
Fix issues with autoport in io.codec.
1 parent bfd0bd5 commit 859fe49

File tree

11 files changed

+143
-132
lines changed

11 files changed

+143
-132
lines changed

io/src/main/java/com/itextpdf/io/codec/BitFile.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ public void writeBits(int bits, int numbits) throws IOException {
6868
{
6969
if (blocks) // GIF
7070
{
71-
buffer[index] |= (bits & ((1 << numbits) - 1)) << (8 - bitsLeft);
71+
buffer[index] |= (byte) ((bits & ((1 << numbits) - 1)) << (8 - bitsLeft));
7272
bitsWritten += numbits;
7373
bitsLeft -= numbits;
7474
numbits = 0;
7575
} else {
76-
buffer[index] |= (bits & ((1 << numbits) - 1)) << (bitsLeft - numbits);
76+
buffer[index] |= (byte) ((bits & ((1 << numbits) - 1)) << (bitsLeft - numbits));
7777
bitsWritten += numbits;
7878
bitsLeft -= numbits;
7979
numbits = 0;
@@ -85,7 +85,7 @@ public void writeBits(int bits, int numbits) throws IOException {
8585
{
8686
// if bits > space left in current byte then the lowest order bits
8787
// of code are taken and put in current byte and rest put in next.
88-
buffer[index] |= (bits & ((1 << bitsLeft) - 1)) << (8 - bitsLeft);
88+
buffer[index] |= (byte) ((bits & ((1 << bitsLeft) - 1)) << (8 - bitsLeft));
8989
bitsWritten += bitsLeft;
9090
bits >>= bitsLeft;
9191
numbits -= bitsLeft;
@@ -96,7 +96,7 @@ public void writeBits(int bits, int numbits) throws IOException {
9696
// of code are taken and put in current byte and rest put in next.
9797
// at highest order bit location !!
9898
int topbits = (bits >>> (numbits - bitsLeft)) & ((1 << bitsLeft) - 1);
99-
buffer[index] |= topbits;
99+
buffer[index] |= (byte) topbits;
100100
numbits -= bitsLeft; // ok this many bits gone off the top
101101
bitsWritten += bitsLeft;
102102
buffer[++index] = 0; // next index

io/src/main/java/com/itextpdf/io/codec/Jbig2SegmentReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void readSegment(Jbig2Segment s) throws java.io.IOException {
207207
int page_bitmap_width = ra.readInt();
208208
int page_bitmap_height = ra.readInt();
209209
ra.seek(last);
210-
Jbig2Page p = pages.get(Integer.valueOf(s.page));
210+
Jbig2Page p = pages.get(s.page);
211211
if (p == null) {
212212
throw new IllegalStateException("referring.to.widht.height.of.page.we.havent.seen.yet.1");
213213
//TODO, s.page);

io/src/main/java/com/itextpdf/io/codec/LZWCompressor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public LZWCompressor(OutputStream outputStream, int codeSize, boolean TIFF) thro
7272
if (tiffFudge_)
7373
--limit_;
7474

75-
prefix_ = (short) 0xFFFF;
75+
//0xFFFF
76+
prefix_ = -1;
7677
lzss_ = new LZWStringTable();
7778
lzss_.ClearTable(codeSize_);
7879
bf_.writeBits(clearCode_, numBits_);

io/src/main/java/com/itextpdf/io/codec/LZWStringTable.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ public class LZWStringTable {
1717
*/
1818
private final static int RES_CODES = 2;
1919

20-
private final static short HASH_FREE = (short) 0xFFFF;
21-
private final static short NEXT_FIRST = (short) 0xFFFF;
20+
//0xFFFF
21+
private final static short HASH_FREE = -1;
22+
//0xFFFF
23+
private final static short NEXT_FIRST = -1;
2224

2325
private final static int MAXBITS = 12;
2426
private final static int MAXSTR = (1 << MAXBITS);
@@ -99,7 +101,8 @@ public short FindCharString(short index, byte b) {
99101
hshidx = (hshidx + HASHSTEP) % HASHSIZE;
100102
}
101103

102-
return (short) 0xFFFF;
104+
//return (short) 0xFFFF;
105+
return -1;
103106
}
104107

105108
/**
@@ -113,12 +116,14 @@ public void ClearTable(int codesize) {
113116
strHsh_[q] = HASH_FREE;
114117

115118
int w = (1 << codesize) + RES_CODES;
116-
for (int q = 0; q < w; q++)
117-
AddCharString((short) 0xFFFF, (byte) q); // init with no prefix
119+
for (int q = 0; q < w; q++) {
120+
//AddCharString((short) 0xFFFF, (byte) q); // init with no prefix
121+
AddCharString((short)-1, (byte) q); // init with no prefix
122+
}
118123
}
119124

120125
static public int Hash(short index, byte lastbyte) {
121-
return ((int) ((short) (lastbyte << 8) ^ index) & 0xFFFF) % HASHSIZE;
126+
return (((short) (lastbyte << 8) ^ index) & 0xFFFF) % HASHSIZE;
122127
}
123128

124129
/**
@@ -145,7 +150,8 @@ public int expandCode(byte[] buf, int offset, short code, int skipHead) {
145150
if (offset == -2) {
146151
if (skipHead == 1) skipHead = 0;
147152
}
148-
if (code == (short) 0xFFFF || // just in case
153+
//-1 ~ 0xFFFF
154+
if (code == -1 || // just in case
149155
skipHead == strLen_[code]) // DONE no more unpacked
150156
return 0;
151157

@@ -163,7 +169,7 @@ public int expandCode(byte[] buf, int offset, short code, int skipHead) {
163169

164170
// NOTE: data unpacks in reverse direction and we are placing the
165171
// unpacked data directly into the array in the correct location.
166-
while ((idx > offset) && (code != (short) 0xFFFF)) {
172+
while ((idx > offset) && (code != -1)) {
167173
if (--skipTail < 0) // skip required of expanded data
168174
{
169175
buf[--idx] = strChr_[code];

io/src/main/java/com/itextpdf/io/codec/PngWriter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private static void make_crc_table() {
8787
int c = n;
8888
for (int k = 0; k < 8; k++) {
8989
if ((c & 1) != 0)
90-
c = 0xedb88320 ^ (c >>> 1);
90+
c = (int)(0xedb88320 ^ (c >>> 1));
9191
else
9292
c = c >>> 1;
9393
}
@@ -108,11 +108,11 @@ private static int update_crc(int crc, byte[] buf, int offset, int len) {
108108
}
109109

110110
private static int crc(byte[] buf, int offset, int len) {
111-
return update_crc(0xffffffff, buf, offset, len) ^ 0xffffffff;
111+
return ~update_crc(-1, buf, offset, len);
112112
}
113113

114114
private static int crc(byte[] buf) {
115-
return update_crc(0xffffffff, buf, 0, buf.length) ^ 0xffffffff;
115+
return ~update_crc(-1, buf, 0, buf.length);
116116
}
117117

118118
public void outputInt(int n) throws IOException {
@@ -130,8 +130,8 @@ public void writeChunk(byte[] chunkType, byte[] data) throws IOException {
130130
outputInt(data.length);
131131
outp.write(chunkType, 0, 4);
132132
outp.write(data);
133-
int c = update_crc(0xffffffff, chunkType, 0, chunkType.length);
134-
c = update_crc(c, data, 0, data.length) ^ 0xffffffff;
133+
int c = update_crc(-1, chunkType, 0, chunkType.length);
134+
c = ~update_crc(c, data, 0, data.length);
135135
outputInt(c);
136136
}
137137

io/src/main/java/com/itextpdf/io/codec/TIFFDirectory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public int getNumEntries() {
414414
* or null if the tag is not present.
415415
*/
416416
public TIFFField getField(int tag) {
417-
Integer i = fieldIndex.get(Integer.valueOf(tag));
417+
Integer i = fieldIndex.get(tag);
418418
if (i == null) {
419419
return null;
420420
} else {
@@ -460,7 +460,7 @@ public TIFFField[] getFields() {
460460
* TIFF_UNDEFINED.
461461
*/
462462
public byte getFieldAsByte(int tag, int index) {
463-
Integer i = fieldIndex.get(Integer.valueOf(tag));
463+
Integer i = fieldIndex.get(tag);
464464
byte[] b = fields[i].getAsBytes();
465465
return b[index];
466466
}
@@ -482,7 +482,7 @@ public byte getFieldAsByte(int tag) {
482482
* TIFF_SHORT, TIFF_SSHORT, TIFF_SLONG or TIFF_LONG.
483483
*/
484484
public long getFieldAsLong(int tag, int index) {
485-
Integer i = fieldIndex.get(Integer.valueOf(tag));
485+
Integer i = fieldIndex.get(tag);
486486
return fields[i].getAsLong(index);
487487
}
488488

@@ -503,7 +503,7 @@ public long getFieldAsLong(int tag) {
503503
* TIFF_ASCII).
504504
*/
505505
public float getFieldAsFloat(int tag, int index) {
506-
Integer i = fieldIndex.get(Integer.valueOf(tag));
506+
Integer i = fieldIndex.get(tag);
507507
return fields[i].getAsFloat(index);
508508
}
509509

@@ -523,7 +523,7 @@ public float getFieldAsFloat(int tag) {
523523
* TIFF_ASCII).
524524
*/
525525
public double getFieldAsDouble(int tag, int index) {
526-
Integer i = fieldIndex.get(Integer.valueOf(tag));
526+
Integer i = fieldIndex.get(tag);
527527
return fields[i].getAsDouble(index);
528528
}
529529

io/src/main/java/com/itextpdf/io/codec/TIFFFaxDecoder.java

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -101,39 +101,39 @@ public class TIFFFaxDecoder {
101101
};
102102

103103
// Table to be used when fillOrder = 2, for flipping bytes.
104-
static byte flipTable[] = {
105-
0, -128, 64, -64, 32, -96, 96, -32,
106-
16, -112, 80, -48, 48, -80, 112, -16,
107-
8, -120, 72, -56, 40, -88, 104, -24,
108-
24, -104, 88, -40, 56, -72, 120, -8,
109-
4, -124, 68, -60, 36, -92, 100, -28,
110-
20, -108, 84, -44, 52, -76, 116, -12,
111-
12, -116, 76, -52, 44, -84, 108, -20,
112-
28, -100, 92, -36, 60, -68, 124, -4,
113-
2, -126, 66, -62, 34, -94, 98, -30,
114-
18, -110, 82, -46, 50, -78, 114, -14,
115-
10, -118, 74, -54, 42, -86, 106, -22,
116-
26, -102, 90, -38, 58, -70, 122, -6,
117-
6, -122, 70, -58, 38, -90, 102, -26,
118-
22, -106, 86, -42, 54, -74, 118, -10,
119-
14, -114, 78, -50, 46, -82, 110, -18,
120-
30, -98, 94, -34, 62, -66, 126, -2,
121-
1, -127, 65, -63, 33, -95, 97, -31,
122-
17, -111, 81, -47, 49, -79, 113, -15,
123-
9, -119, 73, -55, 41, -87, 105, -23,
124-
25, -103, 89, -39, 57, -71, 121, -7,
125-
5, -123, 69, -59, 37, -91, 101, -27,
126-
21, -107, 85, -43, 53, -75, 117, -11,
127-
13, -115, 77, -51, 45, -83, 109, -19,
128-
29, -99, 93, -35, 61, -67, 125, -3,
129-
3, -125, 67, -61, 35, -93, 99, -29,
130-
19, -109, 83, -45, 51, -77, 115, -13,
131-
11, -117, 75, -53, 43, -85, 107, -21,
132-
27, -101, 91, -37, 59, -69, 123, -5,
133-
7, -121, 71, -57, 39, -89, 103, -25,
134-
23, -105, 87, -41, 55, -73, 119, -9,
135-
15, -113, 79, -49, 47, -81, 111, -17,
136-
31, -97, 95, -33, 63, -65, 127, -1,
104+
static public byte flipTable[] = {
105+
(byte) 0, (byte) -128, (byte) 64, (byte) -64, (byte) 32, (byte) -96, (byte) 96, (byte) -32,
106+
(byte) 16, (byte) -112, (byte) 80, (byte) -48, (byte) 48, (byte) -80, (byte) 112, (byte) -16,
107+
(byte) 8, (byte) -120, (byte) 72, (byte) -56, (byte) 40, (byte) -88, (byte) 104, (byte) -24,
108+
(byte) 24, (byte) -104, (byte) 88, (byte) -40, (byte) 56, (byte) -72, (byte) 120, (byte) -8,
109+
(byte) 4, (byte) -124, (byte) 68, (byte) -60, (byte) 36, (byte) -92, (byte) 100, (byte) -28,
110+
(byte) 20, (byte) -108, (byte) 84, (byte) -44, (byte) 52, (byte) -76, (byte) 116, (byte) -12,
111+
(byte) 12, (byte) -116, (byte) 76, (byte) -52, (byte) 44, (byte) -84, (byte) 108, (byte) -20,
112+
(byte) 28, (byte) -100, (byte) 92, (byte) -36, (byte) 60, (byte) -68, (byte) 124, (byte) -4,
113+
(byte) 2, (byte) -126, (byte) 66, (byte) -62, (byte) 34, (byte) -94, (byte) 98, (byte) -30,
114+
(byte) 18, (byte) -110, (byte) 82, (byte) -46, (byte) 50, (byte) -78, (byte) 114, (byte) -14,
115+
(byte) 10, (byte) -118, (byte) 74, (byte) -54, (byte) 42, (byte) -86, (byte) 106, (byte) -22,
116+
(byte) 26, (byte) -102, (byte) 90, (byte) -38, (byte) 58, (byte) -70, (byte) 122, (byte) -6,
117+
(byte) 6, (byte) -122, (byte) 70, (byte) -58, (byte) 38, (byte) -90, (byte) 102, (byte) -26,
118+
(byte) 22, (byte) -106, (byte) 86, (byte) -42, (byte) 54, (byte) -74, (byte) 118, (byte) -10,
119+
(byte) 14, (byte) -114, (byte) 78, (byte) -50, (byte) 46, (byte) -82, (byte) 110, (byte) -18,
120+
(byte) 30, (byte) -98, (byte) 94, (byte) -34, (byte) 62, (byte) -66, (byte) 126, (byte) -2,
121+
(byte) 1, (byte) -127, (byte) 65, (byte) -63, (byte) 33, (byte) -95, (byte) 97, (byte) -31,
122+
(byte) 17, (byte) -111, (byte) 81, (byte) -47, (byte) 49, (byte) -79, (byte) 113, (byte) -15,
123+
(byte) 9, (byte) -119, (byte) 73, (byte) -55, (byte) 41, (byte) -87, (byte) 105, (byte) -23,
124+
(byte) 25, (byte) -103, (byte) 89, (byte) -39, (byte) 57, (byte) -71, (byte) 121, (byte) -7,
125+
(byte) 5, (byte) -123, (byte) 69, (byte) -59, (byte) 37, (byte) -91, (byte) 101, (byte) -27,
126+
(byte) 21, (byte) -107, (byte) 85, (byte) -43, (byte) 53, (byte) -75, (byte) 117, (byte) -11,
127+
(byte) 13, (byte) -115, (byte) 77, (byte) -51, (byte) 45, (byte) -83, (byte) 109, (byte) -19,
128+
(byte) 29, (byte) -99, (byte) 93, (byte) -35, (byte) 61, (byte) -67, (byte) 125, (byte) -3,
129+
(byte) 3, (byte) -125, (byte) 67, (byte) -61, (byte) 35, (byte) -93, (byte) 99, (byte) -29,
130+
(byte) 19, (byte) -109, (byte) 83, (byte) -45, (byte) 51, (byte) -77, (byte) 115, (byte) -13,
131+
(byte) 11, (byte) -117, (byte) 75, (byte) -53, (byte) 43, (byte) -85, (byte) 107, (byte) -21,
132+
(byte) 27, (byte) -101, (byte) 91, (byte) -37, (byte) 59, (byte) -69, (byte) 123, (byte) -5,
133+
(byte) 7, (byte) -121, (byte) 71, (byte) -57, (byte) 39, (byte) -89, (byte) 103, (byte) -25,
134+
(byte) 23, (byte) -105, (byte) 87, (byte) -41, (byte) 55, (byte) -73, (byte) 119, (byte) -9,
135+
(byte) 15, (byte) -113, (byte) 79, (byte) -49, (byte) 47, (byte) -81, (byte) 111, (byte) -17,
136+
(byte) 31, (byte) -97, (byte) 95, (byte) -33, (byte) 63, (byte) -65, (byte) 127, (byte) -1,
137137
};
138138

139139
// The main 10 bit white runs lookup table
@@ -397,11 +397,18 @@ public class TIFFFaxDecoder {
397397
};
398398

399399
// Additional make up codes for both White and Black runs
400-
static short additionalMakeup[] = {
401-
28679, 28679, 31752, (short) 32777,
402-
(short) 33801, (short) 34825, (short) 35849, (short) 36873,
403-
(short) 29703, (short) 29703, (short) 30727, (short) 30727,
404-
(short) 37897, (short) 38921, (short) 39945, (short) 40969
400+
// static short additionalMakeup[] = {
401+
// 28679, 28679, 31752, (short)32777,
402+
// (short)33801, (short)34825, (short)35849, (short)36873,
403+
// (short)29703, (short)29703, (short)30727, (short)30727,
404+
// (short)37897, (short)38921, (short)39945, (short)40969
405+
// };
406+
//replace with constants without overload
407+
static public short additionalMakeup[] = {
408+
28679, 28679, 31752, -32759,
409+
-31735, -30711, -29687, -28663,
410+
29703, 29703, 30727, 30727,
411+
-27639, -26615, -25591, -24567
405412
};
406413

407414
// Initial black run look up table, uses the first 4 bits of a code
@@ -1141,7 +1148,7 @@ private void setToBlack(byte[] buffer,
11411148
int maskVal = 1 << (7 - shift);
11421149
byte val = buffer[byteNum];
11431150
while (maskVal > 0 && bitNum < lastBit) {
1144-
val |= maskVal;
1151+
val |= (byte) maskVal;
11451152
maskVal >>= 1;
11461153
++bitNum;
11471154
}
@@ -1161,7 +1168,7 @@ private void setToBlack(byte[] buffer,
11611168
if (recoverFromImageError && !(byteNum < buffer.length)) {
11621169
// do nothing
11631170
} else {
1164-
buffer[byteNum] |= 1 << (7 - (bitNum & 0x7));
1171+
buffer[byteNum] |= (byte) (1 << (7 - (bitNum & 0x7)));
11651172
}
11661173
++bitNum;
11671174
}

0 commit comments

Comments
 (0)