Browse Source

Fixed frame delay plus resize bug

Former-commit-id: 32ce81eb0e5d90d0b4f2a47e967dfed4c7ec3556
Former-commit-id: d243591041847d982488e17fecdc6e2c76d866b0
af/merge-core
James South 11 years ago
parent
commit
4b83b700c2
  1. 6
      src/ImageProcessor.Playground/Program.cs
  2. 1
      src/ImageProcessor.Playground/images/input/test-original.gif.REMOVED.git-id
  3. 7
      src/ImageProcessor/Imaging/Formats/FormatUtilities.cs
  4. 4
      src/ImageProcessor/Imaging/Formats/GifEncoder.cs
  5. 3
      src/ImageProcessor/Imaging/Formats/GifFrame.cs
  6. 2
      src/ImageProcessor/Imaging/Formats/GifInfo.cs
  7. 2
      src/ImageProcessor/Processors/Resize.cs

6
src/ImageProcessor.Playground/Program.cs

@ -66,7 +66,7 @@ namespace ImageProcessor.PlayGround
{
using (ImageFactory imageFactory = new ImageFactory(true))
{
Size size = new Size(200, 0);
Size size = new Size(270, 260);
ResizeLayer layer = new ResizeLayer(size, ResizeMode.Max, AnchorPosition.Center, false);
//ContentAwareResizeLayer layer = new ContentAwareResizeLayer(size)
@ -84,12 +84,12 @@ namespace ImageProcessor.PlayGround
//.Format(new PngFormat())
//.BackgroundColor(Color.Cyan)
//.ReplaceColor(Color.FromArgb(255, 1, 107, 165), Color.FromArgb(255, 1, 165, 13), 80)
//.Resize(layer)
.Resize(size)
//.DetectEdges(new SobelEdgeFilter(), false)
//.DetectEdges(new LaplacianOfGaussianEdgeFilter())
//.EntropyCrop()
//.Filter(MatrixFilters.Invert)
.Filter(MatrixFilters.Comic)
//.Filter(MatrixFilters.Comic)
//.Filter(MatrixFilters.HiSatch)
//.Pixelate(8)
//.GaussianSharpen(10)

1
src/ImageProcessor.Playground/images/input/test-original.gif.REMOVED.git-id

@ -0,0 +1 @@
782fb5ca5bb57601d2533c090a3c56bc2abd2ae0

7
src/ImageProcessor/Imaging/Formats/FormatUtilities.cs

@ -134,7 +134,7 @@ namespace ImageProcessor.Imaging.Formats
{
int frameCount = image.GetFrameCount(FrameDimension.Time);
int last = frameCount - 1;
int length = 0;
double length = 0;
List<GifFrame> gifFrames = new List<GifFrame>();
@ -145,8 +145,7 @@ namespace ImageProcessor.Imaging.Formats
{
// Convert each 4-byte chunk into an integer.
// GDI returns a single array with all delays, while Mono returns a different array for each frame.
int delay = BitConverter.ToInt32(times, (4 * i) % times.Length);
delay = delay * 10 < 20 ? 20 : delay * 10; // Minimum delay is 20 ms
TimeSpan delay = TimeSpan.FromMilliseconds(BitConverter.ToInt32(times, (4 * i) % times.Length) * 10);
// Find the frame
image.SelectActiveFrame(FrameDimension.Time, i);
@ -160,7 +159,7 @@ namespace ImageProcessor.Imaging.Formats
image.SelectActiveFrame(FrameDimension.Time, 0);
}
length += delay;
length += delay.TotalMilliseconds;
}
info.GifFrames = gifFrames;

4
src/ImageProcessor/Imaging/Formats/GifEncoder.cs

@ -211,7 +211,7 @@ namespace ImageProcessor.Imaging.Formats
this.WriteHeaderBlock(gifStream, frame.Image.Width, frame.Image.Height);
}
this.WriteGraphicControlBlock(gifStream, frame.Delay);
this.WriteGraphicControlBlock(gifStream, Convert.ToInt32(frame.Delay.TotalMilliseconds / 10F));
this.WriteImageBlock(gifStream, !this.isFirstImage, frame.X, frame.Y, frame.Image.Width, frame.Image.Height);
}
@ -351,7 +351,7 @@ namespace ImageProcessor.Imaging.Formats
this.WriteShort(GraphicControlExtensionBlockIdentifier); // Identifier
this.WriteByte(GraphicControlExtensionBlockSize); // Block Size
this.WriteByte(blockhead[3] & 0xf7 | 0x08); // Setting disposal flag
this.WriteShort(Convert.ToInt32(frameDelay / 10.0f)); // Setting frame delay
this.WriteShort(frameDelay); // Setting frame delay
this.WriteByte(blockhead[6]); // Transparent color index
this.WriteByte(0); // Terminator
}

3
src/ImageProcessor/Imaging/Formats/GifFrame.cs

@ -10,6 +10,7 @@
namespace ImageProcessor.Imaging.Formats
{
using System;
using System.Drawing;
/// <summary>
@ -25,7 +26,7 @@ namespace ImageProcessor.Imaging.Formats
/// <summary>
/// Gets or sets the delay in milliseconds.
/// </summary>
public int Delay { get; set; }
public TimeSpan Delay { get; set; }
/// <summary>
/// Gets or sets the x position of the frame.

2
src/ImageProcessor/Imaging/Formats/GifInfo.cs

@ -53,6 +53,6 @@ namespace ImageProcessor.Imaging.Formats
/// <summary>
/// Gets or sets the animation length in milliseconds.
/// </summary>
public int AnimationLength { get; set; }
public double AnimationLength { get; set; }
}
}

2
src/ImageProcessor/Processors/Resize.cs

@ -83,7 +83,7 @@ namespace ImageProcessor.Processors
int.TryParse(this.Settings["MaxWidth"], NumberStyles.Any, CultureInfo.InvariantCulture, out maxWidth);
int.TryParse(this.Settings["MaxHeight"], NumberStyles.Any, CultureInfo.InvariantCulture, out maxHeight);
maxSize.Width = maxHeight;
maxSize.Width = maxWidth;
maxSize.Height = maxHeight;
resizeLayer.MaxSize = maxSize;

Loading…
Cancel
Save