changeset 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 965ac0a77267
children 7d135fe0caf2
files dwt/dwthelper/utils.d dwt/events/ArmEvent.d dwt/events/ArmListener.d dwt/events/ControlAdapter.d dwt/events/ControlEvent.d dwt/events/ControlListener.d dwt/events/DisposeEvent.d dwt/events/DisposeListener.d dwt/events/DragDetectEvent.d dwt/events/DragDetectListener.d dwt/events/ExpandAdapter.d dwt/events/ExpandEvent.d dwt/events/ExpandListener.d dwt/events/FocusAdapter.d dwt/events/FocusEvent.d dwt/events/FocusListener.d dwt/events/HelpEvent.d dwt/events/HelpListener.d dwt/events/KeyAdapter.d dwt/events/KeyEvent.d dwt/events/KeyListener.d dwt/events/MenuAdapter.d dwt/events/MenuDetectEvent.d dwt/events/MenuDetectListener.d dwt/events/MenuEvent.d dwt/events/MenuListener.d dwt/events/ModifyEvent.d dwt/events/ModifyListener.d dwt/events/MouseAdapter.d dwt/events/MouseEvent.d dwt/events/MouseListener.d dwt/events/MouseMoveListener.d dwt/events/MouseTrackAdapter.d dwt/events/MouseTrackListener.d dwt/events/MouseWheelListener.d dwt/events/PaintEvent.d dwt/events/PaintListener.d dwt/events/SelectionAdapter.d dwt/events/SelectionEvent.d dwt/events/SelectionListener.d dwt/events/ShellAdapter.d dwt/events/ShellEvent.d dwt/events/ShellListener.d dwt/events/TraverseEvent.d dwt/events/TraverseListener.d dwt/events/TreeAdapter.d dwt/events/TreeEvent.d dwt/events/TreeListener.d dwt/events/TypedEvent.d dwt/events/VerifyEvent.d dwt/events/VerifyListener.d dwt/graphics/Color.d dwt/graphics/FontMetrics.d dwt/graphics/GC.d dwt/graphics/GCData.d dwt/graphics/Path.d dwt/graphics/Region.d dwt/graphics/Transform.d dwt/internal/c/callback.d dwt/internal/c/qd/bindings.d dwt/internal/c/swt.d dwt/internal/cocoa/NSBezierPath.d dwt/internal/cocoa/OS.d dwt/internal/image/FileFormat.d dwt/internal/image/GIFFileFormat.d dwt/internal/image/JPEGAppn.d dwt/internal/image/JPEGArithmeticConditioningTable.d dwt/internal/image/JPEGComment.d dwt/internal/image/JPEGDecoder.d dwt/internal/image/JPEGEndOfImage.d dwt/internal/image/JPEGFileFormat.d dwt/internal/image/JPEGFixedSizeSegment.d dwt/internal/image/JPEGFrameHeader.d dwt/internal/image/JPEGHuffmanTable.d dwt/internal/image/JPEGQuantizationTable.d dwt/internal/image/JPEGRestartInterval.d dwt/internal/image/JPEGScanHeader.d dwt/internal/image/JPEGSegment.d dwt/internal/image/JPEGStartOfImage.d dwt/internal/image/JPEGVariableSizeSegment.d dwt/internal/image/LEDataInputStream.d dwt/internal/image/LEDataOutputStream.d dwt/internal/image/LZWCodec.d dwt/internal/image/LZWNode.d dwt/internal/image/OS2BMPFileFormat.d dwt/internal/image/PNGFileFormat.d dwt/internal/image/PngChunk.d dwt/internal/image/PngChunkReader.d dwt/internal/image/PngDecodingDataStream.d dwt/internal/image/PngDeflater.d dwt/internal/image/PngEncoder.d dwt/internal/image/PngFileReadState.d dwt/internal/image/PngHuffmanTable.d dwt/internal/image/PngHuffmanTables.d dwt/internal/image/PngIdatChunk.d dwt/internal/image/PngIendChunk.d dwt/internal/image/PngIhdrChunk.d dwt/internal/image/PngInputStream.d dwt/internal/image/PngLzBlockReader.d dwt/internal/image/PngPlteChunk.d dwt/internal/image/PngTrnsChunk.d dwt/internal/image/TIFFDirectory.d dwt/internal/image/TIFFFileFormat.d dwt/internal/image/TIFFModifiedHuffmanCodec.d dwt/internal/image/TIFFRandomFileAccess.d dwt/internal/image/WinBMPFileFormat.d dwt/internal/image/WinICOFileFormat.d
diffstat 107 files changed, 3000 insertions(+), 2805 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/dwthelper/utils.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/dwthelper/utils.d	Sun Sep 14 01:45:57 2008 +0200
@@ -600,6 +600,10 @@
     dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = src[ srcBegin .. srcEnd ];
 }
 
+public void getChars( wchar[] src, int srcBegin, int srcEnd, wchar[] dst, int dstBegin){
+    dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = src[ srcBegin .. srcEnd ];
+}
+
 public wchar[] toCharArray( String str ){
     return toString16( str );
 }
--- a/dwt/events/ArmEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ArmEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,22 +7,25 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ArmEvent;
 
-import dwt.dwthelper.utils;
 import dwt.widgets.Event;
+import dwt.events.TypedEvent;
 
 /**
  * Instances of this class are sent as a result of
  * a widget such as a menu item being armed.
  *
  * @see ArmListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class ArmEvent : TypedEvent {
 
-    static final long serialVersionUID = 3258126964249212217L;
+    //static final long serialVersionUID = 3258126964249212217L;
 
 /**
  * Constructs a new instance of this class based on the
--- a/dwt/events/ArmListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ArmListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,20 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ArmListener;
 
-import dwt.dwthelper.utils;
-
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.ArmEvent;
 
 /**
  * Classes which implement this interface provide a method
  * that deals with the event that is generated when a widget,
  * such as a menu item, is armed.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a widget using the
  * <code>addArmListener</code> method and removed using
  * the <code>removeArmListener</code> method. When the
--- a/dwt/events/ControlAdapter.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ControlAdapter.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,12 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ControlAdapter;
 
-import dwt.dwthelper.utils;
-
-
+import dwt.events.ControlListener;
 /**
  * This adapter class provides default implementations for the
  * methods described by the <code>ControlListener</code> interface.
@@ -24,6 +24,7 @@
  *
  * @see ControlListener
  * @see ControlEvent
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class ControlAdapter : ControlListener {
 
--- a/dwt/events/ControlEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ControlEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,24 +7,26 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ControlEvent;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.widgets.Event;
+import dwt.events.TypedEvent;
 
 /**
  * Instances of this class are sent as a result of
  * controls being moved or resized.
  *
  * @see ControlListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class ControlEvent : TypedEvent {
 
-    static final long serialVersionUID = 3258132436155119161L;
+    //static final long serialVersionUID = 3258132436155119161L;
 
 /**
  * Constructs a new instance of this class based on the
--- a/dwt/events/ControlListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ControlListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,20 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ControlListener;
 
-import dwt.dwthelper.utils;
-
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.ControlEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with the events that are generated by moving
- * and resizing controls. 
+ * and resizing controls.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addControlListener</code> method and removed using
  * the <code>removeControlListener</code> method. When a
--- a/dwt/events/DisposeEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/DisposeEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,24 +7,26 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.DisposeEvent;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.widgets.Event;
+import dwt.events.TypedEvent;
 
 /**
  * Instances of this class are sent as a result of
  * widgets being disposed.
  *
  * @see DisposeListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class DisposeEvent : TypedEvent {
 
-    static final long serialVersionUID = 3257566187633521206L;
+    //static final long serialVersionUID = 3257566187633521206L;
 
 /**
  * Constructs a new instance of this class based on the
--- a/dwt/events/DisposeListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/DisposeListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.DisposeListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.DisposeEvent;
 
 /**
  * Classes which implement this interface provide a method
  * that deals with the event that is generated when a widget
  * is disposed.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a widget using the
  * <code>addDisposeListener</code> method and removed using
  * the <code>removeDisposeListener</code> method. When a
--- a/dwt/events/DragDetectEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/DragDetectEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,25 +7,27 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.DragDetectEvent;
 
-import dwt.dwthelper.utils;
-
 import dwt.widgets.Event;
+import dwt.events.MouseEvent;
 
 /**
  * Instances of this class are sent as a result of
  * a drag gesture.
  *
  * @see DragDetectListener
- * 
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
+ *
  * @since 3.3
  */
 
 public final class DragDetectEvent : MouseEvent {
 
-    private static final long serialVersionUID = -7229172519733647232L;
+    //private static final long serialVersionUID = -7229172519733647232L;
 
 /**
  * Constructs a new instance of this class based on the
--- a/dwt/events/DragDetectListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/DragDetectListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.DragDetectListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.DragDetectEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with the events that are generated when a drag
  * gesture is detected.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addDragDetectListener</code> method and removed using
  * the <code>removeDragDetectListener</code> method. When the
@@ -27,7 +29,7 @@
  * </p>
  *
  * @see DragDetectEvent
- * 
+ *
  * @since 3.3
  */
 public interface DragDetectListener : DWTEventListener {
--- a/dwt/events/ExpandAdapter.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ExpandAdapter.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ExpandAdapter;
 
-import dwt.dwthelper.utils;
-
+import dwt.events.ExpandListener;
 
 /**
  * This adapter class provides default implementations for the
@@ -24,7 +25,8 @@
  *
  * @see ExpandListener
  * @see ExpandEvent
- * 
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
+ *
  * @since 3.2
  */
 public abstract class ExpandAdapter : ExpandListener {
--- a/dwt/events/ExpandEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ExpandEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,27 +7,29 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ExpandEvent;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.widgets.Event;
+import dwt.events.SelectionEvent;
 
 /**
  * Instances of this class are sent as a result of
  * <code>ExpandItem</code>s being expanded or collapsed.
  *
  * @see ExpandListener
- * 
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
+ *
  * @since 3.2
  */
 
 public class ExpandEvent : SelectionEvent {
-    
-    static final long serialVersionUID = 3976735856884987356L;
-    
+
+    //static final long serialVersionUID = 3976735856884987356L;
+
 /**
  * Constructs a new instance of this class based on the
  * information in the given untyped event.
--- a/dwt/events/ExpandListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ExpandListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,29 +7,31 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ExpandListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.ExpandEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with the expanding and collapsing of <code>ExpandItem</code>s.
  *
  * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a <code>ExpandBar</code> 
+ * After creating an instance of a class that :
+ * this interface it can be added to a <code>ExpandBar</code>
  * control using the <code>addExpandListener</code> method and
- * removed using the <code>removeExpandListener</code> method. 
+ * removed using the <code>removeExpandListener</code> method.
  * When a item of the <code>ExpandBar</code> is expanded or
  * collapsed, the appropriate method will be invoked.
  * </p>
  *
  * @see ExpandAdapter
  * @see ExpandEvent
- * 
+ *
  * @since 3.2
  */
 public interface ExpandListener : DWTEventListener {
--- a/dwt/events/FocusAdapter.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/FocusAdapter.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.FocusAdapter;
 
-import dwt.dwthelper.utils;
-
+import dwt.events.FocusListener;
 
 /**
  * This adapter class provides default implementations for the
@@ -24,6 +25,7 @@
  *
  * @see FocusListener
  * @see FocusEvent
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class FocusAdapter : FocusListener {
 
--- a/dwt/events/FocusEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/FocusEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,24 +7,26 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.FocusEvent;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.widgets.Event;
+import dwt.events.TypedEvent;
 
 /**
  * Instances of this class are sent as a result of
  * widgets gaining and losing focus.
  *
  * @see FocusListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class FocusEvent : TypedEvent {
 
-    static final long serialVersionUID = 3258134643684227381L;
+    //static final long serialVersionUID = 3258134643684227381L;
 
 /**
  * Constructs a new instance of this class based on the
--- a/dwt/events/FocusListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/FocusListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.FocusListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.FocusEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with the events that are generated as controls
  * gain and lose focus.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addFocusListener</code> method and removed using
  * the <code>removeFocusListener</code> method. When a
--- a/dwt/events/HelpEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/HelpEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,24 +7,26 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.HelpEvent;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.widgets.Event;
+import dwt.events.TypedEvent;
 
 /**
  * Instances of this class are sent as a result of
  * help being requested for a widget.
  *
  * @see HelpListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class HelpEvent : TypedEvent {
 
-    static final long serialVersionUID = 3257001038606251315L;
+    //static final long serialVersionUID = 3257001038606251315L;
 
 /**
  * Constructs a new instance of this class based on the
--- a/dwt/events/HelpListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/HelpListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.HelpListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.HelpEvent;
 
 /**
  * Classes which implement this interface provide a method
  * that deals with the event that is generated when help is
  * requested for a control, typically when the user presses F1.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addHelpListener</code> method and removed using
  * the <code>removeHelpListener</code> method. When help
--- a/dwt/events/KeyAdapter.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/KeyAdapter.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.KeyAdapter;
 
-import dwt.dwthelper.utils;
-
+import dwt.events.KeyListener;
 
 /**
  * This adapter class provides default implementations for the
@@ -24,6 +25,7 @@
  *
  * @see KeyListener
  * @see KeyEvent
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class KeyAdapter : KeyListener {
 
--- a/dwt/events/KeyEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/KeyEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,6 +7,8 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.KeyEvent;
 
@@ -14,6 +16,9 @@
 
 
 import dwt.widgets.Event;
+import dwt.events.TypedEvent;
+
+import tango.text.convert.Format;
 
 /**
  * Instances of this class are sent as a result of
@@ -30,22 +35,24 @@
  * not necessary to add traversal listeners for these controls,
  * unless you want to override the default traversal.
  * </p>
+ *
  * @see KeyListener
  * @see TraverseListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public class KeyEvent : TypedEvent {
-    
+
     /**
-     * the character represented by the key that was typed.  
+     * the character represented by the key that was typed.
      * This is the final character that results after all modifiers have been
      * applied.  For example, when the user types Ctrl+A, the character value
      * is 0x01.  It is important that applications do not attempt to modify the
      * character value based on a stateMask (such as DWT.CTRL) or the resulting
      * character will not be correct.
      */
-    public char character;
-    
+    public wchar character = '\0';
+
     /**
      * the key code of the key that was typed,
      * as defined by the key code constants in class <code>DWT</code>.
@@ -53,20 +60,20 @@
      * contains the unicode value of the original character.  For example,
      * typing Ctrl+M or Return both result in the character '\r' but the
      * keyCode field will also contain '\r' when Return was typed.
-     * 
+     *
      * @see dwt.DWT
      */
     public int keyCode;
-    
+
     /**
      * the state of the keyboard modifier keys at the time
      * the event was generated, as defined by the key code
      * constants in class <code>DWT</code>.
-     * 
+     *
      * @see dwt.DWT
      */
     public int stateMask;
-    
+
     /**
      * A flag indicating whether the operation should be allowed.
      * Setting this field to <code>false</code> will cancel the operation.
@@ -74,7 +81,7 @@
     public bool doit;
 
     static final long serialVersionUID = 3256442491011412789L;
-    
+
 /**
  * Constructs a new instance of this class based on the
  * information in the given untyped event.
@@ -95,13 +102,9 @@
  *
  * @return a string representation of the event
  */
-public String toString() {
-    String string = super.toString ();
-    return string.substring (0, string.length() - 1) // remove trailing '}'
-        + " character='" + ((character is 0) ? "\\0" : "" + character) + "'"
-        + " keyCode=" + keyCode
-        + " stateMask=" + stateMask
-        + " doit=" + doit
-        + "}";
+public override String toString() {
+    return Format( "{} character={} keyCode={} stateMask={} doit={}}",
+        super.toString[ 0 .. $-2 ],
+        character, keyCode, stateMask, doit );
 }
 }
--- a/dwt/events/KeyListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/KeyListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.KeyListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.KeyEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with the events that are generated as keys
  * are pressed on the system keyboard.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addKeyListener</code> method and removed using
  * the <code>removeKeyListener</code> method. When a
--- a/dwt/events/MenuAdapter.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MenuAdapter.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MenuAdapter;
 
-import dwt.dwthelper.utils;
-
+import dwt.events.MenuListener;
 
 /**
  * This adapter class provides default implementations for the
@@ -24,6 +25,7 @@
  *
  * @see MenuListener
  * @see MenuEvent
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class MenuAdapter : MenuListener {
 
--- a/dwt/events/MenuDetectEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MenuDetectEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,6 +7,8 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MenuDetectEvent;
 
@@ -14,12 +16,15 @@
 
 
 import dwt.widgets.Event;
+import dwt.events.TypedEvent;
 
+import tango.text.convert.Format;
 /**
  * Instances of this class are sent whenever the platform-
  * specific trigger for showing a context menu is detected.
  *
  * @see MenuDetectListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  *
  * @since 3.3
  */
@@ -31,20 +36,20 @@
      * at the time the context menu trigger occurred
      */
     public int x;
-    
+
     /**
      * the display-relative y coordinate of the pointer
      * at the time the context menu trigger occurred
-     */ 
+     */
     public int y;
-    
+
     /**
      * A flag indicating whether the operation should be allowed.
      * Setting this field to <code>false</code> will cancel the operation.
      */
     public bool doit;
 
-    private static final long serialVersionUID = -3061660596590828941L;
+    //private static final long serialVersionUID = -3061660596590828941L;
 
 /**
  * Constructs a new instance of this class based on the
@@ -65,12 +70,7 @@
  *
  * @return a string representation of the event
  */
-public String toString() {
-    String string = super.toString ();
-    return string.substring (0, string.length() - 1) // remove trailing '}'
-        + " x=" + x
-        + " y=" + y
-        + " doit=" + doit
-        + "}";
+public override String toString() {
+    return Format( "{} x={} y={} doit={}}", super.toString[ 0 .. $-2 ], x, y, doit );
 }
 }
--- a/dwt/events/MenuDetectListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MenuDetectListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,12 +7,14 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MenuDetectListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.MenuDetectEvent;
 
 /**
  * Classes which implement this interface provide methods
@@ -20,7 +22,7 @@
  * platform-specific trigger for showing a context menu is
  * detected.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control or TrayItem
  * using the <code>addMenuDetectListener</code> method and
  * removed using the <code>removeMenuDetectListener</code> method.
--- a/dwt/events/MenuEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MenuEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,24 +7,26 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MenuEvent;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.widgets.Event;
+import dwt.events.TypedEvent;
 
 /**
  * Instances of this class are sent as a result of
  * menus being shown and hidden.
  *
  * @see MenuListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class MenuEvent : TypedEvent {
 
-    static final long serialVersionUID = 3258132440332383025L;
+    //static final long serialVersionUID = 3258132440332383025L;
 
 /**
  * Constructs a new instance of this class based on the
--- a/dwt/events/MenuListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MenuListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,18 +7,20 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MenuListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.MenuEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with the hiding and showing of menus.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a menu using the
  * <code>addMenuListener</code> method and removed using
  * the <code>removeMenuListener</code> method. When the
--- a/dwt/events/ModifyEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ModifyEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,24 +7,26 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ModifyEvent;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.widgets.Event;
+import dwt.events.TypedEvent;
 
 /**
  * Instances of this class are sent as a result of
  * text being modified.
  *
  * @see ModifyListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class ModifyEvent : TypedEvent {
 
-    static final long serialVersionUID = 3258129146227011891L;
+    //static final long serialVersionUID = 3258129146227011891L;
 
 /**
  * Constructs a new instance of this class based on the
--- a/dwt/events/ModifyListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ModifyListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ModifyListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.ModifyEvent;
 
 /**
  * Classes which implement this interface provide a method
  * that deals with the events that are generated when text
  * is modified.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a text widget using the
  * <code>addModifyListener</code> method and removed using
  * the <code>removeModifyListener</code> method. When the
--- a/dwt/events/MouseAdapter.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MouseAdapter.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,17 +7,18 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MouseAdapter;
 
-import dwt.dwthelper.utils;
-
+import dwt.events.MouseListener;
 
 /**
  * This adapter class provides default implementations for the
  * methods described by the <code>MouseListener</code> interface.
  * <p>
- * Classes that wish to deal with <code>MouseEvent</code>s 
+ * Classes that wish to deal with <code>MouseEvent</code>s
  * which occur as mouse buttons are pressed and released can
  * extend this class and override only the methods which they are
  * interested in.
@@ -25,11 +26,12 @@
  *
  * @see MouseListener
  * @see MouseEvent
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class MouseAdapter : MouseListener {
 
 /**
- * Sent when a mouse button is pressed twice within the 
+ * Sent when a mouse button is pressed twice within the
  * (operating system specified) double click period.
  * The default behavior is to do nothing.
  *
--- a/dwt/events/MouseEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MouseEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,6 +7,8 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MouseEvent;
 
@@ -14,11 +16,14 @@
 
 
 import dwt.widgets.Event;
+import dwt.events.TypedEvent;
+
+import tango.text.convert.Format;
 
 /**
  * Instances of this class are sent whenever mouse
  * related actions occur. This includes mouse buttons
- * being pressed and released, the mouse pointer being 
+ * being pressed and released, the mouse pointer being
  * moved and the mouse pointer crossing widget boundaries.
  * <p>
  * Note: The <code>button</code> field is an integer that
@@ -29,46 +34,47 @@
  * @see MouseListener
  * @see MouseMoveListener
  * @see MouseTrackListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public class MouseEvent : TypedEvent {
-    
+
     /**
      * the button that was pressed or released; 1 for the
      * first button, 2 for the second button, and 3 for the
      * third button, etc.
      */
     public int button;
-    
+
     /**
      * the state of the keyboard modifier keys at the time
      * the event was generated
      */
     public int stateMask;
-    
+
     /**
      * the widget-relative, x coordinate of the pointer
      * at the time the mouse button was pressed or released
      */
     public int x;
-    
+
     /**
      * the widget-relative, y coordinate of the pointer
      * at the time the mouse button was pressed or released
-     */ 
+     */
     public int y;
-    
+
     /**
      * the number times the mouse has been clicked, as defined
      * by the operating system; 1 for the first click, 2 for the
      * second click and so on.
-     * 
+     *
      * @since 3.3
      */
     public int count;
 
-    static final long serialVersionUID = 3257288037011566898L;
-    
+    //static final long serialVersionUID = 3257288037011566898L;
+
 /**
  * Constructs a new instance of this class based on the
  * information in the given untyped event.
@@ -90,14 +96,9 @@
  *
  * @return a string representation of the event
  */
-public String toString() {
-    String string = super.toString ();
-    return string.substring (0, string.length() - 1) // remove trailing '}'
-        + " button=" + button
-        + " stateMask=" + stateMask
-        + " x=" + x
-        + " y=" + y
-        + " count=" + count
-        + "}";
+public override String toString() {
+    return Format( "{} button={} stateMask={} x={} y={} count={}}",
+        super.toString[ 0 .. $-1 ],
+        button, stateMask, x, y, count );
 }
 }
--- a/dwt/events/MouseListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MouseListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MouseListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.MouseEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with the events that are generated as mouse buttons
  * are pressed.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addMouseListener</code> method and removed using
  * the <code>removeMouseListener</code> method. When a
@@ -33,7 +35,7 @@
 public interface MouseListener : DWTEventListener {
 
 /**
- * Sent when a mouse button is pressed twice within the 
+ * Sent when a mouse button is pressed twice within the
  * (operating system specified) double click period.
  *
  * @param e an event containing information about the mouse double click
--- a/dwt/events/MouseMoveListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MouseMoveListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MouseMoveListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.MouseEvent;
 
 /**
  * Classes which implement this interface provide a method
  * that deals with the events that are generated as the mouse
  * pointer moves.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addMouseMoveListener</code> method and removed using
  * the <code>removeMouseMoveListener</code> method. As the
--- a/dwt/events/MouseTrackAdapter.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MouseTrackAdapter.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MouseTrackAdapter;
 
-import dwt.dwthelper.utils;
-
+import dwt.events.MouseTrackListener;
 
 /**
  * This adapter class provides default implementations for the
@@ -25,6 +26,7 @@
  *
  * @see MouseTrackListener
  * @see MouseEvent
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class MouseTrackAdapter : MouseTrackListener {
 
--- a/dwt/events/MouseTrackListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MouseTrackListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MouseTrackListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.MouseEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with the events that are generated as the mouse
  * pointer passes (or hovers) over controls.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addMouseTrackListener</code> method and removed using
  * the <code>removeMouseTrackListener</code> method. When the
--- a/dwt/events/MouseWheelListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/MouseWheelListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.MouseWheelListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.MouseEvent;
 
 /**
  * Classes which implement this interface provide a method
  * that deals with the event that is generated as the mouse
  * wheel is scrolled.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addMouseWheelListener</code> method and removed using
  * the <code>removeMouseWheelListener</code> method. When the
@@ -38,5 +40,5 @@
  *
  * @param e an event containing information about the mouse wheel action
  */
-public void mouseScrolled (MouseEvent e);   
+public void mouseScrolled (MouseEvent e);
 }
--- a/dwt/events/PaintEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/PaintEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,24 +7,31 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.PaintEvent;
 
 import dwt.dwthelper.utils;
 
 
+import dwt.widgets.Event;
 import dwt.graphics.GC;
-import dwt.widgets.Event;
+
+import dwt.events.TypedEvent;
+
+import tango.text.convert.Format;
 
 /**
  * Instances of this class are sent as a result of
  * visible areas of controls requiring re-painting.
  *
  * @see PaintListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class PaintEvent : TypedEvent {
-    
+
     /**
      * the graphics context to use when painting
      * that is configured to use the colors, font and
@@ -32,27 +39,27 @@
      * only during the paint and must not be disposed
      */
     public GC gc;
-    
+
     /**
-     * the x offset of the bounding rectangle of the 
+     * the x offset of the bounding rectangle of the
      * region that requires painting
      */
     public int x;
-    
+
     /**
-     * the y offset of the bounding rectangle of the 
+     * the y offset of the bounding rectangle of the
      * region that requires painting
      */
     public int y;
-    
+
     /**
-     * the width of the bounding rectangle of the 
+     * the width of the bounding rectangle of the
      * region that requires painting
      */
     public int width;
-    
+
     /**
-     * the height of the bounding rectangle of the 
+     * the height of the bounding rectangle of the
      * region that requires painting
      */
     public int height;
@@ -64,8 +71,8 @@
      */
     public int count;
 
-    static final long serialVersionUID = 3256446919205992497L;
-    
+    //static final long serialVersionUID = 3256446919205992497L;
+
 /**
  * Constructs a new instance of this class based on the
  * information in the given untyped event.
@@ -88,16 +95,15 @@
  *
  * @return a string representation of the event
  */
-public String toString() {
-    String string = super.toString ();
-    return string.substring (0, string.length() - 1) // remove trailing '}'
-        + " gc=" + gc
-        + " x=" + x
-        + " y=" + y
-        + " width=" + width
-        + " height=" + height
-        + " count=" + count
-        + "}";
+public override String toString() {
+    return Format( "{} gc={} x={} y={} width={} height={} count={}}",
+        super.toString[ 0 .. $-1 ],
+        gc is null ? "null" : gc.toString,
+        x,
+        y,
+        width,
+        height,
+        count );
 }
 }
 
--- a/dwt/events/PaintListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/PaintListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.PaintListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.PaintEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with the events that are generated when the
- * control needs to be painted. 
+ * control needs to be painted.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addPaintListener</code> method and removed using
  * the <code>removePaintListener</code> method. When a
--- a/dwt/events/SelectionAdapter.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/SelectionAdapter.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.SelectionAdapter;
 
-import dwt.dwthelper.utils;
-
+import dwt.events.SelectionListener;
 
 /**
  * This adapter class provides default implementations for the
@@ -24,6 +25,7 @@
  *
  * @see SelectionListener
  * @see SelectionEvent
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class SelectionAdapter : SelectionListener {
 
--- a/dwt/events/SelectionEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/SelectionEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,6 +7,8 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.SelectionEvent;
 
@@ -15,7 +17,9 @@
 
 import dwt.widgets.Event;
 import dwt.widgets.Widget;
+import dwt.events.TypedEvent;
 
+import tango.text.convert.Format;
 /**
  * Instances of this class are sent as a result of
  * widgets being selected.
@@ -24,18 +28,19 @@
  * </p>
  *
  * @see SelectionListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public class SelectionEvent : TypedEvent {
-    
+
     /**
      * The item that was selected.
      */
     public Widget item;
-    
+
     /**
      * Extra detail information about the selection, depending on the widget.
-     * 
+     *
      * <p><b>Sash</b><ul>
      * <li>{@link dwt.DWT#DRAG}</li>
      * </ul></p><p><b>ScrollBar and Slider</b><ul>
@@ -60,17 +65,17 @@
      * The x location of the selected area.
      */
     public int x;
-    
+
     /**
      * The y location of selected area.
      */
     public int y;
-    
+
     /**
      * The width of selected area.
      */
     public int width;
-    
+
     /**
      * The height of selected area.
      */
@@ -86,21 +91,21 @@
      * The text of the hyperlink that was selected.
      * This will be either the text of the hyperlink or the value of its HREF,
      * if one was specified.
-     * 
+     *
      * @see dwt.widgets.Link#setText(String)
      * @since 3.1
      */
     public String text;
-    
+
     /**
      * A flag indicating whether the operation should be allowed.
      * Setting this field to <code>false</code> will cancel the
      * operation, depending on the widget.
      */
     public bool doit;
-    
-    static final long serialVersionUID = 3976735856884987953L;
-    
+
+    //static final long serialVersionUID = 3976735856884987953L;
+
 /**
  * Constructs a new instance of this class based on the
  * information in the given untyped event.
@@ -126,19 +131,18 @@
  *
  * @return a string representation of the event
  */
-public String toString() {
-    String string = super.toString ();
-    return string.substring (0, string.length() - 1) // remove trailing '}'
-        + " item=" + item
-        + " detail=" + detail
-        + " x=" + x
-        + " y=" + y
-        + " width=" + width
-        + " height=" + height
-        + " stateMask=" + stateMask
-        + " text=" + text
-        + " doit=" + doit
-        + "}";
+public override String toString() {
+    return Format( "{} item={} detail={} x={} y={} width={} height={} stateMask={} text={} doit={}}",
+        super.toString[ 0 .. $-2 ],
+        item,
+        detail,
+        x,
+        y,
+        width,
+        height,
+        stateMask,
+        text,
+        doit );
 }
 }
 
--- a/dwt/events/SelectionListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/SelectionListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.SelectionListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.SelectionEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with the events that are generated when selection
  * occurs in a control.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addSelectionListener</code> method and removed using
  * the <code>removeSelectionListener</code> method. When
--- a/dwt/events/ShellAdapter.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ShellAdapter.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ShellAdapter;
 
-import dwt.dwthelper.utils;
-
+import dwt.events.ShellListener;
 
 /**
  * This adapter class provides default implementations for the
@@ -24,6 +25,7 @@
  *
  * @see ShellListener
  * @see ShellEvent
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class ShellAdapter : ShellListener {
 
@@ -72,3 +74,51 @@
 public void shellIconified(ShellEvent e) {
 }
 }
+
+class ShellDelegator : ShellAdapter {
+    alias void delegate(ShellEvent) DFunc;
+    DFunc delShellActivated;
+    DFunc delShellClosed;
+    DFunc delShellDeactivated;
+    DFunc delShellDeiconified;
+    DFunc delShellIconified;
+
+private this(
+    DFunc delShellActivated,
+    DFunc delShellClosed,
+    DFunc delShellDeactivated,
+    DFunc delShellDeiconified,
+    DFunc delShellIconified )
+{
+    this.delShellActivated = delShellActivated;
+    this.delShellClosed = delShellClosed;
+    this.delShellDeactivated = delShellDeactivated;
+    this.delShellDeiconified = delShellDeiconified;
+    this.delShellIconified = delShellIconified;
+}
+
+static ShellDelegator createShellActivated( DFunc del ){
+    return new ShellDelegator( del, null, null, null, null );
+}
+static ShellDelegator createShellClosed( DFunc del ){
+    return new ShellDelegator( null, del, null, null, null );
+}
+
+public void shellActivated(ShellEvent e) {
+    if( delShellActivated !is null ) delShellActivated(e);
+}
+public void shellClosed(ShellEvent e) {
+    if( delShellClosed !is null ) delShellClosed(e);
+}
+public void shellDeactivated(ShellEvent e) {
+    if( delShellDeactivated !is null ) delShellDeactivated(e);
+}
+public void shellDeiconified(ShellEvent e) {
+    if( delShellDeiconified !is null ) delShellDeiconified(e);
+}
+public void shellIconified(ShellEvent e) {
+    if( delShellIconified !is null ) delShellIconified(e);
+}
+}
+
+
--- a/dwt/events/ShellEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ShellEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,6 +7,8 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ShellEvent;
 
@@ -14,12 +16,16 @@
 
 
 import dwt.widgets.Event;
+import dwt.events.TypedEvent;
+
+import tango.text.convert.Format;
 
 /**
  * Instances of this class are sent as a result of
  * operations being performed on shells.
  *
  * @see ShellListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class ShellEvent : TypedEvent {
@@ -29,9 +35,9 @@
      * Setting this field to <code>false</code> will cancel the operation.
      */
     public bool doit;
-    
-    static final long serialVersionUID = 3257569490479888441L;
-    
+
+    //static final long serialVersionUID = 3257569490479888441L;
+
 /**
  * Constructs a new instance of this class based on the
  * information in the given untyped event.
@@ -49,11 +55,8 @@
  *
  * @return a string representation of the event
  */
-public String toString() {
-    String string = super.toString ();
-    return string.substring (0, string.length() - 1) // remove trailing '}'
-        + " doit=" + doit
-        + "}";
+public override String toString() {
+    return Format( "{} doit={}}", super.toString[ 0 .. $-2 ], doit );
 }
 }
 
--- a/dwt/events/ShellListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/ShellListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,18 +7,20 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.ShellListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.ShellEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with changes in state of <code>Shell</code>s.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a shell using the
  * <code>addShellListener</code> method and removed using
  * the <code>removeShellListener</code> method. When the
--- a/dwt/events/TraverseEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/TraverseEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,6 +7,8 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.TraverseEvent;
 
@@ -14,7 +16,9 @@
 
 
 import dwt.widgets.Event;
+import dwt.events.KeyEvent;
 
+import tango.text.convert.Format;
 /**
  * Instances of this class are sent as a result of
  * widget traversal actions.
@@ -75,12 +79,13 @@
  * Note: A widget implementor will typically implement traversal using
  * only the doit flag to either enable or disable system traversal.
  * </p>
- * 
+ *
  * @see TraverseListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class TraverseEvent : KeyEvent {
-    
+
     /**
      * The traversal type.
      * <p><ul>
@@ -95,11 +100,11 @@
      * <li>{@link dwt.DWT#TRAVERSE_PAGE_NEXT}</li>
      * <li>{@link dwt.DWT#TRAVERSE_PAGE_PREVIOUS}</li>
      * </ul></p>
-     * 
+     *
      * Setting this field will change the type of traversal.
      * For example, setting the detail to <code>TRAVERSE_NONE</code>
      * causes no traversal action to be taken.
-     * 
+     *
      * When used in conjunction with the <code>doit</code> field, the
      * traversal detail field can be useful when overriding the default
      * traversal mechanism for a control. For example, setting the doit
@@ -109,9 +114,9 @@
      * described by the detail field is to be performed.
      */
     public int detail;
-    
-    static final long serialVersionUID = 3257565105301239349L;
-    
+
+    //static final long serialVersionUID = 3257565105301239349L;
+
 /**
  * Constructs a new instance of this class based on the
  * information in the given untyped event.
@@ -129,10 +134,7 @@
  *
  * @return a string representation of the event
  */
-public String toString() {
-    String string = super.toString ();
-    return string.substring (0, string.length() - 1) // remove trailing '}'
-        + " detail=" + detail
-        + "}";
+public override String toString() {
+    return Format( "{} detail={}}", super.toString[ 0 .. $-2 ], detail );
 }
 }
--- a/dwt/events/TraverseListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/TraverseListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.TraverseListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.TraverseEvent;
 
 /**
  * Classes which implement this interface provide a method
  * that deals with the events that are generated when a
  * traverse event occurs in a control.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a control using the
  * <code>addTraverseListener</code> method and removed using
  * the <code>removeTraverseListener</code> method. When a
--- a/dwt/events/TreeAdapter.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/TreeAdapter.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.TreeAdapter;
 
-import dwt.dwthelper.utils;
-
+import dwt.events.TreeListener;
 
 /**
  * This adapter class provides default implementations for the
@@ -24,6 +25,7 @@
  *
  * @see TreeListener
  * @see TreeEvent
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class TreeAdapter : TreeListener {
 
--- a/dwt/events/TreeEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/TreeEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,24 +7,26 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.TreeEvent;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.widgets.Event;
+import dwt.events.SelectionEvent;
 
 /**
  * Instances of this class are sent as a result of
  * trees being expanded and collapsed.
  *
  * @see TreeListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class TreeEvent : SelectionEvent {
 
-    static final long serialVersionUID = 3257282548009677109L;
+    //static final long serialVersionUID = 3257282548009677109L;
 
 /**
  * Constructs a new instance of this class based on the
--- a/dwt/events/TreeListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/TreeListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2005 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.TreeListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.TreeEvent;
 
 /**
  * Classes which implement this interface provide methods
  * that deal with the expanding and collapsing of tree
  * branches.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a tree control using the
  * <code>addTreeListener</code> method and removed using
  * the <code>removeTreeListener</code> method. When a branch
--- a/dwt/events/TypedEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/TypedEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,16 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.TypedEvent;
 
 import dwt.dwthelper.utils;
 
 
-import dwt.internal.DWTEventObject;
+import dwt.widgets.Event;
 import dwt.widgets.Display;
-import dwt.widgets.Event;
 import dwt.widgets.Widget;
+import dwt.internal.DWTEventObject;
+
+import tango.text.convert.Format;
+import tango.text.Util : split;
 
 /**
  * This is the super class for all typed event classes provided
@@ -24,37 +29,38 @@
  * applicable to the event occurrence.
  *
  * @see dwt.widgets.Event
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public class TypedEvent : DWTEventObject {
-    
+
     /**
      * the display where the event occurred
-     * 
-     * @since 2.0 
-     */ 
+     *
+     * @since 2.0
+     */
     public Display display;
-        
+
     /**
      * the widget that issued the event
      */
     public Widget widget;
-    
+
     /**
      * the time that the event occurred.
-     * 
+     *
      * NOTE: This field is an unsigned integer and should
      * be AND'ed with 0xFFFFFFFFL so that it can be treated
      * as a signed long.
-     */ 
+     */
     public int time;
-    
+
     /**
      * a field for application use
      */
     public Object data;
 
-    static final long serialVersionUID = 3257285846578377524L;
-    
+    //static final long serialVersionUID = 3257285846578377524L;
+
 /**
  * Constructs a new instance of this class.
  *
@@ -80,15 +86,13 @@
 
 /**
  * Returns the name of the event. This is the name of
- * the class without the package name.
+ * the class without the module name.
  *
  * @return the name of the event
  */
 String getName () {
-    String string = getClass ().getName ();
-    int index = string.lastIndexOf ('.');
-    if (index is -1) return string;
-    return string.substring (index + 1, string.length ());
+    String str = this.classinfo.name;
+    return split( str, "." )[$-1];
 }
 
 /**
@@ -97,11 +101,9 @@
  *
  * @return a string representation of the event
  */
-public String toString() {
-    return getName ()
-        + "{" + widget
-        + " time=" + time
-        + " data=" + data
-        + "}";
+public override String toString() {
+    String str_widget = widget is null ? "null" : widget.toString;
+    String str_data   = data is null ? "null" : data.toString;
+    return Format( "{}{{time={} data={}}", str_widget, time, str_data );
 }
 }
--- a/dwt/events/VerifyEvent.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/VerifyEvent.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,6 +7,8 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.VerifyEvent;
 
@@ -14,22 +16,25 @@
 
 
 import dwt.widgets.Event;
+import dwt.events.KeyEvent;
 
+import tango.text.convert.Format;
 /**
  * Instances of this class are sent as a result of
  * widgets handling keyboard events
  *
  * @see VerifyListener
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 
 public final class VerifyEvent : KeyEvent {
-    
+
     /**
      * the range of text being modified.
      * Setting these fields has no effect.
      */
     public int start, end;
-    
+
     /**
      * the new text that will be inserted.
      * Setting this field will change the text that is about to
@@ -37,8 +42,8 @@
      */
     public String text;
 
-    static final long serialVersionUID = 3257003246269577014L;
-    
+    //static final long serialVersionUID = 3257003246269577014L;
+
 /**
  * Constructs a new instance of this class based on the
  * information in the given untyped event.
@@ -58,12 +63,7 @@
  *
  * @return a string representation of the event
  */
-public String toString() {
-    String string = super.toString ();
-    return string.substring (0, string.length() - 1) // remove trailing '}'
-        + " start=" + start
-        + " end=" + end
-        + " text=" + text
-        + "}";
+public override String toString() {
+    return Format( "{} start={} end={} text={}}", super.toString[ 0 .. $-2 ], start, end, text );
 }
 }
--- a/dwt/events/VerifyListener.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/events/VerifyListener.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,21 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.events.VerifyListener;
 
-import dwt.dwthelper.utils;
 
-import dwt.internal.DWTEventListener;
+public import dwt.internal.DWTEventListener;
+public import dwt.events.VerifyEvent;
 
 /**
  * Classes which implement this interface provide a method
  * that deals with the events that are generated when text
  * is about to be modified.
  * <p>
- * After creating an instance of a class that implements
+ * After creating an instance of a class that :
  * this interface it can be added to a text control using the
  * <code>addVerifyListener</code> method and removed using
  * the <code>removeVerifyListener</code> method. When the
--- a/dwt/graphics/Color.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/graphics/Color.d	Sun Sep 14 01:45:57 2008 +0200
@@ -21,6 +21,7 @@
 import dwt.graphics.Device;
 import dwt.graphics.Resource;
 import dwt.graphics.RGB;
+import dwt.internal.cocoa.CGFloat;
 
 /**
  * Instances of this class manage the operating system resources that
@@ -47,7 +48,7 @@
      * platforms and should never be accessed from application code.
      * </p>
      */
-    public float[] handle;
+    public CGFloat[] handle;
 
 this(Device device) {
     super(device);
--- a/dwt/graphics/FontMetrics.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/graphics/FontMetrics.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,6 +7,9 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.FontMetrics;
 
@@ -48,7 +51,7 @@
  *
  * @see #hashCode
  */
-public bool equals (Object object) {
+public int opEquals (Object object) {
     if (object is this) return true;
     if (!( null !is cast(FontMetrics)object )) return false;
     FontMetrics metrics = cast(FontMetrics)object;
@@ -57,6 +60,8 @@
         height is metrics.height;
 }
 
+alias opEquals equals;
+
 /**
  * Returns the ascent of the font described by the receiver. A
  * font's <em>ascent</em> is the distance from the baseline to the 
@@ -127,8 +132,10 @@
  *
  * @see #equals
  */
-public int hashCode() {
+public hash_t toHash() {
     return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
 }
 
+alias toHash hashCode;
+
 }
--- a/dwt/graphics/GC.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/graphics/GC.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,10 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.GC;
 
-import dwt.dwthelper.utils;
 
 import dwt.DWT;
 import dwt.DWTError;
@@ -31,6 +33,29 @@
 import dwt.internal.cocoa.NSString;
 import dwt.internal.cocoa.OS;
 
+import tango.text.convert.Format;
+
+import dwt.dwthelper.utils;
+import dwt.graphics.Color;
+import dwt.graphics.Device;
+import dwt.graphics.Drawable;
+import dwt.graphics.Font;
+import dwt.graphics.FontMetrics;
+import dwt.graphics.GCData;
+import dwt.graphics.Image;
+import dwt.graphics.ImageData;
+import dwt.graphics.LineAttributes;
+import dwt.graphics.Path;
+import dwt.graphics.Pattern;
+import dwt.graphics.Point;
+import dwt.graphics.Rectangle;
+import dwt.graphics.Region;
+import dwt.graphics.Resource;
+import dwt.graphics.RGB;
+import dwt.graphics.Transform;
+import dwt.internal.cocoa.CGFloat;
+import objc = dwt.internal.objc.runtime;
+
 /**
  * Class <code>GC</code> is where all of the drawing capabilities that are 
  * supported by DWT are located. Instances are used to draw on either an 
@@ -76,31 +101,31 @@
     Drawable drawable;
     GCData data;
 
-    static final int TAB_COUNT = 32;
+    static const int TAB_COUNT = 32;
 
-    final static int FOREGROUND = 1 << 0;
-    final static int BACKGROUND = 1 << 1;
-    final static int FONT = 1 << 2;
-    final static int LINE_STYLE = 1 << 3;
-    final static int LINE_CAP = 1 << 4;
-    final static int LINE_JOIN = 1 << 5;
-    final static int LINE_WIDTH = 1 << 6;
-    final static int LINE_MITERLIMIT = 1 << 7;
-    final static int FOREGROUND_FILL = 1 << 8;
-    final static int DRAW_OFFSET = 1 << 9;
-    final static int CLIPPING = 1 << 10;
-    final static int TRANSFORM = 1 << 11;
-    final static int DRAW = CLIPPING | TRANSFORM | FOREGROUND | LINE_WIDTH | LINE_STYLE  | LINE_CAP  | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET;
-    final static int FILL = CLIPPING | TRANSFORM | BACKGROUND;
+    const static int FOREGROUND = 1 << 0;
+    const static int BACKGROUND = 1 << 1;
+    const static int FONT = 1 << 2;
+    const static int LINE_STYLE = 1 << 3;
+    const static int LINE_CAP = 1 << 4;
+    const static int LINE_JOIN = 1 << 5;
+    const static int LINE_WIDTH = 1 << 6;
+    const static int LINE_MITERLIMIT = 1 << 7;
+    const static int FOREGROUND_FILL = 1 << 8;
+    const static int DRAW_OFFSET = 1 << 9;
+    const static int CLIPPING = 1 << 10;
+    const static int TRANSFORM = 1 << 11;
+    const static int DRAW = CLIPPING | TRANSFORM | FOREGROUND | LINE_WIDTH | LINE_STYLE  | LINE_CAP  | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET;
+    const static int FILL = CLIPPING | TRANSFORM | BACKGROUND;
 
-    static final float[] LINE_DOT = new float[]{1, 1};
-    static final float[] LINE_DASH = new float[]{3, 1};
-    static final float[] LINE_DASHDOT = new float[]{3, 1, 1, 1};
-    static final float[] LINE_DASHDOTDOT = new float[]{3, 1, 1, 1, 1, 1};
-    static final float[] LINE_DOT_ZERO = new float[]{3, 3};
-    static final float[] LINE_DASH_ZERO = new float[]{18, 6};
-    static final float[] LINE_DASHDOT_ZERO = new float[]{9, 6, 3, 6};
-    static final float[] LINE_DASHDOTDOT_ZERO = new float[]{9, 3, 3, 3, 3, 3};
+    static const CGFloat[] LINE_DOT = new CGFloat[][1, 1];
+    static const CGFloat[] LINE_DASH = new CGFloat[][3, 1];
+    static const CGFloat[] LINE_DASHDOT = new CGFloat[][3, 1, 1, 1];
+    static const CGFloat[] LINE_DASHDOTDOT = new CGFloat[][3, 1, 1, 1, 1, 1];
+    static const CGFloat[] LINE_DOT_ZERO = new CGFloat[][3, 3];
+    static const CGFloat[] LINE_DASH_ZERO = new CGFloat[][18, 6];
+    static const CGFloat[] LINE_DASHDOT_ZERO = new CGFloat[][9, 6, 3, 6];
+    static const CGFloat[] LINE_DASHDOTDOT_ZERO = new CGFloat[][9, 3, 3, 3, 3, 3];
 
 this() {
 }
@@ -162,7 +187,7 @@
     if (drawable is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     GCData data = new GCData();
     data.style = checkStyle(style);
-    int contextId = drawable.internal_new_GC(data);
+    size_t contextId = drawable.internal_new_GC(data);
     Device device = data.device;
     if (device is null) device = Device.getDevice();
     if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
@@ -195,7 +220,7 @@
  */
 public static GC cocoa_new(Drawable drawable, GCData data) {
     GC gc = new GC();
-    int context = drawable.internal_new_GC(data);
+    size_t context = drawable.internal_new_GC(data);
     gc.device = data.device;
     gc.init(drawable, data, context);
     return gc;
@@ -244,7 +269,7 @@
         if (pattern !is null) {
             if (pattern.color !is null) pattern.color.setStroke();
         } else {
-            float[] color = data.foreground;
+            CGFloat[] color = data.foreground;
             NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setStroke();
         }
     }
@@ -253,7 +278,7 @@
         if (pattern !is null) {
             if (pattern.color !is null) pattern.color.setFill();
         } else {
-            float[] color = data.foreground;
+            CGFloat[] color = data.foreground;
             NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setFill();
         }
         data.state &= ~BACKGROUND;
@@ -263,14 +288,14 @@
         if (pattern !is null) {
             if (pattern.color !is null) pattern.color.setFill();
         } else {
-            float[] color = data.background;
+            CGFloat[] color = data.background;
             NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setFill();
         }
         data.state &= ~FOREGROUND_FILL;
     }
     NSBezierPath path = data.path;
     if ((state & LINE_WIDTH) !is 0) {
-        path.setLineWidth(data.lineWidth is 0 ?  1 : data.lineWidth);
+        path.setLineWidth((data.lineWidth is 0 ?  1 : data.lineWidth));
         switch (data.lineStyle) {
             case DWT.LINE_DOT:
             case DWT.LINE_DASH:
@@ -280,8 +305,8 @@
         }
     }
     if ((state & LINE_STYLE) !is 0) {
-        float[] dashes = null;
-        float width = data.lineWidth;
+        CGFloat[] dashes = null;
+        CGFloat width = data.lineWidth;
         switch (data.lineStyle) {
             case DWT.LINE_SOLID: break;
             case DWT.LINE_DASH: dashes = width !is 0 ? LINE_DASH : LINE_DASH_ZERO; break;
@@ -291,11 +316,11 @@
             case DWT.LINE_CUSTOM: dashes = data.lineDashes; break;
         }
         if (dashes !is null) {
-            float[] lengths = new float[dashes.length];
+            CGFloat[] lengths = new CGFloat[dashes.length];
             for (int i = 0; i < lengths.length; i++) {
                 lengths[i] = width is 0 || data.lineStyle is DWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width;
             }
-            path.setLineDash(lengths, lengths.length, data.lineDashesOffset);
+            path.setLineDash(lengths.ptr, lengths.length, data.lineDashesOffset);
         } else {
             path.setLineDash(null, 0, 0);
         }
@@ -310,7 +335,7 @@
             case DWT.JOIN_ROUND: joinStyle = OS.NSRoundLineJoinStyle; break;
             case DWT.JOIN_BEVEL: joinStyle = OS.NSBevelLineJoinStyle; break;
         }
-        path.setLineJoinStyle(joinStyle);
+        path.setLineJoinStyle(cast(objc.id_) joinStyle);
     }
     if ((state & LINE_CAP) !is 0) {
         int capStyle = 0;
@@ -319,25 +344,25 @@
             case DWT.CAP_FLAT: capStyle = OS.NSButtLineCapStyle; break;
             case DWT.CAP_SQUARE: capStyle = OS.NSSquareLineCapStyle; break;
         }
-        path.setLineCapStyle(capStyle);
+        path.setLineCapStyle(cast(objc.id_) capStyle);
     }
     if ((state & DRAW_OFFSET) !is 0) {
         data.drawXOffset = data.drawYOffset = 0;
-        NSSize size = new NSSize();
+        NSSize size = NSSize();
         size.width = size.height = 1;
         if (data.transform !is null) {
             size = data.transform.transformSize(size);
         }
-        float scaling = size.width;
+        CGFloat scaling = size.width;
         if (scaling < 0) scaling = -scaling;
-        float strokeWidth = data.lineWidth * scaling;
-        if (strokeWidth is 0 || (cast(int)strokeWidth % 2) is 1) {
+        CGFloat strokeWidth = data.lineWidth * scaling;
+        if (strokeWidth is 0 || (cast(size_t)strokeWidth % 2) is 1) {
             data.drawXOffset = 0.5f / scaling;
         }
         scaling = size.height;
         if (scaling < 0) scaling = -scaling;
         strokeWidth = data.lineWidth * scaling;
-        if (strokeWidth is 0 || (cast(int)strokeWidth % 2) is 1) {
+        if (strokeWidth is 0 || (cast(size_t)strokeWidth % 2) is 1) {
             data.drawYOffset = 0.5f / scaling;
         }
     }
@@ -615,16 +640,16 @@
 
 NSAttributedString createString(String string, int flags) {
     NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4);
-    float[] foreground = data.foreground;
+    CGFloat[] foreground = data.foreground;
     NSColor color = NSColor.colorWithDeviceRed(foreground[0], foreground[1], foreground[2], data.alpha / 255f);
     dict.setObject(color, OS.NSForegroundColorAttributeName());
     dict.setObject(data.font.handle, OS.NSFontAttributeName());
     if ((flags & DWT.DRAW_TRANSPARENT) is 0) {
-        float[] background = data.background;
+        CGFloat[] background = data.background;
         color = NSColor.colorWithDeviceRed(background[0], background[1], background[2], data.alpha / 255f);
         dict.setObject(color, OS.NSBackgroundColorAttributeName());
     }
-    int length = string.length();
+    size_t length = string.length();
     char[] chars = new char[length];
     string.getChars(0, length, chars, 0);
 //  int breakCount = 0;
@@ -662,8 +687,8 @@
 //      }
 //      length = j;
 //  }
-    NSString str = NSString.stringWithCharacters(chars, length);
-    return (cast(NSAttributedString)new NSAttributedString().alloc()).initWithString_attributes_(str, dict);
+    NSString str = NSString.stringWithCharacters(chars.toCharArray().ptr, length);
+    return (cast(NSAttributedString)(new NSAttributedString()).alloc()).initWithString_attributes_(str, dict);
 }
 
 void destroy() {
@@ -680,7 +705,7 @@
     data.transform = data.inverseTransform = null;
     
     /* Dispose the GC */
-    if (drawable !is null) drawable.internal_dispose_GC(handle.id, data);
+    if (drawable !is null) drawable.internal_dispose_GC(handle.id_, data);
     handle.restoreGraphicsState();
     handle.release();
 
@@ -735,13 +760,13 @@
     if (width is 0 || height is 0 || arcAngle is 0) return;
     handle.saveGraphicsState();
     NSAffineTransform transform = NSAffineTransform.transform();
-    float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
+    CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset;
     transform.translateXBy(x + xOffset + width / 2f, y + yOffset + height / 2f);
     transform.scaleXBy(width / 2f, height / 2f);
     NSBezierPath path = data.path;
-    NSPoint center = new NSPoint();
-    float sAngle = -startAngle;
-    float eAngle = -(startAngle + arcAngle);
+    NSPoint center = NSPoint();
+    CGFloat sAngle = -startAngle;
+    CGFloat eAngle = -(startAngle + arcAngle);
     path.appendBezierPathWithArcWithCenter_radius_startAngle_endAngle_clockwise_(center, 1, sAngle,  eAngle, arcAngle>0);
     path.transformUsingAffineTransform(transform);
     path.stroke();
@@ -879,12 +904,12 @@
     transform.scaleXBy(1, -1);
     transform.translateXBy(0, -(destHeight + 2 * destY));
     transform.concat();
-    NSRect srcRect = new NSRect();
+    NSRect srcRect = NSRect();
     srcRect.x = srcX;
     srcRect.y = srcY;
     srcRect.width = srcWidth;
     srcRect.height = srcHeight;
-    NSRect destRect = new NSRect();
+    NSRect destRect = NSRect();
     destRect.x = destX;
     destRect.y = destY;
     destRect.width = destWidth;
@@ -913,7 +938,7 @@
     NSGraphicsContext.setCurrentContext(handle);
     checkGC(DRAW);
     NSBezierPath path = data.path;
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = x1 + data.drawXOffset;
     pt.y = y1 + data.drawYOffset;
     path.moveToPoint(pt);
@@ -960,7 +985,7 @@
         height = -height;
     }
     NSBezierPath path = data.path;
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x + data.drawXOffset;
     rect.y = y + data.drawXOffset;
     rect.width = width;
@@ -1035,7 +1060,7 @@
     NSGraphicsContext context = NSGraphicsContext.currentContext();
     NSGraphicsContext.setCurrentContext(handle);
     checkGC(FOREGROUND_FILL);
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x;
     rect.y = y;
     rect.width = 1;
@@ -1071,9 +1096,9 @@
     NSGraphicsContext.setCurrentContext(handle);
     checkGC(DRAW);
     if (pointArray.length < 4) return;
-    float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
+    CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset;
     NSBezierPath path = data.path;
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = pointArray[0] + xOffset;
     pt.y = pointArray[1] + yOffset;
     path.moveToPoint(pt);
@@ -1113,9 +1138,9 @@
     NSGraphicsContext.setCurrentContext(handle);
     checkGC(DRAW);
     if (pointArray.length < 4) return;
-    float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
+    CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset;
     NSBezierPath path = data.path;
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = pointArray[0] + xOffset;
     pt.y = pointArray[1] + yOffset;
     path.moveToPoint(pt);
@@ -1158,7 +1183,7 @@
         y = y + height;
         height = -height;
     }
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x + data.drawXOffset;
     rect.y = y + data.drawYOffset;
     rect.width = width;
@@ -1224,7 +1249,7 @@
         return;
     }
     NSBezierPath path = data.path;
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x + data.drawXOffset;
     rect.y = y + data.drawYOffset;
     rect.width = width;
@@ -1377,7 +1402,7 @@
         transform.translateXBy(0, -(str.size().height + 2 * y));
         transform.concat();
     }
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = x;
     pt.y = y;
     str.drawAtPoint(pt);
@@ -1398,12 +1423,14 @@
  *
  * @see #hashCode
  */
-public bool equals(Object object) {
+public bool opEquals(Object object) {
     if (object is this) return true;
     if (!( null !is cast(GC)object )) return false;
     return handle is (cast(GC)object).handle;
 }
 
+alias opEquals equals;
+
 /**
  * Fills the interior of a circular or elliptical arc within
  * the specified rectangular area, with the receiver's background
@@ -1452,14 +1479,14 @@
     if (width is 0 || height is 0 || arcAngle is 0) return;
     handle.saveGraphicsState();
     NSAffineTransform transform = NSAffineTransform.transform();
-    float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
+    CGFloat xOffset = data.drawXOffset, yOffset = data.drawYOffset;
     transform.translateXBy(x + xOffset + width / 2f, y + yOffset + height / 2f);
     transform.scaleXBy(width / 2f, height / 2f);
     NSBezierPath path = data.path;
-    NSPoint center = new NSPoint();
+    NSPoint center = NSPoint();
     path.moveToPoint(center);
-    float sAngle = -startAngle;
-    float eAngle = -(startAngle + arcAngle);
+    CGFloat sAngle = -startAngle;
+    CGFloat eAngle = -(startAngle + arcAngle);
     path.appendBezierPathWithArcWithCenter_radius_startAngle_endAngle_clockwise_(center, 1, sAngle,  eAngle, arcAngle>0);
     path.closePath();
     path.transformUsingAffineTransform(transform);
@@ -1521,8 +1548,8 @@
     } else {
         NSColor startingColor = NSColor.colorWithDeviceRed(fromRGB.red / 255f, fromRGB.green / 255f, fromRGB.blue / 255f, data.alpha / 255f);
         NSColor endingColor = NSColor.colorWithDeviceRed(toRGB.red / 255f, toRGB.green / 255f, toRGB.blue / 255f, data.alpha / 255f);
-        NSGradient gradient = (cast(NSGradient)new NSGradient().alloc()).initWithStartingColor(startingColor, endingColor);
-        NSRect rect = new NSRect();
+        NSGradient gradient = (cast(NSGradient)(new NSGradient()).alloc()).initWithStartingColor(startingColor, endingColor);
+        NSRect rect = NSRect();
         rect.x = x;
         rect.y = y;
         rect.width = width;
@@ -1563,7 +1590,7 @@
         height = -height;
     }
     NSBezierPath path = data.path;
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x;
     rect.y = y;
     rect.width = width;
@@ -1656,7 +1683,7 @@
     checkGC(FILL);
     if (pointArray.length < 4) return;
     NSBezierPath path = data.path;
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = pointArray[0];
     pt.y = pointArray[1];
     path.moveToPoint(pt);
@@ -1705,7 +1732,7 @@
         y = y + height;
         height = -height;
     }
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x;
     rect.y = y;
     rect.width = width;
@@ -1770,7 +1797,7 @@
         return;
     }
     NSBezierPath path = data.path;
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x;
     rect.y = y;
     rect.width = width;
@@ -1807,7 +1834,7 @@
 public int getAdvanceWidth(char ch) {   
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     //NOT DONE
-    return stringExtent(new String(new char[]{ch})).x;
+    return stringExtent(new char[][ch]).x;
 }
 
 /** 
@@ -1929,7 +1956,7 @@
 public int getCharWidth(char ch) {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     //NOT DONE
-    return stringExtent(new String(new char[]{ch})).x;
+    return stringExtent(new char[][ch]).x;
 }
 
 /** 
@@ -1946,11 +1973,11 @@
  */
 public Rectangle getClipping() {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSRect rect = null;
+    NSRect rect = void;
     if (data.view !is null) {
         rect = data.view.bounds();
     } else {
-        rect = new NSRect();
+        rect = NSRect();
         if (data.image !is null) {
             NSSize size = data.image.handle.size();
             rect.width = size.width;
@@ -1969,10 +1996,10 @@
             OS.NSIntersectionRect(rect, rect, clip);
         }
         if (data.inverseTransform !is null && rect.width > 0 && rect.height > 0) {
-            NSPoint pt = new NSPoint();
+            NSPoint pt = NSPoint();
             pt.x = rect.x;
             pt.y = rect.y;
-            NSSize size = new NSSize();
+            NSSize size = NSSize();
             size.width = rect.width;
             size.height = rect.height;
             pt = data.inverseTransform.transformPoint(pt);
@@ -2005,11 +2032,11 @@
     if (region is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     region.subtract(region);
-    NSRect rect = null;
+    NSRect rect = void;
     if (data.view !is null) {
         rect = data.view.bounds();
     } else {
-        rect = new NSRect();
+        rect = NSRect();
         if (data.image !is null) {
             NSSize size = data.image.handle.size();
             rect.width = size.width;
@@ -2030,11 +2057,11 @@
         int pointCount = 0;
         Region clipRgn = new Region(device);
         int[] pointArray = new int[count * 2];
-        int points = OS.malloc(NSPoint.sizeof);
-        if (points is 0) DWT.error(DWT.ERROR_NO_HANDLES);
-        NSPoint pt = new NSPoint();
-        for (int i = 0; i < count; i++) {
-            int element = clip.elementAtIndex_associatedPoints_(i, points);
+        NSPointArray points = cast(NSPointArray) OS.malloc(NSPoint.sizeof);
+        if (points is null) DWT.error(DWT.ERROR_NO_HANDLES);
+        NSPoint pt = NSPoint();
+        for (NSInteger  i = 0; i < count; i++) {
+            NSBezierPathElement element = clip.elementAtIndex_associatedPoints_(i, points);
             switch (element) {
                 case OS.NSMoveToBezierPathElement:
                     if (pointCount !is 0) clipRgn.add(pointArray, pointCount);
@@ -2214,9 +2241,9 @@
  */
 public LineAttributes getLineAttributes() {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    float[] dashes = null;
+    CGFloat[] dashes = null;
     if (data.lineDashes !is null) {
-        dashes = new float[data.lineDashes.length];
+        dashes = new CGFloat[data.lineDashes.length];
         System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length);
     }
     return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit);
@@ -2382,8 +2409,8 @@
     if (transform.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     NSAffineTransform cmt = data.transform;
     if (cmt !is null) {
-        NSAffineTransformStruct struct = cmt.transformStruct();
-        transform.handle.setTransformStruct(struct);
+        NSAffineTransformStruct structt = cmt.transformStruct();
+        transform.handle.setTransformStruct(structt);
     } else {
         transform.setElements(1, 0, 0, 1, 0, 0);
     }
@@ -2422,11 +2449,13 @@
  *
  * @see #equals
  */
-public int hashCode() {
-    return handle !is null ? handle.id : 0;
+public hash_t toHash() {
+    return handle !is null ? handle.id_ : 0;
 }
 
-void init(Drawable drawable, GCData data, int context) {
+alias toHash hashCode;
+
+void init(Drawable drawable, GCData data, objc.id context) {
     if (data.foreground !is null) data.state &= ~(FOREGROUND | FOREGROUND_FILL);
     if (data.background !is null)  data.state &= ~BACKGROUND;
     if (data.font !is null) data.state &= ~FONT;
@@ -2690,7 +2719,7 @@
         y = y + height;
         height = -height;
     }
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x;
     rect.y = y;
     rect.width = width;
@@ -2729,7 +2758,7 @@
 public void setClipping(Path path) {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (path !is null && path.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    setClipping(new NSBezierPath(path.handle.copy().id));
+    setClipping(new NSBezierPath(path.handle.copy().id_));
 }
 
 /**
@@ -2815,7 +2844,7 @@
             DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     }
     data.fillRule = rule;
-    data.path.setWindingRule(rule is DWT.FILL_WINDING ? OS.NSNonZeroWindingRule : OS.NSEvenOddWindingRule);
+    data.path.setWindingRule(rule is DWT.FILL_WINDING ? cast(objc.id) OS.NSNonZeroWindingRule : cast(objc.id) OS.NSEvenOddWindingRule);
 }
 
 /** 
@@ -2922,7 +2951,7 @@
  */
 public void setInterpolation(int interpolation) {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    int quality = 0;
+    NSImageInterpolation quality = 0;
     switch (interpolation) {
         case DWT.DEFAULT: quality = OS.NSImageInterpolationDefault; break;
         case DWT.NONE: quality = OS.NSImageInterpolationNone; break;
@@ -2962,7 +2991,7 @@
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (attributes is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     int mask = 0;
-    float lineWidth = attributes.width;
+    CGFloat lineWidth = attributes.width;
     if (lineWidth !is data.lineWidth) {
         mask |= LINE_WIDTH | DRAW_OFFSET;
     }
@@ -3007,8 +3036,8 @@
                 DWT.error(DWT.ERROR_INVALID_ARGUMENT);
         }
     }
-    float[] dashes = attributes.dash;
-    float[] lineDashes = data.lineDashes;
+    CGFloat[] dashes = attributes.dash;
+    CGFloat[] lineDashes = data.lineDashes;
     if (dashes !is null && dashes.length > 0) {
         bool changed = lineDashes is null || lineDashes.length !is dashes.length;
         for (int i = 0; i < dashes.length; i++) {
@@ -3017,7 +3046,7 @@
             if (!changed && lineDashes[i] !is dash) changed = true;
         }
         if (changed) {
-            float[] newDashes = new float[dashes.length];
+            CGFloat[] newDashes = new CGFloat[dashes.length];
             System.arraycopy(dashes, 0, newDashes, 0, dashes.length);
             dashes = newDashes;
             mask |= LINE_STYLE;
@@ -3031,7 +3060,7 @@
             dashes = lineDashes;
         }
     }
-    float dashOffset = attributes.dashOffset;
+    CGFloat dashOffset = attributes.dashOffset;
     if (dashOffset !is data.lineDashesOffset) {
         mask |= LINE_STYLE;     
     }
@@ -3100,7 +3129,7 @@
  */
 public void setLineDash(int[] dashes) {
     if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    float[] lineDashes = data.lineDashes;
+    CGFloat[] lineDashes = data.lineDashes;
     if (dashes !is null && dashes.length > 0) {
         bool changed = data.lineStyle !is DWT.LINE_CUSTOM || lineDashes is null || lineDashes.length !is dashes.length;
         for (int i = 0; i < dashes.length; i++) {
@@ -3109,7 +3138,7 @@
             if (!changed && lineDashes[i] !is dash) changed = true;
         }
         if (!changed) return;
-        data.lineDashes = new float[dashes.length];
+        data.lineDashes = new CGFloat[dashes.length];
         for (int i = 0; i < dashes.length; i++) {
             data.lineDashes[i] = dashes[i];
         }
@@ -3312,10 +3341,10 @@
     if (transform !is null) {
         if (data.transform !is null) data.transform.release();
         if (data.inverseTransform !is null) data.inverseTransform.release();
-        data.transform = (cast(NSAffineTransform)new NSAffineTransform().alloc()).initWithTransform(transform.handle);
-        data.inverseTransform = (cast(NSAffineTransform)new NSAffineTransform().alloc()).initWithTransform(transform.handle);
-        NSAffineTransformStruct struct = data.inverseTransform.transformStruct();
-        if ((struct.m11 * struct.m22 - struct.m12 * struct.m21) !is 0) {
+        data.transform = (cast(NSAffineTransform)(new NSAffineTransform()).alloc()).initWithTransform(transform.handle);
+        data.inverseTransform = (cast(NSAffineTransform)(new NSAffineTransform()).alloc()).initWithTransform(transform.handle);
+        NSAffineTransformStruct structt = data.inverseTransform.transformStruct();
+        if ((structt.m11 * structt.m22 - structt.m12 * structt.m21) !is 0) {
             data.inverseTransform.invert();
         }
     } else {
@@ -3418,7 +3447,7 @@
  */
 public String toString () {
     if (isDisposed()) return "GC {*DISPOSED*}";
-    return "GC {" + handle + "}";
+    return Format("GC {{}{}" , handle , "}");
 }
 
 }
--- a/dwt/graphics/GCData.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/graphics/GCData.d	Sun Sep 14 01:45:57 2008 +0200
@@ -26,6 +26,7 @@
 import dwt.graphics.Pattern;
 import dwt.graphics.Image;
 import dwt.graphics.Font;
+import dwt.internal.cocoa.CGFloat;
 
 /**
  * Instances of this class are descriptions of GCs in terms
@@ -40,19 +41,19 @@
 public final class GCData {
     public Device device;
     public int style, state = -1;
-    public float[] foreground;
-    public float[] background;
+    public CGFloat[] foreground;
+    public CGFloat[] background;
     public Pattern foregroundPattern;
     public Pattern backgroundPattern;
     public Font font;
     public int alpha = 0xFF;
-    public float lineWidth;
+    public CGFloat lineWidth;
     public int lineStyle = DWT.LINE_SOLID;
     public int lineCap = DWT.CAP_FLAT;
     public int lineJoin = DWT.JOIN_MITER;
-    public float lineDashesOffset;
-    public float[] lineDashes;
-    public float lineMiterLimit = 10;
+    public CGFloat lineDashesOffset;
+    public CGFloat[] lineDashes;
+    public CGFloat lineMiterLimit = 10;
     public bool xorMode;
     public int antialias = DWT.DEFAULT;
     public int textAntialias = DWT.DEFAULT;
@@ -61,7 +62,7 @@
 
     public Image image;
     
-    public float drawXOffset, drawYOffset;
+    public CGFloat drawXOffset, drawYOffset;
     public NSRect paintRect;
     public NSBezierPath path;
     public NSAffineTransform transform, inverseTransform;
--- a/dwt/graphics/Path.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/graphics/Path.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,10 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.Path;
 
-import dwt.dwthelper.utils;
 
 import dwt.DWT;
 import dwt.DWTError;
@@ -27,6 +29,18 @@
 import dwt.internal.cocoa.NSTextStorage;
 import dwt.internal.cocoa.OS;
 
+import tango.text.convert.Format;
+
+import dwt.dwthelper.utils;
+import dwt.graphics.Device;
+import dwt.graphics.Font;
+import dwt.graphics.GC;
+import dwt.graphics.GCData;
+import dwt.graphics.PathData;
+import dwt.graphics.Resource;
+import dwt.internal.cocoa.CGFloat;
+import dwt.internal.cocoa.NSFont : NSGlyph;
+
 /**
  * Instances of this class represent paths through the two-dimensional
  * coordinate system. Paths do not have to be continuous, and can be
@@ -85,7 +99,7 @@
     handle = NSBezierPath.bezierPath();
     if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
     handle.retain();
-    handle.moveToPoint(new NSPoint());
+    handle.moveToPoint(NSPoint());
     init();
 }
 
@@ -95,9 +109,9 @@
     if (path.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
     flatness = Math.max(0, flatness);
     if (flatness is 0) {
-        handle = new NSBezierPath(path.handle.copy().id);
+        handle = new NSBezierPath(path.handle.copy().id_);
     } else {
-        float defaultFlatness = NSBezierPath.defaultFlatness();
+        CGFloat defaultFlatness = NSBezierPath.defaultFlatness();
         NSBezierPath.setDefaultFlatness(flatness);
         handle = path.handle.bezierPathByFlatteningPath();
         NSBezierPath.setDefaultFlatness(defaultFlatness);       
@@ -147,9 +161,9 @@
     transform.translateXBy(x + width / 2f, y + height / 2f);
     transform.scaleXBy(width / 2f, height / 2f);
     NSBezierPath path = NSBezierPath.bezierPath();
-    NSPoint center = new NSPoint();
-    float sAngle = -startAngle;
-    float eAngle = -(startAngle + arcAngle);
+    NSPoint center = NSPoint();
+    CGFloat sAngle = -startAngle;
+    CGFloat eAngle = -(startAngle + arcAngle);
     path.appendBezierPathWithArcWithCenter_radius_startAngle_endAngle_clockwise_(center, 1, sAngle,  eAngle, arcAngle>0);
     path.transformUsingAffineTransform(transform);
     handle.appendBezierPath(path);
@@ -189,7 +203,7 @@
  */
 public void addRectangle(float x, float y, float width, float height) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSRect rect = new NSRect();
+    NSRect rect = NSRect();
     rect.x = x;
     rect.y = y;
     rect.width = width;
@@ -201,7 +215,7 @@
  * Adds to the receiver the pattern of glyphs generated by drawing
  * the given string using the given font starting at the point (x, y).
  *
- * @param string the text to use
+ * @param stri the text to use
  * @param x the x coordinate of the starting point
  * @param y the y coordinate of the starting point
  * @param font the font to use
@@ -214,32 +228,32 @@
  *    <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
  * </ul>
  */
-public void addString(String string, float x, float y, Font font) {
+public void addString(String stri, float x, float y, Font font) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (font is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (font.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    NSString str = NSString.stringWith(string);
-    NSTextStorage textStorage = (cast(NSTextStorage)new NSTextStorage().alloc());
+    NSString str = NSString.stringWith(stri);
+    NSTextStorage textStorage = (cast(NSTextStorage)(new NSTextStorage()).alloc());
     textStorage.initWithString_(str);
-    NSLayoutManager layoutManager = cast(NSLayoutManager)new NSLayoutManager().alloc().init();
-    NSTextContainer textContainer = cast(NSTextContainer)new NSTextContainer().alloc();
-    NSSize size = new NSSize();
-    size.width = Float.MAX_VALUE;
-    size.height = Float.MAX_VALUE;
+    NSLayoutManager layoutManager = cast(NSLayoutManager)(new NSLayoutManager()).alloc().init();
+    NSTextContainer textContainer = cast(NSTextContainer)(new NSTextContainer()).alloc();
+    NSSize size = NSSize();
+    size.width = CGFloat.max; //Float.MAX_VALUE;
+    size.height = CGFloat.max; //Float.MAX_VALUE;
     textContainer.initWithContainerSize(size);
     textStorage.addLayoutManager(layoutManager);
     layoutManager.addTextContainer(textContainer);
-    NSRange range = new NSRange();
+    NSRange range = NSRange();
     range.length = str.length();
     textStorage.beginEditing();
     textStorage.addAttribute(OS.NSFontAttributeName(), font.handle, range);
     textStorage.endEditing();
     range = layoutManager.glyphRangeForTextContainer(textContainer);
     if (range.length !is 0) {
-        int glyphs = OS.malloc(4 * range.length * 2);
+        NSGlyph* glyphs = OS.malloc(4 * range.length * 2);
         layoutManager.getGlyphs(glyphs, range);
         NSBezierPath path = NSBezierPath.bezierPath();
-        NSPoint point = new NSPoint();
+        NSPoint point = NSPoint();
         point.x = x;
         point.y = y;
         path.moveToPoint(point);
@@ -299,7 +313,7 @@
     if (gc.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
 //  gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH);
     //TODO outline
-    NSPoint point = new NSPoint();
+    NSPoint point = NSPoint();
     point.x = x;
     point.y = y;
     return handle.containsPoint(point);
@@ -321,13 +335,13 @@
  */
 public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = x;
     pt.y = y;
-    NSPoint ct1 = new NSPoint();
+    NSPoint ct1 = NSPoint();
     ct1.x = cx1;
     ct1.y = cy1;
-    NSPoint ct2 = new NSPoint();
+    NSPoint ct2 = NSPoint();
     ct2.x = cx2;
     ct2.y = cy2;
     handle.curveToPoint(pt, ct1, ct2);
@@ -404,11 +418,11 @@
     int pointCount = 0, typeCount = 0;
     byte[] types = new byte[count];
     float[] pointArray = new float[count * 6];
-    int points = OS.malloc(3 * NSPoint.sizeof);
+    NSPointArray points = OS.malloc(3 * NSPoint.sizeof);
     if (points is 0) DWT.error(DWT.ERROR_NO_HANDLES);
-    NSPoint pt = new NSPoint();
-    for (int i = 0; i < count; i++) {
-        int element = handle.elementAtIndex_associatedPoints_(i, points);
+    NSPoint pt = NSPoint();
+    for (NSInteger i = 0; i < count; i++) {
+        NSBezierPathElement  element = handle.elementAtIndex_associatedPoints_(i, points);
         switch (element) {
             case OS.NSMoveToBezierPathElement:
                 types[typeCount++] = DWT.PATH_MOVE_TO;
@@ -505,7 +519,7 @@
  */
 public void lineTo(float x, float y) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = x;
     pt.y = y;
     handle.lineToPoint(pt);
@@ -525,7 +539,7 @@
  */
 public void moveTo(float x, float y) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = x;
     pt.y = y;
     handle.moveToPoint(pt);
@@ -546,10 +560,10 @@
  */
 public void quadTo(float cx, float cy, float x, float y) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSPoint pt = new NSPoint();
+    NSPoint pt = NSPoint();
     pt.x = x;
     pt.y = y;
-    NSPoint ct = new NSPoint();
+    NSPoint ct = NSPoint();
     ct.x = cx;
     ct.y = cy;
     handle.curveToPoint(pt, ct, ct);
@@ -563,7 +577,7 @@
  */
 public String toString () {
     if (isDisposed()) return "Path {*DISPOSED*}";
-    return "Path {" + handle + "}";
+    return Format("Path {{}{}" , handle , "}");
 }
 
 }
--- a/dwt/graphics/Region.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/graphics/Region.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,22 +7,32 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.Region;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.DWT;
 import dwt.DWTError;
 import dwt.DWTException;
-import dwt.internal.Callback;
 import dwt.internal.cocoa.NSAffineTransform;
 import dwt.internal.cocoa.NSBezierPath;
 import dwt.internal.cocoa.NSPoint;
 import dwt.internal.cocoa.NSRect;
 import dwt.internal.cocoa.OS;
 
+import tango.text.convert.Format;
+
+import dwt.dwthelper.utils;
+import dwt.graphics.Device;
+import dwt.graphics.Point;
+import dwt.graphics.Rectangle;
+import dwt.graphics.Resource;
+import dwt.internal.c.qd.Quickdraw;
+import dwt.internal.c.qd.QuickdrawTypes;
+
 /**
  * Instances of this class represent areas of an x-y coordinate
  * system that are aggregates of the areas covered by a number
@@ -44,7 +54,7 @@
      * platforms and should never be accessed from application code.
      * </p>
      */
-    public int handle;
+    public RgnHandle handle;
 
 /**
  * Constructs a new empty region.
@@ -79,11 +89,11 @@
 public this(Device device) {
     super(device);
     handle = OS.NewRgn();
-    if (handle is 0) DWT.error(DWT.ERROR_NO_HANDLES);
+    if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
     init();
 }
 
-this(Device device, int handle) {
+this(Device device, RgnHandle handle) {
     super(device);
     this.handle = handle;
 }
@@ -112,7 +122,7 @@
     
 void add(int[] pointArray, int count) {
     if (count <= 2) return;
-    int polyRgn = OS.NewRgn();
+    RgnHandle polyRgn = OS.NewRgn();
     OS.OpenRgn();
     OS.MoveTo(cast(short)pointArray[0], cast(short)pointArray[1]);
     for (int i = 1; i < count / 2; i++) {
@@ -166,10 +176,10 @@
 public void add(int x, int y, int width, int height) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    int rectRgn = OS.NewRgn();
-    short[] r = new short[4];
-    OS.SetRect(r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
-    OS.RectRgn(rectRgn, r);
+    RgnHandle rectRgn = OS.NewRgn();
+    Rect r;
+    OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
+    OS.RectRgn(rectRgn, &r);
     OS.UnionRgn(handle, rectRgn, handle);
     OS.DisposeRgn(rectRgn);
 }
@@ -211,7 +221,7 @@
  */
 public bool contains(int x, int y) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    short[] point = new short[]{cast(short)x, cast(short)y};
+    Point point = Point(cast(short)x, cast(short)y);
     return OS.PtInRgn(point, handle);
 }
 
@@ -237,40 +247,37 @@
 
 NSAffineTransform transform;
 void convertRgn(NSAffineTransform transform) {
-    int newRgn = OS.NewRgn();
-    Callback callback = new Callback(this, "convertRgn", 4);
-    int proc = callback.getAddress();
-    if (proc is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS);
+    RgnHandle newRgn = OS.NewRgn();
+    RegionToRectsUPP proc = &convertRgn;
     this.transform = transform;
     OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, proc, newRgn);
     this.transform = null;
-    callback.dispose();
     OS.CopyRgn(newRgn, handle);
     OS.DisposeRgn(newRgn);
 }
 
-int convertRgn(int message, int rgn, int r, int newRgn) {
+extern(C) private static OSStatus* convertRgn(ushort message, RgnHandle rgn, Rect* r, void* newRgn) {
     if (message is OS.kQDRegionToRectsMsgParse) {
-        short[] rect = new short[4];
-        OS.memmove(rect, r, rect.length * 2);
-        NSPoint point = new NSPoint(); 
-        int polyRgn = OS.NewRgn();
+        Rect rect;
+        OS.memmove(&rect, r, rect.sizeof);
+        NSPoint point = NSPoint(); 
+        RgnHandle polyRgn = OS.NewRgn();
         OS.OpenRgn();
-        point.x = rect[1];
-        point.y = rect[0];
+        point.x = rect.left;
+        point.y = rect.top;
         point = transform.transformPoint(point);
         short startX, startY;
         OS.MoveTo(startX = cast(short)point.x, startY = cast(short)point.y);
-        point.x = rect[3];
-        point.y = rect[0];
+        point.x = rect.right;
+        point.y = rect.top;
         point = transform.transformPoint(point);
         OS.LineTo(cast(short)Math.round(point.x), cast(short)point.y);
-        point.x = rect[3];
-        point.y = rect[2];
+        point.x = rect.right;
+        point.y = rect.bottom;
         point = transform.transformPoint(point);
         OS.LineTo(cast(short)Math.round(point.x), cast(short)Math.round(point.y));
-        point.x = rect[1];
-        point.y = rect[2];
+        point.x = rect.left;
+        point.y = rect.bottom;
         point = transform.transformPoint(point);
         OS.LineTo(cast(short)point.x, cast(short)Math.round(point.y));
         OS.LineTo(startX, startY);
@@ -278,7 +285,7 @@
         OS.UnionRgn(newRgn, polyRgn, newRgn);
         OS.DisposeRgn(polyRgn);
     }
-    return 0;
+    return null;
 }
 
 void destroy() {
@@ -296,13 +303,15 @@
  *
  * @see #hashCode
  */
-public bool equals(Object object) {
+public int opEquals(Object object) {
     if (this is object) return true;
     if (!( null !is cast(Region)object )) return false;
     Region region = cast(Region)object;
     return handle is region.handle;
 }
 
+alias opEquals equals;
+
 /**
  * Returns a rectangle which represents the rectangular
  * union of the collection of polygons the receiver
@@ -318,45 +327,42 @@
  */
 public Rectangle getBounds() {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    short[] bounds = new short[4];
-    OS.GetRegionBounds(handle, bounds);
-    int width = bounds[3] - bounds[1];
-    int height = bounds[2] - bounds[0];
-    return new Rectangle(bounds[1], bounds[0], width, height);
+    Rect bounds;
+    OS.GetRegionBounds(handle, &bounds);
+    int width = bounds.right - bounds.left;
+    int height = bounds.bottom - bounds.left;
+    return new Rectangle(bounds.left, bounds.top, width, height);
 }
 
 NSBezierPath getPath() {
-    Callback callback = new Callback(this, "regionToRects", 4);
-    if (callback.getAddress() is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS);
     NSBezierPath path = NSBezierPath.bezierPath();
     path.retain();
-    OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, callback.getAddress(), path.id);
-    callback.dispose();
-    if (path.isEmpty()) path.appendBezierPathWithRect(new NSRect());
+    OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, &regionToRects, path.id_);
+    if (path.isEmpty()) path.appendBezierPathWithRect(NSRect());
     return path;
 }
 
-NSPoint pt = new NSPoint();
-short[] rect = new short[4];
-int regionToRects(int message, int rgn, int r, int path) {
+NSPoint pt = NSPoint();
+Rect rect;
+extern(C) private static OSStatus* regionToRects(ushort message, RgnHandle rgn, Rect* r, void* path) {
     if (message is OS.kQDRegionToRectsMsgParse) {
-        OS.memmove(rect, r, rect.length * 2);
-        pt.x = rect[1];
-        pt.y = rect[0];
+        OS.memmove(rect, r, rect.sizeof);
+        pt.x = rect.left;
+        pt.y = rect.top;
         OS.objc_msgSend(path, OS.sel_moveToPoint_1, pt);
-        pt.x = rect[3];
+        pt.x = rect.right;
         OS.objc_msgSend(path, OS.sel_lineToPoint_1, pt);
-        pt.x = rect[3];
-        pt.y = rect[2];
+        pt.x = rect.right;
+        pt.y = rect.bottom;
         OS.objc_msgSend(path, OS.sel_lineToPoint_1, pt);
-        pt.x = rect[1];
+        pt.x = rect.left;
         OS.objc_msgSend(path, OS.sel_lineToPoint_1, pt);
         OS.objc_msgSend(path, OS.sel_closePath);
     }
-    return 0;
+    return null;
 }
 
-public static Region carbon_new(Device device, int handle) {
+public static Region carbon_new(Device device, RgnHandle handle) {
     return new Region(device, handle);
 }
 
@@ -370,10 +376,12 @@
  *
  * @see #equals
  */
-public int hashCode() {
+public hash_t toHash() {
     return handle;
 }
 
+alias toHash hashCode;
+
 /**
  * Intersects the given rectangle to the collection of polygons
  * the receiver maintains to describe its area.
@@ -417,10 +425,10 @@
 public void intersect(int x, int y, int width, int height) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    int rectRgn = OS.NewRgn();
-    short[] r = new short[4];
-    OS.SetRect(r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
-    OS.RectRgn(rectRgn, r);
+    RgnHandle rectRgn = OS.NewRgn();
+    Rect r;
+    OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
+    OS.RectRgn(rectRgn, &r);
     OS.SectRgn(handle, rectRgn, handle);
     OS.DisposeRgn(rectRgn);
 }
@@ -468,9 +476,9 @@
  */
 public bool intersects (int x, int y, int width, int height) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    short[] r = new short[4];
-    OS.SetRect(r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
-    return OS.RectInRgn(rect, handle);
+    Rect r;
+    OS.SetRect(&r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
+    return OS.RectInRgn(&rect, handle);
 }
 
 /**
@@ -506,7 +514,7 @@
  * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
  */
 public bool isDisposed() {
-    return handle is 0;
+    return handle is null;
 }
 
 /**
@@ -544,7 +552,7 @@
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (pointArray.length < 2) return;
-    int polyRgn = OS.NewRgn();
+    RgnHandle polyRgn = OS.NewRgn();
     OS.OpenRgn();
     OS.MoveTo(cast(short)pointArray[0], cast(short)pointArray[1]);
     for (int i = 1; i < pointArray.length / 2; i++) {
@@ -599,10 +607,10 @@
 public void subtract(int x, int y, int width, int height) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (width < 0 || height < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    int rectRgn = OS.NewRgn();
-    short[] r = new short[4];
+    RgnHandle rectRgn = OS.NewRgn();
+    Rect r;
     OS.SetRect(r, cast(short)x, cast(short)y, cast(short)(x + width),cast(short)(y + height));
-    OS.RectRgn(rectRgn, r);
+    OS.RectRgn(rectRgn, &r);
     OS.DiffRgn(handle, rectRgn, handle);
     OS.DisposeRgn(rectRgn);
 }
@@ -678,6 +686,6 @@
  */
 public String toString () {
     if (isDisposed()) return "Region {*DISPOSED*}";
-    return "Region {" + handle + "}";
+    return Format("Region {{}{}" , handle , "}");
 }
 }
--- a/dwt/graphics/Transform.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/graphics/Transform.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.graphics.Transform;
 
-import dwt.dwthelper.utils;
-
 import dwt.DWT;
 import dwt.DWTError;
 import dwt.DWTException;
@@ -19,6 +20,12 @@
 import dwt.internal.cocoa.NSAffineTransformStruct;
 import dwt.internal.cocoa.NSPoint;
 
+import tango.text.convert.Format;
+
+import dwt.dwthelper.utils;
+import dwt.graphics.Device;
+import dwt.graphics.Resource;
+
 /**
  * Instances of this class represent transformation matrices for 
  * points expressed as (x, y) pairs of floating point numbers.
@@ -169,21 +176,21 @@
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (elements is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
     if (elements.length < 6) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
-    NSAffineTransformStruct struct = handle.transformStruct();
-    elements[0] = struct.m11;
-    elements[1] = struct.m12;
-    elements[2] = struct.m21;
-    elements[3] = struct.m22;
-    elements[4] = struct.tX;
-    elements[5] = struct.tY;
+    NSAffineTransformStruct structt = handle.transformStruct();
+    elements[0] = structt.m11;
+    elements[1] = structt.m12;
+    elements[2] = structt.m21;
+    elements[3] = structt.m22;
+    elements[4] = structt.tX;
+    elements[5] = structt.tY;
 }
 
 public void identity() {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSAffineTransformStruct struct = new NSAffineTransformStruct();
-    struct.m11 = 1;
-    struct.m22 = 1;
-    handle.setTransformStruct(struct);
+    NSAffineTransformStruct structt = NSAffineTransformStruct();
+    structt.m11 = 1;
+    structt.m22 = 1;
+    handle.setTransformStruct(structt);
 }
 
 /**
@@ -197,8 +204,8 @@
  */
 public void invert() {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSAffineTransformStruct struct = handle.transformStruct();
-    if ((struct.m11 * struct.m22 - struct.m12 * struct.m21) is 0) {
+    NSAffineTransformStruct structt = handle.transformStruct();
+    if ((structt.m11 * structt.m22 - structt.m12 * structt.m21) is 0) {
         DWT.error(DWT.ERROR_CANNOT_INVERT_MATRIX);
     }
     handle.invert();
@@ -226,8 +233,8 @@
  */
 public bool isIdentity() {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSAffineTransformStruct struct = handle.transformStruct();
-    return struct.m11 is 1 && struct.m12 is 0 && struct.m21 is 0 && struct.m22 is 1 && struct.tX is 0 && struct.tY is 0;
+    NSAffineTransformStruct structt = handle.transformStruct();
+    return structt.m11 is 1 && structt.m12 is 0 && structt.m21 is 0 && structt.m22 is 1 && structt.tX is 0 && structt.tY is 0;
 }
 
 /**
@@ -303,25 +310,25 @@
  */
 public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSAffineTransformStruct struct = new NSAffineTransformStruct();
-    struct.m11 = m11;
-    struct.m12 = m12;
-    struct.m21 = m21;
-    struct.m22 = m22;
-    struct.tX = dx;
-    struct.tY = dy;
-    handle.setTransformStruct(struct);
+    NSAffineTransformStruct structt = NSAffineTransformStruct();
+    structt.m11 = m11;
+    structt.m12 = m12;
+    structt.m21 = m21;
+    structt.m22 = m22;
+    structt.tX = dx;
+    structt.tY = dy;
+    handle.setTransformStruct(structt);
 }
 
 public void shear(float shearX, float shearY) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    NSAffineTransformStruct struct = new NSAffineTransformStruct();
-    struct.m11 = 1;
-    struct.m12 = shearX;
-    struct.m21 = shearY;
-    struct.m22 = 1;
+    NSAffineTransformStruct structt = NSAffineTransformStruct();
+    structt.m11 = 1;
+    structt.m12 = shearX;
+    structt.m21 = shearY;
+    structt.m22 = 1;
     NSAffineTransform matrix = NSAffineTransform.transform();
-    matrix.setTransformStruct(struct);
+    matrix.setTransformStruct(structt);
     handle.prependTransform(matrix);
 }
 
@@ -342,8 +349,8 @@
 public void transform(float[] pointArray) {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
     if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
-    NSPoint point = new NSPoint();
-    int length = pointArray.length / 2;
+    NSPoint point = NSPoint();
+    size_t length = pointArray.length / 2;
     for (int i = 0, j = 0; i < length; i++, j += 2) {
         point.x = pointArray[j];
         point.y = pointArray[j + 1];
@@ -379,7 +386,7 @@
     if (isDisposed()) return "Transform {*DISPOSED*}";
     float[] elements = new float[6];
     getElements(elements);
-    return "Transform {" + elements [0] + ", " + elements [1] + ", " +elements [2] + ", " +elements [3] + ", " +elements [4] + ", " +elements [5] + "}";
+    return Format("Transform {{}{}{}{}{}{}{}{}{}{}{}{}" , elements [0] , ", " , elements [1] , ", " ,elements [2] , ", " ,elements [3] , ", " ,elements [4] , ", " ,elements [5] , "}");
 }
 
 }
--- a/dwt/internal/c/callback.d	Fri Sep 12 13:53:21 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,321 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     IBM Corporation - initial API and implementation
- *     
- * Port to the D programming language:
- *     Jacob Carlborg <jacob.carlborg@gmail.com>
- *******************************************************************************/
-module dwt.internal.c.callback;
-
-/**
- * Callback implementation.
- */
-
-import tango.stdc.string;
-import tango.stdc.posix.sys.mman;
-
-import dwt.dwthelper.utils;
-import dwt.internal.Callback;
-
-/* Header */
-
-const bool REDUCED_CALLBACKS = false;
-alias size_t SWT_PTR;
-
-version (Win32)
-{
-    import tango.sys.win32.UserGdi;
-    import tango.sys.win32.Types;
-    
-    alias LRESULT RETURN_TYPE;
-}
-
-else version (Win32_WCE)
-{
-    import tango.sys.win32.UserGdi;
-    import tango.sys.win32.Types;
-    
-    alias LRESULT RETURN_TYPE;
-}
-
-else
-    alias SWT_PTR RETURN_TYPE;
-
-version (X86)
-    const bool USE_ASSEMBLER = true;
-
-else
-    const bool USE_ASSEMBLER = true;
-
-static if (REDUCED_CALLBACKS)
-    const int MAX_CALLBACKS = 16;
-
-else static if (USE_ASSEMBLER)
-    const int MAX_CALLBACKS = 256;
-
-else
-    const int MAX_CALLBACKS = 128;    
-
-const int MAX_ARGS = 12;
-
-struct CALLBACK_DATA 
-{
-    Callback callback;
-    jmethodID methodID;
-    Object object;
-    bool isStatic;
-    bool isArrayBased; 
-    int argCount;
-    SWT_PTR errorResult;
-}
-
-/* Implementation */
-
-
-/* --------------- callback globals ----------------- */
-
-private
-{
-    CALLBACK_DATA callbackData[MAX_CALLBACKS];
-    int callbackEnabled = 1;
-    int callbackEntryCount = 0;
-    bool initialized = 0;
-    
-    debug
-        int counter = 0;
-}
-
-static if (USE_ASSEMBLER)
-{
-    version (Win32){}
-    else version (Win32_WCE){}
-    else
-        import tango.stdc.posix.sys.mman;
-
-    private ubyte* callbackCode = null;
-    const int CALLBACK_THUNK_SIZE = 64;
-}
-
-SWT_PTR bind (Callback callbackObject, Object object, String method, String signature, int argCount, bool isStatic, bool isArrayBased, SWT_PTR errorResult)
-{
-    int i;
-    jmethodID mid = null;
-    jclass javaClass = that;
-    string methodString = null;
-    string sigString = null;
-
-    if (!initialized)
-    {
-        memset(&callbackData, 0, callbackData.sizeof);
-        initialized = true;
-    }
-    
-    if (method)
-        methodString = method;
-    
-    if (signature)
-        sigString = signature;
-    
-    if (object && methodString && sigString)
-    {
-        if (isStatic)
-        {
-            mid = (*env).GetStaticMethodID(env, object, methodString, sigString);
-        }
-        else
-        {
-            javaClass = (*env).GetObjectClass(env, object);
-            mid = (*env).GetMethodID(env, javaClass, methodString, sigString);
-        }
-    }
-    
-    if (mid == 0)
-        goto fail;
-    
-    for (i = 0; i < MAX_CALLBACKS; i++)
-    {
-        if (!callbackData[i].callback)
-        {
-            if ((callbackData[i].callback = callbackObject) == null)
-                goto fail;
-            
-            if ((callbackData[i].object = object) == null)
-                goto fail;
-            
-            callbackData[i].isStatic = isStatic;
-            callbackData[i].isArrayBased = isArrayBased;
-            callbackData[i].argCount = argCount;
-            callbackData[i].errorResult = errorResult;
-            callbackData[i].methodID = mid;
-
-            static if (!USE_ASSEMBLER)
-                return cast(SWT_PTR) fnx_array[argCount][i];
-            
-            else
-            {
-                int j = 0, k, pad = 0;
-                ubyte* code;
-                
-                if (callbackCode == null)
-                {
-                    version (Win32)
-                    {
-                        callbackCode = VirtualAlloc(null, CALLBACK_THUNK_SIZE * MAX_CALLBACKS, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
-                        if (callbackCode == null)
-                            return 0;
-                    }
-
-                    else version (Win32_WCE)
-                    {
-                        callbackCode = VirtualAlloc(null, CALLBACK_THUNK_SIZE * MAX_CALLBACKS, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
-                        if (callbackCode == null)
-                            return 0;
-                    }
-
-                    else
-                    {
-                        callbackCode = mmap(null, CALLBACK_THUNK_SIZE * MAX_CALLBACKS, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
-                        if (callbackCode == MAP_FAILED)
-                            return 0;
-                    }
-                }
-                code = cast(ubyte*) (callbackCode + (i * CALLBACK_THUNK_SIZE));
-
-                //PUSH EBP - 1 byte
-                code[j++] = 0x55;
-
-                //MOV EBP,ESP - 2 bytes
-                code[j++] = 0x8b;
-                code[j++] = 0xec;
-
-                version (darwin)
-                {
-                    /* darwin calling conventions require that the stack be aligned on a 16-byte boundary. */
-                    k = (argCount + 3) * SWT_PTR.sizeof;
-                    pad = ((k + 15) & ~15) - k;
-                    if (pad > 0)
-                    {
-                        //SUB ESP,pad - 3 bytes
-                        code[j++] = 0x83;
-                        code[j++] = 0xec;
-                        code[j++] = pad;
-                    }
-                }
-
-                // 3*argCount bytes
-                for (k = (argCount + 1) * SWT_PTR.sizeof; k >= SWT_PTR.sizeof * 2; k -= SWT_PTR.sizeof)
-                {
-                    //PUSH SS:[EBP+k]
-                    code[j++] = 0xff;
-                    code[j++] = 0x75;
-                    code[j++] = k;
-                }
-
-                if (i > 127)
-                {
-                    //PUSH i - 5 bytes
-                    code[j++] = 0x68;
-                    code[j++] = ((i >> 0) & 0xFF);
-                    code[j++] = ((i >> 8) & 0xFF);
-                    code[j++] = ((i >> 16) & 0xFF);
-                    code[j++] = ((i >> 24) & 0xFF);
-                }
-                else
-                {
-                    //PUSH i - 2 bytes
-                    code[j++] = 0x6a;
-                    code[j++] = i;
-                }
-
-                //MOV EAX callback - 1 + SWT_PTR.sizeof bytes
-                code[j++] = 0xb8;
-                (cast(SWT_PTR*) &code[j])[0] = cast(SWT_PTR) &callback;
-                j += SWT_PTR.sizeof;
-
-                //CALL EAX - 2 bytes
-                code[j++] = 0xff;
-                code[j++] = 0xd0;
-
-                //ADD ESP,(argCount + 1) * SWT_PTR.sizeof - 3 bytes
-                code[j++] = 0x83;
-                code[j++] = 0xc4;
-
-                version (darwin)
-                    code[j++] = cast(ubyte) (pad + ((argCount + 1) * SWT_PTR.sizeof));
-                else
-                    code[j++] = cast(ubyte) ((argCount + 1) * SWT_PTR.sizeof);
-
-                //POP EBP - 1 byte
-                code[j++] = 0x5d;
-
-                version (Win32)
-                {
-                    // RETN argCount * SWT_PTR.sizeof - 3 bytes
-                    code[j++] = 0xc2;
-                    code[j++] = cast(ubyte) (argCount * SWT_PTR.sizeof);
-                    code[j++] = 0x00;
-                }
-
-                else version (Win32_WCE)
-                {
-                    // RETN argCount * SWT_PTR.sizeof - 3 bytes
-                    code[j++] = 0xc2;
-                    code[j++] = cast(ubyte) (argCount * SWT_PTR.sizeof);
-                    code[j++] = 0x00;
-                }
-
-                else
-                {
-                    // RETN - 1 byte
-                    code[j++] = 0xc3;
-                }
-
-                if (j > CALLBACK_THUNK_SIZE)
-                    throw new Error("Callback thunk overflow");
-
-                return cast(SWT_PTR) code;
-            }
-        }
-    }
-    
-    fail:
-        return 0;
-}
-
-void unbind (Callback callback)
-{
-    int i;
-    for (i=0; i<MAX_CALLBACKS; i++) {
-        if (callbackData[i].callback !is null && callbackData[i].callback == callback) {
-            if (callbackData[i].callback !is null) delete callbackData[i].callback;
-            if (callbackData[i].object !is null) delete allbackData[i].object;
-            memset(&callbackData[i], 0, CALLBACK_DATA.sizeof);
-        }
-    }
-}
-
-bool getEnabled ()
-{
-    return callbackEnabled;
-}
-
-int getEntryCount ()
-{
-    return callbackEntryCount;
-}
-
-void setEnabled (bool enable)
-{
-    callbackEnabled = enable;
-}
-
-void reset ()
-{
-    memset(cast(void*) &callbackData, 0, callbackData.sizeof);
-}
--- a/dwt/internal/c/qd/bindings.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/c/qd/bindings.d	Sun Sep 14 01:45:57 2008 +0200
@@ -27,7 +27,7 @@
 void CloseRgn (RgnHandle dstRgn);
 void DisposeRgn (RgnHandle rgn);
 Boolean PtInRgn (Point pt, RgnHandle rgn);
-Rect* GetRegioinBounds (RgnHandle region, Rect* bounds);
+Rect* GetRegionBounds (RgnHandle region, Rect* bounds);
 void SectRgn (RgnHandle srcRgnA, RgnHandle srcRgnB, RgnHandle dstRgn);
 Boolean EmptyRgn (RgnHandle rgn);
 void DiffRgn (RgnHandle srcRgnA, RgnHandle srcRgnB, RgnHandle dstRgn);
--- a/dwt/internal/c/swt.d	Fri Sep 12 13:53:21 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors:
- *     IBM Corporation - initial API and implementation
- *     
- * Port to the D programming language:
- *     Jacob Carlborg <jacob.carlborg@gmail.com>
- *******************************************************************************/
- 
-/**
- * swt.h
- *
- * This file contains the global macro declarations for the
- * SWT library.
- *
- */
-module dwt.internal.c.swt;
-
-alias size_t SWT_PTR;
\ No newline at end of file
--- a/dwt/internal/cocoa/NSBezierPath.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/cocoa/NSBezierPath.d	Sun Sep 14 01:45:57 2008 +0200
@@ -31,6 +31,42 @@
     NSClosePathBezierPathElement
 }
 
+NSBezierPathElement.NSMoveToBezierPathElement NSMoveToBezierPathElement;
+NSBezierPathElement.NSLineToBezierPathElement NSLineToBezierPathElement;
+NSBezierPathElement.NSCurveToBezierPathElement NSCurveToBezierPathElement;
+NSBezierPathElement.NSClosePathBezierPathElement NSClosePathBezierPathElement;
+
+enum NSLineCapStyle
+{
+    NSButtLineCapStyle = 0,
+    NSRoundLineCapStyle = 1,
+    NSSquareLineCapStyle = 2
+}
+
+NSLineCapStyle.NSButtLineCapStyle NSButtLineCapStyle;
+NSLineCapStyle.NSRoundLineCapStyle NSRoundLineCapStyle;
+NSLineCapStyle.NSSquareLineCapStyle NSSquareLineCapStyle;
+
+enum NSLineJoinStyle
+{
+    NSMiterLineJoinStyle = 0,
+    NSRoundLineJoinStyle = 1,
+    NSBevelLineJoinStyle = 2
+}
+
+NSLineJoinStyle.NSMiterLineJoinStyle NSMiterLineJoinStyle;
+NSLineJoinStyle.NSRoundLineJoinStyle NSRoundLineJoinStyle;
+NSLineJoinStyle.NSBevelLineJoinStyle NSBevelLineJoinStyle;
+
+enum NSWindingRule
+{
+    NSNonZeroWindingRule = 0,
+    NSEvenOddWindingRule = 1
+}
+
+alias NSWindingRule.NSNonZeroWindingRule NSNonZeroWindingRule;
+alias NSWindingRule.NSEvenOddWindingRule NSEvenOddWindingRule;
+
 public class NSBezierPath : NSObject
 {
     public this ()
@@ -70,12 +106,12 @@
                 endAngle, clockwise);
     }
 
-    public void appendBezierPathWithGlyph (objc.id glyph, NSFont font)
+    public void appendBezierPathWithGlyph (NSGlyph glyph, NSFont font)
     {
         OS.objc_msgSend(this.id_, OS.sel_appendBezierPathWithGlyph_1inFont_1, glyph, font !is null ? font.id_ : null);
     }
 
-    public void appendBezierPathWithGlyphs (objc.id glyphs, NSInteger count, NSFont font)
+    public void appendBezierPathWithGlyphs (NSGlyph* glyphs, NSInteger count, NSFont font)
     {
         OS.objc_msgSend(this.id_, OS.sel_appendBezierPathWithGlyphs_1count_1inFont_1, glyphs, count, font !is null ? font.id_ : null);
     }
@@ -85,12 +121,12 @@
         OS.objc_msgSend(this.id_, OS.sel_appendBezierPathWithOvalInRect_1, rect);
     }
 
-    public void appendBezierPathWithPackedGlyphs (objc.id packedGlyphs)
+    public void appendBezierPathWithPackedGlyphs (/*const*/char* packedGlyphs)
     {
         OS.objc_msgSend(this.id_, OS.sel_appendBezierPathWithPackedGlyphs_1, packedGlyphs);
     }
 
-    public void appendBezierPathWithPoints (objc.id points, NSInteger count)
+    public void appendBezierPathWithPoints (NSPointArray points, NSInteger count)
     {
         OS.objc_msgSend(this.id_, OS.sel_appendBezierPathWithPoints_1count_1, points, count);
     }
@@ -192,14 +228,14 @@
         return cast(CGFloat) OS.objc_msgSend_fpret(OS.class_NSBezierPath, OS.sel_defaultFlatness);
     }
 
-    public static objc.id defaultLineCapStyle ()
+    public static NSLineCapStyle defaultLineCapStyle ()
     {
-        return OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_defaultLineCapStyle);
+        return cast(NSLineCapStyle) OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_defaultLineCapStyle);
     }
 
-    public static objc.id defaultLineJoinStyle ()
+    public static NSLineJoinStyle defaultLineJoinStyle ()
     {
-        return OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_defaultLineJoinStyle);
+        return cast(NSLineJoinStyle) OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_defaultLineJoinStyle);
     }
 
     public static CGFloat defaultLineWidth ()
@@ -212,9 +248,9 @@
         return cast(CGFloat) OS.objc_msgSend_fpret(OS.class_NSBezierPath, OS.sel_defaultMiterLimit);
     }
 
-    public static objc.id defaultWindingRule ()
+    public static NSWindingRule defaultWindingRule ()
     {
-        return OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_defaultWindingRule);
+        return cast(NSWindingRule) OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_defaultWindingRule);
     }
 
     public static void drawPackedGlyphs (/*const*/char* packedGlyphs, NSPoint point)
@@ -222,9 +258,9 @@
         OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_drawPackedGlyphs_1atPoint_1, packedGlyphs, point);
     }
 
-    public objc.id elementAtIndex_ (NSInteger index)
+    public NSBezierPathElement elementAtIndex_ (NSInteger index)
     {
-        return OS.objc_msgSend(this.id_, OS.sel_elementAtIndex_1, index);
+        return cast(NSBezierPathElement) OS.objc_msgSend(this.id_, OS.sel_elementAtIndex_1, index);
     }
 
     public NSBezierPathElement elementAtIndex_associatedPoints_ (NSInteger index, NSPointArray points)
@@ -262,14 +298,14 @@
         return OS.objc_msgSend(this.id_, OS.sel_isEmpty) !is null;
     }
 
-    public objc.id lineCapStyle ()
+    public NSLineCapStyle lineCapStyle ()
     {
-        return OS.objc_msgSend(this.id_, OS.sel_lineCapStyle);
+        return cast(NSLineCapStyle) OS.objc_msgSend(this.id_, OS.sel_lineCapStyle);
     }
 
-    public objc.id lineJoinStyle ()
+    public NSLineJoinStyle lineJoinStyle ()
     {
-        return OS.objc_msgSend(this.id_, OS.sel_lineJoinStyle);
+        return cast(NSLineJoinStyle) OS.objc_msgSend(this.id_, OS.sel_lineJoinStyle);
     }
 
     public void lineToPoint (NSPoint point)
@@ -332,12 +368,12 @@
         OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_setDefaultFlatness_1, flatness);
     }
 
-    public static void setDefaultLineCapStyle (objc.id lineCapStyle)
+    public static void setDefaultLineCapStyle (NSLineCapStyle lineCapStyle)
     {
         OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_setDefaultLineCapStyle_1, lineCapStyle);
     }
 
-    public static void setDefaultLineJoinStyle (objc.id lineJoinStyle)
+    public static void setDefaultLineJoinStyle (NSLineJoinStyle lineJoinStyle)
     {
         OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_setDefaultLineJoinStyle_1, lineJoinStyle);
     }
@@ -352,7 +388,7 @@
         OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_setDefaultMiterLimit_1, limit);
     }
 
-    public static void setDefaultWindingRule (objc.id windingRule)
+    public static void setDefaultWindingRule (NSWindingRule windingRule)
     {
         OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_setDefaultWindingRule_1, windingRule);
     }
@@ -362,7 +398,7 @@
         OS.objc_msgSend(this.id_, OS.sel_setFlatness_1, flatness);
     }
 
-    public void setLineCapStyle (objc.id lineCapStyle)
+    public void setLineCapStyle (NSLineCapStyle lineCapStyle)
     {
         OS.objc_msgSend(this.id_, OS.sel_setLineCapStyle_1, lineCapStyle);
     }
@@ -372,7 +408,7 @@
         OS.objc_msgSend(this.id_, OS.sel_setLineDash_1count_1phase_1, pattern, count, phase);
     }
 
-    public void setLineJoinStyle (objc.id lineJoinStyle)
+    public void setLineJoinStyle (NSLineJoinStyle lineJoinStyle)
     {
         OS.objc_msgSend(this.id_, OS.sel_setLineJoinStyle_1, lineJoinStyle);
     }
@@ -387,7 +423,7 @@
         OS.objc_msgSend(this.id_, OS.sel_setMiterLimit_1, miterLimit);
     }
 
-    public void setWindingRule (objc.id windingRule)
+    public void setWindingRule (NSWindingRule windingRule)
     {
         OS.objc_msgSend(this.id_, OS.sel_setWindingRule_1, windingRule);
     }
@@ -412,8 +448,8 @@
         OS.objc_msgSend(this.id_, OS.sel_transformUsingAffineTransform_1, transform !is null ? transform.id_ : null);
     }
 
-    public objc.id windingRule ()
+    public NSWindingRule windingRule ()
     {
-        return OS.objc_msgSend(this.id_, OS.sel_windingRule);
+        return cast(NSWindingRule) OS.objc_msgSend(this.id_, OS.sel_windingRule);
     }
 }
--- a/dwt/internal/cocoa/OS.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/cocoa/OS.d	Sun Sep 14 01:45:57 2008 +0200
@@ -122,7 +122,7 @@
     alias dwt.internal.c.qd.Quickdraw.CloseRgn CloseRgn;
     alias dwt.internal.c.qd.Quickdraw.DisposeRgn DisposeRgn;
     alias dwt.internal.c.qd.Quickdraw.PtInRgn PtInRgn;
-    alias dwt.internal.c.qd.Quickdraw.GetRegioinBounds GetRegioinBounds;
+    alias dwt.internal.c.qd.Quickdraw.GetRegionBounds GetRegionBounds;
     alias dwt.internal.c.qd.Quickdraw.SectRgn SectRgn;
     alias dwt.internal.c.qd.Quickdraw.EmptyRgn EmptyRgn;
     alias dwt.internal.c.qd.Quickdraw.DiffRgn DiffRgn;
--- a/dwt/internal/image/FileFormat.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/FileFormat.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,17 +7,33 @@
  *
  * 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.FileFormat;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import dwt.dwthelper.utils;
+
+public import dwt.graphics.ImageLoader;
+public import dwt.graphics.ImageData;
+public import dwt.internal.image.LEDataInputStream;
+public import dwt.internal.image.LEDataOutputStream;
 
 import dwt.DWT;
-import dwt.graphics.ImageData;
-import dwt.graphics.ImageLoader;
+
+public import dwt.dwthelper.InputStream;
+public import dwt.dwthelper.OutputStream;
+
+import dwt.internal.image.GIFFileFormat;
+import dwt.internal.image.WinBMPFileFormat;
+import dwt.internal.image.WinICOFileFormat;
+import dwt.internal.image.TIFFFileFormat;
+import dwt.internal.image.OS2BMPFileFormat;
+import dwt.internal.image.JPEGFileFormat;
+import dwt.internal.image.PNGFileFormat;
+
+import tango.core.Exception;
+import tango.core.Tuple;
 
 /**
  * Abstract factory class for loading/unloading images from files or streams
@@ -25,10 +41,10 @@
  *
  */
 public abstract class FileFormat {
-    static final String FORMAT_PACKAGE = "dwt.internal.image"; //$NON-NLS-1$
-    static final String FORMAT_SUFFIX = "FileFormat"; //$NON-NLS-1$
-    static final String[] FORMATS = {"WinBMP", "WinBMP", "GIF", "WinICO", "JPEG", "PNG", "TIFF", "OS2BMP"}; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$//$NON-NLS-7$//$NON-NLS-8$
-    
+    static const String FORMAT_PACKAGE = "dwt.internal.image"; //$NON-NLS-1$
+    static const String FORMAT_SUFFIX = "FileFormat"; //$NON-NLS-1$
+    static const String[] FORMATS = [ "WinBMP"[], "WinBMP", "GIF", "WinICO", "JPEG", "PNG", "TIFF", "OS2BMP" ]; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$//$NON-NLS-7$//$NON-NLS-8$
+    alias Tuple!( WinBMPFileFormat, WinBMPFileFormat, GIFFileFormat, WinICOFileFormat, JPEGFileFormat, PNGFileFormat, TIFFFileFormat, OS2BMPFileFormat ) TFormats;
     LEDataInputStream inputStream;
     LEDataOutputStream outputStream;
     ImageLoader loader;
@@ -45,17 +61,16 @@
 /**
  * Read the specified input stream, and return the
  * device independent image array represented by the stream.
- */ 
+ */
 public ImageData[] loadFromStream(LEDataInputStream stream) {
     try {
         inputStream = stream;
         return loadFromByteStream();
+    } catch (IOException e) {
+        DWT.error(DWT.ERROR_IO, e);
+        return null;
     } catch (Exception e) {
-        if ( null !is cast(IOException)e ) {
-            DWT.error(DWT.ERROR_IO, e);
-        } else {
-            DWT.error(DWT.ERROR_INVALID_IMAGE, e);
-        }
+        DWT.error(DWT.ERROR_INVALID_IMAGE, e);
         return null;
     }
 }
@@ -63,24 +78,19 @@
 /**
  * Read the specified input stream using the specified loader, and
  * return the device independent image array represented by the stream.
- */ 
-public static ImageData[] load(InputStream is, ImageLoader loader) {
+ */
+public static ImageData[] load(InputStream istr, ImageLoader loader) {
     FileFormat fileFormat = null;
-    LEDataInputStream stream = new LEDataInputStream(is);
-    bool isSupported = false;   
-    for (int i = 1; i < FORMATS.length; i++) {
-        if (FORMATS[i] !is null) {
-            try {
-                Class clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[i] + FORMAT_SUFFIX);
-                fileFormat = cast(FileFormat) clazz.newInstance();
-                if (fileFormat.isFileFormat(stream)) {
-                    isSupported = true;
-                    break;
-                }
-            } catch (ClassNotFoundException e) {
-                FORMATS[i] = null;
-            } catch (Exception e) {
+    LEDataInputStream stream = new LEDataInputStream(istr);
+    bool isSupported = false;    
+    foreach( TFormat; TFormats ){
+        try{
+            fileFormat = new TFormat();
+            if (fileFormat.isFileFormat(stream)) {
+                isSupported = true;
+                break;
             }
+        } catch (Exception e) {
         }
     }
     if (!isSupported) DWT.error(DWT.ERROR_UNSUPPORTED_FORMAT);
@@ -91,7 +101,7 @@
 /**
  * Write the device independent image array stored in the specified loader
  * to the specified output stream using the specified file format.
- */ 
+ */
 public static void save(OutputStream os, int format, ImageLoader loader) {
     if (format < 0 || format >= FORMATS.length) DWT.error(DWT.ERROR_UNSUPPORTED_FORMAT);
     if (FORMATS[format] is null) DWT.error(DWT.ERROR_UNSUPPORTED_FORMAT);
@@ -100,8 +110,11 @@
     LEDataOutputStream stream = new LEDataOutputStream(os);
     FileFormat fileFormat = null;
     try {
-        Class clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[format] + FORMAT_SUFFIX);
-        fileFormat = cast(FileFormat) clazz.newInstance();
+        foreach( idx, TFormat; TFormats ){
+            if( idx is format ){
+                fileFormat = new TFormat();
+            }
+        }
     } catch (Exception e) {
         DWT.error(DWT.ERROR_UNSUPPORTED_FORMAT);
     }
@@ -109,6 +122,7 @@
         switch (loader.data[0].depth) {
             case 8: fileFormat.compression = 1; break;
             case 4: fileFormat.compression = 2; break;
+            default:
         }
     }
     fileFormat.unloadIntoStream(loader, stream);
@@ -119,7 +133,7 @@
 /**
  * Write the device independent image array stored in the specified loader
  * to the specified output stream.
- */ 
+ */
 public void unloadIntoStream(ImageLoader loader, LEDataOutputStream stream) {
     try {
         outputStream = stream;
--- a/dwt/internal/image/GIFFileFormat.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/GIFFileFormat.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,27 +7,32 @@
  *
  * 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.GIFFileFormat;
+
+public import dwt.internal.image.FileFormat;
+public import dwt.graphics.PaletteData;
+import dwt.internal.image.LEDataInputStream;
+import dwt.internal.image.LZWCodec;
+import dwt.graphics.RGB;
+import dwt.DWT;
+import dwt.graphics.ImageData;
+import dwt.graphics.ImageLoaderEvent;
+import dwt.graphics.ImageLoader;
+import tango.core.Exception;
+import dwt.dwthelper.utils;
 
 
-import java.io.IOException;
-
-import dwt.DWT;
-import dwt.graphics.ImageData;
-import dwt.graphics.ImageLoader;
-import dwt.graphics.ImageLoaderEvent;
-import dwt.graphics.PaletteData;
-import dwt.graphics.RGB;
-
-public final class GIFFileFormat : FileFormat {
+final class GIFFileFormat : FileFormat {
     String signature;
     int screenWidth, screenHeight, backgroundPixel, bitsPerPixel, defaultDepth;
     int disposalMethod = 0;
     int delayTime = 0;
     int transparentPixel = -1;
     int repeatCount = 1;
-    
+
     static final int GIF_APPLICATION_EXTENSION_BLOCK_ID = 0xFF;
     static final int GIF_GRAPHICS_CONTROL_BLOCK_ID = 0xF9;
     static final int GIF_PLAIN_TEXT_BLOCK_ID = 0x01;
@@ -35,9 +40,9 @@
     static final int GIF_EXTENSION_BLOCK_ID = 0x21;
     static final int GIF_IMAGE_BLOCK_ID = 0x2C;
     static final int GIF_TRAILER_ID = 0x3B;
-    static final byte [] GIF89a = new byte[] { cast(byte)'G', cast(byte)'I', cast(byte)'F', cast(byte)'8', cast(byte)'9', cast(byte)'a' };
-    static final byte [] NETSCAPE2_0 = new byte[] { cast(byte)'N', cast(byte)'E', cast(byte)'T', cast(byte)'S', cast(byte)'C', cast(byte)'A', cast(byte)'P', cast(byte)'E', cast(byte)'2', cast(byte)'.', cast(byte)'0' };
-    
+    static final byte[] GIF89a = cast(byte[])"GIF89a";
+    static final byte[] NETSCAPE2_0 = cast(byte[])"NETSCAPE2.0";
+
     /**
      * Answer a palette containing numGrays
      * shades of gray, ranging from black to white.
@@ -52,9 +57,9 @@
         return new PaletteData(colors);
     }
 
-    bool isFileFormat(LEDataInputStream stream) {
+    override bool isFileFormat(LEDataInputStream stream) {
         try {
-            byte[] signature = new byte[3];
+            byte[3] signature;
             stream.read(signature);
             stream.unread(signature);
             return signature[0] is 'G' && signature[1] is 'I' && signature[2] is 'F';
@@ -67,10 +72,10 @@
      * Load the GIF image(s) stored in the input stream.
      * Return an array of ImageData representing the image(s).
      */
-    ImageData[] loadFromByteStream() {
-        byte[] signature = new byte[3];
-        byte[] versionBytes = new byte[3];
-        byte[] block = new byte[7];
+    override ImageData[] loadFromByteStream() {
+        byte[3] signature;
+        byte[3] versionBytes;
+        byte[7] block;
         try {
             inputStream.read(signature);
             if (!(signature[0] is 'G' && signature[1] is 'I' && signature[2] is 'F'))
@@ -116,12 +121,15 @@
             images = new ImageData[oldImages.length + 1];
             System.arraycopy(oldImages, 0, images, 0, oldImages.length);
             images[images.length - 1] = image;
+            //images ~= image;
             try {
                 /* Read the 0-byte terminator at the end of the image. */
                 id = inputStream.read();
                 if (id > 0) {
                     /* We read the terminator earlier. */
-                    inputStream.unread(new byte[] {cast(byte)id});
+                    byte[1] arr;
+                    arr[0] = id;
+                    inputStream.unread( arr );
                 }
             } catch (IOException e) {
                 DWT.error(DWT.ERROR_IO, e);
@@ -164,7 +172,9 @@
         }
         if (id is GIF_IMAGE_BLOCK_ID || id is GIF_TRAILER_ID) {
             try {
-                inputStream.unread(new byte[] {cast(byte)id});
+                byte[1] arr;
+                arr[0] = id;
+                inputStream.unread(arr);
             } catch (IOException e) {
                 DWT.error(DWT.ERROR_IO, e);
             }
@@ -217,6 +227,7 @@
                 comment = new byte[oldComment.length + size];
                 System.arraycopy(oldComment, 0, comment, 0, oldComment.length);
                 System.arraycopy(block, 0, comment, oldComment.length, size);
+                //comment ~= block[ 0 .. size ];
                 size = inputStream.read();
             }
             return comment;
@@ -247,6 +258,7 @@
                 text = new byte[oldText.length + size];
                 System.arraycopy(oldText, 0, text, 0, oldText.length);
                 System.arraycopy(block, 0, text, oldText.length, size);
+                //text ~= block[ 0 .. size ];
                 size = inputStream.read();
             }
             return text;
@@ -314,6 +326,7 @@
                 data = new byte[oldData.length + size];
                 System.arraycopy(oldData, 0, data, 0, oldData.length);
                 System.arraycopy(block, 0, data, oldData.length, size);
+                //data ~= block[ 0 .. size ];
                 size = inputStream.read();
             }
             // Look for the NETSCAPE 'repeat count' field for an animated GIF.
@@ -412,7 +425,7 @@
             left,
             top,
             disposalMethod,
-            delayTime); 
+            delayTime);
         LZWCodec codec = new LZWCodec();
         codec.decode(inputStream, loader, image, interlaced, initialCodeSize);
         return image;
@@ -431,13 +444,13 @@
         }
         RGB[] colors = new RGB[numColors];
         for (int i = 0; i < numColors; i++)
-            colors[i] = new RGB(bytes[i*3] & 0xFF, 
+            colors[i] = new RGB(bytes[i*3] & 0xFF,
                 bytes[i*3+1] & 0xFF, bytes[i*3+2] & 0xFF);
         return new PaletteData(colors);
     }
 
-    void unloadIntoByteStream(ImageLoader loader) {
-        
+    override void unloadIntoByteStream(ImageLoader loader) {
+
         /* Step 1: Acquire GIF parameters. */
         ImageData[] data = loader.data;
         int frameCount = data.length;
@@ -450,7 +463,7 @@
         PaletteData palette = firstImage.palette;
         RGB[] colors = palette.getRGBs();
         short globalTable = 1;
-                
+
         /* Step 2: Check for validity and global/local color map. */
         if (!(depth is 1 || depth is 4 || depth is 8)) {
             DWT.error(DWT.ERROR_UNSUPPORTED_DEPTH);
@@ -467,7 +480,7 @@
                     RGB rgbs[] = data[i].palette.getRGBs();
                     if (rgbs.length !is colors.length) {
                         globalTable = 0;
-                    } else { 
+                    } else {
                         for (int j=0; j<colors.length; j++) {
                             if (!(rgbs[j].red is colors[j].red &&
                                 rgbs[j].green is colors[j].green &&
@@ -478,7 +491,7 @@
                 }
             }
         }
-        
+
         try {
             /* Step 3: Write the GIF89a Header and Logical Screen Descriptor. */
             outputStream.write(GIF89a);
@@ -491,7 +504,7 @@
         } catch (IOException e) {
             DWT.error(DWT.ERROR_IO, e);
         }
-        
+
         /* Step 4: Write Global Color Table if applicable. */
         if (globalTable is 1) {
             writePalette(palette, depth);
@@ -513,14 +526,14 @@
                 DWT.error(DWT.ERROR_IO, e);
             }
         }
-        
+
         for (int frame=0; frame<frameCount; frame++) {
-            
+
             /* Step 6: Write Graphics Control Block for each frame if applicable. */
             if (multi || data[frame].transparentPixel !is -1) {
                 writeGraphicsControlBlock(data[frame]);
             }
-            
+
             /* Step 7: Write Image Header for each frame. */
             int x = data[frame].x;
             int y = data[frame].y;
@@ -536,25 +549,25 @@
                 block[4] = cast(byte)(width & 0xFF);
                 block[5] = cast(byte)((width >> 8) & 0xFF);
                 block[6] = cast(byte)(height & 0xFF);
-                block[7] = cast(byte)((height >> 8) & 0xFF); 
+                block[7] = cast(byte)((height >> 8) & 0xFF);
                 block[8] = cast(byte)(globalTable is 0 ? (depth-1) | 0x80 : 0x00);
                 outputStream.write(block);
             } catch (IOException e) {
                 DWT.error(DWT.ERROR_IO, e);
             }
-            
+
             /* Step 8: Write Local Color Table for each frame if applicable. */
             if (globalTable is 0) {
                 writePalette(data[frame].palette, depth);
             }
-            
+
             /* Step 9: Write the actual data for each frame. */
             try {
                 outputStream.write(depth); // Minimum LZW Code size
             } catch (IOException e) {
                 DWT.error(DWT.ERROR_IO, e);
             }
-            new LZWCodec().encode(outputStream, data[frame]);
+            (new LZWCodec()).encode(outputStream, data[frame]);
         }
 
         /* Step 10: Write GIF terminator. */
--- a/dwt/internal/image/JPEGAppn.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGAppn.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,21 +7,26 @@
  *
  * 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.JPEGAppn;
 
+import dwt.internal.image.JPEGVariableSizeSegment;
+import dwt.internal.image.JPEGFileFormat;
+import dwt.internal.image.LEDataInputStream;
 
 final class JPEGAppn : JPEGVariableSizeSegment {
 
     public this(byte[] reference) {
         super(reference);
     }
-    
+
     public this(LEDataInputStream byteStream) {
         super(byteStream);
     }
-    
-    public bool verify() {
+
+    public override bool verify() {
         int marker = getSegmentMarker();
         return marker >= JPEGFileFormat.APP0 && marker <= JPEGFileFormat.APP15;
     }
--- a/dwt/internal/image/JPEGArithmeticConditioningTable.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGArithmeticConditioningTable.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,17 +7,22 @@
  *
  * 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.JPEGArithmeticConditioningTable;
 
+import dwt.internal.image.JPEGVariableSizeSegment;
+import dwt.internal.image.JPEGFileFormat;
+import dwt.internal.image.LEDataInputStream;
 
 final class JPEGArithmeticConditioningTable : JPEGVariableSizeSegment {
 
     public this(LEDataInputStream byteStream) {
         super(byteStream);
     }
-    
-    public int signature() {
+
+    public override int signature() {
         return JPEGFileFormat.DAC;
     }
 }
--- a/dwt/internal/image/JPEGComment.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGComment.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,21 +7,26 @@
  *
  * 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.JPEGComment;
 
+import dwt.internal.image.JPEGVariableSizeSegment;
+import dwt.internal.image.JPEGFileFormat;
+import dwt.internal.image.LEDataInputStream;
 
 final class JPEGComment : JPEGVariableSizeSegment {
 
     public this(byte[] reference) {
         super(reference);
     }
-    
+
     public this(LEDataInputStream byteStream) {
         super(byteStream);
     }
-    
-    public int signature() {
+
+    public override int signature() {
         return JPEGFileFormat.COM;
     }
 }
--- a/dwt/internal/image/JPEGDecoder.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGDecoder.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,213 +7,219 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
-module dwt.internal.image;
-
-import java.io.IOException;
-import java.io.InputStream;
+module dwt.internal.image.JPEGDecoder;
 
 import dwt.DWT;
+import dwt.dwthelper.InputStream;
+import dwt.internal.image.LEDataInputStream;
 import dwt.graphics.ImageData;
 import dwt.graphics.ImageLoader;
 import dwt.graphics.ImageLoaderEvent;
 import dwt.graphics.PaletteData;
 import dwt.graphics.RGB;
+import dwt.dwthelper.utils;
+
+import tango.core.Exception;
+import tango.util.Convert;
+import Math = tango.math.Math;
 
 public class JPEGDecoder {
-    
-    static final int DCTSIZE = 8;
-    static final int DCTSIZE2 = 64;
-    static final int NUM_QUANT_TBLS = 4;
-    static final int NUM_HUFF_TBLS = 4;
-    static final int NUM_ARITH_TBLS = 16;
-    static final int MAX_COMPS_IN_SCAN = 4;
-    static final int MAX_COMPONENTS = 10;
-    static final int MAX_SAMP_FACTOR = 4;
-    static final int D_MAX_BLOCKS_IN_MCU = 10;
-    static final int HUFF_LOOKAHEAD = 8;
-    static final int MAX_Q_COMPS = 4;
-    static final int IFAST_SCALE_BITS = 2;
-    static final int MAXJSAMPLE = 255;
-    static final int CENTERJSAMPLE = 128;
-    static final int MIN_GET_BITS = 32-7;
-    static final int INPUT_BUFFER_SIZE = 4096;
-
-    static final int SCALEBITS = 16;    /* speediest right-shift on some machines */
-    static final int ONE_HALF = 1 << (SCALEBITS-1);
-    
-    static final int RGB_RED = 2;   /* Offset of Red in an RGB scanline element */
-    static final int RGB_GREEN = 1; /* Offset of Green */
-    static final int RGB_BLUE = 0;  /* Offset of Blue */
-    static final int RGB_PIXELSIZE = 3;
-    
-    static final int JBUF_PASS_THRU = 0;
-    static final int JBUF_SAVE_SOURCE = 1;  /* Run source subobject only, save output */
-    static final int JBUF_CRANK_DEST = 2;   /* Run dest subobject only, using saved data */
-    static final int JBUF_SAVE_AND_PASS = 3;    
-    
-    static final int JPEG_MAX_DIMENSION = 65500;
-    static final int BITS_IN_JSAMPLE = 8;
-    
-    static final int JDITHER_NONE = 0;      /* no dithering */
-    static final int JDITHER_ORDERED = 1;   /* simple ordered dither */
-    static final int JDITHER_FS = 2;    
-    
-    static final int JDCT_ISLOW = 0;    /* slow but accurate integer algorithm */
-    static final int JDCT_IFAST = 1;    /* faster, less accurate integer method */
-    static final int JDCT_FLOAT = 2;    /* floating-point: accurate, fast on fast HW */
-    static final int JDCT_DEFAULT = JDCT_ISLOW;
-
-    static final int JCS_UNKNOWN = 0;       /* error/unspecified */
-    static final int JCS_GRAYSCALE = 1;     /* monochrome */
-    static final int JCS_RGB = 2;       /* red/green/blue */
-    static final int JCS_YCbCr = 3;     /* Y/Cb/Cr (also known as YUV) */
-    static final int JCS_CMYK = 4;      /* C/M/Y/K */
-    static final int JCS_YCCK = 5;      /* Y/Cb/Cr/K */
-
-    static final int SAVED_COEFS = 6;
-    static final int Q01_POS = 1;
-    static final int Q10_POS = 8;
-    static final int Q20_POS = 16;
-    static final int Q11_POS = 9;
-    static final int Q02_POS = 2;
-    
-    static final int CTX_PREPARE_FOR_IMCU = 0;  /* need to prepare for MCU row */
-    static final int CTX_PROCESS_IMCU = 1;  /* feeding iMCU to postprocessor */
-    static final int CTX_POSTPONED_ROW = 2; /* feeding postponed row group */
-    
-    static final int APP0_DATA_LEN = 14;    /* Length of interesting data in APP0 */
-    static final int APP14_DATA_LEN = 12;   /* Length of interesting data in APP14 */
-    static final int APPN_DATA_LEN = 14;    /* Must be the largest of the above!! */
+
+    static const int DCTSIZE = 8;
+    static const int DCTSIZE2 = 64;
+    static const int NUM_QUANT_TBLS = 4;
+    static const int NUM_HUFF_TBLS = 4;
+    static const int NUM_ARITH_TBLS = 16;
+    static const int MAX_COMPS_IN_SCAN = 4;
+    static const int MAX_COMPONENTS = 10;
+    static const int MAX_SAMP_FACTOR = 4;
+    static const int D_MAX_BLOCKS_IN_MCU = 10;
+    static const int HUFF_LOOKAHEAD = 8;
+    static const int MAX_Q_COMPS = 4;
+    static const int IFAST_SCALE_BITS = 2;
+    static const int MAXJSAMPLE = 255;
+    static const int CENTERJSAMPLE = 128;
+    static const int MIN_GET_BITS = 32-7;
+    static const int INPUT_BUFFER_SIZE = 4096;
+
+    static const int SCALEBITS = 16;    /* speediest right-shift on some machines */
+    static const int ONE_HALF = 1 << (SCALEBITS-1);
+
+    static const int RGB_RED = 2;   /* Offset of Red in an RGB scanline element */
+    static const int RGB_GREEN = 1; /* Offset of Green */
+    static const int RGB_BLUE = 0;  /* Offset of Blue */
+    static const int RGB_PIXELSIZE = 3;
+
+    static const int JBUF_PASS_THRU = 0;
+    static const int JBUF_SAVE_SOURCE = 1;  /* Run source subobject only, save output */
+    static const int JBUF_CRANK_DEST = 2;   /* Run dest subobject only, using saved data */
+    static const int JBUF_SAVE_AND_PASS = 3;
+
+    static const int JPEG_MAX_DIMENSION = 65500;
+    static const int BITS_IN_JSAMPLE = 8;
+
+    static const int JDITHER_NONE = 0;      /* no dithering */
+    static const int JDITHER_ORDERED = 1;   /* simple ordered dither */
+    static const int JDITHER_FS = 2;
+
+    static const int JDCT_ISLOW = 0;    /* slow but accurate integer algorithm */
+    static const int JDCT_IFAST = 1;    /* faster, less accurate integer method */
+    static const int JDCT_FLOAT = 2;    /* floating-point: accurate, fast on fast HW */
+    static const int JDCT_DEFAULT = JDCT_ISLOW;
+
+    static const int JCS_UNKNOWN = 0;       /* error/unspecified */
+    static const int JCS_GRAYSCALE = 1;     /* monochrome */
+    static const int JCS_RGB = 2;       /* red/green/blue */
+    static const int JCS_YCbCr = 3;     /* Y/Cb/Cr (also known as YUV) */
+    static const int JCS_CMYK = 4;      /* C/M/Y/K */
+    static const int JCS_YCCK = 5;      /* Y/Cb/Cr/K */
+
+    static const int SAVED_COEFS = 6;
+    static const int Q01_POS = 1;
+    static const int Q10_POS = 8;
+    static const int Q20_POS = 16;
+    static const int Q11_POS = 9;
+    static const int Q02_POS = 2;
+
+    static const int CTX_PREPARE_FOR_IMCU = 0;  /* need to prepare for MCU row */
+    static const int CTX_PROCESS_IMCU = 1;  /* feeding iMCU to postprocessor */
+    static const int CTX_POSTPONED_ROW = 2; /* feeding postponed row group */
+
+    static const int APP0_DATA_LEN = 14;    /* Length of interesting data in APP0 */
+    static const int APP14_DATA_LEN = 12;   /* Length of interesting data in APP14 */
+    static const int APPN_DATA_LEN = 14;    /* Must be the largest of the above!! */
 
     /* markers */
-    static final int M_SOF0 = 0xc0;
-    static final int M_SOF1 = 0xc1;
-    static final int M_SOF2 = 0xc2;
-    static final int M_SOF3 = 0xc3;
-    static final int M_SOF5 = 0xc5;
-    static final int M_SOF6 = 0xc6;
-    static final int M_SOF7 = 0xc7;
-    static final int M_JPG = 0xc8;
-    static final int M_SOF9 = 0xc9;
-    static final int M_SOF10 = 0xca;
-    static final int M_SOF11 = 0xcb;
-    static final int M_SOF13 = 0xcd;
-    static final int M_SOF14 = 0xce;
-    static final int M_SOF15 = 0xcf;
-    static final int M_DHT = 0xc4;
-    static final int M_DAC = 0xcc;
-    static final int M_RST0 = 0xd0;
-    static final int M_RST1 = 0xd1;
-    static final int M_RST2 = 0xd2;
-    static final int M_RST3 = 0xd3;
-    static final int M_RST4 = 0xd4;
-    static final int M_RST5 = 0xd5;
-    static final int M_RST6 = 0xd6;
-    static final int M_RST7 = 0xd7;
-    static final int M_SOI = 0xd8;
-    static final int M_EOI = 0xd9;
-    static final int M_SOS = 0xda;
-    static final int M_DQT = 0xdb;
-    static final int M_DNL = 0xdc;
-    static final int M_DRI = 0xdd;
-    static final int M_DHP = 0xde;
-    static final int M_EXP = 0xdf;
-    static final int M_APP0 = 0xe0;
-    static final int M_APP1 = 0xe1;
-    static final int M_APP2 = 0xe2;
-    static final int M_APP3 = 0xe3;
-    static final int M_APP4 = 0xe4;
-    static final int M_APP5 = 0xe5;
-    static final int M_APP6 = 0xe6;
-    static final int M_APP7 = 0xe7;
-    static final int M_APP8 = 0xe8;
-    static final int M_APP9 = 0xe9;
-    static final int M_APP10 = 0xea;
-    static final int M_APP11 = 0xeb;
-    static final int M_APP12 = 0xec;
-    static final int M_APP13 = 0xed;
-    static final int M_APP14 = 0xee;
-    static final int M_APP15 = 0xef;
-    static final int M_JPG0 = 0xf0;
-    static final int M_JPG13 = 0xfd;
-    static final int M_COM = 0xfe;
-    static final int M_TEM = 0x01;
-    static final int M_ERROR = 0x100;
-    
+    static const int M_SOF0 = 0xc0;
+    static const int M_SOF1 = 0xc1;
+    static const int M_SOF2 = 0xc2;
+    static const int M_SOF3 = 0xc3;
+    static const int M_SOF5 = 0xc5;
+    static const int M_SOF6 = 0xc6;
+    static const int M_SOF7 = 0xc7;
+    static const int M_JPG = 0xc8;
+    static const int M_SOF9 = 0xc9;
+    static const int M_SOF10 = 0xca;
+    static const int M_SOF11 = 0xcb;
+    static const int M_SOF13 = 0xcd;
+    static const int M_SOF14 = 0xce;
+    static const int M_SOF15 = 0xcf;
+    static const int M_DHT = 0xc4;
+    static const int M_DAC = 0xcc;
+    static const int M_RST0 = 0xd0;
+    static const int M_RST1 = 0xd1;
+    static const int M_RST2 = 0xd2;
+    static const int M_RST3 = 0xd3;
+    static const int M_RST4 = 0xd4;
+    static const int M_RST5 = 0xd5;
+    static const int M_RST6 = 0xd6;
+    static const int M_RST7 = 0xd7;
+    static const int M_SOI = 0xd8;
+    static const int M_EOI = 0xd9;
+    static const int M_SOS = 0xda;
+    static const int M_DQT = 0xdb;
+    static const int M_DNL = 0xdc;
+    static const int M_DRI = 0xdd;
+    static const int M_DHP = 0xde;
+    static const int M_EXP = 0xdf;
+    static const int M_APP0 = 0xe0;
+    static const int M_APP1 = 0xe1;
+    static const int M_APP2 = 0xe2;
+    static const int M_APP3 = 0xe3;
+    static const int M_APP4 = 0xe4;
+    static const int M_APP5 = 0xe5;
+    static const int M_APP6 = 0xe6;
+    static const int M_APP7 = 0xe7;
+    static const int M_APP8 = 0xe8;
+    static const int M_APP9 = 0xe9;
+    static const int M_APP10 = 0xea;
+    static const int M_APP11 = 0xeb;
+    static const int M_APP12 = 0xec;
+    static const int M_APP13 = 0xed;
+    static const int M_APP14 = 0xee;
+    static const int M_APP15 = 0xef;
+    static const int M_JPG0 = 0xf0;
+    static const int M_JPG13 = 0xfd;
+    static const int M_COM = 0xfe;
+    static const int M_TEM = 0x01;
+    static const int M_ERROR = 0x100;
+
     /* Values of global_state field (jdapi.c has some dependencies on ordering!) */
-    static final int CSTATE_START = 100;    /* after create_compress */
-    static final int CSTATE_SCANNING = 101; /* start_compress done, write_scanlines OK */
-    static final int CSTATE_RAW_OK = 102;   /* start_compress done, write_raw_data OK */
-    static final int CSTATE_WRCOEFS = 103;  /* jpeg_write_coefficients done */
-    static final int DSTATE_START = 200;    /* after create_decompress */
-    static final int DSTATE_INHEADER = 201; /* reading header markers, no SOS yet */
-    static final int DSTATE_READY = 202;    /* found SOS, ready for start_decompress */
-    static final int DSTATE_PRELOAD = 203;  /* reading multiscan file in start_decompress*/
-    static final int DSTATE_PRESCAN = 204;  /* performing dummy pass for 2-pass quant */
-    static final int DSTATE_SCANNING = 205; /* start_decompress done, read_scanlines OK */
-    static final int DSTATE_RAW_OK = 206;   /* start_decompress done, read_raw_data OK */
-    static final int DSTATE_BUFIMAGE = 207; /* expecting jpeg_start_output */
-    static final int DSTATE_BUFPOST = 208;  /* looking for SOS/EOI in jpeg_finish_output */
-    static final int DSTATE_RDCOEFS = 209;  /* reading file in jpeg_read_coefficients */
-    static final int DSTATE_STOPPING = 210; /* looking for EOI in jpeg_finish_decompress */
-
-    static final int JPEG_REACHED_SOS = 1; /* Reached start of new scan */
-    static final int JPEG_REACHED_EOI = 2; /* Reached end of image */
-    static final int JPEG_ROW_COMPLETED = 3; /* Completed one iMCU row */
-    static final int JPEG_SCAN_COMPLETED = 4; /* Completed last iMCU row of a scan */
-    
-    static final int JPEG_SUSPENDED = 0; /* Suspended due to lack of input data */
-    static final int JPEG_HEADER_OK = 1; /* Found valid image datastream */
-    static final int JPEG_HEADER_TABLES_ONLY = 2; /* Found valid table-specs-only datastream */
+    static const int CSTATE_START = 100;    /* after create_compress */
+    static const int CSTATE_SCANNING = 101; /* start_compress done, write_scanlines OK */
+    static const int CSTATE_RAW_OK = 102;   /* start_compress done, write_raw_data OK */
+    static const int CSTATE_WRCOEFS = 103;  /* jpeg_write_coefficients done */
+    static const int DSTATE_START = 200;    /* after create_decompress */
+    static const int DSTATE_INHEADER = 201; /* reading header markers, no SOS yet */
+    static const int DSTATE_READY = 202;    /* found SOS, ready for start_decompress */
+    static const int DSTATE_PRELOAD = 203;  /* reading multiscan file in start_decompress*/
+    static const int DSTATE_PRESCAN = 204;  /* performing dummy pass for 2-pass quant */
+    static const int DSTATE_SCANNING = 205; /* start_decompress done, read_scanlines OK */
+    static const int DSTATE_RAW_OK = 206;   /* start_decompress done, read_raw_data OK */
+    static const int DSTATE_BUFIMAGE = 207; /* expecting jpeg_start_output */
+    static const int DSTATE_BUFPOST = 208;  /* looking for SOS/EOI in jpeg_finish_output */
+    static const int DSTATE_RDCOEFS = 209;  /* reading file in jpeg_read_coefficients */
+    static const int DSTATE_STOPPING = 210; /* looking for EOI in jpeg_finish_decompress */
+
+    static const int JPEG_REACHED_SOS = 1; /* Reached start of new scan */
+    static const int JPEG_REACHED_EOI = 2; /* Reached end of image */
+    static const int JPEG_ROW_COMPLETED = 3; /* Completed one iMCU row */
+    static const int JPEG_SCAN_COMPLETED = 4; /* Completed last iMCU row of a scan */
+
+    static const int JPEG_SUSPENDED = 0; /* Suspended due to lack of input data */
+    static const int JPEG_HEADER_OK = 1; /* Found valid image datastream */
+    static const int JPEG_HEADER_TABLES_ONLY = 2; /* Found valid table-specs-only datastream */
 
     /* Function pointers */
-    static final int DECOMPRESS_DATA = 0;
-    static final int DECOMPRESS_SMOOTH_DATA = 1;
-    static final int DECOMPRESS_ONEPASS = 2;
-    
-    static final int CONSUME_DATA = 0;
-    static final int DUMMY_CONSUME_DATA = 1;
-    
-    static final int PROCESS_DATA_SIMPLE_MAIN = 0;
-    static final int PROCESS_DATA_CONTEXT_MAIN = 1;
-    static final int PROCESS_DATA_CRANK_POST = 2;
-    
-    static final int POST_PROCESS_1PASS = 0;
-    static final int POST_PROCESS_DATA_UPSAMPLE = 1;
-    
-    static final int NULL_CONVERT = 0;
-    static final int GRAYSCALE_CONVERT = 1;
-    static final int YCC_RGB_CONVERT = 2;
-    static final int GRAY_RGB_CONVERT = 3;
-    static final int YCCK_CMYK_CONVERT = 4;
-    
-    static final int NOOP_UPSAMPLE = 0;
-    static final int FULLSIZE_UPSAMPLE = 1;
-    static final int H2V1_FANCY_UPSAMPLE = 2;
-    static final int H2V1_UPSAMPLE = 3;
-    static final int H2V2_FANCY_UPSAMPLE = 4;
-    static final int H2V2_UPSAMPLE = 5;
-    static final int INT_UPSAMPLE = 6;
-    
-    static final int INPUT_CONSUME_INPUT = 0;
-    static final int COEF_CONSUME_INPUT = 1;
-    
+    static const int DECOMPRESS_DATA = 0;
+    static const int DECOMPRESS_SMOOTH_DATA = 1;
+    static const int DECOMPRESS_ONEPASS = 2;
+
+    static const int CONSUME_DATA = 0;
+    static const int DUMMY_CONSUME_DATA = 1;
+
+    static const int PROCESS_DATA_SIMPLE_MAIN = 0;
+    static const int PROCESS_DATA_CONTEXT_MAIN = 1;
+    static const int PROCESS_DATA_CRANK_POST = 2;
+
+    static const int POST_PROCESS_1PASS = 0;
+    static const int POST_PROCESS_DATA_UPSAMPLE = 1;
+
+    static const int NULL_CONVERT = 0;
+    static const int GRAYSCALE_CONVERT = 1;
+    static const int YCC_RGB_CONVERT = 2;
+    static const int GRAY_RGB_CONVERT = 3;
+    static const int YCCK_CMYK_CONVERT = 4;
+
+    static const int NOOP_UPSAMPLE = 0;
+    static const int FULLSIZE_UPSAMPLE = 1;
+    static const int H2V1_FANCY_UPSAMPLE = 2;
+    static const int H2V1_UPSAMPLE = 3;
+    static const int H2V2_FANCY_UPSAMPLE = 4;
+    static const int H2V2_UPSAMPLE = 5;
+    static const int INT_UPSAMPLE = 6;
+
+    static const int INPUT_CONSUME_INPUT = 0;
+    static const int COEF_CONSUME_INPUT = 1;
+
     static int extend_test[] =   /* entry n is 2**(n-1) */
-    {
+    [
         0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
         0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000
-    };
+    ];
 
     static int extend_offset[] = /* entry n is (-1 << n) + 1 */
-    {
+    [
         0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
         ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
         ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
         ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1
-    };
-    
-    static int jpeg_natural_order[] = {
+    ];
+
+    static int jpeg_natural_order[] = [
         0,  1,  8, 16,  9,  2,  3, 10,
         17, 24, 32, 25, 18, 11, 4,  5,
         12, 19, 26, 33, 40, 48, 41, 34,
@@ -224,40 +230,40 @@
         53, 60, 61, 54, 47, 55, 62, 63,
         63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
         63, 63, 63, 63, 63, 63, 63, 63
-    };
-    
+    ];
+
     static final class JQUANT_TBL {
         /* This array gives the coefficient quantizers in natural array order
          * (not the zigzag order in which they are stored in a JPEG DQT marker).
          * CAUTION: IJG versions prior to v6a kept this array in zigzag order.
          */
-        short[] quantval = new short[DCTSIZE2]; /* quantization step for each coefficient */
+        short[DCTSIZE2] quantval;// = new short[DCTSIZE2];  /* quantization step for each coefficient */
         /* This field is used only during compression.  It's initialized false when
          * the table is created, and set true when it's been output to the file.
          * You could suppress output of a table by setting this to true.
          * (See jpeg_suppress_tables for an example.)
          */
-        bool sent_table;        /* true when table has been output */
+        bool sent_table;     /* true when table has been output */
     }
-    
+
     static final class JHUFF_TBL {
         /* These two fields directly represent the contents of a JPEG DHT marker */
-        byte[] bits = new byte[17]; /* bits[k] = # of symbols with codes of */
+        byte[17] bits;// = new byte[17]; /* bits[k] = # of symbols with codes of */
                                     /* length k bits; bits[0] is unused */
-        byte[] huffval = new byte[256];     /* The symbols, in order of incr code length */
+        byte[256] huffval;// = new byte[256];       /* The symbols, in order of incr code length */
         /* This field is used only during compression.  It's initialized false when
          * the table is created, and set true when it's been output to the file.
          * You could suppress output of a table by setting this to true.
          * (See jpeg_suppress_tables for an example.)
          */
-        bool sent_table;        /* true when table has been output */
+        bool sent_table;     /* true when table has been output */
     }
-    
+
     static final class bitread_perm_state {     /* Bitreading state saved across MCUs */
         int get_buffer; /* current bit-extraction buffer */
         int bits_left;      /* # of unused bits in it */
     }
-    
+
     static final class bitread_working_state {      /* Bitreading working state within an MCU */
         /* Current data source location */
         /* We need a copy, rather than munging the original, in case of suspension */
@@ -271,18 +277,18 @@
         int bits_left;      /* # of unused bits in it */
         /* Pointer needed by jpeg_fill_bit_buffer. */
         jpeg_decompress_struct cinfo;   /* back link to decompress master record */
-    } 
-    
+    }
+
     static final class savable_state {
         int EOBRUN; //Note that this is only used in the progressive case
-        int[] last_dc_val = new int[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
+        int[MAX_COMPS_IN_SCAN] last_dc_val;// = new int[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
     }
-    
+
     static final class d_derived_tbl {
         /* Basic tables: (element [0] of each array is unused) */
-        int[] maxcode = new int[18];        /* largest code of length k (-1 if none) */
+        int[18] maxcode;// = new int[18];       /* largest code of length k (-1 if none) */
         /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */
-        int[] valoffset = new int[17];      /* huffval[] offset for codes of length k */
+        int[17] valoffset;// = new int[17];     /* huffval[] offset for codes of length k */
         /* valoffset[k] = huffval[] index of 1st symbol of code length k, less
          * the smallest code of length k; so given a code of length k, the
          * corresponding symbol is huffval[code + valoffset[k]]
@@ -296,17 +302,17 @@
          * than HUFF_LOOKAHEAD bits long, we can obtain its length and
          * the corresponding symbol directly from these tables.
          */
-        int[] look_nbits = new int[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
-        byte[] look_sym = new byte[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
-    } 
-    
+        int[1<<HUFF_LOOKAHEAD] look_nbits;// = new int[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
+        byte[1<<HUFF_LOOKAHEAD] look_sym;// = new byte[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
+    }
+
     static final class jpeg_d_coef_controller {
         int consume_data;
         int decompress_data;
 
         /* Pointer to array of coefficient virtual arrays, or null if none */
         short[][][] coef_arrays;
-    
+
         /* These variables keep track of the current location of the input side. */
         /* cinfo.input_iMCU_row is also used for this. */
         int MCU_ctr;        /* counts MCUs processed in current row */
@@ -324,21 +330,21 @@
          * In multi-pass modes, this array points to the current MCU's blocks
          * within the virtual arrays; it is used only by the input side.
          */
-        short[][] MCU_buffer = new short[D_MAX_BLOCKS_IN_MCU][];
+        short[][D_MAX_BLOCKS_IN_MCU] MCU_buffer;// = new short[D_MAX_BLOCKS_IN_MCU][];
 
         /* In multi-pass modes, we need a virtual block array for each component. */
-        short[][][][] whole_image = new short[MAX_COMPONENTS][][][];
+        short[][][][MAX_COMPONENTS] whole_image;// = new short[MAX_COMPONENTS][][][];
 
         /* When doing block smoothing, we latch coefficient Al values here */
         int[] coef_bits_latch;
-        
+
         short[] workspace;
 
         void start_input_pass (jpeg_decompress_struct cinfo) {
             cinfo.input_iMCU_row = 0;
             start_iMCU_row(cinfo);
         }
-        
+
         /* Reset within-iMCU-row counters for a new row (input side) */
         void start_iMCU_row (jpeg_decompress_struct cinfo) {
             jpeg_d_coef_controller coef = cinfo.coef;
@@ -359,46 +365,55 @@
             coef.MCU_ctr = 0;
             coef.MCU_vert_offset = 0;
         }
-        
+
     }
-    
+
     static abstract class jpeg_entropy_decoder {
         abstract void start_pass (jpeg_decompress_struct cinfo);
         abstract bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data);
 
         /* This is here to share code between baseline and progressive decoders; */
         /* other modules probably should not use it */
-        bool insufficient_data; /* set true after emitting warning */
-        
-        bitread_working_state br_state_local = new bitread_working_state();
-        savable_state state_local = new savable_state();
-    }   
+        bool insufficient_data;  /* set true after emitting warning */
+
+        bitread_working_state br_state_local;
+        savable_state state_local;
+        public this(){
+            br_state_local = new bitread_working_state();
+            state_local = new savable_state();
+        }
+    }
 
     static final class huff_entropy_decoder : jpeg_entropy_decoder {
-        bitread_perm_state bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */
-        savable_state saved = new savable_state();      /* Other state at start of MCU */
+        bitread_perm_state bitstate;// = new bitread_perm_state();  /* Bit buffer at start of MCU */
+        savable_state saved;// = new savable_state();       /* Other state at start of MCU */
 
         /* These fields are NOT loaded into local working state. */
         int restarts_to_go; /* MCUs left in this restart interval */
 
         /* Pointers to derived tables (these workspaces have image lifespan) */
-        d_derived_tbl[] dc_derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS];
-        d_derived_tbl[] ac_derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS];
+        d_derived_tbl[NUM_HUFF_TBLS] dc_derived_tbls;// = new d_derived_tbl[NUM_HUFF_TBLS];
+        d_derived_tbl[NUM_HUFF_TBLS] ac_derived_tbls;// = new d_derived_tbl[NUM_HUFF_TBLS];
 
         /* Precalculated info set up by start_pass for use in decode_mcu: */
 
         /* Pointers to derived tables to be used for each block within an MCU */
-        d_derived_tbl[] dc_cur_tbls = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU];
-        d_derived_tbl[] ac_cur_tbls = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU];
+        d_derived_tbl[D_MAX_BLOCKS_IN_MCU] dc_cur_tbls;// = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU];
+        d_derived_tbl[D_MAX_BLOCKS_IN_MCU] ac_cur_tbls;// = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU];
         /* Whether we care about the DC and AC coefficient values for each block */
-        bool[] dc_needed = new bool[D_MAX_BLOCKS_IN_MCU];
-        bool[] ac_needed = new bool[D_MAX_BLOCKS_IN_MCU];
-        
-        void start_pass (jpeg_decompress_struct cinfo) {
+        bool[D_MAX_BLOCKS_IN_MCU] dc_needed;// = new bool[D_MAX_BLOCKS_IN_MCU];
+        bool[D_MAX_BLOCKS_IN_MCU] ac_needed;// = new bool[D_MAX_BLOCKS_IN_MCU];
+
+        public this(){
+            bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */
+            saved = new savable_state();      /* Other state at start of MCU */
+        }
+
+        override void start_pass (jpeg_decompress_struct cinfo) {
             start_pass_huff_decoder(cinfo);
         }
 
-        bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) {
+        override bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) {
             huff_entropy_decoder entropy = this;
             int blkn;
 //          BITREAD_STATE_VARS;
@@ -424,12 +439,12 @@
                 /* Load up working state */
 //              BITREAD_LOAD_STATE(cinfo,entropy.bitstate);
                 br_state.cinfo = cinfo;
-                br_state.buffer = cinfo.buffer; 
+                br_state.buffer = cinfo.buffer;
                 br_state.bytes_in_buffer = cinfo.bytes_in_buffer;
                 br_state.bytes_offset = cinfo.bytes_offset;
                 get_buffer = entropy.bitstate.get_buffer;
                 bits_left = entropy.bitstate.bits_left;
-                    
+
 //              ASSIGN_STATE(state, entropy.saved);
                 state.last_dc_val[0] = entropy.saved.last_dc_val[0];
                 state.last_dc_val[1] = entropy.saved.last_dc_val[1];
@@ -466,7 +481,7 @@
                     }
 //                  look = PEEK_BITS(HUFF_LOOKAHEAD);
                     if (nb !is 1) {
-                        look = (( (get_buffer >> (bits_left -   cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1));
+                        look = (( (get_buffer >> (bits_left -   (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
                         if ((nb = dctbl.look_nbits[look]) !is 0) {
 //                          DROP_BITS(nb);
                             bits_left -= nb;
@@ -489,7 +504,7 @@
                             if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) {
                                 return false;
                             }
-                            get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
+                            get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                         }
                         }
 //                      r = GET_BITS(s);
@@ -512,7 +527,7 @@
                         /* Section F.2.2.2: decode the AC coefficients */
                         /* Since zeroes are skipped, output area must be cleared beforehand */
                         for (k = 1; k < DCTSIZE2; k++) {
-//                          HUFF_DECODE(s, br_state, actbl, return FALSE, label2);  
+//                          HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
                             {
                             int nb = 0, look;
                             if (bits_left < HUFF_LOOKAHEAD) {
@@ -521,7 +536,7 @@
                                 }
                                 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                                 if (bits_left < HUFF_LOOKAHEAD) {
-                                    nb = 1; 
+                                    nb = 1;
 //                                  goto slowlabel;
                                     if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb)) < 0) {
                                         return false;
@@ -531,7 +546,7 @@
                             }
                             if (nb !is 1) {
 //                              look = PEEK_BITS(HUFF_LOOKAHEAD);
-                                look = (( (get_buffer >> (bits_left -   cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1));
+                                look = (( (get_buffer >> (bits_left -   (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
                                 if ((nb = actbl.look_nbits[look]) !is 0) {
 //                                  DROP_BITS(nb);
                                     bits_left -= (nb);
@@ -545,10 +560,10 @@
                                     get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                                 }
                             }
-                            }           
+                            }
                             r = s >> 4;
                             s &= 15;
-                        
+
                             if (s !is 0) {
                                 k += r;
 //                              CHECK_BIT_BUFFER(br_state, s, return FALSE);
@@ -557,8 +572,8 @@
                                     if (!jpeg_fill_bit_buffer(br_state, get_buffer, bits_left, s)) {
                                         return false;
                                     }
-                                    get_buffer = (br_state).get_buffer;
-                                    bits_left = (br_state).bits_left;
+                                    get_buffer = br_state.get_buffer;
+                                    bits_left = br_state.bits_left;
                                 }
                                 }
 //                              r = GET_BITS(s);
@@ -604,7 +619,7 @@
                             }
                             if (nb !is 1) {
 //                              look = PEEK_BITS(HUFF_LOOKAHEAD);
-                                look = (( (get_buffer >> (bits_left -   cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1));
+                                look = (( (get_buffer >> (bits_left -   (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
                                 if ((nb = actbl.look_nbits[look]) !is 0) {
 //                                  DROP_BITS(nb);
                                     bits_left -= (nb);
@@ -618,19 +633,19 @@
                                     get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                                 }
                             }
-                            }           
+                            }
                             r = s >> 4;
                             s &= 15;
-                        
+
                             if (s !is 0) {
                                 k += r;
 //                              CHECK_BIT_BUFFER(br_state, s, return FALSE);
                                 {
                                 if (bits_left < (s)) {
-                                    if (!jpeg_fill_bit_buffer((br_state),get_buffer,bits_left,s)) {
+                                    if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) {
                                         return false;
                                     }
-                                    get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
+                                    get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                                     }
                                 }
 //                              DROP_BITS(s);
@@ -715,7 +730,7 @@
             /* Initialize restart counter */
             entropy.restarts_to_go = cinfo.restart_interval;
         }
-    
+
         bool process_restart (jpeg_decompress_struct cinfo) {
             huff_entropy_decoder entropy = this;
             int ci;
@@ -747,30 +762,35 @@
             return true;
         }
     }
-    
+
     static final class phuff_entropy_decoder : jpeg_entropy_decoder {
 
         /* These fields are loaded into local variables at start of each MCU.
          * In case of suspension, we exit WITHOUT updating them.
          */
-        bitread_perm_state bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */
-        savable_state saved = new savable_state();      /* Other state at start of MCU */
+        bitread_perm_state bitstate;// = new bitread_perm_state();  /* Bit buffer at start of MCU */
+        savable_state saved;// = new savable_state();       /* Other state at start of MCU */
 
         /* These fields are NOT loaded into local working state. */
         int restarts_to_go; /* MCUs left in this restart interval */
 
         /* Pointers to derived tables (these workspaces have image lifespan) */
-        d_derived_tbl[] derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS];
+        d_derived_tbl[NUM_HUFF_TBLS] derived_tbls;// = new d_derived_tbl[NUM_HUFF_TBLS];
 
         d_derived_tbl ac_derived_tbl; /* active table during an AC scan */
-        
-        int[] newnz_pos = new int[DCTSIZE2];
-            
-        void start_pass (jpeg_decompress_struct cinfo) {
+
+        int[DCTSIZE2] newnz_pos;// = new int[DCTSIZE2];
+
+        public this(){
+            bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */
+            saved = new savable_state();      /* Other state at start of MCU */
+        }
+
+        override void start_pass (jpeg_decompress_struct cinfo) {
             start_pass_phuff_decoder(cinfo);
         }
-            
-        bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) {
+
+        override bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) {
             bool is_DC_band = (cinfo.Ss is 0);
             if (cinfo.Ah is 0) {
                 if (is_DC_band)
@@ -784,7 +804,7 @@
                     return decode_mcu_AC_refine(cinfo, MCU_data);
             }
         }
-            
+
         bool decode_mcu_DC_refine (jpeg_decompress_struct cinfo, short[][] MCU_data) {
             phuff_entropy_decoder entropy = this;
             int p1 = 1 << cinfo.Al; /* 1 in the bit position being coded */
@@ -795,7 +815,7 @@
             int bits_left;
 //          bitread_working_state br_state = new bitread_working_state();
             bitread_working_state br_state = br_state_local;
-                    
+
             /* Process restart marker if needed; may have to suspend */
             if (cinfo.restart_interval !is 0) {
                 if (entropy.restarts_to_go is 0)
@@ -810,12 +830,12 @@
             /* Load up working state */
 //          BITREAD_LOAD_STATE(cinfo,entropy.bitstate);
             br_state.cinfo = cinfo;
-            br_state.buffer = cinfo.buffer; 
+            br_state.buffer = cinfo.buffer;
             br_state.bytes_in_buffer = cinfo.bytes_in_buffer;
             br_state.bytes_offset = cinfo.bytes_offset;
             get_buffer = entropy.bitstate.get_buffer;
             bits_left = entropy.bitstate.bits_left;
-                    
+
             /* Outer loop handles each block in the MCU */
 
             for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) {
@@ -828,7 +848,7 @@
                     if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) {
                          return false;
                     }
-                    get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
+                    get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                 }
                 }
 //              if (GET_BITS(1))
@@ -844,14 +864,14 @@
             cinfo.bytes_offset = br_state.bytes_offset;
             entropy.bitstate.get_buffer = get_buffer;
             entropy.bitstate.bits_left = bits_left;
-                    
+
             /* Account for restart interval (no-op if not using restarts) */
             entropy.restarts_to_go--;
 
             return true;
 
         }
-            
+
         bool decode_mcu_AC_refine (jpeg_decompress_struct cinfo, short[][] MCU_data) {
             phuff_entropy_decoder entropy = this;
             int Se = cinfo.Se;
@@ -866,7 +886,7 @@
             int bits_left;
 //          bitread_working_state br_state = new bitread_working_state();
             bitread_working_state br_state = br_state_local;
-                
+
             d_derived_tbl tbl;
             int num_newnz;
             int[] newnz_pos = entropy.newnz_pos;
@@ -885,12 +905,12 @@
                 /* Load up working state */
 //              BITREAD_LOAD_STATE(cinfo,entropy.bitstate);
                 br_state.cinfo = cinfo;
-                br_state.buffer = cinfo.buffer; 
+                br_state.buffer = cinfo.buffer;
                 br_state.bytes_in_buffer = cinfo.bytes_in_buffer;
                 br_state.bytes_offset = cinfo.bytes_offset;
                 get_buffer = entropy.bitstate.get_buffer;
                 bits_left = entropy.bitstate.bits_left;
-                    
+
                 EOBRUN = entropy.saved.EOBRUN; /* only part of saved state we need */
 
                 /* There is always only one block per MCU */
@@ -923,7 +943,7 @@
                             }
                             get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                             if (bits_left < HUFF_LOOKAHEAD) {
-                                nb = 1; 
+                                nb = 1;
 //                              goto slowlabel;
                                 if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) {
 //                                  failaction;
@@ -937,7 +957,7 @@
                         }
                         if (nb !is 1) {
 //                          look = PEEK_BITS(HUFF_LOOKAHEAD);
-                            look = (( (get_buffer >> (bits_left -   cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1));
+                            look = (( (get_buffer >> (bits_left -   (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
                             if ((nb = tbl.look_nbits[look]) !is 0) {
 //                              DROP_BITS(nb);
                                 bits_left -= nb;
@@ -945,7 +965,7 @@
                             } else {
                                 nb = HUFF_LOOKAHEAD+1;
 //                              slowlabel:
-                                if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) { 
+                                if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) {
 //                                  failaction;
                                     while (num_newnz > 0)
                                         block[newnz_pos[--num_newnz]] = 0;
@@ -959,7 +979,7 @@
                         r = s >> 4;
                         s &= 15;
                         if (s !is 0) {
-                            if (s !is 1) {      /* size of new coef should always be 1 */
+                            if (s !is 1) {       /* size of new coef should always be 1 */
 //                              WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
                             }
 //                          CHECK_BIT_BUFFER(br_state, 1, goto undoit);
@@ -972,7 +992,7 @@
 
                                     return false;
                                 }
-                                get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
+                                get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                                 }
                             }
 //                          if (GET_BITS(1))
@@ -994,7 +1014,7 @@
 
                                             return false;
                                         }
-                                        get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
+                                        get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                                     }
                                     }
 //                                  r = GET_BITS(r);
@@ -1023,7 +1043,7 @@
 
                                         return false;
                                     }
-                                    get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
+                                    get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                                 }
                                 }
 //                              if (GET_BITS(1)) {
@@ -1068,10 +1088,10 @@
 //                                  failaction;
                                     while (num_newnz > 0)
                                         block[newnz_pos[--num_newnz]] = 0;
-    
+
                                     return false;
                                 }
-                                get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
+                                get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                             }
                             }
 //                          if (GET_BITS(1)) {
@@ -1096,7 +1116,7 @@
                 cinfo.bytes_offset = br_state.bytes_offset;
                 entropy.bitstate.get_buffer = get_buffer;
                 entropy.bitstate.bits_left = bits_left;
-                        
+
                 entropy.saved.EOBRUN = EOBRUN; /* only part of saved state we need */
             }
 
@@ -1112,8 +1132,8 @@
 //
 //              return false;
 
-        }           
-            
+        }
+
         bool decode_mcu_AC_first (jpeg_decompress_struct cinfo, short[][] MCU_data) {
             phuff_entropy_decoder entropy = this;
             int Se = cinfo.Se;
@@ -1126,7 +1146,7 @@
             int bits_left;
 //          bitread_working_state br_state = new bitread_working_state();
             bitread_working_state br_state = br_state_local;
-                    
+
             d_derived_tbl tbl;
 
             /* Process restart marker if needed; may have to suspend */
@@ -1153,12 +1173,12 @@
                 else {
 //                  BITREAD_LOAD_STATE(cinfo,entropy.bitstate);
                     br_state.cinfo = cinfo;
-                    br_state.buffer = cinfo.buffer; 
+                    br_state.buffer = cinfo.buffer;
                     br_state.bytes_in_buffer = cinfo.bytes_in_buffer;
                     br_state.bytes_offset = cinfo.bytes_offset;
                     get_buffer = entropy.bitstate.get_buffer;
                     bits_left = entropy.bitstate.bits_left;
-                        
+
                     block = MCU_data[0];
                     tbl = entropy.ac_derived_tbl;
 
@@ -1182,7 +1202,7 @@
                         }
                         if (nb !is 1) {
 //                          look = PEEK_BITS(HUFF_LOOKAHEAD);
-                            look = (( (get_buffer >> (bits_left -   cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1));
+                            look = (( (get_buffer >> (bits_left -   (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
 
                             if ((nb = tbl.look_nbits[look]) !is 0) {
 //                              DROP_BITS(nb);
@@ -1208,7 +1228,7 @@
                                 if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) {
                                     return false;
                                 }
-                                get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
+                                get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                             }
                             }
 //                          r = GET_BITS(s);
@@ -1222,14 +1242,14 @@
                                 k += 15;        /* skip 15 zeroes in band */
                             } else {        /* EOBr, run length is 2^r + appended bits */
                                 EOBRUN = 1 << r;
-                                if (r !is 0) {      /* EOBr, r > 0 */
+                                if (r !is 0) {       /* EOBr, r > 0 */
 //                                  CHECK_BIT_BUFFER(br_state, r, return FALSE);
                                     {
                                     if (bits_left < (r)) {
                                         if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,r)) {
                                             return false;
                                         }
-                                        get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
+                                        get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                                     }
                                     }
 //                                  r = GET_BITS(r);
@@ -1259,8 +1279,8 @@
 
             return true;
         }
-            
-        bool decode_mcu_DC_first (jpeg_decompress_struct cinfo, short[][] MCU_data) {    
+
+        bool decode_mcu_DC_first (jpeg_decompress_struct cinfo, short[][] MCU_data) {     
             phuff_entropy_decoder entropy = this;
             int Al = cinfo.Al;
             int s = 0, r;
@@ -1271,7 +1291,7 @@
             int bits_left;
 //          bitread_working_state br_state = new bitread_working_state();
             bitread_working_state br_state = br_state_local;
-                
+
 //          savable_state state = new savable_state();
             savable_state state = state_local;
             d_derived_tbl tbl;
@@ -1292,19 +1312,19 @@
                 /* Load up working state */
 //              BITREAD_LOAD_STATE(cinfo,entropy.bitstate);
                 br_state.cinfo = cinfo;
-                br_state.buffer = cinfo.buffer; 
+                br_state.buffer = cinfo.buffer;
                 br_state.bytes_in_buffer = cinfo.bytes_in_buffer;
                 br_state.bytes_offset = cinfo.bytes_offset;
                 get_buffer = entropy.bitstate.get_buffer;
                 bits_left = entropy.bitstate.bits_left;
-                    
+
 //              ASSIGN_STATE(state, entropy.saved);
                 state.EOBRUN = entropy.saved.EOBRUN;
                 state.last_dc_val[0] = entropy.saved.last_dc_val[0];
                 state.last_dc_val[1] = entropy.saved.last_dc_val[1];
                 state.last_dc_val[2] = entropy.saved.last_dc_val[2];
                 state.last_dc_val[3] = entropy.saved.last_dc_val[3];
-                    
+
                 /* Outer loop handles each block in the MCU */
 
                 for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) {
@@ -1335,7 +1355,7 @@
                     }
                     if (nb !is 1) {
 //                      look = PEEK_BITS(HUFF_LOOKAHEAD);
-                        look = (( (get_buffer >> (bits_left -   cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1));
+                        look = (( (get_buffer >> (bits_left -   (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
 
                         if ((nb = tbl.look_nbits[look]) !is 0) {
 //                          DROP_BITS(nb);
@@ -1358,7 +1378,7 @@
                             if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) {
                                 return false;
                             }
-                            get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
+                            get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
                         }
                         }
 //                      r = GET_BITS(s);
@@ -1394,7 +1414,7 @@
 
             return true;
         }
-            
+
         bool process_restart (jpeg_decompress_struct cinfo) {
             phuff_entropy_decoder entropy = this;
             int ci;
@@ -1531,7 +1551,7 @@
         }
 
     }
-    
+
     static final class jpeg_component_info {
         /* These values are fixed over the whole image. */
         /* For compression, they must be supplied by parameter setup; */
@@ -1547,9 +1567,9 @@
         /* The decompressor output side may not use these variables. */
         int dc_tbl_no;      /* DC entropy table selector (0..3) */
         int ac_tbl_no;      /* AC entropy table selector (0..3) */
-        
+
         /* Remaining fields should be treated as private by applications. */
-        
+
         /* These values are computed during compression or decompression startup: */
         /* Component's size in DCT blocks.
          * Any dummy blocks added to complete an MCU are not counted; therefore
@@ -1576,7 +1596,7 @@
          * components will be ignored (eg grayscale output from YCbCr image),
          * we can skip most computations for the unused components.
          */
-        bool component_needed;  /* do we need the value of this component? */
+        bool component_needed;   /* do we need the value of this component? */
 
         /* These values are computed before starting a scan of the component. */
         /* The decompressor output side may not use these variables. */
@@ -1596,7 +1616,7 @@
         /* Private per-component storage for DCT or IDCT subsystem. */
         int[] dct_table;
     }
-    
+
     static final class jpeg_color_quantizer {
 //      JMETHOD(void, start_pass, (j_decompress_ptr cinfo, bool is_pre_scan));
 //      JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
@@ -1604,7 +1624,7 @@
 //                   int num_rows));
 //      JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
 //      JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
-        
+
         /* Initially allocated colormap is saved here */
         int[][] sv_colormap;    /* The color map as a 2-D pixel array */
         int sv_actual;      /* number of entries in use */
@@ -1614,9 +1634,9 @@
          * premultiplied as described above.    Since colormap indexes must fit into
          * JSAMPLEs, the entries of this array will too.
          */
-        bool is_padded;     /* is the colorindex padded for odither? */
-
-        int[] Ncolors = new int [MAX_Q_COMPS];  /* # of values alloced to each component */
+        bool is_padded;      /* is the colorindex padded for odither? */
+
+        int[MAX_Q_COMPS] Ncolors;// = new int [MAX_Q_COMPS];    /* # of values alloced to each component */
 
         /* Variables for ordered dithering */
         int row_index;      /* cur row's vertical index in dither matrix */
@@ -1624,13 +1644,13 @@
 
         /* Variables for Floyd-Steinberg dithering */
 //          FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
-        bool on_odd_row;    
-            
+        bool on_odd_row; 
+
         void start_pass (jpeg_decompress_struct cinfo, bool is_pre_scan) {
             error();
         }
     }
-    
+
     static final class jpeg_upsampler {
 //      JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
 //      JMETHOD(void, upsample, (j_decompress_ptr cinfo,
@@ -1641,8 +1661,8 @@
 //                   JDIMENSION *out_row_ctr,
 //                   JDIMENSION out_rows_avail));
 
-        bool need_context_rows; /* TRUE if need rows above & below */
-            
+        bool need_context_rows;  /* TRUE if need rows above & below */
+
         /* Color conversion buffer. When using separate upsampling and color
          * conversion steps, this buffer holds one upsampled row group until it
          * has been color converted and output.
@@ -1650,24 +1670,24 @@
          * ie do not need rescaling.    The corresponding entry of color_buf[] is
          * simply set to point to the input data array, thereby avoiding copying.
          */
-        byte[][][] color_buf = new byte[MAX_COMPONENTS][][];
-        int[] color_buf_offset = new int[MAX_COMPONENTS];
+        byte[][][MAX_COMPONENTS] color_buf;// = new byte[MAX_COMPONENTS][][];
+        int[MAX_COMPONENTS] color_buf_offset;// = new int[MAX_COMPONENTS];
 
         /* Per-component upsampling method pointers */
-        int[] methods = new int[MAX_COMPONENTS];
+        int[MAX_COMPONENTS] methods;// = new int[MAX_COMPONENTS];
 
         int next_row_out;       /* counts rows emitted from color_buf */
         int rows_to_go; /* counts rows remaining in image */
 
         /* Height of an input row group for each component. */
-        int[] rowgroup_height = new int[MAX_COMPONENTS];
+        int[MAX_COMPONENTS] rowgroup_height;// = new int[MAX_COMPONENTS];
 
         /* These arrays save pixel expansion factors so that int_expand need not
          * recompute them each time.    They are unused for other upsampling methods.
          */
-        byte[] h_expand = new byte[MAX_COMPONENTS];
-        byte[] v_expand = new byte[MAX_COMPONENTS];
-            
+        byte[MAX_COMPONENTS] h_expand;// = new byte[MAX_COMPONENTS];
+        byte[MAX_COMPONENTS] v_expand;// = new byte[MAX_COMPONENTS];
+
         void start_pass (jpeg_decompress_struct cinfo) {
             jpeg_upsampler upsample = cinfo.upsample;
 
@@ -1676,9 +1696,9 @@
             /* Initialize total-height counter for detecting bottom of image */
             upsample.rows_to_go = cinfo.output_height;
         }
-            
+
     }
-    
+
     static final class jpeg_marker_reader {
         /* Read a restart marker --- exported for use by entropy decoder only */
 //      jpeg_marker_parser_method read_restart_marker;
@@ -1686,48 +1706,48 @@
         /* State of marker reader --- nominally internal, but applications
          * supplying COM or APPn handlers might like to know the state.
          */
-        bool saw_SOI;       /* found SOI? */
-        bool saw_SOF;       /* found SOF? */
+        bool saw_SOI;        /* found SOI? */
+        bool saw_SOF;        /* found SOF? */
         int next_restart_num;       /* next restart number expected (0-7) */
         int discarded_bytes;    /* # of bytes skipped looking for a marker */
-        
+
         /* Application-overridable marker processing methods */
 //      jpeg_marker_parser_method process_COM;
 //      jpeg_marker_parser_method process_APPn[16];
 
         /* Limit on marker data length to save for each marker type */
         int length_limit_COM;
-        int[] length_limit_APPn = new int[16];
+        int[16] length_limit_APPn;// = new int[16];
 
         /* Status of COM/APPn marker saving */
 //      jpeg_marker_reader cur_marker;  /* null if not processing a marker */
 //      int bytes_read;     /* data bytes read so far in marker */
         /* Note: cur_marker is not linked into marker_list until it's all read. */
     }
-    
-    
+
+
     static final class jpeg_d_main_controller {
 //      JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
         int process_data;
-                
+
          /* Pointer to allocated workspace (M or M+2 row groups). */
-        byte[][][] buffer = new byte[MAX_COMPONENTS][][];
-        int[] buffer_offset = new int[MAX_COMPONENTS];
-
-        bool buffer_full;       /* Have we gotten an iMCU row from decoder? */
-        int[] rowgroup_ctr = new int[1];    /* counts row groups output to postprocessor */
+        byte[][][MAX_COMPONENTS] buffer;// = new byte[MAX_COMPONENTS][][];
+        int[MAX_COMPONENTS] buffer_offset;// = new int[MAX_COMPONENTS];
+
+        bool buffer_full;        /* Have we gotten an iMCU row from decoder? */
+        int[1] rowgroup_ctr;// = new int[1];    /* counts row groups output to postprocessor */
 
         /* Remaining fields are only used in the context case. */
 
         /* These are the master pointers to the funny-order pointer lists. */
-        byte[][][][] xbuffer = new byte[2][][][];   /* pointers to weird pointer lists */
-        int[][] xbuffer_offset = new int[2][];
+        byte[][][][2] xbuffer;// = new byte[2][][][];   /* pointers to weird pointer lists */
+        int[][2] xbuffer_offset;// = new int[2][];
 
         int whichptr;           /* indicates which pointer set is now in use */
         int context_state;      /* process_data state machine status */
         int rowgroups_avail;    /* row groups available to postprocessor */
         int iMCU_row_ctr;   /* counts iMCU rows to detect image top/bot */
-                    
+
         void start_pass (jpeg_decompress_struct cinfo, int pass_mode) {
             jpeg_d_main_controller main = cinfo.main;
 
@@ -1758,7 +1778,7 @@
                     break;
             }
         }
-                    
+
     }
 
     static final class jpeg_decomp_master {
@@ -1778,13 +1798,13 @@
         jpeg_color_quantizer quantizer_1pass;
         jpeg_color_quantizer quantizer_2pass;
     }
-    
+
     static final class jpeg_inverse_dct {
 //      JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
 //      /* It is useful to allow each component to have a separate IDCT method. */
 //      inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
-        int[] cur_method = new int[MAX_COMPONENTS];
-            
+        int[MAX_COMPONENTS] cur_method;// = new int[MAX_COMPONENTS];
+
         void start_pass (jpeg_decompress_struct cinfo) {
             jpeg_inverse_dct idct = cinfo.idct;
             int ci, i;
@@ -1893,7 +1913,7 @@
 //                              4520,   6270,   5906,   5315,   4520,   3552,   2446,   1247
 //                          };
 //                          SHIFT_TEMPS
-//                          
+//
 //                          for (i = 0; i < DCTSIZE2; i++) {
 //                              ifmtbl[i] = DESCALE(MULTIPLY16V16( qtbl.quantval[i], aanscales[i]), CONST_BITS-IFAST_SCALE_BITS);
 //                          }
@@ -1918,8 +1938,8 @@
 //                          i = 0;
 //                          for (row = 0; row < DCTSIZE; row++) {
 //                              for (col = 0; col < DCTSIZE; col++) {
-//                                  fmtbl[i] = cast(FLOAT_MULT_TYPE)
-//                                      (cast(double) qtbl.quantval[i] *
+//                                  fmtbl[i] = (FLOAT_MULT_TYPE)
+//                                      ((double) qtbl.quantval[i] *
 //                                   aanscalefactor[row] * aanscalefactor[col]);
 //                                  i++;
 //                              }
@@ -1935,35 +1955,35 @@
             }
         }
     }
-            
+
     static final class jpeg_input_controller {
         int consume_input;
-        bool has_multiple_scans;    /* True if file has multiple scans */
+        bool has_multiple_scans; /* True if file has multiple scans */
         bool eoi_reached;
 
-        bool inheaders;     /* true until first SOS is reached */
+        bool inheaders;      /* true until first SOS is reached */
     }
-    
+
     static final class  jpeg_color_deconverter {
 //      JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
         int color_convert;
-        
+
         /* Private state for YCC.RGB conversion */
         int[] Cr_r_tab;     /* => table for Cr to R conversion */
         int[] Cb_b_tab;     /* => table for Cb to B conversion */
         int[] Cr_g_tab;     /* => table for Cr to G conversion */
         int[] Cb_g_tab;     /* => table for Cb to G conversion */
-            
+
         void start_pass (jpeg_decompress_struct cinfo) {
             /* no work needed */
         }
 
     }
-        
+
     static final class jpeg_d_post_controller {
 //      JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
         int post_process_data;
-            
+
         /* Color quantization source buffer: this holds output data from
          * the upsample/color conversion step to be passed to the quantizer.
          * For two-pass color quantization, we need a full-image buffer;
@@ -1975,7 +1995,7 @@
         /* for two-pass mode only: */
         int starting_row;   /* row # of first row in current strip */
         int next_row;       /* index of next row to fill/empty in strip */
-                
+
         void start_pass (jpeg_decompress_struct cinfo, int pass_mode) {
             jpeg_d_post_controller post = cinfo.post;
 
@@ -1992,7 +2012,7 @@
 //                      if (post.buffer is null) {
 //                          post.buffer = (*cinfo.mem.access_virt_sarray)
 //                              ((j_common_ptr) cinfo, post.whole_image,
-//                              cast(JDIMENSION) 0, post.strip_height, TRUE);
+//                              (JDIMENSION) 0, post.strip_height, TRUE);
 //                      }
                     } else {
                         /* For single-pass processing without color quantization,
@@ -2024,13 +2044,13 @@
         }
 
     }
-    
+
     static final class jpeg_decompress_struct {
 //      jpeg_error_mgr * err;   /* Error handler module */\
 //      struct jpeg_memory_mgr * mem;   /* Memory manager module */\
 //      struct jpeg_progress_mgr * progress; /* Progress monitor, or null if none */\
 //      void * client_data;     /* Available for use by application */\
-        bool is_decompressor;   /* So common code can tell which is which */
+        bool is_decompressor;    /* So common code can tell which is which */
         int global_state;       /* For checking call sequence validity */
 
 //      /* Source of compressed data */
@@ -2060,22 +2080,22 @@
 
         double output_gamma;        /* image gamma wanted in output */
 
-        bool buffered_image;    /* true=multiple output passes */
-        bool raw_data_out;      /* true=downsampled data wanted */
+        bool buffered_image; /* true=multiple output passes */
+        bool raw_data_out;       /* true=downsampled data wanted */
 
         int dct_method; /* IDCT algorithm selector */
-        bool do_fancy_upsampling;   /* true=apply fancy upsampling */
-        bool do_block_smoothing;    /* true=apply interblock smoothing */
-
-        bool quantize_colors;   /* true=colormapped output wanted */
+        bool do_fancy_upsampling;    /* true=apply fancy upsampling */
+        bool do_block_smoothing; /* true=apply interblock smoothing */
+
+        bool quantize_colors;    /* true=colormapped output wanted */
         /* the following are ignored if not quantize_colors: */
         int dither_mode;    /* type of color dithering to use */
-        bool two_pass_quantize; /* true=use two-pass color quantization */
+        bool two_pass_quantize;  /* true=use two-pass color quantization */
         int desired_number_of_colors;   /* max # colors to use in created colormap */
         /* these are significant only in buffered-image mode: */
-        bool enable_1pass_quant;    /* enable future use of 1-pass quantizer */
+        bool enable_1pass_quant; /* enable future use of 1-pass quantizer */
         bool enable_external_quant;/* enable future use of external colormap */
-        bool enable_2pass_quant;    /* enable future use of 2-pass quantizer */
+        bool enable_2pass_quant; /* enable future use of 2-pass quantizer */
 
         /* Description of actual output image that will be returned to application.
          * These fields are computed by jpeg_start_decompress().
@@ -2088,7 +2108,7 @@
         int out_color_components;   /* # of color components in out_color_space */
         int output_components;  /* # of color components returned */
         /* output_components is 1 (a colormap index) when quantizing colors;
-         * otherwise it opEquals out_color_components.
+         * otherwise it equals out_color_components.
          */
         int rec_outbuf_height;  /* min recommended height of scanline buffer */
         /* If the buffer passed to jpeg_read_scanlines() is less than this many rows
@@ -2146,11 +2166,11 @@
          * datastreams when processing abbreviated JPEG datastreams.
          */
 
-        JQUANT_TBL[] quant_tbl_ptrs = new JQUANT_TBL[NUM_QUANT_TBLS];
+        JQUANT_TBL[NUM_QUANT_TBLS] quant_tbl_ptrs;// = new JQUANT_TBL[NUM_QUANT_TBLS];
         /* ptrs to coefficient quantization tables, or null if not defined */
 
-        JHUFF_TBL[] dc_huff_tbl_ptrs = new JHUFF_TBL[NUM_HUFF_TBLS];
-        JHUFF_TBL[] ac_huff_tbl_ptrs = new JHUFF_TBL[NUM_HUFF_TBLS];
+        JHUFF_TBL[NUM_HUFF_TBLS] dc_huff_tbl_ptrs;// = new JHUFF_TBL[NUM_HUFF_TBLS];
+        JHUFF_TBL[NUM_HUFF_TBLS] ac_huff_tbl_ptrs;// = new JHUFF_TBL[NUM_HUFF_TBLS];
         /* ptrs to Huffman coding tables, or null if not defined */
 
         /* These parameters are never carried across datastreams, since they
@@ -2162,29 +2182,29 @@
         jpeg_component_info[] comp_info;
         /* comp_info[i] describes component that appears i'th in SOF */
 
-        bool progressive_mode;  /* true if SOFn specifies progressive mode */
-        bool arith_code;        /* true=arithmetic coding, false=Huffman */
-
-        byte[] arith_dc_L = new byte[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
-        byte[] arith_dc_U = new byte[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
-        byte[] arith_ac_K = new byte[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
+        bool progressive_mode;   /* true if SOFn specifies progressive mode */
+        bool arith_code;     /* true=arithmetic coding, false=Huffman */
+
+        byte[NUM_ARITH_TBLS] arith_dc_L;// = new byte[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
+        byte[NUM_ARITH_TBLS] arith_dc_U;// = new byte[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
+        byte[NUM_ARITH_TBLS] arith_ac_K;// = new byte[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
 
         int restart_interval; /* MCUs per restart interval, or 0 for no restart */
 
         /* These fields record data obtained from optional markers recognized by
          * the JPEG library.
          */
-        bool saw_JFIF_marker;   /* true iff a JFIF APP0 marker was found */
+        bool saw_JFIF_marker;    /* true iff a JFIF APP0 marker was found */
         /* Data copied from JFIF marker; only valid if saw_JFIF_marker is true: */
         byte JFIF_major_version;    /* JFIF version number */
         byte JFIF_minor_version;
         byte density_unit;      /* JFIF code for pixel size units */
         short X_density;        /* Horizontal pixel density */
         short Y_density;        /* Vertical pixel density */
-        bool saw_Adobe_marker;  /* true iff an Adobe APP14 marker was found */
+        bool saw_Adobe_marker;   /* true iff an Adobe APP14 marker was found */
         byte Adobe_transform;   /* Color transform code from Adobe marker */
 
-        bool CCIR601_sampling;  /* true=first samples are cosited */
+        bool CCIR601_sampling;   /* true=first samples are cosited */
 
         /* Aside from the specific data retained from APPn markers known to the
          * library, the uninterpreted contents of any or all APPn and COM markers
@@ -2222,14 +2242,14 @@
          * Note that the decompressor output side must not use these fields.
          */
         int comps_in_scan;      /* # of JPEG components in this scan */
-        jpeg_component_info[] cur_comp_info = new jpeg_component_info[MAX_COMPS_IN_SCAN];
+        jpeg_component_info[MAX_COMPS_IN_SCAN] cur_comp_info;// = new jpeg_component_info[MAX_COMPS_IN_SCAN];
         /* *cur_comp_info[i] describes component that appears i'th in SOS */
 
         int MCUs_per_row;   /* # of MCUs across the image */
         int MCU_rows_in_scan;   /* # of MCU rows in the image */
 
         int blocks_in_MCU;      /* # of DCT blocks per MCU */
-        int[] MCU_membership = new int[D_MAX_BLOCKS_IN_MCU];
+        int[D_MAX_BLOCKS_IN_MCU] MCU_membership;// = new int[D_MAX_BLOCKS_IN_MCU];
         /* MCU_membership[i] is index in cur_comp_info of component owning */
         /* i'th block in an MCU */
 
@@ -2240,9 +2260,9 @@
          * read from the data source, but has not yet been processed.
          */
         int unread_marker;
-        
-        int[] workspace = new int[DCTSIZE2];
-        int[] row_ctr = new int[1];
+
+        int[DCTSIZE2] workspace;// = new int[DCTSIZE2];
+        int[1] row_ctr;// = new int[1];
 
         /*
          * Links to decompression subobjects (methods, private variables of modules)
@@ -2316,11 +2336,12 @@
             if (cinfo.progressive_mode)
                 access_rows *= 3;
 //#endif
-            coef.whole_image[ci] = 
-                new short
-                    [cast(int)jround_up( compptr.height_in_blocks, compptr.v_samp_factor)]
-                    [cast(int)jround_up( compptr.width_in_blocks, compptr.h_samp_factor)]
-                    [DCTSIZE2];
+            coef.whole_image[ci] =
+                new short[][][](
+                    cast(int)jround_up( compptr.height_in_blocks, compptr.v_samp_factor),
+                    cast(int)jround_up( compptr.width_in_blocks, compptr.h_samp_factor),
+                    DCTSIZE2
+                    );
         }
 //      coef.consume_data = consume_data;
         coef.decompress_data = DECOMPRESS_DATA;
@@ -2330,7 +2351,9 @@
 //      #endif
     } else {
         /* We only need a single-MCU buffer. */
-        coef.MCU_buffer = new short[D_MAX_BLOCKS_IN_MCU][DCTSIZE2];
+        foreach( inout el; coef.MCU_buffer ){
+            el = new short[](DCTSIZE2);
+        }
 //      coef.consume_data = dummy_consume_data;
         coef.decompress_data = DECOMPRESS_ONEPASS;
         coef.coef_arrays = null; /* flag for no virtual arrays */
@@ -2680,7 +2703,7 @@
 //          post.whole_image = (*cinfo.mem.request_virt_sarray)
 //              ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
 //              cinfo.output_width * cinfo.out_color_components,
-//              cast(JDIMENSION) jround_up(cast(long) cinfo.output_height,
+//              (JDIMENSION) jround_up(cast(long) cinfo.output_height,
 //              cast(long) post.strip_height),
 //   post.strip_height);
 //#else
@@ -2709,7 +2732,7 @@
     int M = cinfo.min_DCT_scaled_size;
     jpeg_component_info compptr;
     byte[][] buf, xbuf0, xbuf1;
-    
+
     for (ci = 0; ci < cinfo.num_components; ci++) {
         compptr = cinfo.comp_info[ci];
         rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) /
@@ -2753,10 +2776,10 @@
     /* Get top-level space for component array pointers.
      * We alloc both arrays with one call to save a few cycles.
      */
-    main.xbuffer[0] = new byte[cinfo.num_components][][];
-    main.xbuffer[1] = new byte[cinfo.num_components][][];
-    main.xbuffer_offset[0] = new int[cinfo.num_components];
-    main.xbuffer_offset[1] = new int[cinfo.num_components];
+    main.xbuffer[0] = new byte[][][](cinfo.num_components);
+    main.xbuffer[1] = new byte[][][](cinfo.num_components);
+    main.xbuffer_offset[0] = new int[](cinfo.num_components);
+    main.xbuffer_offset[1] = new int[](cinfo.num_components);
 
     for (ci = 0; ci < cinfo.num_components; ci++) {
         compptr = cinfo.comp_info[ci];
@@ -2764,7 +2787,7 @@
         /* Get space for pointer lists --- M+4 row groups in each list.
          * We alloc both pointer lists with one call to save a few cycles.
          */
-        xbuf = new byte[2 * (rgroup * (M + 4))][];
+        xbuf = new byte[][](2 * (rgroup * (M + 4)));
         int offset = rgroup;
         main.xbuffer_offset[0][ci] = offset;
         main.xbuffer[0][ci] = xbuf;
@@ -2802,7 +2825,7 @@
     for (ci = 0; ci < cinfo.num_components; ci++) {
         compptr = cinfo.comp_info[ci];
         rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / cinfo.min_DCT_scaled_size; /* height of a row group of component */
-        main.buffer[ci] = new byte[rgroup * ngroups][compptr.width_in_blocks * compptr.DCT_scaled_size];
+        main.buffer[ci] = new byte[][]( rgroup * ngroups, compptr.width_in_blocks * compptr.DCT_scaled_size );
     }
 }
 
@@ -2881,8 +2904,8 @@
             error();
 //          ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
         if (need_buffer) {
-            upsample.color_buf[ci] = new byte[cinfo.max_v_samp_factor]
-                         [cast(int) jround_up(cinfo.output_width, cinfo.max_h_samp_factor)];
+            upsample.color_buf[ci] = new byte[][]( cinfo.max_v_samp_factor,
+                         cast(int) jround_up(cinfo.output_width, cinfo.max_h_samp_factor));
         }
     }
 }
@@ -2895,9 +2918,9 @@
 //  entropy.pub.start_pass = start_pass_phuff_decoder;
 
     /* Create progression status table */
-    cinfo.coef_bits = new int[cinfo.num_components][DCTSIZE2];
+    cinfo.coef_bits = new int[][]( cinfo.num_components, DCTSIZE2 );
     coef_bit_ptr = cinfo.coef_bits;
-    for (ci = 0; ci < cinfo.num_components; ci++) 
+    for (ci = 0; ci < cinfo.num_components; ci++)
         for (i = 0; i < DCTSIZE2; i++)
             coef_bit_ptr[ci][i] = -1;
 }
@@ -2946,11 +2969,11 @@
     int ctr;
     int[] workspace = cinfo.workspace;  /* buffers data between passes */
 //  SHIFT_TEMPS
-    
+
     /* Pass 1: process columns from input, store into work array. */
     /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
     /* furthermore, we scale the results by 2**PASS1_BITS. */
-    
+
     inptr = coef_block;
     quantptr = compptr.dct_table;
     wsptr = workspace;
@@ -2964,7 +2987,7 @@
          * With typical images and quantization tables, half or more of the
          * column DCT calculations can be simplified this way.
          */
-        
+
         if (inptr[DCTSIZE*1+inptr_offset] is 0 && inptr[DCTSIZE*2+inptr_offset] is 0 &&
             inptr[DCTSIZE*3+inptr_offset] is 0 && inptr[DCTSIZE*4+inptr_offset] is 0 &&
             inptr[DCTSIZE*5+inptr_offset] is 0 && inptr[DCTSIZE*6+inptr_offset] is 0 &&
@@ -2972,7 +2995,7 @@
         {
             /* AC terms all zero */
             int dcval = ((inptr[DCTSIZE*0+inptr_offset]) * quantptr[DCTSIZE*0+quantptr_offset]) << PASS1_BITS;
-            
+
             wsptr[DCTSIZE*0+wsptr_offset] = dcval;
             wsptr[DCTSIZE*1+wsptr_offset] = dcval;
             wsptr[DCTSIZE*2+wsptr_offset] = dcval;
@@ -2981,49 +3004,49 @@
             wsptr[DCTSIZE*5+wsptr_offset] = dcval;
             wsptr[DCTSIZE*6+wsptr_offset] = dcval;
             wsptr[DCTSIZE*7+wsptr_offset] = dcval;
-            
+
             inptr_offset++;         /* advance pointers to next column */
             quantptr_offset++;
             wsptr_offset++;
             continue;
         }
-        
+
         /* Even part: reverse the even part of the forward DCT. */
         /* The rotator is sqrt(2)*c(-6). */
-        
+
         z2 = ((inptr[DCTSIZE*2+inptr_offset]) * quantptr[DCTSIZE*2+quantptr_offset]);
         z3 = ((inptr[DCTSIZE*6+inptr_offset]) * quantptr[DCTSIZE*6+quantptr_offset]);
-        
+
         z1 = ((z2 + z3) * 4433/*FIX_0_541196100*/);
         tmp2 = z1 + (z3 * - 15137/*FIX_1_847759065*/);
         tmp3 = z1 + (z2 * 6270/*FIX_0_765366865*/);
-        
+
         z2 = ((inptr[DCTSIZE*0+inptr_offset]) * quantptr[DCTSIZE*0+quantptr_offset]);
         z3 = ((inptr[DCTSIZE*4+inptr_offset]) * quantptr[DCTSIZE*4+quantptr_offset]);
 
         tmp0 = (z2 + z3) << CONST_BITS;
         tmp1 = (z2 - z3) << CONST_BITS;
-        
+
         tmp10 = tmp0 + tmp3;
         tmp13 = tmp0 - tmp3;
         tmp11 = tmp1 + tmp2;
         tmp12 = tmp1 - tmp2;
-        
+
         /* Odd part per figure 8; the matrix is unitary and hence its
          * transpose is its inverse.    i0..i3 are y7,y5,y3,y1 respectively.
          */
-        
+
         tmp0 = ((inptr[DCTSIZE*7+inptr_offset]) * quantptr[DCTSIZE*7+quantptr_offset]);
         tmp1 = ((inptr[DCTSIZE*5+inptr_offset]) * quantptr[DCTSIZE*5+quantptr_offset]);
         tmp2 = ((inptr[DCTSIZE*3+inptr_offset]) * quantptr[DCTSIZE*3+quantptr_offset]);
         tmp3 = ((inptr[DCTSIZE*1+inptr_offset]) * quantptr[DCTSIZE*1+quantptr_offset]);
-        
+
         z1 = tmp0 + tmp3;
         z2 = tmp1 + tmp2;
         z3 = tmp0 + tmp2;
         z4 = tmp1 + tmp3;
         z5 = ((z3 + z4) * 9633/*FIX_1_175875602*/); /* sqrt(2) * c3 */
-        
+
         tmp0 = (tmp0 * 2446/*FIX_0_298631336*/); /* sqrt(2) * (-c1+c3+c5-c7) */
         tmp1 = (tmp1 * 16819/*FIX_2_053119869*/); /* sqrt(2) * ( c1+c3-c5+c7) */
         tmp2 = (tmp2 * 25172/*FIX_3_072711026*/); /* sqrt(2) * ( c1+c3+c5-c7) */
@@ -3032,17 +3055,17 @@
         z2 = (z2 * - 20995/*FIX_2_562915447*/); /* sqrt(2) * (-c1-c3) */
         z3 = (z3 * - 16069/*FIX_1_961570560*/); /* sqrt(2) * (-c3-c5) */
         z4 = (z4 * - 3196/*FIX_0_390180644*/); /* sqrt(2) * (c5-c3) */
-        
+
         z3 += z5;
         z4 += z5;
-        
+
         tmp0 += z1 + z3;
         tmp1 += z2 + z4;
         tmp2 += z2 + z3;
         tmp3 += z1 + z4;
-        
+
         /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
-        
+
 //      #define DESCALE(x,n)    RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
         wsptr[DCTSIZE*0+wsptr_offset] = (((tmp10 + tmp3) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
         wsptr[DCTSIZE*7+wsptr_offset] = (((tmp10 - tmp3) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
@@ -3052,13 +3075,13 @@
         wsptr[DCTSIZE*5+wsptr_offset] = (((tmp12 - tmp1) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
         wsptr[DCTSIZE*3+wsptr_offset] = (((tmp13 + tmp0) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
         wsptr[DCTSIZE*4+wsptr_offset] = (((tmp13 - tmp0) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
-        
+
         inptr_offset++;         /* advance pointers to next column */
         quantptr_offset++;
         wsptr_offset++;
     }
 
-    
+
     /* Pass 2: process rows from work array, store into output array. */
     /* Note that we must descale the results by a factor of 8 is 2**3, */
     /* and also undo the PASS1_BITS scaling. */
@@ -3076,7 +3099,7 @@
          * test takes more time than it's worth.    In that case this section
          * may be commented out.
          */
-        
+
 //#ifndef NO_ZERO_ROW_TEST
         if (wsptr[1+wsptr_offset] is 0 && wsptr[2+wsptr_offset] is 0 && wsptr[3+wsptr_offset] is 0 && wsptr[4+wsptr_offset] is 0 &&
             wsptr[5+wsptr_offset] is 0 && wsptr[6+wsptr_offset] is 0 && wsptr[7+wsptr_offset] is 0)
@@ -3085,7 +3108,7 @@
 //          #define DESCALE(x,n)    RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
             byte dcval = range_limit[range_limit_offset + ((((wsptr[0+wsptr_offset]) + (1 << ((PASS1_BITS+3)-1))) >> PASS1_BITS+3)
                     & RANGE_MASK)];
-            
+
             outptr[0+outptr_offset] = dcval;
             outptr[1+outptr_offset] = dcval;
             outptr[2+outptr_offset] = dcval;
@@ -3099,40 +3122,40 @@
             continue;
         }
 //#endif
-        
+
         /* Even part: reverse the even part of the forward DCT. */
         /* The rotator is sqrt(2)*c(-6). */
-        
+
         z2 = wsptr[2+wsptr_offset];
         z3 = wsptr[6+wsptr_offset];
-        
+
         z1 = ((z2 + z3) * 4433/*FIX_0_541196100*/);
         tmp2 = z1 + (z3 * - 15137/*FIX_1_847759065*/);
         tmp3 = z1 + (z2 * 6270/*FIX_0_765366865*/);
-        
+
         tmp0 = (wsptr[0+wsptr_offset] + wsptr[4+wsptr_offset]) << CONST_BITS;
         tmp1 = (wsptr[0+wsptr_offset] - wsptr[4+wsptr_offset]) << CONST_BITS;
-        
+
         tmp10 = tmp0 + tmp3;
         tmp13 = tmp0 - tmp3;
         tmp11 = tmp1 + tmp2;
         tmp12 = tmp1 - tmp2;
-        
+
         /* Odd part per figure 8; the matrix is unitary and hence its
          * transpose is its inverse.    i0..i3 are y7,y5,y3,y1 respectively.
          */
-        
+
         tmp0 = wsptr[7+wsptr_offset];
         tmp1 = wsptr[5+wsptr_offset];
         tmp2 = wsptr[3+wsptr_offset];
         tmp3 = wsptr[1+wsptr_offset];
-        
+
         z1 = tmp0 + tmp3;
         z2 = tmp1 + tmp2;
         z3 = tmp0 + tmp2;
         z4 = tmp1 + tmp3;
         z5 = ((z3 + z4) * 9633/*FIX_1_175875602*/); /* sqrt(2) * c3 */
-        
+
         tmp0 = (tmp0 * 2446/*FIX_0_298631336*/); /* sqrt(2) * (-c1+c3+c5-c7) */
         tmp1 = (tmp1 * 16819/*FIX_2_053119869*/); /* sqrt(2) * ( c1+c3-c5+c7) */
         tmp2 = (tmp2 * 25172/*FIX_3_072711026*/); /* sqrt(2) * ( c1+c3+c5-c7) */
@@ -3141,17 +3164,17 @@
         z2 = (z2 * - 20995/*FIX_2_562915447*/); /* sqrt(2) * (-c1-c3) */
         z3 = (z3 * - 16069/*FIX_1_961570560*/); /* sqrt(2) * (-c3-c5) */
         z4 = (z4 * - 3196/*FIX_0_390180644*/); /* sqrt(2) * (c5-c3) */
-        
+
         z3 += z5;
         z4 += z5;
-        
+
         tmp0 += z1 + z3;
         tmp1 += z2 + z4;
         tmp2 += z2 + z3;
         tmp3 += z1 + z4;
-        
+
         /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
-        
+
 
 //      #define DESCALE(x,n)    RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
         outptr[0+outptr_offset] = range_limit[range_limit_offset + ((((tmp10 + tmp3) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >>
@@ -3492,7 +3515,7 @@
             if (! master.using_merged_upsample)
                 cinfo.cconvert.start_pass (cinfo);
             cinfo.upsample.start_pass (cinfo);
-            if (cinfo.quantize_colors) 
+            if (cinfo.quantize_colors)
                 cinfo.cquantize.start_pass (cinfo, master.is_dummy_pass);
             cinfo.post.start_pass (cinfo, (master.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
             cinfo.main.start_pass (cinfo, JBUF_PASS_THRU);
@@ -3517,10 +3540,10 @@
 static bool jpeg_resync_to_restart (jpeg_decompress_struct cinfo, int desired) {
     int marker = cinfo.unread_marker;
     int action = 1;
-    
+
     /* Always put up a warning. */
 //  WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
-    
+
     /* Outer loop handles repeated decision after scanning forward. */
     for (;;) {
         if (marker < M_SOF0)
@@ -3551,6 +3574,7 @@
                 /* Return without advancing past this marker. */
                 /* Entropy decoder will be forced to process an empty segment. */
                 return true;
+            default:
         }
     } /* end loop */
 }
@@ -3663,7 +3687,7 @@
                     state.bits_left = bits_left;
 
                     return true;
-        
+
                 }
             }
 
@@ -3713,10 +3737,10 @@
 //  CHECK_BIT_BUFFER(*state, l, return -1);
     {
     if (bits_left < (l)) {
-        if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,l)) { 
+        if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,l)) {
             return -1;
         }
-        get_buffer = (state).get_buffer; bits_left = (state).bits_left;
+        get_buffer = state.get_buffer; bits_left = state.bits_left;
     }
     }
 //  code = GET_BITS(l);
@@ -3730,10 +3754,10 @@
 //      CHECK_BIT_BUFFER(*state, 1, return -1);
         {
         if (bits_left < (1)) {
-            if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,1)) { 
+            if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,1)) {
                 return -1;
             }
-            get_buffer = (state).get_buffer; bits_left = (state).bits_left;
+            get_buffer = state.get_buffer; bits_left = state.bits_left;
         }
         }
 //      code |= GET_BITS(1);
@@ -4249,6 +4273,7 @@
             main.rowgroup_ctr[0] = (cinfo.min_DCT_scaled_size + 1);
             main.rowgroups_avail =  (cinfo.min_DCT_scaled_size + 2);
             main.context_state = CTX_POSTPONED_ROW;
+        default:
     }
 }
 
@@ -4266,7 +4291,7 @@
             case DECOMPRESS_SMOOTH_DATA:
                 result = decompress_smooth_data(cinfo, main.buffer, main.buffer_offset);
                 break;
-            case DECOMPRESS_ONEPASS: 
+            case DECOMPRESS_ONEPASS:
                 result = decompress_onepass(cinfo, main.buffer, main.buffer_offset);
                 break;
             default: result = 0;
@@ -4351,8 +4376,8 @@
 //          }
 //          /* Process some data */
 //          last_scanline = cinfo.output_scanline;
-//          (*cinfo.main.process_data) (cinfo, cast(JSAMPARRAY) NULL,
-//                      &cinfo.output_scanline, cast(JDIMENSION) 0);
+//          (*cinfo.main.process_data) (cinfo, (JSAMPARRAY) NULL,
+//                      &cinfo.output_scanline, (JDIMENSION) 0);
 //          if (cinfo.output_scanline is last_scanline)
 //  return FALSE;       /* No progress made, must suspend */
 //      }
@@ -4385,13 +4410,13 @@
     if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
     length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
     length -= 2;
-    
+
     while (length > 16) {
         if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
         index = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
 
 //      TRACEMS1(cinfo, 1, JTRC_DHT, index);
-            
+
         bits[0] = 0;
         count = 0;
         for (i = 1; i <= 16; i++) {
@@ -4423,7 +4448,7 @@
 
         length -= count;
 
-        if ((index & 0x10) !is 0) {     /* AC table definition */
+        if ((index & 0x10) !is 0) {      /* AC table definition */
             index -= 0x10;
             htblptr = cinfo.ac_huff_tbl_ptrs[index] = new JHUFF_TBL();
         } else {            /* DC table definition */
@@ -4471,7 +4496,7 @@
         if (n >= NUM_QUANT_TBLS)
             error();
 //          ERREXIT1(cinfo, JERR_DQT_INDEX, n);
-            
+
         if (cinfo.quant_tbl_ptrs[n] is null)
             cinfo.quant_tbl_ptrs[n] = new JQUANT_TBL();
         quant_ptr = cinfo.quant_tbl_ptrs[n];
@@ -4521,7 +4546,7 @@
     length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
     if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
     length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-    
+
     if (length !is 4)
     error();
 //      ERREXIT(cinfo, JERR_BAD_LENGTH);
@@ -4548,7 +4573,7 @@
     if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
     length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
     length -= 2;
-    
+
     while (length > 0) {
         if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
         index = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
@@ -4616,7 +4641,7 @@
         cc = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
         if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
         c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-        
+
         for (ci = 0; ci < cinfo.num_components; ci++) {
             compptr = cinfo.comp_info[ci];
             if (cc is compptr.component_id)
@@ -4630,7 +4655,7 @@
         cinfo.cur_comp_info[i] = compptr;
         compptr.dc_tbl_no = (c >> 4) & 15;
         compptr.ac_tbl_no = (c       ) & 15;
-        
+
 //      TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc, compptr.dc_tbl_no, compptr.ac_tbl_no);
     }
 
@@ -4681,7 +4706,7 @@
     cinfo.image_width = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
     if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
     cinfo.image_width |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-    
+
     if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
     cinfo.num_components = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
 
@@ -4708,7 +4733,7 @@
 
     if (cinfo.comp_info is null)    /* do only once, even if suspend */
         cinfo.comp_info = new jpeg_component_info[cinfo.num_components];
-    
+
     for (ci = 0; ci < cinfo.num_components; ci++) {
         jpeg_component_info compptr = cinfo.comp_info[ci] = new jpeg_component_info();
         compptr.component_index = ci;
@@ -4756,6 +4781,7 @@
                 case H2V2_FANCY_UPSAMPLE: h2v2_fancy_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break;
                 case H2V2_UPSAMPLE: h2v2_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break;
                 case INT_UPSAMPLE: int_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break;
+            default:
             }
         }
         upsample.next_row_out = 0;
@@ -4768,7 +4794,7 @@
     /* Not more than the distance to the end of the image.  Need this test
      * in case the image height is not a multiple of max_v_samp_factor:
      */
-    if (num_rows > upsample.rows_to_go) 
+    if (num_rows > upsample.rows_to_go)
         num_rows = upsample.rows_to_go;
     /* And not more than what the client can accept: */
     out_rows_avail -= out_row_ctr[0];
@@ -4781,6 +4807,7 @@
         case YCC_RGB_CONVERT: ycc_rgb_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break;
         case GRAY_RGB_CONVERT: gray_rgb_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break;
         case YCCK_CMYK_CONVERT: error(); break;
+            default:
     }
 
     /* Adjust counts */
@@ -4792,20 +4819,20 @@
         in_row_group_ctr[0]++;
     }
 }
-    
+
 static void noop_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
      byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
 {
     output_data_ptr[output_data_index] = null;  /* safety check */
 }
-    
+
 static void fullsize_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
      byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
 {
     output_data_ptr[output_data_index] = input_data;
     output_data_offset[output_data_index] = input_data_offset;
 }
-    
+
 static void h2v1_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
      byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
 {
@@ -4828,7 +4855,7 @@
         }
     }
 }
-    
+
 static void h2v2_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
     byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
 {
@@ -4855,7 +4882,7 @@
         outrow += 2;
     }
 }
-    
+
 static void h2v1_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
      byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
 {
@@ -4863,7 +4890,7 @@
     byte[] inptr, outptr;
     int invalue;
     int colctr;
-    int inrow;                  
+    int inrow;
     output_data_offset[output_data_index] = 0;
 
     for (inrow = 0; inrow < cinfo.max_v_samp_factor; inrow++) {
@@ -4888,7 +4915,7 @@
         outptr[outptr_offset++] = cast(byte) invalue;
     }
 }
-    
+
 static void h2v2_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
     byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
 {
@@ -4909,7 +4936,7 @@
             else            /* next nearest is row below */
                 inptr1 = input_data[inrow+1+input_data_offset];
             outptr = output_data[outrow++];
-                
+
             int inptr0_offset = 0, inptr1_offset = 0, outptr_offset = 0;
 
             /* Special case for first column */
@@ -4935,7 +4962,7 @@
         inrow++;
     }
 }
-    
+
 static void int_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
      byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
 {
@@ -4948,7 +4975,7 @@
     int h_expand, v_expand;
     int inrow, outrow;
     output_data_offset[output_data_index] = 0;
-        
+
     h_expand = upsample.h_expand[compptr.component_index];
     v_expand = upsample.v_expand[compptr.component_index];
 
@@ -4995,6 +5022,7 @@
                 case 2: offset = RGB_BLUE; break;
                 case 1: offset = RGB_GREEN; break;
                 case 0: offset = RGB_RED; break;
+            default:
             }
             int outptr_offset = offset, inptr_offset = 0;
             for (count = num_cols; count > 0; count--) {
@@ -5006,7 +5034,7 @@
         output_buf_offset++;
     }
 }
-    
+
 static void grayscale_convert (jpeg_decompress_struct cinfo,
     byte[][][] input_buf, int[] input_buf_offset, int input_row,
     byte[][] output_buf, int output_buf_offset, int num_rows)
@@ -5034,7 +5062,7 @@
         }
     }
 }
-    
+
 static void ycc_rgb_convert (jpeg_decompress_struct cinfo,
     byte[][][] input_buf, int[] input_buf_offset, int input_row,
     byte[][] output_buf, int output_buf_offset, int num_rows)
@@ -5109,13 +5137,13 @@
     length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
 
     length -= 2;
-    
+
 //  TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo.unread_marker, cast(int) length);
 
     if (length > 0) {
         skip_input_data (cinfo, length);
     }
-    
+
     return true;
 }
 
@@ -5209,7 +5237,7 @@
 //               GETJOCTET(data[12]), GETJOCTET(data[13]));
         }
         totallen -= APP0_DATA_LEN;
-        if (totallen != ((data[12] & 0xFF) * (data[13] & 0xFF) * 3)) {
+        if (totallen !is ((data[12] & 0xFF) * (data[13] & 0xFF) * 3)) {
 //          TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, cast(int) totallen);
         }
     } else if (datalen >= 6 &&
@@ -5274,7 +5302,7 @@
 
 static bool get_soi (jpeg_decompress_struct cinfo) /* Process an SOI marker */ {
     int i;
-    
+
 //  TRACEMS(cinfo, 1, JTRC_SOI);
 
     if (cinfo.marker.saw_SOI)
@@ -5465,6 +5493,7 @@
         case JPEG_SUSPENDED:
             /* no work */
             break;
+        default:
     }
 
     return retcode;
@@ -5545,7 +5574,7 @@
         default:
             error();
     }
-    return 0;   
+    return 0;
 }
 
 static bool fill_input_buffer(jpeg_decompress_struct cinfo) {
@@ -5701,32 +5730,32 @@
                     return JPEG_SUSPENDED;
                 cinfo.unread_marker = 0;    /* processed the marker */
                 return JPEG_REACHED_SOS;
-    
+
             case M_EOI:
 //              TRACEMS(cinfo, 1, JTRC_EOI);
                 cinfo.unread_marker = 0;    /* processed the marker */
                 return JPEG_REACHED_EOI;
-        
+
             case M_DAC:
                 if (! get_dac(cinfo))
                     return JPEG_SUSPENDED;
                 break;
-        
+
             case M_DHT:
                 if (! get_dht(cinfo))
                     return JPEG_SUSPENDED;
                 break;
-        
+
             case M_DQT:
                 if (! get_dqt(cinfo))
                     return JPEG_SUSPENDED;
                 break;
-        
+
             case M_DRI:
                 if (! get_dri(cinfo))
                     return JPEG_SUSPENDED;
                 break;
-        
+
             case M_APP0:
             case M_APP1:
             case M_APP2:
@@ -5746,7 +5775,7 @@
                 if (! process_APPn(cinfo.unread_marker - M_APP0, cinfo))
                     return JPEG_SUSPENDED;
                 break;
-        
+
             case M_COM:
                 if (! process_COM(cinfo))
                     return JPEG_SUSPENDED;
@@ -5804,7 +5833,7 @@
 
     /* For now, precision must match compiled-in value... */
     if (cinfo.data_precision !is BITS_IN_JSAMPLE)
-        error(" [data precision=" + cinfo.data_precision + "]");
+        error(" [data precision=" ~ to!(String)(cinfo.data_precision) ~ "]");
 //      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
 
     /* Check that number of components won't exceed internal array sizes */
@@ -5867,16 +5896,16 @@
 {
     int ci, mcublks, tmp = 0;
     jpeg_component_info compptr;
-    
+
     if (cinfo.comps_in_scan is 1) {
-        
+
         /* Noninterleaved (single-component) scan */
         compptr = cinfo.cur_comp_info[0];
-        
+
         /* Overall image size in MCUs */
         cinfo.MCUs_per_row = compptr.width_in_blocks;
         cinfo.MCU_rows_in_scan = compptr.height_in_blocks;
-        
+
         /* For noninterleaved scan, always one block per MCU */
         compptr.MCU_width = 1;
         compptr.MCU_height = 1;
@@ -5889,24 +5918,24 @@
         tmp = (compptr.height_in_blocks % compptr.v_samp_factor);
         if (tmp is 0) tmp = compptr.v_samp_factor;
         compptr.last_row_height = tmp;
-        
+
         /* Prepare array describing MCU composition */
         cinfo.blocks_in_MCU = 1;
         cinfo.MCU_membership[0] = 0;
-        
+
     } else {
-        
+
         /* Interleaved (multi-component) scan */
         if (cinfo.comps_in_scan <= 0 || cinfo.comps_in_scan > MAX_COMPS_IN_SCAN)
             error();
 //          ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo.comps_in_scan, MAX_COMPS_IN_SCAN);
-        
+
         /* Overall image size in MCUs */
         cinfo.MCUs_per_row = cast(int)jdiv_round_up( cinfo.image_width, (cinfo.max_h_samp_factor*DCTSIZE));
         cinfo.MCU_rows_in_scan = cast(int)jdiv_round_up( cinfo.image_height, (cinfo.max_v_samp_factor*DCTSIZE));
-        
+
         cinfo.blocks_in_MCU = 0;
-        
+
         for (ci = 0; ci < cinfo.comps_in_scan; ci++) {
             compptr = cinfo.cur_comp_info[ci];
             /* Sampling factors give # of blocks of component in each MCU */
@@ -5930,7 +5959,7 @@
                 cinfo.MCU_membership[cinfo.blocks_in_MCU++] = ci;
             }
         }
-        
+
     }
 }
 
@@ -5980,7 +6009,7 @@
 
     /* Allocate a workspace if we haven't already done so. */
     dtbl.pub = htbl;        /* fill in back link */
-    
+
     /* Figure C.1: make table of Huffman code length for each symbol */
 
     p = 0;
@@ -5994,14 +6023,14 @@
     }
     huffsize[p] = 0;
     numsymbols = p;
-    
+
     /* Figure C.2: generate the codes themselves */
     /* We also validate that the counts represent a legal Huffman code tree. */
-    
+
     code = 0;
     si = huffsize[0];
     p = 0;
-    while ((huffsize[p]) !is 0) {
+    while ( huffsize[p] !is 0) {
         while (( huffsize[p]) is si) {
             huffcode[p++] = code;
             code++;
@@ -6127,6 +6156,7 @@
         break;
     case JPEG_SUSPENDED:
         break;
+    default:
     }
 
     return val;
@@ -6141,7 +6171,7 @@
             cinfo.jpeg_color_space = JCS_GRAYSCALE;
             cinfo.out_color_space = JCS_GRAYSCALE;
             break;
-            
+
         case 3:
             if (cinfo.saw_JFIF_marker) {
                 cinfo.jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
@@ -6153,7 +6183,7 @@
                     case 1:
                         cinfo.jpeg_color_space = JCS_YCbCr;
                         break;
-                    default:    
+                    default:
 //                      WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo.Adobe_transform);
                         cinfo.jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
                     break;
@@ -6163,7 +6193,7 @@
                 int cid0 = cinfo.comp_info[0].component_id;
                 int cid1 = cinfo.comp_info[1].component_id;
                 int cid2 = cinfo.comp_info[2].component_id;
-    
+
                 if (cid0 is 1 && cid1 is 2 && cid2 is 3)
                     cinfo.jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
                 else if (cid0 is 82 && cid1 is 71 && cid2 is 66)
@@ -6176,7 +6206,7 @@
             /* Always guess RGB is proper output colorspace. */
             cinfo.out_color_space = JCS_RGB;
             break;
-            
+
         case 4:
             if (cinfo.saw_Adobe_marker) {
                 switch (cinfo.Adobe_transform) {
@@ -6197,7 +6227,7 @@
             }
             cinfo.out_color_space = JCS_CMYK;
             break;
-            
+
         default:
             cinfo.jpeg_color_space = JCS_UNKNOWN;
             cinfo.out_color_space = JCS_UNKNOWN;
@@ -6307,7 +6337,7 @@
         return false;
     }
 }
-    
+
 static ImageData[] loadFromByteStream(InputStream inputStream, ImageLoader loader) {
     jpeg_decompress_struct cinfo = new jpeg_decompress_struct();
     cinfo.inputStream = inputStream;
@@ -6332,7 +6362,7 @@
     }
     int scanlinePad = 4;
     int row_stride = (((cinfo.output_width * cinfo.out_color_components * 8 + 7) / 8) + (scanlinePad - 1)) / scanlinePad * scanlinePad;
-    byte[][] buffer = new byte[1][row_stride];
+    byte[][] buffer = new byte[][]( 1, row_stride );
     byte[] data = new byte[row_stride * cinfo.output_height];
     ImageData imageData = ImageData.internal_new(
             cinfo.output_width, cinfo.output_height, palette.isDirect ? 24 : 8, palette, scanlinePad, data,
@@ -6359,7 +6389,7 @@
     }
     jpeg_finish_decompress(cinfo);
     jpeg_destroy_decompress(cinfo);
-    return new ImageData[]{imageData};
+    return [imageData];
 }
 
 }
--- a/dwt/internal/image/JPEGEndOfImage.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGEndOfImage.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,25 +7,30 @@
  *
  * 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.JPEGEndOfImage;
 
+import dwt.internal.image.JPEGFixedSizeSegment;
+import dwt.internal.image.JPEGFileFormat;
+import dwt.internal.image.LEDataInputStream;
 
 final class JPEGEndOfImage : JPEGFixedSizeSegment {
 
     public this() {
         super();
     }
-    
+
     public this(byte[] reference) {
         super(reference);
     }
-    
-    public int signature() {
+
+    public override int signature() {
         return JPEGFileFormat.EOI;
     }
-    
-    public int fixedSize() {
+
+    public override int fixedSize() {
         return 2;
     }
 }
--- a/dwt/internal/image/JPEGFileFormat.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGFileFormat.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,25 +1,38 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved.  This source file is made available under the terms contained in the README file
  * accompanying this program.  The README file should be located in the about_files directory of the
  * plug-in that contains this source file.
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
-module dwt.internal.image;
-
-
-import java.io.IOException;
+module dwt.internal.image.JPEGFileFormat;
 
 import dwt.DWT;
-import dwt.graphics.ImageData;
-import dwt.graphics.ImageLoader;
-import dwt.graphics.ImageLoaderEvent;
+import dwt.internal.image.JPEGFrameHeader;
+import dwt.internal.image.JPEGScanHeader;
+import dwt.internal.image.JPEGHuffmanTable;
+import dwt.internal.image.JPEGAppn;
+import dwt.internal.image.JPEGSegment;
+import dwt.internal.image.FileFormat;
+import dwt.internal.image.JPEGComment;
+import dwt.internal.image.JPEGArithmeticConditioningTable;
+import dwt.internal.image.JPEGRestartInterval;
+import dwt.internal.image.JPEGQuantizationTable;
+import dwt.internal.image.JPEGStartOfImage;
+import dwt.internal.image.JPEGDecoder;
+import dwt.internal.image.JPEGEndOfImage;
+import dwt.dwthelper.utils;
+
+import dwt.graphics.RGB;
 import dwt.graphics.PaletteData;
-import dwt.graphics.RGB;
 
-public final class JPEGFileFormat : FileFormat {
+import tango.core.Exception;
+
+final class JPEGFileFormat : FileFormat {
     int restartInterval;
     JPEGFrameHeader frameHeader;
     int imageWidth, imageHeight;
@@ -47,100 +60,83 @@
     int encoderQFactor = 75;
     int eobrun = 0;
     /* JPEGConstants */
-    public static final int DCTSIZE = 8;
-    public static final int DCTSIZESQR = 64;
+    public static const int DCTSIZE = 8;
+    public static const int DCTSIZESQR = 64;
     /* JPEGFixedPointConstants */
-    public static final int FIX_0_899976223 = 7373;
-    public static final int FIX_1_961570560 = 16069;
-    public static final int FIX_2_053119869 = 16819;
-    public static final int FIX_0_298631336 = 2446;
-    public static final int FIX_1_847759065 = 15137;
-    public static final int FIX_1_175875602 = 9633;
-    public static final int FIX_3_072711026 = 25172;
-    public static final int FIX_0_765366865 = 6270;
-    public static final int FIX_2_562915447 = 20995;
-    public static final int FIX_0_541196100 = 4433;
-    public static final int FIX_0_390180644 = 3196;
-    public static final int FIX_1_501321110 = 12299;
+    public static const int FIX_0_899976223 = 7373;
+    public static const int FIX_1_961570560 = 16069;
+    public static const int FIX_2_053119869 = 16819;
+    public static const int FIX_0_298631336 = 2446;
+    public static const int FIX_1_847759065 = 15137;
+    public static const int FIX_1_175875602 = 9633;
+    public static const int FIX_3_072711026 = 25172;
+    public static const int FIX_0_765366865 = 6270;
+    public static const int FIX_2_562915447 = 20995;
+    public static const int FIX_0_541196100 = 4433;
+    public static const int FIX_0_390180644 = 3196;
+    public static const int FIX_1_501321110 = 12299;
     /* JPEGMarkerCodes */
-    public static final int APP0  = 0xFFE0;
-    public static final int APP15 = 0xFFEF;
-    public static final int COM   = 0xFFFE;
-    public static final int DAC   = 0xFFCC;
-    public static final int DHP   = 0xFFDE;
-    public static final int DHT   = 0xFFC4;
-    public static final int DNL   = 0xFFDC;
-    public static final int DRI   = 0xFFDD;
-    public static final int DQT   = 0xFFDB;
-    public static final int EOI   = 0xFFD9;
-    public static final int EXP   = 0xFFDF;
-    public static final int JPG   = 0xFFC8;
-    public static final int JPG0  = 0xFFF0;
-    public static final int JPG13 = 0xFFFD;
-    public static final int RST0  = 0xFFD0;
-    public static final int RST1  = 0xFFD1;
-    public static final int RST2  = 0xFFD2;
-    public static final int RST3  = 0xFFD3;
-    public static final int RST4  = 0xFFD4;
-    public static final int RST5  = 0xFFD5;
-    public static final int RST6  = 0xFFD6;
-    public static final int RST7  = 0xFFD7;
-    public static final int SOF0  = 0xFFC0;
-    public static final int SOF1  = 0xFFC1;
-    public static final int SOF2  = 0xFFC2;
-    public static final int SOF3  = 0xFFC3;
-    public static final int SOF5  = 0xFFC5;
-    public static final int SOF6  = 0xFFC6;
-    public static final int SOF7  = 0xFFC7;
-    public static final int SOF9  = 0xFFC9;
-    public static final int SOF10 = 0xFFCA;
-    public static final int SOF11 = 0xFFCB;
-    public static final int SOF13 = 0xFFCD;
-    public static final int SOF14 = 0xFFCE;
-    public static final int SOF15 = 0xFFCF;
-    public static final int SOI   = 0xFFD8;
-    public static final int SOS   = 0xFFDA;
-    public static final int TEM   = 0xFF01;
+    public static const int APP0  = 0xFFE0;
+    public static const int APP15 = 0xFFEF;
+    public static const int COM   = 0xFFFE;
+    public static const int DAC   = 0xFFCC;
+    public static const int DHP   = 0xFFDE;
+    public static const int DHT   = 0xFFC4;
+    public static const int DNL   = 0xFFDC;
+    public static const int DRI   = 0xFFDD;
+    public static const int DQT   = 0xFFDB;
+    public static const int EOI   = 0xFFD9;
+    public static const int EXP   = 0xFFDF;
+    public static const int JPG   = 0xFFC8;
+    public static const int JPG0  = 0xFFF0;
+    public static const int JPG13 = 0xFFFD;
+    public static const int RST0  = 0xFFD0;
+    public static const int RST1  = 0xFFD1;
+    public static const int RST2  = 0xFFD2;
+    public static const int RST3  = 0xFFD3;
+    public static const int RST4  = 0xFFD4;
+    public static const int RST5  = 0xFFD5;
+    public static const int RST6  = 0xFFD6;
+    public static const int RST7  = 0xFFD7;
+    public static const int SOF0  = 0xFFC0;
+    public static const int SOF1  = 0xFFC1;
+    public static const int SOF2  = 0xFFC2;
+    public static const int SOF3  = 0xFFC3;
+    public static const int SOF5  = 0xFFC5;
+    public static const int SOF6  = 0xFFC6;
+    public static const int SOF7  = 0xFFC7;
+    public static const int SOF9  = 0xFFC9;
+    public static const int SOF10 = 0xFFCA;
+    public static const int SOF11 = 0xFFCB;
+    public static const int SOF13 = 0xFFCD;
+    public static const int SOF14 = 0xFFCE;
+    public static const int SOF15 = 0xFFCF;
+    public static const int SOI   = 0xFFD8;
+    public static const int SOS   = 0xFFDA;
+    public static const int TEM   = 0xFF01;
     /* JPEGFrameComponentParameterConstants */
-    public static final int TQI = 0;
-    public static final int HI  = 1;
-    public static final int VI  = 2;
-    public static final int CW  = 3;
-    public static final int CH  = 4;
+    public static const int TQI = 0;
+    public static const int HI  = 1;
+    public static const int VI  = 2;
+    public static const int CW  = 3;
+    public static const int CH  = 4;
     /* JPEGScanComponentParameterConstants */
-    public static final int DC  = 0;
-    public static final int AC  = 1;
+    public static const int DC  = 0;
+    public static const int AC  = 1;
     /* JFIF Component Constants */
-    public static final int ID_Y        = 1 - 1;
-    public static final int ID_CB   = 2 - 1;
-    public static final int ID_CR   = 3 - 1;
-    public static final RGB[] RGB16 = new RGB[] {
-        new RGB(0,0,0),
-        new RGB(0x80,0,0),
-        new RGB(0,0x80,0),
-        new RGB(0x80,0x80,0),
-        new RGB(0,0,0x80),
-        new RGB(0x80,0,0x80),
-        new RGB(0,0x80,0x80),
-        new RGB(0xC0,0xC0,0xC0),
-        new RGB(0x80,0x80,0x80),
-        new RGB(0xFF,0,0),
-        new RGB(0,0xFF,0),
-        new RGB(0xFF,0xFF,0),
-        new RGB(0,0,0xFF),
-        new RGB(0xFF,0,0xFF),
-        new RGB(0,0xFF,0xFF),
-        new RGB(0xFF,0xFF,0xFF),
-    };
-    public static final int[] ExtendTest = {
-        0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 
+    public static const int ID_Y        = 1 - 1;
+    public static const int ID_CB   = 2 - 1;
+    public static const int ID_CR   = 3 - 1;
+    public static /*const*/ RGB[] RGB16;
+    public static const int[] ExtendTest = [
+        0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
         4096, 8192, 16384, 32768, 65536, 131072, 262144
-    };
-    public static final int[] ExtendOffset = new int[] {
-        0, -1, -3, -7, -15, -31, -63, -127, -255, -511, -1023, -2047, 
+    ];
+    public static const int[] ExtendOffset = [
+        0, -1, -3, -7, -15, -31, -63, -127, -255, -511, -1023, -2047,
         -4095, -8191, -16383, -32767, -65535, -131071, -262143
-    };
-    public static final int[] ZigZag8x8 = {
+    ];
+    public static const int[] ZigZag8x8 = [
         0, 1, 8, 16, 9, 2, 3, 10,
         17, 24, 32, 25, 18, 11, 4, 5,
         12, 19, 26, 33, 40, 48, 41, 34,
@@ -149,19 +145,39 @@
         29, 22, 15, 23, 30, 37, 44, 51,
         58, 59, 52, 45, 38, 31, 39, 46,
         53, 60, 61, 54, 47, 55, 62, 63
-    };
+    ];
+
+    public static int[] CrRTable, CbBTable, CrGTable, CbGTable;
+    public static int[] RYTable, GYTable, BYTable,
+        RCbTable, GCbTable, BCbTable, RCrTable, GCrTable, BCrTable, NBitsTable;
+    //public static void static_this() {
+    static this() {
 
-    public static final int[] CrRTable, CbBTable, CrGTable, CbGTable;
-    public static final int[] RYTable, GYTable, BYTable,
-        RCbTable, GCbTable, BCbTable, RCrTable, GCrTable, BCrTable, NBitsTable;
-    static {
-        /* Initialize RGB-YCbCr Tables */
+        RGB16 = [
+            new RGB(0,0,0),
+            new RGB(0x80,0,0),
+            new RGB(0,0x80,0),
+            new RGB(0x80,0x80,0),
+            new RGB(0,0,0x80),
+            new RGB(0x80,0,0x80),
+            new RGB(0,0x80,0x80),
+            new RGB(0xC0,0xC0,0xC0),
+            new RGB(0x80,0x80,0x80),
+            new RGB(0xFF,0,0),
+            new RGB(0,0xFF,0),
+            new RGB(0xFF,0xFF,0),
+            new RGB(0,0,0xFF),
+            new RGB(0xFF,0,0xFF),
+            new RGB(0,0xFF,0xFF),
+            new RGB(0xFF,0xFF,0xFF)
+        ];
         int [] rYTable = new int[256];
         int [] gYTable = new int[256];
         int [] bYTable = new int[256];
         int [] rCbTable = new int[256];
         int [] gCbTable = new int[256];
         int [] bCbTable = new int[256];
+        int [] rCrTable = new int[256];
         int [] gCrTable = new int[256];
         int [] bCrTable = new int[256];
         for (int i = 0; i < 256; i++) {
@@ -220,7 +236,7 @@
     int srcHeight = image.height;
     int vhFactor = maxV * maxH;
     int[] frameComponent;
-    imageComponents = new byte[nComponents][];
+    imageComponents = new byte[][](nComponents);
     for (int i = 0; i < nComponents; i++) {
         frameComponent = frameComponents[componentIds[i]];
         imageComponents[i] = new byte[frameComponent[CW] * frameComponent[CH]];
@@ -427,7 +443,7 @@
                 int g = pixel & greenMask;
                 g = (greenShift < 0) ? g >>> -greenShift : g << greenShift;
                 int b = pixel & blueMask;
-                b = (blueShift < 0) ? b >>> -blueShift : b << blueShift;                
+                b = (blueShift < 0) ? b >>> -blueShift : b << blueShift;
                 dataYComp[dstDataIndex] = cast(byte)((RYTable[r] + GYTable[g] + BYTable[b]) >> 16);
                 dataCbComp[dstDataIndex] = cast(byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) >> 16);
                 dataCrComp[dstDataIndex] = cast(byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) >> 16);
@@ -488,13 +504,13 @@
      *  B = Y + 1.77200 * Cb
      * where Cb and Cr represent the incoming values less MAXJSAMPLE/2.
      * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
-     * 
+     *
      * To avoid floating-point arithmetic, we represent the fractional constants
      * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
      * the products by 2^16, with appropriate rounding, to get the correct answer.
      * Notice that Y, being an integral input, does not contribute any fraction
      * so it need not participate in the rounding.
-     * 
+     *
      * For even more speed, we avoid doing any multiplications in the inner loop
      * by precalculating the constants times Cb and Cr for all possible values.
      * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
@@ -824,10 +840,10 @@
     if (nBits is 0) {
         DWT.error(DWT.ERROR_INVALID_IMAGE);
     }
-    int[] power2m1 = new int[] {
-        1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 
+    int[] power2m1 = [
+        1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191,
         16383, 32767, 65535, 131125
-    };
+    ];
     int code = (huffCode & power2m1[nBits - 1]) << (24 - nBits - currentBitCount);
     byte[] codeBuffer = new byte[4];
     codeBuffer[0] = cast(byte)(code & 0xFF);
@@ -1006,7 +1022,7 @@
         int tmp4 = dataUnit[rIndex + 3] - dataUnit[rIndex + 4];
 
         /**
-         * Even part per LL&M figure 1 --- note that published figure 
+         * Even part per LL&M figure 1 --- note that published figure
          * is faulty; rotator 'sqrt(2)*c1' should be 'sqrt(2)*c6'.
          */
         int tmp10 = tmp0 + tmp3;
@@ -1086,7 +1102,7 @@
         int tmp4 = dataUnit[c3] - dataUnit[c4];
 
         /**
-         * Even part per LL&M figure 1 --- note that published figure 
+         * Even part per LL&M figure 1 --- note that published figure
          * is faulty; rotator 'sqrt(2)*c1' should be 'sqrt(2)*c6'.
          */
         int tmp10 = tmp0 + tmp3;
@@ -1186,7 +1202,7 @@
     JPEGQuantizationTable dqt = new JPEGQuantizationTable(inputStream);
     int[][] currentTables = quantizationTables;
     if (currentTables is null) {
-        currentTables = new int[4][];
+        currentTables = new int[][](4);
     }
     int[] dqtTablesKeys = dqt.getQuantizationTablesKeys();
     int[][] dqtTablesValues = dqt.getQuantizationTablesValues();
@@ -1249,7 +1265,7 @@
             z3 = tmp0 + tmp2;
             int z4 = tmp1 + tmp3;
             int z5 = (z3 + z4) * FIX_1_175875602; /* sqrt(2) * c3 */
-              
+
             tmp0 *= FIX_0_298631336;        /* sqrt(2) * (-c1+c3+c5-c7) */
             tmp1 *= FIX_2_053119869;        /* sqrt(2) * ( c1+c3-c5+c7) */
             tmp2 *= FIX_3_072711026;        /* sqrt(2) * ( c1+c3+c5-c7) */
@@ -1331,7 +1347,7 @@
             z3 = tmp0 + tmp2;
             z4 = tmp1 + tmp3;
             z0 = (z3 + z4) * FIX_1_175875602;   /* sqrt(2) * c3 */
-            
+
             tmp0 *= FIX_0_298631336;        /* sqrt(2) * (-c1+c3+c5-c7) */
             tmp1 *= FIX_2_053119869;        /* sqrt(2) * ( c1+c3-c5+c7) */
             tmp2 *= FIX_3_072711026;        /* sqrt(2) * ( c1+c3+c5-c7) */
@@ -1340,10 +1356,10 @@
             z2 *= 0 - FIX_2_562915447;  /* sqrt(2) * (-c1-c3) */
             z3 *= 0 - FIX_1_961570560;  /* sqrt(2) * (-c3-c5) */
             z4 *= 0 - FIX_0_390180644;  /* sqrt(2) * (c5-c3) */
-            
+
             z3 += z0;
             z4 += z0;
-            
+
             tmp0 += z1 + z3;
             tmp1 += z2 + z4;
             tmp2 += z2 + z3;
@@ -1361,7 +1377,7 @@
         }
     }
 }
-bool isFileFormat(LEDataInputStream stream) {
+override bool isFileFormat(LEDataInputStream stream) {
     try {
         JPEGStartOfImage soi = new JPEGStartOfImage(stream);
         stream.unread(soi.reference);
@@ -1382,9 +1398,10 @@
             && dataUnit[rIndex + 5] is 0 && dataUnit[rIndex + 6] is 0
             && dataUnit[rIndex + 7] is 0;
 }
-ImageData[] loadFromByteStream() {
+override ImageData[] loadFromByteStream() {
     //TEMPORARY CODE
-    if (System.getProperty("dwt.internal.image.JPEGFileFormat_3.2") is null) {
+    //PORTING_FIXME
+    if (/+System.getProperty("dwt.internal.image.JPEGFileFormat_3.2") is null+/ true ) {
         return JPEGDecoder.loadFromByteStream(inputStream, loader);
     }
     JPEGStartOfImage soi = new JPEGStartOfImage(inputStream);
@@ -1393,7 +1410,7 @@
 
     /* Process the tables preceding the frame header. */
     processTables();
-    
+
     /* Start of Frame. */
     frameHeader = new JPEGFrameHeader(inputStream);
     if (!frameHeader.verify()) DWT.error(DWT.ERROR_INVALID_IMAGE);
@@ -1410,10 +1427,10 @@
     nComponents = frameHeader.getNumberOfImageComponents();
     frameComponents = frameHeader.componentParameters;
     componentIds = frameHeader.componentIdentifiers;
-    imageComponents = new byte[nComponents][];
+    imageComponents = new byte[][](nComponents);
     if (progressive) {
         // Progressive jpeg: need to keep all of the data units.
-        dataUnits = new int[nComponents][][];
+        dataUnits = new int[][][](nComponents);
     } else {
         // Sequential jpeg: only need one data unit.
         dataUnit = new int[8 * 8];
@@ -1423,17 +1440,17 @@
         int bufferSize = frameComponent[CW] * frameComponent[CH];
         imageComponents[i] = new byte[bufferSize];
         if (progressive) {
-            dataUnits[i] = new int[bufferSize][];
+            dataUnits[i] = new int[][](bufferSize);
         }
     }
 
     /* Process the tables preceding the scan header. */
     processTables();
-    
+
     /* Start of Scan. */
     scanHeader = new JPEGScanHeader(inputStream);
     if (!scanHeader.verify()) DWT.error(DWT.ERROR_INVALID_IMAGE);
-    
+
     /* Process scan(s) and further tables until EOI. */
     int progressiveScanCount = 0;
     bool done = false;
@@ -1458,7 +1475,7 @@
                 DWT.error(DWT.ERROR_IO, e);
             }
         }
-        
+
         /* Process the tables preceding the next scan header. */
         JPEGSegment jpegSegment = processTables();
         if (jpegSegment is null || jpegSegment.getSegmentMarker() is EOI) {
@@ -1468,7 +1485,7 @@
             if (!scanHeader.verify()) DWT.error(DWT.ERROR_INVALID_IMAGE);
         }
     }
-    
+
     if (progressive) {
         for (int ymcu = 0; ymcu < interleavedMcuRows; ymcu++) {
             for (int xmcu = 0; xmcu < interleavedMcuCols; xmcu++) {
@@ -1495,12 +1512,12 @@
     if (progressive && loader.hasListeners()) {
         loader.notifyListeners(new ImageLoaderEvent(loader, imageData, progressiveScanCount, true));
     }
-    return new ImageData[] {imageData};
+    return [imageData];
 }
 ImageData createImageData() {
     return ImageData.internal_new(
         imageWidth,
-        imageHeight, 
+        imageHeight,
         nComponents * samplePrecision,
         setUpPalette(),
         nComponents is 1 ? 4 : 1,
@@ -1641,7 +1658,7 @@
                 break;
             default:
                 skipSegmentFrom(inputStream);
-            
+
         }
     }
 }
@@ -1729,7 +1746,7 @@
     try {
         byte[] byteArray = new byte[4];
         JPEGSegment jpegSegment = new JPEGSegment(byteArray);
-    
+
         if (byteStream.read(byteArray) !is byteArray.length) {
             DWT.error(DWT.ERROR_INVALID_IMAGE);
         }
@@ -1762,16 +1779,16 @@
         destIndex += compWidth;
     }
 }
-void unloadIntoByteStream(ImageLoader loader) {
+override void unloadIntoByteStream(ImageLoader loader) {
     ImageData image = loader.data[0];
-    if (!new JPEGStartOfImage().writeToStream(outputStream)) {
+    if (!(new JPEGStartOfImage()).writeToStream(outputStream)) {
         DWT.error(DWT.ERROR_IO);
     }
-    JPEGAppn appn = new JPEGAppn(new byte[] {cast(byte)0xFF, cast(byte)0xE0, 0, 0x10, 0x4A, 0x46, 0x49, 0x46, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0});
+    JPEGAppn appn = new JPEGAppn([cast(byte)0xFF, cast(byte)0xE0, 0, 0x10, 0x4A, 0x46, 0x49, 0x46, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0]);
     if (!appn.writeToStream(outputStream)) {
         DWT.error(DWT.ERROR_IO);
     }
-    quantizationTables = new int[4][];
+    quantizationTables = new int[][](4);
     JPEGQuantizationTable chromDQT = JPEGQuantizationTable.defaultChrominanceTable();
     chromDQT.scaleBy(encoderQFactor);
     int[] jpegDQTKeys = chromDQT.getQuantizationTablesKeys();
@@ -1796,23 +1813,23 @@
     int[][] frameParams, scanParams;
     if (image.depth is 1) {
         frameLength = 11;
-        frameParams = new int[1][];
-        frameParams[0] = new int[] {1, 1, 1, 0, 0};
-        scanParams = new int[1][];
-        scanParams[0] = new int[] {0, 0};
+        frameParams = new int[][](1);
+        frameParams[0] = [1, 1, 1, 0, 0];
+        scanParams = new int[][](1);
+        scanParams[0] = [0, 0];
         scanLength = 8;
         nComponents = 1;
         precision = 1;
     } else {
         frameLength = 17;
-        frameParams = new int[3][];
-        frameParams[0] = new int[] {0, 2, 2, 0, 0};
-        frameParams[1] = new int[] {1, 1, 1, 0, 0};
-        frameParams[2] = new int[] {1, 1, 1, 0, 0};
-        scanParams = new int[3][];
-        scanParams[0] = new int[] {0, 0};
-        scanParams[1] = new int[] {1, 1};
-        scanParams[2] = new int[] {1, 1};
+        frameParams = new int[][](3);
+        frameParams[0] = [0, 2, 2, 0, 0];
+        frameParams[1] = [1, 1, 1, 0, 0];
+        frameParams[2] = [1, 1, 1, 0, 0];
+        scanParams = new int[][](3);
+        scanParams[0] = [0, 0];
+        scanParams[1] = [1, 1];
+        scanParams[2] = [1, 1];
         scanLength = 12;
         nComponents = 3;
         precision = 8;
@@ -1827,7 +1844,7 @@
     frameHeader.setNumberOfLines(imageHeight);
     frameHeader.setNumberOfImageComponents(nComponents);
     frameHeader.componentParameters = frameParams;
-    frameHeader.componentIdentifiers = new int[] {0, 1, 2};
+    frameHeader.componentIdentifiers = [0, 1, 2];
     frameHeader.initializeContents();
     if (!frameHeader.writeToStream(outputStream)) {
         DWT.error(DWT.ERROR_IO);
@@ -1842,12 +1859,12 @@
     interleavedMcuRows = (imageHeight + mcuHeight - 1) / mcuHeight;
     acHuffmanTables = new JPEGHuffmanTable[4];
     dcHuffmanTables = new JPEGHuffmanTable[4];
-    JPEGHuffmanTable[] dhtTables = new JPEGHuffmanTable[] {
+    JPEGHuffmanTable[] dhtTables = [
         JPEGHuffmanTable.getDefaultDCLuminanceTable(),
         JPEGHuffmanTable.getDefaultDCChrominanceTable(),
         JPEGHuffmanTable.getDefaultACLuminanceTable(),
         JPEGHuffmanTable.getDefaultACChrominanceTable()
-    };
+    ];
     for (int i = 0; i < dhtTables.length; i++) {
         JPEGHuffmanTable dhtTable = dhtTables[i];
         if (!dhtTable.writeToStream(outputStream)) {
@@ -1880,7 +1897,7 @@
     currentByte = 0;
     currentBitCount = 0;
     encodeScan();
-    if (!new JPEGEndOfImage().writeToStream(outputStream)) {
+    if (!(new JPEGEndOfImage()).writeToStream(outputStream)) {
         DWT.error(DWT.ERROR_IO);
     }
 }
--- a/dwt/internal/image/JPEGFixedSizeSegment.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGFixedSizeSegment.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,11 +7,18 @@
  *
  * 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.JPEGFixedSizeSegment;
+
 
- 
 import dwt.DWT;
+import dwt.internal.image.JPEGSegment;
+import dwt.internal.image.LEDataInputStream;
+
+import tango.core.Exception;
+
 
 abstract class JPEGFixedSizeSegment : JPEGSegment {
 
@@ -19,26 +26,26 @@
         reference = new byte[fixedSize()];
         setSegmentMarker(signature());
     }
-    
+
     public this(byte[] reference) {
         super(reference);
     }
-    
+
     public this(LEDataInputStream byteStream) {
         reference = new byte[fixedSize()];
         try {
             byteStream.read(reference);
-        } catch (Exception e) { 
+        } catch (Exception e) {
             DWT.error(DWT.ERROR_IO, e);
         }
     }
-    
+
     abstract public int fixedSize();
 
-    public int getSegmentLength() {
+    public override int getSegmentLength() {
         return fixedSize() - 2;
     }
-    
-    public void setSegmentLength(int length) {
+
+    public override void setSegmentLength(int length) {
     }
 }
--- a/dwt/internal/image/JPEGFrameHeader.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGFrameHeader.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,11 +7,17 @@
  *
  * 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.JPEGFrameHeader;
 
 
 import dwt.DWT;
+import dwt.internal.image.JPEGVariableSizeSegment;
+import dwt.internal.image.JPEGFileFormat;
+import dwt.internal.image.LEDataInputStream;
+import dwt.dwthelper.utils;
 
 final class JPEGFrameHeader : JPEGVariableSizeSegment {
     int maxVFactor;
@@ -22,67 +28,67 @@
     public this(byte[] reference) {
         super(reference);
     }
-    
+
     public this(LEDataInputStream byteStream) {
         super(byteStream);
         initializeComponentParameters();
     }
-    
+
     public int getSamplePrecision() {
         return reference[4] & 0xFF;
     }
-    
+
     public int getNumberOfLines() {
         return (reference[5] & 0xFF) << 8 | (reference[6] & 0xFF);
     }
-    
+
     public int getSamplesPerLine() {
         return (reference[7] & 0xFF) << 8 | (reference[8] & 0xFF);
     }
-    
+
     public int getNumberOfImageComponents() {
         return reference[9] & 0xFF;
     }
-    
+
     public void setSamplePrecision(int precision) {
         reference[4] = cast(byte)(precision & 0xFF);
     }
-    
+
     public void setNumberOfLines(int anInteger) {
         reference[5] = cast(byte)((anInteger & 0xFF00) >> 8);
         reference[6] = cast(byte)(anInteger & 0xFF);
     }
-    
+
     public void setSamplesPerLine(int samples) {
         reference[7] = cast(byte)((samples & 0xFF00) >> 8);
         reference[8] = cast(byte)(samples & 0xFF);
     }
-    
+
     public void setNumberOfImageComponents(int anInteger) {
         reference[9] = cast(byte)(anInteger & 0xFF);
     }
-    
+
     public int getMaxHFactor() {
         return maxHFactor;
     }
-    
+
     public int getMaxVFactor() {
         return maxVFactor;
     }
-    
+
     public void setMaxHFactor(int anInteger) {
         maxHFactor = anInteger;
     }
-    
+
     public void setMaxVFactor(int anInteger) {
         maxVFactor = anInteger;
     }
-    
+
     /* Used when decoding. */
     void initializeComponentParameters() {
         int nf = getNumberOfImageComponents();
         componentIdentifiers = new int[nf];
-        int[][] compSpecParams = new int[0][];
+        int[][] compSpecParams;
         int hmax = 1;
         int vmax = 1;
         for (int i = 0; i < nf; i++) {
@@ -103,7 +109,7 @@
             compParam[1] = hi;
             compParam[2] = vi;
             if (compSpecParams.length <= ci) {
-                int[][] newParams = new int[ci + 1][];
+                int[][] newParams = new int[][](ci + 1);
                 System.arraycopy(compSpecParams, 0, newParams, 0, compSpecParams.length);
                 compSpecParams = newParams;
             }
@@ -111,7 +117,7 @@
         }
         int x = getSamplesPerLine();
         int y = getNumberOfLines();
-        int[] multiples = new int[] { 8, 16, 24, 32 };
+        int[] multiples = [ 8, 16, 24, 32 ];
         for (int i = 0; i < nf; i++) {
             int[] compParam = compSpecParams[componentIdentifiers[i]];
             int hi = compParam[1];
@@ -127,7 +133,7 @@
         setMaxVFactor(vmax);
         componentParameters = compSpecParams;
     }
-    
+
     /* Used when encoding. */
     public void initializeContents() {
         int nf = getNumberOfImageComponents();
@@ -153,7 +159,7 @@
         }
         int x = getSamplesPerLine();
         int y = getNumberOfLines();
-        int[] multiples = new int[] {8, 16, 24, 32};
+        int[] multiples = [8, 16, 24, 32];
         for (int i = 0; i < nf; i++) {
             int[] compParam = compSpecParams[componentIdentifiers[i]];
             int hi = compParam[1];
@@ -168,12 +174,12 @@
         setMaxHFactor(hmax);
         setMaxVFactor(vmax);
     }
-    
+
     int roundUpToMultiple(int anInteger, int mInteger) {
         int a = anInteger + mInteger - 1;
         return a - (a % mInteger);
     }
-    
+
     /*
      * Verify the information contained in the receiver is correct.
      * Answer true if the header contains a valid marker. Otherwise,
@@ -192,7 +198,7 @@
      *  SOF_14 - Differential progressive, arithmetic coding
      *  SOF_15 - Differential lossless, arithmetic coding
      */
-    public bool verify() {
+    public override bool verify() {
         int marker = getSegmentMarker();
         return (marker >= JPEGFileFormat.SOF0 && marker <= JPEGFileFormat.SOF3) ||
             (marker >= JPEGFileFormat.SOF5 && marker <= JPEGFileFormat.SOF7) ||
@@ -207,7 +213,7 @@
             || marker is JPEGFileFormat.SOF10
             || marker is JPEGFileFormat.SOF14;
     }
-    
+
     public bool isArithmeticCoding() {
         return getSegmentMarker() >= JPEGFileFormat.SOF9;
     }
--- a/dwt/internal/image/JPEGHuffmanTable.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGHuffmanTable.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,10 +7,16 @@
  *
  * 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.JPEGHuffmanTable;
 
+import dwt.internal.image.JPEGVariableSizeSegment;
+import dwt.internal.image.LEDataInputStream;
+import dwt.internal.image.JPEGFileFormat;
 
+import dwt.dwthelper.System;
 /**
  * JPEGHuffmanTable class actually represents two types of object:
  * 1) A DHT (Define Huffman Tables) segment, which may represent
@@ -31,49 +37,49 @@
     int[] dhValues;
     int[] ehCodes;
     byte[] ehCodeLengths;
-    static byte[] DCLuminanceTable = {
+    static byte[] DCLuminanceTable = [
         cast(byte)255, cast(byte)196, 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
         0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
-    };
-    static byte[] DCChrominanceTable = {
+    ];
+    static byte[] DCChrominanceTable = [
         cast(byte)255, cast(byte)196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
         0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
-    };
-    static byte[] ACLuminanceTable = {
-        cast(byte)255, cast(byte)196, 0, cast(byte)181, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, 
-        1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20, 
-        50, cast(byte)129, cast(byte)145, cast(byte)161, 8, 35, 66, cast(byte)177, cast(byte)193, 21, 82, cast(byte)209, cast(byte)240, 36, 51, 98, 
-        114, cast(byte)130, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53, 
-        54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 
-        88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 
-        119, 120, 121, 122, cast(byte)131, cast(byte)132, cast(byte)133, cast(byte)134, cast(byte)135, cast(byte)136, cast(byte)137, cast(byte)138, cast(byte)146, cast(byte)147, cast(byte)148, 
-        cast(byte)149, cast(byte)150, cast(byte)151, cast(byte)152, cast(byte)153, cast(byte)154, cast(byte)162, cast(byte)163, cast(byte)164, cast(byte)165, cast(byte)166, cast(byte)167, cast(byte)168, cast(byte)169, cast(byte)170, 
-        cast(byte)178, cast(byte)179, cast(byte)180, cast(byte)181, cast(byte)182, cast(byte)183, cast(byte)184, cast(byte)185, cast(byte)186, cast(byte)194, cast(byte)195, cast(byte)196, cast(byte)197, cast(byte)198, cast(byte)199, 
-        cast(byte)200, cast(byte)201, cast(byte)202, cast(byte)210, cast(byte)211, cast(byte)212, cast(byte)213, cast(byte)214, cast(byte)215, cast(byte)216, cast(byte)217, cast(byte)218, cast(byte)225, cast(byte)226, cast(byte)227, 
-        cast(byte)228, cast(byte)229, cast(byte)230, cast(byte)231, cast(byte)232, cast(byte)233, cast(byte)234, cast(byte)241, cast(byte)242, cast(byte)243, cast(byte)244, cast(byte)245, cast(byte)246, cast(byte)247, cast(byte)248, 
+    ];
+    static byte[] ACLuminanceTable = [
+        cast(byte)255, cast(byte)196, 0, cast(byte)181, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125,
+        1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20,
+        50, cast(byte)129, cast(byte)145, cast(byte)161, 8, 35, 66, cast(byte)177, cast(byte)193, 21, 82, cast(byte)209, cast(byte)240, 36, 51, 98,
+        114, cast(byte)130, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53,
+        54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87,
+        88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118,
+        119, 120, 121, 122, cast(byte)131, cast(byte)132, cast(byte)133, cast(byte)134, cast(byte)135, cast(byte)136, cast(byte)137, cast(byte)138, cast(byte)146, cast(byte)147, cast(byte)148,
+        cast(byte)149, cast(byte)150, cast(byte)151, cast(byte)152, cast(byte)153, cast(byte)154, cast(byte)162, cast(byte)163, cast(byte)164, cast(byte)165, cast(byte)166, cast(byte)167, cast(byte)168, cast(byte)169, cast(byte)170,
+        cast(byte)178, cast(byte)179, cast(byte)180, cast(byte)181, cast(byte)182, cast(byte)183, cast(byte)184, cast(byte)185, cast(byte)186, cast(byte)194, cast(byte)195, cast(byte)196, cast(byte)197, cast(byte)198, cast(byte)199,
+        cast(byte)200, cast(byte)201, cast(byte)202, cast(byte)210, cast(byte)211, cast(byte)212, cast(byte)213, cast(byte)214, cast(byte)215, cast(byte)216, cast(byte)217, cast(byte)218, cast(byte)225, cast(byte)226, cast(byte)227,
+        cast(byte)228, cast(byte)229, cast(byte)230, cast(byte)231, cast(byte)232, cast(byte)233, cast(byte)234, cast(byte)241, cast(byte)242, cast(byte)243, cast(byte)244, cast(byte)245, cast(byte)246, cast(byte)247, cast(byte)248,
         cast(byte)249, cast(byte)250
-    };
-    static byte[] ACChrominanceTable = {
-        cast(byte)255, cast(byte)196, 0, cast(byte)181, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 
-        1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34, 
-        50, cast(byte)129, 8, 20, 66, cast(byte)145, cast(byte)161, cast(byte)177, cast(byte)193, 9, 35, 
-        51, 82, cast(byte)240, 21, 98, 114, cast(byte)209, 10, 22, 36, 52, cast(byte)225, 37, 
-        cast(byte)241, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67, 
-        68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 
-        103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, cast(byte)130, 
-        cast(byte)131, cast(byte)132, cast(byte)133, cast(byte)134, cast(byte)135, cast(byte)136, cast(byte)137, 
-        cast(byte)138, cast(byte)146, cast(byte)147, cast(byte)148, cast(byte)149, cast(byte)150, cast(byte)151, 
-        cast(byte)152, cast(byte)153, cast(byte)154, cast(byte)162, cast(byte)163, cast(byte)164, cast(byte)165, 
-        cast(byte)166, cast(byte)167, cast(byte)168, cast(byte)169, cast(byte)170, cast(byte)178, cast(byte)179, 
-        cast(byte)180, cast(byte)181, cast(byte)182, cast(byte)183, cast(byte)184, cast(byte)185, cast(byte)186, 
-        cast(byte)194, cast(byte)195, cast(byte)196, cast(byte)197, cast(byte)198, cast(byte)199, cast(byte)200, 
-        cast(byte)201, cast(byte)202, cast(byte)210, cast(byte)211, cast(byte)212, cast(byte)213, cast(byte)214, 
-        cast(byte)215, cast(byte)216, cast(byte)217, cast(byte)218, cast(byte)226, cast(byte)227, cast(byte)228, 
-        cast(byte)229, cast(byte)230, cast(byte)231, cast(byte)232, cast(byte)233, cast(byte)234, cast(byte)242, 
-        cast(byte)243, cast(byte)244, cast(byte)245, cast(byte)246, cast(byte)247, cast(byte)248, cast(byte)249, 
+    ];
+    static byte[] ACChrominanceTable = [
+        cast(byte)255, cast(byte)196, 0, cast(byte)181, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0,
+        1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34,
+        50, cast(byte)129, 8, 20, 66, cast(byte)145, cast(byte)161, cast(byte)177, cast(byte)193, 9, 35,
+        51, 82, cast(byte)240, 21, 98, 114, cast(byte)209, 10, 22, 36, 52, cast(byte)225, 37,
+        cast(byte)241, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67,
+        68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102,
+        103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, cast(byte)130,
+        cast(byte)131, cast(byte)132, cast(byte)133, cast(byte)134, cast(byte)135, cast(byte)136, cast(byte)137,
+        cast(byte)138, cast(byte)146, cast(byte)147, cast(byte)148, cast(byte)149, cast(byte)150, cast(byte)151,
+        cast(byte)152, cast(byte)153, cast(byte)154, cast(byte)162, cast(byte)163, cast(byte)164, cast(byte)165,
+        cast(byte)166, cast(byte)167, cast(byte)168, cast(byte)169, cast(byte)170, cast(byte)178, cast(byte)179,
+        cast(byte)180, cast(byte)181, cast(byte)182, cast(byte)183, cast(byte)184, cast(byte)185, cast(byte)186,
+        cast(byte)194, cast(byte)195, cast(byte)196, cast(byte)197, cast(byte)198, cast(byte)199, cast(byte)200,
+        cast(byte)201, cast(byte)202, cast(byte)210, cast(byte)211, cast(byte)212, cast(byte)213, cast(byte)214,
+        cast(byte)215, cast(byte)216, cast(byte)217, cast(byte)218, cast(byte)226, cast(byte)227, cast(byte)228,
+        cast(byte)229, cast(byte)230, cast(byte)231, cast(byte)232, cast(byte)233, cast(byte)234, cast(byte)242,
+        cast(byte)243, cast(byte)244, cast(byte)245, cast(byte)246, cast(byte)247, cast(byte)248, cast(byte)249,
         cast(byte)250
-    };
-    
+    ];
+
 public this(byte[] reference) {
     super(reference);
 }
@@ -145,7 +151,7 @@
         int tc = (reference[ofs] & 0xFF) >> 4; // table class: AC (1) or DC (0)
         int tid = reference[ofs] & 0xF; // table id: 0-1 baseline, 0-3 prog/ext
         ofs++;
-        
+
         /* Read the 16 count bytes and add them together to get the table size. */
         int count = 0;
         for (int i = 0; i < bits.length; i++) {
@@ -155,7 +161,7 @@
         }
         ofs += 16;
         totalLength -= 17;
-        
+
         /* Read the table. */
         int[] huffVals = new int[count];
         for (int i = 0; i < count; i++) {
@@ -163,7 +169,7 @@
         }
         ofs += count;
         totalLength -= count;
-        
+
         /* Calculate the lengths. */
         int[] huffCodeLengths = new int[50]; // start with 50 and increment as needed
         int huffCodeLengthsIndex = 0;
@@ -178,14 +184,14 @@
                 huffCodeLengthsIndex++;
             }
         }
-        
+
         /* Truncate huffCodeLengths to the correct size. */
         if (huffCodeLengthsIndex < huffCodeLengths.length) {
             int[] newHuffCodeLengths = new int[huffCodeLengthsIndex];
             System.arraycopy(huffCodeLengths, 0, newHuffCodeLengths, 0, huffCodeLengthsIndex);
             huffCodeLengths = newHuffCodeLengths;
         }
-        
+
         /* Calculate the Huffman codes. */
         int[] huffCodes = new int[50]; // start with 50 and increment as needed
         int huffCodesIndex = 0;
@@ -208,14 +214,14 @@
             code *= 2;
             si++;
         }
-        
+
         /* Truncate huffCodes to the correct size. */
         if (huffCodesIndex < huffCodes.length) {
             int[] newHuffCodes = new int[huffCodesIndex];
             System.arraycopy(huffCodes, 0, newHuffCodes, 0, huffCodesIndex);
             huffCodes = newHuffCodes;
         }
-        
+
         /* Calculate the maximum and minimum codes */
         k = 0;
         int[] maxCodes = new int[16];
@@ -232,7 +238,7 @@
                 maxCodes[i] = huffCodes[k - 1];
             }
         }
-        
+
         /* Calculate the eHuffman codes and lengths. */
         int[] eHuffCodes = new int[256];
         byte[] eHuffSize = new byte[256];
@@ -240,7 +246,7 @@
             eHuffCodes[huffVals[i]] = huffCodes[i];
             eHuffSize[huffVals[i]] = cast(byte)huffCodeLengths[i];
         }
-        
+
         /* Create the new JPEGHuffmanTable and add it to the allTables array. */
         JPEGHuffmanTable dhtTable = new JPEGHuffmanTable(reference);
         dhtTable.tableClass = tc;
@@ -258,7 +264,7 @@
     System.arraycopy(huffTables, 0, allTables, 0, huffTableCount);
 }
 
-public int signature() {
+public override int signature() {
     return JPEGFileFormat.DHT;
 }
 }
--- a/dwt/internal/image/JPEGQuantizationTable.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGQuantizationTable.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,12 +7,19 @@
  *
  * 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.JPEGQuantizationTable;
 
+import dwt.internal.image.LEDataInputStream;
+import dwt.internal.image.JPEGVariableSizeSegment;
+import dwt.internal.image.JPEGFileFormat;
+
+import dwt.dwthelper.System;
 
 final class JPEGQuantizationTable : JPEGVariableSizeSegment {
-    public static byte[] DefaultLuminanceQTable = {
+    public static byte[] DefaultLuminanceQTable = [
         cast(byte)255, cast(byte)219, 0, 67, 0,
         16, 11, 10, 16, 24, 40, 51, 61,
         12, 12, 14, 19, 26, 58, 60, 55,
@@ -22,8 +29,8 @@
         24, 35, 55, 64, 81, 104, 113, 92,
         49, 64, 78, 87, 103, 121, 120, 101,
         72, 92, 95, 98, 112, 100, 103, 99
-    };
-    public static byte[] DefaultChrominanceQTable = {
+    ];
+    public static byte[] DefaultChrominanceQTable = [
         cast(byte)255, cast(byte)219, 0, 67, 1,
         17, 18, 24, 47, 99, 99, 99, 99,
         18, 21, 26, 66, 99, 99, 99, 99,
@@ -33,8 +40,8 @@
         99, 99, 99, 99, 99, 99, 99, 99,
         99, 99, 99, 99, 99, 99, 99, 99,
         99, 99, 99, 99, 99, 99, 99, 99
-    };
-    
+    ];
+
 public this(byte[] reference) {
     super(reference);
 }
@@ -84,7 +91,7 @@
 }
 
 public int[][] getQuantizationTablesValues() {
-    int[][] values = new int[4][];
+    int[][] values = new int[][](4);
     int valuesIndex = 0;
     int totalLength = getSegmentLength() - 2;
     int ofs = 4;
@@ -106,14 +113,14 @@
             totalLength -= 129;
         }
         if (valuesIndex >= values.length) {
-            int[][] newValues = new int[values.length + 4][];
+            int[][] newValues = new int[][](values.length + 4);
             System.arraycopy(values, 0, newValues, 0, values.length);
             values = newValues;
         }
         values[valuesIndex] = qk;
         valuesIndex++;
     }
-    int[][] newValues = new int[valuesIndex][];
+    int[][] newValues = new int[][](valuesIndex);
     System.arraycopy(values, 0, newValues, 0, valuesIndex);
     return newValues;
 }
@@ -159,7 +166,7 @@
     }
 }
 
-public int signature() {
+public override int signature() {
     return JPEGFileFormat.DQT;
 }
 }
--- a/dwt/internal/image/JPEGRestartInterval.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGRestartInterval.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,25 +7,30 @@
  *
  * 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.JPEGRestartInterval;
 
+import dwt.internal.image.JPEGFixedSizeSegment;
+import dwt.internal.image.LEDataInputStream;
+import dwt.internal.image.JPEGFileFormat;
 
 final class JPEGRestartInterval : JPEGFixedSizeSegment {
 
     public this(LEDataInputStream byteStream) {
         super(byteStream);
     }
-    
-    public int signature() {
+
+    public override int signature() {
         return JPEGFileFormat.DRI;
     }
-    
+
     public int getRestartInterval() {
         return ((reference[4] & 0xFF) << 8 | (reference[5] & 0xFF));
     }
 
-    public int fixedSize() {
+    public override int fixedSize() {
         return 6;
     }
 }
--- a/dwt/internal/image/JPEGScanHeader.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGScanHeader.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,11 +7,16 @@
  *
  * 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.JPEGScanHeader;
 
 import dwt.DWT;
+import dwt.internal.image.JPEGVariableSizeSegment;
+import dwt.internal.image.LEDataInputStream;
+import dwt.internal.image.JPEGFileFormat;
+import dwt.dwthelper.utils;
 
 final class JPEGScanHeader : JPEGVariableSizeSegment {
     public int[][] componentParameters;
@@ -48,18 +53,18 @@
 /* Used when decoding. */
 void initializeComponentParameters() {
     int compCount = getNumberOfImageComponents();
-    componentParameters = new int[0][];
+    componentParameters = null;
     for (int i = 0; i < compCount; i++) {
         int ofs = 5 + i * 2;
         int cid = reference[ofs] & 0xFF;
         int dc = (reference[ofs + 1] & 0xFF) >> 4;
         int ac = reference[ofs + 1] & 0xF;
         if (componentParameters.length <= cid) {
-            int[][] newParams = new int[cid + 1][];
+            int[][] newParams = new int[][](cid + 1);
             System.arraycopy(componentParameters, 0, newParams, 0, componentParameters.length);
             componentParameters = newParams;
         }
-        componentParameters[cid] = new int[] { dc, ac };
+        componentParameters[cid] = [ dc, ac ];
     }
 }
 
@@ -90,7 +95,7 @@
     reference[(2 * getNumberOfImageComponents()) + 5] = cast(byte)anInteger;
 }
 
-public int signature() {
+public override int signature() {
     return JPEGFileFormat.SOS;
 }
 
--- a/dwt/internal/image/JPEGSegment.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGSegment.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2003 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,46 +7,51 @@
  *
  * 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.JPEGSegment;
 
+import dwt.internal.image.LEDataOutputStream;
+
+import tango.core.Exception;
 
 class JPEGSegment {
     public byte[] reference;
 
     this() {
     }
-    
+
     public this(byte[] reference) {
         this.reference = reference;
     }
-    
+
     public int signature() {
         return 0;
     }
-    
+
     public bool verify() {
         return getSegmentMarker() is signature();
     }
-    
+
     public int getSegmentMarker() {
         return ((reference[0] & 0xFF) << 8 | (reference[1] & 0xFF));
     }
-    
+
     public void setSegmentMarker(int marker) {
         reference[0] = cast(byte)((marker & 0xFF00) >> 8);
         reference[1] = cast(byte)(marker & 0xFF);
     }
-    
+
     public int getSegmentLength() {
         return ((reference[2] & 0xFF) << 8 | (reference[3] & 0xFF));
     }
-    
+
     public void setSegmentLength(int length) {
         reference[2] = cast(byte)((length & 0xFF00) >> 8);
         reference[3] = cast(byte)(length & 0xFF);
     }
-    
+
     public bool writeToStream(LEDataOutputStream byteStream) {
         try {
             byteStream.write(reference);
--- a/dwt/internal/image/JPEGStartOfImage.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGStartOfImage.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,29 +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.JPEGStartOfImage;
 
+import dwt.internal.image.JPEGFixedSizeSegment;
+import dwt.internal.image.LEDataInputStream;
+import dwt.internal.image.JPEGFileFormat;
 
 final class JPEGStartOfImage : JPEGFixedSizeSegment {
 
     public this() {
         super();
     }
-    
+
     public this(byte[] reference) {
         super(reference);
     }
-    
+
     public this(LEDataInputStream byteStream) {
         super(byteStream);
     }
-    
-    public int signature() {
+
+    public override int signature() {
         return JPEGFileFormat.SOI;
     }
-    
-    public int fixedSize() {
+
+    public override int fixedSize() {
         return 2;
     }
 }
--- a/dwt/internal/image/JPEGVariableSizeSegment.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/JPEGVariableSizeSegment.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2003 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,18 +7,23 @@
  *
  * 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.JPEGVariableSizeSegment;
 
 import dwt.DWT;
+import dwt.internal.image.JPEGSegment;
+import dwt.internal.image.LEDataInputStream;
+
+import tango.core.Exception;
 
 abstract class JPEGVariableSizeSegment : JPEGSegment {
 
     public this(byte[] reference) {
         super(reference);
     }
-    
+
     public this(LEDataInputStream byteStream) {
         try {
             byte[] header = new byte[4];
--- a/dwt/internal/image/LEDataInputStream.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/LEDataInputStream.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,85 +7,92 @@
  *
  * 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.LEDataInputStream;
 
 
-import java.io.IOException;
-import java.io.InputStream;
+import dwt.dwthelper.InputStream;
+import dwt.dwthelper.System;
+import tango.core.Exception;
+
+final class LEDataInputStream : InputStream{
 
-final class LEDataInputStream : InputStream {
+    alias InputStream.read read;
+
+    InputStream host;
+
     int position;
-    InputStream in;
 
     /**
      * The byte array containing the bytes to read.
      */
     protected byte[] buf;
-    
+
     /**
      * The current position within the byte array <code>buf</code>. A value
      * equal to buf.length indicates no bytes available.  A value of
      * 0 indicates the buffer is full.
      */
     protected int pos;
-    
+
 
     public this(InputStream input) {
         this(input, 512);
     }
-    
+
     public this(InputStream input, int bufferSize) {
-        this.in = input;
+        host = input;
         if (bufferSize > 0) {
             buf = new byte[bufferSize];
             pos = bufferSize;
-        } 
-        else throw new IllegalArgumentException();
+        }
+        else throw new IllegalArgumentException("bufferSize must be greater zero" );
     }
-    
+
     public void close() {
         buf = null;
-        if (in !is null) {
-            in.close();
-            in = null;
+        if (host !is null) {
+            host.close();
+            host = null;
         }
     }
-    
+
     /**
      * Answer how many bytes were read.
      */
     public int getPosition() {
         return position;
     }
-    
+
     /**
      * Answers how many bytes are available for reading without blocking
      */
-    public int available() {
-        if (buf is null) throw new IOException();
-        return (buf.length - pos) + in.available();
+    public override int available() {
+        if (buf is null) throw new IOException("buf is null");
+        return (buf.length - pos) + host.available();
     }
-    
+
     /**
      * Answer the next byte of the input stream.
      */
-    public int read() {
-        if (buf is null) throw new IOException();
+    public override int read() {
+        if (buf is null) throw new IOException("buf is null");
         if (pos < buf.length) {
             position++;
             return (buf[pos++] & 0xFF);
         }
-        int c = in.read();
-        if (c !is -1) position++;
+        int c = host.read();
+        if (c !is -1 ) position++;
         return c;
     }
-    
+
     /**
      * Don't imitate the JDK behaviour of reading a random number
      * of bytes when you can actually read them all.
      */
-    public int read(byte b[], int off, int len) {
+    public override int read(byte b[], int off, int len) {
         int read = 0, count;
         while (read !is len && (count = readData(b, off, len - read)) !is -1) {
             off += count;
@@ -95,13 +102,13 @@
         if (read is 0 && read !is len) return -1;
         return read;
     }
-    
+
     /**
-     * Reads at most <code>length</code> bytes from this LEDataInputStream and 
+     * Reads at most <code>length</code> bytes from this LEDataInputStream and
      * stores them in byte array <code>buffer</code> starting at <code>offset</code>.
      * <p>
-     * Answer the number of bytes actually read or -1 if no bytes were read and 
-     * end of stream was encountered.  This implementation reads bytes from 
+     * Answer the number of bytes actually read or -1 if no bytes were read and
+     * end of stream was encountered.  This implementation reads bytes from
      * the pushback buffer first, then the target stream if more bytes are required
      * to satisfy <code>count</code>.
      * </p>
@@ -113,75 +120,75 @@
      *
      * @exception java.io.IOException if an IOException occurs.
      */
-    private int readData(byte[] buffer, int offset, int length) {
-        if (buf is null) throw new IOException();
+    private int readData(byte[] buffer, int offset, int len) {
+        if (buf is null) throw new IOException("buf is null");
         if (offset < 0 || offset > buffer.length ||
-            length < 0 || (length > buffer.length - offset)) {
-            throw new ArrayIndexOutOfBoundsException();
+            len < 0 || (len > buffer.length - offset)) {
+            throw new ArrayBoundsException(__FILE__,__LINE__);
             }
-                
+
         int cacheCopied = 0;
         int newOffset = offset;
-    
+
         // Are there pushback bytes available?
         int available = buf.length - pos;
         if (available > 0) {
-            cacheCopied = (available >= length) ? length : available;
+            cacheCopied = (available >= len) ? len : available;
             System.arraycopy(buf, pos, buffer, newOffset, cacheCopied);
             newOffset += cacheCopied;
             pos += cacheCopied;
         }
-    
+
         // Have we copied enough?
-        if (cacheCopied is length) return length;
+        if (cacheCopied is len) return len;
 
-        int inCopied = in.read(buffer, newOffset, length - cacheCopied);
-
-        if (inCopied > 0) return inCopied + cacheCopied;
+        int inCopied = host.read( buffer, newOffset, len - cacheCopied );
+        if( inCopied is -1 ) inCopied = -1;
+        if (inCopied > 0 ) return inCopied + cacheCopied;
         if (cacheCopied is 0) return inCopied;
         return cacheCopied;
     }
-    
+
     /**
      * Answer an integer comprised of the next
      * four bytes of the input stream.
      */
     public int readInt() {
-        byte[] buf = new byte[4];
+        byte[4] buf = void;
         read(buf);
         return ((buf[3] & 0xFF) << 24) | 
             ((buf[2] & 0xFF) << 16) | 
             ((buf[1] & 0xFF) << 8) | 
             (buf[0] & 0xFF);
     }
-    
+
     /**
      * Answer a short comprised of the next
      * two bytes of the input stream.
      */
     public short readShort() {
-        byte[] buf = new byte[2];
+        byte[2] buf = void;
         read(buf);
         return cast(short)(((buf[1] & 0xFF) << 8) | (buf[0] & 0xFF));
     }
-    
+
     /**
      * Push back the entire content of the given buffer <code>b</code>.
      * <p>
-     * The bytes are pushed so that they would be read back b[0], b[1], etc. 
-     * If the push back buffer cannot handle the bytes copied from <code>b</code>, 
+     * The bytes are pushed so that they would be read back b[0], b[1], etc.
+     * If the push back buffer cannot handle the bytes copied from <code>b</code>,
      * an IOException will be thrown and no byte will be pushed back.
      * </p>
-     * 
+     *
      * @param b the byte array containing bytes to push back into the stream
      *
      * @exception   java.io.IOException if the pushback buffer is too small
      */
     public void unread(byte[] b) {
-        int length = b.length;
-        if (length > pos) throw new IOException();
-        position -= length;
-        pos -= length;
-        System.arraycopy(b, 0, buf, pos, length);
+        int l = b.length;
+        if (l > pos) throw new IOException("cannot unread");
+        position -= l;
+        pos -= l;
+        System.arraycopy(b, 0, buf, pos, l);
     }
 }
--- a/dwt/internal/image/LEDataOutputStream.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/LEDataOutputStream.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,53 +7,58 @@
  *
  * 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.LEDataOutputStream;
 
 
-import java.io.IOException;
-import java.io.OutputStream;
+import dwt.dwthelper.OutputStream;
 
 final class LEDataOutputStream : OutputStream {
-    OutputStream out;
+
+    alias OutputStream.write write;
+
+    OutputStream ostr;
+
 public this(OutputStream output) {
-    this.out = output;
+    this.ostr = output;
 }
 /**
  * Write the specified number of bytes of the given byte array,
  * starting at the specified offset, to the output stream.
  */
-public void write(byte b[], int off, int len) {
-    out.write(b, off, len);
+public override void write(byte b[], int off, int len) {
+    ostr.write(b, off, len);
 }
 /**
  * Write the given byte to the output stream.
  */
-public void write(int b) {
-    out.write(b);
+public override void write(int b)  {
+    ostr.write(b);
 }
 /**
  * Write the given byte to the output stream.
  */
 public void writeByte(byte b) {
-    out.write(b & 0xFF);
+    ostr.write(b);
 }
 /**
  * Write the four bytes of the given integer
  * to the output stream.
  */
 public void writeInt(int theInt) {
-    out.write(theInt & 0xFF);
-    out.write((theInt >> 8) & 0xFF);
-    out.write((theInt >> 16) & 0xFF);
-    out.write((theInt >> 24) & 0xFF);
+    ostr.write(theInt & 0xFF);
+    ostr.write((theInt >> 8) & 0xFF);
+    ostr.write((theInt >> 16) & 0xFF);
+    ostr.write((theInt >> 24) & 0xFF);
 }
 /**
  * Write the two bytes of the given short
  * to the output stream.
  */
 public void writeShort(int theShort) {
-    out.write(theShort & 0xFF);
-    out.write((theShort >> 8) & 0xFF);
+    ostr.write(theShort & 0xFF);
+    ostr.write((theShort >> 8) & 0xFF);
 }
 }
--- a/dwt/internal/image/LZWCodec.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/LZWCodec.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,14 +7,22 @@
  *
  * 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.LZWCodec;
 
 
+import dwt.internal.image.LZWNode;
+import dwt.internal.image.LEDataInputStream;
+import dwt.internal.image.LEDataOutputStream;
 import dwt.DWT;
 import dwt.graphics.ImageData;
 import dwt.graphics.ImageLoader;
 import dwt.graphics.ImageLoaderEvent;
+import dwt.dwthelper.utils;
+
+import tango.core.Exception;
 
 final class LZWCodec {
     int bitsPerPixel, blockSize, blockIndex, currentByte, bitsLeft,
@@ -28,10 +36,10 @@
     ImageData image;
     ImageLoader loader;
     bool interlaced;
-    static final int[] MASK_TABLE = new int[] {
+    static final int[] MASK_TABLE = [
         0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F,
         0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF
-    };
+    ];
 
 /**
  * Decode the input.
--- a/dwt/internal/image/LZWNode.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/LZWNode.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2003 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,8 +7,10 @@
  *
  * 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.LZWNode;
 
 
 final class LZWNode {
--- a/dwt/internal/image/OS2BMPFileFormat.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/OS2BMPFileFormat.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,26 +7,29 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
-module dwt.internal.image;
-
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
+module dwt.internal.image.OS2BMPFileFormat;
 
 import dwt.DWT;
 import dwt.graphics.ImageData;
 import dwt.graphics.ImageLoader;
 import dwt.graphics.PaletteData;
 import dwt.graphics.RGB;
+import dwt.internal.image.LEDataInputStream;
+import dwt.internal.image.FileFormat;
+import dwt.dwthelper.ByteArrayOutputStream;
+import dwt.dwthelper.utils;
 
-public final class OS2BMPFileFormat : FileFormat {
+import tango.core.Exception;
+
+final class OS2BMPFileFormat : FileFormat {
     static final int BMPFileHeaderSize = 14;
     static final int BMPHeaderFixedSize = 12;
     int width, height, bitCount;
 
-bool isFileFormat(LEDataInputStream stream) {
+override bool isFileFormat(LEDataInputStream stream) {
     try {
         byte[] header = new byte[18];
         stream.read(header);
@@ -70,7 +73,7 @@
         DWT.error(DWT.ERROR_INVALID_IMAGE);
     return header;
 }
-ImageData[] loadFromByteStream() {
+override ImageData[] loadFromByteStream() {
     int[] fileHeader = loadFileHeader();
     byte[] infoHeader = new byte[BMPHeaderFixedSize];
     try {
@@ -92,7 +95,7 @@
     }
     byte[] data = loadData(infoHeader);
     int type = DWT.IMAGE_OS2_BMP;
-    return new ImageData[] {
+    return [
         ImageData.internal_new(
             width,
             height,
@@ -110,7 +113,7 @@
             0,
             0,
             0)
-    };
+    ];
 }
 PaletteData loadPalette(byte[] infoHeader) {
     if (bitCount <= 8) {
@@ -157,10 +160,10 @@
     return bytes;
 }
 /**
- * Unload the given image's data into the given byte stream. 
+ * Unload the given image's data into the given byte stream.
  * Answer the number of bytes written.
  */
-int unloadData(ImageData image, OutputStream out) {
+int unloadData(ImageData image, OutputStream ostr) {
     int bmpBpl = 0;
     try {
         int bpl = (image.width * image.depth + 7) / 8;
@@ -183,7 +186,7 @@
                     bufOffset += bmpBpl;
                     dataIndex -= imageBpl;
                 }
-                out.write(buf, 0, bufOffset);
+                ostr.write(buf, 0, bufOffset);
             }
         } else {
             for (int y = 0; y < image.height; y += linesPerBuf) {
@@ -195,7 +198,7 @@
                     bufOffset += bmpBpl;
                     dataIndex -= imageBpl;
                 }
-                out.write(buf, 0, bufOffset);
+                ostr.write(buf, 0, bufOffset);
             }
         }
     } catch (IOException e) {
@@ -207,7 +210,7 @@
  * Unload a DeviceIndependentImage using Windows .BMP format into the given
  * byte stream.
  */
-void unloadIntoByteStream(ImageLoader loader) {
+override void unloadIntoByteStream(ImageLoader loader) {
     ImageData image = loader.data[0];
     byte[] rgbs;
     int numCols;
@@ -240,10 +243,10 @@
 
     // Prepare data. This is done first so we don't have to try to rewind
     // the stream and fill in the details later.
-    ByteArrayOutputStream out = new ByteArrayOutputStream();
-    unloadData(image, out);
-    byte[] data = out.toByteArray();
-    
+    ByteArrayOutputStream ostr = new ByteArrayOutputStream();
+    unloadData(image, ostr);
+    byte[] data = ostr.toByteArray();
+
     // Calculate file size
     fileHeader[1] = fileHeader[4] + data.length;
 
@@ -266,7 +269,7 @@
     } catch (IOException e) {
         DWT.error(DWT.ERROR_IO, e);
     }
-    
+
     // Unload palette
     if (numCols > 0) {
         try {
--- a/dwt/internal/image/PNGFileFormat.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PNGFileFormat.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,21 +7,35 @@
  *
  * 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.PNGFileFormat;
 
 
-import java.io.IOException;
-import java.io.InputStream;
-
 import dwt.DWT;
 import dwt.graphics.ImageData;
+import dwt.graphics.ImageLoaderEvent;
 import dwt.graphics.ImageLoader;
-import dwt.graphics.ImageLoaderEvent;
 import dwt.graphics.PaletteData;
 import dwt.internal.Compatibility;
+import dwt.internal.image.FileFormat;
+import dwt.internal.image.PngIhdrChunk;
+import dwt.internal.image.PngPlteChunk;
+import dwt.internal.image.PngChunkReader;
+import dwt.internal.image.PngChunk;
+import dwt.internal.image.PngTrnsChunk;
+import dwt.internal.image.PngIdatChunk;
+import dwt.internal.image.PngEncoder;
+import dwt.internal.image.PngInputStream;
+import dwt.internal.image.PngDecodingDataStream;
+import dwt.dwthelper.utils;
 
-public final class PNGFileFormat : FileFormat {
+import dwt.dwthelper.BufferedInputStream;
+
+import tango.core.Exception;
+
+final class PNGFileFormat : FileFormat {
     static final int SIGNATURE_LENGTH = 8;
     static final int PRIME = 65521;
     PngIhdrChunk headerChunk;
@@ -35,16 +49,16 @@
 
 /**
  * Skip over signature data. This has already been
- * verified in isFileFormat(). 
+ * verified in isFileFormat().
  */
-void readSignature() {
+void readSignature()  {
     byte[] signature = new byte[SIGNATURE_LENGTH];
     inputStream.read(signature);
 }
 /**
  * Load the PNG image from the byte stream.
  */
-ImageData[] loadFromByteStream() {
+override ImageData[] loadFromByteStream() {
     try {
         readSignature();
         PngChunkReader chunkReader = new PngChunkReader(inputStream);
@@ -52,7 +66,7 @@
         int width = headerChunk.getWidth(), height = headerChunk.getHeight();
         if (width <= 0 || height <= 0) DWT.error(DWT.ERROR_INVALID_IMAGE);
         int imageSize = getAlignedBytesPerRow() * height;
-        data = new byte[imageSize];     
+        data = new byte[imageSize];
         imageData = ImageData.internal_new(
             width,
             height,
@@ -69,28 +83,28 @@
             0,
             0,
             0,
-            0);     
-            
+            0);
+
         if (headerChunk.usesDirectColor()) {
             imageData.palette = headerChunk.getPaletteData();
         }
-        
+
         // Read and process chunks until the IEND chunk is encountered.
         while (chunkReader.hasMoreChunks()) {
             readNextChunk(chunkReader);
         }
-                        
-        return new ImageData[] {imageData};
+
+        return [imageData];
     } catch (IOException e) {
         DWT.error(DWT.ERROR_INVALID_IMAGE);
         return null;
     }
 }
 /**
- * Read and handle the next chunk of data from the 
+ * Read and handle the next chunk of data from the
  * PNG file.
  */
-void readNextChunk(PngChunkReader chunkReader) {
+void readNextChunk(PngChunkReader chunkReader)  {
     PngChunk chunk = chunkReader.readNextChunk();
     switch (chunk.getChunkType()) {
         case PngChunk.CHUNK_IEND:
@@ -98,15 +112,15 @@
         case PngChunk.CHUNK_PLTE:
             if (!headerChunk.usesDirectColor()) {
                 paletteChunk = cast(PngPlteChunk) chunk;
-                imageData.palette = paletteChunk.getPaletteData();                      
-            }           
+                imageData.palette = paletteChunk.getPaletteData();
+            }
             break;
         case PngChunk.CHUNK_tRNS:
             PngTrnsChunk trnsChunk = cast(PngTrnsChunk) chunk;
-            if (trnsChunk.getTransparencyType(headerChunk) is 
-                PngTrnsChunk.TRANSPARENCY_TYPE_PIXEL) 
+            if (trnsChunk.getTransparencyType(headerChunk) is
+                PngTrnsChunk.TRANSPARENCY_TYPE_PIXEL)
             {
-                imageData.transparentPixel = 
+                imageData.transparentPixel =
                     trnsChunk.getSwtTransparentPixel(headerChunk);
             } else {
                 alphaPalette = trnsChunk.getAlphaValues(headerChunk, paletteChunk);
@@ -134,9 +148,9 @@
                 DWT.error(DWT.ERROR_INVALID_IMAGE);
             } else {
                 // Read in the pixel data for the image. This should
-                // go through all the image's IDAT chunks.  
+                // go through all the image's IDAT chunks.
                 PngIdatChunk dataChunk = cast(PngIdatChunk) chunk;
-                readPixelData(dataChunk, chunkReader);              
+                readPixelData(dataChunk, chunkReader);
             }
             break;
         default:
@@ -146,11 +160,11 @@
             }
     }
 }
-void unloadIntoByteStream(ImageLoader loader) {
+override void unloadIntoByteStream(ImageLoader loader) {
     PngEncoder encoder = new PngEncoder(loader);
     encoder.encode(outputStream);
 }
-bool isFileFormat(LEDataInputStream stream) {
+override bool isFileFormat(LEDataInputStream stream) {
     try {
         byte[] signature = new byte[SIGNATURE_LENGTH];
         stream.read(signature);
@@ -162,7 +176,7 @@
         if ((signature[4] & 0xFF) !is 13) return false; //<RETURN>
         if ((signature[5] & 0xFF) !is 10) return false; //<LINEFEED>
         if ((signature[6] & 0xFF) !is 26) return false; //<CTRL/Z>
-        if ((signature[7] & 0xFF) !is 10) return false; //<LINEFEED>        
+        if ((signature[7] & 0xFF) !is 10) return false; //<LINEFEED>     
         return true;
     } catch (Exception e) {
         return false;
@@ -256,7 +270,7 @@
             imageData.data = rgbData;
             imageData.alphaData = alphaData;
             break;
-        }       
+        }
         case PngIhdrChunk.COLOR_TYPE_RGB:
             imageData.data = data;
             break;
@@ -279,7 +293,7 @@
     }
 }
 /**
- * PNG supports some color types and bit depths that are 
+ * PNG supports some color types and bit depths that are
  * unsupported by DWT. If the image uses an unsupported
  * color type (either of the gray scale types) or bit
  * depth (16), convert the data to an DWT-supported
@@ -293,10 +307,11 @@
  * Read the image data from the data stream. This must handle
  * decoding the data, filtering, and interlacing.
  */
-void readPixelData(PngIdatChunk chunk, PngChunkReader chunkReader) {
+void readPixelData(PngIdatChunk chunk, PngChunkReader chunkReader)  {
     InputStream stream = new PngInputStream(chunk, chunkReader);
     //TEMPORARY CODE
-    bool use3_2 = System.getProperty("dwt.internal.image.PNGFileFormat_3.2") !is null;
+    //PORTING_FIXME
+    bool use3_2 = true;//System.getProperty("dwt.internal.image.PNGFileFormat_3.2") !is null;
     InputStream inflaterStream = use3_2 ? null : Compatibility.newInflaterInputStream(stream);
     if (inflaterStream !is null) {
         stream = inflaterStream;
@@ -335,13 +350,13 @@
 /**
  * Answer the number of bytes needed to represent a pixel.
  * This value depends on the image's color type and bit
- * depth. 
+ * depth.
  * Note that this method rounds up if an image's pixel size
  * isn't byte-aligned.
  */
 int getBytesPerPixel() {
     int bitsPerPixel = headerChunk.getBitsPerPixel();
-    return (bitsPerPixel + 7) / 8;  
+    return (bitsPerPixel + 7) / 8;
 }
 /**
  * Answer the number of bytes in a row of the given pixel
@@ -372,13 +387,13 @@
     int alignedBytesPerRow = getAlignedBytesPerRow();
     int height = headerChunk.getHeight();
     if (startRow >= height || startColumn >= width) return;
-    
+
     int pixelsPerRow = (width - startColumn + columnInterval - 1) / columnInterval;
     int bytesPerRow = getBytesPerRow(pixelsPerRow);
     byte[] row1 = new byte[bytesPerRow];
     byte[] row2 = new byte[bytesPerRow];
-    byte[] currentRow = row1;   
-    byte[] lastRow = row2;  
+    byte[] currentRow = row1;
+    byte[] lastRow = row2;
     for (int row = startRow; row < height; row += rowInterval) {
         byte filterType = cast(byte)inputStream.read();
         int read = 0;
@@ -409,7 +424,7 @@
             for (int byteOffset = 0; byteOffset < currentRow.length; byteOffset++) {
                 for (int bitOffset = maxShift; bitOffset >= 0; bitOffset -= bitsPerPixel) {
                     if (column < width) {
-                        int dataOffset = rowBase + (column * bitsPerPixel / 8);                         
+                        int dataOffset = rowBase + (column * bitsPerPixel / 8);
                         int value = (currentRow[byteOffset] >> bitOffset) & valueMask;
                         int dataShift = maxShift - (bitsPerPixel * (column % pixelsPerByte));
                         data[dataOffset] |= value << dataShift;
@@ -428,13 +443,13 @@
  * Read the pixel data for an interlaced image from the
  * data stream.
  */
-void readInterlacedImage(InputStream inputStream) {
+void readInterlacedImage(InputStream inputStream)  {
     readInterlaceFrame(inputStream, 8, 8, 0, 0, 0);
-    readInterlaceFrame(inputStream, 8, 8, 0, 4, 1); 
-    readInterlaceFrame(inputStream, 8, 4, 4, 0, 2); 
+    readInterlaceFrame(inputStream, 8, 8, 0, 4, 1);
+    readInterlaceFrame(inputStream, 8, 4, 4, 0, 2);
     readInterlaceFrame(inputStream, 4, 4, 0, 2, 3);
     readInterlaceFrame(inputStream, 4, 2, 2, 0, 4);
-    readInterlaceFrame(inputStream, 2, 2, 0, 1, 5); 
+    readInterlaceFrame(inputStream, 2, 2, 0, 1, 5);
     readInterlaceFrame(inputStream, 2, 1, 1, 0, 6);
 }
 /**
@@ -455,13 +470,13 @@
  * data stream.
  * Update the imageData to reflect the new data.
  */
-void readNonInterlacedImage(InputStream inputStream) {
+void readNonInterlacedImage(InputStream inputStream)  {
     int dataOffset = 0;
     int alignedBytesPerRow = getAlignedBytesPerRow();
     int bytesPerRow = getBytesPerRow();
     byte[] row1 = new byte[bytesPerRow];
     byte[] row2 = new byte[bytesPerRow];
-    byte[] currentRow = row1;   
+    byte[] currentRow = row1;
     byte[] lastRow = row2;
     int height = headerChunk.getHeight();
     for (int row = 0; row < height; row++) {
@@ -490,16 +505,16 @@
 static void compress16BitDepthTo8BitDepth(
     byte[] source,
     int sourceOffset,
-    byte[] destination, 
+    byte[] destination,
     int destinationOffset,
-    int numberOfValues) 
+    int numberOfValues)
 {
     //double multiplier = (Compatibility.pow2(8) - 1) / (Compatibility.pow2(16) - 1);
     for (int i = 0; i < numberOfValues; i++) {
         int sourceIndex = sourceOffset + (2 * i);
         int destinationIndex = destinationOffset + i;
         //int value = (source[sourceIndex] << 8) | source[sourceIndex + 1];
-        //byte compressedValue = cast(byte)(value * multiplier);
+        //byte compressedValue = (byte)(value * multiplier);
         byte compressedValue = source[sourceIndex];
         destination[destinationIndex] = compressedValue;
     }
@@ -515,7 +530,7 @@
  */
 static int compress16BitDepthTo8BitDepth(int value) {
     //double multiplier = (Compatibility.pow2(8) - 1) / (Compatibility.pow2(16) - 1);
-    //byte compressedValue = cast(byte)(value * multiplier);
+    //byte compressedValue = (byte)(value * multiplier);
     return value >> 8;
 }
 /**
@@ -538,7 +553,7 @@
         case PngIhdrChunk.FILTER_UP:
             for (int i = 0; i < row.length; i++) {
                 int current = row[i] & 0xFF;
-                int above = previousRow[i] & 0xFF;              
+                int above = previousRow[i] & 0xFF;
                 row[i] = cast(byte)((current + above) & 0xFF);
             }
             break;
@@ -555,11 +570,11 @@
                 int left = (i < byteOffset) ? 0 : row[i - byteOffset] & 0xFF;
                 int aboveLeft = (i < byteOffset) ? 0 : previousRow[i - byteOffset] & 0xFF;
                 int above = previousRow[i] & 0xFF;
-                
+
                 int a = Math.abs(above - aboveLeft);
                 int b = Math.abs(left - aboveLeft);
                 int c = Math.abs(left - aboveLeft + above - aboveLeft);
-                
+
                 int preductor = 0;
                 if (a <= b && a <= c) {
                     preductor = left;
@@ -568,11 +583,12 @@
                 } else {
                     preductor = aboveLeft;
                 }
-                
+
                 int currentValue = row[i] & 0xFF;
                 row[i] = cast(byte) ((currentValue + preductor) & 0xFF);
             }
             break;
+        default:
     }
 }
 
--- a/dwt/internal/image/PngChunk.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngChunk.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,42 +7,54 @@
  *
  * 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.PngChunk;
 
 
-import java.io.IOException;
+import dwt.DWT;
+import dwt.internal.image.LEDataInputStream;
+import dwt.internal.image.PngFileReadState;
+import dwt.internal.image.PngIhdrChunk;
+import dwt.internal.image.PngPlteChunk;
+import dwt.internal.image.PngIdatChunk;
+import dwt.internal.image.PngIendChunk;
+import dwt.internal.image.PngTrnsChunk;
+import dwt.dwthelper.utils;
 
-import dwt.DWT;
+import tango.core.Exception;
+import tango.text.convert.Format;
 
-class PngChunk : Object {
+class PngChunk {
     byte[] reference;
 
-    static final int LENGTH_OFFSET = 0;
-    static final int TYPE_OFFSET = 4;
-    static final int DATA_OFFSET = 8;
+    static const int LENGTH_OFFSET = 0;
+    static const int TYPE_OFFSET = 4;
+    static const int DATA_OFFSET = 8;
 
-    static final int TYPE_FIELD_LENGTH = 4;
-    static final int LENGTH_FIELD_LENGTH = 4;
-    static final int MIN_LENGTH = 12;
+    static const int TYPE_FIELD_LENGTH = 4;
+    static const int LENGTH_FIELD_LENGTH = 4;
+    static const int MIN_LENGTH = 12;
 
-    static final int CHUNK_UNKNOWN = -1;
+    static const int CHUNK_UNKNOWN = -1;
     // Critical chunks.
-    static final int CHUNK_IHDR = 0;
-    static final int CHUNK_PLTE = 1;
-    static final int CHUNK_IDAT = 2;
-    static final int CHUNK_IEND = 3;
+    static const int CHUNK_IHDR = 0;
+    static const int CHUNK_PLTE = 1;
+    static const int CHUNK_IDAT = 2;
+    static const int CHUNK_IEND = 3;
     // Non-critical chunks.
-    static final int CHUNK_tRNS = 5;
-    
-    static final byte[] TYPE_IHDR = {cast(byte) 'I', cast(byte) 'H', cast(byte) 'D', cast(byte) 'R'};
-    static final byte[] TYPE_PLTE = {cast(byte) 'P', cast(byte) 'L', cast(byte) 'T', cast(byte) 'E'};
-    static final byte[] TYPE_IDAT = {cast(byte) 'I', cast(byte) 'D', cast(byte) 'A', cast(byte) 'T'};
-    static final byte[] TYPE_IEND = {cast(byte) 'I', cast(byte) 'E', cast(byte) 'N', cast(byte) 'D'};
-    static final byte[] TYPE_tRNS = {cast(byte) 't', cast(byte) 'R', cast(byte) 'N', cast(byte) 'S'};
-    
-    static final int[] CRC_TABLE;
-    static {
+    static const int CHUNK_tRNS = 5;
+
+    static const byte[] TYPE_IHDR = cast(byte[])"IHDR";//{(byte) 'I', (byte) 'H', (byte) 'D', (byte) 'R'};
+    static const byte[] TYPE_PLTE = cast(byte[])"PLTE";//{(byte) 'P', (byte) 'L', (byte) 'T', (byte) 'E'};
+    static const byte[] TYPE_IDAT = cast(byte[])"IDAT";//{(byte) 'I', (byte) 'D', (byte) 'A', (byte) 'T'};
+    static const byte[] TYPE_IEND = cast(byte[])"IEND";//{(byte) 'I', (byte) 'E', (byte) 'N', (byte) 'D'};
+    static const byte[] TYPE_tRNS = cast(byte[])"tRNS";//{(byte) 't', (byte) 'R', (byte) 'N', (byte) 'S'};
+
+    static const int[] CRC_TABLE;
+    //public static void static_this() {
+    static this() {
         CRC_TABLE = new int[256];
         for (int i = 0; i < 256; i++) {
             CRC_TABLE[i] = i;
@@ -53,17 +65,16 @@
                     CRC_TABLE[i] = 0xEDB88320 ^ ((CRC_TABLE[i] >> 1) & 0x7FFFFFFF);
                 }
             }
-        }   
+        }
     }
-    
+
     int length;
-    
+
 /**
  * Construct a PngChunk using the reference bytes
  * given.
- */ 
+ */
 this(byte[] reference) {
-    super();
     setReference(reference);
     if (reference.length < LENGTH_OFFSET + LENGTH_FIELD_LENGTH) DWT.error(DWT.ERROR_INVALID_IMAGE);
     length = getInt32(LENGTH_OFFSET);
@@ -72,7 +83,7 @@
 /**
  * Construct a PngChunk with the specified number of
  * data bytes.
- */ 
+ */
 this(int dataLength) {
     this(new byte[MIN_LENGTH + dataLength]);
     setLength(dataLength);
@@ -80,14 +91,14 @@
 
 /**
  * Get the PngChunk's reference byteArray;
- */ 
+ */
 byte[] getReference() {
     return reference;
 }
 
 /**
  * Set the PngChunk's reference byteArray;
- */ 
+ */
 void setReference(byte[] reference) {
     this.reference = reference;
 }
@@ -95,18 +106,18 @@
 /**
  * Get the 16-bit integer from the reference byte
  * array at the given offset.
- */ 
+ */
 int getInt16(int offset) {
     int answer = 0;
     answer |= (reference[offset] & 0xFF) << 8;
     answer |= (reference[offset + 1] & 0xFF);
-    return answer;  
+    return answer;
 }
 
 /**
  * Set the 16-bit integer in the reference byte
  * array at the given offset.
- */ 
+ */
 void setInt16(int offset, int value) {
     reference[offset] = cast(byte) ((value >> 8) & 0xFF);
     reference[offset + 1] = cast(byte) (value & 0xFF);
@@ -115,20 +126,20 @@
 /**
  * Get the 32-bit integer from the reference byte
  * array at the given offset.
- */ 
+ */
 int getInt32(int offset) {
     int answer = 0;
     answer |= (reference[offset] & 0xFF) << 24;
     answer |= (reference[offset + 1] & 0xFF) << 16;
     answer |= (reference[offset + 2] & 0xFF) << 8;
     answer |= (reference[offset + 3] & 0xFF);
-    return answer;  
+    return answer;
 }
 
 /**
  * Set the 32-bit integer in the reference byte
  * array at the given offset.
- */ 
+ */
 void setInt32(int offset, int value) {
     reference[offset] = cast(byte) ((value >> 24) & 0xFF);
     reference[offset + 1] = cast(byte) ((value >> 16) & 0xFF);
@@ -139,7 +150,7 @@
 /**
  * Get the length of the data component of this chunk.
  * This is not the length of the entire chunk.
- */ 
+ */
 int getLength() {
     return length;
 }
@@ -147,7 +158,7 @@
 /**
  * Set the length of the data component of this chunk.
  * This is not the length of the entire chunk.
- */ 
+ */
 void setLength(int value) {
     setInt32(LENGTH_OFFSET, value);
     length = value;
@@ -159,14 +170,14 @@
  * The first byte is upper case if the chunk is critical.
  * The second byte is upper case if the chunk is publicly defined.
  * The third byte must be upper case.
- * The fourth byte is upper case if the chunk is unsafe to copy. 
+ * The fourth byte is upper case if the chunk is unsafe to copy.
  * Public chunk types are defined by the PNG Development Group.
- */ 
+ */
 byte[] getTypeBytes() {
     byte[] type = new byte[4];
     System.arraycopy(reference, TYPE_OFFSET, type, 0, TYPE_FIELD_LENGTH);
     return type;
-}   
+}
 
 /**
  * Set the chunk type. This is a four byte value.
@@ -174,9 +185,9 @@
  * The first byte is upper case if the chunk is critical.
  * The second byte is upper case if the chunk is publicly defined.
  * The third byte must be upper case.
- * The fourth byte is upper case if the chunk is unsafe to copy. 
+ * The fourth byte is upper case if the chunk is unsafe to copy.
  * Public chunk types are defined by the PNG Development Group.
- */ 
+ */
 void setType(byte[] value) {
     if (value.length !is TYPE_FIELD_LENGTH) {
         DWT.error (DWT.ERROR_INVALID_ARGUMENT);
@@ -268,12 +279,12 @@
         if (reference[TYPE_OFFSET + i] !is array[i]){
             return false;
         }
-    }   
+    }
     return true;
 }
 
 bool isCritical() {
-    char c = cast(wchar) getTypeBytes()[0]; 
+    char c = cast(char) getTypeBytes()[0];
     return 'A' <= c && c <= 'Z';
 }
 
@@ -282,7 +293,7 @@
     if (typeMatchesArray(TYPE_PLTE)) return CHUNK_PLTE;
     if (typeMatchesArray(TYPE_IDAT)) return CHUNK_IDAT;
     if (typeMatchesArray(TYPE_IEND)) return CHUNK_IEND;
-    if (typeMatchesArray(TYPE_tRNS)) return CHUNK_tRNS; 
+    if (typeMatchesArray(TYPE_tRNS)) return CHUNK_tRNS;
     return CHUNK_UNKNOWN;
 }
 
@@ -297,14 +308,15 @@
         int result = stream.read(headerBytes, 0, headerLength);
         stream.unread(headerBytes);
         if (result !is headerLength) return null;
-        
+
         PngChunk tempChunk = new PngChunk(headerBytes);
-        
+
         int chunkLength = tempChunk.getSize();
         byte[] chunk = new byte[chunkLength];
+
         result = stream.read(chunk, 0, chunkLength);
         if (result !is chunkLength) return null;
-    
+
         switch (tempChunk.getChunkType()) {
             case CHUNK_IHDR:
                 return new PngIhdrChunk(chunk);
@@ -318,7 +330,7 @@
                 return new PngTrnsChunk(chunk);
             default:
                 return new PngChunk(chunk);
-        }       
+        }
     } catch (IOException e) {
         return null;
     }
@@ -329,21 +341,21 @@
  */
 void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
     if (reference.length < MIN_LENGTH) DWT.error(DWT.ERROR_INVALID_IMAGE);
-    
+
     byte[] type = getTypeBytes();
-    
+
     // The third character MUST be upper case.
-    char c = cast(wchar) type[2];
+    char c = cast(char) type[2];
     if (!('A' <= c && c <= 'Z')) DWT.error(DWT.ERROR_INVALID_IMAGE);
-    
+
     // All characters must be letters.
     for (int i = 0; i < TYPE_FIELD_LENGTH; i++) {
-        c = cast(wchar) type[i];
+        c = cast(char) type[i];
         if (!(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))) {
             DWT.error(DWT.ERROR_INVALID_IMAGE);
         }
     }
-    
+
     // The stored CRC must match the data's computed CRC.
     if (!checkCRC()) DWT.error(DWT.ERROR_INVALID_IMAGE);
 }
@@ -352,31 +364,23 @@
  * Provided so that subclasses can override and add
  * data to the toString() call.
  */
-void contributeToString(StringBuffer buffer) {}
+String contributeToString() {
+    return "";
+}
 
 /**
- * Returns a String containing a concise, human-readable
+ * Returns a string containing a concise, human-readable
  * description of the receiver.
  *
- * @return a String representation of the event
+ * @return a string representation of the event
  */
-public String toString() {
-    StringBuffer buffer = new StringBuffer();
-    buffer.append("{");
-    buffer.append("\n\tLength: ");
-    buffer.append(getLength());
-    buffer.append("\n\tType: ");
-    byte[] type = getTypeBytes();
-    for(int i = 0; i < type.length; i++) {
-        buffer.append(cast(wchar) type[i]);
-    }
-    
-    contributeToString(buffer);
-    
-    buffer.append("\n\tCRC: ");
-    buffer.append(Integer.toHexString(getCRC()));
-    buffer.append("\n}");
-    return buffer.toString();
+public override String toString() {
+    String buffer = Format( "{\n\tLength: {}\n\tType: {}{}\n\tCRC: {:X}\n}",
+        getLength(),
+        cast(String) getTypeBytes(),
+        contributeToString(),
+        getCRC());
+    return buffer;
 }
 
 }
--- a/dwt/internal/image/PngChunkReader.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngChunkReader.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2006 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,18 +7,26 @@
  *
  * 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.PngChunkReader;
 
 
 import dwt.DWT;
+import dwt.internal.image.LEDataInputStream;
+import dwt.internal.image.PngFileReadState;
+import dwt.internal.image.PngIhdrChunk;
+import dwt.internal.image.PngPlteChunk;
+import dwt.internal.image.PngTrnsChunk;
+import dwt.internal.image.PngChunk;
 
 public class PngChunkReader {
     LEDataInputStream inputStream;
     PngFileReadState readState;
     PngIhdrChunk headerChunk;
     PngPlteChunk paletteChunk;
-    
+
 this(LEDataInputStream inputStream) {
     this.inputStream = inputStream;
     readState = new PngFileReadState();
@@ -27,12 +35,12 @@
 
 PngIhdrChunk getIhdrChunk() {
     if (headerChunk is null) {
-        try { 
-            PngChunk chunk = PngChunk.readNextFromStream(inputStream);
-            if (chunk is null) DWT.error(DWT.ERROR_INVALID_IMAGE);
-            headerChunk = cast(PngIhdrChunk) chunk;
+        PngChunk chunk = PngChunk.readNextFromStream(inputStream);
+        if (chunk is null) DWT.error(DWT.ERROR_INVALID_IMAGE);
+        if(( headerChunk = cast(PngIhdrChunk) chunk ) !is null ){
             headerChunk.validate(readState, null);
-        } catch (ClassCastException e) {
+        }
+        else{
             DWT.error(DWT.ERROR_INVALID_IMAGE);
         }
     }
@@ -41,7 +49,7 @@
 
 PngChunk readNextChunk() {
     if (headerChunk is null) return getIhdrChunk();
-    
+
     PngChunk chunk = PngChunk.readNextFromStream(inputStream);
     if (chunk is null) DWT.error(DWT.ERROR_INVALID_IMAGE);
     switch (chunk.getChunkType()) {
--- a/dwt/internal/image/PngDecodingDataStream.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngDecodingDataStream.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,26 +7,31 @@
  *
  * 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.PngDecodingDataStream;
 
 
-import java.io.IOException;
-import java.io.InputStream;
+import dwt.dwthelper.InputStream;
 
 import dwt.DWT;
+import dwt.internal.image.PngLzBlockReader;
 
 public class PngDecodingDataStream : InputStream {
+
+    alias InputStream.read read;
+
     InputStream stream;
     byte currentByte;
     int nextBitIndex;
-    
+
     PngLzBlockReader lzBlockReader;
     int adlerValue;
-    
+
     static final int PRIME = 65521;
-    static final int MAX_BIT = 7;       
-    
+    static final int MAX_BIT = 7;
+
 this(InputStream stream) {
     super();
     this.stream = stream;
@@ -40,7 +45,7 @@
 /**
  * This method should be called when the image decoder thinks
  * that all of the compressed image data has been read. This
- * method will ensure that the next data value is an end of 
+ * method will ensure that the next data value is an end of
  * block marker. If there are more blocks after this one,
  * the method will read them and ensure that they are empty.
  */
@@ -48,7 +53,7 @@
     lzBlockReader.assertCompressedDataAtEnd();
 }
 
-public void close() {
+public override void close() {
     assertImageDataAtEnd();
     checkAdler();
 }
@@ -69,7 +74,7 @@
     return (currentByte & (1 << nextBitIndex)) >> nextBitIndex++;
 }
 
-byte getNextIdatByte() { 
+byte getNextIdatByte() {
     byte nextByte = cast(byte)stream.read();
     nextBitIndex = MAX_BIT + 1;
     return nextByte;
@@ -84,13 +89,13 @@
     adlerValue = (high << 16) | low;
 }
 
-public int read() {
+public override int read() {
     byte nextDecodedByte = lzBlockReader.getNextByte();
     updateAdler(nextDecodedByte);
     return nextDecodedByte & 0xFF;
 }
 
-public int read(byte[] buffer, int off, int len) {
+public override int read(byte[] buffer, int off, int len) {
     for (int i = 0; i < len; i++) {
         int b = read();
         if (b is -1) return i;
@@ -106,29 +111,30 @@
 private void readCompressedDataHeader() {
     byte headerByte1 = getNextIdatByte();
     byte headerByte2 = getNextIdatByte();
-    
+
     int number = ((headerByte1 & 0xFF) << 8) | (headerByte2 & 0xFF);
     if (number % 31 !is 0) error();
-    
+
     int compressionMethod = headerByte1 & 0x0F;
     if (compressionMethod !is 8) error();
-    
+
     int windowSizeHint = (headerByte1 & 0xF0) >> 4;
     if (windowSizeHint > 7) error();
     int windowSize = (1 << (windowSizeHint + 8));
     lzBlockReader.setWindowSize(windowSize);
-    
+
     int dictionary = (headerByte2 & (1 << 5));
     if (dictionary !is 0) error();
-    
+
 //  int compressionLevel = (headerByte2 & 0xC0) >> 6;
 }
 
 void checkAdler() {
-    int storedAdler = ((getNextIdatByte() & 0xFF) << 24)
-        | ((getNextIdatByte() & 0xFF) << 16)
-        | ((getNextIdatByte() & 0xFF) << 8)
-        | (getNextIdatByte() & 0xFF);
+    int storedAdler = 0;
+    storedAdler |= ((getNextIdatByte() & 0xFF) << 24);
+    storedAdler |= ((getNextIdatByte() & 0xFF) << 16);
+    storedAdler |= ((getNextIdatByte() & 0xFF) << 8);
+    storedAdler |=  (getNextIdatByte() & 0xFF);
     if (storedAdler !is adlerValue) error();
 }
 
--- a/dwt/internal/image/PngDeflater.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngDeflater.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,44 +7,50 @@
  *
  * 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.PngDeflater;
 
-import java.io.ByteArrayOutputStream;
+import dwt.dwthelper.ByteArrayOutputStream;
 
 public class PngDeflater {
 
-    static final int BASE = 65521;
-    static final int WINDOW = 32768;
-    static final int MIN_LENGTH = 3;
-    static final int MAX_MATCHES = 32;
-    static final int HASH = 8209;
-    
-    byte[] in;
+    static const int BASE = 65521;
+    static const int WINDOW = 32768;
+    static const int MIN_LENGTH = 3;
+    static const int MAX_MATCHES = 32;
+    static const int HASH = 8209;
+
+    byte[] istr;
     int inLength;
-    
-    ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024);
-    
+
+    ByteArrayOutputStream bytes;
+
     int adler32 = 1;
-    
+
     int buffer, bitCount;
-    
-    Link[] hashtable = new Link[HASH];
-    Link[] window = new Link[WINDOW];
+
+    Link[HASH] hashtable;// = new Link[HASH];
+    Link[WINDOW] window;// = new Link[WINDOW];
     int nextWindow;
 
-static class Link {
+public this(){
+    bytes = new ByteArrayOutputStream(1024);
+}
+
+class Link {
 
     int hash, value;
     Link previous, next;
-    
+
     this() {
-    
+
         this.hash = 0;
         this.value = 0;
         this.previous = null;
         this.next = null;
-    
+
     }
 
 }
@@ -52,17 +58,17 @@
 static class Match {
 
     int length, distance;
-    
+
     this(int length, int distance) {
-    
+
         this.length = length;
         this.distance = distance;
-    
+
     }
 
 }
 
-static final short mirrorBytes[] = {
+static const short mirrorBytes[] = [ cast(short)
 
     0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
     0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
@@ -97,97 +103,96 @@
     0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
     0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
 
-};
+];
 
 static class Code {
 
     int code, extraBits, min, max;
-    
+
     this(int code, int extraBits, int min, int max) {
-    
+
         this.code = code;
         this.extraBits = extraBits;
         this.min = min;
         this.max = max;
-    
+
     }
 
 }
 
-static final Code lengthCodes[] = {
-
-    new Code(257, 0, 3, 3),
-    new Code(258, 0, 4, 4),
-    new Code(259, 0, 5, 5),
-    new Code(260, 0, 6, 6),
-    new Code(261, 0, 7, 7),
-    new Code(262, 0, 8, 8),
-    new Code(263, 0, 9, 9),
-    new Code(264, 0, 10, 10),
-    new Code(265, 1, 11, 12),
-    new Code(266, 1, 13, 14),
-    new Code(267, 1, 15, 16),
-    new Code(268, 1, 17, 18),
-    new Code(269, 2, 19, 22),
-    new Code(270, 2, 23, 26),
-    new Code(271, 2, 27, 30),
-    new Code(272, 2, 31, 34),
-    new Code(273, 3, 35, 42),
-    new Code(274, 3, 43, 50),
-    new Code(275, 3, 51, 58),
-    new Code(276, 3, 59, 66),
-    new Code(277, 4, 67, 82),
-    new Code(278, 4, 83, 98),
-    new Code(279, 4, 99, 114),
-    new Code(280, 4, 115, 130),
-    new Code(281, 5, 131, 162),
-    new Code(282, 5, 163, 194),
-    new Code(283, 5, 195, 226),
-    new Code(284, 5, 227, 257),
-    new Code(285, 0, 258, 258)
-
-};
+static const Code lengthCodes[];
+static const Code distanceCodes[];
 
-static final Code distanceCodes[] = {
+static this() {
+    lengthCodes = [
+        new Code(257, 0, 3, 3),
+        new Code(258, 0, 4, 4),
+        new Code(259, 0, 5, 5),
+        new Code(260, 0, 6, 6),
+        new Code(261, 0, 7, 7),
+        new Code(262, 0, 8, 8),
+        new Code(263, 0, 9, 9),
+        new Code(264, 0, 10, 10),
+        new Code(265, 1, 11, 12),
+        new Code(266, 1, 13, 14),
+        new Code(267, 1, 15, 16),
+        new Code(268, 1, 17, 18),
+        new Code(269, 2, 19, 22),
+        new Code(270, 2, 23, 26),
+        new Code(271, 2, 27, 30),
+        new Code(272, 2, 31, 34),
+        new Code(273, 3, 35, 42),
+        new Code(274, 3, 43, 50),
+        new Code(275, 3, 51, 58),
+        new Code(276, 3, 59, 66),
+        new Code(277, 4, 67, 82),
+        new Code(278, 4, 83, 98),
+        new Code(279, 4, 99, 114),
+        new Code(280, 4, 115, 130),
+        new Code(281, 5, 131, 162),
+        new Code(282, 5, 163, 194),
+        new Code(283, 5, 195, 226),
+        new Code(284, 5, 227, 257),
+        new Code(285, 0, 258, 258)];
 
-    new Code(0, 0, 1, 1),
-    new Code(1, 0, 2, 2),
-    new Code(2, 0, 3, 3),
-    new Code(3, 0, 4, 4),
-    new Code(4, 1, 5, 6),
-    new Code(5, 1, 7, 8),
-    new Code(6, 2, 9, 12),
-    new Code(7, 2, 13, 16),
-    new Code(8, 3, 17, 24),
-    new Code(9, 3, 25, 32),
-    new Code(10, 4, 33, 48),
-    new Code(11, 4, 49, 64),
-    new Code(12, 5, 65, 96),
-    new Code(13, 5, 97, 128),
-    new Code(14, 6, 129, 192),
-    new Code(15, 6, 193, 256),
-    new Code(16, 7, 257, 384),
-    new Code(17, 7, 385, 512),
-    new Code(18, 8, 513, 768),
-    new Code(19, 8, 769, 1024),
-    new Code(20, 9, 1025, 1536),
-    new Code(21, 9, 1537, 2048),
-    new Code(22, 10, 2049, 3072),
-    new Code(23, 10, 3073, 4096),
-    new Code(24, 11, 4097, 6144),
-    new Code(25, 11, 6145, 8192),
-    new Code(26, 12, 8193, 12288),
-    new Code(27, 12, 12289, 16384),
-    new Code(28, 13, 16385, 24576),
-    new Code(29, 13, 24577, 32768)
-
-};
+    distanceCodes = [
+        new Code(0, 0, 1, 1),
+        new Code(1, 0, 2, 2),
+        new Code(2, 0, 3, 3),
+        new Code(3, 0, 4, 4),
+        new Code(4, 1, 5, 6),
+        new Code(5, 1, 7, 8),
+        new Code(6, 2, 9, 12),
+        new Code(7, 2, 13, 16),
+        new Code(8, 3, 17, 24),
+        new Code(9, 3, 25, 32),
+        new Code(10, 4, 33, 48),
+        new Code(11, 4, 49, 64),
+        new Code(12, 5, 65, 96),
+        new Code(13, 5, 97, 128),
+        new Code(14, 6, 129, 192),
+        new Code(15, 6, 193, 256),
+        new Code(16, 7, 257, 384),
+        new Code(17, 7, 385, 512),
+        new Code(18, 8, 513, 768),
+        new Code(19, 8, 769, 1024),
+        new Code(20, 9, 1025, 1536),
+        new Code(21, 9, 1537, 2048),
+        new Code(22, 10, 2049, 3072),
+        new Code(23, 10, 3073, 4096),
+        new Code(24, 11, 4097, 6144),
+        new Code(25, 11, 6145, 8192),
+        new Code(26, 12, 8193, 12288),
+        new Code(27, 12, 12289, 16384),
+        new Code(28, 13, 16385, 24576),
+        new Code(29, 13, 24577, 32768)];
+}
 
 void writeShortLSB(ByteArrayOutputStream baos, int theShort) {
 
     byte byte1 = cast(byte) (theShort & 0xff);
     byte byte2 = cast(byte) ((theShort >> 8) & 0xff);
-    byte[] temp = {byte1, byte2};
+    byte[] temp = [byte1, byte2];
     baos.write(temp, 0, 2);
 
 }
@@ -198,7 +203,7 @@
     byte byte2 = cast(byte) ((theInt >> 16) & 0xff);
     byte byte3 = cast(byte) ((theInt >> 8) & 0xff);
     byte byte4 = cast(byte) (theInt & 0xff);
-    byte[] temp = {byte1, byte2, byte3, byte4};
+    byte[] temp = [byte1, byte2, byte3, byte4];
     baos.write(temp, 0, 4);
 
 }
@@ -251,7 +256,7 @@
 void outputLiteral(byte literal) {
 
     int i = literal & 0xff;
-    
+
     if (i <= 143) {
         // 0 through 143 are 8 bits long starting at 00110000
         writeBits(mirrorBytes[0x30 + i], 8);
@@ -266,7 +271,7 @@
 Code findCode(int value, Code[] codes) {
 
     int i, j, k;
-    
+
     i = -1;
     j = codes.length;
     while (true) {
@@ -288,13 +293,13 @@
 
     Code d, l;
     int thisLength;
-    
+
     while (length > 0) {
 
         // we can transmit matches of lengths 3 through 258 inclusive
         // so if length exceeds 258, we must transmit in several steps,
         // with 258 or less in each step
-        
+
         if (length > 260) {
             thisLength = 258;
         }
@@ -304,12 +309,12 @@
         else {
             thisLength = length - 3;
         }
-        
+
         length = length - thisLength;
-                
+
         // find length code
         l = findCode(thisLength, lengthCodes);
-        
+
         // transmit the length code
         // 256 through 279 are 7 bits long starting at 0000000
         // 280 through 287 are 8 bits long starting at 11000000
@@ -319,24 +324,24 @@
         else {
             writeBits(mirrorBytes[0xc0 - 280 + l.code], 8);
         }
-        
+
         // transmit the extra bits
         if (l.extraBits !is 0) {
             writeBits(thisLength - l.min, l.extraBits);
         }
-        
+
         // find distance code
         d = findCode(distance, distanceCodes);
-        
+
         // transmit the distance code
         // 5 bits long starting at 00000
         writeBits(mirrorBytes[d.code * 8], 5);
-        
+
         // transmit the extra bits
         if (d.extraBits !is 0) {
             writeBits(distance - d.min, d.extraBits);
         }
-    
+
     }
 
 }
@@ -346,92 +351,92 @@
     Link link = firstPosition;
     int numberOfMatches = 0;
     Match bestMatch = new Match(-1, -1);
-    
+
     while (true) {
-    
+
         int matchPosition = link.value;
-        
+
         if (position - matchPosition < WINDOW && matchPosition !is 0) {
 
             int i;
-            
+
             for (i = 1; position + i < inLength; i++) {
-                if (in[position + i] !is in[matchPosition + i]) {
+                if (istr[position + i] !is istr[matchPosition + i]) {
                     break;
                 }
             }
-            
+
             if (i >= MIN_LENGTH) {
-            
+
                 if (i > bestMatch.length) {
                     bestMatch.length = i;
                     bestMatch.distance = position - matchPosition;
                 }
-                
+
                 numberOfMatches = numberOfMatches + 1;
-                
+
                 if (numberOfMatches is MAX_MATCHES) {
                     break;
                 }
-            
+
             }
-                        
+
         }
-        
+
         link = link.next;
         if (link is null) {
             break;
         }
-    
+
     }
-    
+
     if (bestMatch.length < MIN_LENGTH || bestMatch.distance < 1 || bestMatch.distance > WINDOW) {
         return null;
     }
-    
-    return bestMatch;   
+
+    return bestMatch;
 
 }
 
 void updateHashtable(int to, int from) {
 
     byte[] data = new byte[3];
-    int hash;
+    int hashval;
     Link temp;
-    
+
     for (int i = to; i < from; i++) {
-        
+
         if (i + MIN_LENGTH > inLength) {
             break;
         }
-        
-        data[0] = in[i];
-        data[1] = in[i + 1];
-        data[2] = in[i + 2];
-        
-        hash = hash(data);
-        
+
+        data[0] = istr[i];
+        data[1] = istr[i + 1];
+        data[2] = istr[i + 2];
+
+        hashval = hash(data);
+
         if (window[nextWindow].previous !is null) {
             window[nextWindow].previous.next = null;
         }
         else if (window[nextWindow].hash !is 0) {
             hashtable[window[nextWindow].hash].next = null;
         }
-        
-        window[nextWindow].hash = hash;
+
+        window[nextWindow].hash = hashval;
         window[nextWindow].value = i;
         window[nextWindow].previous = null;
-        temp = window[nextWindow].next = hashtable[hash].next;
-        hashtable[hash].next = window[nextWindow];
+        temp = window[nextWindow].next = hashtable[hashval].next;
+        hashtable[hashval].next = window[nextWindow];
         if (temp !is null) {
             temp.previous = window[nextWindow];
         }
-        
+
         nextWindow = nextWindow + 1;
         if (nextWindow is WINDOW) {
             nextWindow = 0;
         }
-            
+
     }
 
 }
@@ -440,7 +445,7 @@
 
     int position, newPosition;
     byte[] data = new byte[3];
-    int hash;
+    int hashval;
     for (int i = 0; i < HASH; i++) {
         hashtable[i] = new Link();
     }
@@ -452,39 +457,39 @@
     Match match;
     int deferredPosition = -1;
     Match deferredMatch = null;
-    
+
     writeBits(0x01, 1); // BFINAL = 0x01 (final block)
     writeBits(0x01, 2); // BTYPE = 0x01 (compression with fixed Huffman codes)
-    
+
     // just output first byte so we never match at zero
-    outputLiteral(in[0]);
+    outputLiteral(istr[0]);
     position = 1;
-    
+
     while (position < inLength) {
-    
+
         if (inLength - position < MIN_LENGTH) {
-            outputLiteral(in[position]);
+            outputLiteral(istr[position]);
             position = position + 1;
             continue;
         }
-        
-        data[0] = in[position];
-        data[1] = in[position + 1];
-        data[2] = in[position + 2];
-        
-        hash = hash(data);
-        firstPosition = hashtable[hash];
-        
+
+        data[0] = istr[position];
+        data[1] = istr[position + 1];
+        data[2] = istr[position + 2];
+
+        hashval = hash(data);
+        firstPosition = hashtable[hashval];
+
         match = findLongestMatch(position, firstPosition);
-        
+
         updateHashtable(position, position + 1);
-        
+
         if (match !is null) {
-        
+
             if (deferredMatch !is null) {
                 if (match.length > deferredMatch.length + 1) {
                     // output literal at deferredPosition
-                    outputLiteral(in[deferredPosition]);
+                    outputLiteral(istr[deferredPosition]);
                     // defer this match
                     deferredPosition = position;
                     deferredMatch = match;
@@ -506,11 +511,11 @@
                 deferredMatch = match;
                 position = position + 1;
             }
-        
+
         }
-        
+
         else {
-        
+
             // no match found
             if (deferredMatch !is null) {
                 outputMatch(deferredMatch.length, deferredMatch.distance);
@@ -521,14 +526,14 @@
                 position = newPosition;
             }
             else {
-                outputLiteral(in[position]);
+                outputLiteral(istr[position]);
                 position = position + 1;
             }
-        
+
         }
-    
+
     }
-    
+
     writeBits(0, 7); // end of block code
     alignToByte();
 
@@ -537,17 +542,17 @@
 void compressHuffmanOnly() {
 
     int position;
-    
+
     writeBits(0x01, 1); // BFINAL = 0x01 (final block)
     writeBits(0x01, 2); // BTYPE = 0x01 (compression with fixed Huffman codes)
-    
+
     for (position = 0; position < inLength;) {
-    
-        outputLiteral(in[position]);
+
+        outputLiteral(istr[position]);
         position = position + 1;
-    
+
     }
-    
+
     writeBits(0, 7); // end of block code
     alignToByte();
 
@@ -556,14 +561,14 @@
 void store() {
 
     // stored blocks are limited to 0xffff bytes
-    
+
     int start = 0;
     int length = inLength;
     int blockLength;
     int BFINAL = 0x00; // BFINAL = 0x00 or 0x01 (if final block), BTYPE = 0x00 (no compression)
-    
+
     while (length > 0) {
-    
+
         if (length < 65535) {
             blockLength = length;
             BFINAL = 0x01;
@@ -572,45 +577,45 @@
             blockLength = 65535;
             BFINAL = 0x00;
         }
-        
+
         // write data header
         bytes.write(cast(byte) BFINAL);
         writeShortLSB(bytes, blockLength); // LEN
         writeShortLSB(bytes, blockLength ^ 0xffff); // NLEN (one's complement of LEN)
-    
+
         // write actual data
-        bytes.write(in, start, blockLength);
-        
+        bytes.write(istr, start, blockLength);
+
         length = length - blockLength;
         start = start + blockLength;
-    
+
     }
 
 }
 
 public byte[] deflate(byte[] input) {
 
-    in = input;
+    istr = input;
     inLength = input.length;
-    
+
     // write zlib header
     bytes.write(cast(byte) 0x78); // window size = 0x70 (32768), compression method = 0x08
     bytes.write(cast(byte) 0x9C); // compression level = 0x80 (default), check bits = 0x1C
-    
+
     // compute checksum
     for (int i = 0; i < inLength; i++) {
-        updateAdler(in[i]);
+        updateAdler(istr[i]);
     }
-    
+
     //store();
-    
+
     //compressHuffmanOnly();
-    
+
     compress();
-    
+
     // write checksum
     writeInt(bytes, adler32);
-    
+
     return bytes.toByteArray();
 
 }
--- a/dwt/internal/image/PngEncoder.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngEncoder.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,54 +7,59 @@
  *
  * 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.PngEncoder;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
+import dwt.internal.image.LEDataOutputStream;
+import dwt.internal.image.PngDeflater;
+import dwt.dwthelper.ByteArrayOutputStream;
+import dwt.dwthelper.OutputStream;
 import dwt.DWT;
 import dwt.graphics.ImageData;
 import dwt.graphics.ImageLoader;
 import dwt.graphics.RGB;
 import dwt.internal.Compatibility;
+import dwt.internal.image.PngChunk;
 
-final class PngEncoder : Object {
+import tango.core.Exception;
+
+final class PngEncoder {
 
-    static final byte SIGNATURE[] = {cast(byte) '\211', cast(byte) 'P', cast(byte) 'N', cast(byte) 'G', cast(byte) '\r', cast(byte) '\n', cast(byte) '\032', cast(byte) '\n'};
-    static final byte TAG_IHDR[] = {cast(byte) 'I', cast(byte) 'H', cast(byte) 'D', cast(byte) 'R'};
-    static final byte TAG_PLTE[] = {cast(byte) 'P', cast(byte) 'L', cast(byte) 'T', cast(byte) 'E'};
-    static final byte TAG_TRNS[] = {cast(byte) 't', cast(byte) 'R', cast(byte) 'N', cast(byte) 'S'};
-    static final byte TAG_IDAT[] = {cast(byte) 'I', cast(byte) 'D', cast(byte) 'A', cast(byte) 'T'};
-    static final byte TAG_IEND[] = {cast(byte) 'I', cast(byte) 'E', cast(byte) 'N', cast(byte) 'D'};
-    
-    ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024);
+    static const byte SIGNATURE[] = [cast(byte) '\211', cast(byte) 'P', cast(byte) 'N', cast(byte) 'G', cast(byte) '\r', cast(byte) '\n', cast(byte) '\032', cast(byte) '\n'];
+    static const byte TAG_IHDR[] = [cast(byte) 'I', cast(byte) 'H', cast(byte) 'D', cast(byte) 'R'];
+    static const byte TAG_PLTE[] = [cast(byte) 'P', cast(byte) 'L', cast(byte) 'T', cast(byte) 'E'];
+    static const byte TAG_TRNS[] = [cast(byte) 't', cast(byte) 'R', cast(byte) 'N', cast(byte) 'S'];
+    static const byte TAG_IDAT[] = [cast(byte) 'I', cast(byte) 'D', cast(byte) 'A', cast(byte) 'T'];
+    static const byte TAG_IEND[] = [cast(byte) 'I', cast(byte) 'E', cast(byte) 'N', cast(byte) 'D'];
+
+    ByteArrayOutputStream bytes;
     PngChunk chunk;
-    
+
     ImageLoader loader;
     ImageData data;
     int transparencyType;
-    
+
     int width, height, bitDepth, colorType;
-    
+
     int compressionMethod = 0;
     int filterMethod = 0;
     int interlaceMethod = 0;
-    
+
 public this(ImageLoader loader) {
-
+    this.bytes = new ByteArrayOutputStream(1024);
     this.loader = loader;
     this.data = loader.data[0];
     this.transparencyType = data.getTransparencyType();
-    
+
     this.width = data.width;
     this.height = data.height;
-    
+
     this.bitDepth = 8;
-    
+
     this.colorType = 2;
-    
+
     if (data.palette.isDirect) {
         if (transparencyType is DWT.TRANSPARENCY_ALPHA) {
             this.colorType = 6;
@@ -63,7 +68,7 @@
     else {
         this.colorType = 3;
     }
-    
+
     if (!(colorType is 2 || colorType is 3 || colorType is 6)) DWT.error(DWT.ERROR_INVALID_IMAGE);
 
 }
@@ -72,7 +77,7 @@
 
     byte byte1 = cast(byte) ((theShort >> 8) & 0xff);
     byte byte2 = cast(byte) (theShort & 0xff);
-    byte[] temp = {byte1, byte2};
+    byte[] temp = [byte1, byte2];
     baos.write(temp, 0, 2);
 
 }
@@ -83,7 +88,7 @@
     byte byte2 = cast(byte) ((theInt >> 16) & 0xff);
     byte byte3 = cast(byte) ((theInt >> 8) & 0xff);
     byte byte4 = cast(byte) (theInt & 0xff);
-    byte[] temp = {byte1, byte2, byte3, byte4};
+    byte[] temp = [byte1, byte2, byte3, byte4];
     baos.write(temp, 0, 4);
 
 }
@@ -91,9 +96,9 @@
 void writeChunk(byte[] tag, byte[] buffer) {
 
     int bufferLength = (buffer !is null) ? buffer.length : 0;
-    
+
     chunk = new PngChunk(bufferLength);
-    
+
     writeInt(bytes, bufferLength);
     bytes.write(tag, 0, 4);
     chunk.setType(tag);
@@ -117,7 +122,7 @@
 void writeHeader() {
 
     ByteArrayOutputStream baos = new ByteArrayOutputStream(13);
-    
+
     writeInt(baos, width);
     writeInt(baos, height);
     baos.write(bitDepth);
@@ -125,7 +130,7 @@
     baos.write(compressionMethod);
     baos.write(filterMethod);
     baos.write(interlaceMethod);
-    
+
     writeChunk(TAG_IHDR, baos.toByteArray());
 
 }
@@ -133,19 +138,19 @@
 void writePalette() {
 
     RGB[] RGBs = data.palette.getRGBs();
-    
+
     if (RGBs.length > 256) DWT.error(DWT.ERROR_INVALID_IMAGE);
-    
+
     ByteArrayOutputStream baos = new ByteArrayOutputStream(RGBs.length);
-    
+
     for (int i = 0; i < RGBs.length; i++) {
-    
+
         baos.write(cast(byte) RGBs[i].red);
         baos.write(cast(byte) RGBs[i].green);
         baos.write(cast(byte) RGBs[i].blue);
-    
+
     }
-    
+
     writeChunk(TAG_PLTE, baos.toByteArray());
 
 }
@@ -153,78 +158,79 @@
 void writeTransparency() {
 
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
-    
+
     switch (transparencyType) {
-    
+
         case DWT.TRANSPARENCY_ALPHA:
-            
+
             int pixelValue, alphaValue;
-            
+
             byte[] alphas = new byte[data.palette.getRGBs().length];
-            
+
             for (int y = 0; y < height; y++) {
-            
+
                 for (int x = 0; x < width; x++) {
-                
+
                     pixelValue = data.getPixel(x, y);
                     alphaValue = data.getAlpha(x, y);
-                    
+
                     alphas[pixelValue] = cast(byte) alphaValue;
-                
+
                 }
-            
+
             }
-            
+
             baos.write(alphas, 0, alphas.length);
-            
+
             break;
-        
+
         case DWT.TRANSPARENCY_PIXEL:
-            
+
             int pixel = data.transparentPixel;
-            
+
             if (colorType is 2) {
-            
+
                 int redMask = data.palette.redMask;
                 int redShift = data.palette.redShift;
                 int greenMask = data.palette.greenMask;
                 int greenShift = data.palette.greenShift;
                 int blueShift = data.palette.blueShift;
                 int blueMask = data.palette.blueMask;
-                
+
                 int r = pixel & redMask;
                 r = (redShift < 0) ? r >>> -redShift : r << redShift;
                 int g = pixel & greenMask;
                 g = (greenShift < 0) ? g >>> -greenShift : g << greenShift;
                 int b = pixel & blueMask;
                 b = (blueShift < 0) ? b >>> -blueShift : b << blueShift;
-                
+
                 writeShort(baos, r);
                 writeShort(baos, g);
                 writeShort(baos, b);
-            
+
             }
-            
+
             if (colorType is 3) {
-            
+
                 byte[] padding = new byte[pixel + 1];
-                
+
                 for (int i = 0; i < pixel; i++) {
-                
+
                     padding[i] = cast(byte) 255;
-                
+
                 }
-                
+
                 padding[pixel] = cast(byte) 0;
-                
+
                 baos.write(padding, 0, padding.length);
-            
+
             }
-            
+
             break;
-    
+        default:
+
     }
-    
+
     writeChunk(TAG_TRNS, baos.toByteArray());
 
 }
@@ -234,88 +240,88 @@
     ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
     OutputStream os = Compatibility.newDeflaterOutputStream(baos);
     if (os is null) os = baos;
-    
+
     if (colorType is 3) {
-    
+
         byte[] lineData = new byte[width];
-        
+
         for (int y = 0; y < height; y++) {
-            
+
             int filter = 0;
             os.write(filter);
-            
+
             data.getPixels(0, y, width, lineData, 0);
-            
+
             for (int x = 0; x < lineData.length; x++) {
-            
+
                 os.write(lineData[x]);
-            
+
             }
-        
+
         }
-    
+
     }
-    
+
     else {
-    
+
         int[] lineData = new int[width];
         byte[] alphaData = null;
         if (colorType is 6) {
             alphaData = new byte[width];
         }
-        
+
         int redMask = data.palette.redMask;
         int redShift = data.palette.redShift;
         int greenMask = data.palette.greenMask;
         int greenShift = data.palette.greenShift;
         int blueShift = data.palette.blueShift;
         int blueMask = data.palette.blueMask;
-        
+
         for (int y = 0; y < height; y++) {
-        
+
             int filter = 0;
             os.write(filter);
-            
+
             data.getPixels(0, y, width, lineData, 0);
-            
+
             if (colorType is 6) {
                 data.getAlphas(0, y, width, alphaData, 0);
             }
-            
+
             for (int x = 0; x < lineData.length; x++) {
-            
+
                 int pixel = lineData[x];
-                
+
                 int r = pixel & redMask;
                 r = (redShift < 0) ? r >>> -redShift : r << redShift;
                 int g = pixel & greenMask;
                 g = (greenShift < 0) ? g >>> -greenShift : g << greenShift;
                 int b = pixel & blueMask;
                 b = (blueShift < 0) ? b >>> -blueShift : b << blueShift;
-                
+
                 os.write(r);
                 os.write(g);
                 os.write(b);
-                
+
                 if (colorType is 6) {
                     os.write(alphaData[x]);
                 }
-            
+
             }
-        
+
         }
-    
+
     }
-    
+
     os.flush();
     os.close();
-    
+
     byte[] compressed = baos.toByteArray();
     if (os is baos) {
         PngDeflater deflater = new PngDeflater();
         compressed = deflater.deflate(compressed);
     }
-    
+
     writeChunk(TAG_IDAT, compressed);
 
 }
@@ -329,34 +335,34 @@
 public void encode(LEDataOutputStream outputStream) {
 
     try {
-    
+
         writeSignature();
         writeHeader();
-        
+
         if (colorType is 3) {
             writePalette();
         }
-        
+
         bool transparencyAlpha = (transparencyType is DWT.TRANSPARENCY_ALPHA);
         bool transparencyPixel = (transparencyType is DWT.TRANSPARENCY_PIXEL);
         bool type2Transparency = (colorType is 2 && transparencyPixel);
         bool type3Transparency = (colorType is 3 && (transparencyAlpha || transparencyPixel));
-        
+
         if (type2Transparency || type3Transparency) {
             writeTransparency();
         }
-        
+
         writeImageData();
         writeEnd();
-        
+
         outputStream.write(bytes.toByteArray());
-    
+
     }
-    
+
     catch (IOException e) {
-    
+
         DWT.error(DWT.ERROR_IO, e);
-    
+
     }
 
 }
--- a/dwt/internal/image/PngFileReadState.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngFileReadState.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2004 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,19 +7,21 @@
  *
  * 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.PngFileReadState;
 
 
-class PngFileReadState : Object {
+class PngFileReadState {
     bool readIHDR;
     bool readPLTE;
     bool readIDAT;
     bool readIEND;
-    
+
     // Non - critical chunks
     bool readTRNS;
-    
+
     // Set to true after IDATs have been read.
     bool readPixelData;
 }
--- a/dwt/internal/image/PngHuffmanTable.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngHuffmanTable.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,21 +7,22 @@
  *
  * 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.PngHuffmanTable;
 
-import java.io.IOException;
+import dwt.internal.image.PngDecodingDataStream;
 
 public class PngHuffmanTable {
     CodeLengthInfo[] codeLengthInfo;
     int[] codeValues;
-    
-    static final int MAX_CODE_LENGTH = 15;
-    static final int BAD_CODE = 0xFFFFFFF;
-    static final int incs[] = {1391376, 463792, 198768, 86961, 33936, 13776, 4592, 1968, 861, 336, 112, 48, 21, 7, 3, 1};
+
+    static const int MAX_CODE_LENGTH = 15;
+    static const int BAD_CODE = 0xFFFFFFF;
+    static const int incs[] = [1391376, 463792, 198768, 86961, 33936, 13776, 4592, 1968, 861, 336, 112, 48, 21, 7, 3, 1];
 
 this (int[] lengths) {
-    super();
     initialize(lengths);
     generateTable(lengths);
 }
@@ -31,7 +32,7 @@
     for (int i = 0; i < codeValues.length; i++) {
         codeValues[i] = i;
     }
-    
+
     // minCodesByLength[n] : The smallest Huffman code of length n + 1.
     // maxCodesByLength[n] : The largest Huffman code of length n + 1.
     // indexesByLength[n] : Index into the values array. First value with a code of length n + 1.
@@ -44,7 +45,7 @@
         codeLengthInfo[i].max = -1;
     }
 }
-    
+
 private void generateTable(int[] lengths) {
     // Sort the values using shellsort. Primary key is code size. Secondary key is value.
     int codeValuesTemp;
@@ -79,7 +80,7 @@
             code++;
         }
     }
-    
+
     int last = 0;
     for (int i = 0; i < lengths.length; i++) {
         if (last !is lengths[i]) {
@@ -113,8 +114,8 @@
     // so now we can look up the value for the Huffman code in the table.
     int index = codeLengthInfo[codelength].baseIndex + offset;
     return codeValues[index];
-}   
-    
+}
+
 static class CodeLengthInfo {
     int length;
     int max;
--- a/dwt/internal/image/PngHuffmanTables.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngHuffmanTables.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2006 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,20 +7,24 @@
  *
  * 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.PngHuffmanTables;
 
-import java.io.IOException;
+import dwt.internal.image.PngHuffmanTable;
+import dwt.internal.image.PngDecodingDataStream;
+import dwt.internal.image.PngLzBlockReader;
 
 public class PngHuffmanTables {
     PngHuffmanTable literalTable;
     PngHuffmanTable distanceTable;
-    
+
     static PngHuffmanTable FixedLiteralTable;
     static PngHuffmanTable FixedDistanceTable;
-    
+
     static final int LiteralTableSize = 288;
-    static final int[] FixedLiteralLengths = {
+    static final int[] FixedLiteralLengths = [
         8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
         8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
         8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
@@ -33,21 +37,21 @@
         9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
         9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 7, 7, 7,
         7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8,
-    };
+    ];
 
     static final int DistanceTableSize = 32;
-    static final int[] FixedDistanceLengths = {
+    static final int[] FixedDistanceLengths = [
         5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
         5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-    };
-    
+    ];
+
     static final int LengthCodeTableSize = 19;
-    static final int[] LengthCodeOrder = {
+    static final int[] LengthCodeOrder = [
         16, 17, 18, 0, 8, 7, 9, 6, 10, 5,
         11, 4, 12, 3, 13, 2, 14, 1, 15
-    };
-    
-static PngHuffmanTables getDynamicTables(PngDecodingDataStream stream) {
+    ];
+
+static PngHuffmanTables getDynamicTables(PngDecodingDataStream stream)  {
     return new PngHuffmanTables(stream);
 }
 static PngHuffmanTables getFixedTables() {
@@ -73,48 +77,48 @@
     distanceTable = getFixedDistanceTable();
 }
 
-private this (PngDecodingDataStream stream) {
-    int literals = PngLzBlockReader.FIRST_LENGTH_CODE 
+private this (PngDecodingDataStream stream)  {
+    int literals = PngLzBlockReader.FIRST_LENGTH_CODE
         + stream.getNextIdatBits(5);
-    int distances = PngLzBlockReader.FIRST_DISTANCE_CODE 
+    int distances = PngLzBlockReader.FIRST_DISTANCE_CODE
         + stream.getNextIdatBits(5);
-    int codeLengthCodes = PngLzBlockReader.FIRST_CODE_LENGTH_CODE 
+    int codeLengthCodes = PngLzBlockReader.FIRST_CODE_LENGTH_CODE
         + stream.getNextIdatBits(4);
 
     if (codeLengthCodes > PngLzBlockReader.LAST_CODE_LENGTH_CODE) {
         stream.error();
     }
-    
+
     /* Tricky, tricky, tricky. The length codes are stored in
      * a very odd order. (For the order, see the definition of
-     * the static field lengthCodeOrder.) Also, the data may 
-     * not contain values for all the codes. It may just contain 
+     * the static field lengthCodeOrder.) Also, the data may
+     * not contain values for all the codes. It may just contain
      * values for the first X number of codes. The table should
      * be of size <LengthCodeTableSize> regardless of the number
      * of values actually given in the table.
-     */ 
+     */
     int[] lengthCodes = new int[LengthCodeTableSize];
     for (int i = 0; i < codeLengthCodes; i++) {
         lengthCodes[LengthCodeOrder[i]] = stream.getNextIdatBits(3);
     }
     PngHuffmanTable codeLengthsTable = new PngHuffmanTable(lengthCodes);
-    
+
     int[] literalLengths = readLengths(
         stream, literals, codeLengthsTable, LiteralTableSize);
     int[] distanceLengths = readLengths(
         stream, distances, codeLengthsTable, DistanceTableSize);
-    
+
     literalTable = new PngHuffmanTable(literalLengths);
     distanceTable = new PngHuffmanTable(distanceLengths);
 }
 
-private int [] readLengths (PngDecodingDataStream stream, 
-    int numLengths, 
+private int [] readLengths (PngDecodingDataStream stream,
+    int numLengths,
     PngHuffmanTable lengthsTable,
     int tableSize)
 {
     int[] lengths = new int[tableSize];
-    
+
     for (int index = 0; index < numLengths;) {
         int value = lengthsTable.getNextValue(stream);
         if (value < 16) {
@@ -149,11 +153,11 @@
     return lengths;
 }
 
-int getNextLiteralValue(PngDecodingDataStream stream) {
+int getNextLiteralValue(PngDecodingDataStream stream)  {
     return literalTable.getNextValue(stream);
 }
 
-int getNextDistanceValue(PngDecodingDataStream stream) {
+int getNextDistanceValue(PngDecodingDataStream stream)  {
     return distanceTable.getNextValue(stream);
 }
 
--- a/dwt/internal/image/PngIdatChunk.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngIdatChunk.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,25 @@
  *
  * 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.PngIdatChunk;
 
 
 import dwt.DWT;
+import dwt.internal.image.PngFileReadState;
+import dwt.internal.image.PngIhdrChunk;
+import dwt.internal.image.PngChunk;
+import dwt.dwthelper.utils;
 
 class PngIdatChunk : PngChunk {
 
-    static final int HEADER_BYTES_LENGTH = 2;
-    static final int ADLER_FIELD_LENGTH = 4;
-    static final int HEADER_BYTE1_DATA_OFFSET = DATA_OFFSET + 0;
-    static final int HEADER_BYTE2_DATA_OFFSET = DATA_OFFSET + 1;
-    static final int ADLER_DATA_OFFSET = DATA_OFFSET + 2; // plus variable compressed data length
+    static const int HEADER_BYTES_LENGTH = 2;
+    static const int ADLER_FIELD_LENGTH = 4;
+    static const int HEADER_BYTE1_DATA_OFFSET = DATA_OFFSET + 0;
+    static const int HEADER_BYTE2_DATA_OFFSET = DATA_OFFSET + 1;
+    static const int ADLER_DATA_OFFSET = DATA_OFFSET + 2; // plus variable compressed data length
 
 this(byte headerByte1, byte headerByte2, byte[] data, int adler) {
     super(data.length + HEADER_BYTES_LENGTH + ADLER_FIELD_LENGTH);
@@ -30,28 +36,28 @@
     setInt32(ADLER_DATA_OFFSET, adler);
     setCRC(computeCRC());
 }
-        
+
 this(byte[] reference) {
     super(reference);
 }
 
-int getChunkType() {
+override int getChunkType() {
     return CHUNK_IDAT;
 }
 
 /**
  * Answer whether the chunk is a valid IDAT chunk.
  */
-void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
+override void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
     if (!readState.readIHDR
         || (headerChunk.getMustHavePalette() && !readState.readPLTE)
-        || readState.readIEND) 
+        || readState.readIEND)
     {
         DWT.error(DWT.ERROR_INVALID_IMAGE);
     } else {
         readState.readIDAT = true;
     }
-    
+
     super.validate(readState, headerChunk);
 }
 
--- a/dwt/internal/image/PngIendChunk.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngIendChunk.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,11 +7,16 @@
  *
  * 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.PngIendChunk;
 
 
 import dwt.DWT;
+import dwt.internal.image.PngFileReadState;
+import dwt.internal.image.PngIhdrChunk;
+import dwt.internal.image.PngChunk;
 
 class PngIendChunk : PngChunk {
 
@@ -25,29 +30,29 @@
     super(reference);
 }
 
-int getChunkType() {
+override int getChunkType() {
     return CHUNK_IEND;
 }
 
 /**
  * Answer whether the chunk is a valid IEND chunk.
  */
-void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
+override void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
     // An IEND chunk is invalid if no IHDR has been read.
     // Or if a palette is required and has not been read.
     // Or if no IDAT chunk has been read.
     if (!readState.readIHDR
         || (headerChunk.getMustHavePalette() && !readState.readPLTE)
         || !readState.readIDAT
-        || readState.readIEND) 
+        || readState.readIEND)
     {
         DWT.error(DWT.ERROR_INVALID_IMAGE);
     } else {
         readState.readIEND = true;
     }
-    
+
     super.validate(readState, headerChunk);
-    
+
     // IEND chunks are not allowed to have any data.
     if (getLength() > 0) DWT.error(DWT.ERROR_INVALID_IMAGE);
 }
--- a/dwt/internal/image/PngIhdrChunk.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngIhdrChunk.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,46 +7,54 @@
  *
  * 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.PngIhdrChunk;
+
+import dwt.dwthelper.utils;
 
 
 import dwt.DWT;
 import dwt.graphics.PaletteData;
 import dwt.graphics.RGB;
+import dwt.internal.image.PngFileReadState;
+import dwt.internal.image.PngIhdrChunk;
+import dwt.internal.image.PngChunk;
+import tango.text.convert.Format;
 
 class PngIhdrChunk : PngChunk {
-    static final int IHDR_DATA_LENGTH = 13;
-    
-    static final int WIDTH_DATA_OFFSET = DATA_OFFSET + 0;
-    static final int HEIGHT_DATA_OFFSET = DATA_OFFSET + 4;
-    static final int BIT_DEPTH_OFFSET = DATA_OFFSET + 8;
-    static final int COLOR_TYPE_OFFSET = DATA_OFFSET + 9;
-    static final int COMPRESSION_METHOD_OFFSET = DATA_OFFSET + 10;
-    static final int FILTER_METHOD_OFFSET = DATA_OFFSET + 11;
-    static final int INTERLACE_METHOD_OFFSET = DATA_OFFSET + 12;
-    
-    static final byte COLOR_TYPE_GRAYSCALE = 0;
-    static final byte COLOR_TYPE_RGB = 2;
-    static final byte COLOR_TYPE_PALETTE = 3;
-    static final byte COLOR_TYPE_GRAYSCALE_WITH_ALPHA = 4;
-    static final byte COLOR_TYPE_RGB_WITH_ALPHA = 6;
-    
-    static final int INTERLACE_METHOD_NONE = 0;
-    static final int INTERLACE_METHOD_ADAM7 = 1;
-    
-    static final int FILTER_NONE = 0;
-    static final int FILTER_SUB = 1;
-    static final int FILTER_UP = 2;
-    static final int FILTER_AVERAGE = 3;
-    static final int FILTER_PAETH = 4;
-    
-    static final byte[] ValidBitDepths = {1, 2, 4, 8, 16};
-    static final byte[] ValidColorTypes = {0, 2, 3, 4, 6};
-    
+    static const int IHDR_DATA_LENGTH = 13;
+
+    static const int WIDTH_DATA_OFFSET = DATA_OFFSET + 0;
+    static const int HEIGHT_DATA_OFFSET = DATA_OFFSET + 4;
+    static const int BIT_DEPTH_OFFSET = DATA_OFFSET + 8;
+    static const int COLOR_TYPE_OFFSET = DATA_OFFSET + 9;
+    static const int COMPRESSION_METHOD_OFFSET = DATA_OFFSET + 10;
+    static const int FILTER_METHOD_OFFSET = DATA_OFFSET + 11;
+    static const int INTERLACE_METHOD_OFFSET = DATA_OFFSET + 12;
+
+    static const byte COLOR_TYPE_GRAYSCALE = 0;
+    static const byte COLOR_TYPE_RGB = 2;
+    static const byte COLOR_TYPE_PALETTE = 3;
+    static const byte COLOR_TYPE_GRAYSCALE_WITH_ALPHA = 4;
+    static const byte COLOR_TYPE_RGB_WITH_ALPHA = 6;
+
+    static const int INTERLACE_METHOD_NONE = 0;
+    static const int INTERLACE_METHOD_ADAM7 = 1;
+
+    static const int FILTER_NONE = 0;
+    static const int FILTER_SUB = 1;
+    static const int FILTER_UP = 2;
+    static const int FILTER_AVERAGE = 3;
+    static const int FILTER_PAETH = 4;
+
+    static const byte[] ValidBitDepths = [ cast(byte)1, 2, 4, 8, 16];
+    static const byte[] ValidColorTypes = [ cast(byte)0, 2, 3, 4, 6];
+
     int width, height;
     byte bitDepth, colorType, compressionMethod, filterMethod, interlaceMethod;
-    
+
 this(int width, int height, byte bitDepth, byte colorType, byte compressionMethod, byte filterMethod, byte interlaceMethod) {
     super(IHDR_DATA_LENGTH);
     setType(TYPE_IHDR);
@@ -63,7 +71,7 @@
 /**
  * Construct a PNGChunk using the reference bytes
  * given.
- */ 
+ */
 this(byte[] reference) {
     super(reference);
     if (reference.length <= IHDR_DATA_LENGTH) DWT.error(DWT.ERROR_INVALID_IMAGE);
@@ -76,7 +84,7 @@
     interlaceMethod = reference[INTERLACE_METHOD_OFFSET];
 }
 
-int getChunkType() {
+override int getChunkType() {
     return CHUNK_IHDR;
 }
 
@@ -212,28 +220,28 @@
 /**
  * Answer whether the chunk is a valid IHDR chunk.
  */
-void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
+override void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
     // An IHDR chunk is invalid if any other chunk has
     // been read.
-    if (readState.readIHDR 
+    if (readState.readIHDR
         || readState.readPLTE
         || readState.readIDAT
-        || readState.readIEND) 
+        || readState.readIEND)
     {
         DWT.error(DWT.ERROR_INVALID_IMAGE);
     } else {
         readState.readIHDR = true;
     }
-    
+
     super.validate(readState, headerChunk);
-    
+
     if (length !is IHDR_DATA_LENGTH) DWT.error(DWT.ERROR_INVALID_IMAGE);
     if (compressionMethod !is 0) DWT.error(DWT.ERROR_INVALID_IMAGE);
     if (interlaceMethod !is INTERLACE_METHOD_NONE &&
         interlaceMethod !is INTERLACE_METHOD_ADAM7) {
             DWT.error(DWT.ERROR_INVALID_IMAGE);
     }
-    
+
     bool colorTypeIsValid = false;
     for (int i = 0; i < ValidColorTypes.length; i++) {
         if (ValidColorTypes[i] is colorType) {
@@ -251,15 +259,15 @@
         }
     }
     if (!bitDepthIsValid) DWT.error(DWT.ERROR_INVALID_IMAGE);
-    
-    if ((colorType is COLOR_TYPE_RGB 
+
+    if ((colorType is COLOR_TYPE_RGB
         || colorType is COLOR_TYPE_RGB_WITH_ALPHA
         || colorType is COLOR_TYPE_GRAYSCALE_WITH_ALPHA)
-        && bitDepth < 8) 
+        && bitDepth < 8)
     {
             DWT.error(DWT.ERROR_INVALID_IMAGE);
     }
-    
+
     if (colorType is COLOR_TYPE_PALETTE && bitDepth > 8) {
         DWT.error(DWT.ERROR_INVALID_IMAGE);
     }
@@ -268,11 +276,11 @@
 String getColorTypeString() {
     switch (colorType) {
         case COLOR_TYPE_GRAYSCALE:              return "Grayscale";
-        case COLOR_TYPE_RGB:                    return "RGB";       
+        case COLOR_TYPE_RGB:                    return "RGB";
         case COLOR_TYPE_PALETTE:                return "Palette";
         case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:   return "Grayscale with Alpha";
         case COLOR_TYPE_RGB_WITH_ALPHA:         return "RGB with Alpha";
-        default:                                return "Unknown - " + colorType;
+        default:                                return "Unknown - " ~ cast(char)colorType;
     }
 }
 
@@ -295,21 +303,9 @@
     }
 }
 
-void contributeToString(StringBuffer buffer) {
-    buffer.append("\n\tWidth: ");
-    buffer.append(width);
-    buffer.append("\n\tHeight: ");
-    buffer.append(height);
-    buffer.append("\n\tBit Depth: ");
-    buffer.append(bitDepth);
-    buffer.append("\n\tColor Type: ");
-    buffer.append(getColorTypeString());
-    buffer.append("\n\tCompression Method: ");
-    buffer.append(compressionMethod);
-    buffer.append("\n\tFilter Method: ");
-    buffer.append(getFilterMethodString());
-    buffer.append("\n\tInterlace Method: ");
-    buffer.append(getInterlaceMethodString());
+override String contributeToString() {
+    return Format( "\n\tWidth: {}\n\tHeight: {}\n\tBit Depth: {}\n\tColor Type: {}\n\tCompression Method: {}\n\tFilter Method: {}\n\tInterlace Method: {}",
+        width, height, bitDepth, getColorTypeString(), compressionMethod, getFilterMethodString(), getInterlaceMethodString() );
 }
 
 bool getMustHavePalette() {
@@ -317,7 +313,7 @@
 }
 
 bool getCanHavePalette() {
-    return colorType !is COLOR_TYPE_GRAYSCALE && 
+    return colorType !is COLOR_TYPE_GRAYSCALE &&
         colorType !is COLOR_TYPE_GRAYSCALE_WITH_ALPHA;
 }
 
@@ -383,7 +379,7 @@
     int max = (1 << depth) - 1;
     int delta = 255 / max;
     int gray = 0;
-    RGB[] rgbs = new RGB[max + 1]; 
+    RGB[] rgbs = new RGB[max + 1];
     for (int i = 0; i <= max; i++) {
         rgbs[i] = new RGB(gray, gray, gray);
         gray += delta;
@@ -401,7 +397,7 @@
             return new PaletteData(0xFF0000, 0xFF00, 0xFF);
         default:
             return null;
-    }   
+    }
 }
 
 
--- a/dwt/internal/image/PngInputStream.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngInputStream.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,30 @@
  *
  * 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.PngInputStream;
 
-import java.io.IOException;
-import java.io.InputStream;
+import dwt.dwthelper.InputStream;
+import dwt.dwthelper.System;
+import dwt.internal.image.PngIdatChunk;
+import dwt.internal.image.PngChunkReader;
+import dwt.internal.image.PngChunk;
+
+import tango.core.Exception;
+import Math = tango.math.Math;
 
 public class PngInputStream : InputStream {
+
+    alias InputStream.read read;
+
     PngChunkReader reader;
     PngChunk chunk;
     int offset, length;
-    
-    final static int DATA_OFFSET = 8; 
-    
+
+    final static int DATA_OFFSET = 8;
+
 public this(PngIdatChunk chunk, PngChunkReader reader) {
     this.chunk = chunk;
     this.reader = reader;
@@ -27,32 +38,32 @@
     offset = 0;
 }
 
-private bool checkChunk() {
+private bool checkChunk()  {
     while (offset is length) {
         chunk = reader.readNextChunk();
-        if (chunk is null) throw new IOException();
+        if (chunk is null) throw new IOException("no data");
         if (chunk.getChunkType() is PngChunk.CHUNK_IEND) return false;
-        if (chunk.getChunkType() !is PngChunk.CHUNK_IDAT) throw new IOException();
+        if (chunk.getChunkType() !is PngChunk.CHUNK_IDAT) throw new IOException("");
         length = chunk.getLength();
         offset = 0;
     }
     return true;
 }
 
-public void close() {
+public override void close()  {
     chunk = null;
 }
 
-public int read() {
-    if (chunk is null) throw new IOException();
+public override int read()  {
+    if (chunk is null) throw new IOException("");
     if (offset is length && !checkChunk()) return -1;
     int b = chunk.reference[DATA_OFFSET + offset] & 0xFF;
     offset++;
     return b;
 }
 
-public int read(byte[] b, int off, int len) {
-    if (chunk is null) throw new IOException();
+public override int read(byte[] b, int off, int len)  {
+    if (chunk is null) throw new IOException("");
     if (offset is length && !checkChunk()) return -1;
     len = Math.min(len, length - offset);
     System.arraycopy(chunk.reference, DATA_OFFSET + offset, b, off, len);
--- a/dwt/internal/image/PngLzBlockReader.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngLzBlockReader.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2006 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,10 +7,13 @@
  *
  * 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.PngLzBlockReader;
 
-import java.io.IOException;
+import dwt.internal.image.PngDecodingDataStream;
+import dwt.internal.image.PngHuffmanTables;
 
 public class PngLzBlockReader {
     bool isLastBlock;
@@ -18,41 +21,41 @@
     int uncompressedBytesRemaining;
     PngDecodingDataStream stream;
     PngHuffmanTables huffmanTables;
-    
+
     byte[] window;
     int windowIndex;
     int copyIndex;
     int copyBytesRemaining;
-    
-    static final int UNCOMPRESSED = 0;
-    static final int COMPRESSED_FIXED = 1;
-    static final int COMPRESSED_DYNAMIC = 2;
+
+    static const int UNCOMPRESSED = 0;
+    static const int COMPRESSED_FIXED = 1;
+    static const int COMPRESSED_DYNAMIC = 2;
 
-    static final int END_OF_COMPRESSED_BLOCK = 256;
-    static final int FIRST_LENGTH_CODE = 257;
-    static final int LAST_LENGTH_CODE = 285;
-    static final int FIRST_DISTANCE_CODE = 1;
-    static final int LAST_DISTANCE_CODE = 29;
-    static final int FIRST_CODE_LENGTH_CODE = 4;
-    static final int LAST_CODE_LENGTH_CODE = 19;
+    static const int END_OF_COMPRESSED_BLOCK = 256;
+    static const int FIRST_LENGTH_CODE = 257;
+    static const int LAST_LENGTH_CODE = 285;
+    static const int FIRST_DISTANCE_CODE = 1;
+    static const int LAST_DISTANCE_CODE = 29;
+    static const int FIRST_CODE_LENGTH_CODE = 4;
+    static const int LAST_CODE_LENGTH_CODE = 19;
 
-    static final int[] lengthBases = {
-        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 
+    static const int[] lengthBases = [
+        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27,
         31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258
-    } ; 
-    static final int[] extraLengthBits = {
-        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 
+    ];
+    static const int[] extraLengthBits = [
+        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
         3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0,
-    };
-    static final int[] distanceBases = {
+    ];
+    static const int[] distanceBases = [
         1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129,
         193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097,
         6145, 8193, 12289, 16385, 24577,
-    };
-    static final int[] extraDistanceBits = {
+    ];
+    static const int[] extraDistanceBits = [
         0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7,  7,
         8,  8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
-    };  
+    ];
 
 
 this(PngDecodingDataStream stream) {
@@ -62,13 +65,13 @@
 
 void setWindowSize(int windowSize) {
     window = new byte[windowSize];
-}   
+}
 
-void readNextBlockHeader() {
+void readNextBlockHeader()  {
     isLastBlock = stream.getNextIdatBit() !is 0;
     compressionType = cast(byte)(stream.getNextIdatBits(2) & 0xFF);
-    if (compressionType > 2) stream.error();    
-    
+    if (compressionType > 2) stream.error();
+
     if (compressionType is UNCOMPRESSED) {
         byte b1 = stream.getNextIdatByte();
         byte b2 = stream.getNextIdatByte();
@@ -83,7 +86,7 @@
     }
 }
 
-byte getNextByte() {
+byte getNextByte()  {
     if (compressionType is UNCOMPRESSED) {
         if (uncompressedBytesRemaining is 0) {
             readNextBlockHeader();
@@ -103,43 +106,43 @@
     }
 }
 
-private void assertBlockAtEnd() {
+private void assertBlockAtEnd()  {
     if (compressionType is UNCOMPRESSED) {
         if (uncompressedBytesRemaining > 0) stream.error();
     } else if (copyBytesRemaining > 0 ||
-        (huffmanTables.getNextLiteralValue(stream) !is END_OF_COMPRESSED_BLOCK)) 
+        (huffmanTables.getNextLiteralValue(stream) !is END_OF_COMPRESSED_BLOCK))
     {
-        stream.error();     
+        stream.error();
     }
 }
-void assertCompressedDataAtEnd() {
-    assertBlockAtEnd();     
+void assertCompressedDataAtEnd()  {
+    assertBlockAtEnd();
     while (!isLastBlock) {
         readNextBlockHeader();
         assertBlockAtEnd();
-    }   
+    }
 }
 
-private byte getNextCompressedByte() {
+private byte getNextCompressedByte()  {
     if (copyBytesRemaining > 0) {
         byte value = window[copyIndex];
         window[windowIndex] = value;
         copyBytesRemaining--;
-        
+
         copyIndex++;
-        windowIndex++;      
+        windowIndex++;
         if (copyIndex is window.length) copyIndex = 0;
         if (windowIndex is window.length) windowIndex = 0;
 
-        return value;       
+        return value;
     }
-    
+
     int value = huffmanTables.getNextLiteralValue(stream);
     if (value < END_OF_COMPRESSED_BLOCK) {
         window[windowIndex] = cast(byte) (value & 0xFF);
         windowIndex++;
         if (windowIndex >= window.length) windowIndex = 0;
-        return cast(byte) (value & 0xFF);       
+        return cast(byte) (value & 0xFF);
     } else if (value is END_OF_COMPRESSED_BLOCK) {
         readNextBlockHeader();
         return getNextByte();
@@ -149,7 +152,7 @@
         if (extraBits > 0) {
             length += stream.getNextIdatBits(extraBits);
         }
-        
+
         value = huffmanTables.getNextDistanceValue(stream);
         if (value > LAST_DISTANCE_CODE) stream.error();
         extraBits = extraDistanceBits[value];
@@ -157,7 +160,7 @@
         if (extraBits > 0) {
             distance += stream.getNextIdatBits(extraBits);
         }
-        
+
         copyIndex = windowIndex - distance;
         if (copyIndex < 0) copyIndex += window.length;
 
@@ -168,5 +171,5 @@
         return 0;
     }
 }
-    
+
 }
--- a/dwt/internal/image/PngPlteChunk.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngPlteChunk.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,16 +7,25 @@
  *
  * 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.PngPlteChunk;
+
+import dwt.dwthelper.utils;
 
 
 import dwt.DWT;
 import dwt.graphics.PaletteData;
 import dwt.graphics.RGB;
+import dwt.internal.image.PngChunk;
+import dwt.internal.image.PngFileReadState;
+import dwt.internal.image.PngIhdrChunk;
+
+import tango.text.convert.Format;
 
 class PngPlteChunk : PngChunk {
-    
+
     int paletteSize;
 
 this(PaletteData palette) {
@@ -25,14 +34,14 @@
     setType(TYPE_PLTE);
     setPaletteData(palette);
     setCRC(computeCRC());
-}       
+}
 
 this(byte[] reference){
     super(reference);
     paletteSize = length / 3;
 }
 
-int getChunkType() {
+override int getChunkType() {
     return CHUNK_PLTE;
 }
 
@@ -58,7 +67,7 @@
         int red = reference[offset] & 0xFF;
         int green = reference[offset + 1] & 0xFF;
         int blue = reference[offset + 2] & 0xFF;
-        rgbs[i] = new RGB(red, green, blue);        
+        rgbs[i] = new RGB(red, green, blue);
     }
     return new PaletteData(rgbs);
 }
@@ -80,45 +89,44 @@
 /**
  * Answer whether the chunk is a valid PLTE chunk.
  */
-void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
+override void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
     // A PLTE chunk is invalid if no IHDR has been read or if any PLTE,
     // IDAT, or IEND chunk has been read.
     if (!readState.readIHDR
         || readState.readPLTE
         || readState.readTRNS
         || readState.readIDAT
-        || readState.readIEND) 
+        || readState.readIEND)
     {
         DWT.error(DWT.ERROR_INVALID_IMAGE);
     } else {
         readState.readPLTE = true;
     }
-    
+
     super.validate(readState, headerChunk);
-    
+
     // Palettes cannot be included in grayscale images.
-    // 
+    //
     // Note: just ignore the palette.
 //  if (!headerChunk.getCanHavePalette()) DWT.error(DWT.ERROR_INVALID_IMAGE);
-    
+
     // Palette chunks' data fields must be event multiples
     // of 3. Each 3-byte group represents an RGB value.
-    if (getLength() % 3 !is 0) DWT.error(DWT.ERROR_INVALID_IMAGE);  
-    
+    if (getLength() % 3 !is 0) DWT.error(DWT.ERROR_INVALID_IMAGE);   
+
     // Palettes cannot have more entries than 2^bitDepth
     // where bitDepth is the bit depth of the image given
     // in the IHDR chunk.
     if (1 << headerChunk.getBitDepth() < paletteSize) {
         DWT.error(DWT.ERROR_INVALID_IMAGE);
     }
-    
+
     // Palettes cannot have more than 256 entries.
     if (256 < paletteSize) DWT.error(DWT.ERROR_INVALID_IMAGE);
 }
 
-void contributeToString(StringBuffer buffer) {
-    buffer.append("\n\tPalette size:");
-    buffer.append(paletteSize);
+override String contributeToString() {
+    return Format("\n\tPalette size:{}", paletteSize );
 }
 
 }
--- 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++) {
--- a/dwt/internal/image/TIFFDirectory.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/TIFFDirectory.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,18 +7,21 @@
  *
  * 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.TIFFDirectory;
 
-import java.io.IOException;
-
-import dwt.DWT;
+import dwt.internal.image.TIFFRandomFileAccess;
+import dwt.internal.image.TIFFModifiedHuffmanCodec;
+import dwt.internal.image.LEDataOutputStream;
 import dwt.graphics.ImageData;
+import dwt.graphics.ImageLoaderEvent;
 import dwt.graphics.ImageLoader;
-import dwt.graphics.ImageLoaderEvent;
 import dwt.graphics.PaletteData;
 import dwt.graphics.RGB;
+import dwt.DWT;
+import dwt.dwthelper.utils;
 
 final class TIFFDirectory {
 
@@ -26,7 +29,7 @@
     bool isLittleEndian;
     ImageLoader loader;
     int depth;
-    
+
     /* Directory fields */
     int imageWidth;
     int imageLength;
@@ -39,41 +42,41 @@
     int[] stripByteCounts;
     int t4Options;
     int colorMapOffset;
-    
+
     /* Encoder fields */
     ImageData image;
-    LEDataOutputStream out;
-    
-    static final int NO_VALUE = -1;
-    
-    static final short TAG_ImageWidth = 256;
-    static final short TAG_ImageLength = 257;
-    static final short TAG_BitsPerSample = 258;
-    static final short TAG_Compression = 259;
-    static final short TAG_PhotometricInterpretation = 262;
-    static final short TAG_StripOffsets = 273;
-    static final short TAG_SamplesPerPixel = 277;
-    static final short TAG_RowsPerStrip = 278;
-    static final short TAG_StripByteCounts = 279;
-    static final short TAG_XResolution = 282;
-    static final short TAG_YResolution = 283;
-    static final short TAG_T4Options = 292;
-    static final short TAG_ResolutionUnit = 296;
-    static final short TAG_ColorMap = 320;
-    
-    static final int TYPE_BYTE = 1;
-    static final int TYPE_ASCII = 2;
-    static final int TYPE_SHORT = 3;
-    static final int TYPE_LONG = 4;
-    static final int TYPE_RATIONAL = 5;
-    
+    LEDataOutputStream ostr;
+
+    static const int NO_VALUE = -1;
+
+    static const short TAG_ImageWidth = 256;
+    static const short TAG_ImageLength = 257;
+    static const short TAG_BitsPerSample = 258;
+    static const short TAG_Compression = 259;
+    static const short TAG_PhotometricInterpretation = 262;
+    static const short TAG_StripOffsets = 273;
+    static const short TAG_SamplesPerPixel = 277;
+    static const short TAG_RowsPerStrip = 278;
+    static const short TAG_StripByteCounts = 279;
+    static const short TAG_XResolution = 282;
+    static const short TAG_YResolution = 283;
+    static const short TAG_T4Options = 292;
+    static const short TAG_ResolutionUnit = 296;
+    static const short TAG_ColorMap = 320;
+
+    static const int TYPE_BYTE = 1;
+    static const int TYPE_ASCII = 2;
+    static const int TYPE_SHORT = 3;
+    static const int TYPE_LONG = 4;
+    static const int TYPE_RATIONAL = 5;
+
     /* Different compression schemes */
-    static final int COMPRESSION_NONE = 1;
-    static final int COMPRESSION_CCITT_3_1 = 2;
-    static final int COMPRESSION_PACKBITS = 32773;
-    
-    static final int IFD_ENTRY_SIZE = 12;
-    
+    static const int COMPRESSION_NONE = 1;
+    static const int COMPRESSION_CCITT_3_1 = 2;
+    static const int COMPRESSION_PACKBITS = 32773;
+
+    static const int IFD_ENTRY_SIZE = 12;
+
 public this(TIFFRandomFileAccess file, bool isLittleEndian, ImageLoader loader) {
     this.file = file;
     this.isLittleEndian = isLittleEndian;
@@ -93,8 +96,8 @@
         if (0 <= n && n <= 127) {
             /* Copy next n+1 bytes literally */
             System.arraycopy(src, ++srcIndex, dest, destIndex, n + 1);
-            srcIndex += n + 1;      
-            destIndex += n + 1; 
+            srcIndex += n + 1;
+            destIndex += n + 1;
         } else if (-127 <= n && n <= -1) {
             /* Copy next byte -n+1 times */
             byte value = src[++srcIndex];
@@ -115,20 +118,20 @@
     return toInt(buffer, index + 8, type);
 }
 
-void getEntryValue(int type, byte[] buffer, int index, int[] values) {
+void getEntryValue(int type, byte[] buffer, int index, int[] values)  {
     int start = index + 8;
     int size;
     int offset = toInt(buffer, start, TYPE_LONG);
     switch (type) {
         case TYPE_SHORT: size = 2; break;
-        case TYPE_LONG: size = 4; break; 
+        case TYPE_LONG: size = 4; break;
         case TYPE_RATIONAL: size = 8; break;
         case TYPE_ASCII:
         case TYPE_BYTE: size = 1; break;
         default: DWT.error(DWT.ERROR_UNSUPPORTED_FORMAT); return;
     }
     if (values.length * size > 4) {
-        buffer = new byte[values.length * size]; 
+        buffer = new byte[values.length * size];
         file.seek(offset);
         file.read(buffer);
         start = 0;
@@ -138,15 +141,15 @@
     }
 }
 
-void decodePixels(ImageData image) {
-    /* Each row is byte aligned */ 
+void decodePixels(ImageData image)  {
+    /* Each row is byte aligned */
     byte[] imageData = new byte[(imageWidth * depth + 7) / 8 * imageLength];
     image.data = imageData;
     int destIndex = 0;
     int length = stripOffsets.length;
     for (int i = 0; i < length; i++) {
         /* Read a strip */
-        byte[] data = new byte[stripByteCounts[i]];
+        byte[] data = new byte[](stripByteCounts[i]);
         file.seek(stripOffsets[i]);
         file.read(data);
         if (compression is COMPRESSION_NONE) {
@@ -169,7 +172,7 @@
     }
 }
 
-PaletteData getColorMap() {
+PaletteData getColorMap()  {
     int numColors = 1 << bitsPerSample[0];
     /* R, G, B entries are 16 bit wide (2 bytes) */
     int numBytes = 3 * 2 * numColors;
@@ -210,7 +213,7 @@
     return new PaletteData(rgbs);
 }
 
-PaletteData getRGBPalette(int bitsR, int bitsG, int bitsB) {    
+PaletteData getRGBPalette(int bitsR, int bitsG, int bitsB) {
     int blueMask = 0;
     for (int i = 0; i < bitsB; i++) {
         blueMask |= 1 << i;
@@ -222,16 +225,16 @@
     int redMask = 0;
     for (int i = bitsB + bitsG; i < bitsB + bitsG + bitsR; i++) {
         redMask |= 1 << i;
-    }   
+    }
     return new PaletteData(redMask, greenMask, blueMask);
 }
 
 int formatStrips(int rowByteSize, int nbrRows, byte[] data, int maxStripByteSize, int offsetPostIFD, int extraBytes, int[][] strips) {
-    /* 
-    * Calculate the nbr of required strips given the following requirements: 
+    /*
+    * Calculate the nbr of required strips given the following requirements:
     * - each strip should, if possible, not be greater than maxStripByteSize
     * - each strip should contain 1 or more entire rows
-    * 
+    *
     * Format the strip fields arrays so that the image data is stored in one
     * contiguous block. This block is stored after the IFD and after any tag
     * info described in the IFD.
@@ -244,13 +247,13 @@
     } else {
         int nbr = (data.length + maxStripByteSize - 1) / maxStripByteSize;
         nbrRowsPerStrip = nbrRows / nbr;
-        n = (nbrRows + nbrRowsPerStrip - 1) / nbrRowsPerStrip;  
+        n = (nbrRows + nbrRowsPerStrip - 1) / nbrRowsPerStrip;
     }
     int stripByteSize = rowByteSize * nbrRowsPerStrip;
 
     int[] offsets = new int[n];
     int[] counts = new int[n];
-    /* 
+    /*
     * Nbr of bytes between the end of the IFD directory and the start of
     * the image data. Keep space for at least the offsets and counts
     * data, each field being TYPE_LONG (4 bytes). If other tags require
@@ -261,10 +264,10 @@
     */
     int postIFDData = n is 1 ? 0 : n * 2 * 4;
     int startOffset = offsetPostIFD + extraBytes + postIFDData; /* offset of image data */
-    
+
     int offset = startOffset;
     for (int i = 0; i < n; i++) {
-        /* 
+        /*
         * Store all strips sequentially to allow us
         * to copy all pixels in one contiguous area.
         */
@@ -275,17 +278,17 @@
     /* The last strip may contain fewer rows */
     int mod = data.length % stripByteSize;
     if (mod !is 0) counts[counts.length - 1] = mod;
-    
+
     strips[0] = offsets;
     strips[1] = counts;
     return nbrRowsPerStrip;
 }
 
 int[] formatColorMap(RGB[] rgbs) {
-    /* 
+    /*
     * In a TIFF ColorMap, all red come first, followed by
     * green and blue. All values must be converted from
-    * 8 bit to 16 bit. 
+    * 8 bit to 16 bit.
     */
     int[] colorMap = new int[rgbs.length * 3];
     int offsetGreen = rgbs.length;
@@ -298,7 +301,7 @@
     return colorMap;
 }
 
-void parseEntries(byte[] buffer) {
+void parseEntries(byte[] buffer)  {
     for (int offset = 0; offset < buffer.length; offset += IFD_ENTRY_SIZE) {
         int tag = toInt(buffer, offset, TYPE_SHORT);
         int type = toInt(buffer, offset + 2, TYPE_SHORT);
@@ -375,13 +378,14 @@
                 colorMapOffset = getEntryValue(TYPE_LONG, buffer, offset);
                 break;
             }
+            default:
         }
     }
 }
 
-public ImageData read() {
+public ImageData read()  {
     /* Set TIFF default values */
-    bitsPerSample = new int[] {1};
+    bitsPerSample = [1];
     colorMapOffset = NO_VALUE;
     compression = 1;
     imageLength = NO_VALUE;
@@ -391,14 +395,14 @@
     samplesPerPixel = 1;
     stripByteCounts = null;
     stripOffsets = null;
-    
+
     byte[] buffer = new byte[2];
     file.read(buffer);
     int numberEntries = toInt(buffer, 0, TYPE_SHORT);
     buffer = new byte[IFD_ENTRY_SIZE * numberEntries];
     file.read(buffer);
     parseEntries(buffer);
-    
+
     PaletteData palette = null;
     depth = 0;
     switch (photometricInterpretation) {
@@ -415,7 +419,7 @@
             /* SamplesPerPixel 3 is the only value supported */
             palette = getRGBPalette(bitsPerSample[0], bitsPerSample[1], bitsPerSample[2]);
             depth = bitsPerSample[0] + bitsPerSample[1] + bitsPerSample[2];
-            break;      
+            break;
         }
         case 3: {
             /* Palette Color image */
@@ -431,7 +435,7 @@
 
     ImageData image = ImageData.internal_new(
             imageWidth,
-            imageLength, 
+            imageLength,
             depth,
             palette,
             1,
@@ -452,21 +456,21 @@
 
 int toInt(byte[] buffer, int i, int type) {
     if (type is TYPE_LONG) {
-        return isLittleEndian ? 
+        return isLittleEndian ?
         (buffer[i] & 0xFF) | ((buffer[i + 1] & 0xFF) << 8) | ((buffer[i + 2] & 0xFF) << 16) | ((buffer[i + 3] & 0xFF) << 24) :
         (buffer[i + 3] & 0xFF) | ((buffer[i + 2] & 0xFF) << 8) | ((buffer[i + 1] & 0xFF) << 16) | ((buffer[i] & 0xFF) << 24);
     }
     if (type is TYPE_SHORT) {
-        return isLittleEndian ? 
+        return isLittleEndian ?
         (buffer[i] & 0xFF) | ((buffer[i + 1] & 0xFF) << 8) :
-        (buffer[i + 1] & 0xFF) | ((buffer[i] & 0xFF) << 8);     
+        (buffer[i + 1] & 0xFF) | ((buffer[i] & 0xFF) << 8);
     }
     /* Invalid type */
     DWT.error(DWT.ERROR_INVALID_IMAGE);
     return -1;
 }
 
-void write(int photometricInterpretation) {
+void write(int photometricInterpretation)  {
     bool isRGB = photometricInterpretation is 2;
     bool isColorMap = photometricInterpretation is 3;
     bool isBiLevel = photometricInterpretation is 0 || photometricInterpretation is 1;
@@ -474,7 +478,7 @@
     int imageWidth = image.width;
     int imageLength = image.height;
     int rowByteSize = image.bytesPerLine;
-    
+
     int numberEntries = isBiLevel ? 9 : 11;
     int lengthDirectory = 2 + 12 * numberEntries + 4;
     /* Offset following the header and the directory */
@@ -484,7 +488,7 @@
     int extraBytes = 16;
 
     int[] colorMap = null;
-    if (isColorMap) {   
+    if (isColorMap) {
         PaletteData palette = image.palette;
         RGB[] rgbs = palette.getRGBs();
         colorMap = formatColorMap(rgbs);
@@ -496,10 +500,10 @@
     if (isRGB) {
         /* Extra space used by BitsPerSample values */
         extraBytes += 6;
-    } 
+    }
     /* TIFF recommends storing the data in strips of no more than 8 Ko */
     byte[] data = image.data;
-    int[][] strips = new int[2][];
+    int[][] strips = new int[][](2);
     int nbrRowsPerStrip = formatStrips(rowByteSize, imageLength, data, 8192, nextOffset, extraBytes, strips);
     int[] stripOffsets = strips[0];
     int[] stripByteCounts = strips[1];
@@ -528,10 +532,10 @@
     }
     /* TIFF header */
     writeHeader();
-    
+
     /* Image File Directory */
-    out.writeShort(numberEntries);  
-    writeEntry(TAG_ImageWidth, TYPE_LONG, 1, imageWidth);   
+    ostr.writeShort(numberEntries);
+    writeEntry(TAG_ImageWidth, TYPE_LONG, 1, imageWidth);
     writeEntry(TAG_ImageLength, TYPE_LONG, 1, imageLength);
     if (isColorMap) writeEntry(TAG_BitsPerSample, TYPE_SHORT, 1, image.depth);
     if (isRGB) writeEntry(TAG_BitsPerSample, TYPE_SHORT, 3, bitsPerSampleOffset);
@@ -545,53 +549,53 @@
     writeEntry(TAG_YResolution, TYPE_RATIONAL, 1, yResolutionOffset);
     if (isColorMap) writeEntry(TAG_ColorMap, TYPE_SHORT, colorMap.length, colorMapOffset);
     /* Offset of next IFD (0 for last IFD) */
-    out.writeInt(0);
-    
+    ostr.writeInt(0);
+
     /* Values longer than 4 bytes Section */
-    
+
     /* BitsPerSample 8,8,8 */
-    if (isRGB) for (int i = 0; i < 3; i++) out.writeShort(8);
+    if (isRGB) for (int i = 0; i < 3; i++) ostr.writeShort(8);
     if (cnt > 1) {
-        for (int i = 0; i < cnt; i++) out.writeInt(stripOffsets[i]);
-        for (int i = 0; i < cnt; i++) out.writeInt(stripByteCounts[i]);
+        for (int i = 0; i < cnt; i++) ostr.writeInt(stripOffsets[i]);
+        for (int i = 0; i < cnt; i++) ostr.writeInt(stripByteCounts[i]);
     }
     /* XResolution and YResolution set to 300 dpi */
     for (int i = 0; i < 2; i++) {
-        out.writeInt(300);
-        out.writeInt(1);
+        ostr.writeInt(300);
+        ostr.writeInt(1);
     }
     /* ColorMap */
-    if (isColorMap) for (int i = 0; i < colorMap.length; i++) out.writeShort(colorMap[i]);
-    
+    if (isColorMap) for (int i = 0; i < colorMap.length; i++) ostr.writeShort(colorMap[i]);
+
     /* Image Data */
-    out.write(data);
+    ostr.write(data);
 }
 
 void writeEntry(short tag, int type, int count, int value) {
-    out.writeShort(tag);
-    out.writeShort(type);
-    out.writeInt(count);
-    out.writeInt(value);
+    ostr.writeShort(tag);
+    ostr.writeShort(type);
+    ostr.writeInt(count);
+    ostr.writeInt(value);
 }
 
 void writeHeader() {
     /* little endian */
-    out.write(0x49);
-    out.write(0x49);
+    ostr.write(0x49);
+    ostr.write(0x49);
 
     /* TIFF identifier */
-    out.writeShort(42);
-    /* 
+    ostr.writeShort(42);
+    /*
     * Offset of the first IFD is chosen to be 8.
     * It is word aligned and immediately after this header.
     */
-    out.writeInt(8);
+    ostr.writeInt(8);
 }
 
 void writeToStream(LEDataOutputStream byteStream) {
-    out = byteStream;
+    ostr = byteStream;
     int photometricInterpretation = -1;
-    
+
     /* Scanline pad must be 1 */
     if (image.scanlinePad !is 1) DWT.error(DWT.ERROR_UNSUPPORTED_FORMAT);
     switch (image.depth) {
@@ -605,7 +609,7 @@
             if (!(rgb0.red is rgb0.green && rgb0.green is rgb0.blue &&
                 rgb1.red is rgb1.green && rgb1.green is rgb1.blue &&
                 ((rgb0.red is 0x0 && rgb1.red is 0xFF) || (rgb0.red is 0xFF && rgb1.red is 0x0)))) {
-                DWT.error(DWT.ERROR_UNSUPPORTED_FORMAT); 
+                DWT.error(DWT.ERROR_UNSUPPORTED_FORMAT);
             }
             /* 0 means a color index of 0 is imaged as white */
             photometricInterpretation = image.palette.colors[0].red is 0xFF ? 0 : 1;
--- a/dwt/internal/image/TIFFFileFormat.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/TIFFFileFormat.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,23 +7,27 @@
  *
  * 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.TIFFFileFormat;
 
-
-import java.io.IOException;
-
+import dwt.internal.image.TIFFRandomFileAccess;
+import dwt.internal.image.TIFFDirectory;
 import dwt.DWT;
 import dwt.graphics.ImageData;
 import dwt.graphics.ImageLoader;
+import dwt.internal.image.FileFormat;
+
+import tango.core.Exception;
 
 /**
  * Baseline TIFF decoder revision 6.0
  * Extension T4-encoding CCITT T.4 1D
  */
-public final class TIFFFileFormat : FileFormat {
+final class TIFFFileFormat : FileFormat {
 
-bool isFileFormat(LEDataInputStream stream) {
+override bool isFileFormat(LEDataInputStream stream) {
     try {
         byte[] header = new byte[4];
         stream.read(header);
@@ -32,14 +36,14 @@
         if (!(header[0] is 0x49 && header[2] is 42 && header[3] is 0) &&
             !(header[0] is 0x4d && header[2] is 0 && header[3] is 42)) {
             return false;
-        }   
+        }
         return true;
     } catch (Exception e) {
         return false;
     }
 }
 
-ImageData[] loadFromByteStream() {  
+override ImageData[] loadFromByteStream() {
     byte[] header = new byte[8];
     bool isLittleEndian;
     ImageData[] images = new ImageData[0];
@@ -50,23 +54,23 @@
         if (!(header[0] is 0x49 && header[2] is 42 && header[3] is 0) &&
             !(header[0] is 0x4d && header[2] is 0 && header[3] is 42)) {
             DWT.error(DWT.ERROR_INVALID_IMAGE);
-        } 
-        isLittleEndian = header[0] is 0x49; 
-        int offset = isLittleEndian ? 
+        }
+        isLittleEndian = header[0] is 0x49;
+        int offset = isLittleEndian ?
             (header[4] & 0xFF) | ((header[5] & 0xFF) << 8) | ((header[6] & 0xFF) << 16) | ((header[7] & 0xFF) << 24) :
             (header[7] & 0xFF) | ((header[6] & 0xFF) << 8) | ((header[5] & 0xFF) << 16) | ((header[4] & 0xFF) << 24);
         file.seek(offset);
         TIFFDirectory directory = new TIFFDirectory(file, isLittleEndian, loader);
         ImageData image = directory.read();
         /* A baseline reader is only expected to read the first directory */
-        images = new ImageData[] {image};
+        images = [image];
     } catch (IOException e) {
         DWT.error(DWT.ERROR_IO, e);
     }
     return images;
 }
 
-void unloadIntoByteStream(ImageLoader loader) {
+override void unloadIntoByteStream(ImageLoader loader) {
     /* We do not currently support writing multi-page tiff,
      * so we use the first image data in the loader's array. */
     ImageData image = loader.data[0];
--- a/dwt/internal/image/TIFFModifiedHuffmanCodec.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/TIFFModifiedHuffmanCodec.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2003 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,88 +7,90 @@
  *
  * 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.TIFFModifiedHuffmanCodec;
 
 import dwt.DWT;
 
 /*
-* Decoder for 
+* Decoder for
 * - CCITT Group 3 1-Dimensional Modified Huffman run length encoding
 *   (TIFF compression type 2)
 * - CCITT T.4 bi-level encoding 1D
-*   (TIFF compression type 3 option 1D) 
+*   (TIFF compression type 3 option 1D)
 */
 final class TIFFModifiedHuffmanCodec {
-    static final short[][][] BLACK_CODE = {
+    static final short[][][] BLACK_CODE = [
         /* 2 bits  */
-        {{2, 3}, {3, 2}},
+        [[ cast(short)2, 3], [ cast(short)3, 2]],
         /* 3 bits  */
-        {{2, 1}, {3, 4}},
+        [[ cast(short)2, 1], [ cast(short)3, 4]],
         /* 4 bits  */
-        {{2, 6}, {3, 5}},
+        [[ cast(short)2, 6], [ cast(short)3, 5]],
         /* 5 bits  */
-        {{3, 7}},
+        [[ cast(short)3, 7]],
         /* 6 bits  */
-        {{4, 9}, {5, 8}},
+        [[ cast(short)4, 9], [ cast(short)5, 8]],
         /* 7 bits  */
-        {{4, 10}, {5, 11}, {7, 12}},
+        [[ cast(short)4, 10], [ cast(short)5, 11], [ cast(short)7, 12]],
         /* 8 bits  */
-        {{4, 13}, {7, 14}},
+        [[ cast(short)4, 13], [ cast(short)7, 14]],
         /* 9 bits  */
-        {{24, 15}},
+        [[ cast(short)24, 15]],
         /* 10 bits */
-        {{8, 18}, {15, 64}, {23, 16}, {24, 17}, {55, 0}},
+        [[ cast(short)8, 18], [ cast(short)15, 64], [ cast(short)23, 16], [ cast(short)24, 17], [ cast(short)55, 0]],
         /* 11 bits */
-        {/* EOL */{0, -1}, {8, 1792}, {23, 24}, {24, 25}, {40, 23}, {55, 22}, {103, 19},
-        {104, 20}, {108, 21}, {12, 1856}, {13, 1920}},
+        [/* EOL */[ cast(short)0, -1], [ cast(short)8, 1792], [ cast(short)23, 24], [ cast(short)24, 25], [ cast(short)40, 23], [ cast(short)55, 22], [ cast(short)103, 19],
+        [ cast(short)104, 20], [ cast(short)108, 21], [ cast(short)12, 1856], [ cast(short)13, 1920]],
         /* 12 bits */
-        {{18, 1984}, {19, 2048}, {20, 2112}, {21, 2176}, {22, 2240}, {23, 2304},
-        {28, 2368}, {29, 2432}, {30, 2496}, {31, 2560}, {36, 52}, {39, 55}, {40, 56},
-        {43, 59}, {44, 60}, {51, 320}, {52, 384}, {53, 448}, {55, 53}, {56, 54}, {82, 50},
-        {83, 51}, {84, 44}, {85, 45}, {86, 46}, {87, 47}, {88, 57}, {89, 58}, {90, 61},
-        {91, 256}, {100, 48}, {101, 49}, {102, 62}, {103, 63}, {104, 30}, {105, 31},
-        {106, 32}, {107, 33}, {108, 40}, {109, 41}, {200, 128}, {201, 192}, {202, 26},
-        {203, 27}, {204, 28}, {205, 29}, {210, 34}, {211, 35}, {212, 36}, {213, 37},
-        {214, 38}, {215, 39}, {218, 42}, {219, 43}},
+        [[ cast(short)18, 1984], [ cast(short)19, 2048], [ cast(short)20, 2112], [ cast(short)21, 2176], [ cast(short)22, 2240], [ cast(short)23, 2304],
+        [ cast(short)28, 2368], [ cast(short)29, 2432], [ cast(short)30, 2496], [ cast(short)31, 2560], [ cast(short)36, 52], [ cast(short)39, 55], [ cast(short)40, 56],
+        [ cast(short)43, 59], [ cast(short)44, 60], [ cast(short)51, 320], [ cast(short)52, 384], [ cast(short)53, 448], [ cast(short)55, 53], [ cast(short)56, 54], [ cast(short)82, 50],
+        [ cast(short)83, 51], [ cast(short)84, 44], [ cast(short)85, 45], [ cast(short)86, 46], [ cast(short)87, 47], [ cast(short)88, 57], [ cast(short)89, 58], [ cast(short)90, 61],
+        [ cast(short)91, 256], [ cast(short)100, 48], [ cast(short)101, 49], [ cast(short)102, 62], [ cast(short)103, 63], [ cast(short)104, 30], [ cast(short)105, 31],
+        [ cast(short)106, 32], [ cast(short)107, 33], [ cast(short)108, 40], [ cast(short)109, 41], [ cast(short)200, 128], [ cast(short)201, 192], [ cast(short)202, 26],
+        [ cast(short)203, 27], [ cast(short)204, 28], [ cast(short)205, 29], [ cast(short)210, 34], [ cast(short)211, 35], [ cast(short)212, 36], [ cast(short)213, 37],
+        [ cast(short)214, 38], [ cast(short)215, 39], [ cast(short)218, 42], [ cast(short)219, 43]],
         /* 13 bits */
-        {{74, 640}, {75, 704}, {76, 768}, {77, 832}, {82, 1280}, {83, 1344}, {84, 1408},
-        {85, 1472}, {90, 1536}, {91, 1600}, {100, 1664}, {101, 1728}, {108, 512},
-        {109, 576}, {114, 896}, {115, 960}, {116, 1024}, {117, 1088}, {118, 1152},
-        {119, 1216}}
-    };
+        [[ cast(short)74, 640], [ cast(short)75, 704], [ cast(short)76, 768], [ cast(short)77, 832], [ cast(short)82, 1280], [ cast(short)83, 1344], [ cast(short)84, 1408],
+        [ cast(short)85, 1472], [ cast(short)90, 1536], [ cast(short)91, 1600], [ cast(short)100, 1664], [ cast(short)101, 1728], [ cast(short)108, 512],
+        [ cast(short)109, 576], [ cast(short)114, 896], [ cast(short)115, 960], [ cast(short)116, 1024], [ cast(short)117, 1088], [ cast(short)118, 1152],
+        [ cast(short)119, 1216]]
+    ];
 
-    static final short[][][] WHITE_CODE = {
+    static final short[][][] WHITE_CODE = [
         /* 4 bits */
-        {{7, 2}, {8, 3}, {11, 4}, {12, 5}, {14, 6}, {15, 7}},
+        [[ cast(short)7, 2], [ cast(short)8, 3], [ cast(short)11, 4], [ cast(short)12, 5], [ cast(short)14, 6], [ cast(short)15, 7]],
         /* 5 bits */
-        {{7, 10}, {8, 11}, {18, 128}, {19, 8}, {20, 9}, {27, 64}},
+        [[ cast(short)7, 10], [ cast(short)8, 11], [ cast(short)18, 128], [ cast(short)19, 8], [ cast(short)20, 9], [ cast(short)27, 64]],
         /* 6 bits */
-        {{3, 13}, {7, 1}, {8, 12}, {23, 192}, {24, 1664}, {42, 16}, {43, 17}, {52, 14},
-        {53, 15}},
+        [[ cast(short)3, 13], [ cast(short)7, 1], [ cast(short)8, 12], [ cast(short)23, 192], [ cast(short)24, 1664], [ cast(short)42, 16], [ cast(short)43, 17], [ cast(short)52, 14],
+        [ cast(short)53, 15]],
         /* 7 bits */
-        {{3, 22}, {4, 23}, {8, 20}, {12, 19}, {19, 26}, {23, 21}, {24, 28}, {36, 27},
-        {39, 18}, {40, 24}, {43, 25}, {55, 256}},
+        [[ cast(short)3, 22], [ cast(short)4, 23], [ cast(short)8, 20], [ cast(short)12, 19], [ cast(short)19, 26], [ cast(short)23, 21], [ cast(short)24, 28], [ cast(short)36, 27],
+        [ cast(short)39, 18], [ cast(short)40, 24], [ cast(short)43, 25], [ cast(short)55, 256]],
         /* 8 bits */
-        {{2, 29}, {3, 30}, {4, 45}, {5, 46}, {10, 47}, {11, 48}, {18, 33}, {19, 34},
-        {20, 35}, {21, 36}, {22, 37}, {23, 38}, {26, 31}, {27, 32}, {36, 53}, {37, 54},
-        {40, 39}, {41, 40}, {42, 41}, {43, 42}, {44, 43}, {45, 44}, {50, 61}, {51, 62},
-        {52, 63}, {53, 0}, {54, 320}, {55, 384}, {74, 59}, {75, 60}, {82, 49}, {83, 50},
-        {84, 51}, {85, 52}, {88, 55}, {89, 56}, {90, 57}, {91, 58}, {100, 448},
-        {101, 512}, {103, 640}, {104, 576}},
+        [[ cast(short)2, 29], [ cast(short)3, 30], [ cast(short)4, 45], [ cast(short)5, 46], [ cast(short)10, 47], [ cast(short)11, 48], [ cast(short)18, 33], [ cast(short)19, 34],
+        [ cast(short)20, 35], [ cast(short)21, 36], [ cast(short)22, 37], [ cast(short)23, 38], [ cast(short)26, 31], [ cast(short)27, 32], [ cast(short)36, 53], [ cast(short)37, 54],
+        [ cast(short)40, 39], [ cast(short)41, 40], [ cast(short)42, 41], [ cast(short)43, 42], [ cast(short)44, 43], [ cast(short)45, 44], [ cast(short)50, 61], [ cast(short)51, 62],
+        [ cast(short)52, 63], [ cast(short)53, 0], [ cast(short)54, 320], [ cast(short)55, 384], [ cast(short)74, 59], [ cast(short)75, 60], [ cast(short)82, 49], [ cast(short)83, 50],
+        [ cast(short)84, 51], [ cast(short)85, 52], [ cast(short)88, 55], [ cast(short)89, 56], [ cast(short)90, 57], [ cast(short)91, 58], [ cast(short)100, 448],
+        [ cast(short)101, 512], [ cast(short)103, 640], [ cast(short)104, 576]],
         /* 9 bits */
-        {{152, 1472}, {153, 1536}, {154, 1600}, {155, 1728}, {204, 704}, {205, 768},
-        {210, 832}, {211, 896}, {212, 960}, {213, 1024}, {214, 1088}, {215, 1152},
-        {216, 1216}, {217, 1280}, {218, 1344}, {219, 1408}},
+        [[ cast(short)152, 1472], [ cast(short)153, 1536], [ cast(short)154, 1600], [ cast(short)155, 1728], [ cast(short)204, 704], [ cast(short)205, 768],
+        [ cast(short)210, 832], [ cast(short)211, 896], [ cast(short)212, 960], [ cast(short)213, 1024], [ cast(short)214, 1088], [ cast(short)215, 1152],
+        [ cast(short)216, 1216], [ cast(short)217, 1280], [ cast(short)218, 1344], [ cast(short)219, 1408]],
         /* 10 bits */
-        {},
+        [],
         /* 11 bits */
-        {{8, 1792}, {12, 1856}, {13, 1920}},
+        [[ cast(short)8, 1792], [ cast(short)12, 1856], [ cast(short)13, 1920]],
         /* 12 bits */
-        {/* EOL */{1, -1}, {18, 1984}, {19, 2048}, {20, 2112}, {21, 2176}, {22, 2240}, {23, 2304},
-        {28, 2368}, {29, 2432}, {30, 2496}, {31, 2560}}
-    };
-    
+        [/* EOL */[ cast(short)1, -1], [ cast(short)18, 1984], [ cast(short)19, 2048], [ cast(short)20, 2112], [ cast(short)21, 2176], [ cast(short)22, 2240], [ cast(short)23, 2304],
+        [ cast(short)28, 2368], [ cast(short)29, 2432], [ cast(short)30, 2496], [ cast(short)31, 2560]]
+    ];
+
     static final int BLACK_MIN_BITS = 2;
     static final int WHITE_MIN_BITS = 4;
 
@@ -120,7 +122,7 @@
         /* byte aligned */
         if (bitOffsetDest > 0) {
             byteOffsetDest++;
-            bitOffsetDest = 0; 
+            bitOffsetDest = 0;
         }
     }
     return byteOffsetDest - offsetDest;
@@ -166,7 +168,7 @@
             if (found) break;
             code = code << 1 | getNextBit();
         }
-        if (!found) DWT.error(DWT.ERROR_INVALID_IMAGE);          
+        if (!found) DWT.error(DWT.ERROR_INVALID_IMAGE);
     }
 }
 
@@ -195,7 +197,7 @@
             cast(byte)(dest[byteOffsetDest] | (1 << (7 - bitOffsetDest))) :
             cast(byte)(dest[byteOffsetDest] & ~(1 << (7 - bitOffsetDest)));
         n--;
-        bitOffsetDest++; 
+        bitOffsetDest++;
     }
     if (bitOffsetDest is 8) {
         byteOffsetDest++;
@@ -210,8 +212,8 @@
             cast(byte)(dest[byteOffsetDest] | (1 << (7 - bitOffsetDest))) :
             cast(byte)(dest[byteOffsetDest] & ~(1 << (7 - bitOffsetDest)));
         n--;
-        bitOffsetDest++;        
-    }   
+        bitOffsetDest++;
+    }
 }
 
 }
--- a/dwt/internal/image/TIFFRandomFileAccess.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/TIFFRandomFileAccess.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2003 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,10 +7,15 @@
  *
  * 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.TIFFRandomFileAccess;
 
-import java.io.IOException;
+import dwt.internal.image.LEDataInputStream;
+import Math = tango.math.Math;
+import tango.core.Exception;
+import dwt.dwthelper.System;
 
 final class TIFFRandomFileAccess {
 
@@ -24,13 +29,13 @@
 public this(LEDataInputStream stream) {
     inputStream = stream;
     start = current = next = inputStream.getPosition();
-    buffers = new byte[LIST_SIZE][];
+    buffers = new byte[][](LIST_SIZE);
 }
 
 void seek(int pos) {
     if (pos is current) return;
-    if (pos < start) throw new IOException();
-    current = pos;  
+    if (pos < start) throw new IOException( "pos < start" );
+    current = pos;
     if (current > next) {
         int n = current - next;
         /* store required bytes */
@@ -39,7 +44,7 @@
         while (n > 0) {
             if (index >= buffers.length) {
                 byte[][] oldBuffers = buffers;
-                buffers = new byte[Math.max(index + 1, oldBuffers.length + LIST_SIZE)][];
+                buffers = new byte[][]( Math.max(index + 1, oldBuffers.length + LIST_SIZE) );
                 System.arraycopy(oldBuffers, 0, buffers, 0, oldBuffers.length);
             }
             if (buffers[index] is null) buffers[index] = new byte[CHUNK_SIZE];
@@ -60,11 +65,11 @@
     if (nCached > 0) {
         /* Get cached bytes */
         int index = current / CHUNK_SIZE;
-        int offset = current % CHUNK_SIZE;      
+        int offset = current % CHUNK_SIZE;
         while (nCached > 0) {
             int cnt = Math.min(nCached, CHUNK_SIZE - offset);
             System.arraycopy(buffers[index], offset, b, destNext, cnt);
-            nCached -= cnt; 
+            nCached -= cnt;
             destNext += cnt;
             index++;
             offset = 0;
@@ -77,7 +82,7 @@
         while (nMissing > 0) {
             if (index >= buffers.length) {
                 byte[][] oldBuffers = buffers;
-                buffers = new byte[Math.max(index, oldBuffers.length + LIST_SIZE)][];
+                buffers = new byte[][](Math.max(index, oldBuffers.length + LIST_SIZE));
                 System.arraycopy(oldBuffers, 0, buffers, 0, oldBuffers.length);
             }
             if (buffers[index] is null) buffers[index] = new byte[CHUNK_SIZE];
--- a/dwt/internal/image/WinBMPFileFormat.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/WinBMPFileFormat.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,26 +7,31 @@
  *
  * 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.WinBMPFileFormat;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-import dwt.DWT;
-import dwt.graphics.ImageData;
-import dwt.graphics.ImageLoader;
+import dwt.internal.image.FileFormat;
 import dwt.graphics.PaletteData;
 import dwt.graphics.Point;
 import dwt.graphics.RGB;
+import dwt.dwthelper.ByteArrayOutputStream;
+import dwt.DWT;
+import dwt.dwthelper.utils;
 
-public final class WinBMPFileFormat : FileFormat {
+import tango.core.Exception;
+
+final class WinBMPFileFormat : FileFormat {
+
     static final int BMPFileHeaderSize = 14;
     static final int BMPHeaderFixedSize = 40;
     int importantColors;
-    Point pelsPerMeter = new Point(0, 0);
+    Point pelsPerMeter;
+
+public this(){
+    pelsPerMeter = new Point(0, 0);
+}
 
 /**
  * Compress numBytes bytes of image data from src, storing in dest
@@ -110,7 +115,7 @@
         dest[dp] = 0; dp++;
     }
     size += 2;
-    
+
     return size;
 }
 int compressRLE8Data(byte[] src, int srcOffset, int numBytes, byte[] dest, bool last) {
@@ -185,7 +190,7 @@
         dest[dp] = 0; dp++;
     }
     size += 2;
-    
+
     return size;
 }
 void decompressData(byte[] src, byte[] dest, int stride, int cmp) {
@@ -327,7 +332,7 @@
     }
     return 1;
 }
-bool isFileFormat(LEDataInputStream stream) {
+override bool isFileFormat(LEDataInputStream stream) {
     try {
         byte[] header = new byte[18];
         stream.read(header);
@@ -389,7 +394,7 @@
         DWT.error(DWT.ERROR_INVALID_IMAGE);
     return header;
 }
-ImageData[] loadFromByteStream() {
+override ImageData[] loadFromByteStream() {
     int[] fileHeader = loadFileHeader();
     byte[] infoHeader = new byte[BMPHeaderFixedSize];
     try {
@@ -417,7 +422,7 @@
     int yPelsPerMeter = (infoHeader[28] & 0xFF) | ((infoHeader[29] & 0xFF) << 8) | ((infoHeader[30] & 0xFF) << 16) | ((infoHeader[31] & 0xFF) << 24);
     this.pelsPerMeter = new Point(xPelsPerMeter, yPelsPerMeter);
     int type = (this.compression is 1 /*BMP_RLE8_COMPRESSION*/) || (this.compression is 2 /*BMP_RLE4_COMPRESSION*/) ? DWT.IMAGE_BMP_RLE : DWT.IMAGE_BMP;
-    return new ImageData[] {
+    return [
         ImageData.internal_new(
             width,
             height,
@@ -435,7 +440,7 @@
             0,
             0,
             0)
-    };
+    ];
 }
 PaletteData loadPalette(byte[] infoHeader) {
     int depth = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
@@ -506,14 +511,14 @@
 }
 /**
  * Unload the given image's data into the given byte stream
- * using the given compression strategy. 
+ * using the given compression strategy.
  * Answer the number of bytes written.
  */
-int unloadData(ImageData image, OutputStream out, int comp) {
+int unloadData(ImageData image, OutputStream ostr, int comp) {
     int totalSize = 0;
     try {
         if (comp is 0)
-            return unloadDataNoCompression(image, out);
+            return unloadDataNoCompression(image, ostr);
         int bpl = (image.width * image.depth + 7) / 8;
         int bmpBpl = (bpl + 3) / 4 * 4; // BMP pads scanlines to multiples of 4 bytes
         int imageBpl = image.bytesPerLine;
@@ -527,7 +532,7 @@
         for (int y = image.height - 1; y >= 0; y--) {
             int lineSize = compress(comp, data, srcOffset, bpl, buf, y is 0);
             if (buf2Offset + lineSize > buf2.length) {
-                out.write(buf2, 0, buf2Offset);
+                ostr.write(buf2, 0, buf2Offset);
                 buf2Offset = 0;
             }
             System.arraycopy(buf, 0, buf2, buf2Offset, lineSize);
@@ -536,7 +541,7 @@
             srcOffset -= imageBpl;
         }
         if (buf2Offset > 0)
-            out.write(buf2, 0, buf2Offset);
+            ostr.write(buf2, 0, buf2Offset);
     } catch (IOException e) {
         DWT.error(DWT.ERROR_IO, e);
     }
@@ -547,7 +552,7 @@
  * using no compression strategy.
  * Answer the number of bytes written.
  */
-int unloadDataNoCompression(ImageData image, OutputStream out) {
+int unloadDataNoCompression(ImageData image, OutputStream ostr) {
     int bmpBpl = 0;
     try {
         int bpl = (image.width * image.depth + 7) / 8;
@@ -570,7 +575,7 @@
                     bufOffset += bmpBpl;
                     dataIndex -= imageBpl;
                 }
-                out.write(buf, 0, bufOffset);
+                ostr.write(buf, 0, bufOffset);
             }
         } else {
             for (int y = 0; y < image.height; y += linesPerBuf) {
@@ -582,7 +587,7 @@
                     bufOffset += bmpBpl;
                     dataIndex -= imageBpl;
                 }
-                out.write(buf, 0, bufOffset);
+                ostr.write(buf, 0, bufOffset);
             }
         }
     } catch (IOException e) {
@@ -594,7 +599,7 @@
  * Unload a DeviceIndependentImage using Windows .BMP format into the given
  * byte stream.
  */
-void unloadIntoByteStream(ImageLoader loader) {
+override void unloadIntoByteStream(ImageLoader loader) {
     ImageData image = loader.data[0];
     byte[] rgbs;
     int numCols;
@@ -631,10 +636,10 @@
 
     // Prepare data. This is done first so we don't have to try to rewind
     // the stream and fill in the details later.
-    ByteArrayOutputStream out = new ByteArrayOutputStream();
-    unloadData(image, out, comp);
-    byte[] data = out.toByteArray();
-    
+    ByteArrayOutputStream ostr = new ByteArrayOutputStream();
+    unloadData(image, ostr, comp);
+    byte[] data = ostr.toByteArray();
+
     // Calculate file size
     fileHeader[1] = fileHeader[4] + data.length;
 
@@ -663,7 +668,7 @@
     } catch (IOException e) {
         DWT.error(DWT.ERROR_IO, e);
     }
-    
+
     // Unload palette
     if (numCols > 0) {
         try {
--- a/dwt/internal/image/WinICOFileFormat.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/WinICOFileFormat.d	Sun Sep 14 01:45:57 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,19 +7,21 @@
  *
  * 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.WinICOFileFormat;
 
-import java.io.IOException;
-
+import dwt.internal.image.FileFormat;
+import dwt.graphics.PaletteData;
+import dwt.internal.image.WinBMPFileFormat;
 import dwt.DWT;
-import dwt.graphics.ImageData;
-import dwt.graphics.ImageLoader;
-import dwt.graphics.PaletteData;
+import dwt.dwthelper.utils;
+
+import tango.core.Exception;
 
 public final class WinICOFileFormat : FileFormat {
-    
+
 byte[] bitInvertData(byte[] data, int startIndex, int endIndex) {
     // Destructively bit invert data in the given byte array.
     for (int i = startIndex; i < endIndex; i++) {
@@ -53,7 +55,7 @@
     int paletteSize = i.palette.colors !is null ? i.palette.colors.length * 4 : 0;
     return WinBMPFileFormat.BMPHeaderFixedSize + paletteSize + dataSize;
 }
-bool isFileFormat(LEDataInputStream stream) {
+override bool isFileFormat(LEDataInputStream stream) {
     try {
         byte[] header = new byte[4];
         stream.read(header);
@@ -74,6 +76,7 @@
         case 24:
         case 32:
             return i.palette.isDirect;
+        default:
     }
     return false;
 }
@@ -114,7 +117,7 @@
         DWT.error(DWT.ERROR_INVALID_IMAGE);
     return numIcons;
 }
-ImageData[] loadFromByteStream() {
+override ImageData[] loadFromByteStream() {
     int numIcons = loadFileHeader(inputStream);
     int[][] headers = loadIconHeaders(numIcons);
     ImageData[] icons = new ImageData[headers.length];
@@ -160,7 +163,7 @@
         0);
 }
 int[][] loadIconHeaders(int numIcons) {
-    int[][] headers = new int[numIcons][7];
+    int[][] headers = new int[][]( numIcons, 7 );
     try {
         for (int i = 0; i < numIcons; i++) {
             headers[i][0] = inputStream.read();
@@ -235,7 +238,7 @@
     } catch (IOException e) {
         DWT.error(DWT.ERROR_IO, e);
     }
-    
+
     byte[] rgbs = WinBMPFileFormat.paletteToBytes(icon.palette);
     try {
         outputStream.write(rgbs);
@@ -264,7 +267,7 @@
         DWT.error(DWT.ERROR_IO, e);
     }
 }
-void unloadIntoByteStream(ImageLoader loader) {
+override void unloadIntoByteStream(ImageLoader loader) {
     /* We do not currently support writing multi-image ico,
      * so we use the first image data in the loader's array. */
     ImageData image = loader.data[0];