diff dwt/internal/image/JPEGFileFormat.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents 1801ddeb8f32
children fd9c62a2998e
line wrap: on
line diff
--- a/dwt/internal/image/JPEGFileFormat.d	Mon May 05 00:12:38 2008 +0200
+++ b/dwt/internal/image/JPEGFileFormat.d	Sat May 17 17:34:28 2008 +0200
@@ -25,10 +25,10 @@
 import dwt.internal.image.JPEGStartOfImage;
 import dwt.internal.image.JPEGDecoder;
 import dwt.internal.image.JPEGEndOfImage;
+import dwt.dwthelper.utils;
 
 import dwt.graphics.RGB;
 import dwt.graphics.PaletteData;
-import dwt.dwthelper.System;
 
 import tango.core.Exception;
 
@@ -150,39 +150,87 @@
     public static int[] CrRTable, CbBTable, CrGTable, CbGTable;
     public static int[] RYTable, GYTable, BYTable,
         RCbTable, GCbTable, BCbTable, RCrTable, GCrTable, BCrTable, NBitsTable;
+    //public static void static_this() {
+    static this() {
 
-    private static bool static_this_completed = false;
-    private static void static_this() {
-        if( static_this_completed ){
-            return;
+        RGB16 = [
+            new RGB(0,0,0),
+            new RGB(0x80,0,0),
+            new RGB(0,0x80,0),
+            new RGB(0x80,0x80,0),
+            new RGB(0,0,0x80),
+            new RGB(0x80,0,0x80),
+            new RGB(0,0x80,0x80),
+            new RGB(0xC0,0xC0,0xC0),
+            new RGB(0x80,0x80,0x80),
+            new RGB(0xFF,0,0),
+            new RGB(0,0xFF,0),
+            new RGB(0xFF,0xFF,0),
+            new RGB(0,0,0xFF),
+            new RGB(0xFF,0,0xFF),
+            new RGB(0,0xFF,0xFF),
+            new RGB(0xFF,0xFF,0xFF)
+        ];
+        int [] rYTable = new int[256];
+        int [] gYTable = new int[256];
+        int [] bYTable = new int[256];
+        int [] rCbTable = new int[256];
+        int [] gCbTable = new int[256];
+        int [] bCbTable = new int[256];
+        int [] rCrTable = new int[256];
+        int [] gCrTable = new int[256];
+        int [] bCrTable = new int[256];
+        for (int i = 0; i < 256; i++) {
+            rYTable[i] = i * 19595;
+            gYTable[i] = i * 38470;
+            bYTable[i] = i * 7471 + 32768;
+            rCbTable[i] = i * -11059;
+            gCbTable[i] = i * -21709;
+            bCbTable[i] = i * 32768 + 8388608;
+            gCrTable[i] = i * -27439;
+            bCrTable[i] = i * -5329;
         }
-        synchronized {
-            if( static_this_completed ){
-                return;
+        RYTable = rYTable;
+        GYTable = gYTable;
+        BYTable = bYTable;
+        RCbTable = rCbTable;
+        GCbTable = gCbTable;
+        BCbTable = bCbTable;
+        RCrTable = bCbTable;
+        GCrTable = gCrTable;
+        BCrTable = bCrTable;
+
+        /* Initialize YCbCr-RGB Tables */
+        int [] crRTable = new int[256];
+        int [] cbBTable = new int[256];
+        int [] crGTable = new int[256];
+        int [] cbGTable = new int[256];
+        for (int i = 0; i < 256; i++) {
+            int x2 = 2 * i - 255;
+            crRTable[i] = (45941 * x2 + 32768) >> 16;
+            cbBTable[i] = (58065 * x2 + 32768) >> 16;
+            crGTable[i] = -23401 * x2;
+            cbGTable[i] = -11277 * x2 + 32768;
+        }
+        CrRTable = crRTable;
+        CbBTable = cbBTable;
+        CrGTable = crGTable;
+        CbGTable = cbGTable;
+
+        /* Initialize BitCount Table */
+        int nBits = 1;
+        int power2 = 2;
+        int [] nBitsTable = new int[2048];
+        nBitsTable[0] = 0;
+        for (int i = 1; i < nBitsTable.length; i++) {
+            if (!(i < power2)) {
+                nBits++;
+                power2 *= 2;
             }
-            initialize();
-            RGB16 = [
-                new RGB(0,0,0),
-                new RGB(0x80,0,0),
-                new RGB(0,0x80,0),
-                new RGB(0x80,0x80,0),
-                new RGB(0,0,0x80),
-                new RGB(0x80,0,0x80),
-                new RGB(0,0x80,0x80),
-                new RGB(0xC0,0xC0,0xC0),
-                new RGB(0x80,0x80,0x80),
-                new RGB(0xFF,0,0),
-                new RGB(0,0xFF,0),
-                new RGB(0xFF,0xFF,0),
-                new RGB(0,0,0xFF),
-                new RGB(0xFF,0,0xFF),
-                new RGB(0,0xFF,0xFF),
-                new RGB(0xFF,0xFF,0xFF)
-            ];
-            static_this_completed = true;
+            nBitsTable[i] = nBits;
         }
+        NBitsTable = nBitsTable;
     }
-
 void compress(ImageData image, byte[] dataYComp, byte[] dataCbComp, byte[] dataCrComp) {
     int srcWidth = image.width;
     int srcHeight = image.height;
@@ -240,15 +288,15 @@
             int delta = componentWidth - compressedWidth;
             for (int yPos = 0; yPos < compressedHeight; yPos++) {
                 int dstOfs = ((yPos + 1) * componentWidth - delta);
-                int dataValue = imageComponent[dstOfs - 1] & 0xFF;
+                int dataValue = imageComponent[(dstOfs > 0) ? dstOfs - 1 : 0] & 0xFF;
                 for (int i = 0; i < delta; i++) {
                     imageComponent[dstOfs + i] = cast(byte)dataValue;
                 }
             }
         }
         if (compressedHeight < componentHeight) {
-            int srcOfs = (compressedHeight - 1) * componentWidth;
-            for (int yPos = compressedHeight; yPos <= componentHeight; yPos++) {
+            int srcOfs = (compressedHeight > 0) ? (compressedHeight - 1) * componentWidth : 1;
+            for (int yPos = (compressedHeight > 0) ? compressedHeight : 1; yPos <= componentHeight; yPos++) {
                 int dstOfs = (yPos - 1) * componentWidth;
                 System.arraycopy(imageComponent, srcOfs, imageComponent, dstOfs, componentWidth);
             }
@@ -1171,58 +1219,6 @@
     }
     restartInterval = dri.getRestartInterval();
 }
-static void initialize() {
-    initializeRGBYCbCrTables();
-    initializeYCbCrRGBTables();
-    initializeBitCountTable();
-}
-static void initializeBitCountTable() {
-    int nBits = 1;
-    int power2 = 2;
-    NBitsTable = new int[2048];
-    NBitsTable[0] = 0;
-    for (int i = 1; i < NBitsTable.length; i++) {
-        if (!(i < power2)) {
-            nBits++;
-            power2 *= 2;
-        }
-        NBitsTable[i] = nBits;
-    }
-}
-static void initializeRGBYCbCrTables() {
-    RYTable = new int[256];
-    GYTable = new int[256];
-    BYTable = new int[256];
-    RCbTable = new int[256];
-    GCbTable = new int[256];
-    BCbTable = new int[256];
-    RCrTable = BCbTable;
-    GCrTable = new int[256];
-    BCrTable = new int[256];
-    for (int i = 0; i < 256; i++) {
-        RYTable[i] = i * 19595;
-        GYTable[i] = i * 38470;
-        BYTable[i] = i * 7471 + 32768;
-        RCbTable[i] = i * -11059;
-        GCbTable[i] = i * -21709;
-        BCbTable[i] = i * 32768 + 8388608;
-        GCrTable[i] = i * -27439;
-        BCrTable[i] = i * -5329;
-    }
-}
-static void initializeYCbCrRGBTables() {
-    CrRTable = new int[256];
-    CbBTable = new int[256];
-    CrGTable = new int[256];
-    CbGTable = new int[256];
-    for (int i = 0; i < 256; i++) {
-        int x2 = 2 * i - 255;
-        CrRTable[i] = (45941 * x2 + 32768) >> 16;
-        CbBTable[i] = (58065 * x2 + 32768) >> 16;
-        CrGTable[i] = -23401 * x2;
-        CbGTable[i] = -11277 * x2 + 32768;
-    }
-}
 void inverseDCT(int[] dataUnit) {
     for (int row = 0; row < 8; row++) {
         int rIndex = row * DCTSIZE;