comparison dwt/internal/image/LZWCodec.d @ 7:e831403a80a9

Add 'cast' to casts
author Frank Benoit <benoit@tionex.de>
date Wed, 27 Aug 2008 14:30:35 +0200
parents 380af2bdd8e5
children 5123b17c98ef
comparison
equal deleted inserted replaced
6:b903c16b6f48 7:e831403a80a9
51 currentSlot = newCodes; 51 currentSlot = newCodes;
52 topSlot = 1 << codeSize; 52 topSlot = 1 << codeSize;
53 while ((c = nextCode()) is clearCode) {} 53 while ((c = nextCode()) is clearCode) {}
54 if (c !is endCode) { 54 if (c !is endCode) {
55 oc = fc = c; 55 oc = fc = c;
56 buf[bufIndex] = (byte)c; 56 buf[bufIndex] = cast(byte)c;
57 bufIndex++; 57 bufIndex++;
58 if (bufIndex is imageWidth) { 58 if (bufIndex is imageWidth) {
59 nextPutPixels(buf); 59 nextPutPixels(buf);
60 bufIndex = 0; 60 bufIndex = 0;
61 } 61 }
88 topSlot = topSlot + topSlot; 88 topSlot = topSlot + topSlot;
89 } 89 }
90 } 90 }
91 while (stackIndex > 0) { 91 while (stackIndex > 0) {
92 stackIndex--; 92 stackIndex--;
93 buf[bufIndex] = (byte)stack[stackIndex]; 93 buf[bufIndex] = cast(byte)stack[stackIndex];
94 bufIndex++; 94 bufIndex++;
95 if (bufIndex is imageWidth) { 95 if (bufIndex is imageWidth) {
96 nextPutPixels(buf); 96 nextPutPixels(buf);
97 bufIndex = 0; 97 bufIndex = 0;
98 } 98 }
125 nextPutCode(lastPrefix); 125 nextPutCode(lastPrefix);
126 nextPutCode(endCode); 126 nextPutCode(endCode);
127 127
128 // Write out last partial block 128 // Write out last partial block
129 if (bitsLeft is 8) { 129 if (bitsLeft is 8) {
130 block[0] = (byte)(blockIndex - 1); // Nothing in last byte 130 block[0] = cast(byte)(blockIndex - 1); // Nothing in last byte
131 } else { 131 } else {
132 block[0] = (byte)(blockIndex); // Last byte has data 132 block[0] = cast(byte)(blockIndex); // Last byte has data
133 } 133 }
134 writeBlock(); 134 writeBlock();
135 135
136 // Write out empty block to indicate the end (if needed) 136 // Write out empty block to indicate the end (if needed)
137 if (block[0] !is 0) { 137 if (block[0] !is 0) {
255 bitsLeft = 8; 255 bitsLeft = 8;
256 currentByte = 0; 256 currentByte = 0;
257 blockIndex = 1; 257 blockIndex = 1;
258 blockSize = 255; 258 blockSize = 255;
259 block = new byte[blockSize]; 259 block = new byte[blockSize];
260 block[0] = (byte)(blockSize - 1); 260 block[0] = cast(byte)(blockSize - 1);
261 nodeStack = new LZWNode[1 << bitsPerPixel]; 261 nodeStack = new LZWNode[1 << bitsPerPixel];
262 for (int i = 0; i < nodeStack.length; i++) { 262 for (int i = 0; i < nodeStack.length; i++) {
263 LZWNode node = new LZWNode(); 263 LZWNode node = new LZWNode();
264 node.code = i + 1; 264 node.code = i + 1;
265 node.prefix = -1; 265 node.prefix = -1;
342 int codeBitsToDo = codeSize; 342 int codeBitsToDo = codeSize;
343 // Fill in the remainder of the current byte with the 343 // Fill in the remainder of the current byte with the
344 // *high-order* bits of the code. 344 // *high-order* bits of the code.
345 int c = codeToDo & MASK_TABLE[bitsLeft - 1]; 345 int c = codeToDo & MASK_TABLE[bitsLeft - 1];
346 currentByte = currentByte | (c << (8 - bitsLeft)); 346 currentByte = currentByte | (c << (8 - bitsLeft));
347 block[blockIndex] = (byte)currentByte; 347 block[blockIndex] = cast(byte)currentByte;
348 codeBitsToDo -= bitsLeft; 348 codeBitsToDo -= bitsLeft;
349 if (codeBitsToDo < 1) { 349 if (codeBitsToDo < 1) {
350 // The whole code fit in the first byte, so we are done. 350 // The whole code fit in the first byte, so we are done.
351 bitsLeft -= codeSize; 351 bitsLeft -= codeSize;
352 if (bitsLeft is 0) { 352 if (bitsLeft is 0) {
370 writeBlock(); 370 writeBlock();
371 blockIndex = 1; 371 blockIndex = 1;
372 } 372 }
373 while (codeBitsToDo >= 8) { 373 while (codeBitsToDo >= 8) {
374 currentByte = codeToDo & 0xFF; 374 currentByte = codeToDo & 0xFF;
375 block[blockIndex] = (byte)currentByte; 375 block[blockIndex] = cast(byte)currentByte;
376 codeToDo = codeToDo >> 8; 376 codeToDo = codeToDo >> 8;
377 codeBitsToDo -= 8; 377 codeBitsToDo -= 8;
378 blockIndex++; 378 blockIndex++;
379 if (blockIndex >= blockSize) { 379 if (blockIndex >= blockSize) {
380 writeBlock(); 380 writeBlock();
382 } 382 }
383 } 383 }
384 // Fill the *low-order* bits of the last byte with the remainder 384 // Fill the *low-order* bits of the last byte with the remainder
385 bitsLeft = 8 - codeBitsToDo; 385 bitsLeft = 8 - codeBitsToDo;
386 currentByte = codeToDo; 386 currentByte = codeToDo;
387 block[blockIndex] = (byte)currentByte; 387 block[blockIndex] = cast(byte)currentByte;
388 } 388 }
389 /** 389 /**
390 * Copy a row of pixel values to the image. 390 * Copy a row of pixel values to the image.
391 */ 391 */
392 void nextPutPixels(byte[] buf) { 392 void nextPutPixels(byte[] buf) {
419 else if (pass is 3) line = 2; 419 else if (pass is 3) line = 2;
420 else if (pass is 4) line = 1; 420 else if (pass is 4) line = 1;
421 else if (pass is 5) line = 0; 421 else if (pass is 5) line = 0;
422 if (pass < 5) { 422 if (pass < 5) {
423 if (loader.hasListeners()) { 423 if (loader.hasListeners()) {
424 ImageData imageCopy = (ImageData) image.clone(); 424 ImageData imageCopy = cast(ImageData) image.clone();
425 loader.notifyListeners( 425 loader.notifyListeners(
426 new ImageLoaderEvent(loader, imageCopy, pass - 2, false)); 426 new ImageLoaderEvent(loader, imageCopy, pass - 2, false));
427 } 427 }
428 } 428 }
429 } 429 }
453 try { 453 try {
454 size = inputStream.read(); 454 size = inputStream.read();
455 if (size is -1) { 455 if (size is -1) {
456 DWT.error(DWT.ERROR_INVALID_IMAGE); 456 DWT.error(DWT.ERROR_INVALID_IMAGE);
457 } 457 }
458 block[0] = (byte)size; 458 block[0] = cast(byte)size;
459 size = inputStream.read(block, 1, size); 459 size = inputStream.read(block, 1, size);
460 if (size is -1) { 460 if (size is -1) {
461 DWT.error(DWT.ERROR_INVALID_IMAGE); 461 DWT.error(DWT.ERROR_INVALID_IMAGE);
462 } 462 }
463 } catch (Exception e) { 463 } catch (Exception e) {