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/PngEncoder.d

    r2 r213  
    1 /******************************************************************************* 
     1/******************************************************************************* 
    22 * Copyright (c) 2000, 2006 IBM Corporation and others. 
    33 * All rights reserved. This program and the accompanying materials 
     
    1616import dwt.internal.image.PngDeflater; 
    1717import dwt.dwthelper.ByteArrayOutputStream; 
     18import dwt.dwthelper.OutputStream; 
    1819import dwt.DWT; 
    1920import dwt.graphics.ImageData; 
    2021import dwt.graphics.ImageLoader; 
    2122import dwt.graphics.RGB; 
     23import dwt.internal.Compatibility; 
    2224import dwt.internal.image.PngChunk; 
    2325 
     
    237239 
    238240    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); 
     241    OutputStream os = Compatibility.newDeflaterOutputStream(baos); 
     242    if (os is null) os = baos; 
    239243 
    240244    if (colorType is 3) { 
    241245 
     246        byte[] lineData = new byte[width]; 
     247 
     248        for (int y = 0; y < height; y++) { 
     249 
     250            int filter = 0; 
     251            os.write(filter); 
     252 
     253            data.getPixels(0, y, width, lineData, 0); 
     254 
     255            for (int x = 0; x < lineData.length; x++) { 
     256 
     257                os.write(lineData[x]); 
     258 
     259            } 
     260 
     261        } 
     262 
     263    } 
     264 
     265    else { 
     266 
    242267        int[] lineData = new int[width]; 
    243  
    244         for (int y = 0; y < height; y++) { 
    245  
    246             byte filter[] = [0]; 
    247             baos.write(filter, 0, 1); 
    248  
    249             data.getPixels(0, y, width, lineData, 0); 
    250  
    251             for (int x = 0; x < lineData.length; x++) { 
    252  
    253                 baos.write(cast(byte) lineData[x]); 
    254  
    255             } 
    256  
    257         } 
    258  
    259     } 
    260  
    261     else { 
    262  
    263         int[] lineData = new int[width]; 
    264         byte[] alphaData = new byte[width]; 
     268        byte[] alphaData = null; 
     269        if (colorType is 6) { 
     270            alphaData = new byte[width]; 
     271        } 
    265272 
    266273        int redMask = data.palette.redMask; 
     
    273280        for (int y = 0; y < height; y++) { 
    274281 
    275             byte filter[] = [0]
    276             baos.write(filter, 0, 1); 
     282            int filter = 0
     283            os.write(filter); 
    277284 
    278285            data.getPixels(0, y, width, lineData, 0); 
     
    293300                b = (blueShift < 0) ? b >>> -blueShift : b << blueShift; 
    294301 
    295                 byte pixels[] = [cast(byte) r, cast(byte) g, cast(byte) b]; 
    296                 baos.write(pixels, 0, 3); 
     302                os.write(r); 
     303                os.write(g); 
     304                os.write(b); 
    297305 
    298306                if (colorType is 6) { 
    299  
    300                     byte alpha[] = [alphaData[x]]; 
    301                     baos.write(alpha, 0, 1); 
    302  
     307                    os.write(alphaData[x]); 
    303308                } 
    304309 
     
    309314    } 
    310315 
    311     PngDeflater deflater = new PngDeflater(); 
    312     byte[] compressed = deflater.deflate(baos.toByteArray()); 
     316    os.flush(); 
     317    os.close(); 
     318 
     319    byte[] compressed = baos.toByteArray(); 
     320    if (os is baos) { 
     321        PngDeflater deflater = new PngDeflater(); 
     322        compressed = deflater.deflate(compressed); 
     323    } 
    313324 
    314325    writeChunk(TAG_IDAT, compressed);