Changeset 7454


Ignore:
Timestamp:
12/23/10 11:50:42 (9 years ago)
Author:
melissa
Message:

Made PGM parsing more flexible, as required for #479.

File:
1 edited

Legend:

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

    r6881 r7454  
    6565    super("Portable Gray Map", "pgm"); 
    6666    domains = new String[] {FormatTools.GRAPHICS_DOMAIN}; 
     67    suffixNecessary = false; 
    6768  } 
    6869 
     
    7172  /* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */ 
    7273  public boolean isThisType(RandomAccessInputStream stream) throws IOException { 
    73     final int blockLen = 1; 
     74    final int blockLen = 2; 
    7475    if (!FormatTools.validStream(stream, blockLen, false)) return false; 
    75     return stream.read() == PGM_MAGIC_CHAR; 
     76    return stream.read() == PGM_MAGIC_CHAR && 
     77      Character.isDigit((char) stream.read()); 
    7678  } 
    7779 
     
    140142    isBlackAndWhite = magic.equals("P1") || magic.equals("P4"); 
    141143 
    142     String line = in.readLine().trim(); 
    143     while (line.startsWith("#") || line.length() == 0) line = in.readLine(); 
     144    String line = readNextLine(); 
    144145 
    145146    line = line.replaceAll("[^0-9]", " "); 
     
    149150 
    150151    if (!isBlackAndWhite) { 
    151       int max = Integer.parseInt(in.readLine().trim()); 
     152      int max = Integer.parseInt(readNextLine()); 
    152153      if (max > 255) core[0].pixelType = FormatTools.UINT16; 
    153154      else core[0].pixelType = FormatTools.UINT8; 
     
    174175  } 
    175176 
     177  // -- Helper methods -- 
     178 
     179  private String readNextLine() throws IOException { 
     180    String line = in.readLine().trim(); 
     181    while (line.startsWith("#") || line.length() == 0) { 
     182      line = in.readLine().trim(); 
     183    } 
     184    return line; 
     185  } 
     186 
    176187} 
Note: See TracChangeset for help on using the changeset viewer.