diff dwt/internal/image/PngTrnsChunk.d @ 34:5123b17c98ef

Ported dwt.events.*, dwt.graphics.GC, Region, dwt.internal.image.*
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sun, 14 Sep 2008 01:45:57 +0200
parents e831403a80a9
children
line wrap: on
line diff
--- a/dwt/internal/image/PngTrnsChunk.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngTrnsChunk.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,24 +7,34 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
-module dwt.internal.image;
-
+module dwt.internal.image.PngTrnsChunk;
 
 import dwt.DWT;
+import dwt.graphics.PaletteData;
 import dwt.graphics.RGB;
+import dwt.internal.image.PngChunk;
+import dwt.internal.image.PNGFileFormat;
+import dwt.internal.image.PngFileReadState;
+import dwt.internal.image.PngIhdrChunk;
+import dwt.internal.image.PngPlteChunk;
 
 public class PngTrnsChunk : PngChunk {
-    static final int TRANSPARENCY_TYPE_PIXEL = 0;
-    static final int TRANSPARENCY_TYPE_ALPHAS = 1;
-    static final int RGB_DATA_LENGTH = 6;
-    
+
+    alias PngChunk.validate validate;
+
+    static const int TRANSPARENCY_TYPE_PIXEL = 0;
+    static const int TRANSPARENCY_TYPE_ALPHAS = 1;
+    static const int RGB_DATA_LENGTH = 6;
+
 this(RGB rgb) {
     super(RGB_DATA_LENGTH);
     setType(TYPE_tRNS);
     setInt16(DATA_OFFSET, rgb.red);
     setInt16(DATA_OFFSET + 2, rgb.green);
-    setInt16(DATA_OFFSET + 4, rgb.blue);    
+    setInt16(DATA_OFFSET + 4, rgb.blue);
     setCRC(computeCRC());
 }
 
@@ -32,7 +42,7 @@
     super(reference);
 }
 
-int getChunkType() {
+override int getChunkType() {
     return CHUNK_tRNS;
 }
 
@@ -40,11 +50,11 @@
     bool valid;
     switch (header.getColorType()) {
         case PngIhdrChunk.COLOR_TYPE_RGB:
-            // Three 2-byte values cast(RGB)
+            // Three 2-byte values (RGB)
             valid = getLength() is 6;
             break;
         case PngIhdrChunk.COLOR_TYPE_PALETTE:
-            // Three 2-byte values cast(RGB)
+            // Three 2-byte values (RGB)
             valid = getLength() <= paletteChunk.getLength();
             break;
         case PngIhdrChunk.COLOR_TYPE_GRAYSCALE:
@@ -69,15 +79,15 @@
     if (!readState.readIHDR
         || (headerChunk.getMustHavePalette() && !readState.readPLTE)
         || readState.readIDAT
-        || readState.readIEND) 
+        || readState.readIEND)
     {
         DWT.error(DWT.ERROR_INVALID_IMAGE);
     } else {
         readState.readTRNS = true;
     }
-    
+
     validateLength(headerChunk, paletteChunk);
-    
+
     super.validate(readState, headerChunk);
 }
 
@@ -113,13 +123,13 @@
             int green = ((reference[DATA_OFFSET + 2] & 0xFF) << 8)
                 | (reference[DATA_OFFSET + 3] & 0xFF);
             int blue = ((reference[DATA_OFFSET + 4] & 0xFF) << 8)
-                | (reference[DATA_OFFSET + 5] & 0xFF);          
+                | (reference[DATA_OFFSET + 5] & 0xFF);
             if (header.getBitDepth() > 8) {
                 red = PNGFileFormat.compress16BitDepthTo8BitDepth(red);
                 green = PNGFileFormat.compress16BitDepthTo8BitDepth(green);
-                blue = PNGFileFormat.compress16BitDepthTo8BitDepth(blue);           
+                blue = PNGFileFormat.compress16BitDepthTo8BitDepth(blue);
             }
-            return (red << 16) | (green << 8) | blue;   
+            return (red << 16) | (green << 8) | blue;
         default:
             DWT.error(DWT.ERROR_INVALID_IMAGE);
             return -1;
@@ -127,7 +137,7 @@
 }
 
 /**
- * Answer an array of Alpha values that correspond to the 
+ * Answer an array of Alpha values that correspond to the
  * colors in the palette.
  * This is only valid for the COLOR_TYPE_PALETTE color type.
  */
@@ -143,7 +153,7 @@
     }
     /**
      * Any palette entries which do not have a corresponding
-     * alpha value in the tRNS chunk are spec'd to have an 
+     * alpha value in the tRNS chunk are spec'd to have an
      * alpha of 255.
      */
     for (int j = i; j < alphas.length; j++) {