Changeset 5990


Ignore:
Timestamp:
03/04/10 10:50:37 (10 years ago)
Author:
melissa
Message:

Updated differencing/undifferencing logic to be more generic. See #466.

Location:
branches/cleanup/components/bio-formats/src/loci/formats
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/cleanup/components/bio-formats/src/loci/formats/gui/AWTTiffTools.java

    r5988 r5990  
    118118    if (ifd.getIFDValue(IFD.PHOTOMETRIC_INTERPRETATION) == null) 
    119119    { 
    120       PhotoInterp photometricInterpretation =  
     120      PhotoInterp photometricInterpretation = 
    121121        indexed ? PhotoInterp.RGB_PALETTE : nChannels == 1 ? 
    122122            PhotoInterp.BLACK_IS_ZERO : PhotoInterp.RGB; 
     
    197197    for (int i=0; i<stripsPerImage; i++) { 
    198198      strips[i] = stripBuf[i].toByteArray(); 
    199       TiffCompression.difference(strips[i], 
    200         bps, width, planarConfig, predictor); 
     199      TiffCompression.difference(strips[i], ifd); 
    201200      CodecOptions options = compression.getCompressionCodecOptions(ifd); 
    202201      strips[i] = compression.compress(strips[i], options); 
  • branches/cleanup/components/bio-formats/src/loci/formats/tiff/TiffCompression.java

    r5988 r5990  
    183183      int planarConfig = ifd.getPlanarConfiguration(); 
    184184 
     185      int bytes = ifd.getBytesPerSample()[0]; 
     186 
    185187      if (planarConfig == 2 || bitsPerSample[len - 1] == 0) len = 1; 
    186       if (bitsPerSample[0] <= 8) { 
    187         for (int b=0; b<input.length; b++) { 
    188           if (b / len % width == 0) continue; 
    189           input[b] += input[b - len]; 
    190         } 
    191       } 
    192       else if (bitsPerSample[0] <= 16) { 
    193         short[] s = (short[]) DataTools.makeDataArray(input, 2, false, little); 
    194         for (int b=0; b<s.length; b++) { 
    195           if (b / len % width == 0) continue; 
    196           s[b] += s[b - len]; 
    197         } 
    198         for (int i=0; i<s.length; i++) { 
    199           DataTools.unpackBytes(s[i], input, i*2, 2, little); 
    200         } 
     188      len *= bytes; 
     189 
     190      for (int b=0; b<input.length; b+=bytes) { 
     191        if (b / len % width == 0) continue; 
     192        int value = DataTools.bytesToInt(input, b, bytes, little); 
     193        value += DataTools.bytesToInt(input, b - len, bytes, little); 
     194        DataTools.unpackBytes(value, input, b, bytes, little); 
    201195      } 
    202196    } 
     
    207201 
    208202  // -- TiffCompression methods - compression -- 
    209    
     203 
    210204  /** 
    211205   * Creates a set of codec options for compression. 
     
    239233 
    240234  /** Performs in-place differencing according to the given predictor value. */ 
    241   public static void difference(byte[] input, int[] bitsPerSample, 
    242     long width, int planarConfig, int predictor) throws FormatException 
    243   { 
     235  public static void difference(byte[] input, IFD ifd) throws FormatException { 
     236    int predictor = ifd.getIFDIntValue(IFD.PREDICTOR, 1); 
    244237    if (predictor == 2) { 
    245238      LOGGER.debug("performing horizontal differencing"); 
    246       for (int b=input.length-1; b>=0; b--) { 
    247         if (b / bitsPerSample.length % width == 0) continue; 
    248         input[b] -= input[b - bitsPerSample.length]; 
     239      int[] bitsPerSample = ifd.getBitsPerSample(); 
     240      long width = ifd.getImageWidth(); 
     241      boolean little = ifd.isLittleEndian(); 
     242      int planarConfig = ifd.getPlanarConfiguration(); 
     243      int bytes = ifd.getBytesPerSample()[0]; 
     244      int len = bytes * (planarConfig == 2 ? 1 : bitsPerSample.length); 
     245 
     246      for (int b=input.length-bytes; b>=0; b-=bytes) { 
     247        if (b / len % width == 0) continue; 
     248        int value = DataTools.bytesToInt(input, b, bytes, little); 
     249        value -= DataTools.bytesToInt(input, b - len, bytes, little); 
     250        DataTools.unpackBytes(value, input, b, bytes, little); 
    249251      } 
    250252    } 
Note: See TracChangeset for help on using the changeset viewer.