From 2278789736ae646eb1d8195efbbf1d66b905733f Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 24 Jun 2018 01:46:23 +1000 Subject: [PATCH 01/68] Create new DensityUnits enum. --- src/ImageSharp/Formats/DensityUnits.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/ImageSharp/Formats/DensityUnits.cs diff --git a/src/ImageSharp/Formats/DensityUnits.cs b/src/ImageSharp/Formats/DensityUnits.cs new file mode 100644 index 000000000..ce30bd06c --- /dev/null +++ b/src/ImageSharp/Formats/DensityUnits.cs @@ -0,0 +1,26 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.Formats +{ + /// + /// Provides enumeration of available pixel density units. + /// + public enum DensityUnits : byte + { + /// + /// No units; width:height pixel aspect ratio = Ydensity:Xdensity + /// + AspectRatio = 0, + + /// + /// Pixels per inch (2.54 cm) + /// + PixelsPerInch = 1, // Other image formats would default to this. + + /// + /// Pixels per centimeter. + /// + PixelsPerCentimeter = 2 + } +} From d41ece14326d83c93edfc8b57166573953612d90 Mon Sep 17 00:00:00 2001 From: popow Date: Sat, 30 Jun 2018 15:46:22 +0200 Subject: [PATCH 02/68] added first attempt of histogram equalization --- .../HistogramEqualizationExtension.cs | 23 +++++++ .../HistogramEqualizationProcessor.cs | 64 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/ImageSharp/Processing/Contrast/HistogramEqualizationExtension.cs create mode 100644 src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs diff --git a/src/ImageSharp/Processing/Contrast/HistogramEqualizationExtension.cs b/src/ImageSharp/Processing/Contrast/HistogramEqualizationExtension.cs new file mode 100644 index 000000000..1cd29f8b4 --- /dev/null +++ b/src/ImageSharp/Processing/Contrast/HistogramEqualizationExtension.cs @@ -0,0 +1,23 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Contrast +{ + /// + /// Adds extension that allows applying an HistogramEqualization to the image. + /// + public static class HistogramEqualizationExtension + { + /// + /// Equalizes the histogram of an image to increases the global contrast. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static IImageProcessingContext HistogramEqualization(this IImageProcessingContext source) + where TPixel : struct, IPixel + => source.ApplyProcessor(new HistogramEqualizationProcessor()); + } +} diff --git a/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs new file mode 100644 index 000000000..2bacb98ce --- /dev/null +++ b/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs @@ -0,0 +1,64 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing.Contrast +{ + internal class HistogramEqualizationProcessor : ImageProcessor + where TPixel : struct, IPixel + { + /// + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + { + var rgb = default(Rgb24); + int numberOfPixels = source.Width * source.Height; + + // build the histogram of the grayscale levels + int luminanceLevels = 256; + int[] histogram = new int[luminanceLevels]; + for (int y = 0; y < source.Height; y++) + { + Span row = source.GetPixelRowSpan(y); + for (int x = 0; x < source.Width; x++) + { + TPixel sourcePixel = row[x]; + sourcePixel.ToRgb24(ref rgb); + + // Convert to grayscale using ITU-R Recommendation BT.709 if required + int luminance = (int)((.2126F * rgb.R) + (.7152F * rgb.G) + (.0722F * rgb.B)); + histogram[luminance]++; + } + } + + // calculate the cumulative distribution function + double[] cdf = new double[luminanceLevels]; + double sum = 0.0d; + for (int i = 0; i < histogram.Length; i++) + { + double p = (double)histogram[i] / numberOfPixels; + sum += p; + cdf[i] = sum; + } + + // apply the cdf to each pixel of the image + for (int y = 0; y < source.Height; y++) + { + Span row = source.GetPixelRowSpan(y); + for (int x = 0; x < source.Width; x++) + { + TPixel sourcePixel = row[x]; + sourcePixel.ToRgb24(ref rgb); + int luminance = (int)((.2126F * rgb.R) + (.7152F * rgb.G) + (.0722F * rgb.B)); + byte luminanceEqualized = (byte)(cdf[luminance] * luminance); + + row[x].PackFromRgba32(new Rgba32(luminanceEqualized, luminanceEqualized, luminanceEqualized)); + } + } + } + } +} From 687db06e36f714db92555cd230ecab315122ba92 Mon Sep 17 00:00:00 2001 From: popow Date: Sat, 30 Jun 2018 16:25:14 +0200 Subject: [PATCH 03/68] added HistogramEqualizationTest --- .../HistogramEqualizationProcessor.cs | 23 ++++++- .../Contrast/HistogramEqualizationTests.cs | 66 +++++++++++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs diff --git a/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs index 2bacb98ce..23a2d30ba 100644 --- a/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs @@ -35,6 +35,26 @@ namespace SixLabors.ImageSharp.Processing.Contrast } } + int min = luminanceLevels - 1; + for (int i = 0; i < histogram.Length - 1; i++) + { + if (histogram[i] != 0) + { + min = i; + break; + } + } + + int max = 0; + for (int i = histogram.Length - 1; i > 0; i--) + { + if (histogram[i] != 0) + { + max = i; + break; + } + } + // calculate the cumulative distribution function double[] cdf = new double[luminanceLevels]; double sum = 0.0d; @@ -54,8 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Contrast TPixel sourcePixel = row[x]; sourcePixel.ToRgb24(ref rgb); int luminance = (int)((.2126F * rgb.R) + (.7152F * rgb.G) + (.0722F * rgb.B)); - byte luminanceEqualized = (byte)(cdf[luminance] * luminance); - + byte luminanceEqualized = (byte)(cdf[luminance] * (luminanceLevels - 1)); row[x].PackFromRgba32(new Rgba32(luminanceEqualized, luminanceEqualized, luminanceEqualized)); } } diff --git a/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs b/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs new file mode 100644 index 000000000..b5c584a55 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs @@ -0,0 +1,66 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Contrast; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Contrast +{ + public class HistogramEqualizationTests + { + [Fact] + public void HistogramEqualizationTest() + { + // arrange + byte[] pixels = new byte[] + { + 52, 55, 61, 59, 70, 61, 76, 61, + 62, 59, 55, 104, 94, 85, 59, 71, + 63, 65, 66, 113, 144, 104, 63, 72, + 64, 70, 70, 126, 154, 109, 71, 69, + 67, 73, 68, 106, 122, 88, 68, 68, + 68, 79, 60, 79, 77, 66, 58, 75, + 69, 85, 64, 58, 55, 61, 65, 83, + 70, 87, 69, 68, 65, 73, 78, 90 + }; + var image = new Image(8, 8); + for (int y = 0; y < 8; y++) + { + for (int x = 0; x < 8; x++) + { + byte luminance = pixels[y * 8 + x]; + image[x, y] = new Rgba32(luminance, luminance, luminance); + } + } + + byte[] expected = new byte[] + { + 0, 12, 53, 32, 146, 53, 174, 53, + 57, 32, 12, 227, 219, 202, 32, 154, + 65, 85, 93, 239, 251, 227, 65, 158, + 73, 146, 146, 247, 255, 235, 154, 130, + 97, 166, 117, 231, 243, 210, 117, 117, + 117, 190, 36, 190, 178, 93, 20, 170, + 130, 202, 73, 20, 12, 53, 85, 194, + 146, 206, 130, 117, 85, 166, 182, 215 + }; + + // act + image.Mutate(x => x.HistogramEqualization()); + + // assert + for (int y = 0; y < 8; y++) + { + for (int x = 0; x < 8; x++) + { + Rgba32 actual = image[x, y]; + int diff = expected[y * 8 + x] - actual.R; + Assert.True(diff == 0); + int foo = 2; + } + } + } + } +} From 5b1b8b11d3ff40f97d0ea49c23cc32ba1d48784f Mon Sep 17 00:00:00 2001 From: popow Date: Sun, 1 Jul 2018 13:29:46 +0200 Subject: [PATCH 04/68] changed the cdf to be the cumulative histogram --- .../HistogramEqualizationProcessor.cs | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs index 23a2d30ba..f23382d20 100644 --- a/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs @@ -35,37 +35,34 @@ namespace SixLabors.ImageSharp.Processing.Contrast } } - int min = luminanceLevels - 1; - for (int i = 0; i < histogram.Length - 1; i++) + // calculate the cumulative distribution function which will be the cumulative histogram + int[] cdf = new int[luminanceLevels]; + int histSum = 0; + for (int i = 0; i < histogram.Length; i++) { - if (histogram[i] != 0) - { - min = i; - break; - } + histSum += histogram[i]; + cdf[i] = histSum; } - int max = 0; - for (int i = histogram.Length - 1; i > 0; i--) + int cdfMin = 0; + for (int i = 0; i < histogram.Length; i++) { if (histogram[i] != 0) { - max = i; + cdfMin = cdf[i]; break; } } - // calculate the cumulative distribution function - double[] cdf = new double[luminanceLevels]; - double sum = 0.0d; + int[] lut = new int[luminanceLevels]; for (int i = 0; i < histogram.Length; i++) { - double p = (double)histogram[i] / numberOfPixels; - sum += p; - cdf[i] = sum; + lut[i] = cdf[i] - cdfMin; } // apply the cdf to each pixel of the image + double numberOfPixelsMinusCdfMin = (double)(numberOfPixels - cdfMin); + int luminanceLevelsMinusOne = luminanceLevels - 1; for (int y = 0; y < source.Height; y++) { Span row = source.GetPixelRowSpan(y); @@ -74,8 +71,9 @@ namespace SixLabors.ImageSharp.Processing.Contrast TPixel sourcePixel = row[x]; sourcePixel.ToRgb24(ref rgb); int luminance = (int)((.2126F * rgb.R) + (.7152F * rgb.G) + (.0722F * rgb.B)); - byte luminanceEqualized = (byte)(cdf[luminance] * (luminanceLevels - 1)); - row[x].PackFromRgba32(new Rgba32(luminanceEqualized, luminanceEqualized, luminanceEqualized)); + double luminanceEqualized = (lut[luminance] / numberOfPixelsMinusCdfMin) * luminanceLevelsMinusOne; + luminanceEqualized = Math.Round(luminanceEqualized); + row[x].PackFromRgba32(new Rgba32((byte)luminanceEqualized, (byte)luminanceEqualized, (byte)luminanceEqualized)); } } } From 8117d8232f7ea11943f9b2094538e38234d1c7b8 Mon Sep 17 00:00:00 2001 From: popow Date: Sun, 1 Jul 2018 19:09:00 +0200 Subject: [PATCH 05/68] added support for 16 bit greyscale --- .../HistogramEqualizationExtension.cs | 2 +- .../HistogramEqualizationProcessor.cs | 56 +++++++++++++++---- .../Contrast/HistogramEqualizationTests.cs | 17 +++--- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/ImageSharp/Processing/Contrast/HistogramEqualizationExtension.cs b/src/ImageSharp/Processing/Contrast/HistogramEqualizationExtension.cs index 1cd29f8b4..a7b59cedd 100644 --- a/src/ImageSharp/Processing/Contrast/HistogramEqualizationExtension.cs +++ b/src/ImageSharp/Processing/Contrast/HistogramEqualizationExtension.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Processing.Contrast /// /// The pixel format. /// The image this method extends. - /// The . + /// A histogram equalized grayscale image. public static IImageProcessingContext HistogramEqualization(this IImageProcessingContext source) where TPixel : struct, IPixel => source.ApplyProcessor(new HistogramEqualizationProcessor()); diff --git a/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs index f23382d20..df1737455 100644 --- a/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs @@ -9,17 +9,23 @@ using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Contrast { + /// + /// Applies a global histogram equalization to the image. + /// + /// The pixel format. internal class HistogramEqualizationProcessor : ImageProcessor where TPixel : struct, IPixel { /// protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { - var rgb = default(Rgb24); + var rgb48 = default(Rgb48); + var rgb24 = default(Rgb24); int numberOfPixels = source.Width * source.Height; + bool is16bitPerChannel = typeof(TPixel) == typeof(Rgb48) || typeof(TPixel) == typeof(Rgba64); // build the histogram of the grayscale levels - int luminanceLevels = 256; + int luminanceLevels = is16bitPerChannel ? 65536 : 256; int[] histogram = new int[luminanceLevels]; for (int y = 0; y < source.Height; y++) { @@ -27,15 +33,12 @@ namespace SixLabors.ImageSharp.Processing.Contrast for (int x = 0; x < source.Width; x++) { TPixel sourcePixel = row[x]; - sourcePixel.ToRgb24(ref rgb); - - // Convert to grayscale using ITU-R Recommendation BT.709 if required - int luminance = (int)((.2126F * rgb.R) + (.7152F * rgb.G) + (.0722F * rgb.B)); + int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); histogram[luminance]++; } } - // calculate the cumulative distribution function which will be the cumulative histogram + // calculate the cumulative distribution function (which will be the cumulative histogram) int[] cdf = new int[luminanceLevels]; int histSum = 0; for (int i = 0; i < histogram.Length; i++) @@ -69,13 +72,46 @@ namespace SixLabors.ImageSharp.Processing.Contrast for (int x = 0; x < source.Width; x++) { TPixel sourcePixel = row[x]; - sourcePixel.ToRgb24(ref rgb); - int luminance = (int)((.2126F * rgb.R) + (.7152F * rgb.G) + (.0722F * rgb.B)); + + int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); double luminanceEqualized = (lut[luminance] / numberOfPixelsMinusCdfMin) * luminanceLevelsMinusOne; luminanceEqualized = Math.Round(luminanceEqualized); - row[x].PackFromRgba32(new Rgba32((byte)luminanceEqualized, (byte)luminanceEqualized, (byte)luminanceEqualized)); + + if (is16bitPerChannel) + { + row[x].PackFromRgb48(new Rgb48((ushort)luminanceEqualized, (ushort)luminanceEqualized, (ushort)luminanceEqualized)); + } + else + { + row[x].PackFromRgba32(new Rgba32((byte)luminanceEqualized, (byte)luminanceEqualized, (byte)luminanceEqualized)); + } } } } + + /// + /// Convert the pixel values to grayscale using ITU-R Recommendation BT.709. + /// + /// The pixel to get the luminance from + /// Flag indicates, if its 16 bits per channel, otherwise its 8 + /// Will store the pixel values in case of 8 bit per channel + /// Will store the pixel values in case of 16 bit per channel + private int GetLuminance(TPixel sourcePixel, bool is16bitPerChannel, ref Rgb24 rgb24, ref Rgb48 rgb48) + { + // Convert to grayscale using ITU-R Recommendation BT.709 + int luminance; + if (is16bitPerChannel) + { + sourcePixel.ToRgb48(ref rgb48); + luminance = (int)((.2126F * rgb48.R) + (.7152F * rgb48.G) + (.0722F * rgb48.B)); + } + else + { + sourcePixel.ToRgb24(ref rgb24); + luminance = (int)((.2126F * rgb24.R) + (.7152F * rgb24.G) + (.0722F * rgb24.B)); + } + + return luminance; + } } } diff --git a/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs b/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs index b5c584a55..db2282ccd 100644 --- a/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs +++ b/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs @@ -37,14 +37,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Contrast byte[] expected = new byte[] { - 0, 12, 53, 32, 146, 53, 174, 53, - 57, 32, 12, 227, 219, 202, 32, 154, - 65, 85, 93, 239, 251, 227, 65, 158, - 73, 146, 146, 247, 255, 235, 154, 130, - 97, 166, 117, 231, 243, 210, 117, 117, - 117, 190, 36, 190, 178, 93, 20, 170, - 130, 202, 73, 20, 12, 53, 85, 194, - 146, 206, 130, 117, 85, 166, 182, 215 + 0, 12, 53, 32, 146, 53, 174, 53, + 57, 32, 12, 227, 219, 202, 32, 154, + 65, 85, 93, 239, 251, 227, 65, 158, + 73, 146, 146, 247, 255, 235, 154, 130, + 97, 166, 117, 231, 243, 210, 117, 117, + 117, 190, 36, 190, 178, 93, 20, 170, + 130, 202, 73, 20, 12, 53, 85, 194, + 146, 206, 130, 117, 85, 166, 182, 215 }; // act @@ -58,7 +58,6 @@ namespace SixLabors.ImageSharp.Tests.Processing.Contrast Rgba32 actual = image[x, y]; int diff = expected[y * 8 + x] - actual.R; Assert.True(diff == 0); - int foo = 2; } } } From 1d5a8f747bec152aa139eb62588ceb3a82891dc1 Mon Sep 17 00:00:00 2001 From: popow Date: Mon, 2 Jul 2018 15:34:31 +0200 Subject: [PATCH 06/68] SixLabors.ImageSharp.Processing.Contrast -> SixLabors.ImageSharp.Processing.Normalization --- .../HistogramEqualizationExtension.cs | 2 +- .../HistogramEqualizationProcessor.cs | 2 +- .../Processing/Contrast/HistogramEqualizationTests.cs | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) rename src/ImageSharp/Processing/{Contrast => Normalization}/HistogramEqualizationExtension.cs (94%) rename src/ImageSharp/Processing/{Contrast => Normalization}/HistogramEqualizationProcessor.cs (98%) diff --git a/src/ImageSharp/Processing/Contrast/HistogramEqualizationExtension.cs b/src/ImageSharp/Processing/Normalization/HistogramEqualizationExtension.cs similarity index 94% rename from src/ImageSharp/Processing/Contrast/HistogramEqualizationExtension.cs rename to src/ImageSharp/Processing/Normalization/HistogramEqualizationExtension.cs index a7b59cedd..b40064515 100644 --- a/src/ImageSharp/Processing/Contrast/HistogramEqualizationExtension.cs +++ b/src/ImageSharp/Processing/Normalization/HistogramEqualizationExtension.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Contrast +namespace SixLabors.ImageSharp.Processing.Normalization { /// /// Adds extension that allows applying an HistogramEqualization to the image. diff --git a/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs rename to src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs index df1737455..a1f37b039 100644 --- a/src/ImageSharp/Processing/Contrast/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs @@ -7,7 +7,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Contrast +namespace SixLabors.ImageSharp.Processing.Normalization { /// /// Applies a global histogram equalization to the image. diff --git a/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs b/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs index db2282ccd..b989fcf85 100644 --- a/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs +++ b/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Contrast; +using SixLabors.ImageSharp.Processing.Normalization; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Contrast @@ -56,8 +56,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Contrast for (int x = 0; x < 8; x++) { Rgba32 actual = image[x, y]; - int diff = expected[y * 8 + x] - actual.R; - Assert.True(diff == 0); + Assert.Equal(expected[y * 8 + x], actual.R); + Assert.Equal(expected[y * 8 + x], actual.G); + Assert.Equal(expected[y * 8 + x], actual.B); } } } From f4d97863add387b0a8a337a5cbc7c24bc6197588 Mon Sep 17 00:00:00 2001 From: popow Date: Mon, 2 Jul 2018 15:50:05 +0200 Subject: [PATCH 07/68] using memoryAllocator --- .../Normalization/HistogramEqualizationProcessor.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs index a1f37b039..75bd2d256 100644 --- a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs @@ -5,6 +5,7 @@ using System; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Normalization @@ -21,12 +22,13 @@ namespace SixLabors.ImageSharp.Processing.Normalization { var rgb48 = default(Rgb48); var rgb24 = default(Rgb24); + MemoryAllocator memoryAllocator = configuration.MemoryAllocator; int numberOfPixels = source.Width * source.Height; bool is16bitPerChannel = typeof(TPixel) == typeof(Rgb48) || typeof(TPixel) == typeof(Rgba64); // build the histogram of the grayscale levels int luminanceLevels = is16bitPerChannel ? 65536 : 256; - int[] histogram = new int[luminanceLevels]; + Span histogram = memoryAllocator.Allocate(luminanceLevels, clear: true).GetSpan(); for (int y = 0; y < source.Height; y++) { Span row = source.GetPixelRowSpan(y); @@ -39,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization } // calculate the cumulative distribution function (which will be the cumulative histogram) - int[] cdf = new int[luminanceLevels]; + Span cdf = memoryAllocator.Allocate(luminanceLevels, clear: true).GetSpan(); int histSum = 0; for (int i = 0; i < histogram.Length; i++) { @@ -47,6 +49,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization cdf[i] = histSum; } + // get the first none zero value of the cumulative histogram int cdfMin = 0; for (int i = 0; i < histogram.Length; i++) { @@ -57,7 +60,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization } } - int[] lut = new int[luminanceLevels]; + Span lut = memoryAllocator.Allocate(luminanceLevels, clear: true).GetSpan(); for (int i = 0; i < histogram.Length; i++) { lut[i] = cdf[i] - cdfMin; From 7ecfa0cfbfad786df0fbe293fdbe96e8e2c89444 Mon Sep 17 00:00:00 2001 From: popow Date: Mon, 2 Jul 2018 15:57:58 +0200 Subject: [PATCH 08/68] removed unnecessary allocation of the lut, using cdf instead --- .../Normalization/HistogramEqualizationProcessor.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs index 75bd2d256..0036b5dc9 100644 --- a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs @@ -60,10 +60,10 @@ namespace SixLabors.ImageSharp.Processing.Normalization } } - Span lut = memoryAllocator.Allocate(luminanceLevels, clear: true).GetSpan(); + // creating the lookup table: subtracting cdf min, so we do not need to do that inside the for loop for (int i = 0; i < histogram.Length; i++) { - lut[i] = cdf[i] - cdfMin; + cdf[i] = cdf[i] - cdfMin; } // apply the cdf to each pixel of the image @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization TPixel sourcePixel = row[x]; int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); - double luminanceEqualized = (lut[luminance] / numberOfPixelsMinusCdfMin) * luminanceLevelsMinusOne; + double luminanceEqualized = (cdf[luminance] / numberOfPixelsMinusCdfMin) * luminanceLevelsMinusOne; luminanceEqualized = Math.Round(luminanceEqualized); if (is16bitPerChannel) From e6ba7760744cf0048e1fd093a287107f235aefcf Mon Sep 17 00:00:00 2001 From: popow Date: Mon, 2 Jul 2018 18:30:17 +0200 Subject: [PATCH 09/68] moved test to Normalization folder --- .../{Contrast => Normalization}/HistogramEqualizationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/ImageSharp.Tests/Processing/{Contrast => Normalization}/HistogramEqualizationTests.cs (97%) diff --git a/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs similarity index 97% rename from tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs rename to tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs index b989fcf85..7a750ff8b 100644 --- a/tests/ImageSharp.Tests/Processing/Contrast/HistogramEqualizationTests.cs +++ b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs @@ -6,7 +6,7 @@ using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Normalization; using Xunit; -namespace SixLabors.ImageSharp.Tests.Processing.Contrast +namespace SixLabors.ImageSharp.Tests.Processing.Normalization { public class HistogramEqualizationTests { From a5b180ac9add950fbfcb6a6f54621a2e120acfa2 Mon Sep 17 00:00:00 2001 From: popow Date: Mon, 2 Jul 2018 18:34:19 +0200 Subject: [PATCH 10/68] fixed rounding issue in calculating the luminance --- .../Normalization/HistogramEqualizationProcessor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs index 0036b5dc9..aa1526c87 100644 --- a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs @@ -106,12 +106,12 @@ namespace SixLabors.ImageSharp.Processing.Normalization if (is16bitPerChannel) { sourcePixel.ToRgb48(ref rgb48); - luminance = (int)((.2126F * rgb48.R) + (.7152F * rgb48.G) + (.0722F * rgb48.B)); + luminance = Convert.ToInt32((.2126F * rgb48.R) + (.7152F * rgb48.G) + (.0722F * rgb48.B)); } else { sourcePixel.ToRgb24(ref rgb24); - luminance = (int)((.2126F * rgb24.R) + (.7152F * rgb24.G) + (.0722F * rgb24.B)); + luminance = Convert.ToInt32((.2126F * rgb24.R) + (.7152F * rgb24.G) + (.0722F * rgb24.B)); } return luminance; From fc2dc1b69d84958ecf82497a754456ccecaa5160 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 3 Jul 2018 14:48:59 +1000 Subject: [PATCH 11/68] Update ImageSharp Namespaces. --- src/ImageSharp/Formats/Gif/GifEncoder.cs | 2 +- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 2 +- src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs | 2 +- src/ImageSharp/Formats/Png/IPngEncoderOptions.cs | 2 +- src/ImageSharp/Formats/Png/PngEncoder.cs | 2 +- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 2 +- .../{Transforms => }/AnchorPositionMode.cs | 2 +- .../{Transforms => }/AutoOrientExtensions.cs | 4 ++-- .../{Overlays => }/BackgroundColorExtensions.cs | 4 ++-- .../{Binarization => }/BinaryDiffuseExtensions.cs | 6 +++--- .../{Binarization => }/BinaryDitherExtensions.cs | 6 +++--- .../BinaryThresholdExtensions.cs | 4 ++-- .../{Filters => }/BlackWhiteExtensions.cs | 4 ++-- .../{Convolution => }/BoxBlurExtensions.cs | 4 ++-- .../{Filters => }/BrightnessExtensions.cs | 4 ++-- .../{Filters => }/ColorBlindnessExtensions.cs | 4 ++-- .../Processing/{Filters => }/ColorBlindnessMode.cs | 2 +- .../Processing/{Filters => }/ContrastExtensions.cs | 4 ++-- .../Processing/{Transforms => }/CropExtensions.cs | 4 ++-- .../{Convolution => }/DetectEdgesExtensions.cs | 4 ++-- .../{Dithering => }/DiffuseExtensions.cs | 3 +-- .../Processing/{Dithering => }/DitherExtensions.cs | 5 ++--- .../{Convolution => }/EdgeDetectionOperators.cs | 2 +- .../{Transforms => }/EntropyCropExtensions.cs | 4 ++-- .../Processing/{Filters => }/FilterExtensions.cs | 4 ++-- .../Processing/{Transforms => }/FlipExtensions.cs | 4 ++-- .../Processing/{Transforms => }/FlipMode.cs | 2 +- .../{Convolution => }/GaussianBlurExtensions.cs | 4 ++-- .../{Convolution => }/GaussianSharpenExtensions.cs | 4 ++-- .../Processing/{Overlays => }/GlowExtensions.cs | 4 ++-- .../{Filters => }/GrayscaleExtensions.cs | 4 ++-- .../Processing/{Filters => }/GrayscaleMode.cs | 2 +- .../Processing/{Filters => }/HueExtensions.cs | 4 ++-- .../Processing/{Filters => }/InvertExtensions.cs | 4 ++-- .../Processing/{Dithering => }/KnownDiffusers.cs | 4 ++-- .../Processing/{Dithering => }/KnownDitherers.cs | 6 +++--- .../{Filters => }/KnownFilterMatrices.cs | 4 ++-- .../{Quantization => }/KnownQuantizers.cs | 4 +++- .../Processing/{Transforms => }/KnownResamplers.cs | 4 ++-- .../{Filters => }/KodachromeExtensions.cs | 4 ++-- .../{Filters => }/LomographExtensions.cs | 4 ++-- .../Processing/{Effects => }/OilPaintExtensions.cs | 4 ++-- .../Processing/{Filters => }/OpacityExtensions.cs | 4 ++-- .../Processing/{Transforms => }/OrientationMode.cs | 2 +- .../Processing/{Transforms => }/PadExtensions.cs | 2 +- .../Processing/{Effects => }/PixelateExtensions.cs | 4 ++-- .../Processing/{Filters => }/PolaroidExtensions.cs | 4 ++-- .../Binarization}/BinaryErrorDiffusionProcessor.cs | 5 ++--- .../Binarization}/BinaryOrderedDitherProcessor.cs | 5 ++--- .../Binarization}/BinaryThresholdProcessor.cs | 2 +- .../Convolution}/BoxBlurProcessor.cs | 3 +-- .../Convolution}/Convolution2DProcessor.cs | 3 +-- .../Convolution}/Convolution2PassProcessor.cs | 2 +- .../Convolution}/ConvolutionProcessor.cs | 2 +- .../Convolution}/EdgeDetector2DProcessor.cs | 5 ++--- .../Convolution}/EdgeDetectorCompassProcessor.cs | 5 ++--- .../Convolution}/EdgeDetectorProcessor.cs | 5 ++--- .../Convolution}/GaussianBlurProcessor.cs | 2 +- .../Convolution}/GaussianSharpenProcessor.cs | 7 +++---- .../Convolution}/IEdgeDetectorProcessor.cs | 2 +- .../Convolution}/KayyaliKernels.cs | 2 +- .../Convolution}/KayyaliProcessor.cs | 2 +- .../Convolution}/KirschProcessor.cs | 2 +- .../Convolution}/KirshKernels.cs | 2 +- .../Convolution}/Laplacian3x3Processor.cs | 2 +- .../Convolution}/Laplacian5x5Processor.cs | 2 +- .../Convolution}/LaplacianKernelFactory.cs | 2 +- .../Convolution}/LaplacianKernels.cs | 2 +- .../Convolution}/LaplacianOfGaussianProcessor.cs | 2 +- .../Convolution}/PrewittKernels.cs | 2 +- .../Convolution}/PrewittProcessor.cs | 2 +- .../Convolution}/RobertsCrossKernels.cs | 2 +- .../Convolution}/RobertsCrossProcessor.cs | 2 +- .../Convolution}/RobinsonKernels.cs | 2 +- .../Convolution}/RobinsonProcessor.cs | 2 +- .../Convolution}/ScharrKernels.cs | 2 +- .../Convolution}/ScharrProcessor.cs | 2 +- .../Convolution}/SobelKernels.cs | 2 +- .../Convolution}/SobelProcessor.cs | 2 +- .../Processing/Processors/DelegateProcessor.cs | 8 +++----- .../Dithering}/AtkinsonDiffuser.cs | 2 +- .../Dithering}/BayerDither2x2.cs | 2 +- .../Dithering}/BayerDither4x4.cs | 2 +- .../Dithering}/BayerDither8x8.cs | 2 +- .../Dithering}/BurksDiffuser.cs | 2 +- .../{ => Processors}/Dithering/DHALF.TXT | 0 .../{ => Processors}/Dithering/DITHER.TXT | 0 .../Dithering}/ErrorDiffuserBase.cs | 2 +- .../Dithering}/ErrorDiffusionPaletteProcessor.cs | 5 ++--- .../Dithering}/FloydSteinbergDiffuser.cs | 2 +- .../Dithering}/IErrorDiffuser.cs | 2 +- .../Dithering}/IOrderedDither.cs | 2 +- .../Dithering}/JarvisJudiceNinkeDiffuser.cs | 2 +- .../Dithering}/OrderedDither.cs | 2 +- .../Dithering}/OrderedDither3x3.cs | 2 +- .../Dithering}/OrderedDitherFactory.cs | 2 +- .../Dithering}/OrderedDitherPaletteProcessor.cs | 5 ++--- .../Dithering}/PaletteDitherProcessorBase.cs | 3 +-- .../Dithering}/PixelPair.cs | 2 +- .../Dithering}/Sierra2Diffuser.cs | 2 +- .../Dithering}/Sierra3Diffuser.cs | 2 +- .../Dithering}/SierraLiteDiffuser.cs | 2 +- .../Dithering}/StevensonArceDiffuser.cs | 2 +- .../Dithering}/StuckiDiffuser.cs | 2 +- .../{ => Processors}/Dithering/error_diffusion.txt | 0 .../Effects}/OilPaintingProcessor.cs | 5 ++--- .../Effects}/PixelateProcessor.cs | 3 +-- .../Filters}/AchromatomalyProcessor.cs | 2 +- .../Filters}/AchromatopsiaProcessor.cs | 2 +- .../Filters}/BlackWhiteProcessor.cs | 2 +- .../Filters}/BrightnessProcessor.cs | 2 +- .../Filters}/ContrastProcessor.cs | 2 +- .../Filters}/DeuteranomalyProcessor.cs | 2 +- .../Filters}/DeuteranopiaProcessor.cs | 2 +- .../Filters}/FilterProcessor.cs | 3 +-- .../Filters}/GrayscaleBt601Processor.cs | 2 +- .../Filters}/GrayscaleBt709Processor.cs | 2 +- .../Filters}/HueProcessor.cs | 2 +- .../Filters}/InvertProcessor.cs | 2 +- .../Filters}/KodachromeProcessor.cs | 2 +- .../Filters}/LomographProcessor.cs | 4 ++-- .../Filters}/OpacityProcessor.cs | 2 +- .../Filters}/PolaroidProcessor.cs | 4 ++-- .../Filters}/ProtanomalyProcessor.cs | 2 +- .../Filters}/ProtanopiaProcessor.cs | 2 +- .../Processors => Processors/Filters}/README.md | 0 .../Filters}/SaturateProcessor.cs | 2 +- .../Filters}/SepiaProcessor.cs | 2 +- .../Filters}/TritanomalyProcessor.cs | 2 +- .../Filters}/TritanopiaProcessor.cs | 2 +- .../Overlays}/BackgroundColorProcessor.cs | 3 +-- .../Overlays}/GlowProcessor.cs | 3 +-- .../Overlays}/VignetteProcessor.cs | 3 +-- .../Quantization}/FrameQuantizerBase{TPixel}.cs | 4 ++-- .../Quantization}/IFrameQuantizer{TPixel}.cs | 4 ++-- .../{ => Processors}/Quantization/IQuantizer.cs | 5 ++--- .../Quantization}/OctreeFrameQuantizer{TPixel}.cs | 2 +- .../Quantization/OctreeQuantizer.cs | 6 ++---- .../Quantization}/PaletteFrameQuantizer{TPixel}.cs | 2 +- .../Quantization/PaletteQuantizer.cs | 6 ++---- .../Quantization}/QuantizeProcessor.cs | 4 +--- .../Quantization/QuantizedFrame{TPixel}.cs | 2 +- .../Quantization}/WuFrameQuantizer{TPixel}.cs | 2 +- .../{ => Processors}/Quantization/WuQuantizer.cs | 6 ++---- .../Transforms}/AffineTransformProcessor.cs | 3 +-- .../Transforms}/AutoOrientProcessor.cs | 2 +- .../Transforms}/BicubicResampler.cs | 2 +- .../Transforms}/BoxResampler.cs | 2 +- .../Transforms}/CatmullRomResampler.cs | 2 +- .../CenteredAffineTransformProcessor.cs | 3 +-- .../CenteredProjectiveTransformProcessor.cs | 3 +-- .../Transforms}/CropProcessor.cs | 2 +- .../Transforms}/EntropyCropProcessor.cs | 9 ++++----- .../Transforms}/FlipProcessor.cs | 7 +++---- .../Transforms}/HermiteResampler.cs | 2 +- .../Transforms}/IResampler.cs | 2 +- .../InterpolatedTransformProcessorBase.cs | 3 +-- .../Transforms}/Lanczos2Resampler.cs | 2 +- .../Transforms}/Lanczos3Resampler.cs | 2 +- .../Transforms}/Lanczos5Resampler.cs | 2 +- .../Transforms}/Lanczos8Resampler.cs | 2 +- .../Transforms}/MitchellNetravaliResampler.cs | 2 +- .../Transforms}/NearestNeighborResampler.cs | 2 +- .../Transforms}/ProjectiveTransformProcessor.cs | 4 +--- .../Transforms}/ResizeProcessor.cs | 5 ++--- .../Transforms}/RobidouxResampler.cs | 2 +- .../Transforms}/RobidouxSharpResampler.cs | 2 +- .../Transforms}/RotateProcessor.cs | 4 ++-- .../Transforms}/SkewProcessor.cs | 4 ++-- .../Transforms}/SplineResampler.cs | 2 +- .../Transforms/TransformHelpers.cs | 2 +- .../Transforms}/TransformProcessorBase.cs | 2 +- .../Transforms}/TriangleResampler.cs | 2 +- .../Transforms}/WeightsBuffer.cs | 2 +- .../Transforms}/WeightsWindow.cs | 2 +- .../Transforms}/WelchResampler.cs | 2 +- .../{Transforms => }/ProjectiveTransformHelper.cs | 2 +- .../{Quantization => }/QuantizeExtensions.cs | 4 ++-- .../{Transforms => }/ResizeExtensions.cs | 5 ++--- .../Processing/{Transforms => }/ResizeHelper.cs | 2 +- .../Processing/{Transforms => }/ResizeMode.cs | 2 +- .../Processing/{Transforms => }/ResizeOptions.cs | 4 ++-- .../{Transforms => }/RotateExtensions.cs | 5 ++--- .../{Transforms => }/RotateFlipExtensions.cs | 2 +- .../Processing/{Transforms => }/RotateMode.cs | 2 +- .../Processing/{Filters => }/SaturateExtensions.cs | 4 ++-- .../Processing/{Filters => }/SepiaExtensions.cs | 4 ++-- .../Processing/{Transforms => }/SkewExtensions.cs | 5 ++--- .../{Transforms => }/TransformExtensions.cs | 5 ++--- .../{Overlays => }/VignetteExtensions.cs | 4 ++-- tests/ImageSharp.Benchmarks/Codecs/EncodeGif.cs | 2 +- .../Codecs/EncodeGifMultiple.cs | 2 +- .../Codecs/EncodeIndexedPng.cs | 3 ++- tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs | 3 --- tests/ImageSharp.Benchmarks/Drawing/DrawText.cs | 7 ++----- .../Drawing/DrawTextOutline.cs | 4 ---- tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs | 1 - .../ImageSharp.Benchmarks/Drawing/FillRectangle.cs | 1 - tests/ImageSharp.Benchmarks/Samplers/Crop.cs | 1 - .../ImageSharp.Benchmarks/Samplers/DetectEdges.cs | 1 - tests/ImageSharp.Benchmarks/Samplers/Glow.cs | 2 +- tests/ImageSharp.Benchmarks/Samplers/Resize.cs | 1 - tests/ImageSharp.Tests/ComplexIntegrationTests.cs | 2 +- tests/ImageSharp.Tests/Drawing/BeziersTests.cs | 1 - tests/ImageSharp.Tests/Drawing/DrawImageTest.cs | 4 ++-- tests/ImageSharp.Tests/Drawing/DrawPathTests.cs | 1 - tests/ImageSharp.Tests/Drawing/FillPatternTests.cs | 1 - .../Drawing/LineComplexPolygonTests.cs | 1 - tests/ImageSharp.Tests/Drawing/LineTests.cs | 1 - tests/ImageSharp.Tests/Drawing/PolygonTests.cs | 1 - tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs | 1 - .../Drawing/SolidComplexPolygonTests.cs | 1 - .../ImageSharp.Tests/Drawing/SolidPolygonTests.cs | 1 - .../ImageSharp.Tests/Formats/GeneralFormatTests.cs | 2 +- .../Formats/Gif/GifEncoderTests.cs | 2 +- .../Formats/Png/PngEncoderTests.cs | 2 +- .../ImageSharp.Tests/Formats/Png/PngSmokeTests.cs | 4 +--- .../Image/ImageProcessingContextTests.cs | 6 +----- tests/ImageSharp.Tests/Image/ImageRotationTests.cs | 4 +--- .../Processing/Binarization/BinaryDitherTest.cs | 9 +++------ .../Processing/Binarization/BinaryThresholdTest.cs | 4 ++-- .../Binarization/OrderedDitherFactoryTests.cs | 2 +- .../Processing/Convolution/BoxBlurTest.cs | 7 ++----- .../Processing/Convolution/DetectEdgesTest.cs | 4 +--- .../Processing/Convolution/GaussianBlurTest.cs | 7 ++----- .../Processing/Convolution/GaussianSharpenTest.cs | 7 ++----- .../Processors/LaplacianKernelFactoryTests.cs | 4 ++-- .../Processing/Dithering/DitherTest.cs | 5 ++--- .../Processing/Effects/BackgroundColorTest.cs | 4 ++-- .../Processing/Effects/OilPaintTest.cs | 4 ++-- .../Processing/Effects/PixelateTest.cs | 4 ++-- .../Processing/Filters/BlackWhiteTest.cs | 4 ++-- .../Processing/Filters/BrightnessTest.cs | 4 ++-- .../Processing/Filters/ColorBlindnessTest.cs | 4 ++-- .../Processing/Filters/ContrastTest.cs | 4 ++-- .../Processing/Filters/FilterTest.cs | 4 ++-- .../Processing/Filters/GrayscaleTest.cs | 4 ++-- .../ImageSharp.Tests/Processing/Filters/HueTest.cs | 4 ++-- .../Processing/Filters/InvertTest.cs | 4 ++-- .../Processing/Filters/KodachromeTest.cs | 4 ++-- .../Processing/Filters/LomographTest.cs | 4 ++-- .../Processing/Filters/OpacityTest.cs | 4 ++-- .../Processing/Filters/PolaroidTest.cs | 4 ++-- .../Processing/Filters/SaturateTest.cs | 4 ++-- .../Processing/Filters/SepiaTest.cs | 4 ++-- .../Processing/Overlays/GlowTest.cs | 4 ++-- .../Processing/Overlays/VignetteTest.cs | 4 ++-- .../Processors/Binarization/BinaryDitherTests.cs | 5 +---- .../Processors/Binarization/BinaryThresholdTest.cs | 1 - .../Processors/Convolution/BoxBlurTest.cs | 4 +--- .../Processors/Convolution/DetectEdgesTest.cs | 1 - .../Processors/Convolution/GaussianBlurTest.cs | 1 - .../Processors/Convolution/GaussianSharpenTest.cs | 1 - .../Processing/Processors/Dithering/DitherTests.cs | 3 +-- .../Processors/Effects/BackgroundColorTest.cs | 4 +--- .../Processing/Processors/Effects/OilPaintTest.cs | 4 +--- .../Processing/Processors/Effects/PixelateTest.cs | 4 +--- .../Processors/Filters/BlackWhiteTest.cs | 2 +- .../Processors/Filters/BrightnessTest.cs | 2 +- .../Processors/Filters/ColorBlindnessTest.cs | 2 +- .../Processing/Processors/Filters/ContrastTest.cs | 2 +- .../Processing/Processors/Filters/FilterTest.cs | 2 +- .../Processing/Processors/Filters/GrayscaleTest.cs | 2 +- .../Processing/Processors/Filters/HueTest.cs | 2 +- .../Processing/Processors/Filters/InvertTest.cs | 2 +- .../Processors/Filters/KodachromeTest.cs | 2 +- .../Processing/Processors/Filters/LomographTest.cs | 2 +- .../Processing/Processors/Filters/OpacityTest.cs | 2 +- .../Processing/Processors/Filters/PolaroidTest.cs | 2 +- .../Processing/Processors/Filters/SaturateTest.cs | 2 +- .../Processing/Processors/Filters/SepiaTest.cs | 2 +- .../Processing/Processors/Overlays/GlowTest.cs | 4 +--- .../Processing/Processors/Overlays/VignetteTest.cs | 4 +--- .../Processors/Transforms/AutoOrientTests.cs | 2 +- .../Processing/Processors/Transforms/CropTest.cs | 2 -- .../Processors/Transforms/EntropyCropTest.cs | 2 -- .../Processing/Processors/Transforms/FlipTests.cs | 2 +- .../Processing/Processors/Transforms/PadTest.cs | 4 +--- .../Transforms/ResizeProfilingBenchmarks.cs | 4 +--- .../Processors/Transforms/ResizeTests.cs | 3 +-- .../Processors/Transforms/RotateFlipTests.cs | 2 +- .../Processors/Transforms/RotateTests.cs | 6 ++---- .../Processing/Processors/Transforms/SkewTest.cs | 14 ++++++-------- .../Processing/Transforms/AffineTransformTests.cs | 4 +--- .../Processing/Transforms/AutoOrientTests.cs | 4 ++-- .../Processing/Transforms/CropTest.cs | 4 ++-- .../Processing/Transforms/EntropyCropTest.cs | 4 ++-- .../Processing/Transforms/FlipTests.cs | 4 ++-- .../Processing/Transforms/PadTest.cs | 6 +++--- .../Transforms/ProjectiveTransformTests.cs | 6 ++---- .../Processing/Transforms/ResizeTests.cs | 5 ++--- .../Processing/Transforms/RotateFlipTests.cs | 4 ++-- .../Processing/Transforms/RotateTests.cs | 4 +--- .../Processing/Transforms/SkewTest.cs | 4 ++-- .../Processing/Transforms/TransformsHelpersTest.cs | 3 +-- .../Quantization/QuantizedImageTests.cs | 2 +- .../TestUtilities/Tests/ImageComparerTests.cs | 1 - .../Tests/TestUtilityExtensionsTests.cs | 7 +++---- 298 files changed, 393 insertions(+), 523 deletions(-) rename src/ImageSharp/Processing/{Transforms => }/AnchorPositionMode.cs (96%) rename src/ImageSharp/Processing/{Transforms => }/AutoOrientExtensions.cs (89%) rename src/ImageSharp/Processing/{Overlays => }/BackgroundColorExtensions.cs (97%) rename src/ImageSharp/Processing/{Binarization => }/BinaryDiffuseExtensions.cs (96%) rename src/ImageSharp/Processing/{Binarization => }/BinaryDitherExtensions.cs (95%) rename src/ImageSharp/Processing/{Binarization => }/BinaryThresholdExtensions.cs (97%) rename src/ImageSharp/Processing/{Filters => }/BlackWhiteExtensions.cs (93%) rename src/ImageSharp/Processing/{Convolution => }/BoxBlurExtensions.cs (95%) rename src/ImageSharp/Processing/{Filters => }/BrightnessExtensions.cs (95%) rename src/ImageSharp/Processing/{Filters => }/ColorBlindnessExtensions.cs (96%) rename src/ImageSharp/Processing/{Filters => }/ColorBlindnessMode.cs (95%) rename src/ImageSharp/Processing/{Filters => }/ContrastExtensions.cs (95%) rename src/ImageSharp/Processing/{Transforms => }/CropExtensions.cs (93%) rename src/ImageSharp/Processing/{Convolution => }/DetectEdgesExtensions.cs (98%) rename src/ImageSharp/Processing/{Dithering => }/DiffuseExtensions.cs (97%) rename src/ImageSharp/Processing/{Dithering => }/DitherExtensions.cs (96%) rename src/ImageSharp/Processing/{Convolution => }/EdgeDetectionOperators.cs (96%) rename src/ImageSharp/Processing/{Transforms => }/EntropyCropExtensions.cs (93%) rename src/ImageSharp/Processing/{Filters => }/FilterExtensions.cs (94%) rename src/ImageSharp/Processing/{Transforms => }/FlipExtensions.cs (89%) rename src/ImageSharp/Processing/{Transforms => }/FlipMode.cs (90%) rename src/ImageSharp/Processing/{Convolution => }/GaussianBlurExtensions.cs (95%) rename src/ImageSharp/Processing/{Convolution => }/GaussianSharpenExtensions.cs (95%) rename src/ImageSharp/Processing/{Overlays => }/GlowExtensions.cs (98%) rename src/ImageSharp/Processing/{Filters => }/GrayscaleExtensions.cs (98%) rename src/ImageSharp/Processing/{Filters => }/GrayscaleMode.cs (89%) rename src/ImageSharp/Processing/{Filters => }/HueExtensions.cs (94%) rename src/ImageSharp/Processing/{Filters => }/InvertExtensions.cs (93%) rename src/ImageSharp/Processing/{Dithering => }/KnownDiffusers.cs (94%) rename src/ImageSharp/Processing/{Dithering => }/KnownDitherers.cs (88%) rename src/ImageSharp/Processing/{Filters => }/KnownFilterMatrices.cs (99%) rename src/ImageSharp/Processing/{Quantization => }/KnownQuantizers.cs (90%) rename src/ImageSharp/Processing/{Transforms => }/KnownResamplers.cs (97%) rename src/ImageSharp/Processing/{Filters => }/KodachromeExtensions.cs (94%) rename src/ImageSharp/Processing/{Filters => }/LomographExtensions.cs (94%) rename src/ImageSharp/Processing/{Effects => }/OilPaintExtensions.cs (97%) rename src/ImageSharp/Processing/{Filters => }/OpacityExtensions.cs (94%) rename src/ImageSharp/Processing/{Transforms => }/OrientationMode.cs (96%) rename src/ImageSharp/Processing/{Transforms => }/PadExtensions.cs (95%) rename src/ImageSharp/Processing/{Effects => }/PixelateExtensions.cs (95%) rename src/ImageSharp/Processing/{Filters => }/PolaroidExtensions.cs (94%) rename src/ImageSharp/Processing/{Binarization/Processors => Processors/Binarization}/BinaryErrorDiffusionProcessor.cs (96%) rename src/ImageSharp/Processing/{Binarization/Processors => Processors/Binarization}/BinaryOrderedDitherProcessor.cs (95%) rename src/ImageSharp/Processing/{Binarization/Processors => Processors/Binarization}/BinaryThresholdProcessor.cs (98%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/BoxBlurProcessor.cs (96%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/Convolution2DProcessor.cs (97%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/Convolution2PassProcessor.cs (98%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/ConvolutionProcessor.cs (98%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/EdgeDetector2DProcessor.cs (92%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/EdgeDetectorCompassProcessor.cs (97%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/EdgeDetectorProcessor.cs (91%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/GaussianBlurProcessor.cs (98%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/GaussianSharpenProcessor.cs (96%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/IEdgeDetectorProcessor.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/KayyaliKernels.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/KayyaliProcessor.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/KirschProcessor.cs (96%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/KirshKernels.cs (97%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/Laplacian3x3Processor.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/Laplacian5x5Processor.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/LaplacianKernelFactory.cs (94%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/LaplacianKernels.cs (94%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/LaplacianOfGaussianProcessor.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/PrewittKernels.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/PrewittProcessor.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/RobertsCrossKernels.cs (92%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/RobertsCrossProcessor.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/RobinsonKernels.cs (97%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/RobinsonProcessor.cs (96%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/ScharrKernels.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/ScharrProcessor.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/SobelKernels.cs (93%) rename src/ImageSharp/Processing/{Convolution/Processors => Processors/Convolution}/SobelProcessor.cs (93%) rename src/ImageSharp/Processing/{Dithering/ErrorDiffusion => Processors/Dithering}/AtkinsonDiffuser.cs (93%) rename src/ImageSharp/Processing/{Dithering/Ordered => Processors/Dithering}/BayerDither2x2.cs (88%) rename src/ImageSharp/Processing/{Dithering/Ordered => Processors/Dithering}/BayerDither4x4.cs (88%) rename src/ImageSharp/Processing/{Dithering/Ordered => Processors/Dithering}/BayerDither8x8.cs (88%) rename src/ImageSharp/Processing/{Dithering/ErrorDiffusion => Processors/Dithering}/BurksDiffuser.cs (92%) rename src/ImageSharp/Processing/{ => Processors}/Dithering/DHALF.TXT (100%) rename src/ImageSharp/Processing/{ => Processors}/Dithering/DITHER.TXT (100%) rename src/ImageSharp/Processing/{Dithering/ErrorDiffusion => Processors/Dithering}/ErrorDiffuserBase.cs (98%) rename src/ImageSharp/Processing/{Dithering/Processors => Processors/Dithering}/ErrorDiffusionPaletteProcessor.cs (96%) rename src/ImageSharp/Processing/{Dithering/ErrorDiffusion => Processors/Dithering}/FloydSteinbergDiffuser.cs (93%) rename src/ImageSharp/Processing/{Dithering/ErrorDiffusion => Processors/Dithering}/IErrorDiffuser.cs (94%) rename src/ImageSharp/Processing/{Dithering/Ordered => Processors/Dithering}/IOrderedDither.cs (95%) rename src/ImageSharp/Processing/{Dithering/ErrorDiffusion => Processors/Dithering}/JarvisJudiceNinkeDiffuser.cs (93%) rename src/ImageSharp/Processing/{Dithering/Ordered => Processors/Dithering}/OrderedDither.cs (96%) rename src/ImageSharp/Processing/{Dithering/Ordered => Processors/Dithering}/OrderedDither3x3.cs (88%) rename src/ImageSharp/Processing/{Dithering/Ordered => Processors/Dithering}/OrderedDitherFactory.cs (98%) rename src/ImageSharp/Processing/{Dithering/Processors => Processors/Dithering}/OrderedDitherPaletteProcessor.cs (95%) rename src/ImageSharp/Processing/{Dithering/Processors => Processors/Dithering}/PaletteDitherProcessorBase.cs (96%) rename src/ImageSharp/Processing/{Dithering/Processors => Processors/Dithering}/PixelPair.cs (96%) rename src/ImageSharp/Processing/{Dithering/ErrorDiffusion => Processors/Dithering}/Sierra2Diffuser.cs (93%) rename src/ImageSharp/Processing/{Dithering/ErrorDiffusion => Processors/Dithering}/Sierra3Diffuser.cs (93%) rename src/ImageSharp/Processing/{Dithering/ErrorDiffusion => Processors/Dithering}/SierraLiteDiffuser.cs (93%) rename src/ImageSharp/Processing/{Dithering/ErrorDiffusion => Processors/Dithering}/StevensonArceDiffuser.cs (93%) rename src/ImageSharp/Processing/{Dithering/ErrorDiffusion => Processors/Dithering}/StuckiDiffuser.cs (93%) rename src/ImageSharp/Processing/{ => Processors}/Dithering/error_diffusion.txt (100%) rename src/ImageSharp/Processing/{Effects/Processors => Processors/Effects}/OilPaintingProcessor.cs (97%) rename src/ImageSharp/Processing/{Effects/Processors => Processors/Effects}/PixelateProcessor.cs (97%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/AchromatomalyProcessor.cs (92%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/AchromatopsiaProcessor.cs (92%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/BlackWhiteProcessor.cs (91%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/BrightnessProcessor.cs (95%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/ContrastProcessor.cs (95%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/DeuteranomalyProcessor.cs (92%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/DeuteranopiaProcessor.cs (92%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/FilterProcessor.cs (94%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/GrayscaleBt601Processor.cs (94%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/GrayscaleBt709Processor.cs (94%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/HueProcessor.cs (93%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/InvertProcessor.cs (94%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/KodachromeProcessor.cs (92%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/LomographProcessor.cs (90%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/OpacityProcessor.cs (94%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/PolaroidProcessor.cs (91%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/ProtanomalyProcessor.cs (92%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/ProtanopiaProcessor.cs (92%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/README.md (100%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/SaturateProcessor.cs (95%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/SepiaProcessor.cs (93%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/TritanomalyProcessor.cs (92%) rename src/ImageSharp/Processing/{Filters/Processors => Processors/Filters}/TritanopiaProcessor.cs (92%) rename src/ImageSharp/Processing/{Overlays/Processors => Processors/Overlays}/BackgroundColorProcessor.cs (96%) rename src/ImageSharp/Processing/{Overlays/Processors => Processors/Overlays}/GlowProcessor.cs (98%) rename src/ImageSharp/Processing/{Overlays/Processors => Processors/Overlays}/VignetteProcessor.cs (98%) rename src/ImageSharp/Processing/{Quantization/FrameQuantizers => Processors/Quantization}/FrameQuantizerBase{TPixel}.cs (98%) rename src/ImageSharp/Processing/{Quantization/FrameQuantizers => Processors/Quantization}/IFrameQuantizer{TPixel}.cs (89%) rename src/ImageSharp/Processing/{ => Processors}/Quantization/IQuantizer.cs (81%) rename src/ImageSharp/Processing/{Quantization/FrameQuantizers => Processors/Quantization}/OctreeFrameQuantizer{TPixel}.cs (99%) rename src/ImageSharp/Processing/{ => Processors}/Quantization/OctreeQuantizer.cs (92%) rename src/ImageSharp/Processing/{Quantization/FrameQuantizers => Processors/Quantization}/PaletteFrameQuantizer{TPixel}.cs (98%) rename src/ImageSharp/Processing/{ => Processors}/Quantization/PaletteQuantizer.cs (91%) rename src/ImageSharp/Processing/{Quantization/Processors => Processors/Quantization}/QuantizeProcessor.cs (92%) rename src/ImageSharp/Processing/{ => Processors}/Quantization/QuantizedFrame{TPixel}.cs (97%) rename src/ImageSharp/Processing/{Quantization/FrameQuantizers => Processors/Quantization}/WuFrameQuantizer{TPixel}.cs (99%) rename src/ImageSharp/Processing/{ => Processors}/Quantization/WuQuantizer.cs (92%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/AffineTransformProcessor.cs (98%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/AutoOrientProcessor.cs (98%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/BicubicResampler.cs (95%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/BoxResampler.cs (90%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/CatmullRomResampler.cs (92%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/CenteredAffineTransformProcessor.cs (93%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/CenteredProjectiveTransformProcessor.cs (93%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/CropProcessor.cs (97%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/EntropyCropProcessor.cs (89%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/FlipProcessor.cs (93%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/HermiteResampler.cs (91%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/IResampler.cs (91%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/InterpolatedTransformProcessorBase.cs (97%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/Lanczos2Resampler.cs (92%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/Lanczos3Resampler.cs (92%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/Lanczos5Resampler.cs (92%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/Lanczos8Resampler.cs (92%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/MitchellNetravaliResampler.cs (90%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/NearestNeighborResampler.cs (89%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/ProjectiveTransformProcessor.cs (97%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/ResizeProcessor.cs (98%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/RobidouxResampler.cs (90%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/RobidouxSharpResampler.cs (90%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/RotateProcessor.cs (98%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/SkewProcessor.cs (94%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/SplineResampler.cs (90%) rename src/ImageSharp/Processing/{ => Processors}/Transforms/TransformHelpers.cs (99%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/TransformProcessorBase.cs (92%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/TriangleResampler.cs (92%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/WeightsBuffer.cs (96%) rename src/ImageSharp/Processing/{Transforms/Processors => Processors/Transforms}/WeightsWindow.cs (98%) rename src/ImageSharp/Processing/{Transforms/Resamplers => Processors/Transforms}/WelchResampler.cs (91%) rename src/ImageSharp/Processing/{Transforms => }/ProjectiveTransformHelper.cs (99%) rename src/ImageSharp/Processing/{Quantization => }/QuantizeExtensions.cs (92%) rename src/ImageSharp/Processing/{Transforms => }/ResizeExtensions.cs (98%) rename src/ImageSharp/Processing/{Transforms => }/ResizeHelper.cs (99%) rename src/ImageSharp/Processing/{Transforms => }/ResizeMode.cs (96%) rename src/ImageSharp/Processing/{Transforms => }/ResizeOptions.cs (92%) rename src/ImageSharp/Processing/{Transforms => }/RotateExtensions.cs (93%) rename src/ImageSharp/Processing/{Transforms => }/RotateFlipExtensions.cs (95%) rename src/ImageSharp/Processing/{Transforms => }/RotateMode.cs (92%) rename src/ImageSharp/Processing/{Filters => }/SaturateExtensions.cs (95%) rename src/ImageSharp/Processing/{Filters => }/SepiaExtensions.cs (96%) rename src/ImageSharp/Processing/{Transforms => }/SkewExtensions.cs (92%) rename src/ImageSharp/Processing/{Transforms => }/TransformExtensions.cs (97%) rename src/ImageSharp/Processing/{Overlays => }/VignetteExtensions.cs (98%) diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs index 07a70ad96..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 { diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 8a6415c3b..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 diff --git a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs index 30e476e7e..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 { 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 1b3e84b85..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 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 98% rename from src/ImageSharp/Processing/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs rename to src/ImageSharp/Processing/Processors/Dithering/ErrorDiffuserBase.cs index 80b3698a6..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. diff --git a/src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs b/src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs similarity index 96% rename from src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs rename to src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs index 19fde8487..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. 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 95% rename from src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs rename to src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs index 32a3d290e..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. diff --git a/src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs similarity index 96% rename from src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs rename to src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs index 0e801e583..e70c8acd2 100644 --- a/src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs @@ -5,9 +5,8 @@ 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. 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 98% rename from src/ImageSharp/Processing/Quantization/FrameQuantizers/FrameQuantizerBase{TPixel}.cs rename to src/ImageSharp/Processing/Processors/Quantization/FrameQuantizerBase{TPixel}.cs index 6637d54e0..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 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 99% rename from src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs index d73373395..0eb3db864 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs @@ -9,7 +9,7 @@ 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. 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 98% rename from src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Processors/Quantization/PaletteFrameQuantizer{TPixel}.cs index cb72626d5..8df81b426 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/PaletteFrameQuantizer{TPixel}.cs @@ -8,7 +8,7 @@ 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. diff --git a/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs similarity index 91% rename from src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs rename to src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs index dd10a040a..8ae917718 100644 --- a/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs @@ -3,11 +3,9 @@ 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. diff --git a/src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizeProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs rename to src/ImageSharp/Processing/Processors/Quantization/QuantizeProcessor.cs index 5b20805b0..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. diff --git a/src/ImageSharp/Processing/Quantization/QuantizedFrame{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs similarity index 97% rename from src/ImageSharp/Processing/Quantization/QuantizedFrame{TPixel}.cs rename to src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs index 6699c76f4..977b939a1 100644 --- a/src/ImageSharp/Processing/Quantization/QuantizedFrame{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs @@ -6,7 +6,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; // TODO: Consider pooling the TPixel palette also. For Rgba48+ this would end up on th LOH if 256 colors. -namespace SixLabors.ImageSharp.Processing.Quantization +namespace SixLabors.ImageSharp.Processing.Processors.Quantization { /// /// Represents a quantized image frame where the pixels indexed by a color palette. diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs similarity index 99% rename from src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs index cb8721d06..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. 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/Drawing/DrawPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs index ab690f645..112c4a1a8 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -12,12 +12,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..01846708a 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawText.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawText.cs @@ -6,13 +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; @@ -26,7 +23,7 @@ namespace SixLabors.ImageSharp.Benchmarks [Params(10, 100)] 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")] @@ -53,7 +50,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 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)))); } } diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs index e85e33235..d03e69f38 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs @@ -6,13 +6,9 @@ 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; diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs index c53a97515..d78379fc0 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -13,7 +13,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 { diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs index 7bd55e905..ac56caa46 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -11,7 +11,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; 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.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..1790d1a20 100644 --- a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs @@ -6,7 +6,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..4c681fb89 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs @@ -4,14 +4,14 @@ 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..424b875e0 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -6,7 +6,6 @@ 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/FillPatternTests.cs b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs index 29b78220d..c65d04d9d 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -7,7 +7,6 @@ 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 Xunit; namespace SixLabors.ImageSharp.Tests.Drawing diff --git a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs index ecd1c06e8..b664d1a14 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs @@ -6,7 +6,6 @@ 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..6be81e0aa 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.cs @@ -7,7 +7,6 @@ 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/PolygonTests.cs b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs index c7a0531c9..a0b958860 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -7,7 +7,6 @@ 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/SolidBezierTests.cs b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs index 7175e7a65..e8a6eef1d 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -5,7 +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/SolidComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs index 42b0dc1e6..8dcce8167 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs @@ -6,7 +6,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/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index b39cc4632..ed46f323a 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -8,7 +8,6 @@ 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/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index cd3b72e27..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 { diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs index 93cfaff7f..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 diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index 3bcecedec..540fc0716 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -9,7 +9,7 @@ using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Quantization; +using SixLabors.ImageSharp.Processing.Processors.Quantization; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit; 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/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/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 ba31e35a2..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; 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 91b331639..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; 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/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)); } From d6944d5a6a2dc0e1725c514fa797d6da8a6d6ff8 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 3 Jul 2018 15:51:40 +1000 Subject: [PATCH 12/68] Simplify drawing namespaces. --- src/ImageSharp.Drawing/Primitives/ShapePath.cs | 2 +- .../{Drawing/Brushes => }/BrushApplicator.cs | 2 +- .../Processing/{Drawing/Brushes => }/Brushes.cs | 2 +- .../GradientBrushes => }/ColorStop{TPixel}.cs | 7 +++++-- .../{Drawing => }/DrawBezierExtensions.cs | 4 +--- .../Processing/{Drawing => }/DrawImageExtensions.cs | 4 ++-- .../Processing/{Drawing => }/DrawLineExtensions.cs | 4 +--- .../{Drawing => }/DrawPathCollectionExtensions.cs | 4 +--- .../Processing/{Drawing => }/DrawPathExtensions.cs | 4 +--- .../{Drawing => }/DrawPolygonExtensions.cs | 4 +--- .../{Drawing => }/DrawRectangleExtensions.cs | 4 +--- .../Processing/{Text => }/DrawTextExtensions.cs | 6 ++---- .../EllipticGradientBrush{TPixel}.cs | 7 +++++-- .../{Drawing => }/FillPathBuilderExtensions.cs | 3 +-- .../{Drawing => }/FillPathCollectionExtensions.cs | 3 +-- .../Processing/{Drawing => }/FillPathExtensions.cs | 3 +-- .../{Drawing => }/FillPolygonExtensions.cs | 3 +-- .../{Drawing => }/FillRectangleExtensions.cs | 3 +-- .../{Drawing => }/FillRegionExtensions.cs | 5 ++--- .../GradientBrushBase{TPixel}.cs | 7 +++++-- .../GradientBrushes => }/GradientRepetitionMode.cs | 5 ++++- .../Processing/{Drawing/Brushes => }/IBrush.cs | 2 +- .../Processing/{Drawing/Pens => }/IPen.cs | 3 +-- .../{Drawing/Brushes => }/ImageBrush{TPixel}.cs | 2 +- .../LinearGradientBrush{TPixel}.cs | 7 +++++-- .../{Drawing/Brushes => }/PatternBrush{TPixel}.cs | 2 +- .../Processing/{Drawing/Pens => }/Pens.cs | 3 +-- .../Processing/{Drawing/Pens => }/Pen{TPixel}.cs | 11 +++++------ .../Drawing}/DrawImageProcessor.cs | 3 +-- .../Drawing}/FillProcessor.cs | 5 ++--- .../Drawing}/FillRegionProcessor.cs | 4 +--- .../Text}/DrawTextProcessor.cs | 5 +---- .../RadialGradientBrush{TPixel}.cs | 7 +++++-- .../{Drawing/Brushes => }/RecolorBrush{TPixel}.cs | 2 +- .../{Drawing/Brushes => }/SolidBrush{TPixel}.cs | 2 +- .../Processing/{Text => }/TextGraphicsOptions.cs | 2 +- tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs | 1 - tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs | 2 -- tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs | 1 - tests/ImageSharp.Benchmarks/Drawing/DrawText.cs | 13 ++++++------- .../Drawing/DrawTextOutline.cs | 11 +++++------ tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs | 3 +-- .../ImageSharp.Benchmarks/Drawing/FillRectangle.cs | 3 +-- .../Drawing/FillWithPattern.cs | 8 ++------ tests/ImageSharp.Tests/Drawing/BeziersTests.cs | 1 - tests/ImageSharp.Tests/Drawing/DrawImageTest.cs | 2 +- tests/ImageSharp.Tests/Drawing/DrawPathTests.cs | 2 -- .../Drawing/FillEllipticGradientBrushTest.cs | 2 -- .../Drawing/FillLinearGradientBrushTests.cs | 2 -- tests/ImageSharp.Tests/Drawing/FillPatternTests.cs | 5 +---- .../Drawing/FillRadialGradientBrushTests.cs | 3 --- .../Drawing/FillRegionProcessorTests.cs | 8 ++------ .../ImageSharp.Tests/Drawing/FillSolidBrushTests.cs | 2 -- .../Drawing/LineComplexPolygonTests.cs | 2 -- tests/ImageSharp.Tests/Drawing/LineTests.cs | 2 -- .../Drawing/Paths/DrawPathCollection.cs | 6 ++---- tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs | 5 ++--- .../Drawing/Paths/FillPathCollection.cs | 5 ++--- tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs | 5 ++--- .../ImageSharp.Tests/Drawing/Paths/FillRectangle.cs | 5 ++--- tests/ImageSharp.Tests/Drawing/PolygonTests.cs | 1 - tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs | 2 -- tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs | 1 - .../Drawing/SolidComplexPolygonTests.cs | 1 - .../Drawing/SolidFillBlendedShapesTests.cs | 1 - tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs | 2 -- tests/ImageSharp.Tests/Drawing/Text/DrawText.cs | 7 ++----- .../Drawing/Text/DrawTextOnImageTests.cs | 2 -- .../Drawing/Text/TextGraphicsOptionsTests.cs | 2 +- tests/ImageSharp.Tests/Issues/Issue412.cs | 4 +--- .../PixelBlenders/PorterDuffCompositorTests.cs | 1 - .../TestUtilities/ImageProviders/SolidProvider.cs | 2 -- 72 files changed, 100 insertions(+), 171 deletions(-) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes => }/BrushApplicator.cs (98%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes => }/Brushes.cs (99%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes/GradientBrushes => }/ColorStop{TPixel}.cs (86%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/DrawBezierExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/DrawImageExtensions.cs (98%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/DrawLineExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/DrawPathCollectionExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/DrawPathExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/DrawPolygonExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/DrawRectangleExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Text => }/DrawTextExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes/GradientBrushes => }/EllipticGradientBrush{TPixel}.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/FillPathBuilderExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/FillPathCollectionExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/FillPathExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/FillPolygonExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/FillRectangleExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing => }/FillRegionExtensions.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes/GradientBrushes => }/GradientBrushBase{TPixel}.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes/GradientBrushes => }/GradientRepetitionMode.cs (89%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes => }/IBrush.cs (96%) rename src/ImageSharp.Drawing/Processing/{Drawing/Pens => }/IPen.cs (89%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes => }/ImageBrush{TPixel}.cs (98%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes/GradientBrushes => }/LinearGradientBrush{TPixel}.cs (97%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes => }/PatternBrush{TPixel}.cs (99%) rename src/ImageSharp.Drawing/Processing/{Drawing/Pens => }/Pens.cs (98%) rename src/ImageSharp.Drawing/Processing/{Drawing/Pens => }/Pen{TPixel}.cs (84%) rename src/ImageSharp.Drawing/Processing/{Drawing/Processors => Processors/Drawing}/DrawImageProcessor.cs (98%) rename src/ImageSharp.Drawing/Processing/{Drawing/Processors => Processors/Drawing}/FillProcessor.cs (96%) rename src/ImageSharp.Drawing/Processing/{Drawing/Processors => Processors/Drawing}/FillRegionProcessor.cs (97%) rename src/ImageSharp.Drawing/Processing/{Text/Processors => Processors/Text}/DrawTextProcessor.cs (98%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes/GradientBrushes => }/RadialGradientBrush{TPixel}.cs (96%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes => }/RecolorBrush{TPixel}.cs (99%) rename src/ImageSharp.Drawing/Processing/{Drawing/Brushes => }/SolidBrush{TPixel}.cs (98%) rename src/ImageSharp.Drawing/Processing/{Text => }/TextGraphicsOptions.cs (99%) 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 97% rename from src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs rename to src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs index a20d7f730..114de7610 100644 --- a/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs @@ -3,12 +3,10 @@ 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. 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 99% rename from src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs index a7da2cc5b..480c42ee0 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs @@ -8,7 +8,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 brush that can recolor an image 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/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 112c4a1a8..5fbd9f112 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -11,7 +11,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; namespace SixLabors.ImageSharp.Benchmarks { diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawText.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawText.cs index 01846708a..624b54278 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawText.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawText.cs @@ -9,9 +9,8 @@ using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Text; -using SixLabors.ImageSharp.Processing.Drawing; using System.Linq; +using SixLabors.ImageSharp.Processing.Processors.Text; namespace SixLabors.ImageSharp.Benchmarks { @@ -21,7 +20,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(this.TextPhrase, this.TextIterations)); @@ -38,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)); } } } @@ -50,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 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)))); } } @@ -60,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 d03e69f38..ba6d055e3 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs @@ -8,9 +8,8 @@ using System.Drawing.Drawing2D; using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Text; -using SixLabors.ImageSharp.Processing.Drawing; using System.Linq; +using SixLabors.ImageSharp.Processing.Processors.Text; namespace SixLabors.ImageSharp.Benchmarks { @@ -20,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)); @@ -50,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)))); } } @@ -60,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 d78379fc0..8aadb85bf 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -12,7 +12,6 @@ using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; namespace SixLabors.ImageSharp.Benchmarks { @@ -36,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 ac56caa46..643e4ac9a 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -10,7 +10,6 @@ using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; using CoreRectangle = SixLabors.Primitives.Rectangle; using CoreSize = SixLabors.Primitives.Size; @@ -30,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.Tests/Drawing/BeziersTests.cs b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs index 1790d1a20..443b49c7c 100644 --- a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs @@ -5,7 +5,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; using SixLabors.Memory; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs index 4c681fb89..40ad92adc 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs @@ -4,7 +4,7 @@ using System; using System.Numerics; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index 424b875e0..96af63fd5 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.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.Drawing.Pens; 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 c65d04d9d..f13f808b6 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -5,14 +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.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 b664d1a14..d3b39709a 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.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.Drawing.Pens; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/LineTests.cs b/tests/ImageSharp.Tests/Drawing/LineTests.cs index 6be81e0aa..747c75cde 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.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.Drawing.Pens; 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 a0b958860..f9a41baba 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -6,7 +6,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; 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 e8a6eef1d..94d3d49ff 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -4,7 +4,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; using SixLabors.Shapes; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs index 8dcce8167..c8d3fe1bc 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs @@ -5,7 +5,6 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; 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 ed46f323a..e42b4b481 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -6,8 +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.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/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/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/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 From dd698dd483b303b9c602ffbc13e61fb0b6063e29 Mon Sep 17 00:00:00 2001 From: popow Date: Tue, 3 Jul 2018 11:02:55 +0200 Subject: [PATCH 13/68] using GetPixelSpan instead of GetPixelRowSpan --- .../HistogramEqualizationProcessor.cs | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs index aa1526c87..633761352 100644 --- a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs @@ -29,15 +29,12 @@ namespace SixLabors.ImageSharp.Processing.Normalization // build the histogram of the grayscale levels int luminanceLevels = is16bitPerChannel ? 65536 : 256; Span histogram = memoryAllocator.Allocate(luminanceLevels, clear: true).GetSpan(); - for (int y = 0; y < source.Height; y++) + Span pixels = source.GetPixelSpan(); + for (int i = 0; i < pixels.Length; i++) { - Span row = source.GetPixelRowSpan(y); - for (int x = 0; x < source.Width; x++) - { - TPixel sourcePixel = row[x]; - int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); - histogram[luminance]++; - } + TPixel sourcePixel = pixels[i]; + int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); + histogram[luminance]++; } // calculate the cumulative distribution function (which will be the cumulative histogram) @@ -69,25 +66,21 @@ namespace SixLabors.ImageSharp.Processing.Normalization // apply the cdf to each pixel of the image double numberOfPixelsMinusCdfMin = (double)(numberOfPixels - cdfMin); int luminanceLevelsMinusOne = luminanceLevels - 1; - for (int y = 0; y < source.Height; y++) + for (int i = 0; i < pixels.Length; i++) { - Span row = source.GetPixelRowSpan(y); - for (int x = 0; x < source.Width; x++) - { - TPixel sourcePixel = row[x]; + TPixel sourcePixel = pixels[i]; - int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); - double luminanceEqualized = (cdf[luminance] / numberOfPixelsMinusCdfMin) * luminanceLevelsMinusOne; - luminanceEqualized = Math.Round(luminanceEqualized); + int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); + double luminanceEqualized = (cdf[luminance] / numberOfPixelsMinusCdfMin) * luminanceLevelsMinusOne; + luminanceEqualized = Math.Round(luminanceEqualized); - if (is16bitPerChannel) - { - row[x].PackFromRgb48(new Rgb48((ushort)luminanceEqualized, (ushort)luminanceEqualized, (ushort)luminanceEqualized)); - } - else - { - row[x].PackFromRgba32(new Rgba32((byte)luminanceEqualized, (byte)luminanceEqualized, (byte)luminanceEqualized)); - } + if (is16bitPerChannel) + { + pixels[i].PackFromRgb48(new Rgb48((ushort)luminanceEqualized, (ushort)luminanceEqualized, (ushort)luminanceEqualized)); + } + else + { + pixels[i].PackFromRgba32(new Rgba32((byte)luminanceEqualized, (byte)luminanceEqualized, (byte)luminanceEqualized)); } } } From f78d9b752e90e1e37512b2d51112335a878153ce Mon Sep 17 00:00:00 2001 From: popow Date: Tue, 3 Jul 2018 12:20:43 +0200 Subject: [PATCH 14/68] allocating cdf and histogram buffer with a using statement --- .../HistogramEqualizationProcessor.cs | 79 ++++++++++++------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs index 633761352..6558f4889 100644 --- a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs @@ -26,19 +26,57 @@ namespace SixLabors.ImageSharp.Processing.Normalization int numberOfPixels = source.Width * source.Height; bool is16bitPerChannel = typeof(TPixel) == typeof(Rgb48) || typeof(TPixel) == typeof(Rgba64); + Span pixels = source.GetPixelSpan(); + // build the histogram of the grayscale levels int luminanceLevels = is16bitPerChannel ? 65536 : 256; - Span histogram = memoryAllocator.Allocate(luminanceLevels, clear: true).GetSpan(); - Span pixels = source.GetPixelSpan(); - for (int i = 0; i < pixels.Length; i++) + using (IBuffer histogramBuffer = memoryAllocator.AllocateClean(luminanceLevels)) + using (IBuffer cdfBuffer = memoryAllocator.AllocateClean(luminanceLevels)) { - TPixel sourcePixel = pixels[i]; - int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); - histogram[luminance]++; + Span histogram = histogramBuffer.GetSpan(); + for (int i = 0; i < pixels.Length; i++) + { + TPixel sourcePixel = pixels[i]; + int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); + histogram[luminance]++; + } + + // calculate the cumulative distribution function, which will map each input pixel to a new value + Span cdf = cdfBuffer.GetSpan(); + int cdfMin = this.CaluclateCdf(cdf, histogram); + + // apply the cdf to each pixel of the image + double numberOfPixelsMinusCdfMin = (double)(numberOfPixels - cdfMin); + int luminanceLevelsMinusOne = luminanceLevels - 1; + for (int i = 0; i < pixels.Length; i++) + { + TPixel sourcePixel = pixels[i]; + + int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); + double luminanceEqualized = (cdf[luminance] / numberOfPixelsMinusCdfMin) * luminanceLevelsMinusOne; + luminanceEqualized = Math.Round(luminanceEqualized); + + if (is16bitPerChannel) + { + pixels[i].PackFromRgb48(new Rgb48((ushort)luminanceEqualized, (ushort)luminanceEqualized, (ushort)luminanceEqualized)); + } + else + { + pixels[i].PackFromRgba32(new Rgba32((byte)luminanceEqualized, (byte)luminanceEqualized, (byte)luminanceEqualized)); + } + } } + } - // calculate the cumulative distribution function (which will be the cumulative histogram) - Span cdf = memoryAllocator.Allocate(luminanceLevels, clear: true).GetSpan(); + /// + /// Calculate the cumulative distribution function + /// + /// The array holding the cdf + /// The histogram of the input image + /// The first none zero value of the cdf + private int CaluclateCdf(Span cdf, Span histogram) + { + // calculate the cumulative histogram int histSum = 0; for (int i = 0; i < histogram.Length; i++) { @@ -50,7 +88,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization int cdfMin = 0; for (int i = 0; i < histogram.Length; i++) { - if (histogram[i] != 0) + if (cdf[i] != 0) { cdfMin = cdf[i]; break; @@ -60,29 +98,10 @@ namespace SixLabors.ImageSharp.Processing.Normalization // creating the lookup table: subtracting cdf min, so we do not need to do that inside the for loop for (int i = 0; i < histogram.Length; i++) { - cdf[i] = cdf[i] - cdfMin; + cdf[i] = Math.Max(0, cdf[i] - cdfMin); } - // apply the cdf to each pixel of the image - double numberOfPixelsMinusCdfMin = (double)(numberOfPixels - cdfMin); - int luminanceLevelsMinusOne = luminanceLevels - 1; - for (int i = 0; i < pixels.Length; i++) - { - TPixel sourcePixel = pixels[i]; - - int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); - double luminanceEqualized = (cdf[luminance] / numberOfPixelsMinusCdfMin) * luminanceLevelsMinusOne; - luminanceEqualized = Math.Round(luminanceEqualized); - - if (is16bitPerChannel) - { - pixels[i].PackFromRgb48(new Rgb48((ushort)luminanceEqualized, (ushort)luminanceEqualized, (ushort)luminanceEqualized)); - } - else - { - pixels[i].PackFromRgba32(new Rgba32((byte)luminanceEqualized, (byte)luminanceEqualized, (byte)luminanceEqualized)); - } - } + return cdfMin; } /// From ac69aa7bfdeca440f147f8ba97daaf052363ab74 Mon Sep 17 00:00:00 2001 From: popow Date: Tue, 3 Jul 2018 13:46:15 +0200 Subject: [PATCH 15/68] using Vector4 to calculate the luminance and set the pixel value --- .../HistogramEqualizationProcessor.cs | 39 +++++-------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs index 6558f4889..ac6d23725 100644 --- a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Numerics; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; @@ -20,8 +21,6 @@ namespace SixLabors.ImageSharp.Processing.Normalization /// protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { - var rgb48 = default(Rgb48); - var rgb24 = default(Rgb24); MemoryAllocator memoryAllocator = configuration.MemoryAllocator; int numberOfPixels = source.Width * source.Height; bool is16bitPerChannel = typeof(TPixel) == typeof(Rgb48) || typeof(TPixel) == typeof(Rgba64); @@ -37,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization for (int i = 0; i < pixels.Length; i++) { TPixel sourcePixel = pixels[i]; - int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); + int luminance = this.GetLuminance(sourcePixel, luminanceLevels); histogram[luminance]++; } @@ -47,23 +46,14 @@ namespace SixLabors.ImageSharp.Processing.Normalization // apply the cdf to each pixel of the image double numberOfPixelsMinusCdfMin = (double)(numberOfPixels - cdfMin); - int luminanceLevelsMinusOne = luminanceLevels - 1; for (int i = 0; i < pixels.Length; i++) { TPixel sourcePixel = pixels[i]; - int luminance = this.GetLuminance(sourcePixel, is16bitPerChannel, ref rgb24, ref rgb48); - double luminanceEqualized = (cdf[luminance] / numberOfPixelsMinusCdfMin) * luminanceLevelsMinusOne; - luminanceEqualized = Math.Round(luminanceEqualized); + int luminance = this.GetLuminance(sourcePixel, luminanceLevels); + double luminanceEqualized = cdf[luminance] / numberOfPixelsMinusCdfMin; - if (is16bitPerChannel) - { - pixels[i].PackFromRgb48(new Rgb48((ushort)luminanceEqualized, (ushort)luminanceEqualized, (ushort)luminanceEqualized)); - } - else - { - pixels[i].PackFromRgba32(new Rgba32((byte)luminanceEqualized, (byte)luminanceEqualized, (byte)luminanceEqualized)); - } + pixels[i].PackFromVector4(new Vector4((float)luminanceEqualized)); } } } @@ -108,23 +98,12 @@ namespace SixLabors.ImageSharp.Processing.Normalization /// Convert the pixel values to grayscale using ITU-R Recommendation BT.709. /// /// The pixel to get the luminance from - /// Flag indicates, if its 16 bits per channel, otherwise its 8 - /// Will store the pixel values in case of 8 bit per channel - /// Will store the pixel values in case of 16 bit per channel - private int GetLuminance(TPixel sourcePixel, bool is16bitPerChannel, ref Rgb24 rgb24, ref Rgb48 rgb48) + /// The number of luminance levels (256 for 8 bit, 65536 for 16 bit grayscale images) + private int GetLuminance(TPixel sourcePixel, int luminanceLevels) { // Convert to grayscale using ITU-R Recommendation BT.709 - int luminance; - if (is16bitPerChannel) - { - sourcePixel.ToRgb48(ref rgb48); - luminance = Convert.ToInt32((.2126F * rgb48.R) + (.7152F * rgb48.G) + (.0722F * rgb48.B)); - } - else - { - sourcePixel.ToRgb24(ref rgb24); - luminance = Convert.ToInt32((.2126F * rgb24.R) + (.7152F * rgb24.G) + (.0722F * rgb24.B)); - } + var vector = sourcePixel.ToVector4(); + int luminance = Convert.ToInt32(((.2126F * vector.X) + (.7152F * vector.Y) + (.0722F * vector.Y)) * luminanceLevels); return luminance; } From 72b04317a843090d9225aca12db3ba1df74094ee Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 09:07:39 -0700 Subject: [PATCH 16/68] Spanify blittable equality checks --- .../MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs | 2 +- .../MetaData/Profiles/ICC/Curves/IccResponseCurve.cs | 2 +- .../MetaData/Profiles/ICC/Curves/IccSampledCurveElement.cs | 3 +-- .../ICC/MultiProcessElements/IccMatrixProcessElement.cs | 3 +-- .../ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs | 3 +-- .../Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs | 3 +-- .../Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs | 3 +-- .../ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs | 3 +-- .../IccProfileSequenceIdentifierTagDataEntry.cs | 3 +-- .../ICC/TagDataEntries/IccScreeningTagDataEntry.cs | 3 +-- .../ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs | 3 +-- .../ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs | 3 +-- .../ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs | 3 +-- .../ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs | 2 +- .../ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs | 3 +-- .../Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs | 5 ++--- .../Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs | 3 +-- .../Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs | 7 +++---- src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs | 4 ++-- src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs | 3 +-- .../MetaData/Profiles/ICC/Various/IccScreeningChannel.cs | 2 ++ 21 files changed, 26 insertions(+), 40 deletions(-) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs index a7ce0e809..2ad9079e1 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return this.BreakPoints.SequenceEqual(other.BreakPoints) + return this.BreakPoints.AsSpan().SequenceEqual(other.BreakPoints) && this.Segments.SequenceEqual(other.Segments); } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs index e15d8a434..6873c5f4d 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } return this.CurveType == other.CurveType - && this.XyzValues.SequenceEqual(other.XyzValues) + && this.XyzValues.AsSpan().SequenceEqual(other.XyzValues) && this.EqualsResponseArray(other); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccSampledCurveElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccSampledCurveElement.cs index 572c4a8f7..d9badf5a8 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccSampledCurveElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccSampledCurveElement.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -34,7 +33,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { if (base.Equals(other) && other is IccSampledCurveElement segment) { - return this.CurveEntries.SequenceEqual(segment.CurveEntries); + return this.CurveEntries.AsSpan().SequenceEqual(segment.CurveEntries); } return false; diff --git a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs index 13b58161c..e6170f768 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; using SixLabors.ImageSharp.Primitives; @@ -47,7 +46,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc if (base.Equals(other) && other is IccMatrixProcessElement element) { return this.EqualsMatrix(element) - && this.MatrixOx1.SequenceEqual(element.MatrixOx1); + && this.MatrixOx1.AsSpan().SequenceEqual(element.MatrixOx1); } return false; diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs index 2194b8ab4..6df2f556f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -59,7 +58,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return base.Equals(other) && this.ColorantNumber.SequenceEqual(other.ColorantNumber); + return base.Equals(other) && this.ColorantNumber.AsSpan().SequenceEqual(other.ColorantNumber); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs index 154afd8ed..40666934f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -107,7 +106,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return base.Equals(other) && this.CurveData.SequenceEqual(other.CurveData); + return base.Equals(other) && this.CurveData.AsSpan().SequenceEqual(other.CurveData); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs index a1addaa90..7f034cebf 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; using System.Text; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc @@ -83,7 +82,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return base.Equals(other) && this.Data.SequenceEqual(other.Data) && this.IsAscii == other.IsAscii; + return base.Equals(other) && this.Data.AsSpan().SequenceEqual(other.Data) && this.IsAscii == other.IsAscii; } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs index b0d9e1ef9..8a7d068f9 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -56,7 +55,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return base.Equals(other) && this.Data.SequenceEqual(other.Data); + return base.Equals(other) && this.Data.AsSpan().SequenceEqual(other.Data); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs index f6b0582fb..333615524 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -57,7 +56,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return base.Equals(other) && this.Data.SequenceEqual(other.Data); + return base.Equals(other) && this.Data.AsSpan().SequenceEqual(other.Data); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs index c93781d9e..de6264824 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -68,7 +67,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return base.Equals(other) && this.Flags == other.Flags - && this.Channels.SequenceEqual(other.Channels); + && this.Channels.AsSpan().SequenceEqual(other.Channels); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs index 63a19d6d4..4d9979a4f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -56,7 +55,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return base.Equals(other) && this.Data.SequenceEqual(other.Data); + return base.Equals(other) && this.Data.AsSpan().SequenceEqual(other.Data); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs index d082df39a..b0c225d85 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -56,7 +55,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return base.Equals(other) && this.Data.SequenceEqual(other.Data); + return base.Equals(other) && this.Data.AsSpan().SequenceEqual(other.Data); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs index 2e3efe1c7..c8b95d835 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -56,7 +55,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return base.Equals(other) && this.Data.SequenceEqual(other.Data); + return base.Equals(other) && this.Data.AsSpan().SequenceEqual(other.Data); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs index 85ae2f9fa..b780183df 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs @@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return base.Equals(other) && this.Data.SequenceEqual(other.Data); + return base.Equals(other) && this.Data.AsSpan().SequenceEqual(other.Data); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs index a673abf68..920b9efc0 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -56,7 +55,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return base.Equals(other) && this.Data.SequenceEqual(other.Data); + return base.Equals(other) && this.Data.AsSpan().SequenceEqual(other.Data); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs index fd38e659b..28759a54c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -77,8 +76,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } return base.Equals(other) - && this.UcrCurve.SequenceEqual(other.UcrCurve) - && this.BgCurve.SequenceEqual(other.BgCurve) + && this.UcrCurve.AsSpan().SequenceEqual(other.UcrCurve) + && this.BgCurve.AsSpan().SequenceEqual(other.BgCurve) && string.Equals(this.Description, other.Description); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs index 0f0a9d218..68a0ff2f4 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -56,7 +55,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return base.Equals(other) && this.Data.SequenceEqual(other.Data); + return base.Equals(other) && this.Data.AsSpan().SequenceEqual(other.Data); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs index b776cc4c0..162392326 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; using System.Numerics; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc @@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// Initializes a new instance of the class. /// - /// The XYZ numbers + /// The XYZ numbers. public IccXyzTagDataEntry(Vector3[] data) : this(data, IccProfileTag.Unknown) { @@ -34,7 +33,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } /// - /// Gets the XYZ numbers + /// Gets the XYZ numbers. /// public Vector3[] Data { get; } @@ -43,7 +42,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { if (base.Equals(other) && other is IccXyzTagDataEntry entry) { - return this.Data.SequenceEqual(entry.Data); + return this.Data.AsSpan().SequenceEqual(entry.Data); } return false; diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs index e88115438..3f9d865b7 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs @@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc && this.DataType == other.DataType && this.InputChannelCount == other.InputChannelCount && this.OutputChannelCount == other.OutputChannelCount - && this.GridPointCount.SequenceEqual(other.GridPointCount); + && this.GridPointCount.AsSpan().SequenceEqual(other.GridPointCount); } /// @@ -162,7 +162,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc for (int i = 0; i < this.Values.Length; i++) { - if (!this.Values[i].SequenceEqual(other.Values[i])) + if (!this.Values[i].AsSpan().SequenceEqual(other.Values[i])) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs index c263ffe27..a84631143 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Linq; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -68,7 +67,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return true; } - return this.Values.SequenceEqual(other.Values); + return this.Values.AsSpan().SequenceEqual(other.Values); } } } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs index 79c647bf1..1c4ac8465 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs @@ -2,12 +2,14 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Runtime.InteropServices; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { /// /// A single channel of a /// + [StructLayout(LayoutKind.Sequential)] internal readonly struct IccScreeningChannel : IEquatable { /// From 652c056f897cc53531c3ddfd23a3f838787c5208 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 09:11:05 -0700 Subject: [PATCH 17/68] Simplify IccProfileId IsSet --- .../Profiles/ICC/Various/IccProfileId.cs | 15 ++------- .../Profiles/ICC/Various/IccProfileIdTests.cs | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 tests/ImageSharp.Tests/MetaData/Profiles/ICC/Various/IccProfileIdTests.cs diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs index 67911936f..138999710 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// A profile ID with all values set to zero /// - public static readonly IccProfileId Zero = new IccProfileId(0, 0, 0, 0); + public static readonly IccProfileId Zero = default; /// /// Initializes a new instance of the struct. @@ -53,16 +53,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// Gets a value indicating whether the ID is set or just consists of zeros /// - public bool IsSet - { - get - { - return this.Part1 != 0 - && this.Part2 != 0 - && this.Part3 != 0 - && this.Part4 != 0; - } - } + public bool IsSet => !this.Equals(Zero); /// /// Compares two objects for equality. @@ -131,4 +122,4 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return value.ToString("X").PadLeft(8, '0'); } } -} +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/Various/IccProfileIdTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/Various/IccProfileIdTests.cs new file mode 100644 index 000000000..46b8b31b4 --- /dev/null +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/Various/IccProfileIdTests.cs @@ -0,0 +1,32 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.MetaData.Profiles.Icc; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Icc +{ + public class IccProfileIdTests + { + [Fact] + public void ZeroIsEqualToDefault() + { + Assert.True(IccProfileId.Zero.Equals(default)); + + Assert.False(default(IccProfileId).IsSet); + } + + [Fact] + public void SetIsTrueWhenNonDefaultValue() + { + var id = new IccProfileId(1, 2, 3, 4); + + Assert.True(id.IsSet); + + Assert.Equal(1u, id.Part1); + Assert.Equal(2u, id.Part2); + Assert.Equal(3u, id.Part3); + Assert.Equal(4u, id.Part4); + } + } +} \ No newline at end of file From 1de176e0a2cdb13fc5ae2622b01352b4a96d39a1 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 09:24:51 -0700 Subject: [PATCH 18/68] Remove MethodImplOptions.AggressiveInlining from trival field accessors This JIT, particually with tiering enabled, should already be inlining these. --- src/ImageSharp/ColorSpaces/CieLab.cs | 9 +-------- src/ImageSharp/ColorSpaces/CieLch.cs | 6 +----- src/ImageSharp/ColorSpaces/CieLchuv.cs | 9 +-------- src/ImageSharp/ColorSpaces/CieLuv.cs | 9 +-------- .../ColorSpaces/CieXyChromaticityCoordinates.cs | 3 --- src/ImageSharp/ColorSpaces/CieXyy.cs | 9 +-------- src/ImageSharp/ColorSpaces/CieXyz.cs | 4 ---- src/ImageSharp/ColorSpaces/Cmyk.cs | 1 - src/ImageSharp/ColorSpaces/Hsl.cs | 9 +-------- src/ImageSharp/ColorSpaces/HunterLab.cs | 9 +-------- src/ImageSharp/ColorSpaces/LinearRgb.cs | 9 +-------- src/ImageSharp/ColorSpaces/Lms.cs | 9 +-------- src/ImageSharp/ColorSpaces/Rgb.cs | 9 +-------- src/ImageSharp/ColorSpaces/YCbCr.cs | 6 +----- 14 files changed, 11 insertions(+), 90 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index 66900079f..9d8d662c8 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -83,11 +83,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// Gets the reference white point of this color /// - public CieXyz WhitePoint - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get; - } + public CieXyz WhitePoint { get; } /// /// Gets the lightness dimension. @@ -144,7 +140,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(CieLab left, CieLab right) { return left.Equals(right); @@ -162,7 +157,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieLab left, CieLab right) { return !left.Equals(right); @@ -191,7 +185,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is CieLab other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs index 57ed5f48d..521e647e4 100644 --- a/src/ImageSharp/ColorSpaces/CieLch.cs +++ b/src/ImageSharp/ColorSpaces/CieLch.cs @@ -83,11 +83,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// Gets the reference white point of this color /// - public CieXyz WhitePoint - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get; - } + public CieXyz WhitePoint { get; } /// /// Gets the lightness dimension. diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs index a378aae86..682d7f2e4 100644 --- a/src/ImageSharp/ColorSpaces/CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs @@ -83,11 +83,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// Gets the reference white point of this color /// - public CieXyz WhitePoint - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get; - } + public CieXyz WhitePoint { get; } /// /// Gets the lightness dimension. @@ -144,7 +140,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(CieLchuv left, CieLchuv right) { return left.Equals(right); @@ -162,7 +157,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieLchuv left, CieLchuv right) { return !left.Equals(right); @@ -191,7 +185,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is CieLchuv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs index f93e1fd46..60827e4aa 100644 --- a/src/ImageSharp/ColorSpaces/CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLuv.cs @@ -85,11 +85,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// Gets the reference white point of this color /// - public CieXyz WhitePoint - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get; - } + public CieXyz WhitePoint { get; } /// /// Gets the lightness dimension @@ -146,7 +142,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(CieLuv left, CieLuv right) { return left.Equals(right); @@ -164,7 +159,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieLuv left, CieLuv right) { return !left.Equals(right); @@ -193,7 +187,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is CieLuv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs index 6716b1bad..10a251420 100644 --- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs @@ -105,7 +105,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieXyChromaticityCoordinates left, CieXyChromaticityCoordinates right) { return !left.Equals(right); @@ -129,14 +128,12 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is CieXyChromaticityCoordinates other && this.Equals(other); } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(CieXyChromaticityCoordinates other) { // The memberwise comparison here is a workaround for https://github.com/dotnet/coreclr/issues/16443 diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs index 71ad4701a..690b3fcfc 100644 --- a/src/ImageSharp/ColorSpaces/CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/CieXyy.cs @@ -85,11 +85,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public bool IsEmpty => this.Equals(Empty); /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Compares two objects for equality. @@ -103,7 +99,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(CieXyy left, CieXyy right) { return left.Equals(right); @@ -121,7 +116,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieXyy left, CieXyy right) { return !left.Equals(right); @@ -145,7 +139,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is CieXyy other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs index 79676bb08..fec4c74e2 100644 --- a/src/ImageSharp/ColorSpaces/CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/CieXyz.cs @@ -40,7 +40,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// Initializes a new instance of the struct. /// /// The vector representing the x, y, z components. - [MethodImpl(MethodImplOptions.AggressiveInlining)] public CieXyz(Vector3 vector) : this() { @@ -103,7 +102,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(CieXyz left, CieXyz right) { return left.Equals(right); @@ -121,7 +119,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieXyz left, CieXyz right) { return !left.Equals(right); @@ -145,7 +142,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is CieXyz other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs index 989d512bb..ffbe2e265 100644 --- a/src/ImageSharp/ColorSpaces/Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Cmyk.cs @@ -147,7 +147,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is Cmyk other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs index 88b14fa97..31b93d384 100644 --- a/src/ImageSharp/ColorSpaces/Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Hsl.cs @@ -87,11 +87,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public bool IsEmpty => this.Equals(Empty); /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Compares two objects for equality. @@ -105,7 +101,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Hsl left, Hsl right) { return left.Equals(right); @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Hsl left, Hsl right) { return !left.Equals(right); @@ -147,7 +141,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is Hsl other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs index 4395d9d7c..9197be32e 100644 --- a/src/ImageSharp/ColorSpaces/HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/HunterLab.cs @@ -122,11 +122,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public bool IsEmpty => this.Equals(Empty); /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Compares two objects for equality. @@ -140,7 +136,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(HunterLab left, HunterLab right) { return left.Equals(right); @@ -158,7 +153,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(HunterLab left, HunterLab right) { return !left.Equals(right); @@ -187,7 +181,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is HunterLab other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs index c721347be..f66527266 100644 --- a/src/ImageSharp/ColorSpaces/LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs @@ -119,11 +119,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public bool IsEmpty => this.Equals(Empty); /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Compares two objects for equality. @@ -137,7 +133,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(LinearRgb left, LinearRgb right) { return left.Equals(right); @@ -155,7 +150,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(LinearRgb left, LinearRgb right) { return !left.Equals(right); @@ -179,7 +173,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is LinearRgb other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs index e46249569..81a068d50 100644 --- a/src/ImageSharp/ColorSpaces/Lms.cs +++ b/src/ImageSharp/ColorSpaces/Lms.cs @@ -86,11 +86,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public bool IsEmpty => this.Equals(Empty); /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Compares two objects for equality. @@ -104,7 +100,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Lms left, Lms right) { return left.Equals(right); @@ -122,7 +117,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Lms left, Lms right) { return !left.Equals(right); @@ -146,7 +140,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is Lms other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index 8cdf54ace..351d2b187 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -125,11 +125,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public bool IsEmpty => this.Equals(Empty); /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Allows the implicit conversion of an instance of to a @@ -159,7 +155,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Rgb left, Rgb right) { return left.Equals(right); @@ -177,7 +172,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Rgb left, Rgb right) { return !left.Equals(right); @@ -201,7 +195,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is Rgb other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs index 2c3feffa9..cb1060137 100644 --- a/src/ImageSharp/ColorSpaces/YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/YCbCr.cs @@ -89,11 +89,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public bool IsEmpty => this.Equals(Empty); /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Compares two objects for equality. From 4319c22337d454c99c2b9e6b52daf8b16d198d44 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 09:38:56 -0700 Subject: [PATCH 19/68] Use HashHelpers --- src/ImageSharp/ColorSpaces/CieLab.cs | 16 ++++------------ src/ImageSharp/ColorSpaces/CieLch.cs | 16 ++++------------ src/ImageSharp/ColorSpaces/CieLchuv.cs | 17 ++++------------- src/ImageSharp/ColorSpaces/CieLuv.cs | 16 ++++------------ src/ImageSharp/ColorSpaces/HunterLab.cs | 16 ++++------------ 5 files changed, 20 insertions(+), 61 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index 9d8d662c8..9eb072a53 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -165,23 +165,15 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override int GetHashCode() { - unchecked - { - int hashCode = this.WhitePoint.GetHashCode(); - hashCode = (hashCode * 397) ^ this.backingVector.GetHashCode(); - return hashCode; - } + return HashHelpers.Combine(this.WhitePoint.GetHashCode(), this.backingVector.GetHashCode()); } /// public override string ToString() { - if (this.IsEmpty) - { - return "CieLab [Empty]"; - } - - return $"CieLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]"; + return this.IsEmpty + ? "CieLab [Empty]" + : $"CieLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]"; } /// diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs index 521e647e4..059e9684f 100644 --- a/src/ImageSharp/ColorSpaces/CieLch.cs +++ b/src/ImageSharp/ColorSpaces/CieLch.cs @@ -167,23 +167,15 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override int GetHashCode() { - unchecked - { - int hashCode = this.WhitePoint.GetHashCode(); - hashCode = (hashCode * 397) ^ this.backingVector.GetHashCode(); - return hashCode; - } + return HashHelpers.Combine(this.WhitePoint.GetHashCode(), this.backingVector.GetHashCode()); } /// public override string ToString() { - if (this.IsEmpty) - { - return "CieLch [Empty]"; - } - - return $"CieLch [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}]"; + return this.IsEmpty + ? "CieLch [Empty]" + : $"CieLch [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}]"; } /// diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs index 682d7f2e4..503ce65aa 100644 --- a/src/ImageSharp/ColorSpaces/CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs @@ -165,23 +165,15 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override int GetHashCode() { - unchecked - { - int hashCode = this.WhitePoint.GetHashCode(); - hashCode = (hashCode * 397) ^ this.backingVector.GetHashCode(); - return hashCode; - } + return HashHelpers.Combine(this.WhitePoint.GetHashCode(), this.backingVector.GetHashCode()); } /// public override string ToString() { - if (this.IsEmpty) - { - return "CieLchuv [Empty]"; - } - - return $"CieLchuv [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}]"; + return this.IsEmpty + ? "CieLchuv [Empty]" + : $"CieLchuv [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}"; } /// @@ -191,7 +183,6 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(CieLchuv other) { return this.backingVector.Equals(other.backingVector) diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs index 60827e4aa..8b385418c 100644 --- a/src/ImageSharp/ColorSpaces/CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLuv.cs @@ -167,23 +167,15 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override int GetHashCode() { - unchecked - { - int hashCode = this.WhitePoint.GetHashCode(); - hashCode = (hashCode * 397) ^ this.backingVector.GetHashCode(); - return hashCode; - } + return HashHelpers.Combine(this.WhitePoint.GetHashCode(), this.backingVector.GetHashCode()); } /// public override string ToString() { - if (this.IsEmpty) - { - return "CieLuv [ Empty ]"; - } - - return $"CieLuv [ L={this.L:#0.##}, U={this.U:#0.##}, V={this.V:#0.##} ]"; + return this.IsEmpty + ? "CieLuv [ Empty ]" + : $"CieLuv [ L={this.L:#0.##}, U={this.U:#0.##}, V={this.V:#0.##} ]"; } /// diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs index 9197be32e..671801949 100644 --- a/src/ImageSharp/ColorSpaces/HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/HunterLab.cs @@ -161,23 +161,15 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override int GetHashCode() { - unchecked - { - int hashCode = this.WhitePoint.GetHashCode(); - hashCode = (hashCode * 397) ^ this.backingVector.GetHashCode(); - return hashCode; - } + return HashHelpers.Combine(this.WhitePoint.GetHashCode(), this.backingVector.GetHashCode()); } /// public override string ToString() { - if (this.IsEmpty) - { - return "HunterLab [Empty]"; - } - - return $"HunterLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]"; + return this.IsEmpty + ? "HunterLab [Empty]" + : $"HunterLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]"; } /// From 9cdf8e7596bad644bac0592e8b02640cb3328102 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 09:46:03 -0700 Subject: [PATCH 20/68] Remove IsEmpty properties when we can just compare to default --- src/ImageSharp/ColorSpaces/CieLab.cs | 13 +--------- src/ImageSharp/ColorSpaces/CieLch.cs | 13 +--------- src/ImageSharp/ColorSpaces/CieLchuv.cs | 13 +--------- src/ImageSharp/ColorSpaces/CieLuv.cs | 13 +--------- .../CieXyChromaticityCoordinates.cs | 20 +++----------- src/ImageSharp/ColorSpaces/CieXyy.cs | 20 +++----------- src/ImageSharp/ColorSpaces/CieXyz.cs | 20 +++----------- src/ImageSharp/ColorSpaces/Cmyk.cs | 20 +++----------- src/ImageSharp/ColorSpaces/Hsl.cs | 20 +++----------- src/ImageSharp/ColorSpaces/Hsv.cs | 23 +++------------- src/ImageSharp/ColorSpaces/HunterLab.cs | 13 +--------- src/ImageSharp/ColorSpaces/LinearRgb.cs | 20 +++----------- src/ImageSharp/ColorSpaces/Lms.cs | 20 +++----------- src/ImageSharp/ColorSpaces/Rgb.cs | 26 +++---------------- src/ImageSharp/ColorSpaces/YCbCr.cs | 24 +++-------------- 15 files changed, 36 insertions(+), 242 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index 9eb072a53..c9581379b 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -20,11 +20,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public static readonly CieXyz DefaultWhitePoint = Illuminants.D50; - /// - /// Represents a that has L, A, B values set to zero. - /// - public static readonly CieLab Empty = default; - /// /// The backing vector for SIMD support. /// @@ -115,12 +110,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Z; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector { @@ -171,7 +160,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.IsEmpty + return this.Equals(default) ? "CieLab [Empty]" : $"CieLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]"; } diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs index 059e9684f..4fa853206 100644 --- a/src/ImageSharp/ColorSpaces/CieLch.cs +++ b/src/ImageSharp/ColorSpaces/CieLch.cs @@ -20,11 +20,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public static readonly CieXyz DefaultWhitePoint = Illuminants.D50; - /// - /// Represents a that has L, C, H values set to zero. - /// - public static readonly CieLch Empty = default; - /// /// The backing vector for SIMD support. /// @@ -115,12 +110,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Z; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector { @@ -173,7 +162,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.IsEmpty + return this.Equals(default) ? "CieLch [Empty]" : $"CieLch [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}]"; } diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs index 503ce65aa..13cedc96d 100644 --- a/src/ImageSharp/ColorSpaces/CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs @@ -20,11 +20,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public static readonly CieXyz DefaultWhitePoint = Illuminants.D65; - /// - /// Represents a that has L, C, H values set to zero. - /// - public static readonly CieLchuv Empty = default; - /// /// The backing vector for SIMD support. /// @@ -115,12 +110,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Z; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector { @@ -171,7 +160,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.IsEmpty + return this.Equals(default) ? "CieLchuv [Empty]" : $"CieLchuv [ L={this.L:#0.##}, C={this.C:#0.##}, H={this.H:#0.##}"; } diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs index 8b385418c..805052923 100644 --- a/src/ImageSharp/ColorSpaces/CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLuv.cs @@ -22,11 +22,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public static readonly CieXyz DefaultWhitePoint = Illuminants.D65; - /// - /// Represents a that has L, U, and V values set to zero. - /// - public static readonly CieLuv Empty = default; - /// /// The backing vector for SIMD support. /// @@ -117,12 +112,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Z; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector { @@ -173,7 +162,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.IsEmpty + return this.Equals(default) ? "CieLuv [ Empty ]" : $"CieLuv [ L={this.L:#0.##}, U={this.U:#0.##}, V={this.V:#0.##} ]"; } diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs index 10a251420..013bed890 100644 --- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs @@ -14,11 +14,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// internal readonly struct CieXyChromaticityCoordinates : IEquatable, IAlmostEquatable { - /// - /// Represents a that has X, Y values set to zero. - /// - public static readonly CieXyChromaticityCoordinates Empty = default; - /// /// The backing vector for SIMD support. /// @@ -69,12 +64,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Y; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// /// Compares two objects for equality. /// @@ -119,12 +108,9 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - if (this.IsEmpty) - { - return "CieXyChromaticityCoordinates [Empty]"; - } - - return $"CieXyChromaticityCoordinates [ X={this.X:#0.##}, Y={this.Y:#0.##}]"; + return this.Equals(default) + ? "CieXyChromaticityCoordinates [Empty]" + : $"CieXyChromaticityCoordinates [ X={this.X:#0.##}, Y={this.Y:#0.##}]"; } /// diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs index 690b3fcfc..d5ad2aa1f 100644 --- a/src/ImageSharp/ColorSpaces/CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/CieXyy.cs @@ -14,11 +14,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// internal readonly struct CieXyy : IColorVector, IEquatable, IAlmostEquatable { - /// - /// Represents a that has X, Y, and Y values set to zero. - /// - public static readonly CieXyy Empty = default; - /// /// The backing vector for SIMD support. /// @@ -78,12 +73,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Z; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector => this.backingVector; @@ -130,12 +119,9 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - if (this.IsEmpty) - { - return "CieXyy [ Empty ]"; - } - - return $"CieXyy [ X={this.X:#0.##}, Y={this.Y:#0.##}, Yl={this.Yl:#0.##} ]"; + return this.Equals(default) + ? "CieXyy [ Empty ]" + : $"CieXyy [ X={this.X:#0.##}, Y={this.Y:#0.##}, Yl={this.Yl:#0.##} ]"; } /// diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs index fec4c74e2..b1d2392d6 100644 --- a/src/ImageSharp/ColorSpaces/CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/CieXyz.cs @@ -14,11 +14,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// internal readonly struct CieXyz : IColorVector, IEquatable, IAlmostEquatable { - /// - /// Represents a that has X, Y, and Z values set to zero. - /// - public static readonly CieXyz Empty = default; - /// /// The backing vector for SIMD support. /// @@ -77,12 +72,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Z; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector { @@ -133,12 +122,9 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - if (this.IsEmpty) - { - return "CieXyz [ Empty ]"; - } - - return $"CieXyz [ X={this.X:#0.##}, Y={this.Y:#0.##}, Z={this.Z:#0.##} ]"; + return this.Equals(default) + ? "CieXyz [ Empty ]" + : $"CieXyz [ X={this.X:#0.##}, Y={this.Y:#0.##}, Z={this.Z:#0.##} ]"; } /// diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs index ffbe2e265..2571615b5 100644 --- a/src/ImageSharp/ColorSpaces/Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Cmyk.cs @@ -13,11 +13,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// internal readonly struct Cmyk : IEquatable, IAlmostEquatable { - /// - /// Represents a that has C, M, Y, and K values set to zero. - /// - public static readonly Cmyk Empty = default; - /// /// The backing vector for SIMD support. /// @@ -87,12 +82,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.W; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// /// Compares two objects for equality. /// @@ -138,12 +127,9 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - if (this.IsEmpty) - { - return "Cmyk [Empty]"; - } - - return $"Cmyk [ C={this.C:#0.##}, M={this.M:#0.##}, Y={this.Y:#0.##}, K={this.K:#0.##}]"; + return this.Equals(default) + ? "Cmyk [Empty]" + : $"Cmyk [ C={this.C:#0.##}, M={this.M:#0.##}, Y={this.Y:#0.##}, K={this.K:#0.##}]"; } /// diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs index 31b93d384..c49440a8d 100644 --- a/src/ImageSharp/ColorSpaces/Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Hsl.cs @@ -13,11 +13,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// internal readonly struct Hsl : IColorVector, IEquatable, IAlmostEquatable { - /// - /// Represents a that has H, S, and L values set to zero. - /// - public static readonly Hsl Empty = default; - /// /// Max range used for clamping /// @@ -80,12 +75,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Z; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector => this.backingVector; @@ -132,12 +121,9 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - if (this.IsEmpty) - { - return "Hsl [ Empty ]"; - } - - return $"Hsl [ H={this.H:#0.##}, S={this.S:#0.##}, L={this.L:#0.##} ]"; + return this.Equals(default) + ? "Hsl [ Empty ]" + : $"Hsl [ H={this.H:#0.##}, S={this.S:#0.##}, L={this.L:#0.##} ]"; } /// diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs index 1f6c8d5eb..4e73923cc 100644 --- a/src/ImageSharp/ColorSpaces/Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Hsv.cs @@ -15,11 +15,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// internal readonly struct Hsv : IColorVector, IEquatable, IAlmostEquatable { - /// - /// Represents a that has H, S, and V values set to zero. - /// - public static readonly Hsv Empty = default; - /// /// Max range used for clamping /// @@ -82,12 +77,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Z; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector { @@ -157,7 +146,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Hsv left, Hsv right) { return left.Equals(right); @@ -175,7 +163,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Hsv left, Hsv right) { return !left.Equals(right); @@ -190,16 +177,12 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - if (this.IsEmpty) - { - return "Hsv [ Empty ]"; - } - - return $"Hsv [ H={this.H:#0.##}, S={this.S:#0.##}, V={this.V:#0.##} ]"; + return this.Equals(default) + ? "Hsv [ Empty ]" + : $"Hsv [ H={this.H:#0.##}, S={this.S:#0.##}, V={this.V:#0.##} ]"; } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is Hsv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs index 671801949..576a48e8b 100644 --- a/src/ImageSharp/ColorSpaces/HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/HunterLab.cs @@ -20,11 +20,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public static readonly CieXyz DefaultWhitePoint = Illuminants.C; - /// - /// Represents a that has L, A, B values set to zero. - /// - public static readonly HunterLab Empty = default; - /// /// The backing vector for SIMD support. /// @@ -115,12 +110,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Z; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector => this.backingVector; @@ -167,7 +156,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - return this.IsEmpty + return this.Equals(default) ? "HunterLab [Empty]" : $"HunterLab [ L={this.L:#0.##}, A={this.A:#0.##}, B={this.B:#0.##}]"; } diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs index f66527266..6685c506e 100644 --- a/src/ImageSharp/ColorSpaces/LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs @@ -13,11 +13,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// internal readonly struct LinearRgb : IColorVector, IEquatable, IAlmostEquatable { - /// - /// Represents a that has R, G, and B values set to zero. - /// - public static readonly LinearRgb Empty = default; - /// /// The default LinearRgb working space /// @@ -112,12 +107,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public IRgbWorkingSpace WorkingSpace { get; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector => this.backingVector; @@ -164,12 +153,9 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - if (this.IsEmpty) - { - return "LinearRgb [ Empty ]"; - } - - return $"LinearRgb [ R={this.R:#0.##}, G={this.G:#0.##}, B={this.B:#0.##} ]"; + return this.Equals(default) + ? "LinearRgb [ Empty ]" + : $"LinearRgb [ R={this.R:#0.##}, G={this.G:#0.##}, B={this.B:#0.##} ]"; } /// diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs index 81a068d50..09b092f81 100644 --- a/src/ImageSharp/ColorSpaces/Lms.cs +++ b/src/ImageSharp/ColorSpaces/Lms.cs @@ -15,11 +15,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// internal readonly struct Lms : IColorVector, IEquatable, IAlmostEquatable { - /// - /// Represents a that has L, M, and S values set to zero. - /// - public static readonly Lms Empty = default; - /// /// The backing vector for SIMD support. /// @@ -79,12 +74,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Z; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector => this.backingVector; @@ -131,12 +120,9 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - if (this.IsEmpty) - { - return "Lms [ Empty ]"; - } - - return $"Lms [ L={this.L:#0.##}, M={this.M:#0.##}, S={this.S:#0.##} ]"; + return this.Equals(default) + ? "Lms [ Empty ]" + : $"Lms [ L={this.L:#0.##}, M={this.M:#0.##}, S={this.S:#0.##} ]"; } /// diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index 351d2b187..0041605f9 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -15,11 +15,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// internal readonly struct Rgb : IColorVector, IEquatable, IAlmostEquatable { - /// - /// Represents a that has R, G, and B values set to zero. - /// - public static readonly Rgb Empty = default; - /// /// The default rgb working space /// @@ -112,17 +107,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// Gets the Rgb color space /// - public IRgbWorkingSpace WorkingSpace - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get; - } - - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); + public IRgbWorkingSpace WorkingSpace { get; } /// public Vector3 Vector => this.backingVector; @@ -186,12 +171,9 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - if (this.IsEmpty) - { - return "Rgb [ Empty ]"; - } - - return $"Rgb [ R={this.R:#0.##}, G={this.G:#0.##}, B={this.B:#0.##} ]"; + return this.Equals(default) + ? "Rgb [ Empty ]" + : $"Rgb [ R={this.R:#0.##}, G={this.G:#0.##}, B={this.B:#0.##} ]"; } /// diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs index cb1060137..4bc70626c 100644 --- a/src/ImageSharp/ColorSpaces/YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/YCbCr.cs @@ -15,11 +15,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// internal readonly struct YCbCr : IColorVector, IEquatable, IAlmostEquatable { - /// - /// Represents a that has Y, Cb, and Cr values set to zero. - /// - public static readonly YCbCr Empty = default; - /// /// Vector which is used in clamping to the max value /// @@ -82,12 +77,6 @@ namespace SixLabors.ImageSharp.ColorSpaces get => this.backingVector.Z; } - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - /// public Vector3 Vector => this.backingVector; @@ -103,7 +92,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(YCbCr left, YCbCr right) { return left.Equals(right); @@ -121,7 +109,6 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(YCbCr left, YCbCr right) { return !left.Equals(right); @@ -136,23 +123,18 @@ namespace SixLabors.ImageSharp.ColorSpaces /// public override string ToString() { - if (this.IsEmpty) - { - return "YCbCr [ Empty ]"; - } - - return $"YCbCr [ Y={this.Y}, Cb={this.Cb}, Cr={this.Cr} ]"; + return this.Equals(default) + ? "YCbCr [ Empty ]" + : $"YCbCr [ Y={this.Y}, Cb={this.Cb}, Cr={this.Cr} ]"; } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { return obj is YCbCr other && this.Equals(other); } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(YCbCr other) { return this.backingVector.Equals(other.backingVector); From 6d0db4764d0547101b48f169dc5a6999d8759dc1 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 09:52:30 -0700 Subject: [PATCH 21/68] Match AggressiveInlining usage to main pixel classes --- src/ImageSharp/ColorSpaces/CieLab.cs | 2 ++ src/ImageSharp/ColorSpaces/CieLchuv.cs | 2 ++ src/ImageSharp/ColorSpaces/CieLuv.cs | 2 ++ src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs | 3 +++ src/ImageSharp/ColorSpaces/CieXyy.cs | 3 +++ src/ImageSharp/ColorSpaces/CieXyz.cs | 3 +++ src/ImageSharp/ColorSpaces/Cmyk.cs | 1 + src/ImageSharp/ColorSpaces/Hsl.cs | 3 +++ src/ImageSharp/ColorSpaces/Hsv.cs | 3 +++ src/ImageSharp/ColorSpaces/HunterLab.cs | 2 ++ src/ImageSharp/ColorSpaces/LinearRgb.cs | 3 +++ src/ImageSharp/ColorSpaces/Lms.cs | 2 ++ src/ImageSharp/ColorSpaces/Rgb.cs | 2 ++ src/ImageSharp/ColorSpaces/YCbCr.cs | 3 +++ 14 files changed, 34 insertions(+) diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index c9581379b..18693d553 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -129,6 +129,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(CieLab left, CieLab right) { return left.Equals(right); @@ -146,6 +147,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieLab left, CieLab right) { return !left.Equals(right); diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs index 13cedc96d..16c5f0bcc 100644 --- a/src/ImageSharp/ColorSpaces/CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs @@ -152,6 +152,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return HashHelpers.Combine(this.WhitePoint.GetHashCode(), this.backingVector.GetHashCode()); @@ -172,6 +173,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(CieLchuv other) { return this.backingVector.Equals(other.backingVector) diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs index 805052923..fc216b97e 100644 --- a/src/ImageSharp/ColorSpaces/CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLuv.cs @@ -131,6 +131,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(CieLuv left, CieLuv right) { return left.Equals(right); @@ -148,6 +149,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieLuv left, CieLuv right) { return !left.Equals(right); diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs index 013bed890..4f4f95147 100644 --- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs @@ -94,12 +94,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieXyChromaticityCoordinates left, CieXyChromaticityCoordinates right) { return !left.Equals(right); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.backingVector.GetHashCode(); @@ -120,6 +122,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(CieXyChromaticityCoordinates other) { // The memberwise comparison here is a workaround for https://github.com/dotnet/coreclr/issues/16443 diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs index d5ad2aa1f..ac1a4532c 100644 --- a/src/ImageSharp/ColorSpaces/CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/CieXyy.cs @@ -88,6 +88,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(CieXyy left, CieXyy right) { return left.Equals(right); @@ -105,12 +106,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieXyy left, CieXyy right) { return !left.Equals(right); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.backingVector.GetHashCode(); diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs index b1d2392d6..ddca51b95 100644 --- a/src/ImageSharp/ColorSpaces/CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/CieXyz.cs @@ -91,6 +91,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(CieXyz left, CieXyz right) { return left.Equals(right); @@ -108,12 +109,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieXyz left, CieXyz right) { return !left.Equals(right); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.backingVector.GetHashCode(); diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs index 2571615b5..2702d4ba3 100644 --- a/src/ImageSharp/ColorSpaces/Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Cmyk.cs @@ -119,6 +119,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.backingVector.GetHashCode(); diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs index c49440a8d..4e9744f05 100644 --- a/src/ImageSharp/ColorSpaces/Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Hsl.cs @@ -90,6 +90,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Hsl left, Hsl right) { return left.Equals(right); @@ -107,12 +108,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Hsl left, Hsl right) { return !left.Equals(right); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.backingVector.GetHashCode(); diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs index 4e73923cc..954f9f185 100644 --- a/src/ImageSharp/ColorSpaces/Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Hsv.cs @@ -146,6 +146,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Hsv left, Hsv right) { return left.Equals(right); @@ -163,12 +164,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Hsv left, Hsv right) { return !left.Equals(right); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.backingVector.GetHashCode(); diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs index 576a48e8b..44f31bc29 100644 --- a/src/ImageSharp/ColorSpaces/HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/HunterLab.cs @@ -142,12 +142,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(HunterLab left, HunterLab right) { return !left.Equals(right); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return HashHelpers.Combine(this.WhitePoint.GetHashCode(), this.backingVector.GetHashCode()); diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs index 6685c506e..93cf1085c 100644 --- a/src/ImageSharp/ColorSpaces/LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs @@ -122,6 +122,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(LinearRgb left, LinearRgb right) { return left.Equals(right); @@ -139,12 +140,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(LinearRgb left, LinearRgb right) { return !left.Equals(right); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.backingVector.GetHashCode(); diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs index 09b092f81..9b0331e0b 100644 --- a/src/ImageSharp/ColorSpaces/Lms.cs +++ b/src/ImageSharp/ColorSpaces/Lms.cs @@ -89,6 +89,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Lms left, Lms right) { return left.Equals(right); @@ -106,6 +107,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Lms left, Lms right) { return !left.Equals(right); diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index 0041605f9..777e1f4c1 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -140,6 +140,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Rgb left, Rgb right) { return left.Equals(right); @@ -157,6 +158,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Rgb left, Rgb right) { return !left.Equals(right); diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs index 4bc70626c..31079b6b8 100644 --- a/src/ImageSharp/ColorSpaces/YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/YCbCr.cs @@ -109,12 +109,14 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(YCbCr left, YCbCr right) { return !left.Equals(right); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.backingVector.GetHashCode(); @@ -135,6 +137,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(YCbCr other) { return this.backingVector.Equals(other.backingVector); From ba1bbfd7f45887abae15e17138ababcea5c2837a Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 10:00:55 -0700 Subject: [PATCH 22/68] Pass by reference --- .../Conversion/ColorSpaceConverter.Adapt.cs | 16 ++++++------ .../Conversion/ColorSpaceConverter.CieLab.cs | 26 +++++++++---------- .../Conversion/ColorSpaceConverter.CieLch.cs | 26 +++++++++---------- .../ColorSpaceConverter.CieLchuv.cs | 24 ++++++++--------- .../Conversion/ColorSpaceConverter.CieLuv.cs | 26 +++++++++---------- .../Conversion/ColorSpaceConverter.CieXyy.cs | 24 ++++++++--------- .../Conversion/ColorSpaceConverter.CieXyz.cs | 26 +++++++++---------- .../Conversion/ColorSpaceConverter.Cmyk.cs | 26 +++++++++---------- .../Conversion/ColorSpaceConverter.Hsl.cs | 24 ++++++++--------- .../Conversion/ColorSpaceConverter.Hsv.cs | 24 ++++++++--------- .../ColorSpaceConverter.HunterLab.cs | 26 +++++++++---------- .../ColorSpaceConverter.LinearRgb.cs | 26 +++++++++---------- .../Conversion/ColorSpaceConverter.Lms.cs | 26 +++++++++---------- .../Conversion/ColorSpaceConverter.Rgb.cs | 26 +++++++++---------- .../Conversion/ColorSpaceConverter.YCbCr.cs | 26 +++++++++---------- 15 files changed, 186 insertions(+), 186 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs index 4bb537aeb..e2c1308fa 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs @@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// The color to adapt /// The white point to adapt for /// The adapted color - public CieXyz Adapt(CieXyz color, CieXyz sourceWhitePoint) + public CieXyz Adapt(in CieXyz color, in CieXyz sourceWhitePoint) { if (!this.IsChromaticAdaptationPerformed) { @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to adapt /// The adapted color - public CieLab Adapt(CieLab color) + public CieLab Adapt(in CieLab color) { if (!this.IsChromaticAdaptationPerformed) { @@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to adapt /// The adapted color - public CieLch Adapt(CieLch color) + public CieLch Adapt(in CieLch color) { if (!this.IsChromaticAdaptationPerformed) { @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to adapt /// The adapted color - public CieLchuv Adapt(CieLchuv color) + public CieLchuv Adapt(in CieLchuv color) { if (!this.IsChromaticAdaptationPerformed) { @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to adapt /// The adapted color - public CieLuv Adapt(CieLuv color) + public CieLuv Adapt(in CieLuv color) { if (!this.IsChromaticAdaptationPerformed) { @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to adapt /// The adapted color - public HunterLab Adapt(HunterLab color) + public HunterLab Adapt(in HunterLab color) { if (!this.IsChromaticAdaptationPerformed) { @@ -138,7 +138,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to adapt /// The adapted color - public LinearRgb Adapt(LinearRgb color) + public LinearRgb Adapt(in LinearRgb color) { if (!this.IsChromaticAdaptationPerformed) { @@ -167,7 +167,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to adapt /// The adapted color - public Rgb Adapt(Rgb color) + public Rgb Adapt(in Rgb color) { LinearRgb linearInput = this.ToLinearRgb(color); LinearRgb linearOutput = this.Adapt(linearInput); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs index 16e3ec707..1cead3001 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(CieLch color) + public CieLab ToCieLab(in CieLch color) { // Conversion (perserving white point) CieLab unadapted = CieLchToCieLabConverter.Convert(color); @@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(CieLchuv color) + public CieLab ToCieLab(in CieLchuv color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLab(xyzColor); @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(CieLuv color) + public CieLab ToCieLab(in CieLuv color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLab(xyzColor); @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(CieXyy color) + public CieLab ToCieLab(in CieXyy color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLab(xyzColor); @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(CieXyz color) + public CieLab ToCieLab(in CieXyz color) { // Adaptation CieXyz adapted = !this.WhitePoint.Equals(this.TargetLabWhitePoint) && this.IsChromaticAdaptationPerformed @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(Cmyk color) + public CieLab ToCieLab(in Cmyk color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLab(xyzColor); @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(Hsl color) + public CieLab ToCieLab(in Hsl color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLab(xyzColor); @@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(Hsv color) + public CieLab ToCieLab(in Hsv color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLab(xyzColor); @@ -123,7 +123,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(HunterLab color) + public CieLab ToCieLab(in HunterLab color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLab(xyzColor); @@ -134,7 +134,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(Lms color) + public CieLab ToCieLab(in Lms color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLab(xyzColor); @@ -145,7 +145,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(LinearRgb color) + public CieLab ToCieLab(in LinearRgb color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLab(xyzColor); @@ -156,7 +156,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(Rgb color) + public CieLab ToCieLab(in Rgb color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLab(xyzColor); @@ -167,7 +167,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLab ToCieLab(YCbCr color) + public CieLab ToCieLab(in YCbCr color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLab(xyzColor); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs index b13580209..cbefc5ac5 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(CieLab color) + public CieLch ToCieLch(in CieLab color) { // Adaptation CieLab adapted = this.IsChromaticAdaptationPerformed ? this.Adapt(color) : color; @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(CieLchuv color) + public CieLch ToCieLch(in CieLchuv color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLch(xyzColor); @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(CieLuv color) + public CieLch ToCieLch(in CieLuv color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLch(xyzColor); @@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(CieXyy color) + public CieLch ToCieLch(in CieXyy color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLch(xyzColor); @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(CieXyz color) + public CieLch ToCieLch(in CieXyz color) { CieLab labColor = this.ToCieLab(color); return this.ToCieLch(labColor); @@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(Cmyk color) + public CieLch ToCieLch(in Cmyk color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLch(xyzColor); @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(Hsl color) + public CieLch ToCieLch(in Hsl color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLch(xyzColor); @@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(Hsv color) + public CieLch ToCieLch(in Hsv color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLch(xyzColor); @@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(HunterLab color) + public CieLch ToCieLch(in HunterLab color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLch(xyzColor); @@ -122,7 +122,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(LinearRgb color) + public CieLch ToCieLch(in LinearRgb color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLch(xyzColor); @@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(Lms color) + public CieLch ToCieLch(in Lms color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLch(xyzColor); @@ -144,7 +144,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(Rgb color) + public CieLch ToCieLch(in Rgb color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLch(xyzColor); @@ -155,7 +155,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLch ToCieLch(YCbCr color) + public CieLch ToCieLch(in YCbCr color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLch(xyzColor); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs index a5b5220b9..a44541bdb 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(CieLab color) + public CieLchuv ToCieLchuv(in CieLab color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLchuv(xyzColor); @@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(CieLch color) + public CieLchuv ToCieLchuv(in CieLch color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLchuv(xyzColor); @@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(CieLuv color) + public CieLchuv ToCieLchuv(in CieLuv color) { // Adaptation CieLuv adapted = this.IsChromaticAdaptationPerformed ? this.Adapt(color) : color; @@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(CieXyy color) + public CieLchuv ToCieLchuv(in CieXyy color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLchuv(xyzColor); @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(CieXyz color) + public CieLchuv ToCieLchuv(in CieXyz color) { CieLab labColor = this.ToCieLab(color); return this.ToCieLchuv(labColor); @@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(Cmyk color) + public CieLchuv ToCieLchuv(in Cmyk color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLchuv(xyzColor); @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(Hsl color) + public CieLchuv ToCieLchuv(in Hsl color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLchuv(xyzColor); @@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(Hsv color) + public CieLchuv ToCieLchuv(in Hsv color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLchuv(xyzColor); @@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(HunterLab color) + public CieLchuv ToCieLchuv(in HunterLab color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLchuv(xyzColor); @@ -122,7 +122,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(LinearRgb color) + public CieLchuv ToCieLchuv(in LinearRgb color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLchuv(xyzColor); @@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(Lms color) + public CieLchuv ToCieLchuv(in Lms color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLchuv(xyzColor); @@ -155,7 +155,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLchuv ToCieLchuv(YCbCr color) + public CieLchuv ToCieLchuv(in YCbCr color) { CieXyz xyzColor = this.ToCieXyz(color); return this.ToCieLchuv(xyzColor); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs index 7260a818f..36e6501a5 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(CieLab color) + public CieLuv ToCieLuv(in CieLab color) { var xyzColor = this.ToCieXyz(color); return this.ToCieLuv(xyzColor); @@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(CieLch color) + public CieLuv ToCieLuv(in CieLch color) { var xyzColor = this.ToCieXyz(color); return this.ToCieLuv(xyzColor); @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(CieLchuv color) + public CieLuv ToCieLuv(in CieLchuv color) { // Conversion (perserving white point) CieLuv unadapted = CieLchuvToCieLuvConverter.Convert(color); @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(CieXyy color) + public CieLuv ToCieLuv(in CieXyy color) { var xyzColor = this.ToCieXyz(color); return this.ToCieLuv(xyzColor); @@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(CieXyz color) + public CieLuv ToCieLuv(in CieXyz color) { // Adaptation CieXyz adapted = !this.WhitePoint.Equals(this.TargetLabWhitePoint) && this.IsChromaticAdaptationPerformed @@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(Cmyk color) + public CieLuv ToCieLuv(in Cmyk color) { var xyzColor = this.ToCieXyz(color); return this.ToCieLuv(xyzColor); @@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(Hsl color) + public CieLuv ToCieLuv(in Hsl color) { var xyzColor = this.ToCieXyz(color); return this.ToCieLuv(xyzColor); @@ -110,7 +110,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(Hsv color) + public CieLuv ToCieLuv(in Hsv color) { var xyzColor = this.ToCieXyz(color); return this.ToCieLuv(xyzColor); @@ -121,7 +121,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(HunterLab color) + public CieLuv ToCieLuv(in HunterLab color) { var xyzColor = this.ToCieXyz(color); return this.ToCieLuv(xyzColor); @@ -132,7 +132,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(Lms color) + public CieLuv ToCieLuv(in Lms color) { var xyzColor = this.ToCieXyz(color); return this.ToCieLuv(xyzColor); @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(LinearRgb color) + public CieLuv ToCieLuv(in LinearRgb color) { var xyzColor = this.ToCieXyz(color); return this.ToCieLuv(xyzColor); @@ -154,7 +154,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(Rgb color) + public CieLuv ToCieLuv(in Rgb color) { var xyzColor = this.ToCieXyz(color); return this.ToCieLuv(xyzColor); @@ -165,7 +165,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieLuv ToCieLuv(YCbCr color) + public CieLuv ToCieLuv(in YCbCr color) { var xyzColor = this.ToCieXyz(color); return this.ToCieLuv(xyzColor); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs index 5f6aaea6b..25a9f75a4 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(CieLab color) + public CieXyy ToCieXyy(in CieLab color) { var xyzColor = this.ToCieXyz(color); @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(CieLch color) + public CieXyy ToCieXyy(in CieLch color) { var xyzColor = this.ToCieXyz(color); @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(CieLchuv color) + public CieXyy ToCieXyy(in CieLchuv color) { var xyzColor = this.ToCieXyz(color); @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(CieLuv color) + public CieXyy ToCieXyy(in CieLuv color) { var xyzColor = this.ToCieXyz(color); @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(CieXyz color) + public CieXyy ToCieXyy(in CieXyz color) { return CieXyzAndCieXyyConverter.Convert(color); } @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(Cmyk color) + public CieXyy ToCieXyy(in Cmyk color) { var xyzColor = this.ToCieXyz(color); @@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(Hsv color) + public CieXyy ToCieXyy(in Hsv color) { var xyzColor = this.ToCieXyz(color); @@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(HunterLab color) + public CieXyy ToCieXyy(in HunterLab color) { var xyzColor = this.ToCieXyz(color); @@ -123,7 +123,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(LinearRgb color) + public CieXyy ToCieXyy(in LinearRgb color) { var xyzColor = this.ToCieXyz(color); @@ -135,7 +135,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(Lms color) + public CieXyy ToCieXyy(in Lms color) { var xyzColor = this.ToCieXyz(color); @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(Rgb color) + public CieXyy ToCieXyy(in Rgb color) { var xyzColor = this.ToCieXyz(color); @@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyy ToCieXyy(YCbCr color) + public CieXyy ToCieXyy(in YCbCr color) { var xyzColor = this.ToCieXyz(color); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs index cd3f7f3c8..ff3822c86 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(CieLab color) + public CieXyz ToCieXyz(in CieLab color) { // Conversion CieXyz unadapted = CieLabToCieXyzConverter.Convert(color); @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(CieLch color) + public CieXyz ToCieXyz(in CieLch color) { // Conversion to Lab CieLab labColor = CieLchToCieLabConverter.Convert(color); @@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(CieLchuv color) + public CieXyz ToCieXyz(in CieLchuv color) { // Conversion to Luv CieLuv luvColor = CieLchuvToCieLuvConverter.Convert(color); @@ -72,7 +72,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(CieLuv color) + public CieXyz ToCieXyz(in CieLuv color) { // Conversion CieXyz unadapted = CieLuvToCieXyzConverter.Convert(color); @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(CieXyy color) + public CieXyz ToCieXyz(in CieXyy color) { // Conversion return CieXyzAndCieXyyConverter.Convert(color); @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(Cmyk color) + public CieXyz ToCieXyz(in Cmyk color) { // Conversion var rgb = this.ToRgb(color); @@ -114,7 +114,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(Hsl color) + public CieXyz ToCieXyz(in Hsl color) { // Conversion var rgb = this.ToRgb(color); @@ -127,7 +127,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(Hsv color) + public CieXyz ToCieXyz(in Hsv color) { // Conversion var rgb = this.ToRgb(color); @@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(HunterLab color) + public CieXyz ToCieXyz(in HunterLab color) { // Conversion CieXyz unadapted = HunterLabToCieXyzConverter.Convert(color); @@ -158,7 +158,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(LinearRgb color) + public CieXyz ToCieXyz(in LinearRgb color) { // Conversion LinearRgbToCieXyzConverter converter = this.GetLinearRgbToCieXyzConverter(color.WorkingSpace); @@ -175,7 +175,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(Lms color) + public CieXyz ToCieXyz(in Lms color) { // Conversion return this.cachedCieXyzAndLmsConverter.Convert(color); @@ -186,7 +186,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(Rgb color) + public CieXyz ToCieXyz(in Rgb color) { // Conversion LinearRgb linear = RgbToLinearRgbConverter.Convert(color); @@ -198,7 +198,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public CieXyz ToCieXyz(YCbCr color) + public CieXyz ToCieXyz(in YCbCr color) { // Conversion var rgb = this.ToRgb(color); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs index 708c2eac0..1e403828a 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(CieLab color) + public Cmyk ToCmyk(in CieLab color) { var xyzColor = this.ToCieXyz(color); @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(CieLch color) + public Cmyk ToCmyk(in CieLch color) { var xyzColor = this.ToCieXyz(color); @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(CieLchuv color) + public Cmyk ToCmyk(in CieLchuv color) { var xyzColor = this.ToCieXyz(color); @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(CieLuv color) + public Cmyk ToCmyk(in CieLuv color) { var xyzColor = this.ToCieXyz(color); @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(CieXyy color) + public Cmyk ToCmyk(in CieXyy color) { var xyzColor = this.ToCieXyz(color); @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(CieXyz color) + public Cmyk ToCmyk(in CieXyz color) { var rgb = this.ToRgb(color); @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(Hsl color) + public Cmyk ToCmyk(in Hsl color) { var rgb = this.ToRgb(color); @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(Hsv color) + public Cmyk ToCmyk(in Hsv color) { var rgb = this.ToRgb(color); @@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(HunterLab color) + public Cmyk ToCmyk(in HunterLab color) { var xyzColor = this.ToCieXyz(color); @@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(LinearRgb color) + public Cmyk ToCmyk(in LinearRgb color) { var rgb = this.ToRgb(color); @@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(Lms color) + public Cmyk ToCmyk(in Lms color) { var xyzColor = this.ToCieXyz(color); @@ -149,7 +149,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(Rgb color) + public Cmyk ToCmyk(in Rgb color) { return CmykAndRgbConverter.Convert(color); } @@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Cmyk ToCmyk(YCbCr color) + public Cmyk ToCmyk(in YCbCr color) { var rgb = this.ToRgb(color); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs index 909658a06..78f8c36fb 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(CieLab color) + public Hsl ToHsl(in CieLab color) { var xyzColor = this.ToCieXyz(color); @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(CieLch color) + public Hsl ToHsl(in CieLch color) { var xyzColor = this.ToCieXyz(color); @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(CieLchuv color) + public Hsl ToHsl(in CieLchuv color) { var xyzColor = this.ToCieXyz(color); @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(CieLuv color) + public Hsl ToHsl(in CieLuv color) { var xyzColor = this.ToCieXyz(color); @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(CieXyy color) + public Hsl ToHsl(in CieXyy color) { var xyzColor = this.ToCieXyz(color); @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(CieXyz color) + public Hsl ToHsl(in CieXyz color) { var rgb = this.ToRgb(color); @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(Cmyk color) + public Hsl ToHsl(in Cmyk color) { var rgb = this.ToRgb(color); @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(Hsv color) + public Hsl ToHsl(in Hsv color) { var rgb = this.ToRgb(color); @@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(HunterLab color) + public Hsl ToHsl(in HunterLab color) { var xyzColor = this.ToCieXyz(color); @@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(LinearRgb color) + public Hsl ToHsl(in LinearRgb color) { var rgb = this.ToRgb(color); @@ -149,7 +149,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(Rgb color) + public Hsl ToHsl(in Rgb color) { return HslAndRgbConverter.Convert(color); } @@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsl ToHsl(YCbCr color) + public Hsl ToHsl(in YCbCr color) { var rgb = this.ToRgb(color); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs index 0aa644567..3edd72c59 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(CieLab color) + public Hsv ToHsv(in CieLab color) { var xyzColor = this.ToCieXyz(color); @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(CieLch color) + public Hsv ToHsv(in CieLch color) { var xyzColor = this.ToCieXyz(color); @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(CieLchuv color) + public Hsv ToHsv(in CieLchuv color) { var xyzColor = this.ToCieXyz(color); @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(CieLuv color) + public Hsv ToHsv(in CieLuv color) { var xyzColor = this.ToCieXyz(color); @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(CieXyy color) + public Hsv ToHsv(in CieXyy color) { var xyzColor = this.ToCieXyz(color); @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(CieXyz color) + public Hsv ToHsv(in CieXyz color) { var rgb = this.ToRgb(color); @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(Cmyk color) + public Hsv ToHsv(in Cmyk color) { var rgb = this.ToRgb(color); @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(Hsl color) + public Hsv ToHsv(in Hsl color) { var rgb = this.ToRgb(color); @@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(HunterLab color) + public Hsv ToHsv(in HunterLab color) { var xyzColor = this.ToCieXyz(color); @@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(LinearRgb color) + public Hsv ToHsv(in LinearRgb color) { var rgb = this.ToRgb(color); @@ -149,7 +149,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(Rgb color) + public Hsv ToHsv(in Rgb color) { return HsvAndRgbConverter.Convert(color); } @@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Hsv ToHsv(YCbCr color) + public Hsv ToHsv(in YCbCr color) { var rgb = this.ToRgb(color); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs index 880a91551..f3a64164b 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(CieLab color) + public HunterLab ToHunterLab(in CieLab color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(CieLch color) + public HunterLab ToHunterLab(in CieLch color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(CieLchuv color) + public HunterLab ToHunterLab(in CieLchuv color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(CieLuv color) + public HunterLab ToHunterLab(in CieLuv color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(CieXyy color) + public HunterLab ToHunterLab(in CieXyy color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(CieXyz color) + public HunterLab ToHunterLab(in CieXyz color) { // Adaptation CieXyz adapted = !this.WhitePoint.Equals(this.TargetHunterLabWhitePoint) && this.IsChromaticAdaptationPerformed @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(Cmyk color) + public HunterLab ToHunterLab(in Cmyk color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); @@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(Hsl color) + public HunterLab ToHunterLab(in Hsl color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); @@ -108,7 +108,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(Hsv color) + public HunterLab ToHunterLab(in Hsv color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); @@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(LinearRgb color) + public HunterLab ToHunterLab(in LinearRgb color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); @@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(Lms color) + public HunterLab ToHunterLab(in Lms color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(Rgb color) + public HunterLab ToHunterLab(in Rgb color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); @@ -152,7 +152,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public HunterLab ToHunterLab(YCbCr color) + public HunterLab ToHunterLab(in YCbCr color) { var xyzColor = this.ToCieXyz(color); return this.ToHunterLab(xyzColor); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs index 92d2cd861..6cfdb4853 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(CieLab color) + public LinearRgb ToLinearRgb(in CieLab color) { var xyzColor = this.ToCieXyz(color); return this.ToLinearRgb(xyzColor); @@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(CieLch color) + public LinearRgb ToLinearRgb(in CieLch color) { var xyzColor = this.ToCieXyz(color); return this.ToLinearRgb(xyzColor); @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(CieLchuv color) + public LinearRgb ToLinearRgb(in CieLchuv color) { var xyzColor = this.ToCieXyz(color); return this.ToLinearRgb(xyzColor); @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(CieLuv color) + public LinearRgb ToLinearRgb(in CieLuv color) { var xyzColor = this.ToCieXyz(color); return this.ToLinearRgb(xyzColor); @@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(CieXyy color) + public LinearRgb ToLinearRgb(in CieXyy color) { var xyzColor = this.ToCieXyz(color); return this.ToLinearRgb(xyzColor); @@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(CieXyz color) + public LinearRgb ToLinearRgb(in CieXyz color) { // Adaptation CieXyz adapted = this.TargetRgbWorkingSpace.WhitePoint.Equals(this.WhitePoint) || !this.IsChromaticAdaptationPerformed @@ -91,7 +91,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(Cmyk color) + public LinearRgb ToLinearRgb(in Cmyk color) { var rgb = this.ToRgb(color); return this.ToLinearRgb(rgb); @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(Hsl color) + public LinearRgb ToLinearRgb(in Hsl color) { var rgb = this.ToRgb(color); return this.ToLinearRgb(rgb); @@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(Hsv color) + public LinearRgb ToLinearRgb(in Hsv color) { var rgb = this.ToRgb(color); return this.ToLinearRgb(rgb); @@ -124,7 +124,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(HunterLab color) + public LinearRgb ToLinearRgb(in HunterLab color) { var xyzColor = this.ToCieXyz(color); return this.ToLinearRgb(xyzColor); @@ -135,7 +135,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(Lms color) + public LinearRgb ToLinearRgb(in Lms color) { var xyzColor = this.ToCieXyz(color); return this.ToLinearRgb(xyzColor); @@ -146,7 +146,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(Rgb color) + public LinearRgb ToLinearRgb(in Rgb color) { // Conversion return RgbToLinearRgbConverter.Convert(color); @@ -157,7 +157,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public LinearRgb ToLinearRgb(YCbCr color) + public LinearRgb ToLinearRgb(in YCbCr color) { var rgb = this.ToRgb(color); return this.ToLinearRgb(rgb); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs index 1de0d70d3..3293e2f4a 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(CieLab color) + public Lms ToLms(in CieLab color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(CieLch color) + public Lms ToLms(in CieLch color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(CieLchuv color) + public Lms ToLms(in CieLchuv color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(CieLuv color) + public Lms ToLms(in CieLuv color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(CieXyy color) + public Lms ToLms(in CieXyy color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(CieXyz color) + public Lms ToLms(in CieXyz color) { return this.cachedCieXyzAndLmsConverter.Convert(color); } @@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(Cmyk color) + public Lms ToLms(in Cmyk color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); @@ -91,7 +91,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(Hsl color) + public Lms ToLms(in Hsl color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(Hsv color) + public Lms ToLms(in Hsv color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); @@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(HunterLab color) + public Lms ToLms(in HunterLab color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); @@ -124,7 +124,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(LinearRgb color) + public Lms ToLms(in LinearRgb color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); @@ -135,7 +135,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(Rgb color) + public Lms ToLms(in Rgb color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); @@ -146,7 +146,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Lms ToLms(YCbCr color) + public Lms ToLms(in YCbCr color) { var xyzColor = this.ToCieXyz(color); return this.ToLms(xyzColor); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs index b609934e9..5bfb6ee05 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(CieLab color) + public Rgb ToRgb(in CieLab color) { var xyzColor = this.ToCieXyz(color); return this.ToRgb(xyzColor); @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(CieLch color) + public Rgb ToRgb(in CieLch color) { var xyzColor = this.ToCieXyz(color); return this.ToRgb(xyzColor); @@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(CieLchuv color) + public Rgb ToRgb(in CieLchuv color) { var xyzColor = this.ToCieXyz(color); return this.ToRgb(xyzColor); @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(CieLuv color) + public Rgb ToRgb(in CieLuv color) { var xyzColor = this.ToCieXyz(color); return this.ToRgb(xyzColor); @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(CieXyy color) + public Rgb ToRgb(in CieXyy color) { var xyzColor = this.ToCieXyz(color); return this.ToRgb(xyzColor); @@ -72,7 +72,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(CieXyz color) + public Rgb ToRgb(in CieXyz color) { // Conversion var linear = this.ToLinearRgb(color); @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(Cmyk color) + public Rgb ToRgb(in Cmyk color) { // Conversion return CmykAndRgbConverter.Convert(color); @@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(Hsv color) + public Rgb ToRgb(in Hsv color) { // Conversion return HsvAndRgbConverter.Convert(color); @@ -108,7 +108,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(Hsl color) + public Rgb ToRgb(in Hsl color) { // Conversion return HslAndRgbConverter.Convert(color); @@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(HunterLab color) + public Rgb ToRgb(in HunterLab color) { var xyzColor = this.ToCieXyz(color); return this.ToRgb(xyzColor); @@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(LinearRgb color) + public Rgb ToRgb(in LinearRgb color) { // Conversion return LinearRgbToRgbConverter.Convert(color); @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(Lms color) + public Rgb ToRgb(in Lms color) { var xyzColor = this.ToCieXyz(color); return this.ToRgb(xyzColor); @@ -152,7 +152,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public Rgb ToRgb(YCbCr color) + public Rgb ToRgb(in YCbCr color) { // Conversion Rgb rgb = YCbCrAndRgbConverter.Convert(color); diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs index 97d9f3818..b7fe34f41 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(CieLab color) + public YCbCr ToYCbCr(in CieLab color) { var xyzColor = this.ToCieXyz(color); @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(CieLch color) + public YCbCr ToYCbCr(in CieLch color) { var xyzColor = this.ToCieXyz(color); @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(CieLchuv color) + public YCbCr ToYCbCr(in CieLchuv color) { var xyzColor = this.ToCieXyz(color); @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(CieLuv color) + public YCbCr ToYCbCr(in CieLuv color) { var xyzColor = this.ToCieXyz(color); @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(CieXyy color) + public YCbCr ToYCbCr(in CieXyy color) { var xyzColor = this.ToCieXyz(color); @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(CieXyz color) + public YCbCr ToYCbCr(in CieXyz color) { var rgb = this.ToRgb(color); @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(Cmyk color) + public YCbCr ToYCbCr(in Cmyk color) { var rgb = this.ToRgb(color); @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(Hsl color) + public YCbCr ToYCbCr(in Hsl color) { var rgb = this.ToRgb(color); @@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(Hsv color) + public YCbCr ToYCbCr(in Hsv color) { var rgb = this.ToRgb(color); @@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(HunterLab color) + public YCbCr ToYCbCr(in HunterLab color) { var xyzColor = this.ToCieXyz(color); @@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(LinearRgb color) + public YCbCr ToYCbCr(in LinearRgb color) { var rgb = this.ToRgb(color); @@ -149,7 +149,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(Lms color) + public YCbCr ToYCbCr(in Lms color) { var xyzColor = this.ToCieXyz(color); @@ -161,7 +161,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The color to convert. /// The - public YCbCr ToYCbCr(Rgb color) + public YCbCr ToYCbCr(in Rgb color) { return YCbCrAndRgbConverter.Convert(color); } From 315e670b1e33659759f0dad95e0fd1ab1de1e55a Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 10:11:12 -0700 Subject: [PATCH 23/68] Update IColorConversion to support readonly structs --- .../ColorSpaces/Conversion/IChromaticAdaptation.cs | 4 +--- .../ColorSpaces/Conversion/IColorConversion.cs | 6 ++++-- .../Implementation/CieLab/CieLabToCieXyzConverter.cs | 2 +- .../Implementation/CieLab/CieXyzToCieLabConverter.cs | 8 ++------ .../Implementation/CieLch/CIeLchToCieLabConverter.cs | 2 +- .../Implementation/CieLch/CieLabToCieLchConverter.cs | 2 +- .../CieLchuv/CieLchuvToCieLuvConverter.cs | 2 +- .../CieLchuv/CieLuvToCieLchuvConverter.cs | 2 +- .../Implementation/CieLuv/CieLuvToCieXyzConverter.cs | 6 +++--- .../Implementation/CieLuv/CieXyzToCieLuvConverter.cs | 12 ++++-------- .../CieXyy/CieXyzAndCieXyyConverter.cs | 4 ++-- .../Implementation/Cmyk/CmykAndRgbConverter.cs | 4 ++-- .../Implementation/Hsl/HslAndRgbConverter.cs | 4 ++-- .../Implementation/Hsv/HsvAndRgbConverter.cs | 4 ++-- .../HunterLab/CieXyzToHunterLabConverter.cs | 2 +- .../HunterLab/HunterLabToCieXyzConverter.cs | 2 +- .../Implementation/Lms/CieXyzAndLmsConverter.cs | 4 ++-- .../Implementation/Rgb/CieXyzToLinearRgbConverter.cs | 2 +- .../Implementation/Rgb/LinearRgbToCieXyzConverter.cs | 2 +- .../Implementation/Rgb/LinearRgbToRgbConverter.cs | 2 +- .../Implementation/Rgb/RgbToLinearRgbConverter.cs | 2 +- .../Implementation/YCbCr/YCbCrAndRgbConverter.cs | 4 ++-- .../Conversion/VonKriesChromaticAdaptation.cs | 2 +- 23 files changed, 38 insertions(+), 46 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/Conversion/IChromaticAdaptation.cs b/src/ImageSharp/ColorSpaces/Conversion/IChromaticAdaptation.cs index c5d91f9a0..dfba4b926 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/IChromaticAdaptation.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/IChromaticAdaptation.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.ColorSpaces; - namespace SixLabors.ImageSharp.ColorSpaces.Conversion { /// @@ -20,6 +18,6 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// The source white point. /// The target white point. /// The - CieXyz Transform(CieXyz sourceColor, CieXyz sourceWhitePoint, CieXyz targetWhitePoint); + CieXyz Transform(in CieXyz sourceColor, in CieXyz sourceWhitePoint, in CieXyz targetWhitePoint); } } \ No newline at end of file diff --git a/src/ImageSharp/ColorSpaces/Conversion/IColorConversion.cs b/src/ImageSharp/ColorSpaces/Conversion/IColorConversion.cs index 9ef24b38a..009b91c40 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/IColorConversion.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/IColorConversion.cs @@ -8,13 +8,15 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The input color type. /// The result color type. - internal interface IColorConversion + internal interface IColorConversion + where T : struct + where TResult : struct { /// /// Performs the conversion from the input to an instance of the output type. /// /// The input color instance. /// The converted result - TResult Convert(T input); + TResult Convert(in T input); } } \ No newline at end of file diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs index 53d9c927a..ca8f23c56 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLabColor { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieXyz Convert(CieLab input) + public CieXyz Convert(in CieLab input) { // Conversion algorithm described here: http://www.brucelindbloom.com/index.html?Eqn_Lab_to_XYZ.html float l = input.L, a = input.A, b = input.B; diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs index 454601b88..0fe52e6af 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs @@ -33,15 +33,11 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLabColor /// /// Gets the target reference whitepoint. When not set, is used. /// - public CieXyz LabWhitePoint - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get; - } + public CieXyz LabWhitePoint { get; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieLab Convert(CieXyz input) + public CieLab Convert(in CieXyz input) { // Conversion algorithm described here: http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Lab.html float wx = this.LabWhitePoint.X, wy = this.LabWhitePoint.Y, wz = this.LabWhitePoint.Z; diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs index 0b1ebae0e..061d04493 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchColor { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieLab Convert(CieLch input) + public CieLab Convert(in CieLch input) { // Conversion algorithm described here: // https://en.wikipedia.org/wiki/Lab_color_space#Cylindrical_representation:_CIELCh_or_CIEHLC diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs index ec73a830f..105fb2aa1 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchColor { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieLch Convert(CieLab input) + public CieLch Convert(in CieLab input) { // Conversion algorithm described here: // https://en.wikipedia.org/wiki/Lab_color_space#Cylindrical_representation:_CIELCh_or_CIEHLC diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs index eb523806a..7f8e0fc1e 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuvCol { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieLuv Convert(CieLchuv input) + public CieLuv Convert(in CieLchuv input) { // Conversion algorithm described here: // https://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation_.28CIELCH.29 diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs index 7a9dd2c6a..7a23e2da1 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuvCol { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieLchuv Convert(CieLuv input) + public CieLchuv Convert(in CieLuv input) { // Conversion algorithm described here: // https://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation_.28CIELCH.29 diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs index 7a264fdfe..cd2ec488d 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColor { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieXyz Convert(CieLuv input) + public CieXyz Convert(in CieLuv input) { // Conversion algorithm described here: http://www.brucelindbloom.com/index.html?Eqn_Luv_to_XYZ.html float l = input.L, u = input.U, v = input.V; @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColor /// The whitepoint /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static float ComputeU0(CieXyz input) + private static float ComputeU0(in CieXyz input) { return (4 * input.X) / (input.X + (15 * input.Y) + (3 * input.Z)); } @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColor /// The whitepoint /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static float ComputeV0(CieXyz input) + private static float ComputeV0(in CieXyz input) { return (9 * input.Y) / (input.X + (15 * input.Y) + (3 * input.Z)); } diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs index e1c5dde4f..c34a2455a 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs @@ -34,15 +34,11 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColor /// /// Gets the target reference whitepoint. When not set, is used. /// - public CieXyz LuvWhitePoint - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get; - } + public CieXyz LuvWhitePoint { get; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieLuv Convert(CieXyz input) + public CieLuv Convert(in CieXyz input) { // Conversion algorithm described here: http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Luv.html float yr = input.Y / this.LuvWhitePoint.Y; @@ -80,7 +76,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColor /// The whitepoint /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static float ComputeUp(CieXyz input) + private static float ComputeUp(in CieXyz input) { return (4 * input.X) / (input.X + (15 * input.Y) + (3 * input.Z)); } @@ -90,7 +86,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLuvColor /// /// The whitepoint /// The - private static float ComputeVp(CieXyz input) + private static float ComputeVp(in CieXyz input) { return (9 * input.Y) / (input.X + (15 * input.Y) + (3 * input.Z)); } diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs index 7dfc577dc..d15f7360e 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieXyyColor { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieXyy Convert(CieXyz input) + public CieXyy Convert(in CieXyz input) { float x = input.X / (input.X + input.Y + input.Z); float y = input.Y / (input.X + input.Y + input.Z); @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieXyyColor /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieXyz Convert(CieXyy input) + public CieXyz Convert(in CieXyy input) { if (MathF.Abs(input.Y) < Constants.Epsilon) { diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Cmyk/CmykAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Cmyk/CmykAndRgbConverter.cs index ed86ec9a5..869178370 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Cmyk/CmykAndRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Cmyk/CmykAndRgbConverter.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CmykColorSa { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Rgb Convert(Cmyk input) + public Rgb Convert(in Cmyk input) { float r = (1F - input.C) * (1F - input.K); float g = (1F - input.M) * (1F - input.K); @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CmykColorSa /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Cmyk Convert(Rgb input) + public Cmyk Convert(in Rgb input) { // To CMYK float c = 1F - input.R; diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs index 7983b6ce4..1bec834a8 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HslColorSap { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Rgb Convert(Hsl input) + public Rgb Convert(in Hsl input) { float rangedH = input.H / 360F; float r = 0; @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HslColorSap /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Hsl Convert(Rgb input) + public Hsl Convert(in Rgb input) { float r = input.R; float g = input.G; diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsv/HsvAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsv/HsvAndRgbConverter.cs index c46d8f26b..f2c4cc188 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsv/HsvAndRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsv/HsvAndRgbConverter.cs @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HsvColorSap { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Rgb Convert(Hsv input) + public Rgb Convert(in Hsv input) { float s = input.S; float v = input.V; @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HsvColorSap /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Hsv Convert(Rgb input) + public Hsv Convert(in Rgb input) { float r = input.R; float g = input.G; diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs index 58363ea2b..af681e981 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HunterLabCo /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public HunterLab Convert(CieXyz input) + public HunterLab Convert(in CieXyz input) { // Conversion algorithm described here: http://en.wikipedia.org/wiki/Lab_color_space#Hunter_Lab float x = input.X, y = input.Y, z = input.Z; diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs index 228d7362b..eba9fe1c8 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.HunterLabCo { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieXyz Convert(HunterLab input) + public CieXyz Convert(in HunterLab input) { // Conversion algorithm described here: http://en.wikipedia.org/wiki/Lab_color_space#Hunter_Lab float l = input.L, a = input.A, b = input.B; diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/CieXyzAndLmsConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/CieXyzAndLmsConverter.cs index 5241b62f9..c29496c37 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/CieXyzAndLmsConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Lms/CieXyzAndLmsConverter.cs @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.LmsColorSap /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Lms Convert(CieXyz input) + public Lms Convert(in CieXyz input) { Vector3 vector = Vector3.Transform(input.Vector, this.transformationMatrix); return new Lms(vector); @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.LmsColorSap /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public CieXyz Convert(Lms input) + public CieXyz Convert(in Lms input) { Vector3 vector = Vector3.Transform(input.Vector, this.inverseTransformationMatrix); return new CieXyz(vector); diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs index 2f52c2074..e75d4a804 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap public IRgbWorkingSpace TargetWorkingSpace { get; } /// - public LinearRgb Convert(CieXyz input) + public LinearRgb Convert(in CieXyz input) { Matrix4x4.Invert(this.conversionMatrix, out Matrix4x4 inverted); Vector3 vector = Vector3.Transform(input.Vector, inverted); diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs index 0746c78c3..05cd5b72f 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap public IRgbWorkingSpace SourceWorkingSpace { get; } /// - public CieXyz Convert(LinearRgb input) + public CieXyz Convert(in LinearRgb input) { DebugGuard.IsTrue(input.WorkingSpace.Equals(this.SourceWorkingSpace), nameof(input.WorkingSpace), "Input and source working spaces must be equal."); diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToRgbConverter.cs index 3b70c02af..34873c1f5 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToRgbConverter.cs @@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap internal class LinearRgbToRgbConverter : IColorConversion { /// - public Rgb Convert(LinearRgb input) + public Rgb Convert(in LinearRgb input) { Vector3 vector = input.Vector; vector.X = input.WorkingSpace.Companding.Compress(vector.X); diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbToLinearRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbToLinearRgbConverter.cs index ed415df8c..4cc3d607f 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbToLinearRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbToLinearRgbConverter.cs @@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap internal class RgbToLinearRgbConverter : IColorConversion { /// - public LinearRgb Convert(Rgb input) + public LinearRgb Convert(in Rgb input) { Vector3 vector = input.Vector; vector.X = input.WorkingSpace.Companding.Expand(vector.X); diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/YCbCr/YCbCrAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/YCbCr/YCbCrAndRgbConverter.cs index 99149a592..e8d32572a 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/YCbCr/YCbCrAndRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/YCbCr/YCbCrAndRgbConverter.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.YCbCrColorS /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Rgb Convert(YCbCr input) + public Rgb Convert(in YCbCr input) { float y = input.Y; float cb = input.Cb - 128F; @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.YCbCrColorS /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public YCbCr Convert(Rgb input) + public YCbCr Convert(in Rgb input) { Vector3 rgb = input.Vector * MaxBytes; float r = rgb.X; diff --git a/src/ImageSharp/ColorSpaces/Conversion/VonKriesChromaticAdaptation.cs b/src/ImageSharp/ColorSpaces/Conversion/VonKriesChromaticAdaptation.cs index 22ba5928e..0ab194af2 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/VonKriesChromaticAdaptation.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/VonKriesChromaticAdaptation.cs @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion } /// - public CieXyz Transform(CieXyz sourceColor, CieXyz sourceWhitePoint, CieXyz targetWhitePoint) + public CieXyz Transform(in CieXyz sourceColor, in CieXyz sourceWhitePoint, in CieXyz targetWhitePoint) { if (sourceWhitePoint.Equals(targetWhitePoint)) { From 1e20c5c2a178cb79c8d38efc5f62354a2873d44e Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 10:28:49 -0700 Subject: [PATCH 24/68] Prevent boxing of RgbWorkingSpace --- .../Conversion/Implementation/Rgb/RgbWorkingSpace.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs index 530c01691..e43215614 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap /// /// Trivial implementation of /// - internal readonly struct RgbWorkingSpace : IRgbWorkingSpace + internal class RgbWorkingSpace : IRgbWorkingSpace { /// /// Initializes a new instance of the struct. From a3370e5ad4e3ba2ccc09be99dc0be17afc0eb735 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 10:29:27 -0700 Subject: [PATCH 25/68] Return RgbWorkingSpace directly to reduce virtual calls --- .../ColorSpaces/RgbWorkingSpaces.cs | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs b/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs index 098ca9a4a..79cb5b4dc 100644 --- a/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs +++ b/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs @@ -19,97 +19,97 @@ namespace SixLabors.ImageSharp.ColorSpaces /// Uses proper companding function, according to: /// /// - public static readonly IRgbWorkingSpace SRgb = new RgbWorkingSpace(Illuminants.D65, new SRgbCompanding(), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.3000F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); + public static readonly RgbWorkingSpace SRgb = new RgbWorkingSpace(Illuminants.D65, new SRgbCompanding(), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.3000F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); /// /// Simplified sRgb working space (uses gamma companding instead of ). /// See also . /// - public static readonly IRgbWorkingSpace SRgbSimplified = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.3000F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); + public static readonly RgbWorkingSpace SRgbSimplified = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.3000F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); /// /// Rec. 709 (ITU-R Recommendation BT.709) working space /// - public static readonly IRgbWorkingSpace Rec709 = new RgbWorkingSpace(Illuminants.D65, new Rec709Companding(), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.64F, 0.33F), new CieXyChromaticityCoordinates(0.30F, 0.60F), new CieXyChromaticityCoordinates(0.15F, 0.06F))); + public static readonly RgbWorkingSpace Rec709 = new RgbWorkingSpace(Illuminants.D65, new Rec709Companding(), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.64F, 0.33F), new CieXyChromaticityCoordinates(0.30F, 0.60F), new CieXyChromaticityCoordinates(0.15F, 0.06F))); /// /// Rec. 2020 (ITU-R Recommendation BT.2020F) working space /// - public static readonly IRgbWorkingSpace Rec2020 = new RgbWorkingSpace(Illuminants.D65, new Rec2020Companding(), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.708F, 0.292F), new CieXyChromaticityCoordinates(0.170F, 0.797F), new CieXyChromaticityCoordinates(0.131F, 0.046F))); + public static readonly RgbWorkingSpace Rec2020 = new RgbWorkingSpace(Illuminants.D65, new Rec2020Companding(), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.708F, 0.292F), new CieXyChromaticityCoordinates(0.170F, 0.797F), new CieXyChromaticityCoordinates(0.131F, 0.046F))); /// /// ECI Rgb v2 working space /// - public static readonly IRgbWorkingSpace ECIRgbv2 = new RgbWorkingSpace(Illuminants.D50, new LCompanding(), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F))); + public static readonly RgbWorkingSpace ECIRgbv2 = new RgbWorkingSpace(Illuminants.D50, new LCompanding(), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F))); /// /// Adobe Rgb (1998) working space /// - public static readonly IRgbWorkingSpace AdobeRgb1998 = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); + public static readonly RgbWorkingSpace AdobeRgb1998 = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); /// /// Apple sRgb working space /// - public static readonly IRgbWorkingSpace ApplesRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(1.8F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6250F, 0.3400F), new CieXyChromaticityCoordinates(0.2800F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F))); + public static readonly RgbWorkingSpace ApplesRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(1.8F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6250F, 0.3400F), new CieXyChromaticityCoordinates(0.2800F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F))); /// /// Best Rgb working space /// - public static readonly IRgbWorkingSpace BestRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.2150F, 0.7750F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F))); + public static readonly RgbWorkingSpace BestRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.2150F, 0.7750F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F))); /// /// Beta Rgb working space /// - public static readonly IRgbWorkingSpace BetaRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6888F, 0.3112F), new CieXyChromaticityCoordinates(0.1986F, 0.7551F), new CieXyChromaticityCoordinates(0.1265F, 0.0352F))); + public static readonly RgbWorkingSpace BetaRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6888F, 0.3112F), new CieXyChromaticityCoordinates(0.1986F, 0.7551F), new CieXyChromaticityCoordinates(0.1265F, 0.0352F))); /// /// Bruce Rgb working space /// - public static readonly IRgbWorkingSpace BruceRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2800F, 0.6500F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); + public static readonly RgbWorkingSpace BruceRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2800F, 0.6500F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); /// /// CIE Rgb working space /// - public static readonly IRgbWorkingSpace CIERgb = new RgbWorkingSpace(Illuminants.E, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.2740F, 0.7170F), new CieXyChromaticityCoordinates(0.1670F, 0.0090F))); + public static readonly RgbWorkingSpace CIERgb = new RgbWorkingSpace(Illuminants.E, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.2740F, 0.7170F), new CieXyChromaticityCoordinates(0.1670F, 0.0090F))); /// /// ColorMatch Rgb working space /// - public static readonly IRgbWorkingSpace ColorMatchRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(1.8F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.2950F, 0.6050F), new CieXyChromaticityCoordinates(0.1500F, 0.0750F))); + public static readonly RgbWorkingSpace ColorMatchRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(1.8F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.2950F, 0.6050F), new CieXyChromaticityCoordinates(0.1500F, 0.0750F))); /// /// Don Rgb 4 working space /// - public static readonly IRgbWorkingSpace DonRgb4 = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6960F, 0.3000F), new CieXyChromaticityCoordinates(0.2150F, 0.7650F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F))); + public static readonly RgbWorkingSpace DonRgb4 = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6960F, 0.3000F), new CieXyChromaticityCoordinates(0.2150F, 0.7650F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F))); /// /// Ekta Space PS5 working space /// - public static readonly IRgbWorkingSpace EktaSpacePS5 = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6950F, 0.3050F), new CieXyChromaticityCoordinates(0.2600F, 0.7000F), new CieXyChromaticityCoordinates(0.1100F, 0.0050F))); + public static readonly RgbWorkingSpace EktaSpacePS5 = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6950F, 0.3050F), new CieXyChromaticityCoordinates(0.2600F, 0.7000F), new CieXyChromaticityCoordinates(0.1100F, 0.0050F))); /// /// NTSC Rgb working space /// - public static readonly IRgbWorkingSpace NTSCRgb = new RgbWorkingSpace(Illuminants.C, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F))); + public static readonly RgbWorkingSpace NTSCRgb = new RgbWorkingSpace(Illuminants.C, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F))); /// /// PAL/SECAM Rgb working space /// - public static readonly IRgbWorkingSpace PALSECAMRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2900F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); + public static readonly RgbWorkingSpace PALSECAMRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2900F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); /// /// ProPhoto Rgb working space /// - public static readonly IRgbWorkingSpace ProPhotoRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(1.8F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.1596F, 0.8404F), new CieXyChromaticityCoordinates(0.0366F, 0.0001F))); + public static readonly RgbWorkingSpace ProPhotoRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(1.8F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.1596F, 0.8404F), new CieXyChromaticityCoordinates(0.0366F, 0.0001F))); /// /// SMPTE-C Rgb working space /// - public static readonly IRgbWorkingSpace SMPTECRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.3100F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F))); + public static readonly RgbWorkingSpace SMPTECRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.3100F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F))); /// /// Wide Gamut Rgb working space /// - public static readonly IRgbWorkingSpace WideGamutRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.1150F, 0.8260F), new CieXyChromaticityCoordinates(0.1570F, 0.0180F))); + public static readonly RgbWorkingSpace WideGamutRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.1150F, 0.8260F), new CieXyChromaticityCoordinates(0.1570F, 0.0180F))); } } \ No newline at end of file From 958f7dc118da085fb37f576fc0d543d9807810fb Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 10:32:36 -0700 Subject: [PATCH 26/68] Add periods --- src/ImageSharp/ColorSpaces/Hsl.cs | 2 +- src/ImageSharp/ColorSpaces/Hsv.cs | 2 +- .../ColorSpaces/IRgbWorkingSpace.cs | 4 +-- src/ImageSharp/ColorSpaces/LinearRgb.cs | 2 +- .../ColorSpaces/RgbWorkingSpaces.cs | 34 +++++++++---------- src/ImageSharp/ColorSpaces/YCbCr.cs | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs index 4e9744f05..8ed406753 100644 --- a/src/ImageSharp/ColorSpaces/Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Hsl.cs @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.ColorSpaces internal readonly struct Hsl : IColorVector, IEquatable, IAlmostEquatable { /// - /// Max range used for clamping + /// Max range used for clamping. /// private static readonly Vector3 VectorMax = new Vector3(360, 1, 1); diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs index 954f9f185..c8cc7eea0 100644 --- a/src/ImageSharp/ColorSpaces/Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Hsv.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.ColorSpaces internal readonly struct Hsv : IColorVector, IEquatable, IAlmostEquatable { /// - /// Max range used for clamping + /// Max range used for clamping. /// private static readonly Vector3 VectorMax = new Vector3(360, 1, 1); diff --git a/src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs index 156e94ed3..26c4ad6d4 100644 --- a/src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs +++ b/src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs @@ -12,12 +12,12 @@ namespace SixLabors.ImageSharp.ColorSpaces internal interface IRgbWorkingSpace : IEquatable { /// - /// Gets the reference white of the color space + /// Gets the reference white of the color space. /// CieXyz WhitePoint { get; } /// - /// Gets the chromaticity coordinates of the primaries + /// Gets the chromaticity coordinates of the primaries. /// RgbPrimariesChromaticityCoordinates ChromaticityCoordinates { get; } diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs index 93cf1085c..312187c9d 100644 --- a/src/ImageSharp/ColorSpaces/LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.ColorSpaces internal readonly struct LinearRgb : IColorVector, IEquatable, IAlmostEquatable { /// - /// The default LinearRgb working space + /// The default LinearRgb working space. /// public static readonly IRgbWorkingSpace DefaultWorkingSpace = RgbWorkingSpaces.SRgb; diff --git a/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs b/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs index 79cb5b4dc..978a35725 100644 --- a/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs +++ b/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs @@ -28,87 +28,87 @@ namespace SixLabors.ImageSharp.ColorSpaces public static readonly RgbWorkingSpace SRgbSimplified = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.3000F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); /// - /// Rec. 709 (ITU-R Recommendation BT.709) working space + /// Rec. 709 (ITU-R Recommendation BT.709) working space. /// public static readonly RgbWorkingSpace Rec709 = new RgbWorkingSpace(Illuminants.D65, new Rec709Companding(), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.64F, 0.33F), new CieXyChromaticityCoordinates(0.30F, 0.60F), new CieXyChromaticityCoordinates(0.15F, 0.06F))); /// - /// Rec. 2020 (ITU-R Recommendation BT.2020F) working space + /// Rec. 2020 (ITU-R Recommendation BT.2020F) working space. /// public static readonly RgbWorkingSpace Rec2020 = new RgbWorkingSpace(Illuminants.D65, new Rec2020Companding(), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.708F, 0.292F), new CieXyChromaticityCoordinates(0.170F, 0.797F), new CieXyChromaticityCoordinates(0.131F, 0.046F))); /// - /// ECI Rgb v2 working space + /// ECI Rgb v2 working space. /// public static readonly RgbWorkingSpace ECIRgbv2 = new RgbWorkingSpace(Illuminants.D50, new LCompanding(), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F))); /// - /// Adobe Rgb (1998) working space + /// Adobe Rgb (1998) working space. /// public static readonly RgbWorkingSpace AdobeRgb1998 = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); /// - /// Apple sRgb working space + /// Apple sRgb working space. /// public static readonly RgbWorkingSpace ApplesRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(1.8F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6250F, 0.3400F), new CieXyChromaticityCoordinates(0.2800F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F))); /// - /// Best Rgb working space + /// Best Rgb working space. /// public static readonly RgbWorkingSpace BestRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.2150F, 0.7750F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F))); /// - /// Beta Rgb working space + /// Beta Rgb working space. /// public static readonly RgbWorkingSpace BetaRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6888F, 0.3112F), new CieXyChromaticityCoordinates(0.1986F, 0.7551F), new CieXyChromaticityCoordinates(0.1265F, 0.0352F))); /// - /// Bruce Rgb working space + /// Bruce Rgb working space. /// public static readonly RgbWorkingSpace BruceRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2800F, 0.6500F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); /// - /// CIE Rgb working space + /// CIE Rgb working space. /// public static readonly RgbWorkingSpace CIERgb = new RgbWorkingSpace(Illuminants.E, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.2740F, 0.7170F), new CieXyChromaticityCoordinates(0.1670F, 0.0090F))); /// - /// ColorMatch Rgb working space + /// ColorMatch Rgb working space. /// public static readonly RgbWorkingSpace ColorMatchRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(1.8F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.2950F, 0.6050F), new CieXyChromaticityCoordinates(0.1500F, 0.0750F))); /// - /// Don Rgb 4 working space + /// Don Rgb 4 working space. /// public static readonly RgbWorkingSpace DonRgb4 = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6960F, 0.3000F), new CieXyChromaticityCoordinates(0.2150F, 0.7650F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F))); /// - /// Ekta Space PS5 working space + /// Ekta Space PS5 working space. /// public static readonly RgbWorkingSpace EktaSpacePS5 = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6950F, 0.3050F), new CieXyChromaticityCoordinates(0.2600F, 0.7000F), new CieXyChromaticityCoordinates(0.1100F, 0.0050F))); /// - /// NTSC Rgb working space + /// NTSC Rgb working space. /// public static readonly RgbWorkingSpace NTSCRgb = new RgbWorkingSpace(Illuminants.C, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F))); /// - /// PAL/SECAM Rgb working space + /// PAL/SECAM Rgb working space. /// public static readonly RgbWorkingSpace PALSECAMRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2900F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F))); /// - /// ProPhoto Rgb working space + /// ProPhoto Rgb working space. /// public static readonly RgbWorkingSpace ProPhotoRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(1.8F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.1596F, 0.8404F), new CieXyChromaticityCoordinates(0.0366F, 0.0001F))); /// - /// SMPTE-C Rgb working space + /// SMPTE-C Rgb working space. /// public static readonly RgbWorkingSpace SMPTECRgb = new RgbWorkingSpace(Illuminants.D65, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.3100F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F))); /// - /// Wide Gamut Rgb working space + /// Wide Gamut Rgb working space. /// public static readonly RgbWorkingSpace WideGamutRgb = new RgbWorkingSpace(Illuminants.D50, new GammaCompanding(2.2F), new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.1150F, 0.8260F), new CieXyChromaticityCoordinates(0.1570F, 0.0180F))); } diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs index 31079b6b8..00533c699 100644 --- a/src/ImageSharp/ColorSpaces/YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/YCbCr.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.ColorSpaces internal readonly struct YCbCr : IColorVector, IEquatable, IAlmostEquatable { /// - /// Vector which is used in clamping to the max value + /// Vector which is used in clamping to the max value. /// private static readonly Vector3 VectorMax = new Vector3(255F); From 8c120eb0a67a469f892fc3d2a9b636ce06546630 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 10:42:52 -0700 Subject: [PATCH 27/68] Heed to Stylecop --- .../Conversion/Implementation/Rgb/RgbWorkingSpace.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs index e43215614..d4d00db86 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap internal class RgbWorkingSpace : IRgbWorkingSpace { /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the class. /// /// The reference white point. /// The function pair for converting to and back. From c70923500c345578319c305810e78841a33bb5fe Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 3 Jul 2018 10:55:40 -0700 Subject: [PATCH 28/68] Update tests --- .../Colorspaces/ColorSpaceEqualityTests.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs b/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs index f0ac56f4f..759d0f12f 100644 --- a/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs +++ b/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs @@ -19,18 +19,18 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces internal static readonly Dictionary EmptyDataLookup = new Dictionary { - {nameof( CieLab), CieLab.Empty }, - {nameof( CieLch), CieLch.Empty }, - {nameof( CieLchuv), CieLchuv.Empty }, - {nameof( CieLuv), CieLuv.Empty }, - {nameof( CieXyz), CieXyz.Empty }, - {nameof( CieXyy), CieXyy.Empty }, - {nameof( Hsl), Hsl.Empty }, - {nameof( HunterLab), HunterLab.Empty }, - {nameof( Lms), Lms.Empty }, - {nameof( LinearRgb), LinearRgb.Empty }, - {nameof( Rgb), Rgb.Empty }, - {nameof( YCbCr), YCbCr.Empty } + {nameof( CieLab), default(CieLab) }, + {nameof( CieLch), default(CieLch) }, + {nameof( CieLchuv), default(CieLchuv) }, + {nameof( CieLuv), default(CieLuv) }, + {nameof( CieXyz), default(CieXyz) }, + {nameof( CieXyy), default(CieXyy) }, + {nameof( Hsl), default(Hsl) }, + {nameof( HunterLab), default(HunterLab) }, + {nameof( Lms), default(Lms) }, + {nameof( LinearRgb), default(LinearRgb) }, + {nameof( Rgb), default(Rgb) }, + {nameof( YCbCr), default(YCbCr) } }; public static readonly IEnumerable EmptyData = EmptyDataLookup.Select(x => new [] { x.Key }); From 0475a072d5bfeaaf27edab490d996fa979ad6a7b Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Wed, 4 Jul 2018 00:39:29 +0200 Subject: [PATCH 29/68] remove unnecessary partial keyword --- src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs | 2 +- src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs b/src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs index 114de7610..46061ce9b 100644 --- a/src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs @@ -11,7 +11,7 @@ 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/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs index 480c42ee0..058b03d62 100644 --- a/src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Processing /// /// The pixel format. public class RecolorBrush : IBrush - where TPixel : struct, IPixel + where TPixel : struct, IPixel { /// /// Initializes a new instance of the class. From 57081443647cc008477a10902d55b0cc84fcaf9b Mon Sep 17 00:00:00 2001 From: popow Date: Wed, 4 Jul 2018 20:37:00 +0200 Subject: [PATCH 30/68] luminance levels is now a parameter of the constructor, defaults to 65536 --- .../HistogramEqualizationExtension.cs | 6 ++-- .../HistogramEqualizationProcessor.cs | 28 ++++++++++++++----- .../HistogramEqualizationTests.cs | 8 ++++-- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/ImageSharp/Processing/Normalization/HistogramEqualizationExtension.cs b/src/ImageSharp/Processing/Normalization/HistogramEqualizationExtension.cs index b40064515..aa3c86d24 100644 --- a/src/ImageSharp/Processing/Normalization/HistogramEqualizationExtension.cs +++ b/src/ImageSharp/Processing/Normalization/HistogramEqualizationExtension.cs @@ -15,9 +15,11 @@ namespace SixLabors.ImageSharp.Processing.Normalization /// /// The pixel format. /// The image this method extends. + /// The number of different luminance levels. Typical values are 256 for 8-bit grayscale images + /// or 65536 for 16-bit grayscale images.Defaults to 65536. /// A histogram equalized grayscale image. - public static IImageProcessingContext HistogramEqualization(this IImageProcessingContext source) + public static IImageProcessingContext HistogramEqualization(this IImageProcessingContext source, int luminanceLevels = 65536) where TPixel : struct, IPixel - => source.ApplyProcessor(new HistogramEqualizationProcessor()); + => source.ApplyProcessor(new HistogramEqualizationProcessor(luminanceLevels)); } } diff --git a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs index ac6d23725..782df4762 100644 --- a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs @@ -18,25 +18,39 @@ namespace SixLabors.ImageSharp.Processing.Normalization internal class HistogramEqualizationProcessor : ImageProcessor where TPixel : struct, IPixel { + /// + /// Initializes a new instance of the class. + /// + /// The number of different luminance levels. Typical values are 256 for 8-bit grayscale images + /// or 65536 for 16-bit grayscale images.Defaults to 65536. + public HistogramEqualizationProcessor(int luminanceLevels = 65536) + { + Guard.MustBeGreaterThan(luminanceLevels, 0, nameof(luminanceLevels)); + + this.LuminanceLevels = luminanceLevels; + } + + /// + /// Gets the luminance levels. + /// + public int LuminanceLevels { get; } + /// protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { MemoryAllocator memoryAllocator = configuration.MemoryAllocator; int numberOfPixels = source.Width * source.Height; - bool is16bitPerChannel = typeof(TPixel) == typeof(Rgb48) || typeof(TPixel) == typeof(Rgba64); - Span pixels = source.GetPixelSpan(); // build the histogram of the grayscale levels - int luminanceLevels = is16bitPerChannel ? 65536 : 256; - using (IBuffer histogramBuffer = memoryAllocator.AllocateClean(luminanceLevels)) - using (IBuffer cdfBuffer = memoryAllocator.AllocateClean(luminanceLevels)) + using (IBuffer histogramBuffer = memoryAllocator.AllocateClean(this.LuminanceLevels)) + using (IBuffer cdfBuffer = memoryAllocator.AllocateClean(this.LuminanceLevels)) { Span histogram = histogramBuffer.GetSpan(); for (int i = 0; i < pixels.Length; i++) { TPixel sourcePixel = pixels[i]; - int luminance = this.GetLuminance(sourcePixel, luminanceLevels); + int luminance = this.GetLuminance(sourcePixel, this.LuminanceLevels); histogram[luminance]++; } @@ -50,7 +64,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization { TPixel sourcePixel = pixels[i]; - int luminance = this.GetLuminance(sourcePixel, luminanceLevels); + int luminance = this.GetLuminance(sourcePixel, this.LuminanceLevels); double luminanceEqualized = cdf[luminance] / numberOfPixelsMinusCdfMin; pixels[i].PackFromVector4(new Vector4((float)luminanceEqualized)); diff --git a/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs index 7a750ff8b..2fc49db8a 100644 --- a/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs +++ b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs @@ -10,8 +10,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization { public class HistogramEqualizationTests { - [Fact] - public void HistogramEqualizationTest() + [Theory] + [InlineData(256)] + [InlineData(65536)] + public void HistogramEqualizationTest(int luminanceLevels) { // arrange byte[] pixels = new byte[] @@ -48,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization }; // act - image.Mutate(x => x.HistogramEqualization()); + image.Mutate(x => x.HistogramEqualization(luminanceLevels)); // assert for (int y = 0; y < 8; y++) From 9210d4cc3562f4529bc6545658f6690cf06f1d91 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 5 Jul 2018 22:07:44 +1000 Subject: [PATCH 31/68] Can now preserve correct resolution for jpeg and gif. --- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 36 ++++++++++++++++--- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 32 ++++++++++++++++- .../Jpeg/Components/Decoder/JFifMarker.cs | 5 +-- .../Formats/Jpeg/JpegEncoderCore.cs | 10 ++++-- .../Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs | 6 ++++ src/ImageSharp/MetaData/ImageMetaData.cs | 6 ++++ .../ResolutionUnits.cs} | 4 +-- .../Formats/Jpg/JFifMarkerTests.cs | 4 +-- 8 files changed, 89 insertions(+), 14 deletions(-) rename src/ImageSharp/{Formats/DensityUnits.cs => MetaData/ResolutionUnits.cs} (88%) diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index fc73f55a1..553748f95 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -450,8 +450,8 @@ namespace SixLabors.ImageSharp.Formats.Gif { int index = Unsafe.Add(ref indicesRef, i); - if (this.graphicsControlExtension.TransparencyFlag == false || - this.graphicsControlExtension.TransparencyIndex != index) + if (!this.graphicsControlExtension.TransparencyFlag + || this.graphicsControlExtension.TransparencyIndex != index) { ref TPixel pixel = ref Unsafe.Add(ref rowRef, x); rgba.Rgb = colorTable[index]; @@ -516,14 +516,42 @@ namespace SixLabors.ImageSharp.Formats.Gif /// The stream containing image data. private void ReadLogicalScreenDescriptorAndGlobalColorTable(Stream stream) { - this.metaData = new ImageMetaData(); - this.stream = stream; // Skip the identifier this.stream.Skip(6); this.ReadLogicalScreenDescriptor(); + var meta = new ImageMetaData(); + + // The Pixel Aspect Ratio is defined to be the quotient of the pixel's + // width over its height. The value range in this field allows + // specification of the widest pixel of 4:1 to the tallest pixel of + // 1:4 in increments of 1/64th. + // + // Values : 0 - No aspect ratio information is given. + // 1..255 - Value used in the computation. + // + // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64 + if (this.logicalScreenDescriptor.PixelAspectRatio > 0) + { + meta.ResolutionUnits = ResolutionUnits.AspectRatio; + float ratio = (this.logicalScreenDescriptor.PixelAspectRatio + 15) / 64F; + + if (ratio > 1) + { + meta.HorizontalResolution = ratio; + meta.VerticalResolution = 1; + } + else + { + meta.VerticalResolution = 1 / ratio; + meta.HorizontalResolution = 1; + } + } + + this.metaData = meta; + if (this.logicalScreenDescriptor.GlobalColorTableFlag) { int globalColorTableLength = this.logicalScreenDescriptor.GlobalColorTableSize * 3; diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index e4737f3bc..f5c6ac353 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -226,11 +226,41 @@ namespace SixLabors.ImageSharp.Formats.Gif { byte packedValue = GifLogicalScreenDescriptor.GetPackedValue(useGlobalTable, this.bitDepth - 1, false, this.bitDepth - 1); + // The Pixel Aspect Ratio is defined to be the quotient of the pixel's + // width over its height. The value range in this field allows + // specification of the widest pixel of 4:1 to the tallest pixel of + // 1:4 in increments of 1/64th. + // + // Values : 0 - No aspect ratio information is given. + // 1..255 - Value used in the computation. + // + // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64 + ImageMetaData meta = image.MetaData; + byte ratio = 0; + + if (meta.ResolutionUnits == ResolutionUnits.AspectRatio) + { + double hr = meta.HorizontalResolution; + double vr = meta.VerticalResolution; + if (hr != vr) + { + if (hr > vr) + { + ratio = (byte)((hr * 64) - 15); + } + else + { + ratio = (byte)(((1 / vr) * 64) - 15); + } + } + } + var descriptor = new GifLogicalScreenDescriptor( width: (ushort)image.Width, height: (ushort)image.Height, packed: packedValue, - backgroundColorIndex: unchecked((byte)transparencyIndex)); + backgroundColorIndex: unchecked((byte)transparencyIndex), + ratio); descriptor.WriteTo(this.buffer); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs index 591af6344..af0ceea10 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using SixLabors.ImageSharp.MetaData; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { @@ -31,7 +32,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder this.MajorVersion = majorVersion; this.MinorVersion = minorVersion; - this.DensityUnits = densityUnits; + this.DensityUnits = (ResolutionUnits)densityUnits; this.XDensity = xDensity; this.YDensity = yDensity; } @@ -52,7 +53,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// 01 : Pixels per inch (2.54 cm) /// 02 : Pixels per centimeter /// - public byte DensityUnits { get; } + public ResolutionUnits DensityUnits { get; } /// /// Gets the horizontal pixel density. Must not be zero. diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index 1310d90d2..aee5fed8f 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -210,7 +210,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg int componentCount = 3; // Write the Start Of Image marker. - this.WriteApplicationHeader((short)image.MetaData.HorizontalResolution, (short)image.MetaData.VerticalResolution); + this.WriteApplicationHeader( + (byte)image.MetaData.ResolutionUnits, + (short)image.MetaData.HorizontalResolution, + (short)image.MetaData.VerticalResolution); this.WriteProfiles(image); @@ -425,9 +428,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg /// /// Writes the application header containing the JFIF identifier plus extra data. /// + /// The resolution unit of measurement. /// The resolution of the image in the x- direction. /// The resolution of the image in the y- direction. - private void WriteApplicationHeader(short horizontalResolution, short verticalResolution) + private void WriteApplicationHeader(byte resolutionUnits, short horizontalResolution, short verticalResolution) { // Write the start of image marker. Markers are always prefixed with with 0xff. this.buffer[0] = JpegConstants.Markers.XFF; @@ -445,7 +449,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg this.buffer[10] = 0x00; // = "JFIF",'\0' this.buffer[11] = 0x01; // versionhi this.buffer[12] = 0x01; // versionlo - this.buffer[13] = 0x01; // xyunits as dpi + this.buffer[13] = resolutionUnits; // xyunits // Resolution. Big Endian this.buffer[14] = (byte)(horizontalResolution >> 8); diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index a360d5477..be2af7a3a 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -412,6 +412,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort { this.MetaData.HorizontalResolution = this.jFif.XDensity; this.MetaData.VerticalResolution = this.jFif.YDensity; + this.MetaData.ResolutionUnits = this.jFif.DensityUnits; } else if (this.isExif) { @@ -423,10 +424,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort ? ((Rational)verticalTag.Value).ToDouble() : 0; + byte units = this.MetaData.ExifProfile.TryGetValue(ExifTag.ResolutionUnit, out ExifValue resolutionTag) + ? (byte)(((ushort)resolutionTag.Value) - 1) // EXIF is 1,2,3 + : byte.MinValue; + if (horizontalValue > 0 && verticalValue > 0) { this.MetaData.HorizontalResolution = horizontalValue; this.MetaData.VerticalResolution = verticalValue; + this.MetaData.ResolutionUnits = (ResolutionUnits)units; } } diff --git a/src/ImageSharp/MetaData/ImageMetaData.cs b/src/ImageSharp/MetaData/ImageMetaData.cs index af3cc5f5f..9a7e2d179 100644 --- a/src/ImageSharp/MetaData/ImageMetaData.cs +++ b/src/ImageSharp/MetaData/ImageMetaData.cs @@ -47,6 +47,7 @@ namespace SixLabors.ImageSharp.MetaData { this.HorizontalResolution = other.HorizontalResolution; this.VerticalResolution = other.VerticalResolution; + this.ResolutionUnits = other.ResolutionUnits; this.RepeatCount = other.RepeatCount; foreach (ImageProperty property in other.Properties) @@ -99,6 +100,11 @@ namespace SixLabors.ImageSharp.MetaData } } + /// + /// Gets or sets unit of measure used when reporting resolution. + /// + public ResolutionUnits ResolutionUnits { get; set; } = ResolutionUnits.PixelsPerInch; + /// /// Gets or sets the Exif profile. /// diff --git a/src/ImageSharp/Formats/DensityUnits.cs b/src/ImageSharp/MetaData/ResolutionUnits.cs similarity index 88% rename from src/ImageSharp/Formats/DensityUnits.cs rename to src/ImageSharp/MetaData/ResolutionUnits.cs index ce30bd06c..7dfd62de8 100644 --- a/src/ImageSharp/Formats/DensityUnits.cs +++ b/src/ImageSharp/MetaData/ResolutionUnits.cs @@ -1,12 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats +namespace SixLabors.ImageSharp.MetaData { /// /// Provides enumeration of available pixel density units. /// - public enum DensityUnits : byte + public enum ResolutionUnits : byte { /// /// No units; width:height pixel aspect ratio = Ydensity:Xdensity diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs index 332899e8d..e7d8845b4 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; - +using SixLabors.ImageSharp.MetaData; using Xunit; namespace SixLabors.ImageSharp.Tests.Formats.Jpg @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Assert.True(isJFif); Assert.Equal(1, marker.MajorVersion); Assert.Equal(1, marker.MinorVersion); - Assert.Equal(1, marker.DensityUnits); + Assert.Equal(ResolutionUnits.PixelsPerInch, marker.DensityUnits); Assert.Equal(96, marker.XDensity); Assert.Equal(96, marker.YDensity); } From 18fd82039832e608aa8e86cc04245a38cabb11f0 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 6 Jul 2018 17:40:09 +1000 Subject: [PATCH 32/68] Properly handle png resolution. --- .../Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs | 2 +- src/ImageSharp/Formats/Png/PngConstants.cs | 6 +++ src/ImageSharp/Formats/Png/PngDecoderCore.cs | 35 ++++++++++++--- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 44 +++++++++++++++---- 4 files changed, 73 insertions(+), 14 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index be2af7a3a..8e2db4e8e 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -425,7 +425,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort : 0; byte units = this.MetaData.ExifProfile.TryGetValue(ExifTag.ResolutionUnit, out ExifValue resolutionTag) - ? (byte)(((ushort)resolutionTag.Value) - 1) // EXIF is 1,2,3 + ? (byte)(((ushort)resolutionTag.Value) - 1) // ExifTag.ResolutionUnit values are 1, 2, 3 : byte.MinValue; if (horizontalValue > 0 && verticalValue > 0) diff --git a/src/ImageSharp/Formats/Png/PngConstants.cs b/src/ImageSharp/Formats/Png/PngConstants.cs index ff25e26b7..df0e16a17 100644 --- a/src/ImageSharp/Formats/Png/PngConstants.cs +++ b/src/ImageSharp/Formats/Png/PngConstants.cs @@ -41,5 +41,11 @@ namespace SixLabors.ImageSharp.Formats.Png /// The header bytes as a big endian coded ulong. /// public const ulong HeaderValue = 0x89504E470D0A1A0AUL; + + /// + /// The number of inches in a meter. Used for converting PPM to PPI in . + /// One inch is equal to exactly 0.0254 meters. + /// + public const double InchesInMeter = 1 / 0.0254D; } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 04d4f057c..f95b9970a 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -233,7 +233,7 @@ namespace SixLabors.ImageSharp.Formats.Png this.ValidateHeader(); break; case PngChunkType.Physical: - this.ReadPhysicalChunk(metadata, chunk.Data.Array); + this.ReadPhysicalChunk(metadata, chunk.Data.GetSpan()); break; case PngChunkType.Data: if (image == null) @@ -307,7 +307,7 @@ namespace SixLabors.ImageSharp.Formats.Png this.ValidateHeader(); break; case PngChunkType.Physical: - this.ReadPhysicalChunk(metadata, chunk.Data.Array); + this.ReadPhysicalChunk(metadata, chunk.Data.GetSpan()); break; case PngChunkType.Data: this.SkipChunkDataAndCrc(chunk); @@ -396,9 +396,34 @@ namespace SixLabors.ImageSharp.Formats.Png /// The data containing physical data. private void ReadPhysicalChunk(ImageMetaData metadata, ReadOnlySpan data) { - // 39.3700787 = inches in a meter. - metadata.HorizontalResolution = BinaryPrimitives.ReadInt32BigEndian(data.Slice(0, 4)) / 39.3700787d; - metadata.VerticalResolution = BinaryPrimitives.ReadInt32BigEndian(data.Slice(4, 4)) / 39.3700787d; + // The pHYs chunk specifies the intended pixel size or aspect ratio for display of the image. It contains: + // Pixels per unit, X axis: 4 bytes (unsigned integer) + // Pixels per unit, Y axis: 4 bytes (unsigned integer) + // Unit specifier: 1 byte + // + // The following values are legal for the unit specifier: + // 0: unit is unknown + // 1: unit is the meter + // + // When the unit specifier is 0, the pHYs chunk defines pixel aspect ratio only; the actual size of the pixels remains unspecified. + // Conversion note: one inch is equal to exactly 0.0254 meters. + int hResolution = BinaryPrimitives.ReadInt32BigEndian(data.Slice(0, 4)); + int vResolution = BinaryPrimitives.ReadInt32BigEndian(data.Slice(4, 4)); + byte unit = data[8]; + + if (unit == byte.MinValue) + { + metadata.HorizontalResolution = hResolution; + metadata.VerticalResolution = vResolution; + metadata.ResolutionUnits = ResolutionUnits.AspectRatio; + return; + } + + // Use PPI for its commonality. + const double inchesInMeter = PngConstants.InchesInMeter; + metadata.HorizontalResolution = hResolution / inchesInMeter; + metadata.VerticalResolution = vResolution / inchesInMeter; + metadata.ResolutionUnits = ResolutionUnits.PixelsPerInch; } /// diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 69f04979c..6aef2a4d9 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -8,6 +8,7 @@ using System.Linq; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Png.Zlib; +using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Quantization; using SixLabors.Memory; @@ -598,19 +599,46 @@ namespace SixLabors.ImageSharp.Formats.Png private void WritePhysicalChunk(Stream stream, Image image) where TPixel : struct, IPixel { - if (image.MetaData.HorizontalResolution > 0 && image.MetaData.VerticalResolution > 0) + // The pHYs chunk specifies the intended pixel size or aspect ratio for display of the image. It contains: + // Pixels per unit, X axis: 4 bytes (unsigned integer) + // Pixels per unit, Y axis: 4 bytes (unsigned integer) + // Unit specifier: 1 byte + // + // The following values are legal for the unit specifier: + // 0: unit is unknown + // 1: unit is the meter + // + // When the unit specifier is 0, the pHYs chunk defines pixel aspect ratio only; the actual size of the pixels remains unspecified. + // Conversion note: one inch is equal to exactly 0.0254 meters. + ImageMetaData meta = image.MetaData; + Span hResolution = this.chunkDataBuffer.AsSpan(0, 4); + Span vResolution = this.chunkDataBuffer.AsSpan(4, 4); + switch (meta.ResolutionUnits) { - // 39.3700787 = inches in a meter. - int dpmX = (int)Math.Round(image.MetaData.HorizontalResolution * 39.3700787D); - int dpmY = (int)Math.Round(image.MetaData.VerticalResolution * 39.3700787D); + case ResolutionUnits.AspectRatio: - BinaryPrimitives.WriteInt32BigEndian(this.chunkDataBuffer.AsSpan(0, 4), dpmX); - BinaryPrimitives.WriteInt32BigEndian(this.chunkDataBuffer.AsSpan(4, 4), dpmY); + this.chunkDataBuffer[8] = 0; + BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(meta.HorizontalResolution)); + BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(meta.HorizontalResolution)); + break; + + case ResolutionUnits.PixelsPerCentimeter: - this.chunkDataBuffer[8] = 1; + this.chunkDataBuffer[8] = 1; + const int CmInMeter = 100; + BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(meta.HorizontalResolution * CmInMeter)); + BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(meta.HorizontalResolution * CmInMeter)); + break; - this.WriteChunk(stream, PngChunkType.Physical, this.chunkDataBuffer, 0, 9); + default: + + this.chunkDataBuffer[8] = 1; + BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(meta.HorizontalResolution * PngConstants.InchesInMeter)); + BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(meta.HorizontalResolution * PngConstants.InchesInMeter)); + break; } + + this.WriteChunk(stream, PngChunkType.Physical, this.chunkDataBuffer, 0, 9); } /// From 95e77e3ba3034596abb2eac7a1bcca852ffb8a10 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 7 Jul 2018 18:03:14 +1000 Subject: [PATCH 33/68] Use UnitConverter to abstract complexity. --- .../Common/Helpers/UnitConverter.cs | 73 +++++++++++++++++++ src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 2 +- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 2 +- .../Jpeg/Components/Decoder/JFifMarker.cs | 5 +- .../Formats/Jpeg/JpegEncoderCore.cs | 23 +++--- .../Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs | 8 +- src/ImageSharp/Formats/Png/PngConstants.cs | 6 -- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 13 ++-- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 22 +++--- src/ImageSharp/MetaData/ImageMetaData.cs | 2 +- ...olutionUnits.cs => PixelResolutionUnit.cs} | 2 +- .../Formats/Jpg/JFifMarkerTests.cs | 2 +- 12 files changed, 110 insertions(+), 50 deletions(-) create mode 100644 src/ImageSharp/Common/Helpers/UnitConverter.cs rename src/ImageSharp/MetaData/{ResolutionUnits.cs => PixelResolutionUnit.cs} (93%) diff --git a/src/ImageSharp/Common/Helpers/UnitConverter.cs b/src/ImageSharp/Common/Helpers/UnitConverter.cs new file mode 100644 index 000000000..9a7d25c55 --- /dev/null +++ b/src/ImageSharp/Common/Helpers/UnitConverter.cs @@ -0,0 +1,73 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.MetaData; +using SixLabors.ImageSharp.MetaData.Profiles.Exif; + +namespace SixLabors.ImageSharp.Common.Helpers +{ + /// + /// Contains methods for converting values between unit scales. + /// + internal static class UnitConverter + { + /// + /// The number of centimeters in a meter. + /// 1 cm is equal to exactly 0.01 meters. + /// + private const double CmsInMeter = 1 / 0.01D; + + /// + /// The number of inches in a meter. + /// 1 inch is equal to exactly 0.0254 meters. + /// + private const double InchesInMeter = 1 / 0.0254D; + + /// + /// Scales the value from centimeters to meters. + /// + /// The value to scale. + /// The . + [MethodImpl(InliningOptions.ShortMethod)] + public static double CmToMeter(double x) => x * CmsInMeter; + + /// + /// Scales the value from meters to centimeters. + /// + /// The value to scale. + /// The . + [MethodImpl(InliningOptions.ShortMethod)] + public static double MeterToCm(double x) => x / CmsInMeter; + + /// + /// Scales the value from meters to inches. + /// + /// The value to scale. + /// The . + [MethodImpl(InliningOptions.ShortMethod)] + public static double MeterToInch(double x) => x / InchesInMeter; + + /// + /// Scales the value from inches to meters. + /// + /// The value to scale. + /// The . + [MethodImpl(InliningOptions.ShortMethod)] + public static double InchToMeter(double x) => x * InchesInMeter; + + /// + /// Converts an to a . + /// + /// The EXIF profile containing the value. + /// The + [MethodImpl(InliningOptions.ShortMethod)] + public static PixelResolutionUnit ExifProfileToResolutionUnit(ExifProfile profile) + { + return profile.TryGetValue(ExifTag.ResolutionUnit, out ExifValue resolution) + ? (PixelResolutionUnit)(byte)(((ushort)resolution.Value) - 1) // EXIF is 1, 2, 3 + : default; + } + } +} diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 553748f95..462f09897 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -535,7 +535,7 @@ namespace SixLabors.ImageSharp.Formats.Gif // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64 if (this.logicalScreenDescriptor.PixelAspectRatio > 0) { - meta.ResolutionUnits = ResolutionUnits.AspectRatio; + meta.ResolutionUnits = PixelResolutionUnit.AspectRatio; float ratio = (this.logicalScreenDescriptor.PixelAspectRatio + 15) / 64F; if (ratio > 1) diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index f5c6ac353..ea507c781 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -238,7 +238,7 @@ namespace SixLabors.ImageSharp.Formats.Gif ImageMetaData meta = image.MetaData; byte ratio = 0; - if (meta.ResolutionUnits == ResolutionUnits.AspectRatio) + if (meta.ResolutionUnits == PixelResolutionUnit.AspectRatio) { double hr = meta.HorizontalResolution; double vr = meta.VerticalResolution; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs index af0ceea10..f153ce062 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs @@ -29,10 +29,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { Guard.MustBeGreaterThan(xDensity, 0, nameof(xDensity)); Guard.MustBeGreaterThan(yDensity, 0, nameof(yDensity)); + Guard.MustBeBetweenOrEqualTo(densityUnits, 0, 2, nameof(densityUnits)); this.MajorVersion = majorVersion; this.MinorVersion = minorVersion; - this.DensityUnits = (ResolutionUnits)densityUnits; + this.DensityUnits = (PixelResolutionUnit)densityUnits; this.XDensity = xDensity; this.YDensity = yDensity; } @@ -53,7 +54,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// 01 : Pixels per inch (2.54 cm) /// 02 : Pixels per centimeter /// - public ResolutionUnits DensityUnits { get; } + public PixelResolutionUnit DensityUnits { get; } /// /// Gets the horizontal pixel density. Must not be zero. diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index aee5fed8f..80f21c65d 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -2,11 +2,13 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers.Binary; using System.IO; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder; +using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.MetaData.Profiles.Icc; using SixLabors.ImageSharp.PixelFormats; @@ -210,10 +212,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg int componentCount = 3; // Write the Start Of Image marker. - this.WriteApplicationHeader( - (byte)image.MetaData.ResolutionUnits, - (short)image.MetaData.HorizontalResolution, - (short)image.MetaData.VerticalResolution); + this.WriteApplicationHeader(image.MetaData); this.WriteProfiles(image); @@ -428,10 +427,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg /// /// Writes the application header containing the JFIF identifier plus extra data. /// - /// The resolution unit of measurement. - /// The resolution of the image in the x- direction. - /// The resolution of the image in the y- direction. - private void WriteApplicationHeader(byte resolutionUnits, short horizontalResolution, short verticalResolution) + /// The image meta data. + private void WriteApplicationHeader(ImageMetaData meta) { // Write the start of image marker. Markers are always prefixed with with 0xff. this.buffer[0] = JpegConstants.Markers.XFF; @@ -449,13 +446,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg this.buffer[10] = 0x00; // = "JFIF",'\0' this.buffer[11] = 0x01; // versionhi this.buffer[12] = 0x01; // versionlo - this.buffer[13] = resolutionUnits; // xyunits // Resolution. Big Endian - this.buffer[14] = (byte)(horizontalResolution >> 8); - this.buffer[15] = (byte)horizontalResolution; - this.buffer[16] = (byte)(verticalResolution >> 8); - this.buffer[17] = (byte)verticalResolution; + this.buffer[13] = (byte)meta.ResolutionUnits; // xyunits + Span hResolution = this.buffer.AsSpan(14, 2); + Span vResolution = this.buffer.AsSpan(16, 2); + BinaryPrimitives.WriteInt16BigEndian(hResolution, (short)Math.Round(meta.HorizontalResolution)); + BinaryPrimitives.WriteInt16BigEndian(vResolution, (short)Math.Round(meta.VerticalResolution)); // No thumbnail this.buffer[18] = 0x00; // Thumbnail width diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index 8e2db4e8e..409908eac 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - +using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; @@ -424,15 +424,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort ? ((Rational)verticalTag.Value).ToDouble() : 0; - byte units = this.MetaData.ExifProfile.TryGetValue(ExifTag.ResolutionUnit, out ExifValue resolutionTag) - ? (byte)(((ushort)resolutionTag.Value) - 1) // ExifTag.ResolutionUnit values are 1, 2, 3 - : byte.MinValue; - if (horizontalValue > 0 && verticalValue > 0) { this.MetaData.HorizontalResolution = horizontalValue; this.MetaData.VerticalResolution = verticalValue; - this.MetaData.ResolutionUnits = (ResolutionUnits)units; + this.MetaData.ResolutionUnits = UnitConverter.ExifProfileToResolutionUnit(this.MetaData.ExifProfile); } } diff --git a/src/ImageSharp/Formats/Png/PngConstants.cs b/src/ImageSharp/Formats/Png/PngConstants.cs index df0e16a17..ff25e26b7 100644 --- a/src/ImageSharp/Formats/Png/PngConstants.cs +++ b/src/ImageSharp/Formats/Png/PngConstants.cs @@ -41,11 +41,5 @@ namespace SixLabors.ImageSharp.Formats.Png /// The header bytes as a big endian coded ulong. /// public const ulong HeaderValue = 0x89504E470D0A1A0AUL; - - /// - /// The number of inches in a meter. Used for converting PPM to PPI in . - /// One inch is equal to exactly 0.0254 meters. - /// - public const double InchesInMeter = 1 / 0.0254D; } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index f95b9970a..fd2c636bb 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -10,6 +10,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Png.Zlib; using SixLabors.ImageSharp.MetaData; @@ -406,7 +407,6 @@ namespace SixLabors.ImageSharp.Formats.Png // 1: unit is the meter // // When the unit specifier is 0, the pHYs chunk defines pixel aspect ratio only; the actual size of the pixels remains unspecified. - // Conversion note: one inch is equal to exactly 0.0254 meters. int hResolution = BinaryPrimitives.ReadInt32BigEndian(data.Slice(0, 4)); int vResolution = BinaryPrimitives.ReadInt32BigEndian(data.Slice(4, 4)); byte unit = data[8]; @@ -415,15 +415,14 @@ namespace SixLabors.ImageSharp.Formats.Png { metadata.HorizontalResolution = hResolution; metadata.VerticalResolution = vResolution; - metadata.ResolutionUnits = ResolutionUnits.AspectRatio; + metadata.ResolutionUnits = PixelResolutionUnit.AspectRatio; return; } - // Use PPI for its commonality. - const double inchesInMeter = PngConstants.InchesInMeter; - metadata.HorizontalResolution = hResolution / inchesInMeter; - metadata.VerticalResolution = vResolution / inchesInMeter; - metadata.ResolutionUnits = ResolutionUnits.PixelsPerInch; + // Use PPC since original is in meters. + metadata.HorizontalResolution = UnitConverter.MeterToCm(hResolution); + metadata.VerticalResolution = UnitConverter.MeterToCm(vResolution); + metadata.ResolutionUnits = PixelResolutionUnit.PixelsPerCentimeter; } /// diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 6aef2a4d9..b8a5c22bb 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -6,6 +6,7 @@ using System.Buffers.Binary; using System.IO; using System.Linq; using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Png.Zlib; using SixLabors.ImageSharp.MetaData; @@ -609,32 +610,31 @@ namespace SixLabors.ImageSharp.Formats.Png // 1: unit is the meter // // When the unit specifier is 0, the pHYs chunk defines pixel aspect ratio only; the actual size of the pixels remains unspecified. - // Conversion note: one inch is equal to exactly 0.0254 meters. ImageMetaData meta = image.MetaData; Span hResolution = this.chunkDataBuffer.AsSpan(0, 4); Span vResolution = this.chunkDataBuffer.AsSpan(4, 4); + switch (meta.ResolutionUnits) { - case ResolutionUnits.AspectRatio: + case PixelResolutionUnit.AspectRatio: this.chunkDataBuffer[8] = 0; BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(meta.HorizontalResolution)); - BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(meta.HorizontalResolution)); + BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(meta.VerticalResolution)); break; - case ResolutionUnits.PixelsPerCentimeter: + case PixelResolutionUnit.PixelsPerCentimeter: - this.chunkDataBuffer[8] = 1; - const int CmInMeter = 100; - BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(meta.HorizontalResolution * CmInMeter)); - BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(meta.HorizontalResolution * CmInMeter)); + this.chunkDataBuffer[8] = 1; // Per meter + BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(UnitConverter.CmToMeter(meta.HorizontalResolution))); + BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(UnitConverter.CmToMeter(meta.VerticalResolution))); break; default: - this.chunkDataBuffer[8] = 1; - BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(meta.HorizontalResolution * PngConstants.InchesInMeter)); - BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(meta.HorizontalResolution * PngConstants.InchesInMeter)); + this.chunkDataBuffer[8] = 1; // Per meter + BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(UnitConverter.InchToMeter(meta.HorizontalResolution))); + BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(UnitConverter.InchToMeter(meta.VerticalResolution))); break; } diff --git a/src/ImageSharp/MetaData/ImageMetaData.cs b/src/ImageSharp/MetaData/ImageMetaData.cs index 9a7e2d179..af5cc6191 100644 --- a/src/ImageSharp/MetaData/ImageMetaData.cs +++ b/src/ImageSharp/MetaData/ImageMetaData.cs @@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp.MetaData /// /// Gets or sets unit of measure used when reporting resolution. /// - public ResolutionUnits ResolutionUnits { get; set; } = ResolutionUnits.PixelsPerInch; + public PixelResolutionUnit ResolutionUnits { get; set; } = PixelResolutionUnit.PixelsPerInch; /// /// Gets or sets the Exif profile. diff --git a/src/ImageSharp/MetaData/ResolutionUnits.cs b/src/ImageSharp/MetaData/PixelResolutionUnit.cs similarity index 93% rename from src/ImageSharp/MetaData/ResolutionUnits.cs rename to src/ImageSharp/MetaData/PixelResolutionUnit.cs index 7dfd62de8..899dedeb8 100644 --- a/src/ImageSharp/MetaData/ResolutionUnits.cs +++ b/src/ImageSharp/MetaData/PixelResolutionUnit.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.MetaData /// /// Provides enumeration of available pixel density units. /// - public enum ResolutionUnits : byte + public enum PixelResolutionUnit : byte { /// /// No units; width:height pixel aspect ratio = Ydensity:Xdensity diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs index e7d8845b4..b2dc3534d 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Assert.True(isJFif); Assert.Equal(1, marker.MajorVersion); Assert.Equal(1, marker.MinorVersion); - Assert.Equal(ResolutionUnits.PixelsPerInch, marker.DensityUnits); + Assert.Equal(PixelResolutionUnit.PixelsPerInch, marker.DensityUnits); Assert.Equal(96, marker.XDensity); Assert.Equal(96, marker.YDensity); } From 965bc1037debd8d662a4657eb1913a7d257fbb2f Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 9 Jul 2018 00:02:30 +1000 Subject: [PATCH 34/68] Read/Write bmp resolution --- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 20 +++++++++- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 38 ++++++++++++++++++- .../Formats/Jpeg/JpegEncoderCore.cs | 20 ++++++++-- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 16 +++----- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 11 +++++- .../MetaData/PixelResolutionUnit.cs | 13 +++++-- 6 files changed, 94 insertions(+), 24 deletions(-) diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 20175613e..d690a3a75 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -59,6 +59,11 @@ namespace SixLabors.ImageSharp.Formats.Bmp /// private Stream stream; + /// + /// The metadata + /// + private ImageMetaData metaData; + /// /// The file header containing general information. /// TODO: Why is this not used? We advance the stream but do not use the values parsed. @@ -103,7 +108,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { this.ReadImageHeaders(stream, out bool inverted, out byte[] palette); - var image = new Image(this.configuration, this.infoHeader.Width, this.infoHeader.Height); + var image = new Image(this.configuration, this.infoHeader.Width, this.infoHeader.Height, this.metaData); Buffer2D pixels = image.GetRootFramePixelBuffer(); @@ -157,7 +162,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp public IImageInfo Identify(Stream stream) { this.ReadImageHeaders(stream, out _, out _); - return new ImageInfo(new PixelTypeInfo(this.infoHeader.BitsPerPixel), this.infoHeader.Width, this.infoHeader.Height, new ImageMetaData()); + return new ImageInfo(new PixelTypeInfo(this.infoHeader.BitsPerPixel), this.infoHeader.Width, this.infoHeader.Height, this.metaData); } /// @@ -518,6 +523,17 @@ namespace SixLabors.ImageSharp.Formats.Bmp throw new NotSupportedException($"ImageSharp does not support this BMP file. HeaderSize: {headerSize}."); } + // Resolution is stored in PPM. + ImageMetaData meta = new ImageMetaData(); + if (this.infoHeader.XPelsPerMeter > 0 && this.infoHeader.YPelsPerMeter > 0) + { + meta.ResolutionUnits = PixelResolutionUnit.PixelsPerMeter; + meta.HorizontalResolution = this.infoHeader.XPelsPerMeter; + meta.VerticalResolution = this.infoHeader.YPelsPerMeter; + } + + this.metaData = meta; + // skip the remaining header because we can't read those parts this.stream.Skip(skipAmount); } diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index a4e61f910..80fc6330a 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -3,6 +3,8 @@ using System; using System.IO; +using SixLabors.ImageSharp.Common.Helpers; +using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; @@ -50,6 +52,38 @@ namespace SixLabors.ImageSharp.Formats.Bmp int bytesPerLine = 4 * (((image.Width * bpp) + 31) / 32); this.padding = bytesPerLine - (image.Width * (int)this.bitsPerPixel); + // Set Resolution. + ImageMetaData meta = image.MetaData; + int hResolution = 0; + int vResolution = 0; + + if (meta.ResolutionUnits != PixelResolutionUnit.AspectRatio) + { + if (meta.HorizontalResolution > 0 && meta.VerticalResolution > 0) + { + switch (meta.ResolutionUnits) + { + case PixelResolutionUnit.PixelsPerInch: + + hResolution = (int)Math.Round(UnitConverter.InchToMeter(meta.HorizontalResolution)); + vResolution = (int)Math.Round(UnitConverter.InchToMeter(meta.VerticalResolution)); + break; + + case PixelResolutionUnit.PixelsPerCentimeter: + + hResolution = (int)Math.Round(UnitConverter.CmToMeter(meta.HorizontalResolution)); + vResolution = (int)Math.Round(UnitConverter.CmToMeter(meta.VerticalResolution)); + break; + + case PixelResolutionUnit.PixelsPerMeter: + hResolution = (int)Math.Round(meta.HorizontalResolution); + vResolution = (int)Math.Round(meta.VerticalResolution); + + break; + } + } + } + var infoHeader = new BmpInfoHeader( headerSize: BmpInfoHeader.Size, height: image.Height, @@ -58,7 +92,9 @@ namespace SixLabors.ImageSharp.Formats.Bmp planes: 1, imageSize: image.Height * bytesPerLine, clrUsed: 0, - clrImportant: 0); + clrImportant: 0, + xPelsPerMeter: hResolution, + yPelsPerMeter: vResolution); var fileHeader = new BmpFileHeader( type: 19778, // BM diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index 80f21c65d..ada33f2b8 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -5,7 +5,7 @@ using System; using System.Buffers.Binary; using System.IO; using System.Runtime.CompilerServices; - +using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder; using SixLabors.ImageSharp.MetaData; @@ -448,11 +448,23 @@ namespace SixLabors.ImageSharp.Formats.Jpeg this.buffer[12] = 0x01; // versionlo // Resolution. Big Endian - this.buffer[13] = (byte)meta.ResolutionUnits; // xyunits Span hResolution = this.buffer.AsSpan(14, 2); Span vResolution = this.buffer.AsSpan(16, 2); - BinaryPrimitives.WriteInt16BigEndian(hResolution, (short)Math.Round(meta.HorizontalResolution)); - BinaryPrimitives.WriteInt16BigEndian(vResolution, (short)Math.Round(meta.VerticalResolution)); + + if (meta.ResolutionUnits == PixelResolutionUnit.PixelsPerMeter) + { + // Scale down to PPI + this.buffer[13] = (byte)PixelResolutionUnit.PixelsPerInch; // xyunits + BinaryPrimitives.WriteInt16BigEndian(hResolution, (short)Math.Round(UnitConverter.MeterToInch(meta.HorizontalResolution))); + BinaryPrimitives.WriteInt16BigEndian(vResolution, (short)Math.Round(UnitConverter.MeterToInch(meta.VerticalResolution))); + } + else + { + // We can simply pass the value. + this.buffer[13] = (byte)meta.ResolutionUnits; // xyunits + BinaryPrimitives.WriteInt16BigEndian(hResolution, (short)Math.Round(meta.HorizontalResolution)); + BinaryPrimitives.WriteInt16BigEndian(vResolution, (short)Math.Round(meta.VerticalResolution)); + } // No thumbnail this.buffer[18] = 0x00; // Thumbnail width diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index fd2c636bb..38c550344 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -411,18 +411,12 @@ namespace SixLabors.ImageSharp.Formats.Png int vResolution = BinaryPrimitives.ReadInt32BigEndian(data.Slice(4, 4)); byte unit = data[8]; - if (unit == byte.MinValue) - { - metadata.HorizontalResolution = hResolution; - metadata.VerticalResolution = vResolution; - metadata.ResolutionUnits = PixelResolutionUnit.AspectRatio; - return; - } + metadata.ResolutionUnits = unit == byte.MinValue + ? PixelResolutionUnit.AspectRatio + : PixelResolutionUnit.PixelsPerMeter; - // Use PPC since original is in meters. - metadata.HorizontalResolution = UnitConverter.MeterToCm(hResolution); - metadata.VerticalResolution = UnitConverter.MeterToCm(vResolution); - metadata.ResolutionUnits = PixelResolutionUnit.PixelsPerCentimeter; + metadata.HorizontalResolution = hResolution; + metadata.VerticalResolution = vResolution; } /// diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index b8a5c22bb..df0dffa49 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -623,6 +623,13 @@ namespace SixLabors.ImageSharp.Formats.Png BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(meta.VerticalResolution)); break; + case PixelResolutionUnit.PixelsPerInch: + + this.chunkDataBuffer[8] = 1; // Per meter + BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(UnitConverter.InchToMeter(meta.HorizontalResolution))); + BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(UnitConverter.InchToMeter(meta.VerticalResolution))); + break; + case PixelResolutionUnit.PixelsPerCentimeter: this.chunkDataBuffer[8] = 1; // Per meter @@ -633,8 +640,8 @@ namespace SixLabors.ImageSharp.Formats.Png default: this.chunkDataBuffer[8] = 1; // Per meter - BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(UnitConverter.InchToMeter(meta.HorizontalResolution))); - BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(UnitConverter.InchToMeter(meta.VerticalResolution))); + BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(meta.HorizontalResolution)); + BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(meta.VerticalResolution)); break; } diff --git a/src/ImageSharp/MetaData/PixelResolutionUnit.cs b/src/ImageSharp/MetaData/PixelResolutionUnit.cs index 899dedeb8..ce848004f 100644 --- a/src/ImageSharp/MetaData/PixelResolutionUnit.cs +++ b/src/ImageSharp/MetaData/PixelResolutionUnit.cs @@ -9,18 +9,23 @@ namespace SixLabors.ImageSharp.MetaData public enum PixelResolutionUnit : byte { /// - /// No units; width:height pixel aspect ratio = Ydensity:Xdensity + /// No units; width:height pixel aspect ratio. /// AspectRatio = 0, /// - /// Pixels per inch (2.54 cm) + /// Pixels per inch (2.54 cm). /// - PixelsPerInch = 1, // Other image formats would default to this. + PixelsPerInch = 1, /// /// Pixels per centimeter. /// - PixelsPerCentimeter = 2 + PixelsPerCentimeter = 2, + + /// + /// Pixels per meter (100 cm). + /// + PixelsPerMeter = 3 } } From de02be2e5eabfdf168c78a7538e9c6f86b6307b6 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 9 Jul 2018 01:05:16 +1000 Subject: [PATCH 35/68] Fix broken chunk test --- .../Formats/Png/PngDecoderTests.Chunks.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs index 6f04ba651..dc29b1949 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs @@ -77,8 +77,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png [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((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) { @@ -112,9 +111,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png 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); + // Needs a minimum length of 9 for pHYs chunk. + memStream.Write(new byte[] { 0, 0, 0, 9 }, 0, 4); + memStream.Write(Encoding.GetEncoding("ASCII").GetBytes(chunkName), 0, 4); // 4 bytes chunk header + memStream.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 9); // 9 bytes of chunk data + memStream.Write(new byte[] { 0, 0, 0, 0 }, 0, 4); // Junk Crc } private static void WriteDataChunk(MemoryStream memStream) From 72cbea7cc876611d7e91f830133de5be756ae8f5 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Mon, 9 Jul 2018 01:29:33 +0200 Subject: [PATCH 36/68] LoadResizeSave benchmark + add EnableParallelExecution parameter to the Resize benchmark --- .../Codecs/Jpeg/LoadResizeSave.cs | 88 +++++++++++++++++++ .../ImageSharp.Benchmarks/Samplers/Resize.cs | 36 ++++++-- 2 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 tests/ImageSharp.Benchmarks/Codecs/Jpeg/LoadResizeSave.cs diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/LoadResizeSave.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/LoadResizeSave.cs new file mode 100644 index 000000000..296b3fb7a --- /dev/null +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/LoadResizeSave.cs @@ -0,0 +1,88 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using BenchmarkDotNet.Attributes; +using System; +using System.IO; +using SixLabors.ImageSharp.Tests; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Drawing.Imaging; +using SixLabors.ImageSharp.Processing; +using SDImage = System.Drawing.Image; +using SixLabors.ImageSharp.Formats.Jpeg; + +namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg +{ + [Config(typeof(Config.ShortClr))] + public class LoadResizeSave : BenchmarkBase + { + private readonly Configuration configuration = new Configuration(new JpegConfigurationModule()); + + private byte[] sourceBytes; + + private byte[] destBytes; + + private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage); + + [Params( + TestImages.Jpeg.Baseline.Jpeg420Exif + //, TestImages.Jpeg.Baseline.Calliphora + )] + public string TestImage { get; set; } + + [Params(false, true)] + public bool EnableParallelExecution { get; set; } + + [GlobalSetup] + public void Setup() + { + this.configuration.ParallelOptions.MaxDegreeOfParallelism = + this.EnableParallelExecution ? Environment.ProcessorCount : 1; + + if (this.sourceBytes == null) + { + this.sourceBytes = File.ReadAllBytes(this.TestImageFullPath); + } + + if (this.destBytes == null) + { + this.destBytes = new byte[this.sourceBytes.Length]; + } + } + + [Benchmark(Baseline = true)] + public void SystemDrawing() + { + using (var sourceStream = new MemoryStream(this.sourceBytes)) + using (var destStream = new MemoryStream(this.destBytes)) + using (var source = SDImage.FromStream(sourceStream)) + using (var destination = new Bitmap(source.Width / 4, source.Height / 4)) + { + using (var graphics = Graphics.FromImage(destination)) + { + graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; + graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + graphics.CompositingQuality = CompositingQuality.HighQuality; + graphics.DrawImage(source, 0, 0, 400, 400); + } + + destination.Save(destStream, ImageFormat.Jpeg); + } + } + + [Benchmark] + public void ImageSharp() + { + using (var source = Image.Load( + this.configuration, + this.sourceBytes, + new JpegDecoder { IgnoreMetadata = true })) + using (var destStream = new MemoryStream(this.destBytes)) + { + source.Mutate(c => c.Resize(source.Width / 4, source.Height / 4)); + source.SaveAsJpeg(destStream); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs index 8bba227c5..d4506fc6a 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs @@ -3,20 +3,38 @@ // Licensed under the Apache License, Version 2.0. // -namespace SixLabors.ImageSharp.Benchmarks -{ - using System.Drawing; - using System.Drawing.Drawing2D; +using System; +using System.Drawing; +using System.Drawing.Drawing2D; + +using BenchmarkDotNet.Attributes; - using BenchmarkDotNet.Attributes; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; - using SixLabors.ImageSharp.PixelFormats; - using SixLabors.ImageSharp.Processing; +using CoreSize = SixLabors.Primitives.Size; + +namespace SixLabors.ImageSharp.Benchmarks +{ + using System.Threading.Tasks; - using CoreSize = SixLabors.Primitives.Size; + using SixLabors.ImageSharp.Formats.Jpeg; + [Config(typeof(Config.ShortClr))] public class Resize : BenchmarkBase { + private readonly Configuration configuration = new Configuration(new JpegConfigurationModule()); + + [Params(false, true)] + public bool EnableParallelExecution { get; set; } + + [GlobalSetup] + public void Setup() + { + this.configuration.ParallelOptions.MaxDegreeOfParallelism = + this.EnableParallelExecution ? Environment.ProcessorCount : 1; + } + [Benchmark(Baseline = true, Description = "System.Drawing Resize")] public Size ResizeSystemDrawing() { @@ -40,7 +58,7 @@ namespace SixLabors.ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Resize")] public CoreSize ResizeCore() { - using (Image image = new Image(2000, 2000)) + using (var image = new Image(this.configuration, 2000, 2000)) { image.Mutate(x => x.Resize(400, 400)); return new CoreSize(image.Width, image.Height); From 692d539b787c31e199634059c9d0e2db7ce4c1ad Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 9 Jul 2018 12:34:14 +1000 Subject: [PATCH 37/68] Add gif tests --- .../Formats/Gif/GifDecoderTests.cs | 88 +++++++++++++----- .../Formats/Gif/GifEncoderTests.cs | 36 +++++++ tests/ImageSharp.Tests/TestImages.cs | 5 +- tests/Images/Input/Gif/base_1x4.gif | Bin 0 -> 1620 bytes tests/Images/Input/Gif/base_4x1.gif | Bin 0 -> 1620 bytes 5 files changed, 107 insertions(+), 22 deletions(-) create mode 100644 tests/Images/Input/Gif/base_1x4.gif create mode 100644 tests/Images/Input/Gif/base_4x1.gif diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs index ceb60ae5c..b15e8ff33 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs @@ -13,7 +13,7 @@ using SixLabors.ImageSharp.Advanced; namespace SixLabors.ImageSharp.Tests.Formats.Gif { using System.Collections.Generic; - + using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; public class GifDecoderTests @@ -21,31 +21,43 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif private const PixelTypes TestPixelTypes = PixelTypes.Rgba32 | PixelTypes.RgbaVector | PixelTypes.Argb32; public static readonly string[] MultiFrameTestFiles = - { - TestImages.Gif.Giphy, TestImages.Gif.Kumin - }; + { + TestImages.Gif.Giphy, TestImages.Gif.Kumin + }; public static readonly string[] BasicVerificationFiles = - { - TestImages.Gif.Cheers, - TestImages.Gif.Rings, + { + TestImages.Gif.Cheers, + TestImages.Gif.Rings, - // previously DecodeBadApplicationExtensionLength: - TestImages.Gif.Issues.BadAppExtLength, - TestImages.Gif.Issues.BadAppExtLength_2, + // previously DecodeBadApplicationExtensionLength: + TestImages.Gif.Issues.BadAppExtLength, + TestImages.Gif.Issues.BadAppExtLength_2, - // previously DecodeBadDescriptorDimensionsLength: - TestImages.Gif.Issues.BadDescriptorWidth - }; + // previously DecodeBadDescriptorDimensionsLength: + TestImages.Gif.Issues.BadDescriptorWidth + }; + + public static readonly TheoryData RatioFiles = + new TheoryData + { + { TestImages.Gif.Rings, (int)ImageMetaData.DefaultHorizontalResolution, (int)ImageMetaData.DefaultVerticalResolution , PixelResolutionUnit.PixelsPerInch}, + { TestImages.Gif.Ratio1x4, 1, 4 , PixelResolutionUnit.AspectRatio}, + { TestImages.Gif.Ratio4x1, 4, 1, PixelResolutionUnit.AspectRatio } + }; private static readonly Dictionary BasicVerificationFrameCount = - new Dictionary - { - [TestImages.Gif.Cheers] = 93, - [TestImages.Gif.Issues.BadDescriptorWidth] = 36, - }; + new Dictionary + { + [TestImages.Gif.Cheers] = 93, + [TestImages.Gif.Issues.BadDescriptorWidth] = 36, + }; - public static readonly string[] BadAppExtFiles = { TestImages.Gif.Issues.BadAppExtLength, TestImages.Gif.Issues.BadAppExtLength_2 }; + public static readonly string[] BadAppExtFiles = + { + TestImages.Gif.Issues.BadAppExtLength, + TestImages.Gif.Issues.BadAppExtLength_2 + }; [Theory] [WithFileCollection(nameof(MultiFrameTestFiles), PixelTypes.Rgba32)] @@ -59,6 +71,40 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif } } + [Theory] + [MemberData(nameof(RatioFiles))] + public void Decode_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new GifDecoder(); + using (Image image = decoder.Decode(Configuration.Default, stream)) + { + ImageMetaData meta = image.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Identify_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new GifDecoder(); + IImageInfo image = decoder.Identify(Configuration.Default, stream); + ImageMetaData meta = image.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + [Theory] [WithFile(TestImages.Gif.Trans, TestPixelTypes)] public void GifDecoder_IsNotBoundToSinglePixelType(TestImageProvider provider) @@ -88,7 +134,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif image.CompareFirstFrameToReferenceOutput(ImageComparer.Exact, provider); } } - + [Fact] public void Decode_IgnoreMetadataIsFalse_CommentsAreRead() { @@ -169,7 +215,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif [InlineData(TestImages.Gif.Trans, 8)] public void DetectPixelSize(string imagePath, int expectedPixelSize) { - TestFile testFile = TestFile.Create(imagePath); + var testFile = TestFile.Create(imagePath); using (var stream = new MemoryStream(testFile.Bytes, false)) { Assert.Equal(expectedPixelSize, Image.Identify(stream)?.PixelType?.BitsPerPixel); diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs index 2b9c11fb0..e9104ef8d 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs @@ -17,6 +17,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif private const PixelTypes TestPixelTypes = PixelTypes.Rgba32 | PixelTypes.RgbaVector | PixelTypes.Argb32; private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.001F); + public static readonly TheoryData RatioFiles = + new TheoryData + { + { TestImages.Gif.Rings, (int)ImageMetaData.DefaultHorizontalResolution, (int)ImageMetaData.DefaultVerticalResolution , PixelResolutionUnit.PixelsPerInch}, + { TestImages.Gif.Ratio1x4, 1, 4 , PixelResolutionUnit.AspectRatio}, + { TestImages.Gif.Ratio4x1, 4, 1, PixelResolutionUnit.AspectRatio } + }; + [Theory] [WithTestPatternImages(100, 100, TestPixelTypes)] public void EncodeGeneratedPatterns(TestImageProvider provider) @@ -43,6 +51,34 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif } } + [Theory] + [MemberData(nameof(RatioFiles))] + public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var options = new GifEncoder() + { + IgnoreMetadata = false + }; + + var testFile = TestFile.Create(imagePath); + using (Image input = testFile.CreateImage()) + { + using (var memStream = new MemoryStream()) + { + input.Save(memStream, options); + + memStream.Position = 0; + using (var output = Image.Load(memStream)) + { + ImageMetaData meta = output.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + } + } + [Fact] public void Encode_IgnoreMetadataIsFalse_CommentsAreWritten() { diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index b0bdad8e5..99057a434 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -176,6 +176,9 @@ namespace SixLabors.ImageSharp.Tests public const string Cheers = "Gif/cheers.gif"; public const string Trans = "Gif/trans.gif"; public const string Kumin = "Gif/kumin.gif"; + public const string Ratio4x1 = "Gif/base_4x1.gif"; + public const string Ratio1x4 = "Gif/base_1x4.gif"; + public class Issues { @@ -184,7 +187,7 @@ namespace SixLabors.ImageSharp.Tests public const string BadDescriptorWidth = "Gif/issues/issue403_baddescriptorwidth.gif"; } - public static readonly string[] All = { Rings, Giphy, Cheers, Trans, Kumin }; + public static readonly string[] All = { Rings, Giphy, Cheers, Trans, Kumin, Ratio4x1, Ratio1x4 }; } } } diff --git a/tests/Images/Input/Gif/base_1x4.gif b/tests/Images/Input/Gif/base_1x4.gif new file mode 100644 index 0000000000000000000000000000000000000000..b5d481fee1492de7f886fcdb186c12664d5f9200 GIT binary patch literal 1620 zcmcJ~{Xf$Q0KoCDnVIBaX49<;`5Lwen-tJKvQ_S(%hPiqL} zxp^3FSccgs)`nzTo^o79o{nZ5iMm5MUH`;=e*gUN_Q#&_^dQjy8c=1g1pojT42D1; z`uh3?1_p+PhDJt478Vu&@Xf}?#@5yrfk62B`eHB`e}DgP06-uRh(uycOiWTz5`)2D zGMOnUDZn?NxVV_l=L>~GsZ^>|D*O8ShKGk$D%ITF-2D8!Mx)u>-2C=Gcv_5;@)-HJ=m9iTAn$l%Ga)t7BOJ{ja>Z{)0hes6skrhLKyqlODH5yA3 z+rL-OYZey&T3Y_F@=+t6{?mMJbz}3(*Nso zLBzq|toGk-T0x!?xJgP^ljY%vl?hzer{z$PamdC*t?S=E)JJrJB%1hQnC+@VDvrXmb9hsBa zi6`3gocE*TT2rsugauw9XI55s$+N)`#E4Wn>v_!tCTq3*6Nsp@h2GE!QuFbSdV3tN z`azoLiyYp^>{_DEQ0RHIsNLPUN-*H2x@oc<;_iJzEXw;`_AK-mP~W)Jq}k zhC8=9y}*%c>qXECaz6l^JR*Bho|(8LggU%?*{Pj69xJukMl|jM`HMa<#}ddZudte{ zM(2>6O(t7uRDGuQF%k0QgjUtL;$*uU!9YyLX;QnQaO+I7$~ih^tMv+CgY zfP>^yYz=t4+4$uo0XZU$@L|^DgCU>S+0O%SBNIY05`5w(wbXw5$|g(mZ&vU-kJ(2A9&RR9C8gE>1#m+|_E@l}`mv zuAUI1F8{&5Hsdw>uM6s!L&>e}gR{#qnJ1u4CWh8}M}ARU((5O=|6Zy+$pj;Y2Ra#;LZ!m>?Vwpw|Q zQcG$%aet3fk9&`KU5wMr`%HB|^@8uny~m4^OwG)C+_%Kt`Lfro6oz*sy8}+5hkCyF$Z|oQs&`714%o>JuuYX1D*Bx&);Q?$ySY3#{nmbL;kZeWZ>t~-mT;_54|lI~cMCchY`tZB z0kxL>kX>o-fK>!i`vcm0REO{0>*Ye@$P$~y)vT?kKQ{qv0A%e=dU9~|dT{E#+n#IL za^f7@?)#wj&4CLm54xr+Ja4Y$W-V1B&R~@xl=?@!;3|7ujq=j-CbBrO$^~2K?mN1c lmnZ`tic6)qc2+Hu^~O~(N*f|414Tmn{R6f z<$LpGxM3M)qgWe~ZTXhtGV<+c#*wHyl#i}|;$FYMet7!h&Uku|=>Q$5vR?%N01O60 zAP@rs14BbY7z}1)WMpAs0RZ1@Y;0_8ZIMW%udgo_i}m;S{{{d=B9TNQ#l*xUB_%PL zOcslkl9B>^1B#1_1pU!LKP@-lI^eUbl3X*QCDc{e5^u*&kUk^vAo2$x)-R zG>QFt&AfJD@vo)j4=W$FlIcIq=TJl-_lkol(~JMdqxa1uSPpyyxW9w9))-rQZvKvFLHXL1KvSmLFv=w2SyVt z;f%D0{{(=IcTcg!>{ymA=zg|w18QHzWceG&knboNGkw4SeNNzaTNufMIDsj>_CPW- zH61P`o&)RjhghUJTA-)3sSnoU1L&5449Qo52X(IpHw7f-nG8NGUOQP{vAgRP$EZs) zeI7&_{LO0r?WPsfDWRLRbTwHKj$E0*cYRt81sR8IOhj%>%r=TX0oFc`L9J64v*LXu z-tcDiWj|2e!dshQx6QZxKY|Dy^dP+#*Tbnh>#-PS7**3x)8BS$!RyVF1N?v-aTobl zo9d&CsC^NQr^rhs0c5r|Y%tQytiWRCLfS>YF|-}<%d9DQTAax_ai|9tj*Wz4INm8E zvtg!1vzT1MoI}W?Smk9HI4ovIM>dgA9gRkmnQBZyl*h1~3qt{&;2SYVcAUG0SDK>< zBk{=~%1~$__as-8RC?vOxT>sYwSbs2hod{1{m@=G&%0AC8m_!#O>*K*dpX-wj^2?w znVoo|GtYfLN~tyVs!dqn7jkFib(cIF96`)Tm9xIrOknbkwtoVVb+*tOxzssM69s}wdmzq@j+CyAW z!q#x-R;L$uN^QLuT0!XtfRjh$FUm6$mqbv9cP~42QpaOuHrvR?A3*-%53I2S%E~L8 z_UaL-T}x1Bn>`Y-qTDLllmE?Kie$6vE@(8Q3e!xT%um z*e#4aHnTcfe%*3WTtS}l5sxi=Rv#@ZC6qJ|UhG$Yev-kXwyHFh>Ys~~&|G(ohJNK! z!IP^eB46xqoh+avmW;?@przgH;m6jxs#t8o-DbB zp%zr*YRPAHj1)$FX^Nv|dk`BthYBEmF>WTqSM=6r%n`cRQK&%ju5b@5t@nUuobtg= zxCdOs*WY#H%HCZD+T(h7Fp@nEy8Lb~55c&#A6GbTQsmnz41*^eYt+Zz>)hRfNd{YQ z* Date: Mon, 9 Jul 2018 15:30:14 +1000 Subject: [PATCH 38/68] Add png tests --- .../Formats/Gif/GifDecoderTests.cs | 1 - .../Formats/Png/PngDecoderTests.cs | 47 +++++++++++++++++- .../Formats/Png/PngEncoderTests.cs | 34 +++++++++++++ tests/ImageSharp.Tests/TestImages.cs | 3 ++ tests/Images/Input/Png/ratio-1x4.png | Bin 0 -> 404 bytes tests/Images/Input/Png/ratio-4x1.png | Bin 0 -> 344 bytes 6 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 tests/Images/Input/Png/ratio-1x4.png create mode 100644 tests/Images/Input/Png/ratio-4x1.png diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs index b15e8ff33..6d2a74c03 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs @@ -4,7 +4,6 @@ using System.Text; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Primitives; using Xunit; using System.IO; using SixLabors.ImageSharp.Advanced; diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index 66e4f39fd..d2672fe24 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -8,6 +8,7 @@ using System.IO; using System.Text; using SixLabors.ImageSharp.Formats.Png; +using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; @@ -18,8 +19,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png public partial class PngDecoderTests { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32; - - + + public static readonly string[] CommonTestImages = { @@ -67,6 +68,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png TestImages.Png.GrayTrns16BitInterlaced }; + public static readonly TheoryData RatioFiles = + new TheoryData + { + { TestImages.Png.Splash, 11810, 11810 , PixelResolutionUnit.PixelsPerMeter}, + { TestImages.Png.Ratio1x4, 1, 4 , PixelResolutionUnit.AspectRatio}, + { TestImages.Png.Ratio4x1, 4, 1, PixelResolutionUnit.AspectRatio } + }; + [Theory] [WithFileCollection(nameof(CommonTestImages), PixelTypes.Rgba32)] public void Decode(TestImageProvider provider) @@ -218,5 +227,39 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png Assert.Equal(expectedPixelSize, Image.Identify(stream)?.PixelType?.BitsPerPixel); } } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Decode_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new PngDecoder(); + using (Image image = decoder.Decode(Configuration.Default, stream)) + { + ImageMetaData meta = image.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Identify_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new PngDecoder(); + IImageInfo image = decoder.Identify(Configuration.Default, stream); + ImageMetaData meta = image.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } } } \ 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 540fc0716..62de45064 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -7,6 +7,7 @@ using System.Linq; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Png; +using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Quantization; @@ -61,6 +62,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png 80, 100, 120, 230 }; + public static readonly TheoryData RatioFiles = + new TheoryData + { + { TestImages.Png.Splash, 11810, 11810 , PixelResolutionUnit.PixelsPerMeter}, + { TestImages.Png.Ratio1x4, 1, 4 , PixelResolutionUnit.AspectRatio}, + { TestImages.Png.Ratio4x1, 4, 1, PixelResolutionUnit.AspectRatio } + }; + [Theory] [WithFile(TestImages.Png.Palette8Bpp, nameof(PngColorTypes), PixelTypes.Rgba32)] [WithTestPatternImages(nameof(PngColorTypes), 48, 24, PixelTypes.Rgba32)] @@ -256,5 +265,30 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png Assert.Equal(expected, data); } } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var options = new PngEncoder(); + + var testFile = TestFile.Create(imagePath); + using (Image input = testFile.CreateImage()) + { + using (var memStream = new MemoryStream()) + { + input.Save(memStream, options); + + memStream.Position = 0; + using (var output = Image.Load(memStream)) + { + ImageMetaData meta = output.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + } + } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 99057a434..9c9848d24 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -65,6 +65,9 @@ namespace SixLabors.ImageSharp.Tests public const string Banner7Adam7InterlaceMode = "Png/banner7-adam.png"; public const string Banner8Index = "Png/banner8-index.png"; + public const string Ratio1x4 = "Png/ratio-1x4.png"; + public const string Ratio4x1 = "Png/ratio-4x1.png"; + public static class Bad { // Odd chunk lengths diff --git a/tests/Images/Input/Png/ratio-1x4.png b/tests/Images/Input/Png/ratio-1x4.png new file mode 100644 index 0000000000000000000000000000000000000000..559e5261e705daf7a562a18eee445ccc35990e97 GIT binary patch literal 404 zcmV;F0c-w=P)nGg^KQwW7n2!*3?6#5{%QaA_=g+OQ^R1n-BcAPeo8I7%7X;;=;1%j1i zZ)bCl8v&97rVft|P_iC!Ccs>)Nfzav-)4vs=ljCt>^(xPQBFB!f~}2 z33c`L-70SCvR3s|4U=$oHH9TFzjO1%!~RfY+0z-VM(^3 zbZpsM^d4*^09(kX9^w*ZmI5XJmB^)Ql!H<7e6ZY) zc`+QeUEqwtD6lI*MoSDvI5{}WC480&PtuOH*-2AVaV?E<`JCD_tpv-j#9PIaBFEN! ya5NvsJwe(+v{{WEX}38N*-?K$b^NQk+{YgmGj*nOAn>;U0000d_tM6?Z=$-SxY}-ICRK&4y|1 zVwc#f!dHA1xV88oBj*}@g$RWy_hMZ-KIm-D*-?;qSET3(i^4(8Km2Jkn4dfq@Se&3 zTKj@moXkY~bFu#0PPnZ(e1e0$_)enlnWhXC=IqbUUkI-WEMadnm^fjTNZTC0CDs-P zO1_Hd{`ll}k%^K0x`I<0XS2iy+u$b!SFTK5^fGI1n`4Un+K*`hy-NEv><+L^T&{2S kcJ9aK_IoSqvM<+joQ+wPvG4a1ptl)3UHx3vIVCg!05sc)VE_OC literal 0 HcmV?d00001 From b176a0ec17b1569471b91855af70f85c5bdc91fc Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 9 Jul 2018 16:43:48 +1000 Subject: [PATCH 39/68] Add bmp and jpeg tests --- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 11 ++- .../Formats/Bmp/BmpDecoderTests.cs | 52 ++++++++++- .../Formats/Bmp/BmpEncoderTests.cs | 49 ++++++++-- .../Formats/Jpg/JpegDecoderTests.MetaData.cs | 88 +++++++++++++----- .../Formats/Jpg/JpegEncoderTests.cs | 65 +++++++++---- .../Formats/Png/PngDecoderTests.cs | 2 - tests/ImageSharp.Tests/TestImages.cs | 16 ++-- tests/Images/Input/Jpg/baseline/ratio-1x1.jpg | Bin 0 -> 34674 bytes 8 files changed, 221 insertions(+), 62 deletions(-) create mode 100644 tests/Images/Input/Jpg/baseline/ratio-1x1.jpg diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index d690a3a75..c135ab6d6 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -5,6 +5,7 @@ using System; using System.Buffers.Binary; using System.IO; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; @@ -524,13 +525,19 @@ namespace SixLabors.ImageSharp.Formats.Bmp } // Resolution is stored in PPM. - ImageMetaData meta = new ImageMetaData(); + var meta = new ImageMetaData(); + meta.ResolutionUnits = PixelResolutionUnit.PixelsPerMeter; if (this.infoHeader.XPelsPerMeter > 0 && this.infoHeader.YPelsPerMeter > 0) { - meta.ResolutionUnits = PixelResolutionUnit.PixelsPerMeter; meta.HorizontalResolution = this.infoHeader.XPelsPerMeter; meta.VerticalResolution = this.infoHeader.YPelsPerMeter; } + else + { + // Convert default metadata values to PPM. + meta.HorizontalResolution = Math.Round(UnitConverter.InchToMeter(ImageMetaData.DefaultHorizontalResolution)); + meta.VerticalResolution = Math.Round(UnitConverter.InchToMeter(ImageMetaData.DefaultVerticalResolution)); + } this.metaData = meta; diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs index b994af056..09c3d1545 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs @@ -10,17 +10,25 @@ using Xunit; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.MetaData; using static TestImages.Bmp; public class BmpDecoderTests { - public const PixelTypes CommonNonDefaultPixelTypes = - PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector; + public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector; public static readonly string[] AllBmpFiles = - { - Car, F, NegHeight, CoreHeader, V5Header, RLE, RLEInverted, Bit8, Bit8Inverted, Bit16, Bit16Inverted - }; + { + Car, F, NegHeight, CoreHeader, V5Header, RLE, RLEInverted, Bit8, Bit8Inverted, Bit16, Bit16Inverted + }; + + public static readonly TheoryData RatioFiles = + new TheoryData + { + { TestImages.Bmp.Car, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter }, + { TestImages.Bmp.V5Header, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter }, + { TestImages.Bmp.RLE, 2835, 2835, PixelResolutionUnit.PixelsPerMeter } + }; [Theory] [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Rgba32)] @@ -64,5 +72,39 @@ namespace SixLabors.ImageSharp.Tests Assert.Equal(expectedPixelSize, Image.Identify(stream)?.PixelType?.BitsPerPixel); } } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Decode_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new BmpDecoder(); + using (Image image = decoder.Decode(Configuration.Default, stream)) + { + ImageMetaData meta = image.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Identify_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new BmpDecoder(); + IImageInfo image = decoder.Identify(Configuration.Default, stream); + ImageMetaData meta = image.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs index 8d29536b2..d887d23ad 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs @@ -1,7 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System.IO; using SixLabors.ImageSharp.Formats.Bmp; +using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using Xunit; @@ -12,11 +14,19 @@ namespace SixLabors.ImageSharp.Tests public class BmpEncoderTests : FileTestBase { public static readonly TheoryData BitsPerPixel = - new TheoryData - { - BmpBitsPerPixel.Pixel24, - BmpBitsPerPixel.Pixel32 - }; + new TheoryData + { + BmpBitsPerPixel.Pixel24, + BmpBitsPerPixel.Pixel32 + }; + + public static readonly TheoryData RatioFiles = + new TheoryData + { + { TestImages.Bmp.Car, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter }, + { TestImages.Bmp.V5Header, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter }, + { TestImages.Bmp.RLE, 2835, 2835, PixelResolutionUnit.PixelsPerMeter } + }; public BmpEncoderTests(ITestOutputHelper output) { @@ -25,6 +35,31 @@ namespace SixLabors.ImageSharp.Tests private ITestOutputHelper Output { get; } + [Theory] + [MemberData(nameof(RatioFiles))] + public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var options = new BmpEncoder(); + + var testFile = TestFile.Create(imagePath); + using (Image input = testFile.CreateImage()) + { + using (var memStream = new MemoryStream()) + { + input.Save(memStream, options); + + memStream.Position = 0; + using (var output = Image.Load(memStream)) + { + ImageMetaData meta = output.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + } + } + [Theory] [WithTestPatternImages(nameof(BitsPerPixel), 24, 24, PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.Rgb24)] public void Encode_IsNotBoundToSinglePixelType(TestImageProvider provider, BmpBitsPerPixel bitsPerPixel) @@ -44,10 +79,10 @@ namespace SixLabors.ImageSharp.Tests { TestBmpEncoderCore(provider, bitsPerPixel); } - + private static void TestBmpEncoderCore(TestImageProvider provider, BmpBitsPerPixel bitsPerPixel) where TPixel : struct, IPixel - { + { using (Image image = provider.GetImage()) { // there is no alpha in bmp! diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs index 10b098d92..f217f0df1 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs @@ -15,30 +15,39 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Formats.Jpeg; + using SixLabors.ImageSharp.MetaData; public partial class JpegDecoderTests { // TODO: A JPEGsnoop & metadata expert should review if the Exif/Icc expectations are correct. // I'm seeing several entries with Exif-related names in images where we do not decode an exif profile. (- Anton) public static readonly TheoryData MetaDataTestData = - new TheoryData - { - { false, TestImages.Jpeg.Progressive.Progress, 24, false, false }, - { false, TestImages.Jpeg.Progressive.Fb, 24, false, true }, - { false, TestImages.Jpeg.Baseline.Cmyk, 32, false, true }, - { false, TestImages.Jpeg.Baseline.Ycck, 32, true, true }, - { false, TestImages.Jpeg.Baseline.Jpeg400, 8, false, false }, - { false, TestImages.Jpeg.Baseline.Snake, 24, true, true }, - { false, TestImages.Jpeg.Baseline.Jpeg420Exif, 24, true, false }, - - { true, TestImages.Jpeg.Progressive.Progress, 24, false, false }, - { true, TestImages.Jpeg.Progressive.Fb, 24, false, true }, - { true, TestImages.Jpeg.Baseline.Cmyk, 32, false, true }, - { true, TestImages.Jpeg.Baseline.Ycck, 32, true, true }, - { true, TestImages.Jpeg.Baseline.Jpeg400, 8, false, false }, - { true, TestImages.Jpeg.Baseline.Snake, 24, true, true }, - { true, TestImages.Jpeg.Baseline.Jpeg420Exif, 24, true, false }, - }; + new TheoryData + { + { false, TestImages.Jpeg.Progressive.Progress, 24, false, false }, + { false, TestImages.Jpeg.Progressive.Fb, 24, false, true }, + { false, TestImages.Jpeg.Baseline.Cmyk, 32, false, true }, + { false, TestImages.Jpeg.Baseline.Ycck, 32, true, true }, + { false, TestImages.Jpeg.Baseline.Jpeg400, 8, false, false }, + { false, TestImages.Jpeg.Baseline.Snake, 24, true, true }, + { false, TestImages.Jpeg.Baseline.Jpeg420Exif, 24, true, false }, + + { true, TestImages.Jpeg.Progressive.Progress, 24, false, false }, + { true, TestImages.Jpeg.Progressive.Fb, 24, false, true }, + { true, TestImages.Jpeg.Baseline.Cmyk, 32, false, true }, + { true, TestImages.Jpeg.Baseline.Ycck, 32, true, true }, + { true, TestImages.Jpeg.Baseline.Jpeg400, 8, false, false }, + { true, TestImages.Jpeg.Baseline.Snake, 24, true, true }, + { true, TestImages.Jpeg.Baseline.Jpeg420Exif, 24, true, false }, + }; + + public static readonly TheoryData RatioFiles = + new TheoryData + { + { TestImages.Jpeg.Baseline.Ratio1x1, 1, 1 , PixelResolutionUnit.AspectRatio}, + { TestImages.Jpeg.Baseline.Snake, 300, 300 , PixelResolutionUnit.PixelsPerInch}, + { TestImages.Jpeg.Baseline.GammaDalaiLamaGray, 72, 72, PixelResolutionUnit.PixelsPerInch } + }; [Theory] [MemberData(nameof(MetaDataTestData))] @@ -76,14 +85,49 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg iccProfilePresent); } + [Theory] + [MemberData(nameof(RatioFiles))] + public void Decode_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new JpegDecoder(); + using (Image image = decoder.Decode(Configuration.Default, stream)) + { + ImageMetaData meta = image.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Identify_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var testFile = TestFile.Create(imagePath); + using (var stream = new MemoryStream(testFile.Bytes, false)) + { + var decoder = new JpegDecoder(); + IImageInfo image = decoder.Identify(Configuration.Default, stream); + ImageMetaData meta = image.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + private static void TestImageInfo(string imagePath, IImageDecoder decoder, bool useIdentify, Action test) { var testFile = TestFile.Create(imagePath); using (var stream = new MemoryStream(testFile.Bytes, false)) { IImageInfo imageInfo = useIdentify - ? ((IImageInfoDetector)decoder).Identify(Configuration.Default, stream) - : decoder.Decode(Configuration.Default, stream); + ? ((IImageInfoDetector)decoder).Identify(Configuration.Default, stream) + : decoder.Decode(Configuration.Default, stream); + test(imageInfo); } } @@ -141,7 +185,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } }); } - + [Theory] [InlineData(false)] [InlineData(true)] @@ -166,7 +210,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } } } - + [Theory] [InlineData(false)] [InlineData(true)] diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs index 911812ebb..a31ae37b7 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs @@ -3,6 +3,7 @@ using System.IO; using SixLabors.ImageSharp.Formats.Jpeg; +using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; @@ -14,16 +15,24 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg public class JpegEncoderTests { public static readonly TheoryData BitsPerPixel_Quality = - new TheoryData - { - { JpegSubsample.Ratio420, 40 }, - { JpegSubsample.Ratio420, 60 }, - { JpegSubsample.Ratio420, 100 }, + new TheoryData + { + { JpegSubsample.Ratio420, 40 }, + { JpegSubsample.Ratio420, 60 }, + { JpegSubsample.Ratio420, 100 }, - { JpegSubsample.Ratio444, 40 }, - { JpegSubsample.Ratio444, 60 }, - { JpegSubsample.Ratio444, 100 }, - }; + { JpegSubsample.Ratio444, 40 }, + { JpegSubsample.Ratio444, 60 }, + { JpegSubsample.Ratio444, 100 }, + }; + + public static readonly TheoryData RatioFiles = + new TheoryData + { + { TestImages.Jpeg.Baseline.Ratio1x1, 1, 1 , PixelResolutionUnit.AspectRatio}, + { TestImages.Jpeg.Baseline.Snake, 300, 300 , PixelResolutionUnit.PixelsPerInch}, + { TestImages.Jpeg.Baseline.GammaDalaiLamaGray, 72, 72, PixelResolutionUnit.PixelsPerInch } + }; [Theory] [WithFile(TestImages.Png.CalliphoraPartial, nameof(BitsPerPixel_Quality), PixelTypes.Rgba32)] @@ -82,10 +91,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg image.Mutate(c => c.MakeOpaque()); var encoder = new JpegEncoder() - { - Subsample = subsample, - Quality = quality - }; + { + Subsample = subsample, + Quality = quality + }; string info = $"{subsample}-Q{quality}"; ImageComparer comparer = GetComparer(quality, subsample); @@ -93,7 +102,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg image.VerifyEncoder(provider, "jpeg", info, encoder, comparer, referenceImageExtension: "png"); } } - [Theory] [InlineData(false)] @@ -104,7 +112,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { IgnoreMetadata = ignoreMetaData }; - + using (Image input = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage()) { using (var memStream = new MemoryStream()) @@ -126,7 +134,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } } } - + [Fact] public void Quality_0_And_1_Are_Identical() { @@ -172,5 +180,30 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Assert.NotEqual(memStream0.ToArray(), memStream1.ToArray()); } } + + [Theory] + [MemberData(nameof(RatioFiles))] + public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) + { + var options = new JpegEncoder(); + + var testFile = TestFile.Create(imagePath); + using (Image input = testFile.CreateImage()) + { + using (var memStream = new MemoryStream()) + { + input.Save(memStream, options); + + memStream.Position = 0; + using (var output = Image.Load(memStream)) + { + ImageMetaData meta = output.MetaData; + Assert.Equal(xResolution, meta.HorizontalResolution); + Assert.Equal(yResolution, meta.VerticalResolution); + Assert.Equal(resolutionUnit, meta.ResolutionUnits); + } + } + } + } } } \ 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 d2672fe24..54f3e397c 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -20,8 +20,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32; - - public static readonly string[] CommonTestImages = { TestImages.Png.Splash, diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 9c9848d24..142b923ed 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -82,7 +82,7 @@ namespace SixLabors.ImageSharp.Tests Powerpoint, SplashInterlaced, Interlaced, Filter0, Filter1, Filter2, Filter3, Filter4, FilterVar, VimImage1, VimImage2, VersioningImage1, - VersioningImage2 + VersioningImage2, Ratio4x1, Ratio1x4 }; } @@ -127,13 +127,14 @@ namespace SixLabors.ImageSharp.Tests public const string Jpeg420Small = "Jpg/baseline/jpeg420small.jpg"; public const string Testorig420 = "Jpg/baseline/testorig.jpg"; public const string MultiScanBaselineCMYK = "Jpg/baseline/MultiScanBaselineCMYK.jpg"; + public const string Ratio1x1 = "Jpg/baseline/ratio-1x1.jpg"; public static readonly string[] All = - { - Cmyk, Ycck, Exif, Floorplan, - Calliphora, Turtle, GammaDalaiLamaGray, - Hiyamugi, Jpeg400, Jpeg420Exif, Jpeg444, - }; + { + Cmyk, Ycck, Exif, Floorplan, + Calliphora, Turtle, GammaDalaiLamaGray, + Hiyamugi, Jpeg400, Jpeg420Exif, Jpeg444, Ratio1x1 + }; } public static class Issues @@ -182,8 +183,7 @@ namespace SixLabors.ImageSharp.Tests public const string Ratio4x1 = "Gif/base_4x1.gif"; public const string Ratio1x4 = "Gif/base_1x4.gif"; - - public class Issues + public static class Issues { public const string BadAppExtLength = "Gif/issues/issue405_badappextlength252.gif"; public const string BadAppExtLength_2 = "Gif/issues/issue405_badappextlength252-2.gif"; diff --git a/tests/Images/Input/Jpg/baseline/ratio-1x1.jpg b/tests/Images/Input/Jpg/baseline/ratio-1x1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0162ac9aedba988372e8bdf055c6862e47c3db3e GIT binary patch literal 34674 zcmeFYd03j~);CI;rb#o_IAn0z)m=3jH3sJab{matqEdrMoD)qjYScL43{BHC&eW|& zQISR?C@6*~A`&%&L!u~A#0kNwRYb)Za6%8+*SWrPuJ^p}KKoqX_kP#;W8W&m{X9Gm ztb5&S{nl@-wLh}|2jHt~SAVz)IB);}IH33e?DGIu00%$&G(J5ZRE*ER`25p2^2Ha2 zzWDOU(W74;`SQ!7$4?zUdhFz}FTXsYbmHWxuf9_H>ge&)%BR0lRy_ae(?t$^dgsB< zk0{>w)v+&+DQ5paj{VmFr6UIq9KL_>fDYg@r2_|*4(zuBG!-B6)8_*GU*qtRFTVWz z(1FhmDh|7SrT7*H4<0yl=-`)!4t;U(OU2jv?BM5zzEC=RtuN^6h8TH~p%> z?)yB$82$6#S6`}?za5y`9|Ig$T>LYogGvA}V65nW+~VI){w;xjOW@xU__qZ9 zErEYa;Gat1GaG@t+}4a!8;IOnnn-9W&Q_68g1o57hRgs1#^SxYQEq#?EOaWNsLZn1r20prR|oO}OwpewO9=B2tS578i>_<`U|M<6Ca_t#7~Nh(-i6yaKN#WjAWrZOF)2 zHWRL=M~)THT;CHA_BLtcCkU4K%yd4?X)LfLf0gq~yR<9b_%0_`2+rWZtaPu5mL|<6 zPL3a{wEw5F{r}g&gQwkLaA|(iaGGWRAp~a-v zj+96EkuDJI5V21l_vCvM!Wd>snlD*rO+9UUsM}W0QmIUuL8h#{F6MQ;nWvkdyHLfQ zogbsYwTEhS0a@*?p7T#4amhENW5L&A&&QT1_nK9Qnsegyf`m?0vwY>fkh+z}H^=QT z{`}(3t8I+9lv;>;54j~-UvF{P&tJna2IQ`!7?X;>_U|%F#GP6lz(`Y!N!=PA0jgiY zq>vangQGO%tEYy@Z7)Il0KM>`CB{-~)6y|pLW@(W%kfhoZY9Lg)r#{Ovt=@i)!sPn zcttT$5|oy<;tc4aT9-62X#s8U0*_VfkIVjyG=^0~9}RLY*@qr2>ApWohba{I0--nv zOA7ARakxuIm5O)yM2?tBqZ!u1uoZJ7H_xehkwVKO#;8uJy+AW%vtD33%lS!#zu#|3 zQSnup!2>Us-NC`(#nnSENf`ueu^6WHHmyug4+d7uvbJX4|N}KEH*WBY*T zsW#G)v)=hj;rWvw&&2Lh0(K+`2`*4RAvNSX3m6RM3Ugtx)`6fH!;``E22Sm( z)@(E%ell0a`8zRZY%Iw8QtZMq{(0)I8ib_Du+3$*G~%dKvDnp?5+ZG!&m5(3Bn-0- z?Ky%T*c-+M|H$UXn9SP}kXI4@PJTP|H4|?1Om}M>%!9>}-|bR4j=Y=6BCoB&^{O|W z4JI{Jk9%4vWs|$xe7S2PjlXE!D`ysPBKWE>Kd1`lAA-www72&C{jyu>ecY8Q-h$Jp zZDf*Z=xD4LsVOJ5pw6xkeDq!hX&-RCkK0@aSDVX51b;6yH8dd2xI3BE^v(I7e6w?M zX1Btv4XgKMcX(%4z6iDep2ny&CrX^A`B+7{eWQMUr;0^ zQ*Y+A*nL3xCU+|MPdT}c>zve=n;z}(JVr|yS$CEODa=~;=qk7@>cdko5q*Tz0zLrTKDn`UT(F07G^p1^HKTbtRn^6F;EIpS&7K7cAJ zS~s7X;!Mjzgq@7pL<%JoZxX1Zb4kq)C#LOsHa^g*)SlTU7H;m!SIQB|?#R8y7iF~$ z@_OmkT6CN->Qq7x=Vv}8q%`3IgK|hM%t8Z(Di6Cx<4=$u*nUALE`=X<9WQq6rreru zdKyC|ldyzP8ZwQNUW7keCU&1RNv;@SB46L*YTmhkM(XYfZgl^#o z$%n+3fhemRcdIGk9EBHc$WD|thQ)aFD+g#=tpk#^Zv6`@{@-=V>+L7Qpr^6T86y4; z^JJ%=8SB<4nRgeqCRf$qLcq377!oB;eeI_(uh!v%l{?-7TxeoO+zDtVeRGS0z%IFi zXGu-lU&mHG}ijIkKAOalYd+#n8b&6w$nWl5{CU8w)fB{ z>|M|qD#?iw# z_j{H~%2hq734@8MCQ-IKyNlppPpW``43PVQ=qCh=rtYJQ8 zh!pg;7)5h&=7uB%j3|4uq_%iZt3$S_)l=028{O56BvgT*sQAL}g^VrvJ>=a{ODl7- zi!q~Uc~WU8KGo0Kp00|)U33R(%F7H32_Z>kG+eMt|HfkJA}fRWl)73ALn=(52gk*Q zwRi06fxWlzM)$lBZzdN-{-8RACdVeM;(wleIBMs)K|TX7aOiKg zPhh`++frX9!A65Bnx9tJn;Qj`j#Yy1hHRJJ=~$cyLt-J|Q@3wAW|fNIUUQs|Ol_|3Eo1OE93GB)PDZ|iG^%ggW@Nx+S+6(UaGrMP1F zEm@|!5BNsOY@Klw{alo|JxhL4E=rID^bTG&o|+yb_RWmVXM_;I=ZbzEOA4m0*oME@ zaLpygBLoHMuB0WXMzRlQ)sL}9nkBU*L2j?HuXni_Hc7(w0c&Mi>cX-d@zdAaR}CY% z>Q!6pQ*Dp*54opoa*MD^C{A0%N3{Fm-HTI4X3uc2Eiw_f`jqU75rJrcTeZ9x2; z7(7wy2N?y|MAHlqShAgUmhg}5dCXdV1v3|EPaJUv^PR=8)y+*O<)eiK1$iZT@j#%C zct^HSQW(Lfgi@LbiHb;O6^oS=zQ4nG8kX5h*&2s=%bf2-WB!!Yk4M~2V;QX%&JQ=+ z>E;7;OCu1N=b=e^J>H zuC^dj7eI9xS^m2zo>5aMv6=Sq;jSb~=o%q8_p#J^abYXB(t94Y{(5QYgd2MwaI%vL z>3Ep!kt#}GWBNicwdQOsW!R4mu0eN@5v9gWU4f##KbHym8(nCdP3JbxhxLrV-k!_y z)Nx3hR36pb75)Ket^NJK%c}m9>mF=pL6u=pC8cTLU)C;(JBC2{VmFE1qpD=|$r&wV zD4PzO*otKh%awke62JSHt=!^X1WI(vugB`LHc^ zi@B>IDP^vQO$%*%dx1njpmI-mN0`(}AjtUYafk1Q*TaW}h*vwgVSBzVQ0+HqE-W_C zp7r~x_MpM!6Y5a)wqvS0yz#BI7i}8+{Z6A-6B7}8_;1VZ!Etv&W%t(U#9RD2{M+WK zVttuMmerY=lOONPs>V{S+1-H0LrD(nhp@2y;qrzZY0@))C}&bG`DAMST^WRR=OeizF36K!|Iah2C@z7#)Y zt!o+*FnVR%bmu4ML|d2NsS;8Q{3td^_Ah8ZS*wmY4b z2D7J`a22S1!YUgmI^BpfT|D-?NYDkHZ*1`-qpV4>d|Og&Q2Q>KY41w`_o$#Q)3yA(bVa;S_szQl z^=Ex83j!qbvXzycOxp+^tKb?-G~Fx9DH)kL1Vl;-a=)n7L+=?}jd{Qi3G+ zs{cY;=V3?_IQbRYi`Z9XdstfFy*57n*V(uztpQX^cXC6jp%ibf)jx~>o`sJ)}3b1CaZ_WH$&jQ3JCQHKw)S|+2Qv>P~$6mSFG&o@5U za@l+=N1vVHQ0v>3&vEWkKkV!W5XF_{ZnXU{M)NMWI4_d*-e^wPTw8K|A|TY$DzMzMvGHl z+WIV?|6;Vn4inwqs~pH>OMS2Hwz)>z&+5zhAds@Md1BLQ(=Ny_G%_$OBV=nWXY|im zMTqc6?G{fGqTQz{DnTx5)=|x`^D^VZ5}N(-fgq#dg=y>tp=g~_J^i*g5Rv+|bJ7AY zASUu0lWyzf?=R?|qL_r5!DH+UbtMS=(gk7HWZCYj23HAq?dZIzhgBQQqM62Dp!oN- zXmpgAt&DUM(CR!HJ|Mn0iYi)VAnPj4x14KO&ZY0d)FEMWJpFJH4-y&J3BpxQb1;Dzf89P3aj3d1 z6f03UMn9yLPS)FfK;;BR+;7(+Nv+7*kk#y16N|?A9go!Qax-RkPp5_7gU7Ba!mFCVC2#> zyekEK-hj}GF8*pWo6!A0z~2rotX<=(C)@Wd?!bcx`+%q9UoC`n($xjGYC*;K9UslT z^_RFoC&_f()e;)aWgl=+*ALwQ_l>tovT!4YQC-nVSuU8^a#WscQMvW@gU9XRvwo3r zq)_s6$CTiJpG~Agx90c}#iW(AExG#jL0YQ*)vnUoAZYs=s#g5vNN6Z#+M`{Uk8WuD z&T=Bj;v`{C7E0_ZJwMMXLk0YvG1k<}?i+k**fSUtITJu$_HBzME#Ny5i78(dVdhV4 zx9PB)ZLnMSvRWF?1h3UP#$fSJvwvQYx7vaUvf8=gtCK?}&U{i<(nW8)1RjtC&ON&n z*?o?AS+5uw4{0bplF@1?xmbdY@v~2YMvle@_Y75j|5Z^owRd?bGuH*(s4KK(cbrKM z0jl%L+w}9DmoLzxkRKMLZG!S4asBhrx;_E!ap;8h<2WZ+*SfCen>N|dVlgph**FrG z@k+#EGn4Rq1rg(z`t`>n_E&?lI`&e>NJ5|ib7b62cRj*o9SewJJd|{_clWiqnW$Ne zXL8vpJeuP$EZ`UCtmh|MMki`_h)i3E3+;V*8#BgKn{QCG)d44@6>YD{yxs-0v-1$? zq||=kT5|YJW>PH8g>8U!{_cZV@WwBYYe%=}z5ciUaJGOj>k41$nsjYOVE1D2bhLii zFqK~yCsFq3m5{Q*rv>IH&G}g&81q%>yG24|`XnL{%s12i5{LTI&JJ88n2dBwa%Lyx zyyCdRxGL^03Jcus=nT9(`YV4i{-b6apHhqSuTH|qnse^*UhSDXxksQ2^uy(uFB>b( z+(yQ1E%Vx=`qWO4fjhIsfp=}5?BS;tc6S;$J>IP!!tB0IBd7I$IV-syl)a!pwPXd97TVvocvE)QHj!+w0FJhV(nd zIcs_NGkiOMY%O2}`cy%VXyS^k&j8O;crV=kx=lWmPyVqD(%3^$L}FoZAOu8(sL0RF zQEx>bXBy*8Plf7GwuXYA_ch15Oh#v^9ZexyPU*MCv%CCk0eYwZ1^^sCQ;WOSA+mCf z%br1!^bI@ef*yvp$ry3FmetckI;acs;?U4MAkgT?o;Ex#*KfD9q`>3uUn}rn3(}h>JIz^oYc>+#jd;Ho?{mOVB1%DR*gEZC!x7UPQNxQhdgGdt$}q&uAD?Mio{4O~Z$gh)-!?=VMK;Nj#u zm+RVNjxcRKCfn|GS>QO_e!MMU-lrU7IKS^-egL~0nEyV={UWxp+Eb0)=a+=uP^VQ`(2;1nOa8O~vk z(;ZXHp*!a7-(kzbbJR_S`p#T01n&fuO4l%FJ!4#-Qy&cpw1?{^wNdU zET!*d*>rl?Y{qO)AJ9O-FNuow0f&^=(@9ljs;qNvc9+^`;VDu>1_`CKls0+v zr0F@ddQ4vc*=s9$>2Oqo6eXOnSzW5})5>abAZqIM zqtw^8YVVGOUK$GG66}+OrF~MyFK>Boya*kwO1r~V2dM-9T$}&rkDj_-7(QAa;m>eY zfeID2*LgYC7W1R@i(K{?PZ&8FpCX@zQX?_5BrVnP@^J-7h)Ll3nMaah@90<$+BwG> zxd;VGmGp(_J#E9wV3Dk-vw{b#A3AInmK4Auf!|>Wci0jV-%Rdn1x#rjrlZmnnw&aL zo3*}<;*JIF^~+q}(n2*`n}O-Q)=3~yFL@w*a!FM)#ZhY8E z?yQJlgL|AJ)Jxp+y`^XX+e!s-}^)VPFFvs&kxnw|2A1x)kCX`zo^VRq%LQ z*Ba-_*}>#w3DLCZ-GH?9c#><45sj|M}Zg_>{dP}ED% zKM_ahzMIZNzBDoNv_r8W{>XM?&6F^-*&ho*-x#DuU09!$&xdzOib8?z6FbXrp*Vb@ z4k3FbpT5x&gP$e&sm2XQS5s!W7B1Aoux*p)QjBTphe?8Eu-3pX-d%;%ed>`cj3}#c?Ui*Q9OAppNFCvU=(Le-%R$ORvH2uK-_A) zmhY*nN6q?8FU`V&&X=Lj8!^EBSGo@In|dk9Kv(Otn_WGvQjr_yVk#L>)Y*z zg#u#u{p@3|gt`kojChk~^p}M2E^wA^IGV-|kR49Skj;!AgC#2XxcehZd#W4=dLM9E zQ|WB>@4aSVEQ*px>~V}+oYqG3m=5}or#TCL0%lJv%p$^Xv?i1TWbG`)@%91R^M%)r z6fcne+=BJhFFPwTQ++hImj?yh68aJp(Lq}Br6dqCE-1ndMLsA1^KI!p&65i!g-hJ> zjo}9ZdH|p4e*#$x+56@_0YCru*pu&4kwbR%Rg?F|z5z~y&1B>-^WrPXwcPmVcj1`n58?%&sVbDjZZuHS58ELOZ zsI9Jjy4QO1sqrYyG0IgzE1d8^mFMqN&{v9M$c-n5x4p75q zOA^DHYh$-K*-kar<4|U1(G>8}XZm76H|`)Wb&T2^{|Fn6x0R?DUf$tI2x6%73gPRE z>EobppWa3rb~prit>W$)1sl8`ks3SS92S!6`lZr`^qOSK!)K!HyJgnWgoHsa;-RYp<8IGep1IZ>SF?P-bq4-m(bXDB!Y{uhZ-%?C z7cINEtj@T=Kv})tF_Dsh^~}V;*mu|7FW(C9GZiWvc|@=;@hu3tDCR0{kY=Jl-@88R z)xGcsILPTaC6EI~K7N+v@{3pi@s*W>V`j?R)ciW~*17-edaNTNg6! zZN<2-Ngfd;W(6qKLXK0^0(Sw{mu!1=DT(Hid0_6WZ3xLBl+O0=%UuQBg#P9K6x4tE z@6=OIPm_}t_XSbSh z+}`v7padFT_#)o__9o>YiIUDG51a=aaCbe0MFu?r!{AC`OSC0a-xsPx52z z9i1Qjbx?Bggt}`tSK>lW7)kI9d;h*AI)T7%zMxoORIbwHKS`z$ef6n@l|dWmZ+oVV zZV*aa0!fCebc}K@6S!79pR>`0M;50V`PFOO&B{Cg8zJZv2VD!aid@795ic8p%q(Bl z{B=A{u`6SfcfR&)p5z`E)Jb$b1aNuf*+RptaNCX;dFMA89nA?F*x4|W?z&fOI@ir1!@&k`OTu3Z z$qB`7q+vJ0gDP8W`;%bQhTgnq998c(^xlPai0YjQa_7ugD-Fhe@;pk*{itxnr@Y|a zHcUW`IHqxT{wb-WUkrE7u8EL|OgFcO&1E6eITtcsAxsi{ex*{qOrPCuvD`?KStnP^ zH`n@qzu)OKHP;x>RgJYXYht(uFsYeg+2MWaPdzKpt{OPh%UlI{?pnYI;SR<9S& zqUe^k|CRb#m?k~xAi;<7$|1&sODfk3%yPIa2Eqp%8hkL*mpUv?b)VuG#jaN_wy<;I zT3#yCqnK&e?*3sU#*iisAU^Gn#q-9mTZ0c+dsM8*zI;3qcPv+997m@ z`gXhN$D!6*9;895(ifK5{9>a!p{Ur*{8eJQZ~>VyYrXA~_@Xzs;joXz(nhGmkK=x0 zt&+1_v}q3b2f{GYTK;~AsX%0F;$e`I1fQ2NJAC_s)PR(tJ3rQV)y?u7(#y+h3TFus zP-dcB%{E!o6T!6(Iz0Itce}8$1`ffsHHhIcTNg;7d)e;u=NrjnzI2;HEG&tateL{1 z>!v+=(lT1)-!Z^>fx0;F-EvUGv69=qdwx|pF?9oqFwgETGIbz%a7PFW>X0#IvnupK^sF@Z)b{oeJs4NKvf@YmpGcM2-(C{@)Fs_-xoz;hM8*ry}D2Pi6 zQhi67Wkd*?CnhER$*vaoQvEyZrbdO z1G4~PQ>Y8PF&KAVPI!jTD+s_RNyfC4lP{*FMz7231($J;HC^!Ec8j=2c*64qV5B3%v{8~E!qs%2poj2{V!}3^Mh4n%vO|7v)~7; zpY$SpACM)-dE8ClmGzQdeG||@;I!$pp(d-gly#nUKM3_UQc$#KId^9p{pTY7D9xX| zXC9=8x_3w|`+&_Q`b%twKuy1fqiqxCUcXh4Vhr(0+v>(16A@96oMP{(I6o01I$>R^ z9LR#K(tY$eJ0~{Ok6{uylA1m6l!alnaL@P0CHjjk8fp*0%OxO+a}s;yJGfRTjkg#?;p{W(p>4(qMOo2J6-V ziHz*NenM36ifaR)`EPzlLBeGPd~!@=%PBWP3gXftzlQ`aHtqtq{B=${Pew@a8EuV(o3AGywB<$=CptQRxDa+MuxrL$Wi9Qe!%)G0w7DmlQ43?JA>Q`W8E!=UrHz{F zjKX=@;% zpgRtk&B<50=Z3WE^Rm?>nw;o3JFcreY!M{RNR$v6nw$H8mVC?ZyVRmt52vX4{soAe z(lpW4y#)O8#(21yM^eK!hx4Sv0Wj|U&svC1G9N@39}5k!IWPT_OO54&)ygE}StYqn zD!Ucfb?jOi<{bV=0vBfP$n_9?wM(iZSdilFRBjKMe3aYGb$;U!Huj`-LA75%eI5u? zy#r_G4~s%EV`O$$8aYR`tya#EoPY={h0eylZ`#Yk$A{L8S5bc^LSE3p{PsOsz!}Uh z?q=PU2q9wLE1q`3*+lB;=@b(!*%{Vj78>EtDR6VAqQd%jVRB^HsoGNJ5P7%FC3<-) z#v{hHiXP^36YP!dd1({B%Xlt$DaFj|d##0aao16OA4PR7!Qa251hS$)%F!uH+?i?k zFA#o4qSGx_lr?#TmzS*M!S#@`*Z-&pX!mO$wlakQfjr$_b1qC#P6q@k5K?K6wJ7qc z?ZcrH@I^7M0v6rTTwYqbv)iAUt-LL>UY9I!dZD6Y!hVx(yMxa?MuvdloF=PplvGon z6@=OqNzfxcWr3J=h(&6k{x5y5^$D!mK$7kU`X2Nh5#7^z`G@Hw!Hdg zOw;D0Sj@*h3koUn+(neQ_r`}#FOO4D3NDiiyr`(`0)6}FL)9KDEFc`(smQ(MG&fvi z8oaxkuW$|)9FBG0KvKF`kt=b0jIDZGd<*?Bt>ZH zyFPQ`$0a$pCNi5{y(C8K@NVet=%ZIP4Dz#v?6ZIH#(@nvlp%&4=5kQ-w-UtA=z$9!!0FZle?k>jG5zh zeo8R?-IKK6woeUY38-<}ZeveHjH`IZouO(JMrNJw62F^jNJ1D8rKI$=bm!~>KW>*}!0OAW$XN85-mui4;S&&~3JICy@U>>WjlJ;fNO{v9-)??pR1@Xh z^wOTWs^I~JQ{A?9;&uo)@WEr(UUv>`EQTd)79p#sfxS&rCCIrnLUEvjj*gDTPZ3c{ zO3y96PfHsBXxDxGkEZ5-!Ry0kJO)?H{j5xHa-*v{-@c~C=<7*7Oev}n2%!{3iG?G3 zDeM#_^_dmXOTr>W(=L|!(IRz74Pw1?DRNG+YN~!2h}24fg7mH~QgEuT99KprJYyHd zL6ylp-w&)t+?fpympiL#bu`VA>0zA=SM&BH7OUNPYB1S~w-~erKLDq~kV}3PL-fikpxOL+5 z-yh!Ji2NXYwJbwh+de6ujFGjl)s`UIPtc=leGQQx7G6+y>g$$!lWl|8d}FW9^u2pc z`SmZ)bu4c*U{cys<2LPT7iWWFTT0l{)3rj1>&ori)queUIo7&7KM zLRNykt-iAb{w@o45&g<5Z$^oGnp2tFu1VN?Qr&z({fo2P`vA)s^G)^uDCAhOZYFu% zh+rQqIsv`?$L#!>3hjd@_gqKU=!o%QkG;87gtyfd+paoU@O4qn48th^Ig=Ep$P~%r z+M#kE@3)*4bDkN7cx!rU3}b{ehB}$;lv_uiZbTCsE7t2+YXn{4*ewzzwQ<% zTPN9al-J|>^Zy86sfYXm>D3bP%eJ*ESC{xkiW-uc<+CaQ`+#cI%i(rG_iJ@AFOjJ9 z$NV)}DyX*={In?kQLEt8so*s+N2B~}?$z_XZGmYy?x#N0jH_^zl(dwT=GIO=Y5FI7 z_6wUqzv*<2Jd?8Q(zn?E{I=hFLIyF75v`jUizYD$c)~VA+G8wNrK%TOfA2H`r~k z#Zo41q9wY{b_oWA!4#wdBH%Fl?5^Ld)r38Dr~1DinF4KosNeCKkKlJin`bz*wLI)MRziD zHSZeG(NPI|aq{&JG;zVfkwxvrojQMsYDfZamF&t$1XL`KP=&7?@gJ&qQFO}rH8+D~ zHI5svh-U}UatCVt>LHtQhb*ph>{9ost%_`mblQkI6=XZIuGTT z-2D^%_i>1QQaov@NK)i3pdmXZ_-?d3x|DAbj%!KM<0GS%STlEccxxuodJ2oNHJGx- zrWZduP$Jekrk_rj@rR+OHIig;qSI-tm>Ltm^Ke`4o>^C2^nip+V?%7cu3pWp2%s_I zH5sJw$tnNz`s`@EkfJuEO$I_wPcLnj5|o~iG6=4g2Tt()xvhhOByPNzM+#OyI&2;| z?YQkjXDit!#1o5&Lw6q^udp6-iHHHYeptJ=4>&tH+*bGf*U6SY zzA4K>hAPlU9j}K&1$BSaX*HSO%6IWDN?*qtw9haYi&_P0_Q{87w*$(|_{q zR$}XN({>N?m5*{qPm-2JpUJScRCZw}cSi-1+|@}!=&4_jxn&F0eI!Rdn2SQ@~WSGe{LSz^8PNtCP(f*Jqb~kJ)_Qk+3!{uBL9m> zfUSS9Q+PR?BbFS`2vQ`#?hY%7jdpd@2>4OLQzRc5X^@3K3+!1PaLVM}uW{Pq8OXZ@F3?q4`SO1-~mMOfAhGL4Jv@$T%8si$z!`fj}$!qZF| zw-?s$X9n|pHD9)jBqf&VGL+s99og+NdOO?rYRC{5RR1za0UaHdTo7M$f+kAZ+^DNL zH_A(5){-M@vOW;wBU=t1JguW=$f*_dFg(_$HF^1C87U5l_%}xPS{^pr5PQ#9_yt7I z7j)ReomgbgS{T?m!??qJGk)f-BSQVoT9(x@e-A~o5&|9h=;uE6%us^Qa9RD%*L>hh z)8JaujM@$9kW;+E&2^l zNu~2QQCb=waB6t&Uy$ghQ%IU^3R-3~+0IEcq`7Arh6R>jT@?&%&*(J6)qPFTXJjU! z8ToUUL;d9PXK{4_gBJs&MYewImk$W~MN&__5K>@jAUQ9(Y1^YZybSzt?E~FqdszR2 zs1v2$Oy;>}ZrnfKuMx)Q(8XNkgSK<1x8&+n7?1fK6Y6i`dDkii<(?VgP&uLPc8?GU zsy`mxQM_suQXe@+3e+uKLP%?2Ni&vn(?BInpDz}vFTnMJjC?mR~9gy@WJ)$D4F8@F)=U0gQh=qU^02 zdob^@?&SSg5cEZFfNjDQnX?%mvQ|W@`zz{p@$Jh@RE(-Gl&@LeZQYZ1F6Z4J25ZY) zVqfBST@kgDG${xZAHW}*)hl=ytY~#&@YC^%{Q5j8^#VaJctB;k2FIj1IP>QGwBC>* zU1j&kUM#vYs%dMKX3udR}JYiJ{r`oo|dr2~W&YR$|u9EECL`Puv0VkMI z9p=yt!q+)Kjp=ae&ED`^ZFFb!d|3<5YG=^5CuDglj{d9U!m=EyC}^CSZ*Hun%%72j zhq-@X_kO5rOV-sB!%ck2LYShLuIbSjpIJzOhH{(9l;-l{5Q0rHA*Eb*$ODTd#o^Ws z+gV)O9xg9DwVGi?p#?>TyPh%f7>w56K$^`h!@6prAPHx@Dz`JvJ7ToKE+9UU>zHdf{?!Dnh_GxJ-%fyr9Kv~?WV zxbkA@3B5&8KoUKJ3w9@FKHVsR_Gx0* z2);s_pi1qIjtP#ANuWoto|msoU}3$t?{Qj_gG&`grAK<|z?0YRvx`v0vcCW9+YtZ& zbZ&H{7@>Bxvg(dICNn*hDO(!0hbk@wgh4^MO3J1miqeLDz*%)SBPZs2eN2h5_x*HD zN9URKEeIJhxFzy4{BrQSo;ILsoA#H4h?HV!Fz&%TG5~IyM~+nI`Vvpipq7bVb@IM% zl+7Z_9Q0B`@naOi7jG>w7P|r3u(9C5?7_7hL48Y}P?7X+H;ePdAgr7Xc2*Tk(2K&W z3McvF`vtX@^gfU(Y;vw)81gutV9i8<^4n!PDGXAZH|)`^MO;`Fuj|^V_n{`T73_Vc zIoBh_vTB_&6HxDD27`8CRM=X^FT*u!pD*I5m15(gEZ*yZsPL(gjHYFnN|)w5K}RQ) zlt`+c?nK=vl;utkIkVfN-q&QkUxkFL6R(YsyyfU7#_-lHK(7A~Jsu$zuo z!uZEV%s6iO;rz;ImQPPtJ3)FsYI+%t{sF0%nn0>1fb!o^&z`!*N|C$I^Rkor=C;{a z?yi)f&k2JcE7f`NwY}!pfcxQp`A?<#`4z7JAkIJpZ+z1`1R5C%kAaL9-|yh%!`2u9 z4n63b*yWV!LQA7_L5Cvyri?N|mJ11cIzwt0o1`j&gDCNcB#(x7O>!4+)VQRL`}{m% zF2_GY+C2^1@@G!FYI_H@!262UJ+$hi^!a$0v0%U~Iw*Y3DtQq0kT^~2e4eU#Rbk#hoF<>WKb5fdZ@jJ@mHf|}J~Fp!FD z-RKuV98~V|UQH+(aUa)~eA$4cvj+?K!V(Oko3P($Y1t=mLAgfs{?-n=W4Cusgr&m5 zVi#hge0`XaS?a2&-s-)zAYs5Sn-JtT#`%j&cGkH297R8=T?G;C*8JD#-4fNJzQ*Zm z$-*bg{m^ZP(ah@9Ta+Qx$-|@PPsC`7eQeVSe2?uNLy%;2eQh%_N3Y5sg^}J9;hk&8 zdO7CHG>h(#P09WFKxV&v!j2(IT(!Q_c1F3Kd%-)yfbL`|?pFXnN2tpur}vvQ6btIP z6^%3E^f30Iquq8OltgCy{s9A3Aewczf{ZWT0csPHuEOJQ zj8nzH7a`vjP~$C8q$Zaz zpgf0!xU!kZkeE}BZ?}r|hw9?pChEWX!e=0-EYuG=u?>39Nghm=Z^|OiFzTa-QkyQ*MFfAB!BZdXBz(FR{gEC@P_wTV7*q zXoNX$R!!cZ>+VW8e2l*_yYhO(v?c!S^Sp-tbocyko=kc9lDa~zL(KY@ z_hu!>`7xszQ^f|K9CNCUj$QyPK};Lm2e5LUx(#yH?2608lp59>{&IwwZA_&;*Z%7Jv1 zK9kS6kdDZs`~a1%n&j*Gn_b;pWv#Fqqn1F^QZ=75M%ji85ZsOZ>t3xs;zi8kH%@U^ zw`CiPI}(78=U4yF)lky+v-{yb<;j#!XJ2`3KtMOK1@nB`FC#1?VQ)-Bx8l(MX4x&m9Gn{`C>R%V<#!W(1*7iRa!F8Gb_~#v-#=e+>ZbCJs z34fDBSsqYQw(GT&2Kyw&X-ml>ZS)~4ZCajf|080JTzC18;%)L6kF4n?9ZSVsUyr}a z=mkv@;4oDEr`?Vit3zFd#Hw0P!K-1fy#-1VVa@%S|oq55@a zM&vBq8DwS=vnY1y%HNGq7G9tDshf($`Mar&bC(x$V(iNPkM_l2$3OJ1_?5SVoD%DsA>yjPSXk`AjASm-~@um7{X90gJK{; z2x9_5BuD~52w@K1L-%|8`t;k+t@q3A>JRnpoREi{tbMZ2+H3v)zs=LVn$Zh;HC7fp zCwSzG5sve0I=$oshmmleM`LTMF3QSqzkGSVA@k3X2wDbxjzg|%NF$ZFh# zyJg(Oz9dwLhd0?H#YripNd+-f=$Wzh(}N*{=5DFMpYXa86QwJ!u5-0!nbCNCYH5;f zdFknN!l5fes}UJbu9-4(_vVtPDRy#fVqsEq(BjM*BU2`l$c;C|Oy0{IxT9H3u}oFn zsiC@9-e;kSO;L3mi}fpn9KeU)Z?dThU93g5Ys89x&K%`i7o5|LrrN@!(hDg zRL+^Ug^_%YZFeg>LliaZ?L0K=jTKY@3OEB&&)=GZIU1Y69v@3=Ccy1_CpVM799)fm zKB9fM|MCs8s&NQy4KokUJ}kN6F5r=NVK_nx$n+9JcP4#+WP#T+V9{?mMkS&*mFclY zNv9BZPfUKmuD@8H6cfC*(Cuu?ywz1;tt#ov4LoHI+=+}r~lOMzH|4YWpRGY z0z}=@eF=6c%o=}4Gylh&iiNS^z}ai#W!+ikg3O4?GSEbb1oH{}Gc3tXX-MMzpbG5%_n+Hu@XA3rzY_PeyeclnYxuz`lzzLy zeH<5wNubcYDT$*x^V9S&Ku?Aut_5gvq3(Mu>u;;(u3b+w^z$J+Y>?<>R?%O%<6q%= zqj_*+`x-vMyY3`qN{H{d>Hx0qYwst`KRQ3b!`9y{OO~z?YJYgzihbB0ox) zkZSP9=Tx&^zb6*e(ir;{fCF;;5C0tX1f8jB*)$b#@-bz7nMo9f?Pm3(N~<)~gPeCg1;MPSKP{>tpPfGq1-@^Y<&9ZAJ(s*O;2W)jU%y z^fU*d^`?C4vJK?^)`{)hdi9BC-102qSX_dO?;11OE+v{I4-sl-i;5@}H6kn3jyiH) zad9D-tv!9pFyk@&w?M~@z+^W2ro}*=Pye(P9_#!`;7|Cy^%$ZMD>W!ZjPu7e@^+UG zPai&PgXReG|cUB>WmblQ@ zgAZtw>I{nBlZmO^kn&P131_NQ*9s(M>2M3?EZZjLiysft?*{+mY_;beGy3P}D<@O& zj+t@GrBCPeY4;-fQ{qGg4T#2aR48eqLumJ95q;F&YL@sWT}D17^F`-lJ|1nf4+Lbv zJ~?`t@wCOZPZk)ry^?55fumL`^zDJ3FTcmQyREys#XcP}cbj}X6t$TPVoS=`3Q@L{ zxo5)Gd9fGkp?O|@xVhSq3RYY|H2pQ-eG0E$=zpkhtiB??YIUCZQ}X=Gv#fBV!bKxe z$TTWE2dvn7csU@Lj!^Mvi;RJxht+QEBNk47ILoDBPGw=L(kYe>=u}WXXXvTyq3VG7 z>fo64ziyxR+!7PxBFB&~V^f@-ZGzcDZXGzr>80U5Dtg6ES-JtfC4{0) zB%G%xCpY)ED|~#yCPwTpkWia@ZyCZODp^o9g%hD*UPw4QeJiWtgS>HR1-!L$SPlvI zZ@xNS5Ih~{cV`o8Y{+;{v6j8CM zj}{$=+*$O}(GFR7fUu@@wz!G8whK;~dm_7%E#a%(*@)eO3(`8|fMHhr*hpm~s$UTe zDhp?ePN&amYulE6v6g(W;AO;Ii|@InO;1h8Bs4hj>Z5Bn9$leyt83dq>qoxQ7`XS( zKfmAN{DhXjbzX1<)Ochgd(U-pkz>$?Wny(0~1F!oyMEIa?*}-X~K*9ql2gY5g$)ut7CX$FVD!g2R;?m z)>1&{GHt`;VI&+Q6A9;@=d;b=UTg@&uHIy;Bavm?C_DkIz%9AftCHM220>tK7I=0P z-(lvySAO4W;%G*t#5M9@WQdCHI)-{XQc07Sk~tR#rdun-h*~Q1tn0$mv%x0s+lrRk zZeOa{>_#o26L<_`DV+gSZFBYg#w;q{9*A6a*{cv;kuMrD90b=~J!S$TCgMqi3lcw) z5UM+;^tvMla?ONooJP~|kF1SN>9LcprcMW)vkUFM0+c8FmETF8p98ABm;e&?EcrW_K;n8c4FH?SDDC)6I^4l!Wkw0|`ne)J)Rj?i6>2c%6ov9L$Wx^%9$yt`DY8YL+8gpozE>6g~*- z!1nexS6+_>;_u094j+sWCzzWH`TgnbXxV1b>gpL*j4P(P_ZFu1s6HJ?($!A~EQOn~ zqZAwa`#Y!}?szMfDVUt4jY^_myR^1=e!IT|c7G|T^Oy+gvYKD{>142gtd`0m!>A4R zsl|Dy*_DSiC7n4$241%~<>cJP)`Q$XuiqHwD?ci?3n};JjaCYDyqJ-MU{?HO9jN5P zI^Snc(MIBDiNqi2*Un+inV0ow5-G$*f^ci2!PZW5M1|*D?{?>xgB8pF7`XSco;DTC!fMe_+|Y{(XSR)oCnm)GxsC6sR9)N^8E=YGYp_2rS95c9xf{4dnC!0<2lhs4|Mb?0n3pTd=0GcemTqUmiA#7v06& zSh%|0$W4Yg_V*OG+K~s!fvqUZb)jXm?be34=+vw&Soc{g7z_a)aiF6@TiX)E>!tgz zE1X^x(To}DP~U`gcADg2eR%2BIheP3%S5+OP97+yMx~55-1V)+TFs() zZz%j0@Db2jRR%tAE>GS<3^zM5E74Ho?$p5WDmv&D7{+|A8LYR@iu}=9>ZfR_y>S}# zpu;wI8BDIH@RzG10&M!PWE(;{YNVi^b+s^HqaL;HDvtkG%!PKPw+E0CA|4-y8ku4D ztQQ4vC?(%4anx0!WeCKI5MGAd_jK?t+e!*ZaE=b2%mIJz zI(N*~%&Y3q#a`d14_P08vcLOp@qNEhX8(Zgwn3-H_)e%c%FFZf{73QK**Bg(0Z=H^ zje0W=b78_NxJuR5$-E}!xIJ#S9N$h=?T~UKCA(S2x-sDaz1iWGL_j}-&VqUIRs~F0 zj6)X-=1~3Mr?&?dSTy#wGm&6GCvS>h?JB1H`K9f0snlaG$<{LIfKtd;?_AM)4mKDW zc1h088mdt7uYrQkmV)?6ZAuXWYzni?tdxx^1kjLSdD?y!t?TQphLLO04(NJZG#TsADewT ziFGHFt7Nok_->+3^{&oT<&yU`VU5$#jA`$!xgGYio)2cm)$U)NxaD;wI5fV4^UWlp z|67}OcT)sIXb{y zU#`0?d=N{eoY-hQbH1?_tttGuvfpb3(TcMF7MYCyB$PxX>x*m54!%}b`F!f2f|Ken zuAztA8DKK{W(;?(0PJw38s9ru^?xU>cf$7XJ_Mb{r!#=6^z;?dU%V9hKJAPc8!}&Z zHAe3h>#vDV=DB(*sZ@dpnhe4f0HA|hqn7+Xo<}5$lw~$Fo11aI?Mvr?XLtP-v=rhR z-}n)?uw^z_2CruM&b0I(N_nO{kAiR5qyd#0I9dI-laN%$kRdpQWsW zUH=+g=15t|rSAvb>WaO3k2yC|bV2M)Ha22IJ8-C~R`|1=Y#pcJAsV^axOyhh)$Z($ zuv|$~QyeCsleVxenO0k)M`(u3g9TeK|K3q>w!_ERpAs7!efqKyXhR^1%f)M(KbX$_ zI=}OShzSK?#QJNFhI@=3!+8QL;5E?V;x|_54jaLQD`nb%5Q@x&24uTwPkr7GmkiwD zsIr{_x#--wh#4K5o)h$^#K<_Tl#}A|z%-k_ce^nZ$dZq5qUYJE&$f3g;aV}CYZ;CNlOOlfU>8LAz%bV;J$2GqAiy$ga5Xr@NK=w~HN0vr0 ztr5OufS3*f96=cysCZ2qWSXxP<^CnM(|yon(bKJ-yf+PS#mmRK@C0(ca<^#`Ba_N? z-#NCHCEci8X)_BC*vn}UmFvwC($>Q_$IHe1S+sj!2t{w%T=zwj(y7%`G-IaPe4H&a zxLUFR6{qzDO}RpH=oSN_1Pq(g^VBVtHi9WhDW6Z=TwfPyO}2l|wds2E{AQKS zEv)FP2=i;3Xus%J?lo|l`uvhA+rcRzd+p4zxZace{qsKh!8~fnR#DT>Srs88`knd3 zxa>rgDzGaCCaoMTA5!`?VF6%9@mCE@2F_Ce;JDMsm_kn1?{ckOjk3 zlJnsA)K%o_Xwa_+!W1v7Fucq}{JR&wcYR1M|*{@6nHr$^G{Rw~J%G9(tHe$!J8i zsV7hpC=z$$C5arbk4z^Uof6uuzFaR8y^6hEG0q^KG>-HivErmGOtwuvqugy8UYUju*>!y4%@wLTd{oMJLG8XHV@vNY5YGKB$14QsJ6MINbq7bc3}%jgDEd6V0j) zPJcPD0sY~fVEuN7;${^lbt(DaWnNL^bZ~0LET8q1HizazVE)PRgpWcYSV_dU36c^& zOlV_FAx(&2G1aBY{c$cEfeVVZ&O=`$+2GL6ThBVLm`|B)pJuc)Uh{AYg`jmXbAPPy($Z6g7*{~^w*2cx%v1MdODL!Z|M$PYe9goe22VZ7Dw3Gu^ z_;v0xrd^|28xL=dpXuaCt!*o1H)K?*LM~Yu&Hhe)R>Q6B^xw`iHV?fV{`Kg84SitE zl#|vTuivhiON7S6I>w(U8K0$j$IGFwx1wA%C!61y2gg-{Iz2~{T=Yx7 zHJiCG-45g1JmfBi1=?I@O1M&Xq9&*TPuY(B)8lEodCN{W)>)*^Ph9KhoWVEg*H4z} z4Am8$#kdUIEeHE`l#v%E8v%1en2rxtZqtNgj~Z=by0KxI+Mu76ZP@;L!in6x2DbG; zo#1}0^a^nV#Q7G~aFhq#A*&Q^)z^#gh7_x9F*O*`I1N_nn`Jh4dvD=RXJOtRNP=UE z%6Dt>8lXQs+G;aodG%~l&(CSK?HnLZ7eL!JL$+B4 z{UTx~Qid}}KPsoT+FkdcNdQ!KdRbNG;=+opKl$S~>$f%8y~LvAYMj~H^Cq!{wD9!v z8aEM^%YJC>v{%Rbc_|=pZuEpfOsmEIOHts0c4<9#l-t}i&oM7Z4V;)4F-!w}s6)C{ zD?n|&u{syBplBjG?)(6Lo>?Gm?XI5PAPk7BG2(3x zszh}6y*)r^F5kL_egQ|;XqQ0h*K_h!W-}XY+gPo;mPOP_Zm4bwCzQ;892aS0fjqYb z%hYKil6RZsz5|y+&&;h?<&KT^rVPJldFNN6^xlZXwfp{(;lV%gCL~^g3)?7Yg4J=o zq0B%Mxcfj-85D)o_-p>UL~P&ONf@j-Y_NtwO`)4%#}Y<2ss-#Bb$`GP#FCw=7DLKU zJsQoR5kAV@Dg`~P82V>y4L3v@Aoowy=}5FM>3hx%C=>Bv(?#@kuJ8uUdilh<4X?)z zYNxW~Jmap;u9n(Gcm4R|6ce%Y_vW#9zugr*2M;UGAE>vP`)jQDT3Ea5lrO4pvMF&K zm-D)ec3bPiEDu5SQVJ+XGIOt9>573U+8`&GVHd}lkuDQO8ib%9E0B|2buL>QH*&3j z2$Z0OhcdzHw^sO1F z?jml(VwL*PdZo0aUk&we`r9X4J9*;KH@P4z>&1J~KED#SHiv*QnK&dUq4CK56; zO_H-cu)B4LN=kA9!<~BSNToFI&Q+;L^}?GGv(3 zO3Nb+^{&5G_Oxnka_}hwI+j|Ix_|_>W9s1wbJw)>w2e7q!f&OI{vBPPyHx;pJmwFa zqJTn;BgN}jj?Vel=-zIyTqVrP$)9<9Ai^EA|4!wpyXsy1DDW|Br6B1gSJg7KxKq2wJm2v-R5I)nZE^+1H zoH=|?T&PB$L@>DcAWBpU73g;$`JH6-O}3^N$7|cny(UbxV1_G=TM9O6t6us>o&f5y zr68M=0`gjur~%^|!Fxlvn>K!qeao-a0$NvUT#qGLoy5cGa-^=!ovlqzh*rYYD;=Zr z_89_OP$R@|A6zaS-*zU1K_+bX75C^2*(tu}))M(Xe%5D^JviBp6uB7{7b6)j8t4*q zt$&Q7c^O{Kc2@$^m?mR8jW;}8Y4B(x&=dhuV;Ei_3e=$=27`d=#01v!8_=RwXjpl> zS=UhgnL$+{wFgrZZAr@FI;Ya{-V3wjLg)gaZGJqQyb>Os@N|!_Cfe9=zIx{p=Pz@e z>B#cugv%w;wcJj_%M~>5#mTb%;@HV%G!aD8#=UbhP@i_k$Wb*=&RE&$Zhvvu$N3%__F`dP z%e7t^jtQBiZ3O=vdjYX`0~bDNZd2wdr>T06JOgEJ+tg`$^dCk{vO7$8XME+J9SM89 ze=0owX7}X(@Pjolv!iP@w4X!OZu|F9wGO)UGV=4HQ=T{~LTsI@H=`8Aw%_&uW$8sg ziMCe0i>E64!|#`#k0|uJ76(&s=5VYRufa8;-q9Zx_P$<5##Z9Ra;A(@oM-p_z3f^5 z@iiA$(P@^vOv6^y{;3m!VsTkl>fE1%4yP0l)8|JL$X3W~wHpwh{uS<3P#5gkXSa)c z7(RXOZtpSJG)JwxaJdUXe~I5PLB!U3f;?End+q5tTDsHr9TBQ`z{mo+>iAE=^0{Sbogh-*Mor{POlCv#s7JP+!?ugyxFY3@f; zn%U0h4n2JF)&DTUzs1`$n~lINRY2}b(Wx?B0083C)1{<*b5UU=bIiKmH}Zn{`XRKY zS)50V2X~2A6dg~>1&esC`V{g^Stw}=e zBF&u6*@U567swTtM?STm1Rs6J3K8WWr;>G1wpFE55Jg2WCG;{cwCMUy;(6-{`*w90 zWYksXQ7q1HQnHSzcO!Az+kZ^GbsJ&oHyoRV)dq?9I>k+(lz-o?9!jAH5}0tiH7FK-8I2Nw3Z2wnJ&0}2|v!k;nZYg z@wTqYIdAGHqZeFIKPdp3hEa9|pTs~uP%YsAO<_>q{CxMG!ZU!dfRuj){3t`iY{IZ|uTs^do3 zyS`|>u~(PH8?k^Xj|O+TcL%?(R~)sretY}ER&Tv5^$yObK1`FVa>loePmApaw_=C_ zohzVGThrqY8_DneAE80Z--HH1wckCs^IbSt^HSW`9sH;04Bi>TcMlIihc)ubWjd(P zNu7X9`E&2yVl%G8uD3WNvxY}qucQ}+<|bKDtc0qaq7+A5#t_s^cy#&2*~#uqVX*c-tcw$qNwEl%On>A*`DJ6# zf*1R?7iNXOOyE~Z3fDXCNnM88C6sA8?N!G7gnql&_THfy|dM6YbsCk|>W@xggbe=20o@>~r zc+8J7&?Eq97h?-f^$<`+mak13mC7~i)sd9mNmND{QH^$|#qr!OY!lxo{~ z9IcW{B8V`O0F4YSg)sRVc`tjVpCPU+x?)93B|N6x!65lfwZ0yws;tFEc{h(e zY%{!q0OI9GKpVrC5Qy;tEKaU0eQ1AiK@{x$W;xXI&eR}g(Fs(@c5N8JTvkw{pml^E z1##JQRrVgoNgpJ*;KuWxf*HNN&vtx`pI%|lZbTI5dbD@{!=VD^5AOu%KmM>pi(96C?qG|w=B&ITge@sX?Y%DxCb zO;UO1r2C~NJNRYmoA(y)y6w8rNRG5dj(R^+aRpH;H(#LF@_HhC>GHk^4^@yguRd4g zS4L~>R$d_uS=W-0r6u^FSX@s#iNG7SKukBFU3!l>**ar2$&W*XuTrL{8&3{@s^t2( zm-FC^XP}x2I0sFXSyHlMyFlp;XtUPBz8J?Jz1#U|pT zSr+`SqrK<<;|K1Y3pAGeEMcl0M~Ww(Xom>SbC%~kT?1e|N`}N^4`4Rzt(QfcoDF(~ z=zGS5Js+ikJ7tPWQ2-@@M6Q1R9ipw7JciKinkX>Zh?F3{$uyvnZ4=e~=_%x~-sP~l zzeY$P?7$mOoIlYKc!S*eZ*3=d?x1!9Y3ZqTQr@5Ee$5loTA08$o)!?PP6Gs_fJr?>t?Ge6PXumv_GTfBxa2dK(Cq0)>8HhRft%}f8*BaKU^Y0G62YmBn^*V~ z{guNFRZKtykC>4u49Sis@U0Z#f=hul2H%~_i#!~oWE)CzyVE-rgc(=2^+=p>Gcr+KxU9A zI_)kjcT-j`E|dscI(tt8&6TP72IyVHIxDbB2cjF9U|H7|bhLia_{fcg zIeU=M<)*D)q+2zDG#v_V3Jg$!CK$x`lOE45yS^q-5mH6!>K|?eN!YM8o5+L zVvqoy(O0Xf8zJy1FP#Hv#j0(f>xh<~K}w%Z%=7AhS^x3@CVEGCrW$PR?QT-PZwZUH s@jwlSxE!!9{ngg!JKz2H!`~zDdjx)u!0!?GJp#W+;QtkY!*9p`H{RNT?f?J) literal 0 HcmV?d00001 From 7db21263ad24168baf7a480eb0d8c4ab159fcdd8 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 9 Jul 2018 17:08:25 +1000 Subject: [PATCH 40/68] Add UnitConverter tests --- .../Common/Helpers/UnitConverter.cs | 23 ++++++++++- .../Helpers/UnitConverterHelperTests.cs | 41 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/ImageSharp.Tests/Helpers/UnitConverterHelperTests.cs diff --git a/src/ImageSharp/Common/Helpers/UnitConverter.cs b/src/ImageSharp/Common/Helpers/UnitConverter.cs index 9a7d25c55..c8b25bf56 100644 --- a/src/ImageSharp/Common/Helpers/UnitConverter.cs +++ b/src/ImageSharp/Common/Helpers/UnitConverter.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.MetaData.Profiles.Exif; @@ -19,6 +18,12 @@ namespace SixLabors.ImageSharp.Common.Helpers /// private const double CmsInMeter = 1 / 0.01D; + /// + /// The number of centimeters in an inch. + /// 1 inch is equal to exactly 2.54 centimeters. + /// + private const double CmsInInch = 2.54D; + /// /// The number of inches in a meter. /// 1 inch is equal to exactly 0.0254 meters. @@ -57,6 +62,22 @@ namespace SixLabors.ImageSharp.Common.Helpers [MethodImpl(InliningOptions.ShortMethod)] public static double InchToMeter(double x) => x * InchesInMeter; + /// + /// Scales the value from centimeters to inches. + /// + /// The value to scale. + /// The . + [MethodImpl(InliningOptions.ShortMethod)] + public static double CmToInch(double x) => x / CmsInInch; + + /// + /// Scales the value from inches to centimeters. + /// + /// The value to scale. + /// The . + [MethodImpl(InliningOptions.ShortMethod)] + public static double InchToCm(double x) => x * CmsInInch; + /// /// Converts an to a . /// diff --git a/tests/ImageSharp.Tests/Helpers/UnitConverterHelperTests.cs b/tests/ImageSharp.Tests/Helpers/UnitConverterHelperTests.cs new file mode 100644 index 000000000..57e280d93 --- /dev/null +++ b/tests/ImageSharp.Tests/Helpers/UnitConverterHelperTests.cs @@ -0,0 +1,41 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Common.Helpers; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Helpers +{ + public class UnitConverterHelperTests + { + [Fact] + public void InchToFromMeter() + { + const double expected = 96D; + double actual = UnitConverter.InchToMeter(expected); + actual = UnitConverter.MeterToInch(actual); + + Assert.Equal(expected, actual, 15); + } + + [Fact] + public void InchToFromCm() + { + const double expected = 96D; + double actual = UnitConverter.InchToCm(expected); + actual = UnitConverter.CmToInch(actual); + + Assert.Equal(expected, actual, 15); + } + + [Fact] + public void CmToFromMeter() + { + const double expected = 96D; + double actual = UnitConverter.CmToMeter(expected); + actual = UnitConverter.MeterToCm(actual); + + Assert.Equal(expected, actual, 15); + } + } +} From 4068401175f3840377c027966981f76f300953d9 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 10 Jul 2018 07:34:17 -0700 Subject: [PATCH 41/68] Seal memory classes --- src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs | 2 +- src/ImageSharp/Memory/BasicByteBuffer.cs | 2 +- src/ImageSharp/Memory/Buffer2D{T}.cs | 2 +- src/ImageSharp/Memory/ManagedBufferBase.cs | 2 +- src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs index 90950d4b3..f1c4c49c3 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs @@ -9,7 +9,7 @@ namespace SixLabors.Memory /// /// Implements by allocating memory from . /// - public partial class ArrayPoolMemoryAllocator : MemoryAllocator + public sealed partial class ArrayPoolMemoryAllocator : MemoryAllocator { /// /// The for small-to-medium buffers which is not kept clean. diff --git a/src/ImageSharp/Memory/BasicByteBuffer.cs b/src/ImageSharp/Memory/BasicByteBuffer.cs index a8a30b1aa..9f995e347 100644 --- a/src/ImageSharp/Memory/BasicByteBuffer.cs +++ b/src/ImageSharp/Memory/BasicByteBuffer.cs @@ -3,7 +3,7 @@ namespace SixLabors.Memory { - internal class BasicByteBuffer : BasicArrayBuffer, IManagedByteBuffer + internal sealed class BasicByteBuffer : BasicArrayBuffer, IManagedByteBuffer { internal BasicByteBuffer(byte[] array) : base(array) diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index f8d75b54c..b76c06df8 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -12,7 +12,7 @@ namespace SixLabors.Memory /// interpreted as a 2D region of x elements. /// /// The value type. - internal class Buffer2D : IDisposable + internal sealed class Buffer2D : IDisposable where T : struct { /// diff --git a/src/ImageSharp/Memory/ManagedBufferBase.cs b/src/ImageSharp/Memory/ManagedBufferBase.cs index 606d1c962..8de2f5392 100644 --- a/src/ImageSharp/Memory/ManagedBufferBase.cs +++ b/src/ImageSharp/Memory/ManagedBufferBase.cs @@ -9,7 +9,7 @@ namespace SixLabors.Memory /// /// Provides a base class for implementations by implementing pinning logic for adaption. /// - internal abstract class ManagedBufferBase : System.Buffers.MemoryManager, IBuffer + internal abstract class ManagedBufferBase : MemoryManager, IBuffer where T : struct { private GCHandle pinHandle; diff --git a/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs b/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs index 2d339f4c7..df69cec6e 100644 --- a/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs +++ b/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs @@ -3,7 +3,7 @@ /// /// Implements by newing up arrays by the GC on every allocation requests. /// - public class SimpleGcMemoryAllocator : MemoryAllocator + public sealed class SimpleGcMemoryAllocator : MemoryAllocator { /// internal override IBuffer Allocate(int length, bool clear) @@ -16,4 +16,4 @@ return new BasicByteBuffer(new byte[length]); } } -} +} \ No newline at end of file From 88638d3f22428c9929ba4ec26f45b3a5f4eeec96 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 10 Jul 2018 07:36:31 -0700 Subject: [PATCH 42/68] Remove AggressiveInlining hint from trival field accessor --- src/ImageSharp/ColorSpaces/CieLab.cs | 6 +----- src/ImageSharp/ColorSpaces/CieLch.cs | 6 +----- src/ImageSharp/ColorSpaces/CieLchuv.cs | 6 +----- src/ImageSharp/ColorSpaces/CieLuv.cs | 6 +----- src/ImageSharp/ColorSpaces/CieXyz.cs | 6 +----- src/ImageSharp/ColorSpaces/Hsv.cs | 6 +----- 6 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index 18693d553..82975d933 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -111,11 +111,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Compares two objects for equality. diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs index 4fa853206..67a9956bd 100644 --- a/src/ImageSharp/ColorSpaces/CieLch.cs +++ b/src/ImageSharp/ColorSpaces/CieLch.cs @@ -111,11 +111,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Compares two objects for equality. diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs index 16c5f0bcc..0b4c7a903 100644 --- a/src/ImageSharp/ColorSpaces/CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs @@ -111,11 +111,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Compares two objects for equality. diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs index fc216b97e..dbc3b6dee 100644 --- a/src/ImageSharp/ColorSpaces/CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLuv.cs @@ -113,11 +113,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Compares two objects for equality. diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs index ddca51b95..fa4261b46 100644 --- a/src/ImageSharp/ColorSpaces/CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/CieXyz.cs @@ -73,11 +73,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Compares two objects for equality. diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs index c8cc7eea0..78a49097e 100644 --- a/src/ImageSharp/ColorSpaces/Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Hsv.cs @@ -78,11 +78,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public Vector3 Vector - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.backingVector; - } + public Vector3 Vector => this.backingVector; /// /// Allows the implicit conversion of an instance of to a From acf2bb3a44c7b38626f3072bf2701a9036690686 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 10 Jul 2018 07:56:24 -0700 Subject: [PATCH 43/68] Eliminate virtual calls from unnecessary IRgbWorkingSpace abstraction --- .../Conversion/ColorSpaceConverter.CieXyz.cs | 2 +- .../ColorSpaceConverter.LinearRgb.cs | 2 +- .../Conversion/ColorSpaceConverter.cs | 4 +-- .../Rgb/CieXyzToLinearRgbConverter.cs | 6 ++-- .../Rgb/LinearRgbAndCieXyzConverterBase.cs | 2 +- .../Rgb/LinearRgbToCieXyzConverter.cs | 6 ++-- .../RGBPrimariesChromaticityCoordinates.cs | 2 +- .../Implementation/Rgb/RgbWorkingSpace.cs | 8 ++--- src/ImageSharp/ColorSpaces/ICompanding.cs | 4 +-- .../ColorSpaces/IRgbWorkingSpace.cs | 31 ------------------- src/ImageSharp/ColorSpaces/LinearRgb.cs | 12 +++---- src/ImageSharp/ColorSpaces/Rgb.cs | 13 ++++---- .../TestUtilities/ApproximateFloatComparer.cs | 8 ++--- 13 files changed, 33 insertions(+), 67 deletions(-) delete mode 100644 src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs index ff3822c86..f4f28401f 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs @@ -211,7 +211,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The source working space /// The - private LinearRgbToCieXyzConverter GetLinearRgbToCieXyzConverter(IRgbWorkingSpace workingSpace) + private LinearRgbToCieXyzConverter GetLinearRgbToCieXyzConverter(RgbWorkingSpace workingSpace) { if (this.linearRgbToCieXyzConverter != null && this.linearRgbToCieXyzConverter.SourceWorkingSpace.Equals(workingSpace)) { diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs index 6cfdb4853..5fdde5c75 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs @@ -168,7 +168,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// /// The target working space /// The - private CieXyzToLinearRgbConverter GetCieXyxToLinearRgbConverter(IRgbWorkingSpace workingSpace) + private CieXyzToLinearRgbConverter GetCieXyxToLinearRgbConverter(RgbWorkingSpace workingSpace) { if (this.cieXyzToLinearRgbConverter != null && this.cieXyzToLinearRgbConverter.TargetWorkingSpace.Equals(workingSpace)) { diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs index f86f50538..7142ab0e8 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. using System.Numerics; -using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.LmsColorSapce; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce; namespace SixLabors.ImageSharp.ColorSpaces.Conversion { @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion /// Gets or sets the target working space used *when creating* RGB colors. (RGB colors on the input already contain the working space information) /// Defaults to: . /// - public IRgbWorkingSpace TargetRgbWorkingSpace { get; set; } + public RgbWorkingSpace TargetRgbWorkingSpace { get; set; } /// /// Gets or sets the chromatic adaptation method used. When null, no adaptation will be performed. diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs index e75d4a804..217698c23 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/CieXyzToLinearRgbConverter.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap /// /// Color converter between CieXyz and LinearRgb /// - internal class CieXyzToLinearRgbConverter : LinearRgbAndCieXyzConverterBase, IColorConversion + internal sealed class CieXyzToLinearRgbConverter : LinearRgbAndCieXyzConverterBase, IColorConversion { private readonly Matrix4x4 conversionMatrix; @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap /// Initializes a new instance of the class. /// /// The target working space. - public CieXyzToLinearRgbConverter(IRgbWorkingSpace workingSpace) + public CieXyzToLinearRgbConverter(RgbWorkingSpace workingSpace) { this.TargetWorkingSpace = workingSpace; this.conversionMatrix = GetRgbToCieXyzMatrix(workingSpace); @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap /// /// Gets the target working space /// - public IRgbWorkingSpace TargetWorkingSpace { get; } + public RgbWorkingSpace TargetWorkingSpace { get; } /// public LinearRgb Convert(in CieXyz input) diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbAndCieXyzConverterBase.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbAndCieXyzConverterBase.cs index a0da2bc26..bc11c51b5 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbAndCieXyzConverterBase.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbAndCieXyzConverterBase.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap /// /// The Rgb working space. /// The based on the chromaticity and working space. - public static Matrix4x4 GetRgbToCieXyzMatrix(IRgbWorkingSpace workingSpace) + public static Matrix4x4 GetRgbToCieXyzMatrix(RgbWorkingSpace workingSpace) { DebugGuard.NotNull(workingSpace, nameof(workingSpace)); diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs index 05cd5b72f..e597b66af 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LinearRgbToCieXyzConverter.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap /// /// Color converter between LinearRgb and CieXyz /// - internal class LinearRgbToCieXyzConverter : LinearRgbAndCieXyzConverterBase, IColorConversion + internal sealed class LinearRgbToCieXyzConverter : LinearRgbAndCieXyzConverterBase, IColorConversion { private readonly Matrix4x4 conversionMatrix; @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap /// Initializes a new instance of the class. /// /// The target working space. - public LinearRgbToCieXyzConverter(IRgbWorkingSpace workingSpace) + public LinearRgbToCieXyzConverter(RgbWorkingSpace workingSpace) { this.SourceWorkingSpace = workingSpace; this.conversionMatrix = GetRgbToCieXyzMatrix(workingSpace); @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap /// /// Gets the source working space /// - public IRgbWorkingSpace SourceWorkingSpace { get; } + public RgbWorkingSpace SourceWorkingSpace { get; } /// public CieXyz Convert(in LinearRgb input) diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RGBPrimariesChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RGBPrimariesChromaticityCoordinates.cs index 8afe2ffa0..4359d666e 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RGBPrimariesChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RGBPrimariesChromaticityCoordinates.cs @@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap { /// /// Represents the chromaticity coordinates of RGB primaries. - /// One of the specifiers of . + /// One of the specifiers of . /// internal readonly struct RgbPrimariesChromaticityCoordinates : IEquatable { diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs index d4d00db86..f4a79c744 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs @@ -4,9 +4,9 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce { /// - /// Trivial implementation of + /// Trivial implementation of /// - internal class RgbWorkingSpace : IRgbWorkingSpace + internal class RgbWorkingSpace { /// /// Initializes a new instance of the class. @@ -70,14 +70,12 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap return !Equals(left, right); } - /// public override bool Equals(object obj) { return obj is RgbWorkingSpace other && this.Equals(other); } - /// - public bool Equals(IRgbWorkingSpace other) + public bool Equals(RgbWorkingSpace other) { // TODO: Object.Equals for ICompanding will be slow. return this.WhitePoint.Equals(other.WhitePoint) diff --git a/src/ImageSharp/ColorSpaces/ICompanding.cs b/src/ImageSharp/ColorSpaces/ICompanding.cs index 2dfa575ed..17a7c874c 100644 --- a/src/ImageSharp/ColorSpaces/ICompanding.cs +++ b/src/ImageSharp/ColorSpaces/ICompanding.cs @@ -4,9 +4,9 @@ namespace SixLabors.ImageSharp.ColorSpaces { /// - /// Pair of companding functions for . + /// Pair of companding functions for . /// Used for conversion to and backwards. - /// See also: + /// See also: /// internal interface ICompanding { diff --git a/src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs deleted file mode 100644 index 26c4ad6d4..000000000 --- a/src/ImageSharp/ColorSpaces/IRgbWorkingSpace.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce; - -namespace SixLabors.ImageSharp.ColorSpaces -{ - /// - /// Encasulates the RGB working color space - /// - internal interface IRgbWorkingSpace : IEquatable - { - /// - /// Gets the reference white of the color space. - /// - CieXyz WhitePoint { get; } - - /// - /// Gets the chromaticity coordinates of the primaries. - /// - RgbPrimariesChromaticityCoordinates ChromaticityCoordinates { get; } - - /// - /// Gets the companding function associated with the RGB color system. Used for conversion to XYZ and backwards. - /// - /// - /// - ICompanding Companding { get; } - } -} \ No newline at end of file diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs index 312187c9d..aaf05e035 100644 --- a/src/ImageSharp/ColorSpaces/LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs @@ -2,21 +2,21 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.ComponentModel; using System.Numerics; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce; namespace SixLabors.ImageSharp.ColorSpaces { /// - /// Represents an linear Rgb color with specified working space + /// Represents an linear Rgb color with specified working space /// internal readonly struct LinearRgb : IColorVector, IEquatable, IAlmostEquatable { /// /// The default LinearRgb working space. /// - public static readonly IRgbWorkingSpace DefaultWorkingSpace = RgbWorkingSpaces.SRgb; + public static readonly RgbWorkingSpace DefaultWorkingSpace = RgbWorkingSpaces.SRgb; /// /// The backing vector for SIMD support. @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The blue component ranging between 0 and 1. /// The rgb working space. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public LinearRgb(float r, float g, float b, IRgbWorkingSpace workingSpace) + public LinearRgb(float r, float g, float b, RgbWorkingSpace workingSpace) : this(new Vector3(r, g, b), workingSpace) { } @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The vector representing the r, g, b components. /// The LinearRgb working space. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public LinearRgb(Vector3 vector, IRgbWorkingSpace workingSpace) + public LinearRgb(Vector3 vector, RgbWorkingSpace workingSpace) : this() { // Clamp to 0-1 range. @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// Gets the LinearRgb color space /// - public IRgbWorkingSpace WorkingSpace { get; } + public RgbWorkingSpace WorkingSpace { get; } /// public Vector3 Vector => this.backingVector; diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index 777e1f4c1..ccfa1760f 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -2,23 +2,22 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.ComponentModel; using System.Numerics; using System.Runtime.CompilerServices; - +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.ColorSpaces { /// - /// Represents an RGB color with specified working space + /// Represents an RGB color with specified working space /// internal readonly struct Rgb : IColorVector, IEquatable, IAlmostEquatable { /// /// The default rgb working space /// - public static readonly IRgbWorkingSpace DefaultWorkingSpace = RgbWorkingSpaces.SRgb; + public static readonly RgbWorkingSpace DefaultWorkingSpace = RgbWorkingSpaces.SRgb; /// /// The backing vector for SIMD support. @@ -45,7 +44,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The blue component ranging between 0 and 1. /// The rgb working space. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Rgb(float r, float g, float b, IRgbWorkingSpace workingSpace) + public Rgb(float r, float g, float b, RgbWorkingSpace workingSpace) : this(new Vector3(r, g, b), workingSpace) { } @@ -66,7 +65,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// The vector representing the r, g, b components. /// The rgb working space. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Rgb(Vector3 vector, IRgbWorkingSpace workingSpace) + public Rgb(Vector3 vector, RgbWorkingSpace workingSpace) : this() { // Clamp to 0-1 range. @@ -107,7 +106,7 @@ namespace SixLabors.ImageSharp.ColorSpaces /// /// Gets the Rgb color space /// - public IRgbWorkingSpace WorkingSpace { get; } + public RgbWorkingSpace WorkingSpace { get; } /// public Vector3 Vector => this.backingVector; diff --git a/tests/ImageSharp.Tests/TestUtilities/ApproximateFloatComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ApproximateFloatComparer.cs index 24363173a..102a629be 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ApproximateFloatComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ApproximateFloatComparer.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Tests IEqualityComparer, IEqualityComparer, IEqualityComparer, - IEqualityComparer + IEqualityComparer { private readonly float Eps; @@ -76,9 +76,9 @@ namespace SixLabors.ImageSharp.Tests throw new NotImplementedException(); } - public bool Equals(IRgbWorkingSpace x, IRgbWorkingSpace y) + public bool Equals(RgbWorkingSpace x, RgbWorkingSpace y) { - if (x is IRgbWorkingSpace g1 && y is IRgbWorkingSpace g2) + if (x is RgbWorkingSpace g1 && y is RgbWorkingSpace g2) { return this.Equals(g1.WhitePoint, g2.WhitePoint) && this.Equals(g1.ChromaticityCoordinates, g2.ChromaticityCoordinates); @@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Tests && this.Equals(x.ChromaticityCoordinates, y.ChromaticityCoordinates); } - public int GetHashCode(IRgbWorkingSpace obj) + public int GetHashCode(RgbWorkingSpace obj) { throw new NotImplementedException(); } From ff66a9153b9bccb081c6c61d59c4a4d6f0808acc Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 10 Jul 2018 08:00:14 -0700 Subject: [PATCH 44/68] Update benchmarks to use Colourful 2.0.0 (allocation free) --- tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index 67faa7213..3f67f175f 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -17,7 +17,7 @@ - + From 872be9e8e157ba8b580914521240f3a78ac3f623 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 10 Jul 2018 08:02:16 -0700 Subject: [PATCH 45/68] Format with expressions --- src/ImageSharp/ImageFrame{TPixel}.cs | 10 ++-------- src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs | 7 +------ .../MetaData/Profiles/ICC/DataReader/IccDataReader.cs | 5 +---- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index bd86b7dee..93e888cca 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -174,16 +174,10 @@ namespace SixLabors.ImageSharp public TPixel this[int x, int y] { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.PixelBuffer[x, y]; - } + get => this.PixelBuffer[x, y]; [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.PixelBuffer[x, y] = value; - } + set => this.PixelBuffer[x, y] = value; } /// diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs index d475959c6..87e3e4494 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs @@ -147,12 +147,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif /// public static bool operator ==(ExifValue left, ExifValue right) { - if (ReferenceEquals(left, right)) - { - return true; - } - - return left.Equals(right); + return ReferenceEquals(left, right) || left.Equals(right); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs index d6df9e666..49b453a46 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs @@ -35,10 +35,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// Gets the length in bytes of the raw data /// - public int DataLength - { - get { return this.data.Length; } - } + public int DataLength => this.data.Length; /// /// Sets the reading position to the given value From 6dedf3db5f854862bd2310cdaf07f1e2d1658d32 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 10 Jul 2018 09:06:23 -0700 Subject: [PATCH 46/68] Fix comment reference --- src/ImageSharp/ColorSpaces/ICompanding.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ImageSharp/ColorSpaces/ICompanding.cs b/src/ImageSharp/ColorSpaces/ICompanding.cs index 17a7c874c..053c8d17b 100644 --- a/src/ImageSharp/ColorSpaces/ICompanding.cs +++ b/src/ImageSharp/ColorSpaces/ICompanding.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce; + namespace SixLabors.ImageSharp.ColorSpaces { /// From 4307d1a3a503b609d8a4572e2d9cabb2648ab1f0 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 10 Jul 2018 09:07:13 -0700 Subject: [PATCH 47/68] Remove leading whitespace --- src/ImageSharp.Drawing/Processing/BrushApplicator.cs | 2 -- src/ImageSharp/Common/Constants.cs | 2 +- src/ImageSharp/Common/Extensions/Vector4Extensions.cs | 2 +- src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs | 2 +- src/ImageSharp/Formats/Gif/DisposalMethod.cs | 2 +- src/ImageSharp/IConfigurationModule.cs | 2 +- src/ImageSharp/ImageInfoExtensions.cs | 2 +- src/ImageSharp/MetaData/ImageFrameMetaData.cs | 2 +- src/ImageSharp/MetaData/ImageProperty.cs | 2 +- src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs | 2 +- src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs | 2 +- 11 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ImageSharp.Drawing/Processing/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/BrushApplicator.cs index 04e2d0b9d..0ac4e4dd1 100644 --- a/src/ImageSharp.Drawing/Processing/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Processing/BrushApplicator.cs @@ -24,9 +24,7 @@ namespace SixLabors.ImageSharp.Processing internal BrushApplicator(ImageFrame target, GraphicsOptions options) { this.Target = target; - this.Options = options; - this.Blender = PixelOperations.Instance.GetPixelBlender(options.BlenderMode); } diff --git a/src/ImageSharp/Common/Constants.cs b/src/ImageSharp/Common/Constants.cs index b7cfddcb6..a8a693fa6 100644 --- a/src/ImageSharp/Common/Constants.cs +++ b/src/ImageSharp/Common/Constants.cs @@ -18,4 +18,4 @@ namespace SixLabors.ImageSharp /// public static readonly float EpsilonSquared = Epsilon * Epsilon; } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs index 88712a736..b88c229c5 100644 --- a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs +++ b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs @@ -110,4 +110,4 @@ namespace SixLabors.ImageSharp return MathF.Pow((signal + 0.055F) / 1.055F, 2.4F); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs b/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs index 0bfd6980b..56952f035 100644 --- a/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs +++ b/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs @@ -14,4 +14,4 @@ namespace SixLabors.ImageSharp.Formats.Bmp /// BmpBitsPerPixel BitsPerPixel { get; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Gif/DisposalMethod.cs b/src/ImageSharp/Formats/Gif/DisposalMethod.cs index 5371fc0fa..5d3e1b4d8 100644 --- a/src/ImageSharp/Formats/Gif/DisposalMethod.cs +++ b/src/ImageSharp/Formats/Gif/DisposalMethod.cs @@ -35,4 +35,4 @@ namespace SixLabors.ImageSharp.Formats.Gif /// RestoreToPrevious = 3 } -} +} \ No newline at end of file diff --git a/src/ImageSharp/IConfigurationModule.cs b/src/ImageSharp/IConfigurationModule.cs index 93c40497d..3ca8ed918 100644 --- a/src/ImageSharp/IConfigurationModule.cs +++ b/src/ImageSharp/IConfigurationModule.cs @@ -14,4 +14,4 @@ namespace SixLabors.ImageSharp /// The configuration that will retain the encoders, decodes and mime type detectors. void Configure(Configuration configuration); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/ImageInfoExtensions.cs b/src/ImageSharp/ImageInfoExtensions.cs index 0f2b2ba97..dca5502d0 100644 --- a/src/ImageSharp/ImageInfoExtensions.cs +++ b/src/ImageSharp/ImageInfoExtensions.cs @@ -24,4 +24,4 @@ namespace SixLabors.ImageSharp /// The public static Rectangle Bounds(this IImageInfo info) => new Rectangle(0, 0, info.Width, info.Height); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/MetaData/ImageFrameMetaData.cs b/src/ImageSharp/MetaData/ImageFrameMetaData.cs index d507a5b3e..47a2fb775 100644 --- a/src/ImageSharp/MetaData/ImageFrameMetaData.cs +++ b/src/ImageSharp/MetaData/ImageFrameMetaData.cs @@ -56,4 +56,4 @@ namespace SixLabors.ImageSharp.MetaData return new ImageFrameMetaData(this); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/MetaData/ImageProperty.cs b/src/ImageSharp/MetaData/ImageProperty.cs index 3e0cccd42..a08a95fed 100644 --- a/src/ImageSharp/MetaData/ImageProperty.cs +++ b/src/ImageSharp/MetaData/ImageProperty.cs @@ -136,4 +136,4 @@ namespace SixLabors.ImageSharp.MetaData return this.Name.Equals(other.Name) && Equals(this.Value, other.Value); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs index f6ed9325a..da47b565e 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs @@ -146,4 +146,4 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return table.ToArray(); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs index d7221e8cf..c42e32d55 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs @@ -93,4 +93,4 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return table.ToArray(); } } -} +} \ No newline at end of file From f0926bbaab2ba1e2046c8925bec3310b9528dea9 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Tue, 10 Jul 2018 23:20:54 +0200 Subject: [PATCH 48/68] Changed clean boolean for allocation into an enumeration. --- .../Processors/Text/DrawTextProcessor.cs | 2 +- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 4 +- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 6 +-- src/ImageSharp/Formats/Gif/LzwDecoder.cs | 6 +-- src/ImageSharp/Formats/Gif/LzwEncoder.cs | 4 +- .../Components/Decoder/GolangComponent.cs | 2 +- .../Components/DoubleBufferedStreamReader.cs | 2 +- .../Jpeg/PdfJsPort/Components/FastACTables.cs | 2 +- .../Components/PdfJsFrameComponent.cs | 2 +- .../Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs | 6 +-- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 8 ++-- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 22 ++++----- src/ImageSharp/ImageFrame{TPixel}.cs | 2 +- src/ImageSharp/ImageSharp.csproj | 2 +- src/ImageSharp/Memory/AllocationOptions.cs | 21 +++++++++ .../Memory/ArrayPoolMemoryAllocator.cs | 8 ++-- src/ImageSharp/Memory/MemoryAllocator.cs | 13 +++-- .../Memory/MemoryAllocatorExtensions.cs | 47 ++----------------- .../Memory/SimpleGcMemoryAllocator.cs | 4 +- .../DefaultPixelBlenders.Generated.cs | 42 ++++++++--------- .../DefaultPixelBlenders.Generated.tt | 4 +- .../Quantization/QuantizedFrame{TPixel}.cs | 2 +- .../Quantization/WuFrameQuantizer{TPixel}.cs | 14 +++--- .../Processors/Transforms/WeightsBuffer.cs | 2 +- .../Memory/ArrayPoolMemoryManagerTests.cs | 10 ++-- .../ImageSharp.Tests/Memory/Buffer2DTests.cs | 8 ++-- .../Memory/BufferTestSuite.cs | 14 +++--- 27 files changed, 120 insertions(+), 139 deletions(-) create mode 100644 src/ImageSharp/Memory/AllocationOptions.cs diff --git a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs index 9f1158154..8909ca453 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs @@ -334,7 +334,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text } // take the path inside the path builder, scan thing and generate a Buffer2d representing the glyph and cache it. - Buffer2D fullBuffer = this.MemoryAllocator.Allocate2D(size.Width + 1, size.Height + 1, true); + Buffer2D fullBuffer = this.MemoryAllocator.Allocate2D(size.Width + 1, size.Height + 1, AllocationOptions.Clean); using (IBuffer bufferBacking = this.MemoryAllocator.Allocate(path.MaxIntersections)) using (IBuffer rowIntersectionBuffer = this.MemoryAllocator.Allocate(size.Width)) diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 20175613e..274550447 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -220,7 +220,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp TPixel color = default; var rgba = new Rgba32(0, 0, 0, 255); - using (Buffer2D buffer = this.memoryAllocator.AllocateClean2D(width, height)) + using (Buffer2D buffer = this.memoryAllocator.Allocate2D(width, height, AllocationOptions.Clean)) { this.UncompressRle8(width, buffer.GetSpan()); @@ -348,7 +348,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp padding = 4 - padding; } - using (IManagedByteBuffer row = this.memoryAllocator.AllocateCleanManagedByteBuffer(arrayWidth + padding)) + using (IManagedByteBuffer row = this.memoryAllocator.AllocateManagedByteBuffer(arrayWidth + padding, AllocationOptions.Clean)) { TPixel color = default; var rgba = new Rgba32(0, 0, 0, 255); diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index fc73f55a1..a80949624 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -321,11 +321,11 @@ namespace SixLabors.ImageSharp.Formats.Gif if (imageDescriptor.LocalColorTableFlag) { int length = imageDescriptor.LocalColorTableSize * 3; - localColorTable = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(length, true); + localColorTable = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(length, AllocationOptions.Clean); this.stream.Read(localColorTable.Array, 0, length); } - indices = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(imageDescriptor.Width * imageDescriptor.Height, true); + indices = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(imageDescriptor.Width * imageDescriptor.Height, AllocationOptions.Clean); this.ReadFrameIndices(imageDescriptor, indices.GetSpan()); ReadOnlySpan colorTable = MemoryMarshal.Cast((localColorTable ?? this.globalColorTable).GetSpan()); @@ -528,7 +528,7 @@ namespace SixLabors.ImageSharp.Formats.Gif { int globalColorTableLength = this.logicalScreenDescriptor.GlobalColorTableSize * 3; - this.globalColorTable = this.MemoryAllocator.AllocateManagedByteBuffer(globalColorTableLength, true); + this.globalColorTable = this.MemoryAllocator.AllocateManagedByteBuffer(globalColorTableLength, AllocationOptions.Clean); // Read the global color table data from the stream stream.Read(this.globalColorTable.Array, 0, globalColorTableLength); diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs index 35eb43a8a..2884abfe8 100644 --- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs @@ -57,9 +57,9 @@ namespace SixLabors.ImageSharp.Formats.Gif this.stream = stream; - this.prefix = memoryAllocator.Allocate(MaxStackSize, true); - this.suffix = memoryAllocator.Allocate(MaxStackSize, true); - this.pixelStack = memoryAllocator.Allocate(MaxStackSize + 1, true); + this.prefix = memoryAllocator.Allocate(MaxStackSize, AllocationOptions.Clean); + this.suffix = memoryAllocator.Allocate(MaxStackSize, AllocationOptions.Clean); + this.pixelStack = memoryAllocator.Allocate(MaxStackSize + 1, AllocationOptions.Clean); } /// diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs index 347609a54..5a588a671 100644 --- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs @@ -168,8 +168,8 @@ namespace SixLabors.ImageSharp.Formats.Gif public LzwEncoder(MemoryAllocator memoryAllocator, int colorDepth) { this.initialCodeSize = Math.Max(2, colorDepth); - this.hashTable = memoryAllocator.Allocate(HashSize, true); - this.codeTable = memoryAllocator.Allocate(HashSize, true); + this.hashTable = memoryAllocator.Allocate(HashSize, AllocationOptions.Clean); + this.codeTable = memoryAllocator.Allocate(HashSize, AllocationOptions.Clean); } /// diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs index 75cea5551..72213eb38 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors); } - this.SpectralBlocks = memoryAllocator.Allocate2D(this.SizeInBlocks.Width, this.SizeInBlocks.Height, true); + this.SpectralBlocks = memoryAllocator.Allocate2D(this.SizeInBlocks.Width, this.SizeInBlocks.Height, AllocationOptions.Clean); } /// diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs index 7aeee43c2..0e42d074c 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components { this.stream = stream; this.length = (int)stream.Length; - this.managedBuffer = memoryAllocator.AllocateCleanManagedByteBuffer(ChunkLength); + this.managedBuffer = memoryAllocator.AllocateManagedByteBuffer(ChunkLength, AllocationOptions.Clean); this.bufferChunk = this.managedBuffer.Array; } diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FastACTables.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FastACTables.cs index 6cb0d6dfe..0fc85c6e4 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FastACTables.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FastACTables.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// The memory allocator used to allocate memory for image processing operations. public FastACTables(MemoryAllocator memoryAllocator) { - this.tables = memoryAllocator.AllocateClean2D(512, 4); + this.tables = memoryAllocator.Allocate2D(512, 4, AllocationOptions.Clean); } /// diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs index 7501b0d83..7d4eb66e8 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.AllocateClean2D(blocksPerColumnForMcu, blocksPerLineForMcu + 1); + this.SpectralBlocks = this.memoryAllocator.Allocate2D(blocksPerColumnForMcu, blocksPerLineForMcu + 1, AllocationOptions.Clean); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index a360d5477..5ea5f7fe2 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -707,7 +707,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort /// The remaining bytes in the segment block. private void ProcessDefineHuffmanTablesMarker(int remaining) { - using (IManagedByteBuffer huffmanData = this.configuration.MemoryAllocator.AllocateCleanManagedByteBuffer(256)) + using (IManagedByteBuffer huffmanData = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(256, AllocationOptions.Clean)) { ref byte huffmanDataRef = ref MemoryMarshal.GetReference(huffmanData.GetSpan()); for (int i = 2; i < remaining;) @@ -715,7 +715,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort byte huffmanTableSpec = (byte)this.InputStream.ReadByte(); this.InputStream.Read(huffmanData.Array, 0, 16); - using (IManagedByteBuffer codeLengths = this.configuration.MemoryAllocator.AllocateCleanManagedByteBuffer(17)) + using (IManagedByteBuffer codeLengths = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(17, AllocationOptions.Clean)) { ref byte codeLengthsRef = ref MemoryMarshal.GetReference(codeLengths.GetSpan()); int codeLengthSum = 0; @@ -725,7 +725,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort codeLengthSum += Unsafe.Add(ref codeLengthsRef, j) = Unsafe.Add(ref huffmanDataRef, j - 1); } - using (IManagedByteBuffer huffmanValues = this.configuration.MemoryAllocator.AllocateCleanManagedByteBuffer(256)) + using (IManagedByteBuffer huffmanValues = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(256, AllocationOptions.Clean)) { this.InputStream.Read(huffmanValues.Array, 0, codeLengthSum); diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 04d4f057c..5ac798aae 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -369,7 +369,7 @@ namespace SixLabors.ImageSharp.Formats.Png return false; } - buffer = this.MemoryAllocator.AllocateCleanManagedByteBuffer(bytesPerScanline * 8 / bits); + buffer = this.MemoryAllocator.AllocateManagedByteBuffer(bytesPerScanline * 8 / bits, AllocationOptions.Clean); byte[] result = buffer.Array; int mask = 0xFF >> (8 - bits); int resultOffset = 0; @@ -419,8 +419,8 @@ namespace SixLabors.ImageSharp.Formats.Png this.bytesPerSample = this.header.BitDepth / 8; } - this.previousScanline = this.MemoryAllocator.AllocateCleanManagedByteBuffer(this.bytesPerScanline); - this.scanline = this.configuration.MemoryAllocator.AllocateCleanManagedByteBuffer(this.bytesPerScanline); + this.previousScanline = this.MemoryAllocator.AllocateManagedByteBuffer(this.bytesPerScanline, AllocationOptions.Clean); + this.scanline = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(this.bytesPerScanline, AllocationOptions.Clean); } /// @@ -1427,7 +1427,7 @@ namespace SixLabors.ImageSharp.Formats.Png private IManagedByteBuffer ReadChunkData(int length) { // We rent the buffer here to return it afterwards in Decode() - IManagedByteBuffer buffer = this.configuration.MemoryAllocator.AllocateCleanManagedByteBuffer(length); + IManagedByteBuffer buffer = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(length, AllocationOptions.Clean); this.currentStream.Read(buffer.Array, 0, length); diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 69f04979c..0f67c18b1 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -643,9 +643,9 @@ namespace SixLabors.ImageSharp.Formats.Png this.bytesPerScanline = this.width * this.bytesPerPixel; int resultLength = this.bytesPerScanline + 1; - this.previousScanline = this.memoryAllocator.AllocateCleanManagedByteBuffer(this.bytesPerScanline); - this.rawScanline = this.memoryAllocator.AllocateCleanManagedByteBuffer(this.bytesPerScanline); - this.result = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.previousScanline = this.memoryAllocator.AllocateManagedByteBuffer(this.bytesPerScanline, AllocationOptions.Clean); + this.rawScanline = this.memoryAllocator.AllocateManagedByteBuffer(this.bytesPerScanline, AllocationOptions.Clean); + this.result = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); switch (this.pngFilterMethod) { @@ -654,29 +654,29 @@ namespace SixLabors.ImageSharp.Formats.Png case PngFilterMethod.Sub: - this.sub = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.sub = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); break; case PngFilterMethod.Up: - this.up = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.up = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); break; case PngFilterMethod.Average: - this.average = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.average = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); break; case PngFilterMethod.Paeth: - this.paeth = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.paeth = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); break; case PngFilterMethod.Adaptive: - this.sub = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); - this.up = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); - this.average = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); - this.paeth = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.sub = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); + this.up = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); + this.average = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); + this.paeth = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); break; } diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 93e888cca..aa650d380 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp this.configuration = configuration; this.MemoryAllocator = configuration.MemoryAllocator; - this.PixelBuffer = this.MemoryAllocator.Allocate2D(width, height, false); + this.PixelBuffer = this.MemoryAllocator.Allocate2D(width, height); this.MetaData = metaData; this.Clear(configuration.ParallelOptions, backgroundColor); } diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index b40884f4b..eca134101 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -29,7 +29,7 @@ portable True IOperation - 7.3 + Latest diff --git a/src/ImageSharp/Memory/AllocationOptions.cs b/src/ImageSharp/Memory/AllocationOptions.cs new file mode 100644 index 000000000..737762717 --- /dev/null +++ b/src/ImageSharp/Memory/AllocationOptions.cs @@ -0,0 +1,21 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.Memory +{ + /// + /// Options for allocating buffers. + /// + public enum AllocationOptions + { + /// + /// Indicates that the buffer should just be allocated. + /// + None, + + /// + /// Indicates that the allocated buffer should be cleaned. + /// + Clean + } +} diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs index f1c4c49c3..08f28c5b3 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs @@ -89,7 +89,7 @@ namespace SixLabors.Memory } /// - internal override IBuffer Allocate(int length, bool clear) + internal override IBuffer Allocate(int length, AllocationOptions options) { int itemSizeBytes = Unsafe.SizeOf(); int bufferSizeInBytes = length * itemSizeBytes; @@ -98,7 +98,7 @@ namespace SixLabors.Memory byte[] byteArray = pool.Rent(bufferSizeInBytes); var buffer = new Buffer(byteArray, length, pool); - if (clear) + if (options == AllocationOptions.Clean) { buffer.Clear(); } @@ -107,13 +107,13 @@ namespace SixLabors.Memory } /// - internal override IManagedByteBuffer AllocateManagedByteBuffer(int length, bool clear) + internal override IManagedByteBuffer AllocateManagedByteBuffer(int length, AllocationOptions options) { ArrayPool pool = this.GetArrayPool(length); byte[] byteArray = pool.Rent(length); var buffer = new ManagedByteBuffer(byteArray, length, pool); - if (clear) + if (options == AllocationOptions.Clean) { buffer.Clear(); } diff --git a/src/ImageSharp/Memory/MemoryAllocator.cs b/src/ImageSharp/Memory/MemoryAllocator.cs index 2195444fd..4a65848fc 100644 --- a/src/ImageSharp/Memory/MemoryAllocator.cs +++ b/src/ImageSharp/Memory/MemoryAllocator.cs @@ -9,23 +9,22 @@ namespace SixLabors.Memory public abstract class MemoryAllocator { /// - /// Allocates an of size , optionally - /// clearing the buffer before it gets returned. + /// Allocates an of size . /// /// Type of the data stored in the buffer /// Size of the buffer to allocate - /// True to clear the backing memory of the buffer + /// The allocation options. /// A buffer of values of type . - internal abstract IBuffer Allocate(int length, bool clear) + internal abstract IBuffer Allocate(int length, AllocationOptions options = AllocationOptions.None) where T : struct; /// - /// Allocates an + /// Allocates an . /// /// The requested buffer length - /// A value indicating whether to clean the buffer + /// The allocation options. /// The - internal abstract IManagedByteBuffer AllocateManagedByteBuffer(int length, bool clear); + internal abstract IManagedByteBuffer AllocateManagedByteBuffer(int length, AllocationOptions options = AllocationOptions.None); /// /// Releases all retained resources not being in use. diff --git a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs index ab4fc93b7..2f296636d 100644 --- a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs +++ b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs @@ -7,56 +7,17 @@ namespace SixLabors.Memory /// internal static class MemoryAllocatorExtensions { - /// - /// Allocates a of size . - /// Note: Depending on the implementation, the buffer may not cleared before - /// returning, so it may contain data from an earlier use. - /// - /// Type of the data stored in the buffer - /// The - /// Size of the buffer to allocate - /// A buffer of values of type . - public static IBuffer Allocate(this MemoryAllocator memoryAllocator, int length) + public static Buffer2D Allocate2D(this MemoryAllocator memoryAllocator, int width, int height, AllocationOptions options = AllocationOptions.None) where T : struct { - return memoryAllocator.Allocate(length, false); - } - - public static IBuffer AllocateClean(this MemoryAllocator memoryAllocator, int length) - where T : struct - { - return memoryAllocator.Allocate(length, true); - } - - public static IManagedByteBuffer AllocateManagedByteBuffer(this MemoryAllocator memoryAllocator, int length) - { - return memoryAllocator.AllocateManagedByteBuffer(length, false); - } - - public static IManagedByteBuffer AllocateCleanManagedByteBuffer(this MemoryAllocator memoryAllocator, int length) - { - return memoryAllocator.AllocateManagedByteBuffer(length, true); - } - - public static Buffer2D Allocate2D(this MemoryAllocator memoryAllocator, int width, int height, bool clear) - where T : struct - { - IBuffer buffer = memoryAllocator.Allocate(width * height, clear); + IBuffer buffer = memoryAllocator.Allocate(width * height, options); return new Buffer2D(buffer, width, height); } - public static Buffer2D Allocate2D(this MemoryAllocator memoryAllocator, Size size) - where T : struct => - Allocate2D(memoryAllocator, size.Width, size.Height, false); - - public static Buffer2D Allocate2D(this MemoryAllocator memoryAllocator, int width, int height) - where T : struct => - Allocate2D(memoryAllocator, width, height, false); - - public static Buffer2D AllocateClean2D(this MemoryAllocator memoryAllocator, int width, int height) + public static Buffer2D Allocate2D(this MemoryAllocator memoryAllocator, Size size, AllocationOptions options = AllocationOptions.None) where T : struct => - Allocate2D(memoryAllocator, width, height, true); + Allocate2D(memoryAllocator, size.Width, size.Height, options); /// /// Allocates padded buffers for BMP encoder/decoder. (Replacing old PixelRow/PixelArea) diff --git a/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs b/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs index df69cec6e..8cb057366 100644 --- a/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs +++ b/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs @@ -6,12 +6,12 @@ public sealed class SimpleGcMemoryAllocator : MemoryAllocator { /// - internal override IBuffer Allocate(int length, bool clear) + internal override IBuffer Allocate(int length, AllocationOptions options) { return new BasicArrayBuffer(new T[length]); } - internal override IManagedByteBuffer AllocateManagedByteBuffer(int length, bool clear) + internal override IManagedByteBuffer AllocateManagedByteBuffer(int length, AllocationOptions options) { return new BasicByteBuffer(new byte[length]); } diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs index 6828f11dc..84e528d24 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -122,7 +122,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -161,7 +161,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -200,7 +200,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -239,7 +239,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -278,7 +278,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -317,7 +317,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -356,7 +356,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -395,7 +395,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -434,7 +434,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -473,7 +473,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -512,7 +512,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -551,7 +551,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -590,7 +590,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -629,7 +629,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -668,7 +668,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -707,7 +707,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -746,7 +746,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -785,7 +785,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -824,7 +824,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt index 07888a756..cf16f9705 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; - using SixLabors.ImageSharp.Memory; + using SixLabors.Memory; /// @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3, false)) + using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); diff --git a/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs index 977b939a1..6c2e6173f 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization this.Width = width; this.Height = height; this.Palette = palette; - this.pixels = memoryAllocator.AllocateCleanManagedByteBuffer(width * height); + this.pixels = memoryAllocator.AllocateManagedByteBuffer(width * height, AllocationOptions.Clean); } /// diff --git a/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs index 7c2ff77e3..9a2a84e81 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs @@ -139,13 +139,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization try { - this.vwt = memoryAllocator.AllocateClean(TableLength); - this.vmr = memoryAllocator.AllocateClean(TableLength); - this.vmg = memoryAllocator.AllocateClean(TableLength); - this.vmb = memoryAllocator.AllocateClean(TableLength); - this.vma = memoryAllocator.AllocateClean(TableLength); - this.m2 = memoryAllocator.AllocateClean(TableLength); - this.tag = memoryAllocator.AllocateClean(TableLength); + this.vwt = memoryAllocator.Allocate(TableLength, AllocationOptions.Clean); + this.vmr = memoryAllocator.Allocate(TableLength, AllocationOptions.Clean); + this.vmg = memoryAllocator.Allocate(TableLength, AllocationOptions.Clean); + this.vmb = memoryAllocator.Allocate(TableLength, AllocationOptions.Clean); + this.vma = memoryAllocator.Allocate(TableLength, AllocationOptions.Clean); + this.m2 = memoryAllocator.Allocate(TableLength, AllocationOptions.Clean); + this.tag = memoryAllocator.Allocate(TableLength, AllocationOptions.Clean); return base.QuantizeFrame(image); } diff --git a/src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs b/src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs index 581a3353a..3983ea091 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The size of the destination window public WeightsBuffer(MemoryAllocator memoryAllocator, int sourceSize, int destinationSize) { - this.dataBuffer = memoryAllocator.Allocate2D(sourceSize, destinationSize, true); + this.dataBuffer = memoryAllocator.Allocate2D(sourceSize, destinationSize, AllocationOptions.Clean); this.Weights = new WeightsWindow[destinationSize]; } diff --git a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs index c8e304b41..14fbe8225 100644 --- a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs @@ -126,18 +126,18 @@ namespace SixLabors.ImageSharp.Tests.Memory } [Theory] - [InlineData(false)] - [InlineData(true)] - public void CleaningRequests_AreControlledByAllocationParameter_Clean(bool clean) + [InlineData(AllocationOptions.None)] + [InlineData(AllocationOptions.Clean)] + public void CleaningRequests_AreControlledByAllocationParameter_Clean(AllocationOptions options) { using (IBuffer firstAlloc = this.MemoryAllocator.Allocate(42)) { firstAlloc.GetSpan().Fill(666); } - using (IBuffer secondAlloc = this.MemoryAllocator.Allocate(42, clean)) + using (IBuffer secondAlloc = this.MemoryAllocator.Allocate(42, options)) { - int expected = clean ? 0 : 666; + int expected = options == AllocationOptions.Clean ? 0 : 666; Assert.Equal(expected, secondAlloc.GetSpan()[0]); } } diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index 301a76f56..5dd8572dc 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -34,11 +34,11 @@ namespace SixLabors.ImageSharp.Tests.Memory private class MockMemoryAllocator : MemoryAllocator { - internal override IBuffer Allocate(int length, bool clear) + internal override IBuffer Allocate(int length, AllocationOptions options) { var array = new T[length + 42]; - if (!clear) + if (options == AllocationOptions.None) { Span data = MemoryMarshal.Cast(array.AsSpan()); for (int i = 0; i < data.Length; i++) @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Memory return new BasicArrayBuffer(array, length); } - internal override IManagedByteBuffer AllocateManagedByteBuffer(int length, bool clear) + internal override IManagedByteBuffer AllocateManagedByteBuffer(int length, AllocationOptions options) { throw new NotImplementedException(); } @@ -72,7 +72,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void CreateClean() { - using (Buffer2D buffer = this.MemoryAllocator.Allocate2D(42, 42, true)) + using (Buffer2D buffer = this.MemoryAllocator.Allocate2D(42, 42, AllocationOptions.Clean)) { Span span = buffer.GetSpan(); for (int j = 0; j < span.Length; j++) diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs index a0a68a705..fd3331288 100644 --- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs @@ -124,12 +124,12 @@ namespace SixLabors.ImageSharp.Tests.Memory this.TestCanAllocateCleanBuffer(desiredLength); } - private IBuffer Allocate(int desiredLength, bool clean, bool managedByteBuffer) + private IBuffer Allocate(int desiredLength, AllocationOptions options, bool managedByteBuffer) where T : struct { if (managedByteBuffer) { - if (!(this.MemoryAllocator.AllocateManagedByteBuffer(desiredLength, clean) is IBuffer buffer)) + if (!(this.MemoryAllocator.AllocateManagedByteBuffer(desiredLength, options) is IBuffer buffer)) { throw new InvalidOperationException("typeof(T) != typeof(byte)"); } @@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.Tests.Memory return buffer; } - return this.MemoryAllocator.Allocate(desiredLength, clean); + return this.MemoryAllocator.Allocate(desiredLength, options); } private void TestCanAllocateCleanBuffer(int desiredLength, bool testManagedByteBuffer = false) @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Tests.Memory for (int i = 0; i < 10; i++) { - using (IBuffer buffer = this.Allocate(desiredLength, true, testManagedByteBuffer)) + using (IBuffer buffer = this.Allocate(desiredLength, AllocationOptions.Clean, testManagedByteBuffer)) { Assert.True(buffer.GetSpan().SequenceEqual(expected)); } @@ -172,7 +172,7 @@ namespace SixLabors.ImageSharp.Tests.Memory private void TestSpanPropertyIsAlwaysTheSame(int desiredLength, bool testManagedByteBuffer = false) where T : struct { - using (IBuffer buffer = this.Allocate(desiredLength, false, testManagedByteBuffer)) + using (IBuffer buffer = this.Allocate(desiredLength, AllocationOptions.None, testManagedByteBuffer)) { ref T a = ref MemoryMarshal.GetReference(buffer.GetSpan()); ref T b = ref MemoryMarshal.GetReference(buffer.GetSpan()); @@ -201,7 +201,7 @@ namespace SixLabors.ImageSharp.Tests.Memory private void TestWriteAndReadElements(int desiredLength, Func getExpectedValue, bool testManagedByteBuffer = false) where T : struct { - using (IBuffer buffer = this.Allocate(desiredLength, false, testManagedByteBuffer)) + using (IBuffer buffer = this.Allocate(desiredLength, AllocationOptions.None, testManagedByteBuffer)) { T[] expectedVals = new T[buffer.Length()]; @@ -247,7 +247,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { var dummy = default(T); - using (IBuffer buffer = this.Allocate(desiredLength, false, testManagedByteBuffer)) + using (IBuffer buffer = this.Allocate(desiredLength, AllocationOptions.None, testManagedByteBuffer)) { Assert.ThrowsAny( () => From fe9eaac426f3964a785d493cc018e25a5a88f0bb Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 13 Jul 2018 21:20:23 +1000 Subject: [PATCH 49/68] Update xml docs. --- src/ImageSharp/MetaData/ImageMetaData.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/MetaData/ImageMetaData.cs b/src/ImageSharp/MetaData/ImageMetaData.cs index af5cc6191..40880bd08 100644 --- a/src/ImageSharp/MetaData/ImageMetaData.cs +++ b/src/ImageSharp/MetaData/ImageMetaData.cs @@ -14,13 +14,13 @@ namespace SixLabors.ImageSharp.MetaData { /// /// The default horizontal resolution value (dots per inch) in x direction. - /// The default value is 96 dots per inch. + /// The default value is 96 . /// public const double DefaultHorizontalResolution = 96; /// /// The default vertical resolution value (dots per inch) in y direction. - /// The default value is 96 dots per inch. + /// The default value is 96 . /// public const double DefaultVerticalResolution = 96; @@ -102,6 +102,10 @@ namespace SixLabors.ImageSharp.MetaData /// /// Gets or sets unit of measure used when reporting resolution. + /// 00 : No units; width:height pixel aspect ratio = Ydensity:Xdensity + /// 01 : Pixels per inch (2.54 cm) + /// 02 : Pixels per centimeter + /// 03 : Pixels per meter /// public PixelResolutionUnit ResolutionUnits { get; set; } = PixelResolutionUnit.PixelsPerInch; From 16422932b05f22cbd7631a17a49d58eaba9f93b2 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 13 Jul 2018 21:20:54 +1000 Subject: [PATCH 50/68] See if we can fix appveyor by forcing redirects. --- src/ImageSharp/ImageSharp.csproj | 2 +- tests/ImageSharp.Tests/ImageSharp.Tests.csproj | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index b40884f4b..6646feaa0 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -29,7 +29,7 @@ portable True IOperation - 7.3 + latest diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 9e15b6aba..31b81f2a2 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -2,13 +2,14 @@ net471;netcoreapp2.0;netcoreapp2.1;net47;net462 True - 7.2 + latest full portable True SixLabors.ImageSharp.Tests SixLabors.ImageSharp.Tests AnyCPU;x64;x86 + true true @@ -22,9 +23,6 @@ true - - - From 50e5a639a1a3dd134041dcebc0fcacddd2e210f8 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 13 Jul 2018 21:27:45 +1000 Subject: [PATCH 51/68] Explicitly add reference. --- tests/ImageSharp.Tests/ImageSharp.Tests.csproj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 31b81f2a2..7eeff2fdd 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -9,7 +9,6 @@ SixLabors.ImageSharp.Tests SixLabors.ImageSharp.Tests AnyCPU;x64;x86 - true true @@ -23,8 +22,8 @@ true - - + + From 9ed637dcb1fad263894b8563b0667e70520e0df1 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 13 Jul 2018 21:39:53 +1000 Subject: [PATCH 52/68] Use previous VS environment. --- appveyor.yml | 2 +- src/ImageSharp/ImageSharp.csproj | 2 +- tests/ImageSharp.Tests/ImageSharp.Tests.csproj | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 3e6b79bfc..5d84e6cea 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ version: 1.0.0.{build} -image: Visual Studio 2017 +image: Previous Visual Studio 2017 # prevent the double build when a branch has an active PR skip_branch_with_pr: true diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 6646feaa0..b40884f4b 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -29,7 +29,7 @@ portable True IOperation - latest + 7.3 diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 7eeff2fdd..9e15b6aba 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -2,7 +2,7 @@ net471;netcoreapp2.0;netcoreapp2.1;net47;net462 True - latest + 7.2 full portable True @@ -22,8 +22,11 @@ true - - + + + + + From 4fcefc5e1fb06ed4952636d4209e8598898d010f Mon Sep 17 00:00:00 2001 From: popow Date: Sun, 15 Jul 2018 10:36:46 +0200 Subject: [PATCH 53/68] moved extension to the processing namespace and the processor accordingly into Processors namespace --- .../{Normalization => }/HistogramEqualizationExtension.cs | 5 +++-- .../Normalization/HistogramEqualizationProcessor.cs | 7 +++---- .../Processing/Normalization/HistogramEqualizationTests.cs | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) rename src/ImageSharp/Processing/{Normalization => }/HistogramEqualizationExtension.cs (85%) rename src/ImageSharp/Processing/{ => Processors}/Normalization/HistogramEqualizationProcessor.cs (95%) diff --git a/src/ImageSharp/Processing/Normalization/HistogramEqualizationExtension.cs b/src/ImageSharp/Processing/HistogramEqualizationExtension.cs similarity index 85% rename from src/ImageSharp/Processing/Normalization/HistogramEqualizationExtension.cs rename to src/ImageSharp/Processing/HistogramEqualizationExtension.cs index aa3c86d24..b472a2750 100644 --- a/src/ImageSharp/Processing/Normalization/HistogramEqualizationExtension.cs +++ b/src/ImageSharp/Processing/HistogramEqualizationExtension.cs @@ -2,8 +2,9 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors.Normalization; -namespace SixLabors.ImageSharp.Processing.Normalization +namespace SixLabors.ImageSharp.Processing { /// /// Adds extension that allows applying an HistogramEqualization to the image. @@ -16,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization /// The pixel format. /// The image this method extends. /// The number of different luminance levels. Typical values are 256 for 8-bit grayscale images - /// or 65536 for 16-bit grayscale images.Defaults to 65536. + /// or 65536 for 16-bit grayscale images. Defaults to 65536. /// A histogram equalized grayscale image. public static IImageProcessingContext HistogramEqualization(this IImageProcessingContext source, int luminanceLevels = 65536) where TPixel : struct, IPixel diff --git a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs similarity index 95% rename from src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs rename to src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs index 782df4762..fdd439a33 100644 --- a/src/ImageSharp/Processing/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs @@ -5,11 +5,10 @@ using System; using System.Numerics; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Normalization +namespace SixLabors.ImageSharp.Processing.Processors.Normalization { /// /// Applies a global histogram equalization to the image. @@ -22,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization /// Initializes a new instance of the class. /// /// The number of different luminance levels. Typical values are 256 for 8-bit grayscale images - /// or 65536 for 16-bit grayscale images.Defaults to 65536. + /// or 65536 for 16-bit grayscale images. Defaults to 65536. public HistogramEqualizationProcessor(int luminanceLevels = 65536) { Guard.MustBeGreaterThan(luminanceLevels, 0, nameof(luminanceLevels)); @@ -117,7 +116,7 @@ namespace SixLabors.ImageSharp.Processing.Normalization { // Convert to grayscale using ITU-R Recommendation BT.709 var vector = sourcePixel.ToVector4(); - int luminance = Convert.ToInt32(((.2126F * vector.X) + (.7152F * vector.Y) + (.0722F * vector.Y)) * luminanceLevels); + int luminance = Convert.ToInt32(((.2126F * vector.X) + (.7152F * vector.Y) + (.0722F * vector.Y)) * (luminanceLevels - 1)); return luminance; } diff --git a/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs index 2fc49db8a..ebecfec5a 100644 --- a/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs +++ b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs @@ -3,7 +3,6 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Normalization; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Normalization From 0da5e68854df5e7c76f09541c3e9c8f9c5451828 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 16 Jul 2018 23:57:39 +1000 Subject: [PATCH 54/68] Cleanup and remove double cast. --- .../HistogramEqualizationExtension.cs | 18 +++++++-- .../HistogramEqualizationProcessor.cs | 38 ++++++++++--------- .../HistogramEqualizationTests.cs | 7 ++-- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/ImageSharp/Processing/HistogramEqualizationExtension.cs b/src/ImageSharp/Processing/HistogramEqualizationExtension.cs index b472a2750..8dabfcc05 100644 --- a/src/ImageSharp/Processing/HistogramEqualizationExtension.cs +++ b/src/ImageSharp/Processing/HistogramEqualizationExtension.cs @@ -7,19 +7,29 @@ using SixLabors.ImageSharp.Processing.Processors.Normalization; namespace SixLabors.ImageSharp.Processing { /// - /// Adds extension that allows applying an HistogramEqualization to the image. + /// Adds extension that allow the adjustment of the contrast of an image via its histogram. /// public static class HistogramEqualizationExtension { + /// + /// Equalizes the histogram of an image to increases the global contrast using 65536 luminance levels. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static IImageProcessingContext HistogramEqualization(this IImageProcessingContext source) + where TPixel : struct, IPixel + => HistogramEqualization(source, 65536); + /// /// Equalizes the histogram of an image to increases the global contrast. /// /// The pixel format. /// The image this method extends. /// The number of different luminance levels. Typical values are 256 for 8-bit grayscale images - /// or 65536 for 16-bit grayscale images. Defaults to 65536. - /// A histogram equalized grayscale image. - public static IImageProcessingContext HistogramEqualization(this IImageProcessingContext source, int luminanceLevels = 65536) + /// or 65536 for 16-bit grayscale images. + /// The . + public static IImageProcessingContext HistogramEqualization(this IImageProcessingContext source, int luminanceLevels) where TPixel : struct, IPixel => source.ApplyProcessor(new HistogramEqualizationProcessor(luminanceLevels)); } diff --git a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs index fdd439a33..ba56e392f 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs @@ -3,6 +3,7 @@ using System; using System.Numerics; +using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; @@ -21,8 +22,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization /// Initializes a new instance of the class. /// /// The number of different luminance levels. Typical values are 256 for 8-bit grayscale images - /// or 65536 for 16-bit grayscale images. Defaults to 65536. - public HistogramEqualizationProcessor(int luminanceLevels = 65536) + /// or 65536 for 16-bit grayscale images. + public HistogramEqualizationProcessor(int luminanceLevels) { Guard.MustBeGreaterThan(luminanceLevels, 0, nameof(luminanceLevels)); @@ -30,7 +31,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization } /// - /// Gets the luminance levels. + /// Gets the number of luminance levels. /// public int LuminanceLevels { get; } @@ -41,7 +42,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization int numberOfPixels = source.Width * source.Height; Span pixels = source.GetPixelSpan(); - // build the histogram of the grayscale levels + // Build the histogram of the grayscale levels. using (IBuffer histogramBuffer = memoryAllocator.AllocateClean(this.LuminanceLevels)) using (IBuffer cdfBuffer = memoryAllocator.AllocateClean(this.LuminanceLevels)) { @@ -53,33 +54,33 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization histogram[luminance]++; } - // calculate the cumulative distribution function, which will map each input pixel to a new value + // Calculate the cumulative distribution function, which will map each input pixel to a new value. Span cdf = cdfBuffer.GetSpan(); - int cdfMin = this.CaluclateCdf(cdf, histogram); + int cdfMin = this.CalculateCdf(cdf, histogram); - // apply the cdf to each pixel of the image - double numberOfPixelsMinusCdfMin = (double)(numberOfPixels - cdfMin); + // Apply the cdf to each pixel of the image + float numberOfPixelsMinusCdfMin = numberOfPixels - cdfMin; for (int i = 0; i < pixels.Length; i++) { TPixel sourcePixel = pixels[i]; int luminance = this.GetLuminance(sourcePixel, this.LuminanceLevels); - double luminanceEqualized = cdf[luminance] / numberOfPixelsMinusCdfMin; + float luminanceEqualized = cdf[luminance] / numberOfPixelsMinusCdfMin; - pixels[i].PackFromVector4(new Vector4((float)luminanceEqualized)); + pixels[i].PackFromVector4(new Vector4(luminanceEqualized)); } } } /// - /// Calculate the cumulative distribution function + /// Calculates the cumulative distribution function. /// - /// The array holding the cdf - /// The histogram of the input image - /// The first none zero value of the cdf - private int CaluclateCdf(Span cdf, Span histogram) + /// The array holding the cdf. + /// The histogram of the input image. + /// The first none zero value of the cdf. + private int CalculateCdf(Span cdf, Span histogram) { - // calculate the cumulative histogram + // Calculate the cumulative histogram int histSum = 0; for (int i = 0; i < histogram.Length; i++) { @@ -87,7 +88,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization cdf[i] = histSum; } - // get the first none zero value of the cumulative histogram + // Get the first none zero value of the cumulative histogram int cdfMin = 0; for (int i = 0; i < histogram.Length; i++) { @@ -98,7 +99,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization } } - // creating the lookup table: subtracting cdf min, so we do not need to do that inside the for loop + // Creating the lookup table: subtracting cdf min, so we do not need to do that inside the for loop for (int i = 0; i < histogram.Length; i++) { cdf[i] = Math.Max(0, cdf[i] - cdfMin); @@ -112,6 +113,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization /// /// The pixel to get the luminance from /// The number of luminance levels (256 for 8 bit, 65536 for 16 bit grayscale images) + [MethodImpl(InliningOptions.ShortMethod)] private int GetLuminance(TPixel sourcePixel, int luminanceLevels) { // Convert to grayscale using ITU-R Recommendation BT.709 diff --git a/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs index ebecfec5a..1595ed32c 100644 --- a/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs +++ b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization [InlineData(65536)] public void HistogramEqualizationTest(int luminanceLevels) { - // arrange + // Arrange byte[] pixels = new byte[] { 52, 55, 61, 59, 70, 61, 76, 61, @@ -26,6 +26,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization 69, 85, 64, 58, 55, 61, 65, 83, 70, 87, 69, 68, 65, 73, 78, 90 }; + var image = new Image(8, 8); for (int y = 0; y < 8; y++) { @@ -48,10 +49,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization 146, 206, 130, 117, 85, 166, 182, 215 }; - // act + // Act image.Mutate(x => x.HistogramEqualization(luminanceLevels)); - // assert + // Assert for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) From dfbf5536aeef9b01ecec3d520748e5cfdaaeb4d7 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 18 Jul 2018 11:53:35 +1000 Subject: [PATCH 55/68] Fix git merge --- src/ImageSharp/Memory/AllocationOptions.cs | 2 +- .../Normalization/HistogramEqualizationProcessor.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Memory/AllocationOptions.cs b/src/ImageSharp/Memory/AllocationOptions.cs index 737762717..5eda00505 100644 --- a/src/ImageSharp/Memory/AllocationOptions.cs +++ b/src/ImageSharp/Memory/AllocationOptions.cs @@ -14,7 +14,7 @@ namespace SixLabors.Memory None, /// - /// Indicates that the allocated buffer should be cleaned. + /// Indicates that the allocated buffer should be cleaned following allocation. /// Clean } diff --git a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs index ba56e392f..b834b8968 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs @@ -43,8 +43,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization Span pixels = source.GetPixelSpan(); // Build the histogram of the grayscale levels. - using (IBuffer histogramBuffer = memoryAllocator.AllocateClean(this.LuminanceLevels)) - using (IBuffer cdfBuffer = memoryAllocator.AllocateClean(this.LuminanceLevels)) + using (IBuffer histogramBuffer = memoryAllocator.Allocate(this.LuminanceLevels, AllocationOptions.Clean)) + using (IBuffer cdfBuffer = memoryAllocator.Allocate(this.LuminanceLevels, AllocationOptions.Clean)) { Span histogram = histogramBuffer.GetSpan(); for (int i = 0; i < pixels.Length; i++) From 706babe2a2caa07185c86a16ffe17fc6d51afa78 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 22 Jul 2018 17:01:39 +0200 Subject: [PATCH 56/68] introducing BufferManager --- ImageSharp.sln.DotSettings | 5 +- src/ImageSharp/Memory/BufferManager.cs | 73 ++++++++ src/ImageSharp/Memory/IBuffer{T}.cs | 8 +- .../Memory/MemoryAllocatorExtensions.cs | 11 +- .../ImageSharp.Tests/Memory/Buffer2DTests.cs | 50 ++---- .../Memory/BufferManagerTests.cs | 158 ++++++++++++++++++ .../Processors/Transforms/ResizeTests.cs | 3 +- .../TestUtilities/TestMemoryAllocator.cs | 55 ++++++ .../TestUtilities/TestMemoryManager.cs | 19 +-- .../TestUtilities/TestUtils.cs | 2 +- 10 files changed, 328 insertions(+), 56 deletions(-) create mode 100644 src/ImageSharp/Memory/BufferManager.cs create mode 100644 tests/ImageSharp.Tests/Memory/BufferManagerTests.cs create mode 100644 tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs diff --git a/ImageSharp.sln.DotSettings b/ImageSharp.sln.DotSettings index 435aad73b..432f4524a 100644 --- a/ImageSharp.sln.DotSettings +++ b/ImageSharp.sln.DotSettings @@ -343,8 +343,11 @@ <Entry DisplayName="All other members" /> </TypePattern> </Patterns> - True + False True + // Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + AC DC DCT diff --git a/src/ImageSharp/Memory/BufferManager.cs b/src/ImageSharp/Memory/BufferManager.cs new file mode 100644 index 000000000..f1cbb7512 --- /dev/null +++ b/src/ImageSharp/Memory/BufferManager.cs @@ -0,0 +1,73 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Buffers; + +namespace SixLabors.Memory +{ + /// + /// Holds a that is either OWNED or CONSUMED. + /// Implements content transfer logic in that depends on the ownership status. + /// This is needed to transfer the contents of a temporary to a persistent + /// + internal struct BufferManager : IDisposable + { + public BufferManager(IMemoryOwner memoryOwner) + { + this.MemoryOwner = memoryOwner; + this.Memory = memoryOwner.Memory; + } + + public BufferManager(Memory memory) + { + this.Memory = memory; + this.MemoryOwner = null; + } + + public IMemoryOwner MemoryOwner { get; private set; } + + public Memory Memory { get; private set; } + + public bool OwnsMemory => this.MemoryOwner != null; + + /// + /// Swaps the contents of 'destination' with 'source' if the buffers are owned (1), + /// copies the contents of 'source' to 'destination' otherwise (2). Buffers should be of same size in case 2! + /// + public static void SwapOrCopyContent(ref BufferManager destination, ref BufferManager source) + { + if (source.OwnsMemory && destination.OwnsMemory) + { + SwapContents(ref destination, ref source); + } + else + { + if (destination.Memory.Length != source.Memory.Length) + { + throw new InvalidOperationException("SwapOrCopyContents(): buffers should both owned or the same size!"); + } + + source.Memory.CopyTo(destination.Memory); + } + } + + /// + public void Dispose() + { + this.MemoryOwner?.Dispose(); + } + + private static void SwapContents(ref BufferManager a, ref BufferManager b) + { + IMemoryOwner tempOwner = a.MemoryOwner; + Memory tempMemory = a.Memory; + + a.MemoryOwner = b.MemoryOwner; + a.Memory = b.Memory; + + b.MemoryOwner = tempOwner; + b.Memory = tempMemory; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Memory/IBuffer{T}.cs b/src/ImageSharp/Memory/IBuffer{T}.cs index 847f2741d..73406971a 100644 --- a/src/ImageSharp/Memory/IBuffer{T}.cs +++ b/src/ImageSharp/Memory/IBuffer{T}.cs @@ -19,14 +19,14 @@ namespace SixLabors.Memory where T : struct { /// - /// Gets the ownerd/consumed by this buffer. + /// Gets a value indicating whether this instance is owning the . /// - Memory Memory { get; } + bool IsMemoryOwner { get; } /// - /// Gets a value indicating whether this instance is owning the . + /// Gets the ownerd/consumed by this buffer. /// - bool IsMemoryOwner { get; } + Memory Memory { get; } /// /// Gets the span to the memory "promised" by this buffer when it's OWNED (1). diff --git a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs index 2f296636d..899d2f0f6 100644 --- a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs +++ b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs @@ -7,7 +7,11 @@ namespace SixLabors.Memory /// internal static class MemoryAllocatorExtensions { - public static Buffer2D Allocate2D(this MemoryAllocator memoryAllocator, int width, int height, AllocationOptions options = AllocationOptions.None) + public static Buffer2D Allocate2D( + this MemoryAllocator memoryAllocator, + int width, + int height, + AllocationOptions options = AllocationOptions.None) where T : struct { IBuffer buffer = memoryAllocator.Allocate(width * height, options); @@ -15,7 +19,10 @@ namespace SixLabors.Memory return new Buffer2D(buffer, width, height); } - public static Buffer2D Allocate2D(this MemoryAllocator memoryAllocator, Size size, AllocationOptions options = AllocationOptions.None) + public static Buffer2D Allocate2D( + this MemoryAllocator memoryAllocator, + Size size, + AllocationOptions options = AllocationOptions.None) where T : struct => Allocate2D(memoryAllocator, size.Width, size.Height, options); diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index 5dd8572dc..af9c8bd5b 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -1,20 +1,20 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Tests.Memory -{ - using System; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; - using SixLabors.ImageSharp.PixelFormats; - using SixLabors.Memory; - using SixLabors.ImageSharp.Tests.Common; - using SixLabors.Primitives; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; +using SixLabors.Primitives; - using Xunit; +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests.Memory +{ public class Buffer2DTests { // ReSharper disable once ClassNeverInstantiated.Local @@ -30,31 +30,7 @@ namespace SixLabors.ImageSharp.Tests.Memory } } - private MemoryAllocator MemoryAllocator { get; } = new MockMemoryAllocator(); - - private class MockMemoryAllocator : MemoryAllocator - { - internal override IBuffer Allocate(int length, AllocationOptions options) - { - var array = new T[length + 42]; - - if (options == AllocationOptions.None) - { - Span data = MemoryMarshal.Cast(array.AsSpan()); - for (int i = 0; i < data.Length; i++) - { - data[i] = 42; - } - } - - return new BasicArrayBuffer(array, length); - } - - internal override IManagedByteBuffer AllocateManagedByteBuffer(int length, AllocationOptions options) - { - throw new NotImplementedException(); - } - } + private MemoryAllocator MemoryAllocator { get; } = new TestMemoryAllocator(); [Theory] [InlineData(7, 42)] @@ -134,7 +110,7 @@ namespace SixLabors.ImageSharp.Tests.Memory public class SwapOrCopyContent { - private MemoryAllocator MemoryAllocator { get; } = new MockMemoryAllocator(); + private MemoryAllocator MemoryAllocator { get; } = new TestMemoryAllocator(); [Fact] public void WhenBothBuffersAreMemoryOwners_ShouldSwap() diff --git a/tests/ImageSharp.Tests/Memory/BufferManagerTests.cs b/tests/ImageSharp.Tests/Memory/BufferManagerTests.cs new file mode 100644 index 000000000..d08e734e8 --- /dev/null +++ b/tests/ImageSharp.Tests/Memory/BufferManagerTests.cs @@ -0,0 +1,158 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Buffers; + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; + +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests.Memory +{ + public class BufferManagerTests + { + public class Construction + { + [Fact] + public void InitializeAsOwner_MemoryOwner_IsPresent() + { + var data = new Rgba32[21]; + var mmg = new TestMemoryManager(data); + + var a = new BufferManager(mmg); + + Assert.Equal(mmg, a.MemoryOwner); + Assert.Equal(mmg.Memory, a.Memory); + Assert.True(a.OwnsMemory); + } + + [Fact] + public void InitializeAsObserver_MemoryOwner_IsNull() + { + var data = new Rgba32[21]; + var mmg = new TestMemoryManager(data); + + var a = new BufferManager(mmg.Memory); + + Assert.Null(a.MemoryOwner); + Assert.Equal(mmg.Memory, a.Memory); + Assert.False(a.OwnsMemory); + } + } + + public class Dispose + { + [Fact] + public void WhenOwnershipIsTransfered_ShouldDisposeMemoryOwner() + { + var mmg = new TestMemoryManager(new int[10]); + var bmg = new BufferManager(mmg); + + bmg.Dispose(); + Assert.True(mmg.IsDisposed); + } + + [Fact] + public void WhenMemoryObserver_ShouldNotDisposeAnything() + { + var mmg = new TestMemoryManager(new int[10]); + var bmg = new BufferManager(mmg.Memory); + + bmg.Dispose(); + Assert.False(mmg.IsDisposed); + } + } + + public class SwapOrCopyContent + { + private MemoryAllocator MemoryAllocator { get; } = new TestMemoryAllocator(); + + private BufferManager AllocateBufferManager(int length, AllocationOptions options = AllocationOptions.None) + where T : struct + { + var owner = (IMemoryOwner)this.MemoryAllocator.Allocate(length, options); + return new BufferManager(owner); + } + + [Fact] + public void WhenBothAreMemoryOwners_ShouldSwap() + { + BufferManager a = this.AllocateBufferManager(13); + BufferManager b = this.AllocateBufferManager(17); + + IMemoryOwner aa = a.MemoryOwner; + IMemoryOwner bb = b.MemoryOwner; + + Memory aaa = a.Memory; + Memory bbb = b.Memory; + + BufferManager.SwapOrCopyContent(ref a, ref b); + + Assert.Equal(bb, a.MemoryOwner); + Assert.Equal(aa, b.MemoryOwner); + + Assert.Equal(bbb, a.Memory); + Assert.Equal(aaa, b.Memory); + Assert.NotEqual(a.Memory, b.Memory); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void WhenDestIsNotMemoryOwner_SameSize_ShouldCopy(bool sourceIsOwner) + { + var data = new Rgba32[21]; + var color = new Rgba32(1, 2, 3, 4); + + var destOwner = new TestMemoryManager(data); + var dest = new BufferManager(destOwner.Memory); + + var sourceOwner = (IMemoryOwner)this.MemoryAllocator.Allocate(21); + + BufferManager source = sourceIsOwner + ? new BufferManager(sourceOwner) + : new BufferManager(sourceOwner.Memory); + + sourceOwner.Memory.Span[10] = color; + + // Act: + BufferManager.SwapOrCopyContent(ref dest, ref source); + + // Assert: + Assert.Equal(color, dest.Memory.Span[10]); + Assert.NotEqual(sourceOwner, dest.MemoryOwner); + Assert.NotEqual(destOwner, source.MemoryOwner); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void WhenDestIsNotMemoryOwner_DifferentSize_Throws(bool sourceIsOwner) + { + var data = new Rgba32[21]; + var color = new Rgba32(1, 2, 3, 4); + + var destOwner = new TestMemoryManager(data); + var dest = new BufferManager(destOwner.Memory); + + var sourceOwner = (IMemoryOwner)this.MemoryAllocator.Allocate(22); + + BufferManager source = sourceIsOwner + ? new BufferManager(sourceOwner) + : new BufferManager(sourceOwner.Memory); + sourceOwner.Memory.Span[10] = color; + + // Act: + Assert.ThrowsAny( + () => BufferManager.SwapOrCopyContent(ref dest, ref source) + ); + + Assert.Equal(color, source.Memory.Span[10]); + Assert.NotEqual(color, dest.Memory.Span[10]); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index c7efbb1e0..746d8da16 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -3,6 +3,7 @@ using System; +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Transforms; @@ -91,7 +92,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { using (Image image0 = provider.GetImage()) { - var mmg = TestMemoryManager.CreateAsCopyOfPixelData(image0); + var mmg = TestMemoryManager.CreateAsCopyOf(image0.GetPixelSpan()); using (var image1 = Image.WrapMemory(mmg.Memory, image0.Width, image0.Height)) { diff --git a/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs b/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs new file mode 100644 index 000000000..7993b3e99 --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs @@ -0,0 +1,55 @@ +using System; +using System.Runtime.InteropServices; + +using SixLabors.Memory; + +namespace SixLabors.ImageSharp.Tests.Memory +{ + internal class TestMemoryAllocator : MemoryAllocator + { + public TestMemoryAllocator(byte dirtyValue = 42) + { + this.DirtyValue = dirtyValue; + } + + /// + /// The value to initilazie the result buffer with, with non-clean options () + /// + public byte DirtyValue { get; } + + internal override IBuffer Allocate(int length, AllocationOptions options = AllocationOptions.None) + { + T[] array = this.AllocateArray(length, options); + + return new BasicArrayBuffer(array, length); + } + + internal override IManagedByteBuffer AllocateManagedByteBuffer(int length, AllocationOptions options = AllocationOptions.None) + { + byte[] array = this.AllocateArray(length, options); + return new ManagedByteBuffer(array); + } + + private T[] AllocateArray(int length, AllocationOptions options) + where T : struct + { + var array = new T[length + 42]; + + if (options == AllocationOptions.None) + { + Span data = MemoryMarshal.Cast(array.AsSpan()); + data.Fill(this.DirtyValue); + } + + return array; + } + + private class ManagedByteBuffer : BasicArrayBuffer, IManagedByteBuffer + { + public ManagedByteBuffer(byte[] array) + : base(array) + { + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs b/tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs index e7ecb2dda..ce3cfbc9e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs @@ -7,18 +7,16 @@ namespace SixLabors.ImageSharp.Tests using SixLabors.ImageSharp.PixelFormats; class TestMemoryManager : MemoryManager - where T : struct, IPixel + where T : struct { public TestMemoryManager(T[] pixelArray) { this.PixelArray = pixelArray; } - public T[] PixelArray { get; } + public T[] PixelArray { get; private set; } - protected override void Dispose(bool disposing) - { - } + public bool IsDisposed { get; private set; } public override Span GetSpan() { @@ -35,16 +33,17 @@ namespace SixLabors.ImageSharp.Tests throw new NotImplementedException(); } - public static TestMemoryManager CreateAsCopyOfPixelData(Span pixelData) + public static TestMemoryManager CreateAsCopyOf(Span copyThisBuffer) { - var pixelArray = new T[pixelData.Length]; - pixelData.CopyTo(pixelArray); + var pixelArray = new T[copyThisBuffer.Length]; + copyThisBuffer.CopyTo(pixelArray); return new TestMemoryManager(pixelArray); } - public static TestMemoryManager CreateAsCopyOfPixelData(Image image) + protected override void Dispose(bool disposing) { - return CreateAsCopyOfPixelData(image.GetPixelSpan()); + this.IsDisposed = true; + this.PixelArray = null; } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs index 03ab422e5..a6ea76f2d 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs @@ -214,7 +214,7 @@ namespace SixLabors.ImageSharp.Tests using (Image image0 = provider.GetImage()) { - var mmg = TestMemoryManager.CreateAsCopyOfPixelData(image0.GetPixelSpan()); + var mmg = TestMemoryManager.CreateAsCopyOf(image0.GetPixelSpan()); using (var image1 = Image.WrapMemory(mmg.Memory, image0.Width, image0.Height)) { From 80a7b9f14a0a2d3f418b1cb099fdb7eab6035dba Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 22 Jul 2018 19:10:46 +0200 Subject: [PATCH 57/68] replace IBuffer with IMemoryOwner --- .../Primitives/ShapeRegion.cs | 3 +- .../Processing/BrushApplicator.cs | 6 +- .../Processing/ImageBrush{TPixel}.cs | 5 +- .../Processing/PatternBrush{TPixel}.cs | 5 +- .../Processors/Drawing/DrawImageProcessor.cs | 3 +- .../Processors/Drawing/FillProcessor.cs | 4 +- .../Processors/Drawing/FillRegionProcessor.cs | 6 +- .../Processors/Text/DrawTextProcessor.cs | 5 +- .../Processing/RecolorBrush{TPixel}.cs | 5 +- .../Processing/SolidBrush{TPixel}.cs | 6 +- src/ImageSharp/Common/Helpers/ParallelFor.cs | 9 +- src/ImageSharp/Formats/Gif/LzwDecoder.cs | 7 +- src/ImageSharp/Formats/Gif/LzwEncoder.cs | 5 +- .../Decoder/JpegBlockPostProcessor.cs | 2 +- .../Decoder/JpegImagePostProcessor.cs | 3 +- .../PdfJsPort/Components/PdfJsHuffmanTable.cs | 3 +- src/ImageSharp/Image.WrapMemory.cs | 3 +- src/ImageSharp/ImageFrameCollection.cs | 2 +- src/ImageSharp/ImageFrame{TPixel}.cs | 7 +- src/ImageSharp/Image{TPixel}.cs | 4 +- .../ArrayPoolMemoryAllocator.Buffer{T}.cs | 1 - .../Memory/ArrayPoolMemoryAllocator.cs | 2 +- src/ImageSharp/Memory/BasicArrayBuffer.cs | 2 +- src/ImageSharp/Memory/Buffer2D{T}.cs | 54 ++++------ src/ImageSharp/Memory/BufferExtensions.cs | 20 ++-- src/ImageSharp/Memory/BufferManager.cs | 9 ++ src/ImageSharp/Memory/ConsumedBuffer.cs | 34 ------ src/ImageSharp/Memory/IBuffer{T}.cs | 38 ------- src/ImageSharp/Memory/IManagedByteBuffer.cs | 4 +- src/ImageSharp/Memory/ManagedBufferBase.cs | 4 +- src/ImageSharp/Memory/MemoryAllocator.cs | 6 +- .../Memory/MemoryAllocatorExtensions.cs | 6 +- .../Memory/SimpleGcMemoryAllocator.cs | 6 +- .../DefaultPixelBlenders.Generated.cs | 52 ++++----- .../DefaultPixelBlenders.Generated.tt | 12 +-- .../HistogramEqualizationProcessor.cs | 5 +- .../Overlays/BackgroundColorProcessor.cs | 5 +- .../Processors/Overlays/GlowProcessor.cs | 5 +- .../Processors/Overlays/VignetteProcessor.cs | 5 +- .../Quantization/QuantizedFrame{TPixel}.cs | 4 +- .../Quantization/WuFrameQuantizer{TPixel}.cs | 45 ++++---- .../Processors/Transforms/ResizeProcessor.cs | 3 +- .../Processors/Transforms/WeightsWindow.cs | 5 +- .../Color/Bulk/PackFromVector4.cs | 23 ++-- .../Color/Bulk/PackFromXyzw.cs | 18 ++-- .../Color/Bulk/ToVector4.cs | 20 ++-- .../ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs | 19 ++-- .../Color/Bulk/ToXyzw.cs | 18 ++-- .../PixelBlenders/PorterDuffBulkVsPixel.cs | 8 +- tests/ImageSharp.Benchmarks/Samplers/Glow.cs | 4 +- .../Image/ImageTests.WrapMemory.cs | 7 -- .../Memory/ArrayPoolMemoryManagerTests.cs | 16 +-- .../ImageSharp.Tests/Memory/Buffer2DTests.cs | 101 +++--------------- .../Memory/BufferTestSuite.cs | 27 ++--- .../PixelFormats/PixelOperationsTests.cs | 9 +- .../ReferenceCodecs/SystemDrawingBridge.cs | 7 +- .../TestUtilities/TestMemoryAllocator.cs | 3 +- .../TestUtilities/TestMemoryManager.cs | 3 - 58 files changed, 298 insertions(+), 405 deletions(-) delete mode 100644 src/ImageSharp/Memory/ConsumedBuffer.cs delete mode 100644 src/ImageSharp/Memory/IBuffer{T}.cs diff --git a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs index 9f5611dc0..fddd283e0 100644 --- a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs +++ b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using SixLabors.Memory; using SixLabors.Primitives; using SixLabors.Shapes; @@ -45,7 +46,7 @@ namespace SixLabors.ImageSharp.Primitives var start = new PointF(this.Bounds.Left - 1, y); var end = new PointF(this.Bounds.Right + 1, y); - using (IBuffer tempBuffer = configuration.MemoryAllocator.Allocate(buffer.Length)) + using (IMemoryOwner tempBuffer = configuration.MemoryAllocator.Allocate(buffer.Length)) { Span innerBuffer = tempBuffer.GetSpan(); int count = this.Shape.FindIntersections(start, end, innerBuffer); diff --git a/src/ImageSharp.Drawing/Processing/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/BrushApplicator.cs index 0ac4e4dd1..64f37eeab 100644 --- a/src/ImageSharp.Drawing/Processing/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Processing/BrushApplicator.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; + using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; @@ -65,8 +67,8 @@ namespace SixLabors.ImageSharp.Processing { MemoryAllocator memoryAllocator = this.Target.MemoryAllocator; - using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length)) - using (IBuffer overlay = memoryAllocator.Allocate(scanline.Length)) + using (IMemoryOwner amountBuffer = memoryAllocator.Allocate(scanline.Length)) + using (IMemoryOwner overlay = memoryAllocator.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.GetSpan(); Span overlaySpan = overlay.GetSpan(); diff --git a/src/ImageSharp.Drawing/Processing/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/ImageBrush{TPixel}.cs index 7e24dbbe2..5ebad0f32 100644 --- a/src/ImageSharp.Drawing/Processing/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/ImageBrush{TPixel}.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; @@ -118,8 +119,8 @@ namespace SixLabors.ImageSharp.Processing internal override void Apply(Span scanline, int x, int y) { // Create a span for colors - using (IBuffer amountBuffer = this.Target.MemoryAllocator.Allocate(scanline.Length)) - using (IBuffer overlay = this.Target.MemoryAllocator.Allocate(scanline.Length)) + using (IMemoryOwner amountBuffer = this.Target.MemoryAllocator.Allocate(scanline.Length)) + using (IMemoryOwner overlay = this.Target.MemoryAllocator.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.GetSpan(); Span overlaySpan = overlay.GetSpan(); diff --git a/src/ImageSharp.Drawing/Processing/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/PatternBrush{TPixel}.cs index 30d78bc83..ab48a185b 100644 --- a/src/ImageSharp.Drawing/Processing/PatternBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/PatternBrush{TPixel}.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Numerics; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; @@ -153,8 +154,8 @@ namespace SixLabors.ImageSharp.Processing int patternY = y % this.pattern.Rows; MemoryAllocator memoryAllocator = this.Target.MemoryAllocator; - using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length)) - using (IBuffer overlay = memoryAllocator.Allocate(scanline.Length)) + using (IMemoryOwner amountBuffer = memoryAllocator.Allocate(scanline.Length)) + using (IMemoryOwner overlay = memoryAllocator.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.GetSpan(); Span overlaySpan = overlay.GetSpan(); diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs index e4b2eadb4..4a59dfe3e 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; @@ -134,7 +135,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing MemoryAllocator memoryAllocator = this.Image.GetConfiguration().MemoryAllocator; - using (IBuffer amount = memoryAllocator.Allocate(width)) + using (IMemoryOwner amount = memoryAllocator.Allocate(width)) { amount.GetSpan().Fill(this.Opacity); diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs index 595c94687..e40ba5316 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; using SixLabors.Memory; using SixLabors.Primitives; @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing startY = 0; } - using (IBuffer amount = source.MemoryAllocator.Allocate(width)) + using (IMemoryOwner amount = source.MemoryAllocator.Allocate(width)) using (BrushApplicator applicator = this.brush.CreateApplicator( source, sourceRectangle, diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs index 1cc954dd9..b9db3f067 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; + using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Utils; @@ -94,8 +96,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing using (BrushApplicator applicator = this.Brush.CreateApplicator(source, rect, this.Options)) { int scanlineWidth = maxX - minX; - using (IBuffer bBuffer = source.MemoryAllocator.Allocate(maxIntersections)) - using (IBuffer bScanline = source.MemoryAllocator.Allocate(scanlineWidth)) + using (IMemoryOwner bBuffer = source.MemoryAllocator.Allocate(maxIntersections)) + using (IMemoryOwner bScanline = source.MemoryAllocator.Allocate(scanlineWidth)) { bool scanlineDirty = true; float subpixelFraction = 1f / subpixelCount; diff --git a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs index 8909ca453..048c4440d 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Collections.Generic; using SixLabors.Fonts; using SixLabors.ImageSharp.Advanced; @@ -336,8 +337,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text // take the path inside the path builder, scan thing and generate a Buffer2d representing the glyph and cache it. Buffer2D fullBuffer = this.MemoryAllocator.Allocate2D(size.Width + 1, size.Height + 1, AllocationOptions.Clean); - using (IBuffer bufferBacking = this.MemoryAllocator.Allocate(path.MaxIntersections)) - using (IBuffer rowIntersectionBuffer = this.MemoryAllocator.Allocate(size.Width)) + using (IMemoryOwner bufferBacking = this.MemoryAllocator.Allocate(path.MaxIntersections)) + using (IMemoryOwner rowIntersectionBuffer = this.MemoryAllocator.Allocate(size.Width)) { float subpixelFraction = 1f / subpixelCount; float subpixelFractionPoint = subpixelFraction / subpixelCount; diff --git a/src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs index 058b03d62..e1b11637d 100644 --- a/src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Numerics; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; @@ -138,8 +139,8 @@ namespace SixLabors.ImageSharp.Processing { MemoryAllocator memoryAllocator = this.Target.MemoryAllocator; - using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length)) - using (IBuffer overlay = memoryAllocator.Allocate(scanline.Length)) + using (IMemoryOwner amountBuffer = memoryAllocator.Allocate(scanline.Length)) + using (IMemoryOwner overlay = memoryAllocator.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.GetSpan(); Span overlaySpan = overlay.GetSpan(); diff --git a/src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs index 8a2d47c6c..3904f3d9b 100644 --- a/src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; + using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; @@ -65,7 +67,7 @@ namespace SixLabors.ImageSharp.Processing /// /// Gets the colors. /// - protected IBuffer Colors { get; } + protected IMemoryOwner Colors { get; } /// /// Gets the color for a single pixel. @@ -96,7 +98,7 @@ namespace SixLabors.ImageSharp.Processing } else { - using (IBuffer amountBuffer = memoryAllocator.Allocate(scanline.Length)) + using (IMemoryOwner amountBuffer = memoryAllocator.Allocate(scanline.Length)) { Span amountSpan = amountBuffer.GetSpan(); diff --git a/src/ImageSharp/Common/Helpers/ParallelFor.cs b/src/ImageSharp/Common/Helpers/ParallelFor.cs index 7061475a7..02c6deda3 100644 --- a/src/ImageSharp/Common/Helpers/ParallelFor.cs +++ b/src/ImageSharp/Common/Helpers/ParallelFor.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Threading.Tasks; using SixLabors.Memory; @@ -32,23 +33,23 @@ namespace SixLabors.ImageSharp int toExclusive, Configuration configuration, int bufferLength, - Action> body) + Action> body) where T : struct { MemoryAllocator memoryAllocator = configuration.MemoryAllocator; ParallelOptions parallelOptions = configuration.ParallelOptions; - IBuffer InitBuffer() + IMemoryOwner InitBuffer() { return memoryAllocator.Allocate(bufferLength); } - void CleanUpBuffer(IBuffer buffer) + void CleanUpBuffer(IMemoryOwner buffer) { buffer.Dispose(); } - IBuffer BodyFunc(int i, ParallelLoopState state, IBuffer buffer) + IMemoryOwner BodyFunc(int i, ParallelLoopState state, IMemoryOwner buffer) { body(i, buffer); return buffer; diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs index 2884abfe8..7a2aef180 100644 --- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -32,17 +33,17 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// The prefix buffer. /// - private readonly IBuffer prefix; + private readonly IMemoryOwner prefix; /// /// The suffix buffer. /// - private readonly IBuffer suffix; + private readonly IMemoryOwner suffix; /// /// The pixel stack buffer. /// - private readonly IBuffer pixelStack; + private readonly IMemoryOwner pixelStack; /// /// Initializes a new instance of the class diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs index 5a588a671..002457db3 100644 --- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -66,12 +67,12 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// The hash table. /// - private readonly IBuffer hashTable; + private readonly IMemoryOwner hashTable; /// /// The code table. /// - private readonly IBuffer codeTable; + private readonly IMemoryOwner codeTable; /// /// Define the storage for the packet accumulator. diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs index 2baefff9b..87f675491 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs @@ -9,7 +9,7 @@ using SixLabors.Primitives; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// - /// Encapsulates the implementation of processing "raw" -s into Jpeg image channels. + /// Encapsulates the implementation of processing "raw" jpeg buffers into Jpeg image channels. /// [StructLayout(LayoutKind.Sequential)] internal struct JpegBlockPostProcessor diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs index 99408cf57..1b513c612 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Linq; using System.Numerics; using SixLabors.ImageSharp.Advanced; @@ -37,7 +38,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// /// Temporal buffer to store a row of colors. /// - private readonly IBuffer rgbaBuffer; + private readonly IMemoryOwner rgbaBuffer; /// /// The corresponding to the current determined by . diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs index 15ae56331..59992e52c 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.Memory; @@ -48,7 +49,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components public PdfJsHuffmanTable(MemoryAllocator memoryAllocator, ReadOnlySpan count, ReadOnlySpan values) { const int Length = 257; - using (IBuffer huffcode = memoryAllocator.Allocate(Length)) + using (IMemoryOwner huffcode = memoryAllocator.Allocate(Length)) { ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.GetSpan()); diff --git a/src/ImageSharp/Image.WrapMemory.cs b/src/ImageSharp/Image.WrapMemory.cs index 3988120e6..3ccd809f4 100644 --- a/src/ImageSharp/Image.WrapMemory.cs +++ b/src/ImageSharp/Image.WrapMemory.cs @@ -34,8 +34,7 @@ namespace SixLabors.ImageSharp ImageMetaData metaData) where TPixel : struct, IPixel { - var buffer = new ConsumedBuffer(pixelMemory); - return new Image(config, buffer, width, height, metaData); + return new Image(config, pixelMemory, width, height, metaData); } /// diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs index 14a16b691..4b8f90e9b 100644 --- a/src/ImageSharp/ImageFrameCollection.cs +++ b/src/ImageSharp/ImageFrameCollection.cs @@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, backgroundColor)); } - internal ImageFrameCollection(Image parent, int width, int height, IBuffer consumedBuffer) + internal ImageFrameCollection(Image parent, int width, int height, Memory consumedBuffer) { Guard.NotNull(parent, nameof(parent)); diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index aa650d380..2fa35f1e5 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Threading.Tasks; @@ -94,7 +95,7 @@ namespace SixLabors.ImageSharp /// /// Initializes a new instance of the class wrapping an existing buffer. /// - internal ImageFrame(Configuration configuration, int width, int height, IBuffer consumedBuffer) + internal ImageFrame(Configuration configuration, int width, int height, Memory consumedBuffer) : this(configuration, width, height, consumedBuffer, new ImageFrameMetaData()) { } @@ -106,7 +107,7 @@ namespace SixLabors.ImageSharp Configuration configuration, int width, int height, - IBuffer consumedBuffer, + Memory consumedBuffer, ImageFrameMetaData metaData) { Guard.NotNull(configuration, nameof(configuration)); @@ -272,7 +273,7 @@ namespace SixLabors.ImageSharp this.Height, this.configuration, this.Width, - (int y, IBuffer tempRowBuffer) => + (int y, IMemoryOwner tempRowBuffer) => { Span sourceRow = this.GetPixelRowSpan(y); Span targetRow = target.GetPixelRowSpan(y); diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index ad754bc75..9126812dd 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp /// Initializes a new instance of the class /// consuming an external buffer instance. /// - internal Image(Configuration configuration, IBuffer consumedBuffer, int width, int height) + internal Image(Configuration configuration, Memory consumedBuffer, int width, int height) : this(configuration, consumedBuffer, width, height, new ImageMetaData()) { } @@ -95,7 +95,7 @@ namespace SixLabors.ImageSharp /// Initializes a new instance of the class /// consuming an external buffer instance. /// - internal Image(Configuration configuration, IBuffer consumedBuffer, int width, int height, ImageMetaData metadata) + internal Image(Configuration configuration, Memory consumedBuffer, int width, int height, ImageMetaData metadata) { this.configuration = configuration; this.PixelType = new PixelTypeInfo(Unsafe.SizeOf() * 8); diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs index d0f68c9c6..adc8843a3 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs @@ -14,7 +14,6 @@ namespace SixLabors.Memory { /// /// The buffer implementation of . - /// In this implementation is owned. /// private class Buffer : ManagedBufferBase where T : struct diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs index 08f28c5b3..32c1c6d1d 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryAllocator.cs @@ -89,7 +89,7 @@ namespace SixLabors.Memory } /// - internal override IBuffer Allocate(int length, AllocationOptions options) + internal override IMemoryOwner Allocate(int length, AllocationOptions options = AllocationOptions.None) { int itemSizeBytes = Unsafe.SizeOf(); int bufferSizeInBytes = length * itemSizeBytes; diff --git a/src/ImageSharp/Memory/BasicArrayBuffer.cs b/src/ImageSharp/Memory/BasicArrayBuffer.cs index 5e3893d08..f40df7604 100644 --- a/src/ImageSharp/Memory/BasicArrayBuffer.cs +++ b/src/ImageSharp/Memory/BasicArrayBuffer.cs @@ -7,7 +7,7 @@ using System.Runtime.CompilerServices; namespace SixLabors.Memory { /// - /// Wraps an array as an instance. In this implementation is owned. + /// Wraps an array as an instance. /// internal class BasicArrayBuffer : ManagedBufferBase where T : struct diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index b76c06df8..7d331b46d 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Runtime.CompilerServices; using SixLabors.Primitives; @@ -15,19 +16,31 @@ namespace SixLabors.Memory internal sealed class Buffer2D : IDisposable where T : struct { + private BufferManager buffer; + /// /// Initializes a new instance of the class. /// /// The buffer to wrap /// The number of elements in a row /// The number of rows - public Buffer2D(IBuffer wrappedBuffer, int width, int height) + public Buffer2D(BufferManager wrappedBuffer, int width, int height) { - this.Buffer = wrappedBuffer; + this.buffer = wrappedBuffer; this.Width = width; this.Height = height; } + public Buffer2D(IMemoryOwner ownedMemory, int width, int height) + : this(new BufferManager(ownedMemory), width, height) + { + } + + public Buffer2D(Memory observedMemory, int width, int height) + : this(new BufferManager(observedMemory), width, height) + { + } + /// /// Gets the width. /// @@ -39,13 +52,13 @@ namespace SixLabors.Memory public int Height { get; private set; } /// - /// Gets the backing + /// Gets the backing /// - public IBuffer Buffer { get; private set; } + public BufferManager Buffer => this.buffer; public Memory Memory => this.Buffer.Memory; - public Span Span => this.Buffer.GetSpan(); + public Span Span => this.Memory.Span; /// /// Gets a reference to the element at the specified position. @@ -60,7 +73,7 @@ namespace SixLabors.Memory { ImageSharp.DebugGuard.MustBeLessThan(x, this.Width, nameof(x)); DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); - Span span = this.Buffer.GetSpan(); + Span span = this.Span; return ref span[(this.Width * y) + x]; } } @@ -70,7 +83,7 @@ namespace SixLabors.Memory /// public void Dispose() { - this.Buffer?.Dispose(); + this.Buffer.Dispose(); } /// @@ -79,36 +92,15 @@ namespace SixLabors.Memory /// public static void SwapOrCopyContent(Buffer2D destination, Buffer2D source) { - if (source.Buffer.IsMemoryOwner && destination.Buffer.IsMemoryOwner) - { - SwapContents(destination, source); - } - else - { - if (destination.Size() != source.Size()) - { - throw new InvalidOperationException("SwapOrCopyContents(): buffers should both owned or the same size!"); - } - - source.Span.CopyTo(destination.Span); - } + BufferManager.SwapOrCopyContent(ref destination.buffer, ref source.buffer); + SwapDimensionData(destination, source); } - /// - /// Swap the contents (, , ) of the two buffers. - /// Useful to transfer the contents of a temporary to a persistent - /// - /// The first buffer - /// The second buffer - private static void SwapContents(Buffer2D a, Buffer2D b) + private static void SwapDimensionData(Buffer2D a, Buffer2D b) { Size aSize = a.Size(); Size bSize = b.Size(); - IBuffer temp = a.Buffer; - a.Buffer = b.Buffer; - b.Buffer = temp; - b.Width = aSize.Width; b.Height = aSize.Height; diff --git a/src/ImageSharp/Memory/BufferExtensions.cs b/src/ImageSharp/Memory/BufferExtensions.cs index 8ebf866bc..800e0d975 100644 --- a/src/ImageSharp/Memory/BufferExtensions.cs +++ b/src/ImageSharp/Memory/BufferExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -11,8 +12,12 @@ namespace SixLabors.Memory internal static class BufferExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Length(this IBuffer buffer) - where T : struct => buffer.GetSpan().Length; + public static Span GetSpan(this IMemoryOwner buffer) + => buffer.Memory.Span; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Length(this IMemoryOwner buffer) + => buffer.GetSpan().Length; /// /// Gets a to an offseted position inside the buffer. @@ -21,8 +26,7 @@ namespace SixLabors.Memory /// The start /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Span Slice(this IBuffer buffer, int start) - where T : struct + public static Span Slice(this IMemoryOwner buffer, int start) { return buffer.GetSpan().Slice(start); } @@ -35,8 +39,7 @@ namespace SixLabors.Memory /// The length of the slice /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Span Slice(this IBuffer buffer, int start, int length) - where T : struct + public static Span Slice(this IMemoryOwner buffer, int start, int length) { return buffer.GetSpan().Slice(start, length); } @@ -46,13 +49,12 @@ namespace SixLabors.Memory /// /// The buffer [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Clear(this IBuffer buffer) - where T : struct + public static void Clear(this IMemoryOwner buffer) { buffer.GetSpan().Clear(); } - public static ref T GetReference(this IBuffer buffer) + public static ref T GetReference(this IMemoryOwner buffer) where T : struct => ref MemoryMarshal.GetReference(buffer.GetSpan()); diff --git a/src/ImageSharp/Memory/BufferManager.cs b/src/ImageSharp/Memory/BufferManager.cs index f1cbb7512..1a53890d4 100644 --- a/src/ImageSharp/Memory/BufferManager.cs +++ b/src/ImageSharp/Memory/BufferManager.cs @@ -11,6 +11,11 @@ namespace SixLabors.Memory /// Implements content transfer logic in that depends on the ownership status. /// This is needed to transfer the contents of a temporary to a persistent /// + /// + /// For a deeper understanding of the owner/consumer model, check out the following docs:
+ /// https://gist.github.com/GrabYourPitchforks/4c3e1935fd4d9fa2831dbfcab35dffc6 + /// https://www.codemag.com/Article/1807051/Introducing-.NET-Core-2.1-Flagship-Types-Span-T-and-Memory-T + ///
internal struct BufferManager : IDisposable { public BufferManager(IMemoryOwner memoryOwner) @@ -31,6 +36,10 @@ namespace SixLabors.Memory public bool OwnsMemory => this.MemoryOwner != null; + public Span GetSpan() => this.Memory.Span; + + public void Clear() => this.Memory.Span.Clear(); + /// /// Swaps the contents of 'destination' with 'source' if the buffers are owned (1), /// copies the contents of 'source' to 'destination' otherwise (2). Buffers should be of same size in case 2! diff --git a/src/ImageSharp/Memory/ConsumedBuffer.cs b/src/ImageSharp/Memory/ConsumedBuffer.cs deleted file mode 100644 index 73468a381..000000000 --- a/src/ImageSharp/Memory/ConsumedBuffer.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; - -namespace SixLabors.Memory -{ - /// - /// A buffer implementation that consumes an existing instance. - /// The ownership of the memory remains external. - /// - /// The value type - internal sealed class ConsumedBuffer : IBuffer - where T : struct - { - public ConsumedBuffer(Memory memory) - { - this.Memory = memory; - } - - public Memory Memory { get; } - - public bool IsMemoryOwner => false; - - public Span GetSpan() - { - return this.Memory.Span; - } - - public void Dispose() - { - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Memory/IBuffer{T}.cs b/src/ImageSharp/Memory/IBuffer{T}.cs deleted file mode 100644 index 73406971a..000000000 --- a/src/ImageSharp/Memory/IBuffer{T}.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Buffers; - -namespace SixLabors.Memory -{ - /// - /// Represents a contigous memory buffer of value-type items. - /// Depending on it's implementation, an can (1) OWN or (2) CONSUME the instance it wraps. - /// For a deeper understanding of the owner/consumer model, read the following docs:
- /// https://gist.github.com/GrabYourPitchforks/4c3e1935fd4d9fa2831dbfcab35dffc6 - /// TODO: We need more SOC here! For owned buffers we should use . - /// For the consumption case we should not use buffers at all. We need to refactor Buffer2D{T} for this. - ///
- /// The value type - internal interface IBuffer : IDisposable - where T : struct - { - /// - /// Gets a value indicating whether this instance is owning the . - /// - bool IsMemoryOwner { get; } - - /// - /// Gets the ownerd/consumed by this buffer. - /// - Memory Memory { get; } - - /// - /// Gets the span to the memory "promised" by this buffer when it's OWNED (1). - /// Gets `this.Memory.Span` when the buffer CONSUMED (2). - /// - /// The - Span GetSpan(); - } -} \ No newline at end of file diff --git a/src/ImageSharp/Memory/IManagedByteBuffer.cs b/src/ImageSharp/Memory/IManagedByteBuffer.cs index a977eb68f..91c61424b 100644 --- a/src/ImageSharp/Memory/IManagedByteBuffer.cs +++ b/src/ImageSharp/Memory/IManagedByteBuffer.cs @@ -1,12 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System.Buffers; + namespace SixLabors.Memory { /// /// Represents a byte buffer backed by a managed array. Useful for interop with classic .NET API-s. /// - internal interface IManagedByteBuffer : IBuffer + internal interface IManagedByteBuffer : IMemoryOwner { /// /// Gets the managed array backing this buffer instance. diff --git a/src/ImageSharp/Memory/ManagedBufferBase.cs b/src/ImageSharp/Memory/ManagedBufferBase.cs index 8de2f5392..8aaf199ff 100644 --- a/src/ImageSharp/Memory/ManagedBufferBase.cs +++ b/src/ImageSharp/Memory/ManagedBufferBase.cs @@ -7,9 +7,9 @@ using System.Runtime.InteropServices; namespace SixLabors.Memory { /// - /// Provides a base class for implementations by implementing pinning logic for adaption. + /// Provides a base class for implementations by implementing pinning logic for adaption. /// - internal abstract class ManagedBufferBase : MemoryManager, IBuffer + internal abstract class ManagedBufferBase : MemoryManager where T : struct { private GCHandle pinHandle; diff --git a/src/ImageSharp/Memory/MemoryAllocator.cs b/src/ImageSharp/Memory/MemoryAllocator.cs index 4a65848fc..57b721e48 100644 --- a/src/ImageSharp/Memory/MemoryAllocator.cs +++ b/src/ImageSharp/Memory/MemoryAllocator.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System.Buffers; + namespace SixLabors.Memory { /// @@ -9,13 +11,13 @@ namespace SixLabors.Memory public abstract class MemoryAllocator { /// - /// Allocates an of size . + /// Allocates an , holding a of length . /// /// Type of the data stored in the buffer /// Size of the buffer to allocate /// The allocation options. /// A buffer of values of type . - internal abstract IBuffer Allocate(int length, AllocationOptions options = AllocationOptions.None) + internal abstract IMemoryOwner Allocate(int length, AllocationOptions options = AllocationOptions.None) where T : struct; /// diff --git a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs index 899d2f0f6..327bc8bbf 100644 --- a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs +++ b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs @@ -1,4 +1,6 @@ -using SixLabors.Primitives; +using System.Buffers; + +using SixLabors.Primitives; namespace SixLabors.Memory { @@ -14,7 +16,7 @@ namespace SixLabors.Memory AllocationOptions options = AllocationOptions.None) where T : struct { - IBuffer buffer = memoryAllocator.Allocate(width * height, options); + IMemoryOwner buffer = memoryAllocator.Allocate(width * height, options); return new Buffer2D(buffer, width, height); } diff --git a/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs b/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs index 8cb057366..612b53820 100644 --- a/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs +++ b/src/ImageSharp/Memory/SimpleGcMemoryAllocator.cs @@ -1,4 +1,6 @@ -namespace SixLabors.Memory +using System.Buffers; + +namespace SixLabors.Memory { /// /// Implements by newing up arrays by the GC on every allocation requests. @@ -6,7 +8,7 @@ public sealed class SimpleGcMemoryAllocator : MemoryAllocator { /// - internal override IBuffer Allocate(int length, AllocationOptions options) + internal override IMemoryOwner Allocate(int length, AllocationOptions options = AllocationOptions.None) { return new BasicArrayBuffer(new T[length]); } diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs index 84e528d24..c96a05255 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs @@ -2,13 +2,13 @@ // Licensed under the Apache License, Version 2.0. // +using System; +using System.Numerics; +using System.Buffers; +using SixLabors.Memory; + namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { - using System; - using System.Numerics; - using SixLabors.Memory; - - /// /// Collection of Porter Duff alpha blending functions applying different composition models. /// @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -122,7 +122,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -161,7 +161,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -200,7 +200,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -239,7 +239,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -278,7 +278,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -317,7 +317,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -356,7 +356,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -395,7 +395,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -434,7 +434,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -473,7 +473,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -512,7 +512,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -551,7 +551,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -590,7 +590,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -629,7 +629,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -668,7 +668,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -707,7 +707,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -746,7 +746,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -785,7 +785,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -824,7 +824,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt index cf16f9705..4f627764f 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt @@ -12,13 +12,13 @@ // Licensed under the Apache License, Version 2.0. // +using System; +using System.Numerics; +using System.Buffers; +using SixLabors.Memory; + namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders { - using System; - using System.Numerics; - using SixLabors.Memory; - - /// /// Collection of Porter Duff alpha blending functions applying different composition models. /// @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = memoryManager.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = memoryManager.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); diff --git a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs index b834b8968..7b6209c30 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationProcessor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; @@ -43,8 +44,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization Span pixels = source.GetPixelSpan(); // Build the histogram of the grayscale levels. - using (IBuffer histogramBuffer = memoryAllocator.Allocate(this.LuminanceLevels, AllocationOptions.Clean)) - using (IBuffer cdfBuffer = memoryAllocator.Allocate(this.LuminanceLevels, AllocationOptions.Clean)) + using (IMemoryOwner histogramBuffer = memoryAllocator.Allocate(this.LuminanceLevels, AllocationOptions.Clean)) + using (IMemoryOwner cdfBuffer = memoryAllocator.Allocate(this.LuminanceLevels, AllocationOptions.Clean)) { Span histogram = histogramBuffer.GetSpan(); for (int i = 0; i < pixels.Length; i++) diff --git a/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs index 797d388c0..d2e89fcd0 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; @@ -65,8 +66,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays int width = maxX - minX; - using (IBuffer colors = source.MemoryAllocator.Allocate(width)) - using (IBuffer amount = source.MemoryAllocator.Allocate(width)) + using (IMemoryOwner colors = source.MemoryAllocator.Allocate(width)) + using (IMemoryOwner amount = source.MemoryAllocator.Allocate(width)) { // Be careful! Do not capture colorSpan & amountSpan in the lambda below! Span colorSpan = colors.GetSpan(); diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 023643520..17d131413 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; @@ -111,7 +112,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays } int width = maxX - minX; - using (IBuffer rowColors = source.MemoryAllocator.Allocate(width)) + using (IMemoryOwner rowColors = source.MemoryAllocator.Allocate(width)) { // Be careful! Do not capture rowColorsSpan in the lambda below! Span rowColorsSpan = rowColors.GetSpan(); @@ -127,7 +128,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays configuration.ParallelOptions, y => { - using (IBuffer amounts = source.MemoryAllocator.Allocate(width)) + using (IMemoryOwner amounts = source.MemoryAllocator.Allocate(width)) { Span amountsSpan = amounts.GetSpan(); int offsetY = y - startY; diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index 3789e6bf8..a306459d1 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; @@ -113,7 +114,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays } int width = maxX - minX; - using (IBuffer rowColors = source.MemoryAllocator.Allocate(width)) + using (IMemoryOwner rowColors = source.MemoryAllocator.Allocate(width)) { // Be careful! Do not capture rowColorsSpan in the lambda below! Span rowColorsSpan = rowColors.GetSpan(); @@ -129,7 +130,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays configuration.ParallelOptions, y => { - using (IBuffer amounts = source.MemoryAllocator.Allocate(width)) + using (IMemoryOwner amounts = source.MemoryAllocator.Allocate(width)) { Span amountsSpan = amounts.GetSpan(); int offsetY = y - startY; diff --git a/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs index 6c2e6173f..d0d79093c 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; + using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; @@ -15,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization public class QuantizedFrame : IDisposable where TPixel : struct, IPixel { - private IBuffer pixels; + private IMemoryOwner pixels; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs index 9a2a84e81..80eefa9b3 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; @@ -70,37 +71,37 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization /// /// Moment of P(c). /// - private IBuffer vwt; + private IMemoryOwner vwt; /// /// Moment of r*P(c). /// - private IBuffer vmr; + private IMemoryOwner vmr; /// /// Moment of g*P(c). /// - private IBuffer vmg; + private IMemoryOwner vmg; /// /// Moment of b*P(c). /// - private IBuffer vmb; + private IMemoryOwner vmb; /// /// Moment of a*P(c). /// - private IBuffer vma; + private IMemoryOwner vma; /// /// Moment of c^2*P(c). /// - private IBuffer m2; + private IMemoryOwner m2; /// /// Color space tag. /// - private IBuffer tag; + private IMemoryOwner tag; /// /// Maximum allowed color depth @@ -467,18 +468,18 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization Span vmaSpan = this.vma.GetSpan(); Span m2Span = this.m2.GetSpan(); - using (IBuffer volume = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) - using (IBuffer volumeR = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) - using (IBuffer volumeG = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) - 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)) - using (IBuffer areaB = memoryAllocator.Allocate(IndexAlphaCount)) - using (IBuffer areaA = memoryAllocator.Allocate(IndexAlphaCount)) - using (IBuffer area2 = memoryAllocator.Allocate(IndexAlphaCount)) + using (IMemoryOwner volume = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + using (IMemoryOwner volumeR = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + using (IMemoryOwner volumeG = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + using (IMemoryOwner volumeB = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + using (IMemoryOwner volumeA = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + using (IMemoryOwner volume2 = memoryAllocator.Allocate(IndexCount * IndexAlphaCount)) + using (IMemoryOwner area = memoryAllocator.Allocate(IndexAlphaCount)) + using (IMemoryOwner areaR = memoryAllocator.Allocate(IndexAlphaCount)) + using (IMemoryOwner areaG = memoryAllocator.Allocate(IndexAlphaCount)) + using (IMemoryOwner areaB = memoryAllocator.Allocate(IndexAlphaCount)) + using (IMemoryOwner areaA = memoryAllocator.Allocate(IndexAlphaCount)) + using (IMemoryOwner area2 = memoryAllocator.Allocate(IndexAlphaCount)) { Span volumeSpan = volume.GetSpan(); Span volumeRSpan = volumeR.GetSpan(); @@ -791,7 +792,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization this.colorCube = new Box[this.colors]; float[] vv = new float[this.colors]; - ref var cube = ref this.colorCube[0]; + ref Box cube = ref this.colorCube[0]; cube.R0 = cube.G0 = cube.B0 = cube.A0 = 0; cube.R1 = cube.G1 = cube.B1 = IndexCount - 1; cube.A1 = IndexAlphaCount - 1; @@ -800,8 +801,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization for (int i = 1; i < this.colors; i++) { - ref var nextCube = ref this.colorCube[next]; - ref var currentCube = ref this.colorCube[i]; + ref Box nextCube = ref this.colorCube[next]; + ref Box currentCube = ref this.colorCube[i]; if (this.Cut(ref nextCube, ref currentCube)) { vv[next] = nextCube.Volume > 1 ? this.Variance(ref nextCube) : 0F; diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs index 8c9ab9a23..7f18faec3 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Collections.Generic; using System.Linq; using System.Numerics; @@ -303,7 +304,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms sourceRectangle.Bottom, configuration, source.Width, - (int y, IBuffer tempRowBuffer) => + (int y, IMemoryOwner tempRowBuffer) => { ref Vector4 firstPassRow = ref MemoryMarshal.GetReference(firstPassPixels.GetRowSpan(y)); Span sourceRow = source.GetPixelRowSpan(y); diff --git a/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs b/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs index ebf2db4bf..19909aaba 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -32,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// /// The buffer containing the weights values. /// - private readonly IBuffer buffer; + private readonly BufferManager buffer; /// /// Initializes a new instance of the struct. @@ -66,7 +67,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Span GetWindowSpan() => this.buffer.Slice(this.flatStartIndex, this.Length); + public Span GetWindowSpan() => this.buffer.GetSpan().Slice(this.flatStartIndex, this.Length); /// /// Computes the sum of vectors in 'rowSpan' weighted by weight values, pointed by this instance. diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs index ac396d42e..6f4195d6f 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs @@ -1,21 +1,24 @@ // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk -{ - using System.Numerics; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - using BenchmarkDotNet.Attributes; - using SixLabors.Memory; - using SixLabors.ImageSharp.PixelFormats; +using System.Buffers; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +using BenchmarkDotNet.Attributes; +using SixLabors.Memory; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk +{ [Config(typeof(Config.ShortClr))] public abstract class PackFromVector4 where TPixel : struct, IPixel { - private IBuffer source; + private IMemoryOwner source; - private IBuffer destination; + private IMemoryOwner destination; [Params(16, 128, 512)] public int Count { get; set; } diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs index c4c09f67c..33ad9203c 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs @@ -1,19 +1,21 @@ // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk -{ - using System; - using BenchmarkDotNet.Attributes; +using System.Buffers; +using System; + +using BenchmarkDotNet.Attributes; - using SixLabors.Memory; - using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk +{ public abstract class PackFromXyzw where TPixel : struct, IPixel { - private IBuffer destination; + private IMemoryOwner destination; - private IBuffer source; + private IMemoryOwner source; [Params(16, 128, 1024)] public int Count { get; set; } diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs index 3b988757d..75ca1206e 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs @@ -1,20 +1,22 @@ // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk -{ - using System; - using System.Numerics; - using BenchmarkDotNet.Attributes; +using System.Buffers; +using System; +using System.Numerics; + +using BenchmarkDotNet.Attributes; - using SixLabors.Memory; - using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk +{ public abstract class ToVector4 where TPixel : struct, IPixel { - private IBuffer source; + private IMemoryOwner source; - private IBuffer destination; + private IMemoryOwner destination; [Params(64, 300, 1024)] public int Count { get; set; } diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs index 16743eb73..be1ff72d5 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs @@ -1,20 +1,21 @@ // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk -{ - using System; - using System.Numerics; - using BenchmarkDotNet.Attributes; +using System.Buffers; +using System; + +using BenchmarkDotNet.Attributes; - using SixLabors.Memory; - using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; +using SixLabors.ImageSharp.PixelFormats; +namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk +{ public abstract class ToXyz where TPixel : struct, IPixel { - private IBuffer source; + private IMemoryOwner source; - private IBuffer destination; + private IMemoryOwner destination; [Params(16, 128, 1024)] public int Count { get; set; } diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs index f947b6e8d..799be60cc 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs @@ -1,22 +1,20 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Buffers; +using BenchmarkDotNet.Attributes; + +using SixLabors.Memory; +using SixLabors.ImageSharp.PixelFormats; + // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk { - using BenchmarkDotNet.Attributes; - - using SixLabors.Memory; - using SixLabors.ImageSharp.PixelFormats; - public abstract class ToXyzw where TPixel : struct, IPixel { - private IBuffer source; + private IMemoryOwner source; - private IBuffer destination; + private IMemoryOwner destination; [Params(16, 128, 1024)] public int Count { get; set; } diff --git a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs index 5fe8b2785..af16c5d74 100644 --- a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs +++ b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using System.Buffers; + namespace SixLabors.ImageSharp.Benchmarks { using System; @@ -24,7 +26,7 @@ namespace SixLabors.ImageSharp.Benchmarks Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length)); - using (IBuffer buffer = Configuration.Default.MemoryAllocator.Allocate(destination.Length * 3)) + using (IMemoryOwner buffer = Configuration.Default.MemoryAllocator.Allocate(destination.Length * 3)) { Span destinationSpan = buffer.Slice(0, destination.Length); Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); @@ -59,7 +61,7 @@ namespace SixLabors.ImageSharp.Benchmarks { using (var image = new Image(800, 800)) { - using (IBuffer amounts = Configuration.Default.MemoryAllocator.Allocate(image.Width)) + using (IMemoryOwner amounts = Configuration.Default.MemoryAllocator.Allocate(image.Width)) { amounts.GetSpan().Fill(1); @@ -80,7 +82,7 @@ namespace SixLabors.ImageSharp.Benchmarks { using (var image = new Image(800, 800)) { - using (IBuffer amounts = Configuration.Default.MemoryAllocator.Allocate(image.Width)) + using (IMemoryOwner amounts = Configuration.Default.MemoryAllocator.Allocate(image.Width)) { amounts.GetSpan().Fill(1); Buffer2D pixels = image.GetRootFramePixelBuffer(); diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index 85c4fdd7c..f7f54f4eb 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using System.Buffers; + namespace SixLabors.ImageSharp.Benchmarks { @@ -102,7 +104,7 @@ namespace SixLabors.ImageSharp.Benchmarks } int width = maxX - minX; - using (IBuffer rowColors = Configuration.Default.MemoryAllocator.Allocate(width)) + using (IMemoryOwner rowColors = Configuration.Default.MemoryAllocator.Allocate(width)) { Buffer2D sourcePixels = source.PixelBuffer; rowColors.GetSpan().Fill(glowColor); diff --git a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs index 066be4a73..252dbc869 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs @@ -12,13 +12,6 @@ namespace SixLabors.ImageSharp.Tests { public class WrapMemory { - [Fact] - public void ConsumedBuffer_IsMemoryOwner_ReturnsFalse() - { - var memory = new Memory(new int[55]); - var buffer = new ConsumedBuffer(memory); - Assert.False(buffer.IsMemoryOwner); - } } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs index 14fbe8225..89bb9d95f 100644 --- a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs @@ -3,6 +3,8 @@ // ReSharper disable InconsistentNaming +using System.Buffers; + using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Tests.Memory @@ -30,7 +32,7 @@ namespace SixLabors.ImageSharp.Tests.Memory private bool CheckIsRentingPooledBuffer(int length) where T : struct { - IBuffer buffer = this.MemoryAllocator.Allocate(length); + IMemoryOwner buffer = this.MemoryAllocator.Allocate(length); ref T ptrToPrevPosition0 = ref buffer.GetReference(); buffer.Dispose(); @@ -130,12 +132,12 @@ namespace SixLabors.ImageSharp.Tests.Memory [InlineData(AllocationOptions.Clean)] public void CleaningRequests_AreControlledByAllocationParameter_Clean(AllocationOptions options) { - using (IBuffer firstAlloc = this.MemoryAllocator.Allocate(42)) + using (IMemoryOwner firstAlloc = this.MemoryAllocator.Allocate(42)) { firstAlloc.GetSpan().Fill(666); } - using (IBuffer secondAlloc = this.MemoryAllocator.Allocate(42, options)) + using (IMemoryOwner secondAlloc = this.MemoryAllocator.Allocate(42, options)) { int expected = options == AllocationOptions.Clean ? 0 : 666; Assert.Equal(expected, secondAlloc.GetSpan()[0]); @@ -147,7 +149,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [InlineData(true)] public void ReleaseRetainedResources_ReplacesInnerArrayPool(bool keepBufferAlive) { - IBuffer buffer = this.MemoryAllocator.Allocate(32); + IMemoryOwner buffer = this.MemoryAllocator.Allocate(32); ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.GetSpan()); if (!keepBufferAlive) @@ -165,7 +167,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void ReleaseRetainedResources_DisposingPreviouslyAllocatedBuffer_IsAllowed() { - IBuffer buffer = this.MemoryAllocator.Allocate(32); + IMemoryOwner buffer = this.MemoryAllocator.Allocate(32); this.MemoryAllocator.ReleaseRetainedResources(); buffer.Dispose(); } @@ -181,11 +183,11 @@ namespace SixLabors.ImageSharp.Tests.Memory int arrayLengthThreshold = PoolSelectorThresholdInBytes / sizeof(int); - IBuffer small = this.MemoryAllocator.Allocate(arrayLengthThreshold - 1); + IMemoryOwner small = this.MemoryAllocator.Allocate(arrayLengthThreshold - 1); ref int ptr2Small = ref small.GetReference(); small.Dispose(); - IBuffer large = this.MemoryAllocator.Allocate(arrayLengthThreshold + 1); + IMemoryOwner large = this.MemoryAllocator.Allocate(arrayLengthThreshold + 1); Assert.False(Unsafe.AreSame(ref ptr2Small, ref large.GetReference())); } diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index af9c8bd5b..52d3929f6 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -20,7 +21,7 @@ namespace SixLabors.ImageSharp.Tests.Memory // ReSharper disable once ClassNeverInstantiated.Local private class Assert : Xunit.Assert { - public static void SpanPointsTo(Span span, IBuffer buffer, int bufferOffset = 0) + public static void SpanPointsTo(Span span, IMemoryOwner buffer, int bufferOffset = 0) where T : struct { ref T actual = ref MemoryMarshal.GetReference(span); @@ -41,7 +42,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { Assert.Equal(width, buffer.Width); Assert.Equal(height, buffer.Height); - Assert.Equal(width * height, buffer.Buffer.Length()); + Assert.Equal(width * height, buffer.Memory.Length); } } @@ -70,7 +71,7 @@ namespace SixLabors.ImageSharp.Tests.Memory // Assert.Equal(width * y, span.Start); Assert.Equal(width, span.Length); - Assert.SpanPointsTo(span, buffer.Buffer, width * y); + Assert.SpanPointsTo(span, buffer.Buffer.MemoryOwner, width * y); } } @@ -86,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests.Memory // Assert.Equal(width * y + x, span.Start); Assert.Equal(width - x, span.Length); - Assert.SpanPointsTo(span, buffer.Buffer, width * y + x); + Assert.SpanPointsTo(span, buffer.Buffer.MemoryOwner, width * y + x); } } @@ -107,92 +108,24 @@ namespace SixLabors.ImageSharp.Tests.Memory Assert.True(Unsafe.AreSame(ref expected, ref actual)); } } - - public class SwapOrCopyContent - { - private MemoryAllocator MemoryAllocator { get; } = new TestMemoryAllocator(); - - [Fact] - public void WhenBothBuffersAreMemoryOwners_ShouldSwap() - { - using (Buffer2D a = this.MemoryAllocator.Allocate2D(10, 5)) - using (Buffer2D b = this.MemoryAllocator.Allocate2D(3, 7)) - { - IBuffer aa = a.Buffer; - IBuffer bb = b.Buffer; - Buffer2D.SwapOrCopyContent(a, b); - - Assert.Equal(bb, a.Buffer); - Assert.Equal(aa, b.Buffer); - - Assert.Equal(new Size(3, 7), a.Size()); - Assert.Equal(new Size(10, 5), b.Size()); - } - } - - [Fact] - public void WhenDestIsNotMemoryOwner_SameSize_ShouldCopy() + [Fact] + public void SwapOrCopyContent() + { + using (Buffer2D a = this.MemoryAllocator.Allocate2D(10, 5)) + using (Buffer2D b = this.MemoryAllocator.Allocate2D(3, 7)) { - var data = new Rgba32[3 * 7]; - var color = new Rgba32(1, 2, 3, 4); - - var mmg = new TestMemoryManager(data); - var aBuff = new ConsumedBuffer(mmg.Memory); - - using (Buffer2D a = new Buffer2D(aBuff, 3, 7)) - { - IBuffer aa = a.Buffer; + IMemoryOwner aa = a.Buffer.MemoryOwner; + IMemoryOwner bb = b.Buffer.MemoryOwner; - // Precondition: - Assert.Equal(aBuff, aa); + Buffer2D.SwapOrCopyContent(a, b); - using (Buffer2D b = this.MemoryAllocator.Allocate2D(3, 7)) - { - IBuffer bb = b.Buffer; - bb.GetSpan()[10] = color; + Assert.Equal(bb, a.Buffer.MemoryOwner); + Assert.Equal(aa, b.Buffer.MemoryOwner); - // Act: - Buffer2D.SwapOrCopyContent(a, b); - - // Assert: - Assert.Equal(aBuff, a.Buffer); - Assert.Equal(bb, b.Buffer); - } - - // Assert: - Assert.Equal(color, a.Buffer.GetSpan()[10]); - } + Assert.Equal(new Size(3, 7), a.Size()); + Assert.Equal(new Size(10, 5), b.Size()); } - - [Fact] - public void WhenDestIsNotMemoryOwner_DifferentSize_Throws() - { - var data = new Rgba32[3 * 7]; - var color = new Rgba32(1, 2, 3, 4); - data[10] = color; - - var mmg = new TestMemoryManager(data); - var aBuff = new ConsumedBuffer(mmg.Memory); - - using (Buffer2D a = new Buffer2D(aBuff, 3, 7)) - { - IBuffer aa = a.Buffer; - using (Buffer2D b = this.MemoryAllocator.Allocate2D(3, 8)) - { - IBuffer bb = b.Buffer; - - Assert.ThrowsAny( - () => - { - Buffer2D.SwapOrCopyContent(a, b); - }); - } - - Assert.Equal(color, a.Buffer.GetSpan()[10]); - } - } - } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs index fd3331288..e57c13164 100644 --- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs @@ -63,15 +63,6 @@ namespace SixLabors.ImageSharp.Tests.Memory public static readonly TheoryData LenthValues = new TheoryData { 0, 1, 7, 1023, 1024 }; - [Fact] - public void IsMemoryOwner() - { - using (IBuffer buffer = this.MemoryAllocator.Allocate(42)) - { - Assert.True(buffer.IsMemoryOwner); - } - } - [Theory] [MemberData(nameof(LenthValues))] public void HasCorrectLength_byte(int desiredLength) @@ -96,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests.Memory private void TestHasCorrectLength(int desiredLength) where T : struct { - using (IBuffer buffer = this.MemoryAllocator.Allocate(desiredLength)) + using (IMemoryOwner buffer = this.MemoryAllocator.Allocate(desiredLength)) { Assert.Equal(desiredLength, buffer.GetSpan().Length); } @@ -124,12 +115,12 @@ namespace SixLabors.ImageSharp.Tests.Memory this.TestCanAllocateCleanBuffer(desiredLength); } - private IBuffer Allocate(int desiredLength, AllocationOptions options, bool managedByteBuffer) + private IMemoryOwner Allocate(int desiredLength, AllocationOptions options, bool managedByteBuffer) where T : struct { if (managedByteBuffer) { - if (!(this.MemoryAllocator.AllocateManagedByteBuffer(desiredLength, options) is IBuffer buffer)) + if (!(this.MemoryAllocator.AllocateManagedByteBuffer(desiredLength, options) is IMemoryOwner buffer)) { throw new InvalidOperationException("typeof(T) != typeof(byte)"); } @@ -147,7 +138,7 @@ namespace SixLabors.ImageSharp.Tests.Memory for (int i = 0; i < 10; i++) { - using (IBuffer buffer = this.Allocate(desiredLength, AllocationOptions.Clean, testManagedByteBuffer)) + using (IMemoryOwner buffer = this.Allocate(desiredLength, AllocationOptions.Clean, testManagedByteBuffer)) { Assert.True(buffer.GetSpan().SequenceEqual(expected)); } @@ -172,7 +163,7 @@ namespace SixLabors.ImageSharp.Tests.Memory private void TestSpanPropertyIsAlwaysTheSame(int desiredLength, bool testManagedByteBuffer = false) where T : struct { - using (IBuffer buffer = this.Allocate(desiredLength, AllocationOptions.None, testManagedByteBuffer)) + using (IMemoryOwner buffer = this.Allocate(desiredLength, AllocationOptions.None, testManagedByteBuffer)) { ref T a = ref MemoryMarshal.GetReference(buffer.GetSpan()); ref T b = ref MemoryMarshal.GetReference(buffer.GetSpan()); @@ -201,7 +192,7 @@ namespace SixLabors.ImageSharp.Tests.Memory private void TestWriteAndReadElements(int desiredLength, Func getExpectedValue, bool testManagedByteBuffer = false) where T : struct { - using (IBuffer buffer = this.Allocate(desiredLength, AllocationOptions.None, testManagedByteBuffer)) + using (IMemoryOwner buffer = this.Allocate(desiredLength, AllocationOptions.None, testManagedByteBuffer)) { T[] expectedVals = new T[buffer.Length()]; @@ -247,7 +238,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { var dummy = default(T); - using (IBuffer buffer = this.Allocate(desiredLength, AllocationOptions.None, testManagedByteBuffer)) + using (IMemoryOwner buffer = this.Allocate(desiredLength, AllocationOptions.None, testManagedByteBuffer)) { Assert.ThrowsAny( () => @@ -294,7 +285,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void GetMemory_ReturnsValidMemory() { - using (IBuffer buffer = this.MemoryAllocator.Allocate(42)) + using (IMemoryOwner buffer = this.MemoryAllocator.Allocate(42)) { Span span0 = buffer.GetSpan(); span0[10].A = 30; @@ -311,7 +302,7 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public unsafe void GetMemory_ResultIsPinnable() { - using (IBuffer buffer = this.MemoryAllocator.Allocate(42)) + using (IMemoryOwner buffer = this.MemoryAllocator.Allocate(42)) { Span span0 = buffer.GetSpan(); span0[10] = 30; diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs index c0e69a902..ca7e48d0b 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -57,8 +58,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats int times = 200000; int count = 1024; - using (IBuffer source = Configuration.Default.MemoryAllocator.Allocate(count)) - using (IBuffer dest = Configuration.Default.MemoryAllocator.Allocate(count)) + using (IMemoryOwner source = Configuration.Default.MemoryAllocator.Allocate(count)) + using (IMemoryOwner dest = Configuration.Default.MemoryAllocator.Allocate(count)) { this.Measure( times, @@ -537,7 +538,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats where TDest : struct { public TSource[] SourceBuffer { get; } - public IBuffer ActualDestBuffer { get; } + public IMemoryOwner ActualDestBuffer { get; } public TDest[] ExpectedDestBuffer { get; } public TestBuffers(TSource[] source, TDest[] expectedDest) @@ -586,7 +587,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats internal static void TestOperation( TSource[] source, TDest[] expected, - Action> action) + Action> action) where TSource : struct where TDest : struct { diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index f0daa0abb..7cc369244 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Drawing; using System.Drawing.Imaging; @@ -43,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs var image = new Image(w, h); - using (IBuffer workBuffer = Configuration.Default.MemoryAllocator.Allocate(w)) + using (IMemoryOwner workBuffer = Configuration.Default.MemoryAllocator.Allocate(w)) { fixed (Bgra32* destPtr = &workBuffer.GetReference()) { @@ -89,7 +90,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs var image = new Image(w, h); - using (IBuffer workBuffer = Configuration.Default.MemoryAllocator.Allocate(w)) + using (IMemoryOwner workBuffer = Configuration.Default.MemoryAllocator.Allocate(w)) { fixed (Bgr24* destPtr = &workBuffer.GetReference()) { @@ -122,7 +123,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs long destRowByteCount = data.Stride; long sourceRowByteCount = w * sizeof(Bgra32); - using (IBuffer workBuffer = image.GetConfiguration().MemoryAllocator.Allocate(w)) + using (IMemoryOwner workBuffer = image.GetConfiguration().MemoryAllocator.Allocate(w)) { fixed (Bgra32* sourcePtr = &workBuffer.GetReference()) { diff --git a/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs b/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs index 7993b3e99..a580fc7ad 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestMemoryAllocator.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers; using System.Runtime.InteropServices; using SixLabors.Memory; @@ -17,7 +18,7 @@ namespace SixLabors.ImageSharp.Tests.Memory /// public byte DirtyValue { get; } - internal override IBuffer Allocate(int length, AllocationOptions options = AllocationOptions.None) + internal override IMemoryOwner Allocate(int length, AllocationOptions options = AllocationOptions.None) { T[] array = this.AllocateArray(length, options); diff --git a/tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs b/tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs index ce3cfbc9e..9274e5727 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestMemoryManager.cs @@ -3,9 +3,6 @@ using System.Buffers; namespace SixLabors.ImageSharp.Tests { - using SixLabors.ImageSharp.Advanced; - using SixLabors.ImageSharp.PixelFormats; - class TestMemoryManager : MemoryManager where T : struct { From 61eedd77e136243e9672da581e7920b13d08a1ae Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 22 Jul 2018 19:29:25 +0200 Subject: [PATCH 58/68] FillRegion_WorksOnWrappedMemoryImage --- src/ImageSharp/ImageFrameCollection.cs | 4 ++-- src/ImageSharp/ImageFrame{TPixel}.cs | 8 ++++---- src/ImageSharp/Image{TPixel}.cs | 8 ++++---- .../Advanced/AdvancedImageExtensionsTests.cs | 3 +-- .../Drawing/FillSolidBrushTests.cs | 17 +++++++++++++++++ .../Drawing/SolidBezierTests.cs | 1 + .../ImageSharp.Tests/TestUtilities/TestUtils.cs | 4 ++++ 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs index 4b8f90e9b..3c1062df3 100644 --- a/src/ImageSharp/ImageFrameCollection.cs +++ b/src/ImageSharp/ImageFrameCollection.cs @@ -30,14 +30,14 @@ namespace SixLabors.ImageSharp this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, backgroundColor)); } - internal ImageFrameCollection(Image parent, int width, int height, Memory consumedBuffer) + internal ImageFrameCollection(Image parent, int width, int height, Memory consumedMemory) { Guard.NotNull(parent, nameof(parent)); this.parent = parent; // Frames are already cloned within the caller - this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, consumedBuffer)); + this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, consumedMemory)); } internal ImageFrameCollection(Image parent, IEnumerable> frames) diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 2fa35f1e5..370b3763c 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -95,8 +95,8 @@ namespace SixLabors.ImageSharp /// /// Initializes a new instance of the class wrapping an existing buffer. /// - internal ImageFrame(Configuration configuration, int width, int height, Memory consumedBuffer) - : this(configuration, width, height, consumedBuffer, new ImageFrameMetaData()) + internal ImageFrame(Configuration configuration, int width, int height, Memory consumedMemory) + : this(configuration, width, height, consumedMemory, new ImageFrameMetaData()) { } @@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp Configuration configuration, int width, int height, - Memory consumedBuffer, + Memory consumedMemory, ImageFrameMetaData metaData) { Guard.NotNull(configuration, nameof(configuration)); @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp this.configuration = configuration; this.MemoryAllocator = configuration.MemoryAllocator; - this.PixelBuffer = new Buffer2D(consumedBuffer, width, height); + this.PixelBuffer = new Buffer2D(consumedMemory, width, height); this.MetaData = metaData; } diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index 9126812dd..316c381c4 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -86,8 +86,8 @@ namespace SixLabors.ImageSharp /// Initializes a new instance of the class /// consuming an external buffer instance. /// - internal Image(Configuration configuration, Memory consumedBuffer, int width, int height) - : this(configuration, consumedBuffer, width, height, new ImageMetaData()) + internal Image(Configuration configuration, Memory consumedMemory, int width, int height) + : this(configuration, consumedMemory, width, height, new ImageMetaData()) { } @@ -95,12 +95,12 @@ namespace SixLabors.ImageSharp /// Initializes a new instance of the class /// consuming an external buffer instance. /// - internal Image(Configuration configuration, Memory consumedBuffer, int width, int height, ImageMetaData metadata) + internal Image(Configuration configuration, Memory consumedMemory, int width, int height, ImageMetaData metadata) { this.configuration = configuration; this.PixelType = new PixelTypeInfo(Unsafe.SizeOf() * 8); this.MetaData = metadata; - this.frames = new ImageFrameCollection(this, width, height, consumedBuffer); + this.frames = new ImageFrameCollection(this, width, height, consumedMemory); } /// diff --git a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs index 366266652..974099991 100644 --- a/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs +++ b/tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Tests.Advanced Memory externalMemory = managerOfExeternalMemory.Memory; - using (Image image1 = Image.WrapMemory(externalMemory, image0.Width, image0.Height)) + using (var image1 = Image.WrapMemory(externalMemory, image0.Width, image0.Height)) { Memory internalMemory = image1.GetPixelMemory(); Assert.Equal(targetBuffer.Length, internalMemory.Length); @@ -72,7 +72,6 @@ namespace SixLabors.ImageSharp.Tests.Advanced image0.ComparePixelBufferTo(externalMemory.Span); } } - } [Theory] diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index 1f01d54f4..45f1340be 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -81,6 +81,23 @@ namespace SixLabors.ImageSharp.Tests.Drawing provider.RunValidatingProcessorTest(c => c.Fill(color, region), testDetails, ImageComparer.Exact); } + [Theory] + [WithSolidFilledImages(16, 16, "Red", PixelTypes.Rgba32, 5, 7, 3, 8)] + [WithSolidFilledImages(16, 16, "Red", PixelTypes.Rgba32, 8, 5, 6, 4)] + public void FillRegion_WorksOnWrappedMemoryImage(TestImageProvider provider, int x0, int y0, int w, int h) + where TPixel : struct, IPixel + { + FormattableString testDetails = $"(x{x0},y{y0},w{w},h{h})"; + var region = new RectangleF(x0, y0, w, h); + TPixel color = TestUtils.GetPixelOfNamedColor("Blue"); + + provider.RunValidatingProcessorTestOnWrappedMemoryImage( + c => c.Fill(color, region), + testDetails, + ImageComparer.Exact, + useReferenceOutputFrom: nameof(this.FillRegion)); + } + public static readonly TheoryData BlendData = new TheoryData() { diff --git a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs index 94d3d49ff..23acc1a44 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -38,6 +38,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing } } + [Theory] [WithBlankImages(500, 500, PixelTypes.Rgba32)] public void OverlayByFilledPolygonOpacity(TestImageProvider provider) diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs index a6ea76f2d..81310c1a0 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs @@ -228,6 +228,8 @@ namespace SixLabors.ImageSharp.Tests // TODO: Investigate the cause of pixel inaccuracies under Linux if (TestEnvironment.IsWindows) { + string testNameBackup = provider.Utility.TestName; + if (useReferenceOutputFrom != null) { provider.Utility.TestName = useReferenceOutputFrom; @@ -239,6 +241,8 @@ namespace SixLabors.ImageSharp.Tests testOutputDetails, appendPixelTypeToFileName: appendPixelTypeToFileName, appendSourceFileOrDescription: appendSourceFileOrDescription); + + provider.Utility.TestName = testNameBackup; } } } From 844740725eef9ce06d6520b384142a0989e9049a Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 22 Jul 2018 19:54:37 +0200 Subject: [PATCH 59/68] made WrapMemory() public + test case demonstrating using Image.WrapMemory() to draw over a System.Drawing.Bitmap instance --- src/ImageSharp/Image.WrapMemory.cs | 4 +- src/ImageSharp/PixelFormats/Bgra32.cs | 1 + .../Image/ImageTests.WrapMemory.cs | 74 +++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Image.WrapMemory.cs b/src/ImageSharp/Image.WrapMemory.cs index 3ccd809f4..7f0c4ae2e 100644 --- a/src/ImageSharp/Image.WrapMemory.cs +++ b/src/ImageSharp/Image.WrapMemory.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp /// The height of the memory image /// The /// An instance - internal static Image WrapMemory( + public static Image WrapMemory( Configuration config, Memory pixelMemory, int width, @@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp /// The width of the memory image /// The height of the memory image /// An instance - internal static Image WrapMemory( + public static Image WrapMemory( Memory pixelMemory, int width, int height) diff --git a/src/ImageSharp/PixelFormats/Bgra32.cs b/src/ImageSharp/PixelFormats/Bgra32.cs index f951be881..14b2da07c 100644 --- a/src/ImageSharp/PixelFormats/Bgra32.cs +++ b/src/ImageSharp/PixelFormats/Bgra32.cs @@ -11,6 +11,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. /// The color components are stored in blue, green, red, and alpha order (least significant to most significant byte). + /// The format is binary compatible with System.Drawing.Imaging.PixelFormat.Format32bppArgb /// /// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form. /// diff --git a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs index 252dbc869..57f757176 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs @@ -2,7 +2,14 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; +using System.Drawing; +using System.Drawing.Imaging; + +using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; +using SixLabors.Shapes; +using SixLabors.ImageSharp.Processing; using Xunit; // ReSharper disable InconsistentNaming @@ -12,6 +19,73 @@ namespace SixLabors.ImageSharp.Tests { public class WrapMemory { + class BitmapMemoryManager : MemoryManager + { + private System.Drawing.Bitmap bitmap; + + private BitmapData bmpData; + + private int length; + + public BitmapMemoryManager(Bitmap bitmap) + { + if (bitmap.PixelFormat != PixelFormat.Format32bppArgb) + { + throw new ArgumentException("bitmap.PixelFormat != PixelFormat.Format32bppArgb", nameof(bitmap)); + } + + this.bitmap = bitmap; + var rectangle = new Rectangle(0, 0, bitmap.Width, bitmap.Height); + this.bmpData = bitmap.LockBits(rectangle, ImageLockMode.ReadWrite, bitmap.PixelFormat); + this.length = bitmap.Width * bitmap.Height; + } + + protected override void Dispose(bool disposing) + { + this.bitmap.UnlockBits(this.bmpData); + } + + public override unsafe Span GetSpan() + { + void* ptr = (void*) this.bmpData.Scan0; + return new Span(ptr, this.length); + } + + public override unsafe MemoryHandle Pin(int elementIndex = 0) + { + void* ptr = (void*)this.bmpData.Scan0; + return new MemoryHandle(ptr); + } + + public override void Unpin() + { + } + } + + [Fact] + public void WrapSystemDrawingBitmap() + { + using (var bmp = new Bitmap(51, 23)) + { + using (var memoryManager = new BitmapMemoryManager(bmp)) + { + Memory memory = memoryManager.Memory; + Bgra32 bg = NamedColors.Red; + Bgra32 fg = NamedColors.Green; + + using (var image = Image.WrapMemory(memory, bmp.Width, bmp.Height)) + { + image.Mutate(c => c.Fill(bg).Fill(fg, new RectangularPolygon(10, 10, 10, 10))); + } + } + + string fn = System.IO.Path.Combine( + TestEnvironment.ActualOutputDirectoryFullPath, + "WrapSystemDrawingBitmap.bmp"); + + bmp.Save(fn, ImageFormat.Bmp); + } + } } } } \ No newline at end of file From f9dbe41949921bd36fbb958dc7fb6a8c39f24280 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Mon, 23 Jul 2018 00:20:14 +0200 Subject: [PATCH 60/68] kick AppVeyor --- build.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.ps1 b/build.ps1 index 4c5a36cae..35b8344dc 100644 --- a/build.ps1 +++ b/build.ps1 @@ -8,7 +8,7 @@ $tagRegex = '^v?(\d+\.\d+\.\d+)(-([a-zA-Z]+)\.?(\d*))?$' # we are running on the build server $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex - if($isVersionTag){ + if($isVersionTag) { Write-Debug "Building commit tagged with a compatable version number" @@ -26,7 +26,8 @@ $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex $version = "${version}${padded}" } - }else { + } + else { Write-Debug "Untagged" $lastTag = (git tag --list --sort=-taggerdate) | Out-String From 33d32d7407f042dea25a7e2a3b8688bdfceb66e7 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Tue, 24 Jul 2018 00:39:47 +0200 Subject: [PATCH 61/68] renamed BufferManager to MemorySource + enable consuming external IMemoryOwner --- .../Advanced/AdvancedImageExtensions.cs | 2 +- src/ImageSharp/Image.WrapMemory.cs | 5 +- src/ImageSharp/ImageFrameCollection.cs | 4 +- src/ImageSharp/ImageFrame{TPixel}.cs | 8 +-- src/ImageSharp/Image{TPixel}.cs | 15 +--- src/ImageSharp/Memory/Buffer2DExtensions.cs | 4 +- src/ImageSharp/Memory/Buffer2D{T}.cs | 28 +++----- .../Memory/MemoryAllocatorExtensions.cs | 3 +- .../{BufferManager.cs => MemorySource.cs} | 34 ++++++--- .../Processors/Transforms/ResizeProcessor.cs | 2 +- .../Processors/Transforms/WeightsWindow.cs | 4 +- .../Formats/Jpg/JpegColorConverterTests.cs | 3 +- .../Formats/Jpg/SpectralJpegTests.cs | 2 +- .../ImageSharp.Tests/Memory/Buffer2DTests.cs | 14 ++-- ...erManagerTests.cs => MemorySourceTests.cs} | 69 ++++++++++--------- 15 files changed, 101 insertions(+), 96 deletions(-) rename src/ImageSharp/Memory/{BufferManager.cs => MemorySource.cs} (57%) rename tests/ImageSharp.Tests/Memory/{BufferManagerTests.cs => MemorySourceTests.cs} (60%) diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index 18b1d994b..1c73b5ed1 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.Advanced internal static Memory GetPixelMemory(this ImageFrame source) where TPixel : struct, IPixel { - return source.PixelBuffer.Buffer.Memory; + return source.PixelBuffer.MemorySource.Memory; } /// diff --git a/src/ImageSharp/Image.WrapMemory.cs b/src/ImageSharp/Image.WrapMemory.cs index 7f0c4ae2e..c24a932e1 100644 --- a/src/ImageSharp/Image.WrapMemory.cs +++ b/src/ImageSharp/Image.WrapMemory.cs @@ -13,8 +13,6 @@ namespace SixLabors.ImageSharp /// public static partial class Image { - // TODO: This is a WIP API, should be public when finished. - /// /// Wraps an existing contigous memory area of 'width'x'height' pixels, /// allowing to view/manipulate it as an ImageSharp instance. @@ -34,7 +32,8 @@ namespace SixLabors.ImageSharp ImageMetaData metaData) where TPixel : struct, IPixel { - return new Image(config, pixelMemory, width, height, metaData); + var memorySource = new MemorySource(pixelMemory); + return new Image(config, memorySource, width, height, metaData); } /// diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs index 3c1062df3..154ef5014 100644 --- a/src/ImageSharp/ImageFrameCollection.cs +++ b/src/ImageSharp/ImageFrameCollection.cs @@ -30,14 +30,14 @@ namespace SixLabors.ImageSharp this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, backgroundColor)); } - internal ImageFrameCollection(Image parent, int width, int height, Memory consumedMemory) + internal ImageFrameCollection(Image parent, int width, int height, MemorySource memorySource) { Guard.NotNull(parent, nameof(parent)); this.parent = parent; // Frames are already cloned within the caller - this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, consumedMemory)); + this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, memorySource)); } internal ImageFrameCollection(Image parent, IEnumerable> frames) diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 370b3763c..6c04d5aea 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -95,8 +95,8 @@ namespace SixLabors.ImageSharp /// /// Initializes a new instance of the class wrapping an existing buffer. /// - internal ImageFrame(Configuration configuration, int width, int height, Memory consumedMemory) - : this(configuration, width, height, consumedMemory, new ImageFrameMetaData()) + internal ImageFrame(Configuration configuration, int width, int height, MemorySource memorySource) + : this(configuration, width, height, memorySource, new ImageFrameMetaData()) { } @@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp Configuration configuration, int width, int height, - Memory consumedMemory, + MemorySource memorySource, ImageFrameMetaData metaData) { Guard.NotNull(configuration, nameof(configuration)); @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp this.configuration = configuration; this.MemoryAllocator = configuration.MemoryAllocator; - this.PixelBuffer = new Buffer2D(consumedMemory, width, height); + this.PixelBuffer = new Buffer2D(memorySource, width, height); this.MetaData = metaData; } diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index 316c381c4..5a5928d6b 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -84,23 +84,14 @@ namespace SixLabors.ImageSharp /// /// Initializes a new instance of the class - /// consuming an external buffer instance. + /// wrapping an external /// - internal Image(Configuration configuration, Memory consumedMemory, int width, int height) - : this(configuration, consumedMemory, width, height, new ImageMetaData()) - { - } - - /// - /// Initializes a new instance of the class - /// consuming an external buffer instance. - /// - internal Image(Configuration configuration, Memory consumedMemory, int width, int height, ImageMetaData metadata) + internal Image(Configuration configuration, MemorySource memorySource, int width, int height, ImageMetaData metadata) { this.configuration = configuration; this.PixelType = new PixelTypeInfo(Unsafe.SizeOf() * 8); this.MetaData = metadata; - this.frames = new ImageFrameCollection(this, width, height, consumedMemory); + this.frames = new ImageFrameCollection(this, width, height, memorySource); } /// diff --git a/src/ImageSharp/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs index c27752570..be4f0ef15 100644 --- a/src/ImageSharp/Memory/Buffer2DExtensions.cs +++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs @@ -18,7 +18,7 @@ namespace SixLabors.Memory internal static Span GetSpan(this Buffer2D buffer) where T : struct { - return buffer.Buffer.GetSpan(); + return buffer.MemorySource.GetSpan(); } /// @@ -61,7 +61,7 @@ namespace SixLabors.Memory public static Memory GetRowMemory(this Buffer2D buffer, int y) where T : struct { - return buffer.Buffer.Memory.Slice(y * buffer.Width, buffer.Width); + return buffer.MemorySource.Memory.Slice(y * buffer.Width, buffer.Width); } /// diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index 7d331b46d..844ca1ad1 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -16,31 +16,21 @@ namespace SixLabors.Memory internal sealed class Buffer2D : IDisposable where T : struct { - private BufferManager buffer; + private MemorySource memorySource; /// /// Initializes a new instance of the class. /// - /// The buffer to wrap + /// The buffer to wrap /// The number of elements in a row /// The number of rows - public Buffer2D(BufferManager wrappedBuffer, int width, int height) + public Buffer2D(MemorySource memorySource, int width, int height) { - this.buffer = wrappedBuffer; + this.memorySource = memorySource; this.Width = width; this.Height = height; } - public Buffer2D(IMemoryOwner ownedMemory, int width, int height) - : this(new BufferManager(ownedMemory), width, height) - { - } - - public Buffer2D(Memory observedMemory, int width, int height) - : this(new BufferManager(observedMemory), width, height) - { - } - /// /// Gets the width. /// @@ -52,11 +42,11 @@ namespace SixLabors.Memory public int Height { get; private set; } /// - /// Gets the backing + /// Gets the backing /// - public BufferManager Buffer => this.buffer; + public MemorySource MemorySource => this.memorySource; - public Memory Memory => this.Buffer.Memory; + public Memory Memory => this.MemorySource.Memory; public Span Span => this.Memory.Span; @@ -83,7 +73,7 @@ namespace SixLabors.Memory /// public void Dispose() { - this.Buffer.Dispose(); + this.MemorySource.Dispose(); } /// @@ -92,7 +82,7 @@ namespace SixLabors.Memory /// public static void SwapOrCopyContent(Buffer2D destination, Buffer2D source) { - BufferManager.SwapOrCopyContent(ref destination.buffer, ref source.buffer); + MemorySource.SwapOrCopyContent(ref destination.memorySource, ref source.memorySource); SwapDimensionData(destination, source); } diff --git a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs index 327bc8bbf..d8c1f51f4 100644 --- a/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs +++ b/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs @@ -17,8 +17,9 @@ namespace SixLabors.Memory where T : struct { IMemoryOwner buffer = memoryAllocator.Allocate(width * height, options); + var memorySource = new MemorySource(buffer, true); - return new Buffer2D(buffer, width, height); + return new Buffer2D(memorySource, width, height); } public static Buffer2D Allocate2D( diff --git a/src/ImageSharp/Memory/BufferManager.cs b/src/ImageSharp/Memory/MemorySource.cs similarity index 57% rename from src/ImageSharp/Memory/BufferManager.cs rename to src/ImageSharp/Memory/MemorySource.cs index 1a53890d4..27bca11c1 100644 --- a/src/ImageSharp/Memory/BufferManager.cs +++ b/src/ImageSharp/Memory/MemorySource.cs @@ -9,32 +9,50 @@ namespace SixLabors.Memory /// /// Holds a that is either OWNED or CONSUMED. /// Implements content transfer logic in that depends on the ownership status. - /// This is needed to transfer the contents of a temporary to a persistent + /// This is needed to transfer the contents of a temporary + /// to a persistent without copying the buffer. /// /// /// For a deeper understanding of the owner/consumer model, check out the following docs:
/// https://gist.github.com/GrabYourPitchforks/4c3e1935fd4d9fa2831dbfcab35dffc6 /// https://www.codemag.com/Article/1807051/Introducing-.NET-Core-2.1-Flagship-Types-Span-T-and-Memory-T ///
- internal struct BufferManager : IDisposable + internal struct MemorySource : IDisposable { - public BufferManager(IMemoryOwner memoryOwner) + /// + /// Initializes a new instance of the struct + /// by wrapping an existing . + /// + /// The to wrap + /// + /// A value indicating whether is an internal memory source managed by ImageSharp. + /// Eg. allocated by a . + /// + public MemorySource(IMemoryOwner memoryOwner, bool isInternalMemorySource) { this.MemoryOwner = memoryOwner; this.Memory = memoryOwner.Memory; + this.HasSwappableContents = isInternalMemorySource; } - public BufferManager(Memory memory) + public MemorySource(Memory memory) { this.Memory = memory; this.MemoryOwner = null; + this.HasSwappableContents = false; } public IMemoryOwner MemoryOwner { get; private set; } public Memory Memory { get; private set; } - public bool OwnsMemory => this.MemoryOwner != null; + /// + /// Gets a value indicating whether we are allowed to swap the contents of this buffer + /// with an other instance. + /// The value is true only and only if is present, + /// and it's coming from an internal source managed by ImageSharp (). + /// + public bool HasSwappableContents { get; } public Span GetSpan() => this.Memory.Span; @@ -44,9 +62,9 @@ namespace SixLabors.Memory /// Swaps the contents of 'destination' with 'source' if the buffers are owned (1), /// copies the contents of 'source' to 'destination' otherwise (2). Buffers should be of same size in case 2! ///
- public static void SwapOrCopyContent(ref BufferManager destination, ref BufferManager source) + public static void SwapOrCopyContent(ref MemorySource destination, ref MemorySource source) { - if (source.OwnsMemory && destination.OwnsMemory) + if (source.HasSwappableContents && destination.HasSwappableContents) { SwapContents(ref destination, ref source); } @@ -67,7 +85,7 @@ namespace SixLabors.Memory this.MemoryOwner?.Dispose(); } - private static void SwapContents(ref BufferManager a, ref BufferManager b) + private static void SwapContents(ref MemorySource a, ref MemorySource b) { IMemoryOwner tempOwner = a.MemoryOwner; Memory tempMemory = a.Memory; diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs index 7f18faec3..9c09b6a22 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs @@ -297,7 +297,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms // TODO: Using a transposed variant of 'firstPassPixels' could eliminate the need for the WeightsWindow.ComputeWeightedColumnSum() method, and improve speed! using (Buffer2D firstPassPixels = source.MemoryAllocator.Allocate2D(width, source.Height)) { - firstPassPixels.Buffer.Clear(); + firstPassPixels.MemorySource.Clear(); ParallelFor.WithTemporaryBuffer( 0, diff --git a/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs b/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs index 19909aaba..6a2b6fbd1 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// /// The buffer containing the weights values. /// - private readonly BufferManager buffer; + private readonly MemorySource buffer; /// /// Initializes a new instance of the struct. @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms { this.flatStartIndex = (index * buffer.Width) + left; this.Left = left; - this.buffer = buffer.Buffer; + this.buffer = buffer.MemorySource; this.Length = length; } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index aed650b8e..8048dd424 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -290,7 +290,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } // no need to dispose when buffer is not array owner - buffers[i] = new Buffer2D(new BasicArrayBuffer(values), values.Length, 1); + var source = new MemorySource(new BasicArrayBuffer(values), true); + buffers[i] = new Buffer2D(source, values.Length, 1); } return new JpegColorConverter.ComponentValues(buffers, 0); } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs index 46a688b49..9ffd42211 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs @@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg this.Output.WriteLine($"Component{i}: {diff}"); averageDifference += diff.average; totalDifference += diff.total; - tolerance += libJpegComponent.SpectralBlocks.Buffer.GetSpan().Length; + tolerance += libJpegComponent.SpectralBlocks.MemorySource.GetSpan().Length; } averageDifference /= componentCount; diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index 52d3929f6..5753d92b3 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Tests.Memory // Assert.Equal(width * y, span.Start); Assert.Equal(width, span.Length); - Assert.SpanPointsTo(span, buffer.Buffer.MemoryOwner, width * y); + Assert.SpanPointsTo(span, buffer.MemorySource.MemoryOwner, width * y); } } @@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests.Memory // Assert.Equal(width * y + x, span.Start); Assert.Equal(width - x, span.Length); - Assert.SpanPointsTo(span, buffer.Buffer.MemoryOwner, width * y + x); + Assert.SpanPointsTo(span, buffer.MemorySource.MemoryOwner, width * y + x); } } @@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (Buffer2D buffer = this.MemoryAllocator.Allocate2D(width, height)) { - Span span = buffer.Buffer.GetSpan(); + Span span = buffer.MemorySource.GetSpan(); ref TestStructs.Foo actual = ref buffer[x, y]; @@ -115,13 +115,13 @@ namespace SixLabors.ImageSharp.Tests.Memory using (Buffer2D a = this.MemoryAllocator.Allocate2D(10, 5)) using (Buffer2D b = this.MemoryAllocator.Allocate2D(3, 7)) { - IMemoryOwner aa = a.Buffer.MemoryOwner; - IMemoryOwner bb = b.Buffer.MemoryOwner; + IMemoryOwner aa = a.MemorySource.MemoryOwner; + IMemoryOwner bb = b.MemorySource.MemoryOwner; Buffer2D.SwapOrCopyContent(a, b); - Assert.Equal(bb, a.Buffer.MemoryOwner); - Assert.Equal(aa, b.Buffer.MemoryOwner); + Assert.Equal(bb, a.MemorySource.MemoryOwner); + Assert.Equal(aa, b.MemorySource.MemoryOwner); Assert.Equal(new Size(3, 7), a.Size()); Assert.Equal(new Size(10, 5), b.Size()); diff --git a/tests/ImageSharp.Tests/Memory/BufferManagerTests.cs b/tests/ImageSharp.Tests/Memory/MemorySourceTests.cs similarity index 60% rename from tests/ImageSharp.Tests/Memory/BufferManagerTests.cs rename to tests/ImageSharp.Tests/Memory/MemorySourceTests.cs index d08e734e8..9cdfb5635 100644 --- a/tests/ImageSharp.Tests/Memory/BufferManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/MemorySourceTests.cs @@ -12,21 +12,23 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Memory { - public class BufferManagerTests + public class MemorySourceTests { public class Construction { - [Fact] - public void InitializeAsOwner_MemoryOwner_IsPresent() + [Theory] + [InlineData(false)] + [InlineData(true)] + public void InitializeAsOwner(bool isInternalMemorySource) { var data = new Rgba32[21]; var mmg = new TestMemoryManager(data); - var a = new BufferManager(mmg); + var a = new MemorySource(mmg, isInternalMemorySource); Assert.Equal(mmg, a.MemoryOwner); Assert.Equal(mmg.Memory, a.Memory); - Assert.True(a.OwnsMemory); + Assert.Equal(isInternalMemorySource, a.HasSwappableContents); } [Fact] @@ -35,21 +37,23 @@ namespace SixLabors.ImageSharp.Tests.Memory var data = new Rgba32[21]; var mmg = new TestMemoryManager(data); - var a = new BufferManager(mmg.Memory); + var a = new MemorySource(mmg.Memory); Assert.Null(a.MemoryOwner); Assert.Equal(mmg.Memory, a.Memory); - Assert.False(a.OwnsMemory); + Assert.False(a.HasSwappableContents); } } public class Dispose { - [Fact] - public void WhenOwnershipIsTransfered_ShouldDisposeMemoryOwner() + [Theory] + [InlineData(false)] + [InlineData(true)] + public void WhenOwnershipIsTransfered_ShouldDisposeMemoryOwner(bool isInternalMemorySource) { var mmg = new TestMemoryManager(new int[10]); - var bmg = new BufferManager(mmg); + var bmg = new MemorySource(mmg, isInternalMemorySource); bmg.Dispose(); Assert.True(mmg.IsDisposed); @@ -59,7 +63,7 @@ namespace SixLabors.ImageSharp.Tests.Memory public void WhenMemoryObserver_ShouldNotDisposeAnything() { var mmg = new TestMemoryManager(new int[10]); - var bmg = new BufferManager(mmg.Memory); + var bmg = new MemorySource(mmg.Memory); bmg.Dispose(); Assert.False(mmg.IsDisposed); @@ -70,18 +74,18 @@ namespace SixLabors.ImageSharp.Tests.Memory { private MemoryAllocator MemoryAllocator { get; } = new TestMemoryAllocator(); - private BufferManager AllocateBufferManager(int length, AllocationOptions options = AllocationOptions.None) + private MemorySource AllocateMemorySource(int length, AllocationOptions options = AllocationOptions.None) where T : struct { - var owner = (IMemoryOwner)this.MemoryAllocator.Allocate(length, options); - return new BufferManager(owner); + IMemoryOwner owner = this.MemoryAllocator.Allocate(length, options); + return new MemorySource(owner, true); } [Fact] public void WhenBothAreMemoryOwners_ShouldSwap() { - BufferManager a = this.AllocateBufferManager(13); - BufferManager b = this.AllocateBufferManager(17); + MemorySource a = this.AllocateMemorySource(13); + MemorySource b = this.AllocateMemorySource(17); IMemoryOwner aa = a.MemoryOwner; IMemoryOwner bb = b.MemoryOwner; @@ -89,7 +93,7 @@ namespace SixLabors.ImageSharp.Tests.Memory Memory aaa = a.Memory; Memory bbb = b.Memory; - BufferManager.SwapOrCopyContent(ref a, ref b); + MemorySource.SwapOrCopyContent(ref a, ref b); Assert.Equal(bb, a.MemoryOwner); Assert.Equal(aa, b.MemoryOwner); @@ -100,26 +104,27 @@ namespace SixLabors.ImageSharp.Tests.Memory } [Theory] - [InlineData(false)] - [InlineData(true)] - public void WhenDestIsNotMemoryOwner_SameSize_ShouldCopy(bool sourceIsOwner) + [InlineData(false, false)] + [InlineData(true, true)] + [InlineData(true, false)] + public void WhenDestIsNotMemoryOwner_SameSize_ShouldCopy(bool sourceIsOwner, bool isInternalMemorySource) { var data = new Rgba32[21]; var color = new Rgba32(1, 2, 3, 4); var destOwner = new TestMemoryManager(data); - var dest = new BufferManager(destOwner.Memory); + var dest = new MemorySource(destOwner.Memory); - var sourceOwner = (IMemoryOwner)this.MemoryAllocator.Allocate(21); + IMemoryOwner sourceOwner = this.MemoryAllocator.Allocate(21); - BufferManager source = sourceIsOwner - ? new BufferManager(sourceOwner) - : new BufferManager(sourceOwner.Memory); + MemorySource source = sourceIsOwner + ? new MemorySource(sourceOwner, isInternalMemorySource) + : new MemorySource(sourceOwner.Memory); sourceOwner.Memory.Span[10] = color; // Act: - BufferManager.SwapOrCopyContent(ref dest, ref source); + MemorySource.SwapOrCopyContent(ref dest, ref source); // Assert: Assert.Equal(color, dest.Memory.Span[10]); @@ -136,18 +141,18 @@ namespace SixLabors.ImageSharp.Tests.Memory var color = new Rgba32(1, 2, 3, 4); var destOwner = new TestMemoryManager(data); - var dest = new BufferManager(destOwner.Memory); + var dest = new MemorySource(destOwner.Memory); - var sourceOwner = (IMemoryOwner)this.MemoryAllocator.Allocate(22); + IMemoryOwner sourceOwner = this.MemoryAllocator.Allocate(22); - BufferManager source = sourceIsOwner - ? new BufferManager(sourceOwner) - : new BufferManager(sourceOwner.Memory); + MemorySource source = sourceIsOwner + ? new MemorySource(sourceOwner, true) + : new MemorySource(sourceOwner.Memory); sourceOwner.Memory.Span[10] = color; // Act: Assert.ThrowsAny( - () => BufferManager.SwapOrCopyContent(ref dest, ref source) + () => MemorySource.SwapOrCopyContent(ref dest, ref source) ); Assert.Equal(color, source.Memory.Span[10]); From 390691f20905ba34d7feb7d32c43ad180e9f78d2 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Tue, 24 Jul 2018 01:08:41 +0200 Subject: [PATCH 62/68] WrapMemory(IMemoryOwner) + additional System.Drawing test case --- src/ImageSharp/Image.WrapMemory.cs | 95 ++++++++++++++++++- src/ImageSharp/Memory/MemorySource.cs | 1 + .../Image/ImageTests.WrapMemory.cs | 79 +++++++++++++-- 3 files changed, 167 insertions(+), 8 deletions(-) diff --git a/src/ImageSharp/Image.WrapMemory.cs b/src/ImageSharp/Image.WrapMemory.cs index c24a932e1..77432c3ad 100644 --- a/src/ImageSharp/Image.WrapMemory.cs +++ b/src/ImageSharp/Image.WrapMemory.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; + using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Memory; @@ -41,6 +43,27 @@ namespace SixLabors.ImageSharp /// allowing to view/manipulate it as an ImageSharp instance. /// /// The pixel type + /// The + /// The pixel memory + /// The width of the memory image + /// The height of the memory image + /// An instance + public static Image WrapMemory( + Configuration config, + Memory pixelMemory, + int width, + int height) + where TPixel : struct, IPixel + { + return WrapMemory(config, pixelMemory, width, height, new ImageMetaData()); + } + + /// + /// Wraps an existing contigous memory area of 'width'x'height' pixels, + /// allowing to view/manipulate it as an ImageSharp instance. + /// The memory is being observed, the caller remains responsible for managing it's lifecycle. + /// + /// The pixel type /// The pixel memory /// The width of the memory image /// The height of the memory image @@ -51,7 +74,77 @@ namespace SixLabors.ImageSharp int height) where TPixel : struct, IPixel { - return WrapMemory(Configuration.Default, pixelMemory, width, height, new ImageMetaData()); + return WrapMemory(Configuration.Default, pixelMemory, width, height); + } + + /// + /// Wraps an existing contigous memory area of 'width'x'height' pixels, + /// allowing to view/manipulate it as an ImageSharp instance. + /// The ownership of the is being transfered to the new instance, + /// meaning that the caller is not allowed to dispose . + /// It will be disposed together with the result image. + /// + /// The pixel type + /// The + /// The that is being transfered to the image + /// The width of the memory image + /// The height of the memory image + /// The + /// An instance + public static Image WrapMemory( + Configuration config, + IMemoryOwner pixelMemoryOwner, + int width, + int height, + ImageMetaData metaData) + where TPixel : struct, IPixel + { + var memorySource = new MemorySource(pixelMemoryOwner, false); + return new Image(config, memorySource, width, height, metaData); + } + + /// + /// Wraps an existing contigous memory area of 'width'x'height' pixels, + /// allowing to view/manipulate it as an ImageSharp instance. + /// The ownership of the is being transfered to the new instance, + /// meaning that the caller is not allowed to dispose . + /// It will be disposed together with the result image. + /// + /// The pixel type + /// The + /// The that is being transfered to the image + /// The width of the memory image + /// The height of the memory image + /// An instance + public static Image WrapMemory( + Configuration config, + IMemoryOwner pixelMemoryOwner, + int width, + int height) + where TPixel : struct, IPixel + { + return WrapMemory(config, pixelMemoryOwner, width, height, new ImageMetaData()); + } + + /// + /// Wraps an existing contigous memory area of 'width'x'height' pixels, + /// allowing to view/manipulate it as an ImageSharp instance. + /// The ownership of the is being transfered to the new instance, + /// meaning that the caller is not allowed to dispose . + /// It will be disposed together with the result image. + /// + /// The pixel type + /// The that is being transfered to the image + /// The width of the memory image + /// The height of the memory image + /// An instance + public static Image WrapMemory( + IMemoryOwner pixelMemoryOwner, + int width, + int height) + where TPixel : struct, IPixel + { + return WrapMemory(Configuration.Default, pixelMemoryOwner, width, height); } } } \ No newline at end of file diff --git a/src/ImageSharp/Memory/MemorySource.cs b/src/ImageSharp/Memory/MemorySource.cs index 27bca11c1..4253307ef 100644 --- a/src/ImageSharp/Memory/MemorySource.cs +++ b/src/ImageSharp/Memory/MemorySource.cs @@ -8,6 +8,7 @@ namespace SixLabors.Memory { /// /// Holds a that is either OWNED or CONSUMED. + /// When the memory is being owned, the instance is also known. /// Implements content transfer logic in that depends on the ownership status. /// This is needed to transfer the contents of a temporary /// to a persistent without copying the buffer. diff --git a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs index 57f757176..815684d84 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs @@ -5,9 +5,11 @@ using System; using System.Buffers; using System.Drawing; using System.Drawing.Imaging; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Memory; using SixLabors.Shapes; using SixLabors.ImageSharp.Processing; using Xunit; @@ -19,13 +21,17 @@ namespace SixLabors.ImageSharp.Tests { public class WrapMemory { + /// + /// A exposing the locked pixel memory of a instance. + /// TODO: This should be an example in https://github.com/SixLabors/Samples + /// class BitmapMemoryManager : MemoryManager { - private System.Drawing.Bitmap bitmap; + private readonly Bitmap bitmap; - private BitmapData bmpData; + private readonly BitmapData bmpData; - private int length; + private readonly int length; public BitmapMemoryManager(Bitmap bitmap) { @@ -40,9 +46,21 @@ namespace SixLabors.ImageSharp.Tests this.length = bitmap.Width * bitmap.Height; } + public bool IsDisposed { get; private set; } + protected override void Dispose(bool disposing) { - this.bitmap.UnlockBits(this.bmpData); + if (this.IsDisposed) + { + return; + } + + if (disposing) + { + this.bitmap.UnlockBits(this.bmpData); + } + + this.IsDisposed = true; } public override unsafe Span GetSpan() @@ -63,7 +81,26 @@ namespace SixLabors.ImageSharp.Tests } [Fact] - public void WrapSystemDrawingBitmap() + public void WrapMemory_CreatedImageIsCorrect() + { + Configuration cfg = Configuration.Default.ShallowCopy(); + var metaData = new ImageMetaData(); + + var array = new Rgba32[25]; + var memory = new Memory(array); + + using (var image = Image.WrapMemory(cfg, memory, 5, 5, metaData)) + { + ref Rgba32 pixel0 = ref image.GetPixelSpan()[0]; + Assert.True(Unsafe.AreSame(ref array[0], ref pixel0)); + + Assert.Equal(cfg, image.GetConfiguration()); + Assert.Equal(metaData, image.MetaData); + } + } + + [Fact] + public void WrapSystemDrawingBitmap_WhenObserved() { using (var bmp = new Bitmap(51, 23)) { @@ -75,13 +112,41 @@ namespace SixLabors.ImageSharp.Tests using (var image = Image.WrapMemory(memory, bmp.Width, bmp.Height)) { + Assert.Equal(memory, image.GetPixelMemory()); image.Mutate(c => c.Fill(bg).Fill(fg, new RectangularPolygon(10, 10, 10, 10))); } + + Assert.False(memoryManager.IsDisposed); } string fn = System.IO.Path.Combine( TestEnvironment.ActualOutputDirectoryFullPath, - "WrapSystemDrawingBitmap.bmp"); + $"{nameof(this.WrapSystemDrawingBitmap_WhenObserved)}.bmp"); + + bmp.Save(fn, ImageFormat.Bmp); + } + } + + [Fact] + public void WrapSystemDrawingBitmap_WhenOwned() + { + using (var bmp = new Bitmap(51, 23)) + { + var memoryManager = new BitmapMemoryManager(bmp); + Bgra32 bg = NamedColors.Red; + Bgra32 fg = NamedColors.Green; + + using (var image = Image.WrapMemory(memoryManager, bmp.Width, bmp.Height)) + { + Assert.Equal(memoryManager.Memory, image.GetPixelMemory()); + image.Mutate(c => c.Fill(bg).Fill(fg, new RectangularPolygon(10, 10, 10, 10))); + } + + Assert.True(memoryManager.IsDisposed); + + string fn = System.IO.Path.Combine( + TestEnvironment.ActualOutputDirectoryFullPath, + $"{nameof(this.WrapSystemDrawingBitmap_WhenOwned)}.bmp"); bmp.Save(fn, ImageFormat.Bmp); } From f4e8000fb16daec9b3d88962a93c2ded621f453c Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Tue, 24 Jul 2018 01:21:24 +0200 Subject: [PATCH 63/68] WhitespaceCop --- src/ImageSharp/Memory/MemorySource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Memory/MemorySource.cs b/src/ImageSharp/Memory/MemorySource.cs index 4253307ef..c0a74b5f8 100644 --- a/src/ImageSharp/Memory/MemorySource.cs +++ b/src/ImageSharp/Memory/MemorySource.cs @@ -21,7 +21,7 @@ namespace SixLabors.Memory internal struct MemorySource : IDisposable { /// - /// Initializes a new instance of the struct + /// Initializes a new instance of the struct /// by wrapping an existing . /// /// The to wrap From 3033b6924694b6d848e5696d4c0306978e317af0 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 24 Jul 2018 09:25:30 +0100 Subject: [PATCH 64/68] delete golang jpeg decoder --- .../Decoder}/DoubleBufferedStreamReader.cs | 2 +- .../Decoder}/FastACTables.cs | 11 +- .../Decoder}/FixedByteBuffer256.cs | 2 +- .../Decoder}/FixedByteBuffer512.cs | 2 +- .../Decoder}/FixedInt16Buffer257.cs | 2 +- .../Decoder}/FixedInt32Buffer18.cs | 2 +- .../Decoder}/FixedUInt32Buffer18.cs | 2 +- .../Decoder/HuffmanTable.cs} | 8 +- .../Decoder/HuffmanTables.cs} | 13 +- .../Decoder/JpegFileMarker.cs} | 14 +- .../Decoder/JpegFrame.cs} | 8 +- .../Decoder/JpegFrameComponent.cs} | 12 +- .../Decoder}/ScanDecoder.cs | 62 +- .../GolangPort/Components/Decoder/Bits.cs | 155 ---- .../GolangPort/Components/Decoder/Bytes.cs | 255 ------ .../Components/Decoder/DecoderThrowHelper.cs | 96 -- .../Components/Decoder/EOFException.cs | 23 - .../Components/Decoder/GolangComponent.cs | 253 ------ .../Components/Decoder/GolangComponentScan.cs | 29 - .../Decoder/GolangDecoderErrorCode.cs | 27 - .../Components/Decoder/GolangHuffmanTree.cs | 260 ------ .../GolangJpegScanDecoder.ComputationData.cs | 53 -- .../GolangJpegScanDecoder.DataPointers.cs | 51 -- .../Decoder/GolangJpegScanDecoder.cs | 705 --------------- .../Components/Decoder/InputProcessor.cs | 392 --------- .../Components/Decoder/JpegScanDecoder.md | 25 - .../Decoder/MissingFF00Exception.cs | 15 - .../Jpeg/GolangPort/GolangJpegDecoder.cs | 42 - .../Jpeg/GolangPort/GolangJpegDecoderCore.cs | 824 ------------------ src/ImageSharp/Formats/Jpeg/JpegDecoder.cs | 6 +- ...sJpegDecoderCore.cs => JpegDecoderCore.cs} | 51 +- .../Jpeg/PdfJsPort/PdfJsJpegDecoder.cs | 42 - .../Codecs/Jpeg/DecodeJpeg.cs | 20 +- .../Codecs/Jpeg/DecodeJpegMultiple.cs | 13 +- .../Codecs/Jpeg/DecodeJpegParseStreamOnly.cs | 5 +- .../Codecs/Jpeg/DoubleBufferedStreams.cs | 9 +- .../Codecs/Jpeg/EncodeJpeg.cs | 4 +- .../Codecs/Jpeg/IdentifyJpeg.cs | 19 +- .../Codecs/Jpeg/LoadResizeSave.cs | 8 +- .../Jpg/DoubleBufferedStreamReaderTests.cs | 3 +- .../Formats/Jpg/JpegDecoderTests.Baseline.cs | 45 +- .../Formats/Jpg/JpegDecoderTests.MetaData.cs | 26 +- .../Jpg/JpegDecoderTests.Progressive.cs | 40 +- .../Formats/Jpg/JpegDecoderTests.cs | 35 +- .../Jpg/JpegImagePostProcessorTests.cs | 7 +- .../Formats/Jpg/JpegProfilingBenchmarks.cs | 15 +- .../Formats/Jpg/ParseStreamTests.cs | 134 +-- .../Formats/Jpg/SpectralJpegTests.cs | 73 +- .../Formats/Jpg/Utils/JpegFixture.cs | 17 +- .../Jpg/Utils/LibJpegTools.ComponentData.cs | 55 +- .../Jpg/Utils/LibJpegTools.SpectralData.cs | 30 +- 51 files changed, 213 insertions(+), 3789 deletions(-) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components => Components/Decoder}/DoubleBufferedStreamReader.cs (99%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components => Components/Decoder}/FastACTables.cs (89%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components => Components/Decoder}/FixedByteBuffer256.cs (90%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components => Components/Decoder}/FixedByteBuffer512.cs (90%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components => Components/Decoder}/FixedInt16Buffer257.cs (90%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components => Components/Decoder}/FixedInt32Buffer18.cs (90%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components => Components/Decoder}/FixedUInt32Buffer18.cs (90%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components/PdfJsHuffmanTable.cs => Components/Decoder/HuffmanTable.cs} (93%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components/PdfJsHuffmanTables.cs => Components/Decoder/HuffmanTables.cs} (54%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components/PdfJsFileMarker.cs => Components/Decoder/JpegFileMarker.cs} (79%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components/PdfJsFrame.cs => Components/Decoder/JpegFrame.cs} (92%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components/PdfJsFrameComponent.cs => Components/Decoder/JpegFrameComponent.cs} (90%) rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/Components => Components/Decoder}/ScanDecoder.cs (93%) delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderThrowHelper.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/EOFException.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponentScan.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangDecoderErrorCode.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangHuffmanTree.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.ComputationData.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.DataPointers.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegScanDecoder.md delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/MissingFF00Exception.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoder.cs delete mode 100644 src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs rename src/ImageSharp/Formats/Jpeg/{PdfJsPort/PdfJsJpegDecoderCore.cs => JpegDecoderCore.cs} (93%) delete mode 100644 src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoder.cs diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/DoubleBufferedStreamReader.cs similarity index 99% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/DoubleBufferedStreamReader.cs index 0e42d074c..f4527966a 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/DoubleBufferedStreamReader.cs @@ -8,7 +8,7 @@ using System.Runtime.CompilerServices; using SixLabors.Memory; // TODO: This could be useful elsewhere. -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// A stream reader that add a secondary level buffer in addition to native stream buffered reading diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FastACTables.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FastACTables.cs similarity index 89% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FastACTables.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/FastACTables.cs index 0fc85c6e4..6d06abecf 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FastACTables.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FastACTables.cs @@ -5,7 +5,7 @@ using System; using System.Runtime.CompilerServices; using SixLabors.Memory; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// The collection of lookup tables used for fast AC entropy scan decoding. @@ -35,10 +35,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components } /// - /// Gets a reference to the first element of the AC table indexed by - /// + /// Gets a reference to the first element of the AC table indexed by /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref short GetAcTableReference(PdfJsFrameComponent component) + public ref short GetAcTableReference(JpegFrameComponent component) { return ref this.tables.GetRowSpan(component.ACHuffmanTableId)[0]; } @@ -48,11 +47,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// /// The table index. /// The collection of AC Huffman tables. - public void BuildACTableLut(int index, PdfJsHuffmanTables acHuffmanTables) + public void BuildACTableLut(int index, HuffmanTables acHuffmanTables) { const int FastBits = ScanDecoder.FastBits; Span fastAC = this.tables.GetRowSpan(index); - ref PdfJsHuffmanTable huffman = ref acHuffmanTables[index]; + ref HuffmanTable huffman = ref acHuffmanTables[index]; int i; for (i = 0; i < (1 << FastBits); i++) diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedByteBuffer256.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedByteBuffer256.cs similarity index 90% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedByteBuffer256.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedByteBuffer256.cs index 5870e3da8..1d26178e0 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedByteBuffer256.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedByteBuffer256.cs @@ -4,7 +4,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { [StructLayout(LayoutKind.Sequential)] internal unsafe struct FixedByteBuffer256 diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedByteBuffer512.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedByteBuffer512.cs similarity index 90% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedByteBuffer512.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedByteBuffer512.cs index c509903c9..556e74fd5 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedByteBuffer512.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedByteBuffer512.cs @@ -4,7 +4,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { [StructLayout(LayoutKind.Sequential)] internal unsafe struct FixedByteBuffer512 diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer257.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedInt16Buffer257.cs similarity index 90% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer257.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedInt16Buffer257.cs index b304dbf8c..a3b67a700 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt16Buffer257.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedInt16Buffer257.cs @@ -4,7 +4,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { [StructLayout(LayoutKind.Sequential)] internal unsafe struct FixedInt16Buffer257 diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt32Buffer18.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedInt32Buffer18.cs similarity index 90% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt32Buffer18.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedInt32Buffer18.cs index f8507ec47..bba89f072 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedInt32Buffer18.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedInt32Buffer18.cs @@ -4,7 +4,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { [StructLayout(LayoutKind.Sequential)] internal unsafe struct FixedInt32Buffer18 diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedUInt32Buffer18.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedUInt32Buffer18.cs similarity index 90% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedUInt32Buffer18.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedUInt32Buffer18.cs index 9b076d9da..1d3ca9933 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/FixedUInt32Buffer18.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FixedUInt32Buffer18.cs @@ -4,7 +4,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { [StructLayout(LayoutKind.Sequential)] internal unsafe struct FixedUInt32Buffer18 diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs similarity index 93% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs index 15ae56331..c0f3b17cd 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs @@ -6,13 +6,13 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.Memory; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Represents a Huffman Table /// [StructLayout(LayoutKind.Sequential)] - internal unsafe struct PdfJsHuffmanTable + internal unsafe struct HuffmanTable { /// /// Gets the max code array @@ -40,12 +40,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components public FixedInt16Buffer257 Sizes; /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The to use for buffer allocations. /// The code lengths /// The huffman values - public PdfJsHuffmanTable(MemoryAllocator memoryAllocator, ReadOnlySpan count, ReadOnlySpan values) + public HuffmanTable(MemoryAllocator memoryAllocator, ReadOnlySpan count, ReadOnlySpan values) { const int Length = 257; using (IBuffer huffcode = memoryAllocator.Allocate(Length)) diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTables.cs similarity index 54% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTables.cs index 5cbde2b88..dc066aa0a 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTables.cs @@ -1,24 +1,23 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Collections.Generic; using System.Runtime.CompilerServices; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// - /// Defines a 2 pairs of huffman tables + /// Defines a 2 pairs of huffman tables. /// - internal sealed class PdfJsHuffmanTables + internal sealed class HuffmanTables { - private readonly PdfJsHuffmanTable[] tables = new PdfJsHuffmanTable[4]; + private readonly HuffmanTable[] tables = new HuffmanTable[4]; /// /// Gets or sets the table at the given index. /// /// The index - /// The - public ref PdfJsHuffmanTable this[int index] + /// The + public ref HuffmanTable this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => ref this.tables[index]; diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFileMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs similarity index 79% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFileMarker.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs index 85c9f9466..31f4efdcb 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFileMarker.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs @@ -3,19 +3,19 @@ using System.Runtime.CompilerServices; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// - /// Represents a jpeg file marker + /// Represents a jpeg file marker. /// - internal readonly struct PdfJsFileMarker + internal readonly struct JpegFileMarker { /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The marker /// The position within the stream - public PdfJsFileMarker(byte marker, long position) + public JpegFileMarker(byte marker, long position) { this.Marker = marker; this.Position = position; @@ -23,12 +23,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The marker /// The position within the stream /// Whether the current marker is invalid - public PdfJsFileMarker(byte marker, long position, bool invalid) + public JpegFileMarker(byte marker, long position, bool invalid) { this.Marker = marker; this.Position = position; diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrame.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs similarity index 92% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrame.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs index 8ce981a09..a238e0734 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrame.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs @@ -3,12 +3,12 @@ using System; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Represent a single jpeg frame /// - internal sealed class PdfJsFrame : IDisposable + internal sealed class JpegFrame : IDisposable { /// /// Gets or sets a value indicating whether the frame uses the extended specification @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// /// Gets or sets the frame component collection /// - public PdfJsFrameComponent[] Components { get; set; } + public JpegFrameComponent[] Components { get; set; } /// /// Gets or sets the maximum horizontal sampling factor @@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components for (int i = 0; i < this.ComponentCount; i++) { - PdfJsFrameComponent component = this.Components[i]; + JpegFrameComponent component = this.Components[i]; component.Init(); } } diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrameComponent.cs similarity index 90% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrameComponent.cs index 7d4eb66e8..3ce7cacfa 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrameComponent.cs @@ -5,21 +5,19 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats.Jpeg.Components; -using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Represents a single frame component /// - internal class PdfJsFrameComponent : IDisposable, IJpegComponent + internal class JpegFrameComponent : IDisposable, IJpegComponent { private readonly MemoryAllocator memoryAllocator; - public PdfJsFrameComponent(MemoryAllocator memoryAllocator, PdfJsFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index) + public JpegFrameComponent(MemoryAllocator memoryAllocator, JpegFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index) { this.memoryAllocator = memoryAllocator; this.Frame = frame; @@ -89,7 +87,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// public int ACHuffmanTableId { get; set; } - public PdfJsFrame Frame { get; } + public JpegFrame Frame { get; } /// public void Dispose() @@ -125,7 +123,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components } else { - PdfJsFrameComponent c0 = this.Frame.Components[0]; + JpegFrameComponent c0 = this.Frame.Components[0]; this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors); } diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs similarity index 93% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ScanDecoder.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs index 8575bac69..5afe6382f 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/ScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs @@ -2,10 +2,8 @@ // 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 +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Decodes the Huffman encoded spectral scan. @@ -23,13 +21,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components // 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 JpegFrame frame; + private readonly HuffmanTables dcHuffmanTables; + private readonly HuffmanTables acHuffmanTables; private readonly FastACTables fastACTables; private readonly DoubleBufferedStreamReader stream; - private readonly PdfJsFrameComponent[] components; + private readonly JpegFrameComponent[] components; private readonly ZigZag dctZigZag; // The restart interval. @@ -97,9 +95,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// The successive approximation bit low end. public ScanDecoder( DoubleBufferedStreamReader stream, - PdfJsFrame frame, - PdfJsHuffmanTables dcHuffmanTables, - PdfJsHuffmanTables acHuffmanTables, + JpegFrame frame, + HuffmanTables dcHuffmanTables, + HuffmanTables acHuffmanTables, FastACTables fastACTables, int componentIndex, int componentsLength, @@ -177,10 +175,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components // Scan an interleaved mcu... process components in order for (int k = 0; k < this.componentsLength; k++) { - PdfJsFrameComponent component = this.components[k]; + JpegFrameComponent component = this.components[k]; - ref PdfJsHuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; - ref PdfJsHuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId]; + ref HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; + ref HuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId]; ref short fastACRef = ref this.fastACTables.GetAcTableReference(component); int h = component.HorizontalSamplingFactor; int v = component.VerticalSamplingFactor; @@ -231,13 +229,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// private void ParseBaselineDataNonInterleaved() { - PdfJsFrameComponent component = this.components[this.componentIndex]; + JpegFrameComponent 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 HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; + ref HuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId]; ref short fastACRef = ref this.fastACTables.GetAcTableReference(component); int mcu = 0; @@ -296,8 +294,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components // 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]; + JpegFrameComponent component = this.components[k]; + ref HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; int h = component.HorizontalSamplingFactor; int v = component.VerticalSamplingFactor; @@ -345,13 +343,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components /// private void ParseProgressiveDataNonInterleaved() { - PdfJsFrameComponent component = this.components[this.componentIndex]; + JpegFrameComponent 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 HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; + ref HuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId]; ref short fastACRef = ref this.fastACTables.GetAcTableReference(component); int mcu = 0; @@ -396,11 +394,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components } private void DecodeBlockBaseline( - PdfJsFrameComponent component, + JpegFrameComponent component, int row, int col, - ref PdfJsHuffmanTable dcTable, - ref PdfJsHuffmanTable acTable, + ref HuffmanTable dcTable, + ref HuffmanTable acTable, ref short fastACRef) { this.CheckBits(); @@ -475,10 +473,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components } private void DecodeBlockProgressiveDC( - PdfJsFrameComponent component, + JpegFrameComponent component, int row, int col, - ref PdfJsHuffmanTable dcTable) + ref HuffmanTable dcTable) { if (this.spectralEnd != 0) { @@ -511,10 +509,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components } private void DecodeBlockProgressiveAC( - PdfJsFrameComponent component, + JpegFrameComponent component, int row, int col, - ref PdfJsHuffmanTable acTable, + ref HuffmanTable acTable, ref short fastACRef) { if (this.spectralStart == 0) @@ -603,7 +601,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components } } - private void DecodeBlockProgressiveACRefined(ref short blockDataRef, ref PdfJsHuffmanTable acTable) + private void DecodeBlockProgressiveACRefined(ref short blockDataRef, ref HuffmanTable acTable) { int k; @@ -805,7 +803,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components } [MethodImpl(InliningOptions.ShortMethod)] - private int DecodeHuffman(ref PdfJsHuffmanTable table) + private int DecodeHuffman(ref HuffmanTable table) { this.CheckBits(); @@ -830,7 +828,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components } [MethodImpl(InliningOptions.ColdPath)] - private int DecodeHuffmanSlow(ref PdfJsHuffmanTable table) + private int DecodeHuffmanSlow(ref HuffmanTable 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 @@ -941,7 +939,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components for (int i = 0; i < this.components.Length; i++) { - PdfJsFrameComponent c = this.components[i]; + JpegFrameComponent c = this.components[i]; c.DcPredictor = 0; } diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs deleted file mode 100644 index 353eb01fe..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System.Runtime.CompilerServices; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// Holds the unprocessed bits that have been taken from the byte-stream. - /// The n least significant bits of a form the unread bits, to be read in MSB to - /// LSB order. - /// - internal struct Bits - { - /// - /// Gets or sets the accumulator. - /// - public int Accumulator; - - /// - /// Gets or sets the mask. - /// 0, with mask==0 when unreadbits==0.]]> - /// - public int Mask; - - /// - /// Gets or sets the number of unread bits in the accumulator. - /// - public int UnreadBits; - - /// - /// Reads bytes from the byte buffer to ensure that bits.UnreadBits is at - /// least n. For best performance (avoiding function calls inside hot loops), - /// the caller is the one responsible for first checking that bits.UnreadBits < n. - /// - /// The number of bits to ensure. - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void EnsureNBits(int n, ref InputProcessor inputProcessor) - { - GolangDecoderErrorCode errorCode = this.EnsureNBitsUnsafe(n, ref inputProcessor); - errorCode.EnsureNoError(); - } - - /// - /// Reads bytes from the byte buffer to ensure that bits.UnreadBits is at - /// least n. For best performance (avoiding function calls inside hot loops), - /// the caller is the one responsible for first checking that bits.UnreadBits < n. - /// This method does not throw. Returns instead. - /// - /// The number of bits to ensure. - /// The - /// Error code - public GolangDecoderErrorCode EnsureNBitsUnsafe(int n, ref InputProcessor inputProcessor) - { - while (true) - { - GolangDecoderErrorCode errorCode = this.EnsureBitsStepImpl(ref inputProcessor); - if (errorCode != GolangDecoderErrorCode.NoError || this.UnreadBits >= n) - { - return errorCode; - } - } - } - - /// - /// Unrolled version of for n==8 - /// - /// The - /// A - public GolangDecoderErrorCode Ensure8BitsUnsafe(ref InputProcessor inputProcessor) - { - return this.EnsureBitsStepImpl(ref inputProcessor); - } - - /// - /// Unrolled version of for n==1 - /// - /// The - /// A - public GolangDecoderErrorCode Ensure1BitUnsafe(ref InputProcessor inputProcessor) - { - return this.EnsureBitsStepImpl(ref inputProcessor); - } - - /// - /// Receive extend - /// - /// Byte - /// The - /// Read bits value - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int ReceiveExtend(int t, ref InputProcessor inputProcessor) - { - GolangDecoderErrorCode errorCode = this.ReceiveExtendUnsafe(t, ref inputProcessor, out int x); - errorCode.EnsureNoError(); - return x; - } - - /// - /// Receive extend - /// - /// Byte - /// The - /// Read bits value - /// The - public GolangDecoderErrorCode ReceiveExtendUnsafe(int t, ref InputProcessor inputProcessor, out int x) - { - if (this.UnreadBits < t) - { - GolangDecoderErrorCode errorCode = this.EnsureNBitsUnsafe(t, ref inputProcessor); - if (errorCode != GolangDecoderErrorCode.NoError) - { - x = int.MaxValue; - return errorCode; - } - } - - this.UnreadBits -= t; - this.Mask >>= t; - int s = 1 << t; - x = (this.Accumulator >> this.UnreadBits) & (s - 1); - - if (x < (s >> 1)) - { - x += ((-1) << t) + 1; - } - - return GolangDecoderErrorCode.NoError; - } - - private GolangDecoderErrorCode EnsureBitsStepImpl(ref InputProcessor inputProcessor) - { - GolangDecoderErrorCode errorCode = inputProcessor.Bytes.ReadByteStuffedByteUnsafe(inputProcessor.InputStream, out int c); - - if (errorCode != GolangDecoderErrorCode.NoError) - { - return errorCode; - } - - this.Accumulator = (this.Accumulator << 8) | c; - this.UnreadBits += 8; - if (this.Mask == 0) - { - this.Mask = 1 << 7; - } - else - { - this.Mask <<= 8; - } - - return errorCode; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs deleted file mode 100644 index c8c68aa7e..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.IO; -using System.Runtime.CompilerServices; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// Bytes is a byte buffer, similar to a stream, except that it - /// has to be able to unread more than 1 byte, due to byte stuffing. - /// Byte stuffing is specified in section F.1.2.3. - /// TODO: Optimize buffer management inside this class! - /// - internal struct Bytes : IDisposable - { - /// - /// Specifies the buffer size for and - /// - public const int BufferSize = 4096; - - /// - /// Gets or sets the buffer. - /// buffer[i:j] are the buffered bytes read from the underlying - /// stream that haven't yet been passed further on. - /// - public byte[] Buffer; - - /// - /// Values of converted to -s - /// - public int[] BufferAsInt; - - /// - /// Start of bytes read - /// - public int I; - - /// - /// End of bytes read - /// - public int J; - - /// - /// Gets or sets the unreadable bytes. The number of bytes to back up i after - /// overshooting. It can be 0, 1 or 2. - /// - public int UnreadableBytes; - - /// - /// Creates a new instance of the , and initializes it's buffer. - /// - /// The bytes created - public static Bytes Create() - { - // DO NOT bother with buffers and array pooling here! - // It only makes things worse! - return new Bytes - { - Buffer = new byte[BufferSize], - BufferAsInt = new int[BufferSize] - }; - } - - /// - /// Disposes of the underlying buffer - /// - public void Dispose() - { - this.Buffer = null; - this.BufferAsInt = null; - } - - /// - /// ReadByteStuffedByte is like ReadByte but is for byte-stuffed Huffman data. - /// - /// Input stream - /// The result byte as - /// The - public GolangDecoderErrorCode ReadByteStuffedByteUnsafe(Stream inputStream, out int x) - { - // Take the fast path if bytes.buf contains at least two bytes. - if (this.I + 2 <= this.J) - { - x = this.BufferAsInt[this.I]; - this.I++; - this.UnreadableBytes = 1; - if (x != JpegConstants.Markers.XFFInt) - { - return GolangDecoderErrorCode.NoError; - } - - if (this.BufferAsInt[this.I] != 0x00) - { - return GolangDecoderErrorCode.MissingFF00; - } - - this.I++; - this.UnreadableBytes = 2; - x = JpegConstants.Markers.XFF; - return GolangDecoderErrorCode.NoError; - } - - this.UnreadableBytes = 0; - - GolangDecoderErrorCode errorCode = this.ReadByteAsIntUnsafe(inputStream, out x); - this.UnreadableBytes = 1; - if (errorCode != GolangDecoderErrorCode.NoError) - { - return errorCode; - } - - if (x != JpegConstants.Markers.XFF) - { - return GolangDecoderErrorCode.NoError; - } - - errorCode = this.ReadByteAsIntUnsafe(inputStream, out x); - this.UnreadableBytes = 2; - if (errorCode != GolangDecoderErrorCode.NoError) - { - return errorCode; - } - - if (x != 0x00) - { - return GolangDecoderErrorCode.MissingFF00; - } - - x = JpegConstants.Markers.XFF; - return GolangDecoderErrorCode.NoError; - } - - /// - /// Returns the next byte, whether buffered or not buffered. It does not care about byte stuffing. - /// - /// Input stream - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public byte ReadByte(Stream inputStream) - { - GolangDecoderErrorCode errorCode = this.ReadByteUnsafe(inputStream, out byte result); - errorCode.EnsureNoError(); - return result; - } - - /// - /// Extracts the next byte, whether buffered or not buffered into the result out parameter. It does not care about byte stuffing. - /// This method does not throw on format error, it returns a instead. - /// - /// Input stream - /// The result as out parameter - /// The - public GolangDecoderErrorCode ReadByteUnsafe(Stream inputStream, out byte result) - { - GolangDecoderErrorCode errorCode = GolangDecoderErrorCode.NoError; - while (this.I == this.J) - { - errorCode = this.FillUnsafe(inputStream); - if (errorCode != GolangDecoderErrorCode.NoError) - { - result = 0; - return errorCode; - } - } - - result = this.Buffer[this.I]; - this.I++; - this.UnreadableBytes = 0; - return errorCode; - } - - /// - /// Same as but the result is an - /// - /// The input stream - /// The result - /// A - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public GolangDecoderErrorCode ReadByteAsIntUnsafe(Stream inputStream, out int result) - { - GolangDecoderErrorCode errorCode = GolangDecoderErrorCode.NoError; - while (this.I == this.J) - { - errorCode = this.FillUnsafe(inputStream); - if (errorCode != GolangDecoderErrorCode.NoError) - { - result = 0; - return errorCode; - } - } - - result = this.BufferAsInt[this.I]; - this.I++; - this.UnreadableBytes = 0; - return errorCode; - } - - /// - /// Fills up the bytes buffer from the underlying stream. - /// It should only be called when there are no unread bytes in bytes. - /// - /// Thrown when reached end of stream unexpectedly. - /// Input stream - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Fill(Stream inputStream) - { - GolangDecoderErrorCode errorCode = this.FillUnsafe(inputStream); - errorCode.EnsureNoError(); - } - - /// - /// Fills up the bytes buffer from the underlying stream. - /// It should only be called when there are no unread bytes in bytes. - /// This method does not throw , returns a instead! - /// - /// Input stream - /// The - public GolangDecoderErrorCode FillUnsafe(Stream inputStream) - { - if (this.I != this.J) - { - // Unrecoverable error in the input, throwing! - DecoderThrowHelper.ThrowImageFormatException.FillCalledWhenUnreadBytesExist(); - } - - // Move the last 2 bytes to the start of the buffer, in case we need - // to call UnreadByteStuffedByte. - if (this.J > 2) - { - this.Buffer[0] = this.Buffer[this.J - 2]; - this.Buffer[1] = this.Buffer[this.J - 1]; - this.I = 2; - this.J = 2; - } - - // Fill in the rest of the buffer. - int n = inputStream.Read(this.Buffer, this.J, this.Buffer.Length - this.J); - if (n == 0) - { - return GolangDecoderErrorCode.UnexpectedEndOfStream; - } - - this.J += n; - - for (int i = 0; i < this.Buffer.Length; i++) - { - this.BufferAsInt[i] = this.Buffer[i]; - } - - return GolangDecoderErrorCode.NoError; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderThrowHelper.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderThrowHelper.cs deleted file mode 100644 index 2b2bc61ba..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderThrowHelper.cs +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Runtime.CompilerServices; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// Encapsulates exception thrower methods for the Jpeg Encoder - /// - internal static class DecoderThrowHelper - { - /// - /// Throws an exception that belongs to the given - /// - /// The - [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowExceptionForErrorCode(this GolangDecoderErrorCode errorCode) - { - // REMARK: If this method throws for an image that is expected to be decodable, - // consider using the ***Unsafe variant of the parsing method that asks for ThrowExceptionForErrorCode() - // then verify the error code + implement fallback logic manually! - switch (errorCode) - { - case GolangDecoderErrorCode.NoError: - throw new ArgumentException("ThrowExceptionForErrorCode() called with NoError!", nameof(errorCode)); - case GolangDecoderErrorCode.MissingFF00: - throw new MissingFF00Exception(); - case GolangDecoderErrorCode.UnexpectedEndOfStream: - throw new EOFException(); - default: - throw new ArgumentOutOfRangeException(nameof(errorCode), errorCode, null); - } - } - - /// - /// Throws an exception if the given defines an error. - /// - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void EnsureNoError(this GolangDecoderErrorCode errorCode) - { - if (errorCode != GolangDecoderErrorCode.NoError) - { - ThrowExceptionForErrorCode(errorCode); - } - } - - /// - /// Throws an exception if the given is . - /// - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void EnsureNoEOF(this GolangDecoderErrorCode errorCode) - { - if (errorCode == GolangDecoderErrorCode.UnexpectedEndOfStream) - { - errorCode.ThrowExceptionForErrorCode(); - } - } - - /// - /// Encapsulates methods throwing different flavours of -s. - /// - public static class ThrowImageFormatException - { - /// - /// Throws "Fill called when unread bytes exist". - /// - [MethodImpl(MethodImplOptions.NoInlining)] - public static void FillCalledWhenUnreadBytesExist() - { - throw new ImageFormatException("Fill called when unread bytes exist!"); - } - - /// - /// Throws "Bad Huffman code". - /// - [MethodImpl(MethodImplOptions.NoInlining)] - public static void BadHuffmanCode() - { - throw new ImageFormatException("Bad Huffman code!"); - } - - /// - /// Throws "Uninitialized Huffman table". - /// - [MethodImpl(MethodImplOptions.NoInlining)] - public static void UninitializedHuffmanTable() - { - throw new ImageFormatException("Uninitialized Huffman table"); - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/EOFException.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/EOFException.cs deleted file mode 100644 index 60d9b1e1a..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/EOFException.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// The EOF (End of File exception). - /// Thrown when the decoder encounters an EOF marker without a proceeding EOI (End Of Image) marker - /// TODO: Rename to UnexpectedEndOfStreamException - /// - internal class EOFException : Exception - { - /// - /// Initializes a new instance of the class. - /// - public EOFException() - : base("Reached end of stream before proceeding EOI marker!") - { - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs deleted file mode 100644 index 72213eb38..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Runtime.CompilerServices; - -using SixLabors.ImageSharp.Formats.Jpeg.Components; -using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; -using SixLabors.Memory; -using SixLabors.Primitives; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// - /// Represents a single color component - /// - internal class GolangComponent : IDisposable, IJpegComponent - { - public GolangComponent(byte identifier, int index) - { - this.Identifier = identifier; - this.Index = index; - } - - /// - /// Gets the identifier - /// - public byte Identifier { get; } - - /// - public int Index { get; } - - public Size SizeInBlocks { get; private set; } - - public Size SamplingFactors { get; private set; } - - public Size SubSamplingDivisors { get; private set; } - - public int HorizontalSamplingFactor => this.SamplingFactors.Width; - - public int VerticalSamplingFactor => this.SamplingFactors.Height; - - /// - public int QuantizationTableIndex { get; private set; } - - /// - /// - /// Gets the storing the "raw" frequency-domain decoded blocks. - /// We need to apply IDCT, dequantiazition and unzigging to transform them into color-space blocks. - /// This is done by . - /// When us true, we are touching these blocks multiple times - each time we process a Scan. - /// - public Buffer2D SpectralBlocks { get; private set; } - - /// - /// Initializes - /// - /// The to use for buffer allocations. - /// The instance - public void InitializeDerivedData(MemoryAllocator memoryAllocator, GolangJpegDecoderCore decoder) - { - // For 4-component images (either CMYK or YCbCrK), we only support two - // hv vectors: [0x11 0x11 0x11 0x11] and [0x22 0x11 0x11 0x22]. - // Theoretically, 4-component JPEG images could mix and match hv values - // but in practice, those two combinations are the only ones in use, - // and it simplifies the applyBlack code below if we can assume that: - // - for CMYK, the C and K channels have full samples, and if the M - // and Y channels subsample, they subsample both horizontally and - // vertically. - // - for YCbCrK, the Y and K channels have full samples. - this.SizeInBlocks = decoder.ImageSizeInMCU.MultiplyBy(this.SamplingFactors); - - if (this.Index == 0 || this.Index == 3) - { - this.SubSamplingDivisors = new Size(1, 1); - } - else - { - GolangComponent c0 = decoder.Components[0]; - this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors); - } - - this.SpectralBlocks = memoryAllocator.Allocate2D(this.SizeInBlocks.Width, this.SizeInBlocks.Height, AllocationOptions.Clean); - } - - /// - /// Initializes all component data except . - /// - /// The instance - public void InitializeCoreData(GolangJpegDecoderCore decoder) - { - // Section B.2.2 states that "the value of C_i shall be different from - // the values of C_1 through C_(i-1)". - int i = this.Index; - - for (int j = 0; j < this.Index; j++) - { - if (this.Identifier == decoder.Components[j].Identifier) - { - throw new ImageFormatException("Repeated component identifier"); - } - } - - this.QuantizationTableIndex = decoder.Temp[8 + (3 * i)]; - if (this.QuantizationTableIndex > GolangJpegDecoderCore.MaxTq) - { - throw new ImageFormatException("Bad Tq value"); - } - - byte hv = decoder.Temp[7 + (3 * i)]; - int h = hv >> 4; - int v = hv & 0x0f; - if (h < 1 || h > 4 || v < 1 || v > 4) - { - throw new ImageFormatException("Unsupported Luma/chroma subsampling ratio"); - } - - if (h == 3 || v == 3) - { - throw new ImageFormatException("Lnsupported subsampling ratio"); - } - - switch (decoder.ComponentCount) - { - case 1: - - // If a JPEG image has only one component, section A.2 says "this data - // is non-interleaved by definition" and section A.2.2 says "[in this - // case...] the order of data units within a scan shall be left-to-right - // and top-to-bottom... regardless of the values of H_1 and V_1". Section - // 4.8.2 also says "[for non-interleaved data], the MCU is defined to be - // one data unit". Similarly, section A.1.1 explains that it is the ratio - // of H_i to max_j(H_j) that matters, and similarly for V. For grayscale - // images, H_1 is the maximum H_j for all components j, so that ratio is - // always 1. The component's (h, v) is effectively always (1, 1): even if - // the nominal (h, v) is (2, 1), a 20x5 image is encoded in three 8x8 - // MCUs, not two 16x8 MCUs. - h = 1; - v = 1; - break; - - case 3: - - // For YCbCr images, we only support 4:4:4, 4:4:0, 4:2:2, 4:2:0, - // 4:1:1 or 4:1:0 chroma subsampling ratios. This implies that the - // (h, v) values for the Y component are either (1, 1), (1, 2), - // (2, 1), (2, 2), (4, 1) or (4, 2), and the Y component's values - // must be a multiple of the Cb and Cr component's values. We also - // assume that the two chroma components have the same subsampling - // ratio. - switch (i) - { - case 0: - { - // Y. - // We have already verified, above, that h and v are both - // either 1, 2 or 4, so invalid (h, v) combinations are those - // with v == 4. - if (v == 4) - { - throw new ImageFormatException("Unsupported subsampling ratio"); - } - - break; - } - - case 1: - { - // Cb. - Size s0 = decoder.Components[0].SamplingFactors; - - if (s0.Width % h != 0 || s0.Height % v != 0) - { - throw new ImageFormatException("Unsupported subsampling ratio"); - } - - break; - } - - case 2: - { - // Cr. - Size s1 = decoder.Components[1].SamplingFactors; - - if (s1.Width != h || s1.Height != v) - { - throw new ImageFormatException("Unsupported subsampling ratio"); - } - - break; - } - } - - break; - - case 4: - - // For 4-component images (either CMYK or YCbCrK), we only support two - // hv vectors: [0x11 0x11 0x11 0x11] and [0x22 0x11 0x11 0x22]. - // Theoretically, 4-component JPEG images could mix and match hv values - // but in practice, those two combinations are the only ones in use, - // and it simplifies the applyBlack code below if we can assume that: - // - for CMYK, the C and K channels have full samples, and if the M - // and Y channels subsample, they subsample both horizontally and - // vertically. - // - for YCbCrK, the Y and K channels have full samples. - switch (i) - { - case 0: - if (hv != 0x11 && hv != 0x22) - { - throw new ImageFormatException("Unsupported subsampling ratio"); - } - - break; - case 1: - case 2: - if (hv != 0x11) - { - throw new ImageFormatException("Unsupported subsampling ratio"); - } - - break; - case 3: - Size s0 = decoder.Components[0].SamplingFactors; - - if (s0.Width != h || s0.Height != v) - { - throw new ImageFormatException("Unsupported subsampling ratio"); - } - - break; - } - - break; - } - - this.SamplingFactors = new Size(h, v); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref Block8x8 GetBlockReference(int column, int row) - { - return ref this.SpectralBlocks[column, row]; - } - - public void Dispose() - { - this.SpectralBlocks?.Dispose(); - } - } -} diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponentScan.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponentScan.cs deleted file mode 100644 index 6752768ff..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponentScan.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System.Runtime.InteropServices; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// Represents a component scan - /// - [StructLayout(LayoutKind.Sequential)] - internal struct GolangComponentScan - { - /// - /// Gets or sets the component index. - /// - public byte ComponentIndex; - - /// - /// Gets or sets the DC table selector - /// - public byte DcTableSelector; - - /// - /// Gets or sets the AC table selector - /// - public byte AcTableSelector; - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangDecoderErrorCode.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangDecoderErrorCode.cs deleted file mode 100644 index fa3364527..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangDecoderErrorCode.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// Represents "recoverable" decoder errors. - /// - internal enum GolangDecoderErrorCode - { - /// - /// NoError - /// - NoError, - - /// - /// MissingFF00 - /// - // ReSharper disable once InconsistentNaming - MissingFF00, - - /// - /// End of stream reached unexpectedly - /// - UnexpectedEndOfStream - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangHuffmanTree.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangHuffmanTree.cs deleted file mode 100644 index dccce2aaa..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangHuffmanTree.cs +++ /dev/null @@ -1,260 +0,0 @@ -// 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.GolangPort.Components.Decoder -{ - /// - /// Represents a Huffman tree - /// - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct GolangHuffmanTree - { - /// - /// The index of the AC table row - /// - public const int AcTableIndex = 1; - - /// - /// The index of the DC table row - /// - public const int DcTableIndex = 0; - - /// - /// The maximum (inclusive) number of codes in a Huffman tree. - /// - public const int MaxNCodes = 256; - - /// - /// The maximum (inclusive) number of bits in a Huffman code. - /// - public const int MaxCodeLength = 16; - - /// - /// The maximum number of Huffman table classes - /// - public const int MaxTc = 1; - - /// - /// The maximum number of Huffman table identifiers - /// - public const int MaxTh = 3; - - /// - /// Row size of the Huffman table - /// - public const int ThRowSize = MaxTh + 1; - - /// - /// Number of Hufman Trees in the Huffman table - /// - public const int NumberOfTrees = (MaxTc + 1) * (MaxTh + 1); - - /// - /// The log-2 size of the Huffman decoder's look-up table. - /// - public const int LutSizeLog2 = 8; - - /// - /// Gets or sets the number of codes in the tree. - /// - public int Length; - - /// - /// Gets the look-up table for the next LutSize bits in the bit-stream. - /// The high 8 bits of the uint16 are the encoded value. The low 8 bits - /// are 1 plus the code length, or 0 if the value is too large to fit in - /// lutSize bits. - /// - public FixedInt32Buffer256 Lut; - - /// - /// Gets the the decoded values, sorted by their encoding. - /// - public FixedInt32Buffer256 Values; - - /// - /// Gets the array of minimum codes. - /// MinCodes[i] is the minimum code of length i, or -1 if there are no codes of that length. - /// - public FixedInt32Buffer16 MinCodes; - - /// - /// Gets the array of maximum codes. - /// MaxCodes[i] is the maximum code of length i, or -1 if there are no codes of that length. - /// - public FixedInt32Buffer16 MaxCodes; - - /// - /// Gets the array of indices. Indices[i] is the index into Values of MinCodes[i]. - /// - public FixedInt32Buffer16 Indices; - - /// - /// Creates and initializes an array of instances of size - /// - /// An array of instances representing the Huffman tables - public static GolangHuffmanTree[] CreateHuffmanTrees() - { - return new GolangHuffmanTree[NumberOfTrees]; - } - - /// - /// Internal part of the DHT processor, whatever does it mean - /// - /// The decoder instance - /// The temporary buffer that holds the data that has been read from the Jpeg stream - /// Remaining bits - public void ProcessDefineHuffmanTablesMarkerLoop( - ref InputProcessor inputProcessor, - byte[] defineHuffmanTablesData, - ref int remaining) - { - // Read nCodes and huffman.Valuess (and derive h.Length). - // nCodes[i] is the number of codes with code length i. - // h.Length is the total number of codes. - this.Length = 0; - - int[] ncodes = new int[MaxCodeLength]; - for (int i = 0; i < ncodes.Length; i++) - { - ncodes[i] = defineHuffmanTablesData[i + 1]; - this.Length += ncodes[i]; - } - - if (this.Length == 0) - { - throw new ImageFormatException("Huffman table has zero length"); - } - - if (this.Length > MaxNCodes) - { - throw new ImageFormatException("Huffman table has excessive length"); - } - - remaining -= this.Length + 17; - if (remaining < 0) - { - throw new ImageFormatException("DHT has wrong length"); - } - - byte[] values = new byte[MaxNCodes]; - inputProcessor.ReadFull(values, 0, this.Length); - - fixed (int* valuesPtr = this.Values.Data) - fixed (int* lutPtr = this.Lut.Data) - { - for (int i = 0; i < values.Length; i++) - { - valuesPtr[i] = values[i]; - } - - // Derive the look-up table. - for (int i = 0; i < MaxNCodes; i++) - { - lutPtr[i] = 0; - } - - int x = 0, code = 0; - - for (int i = 0; i < LutSizeLog2; i++) - { - code <<= 1; - - for (int j = 0; j < ncodes[i]; j++) - { - // The codeLength is 1+i, so shift code by 8-(1+i) to - // calculate the high bits for every 8-bit sequence - // whose codeLength's high bits matches code. - // The high 8 bits of lutValue are the encoded value. - // The low 8 bits are 1 plus the codeLength. - int base2 = code << (7 - i); - int lutValue = (valuesPtr[x] << 8) | (2 + i); - - for (int k = 0; k < 1 << (7 - i); k++) - { - lutPtr[base2 | k] = lutValue; - } - - code++; - x++; - } - } - } - - fixed (int* minCodesPtr = this.MinCodes.Data) - fixed (int* maxCodesPtr = this.MaxCodes.Data) - fixed (int* indicesPtr = this.Indices.Data) - { - // Derive minCodes, maxCodes, and indices. - int c = 0, index = 0; - for (int i = 0; i < ncodes.Length; i++) - { - int nc = ncodes[i]; - if (nc == 0) - { - minCodesPtr[i] = -1; - maxCodesPtr[i] = -1; - indicesPtr[i] = -1; - } - else - { - minCodesPtr[i] = c; - maxCodesPtr[i] = c + nc - 1; - indicesPtr[i] = index; - c += nc; - index += nc; - } - - c <<= 1; - } - } - } - - /// - /// Gets the value for the given code and index. - /// - /// The code - /// The code length - /// The value - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int GetValue(int code, int codeLength) - { - return this.Values[this.Indices[codeLength] + code - this.MinCodes[codeLength]]; - } - - [StructLayout(LayoutKind.Sequential)] - internal struct FixedInt32Buffer256 - { - public fixed int Data[256]; - - public int this[int idx] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - ref int self = ref Unsafe.As(ref this); - return Unsafe.Add(ref self, idx); - } - } - } - - [StructLayout(LayoutKind.Sequential)] - internal struct FixedInt32Buffer16 - { - public fixed int Data[16]; - - public int this[int idx] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - ref int 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/GolangPort/Components/Decoder/GolangJpegScanDecoder.ComputationData.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.ComputationData.cs deleted file mode 100644 index f3c8aa91b..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.ComputationData.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System.Runtime.InteropServices; - -using SixLabors.ImageSharp.Formats.Jpeg.Components; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// Conains the definition of - /// - internal unsafe partial struct GolangJpegScanDecoder - { - /// - /// Holds the "large" data blocks needed for computations. - /// - [StructLayout(LayoutKind.Sequential)] - public struct ComputationData - { - /// - /// The main input/working block - /// - public Block8x8 Block; - - /// - /// The jpeg unzig data - /// - public ZigZag Unzig; - - /// - /// The buffer storing the -s for each component - /// - public fixed byte ScanData[3 * GolangJpegDecoderCore.MaxComponents]; - - /// - /// The DC values for each component - /// - public fixed int Dc[GolangJpegDecoderCore.MaxComponents]; - - /// - /// Creates and initializes a new instance - /// - /// The - public static ComputationData Create() - { - ComputationData data = default; - data.Unzig = ZigZag.CreateUnzigTable(); - return data; - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.DataPointers.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.DataPointers.cs deleted file mode 100644 index a00da6fca..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.DataPointers.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.Formats.Jpeg.Components; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// Conains the definition of - /// - internal unsafe partial struct GolangJpegScanDecoder - { - /// - /// Contains pointers to the memory regions of so they can be easily passed around to pointer based utility methods of - /// - public struct DataPointers - { - /// - /// Pointer to - /// - public Block8x8* Block; - - /// - /// Pointer to as byte* - /// - public byte* Unzig; - - /// - /// Pointer to as Scan* - /// - public GolangComponentScan* ComponentScan; - - /// - /// Pointer to - /// - public int* Dc; - - /// - /// Initializes a new instance of the struct. - /// - /// The pointer pointing to - public DataPointers(ComputationData* basePtr) - { - this.Block = &basePtr->Block; - this.Unzig = basePtr->Unzig.Data; - this.ComponentScan = (GolangComponentScan*)basePtr->ScanData; - this.Dc = basePtr->Dc; - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.cs deleted file mode 100644 index 3a88cfad4..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.cs +++ /dev/null @@ -1,705 +0,0 @@ -// 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; - -// ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// Encapsulates the impementation of Jpeg SOS Huffman decoding. See JpegScanDecoder.md! - /// - /// and are the spectral selection bounds. - /// and are the successive approximation high and low values. - /// The spec calls these values Ss, Se, Ah and Al. - /// For progressive JPEGs, these are the two more-or-less independent - /// aspects of progression. Spectral selection progression is when not - /// all of a block's 64 DCT coefficients are transmitted in one pass. - /// For example, three passes could transmit coefficient 0 (the DC - /// component), coefficients 1-5, and coefficients 6-63, in zig-zag - /// order. Successive approximation is when not all of the bits of a - /// band of coefficients are transmitted in one pass. For example, - /// three passes could transmit the 6 most significant bits, followed - /// by the second-least significant bit, followed by the least - /// significant bit. - /// For baseline JPEGs, these parameters are hard-coded to 0/63/0/0. - /// - [StructLayout(LayoutKind.Sequential)] - internal unsafe partial struct GolangJpegScanDecoder - { - // The JpegScanDecoder members should be ordered in a way that results in optimal memory layout. -#pragma warning disable SA1202 // ElementsMustBeOrderedByAccess - - /// - /// The buffer - /// - private ComputationData data; - - /// - /// Pointers to elements of - /// - private DataPointers pointers; - - /// - /// The current component index - /// - public int ComponentIndex; - - /// - /// X coordinate of the current block, in units of 8x8. (The third block in the first row has (bx, by) = (2, 0)) - /// - private int bx; - - /// - /// Y coordinate of the current block, in units of 8x8. (The third block in the first row has (bx, by) = (2, 0)) - /// - private int by; - - /// - /// Start index of the zig-zag selection bound - /// - private int zigStart; - - /// - /// End index of the zig-zag selection bound - /// - private int zigEnd; - - /// - /// Successive approximation high value - /// - private int ah; - - /// - /// Successive approximation low value - /// - private int al; - - /// - /// The number of component scans - /// - private int componentScanCount; - - /// - /// Horizontal sampling factor at the current component index - /// - private int hi; - - /// - /// End-of-Band run, specified in section G.1.2.2. - /// - private int eobRun; - - /// - /// The block counter - /// - private int blockCounter; - - /// - /// The MCU counter - /// - private int mcuCounter; - - /// - /// The expected RST marker value - /// - private byte expectedRst; - - /// - /// Initializes a default-constructed instance for reading data from -s stream. - /// - /// Pointer to on the stack - /// The instance - /// The remaining bytes in the segment block. - public static void InitStreamReading(GolangJpegScanDecoder* p, GolangJpegDecoderCore decoder, int remaining) - { - p->data = ComputationData.Create(); - p->pointers = new DataPointers(&p->data); - p->InitStreamReadingImpl(decoder, remaining); - } - - /// - /// Read Huffman data from Jpeg scans in , - /// and decode it as into . - /// - /// The blocks are traversed one MCU at a time. For 4:2:0 chroma - /// subsampling, there are four Y 8x8 blocks in every 16x16 MCU. - /// For a baseline 32x16 pixel image, the Y blocks visiting order is: - /// 0 1 4 5 - /// 2 3 6 7 - /// For progressive images, the interleaved scans (those with component count > 1) - /// are traversed as above, but non-interleaved scans are traversed left - /// to right, top to bottom: - /// 0 1 2 3 - /// 4 5 6 7 - /// Only DC scans (zigStart == 0) can be interleave AC scans must have - /// only one component. - /// To further complicate matters, for non-interleaved scans, there is no - /// data for any blocks that are inside the image at the MCU level but - /// outside the image at the pixel level. For example, a 24x16 pixel 4:2:0 - /// progressive image consists of two 16x16 MCUs. The interleaved scans - /// will process 8 Y blocks: - /// 0 1 4 5 - /// 2 3 6 7 - /// The non-interleaved scans will process only 6 Y blocks: - /// 0 1 2 - /// 3 4 5 - /// - /// The instance - public void DecodeBlocks(GolangJpegDecoderCore decoder) - { - decoder.InputProcessor.ResetErrorState(); - - this.blockCounter = 0; - this.mcuCounter = 0; - this.expectedRst = JpegConstants.Markers.RST0; - - for (int my = 0; my < decoder.MCUCountY; my++) - { - for (int mx = 0; mx < decoder.MCUCountX; mx++) - { - this.DecodeBlocksAtMcuIndex(decoder, mx, my); - - this.mcuCounter++; - - // Handling restart intervals - // Useful info: https://stackoverflow.com/a/8751802 - if (decoder.IsAtRestartInterval(this.mcuCounter)) - { - this.ProcessRSTMarker(decoder); - this.Reset(decoder); - } - } - } - } - - private void DecodeBlocksAtMcuIndex(GolangJpegDecoderCore decoder, int mx, int my) - { - for (int scanIndex = 0; scanIndex < this.componentScanCount; scanIndex++) - { - this.ComponentIndex = this.pointers.ComponentScan[scanIndex].ComponentIndex; - GolangComponent component = decoder.Components[this.ComponentIndex]; - - this.hi = component.HorizontalSamplingFactor; - int vi = component.VerticalSamplingFactor; - - for (int j = 0; j < this.hi * vi; j++) - { - if (this.componentScanCount != 1) - { - this.bx = (this.hi * mx) + (j % this.hi); - this.by = (vi * my) + (j / this.hi); - } - else - { - int q = decoder.MCUCountX * this.hi; - this.bx = this.blockCounter % q; - this.by = this.blockCounter / q; - this.blockCounter++; - if (this.bx * 8 >= decoder.ImageWidth || this.by * 8 >= decoder.ImageHeight) - { - continue; - } - } - - // Find the block at (bx,by) in the component's buffer: - ref Block8x8 blockRefOnHeap = ref component.GetBlockReference(this.bx, this.by); - - // Copy block to stack - this.data.Block = blockRefOnHeap; - - if (!decoder.InputProcessor.ReachedEOF) - { - this.DecodeBlock(decoder, scanIndex); - } - - // Store the result block: - blockRefOnHeap = this.data.Block; - } - } - } - - private void ProcessRSTMarker(GolangJpegDecoderCore decoder) - { - // Attempt to look for RST[0-7] markers to resynchronize from corrupt input. - if (!decoder.InputProcessor.ReachedEOF) - { - decoder.InputProcessor.ReadFullUnsafe(decoder.Temp, 0, 2); - if (decoder.InputProcessor.CheckEOFEnsureNoError()) - { - if (decoder.Temp[0] != 0xFF || decoder.Temp[1] != this.expectedRst) - { - bool invalidRst = true; - - // Most jpeg's containing well-formed input will have a RST[0-7] marker following immediately - // but some, see Issue #481, contain padding bytes "0xFF" before the RST[0-7] marker. - // If we identify that case we attempt to read until we have bypassed the padded bytes. - // We then check again for our RST marker and throw if invalid. - // No other methods are attempted to resynchronize from corrupt input. - if (decoder.Temp[0] == 0xFF && decoder.Temp[1] == 0xFF) - { - while (decoder.Temp[0] == 0xFF && decoder.InputProcessor.CheckEOFEnsureNoError()) - { - decoder.InputProcessor.ReadFullUnsafe(decoder.Temp, 0, 1); - if (!decoder.InputProcessor.CheckEOFEnsureNoError()) - { - break; - } - } - - // Have we found a valid restart marker? - invalidRst = decoder.Temp[0] != this.expectedRst; - } - - if (invalidRst) - { - throw new ImageFormatException("Bad RST marker"); - } - } - - this.expectedRst++; - if (this.expectedRst == JpegConstants.Markers.RST7 + 1) - { - this.expectedRst = JpegConstants.Markers.RST0; - } - } - } - } - - private void Reset(GolangJpegDecoderCore decoder) - { - decoder.InputProcessor.ResetHuffmanDecoder(); - - this.ResetDcValues(); - - // Reset the progressive decoder state, as per section G.1.2.2. - this.eobRun = 0; - } - - /// - /// Reset the DC components, as per section F.2.1.3.1. - /// - private void ResetDcValues() - { - Unsafe.InitBlock(this.pointers.Dc, default, sizeof(int) * GolangJpegDecoderCore.MaxComponents); - } - - /// - /// The implementation part of as an instance method. - /// - /// The - /// The remaining bytes - private void InitStreamReadingImpl(GolangJpegDecoderCore decoder, int remaining) - { - if (decoder.ComponentCount == 0) - { - throw new ImageFormatException("Missing SOF marker"); - } - - if (remaining < 6 || 4 + (2 * decoder.ComponentCount) < remaining || remaining % 2 != 0) - { - throw new ImageFormatException("SOS has wrong length"); - } - - decoder.InputProcessor.ReadFull(decoder.Temp, 0, remaining); - this.componentScanCount = decoder.Temp[0]; - - int scanComponentCountX2 = 2 * this.componentScanCount; - if (remaining != 4 + scanComponentCountX2) - { - throw new ImageFormatException("SOS length inconsistent with number of components"); - } - - int totalHv = 0; - - for (int i = 0; i < this.componentScanCount; i++) - { - this.InitComponentScan(decoder, i, ref this.pointers.ComponentScan[i], ref totalHv); - } - - // Section B.2.3 states that if there is more than one component then the - // total H*V values in a scan must be <= 10. - if (decoder.ComponentCount > 1 && totalHv > 10) - { - throw new ImageFormatException("Total sampling factors too large."); - } - - this.zigEnd = Block8x8F.Size - 1; - - if (decoder.IsProgressive) - { - this.zigStart = decoder.Temp[1 + scanComponentCountX2]; - this.zigEnd = decoder.Temp[2 + scanComponentCountX2]; - this.ah = decoder.Temp[3 + scanComponentCountX2] >> 4; - this.al = decoder.Temp[3 + scanComponentCountX2] & 0x0f; - - if ((this.zigStart == 0 && this.zigEnd != 0) || this.zigStart > this.zigEnd - || this.zigEnd >= Block8x8F.Size) - { - throw new ImageFormatException("Bad spectral selection bounds"); - } - - if (this.zigStart != 0 && this.componentScanCount != 1) - { - throw new ImageFormatException("Progressive AC coefficients for more than one component"); - } - - if (this.ah != 0 && this.ah != this.al + 1) - { - throw new ImageFormatException("Bad successive approximation values"); - } - } - } - - /// - /// Read the current the current block at (, ) from the decoders stream - /// - /// The decoder - /// The index of the scan - private void DecodeBlock(GolangJpegDecoderCore decoder, int scanIndex) - { - Block8x8* b = this.pointers.Block; - int huffmannIdx = (GolangHuffmanTree.AcTableIndex * GolangHuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].AcTableSelector; - if (this.ah != 0) - { - this.Refine(ref decoder.InputProcessor, ref decoder.HuffmanTrees[huffmannIdx], 1 << this.al); - } - else - { - int zig = this.zigStart; - - if (zig == 0) - { - zig++; - - // Decode the DC coefficient, as specified in section F.2.2.1. - int huffmanIndex = (GolangHuffmanTree.DcTableIndex * GolangHuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].DcTableSelector; - decoder.InputProcessor.DecodeHuffmanUnsafe( - ref decoder.HuffmanTrees[huffmanIndex], - out int value); - if (!decoder.InputProcessor.CheckEOF()) - { - return; - } - - if (value > 16) - { - throw new ImageFormatException("Excessive DC component"); - } - - decoder.InputProcessor.ReceiveExtendUnsafe(value, out int deltaDC); - if (!decoder.InputProcessor.CheckEOFEnsureNoError()) - { - return; - } - - this.pointers.Dc[this.ComponentIndex] += deltaDC; - - // b[0] = dc[compIndex] << al; - value = this.pointers.Dc[this.ComponentIndex] << this.al; - Block8x8.SetScalarAt(b, 0, (short)value); - } - - if (zig <= this.zigEnd && this.eobRun > 0) - { - this.eobRun--; - } - else - { - // Decode the AC coefficients, as specified in section F.2.2.2. - for (; zig <= this.zigEnd; zig++) - { - decoder.InputProcessor.DecodeHuffmanUnsafe(ref decoder.HuffmanTrees[huffmannIdx], out int value); - if (decoder.InputProcessor.HasError) - { - return; - } - - int val0 = value >> 4; - int val1 = value & 0x0f; - if (val1 != 0) - { - zig += val0; - if (zig > this.zigEnd) - { - break; - } - - decoder.InputProcessor.ReceiveExtendUnsafe(val1, out int ac); - if (decoder.InputProcessor.HasError) - { - return; - } - - // b[Unzig[zig]] = ac << al; - value = ac << this.al; - Block8x8.SetScalarAt(b, this.pointers.Unzig[zig], (short)value); - } - else - { - if (val0 != 0x0f) - { - this.eobRun = (ushort)(1 << val0); - if (val0 != 0) - { - this.DecodeEobRun(val0, ref decoder.InputProcessor); - if (!decoder.InputProcessor.CheckEOFEnsureNoError()) - { - return; - } - } - - this.eobRun--; - break; - } - - zig += 0x0f; - } - } - } - } - } - - private void DecodeEobRun(int count, ref InputProcessor processor) - { - processor.DecodeBitsUnsafe(count, out int bitsResult); - if (processor.LastErrorCode != GolangDecoderErrorCode.NoError) - { - return; - } - - this.eobRun |= bitsResult; - } - - private void InitComponentScan(GolangJpegDecoderCore decoder, int i, ref GolangComponentScan currentComponentScan, ref int totalHv) - { - // Component selector. - int cs = decoder.Temp[1 + (2 * i)]; - int compIndex = -1; - for (int j = 0; j < decoder.ComponentCount; j++) - { - // Component compv = ; - if (cs == decoder.Components[j].Identifier) - { - compIndex = j; - } - } - - if (compIndex < 0) - { - throw new ImageFormatException("Unknown component selector"); - } - - currentComponentScan.ComponentIndex = (byte)compIndex; - - this.ProcessComponentImpl(decoder, i, ref currentComponentScan, ref totalHv, decoder.Components[compIndex]); - } - - private void ProcessComponentImpl( - GolangJpegDecoderCore decoder, - int i, - ref GolangComponentScan currentComponentScan, - ref int totalHv, - GolangComponent currentComponent) - { - // Section B.2.3 states that "the value of Cs_j shall be different from - // the values of Cs_1 through Cs_(j-1)". Since we have previously - // verified that a frame's component identifiers (C_i values in section - // B.2.2) are unique, it suffices to check that the implicit indexes - // into comp are unique. - for (int j = 0; j < i; j++) - { - if (currentComponentScan.ComponentIndex == this.pointers.ComponentScan[j].ComponentIndex) - { - throw new ImageFormatException("Repeated component selector"); - } - } - - totalHv += currentComponent.HorizontalSamplingFactor * currentComponent.VerticalSamplingFactor; - - currentComponentScan.DcTableSelector = (byte)(decoder.Temp[2 + (2 * i)] >> 4); - if (currentComponentScan.DcTableSelector > GolangHuffmanTree.MaxTh) - { - throw new ImageFormatException("Bad DC table selector value"); - } - - currentComponentScan.AcTableSelector = (byte)(decoder.Temp[2 + (2 * i)] & 0x0f); - if (currentComponentScan.AcTableSelector > GolangHuffmanTree.MaxTh) - { - throw new ImageFormatException("Bad AC table selector value"); - } - } - - /// - /// Decodes a successive approximation refinement block, as specified in section G.1.2. - /// - /// The instance - /// The Huffman tree - /// The low transform offset - private void Refine(ref InputProcessor bp, ref GolangHuffmanTree h, int delta) - { - Block8x8* b = this.pointers.Block; - - // Refining a DC component is trivial. - if (this.zigStart == 0) - { - if (this.zigEnd != 0) - { - throw new ImageFormatException("Invalid state for zig DC component"); - } - - bp.DecodeBitUnsafe(out bool bit); - if (!bp.CheckEOFEnsureNoError()) - { - return; - } - - if (bit) - { - int stuff = Block8x8.GetScalarAt(b, 0); - - // int stuff = (int)b[0]; - stuff |= delta; - - // b[0] = stuff; - Block8x8.SetScalarAt(b, 0, (short)stuff); - } - - return; - } - - // Refining AC components is more complicated; see sections G.1.2.2 and G.1.2.3. - int zig = this.zigStart; - if (this.eobRun == 0) - { - for (; zig <= this.zigEnd; zig++) - { - bool done = false; - int z = 0; - - bp.DecodeHuffmanUnsafe(ref h, out int val); - if (!bp.CheckEOF()) - { - return; - } - - int val0 = val >> 4; - int val1 = val & 0x0f; - - switch (val1) - { - case 0: - if (val0 != 0x0f) - { - this.eobRun = 1 << val0; - if (val0 != 0) - { - this.DecodeEobRun(val0, ref bp); - if (!bp.CheckEOFEnsureNoError()) - { - return; - } - } - - done = true; - } - - break; - case 1: - z = delta; - - bp.DecodeBitUnsafe(out bool bit); - if (!bp.CheckEOFEnsureNoError()) - { - return; - } - - if (!bit) - { - z = -z; - } - - break; - default: - throw new ImageFormatException("Unexpected Huffman code"); - } - - if (done) - { - break; - } - - zig = this.RefineNonZeroes(ref bp, zig, val0, delta); - - if (bp.ReachedEOF || bp.HasError) - { - return; - } - - if (z != 0 && zig <= this.zigEnd) - { - // b[Unzig[zig]] = z; - Block8x8.SetScalarAt(b, this.pointers.Unzig[zig], (short)z); - } - } - } - - if (this.eobRun > 0) - { - this.eobRun--; - this.RefineNonZeroes(ref bp, zig, -1, delta); - } - } - - /// - /// Refines non-zero entries of b in zig-zag order. - /// If >= 0, the first zero entries are skipped over. - /// - /// The - /// The zig-zag start index - /// The non-zero entry - /// The low transform offset - /// The - private int RefineNonZeroes(ref InputProcessor bp, int zig, int nz, int delta) - { - Block8x8* b = this.pointers.Block; - for (; zig <= this.zigEnd; zig++) - { - int u = this.pointers.Unzig[zig]; - int bu = Block8x8.GetScalarAt(b, u); - - // TODO: Are the equality comparsions OK with floating point values? Isn't an epsilon value necessary? - if (bu == 0) - { - if (nz == 0) - { - break; - } - - nz--; - continue; - } - - bp.DecodeBitUnsafe(out bool bit); - if (bp.HasError) - { - return int.MinValue; - } - - if (!bit) - { - continue; - } - - int val = bu >= 0 ? bu + delta : bu - delta; - - Block8x8.SetScalarAt(b, u, (short)val); - } - - return zig; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs deleted file mode 100644 index c7e14ee4f..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs +++ /dev/null @@ -1,392 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.IO; -using System.Runtime.CompilerServices; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// Encapsulates stream reading and processing data and operations for . - /// It's a value type for imporved data locality, and reduced number of CALLVIRT-s - /// - internal struct InputProcessor : IDisposable - { - /// - /// Holds the unprocessed bits that have been taken from the byte-stream. - /// - public Bits Bits; - - /// - /// The byte buffer - /// - public Bytes Bytes; - - /// - /// Initializes a new instance of the struct. - /// - /// The input - /// Temporal buffer, same as - public InputProcessor(Stream inputStream, byte[] temp) - { - this.Bits = default; - this.Bytes = Bytes.Create(); - this.InputStream = inputStream; - this.Temp = temp; - this.LastErrorCode = GolangDecoderErrorCode.NoError; - } - - /// - /// Gets the input stream - /// - public Stream InputStream { get; } - - /// - /// Gets the temporary buffer, same instance as - /// - public byte[] Temp { get; } - - /// - /// Gets a value indicating whether an unexpected EOF reached in . - /// - public bool ReachedEOF => this.LastErrorCode == GolangDecoderErrorCode.UnexpectedEndOfStream; - - public bool HasError => this.LastErrorCode != GolangDecoderErrorCode.NoError; - - public GolangDecoderErrorCode LastErrorCode { get; private set; } - - public void ResetErrorState() => this.LastErrorCode = GolangDecoderErrorCode.NoError; - - /// - /// If errorCode indicates unexpected EOF, sets to true and returns false. - /// Calls and returns true otherwise. - /// - /// A indicating whether EOF reached - public bool CheckEOFEnsureNoError() - { - if (this.LastErrorCode == GolangDecoderErrorCode.UnexpectedEndOfStream) - { - return false; - } - - this.LastErrorCode.EnsureNoError(); - return true; - } - - /// - /// If errorCode indicates unexpected EOF, sets to true and returns false. - /// Returns true otherwise. - /// - /// A indicating whether EOF reached - public bool CheckEOF() - { - if (this.LastErrorCode == GolangDecoderErrorCode.UnexpectedEndOfStream) - { - return false; - } - - return true; - } - - /// - public void Dispose() - { - this.Bytes.Dispose(); - } - - /// - /// Returns the next byte, whether buffered or not buffered. It does not care about byte stuffing. - /// - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public byte ReadByte() - { - return this.Bytes.ReadByte(this.InputStream); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public GolangDecoderErrorCode ReadByteUnsafe(out byte result) - { - this.LastErrorCode = this.Bytes.ReadByteUnsafe(this.InputStream, out result); - return this.LastErrorCode; - } - - /// - /// Decodes a single bit - /// TODO: This method (and also the usages) could be optimized by batching! - /// - /// The decoded bit as a - /// The - public GolangDecoderErrorCode DecodeBitUnsafe(out bool result) - { - if (this.Bits.UnreadBits == 0) - { - this.LastErrorCode = this.Bits.Ensure1BitUnsafe(ref this); - if (this.LastErrorCode != GolangDecoderErrorCode.NoError) - { - result = false; - return this.LastErrorCode; - } - } - - result = (this.Bits.Accumulator & this.Bits.Mask) != 0; - this.Bits.UnreadBits--; - this.Bits.Mask >>= 1; - return this.LastErrorCode = GolangDecoderErrorCode.NoError; - } - - /// - /// Reads exactly length bytes into data. It does not care about byte stuffing. - /// Does not throw on errors, returns instead! - /// - /// The data to write to. - /// The offset in the source buffer - /// The number of bytes to read - /// The - public GolangDecoderErrorCode ReadFullUnsafe(byte[] data, int offset, int length) - { - // Unread the overshot bytes, if any. - if (this.Bytes.UnreadableBytes != 0) - { - if (this.Bits.UnreadBits >= 8) - { - this.UnreadByteStuffedByte(); - } - - this.Bytes.UnreadableBytes = 0; - } - - this.LastErrorCode = GolangDecoderErrorCode.NoError; - while (length > 0 && this.LastErrorCode == GolangDecoderErrorCode.NoError) - { - if (this.Bytes.J - this.Bytes.I >= length) - { - Array.Copy(this.Bytes.Buffer, this.Bytes.I, data, offset, length); - this.Bytes.I += length; - length -= length; - } - else - { - Array.Copy(this.Bytes.Buffer, this.Bytes.I, data, offset, this.Bytes.J - this.Bytes.I); - offset += this.Bytes.J - this.Bytes.I; - length -= this.Bytes.J - this.Bytes.I; - this.Bytes.I += this.Bytes.J - this.Bytes.I; - - this.LastErrorCode = this.Bytes.FillUnsafe(this.InputStream); - } - } - - return this.LastErrorCode; - } - - /// - /// Decodes the given number of bits - /// - /// The number of bits to decode. - /// The result - /// The - public GolangDecoderErrorCode DecodeBitsUnsafe(int count, out int result) - { - if (this.Bits.UnreadBits < count) - { - this.LastErrorCode = this.Bits.EnsureNBitsUnsafe(count, ref this); - if (this.LastErrorCode != GolangDecoderErrorCode.NoError) - { - result = 0; - return this.LastErrorCode; - } - } - - result = this.Bits.Accumulator >> (this.Bits.UnreadBits - count); - result = result & ((1 << count) - 1); - this.Bits.UnreadBits -= count; - this.Bits.Mask >>= count; - return this.LastErrorCode = GolangDecoderErrorCode.NoError; - } - - /// - /// Extracts the next Huffman-coded value from the bit-stream into result, decoded according to the given value. - /// - /// The huffman value - /// The decoded - /// The - public GolangDecoderErrorCode DecodeHuffmanUnsafe(ref GolangHuffmanTree huffmanTree, out int result) - { - result = 0; - - if (huffmanTree.Length == 0) - { - DecoderThrowHelper.ThrowImageFormatException.UninitializedHuffmanTable(); - } - - if (this.Bits.UnreadBits < 8) - { - this.LastErrorCode = this.Bits.Ensure8BitsUnsafe(ref this); - - if (this.LastErrorCode == GolangDecoderErrorCode.NoError) - { - int lutIndex = (this.Bits.Accumulator >> (this.Bits.UnreadBits - GolangHuffmanTree.LutSizeLog2)) & 0xFF; - int v = huffmanTree.Lut[lutIndex]; - - if (v != 0) - { - int n = (v & 0xFF) - 1; - this.Bits.UnreadBits -= n; - this.Bits.Mask >>= n; - result = v >> 8; - return this.LastErrorCode; - } - } - else - { - this.UnreadByteStuffedByte(); - return this.LastErrorCode; - } - } - - int code = 0; - for (int i = 0; i < GolangHuffmanTree.MaxCodeLength; i++) - { - if (this.Bits.UnreadBits == 0) - { - this.LastErrorCode = this.Bits.EnsureNBitsUnsafe(1, ref this); - - if (this.HasError) - { - return this.LastErrorCode; - } - } - - if ((this.Bits.Accumulator & this.Bits.Mask) != 0) - { - code |= 1; - } - - this.Bits.UnreadBits--; - this.Bits.Mask >>= 1; - - if (code <= huffmanTree.MaxCodes[i]) - { - result = huffmanTree.GetValue(code, i); - return this.LastErrorCode = GolangDecoderErrorCode.NoError; - } - - code <<= 1; - } - - // Unrecoverable error, throwing: - DecoderThrowHelper.ThrowImageFormatException.BadHuffmanCode(); - - // DUMMY RETURN! C# doesn't know we have thrown an exception! - return GolangDecoderErrorCode.NoError; - } - - /// - /// Skips the next n bytes. - /// - /// The number of bytes to ignore. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Skip(int count) - { - this.LastErrorCode = this.SkipUnsafe(count); - this.LastErrorCode.EnsureNoError(); - } - - /// - /// Skips the next n bytes. - /// Does not throw, returns instead! - /// - /// The number of bytes to ignore. - /// The - public GolangDecoderErrorCode SkipUnsafe(int count) - { - // Unread the overshot bytes, if any. - if (this.Bytes.UnreadableBytes != 0) - { - if (this.Bits.UnreadBits >= 8) - { - this.UnreadByteStuffedByte(); - } - - this.Bytes.UnreadableBytes = 0; - } - - while (true) - { - int m = this.Bytes.J - this.Bytes.I; - if (m > count) - { - m = count; - } - - this.Bytes.I += m; - count -= m; - if (count == 0) - { - break; - } - - this.LastErrorCode = this.Bytes.FillUnsafe(this.InputStream); - if (this.LastErrorCode != GolangDecoderErrorCode.NoError) - { - return this.LastErrorCode; - } - } - - return this.LastErrorCode = GolangDecoderErrorCode.NoError; - } - - /// - /// Reads exactly length bytes into data. It does not care about byte stuffing. - /// - /// The data to write to. - /// The offset in the source buffer - /// The number of bytes to read - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ReadFull(byte[] data, int offset, int length) - { - this.LastErrorCode = this.ReadFullUnsafe(data, offset, length); - this.LastErrorCode.EnsureNoError(); - } - - /// - /// Undoes the most recent ReadByteStuffedByte call, - /// giving a byte of data back from bits to bytes. The Huffman look-up table - /// requires at least 8 bits for look-up, which means that Huffman decoding can - /// sometimes overshoot and read one or two too many bytes. Two-byte overshoot - /// can happen when expecting to read a 0xff 0x00 byte-stuffed byte. - /// - public void UnreadByteStuffedByte() - { - this.Bytes.I -= this.Bytes.UnreadableBytes; - this.Bytes.UnreadableBytes = 0; - if (this.Bits.UnreadBits >= 8) - { - this.Bits.Accumulator >>= 8; - this.Bits.UnreadBits -= 8; - this.Bits.Mask >>= 8; - } - } - - /// - /// Receive extend - /// - /// Byte - /// Read bits value - /// The - public GolangDecoderErrorCode ReceiveExtendUnsafe(int t, out int x) - { - this.LastErrorCode = this.Bits.ReceiveExtendUnsafe(t, ref this, out x); - return this.LastErrorCode; - } - - /// - /// Reset the Huffman decoder. - /// - public void ResetHuffmanDecoder() - { - this.Bits = default; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegScanDecoder.md b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegScanDecoder.md deleted file mode 100644 index 4ca4d1f64..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegScanDecoder.md +++ /dev/null @@ -1,25 +0,0 @@ -## JpegScanDecoder -Encapsulates the impementation of the Jpeg top-to bottom scan decoder triggered by the `SOS` marker. -The implementation is optimized to hold most of the necessary data in a single value type, which is intended to be used as an on-stack object. - -#### Benefits: -- Maximized locality of reference by keeping most of the operation data on the stack -- Achieving this without long parameter lists, most of the values describing the state of the decoder algorithm -are members of the `JpegScanDecoder` struct -- Most of the logic related to Scan decoding is refactored & simplified now to live in the methods of `JpegScanDecoder` -- The first step is done towards separating the stream reading from block processing. They can be refactored later to be executed in two disctinct loops. - - The input processing loop can be `async` - - The block processing loop can be parallelized - -#### Data layout - -|JpegScanDecoder | -|-------------------| -|Variables | -|DataPointers | -|ComputationData | - -- **ComputationData** holds the "large" data blocks needed for computations (Mostly `Block8x8F`-s) -- **DataPointers** contains pointers to the memory regions of `ComponentData` so they can be easily passed around to pointer based utility methods of `Block8x8F` - - diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/MissingFF00Exception.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/MissingFF00Exception.cs deleted file mode 100644 index 005034b9d..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/MissingFF00Exception.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - /// - /// The missing ff00 exception. - /// - // ReSharper disable once InconsistentNaming - internal class MissingFF00Exception : Exception - { - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoder.cs deleted file mode 100644 index 29255204b..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoder.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System.IO; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort -{ - /// - /// Image decoder for generating an image out of a jpg stream. - /// - internal sealed class GolangJpegDecoder : IImageDecoder, IJpegDecoderOptions, IImageInfoDetector - { - /// - /// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded. - /// - public bool IgnoreMetadata { get; set; } - - /// - public Image Decode(Configuration configuration, Stream stream) - where TPixel : struct, IPixel - { - Guard.NotNull(stream, nameof(stream)); - - using (var decoder = new GolangJpegDecoderCore(configuration, this)) - { - return decoder.Decode(stream); - } - } - - /// - public IImageInfo Identify(Configuration configuration, Stream stream) - { - Guard.NotNull(stream, nameof(stream)); - - using (var decoder = new GolangJpegDecoderCore(configuration, this)) - { - return decoder.Identify(stream); - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs deleted file mode 100644 index 46cdcddb4..000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs +++ /dev/null @@ -1,824 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System.Collections.Generic; -using System.IO; - -using SixLabors.ImageSharp.Formats.Jpeg.Components; -using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; -using SixLabors.ImageSharp.MetaData; -using SixLabors.ImageSharp.MetaData.Profiles.Exif; -using SixLabors.ImageSharp.MetaData.Profiles.Icc; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Primitives; -using SixLabors.Primitives; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort -{ - /// - /// - /// Performs the jpeg decoding operation. - /// - internal sealed unsafe class GolangJpegDecoderCore : IRawJpegData - { - /// - /// The maximum number of color components - /// - public const int MaxComponents = 4; - - /// - /// The maximum number of quantization tables - /// - public const int MaxTq = 3; - - /// - /// The only supported precision - /// - public const int SupportedPrecision = 8; - - // Complex value type field + mutable + available to other classes = the field MUST NOT be private :P -#pragma warning disable SA1401 // FieldsMustBePrivate - - /// - /// Encapsulates stream reading and processing data and operations for . - /// It's a value type for improved data locality, and reduced number of CALLVIRT-s - /// - public InputProcessor InputProcessor; -#pragma warning restore SA401 - - /// - /// The global configuration - /// - private readonly Configuration configuration; - - /// - /// Whether the image has a JFIF header - /// It's faster to check this than to use the equality operator on the struct - /// - private bool isJFif; - - /// - /// Contains information about the JFIF marker - /// - private JFifMarker jFif; - - /// - /// Whether the image has a EXIF header - /// - private bool isExif; - - /// - /// Whether the image has an Adobe marker. - /// It's faster to check this than to use the equality operator on the struct - /// - private bool isAdobe; - - /// - /// Contains information about the Adobe marker - /// - private AdobeMarker adobe; - - /// - /// Initializes a new instance of the class. - /// - /// The configuration. - /// The options. - public GolangJpegDecoderCore(Configuration configuration, IJpegDecoderOptions options) - { - this.IgnoreMetadata = options.IgnoreMetadata; - this.configuration = configuration ?? Configuration.Default; - this.Temp = new byte[2 * Block8x8F.Size]; - } - - /// - public JpegColorSpace ColorSpace { get; private set; } - - /// - /// Gets the component array - /// - public GolangComponent[] Components { get; private set; } - - /// - /// Gets the huffman trees - /// - public GolangHuffmanTree[] HuffmanTrees { get; private set; } - - /// - public Block8x8F[] QuantizationTables { get; private set; } - - /// - /// Gets the temporary buffer used to store bytes read from the stream. - /// TODO: Should be stack allocated, fixed sized buffer! - /// - public byte[] Temp { get; } - - /// - public Size ImageSizeInPixels { get; private set; } - - /// - /// Gets the number of MCU blocks in the image as . - /// - public Size ImageSizeInMCU { get; private set; } - - /// - public int ComponentCount { get; private set; } - - IEnumerable IRawJpegData.Components => this.Components; - - /// - /// Gets the color depth, in number of bits per pixel. - /// - public int BitsPerPixel => this.ComponentCount * SupportedPrecision; - - /// - /// Gets the image height - /// - public int ImageHeight => this.ImageSizeInPixels.Height; - - /// - /// Gets the image width - /// - public int ImageWidth => this.ImageSizeInPixels.Width; - - /// - /// Gets the input stream. - /// - public Stream InputStream { get; private set; } - - /// - /// Gets a value indicating whether the image is interlaced (progressive) - /// - public bool IsProgressive { get; private set; } - - /// - /// Gets the restart interval - /// - public int RestartInterval { get; private set; } - - /// - /// Gets the number of MCU-s (Minimum Coded Units) in the image along the X axis - /// - public int MCUCountX => this.ImageSizeInMCU.Width; - - /// - /// Gets the number of MCU-s (Minimum Coded Units) in the image along the Y axis - /// - public int MCUCountY => this.ImageSizeInMCU.Height; - - /// - /// Gets the total number of MCU-s (Minimum Coded Units) in the image. - /// - public int TotalMCUCount => this.MCUCountX * this.MCUCountY; - - /// - /// Gets a value indicating whether the metadata should be ignored when the image is being decoded. - /// - public bool IgnoreMetadata { get; } - - /// - /// Gets the decoded by this decoder instance. - /// - public ImageMetaData MetaData { get; private set; } - - /// - /// Decodes the image from the specified and sets - /// the data to image. - /// - /// The pixel format. - /// The stream, where the image should be. - /// The decoded image. - public Image Decode(Stream stream) - where TPixel : struct, IPixel - { - this.ParseStream(stream); - return this.PostProcessIntoImage(); - } - - /// - /// Reads the raw image information from the specified stream. - /// - /// The containing image data. - public IImageInfo Identify(Stream stream) - { - this.ParseStream(stream, true); - return new ImageInfo(new PixelTypeInfo(this.BitsPerPixel), this.ImageWidth, this.ImageHeight, this.MetaData); - } - - /// - public void Dispose() - { - if (this.Components != null) - { - foreach (GolangComponent component in this.Components) - { - component?.Dispose(); - } - } - - this.InputProcessor.Dispose(); - } - - /// - /// Read metadata from stream and read the blocks in the scans into . - /// - /// The stream - /// Whether to decode metadata only. - public void ParseStream(Stream stream, bool metadataOnly = false) - { - this.MetaData = new ImageMetaData(); - this.InputStream = stream; - this.InputProcessor = new InputProcessor(stream, this.Temp); - - if (!metadataOnly) - { - this.HuffmanTrees = GolangHuffmanTree.CreateHuffmanTrees(); - this.QuantizationTables = new Block8x8F[MaxTq + 1]; - } - - // Check for the Start Of Image marker. - this.InputProcessor.ReadFull(this.Temp, 0, 2); - - if (this.Temp[0] != JpegConstants.Markers.XFF || this.Temp[1] != JpegConstants.Markers.SOI) - { - throw new ImageFormatException("Missing SOI marker."); - } - - // Process the remaining segments until the End Of Image marker. - bool processBytes = true; - - // we can't currently short circute progressive images so don't try. - while (processBytes) - { - this.InputProcessor.ReadFull(this.Temp, 0, 2); - - if (this.InputProcessor.ReachedEOF) - { - // We've reached the end of the stream. - processBytes = false; - } - - while (this.Temp[0] != 0xff) - { - // Strictly speaking, this is a format error. However, libjpeg is - // liberal in what it accepts. As of version 9, next_marker in - // jdmarker.c treats this as a warning (JWRN_EXTRANEOUS_DATA) and - // continues to decode the stream. Even before next_marker sees - // extraneous data, jpeg_fill_bit_buffer in jdhuff.c reads as many - // bytes as it can, possibly past the end of a scan's data. It - // effectively puts back any markers that it overscanned (e.g. an - // "\xff\xd9" EOI marker), but it does not put back non-marker data, - // and thus it can silently ignore a small number of extraneous - // non-marker bytes before next_marker has a chance to see them (and - // print a warning). - // We are therefore also liberal in what we accept. Extraneous data - // is silently ignore - // This is similar to, but not exactly the same as, the restart - // mechanism within a scan (the RST[0-7] markers). - // Note that extraneous 0xff bytes in e.g. SOS data are escaped as - // "\xff\x00", and so are detected a little further down below. - this.Temp[0] = this.Temp[1]; - this.Temp[1] = this.InputProcessor.ReadByte(); - } - - byte marker = this.Temp[1]; - if (marker == 0) - { - // Treat "\xff\x00" as extraneous data. - continue; - } - - while (marker == 0xff) - { - // Section B.1.1.2 says, "Any marker may optionally be preceded by any - // number of fill bytes, which are bytes assigned code X'FF'". - this.InputProcessor.ReadByteUnsafe(out marker); - - if (this.InputProcessor.ReachedEOF) - { - // We've reached the end of the stream. - processBytes = false; - break; - } - } - - // End Of Image. - if (marker == JpegConstants.Markers.EOI) - { - break; - } - - if (marker >= JpegConstants.Markers.RST0 && marker <= JpegConstants.Markers.RST7) - { - // Figures B.2 and B.16 of the specification suggest that restart markers should - // only occur between Entropy Coded Segments and not after the final ECS. - // However, some encoders may generate incorrect JPEGs with a final restart - // marker. That restart marker will be seen here instead of inside the ProcessSOS - // method, and is ignored as a harmless error. Restart markers have no extra data, - // so we check for this before we read the 16-bit length of the segment. - continue; - } - - // Read the 16-bit length of the segment. The value includes the 2 bytes for the - // length itself, so we subtract 2 to get the number of remaining bytes. - this.InputProcessor.ReadFullUnsafe(this.Temp, 0, 2); - int remaining = (this.Temp[0] << 8) + this.Temp[1] - 2; - if (remaining < 0) - { - throw new ImageFormatException("Short segment length."); - } - - switch (marker) - { - case JpegConstants.Markers.SOF0: - case JpegConstants.Markers.SOF1: - case JpegConstants.Markers.SOF2: - this.IsProgressive = marker == JpegConstants.Markers.SOF2; - this.ProcessStartOfFrameMarker(remaining, metadataOnly); - - break; - case JpegConstants.Markers.DHT: - - if (metadataOnly) - { - this.InputProcessor.Skip(remaining); - } - else - { - this.ProcessDefineHuffmanTablesMarker(remaining); - } - - break; - case JpegConstants.Markers.DQT: - if (metadataOnly) - { - this.InputProcessor.Skip(remaining); - } - else - { - this.ProcessDefineQuantizationTablesMarker(remaining); - } - - break; - case JpegConstants.Markers.SOS: - if (!metadataOnly) - { - this.ProcessStartOfScanMarker(remaining); - if (this.InputProcessor.ReachedEOF) - { - // If unexpected EOF reached. We can stop processing bytes as we now have the image data. - processBytes = false; - } - } - else - { - // It's highly unlikely that APPn related data will be found after the SOS marker - // We should have gathered everything we need by now. - processBytes = false; - } - - break; - - case JpegConstants.Markers.DRI: - if (metadataOnly) - { - this.InputProcessor.Skip(remaining); - } - else - { - this.ProcessDefineRestartIntervalMarker(remaining); - } - - break; - case JpegConstants.Markers.APP0: - this.ProcessApplicationHeaderMarker(remaining); - break; - case JpegConstants.Markers.APP1: - this.ProcessApp1Marker(remaining); - break; - case JpegConstants.Markers.APP2: - this.ProcessApp2Marker(remaining); - break; - case JpegConstants.Markers.APP14: - this.ProcessApp14Marker(remaining); - break; - default: - if ((marker >= JpegConstants.Markers.APP0 && marker <= JpegConstants.Markers.APP15) - || marker == JpegConstants.Markers.COM) - { - this.InputProcessor.Skip(remaining); - } - - break; - } - } - - this.InitDerivedMetaDataProperties(); - } - - /// - /// Returns true if 'mcuCounter' is at restart interval - /// - public bool IsAtRestartInterval(int mcuCounter) - { - return this.RestartInterval > 0 && mcuCounter % this.RestartInterval == 0 - && mcuCounter < this.TotalMCUCount; - } - - /// - /// Assigns derived metadata properties to , eg. horizontal and vertical resolution if it has a JFIF header. - /// - private void InitDerivedMetaDataProperties() - { - if (this.isJFif) - { - this.MetaData.HorizontalResolution = this.jFif.XDensity; - this.MetaData.VerticalResolution = this.jFif.YDensity; - } - else if (this.isExif) - { - double horizontalValue = this.MetaData.ExifProfile.TryGetValue(ExifTag.XResolution, out ExifValue horizonalTag) - ? ((Rational)horizonalTag.Value).ToDouble() - : 0; - - double verticalValue = this.MetaData.ExifProfile.TryGetValue(ExifTag.YResolution, out ExifValue verticalTag) - ? ((Rational)verticalTag.Value).ToDouble() - : 0; - - if (horizontalValue > 0 && verticalValue > 0) - { - this.MetaData.HorizontalResolution = horizontalValue; - this.MetaData.VerticalResolution = verticalValue; - } - } - - if (this.MetaData.IccProfile?.CheckIsValid() == false) - { - this.MetaData.IccProfile = null; - } - } - - /// - /// Processes the application header containing the JFIF identifier plus extra data. - /// - /// The remaining bytes in the segment block. - private void ProcessApplicationHeaderMarker(int remaining) - { - if (remaining < 5) - { - this.InputProcessor.Skip(remaining); - return; - } - - const int MarkerLength = JFifMarker.Length; - this.InputProcessor.ReadFull(this.Temp, 0, MarkerLength); - remaining -= MarkerLength; - - this.isJFif = JFifMarker.TryParse(this.Temp, out this.jFif); - - if (remaining > 0) - { - this.InputProcessor.Skip(remaining); - } - } - - /// - /// Processes the App1 marker retrieving any stored metadata - /// - /// The remaining bytes in the segment block. - private void ProcessApp1Marker(int remaining) - { - if (remaining < 6 || this.IgnoreMetadata) - { - this.InputProcessor.Skip(remaining); - return; - } - - byte[] profile = new byte[remaining]; - this.InputProcessor.ReadFull(profile, 0, remaining); - - if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker)) - { - this.isExif = true; - this.MetaData.ExifProfile = new ExifProfile(profile); - } - } - - /// - /// Processes the App2 marker retrieving any stored ICC profile information - /// - /// The remaining bytes in the segment block. - private void ProcessApp2Marker(int remaining) - { - // Length is 14 though we only need to check 12. - const int Icclength = 14; - if (remaining < Icclength || this.IgnoreMetadata) - { - this.InputProcessor.Skip(remaining); - return; - } - - byte[] identifier = new byte[Icclength]; - this.InputProcessor.ReadFull(identifier, 0, Icclength); - remaining -= Icclength; // We have read it by this point - - if (ProfileResolver.IsProfile(identifier, ProfileResolver.IccMarker)) - { - byte[] profile = new byte[remaining]; - this.InputProcessor.ReadFull(profile, 0, remaining); - - if (this.MetaData.IccProfile == null) - { - this.MetaData.IccProfile = new IccProfile(profile); - } - else - { - this.MetaData.IccProfile.Extend(profile); - } - } - else - { - // Not an ICC profile we can handle. Skip the remaining bytes so we can carry on and ignore this. - this.InputProcessor.Skip(remaining); - } - } - - /// - /// Processes the application header containing the Adobe identifier - /// which stores image encoding information for DCT filters. - /// - /// The remaining bytes in the segment block. - private void ProcessApp14Marker(int remaining) - { - const int MarkerLength = AdobeMarker.Length; - if (remaining < MarkerLength) - { - // Skip the application header length - this.InputProcessor.Skip(remaining); - return; - } - - this.InputProcessor.ReadFull(this.Temp, 0, MarkerLength); - remaining -= MarkerLength; - - this.isAdobe = AdobeMarker.TryParse(this.Temp, out this.adobe); - - if (remaining > 0) - { - this.InputProcessor.Skip(remaining); - } - } - - /// - /// Processes the Define Quantization Marker and tables. Specified in section B.2.4.1. - /// - /// The remaining bytes in the segment block. - /// - /// Thrown if the tables do not match the header - /// - private void ProcessDefineQuantizationTablesMarker(int remaining) - { - while (remaining > 0) - { - bool done = false; - - remaining--; - byte x = this.InputProcessor.ReadByte(); - int tq = x & 0x0F; - if (tq > MaxTq) - { - throw new ImageFormatException("Bad Tq value"); - } - - switch (x >> 4) - { - case 0: - if (remaining < Block8x8F.Size) - { - done = true; - break; - } - - remaining -= Block8x8F.Size; - this.InputProcessor.ReadFull(this.Temp, 0, Block8x8F.Size); - - for (int i = 0; i < Block8x8F.Size; i++) - { - this.QuantizationTables[tq][i] = this.Temp[i]; - } - - break; - case 1: - if (remaining < 2 * Block8x8F.Size) - { - done = true; - break; - } - - remaining -= 2 * Block8x8F.Size; - this.InputProcessor.ReadFull(this.Temp, 0, 2 * Block8x8F.Size); - - for (int i = 0; i < Block8x8F.Size; i++) - { - this.QuantizationTables[tq][i] = (this.Temp[2 * i] << 8) | this.Temp[(2 * i) + 1]; - } - - break; - default: - throw new ImageFormatException("Bad Pq value"); - } - - if (done) - { - break; - } - } - - if (remaining != 0) - { - throw new ImageFormatException("DQT has wrong length"); - } - } - - /// - /// Processes the Start of Frame marker. Specified in section B.2.2. - /// - /// The remaining bytes in the segment block. - /// Whether to decode metadata only. - private void ProcessStartOfFrameMarker(int remaining, bool metadataOnly) - { - if (this.ComponentCount != 0) - { - throw new ImageFormatException("Multiple SOF markers"); - } - - switch (remaining) - { - case 6 + (3 * 1): // grayscale image. - this.ComponentCount = 1; - break; - case 6 + (3 * 3): // YCbCr or RGB image. - this.ComponentCount = 3; - break; - case 6 + (3 * 4): // YCbCrK or CMYK image. - this.ComponentCount = 4; - break; - default: - throw new ImageFormatException("Incorrect number of components"); - } - - this.InputProcessor.ReadFull(this.Temp, 0, remaining); - - // We only support 8-bit precision. - if (this.Temp[0] != SupportedPrecision) - { - throw new ImageFormatException("Only 8-Bit precision supported."); - } - - int height = (this.Temp[1] << 8) + this.Temp[2]; - int width = (this.Temp[3] << 8) + this.Temp[4]; - - this.ImageSizeInPixels = new Size(width, height); - - if (this.Temp[5] != this.ComponentCount) - { - throw new ImageFormatException("SOF has wrong length"); - } - - if (!metadataOnly) - { - this.Components = new GolangComponent[this.ComponentCount]; - - for (int i = 0; i < this.ComponentCount; i++) - { - byte componentIdentifier = this.Temp[6 + (3 * i)]; - var component = new GolangComponent(componentIdentifier, i); - component.InitializeCoreData(this); - this.Components[i] = component; - } - - int h0 = this.Components[0].HorizontalSamplingFactor; - int v0 = this.Components[0].VerticalSamplingFactor; - - this.ImageSizeInMCU = this.ImageSizeInPixels.DivideRoundUp(8 * h0, 8 * v0); - - this.ColorSpace = this.DeduceJpegColorSpace(); - - foreach (GolangComponent component in this.Components) - { - component.InitializeDerivedData(this.configuration.MemoryAllocator, this); - } - } - } - - /// - /// Processes a Define Huffman Table marker, and initializes a huffman - /// struct from its contents. Specified in section B.2.4.2. - /// - /// The remaining bytes in the segment block. - private void ProcessDefineHuffmanTablesMarker(int remaining) - { - while (remaining > 0) - { - if (remaining < 17) - { - throw new ImageFormatException($"DHT has wrong length. {remaining}"); - } - - this.InputProcessor.ReadFull(this.Temp, 0, 17); - - int tc = this.Temp[0] >> 4; - if (tc > GolangHuffmanTree.MaxTc) - { - throw new ImageFormatException("Bad Tc value"); - } - - int th = this.Temp[0] & 0x0f; - if (th > GolangHuffmanTree.MaxTh) - { - throw new ImageFormatException("Bad Th value"); - } - - int huffTreeIndex = (tc * GolangHuffmanTree.ThRowSize) + th; - this.HuffmanTrees[huffTreeIndex].ProcessDefineHuffmanTablesMarkerLoop( - ref this.InputProcessor, - this.Temp, - ref remaining); - } - } - - /// - /// Processes the DRI (Define Restart Interval Marker) Which specifies the interval between RSTn markers, in - /// macroblocks - /// - /// The remaining bytes in the segment block. - private void ProcessDefineRestartIntervalMarker(int remaining) - { - if (remaining != 2) - { - throw new ImageFormatException("DRI has wrong length"); - } - - this.InputProcessor.ReadFull(this.Temp, 0, remaining); - this.RestartInterval = (this.Temp[0] << 8) + this.Temp[1]; - } - - /// - /// Processes the SOS (Start of scan marker). - /// - /// The remaining bytes in the segment block. - /// - /// Missing SOF Marker - /// SOS has wrong length - /// - private void ProcessStartOfScanMarker(int remaining) - { - GolangJpegScanDecoder scan = default; - GolangJpegScanDecoder.InitStreamReading(&scan, this, remaining); - this.InputProcessor.Bits = default; - scan.DecodeBlocks(this); - } - - private JpegColorSpace DeduceJpegColorSpace() - { - switch (this.ComponentCount) - { - case 1: - return JpegColorSpace.Grayscale; - case 3: - if (!this.isAdobe || this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformYCbCr) - { - return JpegColorSpace.YCbCr; - } - - if (this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformUnknown) - { - return JpegColorSpace.RGB; - } - - break; - case 4: - if (this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformYcck) - { - return JpegColorSpace.Ycck; - } - - return JpegColorSpace.Cmyk; - } - - throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}." - + "JpegDecoder only supports YCbCr, RGB, YccK, CMYK and grayscale color spaces."); - } - - private Image PostProcessIntoImage() - where TPixel : struct, IPixel - { - using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryAllocator, this)) - { - var image = new Image(this.configuration, this.ImageWidth, this.ImageHeight, this.MetaData); - postProcessor.PostProcess(image.Frames.RootFrame); - return image; - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs index eafbb391c..57b70dd26 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs @@ -2,8 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System.IO; - -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Jpeg @@ -24,7 +22,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg { Guard.NotNull(stream, nameof(stream)); - using (var decoder = new PdfJsJpegDecoderCore(configuration, this)) + using (var decoder = new JpegDecoderCore(configuration, this)) { return decoder.Decode(stream); } @@ -35,7 +33,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg { Guard.NotNull(stream, nameof(stream)); - using (var decoder = new PdfJsJpegDecoderCore(configuration, this)) + using (var decoder = new JpegDecoderCore(configuration, this)) { return decoder.Identify(stream); } diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs similarity index 93% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs rename to src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 69b5e93b6..5c4dbfc24 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -10,7 +10,6 @@ using System.Runtime.InteropServices; using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.MetaData.Profiles.Icc; @@ -19,14 +18,14 @@ using SixLabors.ImageSharp.Primitives; using SixLabors.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort +namespace SixLabors.ImageSharp.Formats.Jpeg { /// /// Performs the jpeg decoding operation. /// Originally ported from /// with additional fixes for both performance and common encoding errors. /// - internal sealed class PdfJsJpegDecoderCore : IRawJpegData + internal sealed class JpegDecoderCore : IRawJpegData { /// /// The only supported precision @@ -51,12 +50,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort /// /// The DC HUffman tables /// - private PdfJsHuffmanTables dcHuffmanTables; + private HuffmanTables dcHuffmanTables; /// /// The AC HUffman tables /// - private PdfJsHuffmanTables acHuffmanTables; + private HuffmanTables acHuffmanTables; /// /// The fast AC tables used for entropy decoding @@ -84,11 +83,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort private AdobeMarker adobe; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The configuration. /// The options. - public PdfJsJpegDecoderCore(Configuration configuration, IJpegDecoderOptions options) + public JpegDecoderCore(Configuration configuration, IJpegDecoderOptions options) { this.configuration = configuration ?? Configuration.Default; this.IgnoreMetadata = options.IgnoreMetadata; @@ -97,7 +96,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort /// /// Gets the frame /// - public PdfJsFrame Frame { get; private set; } + public JpegFrame Frame { get; private set; } /// public Size ImageSizeInPixels { get; private set; } @@ -146,7 +145,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort /// /// Gets the components. /// - public PdfJsFrameComponent[] Components => this.Frame.Components; + public JpegFrameComponent[] Components => this.Frame.Components; /// IEnumerable IRawJpegData.Components => this.Components; @@ -159,14 +158,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort /// /// The buffer to read file markers to /// The input stream - /// The - public static PdfJsFileMarker FindNextFileMarker(byte[] marker, DoubleBufferedStreamReader stream) + /// The + public static JpegFileMarker FindNextFileMarker(byte[] marker, DoubleBufferedStreamReader stream) { int value = stream.Read(marker, 0, 2); if (value == 0) { - return new PdfJsFileMarker(JpegConstants.Markers.EOI, stream.Length - 2); + return new JpegFileMarker(JpegConstants.Markers.EOI, stream.Length - 2); } if (marker[0] == JpegConstants.Markers.XFF) @@ -179,16 +178,16 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort int suffix = stream.ReadByte(); if (suffix == -1) { - return new PdfJsFileMarker(JpegConstants.Markers.EOI, stream.Length - 2); + return new JpegFileMarker(JpegConstants.Markers.EOI, stream.Length - 2); } m = suffix; } - return new PdfJsFileMarker((byte)m, stream.Position - 2); + return new JpegFileMarker((byte)m, stream.Position - 2); } - return new PdfJsFileMarker(marker[1], stream.Position - 2, true); + return new JpegFileMarker(marker[1], stream.Position - 2, true); } /// @@ -228,7 +227,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort // Check for the Start Of Image marker. this.InputStream.Read(this.markerBuffer, 0, 2); - var fileMarker = new PdfJsFileMarker(this.markerBuffer[1], 0); + var fileMarker = new JpegFileMarker(this.markerBuffer[1], 0); if (fileMarker.Marker != JpegConstants.Markers.SOI) { throw new ImageFormatException("Missing SOI marker."); @@ -236,14 +235,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort this.InputStream.Read(this.markerBuffer, 0, 2); byte marker = this.markerBuffer[1]; - fileMarker = new PdfJsFileMarker(marker, (int)this.InputStream.Position - 2); + fileMarker = new JpegFileMarker(marker, (int)this.InputStream.Position - 2); // Only assign what we need if (!metadataOnly) { this.QuantizationTables = new Block8x8F[4]; - this.dcHuffmanTables = new PdfJsHuffmanTables(); - this.acHuffmanTables = new PdfJsHuffmanTables(); + this.dcHuffmanTables = new HuffmanTables(); + this.acHuffmanTables = new HuffmanTables(); this.fastACTables = new FastACTables(this.configuration.MemoryAllocator); } @@ -630,7 +629,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort /// The remaining bytes in the segment block. /// The current frame marker. /// Whether to parse metadata only - private void ProcessStartOfFrameMarker(int remaining, PdfJsFileMarker frameMarker, bool metadataOnly) + private void ProcessStartOfFrameMarker(int remaining, JpegFileMarker frameMarker, bool metadataOnly) { if (this.Frame != null) { @@ -645,7 +644,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort throw new ImageFormatException("Only 8-Bit precision supported."); } - this.Frame = new PdfJsFrame + this.Frame = new JpegFrame { Extended = frameMarker.Marker == JpegConstants.Markers.SOF1, Progressive = frameMarker.Marker == JpegConstants.Markers.SOF2, @@ -667,7 +666,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort { // No need to pool this. They max out at 4 this.Frame.ComponentIds = new byte[this.Frame.ComponentCount]; - this.Frame.Components = new PdfJsFrameComponent[this.Frame.ComponentCount]; + this.Frame.Components = new JpegFrameComponent[this.Frame.ComponentCount]; this.ColorSpace = this.DeduceJpegColorSpace(); for (int i = 0; i < this.Frame.ComponentCount; i++) @@ -686,7 +685,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort maxV = v; } - var component = new PdfJsFrameComponent(this.configuration.MemoryAllocator, this.Frame, this.temp[index], h, v, this.temp[index + 2], i); + var component = new JpegFrameComponent(this.configuration.MemoryAllocator, this.Frame, this.temp[index], h, v, this.temp[index + 2], i); this.Frame.Components[i] = component; this.Frame.ComponentIds[i] = component.Id; @@ -794,7 +793,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort throw new ImageFormatException("Unknown component selector"); } - ref PdfJsFrameComponent component = ref this.Frame.Components[componentIndex]; + ref JpegFrameComponent component = ref this.Frame.Components[componentIndex]; int tableSpec = this.InputStream.ReadByte(); component.DCHuffmanTableId = tableSpec >> 4; component.ACHuffmanTableId = tableSpec & 15; @@ -831,9 +830,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort /// The codelengths /// The values [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void BuildHuffmanTable(PdfJsHuffmanTables tables, int index, ReadOnlySpan codeLengths, ReadOnlySpan values) + private void BuildHuffmanTable(HuffmanTables tables, int index, ReadOnlySpan codeLengths, ReadOnlySpan values) { - tables[index] = new PdfJsHuffmanTable(this.configuration.MemoryAllocator, codeLengths, values); + tables[index] = new HuffmanTable(this.configuration.MemoryAllocator, codeLengths, values); } /// diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoder.cs deleted file mode 100644 index e12278cc7..000000000 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoder.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System.IO; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort -{ - /// - /// Image decoder for generating an image out of a jpg stream. - /// - internal sealed class PdfJsJpegDecoder : IImageDecoder, IJpegDecoderOptions, IImageInfoDetector - { - /// - /// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded. - /// - public bool IgnoreMetadata { get; set; } - - /// - public Image Decode(Configuration configuration, Stream stream) - where TPixel : struct, IPixel - { - Guard.NotNull(stream, nameof(stream)); - - using (var decoder = new PdfJsJpegDecoderCore(configuration, this)) - { - return decoder.Decode(stream); - } - } - - /// - public IImageInfo Identify(Configuration configuration, Stream stream) - { - Guard.NotNull(stream, nameof(stream)); - - using (var decoder = new PdfJsJpegDecoderCore(configuration, this)) - { - return decoder.Identify(stream); - } - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg.cs index f86919dd1..9b968e4db 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg.cs @@ -4,8 +4,8 @@ using System.Drawing; using System.IO; using BenchmarkDotNet.Attributes; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; + +using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests; using CoreSize = SixLabors.Primitives.Size; @@ -45,23 +45,11 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg } [Benchmark(Description = "Decode Jpeg - ImageSharp")] - public CoreSize JpegImageSharpOrig() - { - using (var memoryStream = new MemoryStream(this.jpegBytes)) - { - using (var image = Image.Load(memoryStream, new GolangJpegDecoder())) - { - return new CoreSize(image.Width, image.Height); - } - } - } - - [Benchmark(Description = "Decode Jpeg - ImageSharp PdfJs")] - public CoreSize JpegImageSharpPdfJs() + public CoreSize JpegImageSharp() { using (var memoryStream = new MemoryStream(this.jpegBytes)) { - using (var image = Image.Load(memoryStream, new PdfJsJpegDecoder())) + using (var image = Image.Load(memoryStream, new JpegDecoder())) { return new CoreSize(image.Width, image.Height); } diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegMultiple.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegMultiple.cs index c4ee732f5..be0fe76b8 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegMultiple.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegMultiple.cs @@ -3,8 +3,7 @@ using System.Collections.Generic; using BenchmarkDotNet.Attributes; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; +using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.PixelFormats; using SDImage = System.Drawing.Image; @@ -22,15 +21,9 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg protected override IEnumerable SearchPatterns => new[] { "*.jpg" }; [Benchmark(Description = "DecodeJpegMultiple - ImageSharp")] - public void DecodeJpegImageSharpOrig() + public void DecodeJpegImageSharp() { - this.ForEachStream(ms => Image.Load(ms, new GolangJpegDecoder())); - } - - [Benchmark(Description = "DecodeJpegMultiple - ImageSharp PDFJs")] - public void DecodeJpegImageSharpPdfJs() - { - this.ForEachStream(ms => Image.Load(ms, new PdfJsJpegDecoder())); + this.ForEachStream(ms => Image.Load(ms, new JpegDecoder())); } [Benchmark(Baseline = true, Description = "DecodeJpegMultiple - System.Drawing")] diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs index 059f312b3..5958b9f79 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs @@ -5,7 +5,6 @@ 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 @@ -38,12 +37,12 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg } } - [Benchmark(Description = "PdfJsJpegDecoderCore.ParseStream")] + [Benchmark(Description = "JpegDecoderCore.ParseStream")] public void ParseStreamPdfJs() { using (var memoryStream = new MemoryStream(this.jpegBytes)) { - var decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder() { IgnoreMetadata = true }); + var decoder = new JpegDecoderCore(Configuration.Default, new Formats.Jpeg.JpegDecoder() { IgnoreMetadata = true }); decoder.ParseStream(memoryStream); decoder.Dispose(); } diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs index f91595df8..c70378464 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs @@ -4,16 +4,17 @@ using System; using System.IO; using BenchmarkDotNet.Attributes; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; + +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg { [Config(typeof(Config.ShortClr))] public class DoubleBufferedStreams { - private byte[] buffer = CreateTestBytes(); - private byte[] chunk1 = new byte[2]; - private byte[] chunk2 = new byte[2]; + private readonly byte[] buffer = CreateTestBytes(); + private readonly byte[] chunk1 = new byte[2]; + private readonly byte[] chunk2 = new byte[2]; private MemoryStream stream1; private MemoryStream stream2; diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/EncodeJpeg.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/EncodeJpeg.cs index 53f0630b9..d934a1d6d 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/EncodeJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/EncodeJpeg.cs @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg [Benchmark(Baseline = true, Description = "System.Drawing Jpeg")] public void JpegSystemDrawing() { - using (MemoryStream memoryStream = new MemoryStream()) + using (var memoryStream = new MemoryStream()) { this.bmpDrawing.Save(memoryStream, ImageFormat.Jpeg); } @@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg [Benchmark(Description = "ImageSharp Jpeg")] public void JpegCore() { - using (MemoryStream memoryStream = new MemoryStream()) + using (var memoryStream = new MemoryStream()) { this.bmpCore.SaveAsJpeg(memoryStream); } diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs index b6ad20d12..ae32167a9 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs @@ -3,8 +3,8 @@ using System.IO; using BenchmarkDotNet.Attributes; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; + +using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Tests; namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg @@ -29,22 +29,11 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg } [Benchmark] - public IImageInfo IdentifyGolang() - { - using (var memoryStream = new MemoryStream(this.jpegBytes)) - { - var decoder = new GolangJpegDecoder(); - - return decoder.Identify(Configuration.Default, memoryStream); - } - } - - [Benchmark] - public IImageInfo IdentifyPdfJs() + public IImageInfo Identify() { using (var memoryStream = new MemoryStream(this.jpegBytes)) { - var decoder = new PdfJsJpegDecoder(); + var decoder = new JpegDecoder(); return decoder.Identify(Configuration.Default, memoryStream); } } diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/LoadResizeSave.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/LoadResizeSave.cs index 296b3fb7a..1d485ee08 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/LoadResizeSave.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/LoadResizeSave.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage); [Params( - TestImages.Jpeg.Baseline.Jpeg420Exif + TestImages.Jpeg.Baseline.Jpeg420Exif //, TestImages.Jpeg.Baseline.Calliphora )] public string TestImage { get; set; } @@ -74,10 +74,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg [Benchmark] public void ImageSharp() { - using (var source = Image.Load( - this.configuration, - this.sourceBytes, - new JpegDecoder { IgnoreMetadata = true })) + var source = Image.Load(this.configuration, this.sourceBytes, new JpegDecoder { IgnoreMetadata = true }); + using (source) using (var destStream = new MemoryStream(this.destBytes)) { source.Mutate(c => c.Resize(source.Width / 4, source.Height / 4)); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs index 20b199441..5316ec758 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs @@ -3,7 +3,8 @@ using System; using System.IO; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; + +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.Memory; using Xunit; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs index e266554d1..8169fdba3 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.Memory; + using SixLabors.ImageSharp.PixelFormats; using Xunit; // ReSharper disable InconsistentNaming @@ -13,33 +13,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { [Theory] [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] - public void DecodeBaselineJpeg_Orig(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (SkipTest(provider)) - { - return; - } - - // For 32 bit test enviroments: - provider.Configuration.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling(); - - using (Image image = provider.GetImage(GolangJpegDecoder)) - { - image.DebugSave(provider); - provider.Utility.TestName = DecodeBaselineJpegOutputName; - image.CompareToReferenceOutput( - this.GetImageComparer(provider), - provider, - appendPixelTypeToFileName: false); - } - - provider.Configuration.MemoryAllocator.ReleaseRetainedResources(); - } - - [Theory] - [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] - public void DecodeBaselineJpeg_PdfJs(TestImageProvider provider) + public void DecodeBaselineJpeg(TestImageProvider provider) where TPixel : struct, IPixel { if (SkipTest(provider)) @@ -48,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg return; } - using (Image image = provider.GetImage(PdfJsJpegDecoder)) + using (Image image = provider.GetImage(JpegDecoder)) { image.DebugSave(provider); @@ -62,20 +36,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Theory] [WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)] - public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_Golang(TestImageProvider provider) - where TPixel : struct, IPixel - { - // TODO: We need a public ImageDecoderException class in ImageSharp! - Assert.ThrowsAny(() => provider.GetImage(GolangJpegDecoder)); - } - - [Theory] - [WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)] - public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_PdfJs(TestImageProvider provider) + public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow(TestImageProvider provider) where TPixel : struct, IPixel { // TODO: We need a public ImageDecoderException class in ImageSharp! - Assert.ThrowsAny(() => provider.GetImage(PdfJsJpegDecoder)); + Assert.ThrowsAny(() => provider.GetImage(JpegDecoder)); } [Theory(Skip = "Debug only, enable manually!")] diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs index f217f0df1..2e67c06c1 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Theory] [MemberData(nameof(MetaDataTestData))] - public void MetaDataIsParsedCorrectly_Orig( + public void MetaDataIsParsedCorrectly( bool useIdentify, string imagePath, int expectedPixelSize, @@ -60,25 +60,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { TestMetaDataImpl( useIdentify, - GolangJpegDecoder, - imagePath, - expectedPixelSize, - exifProfilePresent, - iccProfilePresent); - } - - [Theory] - [MemberData(nameof(MetaDataTestData))] - public void MetaDataIsParsedCorrectly_PdfJs( - bool useIdentify, - string imagePath, - int expectedPixelSize, - bool exifProfilePresent, - bool iccProfilePresent) - { - TestMetaDataImpl( - useIdentify, - PdfJsJpegDecoder, + JpegDecoder, imagePath, expectedPixelSize, exifProfilePresent, @@ -216,7 +198,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(true)] public void Decoder_Reads_Correct_Resolution_From_Jfif(bool useIdentify) { - TestImageInfo(TestImages.Jpeg.Baseline.Floorplan, DefaultJpegDecoder, useIdentify, + TestImageInfo(TestImages.Jpeg.Baseline.Floorplan, JpegDecoder, useIdentify, imageInfo => { Assert.Equal(300, imageInfo.MetaData.HorizontalResolution); @@ -229,7 +211,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(true)] public void Decoder_Reads_Correct_Resolution_From_Exif(bool useIdentify) { - TestImageInfo(TestImages.Jpeg.Baseline.Jpeg420Exif, DefaultJpegDecoder, useIdentify, + TestImageInfo(TestImages.Jpeg.Baseline.Jpeg420Exif, JpegDecoder, useIdentify, imageInfo => { Assert.Equal(72, imageInfo.MetaData.HorizontalResolution); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs index c793b4034..9de788be2 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Linq; -using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; using Xunit; // ReSharper disable InconsistentNaming @@ -15,7 +13,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Theory] [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] - public void DecodeProgressiveJpeg_Orig(TestImageProvider provider) + public void DecodeProgressiveJpeg(TestImageProvider provider) where TPixel : struct, IPixel { if (SkipTest(provider)) @@ -24,41 +22,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg return; } - // Golang decoder is unable to decode these: - if (PdfJsOnly.Any(fn => fn.Contains(provider.SourceFileOrDescription))) - { - return; - } - - // For 32 bit test enviroments: - provider.Configuration.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling(); - - using (Image image = provider.GetImage(GolangJpegDecoder)) - { - image.DebugSave(provider); - - provider.Utility.TestName = DecodeProgressiveJpegOutputName; - image.CompareToReferenceOutput( - this.GetImageComparer(provider), - provider, - appendPixelTypeToFileName: false); - } - - provider.Configuration.MemoryAllocator.ReleaseRetainedResources(); - } - - [Theory] - [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] - public void DecodeProgressiveJpeg_PdfJs(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (SkipTest(provider)) - { - // skipping to avoid OutOfMemoryException on CI - return; - } - - using (Image image = provider.GetImage(PdfJsJpegDecoder)) + using (Image image = provider.GetImage(JpegDecoder)) { image.DebugSave(provider); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 41cc6db51..496891ce4 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -2,14 +2,10 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Jpeg; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; using SixLabors.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; @@ -64,11 +60,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg private ITestOutputHelper Output { get; } - private static GolangJpegDecoder GolangJpegDecoder => new GolangJpegDecoder(); - - private static PdfJsJpegDecoder PdfJsJpegDecoder => new PdfJsJpegDecoder(); - - private static JpegDecoder DefaultJpegDecoder => new JpegDecoder(); + private static JpegDecoder JpegDecoder => new JpegDecoder(); [Fact] public void ParseStream_BasicPropertiesAreCorrect1_PdfJs() @@ -76,7 +68,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg byte[] bytes = TestFile.Create(TestImages.Jpeg.Progressive.Progress).Bytes; using (var ms = new MemoryStream(bytes)) { - var decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder()); + var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder()); decoder.ParseStream(ms); // I don't know why these numbers are different. All I know is that the decoder works @@ -89,9 +81,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg public const string DecodeBaselineJpegOutputName = "DecodeBaselineJpeg"; [Theory] - [WithFile(TestImages.Jpeg.Baseline.Calliphora, CommonNonDefaultPixelTypes, false)] - [WithFile(TestImages.Jpeg.Baseline.Calliphora, CommonNonDefaultPixelTypes, true)] - public void JpegDecoder_IsNotBoundToSinglePixelType(TestImageProvider provider, bool useOldDecoder) + [WithFile(TestImages.Jpeg.Baseline.Calliphora, CommonNonDefaultPixelTypes)] + public void JpegDecoder_IsNotBoundToSinglePixelType(TestImageProvider provider) where TPixel : struct, IPixel { if (SkipTest(provider)) @@ -102,8 +93,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg // For 32 bit test enviroments: provider.Configuration.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling(); - IImageDecoder decoder = useOldDecoder ? (IImageDecoder)GolangJpegDecoder : PdfJsJpegDecoder; - using (Image image = provider.GetImage(decoder)) + using (Image image = provider.GetImage(JpegDecoder)) { image.DebugSave(provider); @@ -125,7 +115,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg appendPixelTypeToFileName: false ).SingleOrDefault(); - if (report != null && report.TotalNormalizedDifference.HasValue) + if (report?.TotalNormalizedDifference != null) { return report.DifferencePercentageString; } @@ -139,17 +129,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg this.Output.WriteLine(provider.SourceFileOrDescription); provider.Utility.TestName = testName; - using (Image image = provider.GetImage(GolangJpegDecoder)) - { - string d = this.GetDifferenceInPercentageString(image, provider); - - this.Output.WriteLine($"Difference using ORIGINAL decoder: {d}"); - } - - using (Image image = provider.GetImage(PdfJsJpegDecoder)) + using (Image image = provider.GetImage(JpegDecoder)) { string d = this.GetDifferenceInPercentageString(image, provider); - this.Output.WriteLine($"Difference using PDFJS decoder: {d}"); + this.Output.WriteLine($"Difference using decoder: {d}"); } } @@ -175,7 +158,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg using (Image expectedImage = provider.GetReferenceOutputImage(appendPixelTypeToFileName: false)) using (var pdfJsOriginalResult = Image.Load(pdfJsOriginalResultPath)) - using (var pdfJsPortResult = Image.Load(sourceBytes, PdfJsJpegDecoder)) + using (var pdfJsPortResult = Image.Load(sourceBytes, JpegDecoder)) { ImageSimilarityReport originalReport = comparer.CompareImagesOrFrames(expectedImage, pdfJsOriginalResult); ImageSimilarityReport portReport = comparer.CompareImagesOrFrames(expectedImage, pdfJsPortResult); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs index 843843f79..cfa421a82 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs @@ -1,9 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; @@ -48,7 +47,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg where TPixel : struct, IPixel { string imageFile = provider.SourceFileOrDescription; - using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(imageFile)) + using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile)) using (var pp = new JpegImagePostProcessor(Configuration.Default.MemoryAllocator, decoder)) using (var imageFrame = new ImageFrame(Configuration.Default, decoder.ImageWidth, decoder.ImageHeight)) { @@ -68,7 +67,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg where TPixel : struct, IPixel { string imageFile = provider.SourceFileOrDescription; - using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(imageFile)) + using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile)) using (var pp = new JpegImagePostProcessor(Configuration.Default.MemoryAllocator, decoder)) using (var image = new Image(decoder.ImageWidth, decoder.ImageHeight)) { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs index b0f342f5a..32538090d 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs @@ -8,8 +8,6 @@ using System.Numerics; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Jpeg; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; using SixLabors.ImageSharp.PixelFormats; using Xunit; @@ -34,18 +32,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg TestImages.Jpeg.Baseline.Jpeg444, }; - //[Theory] // Benchmark, enable manually - //[MemberData(nameof(DecodeJpegData))] - public void DecodeJpeg_Original(string fileName) - { - this.DecodeJpegBenchmarkImpl(fileName, new GolangJpegDecoder()); - } - // [Theory] // Benchmark, enable manually // [MemberData(nameof(DecodeJpegData))] - public void DecodeJpeg_PdfJs(string fileName) + public void DecodeJpeg(string fileName) { - this.DecodeJpegBenchmarkImpl(fileName, new PdfJsJpegDecoder()); + this.DecodeJpegBenchmarkImpl(fileName, new JpegDecoder()); } private void DecodeJpegBenchmarkImpl(string fileName, IImageDecoder decoder) @@ -70,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg ExecutionCount, () => { - Image img = Image.Load(bytes, decoder); + var img = Image.Load(bytes, decoder); }, // ReSharper disable once ExplicitCallerInfoArgument $"Decode {fileName}"); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs index 827a459cd..e4d8d29d4 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs @@ -2,12 +2,10 @@ // Licensed under the Apache License, Version 2.0. using System.Text; + +using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using SixLabors.Primitives; @@ -30,53 +28,20 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(TestImages.Jpeg.Baseline.Jpeg400, JpegColorSpace.Grayscale)] [InlineData(TestImages.Jpeg.Baseline.Ycck, JpegColorSpace.Ycck)] [InlineData(TestImages.Jpeg.Baseline.Cmyk, JpegColorSpace.Cmyk)] - public void ColorSpace_IsDeducedCorrectlyGolang(string imageFile, object expectedColorSpaceValue) + public void ColorSpace_IsDeducedCorrectly(string imageFile, object expectedColorSpaceValue) { var expecteColorSpace = (JpegColorSpace)expectedColorSpaceValue; - using (GolangJpegDecoderCore decoder = JpegFixture.ParseGolangStream(imageFile)) + using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile)) { Assert.Equal(expecteColorSpace, decoder.ColorSpace); } } - [Theory] - [InlineData(TestImages.Jpeg.Baseline.Testorig420, JpegColorSpace.YCbCr)] - [InlineData(TestImages.Jpeg.Baseline.Jpeg400, JpegColorSpace.Grayscale)] - [InlineData(TestImages.Jpeg.Baseline.Ycck, JpegColorSpace.Ycck)] - [InlineData(TestImages.Jpeg.Baseline.Cmyk, JpegColorSpace.Cmyk)] - public void ColorSpace_IsDeducedCorrectlyPdfJs(string imageFile, object expectedColorSpaceValue) - { - var expecteColorSpace = (JpegColorSpace)expectedColorSpaceValue; - - using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(imageFile)) - { - Assert.Equal(expecteColorSpace, decoder.ColorSpace); - } - } - - [Fact] - public void ComponentScalingIsCorrect_1ChannelJpegGolang() - { - using (GolangJpegDecoderCore decoder = JpegFixture.ParseGolangStream(TestImages.Jpeg.Baseline.Jpeg400)) - { - Assert.Equal(1, decoder.ComponentCount); - Assert.Equal(1, decoder.Components.Length); - - Size expectedSizeInBlocks = decoder.ImageSizeInPixels.DivideRoundUp(8); - - Assert.Equal(expectedSizeInBlocks, decoder.ImageSizeInMCU); - - var uniform1 = new Size(1, 1); - GolangComponent c0 = decoder.Components[0]; - VerifyJpeg.VerifyComponent(c0, expectedSizeInBlocks, uniform1, uniform1); - } - } - [Fact] - public void ComponentScalingIsCorrect_1ChannelJpegPdfJs() + public void ComponentScalingIsCorrect_1ChannelJpeg() { - using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(TestImages.Jpeg.Baseline.Jpeg400)) + using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(TestImages.Jpeg.Baseline.Jpeg400)) { Assert.Equal(1, decoder.ComponentCount); Assert.Equal(1, decoder.Components.Length); @@ -86,7 +51,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Assert.Equal(expectedSizeInBlocks, decoder.ImageSizeInMCU); var uniform1 = new Size(1, 1); - PdfJsFrameComponent c0 = decoder.Components[0]; + JpegFrameComponent c0 = decoder.Components[0]; VerifyJpeg.VerifyComponent(c0, expectedSizeInBlocks, uniform1, uniform1); } } @@ -98,40 +63,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(TestImages.Jpeg.Baseline.Testorig420)] [InlineData(TestImages.Jpeg.Baseline.Ycck)] [InlineData(TestImages.Jpeg.Baseline.Cmyk)] - public void PrintComponentDataGolang(string imageFile) - { - var sb = new StringBuilder(); - - using (GolangJpegDecoderCore decoder = JpegFixture.ParseGolangStream(imageFile)) - { - sb.AppendLine(imageFile); - sb.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}"); - GolangComponent c0 = decoder.Components[0]; - GolangComponent c1 = decoder.Components[1]; - - sb.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}"); - sb.AppendLine($"Chroma: {c1.SamplingFactors} BLOCKS: {c1.SizeInBlocks}"); - } - this.Output.WriteLine(sb.ToString()); - } - - [Theory] - [InlineData(TestImages.Jpeg.Baseline.Jpeg444)] - [InlineData(TestImages.Jpeg.Baseline.Jpeg420Exif)] - [InlineData(TestImages.Jpeg.Baseline.Jpeg420Small)] - [InlineData(TestImages.Jpeg.Baseline.Testorig420)] - [InlineData(TestImages.Jpeg.Baseline.Ycck)] - [InlineData(TestImages.Jpeg.Baseline.Cmyk)] - public void PrintComponentDataPdfJs(string imageFile) + public void PrintComponentData(string imageFile) { var sb = new StringBuilder(); - using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(imageFile)) + using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile)) { sb.AppendLine(imageFile); sb.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}"); - PdfJsFrameComponent c0 = decoder.Components[0]; - PdfJsFrameComponent c1 = decoder.Components[1]; + JpegFrameComponent c0 = decoder.Components[0]; + JpegFrameComponent c1 = decoder.Components[1]; sb.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}"); sb.AppendLine($"Chroma: {c1.SamplingFactors} BLOCKS: {c1.SizeInBlocks}"); @@ -152,48 +93,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Theory] [MemberData(nameof(ComponentVerificationData))] - public void ComponentScalingIsCorrect_MultiChannelJpegGolang( - string imageFile, - int componentCount, - object expectedLumaFactors, - object expectedChromaFactors) - { - var fLuma = (Size)expectedLumaFactors; - var fChroma = (Size)expectedChromaFactors; - - using (GolangJpegDecoderCore decoder = JpegFixture.ParseGolangStream(imageFile)) - { - Assert.Equal(componentCount, decoder.ComponentCount); - Assert.Equal(componentCount, decoder.Components.Length); - - GolangComponent c0 = decoder.Components[0]; - GolangComponent c1 = decoder.Components[1]; - GolangComponent c2 = decoder.Components[2]; - - var uniform1 = new Size(1, 1); - - Size expectedLumaSizeInBlocks = decoder.ImageSizeInMCU.MultiplyBy(fLuma); - - Size divisor = fLuma.DivideBy(fChroma); - - Size expectedChromaSizeInBlocks = expectedLumaSizeInBlocks.DivideRoundUp(divisor); - - VerifyJpeg.VerifyComponent(c0, expectedLumaSizeInBlocks, fLuma, uniform1); - VerifyJpeg.VerifyComponent(c1, expectedChromaSizeInBlocks, fChroma, divisor); - VerifyJpeg.VerifyComponent(c2, expectedChromaSizeInBlocks, fChroma, divisor); - - if (componentCount == 4) - { - GolangComponent c3 = decoder.Components[2]; - VerifyJpeg.VerifyComponent(c3, expectedLumaSizeInBlocks, fLuma, uniform1); - } - } - } - - - [Theory] - [MemberData(nameof(ComponentVerificationData))] - public void ComponentScalingIsCorrect_MultiChannelJpegPdfJs( + public void ComponentScalingIsCorrect_MultiChannelJpeg( string imageFile, int componentCount, object expectedLumaFactors, @@ -202,14 +102,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg var fLuma = (Size)expectedLumaFactors; var fChroma = (Size)expectedChromaFactors; - using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(imageFile)) + using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile)) { Assert.Equal(componentCount, decoder.ComponentCount); Assert.Equal(componentCount, decoder.Components.Length); - PdfJsFrameComponent c0 = decoder.Components[0]; - PdfJsFrameComponent c1 = decoder.Components[1]; - PdfJsFrameComponent c2 = decoder.Components[2]; + JpegFrameComponent c0 = decoder.Components[0]; + JpegFrameComponent c1 = decoder.Components[1]; + JpegFrameComponent c2 = decoder.Components[2]; var uniform1 = new Size(1, 1); @@ -225,7 +125,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg if (componentCount == 4) { - PdfJsFrameComponent c3 = decoder.Components[2]; + JpegFrameComponent c3 = decoder.Components[2]; VerifyJpeg.VerifyComponent(c3, expectedLumaSizeInBlocks, fLuma, uniform1); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs index 46a688b49..9378b1c8e 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs @@ -4,8 +4,6 @@ using System.IO; using System.Linq; using SixLabors.ImageSharp.Formats.Jpeg; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; @@ -42,10 +40,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Theory(Skip = "Debug only, enable manually!")] [WithFileCollection(nameof(AllTestJpegs), PixelTypes.Rgba32)] - public void PdfJsDecoder_ParseStream_SaveSpectralResult(TestImageProvider provider) + public void Decoder_ParseStream_SaveSpectralResult(TestImageProvider provider) where TPixel : struct, IPixel { - var decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder()); + var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder()); byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes; @@ -58,25 +56,30 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } } - [Theory(Skip = "Debug only, enable manually!")] + [Theory] [WithFileCollection(nameof(AllTestJpegs), PixelTypes.Rgba32)] - public void OriginalDecoder_ParseStream_SaveSpectralResult(TestImageProvider provider) + public void VerifySpectralCorrectness(TestImageProvider provider) where TPixel : struct, IPixel { - var decoder = new GolangJpegDecoderCore(Configuration.Default, new JpegDecoder()); + if (!TestEnvironment.IsWindows) + { + return; + } + + var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder()); byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes; using (var ms = new MemoryStream(sourceBytes)) { - decoder.ParseStream(ms, false); + decoder.ParseStream(ms); + var imageSharpData = LibJpegTools.SpectralData.LoadFromImageSharpDecoder(decoder); - var data = LibJpegTools.SpectralData.LoadFromImageSharpDecoder(decoder); - VerifyJpeg.SaveSpectralImage(provider, data); + this.VerifySpectralCorrectnessImpl(provider, imageSharpData); } } - - private void VerifySpectralCorrectness( + + private void VerifySpectralCorrectnessImpl( TestImageProvider provider, LibJpegTools.SpectralData imageSharpData) where TPixel : struct, IPixel @@ -119,51 +122,5 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Assert.True(totalDifference < tolerance); } - - [Theory] - [WithFileCollection(nameof(AllTestJpegs), PixelTypes.Rgba32)] - public void VerifySpectralCorrectness_PdfJs(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (!TestEnvironment.IsWindows) - { - return; - } - - var decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder()); - - byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes; - - using (var ms = new MemoryStream(sourceBytes)) - { - decoder.ParseStream(ms); - var imageSharpData = LibJpegTools.SpectralData.LoadFromImageSharpDecoder(decoder); - - this.VerifySpectralCorrectness(provider, imageSharpData); - } - } - - [Theory] - [WithFileCollection(nameof(AllTestJpegs), PixelTypes.Rgba32)] - public void VerifySpectralCorrectness_Golang(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (!TestEnvironment.IsWindows) - { - return; - } - - var decoder = new GolangJpegDecoderCore(Configuration.Default, new GolangJpegDecoder()); - - byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes; - - using (var ms = new MemoryStream(sourceBytes)) - { - decoder.ParseStream(ms); - var imageSharpData = LibJpegTools.SpectralData.LoadFromImageSharpDecoder(decoder); - - this.VerifySpectralCorrectness(provider, imageSharpData); - } - } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/JpegFixture.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/JpegFixture.cs index 7fe98e2af..d14fbc3fc 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/JpegFixture.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/JpegFixture.cs @@ -10,8 +10,6 @@ using System.Text; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg.Components; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; using Xunit; using Xunit.Abstractions; @@ -175,23 +173,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils Assert.False(failed); } - internal static GolangJpegDecoderCore ParseGolangStream(string testFileName, bool metaDataOnly = false) + internal static JpegDecoderCore ParseJpegStream(string testFileName, bool metaDataOnly = false) { byte[] bytes = TestFile.Create(testFileName).Bytes; using (var ms = new MemoryStream(bytes)) { - var decoder = new GolangJpegDecoderCore(Configuration.Default, new JpegDecoder()); - decoder.ParseStream(ms, metaDataOnly); - return decoder; - } - } - - internal static PdfJsJpegDecoderCore ParsePdfJsStream(string testFileName, bool metaDataOnly = false) - { - byte[] bytes = TestFile.Create(testFileName).Bytes; - using (var ms = new MemoryStream(bytes)) - { - var decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder()); + var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder()); decoder.ParseStream(ms, metaDataOnly); return decoder; } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs index 645ee4512..5ffd5d62b 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs @@ -1,18 +1,15 @@ +using System; +using System.Linq; +using System.Numerics; + using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Memory; +using SixLabors.Primitives; namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { - using System; - using System.Linq; - using System.Numerics; - - using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; - using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; - using SixLabors.Memory; - using SixLabors.Primitives; - internal static partial class LibJpegTools { /// @@ -57,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils this.SpectralBlocks[x, y] = new Block8x8(data); } - public static ComponentData Load(PdfJsFrameComponent c, int index) + public static ComponentData Load(JpegFrameComponent c, int index) { var result = new ComponentData( c.WidthInBlocks, @@ -77,26 +74,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils return result; } - public static ComponentData Load(GolangComponent c) - { - var result = new ComponentData( - c.SizeInBlocks.Width, - c.SizeInBlocks.Height, - c.Index - ); - - for (int y = 0; y < result.HeightInBlocks; y++) - { - for (int x = 0; x < result.WidthInBlocks; x++) - { - short[] data = c.GetBlockReference(x, y).ToArray(); - result.MakeBlock(data, y, x); - } - } - - return result; - } - public Image CreateGrayScaleImage() { var result = new Image(this.WidthInBlocks * 8, this.HeightInBlocks * 8); @@ -143,8 +120,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public bool Equals(ComponentData other) { - if (object.ReferenceEquals(null, other)) return false; - if (object.ReferenceEquals(this, other)) return true; + if (other is null) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + bool ok = this.Index == other.Index && this.HeightInBlocks == other.HeightInBlocks && this.WidthInBlocks == other.WidthInBlocks; //&& this.MinVal == other.MinVal @@ -165,8 +150,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public override bool Equals(object obj) { - if (Object.ReferenceEquals(null, obj)) return false; - if (Object.ReferenceEquals(this, obj)) return true; + if (obj is null) return false; + if (object.ReferenceEquals(this, obj)) return true; if (obj.GetType() != this.GetType()) return false; return this.Equals((ComponentData)obj); } @@ -175,7 +160,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { unchecked { - var hashCode = this.Index; + int hashCode = this.Index; hashCode = (hashCode * 397) ^ this.HeightInBlocks; hashCode = (hashCode * 397) ^ this.WidthInBlocks; hashCode = (hashCode * 397) ^ this.MinVal.GetHashCode(); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs index ae8194e1a..e9f0b1138 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs @@ -5,11 +5,9 @@ using System; using System.Linq; using System.Numerics; +using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg.Components; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; -using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils @@ -32,17 +30,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils this.Components = components; } - public static SpectralData LoadFromImageSharpDecoder(PdfJsJpegDecoderCore decoder) + public static SpectralData LoadFromImageSharpDecoder(JpegDecoderCore decoder) { - PdfJsFrameComponent[] srcComponents = decoder.Frame.Components; - LibJpegTools.ComponentData[] destComponents = srcComponents.Select(LibJpegTools.ComponentData.Load).ToArray(); - - return new SpectralData(destComponents); - } - - public static SpectralData LoadFromImageSharpDecoder(GolangJpegDecoderCore decoder) - { - GolangComponent[] srcComponents = decoder.Components; + JpegFrameComponent[] srcComponents = decoder.Frame.Components; LibJpegTools.ComponentData[] destComponents = srcComponents.Select(LibJpegTools.ComponentData.Load).ToArray(); return new SpectralData(destComponents); @@ -108,8 +98,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public bool Equals(SpectralData other) { - if (object.ReferenceEquals(null, other)) return false; - if (object.ReferenceEquals(this, other)) return true; + if (other is null) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + if (this.ComponentCount != other.ComponentCount) { return false; From f6ad783aaf6fcdd07b9f0485ec9563e2c60d77ca Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 24 Jul 2018 10:24:23 +0100 Subject: [PATCH 65/68] Cleanup JpegFrameComponent --- .../Jpeg/Components/Decoder/FastACTables.cs | 4 ++-- ...JpegFrameComponent.cs => JpegComponent.cs} | 17 ++++--------- .../Jpeg/Components/Decoder/JpegFrame.cs | 4 ++-- .../Jpeg/Components/Decoder/ScanDecoder.cs | 24 +++++++++---------- .../Formats/Jpeg/JpegDecoderCore.cs | 8 +++---- .../Formats/Jpg/ParseStreamTests.cs | 14 +++++------ .../Jpg/Utils/LibJpegTools.ComponentData.cs | 2 +- .../Jpg/Utils/LibJpegTools.SpectralData.cs | 2 +- 8 files changed, 34 insertions(+), 41 deletions(-) rename src/ImageSharp/Formats/Jpeg/Components/Decoder/{JpegFrameComponent.cs => JpegComponent.cs} (88%) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/FastACTables.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FastACTables.cs index 6d06abecf..95693c09b 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/FastACTables.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/FastACTables.cs @@ -35,9 +35,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder } /// - /// Gets a reference to the first element of the AC table indexed by /// + /// Gets a reference to the first element of the AC table indexed by /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref short GetAcTableReference(JpegFrameComponent component) + public ref short GetAcTableReference(JpegComponent component) { return ref this.tables.GetRowSpan(component.ACHuffmanTableId)[0]; } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs similarity index 88% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrameComponent.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs index 3ce7cacfa..73a69a069 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrameComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs @@ -13,11 +13,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// /// Represents a single frame component /// - internal class JpegFrameComponent : IDisposable, IJpegComponent + internal class JpegComponent : IDisposable, IJpegComponent { private readonly MemoryAllocator memoryAllocator; - public JpegFrameComponent(MemoryAllocator memoryAllocator, JpegFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index) + public JpegComponent(MemoryAllocator memoryAllocator, JpegFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index) { this.memoryAllocator = memoryAllocator; this.Frame = frame; @@ -123,7 +123,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder } else { - JpegFrameComponent c0 = this.Frame.Components[0]; + JpegComponent c0 = this.Frame.Components[0]; this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors); } @@ -138,16 +138,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int GetBlockBufferOffset(int row, int col) + public ref short GetBlockDataReference(int column, int row) { - 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); + ref Block8x8 blockRef = ref this.GetBlockReference(column, row); return ref Unsafe.As(ref blockRef); } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs index a238e0734..da089fa44 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// /// Gets or sets the frame component collection /// - public JpegFrameComponent[] Components { get; set; } + public JpegComponent[] Components { get; set; } /// /// Gets or sets the maximum horizontal sampling factor @@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder for (int i = 0; i < this.ComponentCount; i++) { - JpegFrameComponent component = this.Components[i]; + JpegComponent component = this.Components[i]; component.Init(); } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs index 5afe6382f..99eaf7f43 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder private readonly FastACTables fastACTables; private readonly DoubleBufferedStreamReader stream; - private readonly JpegFrameComponent[] components; + private readonly JpegComponent[] components; private readonly ZigZag dctZigZag; // The restart interval. @@ -175,7 +175,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder // Scan an interleaved mcu... process components in order for (int k = 0; k < this.componentsLength; k++) { - JpegFrameComponent component = this.components[k]; + JpegComponent component = this.components[k]; ref HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; ref HuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId]; @@ -229,7 +229,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// private void ParseBaselineDataNonInterleaved() { - JpegFrameComponent component = this.components[this.componentIndex]; + JpegComponent component = this.components[this.componentIndex]; int w = component.WidthInBlocks; int h = component.HeightInBlocks; @@ -294,7 +294,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder // Scan an interleaved mcu... process components in order for (int k = 0; k < this.componentsLength; k++) { - JpegFrameComponent component = this.components[k]; + JpegComponent component = this.components[k]; ref HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; int h = component.HorizontalSamplingFactor; int v = component.VerticalSamplingFactor; @@ -343,7 +343,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// private void ParseProgressiveDataNonInterleaved() { - JpegFrameComponent component = this.components[this.componentIndex]; + JpegComponent component = this.components[this.componentIndex]; int w = component.WidthInBlocks; int h = component.HeightInBlocks; @@ -394,7 +394,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder } private void DecodeBlockBaseline( - JpegFrameComponent component, + JpegComponent component, int row, int col, ref HuffmanTable dcTable, @@ -409,7 +409,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder JpegThrowHelper.ThrowBadHuffmanCode(); } - ref short blockDataRef = ref component.GetBlockDataReference(row, col); + ref short blockDataRef = ref component.GetBlockDataReference(col, row); int diff = t != 0 ? this.ExtendReceive(t) : 0; int dc = component.DcPredictor + diff; @@ -473,7 +473,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder } private void DecodeBlockProgressiveDC( - JpegFrameComponent component, + JpegComponent component, int row, int col, ref HuffmanTable dcTable) @@ -485,7 +485,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder this.CheckBits(); - ref short blockDataRef = ref component.GetBlockDataReference(row, col); + ref short blockDataRef = ref component.GetBlockDataReference(col, row); if (this.successiveHigh == 0) { @@ -509,7 +509,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder } private void DecodeBlockProgressiveAC( - JpegFrameComponent component, + JpegComponent component, int row, int col, ref HuffmanTable acTable, @@ -520,7 +520,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder JpegThrowHelper.ThrowImageFormatException("Can't merge DC and AC."); } - ref short blockDataRef = ref component.GetBlockDataReference(row, col); + ref short blockDataRef = ref component.GetBlockDataReference(col, row); if (this.successiveHigh == 0) { @@ -939,7 +939,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder for (int i = 0; i < this.components.Length; i++) { - JpegFrameComponent c = this.components[i]; + JpegComponent c = this.components[i]; c.DcPredictor = 0; } diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 5c4dbfc24..07209bc28 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -145,7 +145,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg /// /// Gets the components. /// - public JpegFrameComponent[] Components => this.Frame.Components; + public JpegComponent[] Components => this.Frame.Components; /// IEnumerable IRawJpegData.Components => this.Components; @@ -666,7 +666,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg { // No need to pool this. They max out at 4 this.Frame.ComponentIds = new byte[this.Frame.ComponentCount]; - this.Frame.Components = new JpegFrameComponent[this.Frame.ComponentCount]; + this.Frame.Components = new JpegComponent[this.Frame.ComponentCount]; this.ColorSpace = this.DeduceJpegColorSpace(); for (int i = 0; i < this.Frame.ComponentCount; i++) @@ -685,7 +685,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg maxV = v; } - var component = new JpegFrameComponent(this.configuration.MemoryAllocator, this.Frame, this.temp[index], h, v, this.temp[index + 2], i); + var component = new JpegComponent(this.configuration.MemoryAllocator, this.Frame, this.temp[index], h, v, this.temp[index + 2], i); this.Frame.Components[i] = component; this.Frame.ComponentIds[i] = component.Id; @@ -793,7 +793,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg throw new ImageFormatException("Unknown component selector"); } - ref JpegFrameComponent component = ref this.Frame.Components[componentIndex]; + ref JpegComponent component = ref this.Frame.Components[componentIndex]; int tableSpec = this.InputStream.ReadByte(); component.DCHuffmanTableId = tableSpec >> 4; component.ACHuffmanTableId = tableSpec & 15; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs index e4d8d29d4..3657110c6 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Assert.Equal(expectedSizeInBlocks, decoder.ImageSizeInMCU); var uniform1 = new Size(1, 1); - JpegFrameComponent c0 = decoder.Components[0]; + JpegComponent c0 = decoder.Components[0]; VerifyJpeg.VerifyComponent(c0, expectedSizeInBlocks, uniform1, uniform1); } } @@ -71,8 +71,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { sb.AppendLine(imageFile); sb.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}"); - JpegFrameComponent c0 = decoder.Components[0]; - JpegFrameComponent c1 = decoder.Components[1]; + JpegComponent c0 = decoder.Components[0]; + JpegComponent c1 = decoder.Components[1]; sb.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}"); sb.AppendLine($"Chroma: {c1.SamplingFactors} BLOCKS: {c1.SizeInBlocks}"); @@ -107,9 +107,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg Assert.Equal(componentCount, decoder.ComponentCount); Assert.Equal(componentCount, decoder.Components.Length); - JpegFrameComponent c0 = decoder.Components[0]; - JpegFrameComponent c1 = decoder.Components[1]; - JpegFrameComponent c2 = decoder.Components[2]; + JpegComponent c0 = decoder.Components[0]; + JpegComponent c1 = decoder.Components[1]; + JpegComponent c2 = decoder.Components[2]; var uniform1 = new Size(1, 1); @@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg if (componentCount == 4) { - JpegFrameComponent c3 = decoder.Components[2]; + JpegComponent c3 = decoder.Components[2]; VerifyJpeg.VerifyComponent(c3, expectedLumaSizeInBlocks, fLuma, uniform1); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs index 5ffd5d62b..a10deb983 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs @@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils this.SpectralBlocks[x, y] = new Block8x8(data); } - public static ComponentData Load(JpegFrameComponent c, int index) + public static ComponentData Load(JpegComponent c, int index) { var result = new ComponentData( c.WidthInBlocks, diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs index e9f0b1138..bcfabca39 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public static SpectralData LoadFromImageSharpDecoder(JpegDecoderCore decoder) { - JpegFrameComponent[] srcComponents = decoder.Frame.Components; + JpegComponent[] srcComponents = decoder.Frame.Components; LibJpegTools.ComponentData[] destComponents = srcComponents.Select(LibJpegTools.ComponentData.Load).ToArray(); return new SpectralData(destComponents); From 568c3ac6ace6b39ae82a1377bb452d3c4634a396 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 24 Jul 2018 10:59:17 +0100 Subject: [PATCH 66/68] Fix sandbox --- tests/ImageSharp.Sandbox46/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ImageSharp.Sandbox46/Program.cs b/tests/ImageSharp.Sandbox46/Program.cs index f3875e24a..fa1d63878 100644 --- a/tests/ImageSharp.Sandbox46/Program.cs +++ b/tests/ImageSharp.Sandbox46/Program.cs @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Sandbox46 foreach (object[] data in JpegProfilingBenchmarks.DecodeJpegData) { string fileName = (string)data[0]; - benchmarks.DecodeJpeg_Original(fileName); + benchmarks.DecodeJpeg(fileName); } } } From 0f15e303cf7bda4849fbacd12a2843f6540484fe Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 24 Jul 2018 13:01:58 +0100 Subject: [PATCH 67/68] Improve coverage. --- .../Jpeg/Components/Decoder/JpegFileMarker.cs | 4 +-- .../Jpeg/Components/Decoder/ScanDecoder.cs | 1 + .../Formats/Jpeg/JpegDecoderCore.cs | 1 + .../DoubleBufferedStreamReader.cs | 3 +-- .../Codecs/Jpeg/DoubleBufferedStreams.cs | 3 +-- .../Formats/Jpg/JpegFileMarkerTests.cs | 25 +++++++++++++++++++ .../DoubleBufferedStreamReaderTests.cs | 25 ++++++++++++++++--- 7 files changed, 51 insertions(+), 11 deletions(-) rename src/ImageSharp/{Formats/Jpeg/Components/Decoder => IO}/DoubleBufferedStreamReader.cs (98%) create mode 100644 tests/ImageSharp.Tests/Formats/Jpg/JpegFileMarkerTests.cs rename tests/ImageSharp.Tests/{Formats/Jpg => IO}/DoubleBufferedStreamReaderTests.cs (87%) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs index 31f4efdcb..d2b0ee26e 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs @@ -16,10 +16,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// The marker /// The position within the stream public JpegFileMarker(byte marker, long position) + : this(marker, position, false) { - this.Marker = marker; - this.Position = position; - this.Invalid = false; } /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs index 99eaf7f43..8c525335b 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.IO; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 07209bc28..3b34719a8 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -10,6 +10,7 @@ using System.Runtime.InteropServices; using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; +using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.MetaData.Profiles.Icc; diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/DoubleBufferedStreamReader.cs b/src/ImageSharp/IO/DoubleBufferedStreamReader.cs similarity index 98% rename from src/ImageSharp/Formats/Jpeg/Components/Decoder/DoubleBufferedStreamReader.cs rename to src/ImageSharp/IO/DoubleBufferedStreamReader.cs index f4527966a..94a2f2cbf 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/DoubleBufferedStreamReader.cs +++ b/src/ImageSharp/IO/DoubleBufferedStreamReader.cs @@ -7,8 +7,7 @@ using System.Runtime.CompilerServices; using SixLabors.Memory; -// TODO: This could be useful elsewhere. -namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder +namespace SixLabors.ImageSharp.IO { /// /// A stream reader that add a secondary level buffer in addition to native stream buffered reading diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs index c70378464..d4cbe81e1 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DoubleBufferedStreams.cs @@ -4,8 +4,7 @@ using System; using System.IO; using BenchmarkDotNet.Attributes; - -using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; +using SixLabors.ImageSharp.IO; namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegFileMarkerTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegFileMarkerTests.cs new file mode 100644 index 000000000..42eea2708 --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegFileMarkerTests.cs @@ -0,0 +1,25 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats.Jpeg; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Formats.Jpg +{ + public class JpegFileMarkerTests + { + [Fact] + public void MarkerConstructorAssignsProperties() + { + const byte app1 = JpegConstants.Markers.APP1; + const int position = 5; + var marker = new JpegFileMarker(app1, position); + + Assert.Equal(app1, marker.Marker); + Assert.Equal(position, marker.Position); + Assert.False(marker.Invalid); + Assert.Equal(app1.ToString("X"), marker.ToString()); + } + } +} diff --git a/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs b/tests/ImageSharp.Tests/IO/DoubleBufferedStreamReaderTests.cs similarity index 87% rename from tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs rename to tests/ImageSharp.Tests/IO/DoubleBufferedStreamReaderTests.cs index 5316ec758..4fac8d954 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/DoubleBufferedStreamReaderTests.cs +++ b/tests/ImageSharp.Tests/IO/DoubleBufferedStreamReaderTests.cs @@ -3,12 +3,11 @@ using System; using System.IO; - -using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; +using SixLabors.ImageSharp.IO; using SixLabors.Memory; using Xunit; -namespace SixLabors.ImageSharp.Tests.Formats.Jpg +namespace SixLabors.ImageSharp.Tests.IO { public class DoubleBufferedStreamReaderTests { @@ -30,6 +29,24 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } } + [Fact] + public void DoubleBufferedStreamReaderCanReadSingleByteFromOffset() + { + using (MemoryStream stream = this.CreateTestStream()) + { + byte[] expected = stream.ToArray(); + const int offset = 5; + var reader = new DoubleBufferedStreamReader(this.allocator, stream); + reader.Position = offset; + + Assert.Equal(expected[offset], reader.ReadByte()); + + // We've read a whole chunk but increment by 1 in our reader. + Assert.Equal(stream.Position, DoubleBufferedStreamReader.ChunkLength + offset); + Assert.Equal(offset + 1, reader.Position); + } + } + [Fact] public void DoubleBufferedStreamReaderCanReadSubsequentSingleByteCorrectly() { @@ -139,7 +156,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg // Skip Again reader.Skip(skip2); - // First Skap + First Read + Second Skip + // First Skip + First Read + Second Skip int position = skip + plusOne + skip2; Assert.Equal(position, reader.Position); From f7af71b1f98518613d357605de5ac755db641a0e Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Tue, 24 Jul 2018 22:15:37 +0200 Subject: [PATCH 68/68] further cleanup --- src/ImageSharp/Formats/Jpeg/README.md | 9 +++++++-- .../Formats/Jpg/JpegDecoderTests.Baseline.cs | 8 -------- .../Formats/Jpg/JpegDecoderTests.Progressive.cs | 8 -------- .../Formats/Jpg/JpegDecoderTests.cs | 17 ++--------------- 4 files changed, 9 insertions(+), 33 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/README.md b/src/ImageSharp/Formats/Jpeg/README.md index 54bc14847..2f766ca0c 100644 --- a/src/ImageSharp/Formats/Jpeg/README.md +++ b/src/ImageSharp/Formats/Jpeg/README.md @@ -1,3 +1,8 @@ -Encoder/Decoder adapted and extended from: +Encoder adapted and extended from: +https://golang.org/src/image/jpeg/ -https://golang.org/src/image/jpeg/ \ No newline at end of file +Decoder orchestration code is based on: +https://github.com/mozilla/pdf.js + +Huffmann decoder is based on: +https://github.com/rds1983/StbSharp \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs index 8169fdba3..73167a4b7 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs @@ -42,13 +42,5 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg // TODO: We need a public ImageDecoderException class in ImageSharp! Assert.ThrowsAny(() => provider.GetImage(JpegDecoder)); } - - [Theory(Skip = "Debug only, enable manually!")] - [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] - public void CompareJpegDecoders_Baseline(TestImageProvider provider) - where TPixel : struct, IPixel - { - this.CompareJpegDecodersImpl(provider, DecodeBaselineJpegOutputName); - } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs index 9de788be2..77bc9f540 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs @@ -33,13 +33,5 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg appendPixelTypeToFileName: false); } } - - [Theory(Skip = "Debug only, enable manually!")] - [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] - public void CompareJpegDecoders_Progressive(TestImageProvider provider) - where TPixel : struct, IPixel - { - this.CompareJpegDecodersImpl(provider, DecodeProgressiveJpegOutputName); - } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 496891ce4..4ae955c32 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg private static JpegDecoder JpegDecoder => new JpegDecoder(); [Fact] - public void ParseStream_BasicPropertiesAreCorrect1_PdfJs() + public void ParseStream_BasicPropertiesAreCorrect() { byte[] bytes = TestFile.Create(TestImages.Jpeg.Progressive.Progress).Bytes; using (var ms = new MemoryStream(bytes)) @@ -122,20 +122,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg return "0%"; } - - private void CompareJpegDecodersImpl(TestImageProvider provider, string testName) - where TPixel : struct, IPixel - { - this.Output.WriteLine(provider.SourceFileOrDescription); - provider.Utility.TestName = testName; - - using (Image image = provider.GetImage(JpegDecoder)) - { - string d = this.GetDifferenceInPercentageString(image, provider); - this.Output.WriteLine($"Difference using decoder: {d}"); - } - } - + // DEBUG ONLY! // The PDF.js output should be saved by "tests\ImageSharp.Tests\Formats\Jpg\pdfjs\jpeg-converter.htm" // into "\tests\Images\ActualOutput\JpegDecoderTests\"