Browse Source

Playing with output quality.

Former-commit-id: 58e7dd2a60d44526cb7495af9b2545af709c5ada
af/merge-core
James South 12 years ago
parent
commit
89b89db549
  1. 6
      src/ImageProcessor/Extensions/ImageExtensions.cs
  2. 35
      src/ImageProcessor/ImageFactory.cs
  3. 4
      src/ImageProcessorConsole/Program.cs
  4. 1
      src/ImageProcessorConsole/images/input/120430.gif.REMOVED.git-id
  5. 1
      src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id

6
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<GifFrame> gifFrames = new List<GifFrame>();
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()
});

35
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
{

4
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)));
}
}
}

1
src/ImageProcessorConsole/images/input/120430.gif.REMOVED.git-id

@ -0,0 +1 @@
56ba9f614f44f7c905481f35e7609cb93e8fe98c

1
src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id

@ -0,0 +1 @@
5e0c47f9c0cfbba294a8ca4fa61358c2af6a45f2
Loading…
Cancel
Save