Changeset 5735


Ignore:
Timestamp:
12/11/09 12:47:52 (10 years ago)
Author:
melissa
Message:

Convert signed data to unsigned data before writing PNG images.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/out/APNGWriter.java

    r5433 r5735  
    5959  private long numFramesPointer = 0; 
    6060  private int nextSequenceNumber; 
     61  private boolean littleEndian; 
    6162 
    6263  // -- Constructor -- 
     
    7778    MetadataRetrieve meta = getMetadataRetrieve(); 
    7879    MetadataTools.verifyMinimumPopulated(meta, series); 
    79     int bytesPerPixel = FormatTools.getBytesPerPixel( 
    80       FormatTools.pixelTypeFromString(meta.getPixelsPixelType(series, 0))); 
     80    int pixelType = 
     81      FormatTools.pixelTypeFromString(meta.getPixelsPixelType(series, 0)); 
     82    int bytesPerPixel = FormatTools.getBytesPerPixel(pixelType); 
     83    boolean signed = FormatTools.isSigned(pixelType); 
     84    littleEndian = !meta.getPixelsBigEndian(0, 0); 
    8185 
    8286    boolean indexed = getColorModel() instanceof IndexColorModel; 
     
    136140 
    137141      // write IDAT chunk 
    138       writePixels("IDAT", buf, width, height, nChannels); 
     142      writePixels("IDAT", buf, width, height, nChannels, signed); 
    139143      initialized = true; 
    140144    } 
     
    144148 
    145149      // write fdAT chunk 
    146       writePixels("fdAT", buf, width, height, nChannels); 
     150      writePixels("fdAT", buf, width, height, nChannels, signed); 
    147151    } 
    148152 
     
    251255 
    252256  private void writePixels(String chunk, byte[] stream, int width, int height, 
    253     int sizeC) throws IOException 
     257    int sizeC, boolean signed) throws IOException 
    254258  { 
    255259    ByteArrayOutputStream s = new ByteArrayOutputStream(); 
     
    269273      } 
    270274      else { 
     275        int max = (int) Math.pow(2, bytesPerPixel * 8 - 1); 
    271276        for (int col=0; col<width; col++) { 
    272277          for (int c=0; c<sizeC; c++) { 
    273             for (int q=0; q<bytesPerPixel; q++) { 
    274               rowBuf[(col * sizeC + c) * bytesPerPixel + q] = 
    275                 stream[c * planeSize + (i * width + col) * bytesPerPixel + q]; 
     278            int offset = c * planeSize + (i * width + col) * bytesPerPixel; 
     279            int pixel = DataTools.bytesToInt(stream, offset, bytesPerPixel, 
     280              littleEndian); 
     281            if (signed) { 
     282              if (pixel < max) pixel += max; 
     283              else pixel -= max; 
    276284            } 
     285            int output = (col * sizeC + c) * bytesPerPixel; 
     286            DataTools.unpackBytes(pixel, rowBuf, output, bytesPerPixel, false); 
    277287          } 
    278288        } 
Note: See TracChangeset for help on using the changeset viewer.