Mercurial > projects > dwt-mac
comparison dwt/internal/image/PngDeflater.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | 1a8b3cb347e0 |
children | 5123b17c98ef |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
183 | 183 |
184 }; | 184 }; |
185 | 185 |
186 void writeShortLSB(ByteArrayOutputStream baos, int theShort) { | 186 void writeShortLSB(ByteArrayOutputStream baos, int theShort) { |
187 | 187 |
188 byte byte1 = (byte) (theShort & 0xff); | 188 byte byte1 = cast(byte) (theShort & 0xff); |
189 byte byte2 = (byte) ((theShort >> 8) & 0xff); | 189 byte byte2 = cast(byte) ((theShort >> 8) & 0xff); |
190 byte[] temp = {byte1, byte2}; | 190 byte[] temp = {byte1, byte2}; |
191 baos.write(temp, 0, 2); | 191 baos.write(temp, 0, 2); |
192 | 192 |
193 } | 193 } |
194 | 194 |
195 void writeInt(ByteArrayOutputStream baos, int theInt) { | 195 void writeInt(ByteArrayOutputStream baos, int theInt) { |
196 | 196 |
197 byte byte1 = (byte) ((theInt >> 24) & 0xff); | 197 byte byte1 = cast(byte) ((theInt >> 24) & 0xff); |
198 byte byte2 = (byte) ((theInt >> 16) & 0xff); | 198 byte byte2 = cast(byte) ((theInt >> 16) & 0xff); |
199 byte byte3 = (byte) ((theInt >> 8) & 0xff); | 199 byte byte3 = cast(byte) ((theInt >> 8) & 0xff); |
200 byte byte4 = (byte) (theInt & 0xff); | 200 byte byte4 = cast(byte) (theInt & 0xff); |
201 byte[] temp = {byte1, byte2, byte3, byte4}; | 201 byte[] temp = {byte1, byte2, byte3, byte4}; |
202 baos.write(temp, 0, 4); | 202 baos.write(temp, 0, 4); |
203 | 203 |
204 } | 204 } |
205 | 205 |
227 void writeBits(int value, int count) { | 227 void writeBits(int value, int count) { |
228 | 228 |
229 buffer |= value << bitCount; | 229 buffer |= value << bitCount; |
230 bitCount += count; | 230 bitCount += count; |
231 if (bitCount >= 16) { | 231 if (bitCount >= 16) { |
232 bytes.write((byte) buffer); | 232 bytes.write(cast(byte) buffer); |
233 bytes.write((byte) (buffer >>> 8)); | 233 bytes.write(cast(byte) (buffer >>> 8)); |
234 buffer >>>= 16; | 234 buffer >>>= 16; |
235 bitCount -= 16; | 235 bitCount -= 16; |
236 } | 236 } |
237 | 237 |
238 } | 238 } |
239 | 239 |
240 void alignToByte() { | 240 void alignToByte() { |
241 | 241 |
242 if (bitCount > 0) { | 242 if (bitCount > 0) { |
243 bytes.write((byte) buffer); | 243 bytes.write(cast(byte) buffer); |
244 if (bitCount > 8) bytes.write((byte) (buffer >>> 8)); | 244 if (bitCount > 8) bytes.write(cast(byte) (buffer >>> 8)); |
245 } | 245 } |
246 buffer = 0; | 246 buffer = 0; |
247 bitCount = 0; | 247 bitCount = 0; |
248 | 248 |
249 } | 249 } |
572 blockLength = 65535; | 572 blockLength = 65535; |
573 BFINAL = 0x00; | 573 BFINAL = 0x00; |
574 } | 574 } |
575 | 575 |
576 // write data header | 576 // write data header |
577 bytes.write((byte) BFINAL); | 577 bytes.write(cast(byte) BFINAL); |
578 writeShortLSB(bytes, blockLength); // LEN | 578 writeShortLSB(bytes, blockLength); // LEN |
579 writeShortLSB(bytes, blockLength ^ 0xffff); // NLEN (one's complement of LEN) | 579 writeShortLSB(bytes, blockLength ^ 0xffff); // NLEN (one's complement of LEN) |
580 | 580 |
581 // write actual data | 581 // write actual data |
582 bytes.write(in, start, blockLength); | 582 bytes.write(in, start, blockLength); |
592 | 592 |
593 in = input; | 593 in = input; |
594 inLength = input.length; | 594 inLength = input.length; |
595 | 595 |
596 // write zlib header | 596 // write zlib header |
597 bytes.write((byte) 0x78); // window size = 0x70 (32768), compression method = 0x08 | 597 bytes.write(cast(byte) 0x78); // window size = 0x70 (32768), compression method = 0x08 |
598 bytes.write((byte) 0x9C); // compression level = 0x80 (default), check bits = 0x1C | 598 bytes.write(cast(byte) 0x9C); // compression level = 0x80 (default), check bits = 0x1C |
599 | 599 |
600 // compute checksum | 600 // compute checksum |
601 for (int i = 0; i < inLength; i++) { | 601 for (int i = 0; i < inLength; i++) { |
602 updateAdler(in[i]); | 602 updateAdler(in[i]); |
603 } | 603 } |