Show
Ignore:
Timestamp:
05/17/08 11:34:28 (8 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Update to SWT 3.4M7

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/internal/image/JPEGFileFormat.d

    r80 r213  
    2626import dwt.internal.image.JPEGDecoder; 
    2727import dwt.internal.image.JPEGEndOfImage; 
     28import dwt.dwthelper.utils; 
    2829 
    2930import dwt.graphics.RGB; 
    3031import dwt.graphics.PaletteData; 
    31 import dwt.dwthelper.System; 
    3232 
    3333import tango.core.Exception; 
     
    151151    public static int[] RYTable, GYTable, BYTable, 
    152152        RCbTable, GCbTable, BCbTable, RCrTable, GCrTable, BCrTable, NBitsTable; 
    153  
    154     private static bool static_this_completed = false; 
    155     private static void static_this() { 
    156         if( static_this_completed ){ 
    157             return; 
    158         } 
    159         synchronized { 
    160             if( static_this_completed ){ 
    161                 return; 
    162             } 
    163             initialize(); 
    164             RGB16 = [ 
    165                 new RGB(0,0,0), 
    166                 new RGB(0x80,0,0), 
    167                 new RGB(0,0x80,0), 
    168                 new RGB(0x80,0x80,0), 
    169                 new RGB(0,0,0x80), 
    170                 new RGB(0x80,0,0x80), 
    171                 new RGB(0,0x80,0x80), 
    172                 new RGB(0xC0,0xC0,0xC0), 
    173                 new RGB(0x80,0x80,0x80), 
    174                 new RGB(0xFF,0,0), 
    175                 new RGB(0,0xFF,0), 
    176                 new RGB(0xFF,0xFF,0), 
    177                 new RGB(0,0,0xFF), 
    178                 new RGB(0xFF,0,0xFF), 
    179                 new RGB(0,0xFF,0xFF), 
    180                 new RGB(0xFF,0xFF,0xFF) 
    181             ]; 
    182             static_this_completed = true; 
    183         } 
    184     } 
    185  
     153    //public static void static_this() { 
     154    static this() { 
     155 
     156        RGB16 = [ 
     157            new RGB(0,0,0), 
     158            new RGB(0x80,0,0), 
     159            new RGB(0,0x80,0), 
     160            new RGB(0x80,0x80,0), 
     161            new RGB(0,0,0x80), 
     162            new RGB(0x80,0,0x80), 
     163            new RGB(0,0x80,0x80), 
     164            new RGB(0xC0,0xC0,0xC0), 
     165            new RGB(0x80,0x80,0x80), 
     166            new RGB(0xFF,0,0), 
     167            new RGB(0,0xFF,0), 
     168            new RGB(0xFF,0xFF,0), 
     169            new RGB(0,0,0xFF), 
     170            new RGB(0xFF,0,0xFF), 
     171            new RGB(0,0xFF,0xFF), 
     172            new RGB(0xFF,0xFF,0xFF) 
     173        ]; 
     174        int [] rYTable = new int[256]; 
     175        int [] gYTable = new int[256]; 
     176        int [] bYTable = new int[256]; 
     177        int [] rCbTable = new int[256]; 
     178        int [] gCbTable = new int[256]; 
     179        int [] bCbTable = new int[256]; 
     180        int [] rCrTable = new int[256]; 
     181        int [] gCrTable = new int[256]; 
     182        int [] bCrTable = new int[256]; 
     183        for (int i = 0; i < 256; i++) { 
     184            rYTable[i] = i * 19595; 
     185            gYTable[i] = i * 38470; 
     186            bYTable[i] = i * 7471 + 32768; 
     187            rCbTable[i] = i * -11059; 
     188            gCbTable[i] = i * -21709; 
     189            bCbTable[i] = i * 32768 + 8388608; 
     190            gCrTable[i] = i * -27439; 
     191            bCrTable[i] = i * -5329; 
     192        } 
     193        RYTable = rYTable; 
     194        GYTable = gYTable; 
     195        BYTable = bYTable; 
     196        RCbTable = rCbTable; 
     197        GCbTable = gCbTable; 
     198        BCbTable = bCbTable; 
     199        RCrTable = bCbTable; 
     200        GCrTable = gCrTable; 
     201        BCrTable = bCrTable; 
     202 
     203        /* Initialize YCbCr-RGB Tables */ 
     204        int [] crRTable = new int[256]; 
     205        int [] cbBTable = new int[256]; 
     206        int [] crGTable = new int[256]; 
     207        int [] cbGTable = new int[256]; 
     208        for (int i = 0; i < 256; i++) { 
     209            int x2 = 2 * i - 255; 
     210            crRTable[i] = (45941 * x2 + 32768) >> 16; 
     211            cbBTable[i] = (58065 * x2 + 32768) >> 16; 
     212            crGTable[i] = -23401 * x2; 
     213            cbGTable[i] = -11277 * x2 + 32768; 
     214        } 
     215        CrRTable = crRTable; 
     216        CbBTable = cbBTable; 
     217        CrGTable = crGTable; 
     218        CbGTable = cbGTable; 
     219 
     220        /* Initialize BitCount Table */ 
     221        int nBits = 1; 
     222        int power2 = 2; 
     223        int [] nBitsTable = new int[2048]; 
     224        nBitsTable[0] = 0; 
     225        for (int i = 1; i < nBitsTable.length; i++) { 
     226            if (!(i < power2)) { 
     227                nBits++; 
     228                power2 *= 2; 
     229            } 
     230            nBitsTable[i] = nBits; 
     231        } 
     232        NBitsTable = nBitsTable; 
     233    } 
    186234void compress(ImageData image, byte[] dataYComp, byte[] dataCbComp, byte[] dataCrComp) { 
    187235    int srcWidth = image.width; 
     
    241289            for (int yPos = 0; yPos < compressedHeight; yPos++) { 
    242290                int dstOfs = ((yPos + 1) * componentWidth - delta); 
    243                 int dataValue = imageComponent[dstOfs - 1] & 0xFF; 
     291                int dataValue = imageComponent[(dstOfs > 0) ? dstOfs - 1 : 0] & 0xFF; 
    244292                for (int i = 0; i < delta; i++) { 
    245293                    imageComponent[dstOfs + i] = cast(byte)dataValue; 
     
    248296        } 
    249297        if (compressedHeight < componentHeight) { 
    250             int srcOfs = (compressedHeight - 1) * componentWidth
    251             for (int yPos = compressedHeight; yPos <= componentHeight; yPos++) { 
     298            int srcOfs = (compressedHeight > 0) ? (compressedHeight - 1) * componentWidth : 1
     299            for (int yPos = (compressedHeight > 0) ? compressedHeight : 1; yPos <= componentHeight; yPos++) { 
    252300                int dstOfs = (yPos - 1) * componentWidth; 
    253301                System.arraycopy(imageComponent, srcOfs, imageComponent, dstOfs, componentWidth); 
     
    11711219    } 
    11721220    restartInterval = dri.getRestartInterval(); 
    1173 } 
    1174 static void initialize() { 
    1175     initializeRGBYCbCrTables(); 
    1176     initializeYCbCrRGBTables(); 
    1177     initializeBitCountTable(); 
    1178 } 
    1179 static void initializeBitCountTable() { 
    1180     int nBits = 1; 
    1181     int power2 = 2; 
    1182     NBitsTable = new int[2048]; 
    1183     NBitsTable[0] = 0; 
    1184     for (int i = 1; i < NBitsTable.length; i++) { 
    1185         if (!(i < power2)) { 
    1186             nBits++; 
    1187             power2 *= 2; 
    1188         } 
    1189         NBitsTable[i] = nBits; 
    1190     } 
    1191 } 
    1192 static void initializeRGBYCbCrTables() { 
    1193     RYTable = new int[256]; 
    1194     GYTable = new int[256]; 
    1195     BYTable = new int[256]; 
    1196     RCbTable = new int[256]; 
    1197     GCbTable = new int[256]; 
    1198     BCbTable = new int[256]; 
    1199     RCrTable = BCbTable; 
    1200     GCrTable = new int[256]; 
    1201     BCrTable = new int[256]; 
    1202     for (int i = 0; i < 256; i++) { 
    1203         RYTable[i] = i * 19595; 
    1204         GYTable[i] = i * 38470; 
    1205         BYTable[i] = i * 7471 + 32768; 
    1206         RCbTable[i] = i * -11059; 
    1207         GCbTable[i] = i * -21709; 
    1208         BCbTable[i] = i * 32768 + 8388608; 
    1209         GCrTable[i] = i * -27439; 
    1210         BCrTable[i] = i * -5329; 
    1211     } 
    1212 } 
    1213 static void initializeYCbCrRGBTables() { 
    1214     CrRTable = new int[256]; 
    1215     CbBTable = new int[256]; 
    1216     CrGTable = new int[256]; 
    1217     CbGTable = new int[256]; 
    1218     for (int i = 0; i < 256; i++) { 
    1219         int x2 = 2 * i - 255; 
    1220         CrRTable[i] = (45941 * x2 + 32768) >> 16; 
    1221         CbBTable[i] = (58065 * x2 + 32768) >> 16; 
    1222         CrGTable[i] = -23401 * x2; 
    1223         CbGTable[i] = -11277 * x2 + 32768; 
    1224     } 
    12251221} 
    12261222void inverseDCT(int[] dataUnit) {