public static int [ ] [ ] loadPNMFile ( InputStream str ) throws IOException { BufferedInputStream stream = new BufferedInputStream ( str ) ; String type = tokenizeString ( stream ) ; if ( type . equals ( "P1" ) ) return loadPlainPBM ( stream ) ; else if ( type . equals ( "P2" ) ) return loadPlainPGM ( stream ) ; else if ( type . equals ( "P4" ) ) return loadRawPBM ( stream ) ; else if ( type . equals ( "P5" ) ) return loadRawPGM ( stream ) ; else throw new IOException ( "Not a viable PBM or PGM stream" ) ; }
Loads plain or raw PGM files or plain or raw PBM files and return the result as an int [ ] [ ] . The Y dimension is not flipped .