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

Ported dwt.events.*, dwt.graphics.GC, Region, dwt.internal.image.*
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sun, 14 Sep 2008 01:45:57 +0200
parents e831403a80a9
children d8635bb48c7c
line wrap: on
line diff
--- 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];
 }
 
 }