Changeset 3951


Ignore:
Timestamp:
04/18/08 12:50:43 (12 years ago)
Author:
melissa
Message:

Added utility methods for packing and swapping floats/doubles.
Fixed how min/max values are computed for float pixels.

Location:
trunk/loci/formats
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/DataTools.java

    r3930 r3951  
    330330 
    331331  /** 
     332   * Translates up to the first 4 bytes of a byte array to a float. 
     333   * If there are fewer than 4 bytes in the array, the MSBs are all 
     334   * assumed to be zero (regardless of endianness). 
     335   */ 
     336  public static float bytesToFloat(byte[] bytes, int off, int len, 
     337    boolean little) 
     338  { 
     339    return Float.intBitsToFloat(bytesToInt(bytes, off, len, little)); 
     340  } 
     341 
     342  /** 
    332343   * Translates up to the first len bytes of a byte array beyond the given 
    333344   * offset to a long. If there are fewer than 8 bytes in the array, 
     
    536547    return (long) (((long) swap((int) x) << 32) | 
    537548      ((long) swap((int) (x >> 32)) & 0xFFFFFFFFL)); 
     549  } 
     550 
     551  public static float swap(float x) { 
     552    return Float.intBitsToFloat(swap(Float.floatToIntBits(x))); 
     553  } 
     554 
     555  public static double swap(double x) { 
     556    return Double.longBitsToDouble(swap(Double.doubleToLongBits(x))); 
    538557  } 
    539558 
  • trunk/loci/formats/MinMaxCalculator.java

    r3812 r3951  
    101101    int series = getSeries(); 
    102102 
    103     // check that all planes have been reade 
     103    // check that all planes have been read 
    104104    if (minMaxDone == null || minMaxDone[series] < getImageCount()) { 
    105105      return null; 
     
    360360          if (bits >= threshold) bits -= 2*threshold; 
    361361        } 
    362         double v = fp ? Double.longBitsToDouble(bits) : (double) bits; 
     362        double v = (double) bits; 
     363        if (pixelType == FormatTools.FLOAT) { 
     364          v = Float.intBitsToFloat((int) bits); 
     365        } 
     366        else if (pixelType == FormatTools.DOUBLE) { 
     367          v = Double.longBitsToDouble(bits); 
     368        } 
    363369 
    364370        if (v > chanMax[series][cBase + c]) { 
Note: See TracChangeset for help on using the changeset viewer.