From 89b89db549760185d7f34d7b18a6e62d513be16d Mon Sep 17 00:00:00 2001 From: James South Date: Tue, 29 Apr 2014 16:24:24 +0100 Subject: [PATCH] Playing with output quality. Former-commit-id: 58e7dd2a60d44526cb7495af9b2545af709c5ada --- .../Extensions/ImageExtensions.cs | 6 ++-- src/ImageProcessor/ImageFactory.cs | 35 ++----------------- src/ImageProcessorConsole/Program.cs | 4 +-- .../images/input/120430.gif.REMOVED.git-id | 1 + .../images/output/120430.gif.REMOVED.git-id | 1 + 5 files changed, 8 insertions(+), 39 deletions(-) create mode 100644 src/ImageProcessorConsole/images/input/120430.gif.REMOVED.git-id create mode 100644 src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id diff --git a/src/ImageProcessor/Extensions/ImageExtensions.cs b/src/ImageProcessor/Extensions/ImageExtensions.cs index a2a967a61a..821143af5a 100644 --- a/src/ImageProcessor/Extensions/ImageExtensions.cs +++ b/src/ImageProcessor/Extensions/ImageExtensions.cs @@ -63,15 +63,13 @@ namespace ImageProcessor.Extensions int frameCount = image.GetFrameCount(frameDimension); int delay = 0; - int[] delays = new int[frameCount]; int index = 0; List gifFrames = new List(); for (int f = 0; f < frameCount; f++) { int thisDelay = BitConverter.ToInt32(image.GetPropertyItem(20736).Value, index); - int toAddDelay = thisDelay * 10 < 100 ? 100 : thisDelay * 10; // Minimum delay is 100 ms - delays[f] = thisDelay; + int toAddDelay = thisDelay * 10 < 20 ? 20 : thisDelay * 10; // Minimum delay is 20 ms // Find the frame image.SelectActiveFrame(frameDimension, f); @@ -81,7 +79,7 @@ namespace ImageProcessor.Extensions // TODO: Get positions. gifFrames.Add(new GifFrame { - Delay = thisDelay, + Delay = toAddDelay, Image = (Image)image.Clone() }); diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index ef403e9c92..f6dfa5e446 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -1036,52 +1036,21 @@ namespace ImageProcessor { using (GifEncoder encoder = new GifEncoder(new MemoryStream(4096), width, height, imageInfo.LoopCount)) { - int counter = 0; foreach (GifFrame frame in imageInfo.GifFrames) { this.Image = frame.Image; - frame.Image = new Bitmap(ColorQuantizer.Quantize(processor.Invoke(this), PixelFormat.Format8bppIndexed)); + //frame.Image = new Bitmap(ColorQuantizer.Quantize(processor.Invoke(this), PixelFormat.Format8bppIndexed)); //using (Image temp = new Bitmap(ColorQuantizer.Quantize(processor.Invoke(this), PixelFormat.Format8bppIndexed))) //{ - + frame.Image = new Bitmap(processor.Invoke(this)); encoder.AddFrame(frame); //frame.Image.Save(Path.Combine(resolvedPath, counter + ".gif"), ImageFormat.Gif); - counter++; } this.Image = encoder.Save(); - - } - //var stream = new MemoryStream(); - //using (GifEncoder2 encoder = new GifEncoder2(stream, width, height, imageInfo.LoopCount)) - //{ - // foreach (GifFrame frame in imageInfo.GifFrames) - // { - // this.Image = frame.Image; - - // using (Image temp = new Bitmap(ColorQuantizer.Quantize(processor.Invoke(this), PixelFormat.Format8bppIndexed))) - // { - // encoder.AddFrame(temp, frame.X, frame.Y, TimeSpan.FromMilliseconds(frame.Delay)); - // } - // } - - // stream.Position = 0; - // this.Image = Image.FromStream(stream); - - // string path = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath; - // // ReSharper disable once AssignNullToNotNullAttribute - // string resolvedPath = Path.Combine(Path.GetDirectoryName(path), "output"); - // DirectoryInfo di = new DirectoryInfo(resolvedPath); - // if (!di.Exists) - // { - // di.Create(); - // } - - // this.Image.Save(Path.Combine(resolvedPath, "test.gif"), ImageFormat.Gif); - //} } else { diff --git a/src/ImageProcessorConsole/Program.cs b/src/ImageProcessorConsole/Program.cs index c73615a61e..a858704999 100644 --- a/src/ImageProcessorConsole/Program.cs +++ b/src/ImageProcessorConsole/Program.cs @@ -18,7 +18,7 @@ namespace ImageProcessorConsole { string path = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath; // ReSharper disable once AssignNullToNotNullAttribute - string resolvedPath = Path.Combine(Path.GetDirectoryName(path), "images"); + string resolvedPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), @"..\..\images\input")); DirectoryInfo di = new DirectoryInfo(resolvedPath); if (!di.Exists) { @@ -43,7 +43,7 @@ namespace ImageProcessorConsole imageFactory.Load(inStream) .Constrain(size) .Format(format) - .Save(Path.Combine(Path.GetDirectoryName(path), "output", fileInfo.Name)); + .Save(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), @"..\..\images\output", fileInfo.Name))); } } } diff --git a/src/ImageProcessorConsole/images/input/120430.gif.REMOVED.git-id b/src/ImageProcessorConsole/images/input/120430.gif.REMOVED.git-id new file mode 100644 index 0000000000..e55299d032 --- /dev/null +++ b/src/ImageProcessorConsole/images/input/120430.gif.REMOVED.git-id @@ -0,0 +1 @@ +56ba9f614f44f7c905481f35e7609cb93e8fe98c \ No newline at end of file diff --git a/src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id b/src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id new file mode 100644 index 0000000000..54bec4704d --- /dev/null +++ b/src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id @@ -0,0 +1 @@ +5e0c47f9c0cfbba294a8ca4fa61358c2af6a45f2 \ No newline at end of file