Mercurial > projects > dwt-mac
comparison dwt/internal/image/PNGFileFormat.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | b903c16b6f48 |
children | 5123b17c98ef |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
95 switch (chunk.getChunkType()) { | 95 switch (chunk.getChunkType()) { |
96 case PngChunk.CHUNK_IEND: | 96 case PngChunk.CHUNK_IEND: |
97 break; | 97 break; |
98 case PngChunk.CHUNK_PLTE: | 98 case PngChunk.CHUNK_PLTE: |
99 if (!headerChunk.usesDirectColor()) { | 99 if (!headerChunk.usesDirectColor()) { |
100 paletteChunk = (PngPlteChunk) chunk; | 100 paletteChunk = cast(PngPlteChunk) chunk; |
101 imageData.palette = paletteChunk.getPaletteData(); | 101 imageData.palette = paletteChunk.getPaletteData(); |
102 } | 102 } |
103 break; | 103 break; |
104 case PngChunk.CHUNK_tRNS: | 104 case PngChunk.CHUNK_tRNS: |
105 PngTrnsChunk trnsChunk = (PngTrnsChunk) chunk; | 105 PngTrnsChunk trnsChunk = cast(PngTrnsChunk) chunk; |
106 if (trnsChunk.getTransparencyType(headerChunk) is | 106 if (trnsChunk.getTransparencyType(headerChunk) is |
107 PngTrnsChunk.TRANSPARENCY_TYPE_PIXEL) | 107 PngTrnsChunk.TRANSPARENCY_TYPE_PIXEL) |
108 { | 108 { |
109 imageData.transparentPixel = | 109 imageData.transparentPixel = |
110 trnsChunk.getSwtTransparentPixel(headerChunk); | 110 trnsChunk.getSwtTransparentPixel(headerChunk); |
133 // then this is an invalid image. | 133 // then this is an invalid image. |
134 DWT.error(DWT.ERROR_INVALID_IMAGE); | 134 DWT.error(DWT.ERROR_INVALID_IMAGE); |
135 } else { | 135 } else { |
136 // Read in the pixel data for the image. This should | 136 // Read in the pixel data for the image. This should |
137 // go through all the image's IDAT chunks. | 137 // go through all the image's IDAT chunks. |
138 PngIdatChunk dataChunk = (PngIdatChunk) chunk; | 138 PngIdatChunk dataChunk = cast(PngIdatChunk) chunk; |
139 readPixelData(dataChunk, chunkReader); | 139 readPixelData(dataChunk, chunkReader); |
140 } | 140 } |
141 break; | 141 break; |
142 default: | 142 default: |
143 if (chunk.isCritical()) { | 143 if (chunk.isCritical()) { |
378 byte[] row1 = new byte[bytesPerRow]; | 378 byte[] row1 = new byte[bytesPerRow]; |
379 byte[] row2 = new byte[bytesPerRow]; | 379 byte[] row2 = new byte[bytesPerRow]; |
380 byte[] currentRow = row1; | 380 byte[] currentRow = row1; |
381 byte[] lastRow = row2; | 381 byte[] lastRow = row2; |
382 for (int row = startRow; row < height; row += rowInterval) { | 382 for (int row = startRow; row < height; row += rowInterval) { |
383 byte filterType = (byte)inputStream.read(); | 383 byte filterType = cast(byte)inputStream.read(); |
384 int read = 0; | 384 int read = 0; |
385 while (read !is bytesPerRow) { | 385 while (read !is bytesPerRow) { |
386 read += inputStream.read(currentRow, read, bytesPerRow - read); | 386 read += inputStream.read(currentRow, read, bytesPerRow - read); |
387 } | 387 } |
388 filterRow(currentRow, lastRow, filterType); | 388 filterRow(currentRow, lastRow, filterType); |
443 * finalFrame should be true if the image has finished | 443 * finalFrame should be true if the image has finished |
444 * loading, false if there are more frames to come. | 444 * loading, false if there are more frames to come. |
445 */ | 445 */ |
446 void fireInterlacedFrameEvent(int frameCount) { | 446 void fireInterlacedFrameEvent(int frameCount) { |
447 if (loader.hasListeners()) { | 447 if (loader.hasListeners()) { |
448 ImageData image = (ImageData) imageData.clone(); | 448 ImageData image = cast(ImageData) imageData.clone(); |
449 bool finalFrame = frameCount is 6; | 449 bool finalFrame = frameCount is 6; |
450 loader.notifyListeners(new ImageLoaderEvent(loader, image, frameCount, finalFrame)); | 450 loader.notifyListeners(new ImageLoaderEvent(loader, image, frameCount, finalFrame)); |
451 } | 451 } |
452 } | 452 } |
453 /** | 453 /** |
463 byte[] row2 = new byte[bytesPerRow]; | 463 byte[] row2 = new byte[bytesPerRow]; |
464 byte[] currentRow = row1; | 464 byte[] currentRow = row1; |
465 byte[] lastRow = row2; | 465 byte[] lastRow = row2; |
466 int height = headerChunk.getHeight(); | 466 int height = headerChunk.getHeight(); |
467 for (int row = 0; row < height; row++) { | 467 for (int row = 0; row < height; row++) { |
468 byte filterType = (byte)inputStream.read(); | 468 byte filterType = cast(byte)inputStream.read(); |
469 int read = 0; | 469 int read = 0; |
470 while (read !is bytesPerRow) { | 470 while (read !is bytesPerRow) { |
471 read += inputStream.read(currentRow, read, bytesPerRow - read); | 471 read += inputStream.read(currentRow, read, bytesPerRow - read); |
472 } | 472 } |
473 filterRow(currentRow, lastRow, filterType); | 473 filterRow(currentRow, lastRow, filterType); |
497 //double multiplier = (Compatibility.pow2(8) - 1) / (Compatibility.pow2(16) - 1); | 497 //double multiplier = (Compatibility.pow2(8) - 1) / (Compatibility.pow2(16) - 1); |
498 for (int i = 0; i < numberOfValues; i++) { | 498 for (int i = 0; i < numberOfValues; i++) { |
499 int sourceIndex = sourceOffset + (2 * i); | 499 int sourceIndex = sourceOffset + (2 * i); |
500 int destinationIndex = destinationOffset + i; | 500 int destinationIndex = destinationOffset + i; |
501 //int value = (source[sourceIndex] << 8) | source[sourceIndex + 1]; | 501 //int value = (source[sourceIndex] << 8) | source[sourceIndex + 1]; |
502 //byte compressedValue = (byte)(value * multiplier); | 502 //byte compressedValue = cast(byte)(value * multiplier); |
503 byte compressedValue = source[sourceIndex]; | 503 byte compressedValue = source[sourceIndex]; |
504 destination[destinationIndex] = compressedValue; | 504 destination[destinationIndex] = compressedValue; |
505 } | 505 } |
506 } | 506 } |
507 /** | 507 /** |
513 * The fast way to do this is just to drop the low | 513 * The fast way to do this is just to drop the low |
514 * byte of the 16-bit value. | 514 * byte of the 16-bit value. |
515 */ | 515 */ |
516 static int compress16BitDepthTo8BitDepth(int value) { | 516 static int compress16BitDepthTo8BitDepth(int value) { |
517 //double multiplier = (Compatibility.pow2(8) - 1) / (Compatibility.pow2(16) - 1); | 517 //double multiplier = (Compatibility.pow2(8) - 1) / (Compatibility.pow2(16) - 1); |
518 //byte compressedValue = (byte)(value * multiplier); | 518 //byte compressedValue = cast(byte)(value * multiplier); |
519 return value >> 8; | 519 return value >> 8; |
520 } | 520 } |
521 /** | 521 /** |
522 * PNG supports four filtering types. These types are applied | 522 * PNG supports four filtering types. These types are applied |
523 * per row of image data. This method unfilters the given row | 523 * per row of image data. This method unfilters the given row |
530 break; | 530 break; |
531 case PngIhdrChunk.FILTER_SUB: | 531 case PngIhdrChunk.FILTER_SUB: |
532 for (int i = byteOffset; i < row.length; i++) { | 532 for (int i = byteOffset; i < row.length; i++) { |
533 int current = row[i] & 0xFF; | 533 int current = row[i] & 0xFF; |
534 int left = row[i - byteOffset] & 0xFF; | 534 int left = row[i - byteOffset] & 0xFF; |
535 row[i] = (byte)((current + left) & 0xFF); | 535 row[i] = cast(byte)((current + left) & 0xFF); |
536 } | 536 } |
537 break; | 537 break; |
538 case PngIhdrChunk.FILTER_UP: | 538 case PngIhdrChunk.FILTER_UP: |
539 for (int i = 0; i < row.length; i++) { | 539 for (int i = 0; i < row.length; i++) { |
540 int current = row[i] & 0xFF; | 540 int current = row[i] & 0xFF; |
541 int above = previousRow[i] & 0xFF; | 541 int above = previousRow[i] & 0xFF; |
542 row[i] = (byte)((current + above) & 0xFF); | 542 row[i] = cast(byte)((current + above) & 0xFF); |
543 } | 543 } |
544 break; | 544 break; |
545 case PngIhdrChunk.FILTER_AVERAGE: | 545 case PngIhdrChunk.FILTER_AVERAGE: |
546 for (int i = 0; i < row.length; i++) { | 546 for (int i = 0; i < row.length; i++) { |
547 int left = (i < byteOffset) ? 0 : row[i - byteOffset] & 0xFF; | 547 int left = (i < byteOffset) ? 0 : row[i - byteOffset] & 0xFF; |
548 int above = previousRow[i] & 0xFF; | 548 int above = previousRow[i] & 0xFF; |
549 int current = row[i] & 0xFF; | 549 int current = row[i] & 0xFF; |
550 row[i] = (byte)((current + ((left + above) / 2)) & 0xFF); | 550 row[i] = cast(byte)((current + ((left + above) / 2)) & 0xFF); |
551 } | 551 } |
552 break; | 552 break; |
553 case PngIhdrChunk.FILTER_PAETH: | 553 case PngIhdrChunk.FILTER_PAETH: |
554 for (int i = 0; i < row.length; i++) { | 554 for (int i = 0; i < row.length; i++) { |
555 int left = (i < byteOffset) ? 0 : row[i - byteOffset] & 0xFF; | 555 int left = (i < byteOffset) ? 0 : row[i - byteOffset] & 0xFF; |
568 } else { | 568 } else { |
569 preductor = aboveLeft; | 569 preductor = aboveLeft; |
570 } | 570 } |
571 | 571 |
572 int currentValue = row[i] & 0xFF; | 572 int currentValue = row[i] & 0xFF; |
573 row[i] = (byte) ((currentValue + preductor) & 0xFF); | 573 row[i] = cast(byte) ((currentValue + preductor) & 0xFF); |
574 } | 574 } |
575 break; | 575 break; |
576 } | 576 } |
577 } | 577 } |
578 | 578 |
579 } | 579 } |