Changeset 7124


Ignore:
Timestamp:
10/24/10 17:01:31 (9 years ago)
Author:
melissa
Message:

Fixed scanline padding and various metadata parsing bugs.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2/components/bio-formats/src/loci/formats/in/ND2Handler.java

    r7102 r7124  
    387387    } 
    388388    else if (qName.endsWith("DyeName")) { 
    389       dyes.put(qName.substring(0, qName.indexOf("Channel")), value); 
     389      int channelIndex = qName.indexOf("Channel"); 
     390      if (channelIndex < 0) channelIndex = 0; 
     391      dyes.put(qName.substring(0, channelIndex), value); 
    390392    } 
    391393    else { 
     
    422424      pixelSizeZ = Double.parseDouble(sanitizeDouble(value)); 
    423425    } 
    424     else if (key.endsWith("Gain")) gain.add(new Double(sanitizeDouble(value))); 
     426    else if (key.endsWith("Gain")) { 
     427      value = sanitizeDouble(value); 
     428      if (!value.equals("")) { 
     429        gain.add(new Double(value)); 
     430      } 
     431    } 
    425432    else if (key.endsWith("dLampVoltage")) { 
    426433      voltage = new Double(sanitizeDouble(value)); 
     
    453460      if (magIndex >= 0) { 
    454461        String m = tokens[magIndex].substring(0, tokens[magIndex].indexOf("x")); 
    455         mag = new Double(sanitizeDouble(m)); 
     462        m = sanitizeDouble(m); 
     463        if (m.length() > 0) { 
     464          mag = new Double(m); 
     465        } 
    456466      } 
    457467      if (magIndex + 1 < tokens.length) immersion = tokens[magIndex + 1]; 
  • branches/4.2/components/bio-formats/src/loci/formats/in/NativeND2Reader.java

    r7100 r7124  
    203203    options.maxBytes = (int) maxFP; 
    204204 
    205     int scanlinePad = isJPEG ? 0 : getSizeX() % 2; 
     205    int scanlinePad = (isJPEG || !isLossless) ? 0 : getSizeX() % 2; 
    206206 
    207207    if (isJPEG || isLossless) { 
    208208      if (codec == null) codec = createCodec(isJPEG); 
    209209      byte[] t = codec.decompress(in, options); 
    210       byte[] pix = new byte[(buf.length / bpp) * pixel]; 
    211       int effectiveX = getSizeX() + scanlinePad; 
    212       for (int row=0; row<h; row++) { 
    213         int offset = (row + y) * effectiveX * pixel + x * pixel; 
    214         if (offset + w * pixel <= t.length) { 
    215           System.arraycopy(t, offset, pix, row * w * pixel, w * pixel); 
    216         } 
    217       } 
     210      copyPixels(x, y, w, h, bpp, scanlinePad, t, buf, split); 
    218211      t = null; 
    219  
    220       copyPixels(x, y, w, h, bpp, scanlinePad, pix, buf); 
    221212    } 
    222213    else if (split) { 
    223214      byte[] pix = new byte[(getSizeX() + scanlinePad) * getSizeY() * pixel]; 
    224215      in.read(pix); 
    225       copyPixels(x, y, w, h, bpp, scanlinePad, pix, buf); 
     216      copyPixels(x, y, w, h, bpp, scanlinePad, pix, buf, split); 
    226217      pix = null; 
    227218    } 
     
    10901081 
    10911082  private void copyPixels(int x, int y, int w, int h, int bpp, int scanlinePad, 
    1092     byte[] pix, byte[] buf) 
     1083    byte[] pix, byte[] buf, boolean split) 
    10931084    throws IOException 
    10941085  { 
    1095     pix = ImageTools.splitChannels(pix, lastChannel, getEffectiveSizeC(), bpp, 
    1096       false, true); 
     1086    if (split) { 
     1087      pix = ImageTools.splitChannels(pix, lastChannel, getEffectiveSizeC(), bpp, 
     1088        false, true); 
     1089    } 
    10971090    RandomAccessInputStream s = new RandomAccessInputStream(pix); 
    10981091    readPlane(s, x, y, w, h, scanlinePad, buf); 
  • trunk/components/bio-formats/src/loci/formats/in/ND2Handler.java

    r7055 r7124  
    387387    } 
    388388    else if (qName.endsWith("DyeName")) { 
    389       dyes.put(qName.substring(0, qName.indexOf("Channel")), value); 
     389      int channelIndex = qName.indexOf("Channel"); 
     390      if (channelIndex < 0) channelIndex = 0; 
     391      dyes.put(qName.substring(0, channelIndex), value); 
    390392    } 
    391393    else { 
     
    422424      pixelSizeZ = Double.parseDouble(sanitizeDouble(value)); 
    423425    } 
    424     else if (key.endsWith("Gain")) gain.add(new Double(sanitizeDouble(value))); 
     426    else if (key.endsWith("Gain")) { 
     427      value = sanitizeDouble(value); 
     428      if (!value.equals("")) { 
     429        gain.add(new Double(value)); 
     430      } 
     431    } 
    425432    else if (key.endsWith("dLampVoltage")) { 
    426433      voltage = new Double(sanitizeDouble(value)); 
     
    453460      if (magIndex >= 0) { 
    454461        String m = tokens[magIndex].substring(0, tokens[magIndex].indexOf("x")); 
    455         mag = new Double(sanitizeDouble(m)); 
     462        m = sanitizeDouble(m); 
     463        if (m.length() > 0) { 
     464          mag = new Double(m); 
     465        } 
    456466      } 
    457467      if (magIndex + 1 < tokens.length) immersion = tokens[magIndex + 1]; 
  • trunk/components/bio-formats/src/loci/formats/in/NativeND2Reader.java

    r7042 r7124  
    203203    options.maxBytes = (int) maxFP; 
    204204 
    205     int scanlinePad = isJPEG ? 0 : getSizeX() % 2; 
     205    int scanlinePad = (isJPEG || !isLossless) ? 0 : getSizeX() % 2; 
    206206 
    207207    if (isJPEG || isLossless) { 
    208208      if (codec == null) codec = createCodec(isJPEG); 
    209209      byte[] t = codec.decompress(in, options); 
    210       byte[] pix = new byte[(buf.length / bpp) * pixel]; 
    211       int effectiveX = getSizeX() + scanlinePad; 
    212       for (int row=0; row<h; row++) { 
    213         int offset = (row + y) * effectiveX * pixel + x * pixel; 
    214         if (offset + w * pixel <= t.length) { 
    215           System.arraycopy(t, offset, pix, row * w * pixel, w * pixel); 
    216         } 
    217       } 
     210      copyPixels(x, y, w, h, bpp, scanlinePad, t, buf, split); 
    218211      t = null; 
    219  
    220       copyPixels(x, y, w, h, bpp, scanlinePad, pix, buf); 
    221212    } 
    222213    else if (split) { 
    223214      byte[] pix = new byte[(getSizeX() + scanlinePad) * getSizeY() * pixel]; 
    224215      in.read(pix); 
    225       copyPixels(x, y, w, h, bpp, scanlinePad, pix, buf); 
     216      copyPixels(x, y, w, h, bpp, scanlinePad, pix, buf, split); 
    226217      pix = null; 
    227218    } 
     
    10901081 
    10911082  private void copyPixels(int x, int y, int w, int h, int bpp, int scanlinePad, 
    1092     byte[] pix, byte[] buf) 
     1083    byte[] pix, byte[] buf, boolean split) 
    10931084    throws IOException 
    10941085  { 
    1095     pix = ImageTools.splitChannels(pix, lastChannel, getEffectiveSizeC(), bpp, 
    1096       false, true); 
     1086    if (split) { 
     1087      pix = ImageTools.splitChannels(pix, lastChannel, getEffectiveSizeC(), bpp, 
     1088        false, true); 
     1089    } 
    10971090    RandomAccessInputStream s = new RandomAccessInputStream(pix); 
    10981091    readPlane(s, x, y, w, h, scanlinePad, buf); 
Note: See TracChangeset for help on using the changeset viewer.