Mercurial > projects > dwt-mac
comparison dwt/internal/image/PngDecodingDataStream.d @ 6:b903c16b6f48
Removed throws decls
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:10:03 +0200 |
parents | 1a8b3cb347e0 |
children | e831403a80a9 |
comparison
equal
deleted
inserted
replaced
5:1a8b3cb347e0 | 6:b903c16b6f48 |
---|---|
25 int adlerValue; | 25 int adlerValue; |
26 | 26 |
27 static final int PRIME = 65521; | 27 static final int PRIME = 65521; |
28 static final int MAX_BIT = 7; | 28 static final int MAX_BIT = 7; |
29 | 29 |
30 this(InputStream stream) throws IOException { | 30 this(InputStream stream) { |
31 super(); | 31 super(); |
32 this.stream = stream; | 32 this.stream = stream; |
33 nextBitIndex = MAX_BIT + 1; | 33 nextBitIndex = MAX_BIT + 1; |
34 adlerValue = 1; | 34 adlerValue = 1; |
35 lzBlockReader = new PngLzBlockReader(this); | 35 lzBlockReader = new PngLzBlockReader(this); |
42 * that all of the compressed image data has been read. This | 42 * that all of the compressed image data has been read. This |
43 * method will ensure that the next data value is an end of | 43 * method will ensure that the next data value is an end of |
44 * block marker. If there are more blocks after this one, | 44 * block marker. If there are more blocks after this one, |
45 * the method will read them and ensure that they are empty. | 45 * the method will read them and ensure that they are empty. |
46 */ | 46 */ |
47 void assertImageDataAtEnd() throws IOException { | 47 void assertImageDataAtEnd() { |
48 lzBlockReader.assertCompressedDataAtEnd(); | 48 lzBlockReader.assertCompressedDataAtEnd(); |
49 } | 49 } |
50 | 50 |
51 public void close() throws IOException { | 51 public void close() { |
52 assertImageDataAtEnd(); | 52 assertImageDataAtEnd(); |
53 checkAdler(); | 53 checkAdler(); |
54 } | 54 } |
55 | 55 |
56 int getNextIdatBits(int length) throws IOException { | 56 int getNextIdatBits(int length) { |
57 int value = 0; | 57 int value = 0; |
58 for (int i = 0; i < length; i++) { | 58 for (int i = 0; i < length; i++) { |
59 value |= (getNextIdatBit() << i); | 59 value |= (getNextIdatBit() << i); |
60 } | 60 } |
61 return value; | 61 return value; |
62 } | 62 } |
63 | 63 |
64 int getNextIdatBit() throws IOException { | 64 int getNextIdatBit() { |
65 if (nextBitIndex > MAX_BIT) { | 65 if (nextBitIndex > MAX_BIT) { |
66 currentByte = getNextIdatByte(); | 66 currentByte = getNextIdatByte(); |
67 nextBitIndex = 0; | 67 nextBitIndex = 0; |
68 } | 68 } |
69 return (currentByte & (1 << nextBitIndex)) >> nextBitIndex++; | 69 return (currentByte & (1 << nextBitIndex)) >> nextBitIndex++; |
70 } | 70 } |
71 | 71 |
72 byte getNextIdatByte() throws IOException { | 72 byte getNextIdatByte() { |
73 byte nextByte = (byte)stream.read(); | 73 byte nextByte = (byte)stream.read(); |
74 nextBitIndex = MAX_BIT + 1; | 74 nextBitIndex = MAX_BIT + 1; |
75 return nextByte; | 75 return nextByte; |
76 } | 76 } |
77 | 77 |
82 low = (low + valueInt) % PRIME; | 82 low = (low + valueInt) % PRIME; |
83 high = (low + high) % PRIME; | 83 high = (low + high) % PRIME; |
84 adlerValue = (high << 16) | low; | 84 adlerValue = (high << 16) | low; |
85 } | 85 } |
86 | 86 |
87 public int read() throws IOException { | 87 public int read() { |
88 byte nextDecodedByte = lzBlockReader.getNextByte(); | 88 byte nextDecodedByte = lzBlockReader.getNextByte(); |
89 updateAdler(nextDecodedByte); | 89 updateAdler(nextDecodedByte); |
90 return nextDecodedByte & 0xFF; | 90 return nextDecodedByte & 0xFF; |
91 } | 91 } |
92 | 92 |
93 public int read(byte[] buffer, int off, int len) throws IOException { | 93 public int read(byte[] buffer, int off, int len) { |
94 for (int i = 0; i < len; i++) { | 94 for (int i = 0; i < len; i++) { |
95 int b = read(); | 95 int b = read(); |
96 if (b is -1) return i; | 96 if (b is -1) return i; |
97 buffer[off + i] = (byte)b; | 97 buffer[off + i] = (byte)b; |
98 } | 98 } |
101 | 101 |
102 void error() { | 102 void error() { |
103 DWT.error(DWT.ERROR_INVALID_IMAGE); | 103 DWT.error(DWT.ERROR_INVALID_IMAGE); |
104 } | 104 } |
105 | 105 |
106 private void readCompressedDataHeader() throws IOException { | 106 private void readCompressedDataHeader() { |
107 byte headerByte1 = getNextIdatByte(); | 107 byte headerByte1 = getNextIdatByte(); |
108 byte headerByte2 = getNextIdatByte(); | 108 byte headerByte2 = getNextIdatByte(); |
109 | 109 |
110 int number = ((headerByte1 & 0xFF) << 8) | (headerByte2 & 0xFF); | 110 int number = ((headerByte1 & 0xFF) << 8) | (headerByte2 & 0xFF); |
111 if (number % 31 !is 0) error(); | 111 if (number % 31 !is 0) error(); |
122 if (dictionary !is 0) error(); | 122 if (dictionary !is 0) error(); |
123 | 123 |
124 // int compressionLevel = (headerByte2 & 0xC0) >> 6; | 124 // int compressionLevel = (headerByte2 & 0xC0) >> 6; |
125 } | 125 } |
126 | 126 |
127 void checkAdler() throws IOException { | 127 void checkAdler() { |
128 int storedAdler = ((getNextIdatByte() & 0xFF) << 24) | 128 int storedAdler = ((getNextIdatByte() & 0xFF) << 24) |
129 | ((getNextIdatByte() & 0xFF) << 16) | 129 | ((getNextIdatByte() & 0xFF) << 16) |
130 | ((getNextIdatByte() & 0xFF) << 8) | 130 | ((getNextIdatByte() & 0xFF) << 8) |
131 | (getNextIdatByte() & 0xFF); | 131 | (getNextIdatByte() & 0xFF); |
132 if (storedAdler !is adlerValue) error(); | 132 if (storedAdler !is adlerValue) error(); |