public void ResultIsJpeg (string name)
			{
				string path = CreateFile (name, 48);
				IFilter filter = new JpegFilter ();
				FilterRequest req = new FilterRequest (path);
				filter.Convert (req);
				using (ImageFile img = new JpegFile (req.Current)) {
					Assert.IsTrue (img != null, "result is null");
					Assert.IsTrue (img is JpegFile, "result is not a jpg");
				}
				System.IO.File.Delete (path);
			}
            public void ResultIsJpeg(string name)
            {
                string        path   = CreateFile(name, 48);
                IFilter       filter = new JpegFilter();
                FilterRequest req    = new FilterRequest(path);

                filter.Convert(req);
                using (ImageFile img = new JpegFile(req.Current)) {
                    Assert.IsTrue(img != null, "result is null");
                    Assert.IsTrue(img is JpegFile, "result is not a jpg");
                }
                System.IO.File.Delete(path);
            }
        private static void ProcessFile(string inputFileName, string outputFileName, long jpegQuality = 100)
        {
            LinkedList <Tuple <string, byte[]> > jpegSegments;
            JpegFile jpegFile = new JpegFile();
            Dictionary <string, string> panoDict;

            byte[] extendedXMPURI       = Encoding.UTF8.GetBytes("http://ns.adobe.com/xmp/extension/");
            byte[] zeroByte             = { 0x0 };
            byte[] extendedXMPSignature = null;
            string extendXMP            = "";

            //            string inputJpeg = args[0];
            //            string outputJpeg = args[1];
            ExifReadWrite exif = new ExifReadWrite();


            using (var stream = File.OpenRead(inputFileName))
                jpegSegments = jpegFile.Parse(stream);

            bool xmpFound         = false;
            bool extendedXMPFound = false;

            foreach (var segment in jpegSegments)
            {
                //Console.WriteLine(segment.Item1);

                if (segment.Item1 == "EXIF")
                {
                    exif.ReadExifAPP1(segment.Item2);
                }

                if (xmpFound != true && segment.Item1 == "APP1")
                {
                    string start = Encoding.UTF8.GetString(segment.Item2, 0, 28);
                    if (start == "http://ns.adobe.com/xap/1.0/")
                    {
                        // XMP, extract the GPano if its there.
                        panoDict = jpegFile.ExtractGPano(Encoding.UTF8.GetString(segment.Item2, 29, segment.Item2.Length - 29));
                        string xmpMD5;
                        if (panoDict.TryGetValue("xmpNote:HasExtendedXMP", out xmpMD5))
                        {
                            extendedXMPSignature = extendedXMPURI.Concat(zeroByte).Concat(Encoding.UTF8.GetBytes(xmpMD5)).ToArray();
                            extendedXMPFound     = true;
                        }
                    }
                }

                if (extendedXMPFound == true && segment.Item1 == "APP1" && jpegFile.segmentCompare(extendedXMPSignature, segment.Item2))
                {
                    extendXMP += jpegFile.ProcessExtendedXMPSegemnt(segment.Item2, extendXMP.Length);
                }
            }

            var md5     = System.Security.Cryptography.MD5.Create();
            var md5hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(extendXMP));

            var sb = new StringBuilder();

            for (int i = 0; i < md5hash.Length; i++)
            {
                sb.Append(md5hash[i].ToString("x2"));
            }

            if (extendXMP.Length > 0)
            {
                var newJpeg = jpegFile.ProcessExtendedXMPXML(extendXMP);
                if (newJpeg != null)
                {
                    jpegFile.WriteCombineImage(inputFileName, outputFileName, newJpeg, exif, jpegQuality);
                }
            }
        }
        public bool Convert(FilterRequest req)
        {
            string source = req.Current.LocalPath;

            System.Uri dest_uri = req.TempUri(System.IO.Path.GetExtension(source));
            string     dest     = dest_uri.LocalPath;

            using (ImageFile img = ImageFile.Create(source)) {
                bool changed = false;

                if (img.Orientation != PixbufOrientation.TopLeft && img is JpegFile)
                {
                    JpegFile jimg = img as JpegFile;

                    if (img.Orientation == PixbufOrientation.RightTop)
                    {
                        JpegUtils.Transform(source,
                                            dest,
                                            JpegUtils.TransformType.Rotate90);
                        changed = true;
                    }
                    else if (img.Orientation == PixbufOrientation.LeftBottom)
                    {
                        JpegUtils.Transform(source,
                                            dest,
                                            JpegUtils.TransformType.Rotate270);
                        changed = true;
                    }
                    else if (img.Orientation == PixbufOrientation.BottomRight)
                    {
                        JpegUtils.Transform(source,
                                            dest,
                                            JpegUtils.TransformType.Rotate180);
                        changed = true;
                    }

                    int width, height;

                    jimg = ImageFile.Create(dest) as JpegFile;

                    PixbufUtils.GetSize(dest, out width, out height);

                    jimg.SetOrientation(PixbufOrientation.TopLeft);
                    jimg.SetDimensions(width, height);

                    Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(dest, 160, 120, true);
                    jimg.SetThumbnail(pixbuf);
                    pixbuf.Dispose();

                    jimg.SaveMetaData(dest);
                    jimg.Dispose();
                }

                if (changed)
                {
                    req.Current = dest_uri;
                }

                return(changed);
            }
        }