Changeset 4688


Ignore:
Timestamp:
12/11/08 13:15:34 (11 years ago)
Author:
melissa
Message:

Fixed problems with displaying signed data.

Location:
trunk/components
Files:
3 edited

Legend:

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

    r4607 r4688  
    306306    boolean interleaved, int bpp, boolean little) 
    307307  { 
    308     return makeImage(data, w, h, c, interleaved, bpp, false, little); 
     308    return makeImage(data, w, h, c, interleaved, bpp, false, little, false); 
    309309  } 
    310310 
     
    326326   */ 
    327327  public static BufferedImage makeImage(byte[] data, int w, int h, int c, 
    328     boolean interleaved, int bpp, boolean fp, boolean little) 
     328    boolean interleaved, int bpp, boolean fp, boolean little, boolean signed) 
    329329  { 
    330330    Object pixels = DataTools.makeDataArray(data, 
    331       bpp % 3 == 0 ? bpp / 3 : bpp, fp, little); 
     331      bpp % 3 == 0 ? bpp / 3 : bpp, fp, little, signed); 
    332332 
    333333    if (pixels instanceof byte[]) { 
     
    362362    int w, int h, int bpp, boolean little) 
    363363  { 
    364     return makeImage(data, w, h, bpp, false, little); 
     364    return makeImage(data, w, h, bpp, false, little, false); 
    365365  } 
    366366 
     
    377377   */ 
    378378  public static BufferedImage makeImage(byte[][] data, 
    379     int w, int h, int bpp, boolean fp, boolean little) 
     379    int w, int h, int bpp, boolean fp, boolean little, boolean signed) 
    380380  { 
    381381    int c = data.length; 
     
    383383    for (int i=0; i<c; i++) { 
    384384      Object pixels = DataTools.makeDataArray(data[i], 
    385         bpp % 3 == 0 ? bpp / 3 : bpp, fp, little); 
     385        bpp % 3 == 0 ? bpp / 3 : bpp, fp, little, signed); 
    386386      if (pixels instanceof byte[]) { 
    387387        if (v == null) v = new byte[c][]; 
     
    560560    int pixelType = r.getPixelType(); 
    561561    if (pixelType == FormatTools.FLOAT) { 
    562       float[] f = 
    563         (float[]) DataTools.makeDataArray(buf, 4, true, r.isLittleEndian()); 
     562      float[] f = (float[]) DataTools.makeDataArray(buf, 4, true, 
     563        r.isLittleEndian(), false); 
    564564      if (r.isNormalized()) f = DataTools.normalizeFloats(f); 
    565565      return makeImage(f, w, h, r.getRGBChannelCount(), r.isInterleaved()); 
    566566    } 
    567567    else if (pixelType == FormatTools.DOUBLE) { 
    568       double[] d = 
    569         (double[]) DataTools.makeDataArray(buf, 8, true, r.isLittleEndian()); 
     568      double[] d = (double[]) DataTools.makeDataArray(buf, 8, true, 
     569        r.isLittleEndian(), false); 
    570570      if (r.isNormalized()) d = DataTools.normalizeDoubles(d); 
    571571      return makeImage(d, w, h, r.getRGBChannelCount(), r.isInterleaved()); 
     
    594594    BufferedImage b = makeImage(buf, w, h, 
    595595      r.isIndexed() ? 1 : r.getRGBChannelCount(), r.isInterleaved(), 
    596       FormatTools.getBytesPerPixel(r.getPixelType()), r.isLittleEndian()); 
     596      FormatTools.getBytesPerPixel(r.getPixelType()), false, 
     597      r.isLittleEndian(), signed); 
    597598 
    598599    if (r.isIndexed()) { 
  • trunk/components/common/src/loci/common/DataTools.java

    r4650 r4688  
    512512   * @param little Whether byte array is in little-endian order. 
    513513   */ 
     514  public static Object makeDataArray(byte[] b, int bpp, boolean fp, 
     515    boolean little) 
     516  { 
     517    return makeDataArray(b, bpp, fp, little, false); 
     518  } 
     519 
     520  /** 
     521   * Convert a byte array to the appropriate primitive type array. 
     522   * @param b Byte array to convert. 
     523   * @param bpp Denotes the number of bytes in the returned primitive type 
     524   *   (e.g. if bpp == 2, we should return an array of type short). 
     525   * @param fp If set and bpp == 4 or bpp == 8, then return floats or doubles. 
     526   * @param little Whether byte array is in little-endian order. 
     527   */ 
    514528  public static Object makeDataArray(byte[] b, 
    515     int bpp, boolean fp, boolean little) 
    516   { 
    517     if (bpp == 1) return b; 
     529    int bpp, boolean fp, boolean little, boolean signed) 
     530  { 
     531    if (bpp == 1) { 
     532      if (signed) b = makeSigned(b); 
     533      return b; 
     534    } 
    518535    else if (bpp == 2) { 
    519536      short[] s = new short[b.length / 2]; 
     
    521538        s[i] = bytesToShort(b, i*2, 2, little); 
    522539      } 
     540      if (signed) s = makeSigned(s); 
    523541      return s; 
    524542    } 
     
    535553        i[j] = bytesToInt(b, j*4, 4, little); 
    536554      } 
     555      if (signed) i = makeSigned(i); 
    537556      return i; 
    538557    } 
     
    823842  } 
    824843 
     844  // -- Signed data conversion -- 
     845 
     846  public static byte[] makeSigned(byte[] b) { 
     847    for (int i=0; i<b.length; i++) { 
     848      b[i] = (byte) (b[i] + 128); 
     849    } 
     850    return b; 
     851  } 
     852 
     853  public static short[] makeSigned(short[] s) { 
     854    for (int i=0; i<s.length; i++) { 
     855      s[i] = (short) (s[i] + 32768); 
     856    } 
     857    return s; 
     858  } 
     859 
     860  public static int[] makeSigned(int[] i) { 
     861    for (int j=0; j<i.length; j++) { 
     862      i[j] = (int) (i[j] + 2147483648L); 
     863    } 
     864    return i; 
     865  } 
     866 
    825867} 
  • trunk/components/loci-plugins/src/loci/plugins/Util.java

    r4607 r4688  
    150150    boolean isFloat = type == FormatTools.FLOAT || type == FormatTools.DOUBLE; 
    151151    boolean isLittle = r.isLittleEndian(); 
     152    boolean isSigned = type == FormatTools.INT8 || type == FormatTools.INT16 || 
     153      type == FormatTools.INT32; 
    152154 
    153155    IndexColorModel cm = null; 
     
    174176          System.arraycopy(tmp, 0, q, 0, q.length); 
    175177        } 
     178        if (isSigned) q = DataTools.makeSigned(q); 
    176179 
    177180        ip[i] = new ByteProcessor(w, h, q, null); 
     
    185188          System.arraycopy(tmp, 0, q, 0, q.length); 
    186189        } 
     190        if (isSigned) q = DataTools.makeSigned(q); 
    187191 
    188192        ip[i] = new ShortProcessor(w, h, q, model); 
Note: See TracChangeset for help on using the changeset viewer.