From 2e5416ba8d2414ca097afbab4775990f7bde7738 Mon Sep 17 00:00:00 2001 From: JimBobSquarePants Date: Thu, 5 Oct 2017 14:00:19 +1100 Subject: [PATCH 1/4] Update EXIF on rotate. Fix #268 Since we don't know the updated rotation value and EXIF tags only cover certain angles the best fix is to remove the rotate tag. We also update height width if the canvas has been expanded. --- .../Processors/Transforms/RotateProcessor.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs index a7fb400ac..f057c8254 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -24,6 +25,11 @@ namespace SixLabors.ImageSharp.Processing.Processors /// private Matrix3x2 processMatrix; + /// + /// The final rotated angle. + /// + private int optimizedRotatedAngle; + /// /// Gets or sets the angle of processMatrix in degrees. /// @@ -87,6 +93,30 @@ namespace SixLabors.ImageSharp.Processing.Processors } } + /// + protected override void AfterImageApply(Image source, Rectangle sourceRectangle) + { + ExifProfile profile = source.MetaData.ExifProfile; + if (profile == null) + { + return; + } + + if (MathF.Abs(this.Angle) < Constants.Epsilon) + { + // No need to do anything so return. + return; + } + + profile.RemoveValue(ExifTag.Orientation); + + if (this.Expand && profile.GetValue(ExifTag.PixelXDimension) != null) + { + profile.SetValue(ExifTag.PixelXDimension, source.Width); + profile.SetValue(ExifTag.PixelYDimension, source.Height); + } + } + /// /// Rotates the images with an optimized method when the angle is 90, 180 or 270 degrees. /// From ff774968f361670179a78e48be2eaa7834b8070b Mon Sep 17 00:00:00 2001 From: JimBobSquarePants Date: Thu, 5 Oct 2017 14:03:27 +1100 Subject: [PATCH 2/4] Remove unused field --- .../Processing/Processors/Transforms/RotateProcessor.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs index f057c8254..86a0c7360 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs @@ -25,11 +25,6 @@ namespace SixLabors.ImageSharp.Processing.Processors /// private Matrix3x2 processMatrix; - /// - /// The final rotated angle. - /// - private int optimizedRotatedAngle; - /// /// Gets or sets the angle of processMatrix in degrees. /// From 9e3729b1527d5e2bdfa1e2b03a0a9c99987dd0bc Mon Sep 17 00:00:00 2001 From: JimBobSquarePants Date: Fri, 6 Oct 2017 11:34:16 +1100 Subject: [PATCH 3/4] Ensure colormap cache is cleared --- src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs | 1 + src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs | 1 + src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs index 49adce23b..8766f1042 100644 --- a/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs @@ -61,6 +61,7 @@ namespace SixLabors.ImageSharp.Quantizers this.colors = (byte)maxColors.Clamp(1, 255); this.octree = new Octree(this.GetBitsNeededForColorDepth(this.colors)); this.palette = null; + this.colorMap.Clear(); return base.Quantize(image, this.colors); } diff --git a/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs b/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs index ca11a042f..0b95c09a6 100644 --- a/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs @@ -58,6 +58,7 @@ namespace SixLabors.ImageSharp.Quantizers public override QuantizedImage Quantize(ImageFrame image, int maxColors) { Array.Resize(ref this.colors, maxColors.Clamp(1, 255)); + this.colorMap.Clear(); return base.Quantize(image, maxColors); } diff --git a/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs b/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs index 77c421468..8ab390f4e 100644 --- a/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs @@ -139,6 +139,7 @@ namespace SixLabors.ImageSharp.Quantizers this.colors = maxColors.Clamp(1, 255); this.palette = null; + this.colorMap.Clear(); try { From 3909313a87f774c0aa22ebb3e7742d302f0a3794 Mon Sep 17 00:00:00 2001 From: JimBobSquarePants Date: Fri, 6 Oct 2017 11:34:41 +1100 Subject: [PATCH 4/4] FS makes much smaller files --- src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs b/src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs index 7f58ff1bf..20ba2e637 100644 --- a/src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs +++ b/src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Quantizers.Base public bool Dither { get; set; } = true; /// - public IErrorDiffuser DitherType { get; set; } = new SierraLiteDiffuser(); + public IErrorDiffuser DitherType { get; set; } = new FloydSteinbergDiffuser(); /// public virtual QuantizedImage Quantize(ImageFrame image, int maxColors)