diff --git a/src/ImageSharp.Drawing/Primitives/ShapePath.cs b/src/ImageSharp.Drawing/Primitives/ShapePath.cs index 7a8c9e895..a4fef66a6 100644 --- a/src/ImageSharp.Drawing/Primitives/ShapePath.cs +++ b/src/ImageSharp.Drawing/Primitives/ShapePath.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Processing.Drawing.Pens; +using SixLabors.ImageSharp.Processing; using SixLabors.Shapes; namespace SixLabors.ImageSharp.Primitives diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/BrushApplicator.cs similarity index 98% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs rename to src/ImageSharp.Drawing/Processing/BrushApplicator.cs index 7672681da..04e2d0b9d 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Processing/BrushApplicator.cs @@ -6,7 +6,7 @@ using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing { /// /// primitive that converts a point in to a color for discovering the fill color based on an implementation diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/Brushes.cs b/src/ImageSharp.Drawing/Processing/Brushes.cs similarity index 99% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/Brushes.cs rename to src/ImageSharp.Drawing/Processing/Brushes.cs index 141ca403b..c5e7a3e9f 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/Brushes.cs +++ b/src/ImageSharp.Drawing/Processing/Brushes.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing { /// /// A collection of methods for creating generic brushes. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/ColorStop{TPixel}.cs b/src/ImageSharp.Drawing/Processing/ColorStop{TPixel}.cs similarity index 86% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/ColorStop{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/ColorStop{TPixel}.cs index 298af5cb5..7fd0ba7cd 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/ColorStop{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/ColorStop{TPixel}.cs @@ -1,8 +1,11 @@ -using System.Diagnostics; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Diagnostics; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes +namespace SixLabors.ImageSharp.Processing { /// /// A struct that defines a single color stop. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs b/src/ImageSharp.Drawing/Processing/DrawBezierExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs rename to src/ImageSharp.Drawing/Processing/DrawBezierExtensions.cs index 72bd76fa6..782f5d4d7 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/DrawBezierExtensions.cs @@ -2,12 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the drawing of Bezier paths to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs b/src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs similarity index 98% rename from src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs rename to src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs index 83e1b90f5..7c9d7c280 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the drawing of images to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs b/src/ImageSharp.Drawing/Processing/DrawLineExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs rename to src/ImageSharp.Drawing/Processing/DrawLineExtensions.cs index 981a07e13..9084b30ef 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/DrawLineExtensions.cs @@ -2,12 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the drawing of lines to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs b/src/ImageSharp.Drawing/Processing/DrawPathCollectionExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs rename to src/ImageSharp.Drawing/Processing/DrawPathCollectionExtensions.cs index eca3805bd..0d3abf297 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/DrawPathCollectionExtensions.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the drawing of collections of polygon outlines to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs b/src/ImageSharp.Drawing/Processing/DrawPathExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs rename to src/ImageSharp.Drawing/Processing/DrawPathExtensions.cs index a15412a45..4dbe942f2 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/DrawPathExtensions.cs @@ -3,11 +3,9 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the drawing of polygon outlines to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs b/src/ImageSharp.Drawing/Processing/DrawPolygonExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs rename to src/ImageSharp.Drawing/Processing/DrawPolygonExtensions.cs index 9f8d74f00..4dcfe00aa 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/DrawPolygonExtensions.cs @@ -2,12 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the drawing of closed linear polygons to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs b/src/ImageSharp.Drawing/Processing/DrawRectangleExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs rename to src/ImageSharp.Drawing/Processing/DrawRectangleExtensions.cs index 1f4a38a27..918fb1e73 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/DrawRectangleExtensions.cs @@ -2,12 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the drawing of rectangles to the type. diff --git a/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs b/src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs similarity index 96% rename from src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs rename to src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs index a20d7f730..46061ce9b 100644 --- a/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs @@ -3,17 +3,15 @@ using SixLabors.Fonts; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Pens; -using SixLabors.ImageSharp.Processing.Text.Processors; +using SixLabors.ImageSharp.Processing.Processors.Text; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Text +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the drawing of text to the type. /// - public static partial class DrawTextExtensions + public static class DrawTextExtensions { /// /// Draws the text onto the the image filled via the brush. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/EllipticGradientBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/EllipticGradientBrush{TPixel}.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/EllipticGradientBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/EllipticGradientBrush{TPixel}.cs index 43f7fe04e..8af01564c 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/EllipticGradientBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/EllipticGradientBrush{TPixel}.cs @@ -1,9 +1,12 @@ -using System; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes +namespace SixLabors.ImageSharp.Processing { /// /// Gradient Brush with elliptic shape. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs b/src/ImageSharp.Drawing/Processing/FillPathBuilderExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs rename to src/ImageSharp.Drawing/Processing/FillPathBuilderExtensions.cs index 921209d2e..ff4de3ff8 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/FillPathBuilderExtensions.cs @@ -3,10 +3,9 @@ using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the filling of polygons with various brushes to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs b/src/ImageSharp.Drawing/Processing/FillPathCollectionExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs rename to src/ImageSharp.Drawing/Processing/FillPathCollectionExtensions.cs index 71474dceb..da2dd35b6 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/FillPathCollectionExtensions.cs @@ -2,10 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the filling of collections of polygon outlines to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs b/src/ImageSharp.Drawing/Processing/FillPathExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs rename to src/ImageSharp.Drawing/Processing/FillPathExtensions.cs index 4273fd8be..da1062111 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/FillPathExtensions.cs @@ -3,10 +3,9 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the filling of polygon outlines to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs b/src/ImageSharp.Drawing/Processing/FillPolygonExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs rename to src/ImageSharp.Drawing/Processing/FillPolygonExtensions.cs index 3b80dd0f4..970ca2264 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/FillPolygonExtensions.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the filling of closed linear polygons to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs b/src/ImageSharp.Drawing/Processing/FillRectangleExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs rename to src/ImageSharp.Drawing/Processing/FillRectangleExtensions.cs index ae0afc5d5..26bf214f7 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/FillRectangleExtensions.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the filling of rectangles to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs b/src/ImageSharp.Drawing/Processing/FillRegionExtensions.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs rename to src/ImageSharp.Drawing/Processing/FillRegionExtensions.cs index 997dba22e..e566d0323 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/FillRegionExtensions.cs @@ -3,10 +3,9 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Drawing; -namespace SixLabors.ImageSharp.Processing.Drawing +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the filling of regions with various brushes to the type. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/GradientBrushBase{TPixel}.cs b/src/ImageSharp.Drawing/Processing/GradientBrushBase{TPixel}.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/GradientBrushBase{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/GradientBrushBase{TPixel}.cs index d0a1ef1c2..a844457ac 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/GradientBrushBase{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/GradientBrushBase{TPixel}.cs @@ -1,11 +1,14 @@ -using System; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats.PixelBlenders; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes +namespace SixLabors.ImageSharp.Processing { /// /// Base class for Gradient brushes diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/GradientRepetitionMode.cs b/src/ImageSharp.Drawing/Processing/GradientRepetitionMode.cs similarity index 89% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/GradientRepetitionMode.cs rename to src/ImageSharp.Drawing/Processing/GradientRepetitionMode.cs index adbc26ed4..c156153be 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/GradientRepetitionMode.cs +++ b/src/ImageSharp.Drawing/Processing/GradientRepetitionMode.cs @@ -1,4 +1,7 @@ -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.Processing { /// /// Modes to repeat a gradient. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/IBrush.cs b/src/ImageSharp.Drawing/Processing/IBrush.cs similarity index 96% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/IBrush.cs rename to src/ImageSharp.Drawing/Processing/IBrush.cs index 93ecb7788..a3c94a1b5 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/IBrush.cs +++ b/src/ImageSharp.Drawing/Processing/IBrush.cs @@ -4,7 +4,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing { /// /// Brush represents a logical configuration of a brush which can be used to source pixel colors diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Pens/IPen.cs b/src/ImageSharp.Drawing/Processing/IPen.cs similarity index 89% rename from src/ImageSharp.Drawing/Processing/Drawing/Pens/IPen.cs rename to src/ImageSharp.Drawing/Processing/IPen.cs index 387165e20..6f63dcfd0 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Pens/IPen.cs +++ b/src/ImageSharp.Drawing/Processing/IPen.cs @@ -3,9 +3,8 @@ using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -namespace SixLabors.ImageSharp.Processing.Drawing.Pens +namespace SixLabors.ImageSharp.Processing { /// /// Interface representing a Pen diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/ImageBrush{TPixel}.cs similarity index 98% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/ImageBrush{TPixel}.cs index 779848856..7e24dbbe2 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/ImageBrush{TPixel}.cs @@ -7,7 +7,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing { /// /// Provides an implementation of an image brush for painting images within areas. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/LinearGradientBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/LinearGradientBrush{TPixel}.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/LinearGradientBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/LinearGradientBrush{TPixel}.cs index 09f816dd9..765bf5499 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/LinearGradientBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/LinearGradientBrush{TPixel}.cs @@ -1,9 +1,12 @@ -using System; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes +namespace SixLabors.ImageSharp.Processing { /// /// Provides an implementation of a brush for painting linear gradients within areas. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/PatternBrush{TPixel}.cs similarity index 99% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/PatternBrush{TPixel}.cs index 21f2066fb..30d78bc83 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/PatternBrush{TPixel}.cs @@ -9,7 +9,7 @@ using SixLabors.ImageSharp.Primitives; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing { /// /// Provides an implementation of a pattern brush for painting patterns. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Pens/Pens.cs b/src/ImageSharp.Drawing/Processing/Pens.cs similarity index 98% rename from src/ImageSharp.Drawing/Processing/Drawing/Pens/Pens.cs rename to src/ImageSharp.Drawing/Processing/Pens.cs index b1883e322..90253a3cb 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Pens/Pens.cs +++ b/src/ImageSharp.Drawing/Processing/Pens.cs @@ -2,9 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -namespace SixLabors.ImageSharp.Processing.Drawing.Pens +namespace SixLabors.ImageSharp.Processing { /// /// Contains a collection of common Pen styles diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Pens/Pen{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Pen{TPixel}.cs similarity index 84% rename from src/ImageSharp.Drawing/Processing/Drawing/Pens/Pen{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/Pen{TPixel}.cs index 1dd6b6616..26c21a0e5 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Pens/Pen{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Pen{TPixel}.cs @@ -3,9 +3,8 @@ using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -namespace SixLabors.ImageSharp.Processing.Drawing.Pens +namespace SixLabors.ImageSharp.Processing { /// /// Provides a pen that can apply a pattern to a line with a set brush and thickness @@ -25,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Pens private readonly float[] pattern; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The color. /// The width. @@ -36,7 +35,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Pens } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush. /// The width. @@ -49,7 +48,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Pens } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The color. /// The width. @@ -59,7 +58,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Pens } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush. /// The width. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs similarity index 98% rename from src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs rename to src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs index 506df3886..e4b2eadb4 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs @@ -5,11 +5,10 @@ using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Drawing { /// /// Combines two images together by blending the pixels. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs similarity index 96% rename from src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs rename to src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs index 4214041a7..595c94687 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs @@ -5,12 +5,11 @@ using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Drawing { /// /// Using the brush as a source of pixels colors blends the brush color with source. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs similarity index 97% rename from src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs rename to src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs index 1e968b97e..1cc954dd9 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs @@ -4,13 +4,11 @@ using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Utils; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Drawing { /// /// Using a brush and a shape fills shape with contents of brush the diff --git a/src/ImageSharp.Drawing/Processing/Text/Processors/DrawTextProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs similarity index 98% rename from src/ImageSharp.Drawing/Processing/Text/Processors/DrawTextProcessor.cs rename to src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs index 9327f9449..9f1158154 100644 --- a/src/ImageSharp.Drawing/Processing/Text/Processors/DrawTextProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs @@ -6,15 +6,12 @@ using System.Collections.Generic; using SixLabors.Fonts; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Pens; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Utils; using SixLabors.Memory; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Processing.Text.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Text { /// /// Using the brush as a source of pixels colors blends the brush color with source. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/RadialGradientBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/RadialGradientBrush{TPixel}.cs similarity index 96% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/RadialGradientBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/RadialGradientBrush{TPixel}.cs index 5c0d8051c..16380fc34 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/GradientBrushes/RadialGradientBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/RadialGradientBrush{TPixel}.cs @@ -1,9 +1,12 @@ -using System; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes +namespace SixLabors.ImageSharp.Processing { /// /// A Circular Gradient Brush, defined by center point and radius. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs similarity index 98% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs index a7da2cc5b..058b03d62 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs @@ -8,14 +8,14 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing { /// /// Provides an implementation of a brush that can recolor an image /// /// The pixel format. public class RecolorBrush : IBrush - where TPixel : struct, IPixel + where TPixel : struct, IPixel { /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs similarity index 98% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs index 791c307bf..8a2d47c6c 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs @@ -7,7 +7,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing { /// /// Provides an implementation of a solid brush for painting solid color areas. diff --git a/src/ImageSharp.Drawing/Processing/Text/TextGraphicsOptions.cs b/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs similarity index 99% rename from src/ImageSharp.Drawing/Processing/Text/TextGraphicsOptions.cs rename to src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs index aaa6dea56..dfad06768 100644 --- a/src/ImageSharp.Drawing/Processing/Text/TextGraphicsOptions.cs +++ b/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs @@ -4,7 +4,7 @@ using SixLabors.Fonts; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Text +namespace SixLabors.ImageSharp.Processing { /// /// Options for influencing the drawing functions. diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index ce5c6c118..66900079f 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -194,12 +194,7 @@ namespace SixLabors.ImageSharp.ColorSpaces [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { - if (obj is CieLab) - { - return this.Equals((CieLab)obj); - } - - return false; + return obj is CieLab other && this.Equals(other); } /// diff --git a/src/ImageSharp/Common/Constants.cs b/src/ImageSharp/Common/Constants.cs index 41f2bce24..b7cfddcb6 100644 --- a/src/ImageSharp/Common/Constants.cs +++ b/src/ImageSharp/Common/Constants.cs @@ -9,8 +9,13 @@ namespace SixLabors.ImageSharp internal static class Constants { /// - /// The epsilon for comparing floating point numbers. + /// The epsilon value for comparing floating point numbers. /// - public static readonly float Epsilon = 0.001f; + public static readonly float Epsilon = 0.001F; + + /// + /// The epsilon squared value for comparing floating point numbers. + /// + public static readonly float EpsilonSquared = Epsilon * Epsilon; } } diff --git a/src/ImageSharp/Common/Extensions/ListExtensions.cs b/src/ImageSharp/Common/Extensions/ListExtensions.cs deleted file mode 100644 index 2713896c0..000000000 --- a/src/ImageSharp/Common/Extensions/ListExtensions.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System.Collections.Generic; - -namespace SixLabors.ImageSharp.Common.Extensions -{ - /// - /// Encapsulates a series of time saving extension methods to the class. - /// - internal static class ListExtensions - { - /// - /// Inserts an item at the given index automatically expanding the capacity if required. - /// - /// The type of object within the list - /// The list - /// The index - /// The item to insert - public static void SafeInsert(this List list, int index, T item) - { - if (index >= list.Count) - { - list.Add(item); - } - else - { - list[index] = item; - } - } - - /// - /// Removes the last element from a list and returns that element. This method changes the length of the list. - /// - /// The type of object within the list - /// The list - /// The last element in the specified sequence. - public static T Pop(this List list) - { - int last = list.Count - 1; - T item = list[last]; - list.RemoveAt(last); - return item; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Common/Helpers/DebugGuard.cs b/src/ImageSharp/Common/Helpers/DebugGuard.cs index 6dcd0fd27..5a1d3a2e3 100644 --- a/src/ImageSharp/Common/Helpers/DebugGuard.cs +++ b/src/ImageSharp/Common/Helpers/DebugGuard.cs @@ -17,13 +17,14 @@ namespace SixLabors.ImageSharp /// Verifies, that the method parameter with specified object value is not null /// and throws an exception if it is found to be so. /// - /// The target object, which cannot be null. + /// The target object, which cannot be null. /// The name of the parameter that is to be checked. - /// is null + /// is null [Conditional("DEBUG")] - public static void NotNull(object target, string parameterName) + public static void NotNull(T value, string parameterName) + where T : class { - if (target == null) + if (value == null) { throw new ArgumentNullException(parameterName); } diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs index 011d7fdaa..d09079062 100644 --- a/src/ImageSharp/Common/Helpers/Guard.cs +++ b/src/ImageSharp/Common/Helpers/Guard.cs @@ -19,7 +19,8 @@ namespace SixLabors.ImageSharp /// The target object, which cannot be null. /// The name of the parameter that is to be checked. /// is null - public static void NotNull(object value, string parameterName) + public static void NotNull(T value, string parameterName) + where T : class { if (value == null) { diff --git a/src/ImageSharp/Common/Helpers/InliningOptions.cs b/src/ImageSharp/Common/Helpers/InliningOptions.cs new file mode 100644 index 000000000..e1d51da8d --- /dev/null +++ b/src/ImageSharp/Common/Helpers/InliningOptions.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +// Uncomment this for verbose profiler results: +// #define PROFILING +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp +{ + /// + /// Global inlining options. Helps temporarily disable inling for better profiler output. + /// + internal static class InliningOptions + { +#if PROFILING + public const MethodImplOptions ShortMethod = 0; +#else + public const MethodImplOptions ShortMethod = MethodImplOptions.AggressiveInlining; +#endif + public const MethodImplOptions ColdPath = MethodImplOptions.NoInlining; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Gif/GifColorTableMode.cs b/src/ImageSharp/Formats/Gif/GifColorTableMode.cs new file mode 100644 index 000000000..aa4192863 --- /dev/null +++ b/src/ImageSharp/Formats/Gif/GifColorTableMode.cs @@ -0,0 +1,21 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.Formats.Gif +{ + /// + /// Provides enumeration for the available Gif color table modes. + /// + public enum GifColorTableMode + { + /// + /// A single color table is calculated from the first frame and reused for subsequent frames. + /// + Global, + + /// + /// A unique color table is calculated for each frame. + /// + Local + } +} diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs index a07928b04..e8e28ccdd 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoder.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs @@ -5,7 +5,7 @@ using System.IO; using System.Text; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Quantization; namespace SixLabors.ImageSharp.Formats.Gif { @@ -30,6 +30,11 @@ namespace SixLabors.ImageSharp.Formats.Gif /// public IQuantizer Quantizer { get; set; } = new OctreeQuantizer(); + /// + /// Gets or sets the color table mode: Global or local. + /// + public GifColorTableMode ColorTableMode { get; set; } + /// public void Encode(Image image, Stream stream) where TPixel : struct, IPixel diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index f84b13f5f..e4737f3bc 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -9,7 +9,7 @@ using System.Runtime.InteropServices; using System.Text; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Quantization; using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Gif @@ -19,6 +19,9 @@ namespace SixLabors.ImageSharp.Formats.Gif /// internal sealed class GifEncoderCore { + /// + /// Used for allocating memory during procesing operations. + /// private readonly MemoryAllocator memoryAllocator; /// @@ -27,15 +30,20 @@ namespace SixLabors.ImageSharp.Formats.Gif private readonly byte[] buffer = new byte[20]; /// - /// Gets the text encoding used to write comments. + /// The text encoding used to write comments. /// private readonly Encoding textEncoding; /// - /// Gets or sets the quantizer used to generate the color palette. + /// The quantizer used to generate the color palette. /// private readonly IQuantizer quantizer; + /// + /// The color table mode: Global or local. + /// + private readonly GifColorTableMode colorTableMode; + /// /// A flag indicating whether to ingore the metadata when writing the image. /// @@ -56,6 +64,7 @@ namespace SixLabors.ImageSharp.Formats.Gif this.memoryAllocator = memoryAllocator; this.textEncoding = options.TextEncoding ?? GifConstants.DefaultEncoding; this.quantizer = options.Quantizer; + this.colorTableMode = options.ColorTableMode; this.ignoreMetadata = options.IgnoreMetadata; } @@ -72,28 +81,80 @@ namespace SixLabors.ImageSharp.Formats.Gif Guard.NotNull(stream, nameof(stream)); // Quantize the image returning a palette. - QuantizedFrame quantized = this.quantizer.CreateFrameQuantizer().QuantizeFrame(image.Frames.RootFrame); + QuantizedFrame quantized = + this.quantizer.CreateFrameQuantizer().QuantizeFrame(image.Frames.RootFrame); // Get the number of bits. this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length).Clamp(1, 8); - int index = this.GetTransparentIndex(quantized); - // Write the header. this.WriteHeader(stream); - // Write the LSD. We'll use local color tables for now. - this.WriteLogicalScreenDescriptor(image, stream, index); + // Write the LSD. + int index = this.GetTransparentIndex(quantized); + bool useGlobalTable = this.colorTableMode.Equals(GifColorTableMode.Global); + this.WriteLogicalScreenDescriptor(image, index, useGlobalTable, stream); + + if (useGlobalTable) + { + this.WriteColorTable(quantized, stream); + } - // Write the first frame. + // Write the comments. this.WriteComments(image.MetaData, stream); - // Write additional frames. + // Write application extension to allow additional frames. if (image.Frames.Count > 1) { this.WriteApplicationExtension(stream, image.MetaData.RepeatCount); } + if (useGlobalTable) + { + this.EncodeGlobal(image, quantized, index, stream); + } + else + { + this.EncodeLocal(image, quantized, stream); + } + + // Clean up. + quantized?.Dispose(); + quantized = null; + + // TODO: Write extension etc + stream.WriteByte(GifConstants.EndIntroducer); + } + + private void EncodeGlobal(Image image, QuantizedFrame quantized, int transparencyIndex, Stream stream) + where TPixel : struct, IPixel + { + var palleteQuantizer = new PaletteQuantizer(this.quantizer.Diffuser); + + for (int i = 0; i < image.Frames.Count; i++) + { + ImageFrame frame = image.Frames[i]; + + this.WriteGraphicalControlExtension(frame.MetaData, transparencyIndex, stream); + this.WriteImageDescriptor(frame, false, stream); + + if (i == 0) + { + this.WriteImageData(quantized, stream); + } + else + { + using (QuantizedFrame paletteQuantized = palleteQuantizer.CreateFrameQuantizer(() => quantized.Palette).QuantizeFrame(frame)) + { + this.WriteImageData(paletteQuantized, stream); + } + } + } + } + + private void EncodeLocal(Image image, QuantizedFrame quantized, Stream stream) + where TPixel : struct, IPixel + { foreach (ImageFrame frame in image.Frames) { if (quantized == null) @@ -101,16 +162,14 @@ namespace SixLabors.ImageSharp.Formats.Gif quantized = this.quantizer.CreateFrameQuantizer().QuantizeFrame(frame); } - this.WriteGraphicalControlExtension(frame.MetaData, stream, this.GetTransparentIndex(quantized)); - this.WriteImageDescriptor(frame, stream); + this.WriteGraphicalControlExtension(frame.MetaData, this.GetTransparentIndex(quantized), stream); + this.WriteImageDescriptor(frame, true, stream); this.WriteColorTable(quantized, stream); this.WriteImageData(quantized, stream); + quantized?.Dispose(); quantized = null; // So next frame can regenerate it } - - // TODO: Write extension etc - stream.WriteByte(GifConstants.EndIntroducer); } /// @@ -159,12 +218,13 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// The pixel format. /// The image to encode. - /// The stream to write to. /// The transparency index to set the default background index to. - private void WriteLogicalScreenDescriptor(Image image, Stream stream, int transparencyIndex) + /// Whether to use a global or local color table. + /// The stream to write to. + private void WriteLogicalScreenDescriptor(Image image, int transparencyIndex, bool useGlobalTable, Stream stream) where TPixel : struct, IPixel { - byte packedValue = GifLogicalScreenDescriptor.GetPackedValue(false, this.bitDepth - 1, false, this.bitDepth - 1); + byte packedValue = GifLogicalScreenDescriptor.GetPackedValue(useGlobalTable, this.bitDepth - 1, false, this.bitDepth - 1); var descriptor = new GifLogicalScreenDescriptor( width: (ushort)image.Width, @@ -243,9 +303,9 @@ namespace SixLabors.ImageSharp.Formats.Gif /// Writes the graphics control extension to the stream. /// /// The metadata of the image or frame. - /// The stream to write to. /// The index of the color in the color palette to make transparent. - private void WriteGraphicalControlExtension(ImageFrameMetaData metaData, Stream stream, int transparencyIndex) + /// The stream to write to. + private void WriteGraphicalControlExtension(ImageFrameMetaData metaData, int transparencyIndex, Stream stream) { byte packedValue = GifGraphicControlExtension.GetPackedValue( disposalMethod: metaData.DisposalMethod, @@ -253,8 +313,8 @@ namespace SixLabors.ImageSharp.Formats.Gif var extension = new GifGraphicControlExtension( packed: packedValue, - transparencyIndex: unchecked((byte)transparencyIndex), - delayTime: (ushort)metaData.FrameDelay); + delayTime: (ushort)metaData.FrameDelay, + transparencyIndex: unchecked((byte)transparencyIndex)); this.WriteExtension(extension, stream); } @@ -281,15 +341,16 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// The pixel format. /// The to be encoded. + /// Whether to use the global color table. /// The stream to write to. - private void WriteImageDescriptor(ImageFrame image, Stream stream) + private void WriteImageDescriptor(ImageFrame image, bool hasColorTable, Stream stream) where TPixel : struct, IPixel { byte packedValue = GifImageDescriptor.GetPackedValue( - localColorTableFlag: true, + localColorTableFlag: hasColorTable, interfaceFlag: false, sortFlag: false, - localColorTableSize: (byte)this.bitDepth); // Note: we subtract 1 from the colorTableSize writing + localColorTableSize: (byte)this.bitDepth); var descriptor = new GifImageDescriptor( left: 0, @@ -342,9 +403,9 @@ namespace SixLabors.ImageSharp.Formats.Gif private void WriteImageData(QuantizedFrame image, Stream stream) where TPixel : struct, IPixel { - using (var encoder = new LzwEncoder(this.memoryAllocator, image.Pixels, (byte)this.bitDepth)) + using (var encoder = new LzwEncoder(this.memoryAllocator, (byte)this.bitDepth)) { - encoder.Encode(stream); + encoder.Encode(image.GetPixelSpan(), stream); } } } diff --git a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs index 44dd19db6..bad6e0031 100644 --- a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs +++ b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System.Text; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Quantization; namespace SixLabors.ImageSharp.Formats.Gif { @@ -25,5 +25,10 @@ namespace SixLabors.ImageSharp.Formats.Gif /// Gets the quantizer used to generate the color palette. /// IQuantizer Quantizer { get; } + + /// + /// Gets the color table mode: Global or local. + /// + GifColorTableMode ColorTableMode { get; } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs index de9de5e15..347609a54 100644 --- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs @@ -58,11 +58,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// private const int MaxMaxCode = 1 << MaxBits; - /// - /// The working pixel array. - /// - private readonly byte[] pixelArray; - /// /// The initial code size. /// @@ -83,6 +78,11 @@ namespace SixLabors.ImageSharp.Formats.Gif /// private readonly byte[] accumulators = new byte[256]; + /// + /// For dynamic table sizing + /// + private readonly int hsize = HashSize; + /// /// The current position within the pixelArray. /// @@ -98,11 +98,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// private int maxCode; - /// - /// For dynamic table sizing - /// - private int hsize = HashSize; - /// /// First unused entry /// @@ -169,13 +164,10 @@ namespace SixLabors.ImageSharp.Formats.Gif /// Initializes a new instance of the class. /// /// The to use for buffer allocations. - /// The array of indexed pixels. /// The color depth in bits. - public LzwEncoder(MemoryAllocator memoryAllocator, byte[] indexedPixels, int colorDepth) + public LzwEncoder(MemoryAllocator memoryAllocator, int colorDepth) { - this.pixelArray = indexedPixels; this.initialCodeSize = Math.Max(2, colorDepth); - this.hashTable = memoryAllocator.Allocate(HashSize, true); this.codeTable = memoryAllocator.Allocate(HashSize, true); } @@ -183,8 +175,9 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// Encodes and compresses the indexed pixels to the stream. /// + /// The span of indexed pixels. /// The stream to write to. - public void Encode(Stream stream) + public void Encode(Span indexedPixels, Stream stream) { // Write "initial code size" byte stream.WriteByte((byte)this.initialCodeSize); @@ -192,7 +185,7 @@ namespace SixLabors.ImageSharp.Formats.Gif this.position = 0; // Compress and write the pixel data - this.Compress(this.initialCodeSize + 1, stream); + this.Compress(indexedPixels, this.initialCodeSize + 1, stream); // Write block terminator stream.WriteByte(GifConstants.Terminator); @@ -252,9 +245,10 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// Compress the packets to the stream. /// + /// The span of indexed pixels. /// The initial bits. /// The stream to write to. - private void Compress(int intialBits, Stream stream) + private void Compress(Span indexedPixels, int intialBits, Stream stream) { int fcode; int c; @@ -276,7 +270,7 @@ namespace SixLabors.ImageSharp.Formats.Gif this.accumulatorCount = 0; // clear packet - ent = this.NextPixel(); + ent = this.NextPixel(indexedPixels); // TODO: PERF: It looks likt hshift could be calculated once statically. hshift = 0; @@ -296,9 +290,9 @@ namespace SixLabors.ImageSharp.Formats.Gif ref int hashTableRef = ref MemoryMarshal.GetReference(this.hashTable.GetSpan()); ref int codeTableRef = ref MemoryMarshal.GetReference(this.codeTable.GetSpan()); - while (this.position < this.pixelArray.Length) + while (this.position < indexedPixels.Length) { - c = this.NextPixel(); + c = this.NextPixel(indexedPixels); fcode = (c << MaxBits) + ent; int i = (c << hshift) ^ ent /* = 0 */; @@ -373,13 +367,14 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// Reads the next pixel from the image. /// + /// The span of indexed pixels. /// /// The /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - private int NextPixel() + private int NextPixel(Span indexedPixels) { - return this.pixelArray[this.position++] & 0xff; + return indexedPixels[this.position++] & 0xFF; } /// diff --git a/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs b/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs new file mode 100644 index 000000000..c7f366660 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs @@ -0,0 +1,26 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp.Formats.Jpeg +{ + internal static class JpegThrowHelper + { + /// + /// Cold path optimization for throwing -s + /// + /// The error message for the exception + [MethodImpl(MethodImplOptions.NoInlining)] + public static void ThrowImageFormatException(string errorMessage) + { + throw new ImageFormatException(errorMessage); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static void ThrowBadHuffmanCode() + { + throw new ImageFormatException("Bad Huffman code."); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FastACTables.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FastACTables.cs new file mode 100644 index 000000000..6cb0d6dfe --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FastACTables.cs @@ -0,0 +1,96 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Runtime.CompilerServices; +using SixLabors.Memory; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// The collection of lookup tables used for fast AC entropy scan decoding. + /// + internal sealed class FastACTables : IDisposable + { + private Buffer2D tables; + + /// + /// Initializes a new instance of the class. + /// + /// The memory allocator used to allocate memory for image processing operations. + public FastACTables(MemoryAllocator memoryAllocator) + { + this.tables = memoryAllocator.AllocateClean2D(512, 4); + } + + /// + /// Gets the representing the table at the index in the collection. + /// + /// The table index. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ReadOnlySpan GetTableSpan(int index) + { + return this.tables.GetRowSpan(index); + } + + /// + /// Gets a reference to the first element of the AC table indexed by + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref short GetAcTableReference(PdfJsFrameComponent component) + { + return ref this.tables.GetRowSpan(component.ACHuffmanTableId)[0]; + } + + /// + /// Builds a lookup table for fast AC entropy scan decoding. + /// + /// The table index. + /// The collection of AC Huffman tables. + public void BuildACTableLut(int index, PdfJsHuffmanTables acHuffmanTables) + { + const int FastBits = ScanDecoder.FastBits; + Span fastAC = this.tables.GetRowSpan(index); + ref PdfJsHuffmanTable huffman = ref acHuffmanTables[index]; + + int i; + for (i = 0; i < (1 << FastBits); i++) + { + byte fast = huffman.Lookahead[i]; + fastAC[i] = 0; + if (fast < byte.MaxValue) + { + int rs = huffman.Values[fast]; + int run = (rs >> 4) & 15; + int magbits = rs & 15; + int len = huffman.Sizes[fast]; + + if (magbits > 0 && len + magbits <= FastBits) + { + // Magnitude code followed by receive_extend code + int k = ((i << len) & ((1 << FastBits) - 1)) >> (FastBits - magbits); + int m = 1 << (magbits - 1); + if (k < m) + { + k += (int)((~0U << magbits) + 1); + } + + // if the result is small enough, we can fit it in fastAC table + if (k >= -128 && k <= 127) + { + fastAC[i] = (short)((k * 256) + (run * 16) + (len + magbits)); + } + } + } + } + } + + /// + public void Dispose() + { + this.tables?.Dispose(); + this.tables = null; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedByteBuffer512.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedByteBuffer512.cs new file mode 100644 index 000000000..c509903c9 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedByteBuffer512.cs @@ -0,0 +1,24 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + [StructLayout(LayoutKind.Sequential)] + internal unsafe struct FixedByteBuffer512 + { + public fixed byte Data[1 << ScanDecoder.FastBits]; + + public byte this[int idx] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + ref byte self = ref Unsafe.As(ref this); + return Unsafe.Add(ref self, idx); + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer256.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer257.cs similarity index 84% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer256.cs rename to src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer257.cs index 2c16a918f..b304dbf8c 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer256.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer257.cs @@ -7,16 +7,16 @@ using System.Runtime.InteropServices; namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components { [StructLayout(LayoutKind.Sequential)] - internal unsafe struct FixedInt16Buffer256 + internal unsafe struct FixedInt16Buffer257 { - public fixed short Data[256]; + public fixed short Data[257]; public short this[int idx] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ref short self = ref Unsafe.As(ref this); + ref short self = ref Unsafe.As(ref this); return Unsafe.Add(ref self, idx); } } diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt64Buffer18.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt32Buffer18.cs similarity index 70% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt64Buffer18.cs rename to src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt32Buffer18.cs index 51381cb27..f8507ec47 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt64Buffer18.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt32Buffer18.cs @@ -7,16 +7,16 @@ using System.Runtime.InteropServices; namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components { [StructLayout(LayoutKind.Sequential)] - internal unsafe struct FixedInt64Buffer18 + internal unsafe struct FixedInt32Buffer18 { - public fixed long Data[18]; + public fixed int Data[18]; - public long this[int idx] + public int this[int idx] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ref long self = ref Unsafe.As(ref this); + ref int self = ref Unsafe.As(ref this); return Unsafe.Add(ref self, idx); } } diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer18.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedUInt32Buffer18.cs similarity index 70% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer18.cs rename to src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedUInt32Buffer18.cs index 20d4b7733..9b076d9da 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer18.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedUInt32Buffer18.cs @@ -7,16 +7,16 @@ using System.Runtime.InteropServices; namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components { [StructLayout(LayoutKind.Sequential)] - internal unsafe struct FixedInt16Buffer18 + internal unsafe struct FixedUInt32Buffer18 { - public fixed short Data[18]; + public fixed uint Data[18]; - public short this[int idx] + public uint this[int idx] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ref short self = ref Unsafe.As(ref this); + ref uint self = ref Unsafe.As(ref this); return Unsafe.Add(ref self, idx); } } diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs index eefe8b97e..7501b0d83 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs @@ -129,7 +129,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors); } - this.SpectralBlocks = this.memoryAllocator.Allocate2D(blocksPerColumnForMcu, blocksPerLineForMcu + 1, true); + this.SpectralBlocks = this.memoryAllocator.AllocateClean2D(blocksPerColumnForMcu, blocksPerLineForMcu + 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -144,5 +144,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components { return 64 * (((this.WidthInBlocks + 1) * row) + col); } + + // TODO: we need consistence in (row, col) VS (col, row) ordering + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref short GetBlockDataReference(int row, int col) + { + ref Block8x8 blockRef = ref this.GetBlockReference(col, row); + return ref Unsafe.As(ref blockRef); + } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs index 2789f0cc0..15ae56331 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs @@ -17,163 +17,114 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// /// Gets the max code array /// - public FixedInt64Buffer18 MaxCode; + public FixedUInt32Buffer18 MaxCode; /// /// Gets the value offset array /// - public FixedInt16Buffer18 ValOffset; + public FixedInt32Buffer18 ValOffset; /// /// Gets the huffman value array /// - public FixedByteBuffer256 HuffVal; + public FixedByteBuffer256 Values; /// /// Gets the lookahead array /// - public FixedInt16Buffer256 Lookahead; + public FixedByteBuffer512 Lookahead; + + /// + /// Gets the sizes array + /// + public FixedInt16Buffer257 Sizes; /// /// Initializes a new instance of the struct. /// /// The to use for buffer allocations. - /// The code lengths + /// The code lengths /// The huffman values - public PdfJsHuffmanTable(MemoryAllocator memoryAllocator, ReadOnlySpan lengths, ReadOnlySpan values) + public PdfJsHuffmanTable(MemoryAllocator memoryAllocator, ReadOnlySpan count, ReadOnlySpan values) { - const int length = 257; - using (IBuffer huffsize = memoryAllocator.Allocate(length)) - using (IBuffer huffcode = memoryAllocator.Allocate(length)) + const int Length = 257; + using (IBuffer huffcode = memoryAllocator.Allocate(Length)) { - ref short huffsizeRef = ref MemoryMarshal.GetReference(huffsize.GetSpan()); ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.GetSpan()); - GenerateSizeTable(lengths, ref huffsizeRef); - GenerateCodeTable(ref huffsizeRef, ref huffcodeRef, length); - this.GenerateDecoderTables(lengths, ref huffcodeRef); - this.GenerateLookaheadTables(lengths, values, ref huffcodeRef); - } - - fixed (byte* huffValRef = this.HuffVal.Data) - { - var huffValSpan = new Span(huffValRef, 256); - - values.CopyTo(huffValSpan); - } - } - - /// - /// Figure C.1: make table of Huffman code length for each symbol - /// - /// The code lengths - /// The huffman size span ref - private static void GenerateSizeTable(ReadOnlySpan lengths, ref short huffsizeRef) - { - short index = 0; - for (short l = 1; l <= 16; l++) - { - byte i = lengths[l]; - for (short j = 0; j < i; j++) - { - Unsafe.Add(ref huffsizeRef, index) = l; - index++; - } - } - - Unsafe.Add(ref huffsizeRef, index) = 0; - } - - /// - /// Figure C.2: generate the codes themselves - /// - /// The huffman size span ref - /// The huffman code span ref - /// The length of the huffsize span - private static void GenerateCodeTable(ref short huffsizeRef, ref short huffcodeRef, int length) - { - short k = 0; - short si = huffsizeRef; - short code = 0; - for (short i = 0; i < length; i++) - { - while (Unsafe.Add(ref huffsizeRef, k) == si) - { - Unsafe.Add(ref huffcodeRef, k) = code; - code++; - k++; - } - - code <<= 1; - si++; - } - } - - /// - /// Figure F.15: generate decoding tables for bit-sequential decoding - /// - /// The code lengths - /// The huffman code span ref - private void GenerateDecoderTables(ReadOnlySpan lengths, ref short huffcodeRef) - { - fixed (short* valOffsetRef = this.ValOffset.Data) - fixed (long* maxcodeRef = this.MaxCode.Data) - { - short bitcount = 0; - for (int i = 1; i <= 16; i++) + // Figure C.1: make table of Huffman code length for each symbol + fixed (short* sizesRef = this.Sizes.Data) { - if (lengths[i] != 0) + short x = 0; + for (short i = 1; i < 17; i++) { - // valOffsetRef[l] = huffcodeRef[] index of 1st symbol of code length i, minus the minimum code of length i - valOffsetRef[i] = (short)(bitcount - Unsafe.Add(ref huffcodeRef, bitcount)); - bitcount += lengths[i]; - maxcodeRef[i] = Unsafe.Add(ref huffcodeRef, bitcount - 1); // maximum code of length i - } - else - { - maxcodeRef[i] = -1; // -1 if no codes of this length + byte l = count[i]; + for (short j = 0; j < l; j++) + { + sizesRef[x] = i; + x++; + } } - } - valOffsetRef[17] = 0; - maxcodeRef[17] = 0xFFFFFL; - } - } + sizesRef[x] = 0; - /// - /// Generates lookup tables to speed up decoding - /// - /// The code lengths - /// The huffman value array - /// The huffman code span ref - private void GenerateLookaheadTables(ReadOnlySpan lengths, ReadOnlySpan huffval, ref short huffcodeRef) - { - // TODO: This generation code matches the libJpeg code but the lookahead table is not actually used yet. - // To use it we need to implement fast lookup path in PdfJsScanDecoder.DecodeHuffman - // This should yield much faster scan decoding as usually, more than 95% of the Huffman codes - // will be 8 or fewer bits long and can be handled without looping. - fixed (short* lookaheadRef = this.Lookahead.Data) - { - var lookaheadSpan = new Span(lookaheadRef, 256); + // Figure C.2: generate the codes themselves + int k = 0; + fixed (int* valOffsetRef = this.ValOffset.Data) + fixed (uint* maxcodeRef = this.MaxCode.Data) + { + uint code = 0; + int j; + for (j = 1; j < 17; j++) + { + // Compute delta to add to code to compute symbol id. + valOffsetRef[j] = (int)(k - code); + if (sizesRef[k] == j) + { + while (sizesRef[k] == j) + { + Unsafe.Add(ref huffcodeRef, k++) = (short)code++; + } + } + + // Figure F.15: generate decoding tables for bit-sequential decoding. + // Compute largest code + 1 for this size. preshifted as need later. + maxcodeRef[j] = code << (16 - j); + code <<= 1; + } - lookaheadSpan.Fill(2034); // 9 << 8; + maxcodeRef[j] = 0xFFFFFFFF; + } - int p = 0; - for (int l = 1; l <= 8; l++) - { - for (int i = 1; i <= lengths[l]; i++, p++) + // Generate non-spec lookup tables to speed up decoding. + fixed (byte* lookaheadRef = this.Lookahead.Data) { - // l = current code's length, p = its index in huffcode[] & huffval[]. - // Generate left-justified code followed by all possible bit sequences - int lookBits = Unsafe.Add(ref huffcodeRef, p) << (8 - l); - for (int ctr = 1 << (8 - l); ctr > 0; ctr--) + const int FastBits = ScanDecoder.FastBits; + var fast = new Span(lookaheadRef, 1 << FastBits); + fast.Fill(0xFF); // Flag for non-accelerated + + for (int i = 0; i < k; i++) { - lookaheadRef[lookBits] = (short)((l << 8) | huffval[p]); - lookBits++; + int s = sizesRef[i]; + if (s <= ScanDecoder.FastBits) + { + int c = Unsafe.Add(ref huffcodeRef, i) << (FastBits - s); + int m = 1 << (FastBits - s); + for (int j = 0; j < m; j++) + { + fast[c + j] = (byte)i; + } + } } } } } + + fixed (byte* huffValRef = this.Values.Data) + { + var huffValSpan = new Span(huffValRef, 256); + values.CopyTo(huffValSpan); + } } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs index 3a559bb86..5cbde2b88 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// Gets or sets the table at the given index. /// /// The index - /// The + /// The public ref PdfJsHuffmanTable this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs deleted file mode 100644 index c9f1c555d..000000000 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs +++ /dev/null @@ -1,866 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; - -#if DEBUG -using System.Diagnostics; -#endif -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats.Jpeg.Components; -using SixLabors.Memory; - -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components -{ - /// - /// Provides the means to decode a spectral scan - /// - internal struct PdfJsScanDecoder - { - private ZigZag dctZigZag; - - private byte[] markerBuffer; - - private int mcuToRead; - - private int mcusPerLine; - - private int mcu; - - private int bitsData; - - private int bitsCount; - - private int specStart; - - private int specEnd; - - private int eobrun; - - private int compIndex; - - private int successiveState; - - private int successiveACState; - - private int successiveACNextValue; - - private bool endOfStreamReached; - - private bool unexpectedMarkerReached; - - /// - /// Decodes the spectral scan - /// - /// The image frame - /// The input stream - /// The DC Huffman tables - /// The AC Huffman tables - /// The scan components - /// The component index within the array - /// The length of the components. Different to the array length - /// The reset interval - /// The spectral selection start - /// The spectral selection end - /// The successive approximation bit high end - /// The successive approximation bit low end - public void DecodeScan( - PdfJsFrame frame, - DoubleBufferedStreamReader stream, - PdfJsHuffmanTables dcHuffmanTables, - PdfJsHuffmanTables acHuffmanTables, - PdfJsFrameComponent[] components, - int componentIndex, - int componentsLength, - ushort resetInterval, - int spectralStart, - int spectralEnd, - int successivePrev, - int successive) - { - this.dctZigZag = ZigZag.CreateUnzigTable(); - this.markerBuffer = new byte[2]; - this.compIndex = componentIndex; - this.specStart = spectralStart; - this.specEnd = spectralEnd; - this.successiveState = successive; - this.endOfStreamReached = false; - this.unexpectedMarkerReached = false; - - bool progressive = frame.Progressive; - this.mcusPerLine = frame.McusPerLine; - - this.mcu = 0; - int mcuExpected; - if (componentsLength == 1) - { - mcuExpected = components[this.compIndex].WidthInBlocks * components[this.compIndex].HeightInBlocks; - } - else - { - mcuExpected = this.mcusPerLine * frame.McusPerColumn; - } - - while (this.mcu < mcuExpected) - { - // Reset interval stuff - this.mcuToRead = resetInterval != 0 ? Math.Min(mcuExpected - this.mcu, resetInterval) : mcuExpected; - for (int i = 0; i < components.Length; i++) - { - PdfJsFrameComponent c = components[i]; - c.DcPredictor = 0; - } - - this.eobrun = 0; - - if (!progressive) - { - this.DecodeScanBaseline(dcHuffmanTables, acHuffmanTables, components, componentsLength, stream); - } - else - { - bool isAc = this.specStart != 0; - bool isFirst = successivePrev == 0; - PdfJsHuffmanTables huffmanTables = isAc ? acHuffmanTables : dcHuffmanTables; - this.DecodeScanProgressive(huffmanTables, isAc, isFirst, components, componentsLength, stream); - } - - // Reset - // TODO: I do not understand why these values are reset? We should surely be tracking the bits across mcu's? - this.bitsCount = 0; - this.bitsData = 0; - this.unexpectedMarkerReached = false; - - // Some images include more scan blocks than expected, skip past those and - // attempt to find the next valid marker - PdfJsFileMarker fileMarker = PdfJsJpegDecoderCore.FindNextFileMarker(this.markerBuffer, stream); - byte marker = fileMarker.Marker; - - // RSTn - We've already read the bytes and altered the position so no need to skip - if (marker >= JpegConstants.Markers.RST0 && marker <= JpegConstants.Markers.RST7) - { - continue; - } - - if (!fileMarker.Invalid) - { - // We've found a valid marker. - // Rewind the stream to the position of the marker and break - stream.Position = fileMarker.Position; - break; - } - -#if DEBUG - Debug.WriteLine($"DecodeScan - Unexpected MCU data at {stream.Position}, next marker is: {fileMarker.Marker:X}"); -#endif - } - } - - private void DecodeScanBaseline( - PdfJsHuffmanTables dcHuffmanTables, - PdfJsHuffmanTables acHuffmanTables, - PdfJsFrameComponent[] components, - int componentsLength, - DoubleBufferedStreamReader stream) - { - if (componentsLength == 1) - { - PdfJsFrameComponent component = components[this.compIndex]; - ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan())); - ref PdfJsHuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId]; - ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId]; - - for (int n = 0; n < this.mcuToRead; n++) - { - if (this.endOfStreamReached || this.unexpectedMarkerReached) - { - continue; - } - - this.DecodeBlockBaseline(ref dcHuffmanTable, ref acHuffmanTable, component, ref blockDataRef, stream); - this.mcu++; - } - } - else - { - for (int n = 0; n < this.mcuToRead; n++) - { - for (int i = 0; i < componentsLength; i++) - { - PdfJsFrameComponent component = components[i]; - ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan())); - ref PdfJsHuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId]; - ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId]; - int h = component.HorizontalSamplingFactor; - int v = component.VerticalSamplingFactor; - - for (int j = 0; j < v; j++) - { - for (int k = 0; k < h; k++) - { - if (this.endOfStreamReached || this.unexpectedMarkerReached) - { - continue; - } - - this.DecodeMcuBaseline(ref dcHuffmanTable, ref acHuffmanTable, component, ref blockDataRef, j, k, stream); - } - } - } - - this.mcu++; - } - } - } - - private void DecodeScanProgressive( - PdfJsHuffmanTables huffmanTables, - bool isAC, - bool isFirst, - PdfJsFrameComponent[] components, - int componentsLength, - DoubleBufferedStreamReader stream) - { - if (componentsLength == 1) - { - PdfJsFrameComponent component = components[this.compIndex]; - ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan())); - ref PdfJsHuffmanTable huffmanTable = ref huffmanTables[isAC ? component.ACHuffmanTableId : component.DCHuffmanTableId]; - - for (int n = 0; n < this.mcuToRead; n++) - { - if (this.endOfStreamReached || this.unexpectedMarkerReached) - { - continue; - } - - if (isAC) - { - if (isFirst) - { - this.DecodeBlockACFirst(ref huffmanTable, component, ref blockDataRef, stream); - } - else - { - this.DecodeBlockACSuccessive(ref huffmanTable, component, ref blockDataRef, stream); - } - } - else - { - if (isFirst) - { - this.DecodeBlockDCFirst(ref huffmanTable, component, ref blockDataRef, stream); - } - else - { - this.DecodeBlockDCSuccessive(component, ref blockDataRef, stream); - } - } - - this.mcu++; - } - } - else - { - for (int n = 0; n < this.mcuToRead; n++) - { - for (int i = 0; i < componentsLength; i++) - { - PdfJsFrameComponent component = components[i]; - ref short blockDataRef = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(component.SpectralBlocks.GetSpan())); - ref PdfJsHuffmanTable huffmanTable = ref huffmanTables[isAC ? component.ACHuffmanTableId : component.DCHuffmanTableId]; - int h = component.HorizontalSamplingFactor; - int v = component.VerticalSamplingFactor; - - for (int j = 0; j < v; j++) - { - for (int k = 0; k < h; k++) - { - // No need to continue here. - if (this.endOfStreamReached || this.unexpectedMarkerReached) - { - break; - } - - if (isAC) - { - if (isFirst) - { - this.DecodeMcuACFirst(ref huffmanTable, component, ref blockDataRef, j, k, stream); - } - else - { - this.DecodeMcuACSuccessive(ref huffmanTable, component, ref blockDataRef, j, k, stream); - } - } - else - { - if (isFirst) - { - this.DecodeMcuDCFirst(ref huffmanTable, component, ref blockDataRef, j, k, stream); - } - else - { - this.DecodeMcuDCSuccessive(component, ref blockDataRef, j, k, stream); - } - } - } - } - } - - this.mcu++; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeBlockBaseline(ref PdfJsHuffmanTable dcHuffmanTable, ref PdfJsHuffmanTable acHuffmanTable, PdfJsFrameComponent component, ref short blockDataRef, DoubleBufferedStreamReader stream) - { - int blockRow = this.mcu / component.WidthInBlocks; - int blockCol = this.mcu % component.WidthInBlocks; - int offset = component.GetBlockBufferOffset(blockRow, blockCol); - this.DecodeBaseline(component, ref blockDataRef, offset, ref dcHuffmanTable, ref acHuffmanTable, stream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeMcuBaseline(ref PdfJsHuffmanTable dcHuffmanTable, ref PdfJsHuffmanTable acHuffmanTable, PdfJsFrameComponent component, ref short blockDataRef, int row, int col, DoubleBufferedStreamReader stream) - { - int mcuRow = this.mcu / this.mcusPerLine; - int mcuCol = this.mcu % this.mcusPerLine; - int blockRow = (mcuRow * component.VerticalSamplingFactor) + row; - int blockCol = (mcuCol * component.HorizontalSamplingFactor) + col; - int offset = component.GetBlockBufferOffset(blockRow, blockCol); - this.DecodeBaseline(component, ref blockDataRef, offset, ref dcHuffmanTable, ref acHuffmanTable, stream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeBlockDCFirst(ref PdfJsHuffmanTable dcHuffmanTable, PdfJsFrameComponent component, ref short blockDataRef, DoubleBufferedStreamReader stream) - { - int blockRow = this.mcu / component.WidthInBlocks; - int blockCol = this.mcu % component.WidthInBlocks; - int offset = component.GetBlockBufferOffset(blockRow, blockCol); - this.DecodeDCFirst(component, ref blockDataRef, offset, ref dcHuffmanTable, stream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeMcuDCFirst(ref PdfJsHuffmanTable dcHuffmanTable, PdfJsFrameComponent component, ref short blockDataRef, int row, int col, DoubleBufferedStreamReader stream) - { - int mcuRow = this.mcu / this.mcusPerLine; - int mcuCol = this.mcu % this.mcusPerLine; - int blockRow = (mcuRow * component.VerticalSamplingFactor) + row; - int blockCol = (mcuCol * component.HorizontalSamplingFactor) + col; - int offset = component.GetBlockBufferOffset(blockRow, blockCol); - this.DecodeDCFirst(component, ref blockDataRef, offset, ref dcHuffmanTable, stream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeBlockDCSuccessive(PdfJsFrameComponent component, ref short blockDataRef, DoubleBufferedStreamReader stream) - { - int blockRow = this.mcu / component.WidthInBlocks; - int blockCol = this.mcu % component.WidthInBlocks; - int offset = component.GetBlockBufferOffset(blockRow, blockCol); - this.DecodeDCSuccessive(component, ref blockDataRef, offset, stream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeMcuDCSuccessive(PdfJsFrameComponent component, ref short blockDataRef, int row, int col, DoubleBufferedStreamReader stream) - { - int mcuRow = this.mcu / this.mcusPerLine; - int mcuCol = this.mcu % this.mcusPerLine; - int blockRow = (mcuRow * component.VerticalSamplingFactor) + row; - int blockCol = (mcuCol * component.HorizontalSamplingFactor) + col; - int offset = component.GetBlockBufferOffset(blockRow, blockCol); - this.DecodeDCSuccessive(component, ref blockDataRef, offset, stream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeBlockACFirst(ref PdfJsHuffmanTable acHuffmanTable, PdfJsFrameComponent component, ref short blockDataRef, DoubleBufferedStreamReader stream) - { - int blockRow = this.mcu / component.WidthInBlocks; - int blockCol = this.mcu % component.WidthInBlocks; - int offset = component.GetBlockBufferOffset(blockRow, blockCol); - this.DecodeACFirst(ref blockDataRef, offset, ref acHuffmanTable, stream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeMcuACFirst(ref PdfJsHuffmanTable acHuffmanTable, PdfJsFrameComponent component, ref short blockDataRef, int row, int col, DoubleBufferedStreamReader stream) - { - int mcuRow = this.mcu / this.mcusPerLine; - int mcuCol = this.mcu % this.mcusPerLine; - int blockRow = (mcuRow * component.VerticalSamplingFactor) + row; - int blockCol = (mcuCol * component.HorizontalSamplingFactor) + col; - int offset = component.GetBlockBufferOffset(blockRow, blockCol); - this.DecodeACFirst(ref blockDataRef, offset, ref acHuffmanTable, stream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeBlockACSuccessive(ref PdfJsHuffmanTable acHuffmanTable, PdfJsFrameComponent component, ref short blockDataRef, DoubleBufferedStreamReader stream) - { - int blockRow = this.mcu / component.WidthInBlocks; - int blockCol = this.mcu % component.WidthInBlocks; - int offset = component.GetBlockBufferOffset(blockRow, blockCol); - this.DecodeACSuccessive(ref blockDataRef, offset, ref acHuffmanTable, stream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeMcuACSuccessive(ref PdfJsHuffmanTable acHuffmanTable, PdfJsFrameComponent component, ref short blockDataRef, int row, int col, DoubleBufferedStreamReader stream) - { - int mcuRow = this.mcu / this.mcusPerLine; - int mcuCol = this.mcu % this.mcusPerLine; - int blockRow = (mcuRow * component.VerticalSamplingFactor) + row; - int blockCol = (mcuCol * component.HorizontalSamplingFactor) + col; - int offset = component.GetBlockBufferOffset(blockRow, blockCol); - this.DecodeACSuccessive(ref blockDataRef, offset, ref acHuffmanTable, stream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool TryReadBit(DoubleBufferedStreamReader stream, out int bit) - { - if (this.bitsCount == 0) - { - if (!this.TryFillBits(stream)) - { - bit = 0; - return false; - } - } - - this.bitsCount--; - bit = (this.bitsData >> this.bitsCount) & 1; - return true; - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private bool TryFillBits(DoubleBufferedStreamReader stream) - { - // TODO: Read more then 1 byte at a time. - // In LibJpegTurbo this is be 25 bits (32-7) but I cannot get this to work - // for some images, I'm assuming because I am crossing MCU boundaries and not maintining the correct buffer state. - const int MinGetBits = 7; - - if (!this.unexpectedMarkerReached) - { - // Attempt to load to the minimum bit count. - while (this.bitsCount < MinGetBits) - { - int c = stream.ReadByte(); - - switch (c) - { - case -0x1: - - // We've encountered the end of the file stream which means there's no EOI marker in the image. - this.endOfStreamReached = true; - return false; - - case JpegConstants.Markers.XFF: - int nextByte = stream.ReadByte(); - - if (nextByte == -0x1) - { - this.endOfStreamReached = true; - return false; - } - - if (nextByte != 0) - { -#if DEBUG - Debug.WriteLine($"DecodeScan - Unexpected marker {(c << 8) | nextByte:X} at {stream.Position}"); -#endif - - // We've encountered an unexpected marker. Reverse the stream and exit. - this.unexpectedMarkerReached = true; - stream.Position -= 2; - - // TODO: double check we need this. - // Fill buffer with zero bits. - if (this.bitsCount == 0) - { - this.bitsData <<= MinGetBits; - this.bitsCount = MinGetBits; - } - - return true; - } - - break; - } - - // OK, load the next byte into bitsData - this.bitsData = (this.bitsData << 8) | c; - this.bitsCount += 8; - } - } - - return true; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private int PeekBits(int count) - { - return this.bitsData >> (this.bitsCount - count) & ((1 << count) - 1); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DropBits(int count) - { - this.bitsCount -= count; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool TryDecodeHuffman(ref PdfJsHuffmanTable tree, DoubleBufferedStreamReader stream, out short value) - { - value = -1; - - // TODO: Implement fast Huffman decoding. - // In LibJpegTurbo a minimum of 25 bits (32-7) is collected from the stream - // Then a LUT is used to avoid the loop when decoding the Huffman value. - // using 3 methods: FillBits, PeekBits, and DropBits. - // The LUT has been ported from LibJpegTurbo as has this code but it doesn't work. - // this.TryFillBits(stream); - // - // const int LookAhead = 8; - // int look = this.PeekBits(LookAhead); - // look = tree.Lookahead[look]; - // int bits = look >> LookAhead; - // - // if (bits <= LookAhead) - // { - // this.DropBits(bits); - // value = (short)(look & ((1 << LookAhead) - 1)); - // return true; - // } - if (!this.TryReadBit(stream, out int bit)) - { - return false; - } - - short code = (short)bit; - - // "DECODE", section F.2.2.3, figure F.16, page 109 of T.81 - int i = 1; - - while (code > tree.MaxCode[i]) - { - if (!this.TryReadBit(stream, out bit)) - { - return false; - } - - code <<= 1; - code |= (short)bit; - i++; - } - - int j = tree.ValOffset[i]; - value = tree.HuffVal[(j + code) & 0xFF]; - return true; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool TryReceive(int length, DoubleBufferedStreamReader stream, out int value) - { - value = 0; - while (length > 0) - { - if (!this.TryReadBit(stream, out int bit)) - { - return false; - } - - value = (value << 1) | bit; - length--; - } - - return true; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool TryReceiveAndExtend(int length, DoubleBufferedStreamReader stream, out int value) - { - if (length == 1) - { - if (!this.TryReadBit(stream, out value)) - { - return false; - } - - value = value == 1 ? 1 : -1; - } - else - { - if (!this.TryReceive(length, stream, out value)) - { - return false; - } - - if (value < 1 << (length - 1)) - { - value += (-1 << length) + 1; - } - } - - return true; - } - - private void DecodeBaseline(PdfJsFrameComponent component, ref short blockDataRef, int offset, ref PdfJsHuffmanTable dcHuffmanTable, ref PdfJsHuffmanTable acHuffmanTable, DoubleBufferedStreamReader stream) - { - if (!this.TryDecodeHuffman(ref dcHuffmanTable, stream, out short t)) - { - return; - } - - int diff = 0; - if (t != 0) - { - if (!this.TryReceiveAndExtend(t, stream, out diff)) - { - return; - } - } - - Unsafe.Add(ref blockDataRef, offset) = (short)(component.DcPredictor += diff); - - int k = 1; - while (k < 64) - { - if (!this.TryDecodeHuffman(ref acHuffmanTable, stream, out short rs)) - { - return; - } - - int s = rs & 15; - int r = rs >> 4; - - if (s == 0) - { - if (r < 15) - { - break; - } - - k += 16; - continue; - } - - k += r; - - byte z = this.dctZigZag[k]; - - if (!this.TryReceiveAndExtend(s, stream, out int re)) - { - return; - } - - Unsafe.Add(ref blockDataRef, offset + z) = (short)re; - k++; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeDCFirst(PdfJsFrameComponent component, ref short blockDataRef, int offset, ref PdfJsHuffmanTable dcHuffmanTable, DoubleBufferedStreamReader stream) - { - if (!this.TryDecodeHuffman(ref dcHuffmanTable, stream, out short t)) - { - return; - } - - int diff = 0; - if (t != 0) - { - if (!this.TryReceiveAndExtend(t, stream, out diff)) - { - return; - } - } - - Unsafe.Add(ref blockDataRef, offset) = (short)(component.DcPredictor += diff << this.successiveState); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void DecodeDCSuccessive(PdfJsFrameComponent component, ref short blockDataRef, int offset, DoubleBufferedStreamReader stream) - { - if (!this.TryReadBit(stream, out int bit)) - { - return; - } - - Unsafe.Add(ref blockDataRef, offset) |= (short)(bit << this.successiveState); - } - - private void DecodeACFirst(ref short blockDataRef, int offset, ref PdfJsHuffmanTable acHuffmanTable, DoubleBufferedStreamReader stream) - { - if (this.eobrun > 0) - { - this.eobrun--; - return; - } - - int k = this.specStart; - int e = this.specEnd; - while (k <= e) - { - if (!this.TryDecodeHuffman(ref acHuffmanTable, stream, out short rs)) - { - return; - } - - int s = rs & 15; - int r = rs >> 4; - - if (s == 0) - { - if (r < 15) - { - if (!this.TryReceive(r, stream, out int eob)) - { - return; - } - - this.eobrun = eob + (1 << r) - 1; - break; - } - - k += 16; - continue; - } - - k += r; - - byte z = this.dctZigZag[k]; - - if (!this.TryReceiveAndExtend(s, stream, out int v)) - { - return; - } - - Unsafe.Add(ref blockDataRef, offset + z) = (short)(v * (1 << this.successiveState)); - k++; - } - } - - private void DecodeACSuccessive(ref short blockDataRef, int offset, ref PdfJsHuffmanTable acHuffmanTable, DoubleBufferedStreamReader stream) - { - int k = this.specStart; - int e = this.specEnd; - int r = 0; - - while (k <= e) - { - int offsetZ = offset + this.dctZigZag[k]; - ref short blockOffsetZRef = ref Unsafe.Add(ref blockDataRef, offsetZ); - int sign = blockOffsetZRef < 0 ? -1 : 1; - - switch (this.successiveACState) - { - case 0: // Initial state - - if (!this.TryDecodeHuffman(ref acHuffmanTable, stream, out short rs)) - { - return; - } - - int s = rs & 15; - r = rs >> 4; - if (s == 0) - { - if (r < 15) - { - if (!this.TryReceive(r, stream, out int eob)) - { - return; - } - - this.eobrun = eob + (1 << r); - this.successiveACState = 4; - } - else - { - r = 16; - this.successiveACState = 1; - } - } - else - { - if (s != 1) - { - throw new ImageFormatException("Invalid ACn encoding"); - } - - if (!this.TryReceiveAndExtend(s, stream, out int v)) - { - return; - } - - this.successiveACNextValue = v; - this.successiveACState = r > 0 ? 2 : 3; - } - - continue; - case 1: // Skipping r zero items - case 2: - if (blockOffsetZRef != 0) - { - if (!this.TryReadBit(stream, out int bit)) - { - return; - } - - blockOffsetZRef += (short)(sign * (bit << this.successiveState)); - } - else - { - r--; - if (r == 0) - { - this.successiveACState = this.successiveACState == 2 ? 3 : 0; - } - } - - break; - case 3: // Set value for a zero item - if (blockOffsetZRef != 0) - { - if (!this.TryReadBit(stream, out int bit)) - { - return; - } - - blockOffsetZRef += (short)(sign * (bit << this.successiveState)); - } - else - { - blockOffsetZRef = (short)(this.successiveACNextValue << this.successiveState); - this.successiveACState = 0; - } - - break; - case 4: // Eob - if (blockOffsetZRef != 0) - { - if (!this.TryReadBit(stream, out int bit)) - { - return; - } - - blockOffsetZRef += (short)(sign * (bit << this.successiveState)); - } - - break; - } - - k++; - } - - if (this.successiveACState == 4) - { - this.eobrun--; - if (this.eobrun == 0) - { - this.successiveACState = 0; - } - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ScanDecoder.cs new file mode 100644 index 000000000..8575bac69 --- /dev/null +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ScanDecoder.cs @@ -0,0 +1,958 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using SixLabors.ImageSharp.Formats.Jpeg.Components; + +namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +{ + /// + /// Decodes the Huffman encoded spectral scan. + /// Originally ported from + /// with additional fixes for both performance and common encoding errors. + /// + internal class ScanDecoder + { + // The number of bits that can be read via a LUT. + public const int FastBits = 9; + + // LUT mask for n rightmost bits. Bmask[n] = (1 << n) - 1 + private static readonly uint[] Bmask = { 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535 }; + + // LUT Bias[n] = (-1 << n) + 1 + private static readonly int[] Bias = { 0, -1, -3, -7, -15, -31, -63, -127, -255, -511, -1023, -2047, -4095, -8191, -16383, -32767 }; + + private readonly PdfJsFrame frame; + private readonly PdfJsHuffmanTables dcHuffmanTables; + private readonly PdfJsHuffmanTables acHuffmanTables; + private readonly FastACTables fastACTables; + + private readonly DoubleBufferedStreamReader stream; + private readonly PdfJsFrameComponent[] components; + private readonly ZigZag dctZigZag; + + // The restart interval. + private readonly int restartInterval; + + // The current component index. + private readonly int componentIndex; + + // The number of interleaved components. + private readonly int componentsLength; + + // The spectral selection start. + private readonly int spectralStart; + + // The spectral selection end. + private readonly int spectralEnd; + + // The successive approximation high bit end. + private readonly int successiveHigh; + + // The successive approximation low bit end. + private readonly int successiveLow; + + // The number of valid bits left to read in the buffer. + private int codeBits; + + // The entropy encoded code buffer. + private uint codeBuffer; + + // Whether there is more data to pull from the stream for the current mcu. + private bool nomore; + + // Whether we have prematurely reached the end of the file. + private bool eof; + + // The current, if any, marker in the input stream. + private byte marker; + + // Whether we have a bad marker, I.E. One that is not between RST0 and RST7 + private bool badMarker; + + // The opening position of an identified marker. + private long markerPosition; + + // How many mcu's are left to do. + private int todo; + + // The End-Of-Block countdown for ending the sequence prematurely when the remaining coefficients are zero. + private int eobrun; + + /// + /// Initializes a new instance of the class. + /// + /// The input stream. + /// The image frame. + /// The DC Huffman tables. + /// The AC Huffman tables. + /// The fast AC decoding tables. + /// The component index within the array. + /// The length of the components. Different to the array length. + /// The reset interval. + /// The spectral selection start. + /// The spectral selection end. + /// The successive approximation bit high end. + /// The successive approximation bit low end. + public ScanDecoder( + DoubleBufferedStreamReader stream, + PdfJsFrame frame, + PdfJsHuffmanTables dcHuffmanTables, + PdfJsHuffmanTables acHuffmanTables, + FastACTables fastACTables, + int componentIndex, + int componentsLength, + int restartInterval, + int spectralStart, + int spectralEnd, + int successiveHigh, + int successiveLow) + { + this.dctZigZag = ZigZag.CreateUnzigTable(); + this.stream = stream; + this.frame = frame; + this.dcHuffmanTables = dcHuffmanTables; + this.acHuffmanTables = acHuffmanTables; + this.fastACTables = fastACTables; + this.components = frame.Components; + this.marker = JpegConstants.Markers.XFF; + this.markerPosition = 0; + this.componentIndex = componentIndex; + this.componentsLength = componentsLength; + this.restartInterval = restartInterval; + this.spectralStart = spectralStart; + this.spectralEnd = spectralEnd; + this.successiveHigh = successiveHigh; + this.successiveLow = successiveLow; + } + + /// + /// Decodes the entropy coded data. + /// + public void ParseEntropyCodedData() + { + this.Reset(); + + if (!this.frame.Progressive) + { + this.ParseBaselineData(); + } + else + { + this.ParseProgressiveData(); + } + + if (this.badMarker) + { + this.stream.Position = this.markerPosition; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static uint LRot(uint x, int y) => (x << y) | (x >> (32 - y)); + + private void ParseBaselineData() + { + if (this.componentsLength == 1) + { + this.ParseBaselineDataNonInterleaved(); + } + else + { + this.ParseBaselineDataInterleaved(); + } + } + + private void ParseBaselineDataInterleaved() + { + // Interleaved + int mcu = 0; + int mcusPerColumn = this.frame.McusPerColumn; + int mcusPerLine = this.frame.McusPerLine; + for (int j = 0; j < mcusPerColumn; j++) + { + for (int i = 0; i < mcusPerLine; i++) + { + // Scan an interleaved mcu... process components in order + for (int k = 0; k < this.componentsLength; k++) + { + PdfJsFrameComponent component = this.components[k]; + + ref PdfJsHuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; + ref PdfJsHuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId]; + ref short fastACRef = ref this.fastACTables.GetAcTableReference(component); + int h = component.HorizontalSamplingFactor; + int v = component.VerticalSamplingFactor; + + // Scan out an mcu's worth of this component; that's just determined + // by the basic H and V specified for the component + for (int y = 0; y < v; y++) + { + for (int x = 0; x < h; x++) + { + if (this.eof) + { + return; + } + + int mcuRow = mcu / mcusPerLine; + int mcuCol = mcu % mcusPerLine; + int blockRow = (mcuRow * v) + y; + int blockCol = (mcuCol * h) + x; + + this.DecodeBlockBaseline( + component, + blockRow, + blockCol, + ref dcHuffmanTable, + ref acHuffmanTable, + ref fastACRef); + } + } + } + + // After all interleaved components, that's an interleaved MCU, + // so now count down the restart interval + mcu++; + if (!this.ContinueOnMcuComplete()) + { + return; + } + } + } + } + + /// + /// Non-interleaved data, we just need to process one block at a ti + /// in trivial scanline order + /// number of blocks to do just depends on how many actual "pixels" + /// component has, independent of interleaved MCU blocking and such + /// + private void ParseBaselineDataNonInterleaved() + { + PdfJsFrameComponent component = this.components[this.componentIndex]; + + int w = component.WidthInBlocks; + int h = component.HeightInBlocks; + + ref PdfJsHuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; + ref PdfJsHuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId]; + ref short fastACRef = ref this.fastACTables.GetAcTableReference(component); + + int mcu = 0; + for (int j = 0; j < h; j++) + { + for (int i = 0; i < w; i++) + { + if (this.eof) + { + return; + } + + int blockRow = mcu / w; + int blockCol = mcu % w; + + this.DecodeBlockBaseline( + component, + blockRow, + blockCol, + ref dcHuffmanTable, + ref acHuffmanTable, + ref fastACRef); + + // Every data block is an MCU, so countdown the restart interval + mcu++; + if (!this.ContinueOnMcuComplete()) + { + return; + } + } + } + } + + private void ParseProgressiveData() + { + if (this.componentsLength == 1) + { + this.ParseProgressiveDataNonInterleaved(); + } + else + { + this.ParseProgressiveDataInterleaved(); + } + } + + private void ParseProgressiveDataInterleaved() + { + // Interleaved + int mcu = 0; + int mcusPerColumn = this.frame.McusPerColumn; + int mcusPerLine = this.frame.McusPerLine; + for (int j = 0; j < mcusPerColumn; j++) + { + for (int i = 0; i < mcusPerLine; i++) + { + // Scan an interleaved mcu... process components in order + for (int k = 0; k < this.componentsLength; k++) + { + PdfJsFrameComponent component = this.components[k]; + ref PdfJsHuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; + int h = component.HorizontalSamplingFactor; + int v = component.VerticalSamplingFactor; + + // Scan out an mcu's worth of this component; that's just determined + // by the basic H and V specified for the component + for (int y = 0; y < v; y++) + { + for (int x = 0; x < h; x++) + { + if (this.eof) + { + return; + } + + int mcuRow = mcu / mcusPerLine; + int mcuCol = mcu % mcusPerLine; + int blockRow = (mcuRow * v) + y; + int blockCol = (mcuCol * h) + x; + + this.DecodeBlockProgressiveDC( + component, + blockRow, + blockCol, + ref dcHuffmanTable); + } + } + } + + // After all interleaved components, that's an interleaved MCU, + // so now count down the restart interval + mcu++; + if (!this.ContinueOnMcuComplete()) + { + return; + } + } + } + } + + /// + /// Non-interleaved data, we just need to process one block at a time, + /// in trivial scanline order + /// number of blocks to do just depends on how many actual "pixels" this + /// component has, independent of interleaved MCU blocking and such + /// + private void ParseProgressiveDataNonInterleaved() + { + PdfJsFrameComponent component = this.components[this.componentIndex]; + + int w = component.WidthInBlocks; + int h = component.HeightInBlocks; + + ref PdfJsHuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; + ref PdfJsHuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId]; + ref short fastACRef = ref this.fastACTables.GetAcTableReference(component); + + int mcu = 0; + for (int j = 0; j < h; j++) + { + for (int i = 0; i < w; i++) + { + if (this.eof) + { + return; + } + + int blockRow = mcu / w; + int blockCol = mcu % w; + + if (this.spectralStart == 0) + { + this.DecodeBlockProgressiveDC( + component, + blockRow, + blockCol, + ref dcHuffmanTable); + } + else + { + this.DecodeBlockProgressiveAC( + component, + blockRow, + blockCol, + ref acHuffmanTable, + ref fastACRef); + } + + // Every data block is an MCU, so countdown the restart interval + mcu++; + if (!this.ContinueOnMcuComplete()) + { + return; + } + } + } + } + + private void DecodeBlockBaseline( + PdfJsFrameComponent component, + int row, + int col, + ref PdfJsHuffmanTable dcTable, + ref PdfJsHuffmanTable acTable, + ref short fastACRef) + { + this.CheckBits(); + int t = this.DecodeHuffman(ref dcTable); + + if (t < 0) + { + JpegThrowHelper.ThrowBadHuffmanCode(); + } + + ref short blockDataRef = ref component.GetBlockDataReference(row, col); + + int diff = t != 0 ? this.ExtendReceive(t) : 0; + int dc = component.DcPredictor + diff; + component.DcPredictor = dc; + blockDataRef = (short)dc; + + // Decode AC Components, See Jpeg Spec + int k = 1; + do + { + int zig; + int s; + + this.CheckBits(); + int c = this.PeekBits(); + int r = Unsafe.Add(ref fastACRef, c); + + if (r != 0) + { + // Fast AC path + k += (r >> 4) & 15; // Run + s = r & 15; // Combined Length + this.codeBuffer <<= s; + this.codeBits -= s; + + // Decode into unzigzag location + zig = this.dctZigZag[k++]; + Unsafe.Add(ref blockDataRef, zig) = (short)(r >> 8); + } + else + { + int rs = this.DecodeHuffman(ref acTable); + + if (rs < 0) + { + JpegThrowHelper.ThrowBadHuffmanCode(); + } + + s = rs & 15; + r = rs >> 4; + + if (s == 0) + { + if (rs != 0xF0) + { + break; // End block + } + + k += 16; + } + else + { + k += r; + + // Decode into unzigzag location + zig = this.dctZigZag[k++]; + Unsafe.Add(ref blockDataRef, zig) = (short)this.ExtendReceive(s); + } + } + } while (k < 64); + } + + private void DecodeBlockProgressiveDC( + PdfJsFrameComponent component, + int row, + int col, + ref PdfJsHuffmanTable dcTable) + { + if (this.spectralEnd != 0) + { + JpegThrowHelper.ThrowImageFormatException("Can't merge DC and AC."); + } + + this.CheckBits(); + + ref short blockDataRef = ref component.GetBlockDataReference(row, col); + + if (this.successiveHigh == 0) + { + // First scan for DC coefficient, must be first + int t = this.DecodeHuffman(ref dcTable); + int diff = t != 0 ? this.ExtendReceive(t) : 0; + + int dc = component.DcPredictor + diff; + component.DcPredictor = dc; + + blockDataRef = (short)(dc << this.successiveLow); + } + else + { + // Refinement scan for DC coefficient + if (this.GetBit() != 0) + { + blockDataRef += (short)(1 << this.successiveLow); + } + } + } + + private void DecodeBlockProgressiveAC( + PdfJsFrameComponent component, + int row, + int col, + ref PdfJsHuffmanTable acTable, + ref short fastACRef) + { + if (this.spectralStart == 0) + { + JpegThrowHelper.ThrowImageFormatException("Can't merge DC and AC."); + } + + ref short blockDataRef = ref component.GetBlockDataReference(row, col); + + if (this.successiveHigh == 0) + { + // MCU decoding for AC initial scan (either spectral selection, + // or first pass of successive approximation). + int shift = this.successiveLow; + + if (this.eobrun != 0) + { + this.eobrun--; + return; + } + + int k = this.spectralStart; + do + { + int zig; + int s; + + this.CheckBits(); + int c = this.PeekBits(); + int r = Unsafe.Add(ref fastACRef, c); + + if (r != 0) + { + // Fast AC path + k += (r >> 4) & 15; // Run + s = r & 15; // Combined length + this.codeBuffer <<= s; + this.codeBits -= s; + + // Decode into unzigzag location + zig = this.dctZigZag[k++]; + Unsafe.Add(ref blockDataRef, zig) = (short)((r >> 8) << shift); + } + else + { + int rs = this.DecodeHuffman(ref acTable); + + if (rs < 0) + { + JpegThrowHelper.ThrowBadHuffmanCode(); + } + + s = rs & 15; + r = rs >> 4; + + if (s == 0) + { + if (r < 15) + { + this.eobrun = 1 << r; + if (r != 0) + { + this.eobrun += this.GetBits(r); + } + + this.eobrun--; + break; + } + + k += 16; + } + else + { + k += r; + zig = this.dctZigZag[k++]; + Unsafe.Add(ref blockDataRef, zig) = (short)(this.ExtendReceive(s) << shift); + } + } + } + while (k <= this.spectralEnd); + } + else + { + // Refinement scan for these AC coefficients + this.DecodeBlockProgressiveACRefined(ref blockDataRef, ref acTable); + } + } + + private void DecodeBlockProgressiveACRefined(ref short blockDataRef, ref PdfJsHuffmanTable acTable) + { + int k; + + // Refinement scan for these AC coefficients + short bit = (short)(1 << this.successiveLow); + + if (this.eobrun != 0) + { + this.eobrun--; + for (k = this.spectralStart; k <= this.spectralEnd; k++) + { + ref short p = ref Unsafe.Add(ref blockDataRef, this.dctZigZag[k]); + if (p != 0) + { + if (this.GetBit() != 0) + { + if ((p & bit) == 0) + { + if (p > 0) + { + p += bit; + } + else + { + p -= bit; + } + } + } + } + } + } + else + { + k = this.spectralStart; + do + { + int rs = this.DecodeHuffman(ref acTable); + if (rs < 0) + { + JpegThrowHelper.ThrowBadHuffmanCode(); + } + + int s = rs & 15; + int r = rs >> 4; + + if (s == 0) + { + // r=15 s=0 should write 16 0s, so we just do + // a run of 15 0s and then write s (which is 0), + // so we don't have to do anything special here + if (r < 15) + { + this.eobrun = (1 << r) - 1; + + if (r != 0) + { + this.eobrun += this.GetBits(r); + } + + r = 64; // Force end of block + } + } + else + { + if (s != 1) + { + JpegThrowHelper.ThrowBadHuffmanCode(); + } + + // Sign bit + if (this.GetBit() != 0) + { + s = bit; + } + else + { + s = -bit; + } + } + + // Advance by r + while (k <= this.spectralEnd) + { + ref short p = ref Unsafe.Add(ref blockDataRef, this.dctZigZag[k++]); + if (p != 0) + { + if (this.GetBit() != 0) + { + if ((p & bit) == 0) + { + if (p > 0) + { + p += bit; + } + else + { + p -= bit; + } + } + } + } + else + { + if (r == 0) + { + p = (short)s; + break; + } + + r--; + } + } + } + while (k <= this.spectralEnd); + } + } + + [MethodImpl(InliningOptions.ShortMethod)] + private int GetBits(int n) + { + if (this.codeBits < n) + { + this.FillBuffer(); + } + + uint k = LRot(this.codeBuffer, n); + this.codeBuffer = k & ~Bmask[n]; + k &= Bmask[n]; + this.codeBits -= n; + return (int)k; + } + + [MethodImpl(InliningOptions.ShortMethod)] + private int GetBit() + { + if (this.codeBits < 1) + { + this.FillBuffer(); + } + + uint k = this.codeBuffer; + this.codeBuffer <<= 1; + this.codeBits--; + + return (int)(k & 0x80000000); + } + + [MethodImpl(InliningOptions.ColdPath)] + private void FillBuffer() + { + // Attempt to load at least the minimum nbumber of required bits into the buffer. + // We fail to do so only if we hit a marker or reach the end of the input stream. + do + { + int b = this.nomore ? 0 : this.stream.ReadByte(); + + if (b == -1) + { + // We've encountered the end of the file stream which means there's no EOI marker in the image + // or the SOS marker has the wrong dimensions set. + this.eof = true; + b = 0; + } + + // Found a marker. + if (b == JpegConstants.Markers.XFF) + { + this.markerPosition = this.stream.Position - 1; + int c = this.stream.ReadByte(); + while (c == JpegConstants.Markers.XFF) + { + c = this.stream.ReadByte(); + + if (c == -1) + { + this.eof = true; + c = 0; + break; + } + } + + if (c != 0) + { + this.marker = (byte)c; + this.nomore = true; + if (!this.HasRestart()) + { + this.badMarker = true; + } + + return; + } + } + + this.codeBuffer |= (uint)b << (24 - this.codeBits); + this.codeBits += 8; + } + while (this.codeBits <= 24); + } + + [MethodImpl(InliningOptions.ShortMethod)] + private int DecodeHuffman(ref PdfJsHuffmanTable table) + { + this.CheckBits(); + + // Look at the top FastBits and determine what symbol ID it is, + // if the code is <= FastBits. + int c = this.PeekBits(); + int k = table.Lookahead[c]; + if (k < 0xFF) + { + int s = table.Sizes[k]; + if (s > this.codeBits) + { + return -1; + } + + this.codeBuffer <<= s; + this.codeBits -= s; + return table.Values[k]; + } + + return this.DecodeHuffmanSlow(ref table); + } + + [MethodImpl(InliningOptions.ColdPath)] + private int DecodeHuffmanSlow(ref PdfJsHuffmanTable table) + { + // Naive test is to shift the code_buffer down so k bits are + // valid, then test against MaxCode. To speed this up, we've + // preshifted maxcode left so that it has (16-k) 0s at the + // end; in other words, regardless of the number of bits, it + // wants to be compared against something shifted to have 16; + // that way we don't need to shift inside the loop. + uint temp = this.codeBuffer >> 16; + int k; + for (k = FastBits + 1; ; k++) + { + if (temp < table.MaxCode[k]) + { + break; + } + } + + if (k == 17) + { + // Error! code not found + this.codeBits -= 16; + return -1; + } + + if (k > this.codeBits) + { + return -1; + } + + // Convert the huffman code to the symbol id + int c = (int)(((this.codeBuffer >> (32 - k)) & Bmask[k]) + table.ValOffset[k]); + + // Convert the id to a symbol + this.codeBits -= k; + this.codeBuffer <<= k; + return table.Values[c]; + } + + [MethodImpl(InliningOptions.ShortMethod)] + private int ExtendReceive(int n) + { + if (this.codeBits < n) + { + this.FillBuffer(); + } + + int sgn = (int)this.codeBuffer >> 31; + uint k = LRot(this.codeBuffer, n); + this.codeBuffer = k & ~Bmask[n]; + k &= Bmask[n]; + this.codeBits -= n; + return (int)(k + (Bias[n] & ~sgn)); + } + + [MethodImpl(InliningOptions.ShortMethod)] + private void CheckBits() + { + if (this.codeBits < 16) + { + this.FillBuffer(); + } + } + + [MethodImpl(InliningOptions.ShortMethod)] + private int PeekBits() => (int)((this.codeBuffer >> (32 - FastBits)) & ((1 << FastBits) - 1)); + + [MethodImpl(InliningOptions.ShortMethod)] + private bool ContinueOnMcuComplete() + { + if (--this.todo > 0) + { + return true; + } + + if (this.codeBits < 24) + { + this.FillBuffer(); + } + + // If it's NOT a restart, then just bail, so we get corrupt data rather than no data. + // Reset the stream to before any bad markers to ensure we can read sucessive segments. + if (this.badMarker) + { + this.stream.Position = this.markerPosition; + } + + if (!this.HasRestart()) + { + return false; + } + + this.Reset(); + + return true; + } + + [MethodImpl(InliningOptions.ShortMethod)] + private bool HasRestart() + { + byte m = this.marker; + return m >= JpegConstants.Markers.RST0 && m <= JpegConstants.Markers.RST7; + } + + private void Reset() + { + this.codeBits = 0; + this.codeBuffer = 0; + + for (int i = 0; i < this.components.Length; i++) + { + PdfJsFrameComponent c = this.components[i]; + c.DcPredictor = 0; + } + + this.nomore = false; + this.marker = JpegConstants.Markers.XFF; + this.markerPosition = 0; + this.badMarker = false; + this.eobrun = 0; + + // No more than 1<<31 MCUs if no restartInterval? that's plenty safe since we don't even allow 1<<30 pixels + this.todo = this.restartInterval > 0 ? this.restartInterval : int.MaxValue; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index bd1d84ecc..a360d5477 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -58,6 +58,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort /// private PdfJsHuffmanTables acHuffmanTables; + /// + /// The fast AC tables used for entropy decoding + /// + private FastACTables fastACTables; + /// /// The reset interval determined by RST markers /// @@ -239,6 +244,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort this.QuantizationTables = new Block8x8F[4]; this.dcHuffmanTables = new PdfJsHuffmanTables(); this.acHuffmanTables = new PdfJsHuffmanTables(); + this.fastACTables = new FastACTables(this.configuration.MemoryAllocator); } while (fileMarker.Marker != JpegConstants.Markers.EOI) @@ -353,12 +359,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort { this.InputStream?.Dispose(); this.Frame?.Dispose(); + this.fastACTables?.Dispose(); // Set large fields to null. this.InputStream = null; this.Frame = null; this.dcHuffmanTables = null; this.acHuffmanTables = null; + this.fastACTables = null; } /// @@ -723,11 +731,20 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort i += 17 + codeLengthSum; + int tableType = huffmanTableSpec >> 4; + int tableIndex = huffmanTableSpec & 15; + this.BuildHuffmanTable( - huffmanTableSpec >> 4 == 0 ? this.dcHuffmanTables : this.acHuffmanTables, - huffmanTableSpec & 15, + tableType == 0 ? this.dcHuffmanTables : this.acHuffmanTables, + tableIndex, codeLengths.GetSpan(), huffmanValues.GetSpan()); + + if (huffmanTableSpec >> 4 != 0) + { + // Build a table that decodes both magnitude and value of small ACs in one go. + this.fastACTables.BuildACTableLut(huffmanTableSpec & 15, this.acHuffmanTables); + } } } } @@ -786,21 +803,22 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort int spectralStart = this.temp[0]; int spectralEnd = this.temp[1]; int successiveApproximation = this.temp[2]; - PdfJsScanDecoder scanDecoder = default; - - scanDecoder.DecodeScan( - this.Frame, - this.InputStream, - this.dcHuffmanTables, - this.acHuffmanTables, - this.Frame.Components, - componentIndex, - selectorsCount, - this.resetInterval, - spectralStart, - spectralEnd, - successiveApproximation >> 4, - successiveApproximation & 15); + + var sd = new ScanDecoder( + this.InputStream, + this.Frame, + this.dcHuffmanTables, + this.acHuffmanTables, + this.fastACTables, + componentIndex, + selectorsCount, + this.resetInterval, + spectralStart, + spectralEnd, + successiveApproximation >> 4, + successiveApproximation & 15); + + sd.ParseEntropyCodedData(); } /// @@ -827,6 +845,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort return BinaryPrimitives.ReadUInt16BigEndian(this.markerBuffer); } + /// + /// Post processes the pixels into the destination image. + /// + /// The pixel format. + /// The . private Image PostProcessIntoImage() where TPixel : struct, IPixel { diff --git a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs index 3b8aea669..f3231fa22 100644 --- a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs +++ b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Quantization; namespace SixLabors.ImageSharp.Formats.Png { diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index babda2eff..109e6ad77 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -4,7 +4,7 @@ using System.IO; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Quantization; namespace SixLabors.ImageSharp.Formats.Png { diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 45e8669d6..69f04979c 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -9,7 +9,7 @@ using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Png.Zlib; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Quantization; using SixLabors.Memory; namespace SixLabors.ImageSharp.Formats.Png @@ -86,11 +86,6 @@ namespace SixLabors.ImageSharp.Formats.Png /// private readonly bool writeGamma; - /// - /// Contains the raw pixel data from an indexed image. - /// - private byte[] palettePixelData; - /// /// The image width. /// @@ -188,11 +183,12 @@ namespace SixLabors.ImageSharp.Formats.Png stream.Write(PngConstants.HeaderBytes, 0, PngConstants.HeaderBytes.Length); QuantizedFrame quantized = null; + ReadOnlySpan quantizedPixelsSpan = default; if (this.pngColorType == PngColorType.Palette) { // Create quantized frame returning the palette and set the bit depth. quantized = this.quantizer.CreateFrameQuantizer().QuantizeFrame(image.Frames.RootFrame); - this.palettePixelData = quantized.Pixels; + quantizedPixelsSpan = quantized.GetPixelSpan(); byte bits = (byte)ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length).Clamp(1, 8); // Png only supports in four pixel depths: 1, 2, 4, and 8 bits when using the PLTE chunk @@ -233,9 +229,11 @@ namespace SixLabors.ImageSharp.Formats.Png this.WritePhysicalChunk(stream, image); this.WriteGammaChunk(stream); - this.WriteDataChunks(image.Frames.RootFrame, stream); + this.WriteDataChunks(image.Frames.RootFrame, quantizedPixelsSpan, stream); this.WriteEndChunk(stream); stream.Flush(); + + quantized?.Dispose(); } /// @@ -384,9 +382,10 @@ namespace SixLabors.ImageSharp.Formats.Png /// /// The pixel format. /// The row span. + /// The span of quantized pixels. Can be null. /// The row. /// The - private IManagedByteBuffer EncodePixelRow(ReadOnlySpan rowSpan, int row) + private IManagedByteBuffer EncodePixelRow(ReadOnlySpan rowSpan, ReadOnlySpan quantizedPixelsSpan, int row) where TPixel : struct, IPixel { switch (this.pngColorType) @@ -394,7 +393,7 @@ namespace SixLabors.ImageSharp.Formats.Png case PngColorType.Palette: int stride = this.rawScanline.Length(); - this.palettePixelData.AsSpan(row * stride, stride).CopyTo(this.rawScanline.GetSpan()); + quantizedPixelsSpan.Slice(row * stride, stride).CopyTo(this.rawScanline.GetSpan()); break; case PngColorType.Grayscale: @@ -555,10 +554,11 @@ namespace SixLabors.ImageSharp.Formats.Png { Span colorTableSpan = colorTable.GetSpan(); Span alphaTableSpan = alphaTable.GetSpan(); + Span quantizedSpan = quantized.GetPixelSpan(); for (byte i = 0; i < pixelCount; i++) { - if (quantized.Pixels.Contains(i)) + if (quantizedSpan.IndexOf(i) > -1) { int offset = i * 3; palette[i].ToRgba32(ref rgba); @@ -571,10 +571,10 @@ namespace SixLabors.ImageSharp.Formats.Png if (alpha > this.threshold) { - alpha = 255; + alpha = byte.MaxValue; } - anyAlpha = anyAlpha || alpha < 255; + anyAlpha = anyAlpha || alpha < byte.MaxValue; alphaTableSpan[i] = alpha; } } @@ -635,8 +635,9 @@ namespace SixLabors.ImageSharp.Formats.Png /// /// The pixel format. /// The image. + /// The span of quantized pixel data. Can be null. /// The stream. - private void WriteDataChunks(ImageFrame pixels, Stream stream) + private void WriteDataChunks(ImageFrame pixels, ReadOnlySpan quantizedPixelsSpan, Stream stream) where TPixel : struct, IPixel { this.bytesPerScanline = this.width * this.bytesPerPixel; @@ -688,7 +689,7 @@ namespace SixLabors.ImageSharp.Formats.Png { for (int y = 0; y < this.height; y++) { - IManagedByteBuffer r = this.EncodePixelRow((ReadOnlySpan)pixels.GetPixelRowSpan(y), y); + IManagedByteBuffer r = this.EncodePixelRow((ReadOnlySpan)pixels.GetPixelRowSpan(y), quantizedPixelsSpan, y); deflateStream.Write(r.Array, 0, resultLength); IManagedByteBuffer temp = this.rawScanline; diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs index d3ea9743f..6d473fd4b 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs @@ -6,6 +6,7 @@ using System.Buffers.Binary; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using SixLabors.ImageSharp.IO; @@ -462,7 +463,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif } } - private unsafe double ConvertToDouble(ReadOnlySpan buffer) + private double ConvertToDouble(ReadOnlySpan buffer) { if (buffer.Length < 8) { @@ -473,7 +474,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif ? BinaryPrimitives.ReadInt64BigEndian(buffer) : BinaryPrimitives.ReadInt64LittleEndian(buffer); - return *((double*)&intValue); + return Unsafe.As(ref intValue); } private uint ConvertToUInt32(ReadOnlySpan buffer) @@ -501,7 +502,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif : BinaryPrimitives.ReadUInt16LittleEndian(buffer); } - private unsafe float ConvertToSingle(ReadOnlySpan buffer) + private float ConvertToSingle(ReadOnlySpan buffer) { if (buffer.Length < 4) { @@ -512,7 +513,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif ? BinaryPrimitives.ReadInt32BigEndian(buffer) : BinaryPrimitives.ReadInt32LittleEndian(buffer); - return *((float*)&intValue); + return Unsafe.As(ref intValue); } private Rational ToRational(ReadOnlySpan buffer) diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs index bdd902e23..d475959c6 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs @@ -181,7 +181,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif /// public bool Equals(ExifValue other) { - if (ReferenceEquals(other, null)) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs index 9c3f8aa5e..a241acd21 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs @@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccParametricCurve other) { - if (other == null) + if (other is null) { return false; } @@ -148,16 +148,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccParametricCurve other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs index 02a817b8c..e15d8a434 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs @@ -67,16 +67,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccResponseCurve other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs index 8b942498a..7dc8cf98a 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs @@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// Reads an ICC profile version number /// /// the version number - public Version ReadVersionNumber() + public IccVersion ReadVersionNumber() { int version = this.ReadInt32(); @@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc int minor = (version >> 20) & 0x0F; int bugfix = (version >> 16) & 0x0F; - return new Version(major, minor, bugfix); + return new IccVersion(major, minor, bugfix); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs index 538a31d6a..5be0060f6 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs @@ -3,6 +3,7 @@ using System; using System.Buffers.Binary; +using System.Runtime.CompilerServices; using System.Text; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc @@ -70,22 +71,22 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// Reads a float. /// /// the value - public unsafe float ReadSingle() + public float ReadSingle() { int intValue = this.ReadInt32(); - return *((float*)&intValue); + return Unsafe.As(ref intValue); } /// /// Reads a double /// /// the value - public unsafe double ReadDouble() + public double ReadDouble() { long intValue = this.ReadInt64(); - return *((double*)&intValue); + return Unsafe.As(ref intValue); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs index 791a94a33..1a3c2c0ac 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs @@ -31,11 +31,11 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// The value to write /// the number of bytes written - public int WriteVersionNumber(Version value) + public int WriteVersionNumber(in IccVersion value) { int major = value.Major.Clamp(0, byte.MaxValue); int minor = value.Minor.Clamp(0, 15); - int bugfix = value.Build.Clamp(0, 15); + int bugfix = value.Patch.Clamp(0, 15); // TODO: This is not used? byte mb = (byte)((minor << 4) | bugfix); @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// The value to write /// the number of bytes written - public int WriteProfileId(IccProfileId value) + public int WriteProfileId(in IccProfileId value) { return this.WriteUInt32(value.Part1) + this.WriteUInt32(value.Part2) @@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// The value to write /// the number of bytes written - public int WritePositionNumber(IccPositionNumber value) + public int WritePositionNumber(in IccPositionNumber value) { return this.WriteUInt32(value.Offset) + this.WriteUInt32(value.Size); @@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// The value to write /// the number of bytes written - public int WriteResponseNumber(IccResponseNumber value) + public int WriteResponseNumber(in IccResponseNumber value) { return this.WriteUInt16(value.DeviceCode) + this.WriteFix16(value.MeasurementValue); @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// The value to write /// the number of bytes written - public int WriteNamedColor(IccNamedColor value) + public int WriteNamedColor(in IccNamedColor value) { return this.WriteAsciiString(value.Name, 32, true) + this.WriteArray(value.PcsCoordinates) @@ -108,7 +108,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// The value to write /// the number of bytes written - public int WriteProfileDescription(IccProfileDescription value) + public int WriteProfileDescription(in IccProfileDescription value) { return this.WriteUInt32(value.DeviceManufacturer) + this.WriteUInt32(value.DeviceModel) @@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// The value to write /// the number of bytes written - public int WriteScreeningChannel(IccScreeningChannel value) + public int WriteScreeningChannel(in IccScreeningChannel value) { return this.WriteFix16(value.Frequency) + this.WriteFix16(value.Angle) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs index 52b8e43da..db1d96d7e 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs @@ -167,11 +167,22 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// True if the profile is valid; False otherwise public bool CheckIsValid() { - return Enum.IsDefined(typeof(IccColorSpaceType), this.Header.DataColorSpace) && + const int minSize = 128; + const int maxSize = 50_000_000; // it's unlikely there is a profile bigger than 50MB + + bool arrayValid = true; + if (this.data != null) + { + arrayValid = this.data.Length >= minSize && + this.data.Length >= this.Header.Size; + } + + return arrayValid && + Enum.IsDefined(typeof(IccColorSpaceType), this.Header.DataColorSpace) && Enum.IsDefined(typeof(IccColorSpaceType), this.Header.ProfileConnectionSpace) && Enum.IsDefined(typeof(IccRenderingIntent), this.Header.RenderingIntent) && - this.Header.Size >= 128 && - this.Header.Size < 50_000_000; // it's unlikely there is a profile bigger than 50MB + this.Header.Size >= minSize && + this.Header.Size < maxSize; } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccProfileHeader.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccProfileHeader.cs index f91572cfe..189b40275 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccProfileHeader.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccProfileHeader.cs @@ -7,42 +7,42 @@ using System.Numerics; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { /// - /// Contains all values of an ICC profile header + /// Contains all values of an ICC profile header. /// public sealed class IccProfileHeader { /// - /// Gets or sets the profile size in bytes (will be ignored when writing a profile) + /// Gets or sets the profile size in bytes (will be ignored when writing a profile). /// public uint Size { get; set; } /// - /// Gets or sets the preferred CMM (Color Management Module) type + /// Gets or sets the preferred CMM (Color Management Module) type. /// public string CmmType { get; set; } /// - /// Gets or sets the profiles version number + /// Gets or sets the profiles version number. /// - public Version Version { get; set; } + public IccVersion Version { get; set; } /// - /// Gets or sets the type of the profile + /// Gets or sets the type of the profile. /// public IccProfileClass Class { get; set; } /// - /// Gets or sets the data colorspace + /// Gets or sets the data colorspace. /// public IccColorSpaceType DataColorSpace { get; set; } /// - /// Gets or sets the profile connection space + /// Gets or sets the profile connection space. /// public IccColorSpaceType ProfileConnectionSpace { get; set; } /// - /// Gets or sets the date and time this profile was created + /// Gets or sets the date and time this profile was created. /// public DateTime CreationDate { get; set; } @@ -59,42 +59,42 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// Gets or sets the profile flags to indicate various options for the CMM - /// such as distributed processing and caching options + /// such as distributed processing and caching options. /// public IccProfileFlag Flags { get; set; } /// - /// Gets or sets the device manufacturer of the device for which this profile is created + /// Gets or sets the device manufacturer of the device for which this profile is created. /// public uint DeviceManufacturer { get; set; } /// - /// Gets or sets the model of the device for which this profile is created + /// Gets or sets the model of the device for which this profile is created. /// public uint DeviceModel { get; set; } /// - /// Gets or sets the device attributes unique to the particular device setup such as media type + /// Gets or sets the device attributes unique to the particular device setup such as media type. /// public IccDeviceAttribute DeviceAttributes { get; set; } /// - /// Gets or sets the rendering Intent + /// Gets or sets the rendering Intent. /// public IccRenderingIntent RenderingIntent { get; set; } /// - /// Gets or sets The normalized XYZ values of the illuminant of the PCS + /// Gets or sets The normalized XYZ values of the illuminant of the PCS. /// public Vector3 PcsIlluminant { get; set; } /// - /// Gets or sets Profile creator signature + /// Gets or sets profile creator signature. /// public string CreatorSignature { get; set; } /// - /// Gets or sets the profile ID (hash) + /// Gets or sets the profile ID (hash). /// public IccProfileId Id { get; set; } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs index 1b0d041b6..231f3818a 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs @@ -44,28 +44,9 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccTagDataEntry entry && this.Equals(entry); } - /// - public override int GetHashCode() - { - unchecked - { - return (int)this.Signature * 397; - } - } - /// public virtual bool Equals(IccTagDataEntry other) { @@ -81,5 +62,14 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return this.Signature == other.Signature; } + + /// + public override int GetHashCode() + { + unchecked + { + return (int)this.Signature * 397; + } + } } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs index b400e1bd7..c008463ee 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs @@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccChromaticityTagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -104,17 +104,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is IccChromaticityTagDataEntry && this.Equals((IccChromaticityTagDataEntry)obj); + return obj is IccChromaticityTagDataEntry other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs index 73024ee12..2194b8ab4 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs @@ -65,16 +65,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccColorantOrderTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs index 353dab604..90b1c304b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs @@ -66,16 +66,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccColorantTableTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs index 848418f95..b2bbb7b56 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs @@ -115,16 +115,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccCrdInfoTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs index c9a59bb32..154afd8ed 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs @@ -113,16 +113,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccCurveTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs index c8f5f8b7c..a1addaa90 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs @@ -89,16 +89,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccDataTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs index 7a2d97571..004603a0e 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs @@ -60,17 +60,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is IccDateTimeTagDataEntry && this.Equals((IccDateTimeTagDataEntry)obj); + return obj is IccDateTimeTagDataEntry other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs index afe4e0bd3..b0d9e1ef9 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs @@ -62,16 +62,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccFix16ArrayTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs index d98e45ace..f296a8b07 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs @@ -137,17 +137,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is IccLut16TagDataEntry && this.Equals((IccLut16TagDataEntry)obj); + return obj is IccLut16TagDataEntry other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs index e57e0f543..f94d500c3 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs @@ -140,17 +140,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is IccLut8TagDataEntry && this.Equals((IccLut8TagDataEntry)obj); + return obj is IccLut8TagDataEntry other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs index 59c80d409..c4f3f8a2a 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs @@ -177,16 +177,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccLutAToBTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs index 57b17c452..17bbf915b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs @@ -177,16 +177,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccLutBToATagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs index 5f2dbe347..f32e17714 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs @@ -100,17 +100,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is IccMeasurementTagDataEntry && this.Equals((IccMeasurementTagDataEntry)obj); + return obj is IccMeasurementTagDataEntry other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs index d1745faac..c006c9556 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs @@ -63,17 +63,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is IccMultiLocalizedUnicodeTagDataEntry && this.Equals((IccMultiLocalizedUnicodeTagDataEntry)obj); + return obj is IccMultiLocalizedUnicodeTagDataEntry other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs index 8b0c06568..dcfe010aa 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs @@ -84,16 +84,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccMultiProcessElementsTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs index bdb1aacb3..c32a45182 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs @@ -127,7 +127,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccNamedColor2TagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -148,16 +148,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccNamedColor2TagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs index e8bbc5e8f..46719b80f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccParametricCurveTagDataEntry.cs @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccParametricCurveTagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -61,16 +61,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccParametricCurveTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs index cde7c4043..c42004634 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccProfileSequenceDescTagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -64,16 +64,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccProfileSequenceDescTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs index 2309a460e..f6b0582fb 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccProfileSequenceIdentifierTagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -63,16 +63,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccProfileSequenceIdentifierTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs index 5925454a3..e2cd5860b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccResponseCurveSet16TagDataEntry.cs @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccResponseCurveSet16TagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -77,17 +77,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is IccResponseCurveSet16TagDataEntry && this.Equals((IccResponseCurveSet16TagDataEntry)obj); + return obj is IccResponseCurveSet16TagDataEntry other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs index 1e17d0862..c93781d9e 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs @@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccScreeningTagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -74,16 +74,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccScreeningTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs index a808541cf..e469e7eab 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs @@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccSignatureTagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -62,16 +62,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccSignatureTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs index c509197e4..cc67dd1b1 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs @@ -139,7 +139,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccTextDescriptionTagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -160,17 +160,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is IccTextDescriptionTagDataEntry && this.Equals((IccTextDescriptionTagDataEntry)obj); + return obj is IccTextDescriptionTagDataEntry other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs index f5e31ea87..1cf321893 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccTextTagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -61,16 +61,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccTextTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs index c619b40d4..63a19d6d4 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs @@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccUFix16ArrayTagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -62,16 +62,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccUFix16ArrayTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs index 4f1959cf1..d082df39a 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs @@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccUInt16ArrayTagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -62,16 +62,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccUInt16ArrayTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs index 00ca43084..2e3efe1c7 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs @@ -62,17 +62,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is IccUInt32ArrayTagDataEntry && this.Equals((IccUInt32ArrayTagDataEntry)obj); + return obj is IccUInt32ArrayTagDataEntry other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs index 27c273e42..85ae2f9fa 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs @@ -62,17 +62,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is IccUInt64ArrayTagDataEntry && this.Equals((IccUInt64ArrayTagDataEntry)obj); + return obj is IccUInt64ArrayTagDataEntry other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs index bf6fdd662..a673abf68 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs @@ -62,16 +62,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccUInt8ArrayTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs index 0f190021f..fd38e659b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs @@ -85,16 +85,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccUcrBgTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs index ce3be9b69..0f0a9d218 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs @@ -62,16 +62,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccUnknownTagDataEntry other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs index a4db8f7ab..6be21dcc9 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccViewingConditionsTagDataEntry.cs @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccViewingConditionsTagDataEntry other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } @@ -80,17 +80,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is IccViewingConditionsTagDataEntry && this.Equals((IccViewingConditionsTagDataEntry)obj); + return obj is IccViewingConditionsTagDataEntry other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs index d704fee96..b776cc4c0 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs @@ -55,4 +55,4 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return this.Equals((IccTagDataEntry)other); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs index c42d85134..e88115438 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs @@ -136,16 +136,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - if (obj == null) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - return obj is IccClut other && this.Equals(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs index c038cfaba..79c647bf1 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public override bool Equals(object obj) { - return obj is IccScreeningChannel && this.Equals((IccScreeningChannel)obj); + return obj is IccScreeningChannel other && this.Equals(other); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccVersion.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccVersion.cs new file mode 100644 index 000000000..2486cc80a --- /dev/null +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccVersion.cs @@ -0,0 +1,53 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; + +namespace SixLabors.ImageSharp.MetaData.Profiles.Icc +{ + /// + /// Represents the ICC profile version number. + /// + public readonly struct IccVersion : IEquatable + { + /// + /// Initializes a new instance of the struct. + /// + /// The major version number. + /// The minor version number. + /// The patch version number. + public IccVersion(int major, int minor, int patch) + { + this.Major = major; + this.Minor = minor; + this.Patch = patch; + } + + /// + /// Gets the major version number. + /// + public int Major { get; } + + /// + /// Gets the minor version number. + /// + public int Minor { get; } + + /// + /// Gets the patch number. + /// + public int Patch { get; } + + /// + public bool Equals(IccVersion other) => + this.Major == other.Major && + this.Minor == other.Minor && + this.Patch == other.Patch; + + /// + public override string ToString() + { + return string.Join(".", this.Major, this.Minor, this.Patch); + } + } +} diff --git a/src/ImageSharp/PixelFormats/Bgr565.cs b/src/ImageSharp/PixelFormats/Bgr565.cs index 8595c6b9b..f9a0ce9dc 100644 --- a/src/ImageSharp/PixelFormats/Bgr565.cs +++ b/src/ImageSharp/PixelFormats/Bgr565.cs @@ -206,7 +206,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override bool Equals(object obj) { - return (obj is Bgr565) && this.Equals((Bgr565)obj); + return obj is Bgr565 other && this.Equals(other); } /// diff --git a/src/ImageSharp/PixelFormats/HalfSingle.cs b/src/ImageSharp/PixelFormats/HalfSingle.cs index 504992542..54c615f9b 100644 --- a/src/ImageSharp/PixelFormats/HalfSingle.cs +++ b/src/ImageSharp/PixelFormats/HalfSingle.cs @@ -211,7 +211,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override bool Equals(object obj) { - return (obj is HalfSingle) && this.Equals((HalfSingle)obj); + return obj is HalfSingle other && this.Equals(other); } /// diff --git a/src/ImageSharp/PixelFormats/HalfVector2.cs b/src/ImageSharp/PixelFormats/HalfVector2.cs index 72eb4f79c..4a135a77c 100644 --- a/src/ImageSharp/PixelFormats/HalfVector2.cs +++ b/src/ImageSharp/PixelFormats/HalfVector2.cs @@ -239,7 +239,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override bool Equals(object obj) { - return (obj is HalfVector2) && this.Equals((HalfVector2)obj); + return obj is HalfVector2 other && this.Equals(other); } /// diff --git a/src/ImageSharp/PixelFormats/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/NormalizedShort2.cs index 2ddc83e76..1ced412d0 100644 --- a/src/ImageSharp/PixelFormats/NormalizedShort2.cs +++ b/src/ImageSharp/PixelFormats/NormalizedShort2.cs @@ -247,7 +247,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override bool Equals(object obj) { - return (obj is NormalizedShort2) && this.Equals((NormalizedShort2)obj); + return obj is NormalizedShort2 other && this.Equals(other); } /// diff --git a/src/ImageSharp/PixelFormats/Rg32.cs b/src/ImageSharp/PixelFormats/Rg32.cs index 39a0ff424..e5ceeacec 100644 --- a/src/ImageSharp/PixelFormats/Rg32.cs +++ b/src/ImageSharp/PixelFormats/Rg32.cs @@ -210,7 +210,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override bool Equals(object obj) { - return (obj is Rg32) && this.Equals((Rg32)obj); + return obj is Rg32 other && this.Equals(other); } /// diff --git a/src/ImageSharp/PixelFormats/Rgba64.cs b/src/ImageSharp/PixelFormats/Rgba64.cs index b0aeab92e..a66485ba4 100644 --- a/src/ImageSharp/PixelFormats/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/Rgba64.cs @@ -290,7 +290,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override string ToString() { - return this.ToVector4().ToString(); + return $"({this.R},{this.G},{this.B},{this.A})"; } /// diff --git a/src/ImageSharp/Processing/Transforms/AnchorPositionMode.cs b/src/ImageSharp/Processing/AnchorPositionMode.cs similarity index 96% rename from src/ImageSharp/Processing/Transforms/AnchorPositionMode.cs rename to src/ImageSharp/Processing/AnchorPositionMode.cs index 793fc0dfc..ef9c0fdaf 100644 --- a/src/ImageSharp/Processing/Transforms/AnchorPositionMode.cs +++ b/src/ImageSharp/Processing/AnchorPositionMode.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Enumerated anchor positions to apply to resized images. diff --git a/src/ImageSharp/Processing/Transforms/AutoOrientExtensions.cs b/src/ImageSharp/Processing/AutoOrientExtensions.cs similarity index 89% rename from src/ImageSharp/Processing/Transforms/AutoOrientExtensions.cs rename to src/ImageSharp/Processing/AutoOrientExtensions.cs index d3ac16708..d11fc9623 100644 --- a/src/ImageSharp/Processing/Transforms/AutoOrientExtensions.cs +++ b/src/ImageSharp/Processing/AutoOrientExtensions.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing.Processors.Transforms; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of auto-orientation operations to the type. diff --git a/src/ImageSharp/Processing/Overlays/BackgroundColorExtensions.cs b/src/ImageSharp/Processing/BackgroundColorExtensions.cs similarity index 97% rename from src/ImageSharp/Processing/Overlays/BackgroundColorExtensions.cs rename to src/ImageSharp/Processing/BackgroundColorExtensions.cs index 1a8224769..1ad2c9237 100644 --- a/src/ImageSharp/Processing/Overlays/BackgroundColorExtensions.cs +++ b/src/ImageSharp/Processing/BackgroundColorExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Overlays.Processors; +using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Overlays +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of a background color to the type. diff --git a/src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs b/src/ImageSharp/Processing/BinaryDiffuseExtensions.cs similarity index 96% rename from src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs rename to src/ImageSharp/Processing/BinaryDiffuseExtensions.cs index a2859b011..788942dde 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs +++ b/src/ImageSharp/Processing/BinaryDiffuseExtensions.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Binarization.Processors; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Processors.Binarization; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Binarization +namespace SixLabors.ImageSharp.Processing { /// /// Adds binary diffusion extensions to the type. diff --git a/src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs b/src/ImageSharp/Processing/BinaryDitherExtensions.cs similarity index 95% rename from src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs rename to src/ImageSharp/Processing/BinaryDitherExtensions.cs index e66be55de..617770196 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs +++ b/src/ImageSharp/Processing/BinaryDitherExtensions.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Binarization.Processors; -using SixLabors.ImageSharp.Processing.Dithering.Ordered; +using SixLabors.ImageSharp.Processing.Processors.Binarization; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Binarization +namespace SixLabors.ImageSharp.Processing { /// /// Adds binary dithering extensions to the type. diff --git a/src/ImageSharp/Processing/Binarization/BinaryThresholdExtensions.cs b/src/ImageSharp/Processing/BinaryThresholdExtensions.cs similarity index 97% rename from src/ImageSharp/Processing/Binarization/BinaryThresholdExtensions.cs rename to src/ImageSharp/Processing/BinaryThresholdExtensions.cs index 005061394..31f81ba4b 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryThresholdExtensions.cs +++ b/src/ImageSharp/Processing/BinaryThresholdExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Binarization.Processors; +using SixLabors.ImageSharp.Processing.Processors.Binarization; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Binarization +namespace SixLabors.ImageSharp.Processing { /// /// Adds binary thresholding extensions to the type. diff --git a/src/ImageSharp/Processing/Filters/BlackWhiteExtensions.cs b/src/ImageSharp/Processing/BlackWhiteExtensions.cs similarity index 93% rename from src/ImageSharp/Processing/Filters/BlackWhiteExtensions.cs rename to src/ImageSharp/Processing/BlackWhiteExtensions.cs index f30cefb86..0484fa84e 100644 --- a/src/ImageSharp/Processing/Filters/BlackWhiteExtensions.cs +++ b/src/ImageSharp/Processing/BlackWhiteExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of black and white toning to the type. diff --git a/src/ImageSharp/Processing/Convolution/BoxBlurExtensions.cs b/src/ImageSharp/Processing/BoxBlurExtensions.cs similarity index 95% rename from src/ImageSharp/Processing/Convolution/BoxBlurExtensions.cs rename to src/ImageSharp/Processing/BoxBlurExtensions.cs index edb798fb4..624da239b 100644 --- a/src/ImageSharp/Processing/Convolution/BoxBlurExtensions.cs +++ b/src/ImageSharp/Processing/BoxBlurExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Convolution.Processors; +using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution +namespace SixLabors.ImageSharp.Processing { /// /// Adds box blurring extensions to the type. diff --git a/src/ImageSharp/Processing/Filters/BrightnessExtensions.cs b/src/ImageSharp/Processing/BrightnessExtensions.cs similarity index 95% rename from src/ImageSharp/Processing/Filters/BrightnessExtensions.cs rename to src/ImageSharp/Processing/BrightnessExtensions.cs index a36d588d5..2f252ad30 100644 --- a/src/ImageSharp/Processing/Filters/BrightnessExtensions.cs +++ b/src/ImageSharp/Processing/BrightnessExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the alteration of the brightness component to the type. diff --git a/src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs b/src/ImageSharp/Processing/ColorBlindnessExtensions.cs similarity index 96% rename from src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs rename to src/ImageSharp/Processing/ColorBlindnessExtensions.cs index d70064097..331635895 100644 --- a/src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs +++ b/src/ImageSharp/Processing/ColorBlindnessExtensions.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that simulate the effects of various color blindness disorders to the type. diff --git a/src/ImageSharp/Processing/Filters/ColorBlindnessMode.cs b/src/ImageSharp/Processing/ColorBlindnessMode.cs similarity index 95% rename from src/ImageSharp/Processing/Filters/ColorBlindnessMode.cs rename to src/ImageSharp/Processing/ColorBlindnessMode.cs index 584c9fa08..2ff19e77e 100644 --- a/src/ImageSharp/Processing/Filters/ColorBlindnessMode.cs +++ b/src/ImageSharp/Processing/ColorBlindnessMode.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Enumerates the various types of defined color blindness filters. diff --git a/src/ImageSharp/Processing/Filters/ContrastExtensions.cs b/src/ImageSharp/Processing/ContrastExtensions.cs similarity index 95% rename from src/ImageSharp/Processing/Filters/ContrastExtensions.cs rename to src/ImageSharp/Processing/ContrastExtensions.cs index 16225039c..776aa6751 100644 --- a/src/ImageSharp/Processing/Filters/ContrastExtensions.cs +++ b/src/ImageSharp/Processing/ContrastExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the alteration of the contrast component to the type. diff --git a/src/ImageSharp/Processing/Transforms/CropExtensions.cs b/src/ImageSharp/Processing/CropExtensions.cs similarity index 93% rename from src/ImageSharp/Processing/Transforms/CropExtensions.cs rename to src/ImageSharp/Processing/CropExtensions.cs index 9e347f51c..34c754a08 100644 --- a/src/ImageSharp/Processing/Transforms/CropExtensions.cs +++ b/src/ImageSharp/Processing/CropExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of cropping operations to the type. diff --git a/src/ImageSharp/Processing/Convolution/DetectEdgesExtensions.cs b/src/ImageSharp/Processing/DetectEdgesExtensions.cs similarity index 98% rename from src/ImageSharp/Processing/Convolution/DetectEdgesExtensions.cs rename to src/ImageSharp/Processing/DetectEdgesExtensions.cs index a2b2b244b..5ac89df29 100644 --- a/src/ImageSharp/Processing/Convolution/DetectEdgesExtensions.cs +++ b/src/ImageSharp/Processing/DetectEdgesExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Convolution.Processors; +using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution +namespace SixLabors.ImageSharp.Processing { /// /// Adds edge detection extensions to the type. diff --git a/src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs b/src/ImageSharp/Processing/DiffuseExtensions.cs similarity index 97% rename from src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs rename to src/ImageSharp/Processing/DiffuseExtensions.cs index adb678ee4..768d28116 100644 --- a/src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs +++ b/src/ImageSharp/Processing/DiffuseExtensions.cs @@ -2,8 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -using SixLabors.ImageSharp.Processing.Dithering.Processors; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Dithering diff --git a/src/ImageSharp/Processing/Dithering/DitherExtensions.cs b/src/ImageSharp/Processing/DitherExtensions.cs similarity index 96% rename from src/ImageSharp/Processing/Dithering/DitherExtensions.cs rename to src/ImageSharp/Processing/DitherExtensions.cs index 48dd87a3b..795561e70 100644 --- a/src/ImageSharp/Processing/Dithering/DitherExtensions.cs +++ b/src/ImageSharp/Processing/DitherExtensions.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering.Ordered; -using SixLabors.ImageSharp.Processing.Dithering.Processors; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering +namespace SixLabors.ImageSharp.Processing { /// /// Adds dithering extensions to the type. diff --git a/src/ImageSharp/Processing/Convolution/EdgeDetectionOperators.cs b/src/ImageSharp/Processing/EdgeDetectionOperators.cs similarity index 96% rename from src/ImageSharp/Processing/Convolution/EdgeDetectionOperators.cs rename to src/ImageSharp/Processing/EdgeDetectionOperators.cs index 55cbbeaf7..1f3526760 100644 --- a/src/ImageSharp/Processing/Convolution/EdgeDetectionOperators.cs +++ b/src/ImageSharp/Processing/EdgeDetectionOperators.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Convolution +namespace SixLabors.ImageSharp.Processing { /// /// Enumerates the various types of defined edge detection filters. diff --git a/src/ImageSharp/Processing/Transforms/EntropyCropExtensions.cs b/src/ImageSharp/Processing/EntropyCropExtensions.cs similarity index 93% rename from src/ImageSharp/Processing/Transforms/EntropyCropExtensions.cs rename to src/ImageSharp/Processing/EntropyCropExtensions.cs index 3ca4c72bc..157e69ef2 100644 --- a/src/ImageSharp/Processing/Transforms/EntropyCropExtensions.cs +++ b/src/ImageSharp/Processing/EntropyCropExtensions.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing.Processors.Transforms; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of entropy cropping operations to the type. diff --git a/src/ImageSharp/Processing/Filters/FilterExtensions.cs b/src/ImageSharp/Processing/FilterExtensions.cs similarity index 94% rename from src/ImageSharp/Processing/Filters/FilterExtensions.cs rename to src/ImageSharp/Processing/FilterExtensions.cs index ae8bbda03..bfae4ae65 100644 --- a/src/ImageSharp/Processing/Filters/FilterExtensions.cs +++ b/src/ImageSharp/Processing/FilterExtensions.cs @@ -3,10 +3,10 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of composable filters to the type. diff --git a/src/ImageSharp/Processing/Transforms/FlipExtensions.cs b/src/ImageSharp/Processing/FlipExtensions.cs similarity index 89% rename from src/ImageSharp/Processing/Transforms/FlipExtensions.cs rename to src/ImageSharp/Processing/FlipExtensions.cs index 0cbbdd95f..dfbff7e4d 100644 --- a/src/ImageSharp/Processing/Transforms/FlipExtensions.cs +++ b/src/ImageSharp/Processing/FlipExtensions.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing.Processors.Transforms; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of flipping operations to the type. diff --git a/src/ImageSharp/Processing/Transforms/FlipMode.cs b/src/ImageSharp/Processing/FlipMode.cs similarity index 90% rename from src/ImageSharp/Processing/Transforms/FlipMode.cs rename to src/ImageSharp/Processing/FlipMode.cs index 32c910c80..96cd38de4 100644 --- a/src/ImageSharp/Processing/Transforms/FlipMode.cs +++ b/src/ImageSharp/Processing/FlipMode.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Provides enumeration over how a image should be flipped. diff --git a/src/ImageSharp/Processing/Convolution/GaussianBlurExtensions.cs b/src/ImageSharp/Processing/GaussianBlurExtensions.cs similarity index 95% rename from src/ImageSharp/Processing/Convolution/GaussianBlurExtensions.cs rename to src/ImageSharp/Processing/GaussianBlurExtensions.cs index ae3eace64..165c4ce1a 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianBlurExtensions.cs +++ b/src/ImageSharp/Processing/GaussianBlurExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Convolution.Processors; +using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution +namespace SixLabors.ImageSharp.Processing { /// /// Adds Gaussian blurring extensions to the type. diff --git a/src/ImageSharp/Processing/Convolution/GaussianSharpenExtensions.cs b/src/ImageSharp/Processing/GaussianSharpenExtensions.cs similarity index 95% rename from src/ImageSharp/Processing/Convolution/GaussianSharpenExtensions.cs rename to src/ImageSharp/Processing/GaussianSharpenExtensions.cs index 334a02b79..675bbc142 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianSharpenExtensions.cs +++ b/src/ImageSharp/Processing/GaussianSharpenExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Convolution.Processors; +using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution +namespace SixLabors.ImageSharp.Processing { /// /// Adds Gaussian sharpening extensions to the type. diff --git a/src/ImageSharp/Processing/Overlays/GlowExtensions.cs b/src/ImageSharp/Processing/GlowExtensions.cs similarity index 98% rename from src/ImageSharp/Processing/Overlays/GlowExtensions.cs rename to src/ImageSharp/Processing/GlowExtensions.cs index 54af9f274..8b6e8ffc2 100644 --- a/src/ImageSharp/Processing/Overlays/GlowExtensions.cs +++ b/src/ImageSharp/Processing/GlowExtensions.cs @@ -3,10 +3,10 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Overlays.Processors; +using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Overlays +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of a radial glow to the type. diff --git a/src/ImageSharp/Processing/Filters/GrayscaleExtensions.cs b/src/ImageSharp/Processing/GrayscaleExtensions.cs similarity index 98% rename from src/ImageSharp/Processing/Filters/GrayscaleExtensions.cs rename to src/ImageSharp/Processing/GrayscaleExtensions.cs index 34ee4d0f3..9ab664056 100644 --- a/src/ImageSharp/Processing/Filters/GrayscaleExtensions.cs +++ b/src/ImageSharp/Processing/GrayscaleExtensions.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of grayscale toning to the type. diff --git a/src/ImageSharp/Processing/Filters/GrayscaleMode.cs b/src/ImageSharp/Processing/GrayscaleMode.cs similarity index 89% rename from src/ImageSharp/Processing/Filters/GrayscaleMode.cs rename to src/ImageSharp/Processing/GrayscaleMode.cs index db30e67ff..e42a2e633 100644 --- a/src/ImageSharp/Processing/Filters/GrayscaleMode.cs +++ b/src/ImageSharp/Processing/GrayscaleMode.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Enumerates the various types of defined grayscale filters. diff --git a/src/ImageSharp/Processing/Filters/HueExtensions.cs b/src/ImageSharp/Processing/HueExtensions.cs similarity index 94% rename from src/ImageSharp/Processing/Filters/HueExtensions.cs rename to src/ImageSharp/Processing/HueExtensions.cs index 1b730d7f0..246d4bf2b 100644 --- a/src/ImageSharp/Processing/Filters/HueExtensions.cs +++ b/src/ImageSharp/Processing/HueExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the alteration of the hue component to the type. diff --git a/src/ImageSharp/Processing/Filters/InvertExtensions.cs b/src/ImageSharp/Processing/InvertExtensions.cs similarity index 93% rename from src/ImageSharp/Processing/Filters/InvertExtensions.cs rename to src/ImageSharp/Processing/InvertExtensions.cs index 784b37c56..9e031bc95 100644 --- a/src/ImageSharp/Processing/Filters/InvertExtensions.cs +++ b/src/ImageSharp/Processing/InvertExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the inversion of colors to the type. diff --git a/src/ImageSharp/Processing/Dithering/KnownDiffusers.cs b/src/ImageSharp/Processing/KnownDiffusers.cs similarity index 94% rename from src/ImageSharp/Processing/Dithering/KnownDiffusers.cs rename to src/ImageSharp/Processing/KnownDiffusers.cs index 250a543ec..2b10312fe 100644 --- a/src/ImageSharp/Processing/Dithering/KnownDiffusers.cs +++ b/src/ImageSharp/Processing/KnownDiffusers.cs @@ -1,9 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Processors.Dithering; -namespace SixLabors.ImageSharp.Processing.Dithering +namespace SixLabors.ImageSharp.Processing { /// /// Contains reusable static instances of known error diffusion algorithms diff --git a/src/ImageSharp/Processing/Dithering/KnownDitherers.cs b/src/ImageSharp/Processing/KnownDitherers.cs similarity index 88% rename from src/ImageSharp/Processing/Dithering/KnownDitherers.cs rename to src/ImageSharp/Processing/KnownDitherers.cs index b268ae12c..dad5bb38c 100644 --- a/src/ImageSharp/Processing/Dithering/KnownDitherers.cs +++ b/src/ImageSharp/Processing/KnownDitherers.cs @@ -1,14 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Processing.Dithering.Ordered; +using SixLabors.ImageSharp.Processing.Processors.Dithering; -namespace SixLabors.ImageSharp.Processing.Dithering +namespace SixLabors.ImageSharp.Processing { /// /// Contains reusable static instances of known ordered dither matrices /// - public class KnownDitherers + public static class KnownDitherers { /// /// Gets the order ditherer using the 2x2 Bayer dithering matrix diff --git a/src/ImageSharp/Processing/Filters/KnownFilterMatrices.cs b/src/ImageSharp/Processing/KnownFilterMatrices.cs similarity index 99% rename from src/ImageSharp/Processing/Filters/KnownFilterMatrices.cs rename to src/ImageSharp/Processing/KnownFilterMatrices.cs index 9da4aaa65..4f5e3c869 100644 --- a/src/ImageSharp/Processing/Filters/KnownFilterMatrices.cs +++ b/src/ImageSharp/Processing/KnownFilterMatrices.cs @@ -4,7 +4,7 @@ using System; using System.Numerics; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// A collection of known values for composing filters @@ -314,7 +314,7 @@ namespace SixLabors.ImageSharp.Processing.Filters public static Matrix4x4 CreateHueFilter(float degrees) { // Wrap the angle round at 360. - degrees = degrees % 360; + degrees %= 360; // Make sure it's not negative. while (degrees < 0) diff --git a/src/ImageSharp/Processing/Quantization/KnownQuantizers.cs b/src/ImageSharp/Processing/KnownQuantizers.cs similarity index 90% rename from src/ImageSharp/Processing/Quantization/KnownQuantizers.cs rename to src/ImageSharp/Processing/KnownQuantizers.cs index 357cd5676..fe9806310 100644 --- a/src/ImageSharp/Processing/Quantization/KnownQuantizers.cs +++ b/src/ImageSharp/Processing/KnownQuantizers.cs @@ -1,7 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Quantization +using SixLabors.ImageSharp.Processing.Processors.Quantization; + +namespace SixLabors.ImageSharp.Processing { /// /// Contains reusable static instances of known quantizing algorithms diff --git a/src/ImageSharp/Processing/Transforms/KnownResamplers.cs b/src/ImageSharp/Processing/KnownResamplers.cs similarity index 97% rename from src/ImageSharp/Processing/Transforms/KnownResamplers.cs rename to src/ImageSharp/Processing/KnownResamplers.cs index 2b589d461..70a413ec0 100644 --- a/src/ImageSharp/Processing/Transforms/KnownResamplers.cs +++ b/src/ImageSharp/Processing/KnownResamplers.cs @@ -1,9 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Contains reusable static instances of known resampling algorithms diff --git a/src/ImageSharp/Processing/Filters/KodachromeExtensions.cs b/src/ImageSharp/Processing/KodachromeExtensions.cs similarity index 94% rename from src/ImageSharp/Processing/Filters/KodachromeExtensions.cs rename to src/ImageSharp/Processing/KodachromeExtensions.cs index 94f1acc0c..e438b131e 100644 --- a/src/ImageSharp/Processing/Filters/KodachromeExtensions.cs +++ b/src/ImageSharp/Processing/KodachromeExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the recreation of an old Kodachrome camera effect to the type. diff --git a/src/ImageSharp/Processing/Filters/LomographExtensions.cs b/src/ImageSharp/Processing/LomographExtensions.cs similarity index 94% rename from src/ImageSharp/Processing/Filters/LomographExtensions.cs rename to src/ImageSharp/Processing/LomographExtensions.cs index ed9e1cc29..7dff16402 100644 --- a/src/ImageSharp/Processing/Filters/LomographExtensions.cs +++ b/src/ImageSharp/Processing/LomographExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the recreation of an old Lomograph camera effect to the type. diff --git a/src/ImageSharp/Processing/Effects/OilPaintExtensions.cs b/src/ImageSharp/Processing/OilPaintExtensions.cs similarity index 97% rename from src/ImageSharp/Processing/Effects/OilPaintExtensions.cs rename to src/ImageSharp/Processing/OilPaintExtensions.cs index a04bbec4e..b6fa4149a 100644 --- a/src/ImageSharp/Processing/Effects/OilPaintExtensions.cs +++ b/src/ImageSharp/Processing/OilPaintExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Effects.Processors; +using SixLabors.ImageSharp.Processing.Processors.Effects; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Effects +namespace SixLabors.ImageSharp.Processing { /// /// Adds oil painting effect extensions to the type. diff --git a/src/ImageSharp/Processing/Filters/OpacityExtensions.cs b/src/ImageSharp/Processing/OpacityExtensions.cs similarity index 94% rename from src/ImageSharp/Processing/Filters/OpacityExtensions.cs rename to src/ImageSharp/Processing/OpacityExtensions.cs index e263fef4e..fc3fd331d 100644 --- a/src/ImageSharp/Processing/Filters/OpacityExtensions.cs +++ b/src/ImageSharp/Processing/OpacityExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the alteration of the opacity component to the type. diff --git a/src/ImageSharp/Processing/Transforms/OrientationMode.cs b/src/ImageSharp/Processing/OrientationMode.cs similarity index 96% rename from src/ImageSharp/Processing/Transforms/OrientationMode.cs rename to src/ImageSharp/Processing/OrientationMode.cs index c6f05380b..ba55425b8 100644 --- a/src/ImageSharp/Processing/Transforms/OrientationMode.cs +++ b/src/ImageSharp/Processing/OrientationMode.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Enumerates the available orientation values supplied by EXIF metadata. diff --git a/src/ImageSharp/Processing/Transforms/PadExtensions.cs b/src/ImageSharp/Processing/PadExtensions.cs similarity index 95% rename from src/ImageSharp/Processing/Transforms/PadExtensions.cs rename to src/ImageSharp/Processing/PadExtensions.cs index a231088dd..f73033968 100644 --- a/src/ImageSharp/Processing/Transforms/PadExtensions.cs +++ b/src/ImageSharp/Processing/PadExtensions.cs @@ -4,7 +4,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of padding operations to the type. diff --git a/src/ImageSharp/Processing/Effects/PixelateExtensions.cs b/src/ImageSharp/Processing/PixelateExtensions.cs similarity index 95% rename from src/ImageSharp/Processing/Effects/PixelateExtensions.cs rename to src/ImageSharp/Processing/PixelateExtensions.cs index d6fcfe6f1..4507f6392 100644 --- a/src/ImageSharp/Processing/Effects/PixelateExtensions.cs +++ b/src/ImageSharp/Processing/PixelateExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Effects.Processors; +using SixLabors.ImageSharp.Processing.Processors.Effects; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Effects +namespace SixLabors.ImageSharp.Processing { /// /// Adds pixelation effect extensions to the type. diff --git a/src/ImageSharp/Processing/Filters/PolaroidExtensions.cs b/src/ImageSharp/Processing/PolaroidExtensions.cs similarity index 94% rename from src/ImageSharp/Processing/Filters/PolaroidExtensions.cs rename to src/ImageSharp/Processing/PolaroidExtensions.cs index 37f06f9cf..5d4beee22 100644 --- a/src/ImageSharp/Processing/Filters/PolaroidExtensions.cs +++ b/src/ImageSharp/Processing/PolaroidExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the recreation of an old Polaroid camera effect to the type. diff --git a/src/ImageSharp/Processing/Binarization/Processors/BinaryErrorDiffusionProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs similarity index 96% rename from src/ImageSharp/Processing/Binarization/Processors/BinaryErrorDiffusionProcessor.cs rename to src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs index 64763b657..5041dcf5a 100644 --- a/src/ImageSharp/Processing/Binarization/Processors/BinaryErrorDiffusionProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs @@ -4,11 +4,10 @@ using System; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Binarization.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Binarization { /// /// Performs binary threshold filtering against an image using error diffusion. diff --git a/src/ImageSharp/Processing/Binarization/Processors/BinaryOrderedDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs similarity index 95% rename from src/ImageSharp/Processing/Binarization/Processors/BinaryOrderedDitherProcessor.cs rename to src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs index 3fe56ff44..95f4ef472 100644 --- a/src/ImageSharp/Processing/Binarization/Processors/BinaryOrderedDitherProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs @@ -4,11 +4,10 @@ using System; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering.Ordered; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Binarization.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Binarization { /// /// Performs binary threshold filtering against an image using ordered dithering. diff --git a/src/ImageSharp/Processing/Binarization/Processors/BinaryThresholdProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Binarization/Processors/BinaryThresholdProcessor.cs rename to src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs index dc1297d6f..57d4e00ae 100644 --- a/src/ImageSharp/Processing/Binarization/Processors/BinaryThresholdProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs @@ -8,7 +8,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Binarization.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Binarization { /// /// Performs simple binary threshold filtering against an image. diff --git a/src/ImageSharp/Processing/Convolution/Processors/BoxBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs similarity index 96% rename from src/ImageSharp/Processing/Convolution/Processors/BoxBlurProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs index 886fb5d75..0ec62ac3d 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/BoxBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs @@ -3,10 +3,9 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies box blur processing to the image. diff --git a/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs similarity index 97% rename from src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs index 48503e999..57f71a9ce 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs @@ -7,11 +7,10 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Defines a processor that uses two one-dimensional matrices to perform convolution against an image. diff --git a/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs index 4e14882ff..6d7147cf7 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs @@ -10,7 +10,7 @@ using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Defines a processor that uses two one-dimensional matrices to perform two-pass convolution against an image. diff --git a/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs index 221cf19ec..84a166545 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs @@ -11,7 +11,7 @@ using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Defines a processor that uses a 2 dimensional matrix to perform convolution against an image. diff --git a/src/ImageSharp/Processing/Convolution/Processors/EdgeDetector2DProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Convolution/Processors/EdgeDetector2DProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor.cs index c3530647a..dd43d3e15 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/EdgeDetector2DProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor.cs @@ -3,11 +3,10 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Filters.Processors; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Defines a processor that detects edges within an image using two one-dimensional matrices. diff --git a/src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorCompassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor.cs similarity index 97% rename from src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorCompassProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor.cs index b78145089..22297b8f2 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorCompassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor.cs @@ -8,12 +8,11 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Filters.Processors; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Defines a processor that detects edges within an image using a eight two dimensional matrices. diff --git a/src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor.cs similarity index 91% rename from src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor.cs index e0ca83828..9173bc229 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorProcessor.cs @@ -3,11 +3,10 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Filters.Processors; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Defines a processor that detects edges within an image using a single two dimensional matrix. diff --git a/src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs index 6f33e23ec..3045b9993 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs @@ -7,7 +7,7 @@ using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies Gaussian blur processing to the image. diff --git a/src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs similarity index 96% rename from src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs index 5f296e29e..18963c73c 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs @@ -4,10 +4,9 @@ using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies Gaussian sharpening processing to the image. @@ -160,14 +159,14 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors { for (int i = 0; i < size; i++) { - kernel[0, i] = kernel[0, i] / sum; + kernel[0, i] /= sum; } } else { for (int i = 0; i < size; i++) { - kernel[i, 0] = kernel[i, 0] / sum; + kernel[i, 0] /= sum; } } diff --git a/src/ImageSharp/Processing/Convolution/Processors/IEdgeDetectorProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/IEdgeDetectorProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/IEdgeDetectorProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/IEdgeDetectorProcessor.cs index 486929e02..b2ecbf115 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/IEdgeDetectorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/IEdgeDetectorProcessor.cs @@ -4,7 +4,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Provides properties and methods allowing the detection of edges within an image. diff --git a/src/ImageSharp/Processing/Convolution/Processors/KayyaliKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/KayyaliKernels.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/KayyaliKernels.cs rename to src/ImageSharp/Processing/Processors/Convolution/KayyaliKernels.cs index e131cac38..dd4d02302 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/KayyaliKernels.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/KayyaliKernels.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Contains the kernels used for Kayyali edge detection diff --git a/src/ImageSharp/Processing/Convolution/Processors/KayyaliProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/KayyaliProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/KayyaliProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/KayyaliProcessor.cs index 357c6c397..8652efa12 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/KayyaliProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/KayyaliProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies edge detection processing to the image using the Kayyali operator filter. diff --git a/src/ImageSharp/Processing/Convolution/Processors/KirschProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/KirschProcessor.cs similarity index 96% rename from src/ImageSharp/Processing/Convolution/Processors/KirschProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/KirschProcessor.cs index c9a21da0b..46cf00c22 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/KirschProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/KirschProcessor.cs @@ -4,7 +4,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies edge detection processing to the image using the Kirsch operator filter. diff --git a/src/ImageSharp/Processing/Convolution/Processors/KirshKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/KirshKernels.cs similarity index 97% rename from src/ImageSharp/Processing/Convolution/Processors/KirshKernels.cs rename to src/ImageSharp/Processing/Processors/Convolution/KirshKernels.cs index 8e52f8df4..d31587508 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/KirshKernels.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/KirshKernels.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Contains the eight matrices used for Kirsh edge detection diff --git a/src/ImageSharp/Processing/Convolution/Processors/Laplacian3x3Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/Laplacian3x3Processor.cs rename to src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs index 657a93c81..f498d374c 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/Laplacian3x3Processor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Laplacian3x3Processor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies edge detection processing to the image using the Laplacian 3x3 operator filter. diff --git a/src/ImageSharp/Processing/Convolution/Processors/Laplacian5x5Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/Laplacian5x5Processor.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/Laplacian5x5Processor.cs rename to src/ImageSharp/Processing/Processors/Convolution/Laplacian5x5Processor.cs index 5b44773ad..558acf7b3 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/Laplacian5x5Processor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Laplacian5x5Processor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies edge detection processing to the image using the Laplacian 5x5 operator filter. diff --git a/src/ImageSharp/Processing/Convolution/Processors/LaplacianKernelFactory.cs b/src/ImageSharp/Processing/Processors/Convolution/LaplacianKernelFactory.cs similarity index 94% rename from src/ImageSharp/Processing/Convolution/Processors/LaplacianKernelFactory.cs rename to src/ImageSharp/Processing/Processors/Convolution/LaplacianKernelFactory.cs index 053033432..19f2d1161 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/LaplacianKernelFactory.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/LaplacianKernelFactory.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// A factory for creating Laplacian kernel matrices. diff --git a/src/ImageSharp/Processing/Convolution/Processors/LaplacianKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/LaplacianKernels.cs similarity index 94% rename from src/ImageSharp/Processing/Convolution/Processors/LaplacianKernels.cs rename to src/ImageSharp/Processing/Processors/Convolution/LaplacianKernels.cs index 407736980..e7b7f965b 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/LaplacianKernels.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/LaplacianKernels.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Contains Laplacian kernels of different sizes diff --git a/src/ImageSharp/Processing/Convolution/Processors/LaplacianOfGaussianProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/LaplacianOfGaussianProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/LaplacianOfGaussianProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/LaplacianOfGaussianProcessor.cs index e65e0d215..6cc65dc58 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/LaplacianOfGaussianProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/LaplacianOfGaussianProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies edge detection processing to the image using the Laplacian of Gaussian operator filter. diff --git a/src/ImageSharp/Processing/Convolution/Processors/PrewittKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/PrewittKernels.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/PrewittKernels.cs rename to src/ImageSharp/Processing/Processors/Convolution/PrewittKernels.cs index aba4d52c3..381e028d4 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/PrewittKernels.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/PrewittKernels.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Contains the kernels used for Prewitt edge detection diff --git a/src/ImageSharp/Processing/Convolution/Processors/PrewittProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/PrewittProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/PrewittProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/PrewittProcessor.cs index 5683d6f60..75ef4dac6 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/PrewittProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/PrewittProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies edge detection processing to the image using the Prewitt operator filter. diff --git a/src/ImageSharp/Processing/Convolution/Processors/RobertsCrossKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossKernels.cs similarity index 92% rename from src/ImageSharp/Processing/Convolution/Processors/RobertsCrossKernels.cs rename to src/ImageSharp/Processing/Processors/Convolution/RobertsCrossKernels.cs index 64d1fcea5..f61220e1e 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/RobertsCrossKernels.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossKernels.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Contains the kernels used for RobertsCross edge detection diff --git a/src/ImageSharp/Processing/Convolution/Processors/RobertsCrossProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/RobertsCrossProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs index 38d1fffc9..d685860f6 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/RobertsCrossProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/RobertsCrossProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies edge detection processing to the image using the Roberts Cross operator filter. diff --git a/src/ImageSharp/Processing/Convolution/Processors/RobinsonKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/RobinsonKernels.cs similarity index 97% rename from src/ImageSharp/Processing/Convolution/Processors/RobinsonKernels.cs rename to src/ImageSharp/Processing/Processors/Convolution/RobinsonKernels.cs index 9d440fcc0..4f47184e3 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/RobinsonKernels.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/RobinsonKernels.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Contains the kernels used for Robinson edge detection diff --git a/src/ImageSharp/Processing/Convolution/Processors/RobinsonProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs similarity index 96% rename from src/ImageSharp/Processing/Convolution/Processors/RobinsonProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs index f129b1daa..193c1008d 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/RobinsonProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/RobinsonProcessor.cs @@ -4,7 +4,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies edge detection processing to the image using the Robinson operator filter. diff --git a/src/ImageSharp/Processing/Convolution/Processors/ScharrKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/ScharrKernels.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/ScharrKernels.cs rename to src/ImageSharp/Processing/Processors/Convolution/ScharrKernels.cs index c309e4cec..f0662c667 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/ScharrKernels.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ScharrKernels.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Contains the kernels used for Scharr edge detection diff --git a/src/ImageSharp/Processing/Convolution/Processors/ScharrProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/ScharrProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs index c101d092d..79fc0e79f 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/ScharrProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ScharrProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Applies edge detection processing to the image using the Scharr operator filter. diff --git a/src/ImageSharp/Processing/Convolution/Processors/SobelKernels.cs b/src/ImageSharp/Processing/Processors/Convolution/SobelKernels.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/SobelKernels.cs rename to src/ImageSharp/Processing/Processors/Convolution/SobelKernels.cs index 626226c66..113957c83 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/SobelKernels.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/SobelKernels.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// Contains the kernels used for Sobel edge detection diff --git a/src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.cs rename to src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs index 9fb9c56c4..3ca53f6f0 100644 --- a/src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/SobelProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Convolution { /// /// The Sobel operator filter. diff --git a/src/ImageSharp/Processing/Processors/DelegateProcessor.cs b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs index 2ff00d583..7a9753d1a 100644 --- a/src/ImageSharp/Processing/Processors/DelegateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs @@ -14,26 +14,24 @@ namespace SixLabors.ImageSharp.Processing.Processors internal class DelegateProcessor : ImageProcessor where TPixel : struct, IPixel { - private readonly Action> action; - /// /// Initializes a new instance of the class. /// /// The action. public DelegateProcessor(Action> action) { - this.action = action; + this.Action = action; } /// /// Gets the action that will be applied to the image. /// - internal Action> Action => this.action; + internal Action> Action { get; } /// protected override void BeforeImageApply(Image source, Rectangle sourceRectangle) { - this.action?.Invoke(source); + this.Action?.Invoke(source); } /// diff --git a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs b/src/ImageSharp/Processing/Processors/Dithering/AtkinsonDiffuser.cs similarity index 93% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs rename to src/ImageSharp/Processing/Processors/Dithering/AtkinsonDiffuser.cs index 2b13980fc..17c97ddc9 100644 --- a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/AtkinsonDiffuser.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies error diffusion based dithering using the Atkinson image dithering algorithm. diff --git a/src/ImageSharp/Processing/Dithering/Ordered/BayerDither2x2.cs b/src/ImageSharp/Processing/Processors/Dithering/BayerDither2x2.cs similarity index 88% rename from src/ImageSharp/Processing/Dithering/Ordered/BayerDither2x2.cs rename to src/ImageSharp/Processing/Processors/Dithering/BayerDither2x2.cs index 2d674787a..b7fdfbfe5 100644 --- a/src/ImageSharp/Processing/Dithering/Ordered/BayerDither2x2.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/BayerDither2x2.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Dithering.Ordered +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies order dithering using the 2x2 Bayer dithering matrix. diff --git a/src/ImageSharp/Processing/Dithering/Ordered/BayerDither4x4.cs b/src/ImageSharp/Processing/Processors/Dithering/BayerDither4x4.cs similarity index 88% rename from src/ImageSharp/Processing/Dithering/Ordered/BayerDither4x4.cs rename to src/ImageSharp/Processing/Processors/Dithering/BayerDither4x4.cs index edc57441a..4f6d5dd07 100644 --- a/src/ImageSharp/Processing/Dithering/Ordered/BayerDither4x4.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/BayerDither4x4.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Dithering.Ordered +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies order dithering using the 4x4 Bayer dithering matrix. diff --git a/src/ImageSharp/Processing/Dithering/Ordered/BayerDither8x8.cs b/src/ImageSharp/Processing/Processors/Dithering/BayerDither8x8.cs similarity index 88% rename from src/ImageSharp/Processing/Dithering/Ordered/BayerDither8x8.cs rename to src/ImageSharp/Processing/Processors/Dithering/BayerDither8x8.cs index b79216208..8d0c23aa3 100644 --- a/src/ImageSharp/Processing/Dithering/Ordered/BayerDither8x8.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/BayerDither8x8.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Dithering.Ordered +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies order dithering using the 8x8 Bayer dithering matrix. diff --git a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/BurksDiffuser.cs b/src/ImageSharp/Processing/Processors/Dithering/BurksDiffuser.cs similarity index 92% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/BurksDiffuser.cs rename to src/ImageSharp/Processing/Processors/Dithering/BurksDiffuser.cs index b4b439c9a..84455b24a 100644 --- a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/BurksDiffuser.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/BurksDiffuser.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies error diffusion based dithering using the Burks image dithering algorithm. diff --git a/src/ImageSharp/Processing/Dithering/DHALF.TXT b/src/ImageSharp/Processing/Processors/Dithering/DHALF.TXT similarity index 100% rename from src/ImageSharp/Processing/Dithering/DHALF.TXT rename to src/ImageSharp/Processing/Processors/Dithering/DHALF.TXT diff --git a/src/ImageSharp/Processing/Dithering/DITHER.TXT b/src/ImageSharp/Processing/Processors/Dithering/DITHER.TXT similarity index 100% rename from src/ImageSharp/Processing/Dithering/DITHER.TXT rename to src/ImageSharp/Processing/Processors/Dithering/DITHER.TXT diff --git a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs b/src/ImageSharp/Processing/Processors/Dithering/ErrorDiffuserBase.cs similarity index 88% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs rename to src/ImageSharp/Processing/Processors/Dithering/ErrorDiffuserBase.cs index 3bc1df0bb..b407841f2 100644 --- a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/ErrorDiffuserBase.cs @@ -8,7 +8,7 @@ using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// The base class for performing error diffusion based dithering. @@ -47,7 +47,6 @@ namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion /// The divisor. internal ErrorDiffuserBase(DenseMatrix matrix, byte divisor) { - Guard.NotNull(matrix, nameof(matrix)); Guard.MustBeGreaterThan(divisor, 0, nameof(divisor)); this.matrix = matrix; @@ -75,9 +74,21 @@ namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { image[x, y] = transformed; + // Equal? Break out as there's nothing to pass. + if (source.Equals(transformed)) + { + return; + } + // Calculate the error Vector4 error = source.ToVector4() - transformed.ToVector4(); + this.DoDither(image, x, y, minX, minY, maxX, maxY, error); + } + [MethodImpl(MethodImplOptions.NoInlining)] + private void DoDither(ImageFrame image, int x, int y, int minX, int minY, int maxX, int maxY, Vector4 error) + where TPixel : struct, IPixel + { // Loop through and distribute the error amongst neighboring pixels. for (int row = 0; row < this.matrixHeight; row++) { diff --git a/src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs b/src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs rename to src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs index 0f9e2d397..8e2b2a5a8 100644 --- a/src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs @@ -4,11 +4,10 @@ using System; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// An that dithers an image using error diffusion. @@ -78,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering.Processors // Collect the values before looping so we can reduce our calculation count for identical sibling pixels TPixel sourcePixel = source[startX, startY]; TPixel previousPixel = sourcePixel; - PixelPair pair = this.GetClosestPixelPair(ref sourcePixel, this.Palette); + PixelPair pair = this.GetClosestPixelPair(ref sourcePixel); sourcePixel.ToRgba32(ref rgba); // Convert to grayscale using ITU-R Recommendation BT.709 if required @@ -96,7 +95,14 @@ namespace SixLabors.ImageSharp.Processing.Dithering.Processors // rather than calculating it again. This is an inexpensive optimization. if (!previousPixel.Equals(sourcePixel)) { - pair = this.GetClosestPixelPair(ref sourcePixel, this.Palette); + pair = this.GetClosestPixelPair(ref sourcePixel); + + // No error to spread, exact match. + if (sourcePixel.Equals(pair.First)) + { + continue; + } + sourcePixel.ToRgba32(ref rgba); luminance = isAlphaOnly ? rgba.A : (.2126F * rgba.R) + (.7152F * rgba.G) + (.0722F * rgba.B); diff --git a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs b/src/ImageSharp/Processing/Processors/Dithering/FloydSteinbergDiffuser.cs similarity index 93% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs rename to src/ImageSharp/Processing/Processors/Dithering/FloydSteinbergDiffuser.cs index 290d77864..6a7655b59 100644 --- a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/FloydSteinbergDiffuser.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies error diffusion based dithering using the Floyd–Steinberg image dithering algorithm. diff --git a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/IErrorDiffuser.cs b/src/ImageSharp/Processing/Processors/Dithering/IErrorDiffuser.cs similarity index 94% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/IErrorDiffuser.cs rename to src/ImageSharp/Processing/Processors/Dithering/IErrorDiffuser.cs index 795aa6506..5b30c0dc4 100644 --- a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/IErrorDiffuser.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/IErrorDiffuser.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Encapsulates properties and methods required to perform diffused error dithering on an image. diff --git a/src/ImageSharp/Processing/Dithering/Ordered/IOrderedDither.cs b/src/ImageSharp/Processing/Processors/Dithering/IOrderedDither.cs similarity index 95% rename from src/ImageSharp/Processing/Dithering/Ordered/IOrderedDither.cs rename to src/ImageSharp/Processing/Processors/Dithering/IOrderedDither.cs index 29b96ab45..571929b99 100644 --- a/src/ImageSharp/Processing/Dithering/Ordered/IOrderedDither.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/IOrderedDither.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Dithering.Ordered +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Encapsulates properties and methods required to perform ordered dithering on an image. diff --git a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs b/src/ImageSharp/Processing/Processors/Dithering/JarvisJudiceNinkeDiffuser.cs similarity index 93% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs rename to src/ImageSharp/Processing/Processors/Dithering/JarvisJudiceNinkeDiffuser.cs index 816447ec9..a69557d6d 100644 --- a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/JarvisJudiceNinkeDiffuser.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies error diffusion based dithering using the JarvisJudiceNinke image dithering algorithm. diff --git a/src/ImageSharp/Processing/Dithering/Ordered/OrderedDither.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs similarity index 96% rename from src/ImageSharp/Processing/Dithering/Ordered/OrderedDither.cs rename to src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs index 9fd274ab7..174732f80 100644 --- a/src/ImageSharp/Processing/Dithering/Ordered/OrderedDither.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither.cs @@ -4,7 +4,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.Ordered +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// An ordered dithering matrix with equal sides of arbitrary length diff --git a/src/ImageSharp/Processing/Dithering/Ordered/OrderedDither3x3.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither3x3.cs similarity index 88% rename from src/ImageSharp/Processing/Dithering/Ordered/OrderedDither3x3.cs rename to src/ImageSharp/Processing/Processors/Dithering/OrderedDither3x3.cs index dd20817cf..93bce0578 100644 --- a/src/ImageSharp/Processing/Dithering/Ordered/OrderedDither3x3.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDither3x3.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Dithering.Ordered +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies order dithering using the 3x3 dithering matrix. diff --git a/src/ImageSharp/Processing/Dithering/Ordered/OrderedDitherFactory.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherFactory.cs similarity index 98% rename from src/ImageSharp/Processing/Dithering/Ordered/OrderedDitherFactory.cs rename to src/ImageSharp/Processing/Processors/Dithering/OrderedDitherFactory.cs index 7538aa50e..4b93c4259 100644 --- a/src/ImageSharp/Processing/Dithering/Ordered/OrderedDitherFactory.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherFactory.cs @@ -4,7 +4,7 @@ using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.Ordered +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// A factory for creating ordered dither matrices. diff --git a/src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs similarity index 91% rename from src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs rename to src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs index a59826e23..4100fef8c 100644 --- a/src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs @@ -4,11 +4,10 @@ using System; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering.Ordered; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// An that dithers an image using error diffusion. @@ -59,7 +58,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering.Processors // Collect the values before looping so we can reduce our calculation count for identical sibling pixels TPixel sourcePixel = source[startX, startY]; TPixel previousPixel = sourcePixel; - PixelPair pair = this.GetClosestPixelPair(ref sourcePixel, this.Palette); + PixelPair pair = this.GetClosestPixelPair(ref sourcePixel); sourcePixel.ToRgba32(ref rgba); // Convert to grayscale using ITU-R Recommendation BT.709 if required @@ -77,7 +76,14 @@ namespace SixLabors.ImageSharp.Processing.Dithering.Processors // rather than calculating it again. This is an inexpensive optimization. if (!previousPixel.Equals(sourcePixel)) { - pair = this.GetClosestPixelPair(ref sourcePixel, this.Palette); + pair = this.GetClosestPixelPair(ref sourcePixel); + + // No error to spread, exact match. + if (sourcePixel.Equals(pair.First)) + { + continue; + } + sourcePixel.ToRgba32(ref rgba); luminance = isAlphaOnly ? rgba.A : (.2126F * rgba.R) + (.7152F * rgba.G) + (.0722F * rgba.B); diff --git a/src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs similarity index 60% rename from src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs rename to src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs index 683ef7044..e70c8acd2 100644 --- a/src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs @@ -5,18 +5,23 @@ using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; -namespace SixLabors.ImageSharp.Processing.Dithering.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// The base class for dither and diffusion processors that consume a palette. /// + /// The pixel format. internal abstract class PaletteDitherProcessorBase : ImageProcessor where TPixel : struct, IPixel { private readonly Dictionary> cache = new Dictionary>(); + /// + /// The vector representation of the image palette. + /// + private readonly Vector4[] paletteVector; + /// /// Initializes a new instance of the class. /// @@ -25,6 +30,8 @@ namespace SixLabors.ImageSharp.Processing.Dithering.Processors { Guard.NotNull(palette, nameof(palette)); this.Palette = palette; + this.paletteVector = new Vector4[this.Palette.Length]; + PixelOperations.Instance.ToScaledVector4(this.Palette, this.paletteVector, this.Palette.Length); } /// @@ -32,37 +39,48 @@ namespace SixLabors.ImageSharp.Processing.Dithering.Processors /// public TPixel[] Palette { get; } + /// + /// Returns the two closest colors from the palette calcluated via Euclidean distance in the Rgba space. + /// + /// The source color to match. + /// The . [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected PixelPair GetClosestPixelPair(ref TPixel pixel, TPixel[] colorPalette) + protected PixelPair GetClosestPixelPair(ref TPixel pixel) { // Check if the color is in the lookup table - if (this.cache.ContainsKey(pixel)) + if (this.cache.TryGetValue(pixel, out PixelPair value)) { - return this.cache[pixel]; + return value; } + return this.GetClosestPixelPairSlow(ref pixel); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private PixelPair GetClosestPixelPairSlow(ref TPixel pixel) + { // Not found - loop through the palette and find the nearest match. - float leastDistance = int.MaxValue; - float secondLeastDistance = int.MaxValue; + float leastDistance = float.MaxValue; + float secondLeastDistance = float.MaxValue; var vector = pixel.ToVector4(); TPixel closest = default; TPixel secondClosest = default; - for (int index = 0; index < colorPalette.Length; index++) + for (int index = 0; index < this.paletteVector.Length; index++) { - TPixel temp = colorPalette[index]; - float distance = Vector4.DistanceSquared(vector, temp.ToVector4()); + ref Vector4 candidate = ref this.paletteVector[index]; + float distance = Vector4.DistanceSquared(vector, candidate); if (distance < leastDistance) { leastDistance = distance; secondClosest = closest; - closest = temp; + closest = this.Palette[index]; } else if (distance < secondLeastDistance) { secondLeastDistance = distance; - secondClosest = temp; + secondClosest = this.Palette[index]; } } diff --git a/src/ImageSharp/Processing/Dithering/Processors/PixelPair.cs b/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs similarity index 96% rename from src/ImageSharp/Processing/Dithering/Processors/PixelPair.cs rename to src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs index 127c0be6d..b7bea2c74 100644 --- a/src/ImageSharp/Processing/Dithering/Processors/PixelPair.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs @@ -4,7 +4,7 @@ using System; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Dithering.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Represents a composite pair of pixels. Used for caching color distance lookups. diff --git a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra2Diffuser.cs b/src/ImageSharp/Processing/Processors/Dithering/Sierra2Diffuser.cs similarity index 93% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra2Diffuser.cs rename to src/ImageSharp/Processing/Processors/Dithering/Sierra2Diffuser.cs index 0b7e13c84..ebde2ceaf 100644 --- a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra2Diffuser.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/Sierra2Diffuser.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies error diffusion based dithering using the Sierra2 image dithering algorithm. diff --git a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra3Diffuser.cs b/src/ImageSharp/Processing/Processors/Dithering/Sierra3Diffuser.cs similarity index 93% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra3Diffuser.cs rename to src/ImageSharp/Processing/Processors/Dithering/Sierra3Diffuser.cs index 937b3a8cb..144a83a82 100644 --- a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra3Diffuser.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/Sierra3Diffuser.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies error diffusion based dithering using the Sierra3 image dithering algorithm. diff --git a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs b/src/ImageSharp/Processing/Processors/Dithering/SierraLiteDiffuser.cs similarity index 93% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs rename to src/ImageSharp/Processing/Processors/Dithering/SierraLiteDiffuser.cs index c9594e9e2..d71fba9f2 100644 --- a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/SierraLiteDiffuser.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies error diffusion based dithering using the SierraLite image dithering algorithm. diff --git a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs b/src/ImageSharp/Processing/Processors/Dithering/StevensonArceDiffuser.cs similarity index 93% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs rename to src/ImageSharp/Processing/Processors/Dithering/StevensonArceDiffuser.cs index 749502a03..4b1323065 100644 --- a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/StevensonArceDiffuser.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies error diffusion based dithering using the Stevenson-Arce image dithering algorithm. diff --git a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/StuckiDiffuser.cs b/src/ImageSharp/Processing/Processors/Dithering/StuckiDiffuser.cs similarity index 93% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/StuckiDiffuser.cs rename to src/ImageSharp/Processing/Processors/Dithering/StuckiDiffuser.cs index 077c02cbd..1dd510a5e 100644 --- a/src/ImageSharp/Processing/Dithering/ErrorDiffusion/StuckiDiffuser.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/StuckiDiffuser.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion +namespace SixLabors.ImageSharp.Processing.Processors.Dithering { /// /// Applies error diffusion based dithering using the Stucki image dithering algorithm. diff --git a/src/ImageSharp/Processing/Dithering/error_diffusion.txt b/src/ImageSharp/Processing/Processors/Dithering/error_diffusion.txt similarity index 100% rename from src/ImageSharp/Processing/Dithering/error_diffusion.txt rename to src/ImageSharp/Processing/Processors/Dithering/error_diffusion.txt diff --git a/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs similarity index 97% rename from src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs rename to src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs index cdaa6113f..b9329f4df 100644 --- a/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs @@ -6,11 +6,10 @@ using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Effects.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Effects { /// /// Applies oil painting effect processing to the image. @@ -112,7 +111,7 @@ namespace SixLabors.ImageSharp.Processing.Effects.Processors int currentIntensity = (int)MathF.Round((sourceBlue + sourceGreen + sourceRed) / 3F * (levels - 1)); - intensityBin[currentIntensity] += 1; + intensityBin[currentIntensity]++; blueBin[currentIntensity] += sourceBlue; greenBin[currentIntensity] += sourceGreen; redBin[currentIntensity] += sourceRed; diff --git a/src/ImageSharp/Processing/Effects/Processors/PixelateProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs similarity index 97% rename from src/ImageSharp/Processing/Effects/Processors/PixelateProcessor.cs rename to src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs index d45d2093f..56085e76c 100644 --- a/src/ImageSharp/Processing/Effects/Processors/PixelateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs @@ -7,10 +7,9 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Common; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Effects.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Effects { /// /// Applies a pixelation effect processing to the image. diff --git a/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/AchromatomalyProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/AchromatomalyProcessor.cs index e7238c68c..57c1bad39 100644 --- a/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/AchromatomalyProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness. diff --git a/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/AchromatopsiaProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/AchromatopsiaProcessor.cs index b581f8925..696a854ab 100644 --- a/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/AchromatopsiaProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness. diff --git a/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/BlackWhiteProcessor.cs similarity index 91% rename from src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/BlackWhiteProcessor.cs index 428b9d4dd..9925ce5c2 100644 --- a/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/BlackWhiteProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Applies a black and white filter matrix to the image diff --git a/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs similarity index 95% rename from src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs index e5c43bd8a..b1b8ad747 100644 --- a/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Applies a brightness filter matrix using the given amount. diff --git a/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs similarity index 95% rename from src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs index 51f8ba6b1..ebec464d5 100644 --- a/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Applies a contrast filter matrix using the given amount. diff --git a/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/DeuteranomalyProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/DeuteranomalyProcessor.cs index d93068c8c..0d1b1da90 100644 --- a/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/DeuteranomalyProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness. diff --git a/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/DeuteranopiaProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/DeuteranopiaProcessor.cs index 4b57a1fa4..ae0727048 100644 --- a/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/DeuteranopiaProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness. diff --git a/src/ImageSharp/Processing/Filters/Processors/FilterProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs similarity index 94% rename from src/ImageSharp/Processing/Filters/Processors/FilterProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs index 18163b754..e8a1fc9cb 100644 --- a/src/ImageSharp/Processing/Filters/Processors/FilterProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs @@ -6,10 +6,9 @@ using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Provides methods that accept a matrix to apply free-form filters to images. diff --git a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs b/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs similarity index 94% rename from src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs rename to src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs index b4ea8ac6b..c933d4858 100644 --- a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Applies a grayscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.601 diff --git a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs b/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs similarity index 94% rename from src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs rename to src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs index 480b134d3..1716773b4 100644 --- a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Applies a grayscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.709 diff --git a/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs index 95ae98e78..4c3a0c73e 100644 --- a/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Applies a hue filter matrix using the given angle of rotation in degrees diff --git a/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs similarity index 94% rename from src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs index 7b8ed2a03..462c42070 100644 --- a/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Applies a filter matrix that inverts the colors of an image diff --git a/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs index cc3fa42f6..003766e8a 100644 --- a/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Applies a filter matrix recreating an old Kodachrome camera effect matrix to the image diff --git a/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs similarity index 90% rename from src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs index d97bf57dd..737ebf618 100644 --- a/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Overlays.Processors; +using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Converts the colors of the image recreating an old Lomograph effect. diff --git a/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs similarity index 94% rename from src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs index f50d27ae0..0fea61cad 100644 --- a/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Applies an opacity filter matrix using the given amount. diff --git a/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs similarity index 91% rename from src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs index b6aa56223..fb065ac17 100644 --- a/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Overlays.Processors; +using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Converts the colors of the image recreating an old Polaroid effect. diff --git a/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/ProtanomalyProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/ProtanomalyProcessor.cs index 88e2ee3c3..79eb70851 100644 --- a/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/ProtanomalyProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Converts the colors of the image recreating Protanomaly (Red-Weak) color blindness. diff --git a/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/ProtanopiaProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/ProtanopiaProcessor.cs index 17020bbe2..c6a01439a 100644 --- a/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/ProtanopiaProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness. diff --git a/src/ImageSharp/Processing/Filters/Processors/README.md b/src/ImageSharp/Processing/Processors/Filters/README.md similarity index 100% rename from src/ImageSharp/Processing/Filters/Processors/README.md rename to src/ImageSharp/Processing/Processors/Filters/README.md diff --git a/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/SaturateProcessor.cs similarity index 95% rename from src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/SaturateProcessor.cs index d4b28a894..75e956071 100644 --- a/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/SaturateProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Applies a saturation filter matrix using the given amount. diff --git a/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/SepiaProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/SepiaProcessor.cs index 7295cee99..2009dccd5 100644 --- a/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/SepiaProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Applies a sepia filter matrix using the given amount. diff --git a/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/TritanomalyProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/TritanomalyProcessor.cs index 6991506e6..593f7f5b0 100644 --- a/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/TritanomalyProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Converts the colors of the image recreating Tritanomaly (Blue-Weak) color blindness. diff --git a/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/TritanopiaProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs rename to src/ImageSharp/Processing/Processors/Filters/TritanopiaProcessor.cs index 95c6cb542..153ad5559 100644 --- a/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Filters/TritanopiaProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Filters.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Filters { /// /// Converts the colors of the image recreating Tritanopia (Blue-Blind) color blindness. diff --git a/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs similarity index 96% rename from src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs rename to src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs index cc7e2ad8b..797d388c0 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs @@ -5,11 +5,10 @@ using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Overlays.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Overlays { /// /// Sets the background color of the image. diff --git a/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs rename to src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 51634ea2c..023643520 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -7,11 +7,10 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Overlays.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Overlays { /// /// An that applies a radial glow effect an . diff --git a/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs rename to src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index b73fab179..3789e6bf8 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -7,11 +7,10 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Overlays.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Overlays { /// /// An that applies a radial vignette effect to an . diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/FrameQuantizerBase{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/FrameQuantizerBase{TPixel}.cs similarity index 52% rename from src/ImageSharp/Processing/Quantization/FrameQuantizers/FrameQuantizerBase{TPixel}.cs rename to src/ImageSharp/Processing/Processors/Quantization/FrameQuantizerBase{TPixel}.cs index bf0d80b07..6e594f223 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/FrameQuantizerBase{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/FrameQuantizerBase{TPixel}.cs @@ -6,9 +6,9 @@ using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Processors.Dithering; -namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// The base class for all implementations @@ -17,11 +17,21 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers public abstract class FrameQuantizerBase : IFrameQuantizer where TPixel : struct, IPixel { + /// + /// A lookup table for colors + /// + private readonly Dictionary distanceCache = new Dictionary(); + /// /// Flag used to indicate whether a single pass or two passes are needed for quantization. /// private readonly bool singlePass; + /// + /// The vector representation of the image palette. + /// + private Vector4[] paletteVector; + /// /// Initializes a new instance of the class. /// @@ -30,10 +40,9 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// If true, the quantization process only needs to loop through the source pixels once /// /// - /// If you construct this class with a true value for singlePass, then the code will, when quantizing your image, - /// only call the methods. - /// If two passes are required, the code will also call - /// and then 'QuantizeImage'. + /// If you construct this class with a true for , then the code will + /// only call the method. + /// If two passes are required, the code will also call . /// protected FrameQuantizerBase(IQuantizer quantizer, bool singlePass) { @@ -58,7 +67,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers // Get the size of the source image int height = image.Height; int width = image.Width; - byte[] quantizedPixels = new byte[width * height]; // Call the FirstPass function if not a single pass algorithm. // For something like an Octree quantizer, this will run through @@ -69,28 +77,31 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers } // Collect the palette. Required before the second pass runs. - TPixel[] colorPalette = this.GetPalette(); + TPixel[] palette = this.GetPalette(); + this.paletteVector = new Vector4[palette.Length]; + PixelOperations.Instance.ToScaledVector4(palette, this.paletteVector, palette.Length); + var quantizedFrame = new QuantizedFrame(image.MemoryAllocator, width, height, palette); if (this.Dither) { - // We clone the image as we don't want to alter the original. + // We clone the image as we don't want to alter the original via dithering. using (ImageFrame clone = image.Clone()) { - this.SecondPass(clone, quantizedPixels, width, height); + this.SecondPass(clone, quantizedFrame.GetPixelSpan(), palette, width, height); } } else { - this.SecondPass(image, quantizedPixels, width, height); + this.SecondPass(image, quantizedFrame.GetPixelSpan(), palette, width, height); } - return new QuantizedFrame(width, height, colorPalette, quantizedPixels); + return quantizedFrame; } /// - /// Execute the first pass through the pixels in the image + /// Execute the first pass through the pixels in the image to create the palette. /// - /// The source data + /// The source data. /// The width in pixels of the image. /// The height in pixels of the image. protected virtual void FirstPass(ImageFrame source, int width, int height) @@ -98,17 +109,22 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers } /// - /// Execute a second pass through the image + /// Execute a second pass through the image to assign the pixels to a palette entry. /// /// The source image. - /// The output pixel array - /// The width in pixels of the image - /// The height in pixels of the image - protected abstract void SecondPass(ImageFrame source, byte[] output, int width, int height); + /// The output pixel array. + /// The output color palette. + /// The width in pixels of the image. + /// The height in pixels of the image. + protected abstract void SecondPass( + ImageFrame source, + Span output, + ReadOnlySpan palette, + int width, + int height); /// /// Retrieve the palette for the quantized image. - /// Can be called more than once so make sure calls are cached. /// /// /// @@ -116,29 +132,57 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers protected abstract TPixel[] GetPalette(); /// - /// Returns the closest color from the palette to the given color by calculating the Euclidean distance. + /// Returns the index of the first instance of the transparent color in the palette. + /// + /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected byte GetTransparentIndex() + { + // Transparent pixels are much more likely to be found at the end of a palette. + int index = this.paletteVector.Length - 1; + for (int i = this.paletteVector.Length - 1; i >= 0; i--) + { + ref Vector4 candidate = ref this.paletteVector[i]; + if (candidate.Equals(default)) + { + index = i; + } + } + + return (byte)index; + } + + /// + /// Returns the closest color from the palette to the given color by calculating the + /// Euclidean distance in the Rgba colorspace. /// /// The color. - /// The color palette. - /// The cache to store the result in. - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected byte GetClosestPixel(TPixel pixel, TPixel[] colorPalette, Dictionary cache) + protected byte GetClosestPixel(ref TPixel pixel) { // Check if the color is in the lookup table - if (cache.ContainsKey(pixel)) + if (this.distanceCache.TryGetValue(pixel, out byte value)) { - return cache[pixel]; + return value; } - // Not found - loop through the palette and find the nearest match. - byte colorIndex = 0; - float leastDistance = int.MaxValue; - var vector = pixel.ToVector4(); + return this.GetClosestPixelSlow(ref pixel); + } - for (int index = 0; index < colorPalette.Length; index++) + [MethodImpl(MethodImplOptions.NoInlining)] + private byte GetClosestPixelSlow(ref TPixel pixel) + { + // Loop through the palette and find the nearest match. + int colorIndex = 0; + float leastDistance = float.MaxValue; + Vector4 vector = pixel.ToScaledVector4(); + float epsilon = Constants.EpsilonSquared; + + for (int index = 0; index < this.paletteVector.Length; index++) { - float distance = Vector4.Distance(vector, colorPalette[index].ToVector4()); + ref Vector4 candidate = ref this.paletteVector[index]; + float distance = Vector4.DistanceSquared(vector, candidate); // Greater... Move on. if (!(distance < leastDistance)) @@ -146,20 +190,20 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers continue; } - colorIndex = (byte)index; + colorIndex = index; leastDistance = distance; // And if it's an exact match, exit the loop - if (MathF.Abs(distance) < Constants.Epsilon) + if (distance < epsilon) { break; } } // Now I have the index, pop it into the cache for next time - cache.Add(pixel, colorIndex); - - return colorIndex; + byte result = (byte)colorIndex; + this.distanceCache.Add(pixel, result); + return result; } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/IFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/IFrameQuantizer{TPixel}.cs similarity index 89% rename from src/ImageSharp/Processing/Quantization/FrameQuantizers/IFrameQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Processors/Quantization/IFrameQuantizer{TPixel}.cs index 435302bd3..50fdb5b58 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/IFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/IFrameQuantizer{TPixel}.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Processors.Dithering; -namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// Provides methods to allow the execution of the quantization process on an image frame. diff --git a/src/ImageSharp/Processing/Quantization/IQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/IQuantizer.cs similarity index 81% rename from src/ImageSharp/Processing/Quantization/IQuantizer.cs rename to src/ImageSharp/Processing/Processors/Quantization/IQuantizer.cs index e00b865ac..0f6846d1b 100644 --- a/src/ImageSharp/Processing/Quantization/IQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/IQuantizer.cs @@ -2,10 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -using SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers; +using SixLabors.ImageSharp.Processing.Processors.Dithering; -namespace SixLabors.ImageSharp.Processing.Quantization +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// Provides methods for allowing quantization of images pixels with configurable dithering. diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs similarity index 77% rename from src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs index e32022254..0eb3db864 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs @@ -3,12 +3,13 @@ using System; using System.Collections.Generic; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// Encapsulates methods to calculate the color palette if an image using an Octree pattern. @@ -18,11 +19,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers internal sealed class OctreeFrameQuantizer : FrameQuantizerBase where TPixel : struct, IPixel { - /// - /// A lookup table for colors - /// - private readonly Dictionary colorMap = new Dictionary(); - /// /// Maximum allowed color depth /// @@ -33,11 +29,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// private readonly Octree octree; - /// - /// The reduced image palette - /// - private TPixel[] palette; - /// /// The transparent index /// @@ -55,7 +46,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers : base(quantizer, false) { this.colors = (byte)quantizer.MaxColors; - this.octree = new Octree(this.GetBitsNeededForColorDepth(this.colors)); + this.octree = new Octree(ImageMaths.GetBitsNeededForColorDepth(this.colors).Clamp(1, 8)); } /// @@ -81,16 +72,21 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers } /// - protected override void SecondPass(ImageFrame source, byte[] output, int width, int height) + protected override void SecondPass( + ImageFrame source, + Span output, + ReadOnlySpan palette, + int width, + int height) { // Load up the values for the first pixel. We can use these to speed up the second // pass of the algorithm by avoiding transforming rows of identical color. TPixel sourcePixel = source[0, 0]; TPixel previousPixel = sourcePixel; Rgba32 rgba = default; - byte pixelValue = this.QuantizePixel(sourcePixel, ref rgba); - TPixel[] colorPalette = this.GetPalette(); - TPixel transformedPixel = colorPalette[pixelValue]; + this.transparentIndex = this.GetTransparentIndex(); + byte pixelValue = this.QuantizePixel(ref sourcePixel, ref rgba); + TPixel transformedPixel = palette[pixelValue]; for (int y = 0; y < height; y++) { @@ -107,14 +103,14 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers if (!previousPixel.Equals(sourcePixel)) { // Quantize the pixel - pixelValue = this.QuantizePixel(sourcePixel, ref rgba); + pixelValue = this.QuantizePixel(ref sourcePixel, ref rgba); // And setup the previous pointer previousPixel = sourcePixel; if (this.Dither) { - transformedPixel = colorPalette[pixelValue]; + transformedPixel = palette[pixelValue]; } } @@ -130,62 +126,26 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers } /// - protected override TPixel[] GetPalette() - { - if (this.palette == null) - { - this.palette = this.octree.Palletize(Math.Max(this.colors, (byte)1)); - this.transparentIndex = this.GetTransparentIndex(); - } - - return this.palette; - } - - /// - /// Returns the index of the first instance of the transparent color in the palette. - /// - /// - /// The . - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private byte GetTransparentIndex() - { - // Transparent pixels are much more likely to be found at the end of a palette - int index = this.colors; - Rgba32 trans = default; - for (int i = this.palette.Length - 1; i >= 0; i--) - { - this.palette[i].ToRgba32(ref trans); - - if (trans.Equals(default(Rgba32))) - { - index = i; - } - } - - return (byte)index; - } + protected override TPixel[] GetPalette() => this.octree.Palletize(this.colors); /// - /// Process the pixel in the second pass of the algorithm + /// Process the pixel in the second pass of the algorithm. /// - /// The pixel to quantize - /// The color to compare against - /// - /// The quantized value - /// + /// The pixel to quantize. + /// The color to compare against. + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - private byte QuantizePixel(TPixel pixel, ref Rgba32 rgba) + private byte QuantizePixel(ref TPixel pixel, ref Rgba32 rgba) { if (this.Dither) { - // The colors have changed so we need to use Euclidean distance calculation to find the closest value. - // This palette can never be null here. - return this.GetClosestPixel(pixel, this.palette, this.colorMap); + // The colors have changed so we need to use Euclidean distance calculation to + // find the closest value. + return this.GetClosestPixel(ref pixel); } pixel.ToRgba32(ref rgba); - if (rgba.Equals(default(Rgba32))) + if (rgba.Equals(default)) { return this.transparentIndex; } @@ -193,20 +153,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers return (byte)this.octree.GetPaletteIndex(ref pixel, ref rgba); } - /// - /// Returns how many bits are required to store the specified number of colors. - /// Performs a Log2() on the value. - /// - /// The number of colors. - /// - /// The - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private int GetBitsNeededForColorDepth(int colorCount) - { - return (int)Math.Ceiling(Math.Log(colorCount, 2)); - } - /// /// Class which does the actual quantization /// @@ -223,11 +169,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// private readonly OctreeNode root; - /// - /// Array of reducible nodes - /// - private readonly OctreeNode[] reducibleNodes; - /// /// Maximum number of significant bits in the image /// @@ -253,21 +194,32 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers { this.maxColorBits = maxColorBits; this.Leaves = 0; - this.reducibleNodes = new OctreeNode[9]; + this.ReducibleNodes = new OctreeNode[9]; this.root = new OctreeNode(0, this.maxColorBits, this); - this.previousColor = default(TPixel); + this.previousColor = default; this.previousNode = null; } /// /// Gets or sets the number of leaves in the tree /// - private int Leaves { get; set; } + public int Leaves + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + set; + } /// /// Gets the array of reducible nodes /// - private OctreeNode[] ReducibleNodes => this.reducibleNodes; + private OctreeNode[] ReducibleNodes + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; + } /// /// Add a given color value to the Octree @@ -306,6 +258,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// /// An with the palletized colors /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TPixel[] Palletize(int colorCount) { while (this.Leaves > colorCount) @@ -331,6 +284,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// /// The . /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetPaletteIndex(ref TPixel pixel, ref Rgba32 rgba) { return this.root.GetPaletteIndex(ref pixel, 0, ref rgba); @@ -342,6 +296,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// /// The node last quantized /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void TrackPrevious(OctreeNode node) { this.previousNode = node; @@ -354,14 +309,14 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers { // Find the deepest level containing at least one reducible node int index = this.maxColorBits - 1; - while ((index > 0) && (this.reducibleNodes[index] == null)) + while ((index > 0) && (this.ReducibleNodes[index] == null)) { index--; } // Reduce the node most recently added to the list at level 'index' - OctreeNode node = this.reducibleNodes[index]; - this.reducibleNodes[index] = node.NextReducible; + OctreeNode node = this.ReducibleNodes[index]; + this.ReducibleNodes[index] = node.NextReducible; // Decrement the leaf count after reducing the node this.Leaves -= node.Reduce(); @@ -450,7 +405,11 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// /// Gets the next reducible node /// - public OctreeNode NextReducible { get; } + public OctreeNode NextReducible + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; + } /// /// Add a color into the tree @@ -476,12 +435,11 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers int shift = 7 - level; pixel.ToRgba32(ref rgba); - int index = ((rgba.B & Mask[level]) >> (shift - 2)) | - ((rgba.G & Mask[level]) >> (shift - 1)) | - ((rgba.R & Mask[level]) >> shift); + int index = ((rgba.B & Mask[level]) >> (shift - 2)) + | ((rgba.G & Mask[level]) >> (shift - 1)) + | ((rgba.R & Mask[level]) >> shift); OctreeNode child = this.children[index]; - if (child == null) { // Create a new child node and store it in the array @@ -506,12 +464,13 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers // Loop through all children and add their information to this node for (int index = 0; index < 8; index++) { - if (this.children[index] != null) + OctreeNode child = this.children[index]; + if (child != null) { - this.red += this.children[index].red; - this.green += this.children[index].green; - this.blue += this.children[index].blue; - this.pixelCount += this.children[index].pixelCount; + this.red += child.red; + this.green += child.green; + this.blue += child.blue; + this.pixelCount += child.pixelCount; ++childNodes; this.children[index] = null; } @@ -529,18 +488,15 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// /// The palette /// The current palette index + [MethodImpl(MethodImplOptions.NoInlining)] public void ConstructPalette(TPixel[] palette, ref int index) { if (this.leaf) { - // This seems faster than using Vector4 - byte r = (this.red / this.pixelCount).ToByte(); - byte g = (this.green / this.pixelCount).ToByte(); - byte b = (this.blue / this.pixelCount).ToByte(); - - // And set the color of the palette entry + // Set the color of the palette entry + var vector = Vector3.Clamp(new Vector3(this.red, this.green, this.blue) / this.pixelCount, Vector3.Zero, new Vector3(255)); TPixel pixel = default; - pixel.PackFromRgba32(new Rgba32(r, g, b, 255)); + pixel.PackFromRgba32(new Rgba32((byte)vector.X, (byte)vector.Y, (byte)vector.Z, byte.MaxValue)); palette[index] = pixel; // Consume the next palette index @@ -551,10 +507,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers // Loop through children looking for leaves for (int i = 0; i < 8; i++) { - if (this.children[i] != null) - { - this.children[i].ConstructPalette(palette, ref index); - } + this.children[i]?.ConstructPalette(palette, ref index); } } } @@ -568,6 +521,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// /// The representing the index of the pixel in the palette. /// + [MethodImpl(MethodImplOptions.NoInlining)] public int GetPaletteIndex(ref TPixel pixel, int level, ref Rgba32 rgba) { int index = this.paletteIndex; @@ -577,17 +531,18 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers int shift = 7 - level; pixel.ToRgba32(ref rgba); - int pixelIndex = ((rgba.B & Mask[level]) >> (shift - 2)) | - ((rgba.G & Mask[level]) >> (shift - 1)) | - ((rgba.R & Mask[level]) >> shift); + int pixelIndex = ((rgba.B & Mask[level]) >> (shift - 2)) + | ((rgba.G & Mask[level]) >> (shift - 1)) + | ((rgba.R & Mask[level]) >> shift); - if (this.children[pixelIndex] != null) + OctreeNode child = this.children[pixelIndex]; + if (child != null) { - index = this.children[pixelIndex].GetPaletteIndex(ref pixel, level + 1, ref rgba); + index = child.GetPaletteIndex(ref pixel, level + 1, ref rgba); } else { - throw new Exception($"Cannot retrive a pixel at the given index {pixelIndex}."); + throw new Exception($"Cannot retrieve a pixel at the given index {pixelIndex}."); } } @@ -599,6 +554,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// /// The pixel to add. /// The color to map to. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Increment(ref TPixel pixel, ref Rgba32 rgba) { pixel.ToRgba32(ref rgba); diff --git a/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer.cs similarity index 92% rename from src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs rename to src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer.cs index 385ddceec..385f6246f 100644 --- a/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -using SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers; +using SixLabors.ImageSharp.Processing.Processors.Dithering; -namespace SixLabors.ImageSharp.Processing.Quantization +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// Allows the quantization of images pixels using Octrees. diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/PaletteFrameQuantizer{TPixel}.cs similarity index 65% rename from src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Processors/Quantization/PaletteFrameQuantizer{TPixel}.cs index 34cb7eb16..8df81b426 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/PaletteFrameQuantizer{TPixel}.cs @@ -2,13 +2,13 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Collections.Generic; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// Encapsulates methods to create a quantized image based upon the given palette. @@ -19,35 +19,44 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers where TPixel : struct, IPixel { /// - /// A lookup table for colors + /// The reduced image palette. /// - private readonly Dictionary colorMap = new Dictionary(); + private readonly TPixel[] palette; /// - /// List of all colors in the palette + /// The vector representation of the image palette. /// - private readonly TPixel[] colors; + private readonly Vector4[] paletteVector; /// /// Initializes a new instance of the class. /// - /// The palette quantizer - public PaletteFrameQuantizer(PaletteQuantizer quantizer) + /// The palette quantizer. + /// An array of all colors in the palette. + public PaletteFrameQuantizer(PaletteQuantizer quantizer, TPixel[] colors) : base(quantizer, true) { - this.colors = quantizer.GetPalette(); + Guard.MustBeBetweenOrEqualTo(colors.Length, 1, 256, nameof(colors)); + this.palette = colors; + this.paletteVector = new Vector4[this.palette.Length]; + PixelOperations.Instance.ToScaledVector4(this.palette, this.paletteVector, this.palette.Length); } /// - protected override void SecondPass(ImageFrame source, byte[] output, int width, int height) + protected override void SecondPass( + ImageFrame source, + Span output, + ReadOnlySpan palette, + int width, + int height) { // Load up the values for the first pixel. We can use these to speed up the second // pass of the algorithm by avoiding transforming rows of identical color. TPixel sourcePixel = source[0, 0]; TPixel previousPixel = sourcePixel; - byte pixelValue = this.QuantizePixel(sourcePixel); - ref TPixel colorPaletteRef = ref MemoryMarshal.GetReference(this.GetPalette().AsSpan()); - TPixel transformedPixel = Unsafe.Add(ref colorPaletteRef, pixelValue); + byte pixelValue = this.QuantizePixel(ref sourcePixel); + ref TPixel paletteRef = ref MemoryMarshal.GetReference(palette); + TPixel transformedPixel = Unsafe.Add(ref paletteRef, pixelValue); for (int y = 0; y < height; y++) { @@ -64,14 +73,14 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers if (!previousPixel.Equals(sourcePixel)) { // Quantize the pixel - pixelValue = this.QuantizePixel(sourcePixel); + pixelValue = this.QuantizePixel(ref sourcePixel); // And setup the previous pointer previousPixel = sourcePixel; if (this.Dither) { - transformedPixel = Unsafe.Add(ref colorPaletteRef, pixelValue); + transformedPixel = Unsafe.Add(ref paletteRef, pixelValue); } } @@ -88,10 +97,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected override TPixel[] GetPalette() - { - return this.colors; - } + protected override TPixel[] GetPalette() => this.palette; /// /// Process the pixel in the second pass of the algorithm @@ -101,9 +107,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// The quantized value /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - private byte QuantizePixel(TPixel pixel) - { - return this.GetClosestPixel(pixel, this.GetPalette(), this.colorMap); - } + private byte QuantizePixel(ref TPixel pixel) => this.GetClosestPixel(ref pixel); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs similarity index 78% rename from src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs rename to src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs index 8f790dfc9..8ae917718 100644 --- a/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs @@ -1,12 +1,11 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -using SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers; +using SixLabors.ImageSharp.Processing.Processors.Dithering; -namespace SixLabors.ImageSharp.Processing.Quantization +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// Allows the quantization of images pixels using web safe colors defined in the CSS Color Module Level 4. @@ -46,19 +45,20 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// public IErrorDiffuser Diffuser { get; } + /// + public virtual IFrameQuantizer CreateFrameQuantizer() + where TPixel : struct, IPixel + => this.CreateFrameQuantizer(() => NamedColors.WebSafePalette); + /// /// Gets the palette to use to quantize the image. /// /// The pixel format. - /// The - public virtual TPixel[] GetPalette() - where TPixel : struct, IPixel - => NamedColors.WebSafePalette; - - /// - public IFrameQuantizer CreateFrameQuantizer() + /// The method to return the palette. + /// The + public IFrameQuantizer CreateFrameQuantizer(Func paletteFunction) where TPixel : struct, IPixel - => new PaletteFrameQuantizer(this); + => new PaletteFrameQuantizer(this, paletteFunction.Invoke()); private static IErrorDiffuser GetDiffuser(bool dither) => dither ? KnownDiffusers.FloydSteinberg : null; } diff --git a/src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizeProcessor.cs similarity index 60% rename from src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs rename to src/ImageSharp/Processing/Processors/Quantization/QuantizeProcessor.cs index 951e47127..bd5a6e9ec 100644 --- a/src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizeProcessor.cs @@ -4,11 +4,9 @@ using System; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Quantization.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// Enables the quantization of images to reduce the number of colors used in the image palette. @@ -36,22 +34,24 @@ namespace SixLabors.ImageSharp.Processing.Quantization.Processors protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { IFrameQuantizer executor = this.Quantizer.CreateFrameQuantizer(); - QuantizedFrame quantized = executor.QuantizeFrame(source); - int paletteCount = quantized.Palette.Length - 1; - - // Not parallel to remove "quantized" closure allocation. - // We can operate directly on the source here as we've already read it to get the - // quantized result - for (int y = 0; y < source.Height; y++) + using (QuantizedFrame quantized = executor.QuantizeFrame(source)) { - Span row = source.GetPixelRowSpan(y); - int yy = y * source.Width; + int paletteCount = quantized.Palette.Length - 1; - for (int x = 0; x < source.Width; x++) + // Not parallel to remove "quantized" closure allocation. + // We can operate directly on the source here as we've already read it to get the + // quantized result + for (int y = 0; y < source.Height; y++) { - int i = x + yy; - TPixel color = quantized.Palette[Math.Min(paletteCount, quantized.Pixels[i])]; - row[x] = color; + Span row = source.GetPixelRowSpan(y); + ReadOnlySpan quantizedPixelSpan = quantized.GetPixelSpan(); + int yy = y * source.Width; + + for (int x = 0; x < source.Width; x++) + { + int i = x + yy; + row[x] = quantized.Palette[Math.Min(paletteCount, quantizedPixelSpan[i])]; + } } } } diff --git a/src/ImageSharp/Processing/Quantization/QuantizedFrame{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs similarity index 61% rename from src/ImageSharp/Processing/Quantization/QuantizedFrame{TPixel}.cs rename to src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs index ac87e1c7c..977b939a1 100644 --- a/src/ImageSharp/Processing/Quantization/QuantizedFrame{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs @@ -3,39 +3,36 @@ using System; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; -namespace SixLabors.ImageSharp.Processing.Quantization +// TODO: Consider pooling the TPixel palette also. For Rgba48+ this would end up on th LOH if 256 colors. +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// Represents a quantized image frame where the pixels indexed by a color palette. /// /// The pixel format. - public class QuantizedFrame + public class QuantizedFrame : IDisposable where TPixel : struct, IPixel { + private IBuffer pixels; + /// /// Initializes a new instance of the class. /// + /// Used to allocated memory for image processing operations. /// The image width. /// The image height. /// The color palette. - /// The quantized pixels. - public QuantizedFrame(int width, int height, TPixel[] palette, byte[] pixels) + public QuantizedFrame(MemoryAllocator memoryAllocator, int width, int height, TPixel[] palette) { Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); - Guard.NotNull(palette, nameof(palette)); - Guard.NotNull(pixels, nameof(pixels)); - - if (pixels.Length != width * height) - { - throw new ArgumentException($"Pixel array size must be {nameof(width)} * {nameof(height)}", nameof(pixels)); - } this.Width = width; this.Height = height; this.Palette = palette; - this.Pixels = pixels; + this.pixels = memoryAllocator.AllocateCleanManagedByteBuffer(width * height); } /// @@ -51,11 +48,20 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// /// Gets the color palette of this . /// - public TPixel[] Palette { get; } + public TPixel[] Palette { get; private set; } /// /// Gets the pixels of this . /// - public byte[] Pixels { get; } + /// The + public Span GetPixelSpan() => this.pixels.GetSpan(); + + /// + public void Dispose() + { + this.pixels?.Dispose(); + this.pixels = null; + this.Palette = null; + } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs similarity index 97% rename from src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs index 78c4bfbf8..7c2ff77e3 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs @@ -10,7 +10,7 @@ using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; -namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// An implementation of Wu's color quantizer with alpha channel. @@ -39,7 +39,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers // - Do we really need to ALWAYS allocate the whole table of size TableLength? (~ 2471625 * sizeof(long) * 5 bytes ) // - Isn't an AOS ("array of structures") layout more efficient & more readable than SOA ("structure of arrays") for this particular use case? // (T, R, G, B, A, M2) could be grouped together! - // - There are per-pixel virtual calls in InitialQuantizePixel, why not do it on a per-row basis? // - It's a frequently used class, we need tests! (So we can optimize safely.) There are tests in the original!!! We should just adopt them! // https://github.com/JeremyAnsel/JeremyAnsel.ColorQuant/blob/master/JeremyAnsel.ColorQuant/JeremyAnsel.ColorQuant.Tests/WuColorQuantizerTests.cs @@ -68,11 +67,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// private const int TableLength = IndexCount * IndexCount * IndexCount * IndexAlphaCount; - /// - /// A lookup table for colors - /// - private readonly Dictionary colorMap = new Dictionary(); - /// /// Moment of P(c). /// @@ -187,7 +181,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers float a = Volume(ref this.colorCube[k], this.vma.GetSpan()); ref TPixel color = ref this.palette[k]; - color.PackFromVector4(new Vector4(r, g, b, a) / weight / 255F); + color.PackFromScaledVector4(new Vector4(r, g, b, a) / weight / 255F); } } } @@ -251,15 +245,14 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers } /// - protected override void SecondPass(ImageFrame source, byte[] output, int width, int height) + protected override void SecondPass(ImageFrame source, Span output, ReadOnlySpan palette, int width, int height) { // Load up the values for the first pixel. We can use these to speed up the second // pass of the algorithm by avoiding transforming rows of identical color. TPixel sourcePixel = source[0, 0]; TPixel previousPixel = sourcePixel; - byte pixelValue = this.QuantizePixel(sourcePixel); - TPixel[] colorPalette = this.GetPalette(); - TPixel transformedPixel = colorPalette[pixelValue]; + byte pixelValue = this.QuantizePixel(ref sourcePixel); + TPixel transformedPixel = palette[pixelValue]; for (int y = 0; y < height; y++) { @@ -276,14 +269,14 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers if (!previousPixel.Equals(sourcePixel)) { // Quantize the pixel - pixelValue = this.QuantizePixel(sourcePixel); + pixelValue = this.QuantizePixel(ref sourcePixel); // And setup the previous pointer previousPixel = sourcePixel; if (this.Dither) { - transformedPixel = colorPalette[pixelValue]; + transformedPixel = palette[pixelValue]; } } @@ -464,6 +457,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// /// Converts the histogram into moments so that we can rapidly calculate the sums of the above quantities over any desired box. /// + /// The memory allocator used for allocating buffers. private void Get3DMoments(MemoryAllocator memoryAllocator) { Span vwtSpan = this.vwt.GetSpan(); @@ -479,7 +473,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers using (IBuffer volumeB = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) using (IBuffer volumeA = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) using (IBuffer volume2 = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) - using (IBuffer area = memoryAllocator.Allocate(IndexAlphaCount)) using (IBuffer areaR = memoryAllocator.Allocate(IndexAlphaCount)) using (IBuffer areaG = memoryAllocator.Allocate(IndexAlphaCount)) @@ -848,13 +841,13 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// The quantized value /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - private byte QuantizePixel(TPixel pixel) + private byte QuantizePixel(ref TPixel pixel) { if (this.Dither) { - // The colors have changed so we need to use Euclidean distance calculation to find the closest value. - // This palette can never be null here. - return this.GetClosestPixel(pixel, this.palette, this.colorMap); + // The colors have changed so we need to use Euclidean distance calculation to + // find the closest value. + return this.GetClosestPixel(ref pixel); } // Expected order r->g->b->a diff --git a/src/ImageSharp/Processing/Quantization/WuQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer.cs similarity index 92% rename from src/ImageSharp/Processing/Quantization/WuQuantizer.cs rename to src/ImageSharp/Processing/Processors/Quantization/WuQuantizer.cs index f46cddfe6..3aa1f4c5e 100644 --- a/src/ImageSharp/Processing/Quantization/WuQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -using SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers; +using SixLabors.ImageSharp.Processing.Processors.Dithering; -namespace SixLabors.ImageSharp.Processing.Quantization +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// Allows the quantization of images pixels using Xiaolin Wu's Color Quantizer diff --git a/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs rename to src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs index 2e1a88983..d9f35c892 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs @@ -10,11 +10,10 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Provides the base methods to perform affine transforms on an image. diff --git a/src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs rename to src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs index 68dc7f0ad..c077914ff 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs @@ -7,7 +7,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/BicubicResampler.cs similarity index 95% rename from src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/BicubicResampler.cs index dd655a8a3..199563bc7 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/BicubicResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the bicubic kernel algorithm W(x) as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/BoxResampler.cs similarity index 90% rename from src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/BoxResampler.cs index d6f79721c..0667226d9 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/BoxResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the box algorithm. Similar to nearest neighbor when upscaling. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/CatmullRomResampler.cs similarity index 92% rename from src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/CatmullRomResampler.cs index 7284bf715..8995d2d8a 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/CatmullRomResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The Catmull-Rom filter is a well known standard Cubic Filter often used as a interpolation function. diff --git a/src/ImageSharp/Processing/Transforms/Processors/CenteredAffineTransformProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/CenteredAffineTransformProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Transforms/Processors/CenteredAffineTransformProcessor.cs rename to src/ImageSharp/Processing/Processors/Transforms/CenteredAffineTransformProcessor.cs index adeed55ef..adaee1766 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/CenteredAffineTransformProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/CenteredAffineTransformProcessor.cs @@ -3,10 +3,9 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// A base class that provides methods to allow the automatic centering of affine transforms diff --git a/src/ImageSharp/Processing/Transforms/Processors/CenteredProjectiveTransformProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/CenteredProjectiveTransformProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Transforms/Processors/CenteredProjectiveTransformProcessor.cs rename to src/ImageSharp/Processing/Processors/Transforms/CenteredProjectiveTransformProcessor.cs index 5cdcde483..962b9e4c9 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/CenteredProjectiveTransformProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/CenteredProjectiveTransformProcessor.cs @@ -3,10 +3,9 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// A base class that provides methods to allow the automatic centering of non-affine transforms diff --git a/src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs similarity index 97% rename from src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs rename to src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs index 2228c69fa..5d714eef5 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs @@ -9,7 +9,7 @@ using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Provides methods to allow the cropping of an image. diff --git a/src/ImageSharp/Processing/Transforms/Processors/EntropyCropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs similarity index 89% rename from src/ImageSharp/Processing/Transforms/Processors/EntropyCropProcessor.cs rename to src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs index 66b781517..8eeae5d1f 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/EntropyCropProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs @@ -3,12 +3,11 @@ using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Binarization.Processors; -using SixLabors.ImageSharp.Processing.Convolution.Processors; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Binarization; +using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Provides methods to allow the cropping of an image to preserve areas of highest entropy. @@ -67,7 +66,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors } /// - protected override void OnFrameApply(ImageFrame sourceBase, Rectangle sourceRectangle, Configuration config) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { // All processing happens at the image level within BeforeImageApply(); } diff --git a/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs rename to src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs index 5d4961f57..4ab4971b8 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs @@ -5,11 +5,10 @@ using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Provides methods that allow the flipping of an image around its center point. @@ -21,14 +20,14 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors /// /// Initializes a new instance of the class. /// - /// The used to perform flipping. + /// The used to perform flipping. public FlipProcessor(FlipMode flipMode) { this.FlipMode = flipMode; } /// - /// Gets the used to perform flipping. + /// Gets the used to perform flipping. /// public FlipMode FlipMode { get; } diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/HermiteResampler.cs similarity index 91% rename from src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/HermiteResampler.cs index 2017a1cb5..18c3fda7c 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/HermiteResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The Hermite filter is type of smoothed triangular interpolation Filter, diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/IResampler.cs similarity index 91% rename from src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/IResampler.cs index 6bc4feaf0..6db03d5b4 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/IResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Encapsulates an interpolation algorithm for resampling images. diff --git a/src/ImageSharp/Processing/Transforms/Processors/InterpolatedTransformProcessorBase.cs b/src/ImageSharp/Processing/Processors/Transforms/InterpolatedTransformProcessorBase.cs similarity index 97% rename from src/ImageSharp/Processing/Transforms/Processors/InterpolatedTransformProcessorBase.cs rename to src/ImageSharp/Processing/Processors/Transforms/InterpolatedTransformProcessorBase.cs index 8f57f3ba3..c1abb4a5e 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/InterpolatedTransformProcessorBase.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/InterpolatedTransformProcessorBase.cs @@ -4,9 +4,8 @@ using System; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The base class for performing interpolated affine and non-affine transforms. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs b/src/ImageSharp/Processing/Processors/Transforms/Lanczos2Resampler.cs similarity index 92% rename from src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/Lanczos2Resampler.cs index 35735189a..2294696de 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Lanczos2Resampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the Lanczos kernel algorithm as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs b/src/ImageSharp/Processing/Processors/Transforms/Lanczos3Resampler.cs similarity index 92% rename from src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/Lanczos3Resampler.cs index fa85767a6..95fb206a9 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Lanczos3Resampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the Lanczos kernel algorithm as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs b/src/ImageSharp/Processing/Processors/Transforms/Lanczos5Resampler.cs similarity index 92% rename from src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/Lanczos5Resampler.cs index ec6b7181a..c99ed1e85 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Lanczos5Resampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the Lanczos kernel algorithm as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs b/src/ImageSharp/Processing/Processors/Transforms/Lanczos8Resampler.cs similarity index 92% rename from src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/Lanczos8Resampler.cs index c1f6aecf1..4efdb882b 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Lanczos8Resampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the Lanczos kernel algorithm as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/MitchellNetravaliResampler.cs similarity index 90% rename from src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/MitchellNetravaliResampler.cs index b7817400b..d4ba954f2 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/MitchellNetravaliResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the mitchell algorithm as described on diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/NearestNeighborResampler.cs similarity index 89% rename from src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/NearestNeighborResampler.cs index 61155132e..1f12334f4 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/NearestNeighborResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the nearest neighbor algorithm. This uses an unscaled filter diff --git a/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs similarity index 97% rename from src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs rename to src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs index 24a72fefb..716133fb7 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs @@ -10,12 +10,10 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Memory; using SixLabors.Primitives; -// TODO: Doesn't work yet! Implement tests + Finish implementation + Document Matrix4x4 behavior -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Provides the base methods to perform non-affine transforms on an image. diff --git a/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs rename to src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs index dfb3a82ff..8c9ab9a23 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs @@ -10,11 +10,10 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Provides methods that allow the resizing of images using various algorithms. @@ -202,7 +201,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors { // weights[w] = weights[w] / sum: ref float wRef = ref Unsafe.Add(ref weightsBaseRef, w); - wRef = wRef / sum; + wRef /= sum; } } } diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/RobidouxResampler.cs similarity index 90% rename from src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/RobidouxResampler.cs index 03a6e8677..51938566c 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RobidouxResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the Robidoux algorithm. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/RobidouxSharpResampler.cs similarity index 90% rename from src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/RobidouxSharpResampler.cs index 83213c3f4..015b7f0af 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RobidouxSharpResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the Robidoux Sharp algorithm. diff --git a/src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs rename to src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs index 62c3e476b..d57e9cbd9 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs @@ -6,10 +6,10 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Provides methods that allow the rotating of images. diff --git a/src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs similarity index 94% rename from src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs rename to src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs index 61e8b1268..a0cfa6379 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Provides methods that allow the skewing of images. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/SplineResampler.cs similarity index 90% rename from src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/SplineResampler.cs index 45f18a4a0..df6c2a338 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/SplineResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the spline algorithm. diff --git a/src/ImageSharp/Processing/Transforms/TransformHelpers.cs b/src/ImageSharp/Processing/Processors/Transforms/TransformHelpers.cs similarity index 99% rename from src/ImageSharp/Processing/Transforms/TransformHelpers.cs rename to src/ImageSharp/Processing/Processors/Transforms/TransformHelpers.cs index 71d3b35c1..1b676139b 100644 --- a/src/ImageSharp/Processing/Transforms/TransformHelpers.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/TransformHelpers.cs @@ -7,7 +7,7 @@ using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Contains helper methods for working with affine and non-affine transforms diff --git a/src/ImageSharp/Processing/Transforms/Processors/TransformProcessorBase.cs b/src/ImageSharp/Processing/Processors/Transforms/TransformProcessorBase.cs similarity index 92% rename from src/ImageSharp/Processing/Transforms/Processors/TransformProcessorBase.cs rename to src/ImageSharp/Processing/Processors/Transforms/TransformProcessorBase.cs index 0ca5ee191..13ee90a06 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/TransformProcessorBase.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/TransformProcessorBase.cs @@ -5,7 +5,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The base class for all transform processors. Any processor that changes the dimensions of the image should inherit from this. diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/TriangleResampler.cs similarity index 92% rename from src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/TriangleResampler.cs index 0fde54486..57d1fa11d 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/TriangleResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the triangle (bilinear) algorithm. diff --git a/src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs b/src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs similarity index 96% rename from src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs rename to src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs index 8c479992e..581a3353a 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs @@ -4,7 +4,7 @@ using System; using SixLabors.Memory; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Holds the values in an optimized contigous memory region. diff --git a/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs b/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs similarity index 98% rename from src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs rename to src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs index 440b19ecc..ebf2db4bf 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs @@ -7,7 +7,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.Memory; -namespace SixLabors.ImageSharp.Processing.Transforms.Processors +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// Points to a collection of of weights allocated in . diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs b/src/ImageSharp/Processing/Processors/Transforms/WelchResampler.cs similarity index 91% rename from src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs rename to src/ImageSharp/Processing/Processors/Transforms/WelchResampler.cs index 01a07fed5..edce5fcf9 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/WelchResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers +namespace SixLabors.ImageSharp.Processing.Processors.Transforms { /// /// The function implements the welch algorithm. diff --git a/src/ImageSharp/Processing/Transforms/ProjectiveTransformHelper.cs b/src/ImageSharp/Processing/ProjectiveTransformHelper.cs similarity index 99% rename from src/ImageSharp/Processing/Transforms/ProjectiveTransformHelper.cs rename to src/ImageSharp/Processing/ProjectiveTransformHelper.cs index 7c79776d9..4057ec586 100644 --- a/src/ImageSharp/Processing/Transforms/ProjectiveTransformHelper.cs +++ b/src/ImageSharp/Processing/ProjectiveTransformHelper.cs @@ -4,7 +4,7 @@ using System.Numerics; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Enumerates the various options which determine which side to taper diff --git a/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs b/src/ImageSharp/Processing/QuantizeExtensions.cs similarity index 92% rename from src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs rename to src/ImageSharp/Processing/QuantizeExtensions.cs index bf49c765a..5bd2f49bd 100644 --- a/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs +++ b/src/ImageSharp/Processing/QuantizeExtensions.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Quantization.Processors; +using SixLabors.ImageSharp.Processing.Processors.Quantization; -namespace SixLabors.ImageSharp.Processing.Quantization +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of quantizing algorithms to the type. diff --git a/src/ImageSharp/Processing/Transforms/ResizeExtensions.cs b/src/ImageSharp/Processing/ResizeExtensions.cs similarity index 98% rename from src/ImageSharp/Processing/Transforms/ResizeExtensions.cs rename to src/ImageSharp/Processing/ResizeExtensions.cs index 4317c1fc1..8a370db69 100644 --- a/src/ImageSharp/Processing/Transforms/ResizeExtensions.cs +++ b/src/ImageSharp/Processing/ResizeExtensions.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Processors; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of resize operations to the type. diff --git a/src/ImageSharp/Processing/Transforms/ResizeHelper.cs b/src/ImageSharp/Processing/ResizeHelper.cs similarity index 99% rename from src/ImageSharp/Processing/Transforms/ResizeHelper.cs rename to src/ImageSharp/Processing/ResizeHelper.cs index aca9d97d3..b9233937b 100644 --- a/src/ImageSharp/Processing/Transforms/ResizeHelper.cs +++ b/src/ImageSharp/Processing/ResizeHelper.cs @@ -5,7 +5,7 @@ using System; using System.Linq; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Provides methods to help calculate the target rectangle when resizing using the diff --git a/src/ImageSharp/Processing/Transforms/ResizeMode.cs b/src/ImageSharp/Processing/ResizeMode.cs similarity index 96% rename from src/ImageSharp/Processing/Transforms/ResizeMode.cs rename to src/ImageSharp/Processing/ResizeMode.cs index 2707b11b3..6adeac66d 100644 --- a/src/ImageSharp/Processing/Transforms/ResizeMode.cs +++ b/src/ImageSharp/Processing/ResizeMode.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Provides enumeration over how the image should be resized. diff --git a/src/ImageSharp/Processing/Transforms/ResizeOptions.cs b/src/ImageSharp/Processing/ResizeOptions.cs similarity index 92% rename from src/ImageSharp/Processing/Transforms/ResizeOptions.cs rename to src/ImageSharp/Processing/ResizeOptions.cs index c14abe2a8..0d5bfe38b 100644 --- a/src/ImageSharp/Processing/Transforms/ResizeOptions.cs +++ b/src/ImageSharp/Processing/ResizeOptions.cs @@ -3,10 +3,10 @@ using System.Collections.Generic; using System.Linq; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// The resize options for resizing images against certain modes. diff --git a/src/ImageSharp/Processing/Transforms/RotateExtensions.cs b/src/ImageSharp/Processing/RotateExtensions.cs similarity index 93% rename from src/ImageSharp/Processing/Transforms/RotateExtensions.cs rename to src/ImageSharp/Processing/RotateExtensions.cs index 28819099e..398a634d1 100644 --- a/src/ImageSharp/Processing/Transforms/RotateExtensions.cs +++ b/src/ImageSharp/Processing/RotateExtensions.cs @@ -2,10 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Processors; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of rotate operations to the type. diff --git a/src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs b/src/ImageSharp/Processing/RotateFlipExtensions.cs similarity index 95% rename from src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs rename to src/ImageSharp/Processing/RotateFlipExtensions.cs index 66bb27b36..27ddc8de9 100644 --- a/src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs +++ b/src/ImageSharp/Processing/RotateFlipExtensions.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of rotate-flip operations to the type. diff --git a/src/ImageSharp/Processing/Transforms/RotateMode.cs b/src/ImageSharp/Processing/RotateMode.cs similarity index 92% rename from src/ImageSharp/Processing/Transforms/RotateMode.cs rename to src/ImageSharp/Processing/RotateMode.cs index 6f66d0c09..c890f2bd6 100644 --- a/src/ImageSharp/Processing/Transforms/RotateMode.cs +++ b/src/ImageSharp/Processing/RotateMode.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Provides enumeration over how the image should be rotated. diff --git a/src/ImageSharp/Processing/Filters/SaturateExtensions.cs b/src/ImageSharp/Processing/SaturateExtensions.cs similarity index 95% rename from src/ImageSharp/Processing/Filters/SaturateExtensions.cs rename to src/ImageSharp/Processing/SaturateExtensions.cs index 282bdef64..ba45ae12c 100644 --- a/src/ImageSharp/Processing/Filters/SaturateExtensions.cs +++ b/src/ImageSharp/Processing/SaturateExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the alteration of the saturation component to the type. diff --git a/src/ImageSharp/Processing/Filters/SepiaExtensions.cs b/src/ImageSharp/Processing/SepiaExtensions.cs similarity index 96% rename from src/ImageSharp/Processing/Filters/SepiaExtensions.cs rename to src/ImageSharp/Processing/SepiaExtensions.cs index 09d8c3684..08676ee62 100644 --- a/src/ImageSharp/Processing/Filters/SepiaExtensions.cs +++ b/src/ImageSharp/Processing/SepiaExtensions.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Filters +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of sepia toning to the type. diff --git a/src/ImageSharp/Processing/Transforms/SkewExtensions.cs b/src/ImageSharp/Processing/SkewExtensions.cs similarity index 92% rename from src/ImageSharp/Processing/Transforms/SkewExtensions.cs rename to src/ImageSharp/Processing/SkewExtensions.cs index cbb414888..07e3c6087 100644 --- a/src/ImageSharp/Processing/Transforms/SkewExtensions.cs +++ b/src/ImageSharp/Processing/SkewExtensions.cs @@ -2,10 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Processors; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of skew operations to the type. diff --git a/src/ImageSharp/Processing/Transforms/TransformExtensions.cs b/src/ImageSharp/Processing/TransformExtensions.cs similarity index 97% rename from src/ImageSharp/Processing/Transforms/TransformExtensions.cs rename to src/ImageSharp/Processing/TransformExtensions.cs index 2607c102b..0ec1e295d 100644 --- a/src/ImageSharp/Processing/Transforms/TransformExtensions.cs +++ b/src/ImageSharp/Processing/TransformExtensions.cs @@ -3,11 +3,10 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Processors; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Transforms +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of composable transform operations to the type. diff --git a/src/ImageSharp/Processing/Overlays/VignetteExtensions.cs b/src/ImageSharp/Processing/VignetteExtensions.cs similarity index 98% rename from src/ImageSharp/Processing/Overlays/VignetteExtensions.cs rename to src/ImageSharp/Processing/VignetteExtensions.cs index 25b067d7f..18dd8064c 100644 --- a/src/ImageSharp/Processing/Overlays/VignetteExtensions.cs +++ b/src/ImageSharp/Processing/VignetteExtensions.cs @@ -3,10 +3,10 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Overlays.Processors; +using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Overlays +namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the application of a radial glow to the type. diff --git a/tests/ImageSharp.Benchmarks/Codecs/EncodeGif.cs b/tests/ImageSharp.Benchmarks/Codecs/EncodeGif.cs index 4f5bcdf0a..12e74ccdb 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/EncodeGif.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/EncodeGif.cs @@ -6,7 +6,7 @@ using System.IO; using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Quantization; using SixLabors.ImageSharp.Tests; using SDImage = System.Drawing.Image; diff --git a/tests/ImageSharp.Benchmarks/Codecs/EncodeGifMultiple.cs b/tests/ImageSharp.Benchmarks/Codecs/EncodeGifMultiple.cs index cf94a1ec3..9b94347f3 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/EncodeGifMultiple.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/EncodeGifMultiple.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Drawing.Imaging; using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.Formats.Gif; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Quantization; namespace SixLabors.ImageSharp.Benchmarks.Codecs { diff --git a/tests/ImageSharp.Benchmarks/Codecs/EncodeIndexedPng.cs b/tests/ImageSharp.Benchmarks/Codecs/EncodeIndexedPng.cs index db415d3c2..962b34eb7 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/EncodeIndexedPng.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/EncodeIndexedPng.cs @@ -5,7 +5,8 @@ using System.IO; using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Quantization; using SixLabors.ImageSharp.Tests; using CoreImage = SixLabors.ImageSharp.Image; diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs new file mode 100644 index 000000000..059f312b3 --- /dev/null +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs @@ -0,0 +1,52 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using BenchmarkDotNet.Attributes; +using System.Drawing; +using System.IO; +using SixLabors.ImageSharp.Formats.Jpeg; +using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; +using SixLabors.ImageSharp.Tests; + +namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg +{ + [Config(typeof(Config.ShortClr))] + public class DecodeJpegParseStreamOnly + { + [Params(TestImages.Jpeg.Baseline.Jpeg420Exif)] + public string TestImage { get; set; } + + private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage); + + private byte[] jpegBytes; + + [GlobalSetup] + public void Setup() + { + this.jpegBytes = File.ReadAllBytes(this.TestImageFullPath); + } + + [Benchmark(Baseline = true, Description = "System.Drawing FULL")] + public Size JpegSystemDrawing() + { + using (var memoryStream = new MemoryStream(this.jpegBytes)) + { + using (var image = System.Drawing.Image.FromStream(memoryStream)) + { + return image.Size; + } + } + } + + [Benchmark(Description = "PdfJsJpegDecoderCore.ParseStream")] + public void ParseStreamPdfJs() + { + using (var memoryStream = new MemoryStream(this.jpegBytes)) + { + var decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder() { IgnoreMetadata = true }); + decoder.ParseStream(memoryStream); + decoder.Dispose(); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs index d2f54f140..edbbceb62 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs @@ -11,7 +11,6 @@ using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; namespace SixLabors.ImageSharp.Benchmarks { diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs index a027108a1..894683599 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs @@ -3,8 +3,6 @@ // Licensed under the Apache License, Version 2.0. // -using SixLabors.ImageSharp.Processing.Drawing; - namespace SixLabors.ImageSharp.Benchmarks { using System.Drawing; diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs index ab690f645..5fbd9f112 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -11,13 +11,9 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Overlays; namespace SixLabors.ImageSharp.Benchmarks { - - public class DrawPolygon : BenchmarkBase { [Benchmark(Baseline = true, Description = "System.Drawing Draw Polygon")] diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawText.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawText.cs index 96912a6df..624b54278 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawText.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawText.cs @@ -6,15 +6,11 @@ using System.Drawing; using System.Drawing.Drawing2D; using BenchmarkDotNet.Attributes; -using System.IO; -using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Text; -using SixLabors.ImageSharp.Processing.Overlays; -using SixLabors.ImageSharp.Processing.Drawing; using System.Linq; +using SixLabors.ImageSharp.Processing.Processors.Text; namespace SixLabors.ImageSharp.Benchmarks { @@ -24,9 +20,9 @@ namespace SixLabors.ImageSharp.Benchmarks { [Params(10, 100)] - public int TextIterations{ get; set; } + public int TextIterations { get; set; } public string TextPhrase { get; set; } = "Hello World"; - public string TextToRender => string.Join(" ", Enumerable.Repeat(TextPhrase, TextIterations)); + public string TextToRender => string.Join(" ", Enumerable.Repeat(this.TextPhrase, this.TextIterations)); [Benchmark(Baseline = true, Description = "System.Drawing Draw Text")] @@ -41,7 +37,7 @@ namespace SixLabors.ImageSharp.Benchmarks graphics.SmoothingMode = SmoothingMode.AntiAlias; Pen pen = new Pen(System.Drawing.Color.HotPink, 10); var font = new Font("Arial", 12, GraphicsUnit.Point); - graphics.DrawString(TextToRender, font, Brushes.HotPink, new RectangleF(10, 10, 780, 780)); + graphics.DrawString(TextToRender, font, System.Drawing.Brushes.HotPink, new RectangleF(10, 10, 780, 780)); } } } @@ -53,7 +49,7 @@ namespace SixLabors.ImageSharp.Benchmarks using (Image image = new Image(800, 800)) { var font = SixLabors.Fonts.SystemFonts.CreateFont("Arial", 12); - image.Mutate(x => x.ApplyProcessor(new SixLabors.ImageSharp.Processing.Text.Processors.DrawTextProcessor(new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, SixLabors.ImageSharp.Processing.Drawing.Brushes.Brushes.Solid(Rgba32.HotPink), null, new SixLabors.Primitives.PointF(10, 10)))); + image.Mutate(x => x.ApplyProcessor(new DrawTextProcessor(new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, Processing.Brushes.Solid(Rgba32.HotPink), null, new SixLabors.Primitives.PointF(10, 10)))); } } @@ -63,10 +59,10 @@ namespace SixLabors.ImageSharp.Benchmarks using (Image image = new Image(800, 800)) { var font = SixLabors.Fonts.SystemFonts.CreateFont("Arial", 12); - image.Mutate(x => DrawTextOldVersion(x, new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, SixLabors.ImageSharp.Processing.Drawing.Brushes.Brushes.Solid(Rgba32.HotPink), null, new SixLabors.Primitives.PointF(10, 10))); + image.Mutate(x => DrawTextOldVersion(x, new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, Processing.Brushes.Solid(Rgba32.HotPink), null, new SixLabors.Primitives.PointF(10, 10))); } - IImageProcessingContext DrawTextOldVersion(IImageProcessingContext source, TextGraphicsOptions options, string text, SixLabors.Fonts.Font font, SixLabors.ImageSharp.Processing.Drawing.Brushes.IBrush brush, SixLabors.ImageSharp.Processing.Drawing.Pens.IPen pen, SixLabors.Primitives.PointF location) + IImageProcessingContext DrawTextOldVersion(IImageProcessingContext source, TextGraphicsOptions options, string text, SixLabors.Fonts.Font font, IBrush brush, IPen pen, SixLabors.Primitives.PointF location) where TPixel : struct, IPixel { float dpiX = 72; diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs index e85e33235..ba6d055e3 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs @@ -6,15 +6,10 @@ using System.Drawing; using System.Drawing.Drawing2D; using BenchmarkDotNet.Attributes; -using System.IO; -using System.Numerics; - using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Text; -using SixLabors.ImageSharp.Processing.Overlays; -using SixLabors.ImageSharp.Processing.Drawing; using System.Linq; +using SixLabors.ImageSharp.Processing.Processors.Text; namespace SixLabors.ImageSharp.Benchmarks { @@ -24,7 +19,7 @@ namespace SixLabors.ImageSharp.Benchmarks { [Params(10, 100)] - public int TextIterations{ get; set; } + public int TextIterations { get; set; } public string TextPhrase { get; set; } = "Hello World"; public string TextToRender => string.Join(" ", Enumerable.Repeat(TextPhrase, TextIterations)); @@ -54,7 +49,7 @@ namespace SixLabors.ImageSharp.Benchmarks using (Image image = new Image(800, 800)) { var font = SixLabors.Fonts.SystemFonts.CreateFont("Arial", 12); - image.Mutate(x => x.ApplyProcessor(new SixLabors.ImageSharp.Processing.Text.Processors.DrawTextProcessor(new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, null, SixLabors.ImageSharp.Processing.Drawing.Pens.Pens.Solid(Rgba32.HotPink, 10), new SixLabors.Primitives.PointF(10, 10)))); + image.Mutate(x => x.ApplyProcessor(new DrawTextProcessor(new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, null, Processing.Pens.Solid(Rgba32.HotPink, 10), new SixLabors.Primitives.PointF(10, 10)))); } } @@ -64,10 +59,10 @@ namespace SixLabors.ImageSharp.Benchmarks using (Image image = new Image(800, 800)) { var font = SixLabors.Fonts.SystemFonts.CreateFont("Arial", 12); - image.Mutate(x => DrawTextOldVersion(x, new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, null, SixLabors.ImageSharp.Processing.Drawing.Pens.Pens.Solid(Rgba32.HotPink, 10), new SixLabors.Primitives.PointF(10, 10))); + image.Mutate(x => DrawTextOldVersion(x, new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, null, Processing.Pens.Solid(Rgba32.HotPink, 10), new SixLabors.Primitives.PointF(10, 10))); } - IImageProcessingContext DrawTextOldVersion(IImageProcessingContext source, TextGraphicsOptions options, string text, SixLabors.Fonts.Font font, SixLabors.ImageSharp.Processing.Drawing.Brushes.IBrush brush, SixLabors.ImageSharp.Processing.Drawing.Pens.IPen pen, SixLabors.Primitives.PointF location) + IImageProcessingContext DrawTextOldVersion(IImageProcessingContext source, TextGraphicsOptions options, string text, SixLabors.Fonts.Font font, IBrush brush, IPen pen, SixLabors.Primitives.PointF location) where TPixel : struct, IPixel { var style = new SixLabors.Fonts.RendererOptions(font, options.DpiX, options.DpiY, location) diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs index c53a97515..8aadb85bf 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -12,8 +12,6 @@ using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Overlays; namespace SixLabors.ImageSharp.Benchmarks { @@ -37,7 +35,7 @@ namespace SixLabors.ImageSharp.Benchmarks using (Graphics graphics = Graphics.FromImage(destination)) { graphics.SmoothingMode = SmoothingMode.AntiAlias; - graphics.FillPolygon(Brushes.HotPink, + graphics.FillPolygon(System.Drawing.Brushes.HotPink, new[] { new Point(10, 10), diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs index 7bd55e905..643e4ac9a 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -10,8 +10,6 @@ using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Overlays; using CoreRectangle = SixLabors.Primitives.Rectangle; using CoreSize = SixLabors.Primitives.Size; @@ -31,7 +29,7 @@ namespace SixLabors.ImageSharp.Benchmarks { graphics.InterpolationMode = InterpolationMode.Default; graphics.SmoothingMode = SmoothingMode.AntiAlias; - graphics.FillRectangle(Brushes.HotPink, new Rectangle(10, 10, 190, 140)); + graphics.FillRectangle(System.Drawing.Brushes.HotPink, new Rectangle(10, 10, 190, 140)); } return destination.Size; } diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs index 059398c6c..5f8f2ff06 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs @@ -11,15 +11,11 @@ using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; - -using CoreBrushes = SixLabors.ImageSharp.Processing.Drawing.Brushes.Brushes; +using CoreBrushes = SixLabors.ImageSharp.Processing.Brushes; namespace SixLabors.ImageSharp.Benchmarks { - - public class FillWithPattern { [Benchmark(Baseline = true, Description = "System.Drawing Fill with Pattern")] @@ -30,7 +26,7 @@ namespace SixLabors.ImageSharp.Benchmarks using (Graphics graphics = Graphics.FromImage(destination)) { graphics.SmoothingMode = SmoothingMode.AntiAlias; - HatchBrush brush = new HatchBrush(HatchStyle.BackwardDiagonal, System.Drawing.Color.HotPink); + HatchBrush brush = new HatchBrush(HatchStyle.BackwardDiagonal, Color.HotPink); graphics.FillRectangle(brush, new Rectangle(0, 0, 800, 800)); // can't find a way to flood fill with a brush } using (MemoryStream ms = new MemoryStream()) diff --git a/tests/ImageSharp.Benchmarks/Samplers/Crop.cs b/tests/ImageSharp.Benchmarks/Samplers/Crop.cs index d5ac6a6f1..240a277cf 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Crop.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Crop.cs @@ -12,7 +12,6 @@ namespace SixLabors.ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Transforms; using CoreSize = SixLabors.Primitives.Size; diff --git a/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs b/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs index 569b5bc44..006d1b639 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs @@ -12,7 +12,6 @@ namespace SixLabors.ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Convolution; using CoreImage = ImageSharp.Image; diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index ce17481c4..85c4fdd7c 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Benchmarks using SixLabors.Memory; using SixLabors.Primitives; - using SixLabors.ImageSharp.Processing.Overlays.Processors; + using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.ImageSharp.Processing.Processors; public class Glow : BenchmarkBase diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs index 0a4730686..8bba227c5 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs @@ -12,7 +12,6 @@ namespace SixLabors.ImageSharp.Benchmarks using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Transforms; using CoreSize = SixLabors.Primitives.Size; diff --git a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj index 245af5289..80cf162c5 100644 --- a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj +++ b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj @@ -19,6 +19,7 @@ + diff --git a/tests/ImageSharp.Tests/ComplexIntegrationTests.cs b/tests/ImageSharp.Tests/ComplexIntegrationTests.cs index ed4bb6104..a260ec33c 100644 --- a/tests/ImageSharp.Tests/ComplexIntegrationTests.cs +++ b/tests/ImageSharp.Tests/ComplexIntegrationTests.cs @@ -1,6 +1,6 @@ using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms; +using SixLabors.ImageSharp.Processing; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs index a5fda7958..443b49c7c 100644 --- a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs @@ -5,8 +5,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Overlays; using SixLabors.Memory; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs index d0087b1d2..40ad92adc 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs @@ -5,13 +5,13 @@ using System; using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests { - using SixLabors.ImageSharp.Processing.Transforms; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Processors.Transforms; public class DrawImageTest : FileTestBase { diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index c1865e930..96af63fd5 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -4,9 +4,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Pens; -using SixLabors.ImageSharp.Processing.Overlays; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs b/tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs index 7c9fa2088..fa4d4a709 100644 --- a/tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs +++ b/tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs @@ -5,8 +5,6 @@ using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs index 9e7af1e57..3522ade7c 100644 --- a/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs @@ -8,8 +8,6 @@ using System.Text; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes; using Xunit; // ReSharper disable InconsistentNaming diff --git a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs index 29b78220d..f13f808b6 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -5,15 +5,11 @@ using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Transforms; +using SixLabors.Memory; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { - using SixLabors.Memory; - public class FillPatternBrushTests : FileTestBase { private void Test(string name, Rgba32 background, IBrush brush, Rgba32[,] expectedPattern) diff --git a/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs index eafbf3df1..7461347de 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs @@ -1,13 +1,10 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { - using System; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index c664bcf9c..dc7da3543 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -5,20 +5,16 @@ using System.Numerics; using Moq; using System; -using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Pens; -using SixLabors.ImageSharp.Processing.Drawing.Processors; using SixLabors.Primitives; using Xunit; +using SixLabors.ImageSharp.Processing.Processors.Drawing; namespace SixLabors.ImageSharp.Tests.Drawing { - + public class FillRegionProcessorTests { diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index 58fd4c767..1f01d54f4 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -3,9 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Shapes; using Xunit; // ReSharper disable InconsistentNaming diff --git a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs index ecd1c06e8..d3b39709a 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs @@ -4,9 +4,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Pens; -using SixLabors.ImageSharp.Processing.Overlays; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/LineTests.cs b/tests/ImageSharp.Tests/Drawing/LineTests.cs index 28b59746f..747c75cde 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.cs @@ -5,9 +5,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Pens; -using SixLabors.ImageSharp.Processing.Overlays; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs index ecdfd03e5..326517a4e 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPathCollection.cs @@ -4,10 +4,8 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Pens; -using SixLabors.ImageSharp.Processing.Drawing.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs index 1a402c5b7..e72fbbdf2 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -4,9 +4,8 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs index b728ea7bf..ec7a5a20c 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs @@ -4,9 +4,8 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs index 0c0fb58fa..d8927a468 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -4,9 +4,8 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs index 4c232b452..8f648e425 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs @@ -3,9 +3,8 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Drawing; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing.Paths diff --git a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs index c7a0531c9..f9a41baba 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -6,8 +6,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Overlays; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing diff --git a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs index 6ce1e2da3..2dcd8b3d3 100644 --- a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs @@ -3,8 +3,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs index 7175e7a65..94d3d49ff 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -4,8 +4,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Overlays; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs index 42b0dc1e6..c8d3fe1bc 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs @@ -5,8 +5,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Overlays; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs b/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs index 7d73d1b65..0c08f66c6 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Linq; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index b39cc4632..e42b4b481 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -6,9 +6,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Overlays; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs index 2a03eb415..76f40e0ac 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs @@ -4,11 +4,8 @@ using System.Numerics; using SixLabors.Fonts; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing.Brushes; -using SixLabors.ImageSharp.Processing.Drawing.Pens; -using SixLabors.ImageSharp.Processing.Drawing.Processors; -using SixLabors.ImageSharp.Processing.Text; -using SixLabors.ImageSharp.Processing.Text.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Text; using SixLabors.Primitives; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs index 0885dd183..44bb160ce 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs @@ -7,8 +7,6 @@ using System.Text; using SixLabors.Fonts; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing.Pens; -using SixLabors.ImageSharp.Processing.Text; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs b/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs index d710229ff..0885611c6 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Processing.Text; +using SixLabors.ImageSharp.Processing; using Xunit; diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs index d958278f6..b994af056 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs @@ -30,7 +30,11 @@ namespace SixLabors.ImageSharp.Tests using (Image image = provider.GetImage(new BmpDecoder())) { image.DebugSave(provider, "bmp"); - image.CompareToOriginal(provider); + + if (TestEnvironment.IsWindows) + { + image.CompareToOriginal(provider); + } } } @@ -52,7 +56,7 @@ namespace SixLabors.ImageSharp.Tests [InlineData(NegHeight, 24)] [InlineData(Bit8, 8)] [InlineData(Bit8Inverted, 8)] - public void DetectPixelSize(string imagePath, int expectedPixelSize) + public void Identify(string imagePath, int expectedPixelSize) { var testFile = TestFile.Create(imagePath); using (var stream = new MemoryStream(testFile.Bytes, false)) diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index 97b498ee4..23b806767 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests using SixLabors.Memory; using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Quantization; + using SixLabors.ImageSharp.Processing.Processors.Quantization; public class GeneralFormatTests : FileTestBase { @@ -83,46 +83,10 @@ namespace SixLabors.ImageSharp.Tests using (Image image = provider.GetImage()) { - image.Mutate(c => c.Quantize(quantizer)); - image.DebugSave(provider, new PngEncoder() { ColorType = PngColorType.Palette }, testOutputDetails: quantizerName); + image.DebugSave(provider, new PngEncoder() { ColorType = PngColorType.Palette, Quantizer = quantizer }, testOutputDetails: quantizerName); } provider.Configuration.MemoryAllocator.ReleaseRetainedResources(); - - //string path = TestEnvironment.CreateOutputDirectory("Quantize"); - - //foreach (TestFile file in Files) - //{ - // using (Image srcImage = Image.Load(file.Bytes, out IImageFormat mimeType)) - // { - // using (Image image = srcImage.Clone()) - // { - // using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}")) - // { - // image.Mutate(x => x.Quantize(KnownQuantizers.Octree)); - // image.Save(output, mimeType); - // } - // } - - // using (Image image = srcImage.Clone()) - // { - // using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}")) - // { - // image.Mutate(x => x.Quantize(KnownQuantizers.Wu)); - // image.Save(output, mimeType); - // } - // } - - // using (Image image = srcImage.Clone()) - // { - // using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}")) - // { - // image.Mutate(x => x.Quantize(KnownQuantizers.Palette)); - // image.Save(output, mimeType); - // } - // } - // } - //} } private static IQuantizer GetQuantizer(string name) diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs index 918d39021..2b9c11fb0 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs @@ -5,7 +5,7 @@ using System.IO; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Quantization; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit; // ReSharper disable InconsistentNaming @@ -117,5 +117,31 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif } } } + + [Theory] + [WithFile(TestImages.Gif.Cheers, PixelTypes.Rgba32)] + public void EncodeGlobalPaletteReturnsSmallerFile(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + var encoder = new GifEncoder + { + ColorTableMode = GifColorTableMode.Global, + Quantizer = new OctreeQuantizer(false) + }; + + // Always save as we need to compare the encoded output. + provider.Utility.SaveTestOutputFile(image, "gif", encoder, "global"); + + encoder.ColorTableMode = GifColorTableMode.Local; + provider.Utility.SaveTestOutputFile(image, "gif", encoder, "local"); + + var fileInfoGlobal = new FileInfo(provider.Utility.GetTestOutputFileName("gif", "global")); + var fileInfoLocal = new FileInfo(provider.Utility.GetTestOutputFileName("gif", "local")); + + Assert.True(fileInfoGlobal.Length < fileInfoLocal.Length); + } + } } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs index 539ab7319..3c98d5be7 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs @@ -38,6 +38,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg TestImages.Jpeg.Issues.NoEoiProgressive517, TestImages.Jpeg.Issues.BadRstProgressive518, TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159, + TestImages.Jpeg.Issues.DhtHasWrongLength624, }; /// diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs new file mode 100644 index 000000000..6f04ba651 --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs @@ -0,0 +1,127 @@ +using System.Buffers.Binary; +using System.IO; +using System.Text; + +using SixLabors.ImageSharp.Formats.Png; +using SixLabors.ImageSharp.PixelFormats; + +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests.Formats.Png +{ + public partial class PngDecoderTests + { + // Contains the png marker, IHDR and pHYs chunks of a 1x1 pixel 32bit png 1 a single black pixel. + private static readonly byte[] Raw1X1PngIhdrAndpHYs = + { + // PNG Identifier + 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, + + // IHDR + 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, + 0x00, 0x00, 0x00, + // IHDR CRC + 0x90, 0x77, 0x53, 0xDE, + + // pHYS + 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, + 0x00, 0x0E, 0xC3, 0x00, 0x00, 0x0E, 0xC3, 0x01, + // pHYS CRC + 0xC7, 0x6F, 0xA8, 0x64 + }; + + // Contains the png marker, IDAT and IEND chunks of a 1x1 pixel 32bit png 1 a single black pixel. + private static readonly byte[] Raw1X1PngIdatAndIend = + { + // IDAT + 0x00, 0x00, 0x00, 0x0C, 0x49, 0x44, 0x41, 0x54, 0x18, + 0x57, 0x63, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x04, + 0x00, 0x01, + + // IDAT CRC + 0x5C, 0xCD, 0xFF, 0x69, + + // IEND + 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, + + // IEND CRC + 0xAE, 0x42, 0x60, 0x82 + }; + + [Theory] + [InlineData((uint)PngChunkType.Header)] // IHDR + [InlineData((uint)PngChunkType.Palette)] // PLTE + // [InlineData(PngChunkTypes.Data)] //TODO: Figure out how to test this + [InlineData((uint)PngChunkType.End)] // IEND + public void Decode_IncorrectCRCForCriticalChunk_ExceptionIsThrown(uint chunkType) + { + string chunkName = GetChunkTypeName(chunkType); + + using (var memStream = new MemoryStream()) + { + WriteHeaderChunk(memStream); + WriteChunk(memStream, chunkName); + WriteDataChunk(memStream); + + var decoder = new PngDecoder(); + + ImageFormatException exception = + Assert.Throws(() => decoder.Decode(null, memStream)); + + Assert.Equal($"CRC Error. PNG {chunkName} chunk is corrupt!", exception.Message); + } + } + + [Theory] + [InlineData((uint)PngChunkType.Gamma)] // gAMA + [InlineData((uint)PngChunkType.PaletteAlpha)] // tRNS + [InlineData( + (uint)PngChunkType.Physical)] // pHYs: It's ok to test physical as we don't throw for duplicate chunks. + //[InlineData(PngChunkTypes.Text)] //TODO: Figure out how to test this + public void Decode_IncorrectCRCForNonCriticalChunk_ExceptionIsThrown(uint chunkType) + { + string chunkName = GetChunkTypeName(chunkType); + + using (var memStream = new MemoryStream()) + { + WriteHeaderChunk(memStream); + WriteChunk(memStream, chunkName); + WriteDataChunk(memStream); + + var decoder = new PngDecoder(); + decoder.Decode(null, memStream); + } + } + + private static string GetChunkTypeName(uint value) + { + byte[] data = new byte[4]; + + BinaryPrimitives.WriteUInt32BigEndian(data, value); + + return Encoding.ASCII.GetString(data); + } + + private static void WriteHeaderChunk(MemoryStream memStream) + { + // Writes a 1x1 32bit png header chunk containing a single black pixel + memStream.Write(Raw1X1PngIhdrAndpHYs, 0, Raw1X1PngIhdrAndpHYs.Length); + } + + private static void WriteChunk(MemoryStream memStream, string chunkName) + { + memStream.Write(new byte[] { 0, 0, 0, 1 }, 0, 4); + memStream.Write(Encoding.GetEncoding("ASCII").GetBytes(chunkName), 0, 4); + memStream.Write(new byte[] { 0, 0, 0, 0, 0 }, 0, 5); + } + + private static void WriteDataChunk(MemoryStream memStream) + { + // Writes a 1x1 32bit png data chunk containing a single black pixel + memStream.Write(Raw1X1PngIdatAndIend, 0, Raw1X1PngIdatAndIend.Length); + memStream.Position = 0; + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index 53f71fb7b..66e4f39fd 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -1,63 +1,25 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +// ReSharper disable InconsistentNaming + +using System.Buffers.Binary; using System.IO; using System.Text; + +using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + using Xunit; -// ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests.Formats.Png { - using System.Buffers.Binary; - using System.Linq; - - using SixLabors.ImageSharp.Formats.Png; - using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; - - // TODO: Fix all bugs, and re enable Skipped and commented stuff !!! - public class PngDecoderTests + public partial class PngDecoderTests { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32; - - // TODO: Cannot use exact comparer since System.Drawing doesn't preserve more than 32bits. - private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.1302F, 2134); - - // Contains the png marker, IHDR and pHYs chunks of a 1x1 pixel 32bit png 1 a single black pixel. - private static readonly byte[] raw1x1PngIHDRAndpHYs = - { - // PNG Identifier - 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, - - // IHDR - 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, - // IHDR CRC - 0x90, 0x77, 0x53, 0xDE, - - // pHYS - 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0E, 0xC3, 0x00, 0x00, 0x0E, 0xC3, 0x01, - // pHYS CRC - 0xC7, 0x6F, 0xA8, 0x64 - }; - - // Contains the png marker, IDAT and IEND chunks of a 1x1 pixel 32bit png 1 a single black pixel. - private static readonly byte[] raw1x1PngIDATAndIEND = - { - // IDAT - 0x00, 0x00, 0x00, 0x0C, 0x49, 0x44, 0x41, 0x54, 0x18, 0x57, 0x63, 0x60, 0x60, 0x60, 0x00, 0x00, - 0x00, 0x04, 0x00, 0x01, - - // IDAT CRC - 0x5C, 0xCD, 0xFF, 0x69, - - // IEND - 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, - 0x4E, 0x44, - - // IEND CRC - 0xAE, 0x42, 0x60, 0x82 - }; + + public static readonly string[] CommonTestImages = { @@ -105,30 +67,6 @@ namespace SixLabors.ImageSharp.Tests TestImages.Png.GrayTrns16BitInterlaced }; - // This is a workaround for Mono-s decoder being incompatible with ours and GDI+. - // We shouldn't mix these with the Interleaved cases (which are also failing with Mono System.Drawing). Let's go AAA! - private static readonly string[] SkipOnMono = - { - TestImages.Png.Bad.ChunkLength2, - TestImages.Png.VimImage2, - TestImages.Png.Splash, - TestImages.Png.Indexed, - TestImages.Png.Bad.ChunkLength1, - TestImages.Png.VersioningImage1, - TestImages.Png.Banner7Adam7InterlaceMode, - TestImages.Png.GrayTrns16BitInterlaced, - TestImages.Png.Rgb48BppInterlaced - }; - - private static bool SkipVerification(ITestImageProvider provider) - { - string fn = provider.SourceFileOrDescription; - - // This is a workaround for Mono-s decoder being incompatible with ours and GDI+. - // We shouldn't mix these with the Interleaved cases (which are also failing with Mono System.Drawing). Let's go AAA! - return (TestEnvironment.IsLinux || TestEnvironment.IsMono) && SkipOnMono.Contains(fn); - } - [Theory] [WithFileCollection(nameof(CommonTestImages), PixelTypes.Rgba32)] public void Decode(TestImageProvider provider) @@ -137,22 +75,7 @@ namespace SixLabors.ImageSharp.Tests using (Image image = provider.GetImage(new PngDecoder())) { image.DebugSave(provider); - - if (!SkipVerification(provider)) - { - image.CompareToOriginal(provider, ImageComparer.Exact); - } - } - } - - [Theory] - [WithFile(TestImages.Png.Interlaced, PixelTypes.Rgba32)] - public void Decode_Interlaced_DoesNotThrow(TestImageProvider provider) - where TPixel : struct, IPixel - { - using (Image image = provider.GetImage(new PngDecoder())) - { - image.DebugSave(provider); + image.CompareToOriginal(provider, ImageComparer.Exact); } } @@ -175,12 +98,8 @@ namespace SixLabors.ImageSharp.Tests { using (Image image = provider.GetImage(new PngDecoder())) { - var encoder = new PngEncoder { ColorType = PngColorType.Rgb, BitDepth = PngBitDepth.Bit16 }; - - if (!SkipVerification(provider)) - { - image.VerifyEncoder(provider, "png", null, encoder, customComparer: ValidatorComparer); - } + image.DebugSave(provider); + image.CompareToOriginal(provider, ImageComparer.Exact); } } @@ -191,12 +110,8 @@ namespace SixLabors.ImageSharp.Tests { using (Image image = provider.GetImage(new PngDecoder())) { - var encoder = new PngEncoder { ColorType = PngColorType.RgbWithAlpha, BitDepth = PngBitDepth.Bit16 }; - - if (!SkipVerification(provider)) - { - image.VerifyEncoder(provider, "png", null, encoder, customComparer: ValidatorComparer); - } + image.DebugSave(provider); + image.CompareToOriginal(provider, ImageComparer.Exact); } } @@ -207,12 +122,8 @@ namespace SixLabors.ImageSharp.Tests { using (Image image = provider.GetImage(new PngDecoder())) { - var encoder = new PngEncoder { ColorType = PngColorType.Grayscale, BitDepth = PngBitDepth.Bit16 }; - - if (!SkipVerification(provider)) - { - image.VerifyEncoder(provider, "png", null, encoder, customComparer: ValidatorComparer); - } + image.DebugSave(provider); + image.CompareToOriginal(provider, ImageComparer.Exact); } } @@ -223,12 +134,8 @@ namespace SixLabors.ImageSharp.Tests { using (Image image = provider.GetImage(new PngDecoder())) { - var encoder = new PngEncoder { ColorType = PngColorType.GrayscaleWithAlpha, BitDepth = PngBitDepth.Bit16 }; - - if (!SkipVerification(provider)) - { - image.VerifyEncoder(provider, "png", null, encoder, customComparer: ValidatorComparer); - } + image.DebugSave(provider); + image.CompareToOriginal(provider, ImageComparer.Exact); } } @@ -303,7 +210,7 @@ namespace SixLabors.ImageSharp.Tests [InlineData(TestImages.Png.Blur, 32)] [InlineData(TestImages.Png.Rgb48Bpp, 48)] [InlineData(TestImages.Png.Rgb48BppInterlaced, 48)] - public void DetectPixelSize(string imagePath, int expectedPixelSize) + public void Identify(string imagePath, int expectedPixelSize) { var testFile = TestFile.Create(imagePath); using (var stream = new MemoryStream(testFile.Bytes, false)) @@ -311,77 +218,5 @@ namespace SixLabors.ImageSharp.Tests Assert.Equal(expectedPixelSize, Image.Identify(stream)?.PixelType?.BitsPerPixel); } } - - [Theory] - [InlineData((uint)PngChunkType.Header)] // IHDR - [InlineData((uint)PngChunkType.Palette)] // PLTE - // [InlineData(PngChunkTypes.Data)] //TODO: Figure out how to test this - [InlineData((uint)PngChunkType.End)] // IEND - public void Decode_IncorrectCRCForCriticalChunk_ExceptionIsThrown(uint chunkType) - { - string chunkName = GetChunkTypeName(chunkType); - - using (var memStream = new MemoryStream()) - { - WriteHeaderChunk(memStream); - WriteChunk(memStream, chunkName); - WriteDataChunk(memStream); - - var decoder = new PngDecoder(); - - ImageFormatException exception = Assert.Throws(() => decoder.Decode(null, memStream)); - - Assert.Equal($"CRC Error. PNG {chunkName} chunk is corrupt!", exception.Message); - } - } - - [Theory] - [InlineData((uint)PngChunkType.Gamma)] // gAMA - [InlineData((uint)PngChunkType.PaletteAlpha)] // tRNS - [InlineData((uint)PngChunkType.Physical)] // pHYs: It's ok to test physical as we don't throw for duplicate chunks. - //[InlineData(PngChunkTypes.Text)] //TODO: Figure out how to test this - public void Decode_IncorrectCRCForNonCriticalChunk_ExceptionIsThrown(uint chunkType) - { - string chunkName = GetChunkTypeName(chunkType); - - using (var memStream = new MemoryStream()) - { - WriteHeaderChunk(memStream); - WriteChunk(memStream, chunkName); - WriteDataChunk(memStream); - - var decoder = new PngDecoder(); - decoder.Decode(null, memStream); - } - } - - private static string GetChunkTypeName(uint value) - { - byte[] data = new byte[4]; - - BinaryPrimitives.WriteUInt32BigEndian(data, value); - - return Encoding.ASCII.GetString(data); - } - - private static void WriteHeaderChunk(MemoryStream memStream) - { - // Writes a 1x1 32bit png header chunk containing a single black pixel - memStream.Write(raw1x1PngIHDRAndpHYs, 0, raw1x1PngIHDRAndpHYs.Length); - } - - private static void WriteChunk(MemoryStream memStream, string chunkName) - { - memStream.Write(new byte[] { 0, 0, 0, 1 }, 0, 4); - memStream.Write(Encoding.GetEncoding("ASCII").GetBytes(chunkName), 0, 4); - memStream.Write(new byte[] { 0, 0, 0, 0, 0 }, 0, 5); - } - - private static void WriteDataChunk(MemoryStream memStream) - { - // Writes a 1x1 32bit png data chunk containing a single black pixel - memStream.Write(raw1x1PngIDATAndIEND, 0, raw1x1PngIDATAndIEND.Length); - memStream.Position = 0; - } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index eb046165d..540fc0716 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -1,25 +1,26 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +// ReSharper disable InconsistentNaming using System.IO; using System.Linq; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Quantization; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit; -// ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests.Formats.Png { - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; - public class PngEncoderTests { - private const float ToleranceThresholdForPaletteEncoder = 0.2f / 100; + // This is bull. Failing online for no good reason. + // The images are an exact match. Maybe the submodule isn't updating? + private const float ToleranceThresholdForPaletteEncoder = 1.3F / 100; /// /// All types except Palette @@ -70,7 +71,12 @@ namespace SixLabors.ImageSharp.Tests public void WorksWithDifferentSizes(TestImageProvider provider, PngColorType pngColorType) where TPixel : struct, IPixel { - TestPngEncoderCore(provider, pngColorType, PngFilterMethod.Adaptive, appendPngColorType: true); + TestPngEncoderCore( + provider, + pngColorType, + PngFilterMethod.Adaptive, + PngBitDepth.Bit8, + appendPngColorType: true); } [Theory] @@ -78,7 +84,13 @@ namespace SixLabors.ImageSharp.Tests public void IsNotBoundToSinglePixelType(TestImageProvider provider, PngColorType pngColorType) where TPixel : struct, IPixel { - TestPngEncoderCore(provider, pngColorType, PngFilterMethod.Adaptive, appendPixelType: true, appendPngColorType: true); + TestPngEncoderCore( + provider, + pngColorType, + PngFilterMethod.Adaptive, + PngBitDepth.Bit8, + appendPixelType: true, + appendPngColorType: true); } [Theory] @@ -86,7 +98,12 @@ namespace SixLabors.ImageSharp.Tests public void WorksWithAllFilterMethods(TestImageProvider provider, PngFilterMethod pngFilterMethod) where TPixel : struct, IPixel { - TestPngEncoderCore(provider, PngColorType.RgbWithAlpha, pngFilterMethod, appendPngFilterMethod: true); + TestPngEncoderCore( + provider, + PngColorType.RgbWithAlpha, + pngFilterMethod, + PngBitDepth.Bit8, + appendPngFilterMethod: true); } [Theory] @@ -94,7 +111,29 @@ namespace SixLabors.ImageSharp.Tests public void WorksWithAllCompressionLevels(TestImageProvider provider, int compressionLevel) where TPixel : struct, IPixel { - TestPngEncoderCore(provider, PngColorType.RgbWithAlpha, PngFilterMethod.Adaptive, compressionLevel, appendCompressionLevel: true); + TestPngEncoderCore( + provider, + PngColorType.RgbWithAlpha, + PngFilterMethod.Adaptive, + PngBitDepth.Bit8, + compressionLevel, + appendCompressionLevel: true); + } + + [Theory] + [WithTestPatternImages(24, 24, PixelTypes.Rgba64, PngColorType.Rgb)] + [WithTestPatternImages(24, 24, PixelTypes.Rgba64, PngColorType.RgbWithAlpha)] + [WithTestPatternImages(24, 24, PixelTypes.Rgba32, PngColorType.RgbWithAlpha)] + public void WorksWithBitDepth16(TestImageProvider provider, PngColorType pngColorType) + where TPixel : struct, IPixel + { + TestPngEncoderCore( + provider, + pngColorType, + PngFilterMethod.Adaptive, + PngBitDepth.Bit16, + appendPngColorType: true, + appendPixelType: true); } [Theory] @@ -102,7 +141,13 @@ namespace SixLabors.ImageSharp.Tests public void PaletteColorType_WuQuantizer(TestImageProvider provider, int paletteSize) where TPixel : struct, IPixel { - TestPngEncoderCore(provider, PngColorType.Palette, PngFilterMethod.Adaptive, paletteSize: paletteSize, appendPaletteSize: true); + TestPngEncoderCore( + provider, + PngColorType.Palette, + PngFilterMethod.Adaptive, + PngBitDepth.Bit8, + paletteSize: paletteSize, + appendPaletteSize: true); } private static bool HasAlpha(PngColorType pngColorType) => @@ -112,6 +157,7 @@ namespace SixLabors.ImageSharp.Tests TestImageProvider provider, PngColorType pngColorType, PngFilterMethod pngFilterMethod, + PngBitDepth bitDepth, int compressionLevel = 6, int paletteSize = 255, bool appendPngColorType = false, @@ -133,6 +179,7 @@ namespace SixLabors.ImageSharp.Tests ColorType = pngColorType, FilterMethod = pngFilterMethod, CompressionLevel = compressionLevel, + BitDepth = bitDepth, Quantizer = new WuQuantizer(paletteSize) }; @@ -155,16 +202,31 @@ namespace SixLabors.ImageSharp.Tests IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(actualOutputFile); string referenceOutputFile = ((ITestImageProvider)provider).Utility.GetReferenceOutputFileName("png", debugInfo, appendPixelType, true); + bool referenceOutputFileExists = File.Exists(referenceOutputFile); + using (var actualImage = Image.Load(actualOutputFile, referenceDecoder)) - using (var referenceImage = Image.Load(referenceOutputFile, referenceDecoder)) { + // TODO: Do we still need the reference output files? + Image referenceImage = referenceOutputFileExists + ? Image.Load(referenceOutputFile, referenceDecoder) + : image; + float paletteToleranceHack = 80f / paletteSize; paletteToleranceHack = paletteToleranceHack * paletteToleranceHack; ImageComparer comparer = pngColorType == PngColorType.Palette ? ImageComparer.Tolerant(ToleranceThresholdForPaletteEncoder * paletteToleranceHack) : ImageComparer.Exact; - - comparer.VerifySimilarity(referenceImage, actualImage); + try + { + comparer.VerifySimilarity(referenceImage, actualImage); + } + finally + { + if (referenceOutputFileExists) + { + referenceImage.Dispose(); + } + } } } } diff --git a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs index e7fd21d96..81a31e42d 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs @@ -5,14 +5,12 @@ using System.IO; using Xunit; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.ImageSharp.Formats.Png; namespace SixLabors.ImageSharp.Tests.Formats.Png { - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Transforms; - public class PngSmokeTests { [Theory] diff --git a/tests/ImageSharp.Tests/Helpers/GuardTests.cs b/tests/ImageSharp.Tests/Helpers/GuardTests.cs index 42913e02d..0d1bb5ce9 100644 --- a/tests/ImageSharp.Tests/Helpers/GuardTests.cs +++ b/tests/ImageSharp.Tests/Helpers/GuardTests.cs @@ -12,13 +12,17 @@ namespace SixLabors.ImageSharp.Tests.Helpers /// public class GuardTests { + class Test + { + } + /// /// Tests that the method throws when the argument is null. /// [Fact] public void NotNullThrowsWhenArgIsNull() { - Assert.Throws(() => Guard.NotNull(null, "foo")); + Assert.Throws(() => Guard.NotNull((Test)null, "foo")); } /// @@ -27,7 +31,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers [Fact] public void NotNullThrowsWhenArgNameEmpty() { - Assert.Throws(() => Guard.NotNull(null, string.Empty)); + Assert.Throws(() => Guard.NotNull((Test)null, string.Empty)); } /// diff --git a/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs b/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs index 4e149da50..041b6c846 100644 --- a/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs @@ -1,17 +1,13 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -//using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests { - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Transforms; - public class ImageProcessingContextTests { [Fact] diff --git a/tests/ImageSharp.Tests/Image/ImageRotationTests.cs b/tests/ImageSharp.Tests/Image/ImageRotationTests.cs index 8310d67e8..e1c4a419e 100644 --- a/tests/ImageSharp.Tests/Image/ImageRotationTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageRotationTests.cs @@ -2,14 +2,12 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests { - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Transforms; - public class ImageRotationTests { [Fact] diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index e7e2577a8..9e15b6aba 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -27,6 +27,7 @@ + diff --git a/tests/ImageSharp.Tests/Issues/Issue412.cs b/tests/ImageSharp.Tests/Issues/Issue412.cs index a1bf7f36a..6123c822b 100644 --- a/tests/ImageSharp.Tests/Issues/Issue412.cs +++ b/tests/ImageSharp.Tests/Issues/Issue412.cs @@ -2,12 +2,10 @@ using Xunit; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing; namespace SixLabors.ImageSharp.Tests.Issues { - using SixLabors.ImageSharp.Processing; - public class Issue412 { [Theory] diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs index 6530850ec..a0a68a705 100644 --- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs @@ -46,8 +46,7 @@ namespace SixLabors.ImageSharp.Tests.Memory public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) return false; - return obj is CustomStruct && this.Equals((CustomStruct)obj); + return obj is CustomStruct other && this.Equals(other); } public override int GetHashCode() diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitivesTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitivesTests.cs index 880fa0607..86f308ea1 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitivesTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitivesTests.cs @@ -23,11 +23,11 @@ namespace SixLabors.ImageSharp.Tests.Icc [Theory] [MemberData(nameof(IccTestDataNonPrimitives.VersionNumberTestData), MemberType = typeof(IccTestDataNonPrimitives))] - public void ReadVersionNumber(byte[] data, Version expected) + public void ReadVersionNumber(byte[] data, IccVersion expected) { IccDataReader reader = CreateReader(data); - Version output = reader.ReadVersionNumber(); + IccVersion output = reader.ReadVersionNumber(); Assert.Equal(expected, output); } diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitivesTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitivesTests.cs index eda6a33c7..1d482e2c1 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitivesTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitivesTests.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Tests.Icc [Theory] [MemberData(nameof(IccTestDataNonPrimitives.VersionNumberTestData), MemberType = typeof(IccTestDataNonPrimitives))] - public void WriteVersionNumber(byte[] expected, Version data) + public void WriteVersionNumber(byte[] expected, IccVersion data) { IccDataWriter writer = CreateWriter(); diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs index 36473fa56..120619fb5 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs @@ -5,7 +5,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders { using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Drawing; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs index 46198991a..5f6e825f6 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs @@ -2,12 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; - -using SixLabors.ImageSharp.Processing.Binarization; -using SixLabors.ImageSharp.Processing.Binarization.Processors; -using SixLabors.ImageSharp.Processing.Dithering; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -using SixLabors.ImageSharp.Processing.Dithering.Ordered; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Binarization; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs index bf15db366..569c4ba21 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Binarization; -using SixLabors.ImageSharp.Processing.Binarization.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Binarization; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Binarization/OrderedDitherFactoryTests.cs b/tests/ImageSharp.Tests/Processing/Binarization/OrderedDitherFactoryTests.cs index 3e1a7acc0..c98f91046 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/OrderedDitherFactoryTests.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/OrderedDitherFactoryTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Dithering.Ordered; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs index 07c69a94c..e425b6315 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs @@ -2,15 +2,12 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.Primitives; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Convolution; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Convolution { - using SixLabors.ImageSharp.Processing.Convolution; - using SixLabors.ImageSharp.Processing.Convolution.Processors; - public class BoxBlurTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs index 45a5b0313..60fa19b49 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs @@ -5,15 +5,13 @@ using System.Collections.Generic; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.ImageSharp.Tests.TestUtilities; using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Convolution { - using SixLabors.ImageSharp.Processing.Convolution; - using SixLabors.ImageSharp.Processing.Convolution.Processors; - public class DetectEdgesTest : BaseImageOperationsExtensionTest { diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs index 5399a7ec8..c87a834eb 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs @@ -2,15 +2,12 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.Primitives; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Convolution; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Convolution { - using SixLabors.ImageSharp.Processing.Convolution; - using SixLabors.ImageSharp.Processing.Convolution.Processors; - public class GaussianBlurTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs index 518c2960f..675498745 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs @@ -2,15 +2,12 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.Primitives; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Convolution; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Convolution { - using SixLabors.ImageSharp.Processing.Convolution; - using SixLabors.ImageSharp.Processing.Convolution.Processors; - public class GaussianSharpenTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Convolution/Processors/LaplacianKernelFactoryTests.cs b/tests/ImageSharp.Tests/Processing/Convolution/Processors/LaplacianKernelFactoryTests.cs index 439632210..8b3524fe6 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/Processors/LaplacianKernelFactoryTests.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/Processors/LaplacianKernelFactoryTests.cs @@ -3,10 +3,10 @@ using System; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Convolution.Processors; +using SixLabors.ImageSharp.Processing.Processors.Convolution; using Xunit; -namespace SixLabors.ImageSharp.Tests.Processing.Convolution.Processors +namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution { public class LaplacianKernelFactoryTests { diff --git a/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs index e53de85fe..f393d5923 100644 --- a/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs @@ -2,10 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Dithering; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -using SixLabors.ImageSharp.Processing.Dithering.Ordered; -using SixLabors.ImageSharp.Processing.Dithering.Processors; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs index 6aa8fbba6..7775de2d2 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Overlays; -using SixLabors.ImageSharp.Processing.Overlays.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Overlays; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs index 2f4ba0516..9cd24fc6d 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Effects; -using SixLabors.ImageSharp.Processing.Effects.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Effects; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects diff --git a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs index 245e104f9..a93eaf0bc 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Effects; -using SixLabors.ImageSharp.Processing.Effects.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Effects; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects diff --git a/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs index 7e06e67d7..d651f2f04 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters diff --git a/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs index e47430efa..e210450a8 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects diff --git a/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs index ee99938bb..aeafe5fe1 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Tests.TestUtilities; diff --git a/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs index 2f9a8331d..21a552e6a 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs @@ -7,8 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects { - using SixLabors.ImageSharp.Processing.Filters; - using SixLabors.ImageSharp.Processing.Filters.Processors; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Processors.Filters; public class ContrastTest : BaseImageOperationsExtensionTest { diff --git a/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs b/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs index cac1d7057..414a0d74e 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs @@ -8,8 +8,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters { - using SixLabors.ImageSharp.Processing.Filters; - using SixLabors.ImageSharp.Processing.Filters.Processors; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Processors.Filters; public class FilterTest : BaseImageOperationsExtensionTest { diff --git a/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs index 667354b28..d63d97820 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Tests.TestUtilities; diff --git a/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs b/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs index 61220d59f..f56578dd6 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs index 61fd206db..c93afc942 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects diff --git a/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs index a0a551d09..a98252140 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters diff --git a/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs index 5bd4394ab..c104f8c25 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs @@ -9,8 +9,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests { - using SixLabors.ImageSharp.Processing.Filters; - using SixLabors.ImageSharp.Processing.Filters.Processors; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Processors.Filters; public class LomographTest : BaseImageOperationsExtensionTest { diff --git a/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs b/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs index 96811544c..adbb8cf29 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects diff --git a/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs index 4f7c410f0..f28827b71 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs b/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs index 830580fc2..4b8e80881 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters diff --git a/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs index 5e01e26f4..9351c8443 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Filters; -using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Filters; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters diff --git a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs index 4165ea24e..899082e36 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs @@ -5,8 +5,8 @@ using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Overlays; -using SixLabors.ImageSharp.Processing.Overlays.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs index bd42cf14e..f47bffe26 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs @@ -3,8 +3,8 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; -using SixLabors.ImageSharp.Processing.Overlays; -using SixLabors.ImageSharp.Processing.Overlays.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs index eb5785919..44fdfc703 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs @@ -3,10 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Binarization; -using SixLabors.ImageSharp.Processing.Dithering; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -using SixLabors.ImageSharp.Processing.Dithering.Ordered; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs index b1092782c..988c9125b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs @@ -10,7 +10,6 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization { using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Binarization; public class BinaryThresholdTest : FileTestBase { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs index b49fbf435..0c40debad 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; @@ -9,9 +10,6 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution { - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Convolution; - public class BoxBlurTest : FileTestBase { public static readonly TheoryData BoxBlurValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs index ae172a0bf..a32239d96 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -3,7 +3,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Convolution; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs index 3b6a52bb1..6bd3b34bb 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs @@ -3,7 +3,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Convolution; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs index 3d97cf0d0..8eb1f85eb 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs @@ -3,7 +3,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Convolution; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs index 24cb87c7f..9774cb50c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs @@ -5,8 +5,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Dithering; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -using SixLabors.ImageSharp.Processing.Dithering.Ordered; +using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.Primitives; using Xunit; @@ -40,7 +39,6 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization { "Stucki", KnownDiffusers.Stucki }, }; - private static IOrderedDither DefaultDitherer => KnownDitherers.BayerDither4x4; private static IErrorDiffuser DefaultErrorDiffuser => KnownDiffusers.Atkinson; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs index 1e234e81e..792c7b080 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; @@ -9,9 +10,6 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Overlays; - public class BackgroundColorTest : FileTestBase { [Theory] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs index 715e997bf..d4429aaf3 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; @@ -9,9 +10,6 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Effects; - public class OilPaintTest : FileTestBase { public static readonly TheoryData OilPaintValues = new TheoryData diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs index 84831e415..cb9a0ba0c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; @@ -9,9 +10,6 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Effects; - public class PixelateTest : FileTestBase { public static readonly TheoryData PixelateValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs index f360faff4..64aeae053 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; [GroupOutput("Filters")] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs index 14f5fa080..ed790cbac 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class BrightnessTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs index fd7724531..3d48e16ec 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs @@ -8,7 +8,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class ColorBlindnessTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs index c6afc5e11..e5e4fa4a9 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class ContrastTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs index d275c1b1a..479a3c33a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs @@ -11,7 +11,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class FilterTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs index 192034fbb..f08ec147e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs @@ -9,7 +9,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class GrayscaleTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs index 6e3fd5fef..4ce700bad 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class HueTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs index de105437b..1b4c70646 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class InvertTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs index 2265e0b0b..b7b635c2d 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class KodachromeTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs index 92c5b788c..013ec3874 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class LomographTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs index c76bf3b1d..35e405f4c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class OpacityTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs index 19fcc6788..3b39542a5 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class PolaroidTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs index 18d77660e..31fab8b65 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class SaturateTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs index 50bf0e3a1..b7d381f5f 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { - using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing; [GroupOutput("Filters")] public class SepiaTest diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs index 5c610fb31..479ee346a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; @@ -9,9 +10,6 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays { - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Overlays; - public class GlowTest : FileTestBase { [Theory] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs index 1c69b531c..3a378a095 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; @@ -9,9 +10,6 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays { - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Overlays; - public class VignetteTest : FileTestBase { [Theory] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs index bae22e7a9..d31f999d0 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs @@ -9,7 +9,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { - using SixLabors.ImageSharp.Processing.Transforms; + using SixLabors.ImageSharp.Processing; public class AutoOrientTests : FileTestBase { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs index 0936bf477..c154c8ff3 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs @@ -3,8 +3,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Transforms; - using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs index 86b37365d..728527021 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs @@ -3,8 +3,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Transforms; - using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs index 0ac8a9459..d7e7a724c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs @@ -9,7 +9,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { - using SixLabors.ImageSharp.Processing.Transforms; + using SixLabors.ImageSharp.Processing; public class FlipTests { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs index 3294ecc73..6cce62d14 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs @@ -2,13 +2,11 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Transforms; - public class PadTest : FileTestBase { [Theory] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs index ab19c21eb..d5f015404 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs @@ -7,9 +7,7 @@ using System.Text; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.ImageSharp.Processing.Transforms; -using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; using Xunit.Abstractions; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index 6a6dc45f7..c7efbb1e0 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -5,8 +5,7 @@ using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Transforms; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs index b2865d9da..d6376b179 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs @@ -7,7 +7,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { - using SixLabors.ImageSharp.Processing.Transforms; + using SixLabors.ImageSharp.Processing; public class RotateFlipTests : FileTestBase { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs index 2163f5fc9..c0db205f9 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs @@ -3,8 +3,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Transforms; - using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms @@ -25,7 +23,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms RotateMode.Rotate180, RotateMode.Rotate270 }; - + [Theory] [WithTestPatternImages(nameof(RotateAngles), 100, 50, DefaultPixelType)] [WithTestPatternImages(nameof(RotateAngles), 50, 100, DefaultPixelType)] @@ -38,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms image.DebugSave(provider, value); } } - + [Theory] [WithTestPatternImages(nameof(RotateEnumValues), 100, 50, DefaultPixelType)] [WithTestPatternImages(nameof(RotateEnumValues), 50, 100, DefaultPixelType)] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs index 30c9e682d..ae2b12e87 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs @@ -1,19 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; +using System.Collections.Generic; +using System.Reflection; + +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.ImageSharp.PixelFormats; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { - using System; - using System.Collections.Generic; - using System.Reflection; - - using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.Processing.Transforms; - using SixLabors.ImageSharp.Processing.Transforms.Resamplers; - public class SkewTest : FileTestBase { public static readonly TheoryData SkewValues diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs index fae876aff..8ec8409ad 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs @@ -4,8 +4,7 @@ using System.Reflection; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Transforms; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; @@ -14,7 +13,6 @@ using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { - public class AffineTransformTests { private readonly ITestOutputHelper Output; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs index d01e84220..bba4661db 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs @@ -7,8 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { - using SixLabors.ImageSharp.Processing.Transforms; - using SixLabors.ImageSharp.Processing.Transforms.Processors; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Processors.Transforms; public class AutoOrientTests : BaseImageOperationsExtensionTest { diff --git a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs index 78b6852e4..154167f15 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms; -using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs index 9c2176b25..03a8628a5 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms; -using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms diff --git a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs index 41aeb1ad5..39adcaa3f 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs @@ -9,8 +9,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { - using SixLabors.ImageSharp.Processing.Transforms; - using SixLabors.ImageSharp.Processing.Transforms.Processors; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Processors.Transforms; public class FlipTests : BaseImageOperationsExtensionTest { diff --git a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs index dd4c31458..82d768255 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs @@ -2,13 +2,13 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { - using SixLabors.ImageSharp.Processing.Transforms; - using SixLabors.ImageSharp.Processing.Transforms.Processors; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Processors.Transforms; public class PadTest : BaseImageOperationsExtensionTest { diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs index ece3f1742..f0a924d27 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs @@ -6,16 +6,14 @@ using System.Numerics; using System.Reflection; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Transforms; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit; +using Xunit.Abstractions; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests.Processing.Transforms { - using Xunit.Abstractions; - public class ProjectiveTransformTests { private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.03f, 3); diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs index ee72f361b..948c79d8d 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs @@ -2,9 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms; -using SixLabors.ImageSharp.Processing.Transforms.Processors; -using SixLabors.ImageSharp.Processing.Transforms.Resamplers; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs index 9a396e871..dccf7afa6 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms; -using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs index 2bf7cded8..ae312d723 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs @@ -3,9 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.ImageSharp.Processing.Transforms; -using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs index 9df8e267c..73754b971 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs @@ -3,8 +3,8 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.ImageSharp.Processing.Transforms; -using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Transforms; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs index 5de92a40b..146ed6230 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs @@ -3,8 +3,7 @@ using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Transforms; - +using SixLabors.ImageSharp.Processing.Processors.Transforms; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms diff --git a/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs b/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs index 91ba160ab..c2b1c26c5 100644 --- a/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs +++ b/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Quantization; using Xunit; @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests QuantizedFrame quantized = quantizer.CreateFrameQuantizer().QuantizeFrame(frame); int index = this.GetTransparentIndex(quantized); - Assert.Equal(index, quantized.Pixels[0]); + Assert.Equal(index, quantized.GetPixelSpan()[0]); } } } @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests QuantizedFrame quantized = quantizer.CreateFrameQuantizer().QuantizeFrame(frame); int index = this.GetTransparentIndex(quantized); - Assert.Equal(index, quantized.Pixels[0]); + Assert.Equal(index, quantized.GetPixelSpan()[0]); } } } @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests QuantizedFrame quantized = quantizer.CreateFrameQuantizer().QuantizeFrame(frame); int index = this.GetTransparentIndex(quantized); - Assert.Equal(index, quantized.Pixels[0]); + Assert.Equal(index, quantized.GetPixelSpan()[0]); } } } diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs index 3b8c3321a..f16da90c6 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs @@ -67,10 +67,10 @@ namespace SixLabors.ImageSharp.Tests #region VersionNumber - public static readonly Version VersionNumber_ValMin = new Version(0, 0, 0); - public static readonly Version VersionNumber_Val211 = new Version(2, 1, 1); - public static readonly Version VersionNumber_Val430 = new Version(4, 3, 0); - public static readonly Version VersionNumber_ValMax = new Version(255, 15, 15); + public static readonly IccVersion VersionNumber_ValMin = new IccVersion(0, 0, 0); + public static readonly IccVersion VersionNumber_Val211 = new IccVersion(2, 1, 1); + public static readonly IccVersion VersionNumber_Val430 = new IccVersion(4, 3, 0); + public static readonly IccVersion VersionNumber_ValMax = new IccVersion(255, 15, 15); public static readonly byte[] VersionNumber_Min = { 0x00, 0x00, 0x00, 0x00 }; public static readonly byte[] VersionNumber_211 = { 0x02, 0x11, 0x00, 0x00 }; diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs index 586bb818d..35ffa2bbb 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests ProfileConnectionSpace = IccColorSpaceType.CieXyz, RenderingIntent = IccRenderingIntent.AbsoluteColorimetric, Size = size, - Version = new Version(4, 3, 0), + Version = new IccVersion(4, 3, 0), }; } @@ -99,12 +99,12 @@ namespace SixLabors.ImageSharp.Tests 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // Nr of tag table entries (0) + // Nr of tag table entries (byte)(nrOfEntries >> 24), (byte)(nrOfEntries >> 16), (byte)(nrOfEntries >> 8), (byte)nrOfEntries }); } - public static byte[] Profile_Random_Array = ArrayHelper.Concat(CreateHeaderRandomArray(168, 2, Profile_Random_Id_Array), + public static readonly byte[] Profile_Random_Array = ArrayHelper.Concat(CreateHeaderRandomArray(168, 2, Profile_Random_Id_Array), new byte[] { 0x00, 0x00, 0x00, 0x00, // tag signature (Unknown) @@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.Tests IccTestDataTagDataEntry.Unknown_Arr ); - public static IccProfile Profile_Random_Val = new IccProfile(CreateHeaderRandomValue(168, + public static readonly IccProfile Profile_Random_Val = new IccProfile(CreateHeaderRandomValue(168, #if !NETSTANDARD1_1 Profile_Random_Id_Value, #else @@ -132,41 +132,110 @@ namespace SixLabors.ImageSharp.Tests IccTestDataTagDataEntry.Unknown_Val }); - public static byte[] Header_Corrupt1_Array = + public static readonly byte[] Header_CorruptDataColorSpace_Array = { - 0x81, 0xB1, 0x81, 0xE4, 0x82, 0x16, 0x82, 0x49, 0x82, 0x7B, 0x82, 0xAD, 0x82, 0xDF, 0x83, 0x11, - 0x83, 0x43, 0x83, 0x75, 0x83, 0xA7, 0x83, 0xD8, 0x84, 0x0A, 0x84, 0x3B, 0x84, 0x6C, 0x84, 0x9E, - 0x84, 0xCF, 0x85, 0x00, 0x85, 0x31, 0x85, 0x62, 0x85, 0x93, 0x85, 0xC3, 0x85, 0xF4, 0x86, 0x24, - 0x86, 0x55, 0x86, 0x85, 0x86, 0xB5, 0x86, 0xE6, 0x87, 0x16, 0x87, 0x46, 0x87, 0x76, 0x87, 0xA5, - 0x87, 0xD5, 0x88, 0x05, 0x88, 0x34, 0x88, 0x64, 0x88, 0x93, 0x88, 0xC3, 0x88, 0xF2, 0x89, 0x21, - 0x89, 0x50, 0x89, 0x7F, 0x89, 0xAE, 0x89, 0xDD, 0x8A, 0x0C, 0x8A, 0x3B, 0x8A, 0x69, 0x8A, 0x98, - 0x8A, 0xC6, 0x8A, 0xF5, 0x8B, 0x23, 0x8B, 0x51, 0x8B, 0x7F, 0x8B, 0xAE, 0x8B, 0xDC, 0x8C, 0x09, - 0x8C, 0x37, 0x8C, 0x65, 0x8C, 0x93, 0x8C, 0xC1, 0x8C, 0xEE, 0x8D, 0x1C, 0x8D, 0x49, 0x8D, 0x76, + 0x00, 0x00, 0x00, 0x80, // Size + 0x61, 0x62, 0x63, 0x64, // CmmType + 0x04, 0x30, 0x00, 0x00, // Version + 0x6D, 0x6E, 0x74, 0x72, // Class + 0x68, 0x45, 0x8D, 0x6A, // DataColorSpace + 0x58, 0x59, 0x5A, 0x20, // ProfileConnectionSpace + 0x07, 0xC6, 0x00, 0x0B, 0x00, 0x1A, 0x00, 0x07, 0x00, 0x15, 0x00, 0x2A, // CreationDate + 0x61, 0x63, 0x73, 0x70, // FileSignature + 0x4D, 0x53, 0x46, 0x54, // PrimaryPlatformSignature + 0x00, 0x00, 0x00, 0x01, // Flags + 0x07, 0x5B, 0xCD, 0x15, // DeviceManufacturer + 0x3A, 0xDE, 0x68, 0xB1, // DeviceModel + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, // DeviceAttributes + 0x00, 0x00, 0x00, 0x03, // RenderingIntent + 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // PcsIlluminant + 0x64, 0x63, 0x62, 0x61, // CreatorSignature + // Profile ID + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Padding + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, }; - public static byte[] Header_Corrupt2_Array = + public static readonly byte[] Header_CorruptProfileConnectionSpace_Array = { - 0x23, 0x74, 0x6D, 0x6D, 0xB1, 0xBC, 0x28, 0xB2, 0x6D, 0x0B, 0xA3, 0x9C, 0x2D, 0x60, 0x6C, 0xB4, - 0x96, 0xF2, 0x31, 0x88, 0x6C, 0x67, 0x8B, 0xA9, 0x35, 0x31, 0x6C, 0x24, 0x81, 0xAE, 0x38, 0x64, - 0x6B, 0xE9, 0x78, 0xEC, 0x3B, 0x28, 0x6B, 0xB7, 0x71, 0x4F, 0x3D, 0x87, 0x6B, 0x8C, 0x6A, 0xC3, - 0x3F, 0x87, 0x6B, 0x68, 0x65, 0x33, 0x41, 0x30, 0x6B, 0x4A, 0x60, 0x8C, 0x42, 0x8C, 0x6B, 0x32, - 0x5C, 0xB8, 0x43, 0xA2, 0x6B, 0x1F, 0x59, 0xA4, 0x44, 0x79, 0x6B, 0x10, 0x57, 0x3B, 0x45, 0x1A, - 0x6B, 0x05, 0x55, 0x68, 0x45, 0x8D, 0x6A, 0xFE, 0x54, 0x15, 0x45, 0xDA, 0x6A, 0xF9, 0x53, 0x2A, - 0x46, 0x16, 0x6A, 0xF5, 0x52, 0x74, 0x46, 0x27, 0x6A, 0xF4, 0x52, 0x43, 0x46, 0x27, 0x6A, 0xF4, - 0x52, 0x43, 0x46, 0x27, 0x6A, 0xF4, 0x52, 0x43, 0x46, 0x27, 0x6A, 0xF4, 0x52, 0x43, 0x46, 0x27, + 0x00, 0x00, 0x00, 0x80, // Size + 0x62, 0x63, 0x64, 0x65, // CmmType + 0x04, 0x30, 0x00, 0x00, // Version + 0x6D, 0x6E, 0x74, 0x72, // Class + 0x52, 0x47, 0x42, 0x20, // DataColorSpace + 0x68, 0x45, 0x8D, 0x6A, // ProfileConnectionSpace + 0x07, 0xC6, 0x00, 0x0B, 0x00, 0x1A, 0x00, 0x07, 0x00, 0x15, 0x00, 0x2A, // CreationDate + 0x61, 0x63, 0x73, 0x70, // FileSignature + 0x4D, 0x53, 0x46, 0x54, // PrimaryPlatformSignature + 0x00, 0x00, 0x00, 0x01, // Flags + 0x07, 0x5B, 0xCD, 0x15, // DeviceManufacturer + 0x3A, 0xDE, 0x68, 0xB1, // DeviceModel + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, // DeviceAttributes + 0x00, 0x00, 0x00, 0x03, // RenderingIntent + 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // PcsIlluminant + 0x64, 0x63, 0x62, 0x61, // CreatorSignature + // Profile ID + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Padding + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, }; + public static readonly byte[] Header_CorruptRenderingIntent_Array = + { + 0x00, 0x00, 0x00, 0x80, // Size + 0x63, 0x64, 0x65, 0x66, // CmmType + 0x04, 0x30, 0x00, 0x00, // Version + 0x6D, 0x6E, 0x74, 0x72, // Class + 0x52, 0x47, 0x42, 0x20, // DataColorSpace + 0x58, 0x59, 0x5A, 0x20, // ProfileConnectionSpace + 0x07, 0xC6, 0x00, 0x0B, 0x00, 0x1A, 0x00, 0x07, 0x00, 0x15, 0x00, 0x2A, // CreationDate + 0x61, 0x63, 0x73, 0x70, // FileSignature + 0x4D, 0x53, 0x46, 0x54, // PrimaryPlatformSignature + 0x00, 0x00, 0x00, 0x01, // Flags + 0x07, 0x5B, 0xCD, 0x15, // DeviceManufacturer + 0x3A, 0xDE, 0x68, 0xB1, // DeviceModel + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, // DeviceAttributes + 0x33, 0x41, 0x30, 0x6B, // RenderingIntent + 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // PcsIlluminant + 0x64, 0x63, 0x62, 0x61, // CreatorSignature + // Profile ID + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Padding + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + }; + + public static readonly byte[] Header_DataTooSmall_Array = new byte[127]; + + public static readonly byte[] Header_InvalidSizeSmall_Array = CreateHeaderRandomArray(127, 0, Header_Random_Id_Array); + + public static readonly byte[] Header_InvalidSizeBig_Array = CreateHeaderRandomArray(50_000_000, 0, Header_Random_Id_Array); + + public static readonly byte[] Header_SizeBiggerThanData_Array = CreateHeaderRandomArray(160, 0, Header_Random_Id_Array); - public static object[][] ProfileIdTestData = + public static readonly object[][] ProfileIdTestData = { new object[] { Header_Random_Array, Header_Random_Id_Value }, new object[] { Profile_Random_Array, Profile_Random_Id_Value }, }; - public static object[][] ProfileValidityTestData = + public static readonly object[][] ProfileValidityTestData = { - new object[] { Header_Corrupt1_Array, false }, - new object[] { Header_Corrupt2_Array, false }, + new object[] { Header_CorruptDataColorSpace_Array, false }, + new object[] { Header_CorruptProfileConnectionSpace_Array, false }, + new object[] { Header_CorruptRenderingIntent_Array, false }, + new object[] { Header_DataTooSmall_Array, false }, + new object[] { Header_InvalidSizeSmall_Array, false }, + new object[] { Header_InvalidSizeBig_Array, false }, + new object[] { Header_SizeBiggerThanData_Array, false }, new object[] { Header_Random_Array, true }, }; } diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 6d3a76e75..b0bdad8e5 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -144,6 +144,7 @@ namespace SixLabors.ImageSharp.Tests public const string NoEoiProgressive517 = "Jpg/issues/Issue517-No-EOI-Progressive.jpg"; public const string BadRstProgressive518 = "Jpg/issues/Issue518-Bad-RST-Progressive.jpg"; public const string InvalidCast520 = "Jpg/issues/Issue520-InvalidCast.jpg"; + public const string DhtHasWrongLength624 = "Jpg/issues/Issue624-DhtHasWrongLength-Progressive-N.jpg"; } public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray(); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs index 70e762585..97ed30b99 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs @@ -4,8 +4,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; - using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests diff --git a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs index 2c4eb6c33..65b32e088 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs @@ -146,7 +146,6 @@ namespace SixLabors.ImageSharp.Tests appendSourceFileOrDescription); } - /// /// Encodes image by the format matching the required extension, than saves it to the recommended output file. /// @@ -154,7 +153,9 @@ namespace SixLabors.ImageSharp.Tests /// The image instance /// The requested extension /// Optional encoder - /// /// A boolean indicating whether to append to the test output file name. + /// A value indicating whether to append the pixel type to the test output file name + /// A boolean indicating whether to append to the test output file name. + /// Additional information to append to the test output file name public string SaveTestOutputFile( Image image, string extension = null, @@ -176,6 +177,7 @@ namespace SixLabors.ImageSharp.Tests { image.Save(stream, encoder); } + return path; } diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs new file mode 100644 index 000000000..8cfc2472f --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs @@ -0,0 +1,53 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.IO; +using System.Runtime.InteropServices; + +using ImageMagick; + +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs +{ + public class MagickReferenceDecoder : IImageDecoder + { + public static MagickReferenceDecoder Instance { get; } = new MagickReferenceDecoder(); + + public Image Decode(Configuration configuration, Stream stream) + where TPixel : struct, IPixel + { + using (var magickImage = new MagickImage(stream)) + { + var result = new Image(configuration, magickImage.Width, magickImage.Height); + Span resultPixels = result.GetPixelSpan(); + + using (IPixelCollection pixels = magickImage.GetPixelsUnsafe()) + { + if (magickImage.Depth == 8) + { + byte[] data = pixels.ToByteArray("RGBA"); + + PixelOperations.Instance.PackFromRgba32Bytes(data, resultPixels, resultPixels.Length); + } + else if (magickImage.Depth == 16) + { + ushort[] data = pixels.ToShortArray("RGBA"); + Span bytes = MemoryMarshal.Cast(data.AsSpan()); + + PixelOperations.Instance.PackFromRgba64Bytes(bytes, resultPixels, resultPixels.Length); + } + else + { + throw new InvalidOperationException(); + } + } + + return result; + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs index 912333695..46dae17a1 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs @@ -20,6 +20,8 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs public static SystemDrawingReferenceEncoder Png { get; } = new SystemDrawingReferenceEncoder(ImageFormat.Png); + public static SystemDrawingReferenceEncoder Bmp { get; } = new SystemDrawingReferenceEncoder(ImageFormat.Bmp); + public void Encode(Image image, Stream stream) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs index 566c22342..90c999f7c 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs @@ -14,9 +14,9 @@ namespace SixLabors.ImageSharp.Tests { public static partial class TestEnvironment { - private static Lazy configuration = new Lazy(CreateDefaultConfiguration); + private static readonly Lazy ConfigurationLazy = new Lazy(CreateDefaultConfiguration); - internal static Configuration Configuration => configuration.Value; + internal static Configuration Configuration => ConfigurationLazy.Value; internal static IImageDecoder GetReferenceDecoder(string filePath) { @@ -52,36 +52,28 @@ namespace SixLabors.ImageSharp.Tests private static Configuration CreateDefaultConfiguration() { - var configuration = new Configuration( - new PngConfigurationModule(), + var cfg = new Configuration( new JpegConfigurationModule(), new GifConfigurationModule() ); - if (!IsLinux) - { - // TODO: System.Drawing on Windows can decode 48bit and 64bit pngs but - // it doesn't preserve the accuracy we require for comparison. - // This makes CompareToOriginal method non-useful. - configuration.ConfigureCodecs( - ImageFormats.Png, - SystemDrawingReferenceDecoder.Instance, - SystemDrawingReferenceEncoder.Png, - new PngImageFormatDetector()); + // Magick codecs should work on all platforms + IImageEncoder pngEncoder = IsWindows ? (IImageEncoder)SystemDrawingReferenceEncoder.Png : new PngEncoder(); + IImageEncoder bmpEncoder = IsWindows ? (IImageEncoder)SystemDrawingReferenceEncoder.Bmp : new BmpEncoder(); - configuration.ConfigureCodecs( - ImageFormats.Bmp, - SystemDrawingReferenceDecoder.Instance, - SystemDrawingReferenceEncoder.Png, - new PngImageFormatDetector()); - } - else - { - configuration.Configure(new PngConfigurationModule()); - configuration.Configure(new BmpConfigurationModule()); - } + cfg.ConfigureCodecs( + ImageFormats.Png, + MagickReferenceDecoder.Instance, + pngEncoder, + new PngImageFormatDetector()); - return configuration; + cfg.ConfigureCodecs( + ImageFormats.Bmp, + SystemDrawingReferenceDecoder.Instance, + bmpEncoder, + new BmpImageFormatDetector()); + + return cfg; } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs index 9a41e6602..a5a3e332c 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs @@ -21,9 +21,9 @@ namespace SixLabors.ImageSharp.Tests private const string ToolsDirectoryRelativePath = @"tests\Images\External\tools"; - private static Lazy solutionDirectoryFullPath = new Lazy(GetSolutionDirectoryFullPathImpl); + private static readonly Lazy SolutionDirectoryFullPathLazy = new Lazy(GetSolutionDirectoryFullPathImpl); - private static Lazy runsOnCi = new Lazy( + private static readonly Lazy RunsOnCiLazy = new Lazy( () => { bool isCi; @@ -41,9 +41,9 @@ namespace SixLabors.ImageSharp.Tests /// /// Gets a value indicating whether test execution runs on CI. /// - internal static bool RunsOnCI => runsOnCi.Value; + internal static bool RunsOnCI => RunsOnCiLazy.Value; - internal static string SolutionDirectoryFullPath => solutionDirectoryFullPath.Value; + internal static string SolutionDirectoryFullPath => SolutionDirectoryFullPathLazy.Value; private static string GetSolutionDirectoryFullPathImpl() { @@ -65,6 +65,7 @@ namespace SixLabors.ImageSharp.Tests $"Unable to find ImageSharp solution directory from {assemblyLocation} because of {ex.GetType().Name}!", ex); } + if (directory == null) { throw new Exception($"Unable to find ImageSharp solution directory from {assemblyLocation}!"); @@ -116,7 +117,7 @@ namespace SixLabors.ImageSharp.Tests /// internal static string CreateOutputDirectory(string path, params string[] pathParts) { - path = Path.Combine(TestEnvironment.ActualOutputDirectoryFullPath, path); + path = Path.Combine(ActualOutputDirectoryFullPath, path); if (pathParts != null && pathParts.Length > 0) { diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index 016ae7ad2..a1f97afb9 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -499,16 +499,18 @@ namespace SixLabors.ImageSharp.Tests public static Image CompareToOriginal( this Image image, - ITestImageProvider provider) + ITestImageProvider provider, + IImageDecoder referenceDecoder = null) where TPixel : struct, IPixel { - return CompareToOriginal(image, provider, ImageComparer.Tolerant()); + return CompareToOriginal(image, provider, ImageComparer.Tolerant(), referenceDecoder); } public static Image CompareToOriginal( this Image image, ITestImageProvider provider, - ImageComparer comparer) + ImageComparer comparer, + IImageDecoder referenceDecoder = null) where TPixel : struct, IPixel { string path = TestImageProvider.GetFilePathOrNull(provider); @@ -519,15 +521,8 @@ namespace SixLabors.ImageSharp.Tests var testFile = TestFile.Create(path); - IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(path); - IImageFormat format = TestEnvironment.GetImageFormat(path); - IImageDecoder defaultDecoder = Configuration.Default.ImageFormatsManager.FindDecoder(format); - - //if (referenceDecoder.GetType() == defaultDecoder.GetType()) - //{ - // throw new InvalidOperationException($"Can't use CompareToOriginal(): no actual reference decoder registered for {format.Name}"); - //} - + referenceDecoder = referenceDecoder ?? TestEnvironment.GetReferenceDecoder(path); + using (var original = Image.Load(testFile.Bytes, referenceDecoder)) { comparer.VerifySimilarity(original, image); @@ -641,7 +636,8 @@ namespace SixLabors.ImageSharp.Tests IImageEncoder encoder, ImageComparer customComparer = null, bool appendPixelTypeToFileName = true, - string referenceImageExtension = null) + string referenceImageExtension = null, + IImageDecoder referenceDecoder = null) where TPixel : struct, IPixel { string actualOutputFile = provider.Utility.SaveTestOutputFile( @@ -650,7 +646,8 @@ namespace SixLabors.ImageSharp.Tests encoder, testOutputDetails, appendPixelTypeToFileName); - IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(actualOutputFile); + + referenceDecoder = referenceDecoder ?? TestEnvironment.GetReferenceDecoder(actualOutputFile); using (var actualImage = Image.Load(actualOutputFile, referenceDecoder)) { diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs index b9fa70f22..c935a4b98 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs @@ -5,7 +5,6 @@ using Moq; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Transforms; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/MagickReferenceCodecTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/MagickReferenceCodecTests.cs new file mode 100644 index 000000000..db651886f --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/MagickReferenceCodecTests.cs @@ -0,0 +1,89 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests +{ + using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; + + using Xunit.Abstractions; + + public class MagickReferenceCodecTests + { + public MagickReferenceCodecTests(ITestOutputHelper output) + { + this.Output = output; + } + + private ITestOutputHelper Output { get; } + + public const PixelTypes PixelTypesToTest32 = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.Rgb24; + + public const PixelTypes PixelTypesToTest64 = + PixelTypes.Rgba32 | PixelTypes.Rgb24 | PixelTypes.Rgba64 | PixelTypes.Rgb48; + + public const PixelTypes PixelTypesToTest48 = + PixelTypes.Rgba32 | PixelTypes.Rgba64 | PixelTypes.Rgb48; + + [Theory] + [WithBlankImages(1, 1, PixelTypesToTest32, TestImages.Png.Splash)] + [WithBlankImages(1, 1, PixelTypesToTest32, TestImages.Png.Indexed)] + public void MagickDecode_8BitDepthImage_IsEquivalentTo_SystemDrawingResult(TestImageProvider dummyProvider, string testImage) + where TPixel : struct, IPixel + { + string path = TestFile.GetInputFileFullPath(testImage); + + var magickDecoder = new MagickReferenceDecoder(); + var sdDecoder = new SystemDrawingReferenceDecoder(); + + ImageComparer comparer = ImageComparer.Exact; + + using (var mImage = Image.Load(path, magickDecoder)) + using (var sdImage = Image.Load(path, sdDecoder)) + { + ImageSimilarityReport report = comparer.CompareImagesOrFrames(mImage, sdImage); + + mImage.DebugSave(dummyProvider); + + if (TestEnvironment.IsWindows) + { + Assert.True(report.IsEmpty); + } + } + } + + [Theory] + [WithBlankImages(1, 1, PixelTypesToTest64, TestImages.Png.Rgba64Bpp)] + [WithBlankImages(1, 1, PixelTypesToTest48, TestImages.Png.Rgb48Bpp)] + [WithBlankImages(1, 1, PixelTypesToTest48, TestImages.Png.Rgb48BppInterlaced)] + [WithBlankImages(1, 1, PixelTypesToTest48, TestImages.Png.Rgb48BppTrans)] + public void MagickDecode_16BitDepthImage_IsApproximatelyEquivalentTo_SystemDrawingResult(TestImageProvider dummyProvider, string testImage) + where TPixel : struct, IPixel + { + string path = TestFile.GetInputFileFullPath(testImage); + + var magickDecoder = new MagickReferenceDecoder(); + var sdDecoder = new SystemDrawingReferenceDecoder(); + + // 1020 == 4 * 255 (Equivalent to manhattan distance of 1+1+1+1=4 in Rgba32 space) + var comparer = ImageComparer.TolerantPercentage(1, 1020); + + using (var mImage = Image.Load(path, magickDecoder)) + using (var sdImage = Image.Load(path, sdDecoder)) + { + ImageSimilarityReport report = comparer.CompareImagesOrFrames(mImage, sdImage); + + mImage.DebugSave(dummyProvider); + + if (TestEnvironment.IsWindows) + { + Assert.True(report.IsEmpty); + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceDecoderBenchmarks.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceDecoderBenchmarks.cs new file mode 100644 index 000000000..724c2e414 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceDecoderBenchmarks.cs @@ -0,0 +1,96 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Collections.Generic; + +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; + +using Xunit; +using Xunit.Abstractions; + +namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests +{ + public class ReferenceDecoderBenchmarks + { + private ITestOutputHelper Output { get; } + + public const string SkipBenchmarks = +#if false + "Benchmark, enable manually!"; +#else + null; +#endif + + public const int DefaultExecutionCount = 50; + + public static readonly string[] PngBenchmarkFiles = + { + TestImages.Png.CalliphoraPartial, + TestImages.Png.Kaboom, + TestImages.Png.Bike, + TestImages.Png.Splash, + TestImages.Png.SplashInterlaced + }; + + public static readonly string[] BmpBenchmarkFiles = + { + TestImages.Bmp.NegHeight, + TestImages.Bmp.Car, + TestImages.Bmp.V5Header + }; + + public ReferenceDecoderBenchmarks(ITestOutputHelper output) + { + this.Output = output; + } + + [Theory(Skip = SkipBenchmarks)] + [WithFile(TestImages.Png.Kaboom, PixelTypes.Rgba32)] + public void BenchmarkMagickPngDecoder(TestImageProvider provider) + where TPixel : struct, IPixel + { + this.BenckmarkDecoderImpl(PngBenchmarkFiles, new MagickReferenceDecoder(), $@"Magick Decode Png"); + } + + [Theory(Skip = SkipBenchmarks)] + [WithFile(TestImages.Png.Kaboom, PixelTypes.Rgba32)] + public void BenchmarkSystemDrawingPngDecoder(TestImageProvider provider) + where TPixel : struct, IPixel + { + this.BenckmarkDecoderImpl(PngBenchmarkFiles, new SystemDrawingReferenceDecoder(), $@"System.Drawing Decode Png"); + } + + [Theory(Skip = SkipBenchmarks)] + [WithFile(TestImages.Png.Kaboom, PixelTypes.Rgba32)] + public void BenchmarkMagickBmpDecoder(TestImageProvider provider) + where TPixel : struct, IPixel + { + this.BenckmarkDecoderImpl(BmpBenchmarkFiles, new MagickReferenceDecoder(), $@"Magick Decode Bmp"); + } + + [Theory(Skip = SkipBenchmarks)] + [WithFile(TestImages.Png.Kaboom, PixelTypes.Rgba32)] + public void BenchmarkSystemDrawingBmpDecoder(TestImageProvider provider) + where TPixel : struct, IPixel + { + this.BenckmarkDecoderImpl(BmpBenchmarkFiles, new SystemDrawingReferenceDecoder(), $@"System.Drawing Decode Bmp"); + } + + private void BenckmarkDecoderImpl(IEnumerable testFiles, IImageDecoder decoder, string info, int times = DefaultExecutionCount) + { + var measure = new MeasureFixture(this.Output); + measure.Measure(times, + () => + { + foreach (string testFile in testFiles) + { + Image image = TestFile.Create(testFile).CreateImage(decoder); + image.Dispose(); + } + }, + info); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/SystemDrawingReferenceCodecTests.cs similarity index 94% rename from tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs rename to tests/ImageSharp.Tests/TestUtilities/Tests/SystemDrawingReferenceCodecTests.cs index 3ad595b7e..3cdb67dbd 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/SystemDrawingReferenceCodecTests.cs @@ -1,4 +1,6 @@ -using System.IO; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; @@ -8,13 +10,13 @@ using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; using Xunit; using Xunit.Abstractions; -namespace SixLabors.ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests { - public class ReferenceCodecTests + public class SystemDrawingReferenceCodecTests { private ITestOutputHelper Output { get; } - public ReferenceCodecTests(ITestOutputHelper output) + public SystemDrawingReferenceCodecTests(ITestOutputHelper output) { this.Output = output; } diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs index f6d3bdb7b..8a3e69059 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs @@ -18,7 +18,6 @@ using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests { - public class TestEnvironmentTests { public TestEnvironmentTests(ITestOutputHelper output) @@ -99,7 +98,7 @@ namespace SixLabors.ImageSharp.Tests } [Theory] - [InlineData("lol/foo.png", typeof(SystemDrawingReferenceDecoder))] + [InlineData("lol/foo.png", typeof(MagickReferenceDecoder))] [InlineData("lol/Rofl.bmp", typeof(SystemDrawingReferenceDecoder))] [InlineData("lol/Baz.JPG", typeof(JpegDecoder))] [InlineData("lol/Baz.gif", typeof(GifDecoder))] @@ -125,8 +124,8 @@ namespace SixLabors.ImageSharp.Tests } [Theory] - [InlineData("lol/foo.png", typeof(PngDecoder))] - [InlineData("lol/Rofl.bmp", typeof(BmpDecoder))] + [InlineData("lol/foo.png", typeof(MagickReferenceDecoder))] + [InlineData("lol/Rofl.bmp", typeof(SystemDrawingReferenceDecoder))] [InlineData("lol/Baz.JPG", typeof(JpegDecoder))] [InlineData("lol/Baz.gif", typeof(GifDecoder))] public void GetReferenceDecoder_ReturnsCorrectDecoders_Linux(string fileName, Type expectedDecoderType) diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index 06c77235b..02acdfa18 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -241,7 +241,11 @@ namespace SixLabors.ImageSharp.Tests } - public static string[] AllBmpFiles => TestImages.Bmp.All; + public static string[] AllBmpFiles = + { + TestImages.Bmp.F, + TestImages.Bmp.Bit8 + }; [Theory] [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Rgba32 | PixelTypes.Argb32)] diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index cab61bc59..6e8278276 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -7,15 +7,14 @@ using System.Linq; using System.Numerics; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.Memory; using Xunit; using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests { - using SixLabors.ImageSharp.Processing.Effects; - using SixLabors.Memory; - public class TestUtilityExtensionsTests { public TestUtilityExtensionsTests(ITestOutputHelper output) @@ -55,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests where TPixel : struct, IPixel { Image a = provider.GetImage(); - Image b = provider.GetImage(x=>x.OilPaint(3, 2)); + Image b = provider.GetImage(x => x.OilPaint(3, 2)); Assert.False(a.IsEquivalentTo(b, compareAlpha)); } diff --git a/tests/Images/External b/tests/Images/External index 6fcee2ccd..98fb7e2e4 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 6fcee2ccd5e8bac98a0290b467ad86bb02d00b6c +Subproject commit 98fb7e2e4d5935b1c733bd2b206b6145b71ef378 diff --git a/tests/Images/Input/Jpg/issues/Issue624-DhtHasWrongLength-Progressive-N.jpg b/tests/Images/Input/Jpg/issues/Issue624-DhtHasWrongLength-Progressive-N.jpg new file mode 100644 index 000000000..20a50fba9 --- /dev/null +++ b/tests/Images/Input/Jpg/issues/Issue624-DhtHasWrongLength-Progressive-N.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da574d176b964eba84b5decb1e88a35d425e09975e0bc0ca73e485604179868f +size 30441