internal static string GetMagicWord(PnmType ptype, PnmEncoding encoding) { if ((ptype == PnmType.Pgm) && (encoding == PnmEncoding.ASCIIEncoding)) { return("P2"); } if ((ptype != PnmType.Pgm) || (encoding != PnmEncoding.BinaryEncoding)) { if ((ptype == PnmType.Ppm) && (encoding == PnmEncoding.ASCIIEncoding)) { return("P3"); } if ((ptype == PnmType.Ppm) && (encoding == PnmEncoding.BinaryEncoding)) { return("P6"); } if ((ptype == PnmType.Pbm) && (encoding == PnmEncoding.ASCIIEncoding)) { return("P1"); } if ((ptype == PnmType.Pbm) && (encoding == PnmEncoding.BinaryEncoding)) { throw new Exception("PBM files are only written in ASCII encoding."); } } return("P5"); }
internal static string GetMaxPixel(PnmType ptype) { if (ptype == PnmType.Pbm) { return("-1"); } return("255"); }
internal static IPnmWriter GetIPNMWriter(PnmType ptype) { switch (ptype) { case PnmType.Pbm: return(new PbmWriter()); case PnmType.Pgm: return(new PgmWriter()); case PnmType.Ppm: return(new PpmWriter()); } return(null); }
public static void WritePnm(Stream fs, Image im, PnmEncoding encoding, PnmType ptype) { IPnmDataWriter iPNMDataWriter = PnmFactory.GetIPNMDataWriter(fs, encoding); if (iPNMDataWriter == null) { throw new Exception("Currently only Binary and ASCII encoding is supported"); } try { iPNMDataWriter.WriteLine(PnmFactory.GetMagicWord(ptype, encoding)); iPNMDataWriter.WriteLine(im.Width.ToString() + " " + im.Height.ToString()); if (ptype != PnmType.Pbm) { iPNMDataWriter.WriteLine("255"); } PnmFactory.GetIPNMWriter(ptype).WriteImageData(iPNMDataWriter, im); } catch { throw; } }
internal static string GetMaxPixel(PnmType ptype) { if (ptype == PnmType.Pbm) { return "-1"; } return "255"; }
internal static string GetMagicWord(PnmType ptype, PnmEncoding encoding) { if ((ptype == PnmType.Pgm) && (encoding == PnmEncoding.ASCIIEncoding)) { return "P2"; } if ((ptype != PnmType.Pgm) || (encoding != PnmEncoding.BinaryEncoding)) { if ((ptype == PnmType.Ppm) && (encoding == PnmEncoding.ASCIIEncoding)) { return "P3"; } if ((ptype == PnmType.Ppm) && (encoding == PnmEncoding.BinaryEncoding)) { return "P6"; } if ((ptype == PnmType.Pbm) && (encoding == PnmEncoding.ASCIIEncoding)) { return "P1"; } if ((ptype == PnmType.Pbm) && (encoding == PnmEncoding.BinaryEncoding)) { throw new Exception("PBM files are only written in ASCII encoding."); } } return "P5"; }
internal static IPnmWriter GetIPNMWriter(PnmType ptype) { switch (ptype) { case PnmType.Pbm: return new PbmWriter(); case PnmType.Pgm: return new PgmWriter(); case PnmType.Ppm: return new PpmWriter(); } return null; }
public static void WritePnm(Stream fs, Image im, PnmEncoding encoding, PnmType ptype) { IPnmDataWriter iPNMDataWriter = PnmFactory.GetIPNMDataWriter(fs, encoding); if (iPNMDataWriter == null) { throw new Exception("Currently only Binary and ASCII encoding is supported"); } try { iPNMDataWriter.WriteLine(PnmFactory.GetMagicWord(ptype, encoding)); iPNMDataWriter.WriteLine(im.Width.ToString() + " " + im.Height.ToString()); if (ptype != PnmType.Pbm) { iPNMDataWriter.WriteLine("255"); } PnmFactory.GetIPNMWriter(ptype).WriteImageData(iPNMDataWriter, im); } catch { throw; } }