using System; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Drawing; using System.Windows.Forms; using System.Security.Cryptography; namespace J2000.Utils { class PGXReader { private static string ReadLine(BinaryReader br) { StringBuilder sb=new StringBuilder(); char c; while ((c=br.ReadChar())!='\n') { sb.Append(c); } return sb.ToString(); } public static Bitmap Read(string filename, out string hash) { FileStream f=new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReader br=new BinaryReader(f); Regex r=new Regex(@"[\s]+"); string[] head=r.Split(ReadLine(br)); Console.WriteLine(String.Join(",",head)); if (head[0]!="PG") throw new Exception("Not a PGX file"); bool bigendian=head[1]=="ML"; int prec=Math.Abs(int.Parse(head[2])); bool sgnd=int.Parse(head[2])<0; int w=int.Parse(head[3]); int h=int.Parse(head[4]); Console.WriteLine("prec="+prec+", sgnd="+sgnd+", w="+w+", h="+h); HashAlgorithm md5=new MD5CryptoServiceProvider(); CryptoStream cs=new CryptoStream(Stream.Null, md5, CryptoStreamMode.Write); BinaryWriter bw=new BinaryWriter(cs); Bitmap bmp=new Bitmap(w, h); for (int j=0; j