diff --git a/src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs similarity index 99% rename from src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs rename to src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs index efaa0b4a48..cb73ee9478 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs @@ -7,7 +7,7 @@ using System.Runtime.InteropServices; using System.Text; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Components { /// /// Represents a Jpeg block with coefficiens. diff --git a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.CopyTo.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs similarity index 99% rename from src/ImageSharp/Formats/Jpeg/Common/Block8x8F.CopyTo.cs rename to src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs index d8963a8b60..43cc3e9dba 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.CopyTo.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.CopyTo.cs @@ -3,10 +3,11 @@ using System.Numerics; using System.Runtime.CompilerServices; + using SixLabors.ImageSharp.Memory; // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Components { internal partial struct Block8x8F { diff --git a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs similarity index 99% rename from src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.cs rename to src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs index 93e9e03885..e83896f587 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs @@ -5,7 +5,7 @@ using System.Runtime.CompilerServices; // -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Components { internal partial struct Block8x8F { diff --git a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.tt b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt similarity index 98% rename from src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.tt rename to src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt index dc0996b65d..82d82ef0c2 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.Generated.tt +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt @@ -18,7 +18,7 @@ using System.Runtime.CompilerServices; <# char[] coordz = {'X', 'Y', 'Z', 'W'}; #> -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Components { internal partial struct Block8x8F { diff --git a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs similarity index 98% rename from src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs rename to src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs index 53297ab550..38974cc76b 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs @@ -9,7 +9,7 @@ using System.Text; // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Components { /// /// Represents a Jpeg block with coefficients. @@ -100,7 +100,7 @@ public float this[int idx] { float val = result[i]; val /= value; - result[i] = (float)val; + result[i] = val; } return result; @@ -113,7 +113,7 @@ public float this[int idx] { float val = result[i]; val += value; - result[i] = (float)val; + result[i] = val; } return result; @@ -126,7 +126,7 @@ public float this[int idx] { float val = result[i]; val -= value; - result[i] = (float)val; + result[i] = val; } return result; @@ -153,7 +153,7 @@ public static Block8x8F Load(Span data) public void Clear() { // The cheapest way to do this in C#: - this = default(Block8x8F); + this = default; } /// diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/AdobeMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs similarity index 97% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/AdobeMarker.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs index 40059c5a0f..af0938d302 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/AdobeMarker.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs @@ -4,7 +4,7 @@ using System; // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Provides information about the Adobe marker segment. @@ -78,7 +78,7 @@ public static bool TryParse(byte[] bytes, out AdobeMarker marker) return true; } - marker = default(AdobeMarker); + marker = default; return false; } diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs similarity index 86% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs index 86d5957846..bac77f905e 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmyk.cs @@ -4,18 +4,18 @@ using System; using System.Numerics; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters { internal abstract partial class JpegColorConverter { - internal class FromCmyk : ColorConverters.JpegColorConverter + internal class FromCmyk : JpegColorConverter { public FromCmyk() : base(JpegColorSpace.Cmyk) { } - public override void ConvertToRGBA(ComponentValues values, Span result) + public override void ConvertToRgba(ComponentValues values, Span result) { // TODO: We can optimize a lot here with Vector and SRCS.Unsafe()! ReadOnlySpan cVals = values.Component0; diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs similarity index 81% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs index 4769bef1d7..b07e57e170 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs @@ -4,18 +4,18 @@ using System; using System.Numerics; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters { internal abstract partial class JpegColorConverter { - internal class FromGrayscale : ColorConverters.JpegColorConverter + internal class FromGrayscale : JpegColorConverter { public FromGrayscale() : base(JpegColorSpace.Grayscale) { } - public override void ConvertToRGBA(ComponentValues values, Span result) + public override void ConvertToRgba(ComponentValues values, Span result) { // TODO: We can optimize a lot here with Vector and SRCS.Unsafe()! ReadOnlySpan yVals = values.Component0; diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs similarity index 84% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs index 7f01eedadb..6b7e77e148 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromRgb.cs @@ -4,18 +4,18 @@ using System; using System.Numerics; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters { internal abstract partial class JpegColorConverter { - internal class FromRgb : ColorConverters.JpegColorConverter + internal class FromRgb : JpegColorConverter { public FromRgb() : base(JpegColorSpace.RGB) { } - public override void ConvertToRGBA(ComponentValues values, Span result) + public override void ConvertToRgba(ComponentValues values, Span result) { // TODO: We can optimize a lot here with Vector and SRCS.Unsafe()! ReadOnlySpan rVals = values.Component0; diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrBasic.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrBasic.cs similarity index 87% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrBasic.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrBasic.cs index ddd2197d4a..35700ea312 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrBasic.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrBasic.cs @@ -4,18 +4,18 @@ using System; using System.Numerics; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters { internal abstract partial class JpegColorConverter { - internal class FromYCbCrBasic : ColorConverters.JpegColorConverter + internal class FromYCbCrBasic : JpegColorConverter { public FromYCbCrBasic() : base(JpegColorSpace.YCbCr) { } - public override void ConvertToRGBA(ComponentValues values, Span result) + public override void ConvertToRgba(ComponentValues values, Span result) { ConvertCore(values, result); } diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs similarity index 95% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs index 2f214f88a9..fd2f17da9e 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs @@ -5,20 +5,21 @@ using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + using SixLabors.ImageSharp.Common.Tuples; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters { internal abstract partial class JpegColorConverter { - internal class FromYCbCrSimd : ColorConverters.JpegColorConverter + internal class FromYCbCrSimd : JpegColorConverter { public FromYCbCrSimd() : base(JpegColorSpace.YCbCr) { } - public override void ConvertToRGBA(ComponentValues values, Span result) + public override void ConvertToRgba(ComponentValues values, Span result) { int remainder = result.Length % 8; int simdCount = result.Length - remainder; diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs similarity index 95% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs index f8a4514221..c43713bf4c 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs @@ -5,14 +5,15 @@ using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + using SixLabors.ImageSharp.Common.Tuples; // ReSharper disable ImpureMethodCallOnReadonlyValueField -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters { internal abstract partial class JpegColorConverter { - internal class FromYCbCrSimdAvx2 : ColorConverters.JpegColorConverter + internal class FromYCbCrSimdAvx2 : JpegColorConverter { public FromYCbCrSimdAvx2() : base(JpegColorSpace.YCbCr) @@ -21,7 +22,7 @@ public FromYCbCrSimdAvx2() public static bool IsAvailable => Vector.IsHardwareAccelerated && SimdUtils.IsAvx2CompatibleArchitecture; - public override void ConvertToRGBA(ComponentValues values, Span result) + public override void ConvertToRgba(ComponentValues values, Span result) { int remainder = result.Length % 8; int simdCount = result.Length - remainder; diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs similarity index 91% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs index 6d8e6ef5a9..83feefa94a 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccK.cs @@ -4,7 +4,7 @@ using System; using System.Numerics; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters { internal abstract partial class JpegColorConverter { @@ -15,7 +15,7 @@ public FromYccK() { } - public override void ConvertToRGBA(ComponentValues values, Span result) + public override void ConvertToRgba(ComponentValues values, Span result) { // TODO: We can optimize a lot here with Vector and SRCS.Unsafe()! ReadOnlySpan yVals = values.Component0; diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs similarity index 95% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs index 4391be5484..080bf83338 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs @@ -5,10 +5,11 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; + using SixLabors.ImageSharp.Common.Tuples; using SixLabors.ImageSharp.Memory; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters { /// /// Encapsulates the conversion of Jpeg channels to RGBA values packed in buffer. @@ -55,13 +56,13 @@ public static JpegColorConverter GetConverter(JpegColorSpace colorSpace) /// /// The input as a stack-only struct /// The destination buffer of values - public abstract void ConvertToRGBA(ComponentValues values, Span result); + public abstract void ConvertToRgba(ComponentValues values, Span result); /// /// Returns the for the YCbCr colorspace that matches the current CPU architecture. /// private static JpegColorConverter GetYCbCrConverter() => - FromYCbCrSimdAvx2.IsAvailable ? (JpegColorConverter)new FromYCbCrSimdAvx2() : new FromYCbCrSimd(); + JpegColorConverter.FromYCbCrSimdAvx2.IsAvailable ? (JpegColorConverter)new JpegColorConverter.FromYCbCrSimdAvx2() : new JpegColorConverter.FromYCbCrSimd(); /// /// A stack-only struct to reference the input buffers using -s. diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs similarity index 92% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs index de9f75dc1f..efa746819d 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs @@ -1,7 +1,10 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Common interface to represent raw Jpeg components. diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/IRawJpegData.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs similarity index 81% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/IRawJpegData.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs index 3873656a4e..dace78b337 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/IRawJpegData.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs @@ -1,13 +1,16 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + using System; using System.Collections.Generic; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// - /// Represents decompressed, unprocessed jpeg data with spectral space -s. + /// Represents decompressed, unprocessed jpeg data with spectral space -s. /// internal interface IRawJpegData : IDisposable { diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JFifMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs similarity index 98% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/JFifMarker.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs index afe4794a23..591af63442 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JFifMarker.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs @@ -3,7 +3,7 @@ using System; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Provides information about the JFIF marker segment diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegBlockPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs similarity index 97% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegBlockPostProcessor.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs index 2f59bcb822..b586d520a6 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegBlockPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs @@ -2,10 +2,11 @@ // Licensed under the Apache License, Version 2.0. using System.Runtime.InteropServices; + using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Encapsulates the implementation of processing "raw" -s into Jpeg image channels. diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegColorSpace.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegColorSpace.cs similarity index 59% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegColorSpace.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegColorSpace.cs index abc93727e1..2861a2c2e9 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegColorSpace.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegColorSpace.cs @@ -1,4 +1,7 @@ -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Identifies the colorspace of a Jpeg image diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegComponentPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs similarity index 95% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegComponentPostProcessor.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs index 1be637b6df..fe18f8438c 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegComponentPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs @@ -1,8 +1,12 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + using System; + using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Encapsulates postprocessing data for one component for . diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs similarity index 89% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs index 483242c768..38340b2380 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs @@ -1,12 +1,18 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + using System; using System.Linq; using System.Numerics; + using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder +using JpegColorConverter = SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters.JpegColorConverter; + +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Encapsulates the execution od post-processing algorithms to be applied on a to produce a valid :
@@ -36,9 +42,9 @@ internal class JpegImagePostProcessor : IDisposable private readonly IBuffer rgbaBuffer; /// - /// The corresponding to the current determined by . + /// The corresponding to the current determined by . /// - private ColorConverters.JpegColorConverter colorConverter; + private readonly JpegColorConverter colorConverter; /// /// Initializes a new instance of the class. @@ -54,7 +60,7 @@ public JpegImagePostProcessor(MemoryManager memoryManager, IRawJpegData rawJpeg) this.ComponentProcessors = rawJpeg.Components.Select(c => new JpegComponentPostProcessor(memoryManager, this, c)).ToArray(); this.rgbaBuffer = memoryManager.Allocate(rawJpeg.ImageSizeInPixels.Width); - this.colorConverter = ColorConverters.JpegColorConverter.GetConverter(rawJpeg.ColorSpace); + this.colorConverter = JpegColorConverter.GetConverter(rawJpeg.ColorSpace); } /// @@ -148,8 +154,8 @@ private void ConvertColorsInto(ImageFrame destination) { int y = yy - this.PixelRowCounter; - var values = new ColorConverters.JpegColorConverter.ComponentValues(buffers, y); - this.colorConverter.ConvertToRGBA(values, this.rgbaBuffer.Span); + var values = new JpegColorConverter.ComponentValues(buffers, y); + this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.Span); Span destRow = destination.GetPixelRowSpan(yy); diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ProfileResolver.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs similarity index 96% rename from src/ImageSharp/Formats/Jpeg/Common/Decoder/ProfileResolver.cs rename to src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs index 2030ad71b1..e5de4441c2 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ProfileResolver.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs @@ -4,7 +4,7 @@ using System; using System.Text; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { /// /// Provides methods for identifying metadata and color profiles within jpeg images. diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/BlockQuad.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/BlockQuad.cs similarity index 66% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/BlockQuad.cs rename to src/ImageSharp/Formats/Jpeg/Components/Encoder/BlockQuad.cs index 6b16ea824e..7a312138d0 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/BlockQuad.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/BlockQuad.cs @@ -1,18 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder { /// - /// Poor man's stackalloc: Contains a value-type buffer sized for 4 instances. + /// Poor man's stackalloc: Contains a value-type buffer sized for 4 instances. /// Useful for decoder/encoder operations allocating a block for each Jpeg component. /// internal unsafe struct BlockQuad { /// - /// The value-type buffer sized for 4 instances. + /// The value-type buffer sized for 4 instances. /// public fixed float Data[4 * Block8x8F.Size]; } diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffIndex.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffIndex.cs similarity index 91% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffIndex.cs rename to src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffIndex.cs index 23fcda2964..633d7ea80f 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffIndex.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffIndex.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder { /// /// Enumerates the Huffman tables diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs similarity index 96% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs rename to src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs index 7756a7e3ba..a31c4bf2f4 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder { /// /// A compiled look-up table representation of a huffmanSpec. diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs similarity index 98% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs rename to src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs index 1c8228aaa2..2e2ee9575c 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder { /// /// The Huffman encoding specifications. diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/QuantIndex.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/QuantIndex.cs similarity index 86% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/QuantIndex.cs rename to src/ImageSharp/Formats/Jpeg/Components/Encoder/QuantIndex.cs index 459d29f91f..d0933af0c4 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/QuantIndex.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/QuantIndex.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder { /// /// Enumerates the quantization tables diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/RgbToYCbCrTables.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbToYCbCrTables.cs similarity index 93% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/RgbToYCbCrTables.cs rename to src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbToYCbCrTables.cs index 923fe244eb..a0cc9ee8e5 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/RgbToYCbCrTables.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbToYCbCrTables.cs @@ -3,9 +3,7 @@ using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Memory; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder { /// /// Provides 8-bit lookup tables for converting from Rgb to YCbCr colorspace. @@ -68,7 +66,7 @@ internal unsafe struct RgbToYCbCrTables /// The intialized public static RgbToYCbCrTables Create() { - RgbToYCbCrTables tables = default(RgbToYCbCrTables); + RgbToYCbCrTables tables = default; for (int i = 0; i <= 255; i++) { @@ -123,11 +121,5 @@ private static int Fix(float x) { return (int)((x * (1L << ScaleBits)) + 0.5F); } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static int RightShift(int x) - { - return x >> ScaleBits; - } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/YCbCrForwardConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs similarity index 95% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/YCbCrForwardConverter{TPixel}.cs rename to src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs index 3c95a85080..311ffed24b 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/YCbCrForwardConverter{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs @@ -1,10 +1,10 @@ using System; using System.Runtime.CompilerServices; + using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Formats.Jpeg.Common; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder +namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder { /// /// On-stack worker struct to efficiently encapsulate the TPixel -> Rgb24 -> YCbCr conversion chain of 8x8 pixel blocks. diff --git a/src/ImageSharp/Formats/Jpeg/Common/FastFloatingPointDCT.cs b/src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs similarity index 99% rename from src/ImageSharp/Formats/Jpeg/Common/FastFloatingPointDCT.cs rename to src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs index 3ee6e72c5d..dcdc7e9ba7 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/FastFloatingPointDCT.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs @@ -5,7 +5,7 @@ using System.Runtime.CompilerServices; // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Components { /// /// Contains inaccurate, but fast forward and inverse DCT implementations. diff --git a/src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.Generated.cs b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.cs similarity index 89% rename from src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.Generated.cs rename to src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.cs index 1bb37a7d32..0cc729371f 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.Generated.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.cs @@ -1,11 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Numerics; -using System.Runtime.CompilerServices; - // -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Components { internal unsafe partial struct GenericBlock8x8 { diff --git a/src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.Generated.tt b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.tt similarity index 90% rename from src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.Generated.tt rename to src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.tt index d9b15b34fa..28bcea791b 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.Generated.tt +++ b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.Generated.tt @@ -11,11 +11,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Numerics; -using System.Runtime.CompilerServices; - // -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Components { internal unsafe partial struct GenericBlock8x8 { diff --git a/src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs similarity index 96% rename from src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.cs rename to src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs index 09a7eb73aa..9aceb78b2a 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs @@ -1,13 +1,16 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Primitives; // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Components { /// /// A generic 8x8 block implementation, useful for manipulating custom 8x8 pixel data. @@ -18,8 +21,6 @@ internal unsafe partial struct GenericBlock8x8 { public const int Size = 64; - public const int SizeInBytes = Size * 3; - /// /// FOR TESTING ONLY! /// Gets or sets a value at the given index diff --git a/src/ImageSharp/Formats/Jpeg/Common/SizeExtensions.cs b/src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs similarity index 97% rename from src/ImageSharp/Formats/Jpeg/Common/SizeExtensions.cs rename to src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs index 978688673f..48ad188561 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/SizeExtensions.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs @@ -3,9 +3,10 @@ using System; using System.Numerics; + using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Components { /// /// Extension methods for diff --git a/src/ImageSharp/Formats/Jpeg/Common/ZigZag.cs b/src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs similarity index 98% rename from src/ImageSharp/Formats/Jpeg/Common/ZigZag.cs rename to src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs index cb035a8d3d..a3701f2c1b 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/ZigZag.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs @@ -1,10 +1,11 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. + using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Components { /// /// Holds the Jpeg UnZig array in a value/stack type. diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs index 05bde78e65..353eb01fe2 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs @@ -38,7 +38,7 @@ internal struct Bits [MethodImpl(MethodImplOptions.AggressiveInlining)] public void EnsureNBits(int n, ref InputProcessor inputProcessor) { - OrigDecoderErrorCode errorCode = this.EnsureNBitsUnsafe(n, ref inputProcessor); + GolangDecoderErrorCode errorCode = this.EnsureNBitsUnsafe(n, ref inputProcessor); errorCode.EnsureNoError(); } @@ -46,17 +46,17 @@ public void EnsureNBits(int n, ref InputProcessor inputProcessor) /// 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. + /// This method does not throw. Returns instead. /// /// The number of bits to ensure. /// The /// Error code - public OrigDecoderErrorCode EnsureNBitsUnsafe(int n, ref InputProcessor inputProcessor) + public GolangDecoderErrorCode EnsureNBitsUnsafe(int n, ref InputProcessor inputProcessor) { while (true) { - OrigDecoderErrorCode errorCode = this.EnsureBitsStepImpl(ref inputProcessor); - if (errorCode != OrigDecoderErrorCode.NoError || this.UnreadBits >= n) + GolangDecoderErrorCode errorCode = this.EnsureBitsStepImpl(ref inputProcessor); + if (errorCode != GolangDecoderErrorCode.NoError || this.UnreadBits >= n) { return errorCode; } @@ -67,8 +67,8 @@ public OrigDecoderErrorCode EnsureNBitsUnsafe(int n, ref InputProcessor inputPro /// Unrolled version of for n==8 /// /// The - /// A - public OrigDecoderErrorCode Ensure8BitsUnsafe(ref InputProcessor inputProcessor) + /// A + public GolangDecoderErrorCode Ensure8BitsUnsafe(ref InputProcessor inputProcessor) { return this.EnsureBitsStepImpl(ref inputProcessor); } @@ -77,8 +77,8 @@ public OrigDecoderErrorCode Ensure8BitsUnsafe(ref InputProcessor inputProcessor) /// Unrolled version of for n==1 /// /// The - /// A - public OrigDecoderErrorCode Ensure1BitUnsafe(ref InputProcessor inputProcessor) + /// A + public GolangDecoderErrorCode Ensure1BitUnsafe(ref InputProcessor inputProcessor) { return this.EnsureBitsStepImpl(ref inputProcessor); } @@ -92,7 +92,7 @@ public OrigDecoderErrorCode Ensure1BitUnsafe(ref InputProcessor inputProcessor) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int ReceiveExtend(int t, ref InputProcessor inputProcessor) { - OrigDecoderErrorCode errorCode = this.ReceiveExtendUnsafe(t, ref inputProcessor, out int x); + GolangDecoderErrorCode errorCode = this.ReceiveExtendUnsafe(t, ref inputProcessor, out int x); errorCode.EnsureNoError(); return x; } @@ -103,13 +103,13 @@ public int ReceiveExtend(int t, ref InputProcessor inputProcessor) /// Byte /// The /// Read bits value - /// The - public OrigDecoderErrorCode ReceiveExtendUnsafe(int t, ref InputProcessor inputProcessor, out int x) + /// The + public GolangDecoderErrorCode ReceiveExtendUnsafe(int t, ref InputProcessor inputProcessor, out int x) { if (this.UnreadBits < t) { - OrigDecoderErrorCode errorCode = this.EnsureNBitsUnsafe(t, ref inputProcessor); - if (errorCode != OrigDecoderErrorCode.NoError) + GolangDecoderErrorCode errorCode = this.EnsureNBitsUnsafe(t, ref inputProcessor); + if (errorCode != GolangDecoderErrorCode.NoError) { x = int.MaxValue; return errorCode; @@ -126,14 +126,14 @@ public OrigDecoderErrorCode ReceiveExtendUnsafe(int t, ref InputProcessor inputP x += ((-1) << t) + 1; } - return OrigDecoderErrorCode.NoError; + return GolangDecoderErrorCode.NoError; } - private OrigDecoderErrorCode EnsureBitsStepImpl(ref InputProcessor inputProcessor) + private GolangDecoderErrorCode EnsureBitsStepImpl(ref InputProcessor inputProcessor) { - OrigDecoderErrorCode errorCode = inputProcessor.Bytes.ReadByteStuffedByteUnsafe(inputProcessor.InputStream, out int c); + GolangDecoderErrorCode errorCode = inputProcessor.Bytes.ReadByteStuffedByteUnsafe(inputProcessor.InputStream, out int c); - if (errorCode != OrigDecoderErrorCode.NoError) + if (errorCode != GolangDecoderErrorCode.NoError) { return errorCode; } diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs index 2a3817400c..c8c68aa7ea 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs @@ -77,8 +77,8 @@ public void Dispose() /// /// Input stream /// The result byte as - /// The - public OrigDecoderErrorCode ReadByteStuffedByteUnsafe(Stream inputStream, out int x) + /// 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) @@ -86,50 +86,50 @@ public OrigDecoderErrorCode ReadByteStuffedByteUnsafe(Stream inputStream, out in x = this.BufferAsInt[this.I]; this.I++; this.UnreadableBytes = 1; - if (x != OrigJpegConstants.Markers.XFFInt) + if (x != JpegConstants.Markers.XFFInt) { - return OrigDecoderErrorCode.NoError; + return GolangDecoderErrorCode.NoError; } if (this.BufferAsInt[this.I] != 0x00) { - return OrigDecoderErrorCode.MissingFF00; + return GolangDecoderErrorCode.MissingFF00; } this.I++; this.UnreadableBytes = 2; - x = OrigJpegConstants.Markers.XFF; - return OrigDecoderErrorCode.NoError; + x = JpegConstants.Markers.XFF; + return GolangDecoderErrorCode.NoError; } this.UnreadableBytes = 0; - OrigDecoderErrorCode errorCode = this.ReadByteAsIntUnsafe(inputStream, out x); + GolangDecoderErrorCode errorCode = this.ReadByteAsIntUnsafe(inputStream, out x); this.UnreadableBytes = 1; - if (errorCode != OrigDecoderErrorCode.NoError) + if (errorCode != GolangDecoderErrorCode.NoError) { return errorCode; } - if (x != OrigJpegConstants.Markers.XFF) + if (x != JpegConstants.Markers.XFF) { - return OrigDecoderErrorCode.NoError; + return GolangDecoderErrorCode.NoError; } errorCode = this.ReadByteAsIntUnsafe(inputStream, out x); this.UnreadableBytes = 2; - if (errorCode != OrigDecoderErrorCode.NoError) + if (errorCode != GolangDecoderErrorCode.NoError) { return errorCode; } if (x != 0x00) { - return OrigDecoderErrorCode.MissingFF00; + return GolangDecoderErrorCode.MissingFF00; } - x = OrigJpegConstants.Markers.XFF; - return OrigDecoderErrorCode.NoError; + x = JpegConstants.Markers.XFF; + return GolangDecoderErrorCode.NoError; } /// @@ -140,25 +140,25 @@ public OrigDecoderErrorCode ReadByteStuffedByteUnsafe(Stream inputStream, out in [MethodImpl(MethodImplOptions.AggressiveInlining)] public byte ReadByte(Stream inputStream) { - OrigDecoderErrorCode errorCode = this.ReadByteUnsafe(inputStream, out byte result); + 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. + /// This method does not throw on format error, it returns a instead. /// /// Input stream /// The result as out parameter - /// The - public OrigDecoderErrorCode ReadByteUnsafe(Stream inputStream, out byte result) + /// The + public GolangDecoderErrorCode ReadByteUnsafe(Stream inputStream, out byte result) { - OrigDecoderErrorCode errorCode = OrigDecoderErrorCode.NoError; + GolangDecoderErrorCode errorCode = GolangDecoderErrorCode.NoError; while (this.I == this.J) { errorCode = this.FillUnsafe(inputStream); - if (errorCode != OrigDecoderErrorCode.NoError) + if (errorCode != GolangDecoderErrorCode.NoError) { result = 0; return errorCode; @@ -176,15 +176,15 @@ public OrigDecoderErrorCode ReadByteUnsafe(Stream inputStream, out byte result) /// /// The input stream /// The result - /// A + /// A [MethodImpl(MethodImplOptions.AggressiveInlining)] - public OrigDecoderErrorCode ReadByteAsIntUnsafe(Stream inputStream, out int result) + public GolangDecoderErrorCode ReadByteAsIntUnsafe(Stream inputStream, out int result) { - OrigDecoderErrorCode errorCode = OrigDecoderErrorCode.NoError; + GolangDecoderErrorCode errorCode = GolangDecoderErrorCode.NoError; while (this.I == this.J) { errorCode = this.FillUnsafe(inputStream); - if (errorCode != OrigDecoderErrorCode.NoError) + if (errorCode != GolangDecoderErrorCode.NoError) { result = 0; return errorCode; @@ -206,18 +206,18 @@ public OrigDecoderErrorCode ReadByteAsIntUnsafe(Stream inputStream, out int resu [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Fill(Stream inputStream) { - OrigDecoderErrorCode errorCode = this.FillUnsafe(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! + /// This method does not throw , returns a instead! /// /// Input stream - /// The - public OrigDecoderErrorCode FillUnsafe(Stream inputStream) + /// The + public GolangDecoderErrorCode FillUnsafe(Stream inputStream) { if (this.I != this.J) { @@ -239,7 +239,7 @@ public OrigDecoderErrorCode FillUnsafe(Stream inputStream) int n = inputStream.Read(this.Buffer, this.J, this.Buffer.Length - this.J); if (n == 0) { - return OrigDecoderErrorCode.UnexpectedEndOfStream; + return GolangDecoderErrorCode.UnexpectedEndOfStream; } this.J += n; @@ -249,7 +249,7 @@ public OrigDecoderErrorCode FillUnsafe(Stream inputStream) this.BufferAsInt[i] = this.Buffer[i]; } - return OrigDecoderErrorCode.NoError; + 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 index 904ce00dde..2b2bc61ba8 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderThrowHelper.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderThrowHelper.cs @@ -12,22 +12,22 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder internal static class DecoderThrowHelper { /// - /// Throws an exception that belongs to the given + /// Throws an exception that belongs to the given /// - /// The + /// The [MethodImpl(MethodImplOptions.NoInlining)] - public static void ThrowExceptionForErrorCode(this OrigDecoderErrorCode errorCode) + 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 OrigDecoderErrorCode.NoError: + case GolangDecoderErrorCode.NoError: throw new ArgumentException("ThrowExceptionForErrorCode() called with NoError!", nameof(errorCode)); - case OrigDecoderErrorCode.MissingFF00: + case GolangDecoderErrorCode.MissingFF00: throw new MissingFF00Exception(); - case OrigDecoderErrorCode.UnexpectedEndOfStream: + case GolangDecoderErrorCode.UnexpectedEndOfStream: throw new EOFException(); default: throw new ArgumentOutOfRangeException(nameof(errorCode), errorCode, null); @@ -35,26 +35,26 @@ public static void ThrowExceptionForErrorCode(this OrigDecoderErrorCode errorCod } /// - /// Throws an exception if the given defines an error. + /// Throws an exception if the given defines an error. /// - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void EnsureNoError(this OrigDecoderErrorCode errorCode) + public static void EnsureNoError(this GolangDecoderErrorCode errorCode) { - if (errorCode != OrigDecoderErrorCode.NoError) + if (errorCode != GolangDecoderErrorCode.NoError) { ThrowExceptionForErrorCode(errorCode); } } /// - /// Throws an exception if the given is . + /// Throws an exception if the given is . /// - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void EnsureNoEOF(this OrigDecoderErrorCode errorCode) + public static void EnsureNoEOF(this GolangDecoderErrorCode errorCode) { - if (errorCode == OrigDecoderErrorCode.UnexpectedEndOfStream) + if (errorCode == GolangDecoderErrorCode.UnexpectedEndOfStream) { errorCode.ThrowExceptionForErrorCode(); } diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs similarity index 93% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs index e2b72db057..bb3bd01aa3 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponent.cs @@ -3,8 +3,9 @@ using System; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Formats.Jpeg.Common; -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; + +using SixLabors.ImageSharp.Formats.Jpeg.Components; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; @@ -14,9 +15,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder /// /// Represents a single color component /// - internal class OrigComponent : IDisposable, IJpegComponent + internal class GolangComponent : IDisposable, IJpegComponent { - public OrigComponent(byte identifier, int index) + public GolangComponent(byte identifier, int index) { this.Identifier = identifier; this.Index = index; @@ -56,8 +57,8 @@ public OrigComponent(byte identifier, int index) /// Initializes /// /// The to use for buffer allocations. - /// The instance - public void InitializeDerivedData(MemoryManager memoryManager, OrigJpegDecoderCore decoder) + /// The instance + public void InitializeDerivedData(MemoryManager memoryManager, 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]. @@ -76,7 +77,7 @@ public void InitializeDerivedData(MemoryManager memoryManager, OrigJpegDecoderCo } else { - OrigComponent c0 = decoder.Components[0]; + GolangComponent c0 = decoder.Components[0]; this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors); } @@ -86,8 +87,8 @@ public void InitializeDerivedData(MemoryManager memoryManager, OrigJpegDecoderCo /// /// Initializes all component data except . /// - /// The instance - public void InitializeCoreData(OrigJpegDecoderCore decoder) + /// 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)". @@ -102,7 +103,7 @@ public void InitializeCoreData(OrigJpegDecoderCore decoder) } this.QuantizationTableIndex = decoder.Temp[8 + (3 * i)]; - if (this.QuantizationTableIndex > OrigJpegDecoderCore.MaxTq) + if (this.QuantizationTableIndex > GolangJpegDecoderCore.MaxTq) { throw new ImageFormatException("Bad Tq value"); } diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponentScan.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponentScan.cs similarity index 94% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponentScan.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponentScan.cs index 0d98044045..6752768ffa 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponentScan.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangComponentScan.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder /// Represents a component scan /// [StructLayout(LayoutKind.Sequential)] - internal struct OrigComponentScan + internal struct GolangComponentScan { /// /// Gets or sets the component index. diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigDecoderErrorCode.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangDecoderErrorCode.cs similarity index 93% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigDecoderErrorCode.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangDecoderErrorCode.cs index 02a8ea55e0..fa3364527c 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigDecoderErrorCode.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangDecoderErrorCode.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder /// /// Represents "recoverable" decoder errors. /// - internal enum OrigDecoderErrorCode + internal enum GolangDecoderErrorCode { /// /// NoError diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigHuffmanTree.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangHuffmanTree.cs similarity index 95% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigHuffmanTree.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangHuffmanTree.cs index dbc7bb0f7f..dccce2aaa8 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigHuffmanTree.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangHuffmanTree.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Buffers; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,7 +10,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder /// Represents a Huffman tree /// [StructLayout(LayoutKind.Sequential)] - internal unsafe struct OrigHuffmanTree + internal unsafe struct GolangHuffmanTree { /// /// The index of the AC table row @@ -95,12 +93,12 @@ internal unsafe struct OrigHuffmanTree public FixedInt32Buffer16 Indices; /// - /// Creates and initializes an array of instances of size + /// Creates and initializes an array of instances of size /// - /// An array of instances representing the Huffman tables - public static OrigHuffmanTree[] CreateHuffmanTrees() + /// An array of instances representing the Huffman tables + public static GolangHuffmanTree[] CreateHuffmanTrees() { - return new OrigHuffmanTree[NumberOfTrees]; + return new GolangHuffmanTree[NumberOfTrees]; } /// diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.ComputationData.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.ComputationData.cs similarity index 79% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.ComputationData.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.ComputationData.cs index c9bb898aa5..f1dd2526ae 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.ComputationData.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.ComputationData.cs @@ -2,14 +2,15 @@ // Licensed under the Apache License, Version 2.0. using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats.Jpeg.Common; + +using SixLabors.ImageSharp.Formats.Jpeg.Components; namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { /// /// Conains the definition of /// - internal unsafe partial struct OrigJpegScanDecoder + internal unsafe partial struct GolangJpegScanDecoder { /// /// Holds the "large" data blocks needed for computations. @@ -28,14 +29,14 @@ public struct ComputationData public ZigZag Unzig; /// - /// The buffer storing the -s for each component + /// The buffer storing the -s for each component /// - public fixed byte ScanData[3 * OrigJpegDecoderCore.MaxComponents]; + public fixed byte ScanData[3 * GolangJpegDecoderCore.MaxComponents]; /// /// The DC values for each component /// - public fixed int Dc[OrigJpegDecoderCore.MaxComponents]; + public fixed int Dc[GolangJpegDecoderCore.MaxComponents]; /// /// Creates and initializes a new instance diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.DataPointers.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.DataPointers.cs similarity index 86% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.DataPointers.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.DataPointers.cs index 0207280e3e..a00da6fcaf 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.DataPointers.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.DataPointers.cs @@ -1,14 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { /// /// Conains the definition of /// - internal unsafe partial struct OrigJpegScanDecoder + 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 @@ -28,7 +28,7 @@ public struct DataPointers /// /// Pointer to as Scan* /// - public OrigComponentScan* ComponentScan; + public GolangComponentScan* ComponentScan; /// /// Pointer to @@ -43,7 +43,7 @@ public DataPointers(ComputationData* basePtr) { this.Block = &basePtr->Block; this.Unzig = basePtr->Unzig.Data; - this.ComponentScan = (OrigComponentScan*)basePtr->ScanData; + this.ComponentScan = (GolangComponentScan*)basePtr->ScanData; this.Dc = basePtr->Dc; } } diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.cs similarity index 89% rename from src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.cs index d10def3ce7..3a88cfad4b 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/GolangJpegScanDecoder.cs @@ -3,9 +3,8 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats.Jpeg.Common; -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; -using SixLabors.ImageSharp.Memory; + +using SixLabors.ImageSharp.Formats.Jpeg.Components; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder @@ -29,7 +28,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder /// For baseline JPEGs, these parameters are hard-coded to 0/63/0/0. /// [StructLayout(LayoutKind.Sequential)] - internal unsafe partial struct OrigJpegScanDecoder + 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 @@ -110,12 +109,12 @@ internal unsafe partial struct OrigJpegScanDecoder private byte expectedRst; /// - /// Initializes a default-constructed instance for reading data from -s stream. + /// Initializes a default-constructed instance for reading data from -s stream. /// - /// Pointer to on the stack - /// The instance + /// Pointer to on the stack + /// The instance /// The remaining bytes in the segment block. - public static void InitStreamReading(OrigJpegScanDecoder* p, OrigJpegDecoderCore decoder, int remaining) + public static void InitStreamReading(GolangJpegScanDecoder* p, GolangJpegDecoderCore decoder, int remaining) { p->data = ComputationData.Create(); p->pointers = new DataPointers(&p->data); @@ -123,8 +122,8 @@ public static void InitStreamReading(OrigJpegScanDecoder* p, OrigJpegDecoderCore } /// - /// Read Huffman data from Jpeg scans in , - /// and decode it as into . + /// 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. @@ -149,14 +148,14 @@ public static void InitStreamReading(OrigJpegScanDecoder* p, OrigJpegDecoderCore /// 0 1 2 /// 3 4 5 /// - /// The instance - public void DecodeBlocks(OrigJpegDecoderCore decoder) + /// The instance + public void DecodeBlocks(GolangJpegDecoderCore decoder) { decoder.InputProcessor.ResetErrorState(); this.blockCounter = 0; this.mcuCounter = 0; - this.expectedRst = OrigJpegConstants.Markers.RST0; + this.expectedRst = JpegConstants.Markers.RST0; for (int my = 0; my < decoder.MCUCountY; my++) { @@ -177,12 +176,12 @@ public void DecodeBlocks(OrigJpegDecoderCore decoder) } } - private void DecodeBlocksAtMcuIndex(OrigJpegDecoderCore decoder, int mx, int my) + private void DecodeBlocksAtMcuIndex(GolangJpegDecoderCore decoder, int mx, int my) { for (int scanIndex = 0; scanIndex < this.componentScanCount; scanIndex++) { this.ComponentIndex = this.pointers.ComponentScan[scanIndex].ComponentIndex; - OrigComponent component = decoder.Components[this.ComponentIndex]; + GolangComponent component = decoder.Components[this.ComponentIndex]; this.hi = component.HorizontalSamplingFactor; int vi = component.VerticalSamplingFactor; @@ -223,7 +222,7 @@ private void DecodeBlocksAtMcuIndex(OrigJpegDecoderCore decoder, int mx, int my) } } - private void ProcessRSTMarker(OrigJpegDecoderCore decoder) + private void ProcessRSTMarker(GolangJpegDecoderCore decoder) { // Attempt to look for RST[0-7] markers to resynchronize from corrupt input. if (!decoder.InputProcessor.ReachedEOF) @@ -262,15 +261,15 @@ private void ProcessRSTMarker(OrigJpegDecoderCore decoder) } this.expectedRst++; - if (this.expectedRst == OrigJpegConstants.Markers.RST7 + 1) + if (this.expectedRst == JpegConstants.Markers.RST7 + 1) { - this.expectedRst = OrigJpegConstants.Markers.RST0; + this.expectedRst = JpegConstants.Markers.RST0; } } } } - private void Reset(OrigJpegDecoderCore decoder) + private void Reset(GolangJpegDecoderCore decoder) { decoder.InputProcessor.ResetHuffmanDecoder(); @@ -285,15 +284,15 @@ private void Reset(OrigJpegDecoderCore decoder) /// private void ResetDcValues() { - Unsafe.InitBlock(this.pointers.Dc, default(byte), sizeof(int) * OrigJpegDecoderCore.MaxComponents); + Unsafe.InitBlock(this.pointers.Dc, default, sizeof(int) * GolangJpegDecoderCore.MaxComponents); } /// /// The implementation part of as an instance method. /// - /// The + /// The /// The remaining bytes - private void InitStreamReadingImpl(OrigJpegDecoderCore decoder, int remaining) + private void InitStreamReadingImpl(GolangJpegDecoderCore decoder, int remaining) { if (decoder.ComponentCount == 0) { @@ -360,10 +359,10 @@ private void InitStreamReadingImpl(OrigJpegDecoderCore decoder, int remaining) /// /// The decoder /// The index of the scan - private void DecodeBlock(OrigJpegDecoderCore decoder, int scanIndex) + private void DecodeBlock(GolangJpegDecoderCore decoder, int scanIndex) { Block8x8* b = this.pointers.Block; - int huffmannIdx = (OrigHuffmanTree.AcTableIndex * OrigHuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].AcTableSelector; + 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); @@ -377,7 +376,7 @@ private void DecodeBlock(OrigJpegDecoderCore decoder, int scanIndex) zig++; // Decode the DC coefficient, as specified in section F.2.2.1. - int huffmanIndex = (OrigHuffmanTree.DcTableIndex * OrigHuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].DcTableSelector; + int huffmanIndex = (GolangHuffmanTree.DcTableIndex * GolangHuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].DcTableSelector; decoder.InputProcessor.DecodeHuffmanUnsafe( ref decoder.HuffmanTrees[huffmanIndex], out int value); @@ -467,7 +466,7 @@ private void DecodeBlock(OrigJpegDecoderCore decoder, int scanIndex) private void DecodeEobRun(int count, ref InputProcessor processor) { processor.DecodeBitsUnsafe(count, out int bitsResult); - if (processor.LastErrorCode != OrigDecoderErrorCode.NoError) + if (processor.LastErrorCode != GolangDecoderErrorCode.NoError) { return; } @@ -475,7 +474,7 @@ private void DecodeEobRun(int count, ref InputProcessor processor) this.eobRun |= bitsResult; } - private void InitComponentScan(OrigJpegDecoderCore decoder, int i, ref OrigComponentScan currentComponentScan, ref int totalHv) + private void InitComponentScan(GolangJpegDecoderCore decoder, int i, ref GolangComponentScan currentComponentScan, ref int totalHv) { // Component selector. int cs = decoder.Temp[1 + (2 * i)]; @@ -500,11 +499,11 @@ private void InitComponentScan(OrigJpegDecoderCore decoder, int i, ref OrigCompo } private void ProcessComponentImpl( - OrigJpegDecoderCore decoder, + GolangJpegDecoderCore decoder, int i, - ref OrigComponentScan currentComponentScan, + ref GolangComponentScan currentComponentScan, ref int totalHv, - OrigComponent currentComponent) + 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 @@ -522,13 +521,13 @@ private void ProcessComponentImpl( totalHv += currentComponent.HorizontalSamplingFactor * currentComponent.VerticalSamplingFactor; currentComponentScan.DcTableSelector = (byte)(decoder.Temp[2 + (2 * i)] >> 4); - if (currentComponentScan.DcTableSelector > OrigHuffmanTree.MaxTh) + 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 > OrigHuffmanTree.MaxTh) + if (currentComponentScan.AcTableSelector > GolangHuffmanTree.MaxTh) { throw new ImageFormatException("Bad AC table selector value"); } @@ -540,7 +539,7 @@ private void ProcessComponentImpl( /// The instance /// The Huffman tree /// The low transform offset - private void Refine(ref InputProcessor bp, ref OrigHuffmanTree h, int delta) + private void Refine(ref InputProcessor bp, ref GolangHuffmanTree h, int delta) { Block8x8* b = this.pointers.Block; @@ -560,7 +559,7 @@ private void Refine(ref InputProcessor bp, ref OrigHuffmanTree h, int delta) if (bit) { - int stuff = (int)Block8x8.GetScalarAt(b, 0); + int stuff = Block8x8.GetScalarAt(b, 0); // int stuff = (int)b[0]; stuff |= delta; diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs index cb4b63cffd..c7e14ee4f2 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { /// - /// Encapsulates stream reading and processing data and operations for . + /// 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 @@ -27,14 +27,14 @@ internal struct InputProcessor : IDisposable /// Initializes a new instance of the struct. /// /// The input - /// Temporal buffer, same as + /// Temporal buffer, same as public InputProcessor(Stream inputStream, byte[] temp) { - this.Bits = default(Bits); + this.Bits = default; this.Bytes = Bytes.Create(); this.InputStream = inputStream; this.Temp = temp; - this.LastErrorCode = OrigDecoderErrorCode.NoError; + this.LastErrorCode = GolangDecoderErrorCode.NoError; } /// @@ -43,20 +43,20 @@ public InputProcessor(Stream inputStream, byte[] temp) public Stream InputStream { get; } /// - /// Gets the temporary buffer, same instance as + /// 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 == OrigDecoderErrorCode.UnexpectedEndOfStream; + public bool ReachedEOF => this.LastErrorCode == GolangDecoderErrorCode.UnexpectedEndOfStream; - public bool HasError => this.LastErrorCode != OrigDecoderErrorCode.NoError; + public bool HasError => this.LastErrorCode != GolangDecoderErrorCode.NoError; - public OrigDecoderErrorCode LastErrorCode { get; private set; } + public GolangDecoderErrorCode LastErrorCode { get; private set; } - public void ResetErrorState() => this.LastErrorCode = OrigDecoderErrorCode.NoError; + public void ResetErrorState() => this.LastErrorCode = GolangDecoderErrorCode.NoError; /// /// If errorCode indicates unexpected EOF, sets to true and returns false. @@ -65,7 +65,7 @@ public InputProcessor(Stream inputStream, byte[] temp) /// A indicating whether EOF reached public bool CheckEOFEnsureNoError() { - if (this.LastErrorCode == OrigDecoderErrorCode.UnexpectedEndOfStream) + if (this.LastErrorCode == GolangDecoderErrorCode.UnexpectedEndOfStream) { return false; } @@ -81,7 +81,7 @@ public bool CheckEOFEnsureNoError() /// A indicating whether EOF reached public bool CheckEOF() { - if (this.LastErrorCode == OrigDecoderErrorCode.UnexpectedEndOfStream) + if (this.LastErrorCode == GolangDecoderErrorCode.UnexpectedEndOfStream) { return false; } @@ -106,7 +106,7 @@ public byte ReadByte() } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public OrigDecoderErrorCode ReadByteUnsafe(out byte result) + public GolangDecoderErrorCode ReadByteUnsafe(out byte result) { this.LastErrorCode = this.Bytes.ReadByteUnsafe(this.InputStream, out result); return this.LastErrorCode; @@ -117,13 +117,13 @@ public OrigDecoderErrorCode ReadByteUnsafe(out byte result) /// TODO: This method (and also the usages) could be optimized by batching! /// /// The decoded bit as a - /// The - public OrigDecoderErrorCode DecodeBitUnsafe(out bool result) + /// The + public GolangDecoderErrorCode DecodeBitUnsafe(out bool result) { if (this.Bits.UnreadBits == 0) { this.LastErrorCode = this.Bits.Ensure1BitUnsafe(ref this); - if (this.LastErrorCode != OrigDecoderErrorCode.NoError) + if (this.LastErrorCode != GolangDecoderErrorCode.NoError) { result = false; return this.LastErrorCode; @@ -133,18 +133,18 @@ public OrigDecoderErrorCode DecodeBitUnsafe(out bool result) result = (this.Bits.Accumulator & this.Bits.Mask) != 0; this.Bits.UnreadBits--; this.Bits.Mask >>= 1; - return this.LastErrorCode = OrigDecoderErrorCode.NoError; + 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! + /// 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 OrigDecoderErrorCode ReadFullUnsafe(byte[] data, int offset, int length) + /// The + public GolangDecoderErrorCode ReadFullUnsafe(byte[] data, int offset, int length) { // Unread the overshot bytes, if any. if (this.Bytes.UnreadableBytes != 0) @@ -157,8 +157,8 @@ public OrigDecoderErrorCode ReadFullUnsafe(byte[] data, int offset, int length) this.Bytes.UnreadableBytes = 0; } - this.LastErrorCode = OrigDecoderErrorCode.NoError; - while (length > 0 && this.LastErrorCode == OrigDecoderErrorCode.NoError) + this.LastErrorCode = GolangDecoderErrorCode.NoError; + while (length > 0 && this.LastErrorCode == GolangDecoderErrorCode.NoError) { if (this.Bytes.J - this.Bytes.I >= length) { @@ -185,13 +185,13 @@ public OrigDecoderErrorCode ReadFullUnsafe(byte[] data, int offset, int length) /// /// The number of bits to decode. /// The result - /// The - public OrigDecoderErrorCode DecodeBitsUnsafe(int count, out int 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 != OrigDecoderErrorCode.NoError) + if (this.LastErrorCode != GolangDecoderErrorCode.NoError) { result = 0; return this.LastErrorCode; @@ -202,7 +202,7 @@ public OrigDecoderErrorCode DecodeBitsUnsafe(int count, out int result) result = result & ((1 << count) - 1); this.Bits.UnreadBits -= count; this.Bits.Mask >>= count; - return this.LastErrorCode = OrigDecoderErrorCode.NoError; + return this.LastErrorCode = GolangDecoderErrorCode.NoError; } /// @@ -210,8 +210,8 @@ public OrigDecoderErrorCode DecodeBitsUnsafe(int count, out int result) /// /// The huffman value /// The decoded - /// The - public OrigDecoderErrorCode DecodeHuffmanUnsafe(ref OrigHuffmanTree huffmanTree, out int result) + /// The + public GolangDecoderErrorCode DecodeHuffmanUnsafe(ref GolangHuffmanTree huffmanTree, out int result) { result = 0; @@ -224,9 +224,9 @@ public OrigDecoderErrorCode DecodeHuffmanUnsafe(ref OrigHuffmanTree huffmanTree, { this.LastErrorCode = this.Bits.Ensure8BitsUnsafe(ref this); - if (this.LastErrorCode == OrigDecoderErrorCode.NoError) + if (this.LastErrorCode == GolangDecoderErrorCode.NoError) { - int lutIndex = (this.Bits.Accumulator >> (this.Bits.UnreadBits - OrigHuffmanTree.LutSizeLog2)) & 0xFF; + int lutIndex = (this.Bits.Accumulator >> (this.Bits.UnreadBits - GolangHuffmanTree.LutSizeLog2)) & 0xFF; int v = huffmanTree.Lut[lutIndex]; if (v != 0) @@ -246,7 +246,7 @@ public OrigDecoderErrorCode DecodeHuffmanUnsafe(ref OrigHuffmanTree huffmanTree, } int code = 0; - for (int i = 0; i < OrigHuffmanTree.MaxCodeLength; i++) + for (int i = 0; i < GolangHuffmanTree.MaxCodeLength; i++) { if (this.Bits.UnreadBits == 0) { @@ -269,7 +269,7 @@ public OrigDecoderErrorCode DecodeHuffmanUnsafe(ref OrigHuffmanTree huffmanTree, if (code <= huffmanTree.MaxCodes[i]) { result = huffmanTree.GetValue(code, i); - return this.LastErrorCode = OrigDecoderErrorCode.NoError; + return this.LastErrorCode = GolangDecoderErrorCode.NoError; } code <<= 1; @@ -279,7 +279,7 @@ public OrigDecoderErrorCode DecodeHuffmanUnsafe(ref OrigHuffmanTree huffmanTree, DecoderThrowHelper.ThrowImageFormatException.BadHuffmanCode(); // DUMMY RETURN! C# doesn't know we have thrown an exception! - return OrigDecoderErrorCode.NoError; + return GolangDecoderErrorCode.NoError; } /// @@ -295,11 +295,11 @@ public void Skip(int count) /// /// Skips the next n bytes. - /// Does not throw, returns instead! + /// Does not throw, returns instead! /// /// The number of bytes to ignore. - /// The - public OrigDecoderErrorCode SkipUnsafe(int count) + /// The + public GolangDecoderErrorCode SkipUnsafe(int count) { // Unread the overshot bytes, if any. if (this.Bytes.UnreadableBytes != 0) @@ -328,13 +328,13 @@ public OrigDecoderErrorCode SkipUnsafe(int count) } this.LastErrorCode = this.Bytes.FillUnsafe(this.InputStream); - if (this.LastErrorCode != OrigDecoderErrorCode.NoError) + if (this.LastErrorCode != GolangDecoderErrorCode.NoError) { return this.LastErrorCode; } } - return this.LastErrorCode = OrigDecoderErrorCode.NoError; + return this.LastErrorCode = GolangDecoderErrorCode.NoError; } /// @@ -374,8 +374,8 @@ public void UnreadByteStuffedByte() /// /// Byte /// Read bits value - /// The - public OrigDecoderErrorCode ReceiveExtendUnsafe(int t, out int x) + /// The + public GolangDecoderErrorCode ReceiveExtendUnsafe(int t, out int x) { this.LastErrorCode = this.Bits.ReceiveExtendUnsafe(t, ref this, out x); return this.LastErrorCode; @@ -386,7 +386,7 @@ public OrigDecoderErrorCode ReceiveExtendUnsafe(int t, out int x) /// public void ResetHuffmanDecoder() { - this.Bits = default(Bits); + this.Bits = default; } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoder.cs similarity index 80% rename from src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoder.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoder.cs index bf2f64b349..29255204b4 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoder.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort /// /// Image decoder for generating an image out of a jpg stream. /// - internal sealed class OrigJpegDecoder : IImageDecoder, IJpegDecoderOptions, IImageInfoDetector + 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. @@ -22,7 +22,7 @@ public Image Decode(Configuration configuration, Stream stream) { Guard.NotNull(stream, nameof(stream)); - using (var decoder = new OrigJpegDecoderCore(configuration, this)) + using (var decoder = new GolangJpegDecoderCore(configuration, this)) { return decoder.Decode(stream); } @@ -33,7 +33,7 @@ public IImageInfo Identify(Configuration configuration, Stream stream) { Guard.NotNull(stream, nameof(stream)); - using (var decoder = new OrigJpegDecoderCore(configuration, this)) + using (var decoder = new GolangJpegDecoderCore(configuration, this)) { return decoder.Identify(stream); } diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs similarity index 91% rename from src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs rename to src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs index 875f16ec2e..fbcd265ac3 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.IO; -using SixLabors.ImageSharp.Formats.Jpeg.Common; -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; + +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; @@ -19,7 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort /// /// Performs the jpeg decoding operation. /// - internal sealed unsafe class OrigJpegDecoderCore : IRawJpegData + internal sealed unsafe class GolangJpegDecoderCore : IRawJpegData { /// /// The maximum number of color components @@ -40,7 +41,7 @@ internal sealed unsafe class OrigJpegDecoderCore : IRawJpegData #pragma warning disable SA1401 // FieldsMustBePrivate /// - /// Encapsulates stream reading and processing data and operations for . + /// 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; @@ -79,11 +80,11 @@ internal sealed unsafe class OrigJpegDecoderCore : IRawJpegData private AdobeMarker adobe; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The configuration. /// The options. - public OrigJpegDecoderCore(Configuration configuration, IJpegDecoderOptions options) + public GolangJpegDecoderCore(Configuration configuration, IJpegDecoderOptions options) { this.IgnoreMetadata = options.IgnoreMetadata; this.configuration = configuration ?? Configuration.Default; @@ -96,12 +97,12 @@ public OrigJpegDecoderCore(Configuration configuration, IJpegDecoderOptions opti /// /// Gets the component array /// - public OrigComponent[] Components { get; private set; } + public GolangComponent[] Components { get; private set; } /// /// Gets the huffman trees /// - public OrigHuffmanTree[] HuffmanTrees { get; private set; } + public GolangHuffmanTree[] HuffmanTrees { get; private set; } /// public Block8x8F[] QuantizationTables { get; private set; } @@ -209,7 +210,7 @@ public void Dispose() { if (this.Components != null) { - foreach (OrigComponent component in this.Components) + foreach (GolangComponent component in this.Components) { component?.Dispose(); } @@ -219,7 +220,7 @@ public void Dispose() } /// - /// Read metadata from stream and read the blocks in the scans into . + /// Read metadata from stream and read the blocks in the scans into . /// /// The stream /// Whether to decode metadata only. @@ -231,14 +232,14 @@ public void ParseStream(Stream stream, bool metadataOnly = false) if (!metadataOnly) { - this.HuffmanTrees = OrigHuffmanTree.CreateHuffmanTrees(); + 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] != OrigJpegConstants.Markers.XFF || this.Temp[1] != OrigJpegConstants.Markers.SOI) + if (this.Temp[0] != JpegConstants.Markers.XFF || this.Temp[1] != JpegConstants.Markers.SOI) { throw new ImageFormatException("Missing SOI marker."); } @@ -302,12 +303,12 @@ public void ParseStream(Stream stream, bool metadataOnly = false) } // End Of Image. - if (marker == OrigJpegConstants.Markers.EOI) + if (marker == JpegConstants.Markers.EOI) { break; } - if (marker >= OrigJpegConstants.Markers.RST0 && marker <= OrigJpegConstants.Markers.RST7) + 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. @@ -329,14 +330,14 @@ public void ParseStream(Stream stream, bool metadataOnly = false) switch (marker) { - case OrigJpegConstants.Markers.SOF0: - case OrigJpegConstants.Markers.SOF1: - case OrigJpegConstants.Markers.SOF2: - this.IsProgressive = marker == OrigJpegConstants.Markers.SOF2; + case JpegConstants.Markers.SOF0: + case JpegConstants.Markers.SOF1: + case JpegConstants.Markers.SOF2: + this.IsProgressive = marker == JpegConstants.Markers.SOF2; this.ProcessStartOfFrameMarker(remaining, metadataOnly); break; - case OrigJpegConstants.Markers.DHT: + case JpegConstants.Markers.DHT: if (metadataOnly) { this.InputProcessor.Skip(remaining); @@ -347,7 +348,7 @@ public void ParseStream(Stream stream, bool metadataOnly = false) } break; - case OrigJpegConstants.Markers.DQT: + case JpegConstants.Markers.DQT: if (metadataOnly) { this.InputProcessor.Skip(remaining); @@ -358,7 +359,7 @@ public void ParseStream(Stream stream, bool metadataOnly = false) } break; - case OrigJpegConstants.Markers.SOS: + case JpegConstants.Markers.SOS: if (!metadataOnly) { this.ProcessStartOfScanMarker(remaining); @@ -377,7 +378,7 @@ public void ParseStream(Stream stream, bool metadataOnly = false) break; - case OrigJpegConstants.Markers.DRI: + case JpegConstants.Markers.DRI: if (metadataOnly) { this.InputProcessor.Skip(remaining); @@ -388,21 +389,21 @@ public void ParseStream(Stream stream, bool metadataOnly = false) } break; - case OrigJpegConstants.Markers.APP0: + case JpegConstants.Markers.APP0: this.ProcessApplicationHeaderMarker(remaining); break; - case OrigJpegConstants.Markers.APP1: + case JpegConstants.Markers.APP1: this.ProcessApp1Marker(remaining); break; - case OrigJpegConstants.Markers.APP2: + case JpegConstants.Markers.APP2: this.ProcessApp2Marker(remaining); break; - case OrigJpegConstants.Markers.APP14: + case JpegConstants.Markers.APP14: this.ProcessApp14Marker(remaining); break; default: - if ((marker >= OrigJpegConstants.Markers.APP0 && marker <= OrigJpegConstants.Markers.APP15) - || marker == OrigJpegConstants.Markers.COM) + if ((marker >= JpegConstants.Markers.APP0 && marker <= JpegConstants.Markers.APP15) + || marker == JpegConstants.Markers.COM) { this.InputProcessor.Skip(remaining); } @@ -680,12 +681,12 @@ private void ProcessStartOfFrameMarker(int remaining, bool metadataOnly) if (!metadataOnly) { - this.Components = new OrigComponent[this.ComponentCount]; + this.Components = new GolangComponent[this.ComponentCount]; for (int i = 0; i < this.ComponentCount; i++) { byte componentIdentifier = this.Temp[6 + (3 * i)]; - var component = new OrigComponent(componentIdentifier, i); + var component = new GolangComponent(componentIdentifier, i); component.InitializeCoreData(this); this.Components[i] = component; } @@ -697,7 +698,7 @@ private void ProcessStartOfFrameMarker(int remaining, bool metadataOnly) this.ColorSpace = this.DeduceJpegColorSpace(); - foreach (OrigComponent component in this.Components) + foreach (GolangComponent component in this.Components) { component.InitializeDerivedData(this.configuration.MemoryManager, this); } @@ -721,18 +722,18 @@ private void ProcessDefineHuffmanTablesMarker(int remaining) this.InputProcessor.ReadFull(this.Temp, 0, 17); int tc = this.Temp[0] >> 4; - if (tc > OrigHuffmanTree.MaxTc) + if (tc > GolangHuffmanTree.MaxTc) { throw new ImageFormatException("Bad Tc value"); } int th = this.Temp[0] & 0x0f; - if (th > OrigHuffmanTree.MaxTh) + if (th > GolangHuffmanTree.MaxTh) { throw new ImageFormatException("Bad Th value"); } - int huffTreeIndex = (tc * OrigHuffmanTree.ThRowSize) + th; + int huffTreeIndex = (tc * GolangHuffmanTree.ThRowSize) + th; this.HuffmanTrees[huffTreeIndex].ProcessDefineHuffmanTablesMarkerLoop( ref this.InputProcessor, this.Temp, @@ -766,9 +767,9 @@ private void ProcessDefineRestartIntervalMarker(int remaining) /// private void ProcessStartOfScanMarker(int remaining) { - var scan = default(OrigJpegScanDecoder); - OrigJpegScanDecoder.InitStreamReading(&scan, this, remaining); - this.InputProcessor.Bits = default(Bits); + var scan = default(GolangJpegScanDecoder); + GolangJpegScanDecoder.InitStreamReading(&scan, this, remaining); + this.InputProcessor.Bits = default; scan.DecodeBlocks(this); } @@ -779,19 +780,19 @@ private JpegColorSpace DeduceJpegColorSpace() case 1: return JpegColorSpace.Grayscale; case 3: - if (!this.isAdobe || this.adobe.ColorTransform == OrigJpegConstants.Adobe.ColorTransformYCbCr) + if (!this.isAdobe || this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformYCbCr) { return JpegColorSpace.YCbCr; } - if (this.adobe.ColorTransform == OrigJpegConstants.Adobe.ColorTransformUnknown) + if (this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformUnknown) { return JpegColorSpace.RGB; } break; case 4: - if (this.adobe.ColorTransform == OrigJpegConstants.Adobe.ColorTransformYcck) + if (this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformYcck) { return JpegColorSpace.Ycck; } diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegConstants.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegConstants.cs deleted file mode 100644 index be383d2120..0000000000 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegConstants.cs +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System.Collections.Generic; - -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort -{ - /// - /// Defines jpeg constants defined in the specification. - /// - internal static class OrigJpegConstants - { - /// - /// The maximum allowable length in each dimension of a jpeg image. - /// - public const ushort MaxLength = 65535; - - /// - /// The list of mimetypes that equate to a jpeg. - /// - public static readonly IEnumerable MimeTypes = new[] { "image/jpeg", "image/pjpeg" }; - - /// - /// The list of file extensions that equate to a jpeg. - /// - public static readonly IEnumerable FileExtensions = new[] { "jpg", "jpeg", "jfif" }; - - /// - /// Describes common Jpeg markers - /// - internal static class Markers - { - /// - /// Marker prefix. Next byte is a marker. - /// - public const byte XFF = 0xff; - - /// - /// Same as but of type - /// - public const int XFFInt = XFF; - - /// - /// Start of Image - /// - public const byte SOI = 0xd8; - - /// - /// Start of Frame (baseline DCT) - /// - /// Indicates that this is a baseline DCT-based JPEG, and specifies the width, height, number of components, - /// and component subsampling (e.g., 4:2:0). - /// - /// - public const byte SOF0 = 0xc0; - - /// - /// Start Of Frame (Extended Sequential DCT) - /// - /// Indicates that this is a progressive DCT-based JPEG, and specifies the width, height, number of components, - /// and component subsampling (e.g., 4:2:0). - /// - /// - public const byte SOF1 = 0xc1; - - /// - /// Start Of Frame (progressive DCT) - /// - /// Indicates that this is a progressive DCT-based JPEG, and specifies the width, height, number of components, - /// and component subsampling (e.g., 4:2:0). - /// - /// - public const byte SOF2 = 0xc2; - - /// - /// Define Huffman Table(s) - /// - /// Specifies one or more Huffman tables. - /// - /// - public const byte DHT = 0xc4; - - /// - /// Define Quantization Table(s) - /// - /// Specifies one or more quantization tables. - /// - /// - public const byte DQT = 0xdb; - - /// - /// Define Restart Interval - /// - /// Specifies the interval between RSTn markers, in macroblocks. This marker is followed by two bytes - /// indicating the fixed size so it can be treated like any other variable size segment. - /// - /// - public const byte DRI = 0xdd; - - /// - /// Define First Restart - /// - /// Inserted every r macroblocks, where r is the restart interval set by a DRI marker. - /// Not used if there was no DRI marker. The low three bits of the marker code cycle in value from 0 to 7. - /// - /// - public const byte RST0 = 0xd0; - - /// - /// Define Eigth Restart - /// - /// Inserted every r macroblocks, where r is the restart interval set by a DRI marker. - /// Not used if there was no DRI marker. The low three bits of the marker code cycle in value from 0 to 7. - /// - /// - public const byte RST7 = 0xd7; - - /// - /// Start of Scan - /// - /// Begins a top-to-bottom scan of the image. In baseline DCT JPEG images, there is generally a single scan. - /// Progressive DCT JPEG images usually contain multiple scans. This marker specifies which slice of data it - /// will contain, and is immediately followed by entropy-coded data. - /// - /// - public const byte SOS = 0xda; - - /// - /// Comment - /// - /// Contains a text comment. - /// - /// - public const byte COM = 0xfe; - - /// - /// End of Image - /// - public const byte EOI = 0xd9; - - /// - /// Application specific marker for marking the jpeg format. - /// - /// - public const byte APP0 = 0xe0; - - /// - /// Application specific marker for marking where to store metadata. - /// - public const byte APP1 = 0xe1; - - /// - /// Application specific marker for marking where to store ICC profile information. - /// - public const byte APP2 = 0xe2; - - /// - /// Application specific marker used by Adobe for storing encoding information for DCT filters. - /// - public const byte APP14 = 0xee; - - /// - /// Application specific marker used by GraphicConverter to store JPEG quality. - /// - public const byte APP15 = 0xef; - } - - /// - /// Describes Adobe specific markers - /// - internal static class Adobe - { - /// - /// The color transform is unknown.(RGB or CMYK) - /// - public const int ColorTransformUnknown = 0; - - /// - /// The color transform is YCbCr (luminance, red chroma, blue chroma) - /// - public const int ColorTransformYCbCr = 1; - - /// - /// The color transform is YCCK (luminance, red chroma, blue chroma, keyline) - /// - public const int ColorTransformYcck = 2; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegConstants.cs b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs similarity index 78% rename from src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegConstants.cs rename to src/ImageSharp/Formats/Jpeg/JpegConstants.cs index 437f772860..49e3b41704 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegConstants.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs @@ -1,23 +1,45 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -// ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort +using System.Collections.Generic; + +namespace SixLabors.ImageSharp.Formats.Jpeg { /// - /// Contains jpeg constant values + /// Contains jpeg constant values defined in the specification. /// - internal static class PdfJsJpegConstants + internal static class JpegConstants { + /// + /// The maximum allowable length in each dimension of a jpeg image. + /// + public const ushort MaxLength = 65535; + + /// + /// The list of mimetypes that equate to a jpeg. + /// + public static readonly IEnumerable MimeTypes = new[] { "image/jpeg", "image/pjpeg" }; + + /// + /// The list of file extensions that equate to a jpeg. + /// + public static readonly IEnumerable FileExtensions = new[] { "jpg", "jpeg", "jfif" }; + /// /// Contains marker specific constants /// - public static class Markers + // ReSharper disable InconsistentNaming + internal static class Markers { /// /// The prefix used for all markers. /// - public const byte Prefix = 0xFF; + public const byte XFF = 0xFF; + + /// + /// Same as but of type + /// + public const int XFFInt = XFF; /// /// The Start of Image marker @@ -161,7 +183,8 @@ public static class Markers /// /// Define Restart Interval /// - /// Specifies the interval between RSTn markers, in macroblocks.This marker is followed by two bytes indicating the fixed size so it can be treated like any other variable size segment. + /// Specifies the interval between RSTn markers, in macroblocks.This marker is followed by two bytes indicating the fixed size so + /// it can be treated like any other variable size segment. /// /// public const byte DRI = 0xDD; @@ -193,27 +216,27 @@ public static class Markers /// /// public const byte RST7 = 0xD7; + } + /// + /// Contains Adobe specific constants + /// + internal static class Adobe + { /// - /// Contains Adobe specific markers + /// The color transform is unknown.(RGB or CMYK) /// - public static class Adobe - { - /// - /// The color transform is unknown.(RGB or CMYK) - /// - public const byte ColorTransformUnknown = 0; + public const byte ColorTransformUnknown = 0; - /// - /// The color transform is YCbCr (luminance, red chroma, blue chroma) - /// - public const byte ColorTransformYCbCr = 1; + /// + /// The color transform is YCbCr (luminance, red chroma, blue chroma) + /// + public const byte ColorTransformYCbCr = 1; - /// - /// The color transform is YCCK (luminance, red chroma, blue chroma, keyline) - /// - public const byte ColorTransformYcck = 2; - } + /// + /// The color transform is YCCK (luminance, red chroma, blue chroma, keyline) + /// + public const byte ColorTransformYcck = 2; } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs index 91835b5d71..e738982cba 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs @@ -3,7 +3,7 @@ using System.IO; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; +using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Jpeg @@ -24,7 +24,7 @@ public Image Decode(Configuration configuration, Stream stream) { Guard.NotNull(stream, nameof(stream)); - using (var decoder = new OrigJpegDecoderCore(configuration, this)) + using (var decoder = new PdfJsJpegDecoderCore(configuration, this)) { return decoder.Decode(stream); } @@ -35,7 +35,7 @@ public IImageInfo Identify(Configuration configuration, Stream stream) { Guard.NotNull(stream, "stream"); - using (var decoder = new OrigJpegDecoderCore(configuration, this)) + using (var decoder = new PdfJsJpegDecoderCore(configuration, this)) { return decoder.Identify(stream); } diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs index 60b00c0f5b..0f389dee0f 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System.IO; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Jpeg diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs similarity index 93% rename from src/ImageSharp/Formats/Jpeg/GolangPort/JpegEncoderCore.cs rename to src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index 4fbb20ee82..37279d5263 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -1,19 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Buffers; using System.IO; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Formats.Jpeg.Common; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder; -using SixLabors.ImageSharp.Memory; + +using SixLabors.ImageSharp.Formats.Jpeg.Components; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.MetaData.Profiles.Icc; using SixLabors.ImageSharp.PixelFormats; -using Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort +namespace SixLabors.ImageSharp.Formats.Jpeg { /// /// Image encoder for writing an image to a stream as a jpeg. @@ -58,7 +55,7 @@ internal sealed unsafe class JpegEncoderCore /// private static readonly byte[] SosHeaderYCbCr = { - OrigJpegConstants.Markers.XFF, OrigJpegConstants.Markers.SOS, + JpegConstants.Markers.XFF, JpegConstants.Markers.SOS, // Marker 0x00, 0x0c, @@ -104,11 +101,6 @@ internal sealed unsafe class JpegEncoderCore } }; - /// - /// Lookup tables for converting Rgb to YCbCr - /// - private static RgbToYCbCrTables rgbToYCbCrTables = RgbToYCbCrTables.Create(); - /// /// A scratch buffer to reduce allocations. /// @@ -190,7 +182,7 @@ public void Encode(Image image, Stream stream) Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); - ushort max = OrigJpegConstants.MaxLength; + ushort max = JpegConstants.MaxLength; if (image.Width >= max || image.Height >= max) { throw new ImageFormatException($"Image is too large to encode at {image.Width}x{image.Height}."); @@ -234,8 +226,8 @@ public void Encode(Image image, Stream stream) this.WriteStartOfScan(image); // Write the End Of Image marker. - this.buffer[0] = OrigJpegConstants.Markers.XFF; - this.buffer[1] = OrigJpegConstants.Markers.EOI; + this.buffer[0] = JpegConstants.Markers.XFF; + this.buffer[1] = JpegConstants.Markers.EOI; stream.Write(this.buffer, 0, 2); stream.Flush(); } @@ -382,18 +374,18 @@ private void Encode444(Image pixels) { // TODO: Need a JpegScanEncoder class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) // (Partially done with YCbCrForwardConverter) - Block8x8F temp1 = default(Block8x8F); - Block8x8F temp2 = default(Block8x8F); + Block8x8F temp1 = default; + Block8x8F temp2 = default; Block8x8F onStackLuminanceQuantTable = this.luminanceQuantTable; Block8x8F onStackChrominanceQuantTable = this.chrominanceQuantTable; - ZigZag unzig = ZigZag.CreateUnzigTable(); + var unzig = ZigZag.CreateUnzigTable(); // ReSharper disable once InconsistentNaming int prevDCY = 0, prevDCCb = 0, prevDCCr = 0; - YCbCrForwardConverter pixelConverter = YCbCrForwardConverter.Create(); + var pixelConverter = YCbCrForwardConverter.Create(); for (int y = 0; y < pixels.Height; y += 8) { @@ -437,12 +429,12 @@ private void Encode444(Image pixels) private void WriteApplicationHeader(short horizontalResolution, short verticalResolution) { // Write the start of image marker. Markers are always prefixed with with 0xff. - this.buffer[0] = OrigJpegConstants.Markers.XFF; - this.buffer[1] = OrigJpegConstants.Markers.SOI; + this.buffer[0] = JpegConstants.Markers.XFF; + this.buffer[1] = JpegConstants.Markers.SOI; // Write the JFIF headers - this.buffer[2] = OrigJpegConstants.Markers.XFF; - this.buffer[3] = OrigJpegConstants.Markers.APP0; // Application Marker + this.buffer[2] = JpegConstants.Markers.XFF; + this.buffer[3] = JpegConstants.Markers.APP0; // Application Marker this.buffer[4] = 0x00; this.buffer[5] = 0x10; this.buffer[6] = 0x4a; // J @@ -502,7 +494,7 @@ private int WriteBlock( this.EmitHuffRLE((HuffIndex)((2 * (int)index) + 0), 0, dc - prevDC); // Emit the AC components. - HuffIndex h = (HuffIndex)((2 * (int)index) + 1); + var h = (HuffIndex)((2 * (int)index) + 1); int runLength = 0; for (int zig = 1; zig < Block8x8F.Size; zig++) @@ -556,7 +548,7 @@ private void WriteDefineHuffmanTables(int componentCount) markerlen += 1 + 16 + s.Values.Length; } - this.WriteMarkerHeader(OrigJpegConstants.Markers.DHT, markerlen); + this.WriteMarkerHeader(JpegConstants.Markers.DHT, markerlen); for (int i = 0; i < specs.Length; i++) { HuffmanSpec spec = specs[i]; @@ -590,7 +582,7 @@ private void WriteDefineQuantizationTables() { // Marker + quantization table lengths int markerlen = 2 + (QuantizationTableCount * (1 + Block8x8F.Size)); - this.WriteMarkerHeader(OrigJpegConstants.Markers.DQT, markerlen); + this.WriteMarkerHeader(JpegConstants.Markers.DQT, markerlen); // Loop through and collect the tables as one array. // This allows us to reduce the number of writes to the stream. @@ -627,8 +619,8 @@ private void WriteExifProfile(ExifProfile exifProfile) int length = data.Length + 2; - this.buffer[0] = OrigJpegConstants.Markers.XFF; - this.buffer[1] = OrigJpegConstants.Markers.APP1; // Application Marker + this.buffer[0] = JpegConstants.Markers.XFF; + this.buffer[1] = JpegConstants.Markers.APP1; // Application Marker this.buffer[2] = (byte)((length >> 8) & 0xFF); this.buffer[3] = (byte)(length & 0xFF); @@ -686,8 +678,8 @@ private void WriteIccProfile(IccProfile iccProfile) dataLength -= length; - this.buffer[0] = OrigJpegConstants.Markers.XFF; - this.buffer[1] = OrigJpegConstants.Markers.APP2; // Application Marker + this.buffer[0] = JpegConstants.Markers.XFF; + this.buffer[1] = JpegConstants.Markers.APP2; // Application Marker int markerLength = length + 16; this.buffer[2] = (byte)((markerLength >> 8) & 0xFF); this.buffer[3] = (byte)(markerLength & 0xFF); @@ -759,7 +751,7 @@ private void WriteStartOfFrame(int width, int height, int componentCount) // Length (high byte, low byte), 8 + components * 3. int markerlen = 8 + (3 * componentCount); - this.WriteMarkerHeader(OrigJpegConstants.Markers.SOF0, markerlen); + this.WriteMarkerHeader(JpegConstants.Markers.SOF0, markerlen); this.buffer[0] = 8; // Data Precision. 8 for now, 12 and 16 bit jpegs not supported this.buffer[1] = (byte)(height >> 8); this.buffer[2] = (byte)(height & 0xff); // (2 bytes, Hi-Lo), must be > 0 if DNL not supported @@ -827,20 +819,20 @@ private void Encode420(Image pixels) where TPixel : struct, IPixel { // TODO: Need a JpegScanEncoder class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) - Block8x8F b = default(Block8x8F); + Block8x8F b = default; - BlockQuad cb = default(BlockQuad); - BlockQuad cr = default(BlockQuad); - Block8x8F* cbPtr = (Block8x8F*)cb.Data; - Block8x8F* crPtr = (Block8x8F*)cr.Data; + BlockQuad cb = default; + BlockQuad cr = default; + var cbPtr = (Block8x8F*)cb.Data; + var crPtr = (Block8x8F*)cr.Data; - Block8x8F temp1 = default(Block8x8F); - Block8x8F temp2 = default(Block8x8F); + Block8x8F temp1 = default; + Block8x8F temp2 = default; Block8x8F onStackLuminanceQuantTable = this.luminanceQuantTable; Block8x8F onStackChrominanceQuantTable = this.chrominanceQuantTable; - ZigZag unzig = ZigZag.CreateUnzigTable(); + var unzig = ZigZag.CreateUnzigTable(); var pixelConverter = YCbCrForwardConverter.Create(); @@ -902,7 +894,7 @@ private void Encode420(Image pixels) private void WriteMarkerHeader(byte marker, int length) { // Markers are always prefixed with with 0xff. - this.buffer[0] = OrigJpegConstants.Markers.XFF; + this.buffer[0] = JpegConstants.Markers.XFF; this.buffer[1] = marker; this.buffer[2] = (byte)(length >> 8); this.buffer[3] = (byte)(length & 0xff); diff --git a/src/ImageSharp/Formats/Jpeg/JpegFormat.cs b/src/ImageSharp/Formats/Jpeg/JpegFormat.cs index 4f368dcdee..9a18f14d30 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegFormat.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegFormat.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; namespace SixLabors.ImageSharp.Formats.Jpeg { @@ -18,9 +17,9 @@ internal sealed class JpegFormat : IImageFormat public string DefaultMimeType => "image/jpeg"; /// - public IEnumerable MimeTypes => OrigJpegConstants.MimeTypes; + public IEnumerable MimeTypes => JpegConstants.MimeTypes; /// - public IEnumerable FileExtensions => OrigJpegConstants.FileExtensions; + public IEnumerable FileExtensions => JpegConstants.FileExtensions; } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs index 7f50a8529c..ccbb5c6c01 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs @@ -4,8 +4,9 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats.Jpeg.Common; -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; + +using SixLabors.ImageSharp.Formats.Jpeg.Components; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; @@ -36,9 +37,9 @@ public PdfJsFrameComponent(MemoryManager memoryManager, PdfJsFrame frame, byte i public byte Id { get; } /// - /// Gets or sets Pred TODO: What does pred stand for? + /// Gets or sets DC coefficient predictor /// - public int Pred { get; set; } + public int DcPredictor { get; set; } /// /// Gets the horizontal sampling factor. diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs index c6b14d6fb0..49bc105391 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs @@ -7,7 +7,8 @@ #endif using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats.Jpeg.Common; + +using SixLabors.ImageSharp.Formats.Jpeg.Components; namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components { @@ -107,7 +108,7 @@ public void DecodeScan( for (int i = 0; i < components.Length; i++) { PdfJsFrameComponent c = components[i]; - c.Pred = 0; + c.DcPredictor = 0; } this.eobrun = 0; @@ -136,7 +137,7 @@ public void DecodeScan( byte marker = fileMarker.Marker; // RSTn - We've already read the bytes and altered the position so no need to skip - if (marker >= PdfJsJpegConstants.Markers.RST0 && marker <= PdfJsJpegConstants.Markers.RST7) + if (marker >= JpegConstants.Markers.RST0 && marker <= JpegConstants.Markers.RST7) { continue; } @@ -452,7 +453,7 @@ private bool TryFillBits(DoubleBufferedStreamReader stream) this.endOfStreamReached = true; return false; - case PdfJsJpegConstants.Markers.Prefix: + case JpegConstants.Markers.XFF: int nextByte = stream.ReadByte(); if (nextByte == -0x1) @@ -618,7 +619,7 @@ private void DecodeBaseline(PdfJsFrameComponent component, ref short blockDataRe } } - Unsafe.Add(ref blockDataRef, offset) = (short)(component.Pred += diff); + Unsafe.Add(ref blockDataRef, offset) = (short)(component.DcPredictor += diff); int k = 1; while (k < 64) @@ -673,7 +674,7 @@ private void DecodeDCFirst(PdfJsFrameComponent component, ref short blockDataRef } } - Unsafe.Add(ref blockDataRef, offset) = (short)(component.Pred += diff << this.successiveState); + Unsafe.Add(ref blockDataRef, offset) = (short)(component.DcPredictor += diff << this.successiveState); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index df803a9202..3dda253d2b 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -7,8 +7,9 @@ using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Formats.Jpeg.Common; -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; + +using SixLabors.ImageSharp.Formats.Jpeg.Components; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; @@ -93,15 +94,23 @@ public PdfJsJpegDecoderCore(Configuration configuration, IJpegDecoderOptions opt /// public PdfJsFrame Frame { get; private set; } + /// + public Size ImageSizeInPixels { get; private set; } + + /// + /// Gets the number of MCU blocks in the image as . + /// + public Size ImageSizeInMCU { get; private set; } + /// /// Gets the image width /// - public int ImageWidth { get; private set; } + public int ImageWidth => this.ImageSizeInPixels.Width; /// /// Gets the image height /// - public int ImageHeight { get; private set; } + public int ImageHeight => this.ImageSizeInPixels.Height; /// /// Gets the color depth, in number of bits per pixel. @@ -123,17 +132,19 @@ public PdfJsJpegDecoderCore(Configuration configuration, IJpegDecoderOptions opt /// public ImageMetaData MetaData { get; private set; } - /// - public Size ImageSizeInPixels => new Size(this.ImageWidth, this.ImageHeight); - /// public int ComponentCount { get; private set; } /// public JpegColorSpace ColorSpace { get; private set; } + /// + /// Gets the components. + /// + public PdfJsFrameComponent[] Components => this.Frame.Components; + /// - public IEnumerable Components => this.Frame.Components; + IEnumerable IRawJpegData.Components => this.Components; /// public Block8x8F[] QuantizationTables { get; private set; } @@ -150,20 +161,20 @@ public static PdfJsFileMarker FindNextFileMarker(byte[] marker, DoubleBufferedSt if (value == 0) { - return new PdfJsFileMarker(PdfJsJpegConstants.Markers.EOI, stream.Length - 2); + return new PdfJsFileMarker(JpegConstants.Markers.EOI, stream.Length - 2); } - if (marker[0] == PdfJsJpegConstants.Markers.Prefix) + if (marker[0] == JpegConstants.Markers.XFF) { // According to Section B.1.1.2: // "Any marker may optionally be preceded by any number of fill bytes, which are bytes assigned code 0xFF." int m = marker[1]; - while (m == PdfJsJpegConstants.Markers.Prefix) + while (m == JpegConstants.Markers.XFF) { int suffix = stream.ReadByte(); if (suffix == -1) { - return new PdfJsFileMarker(PdfJsJpegConstants.Markers.EOI, stream.Length - 2); + return new PdfJsFileMarker(JpegConstants.Markers.EOI, stream.Length - 2); } m = suffix; @@ -213,7 +224,7 @@ public void ParseStream(Stream stream, bool metadataOnly = false) // Check for the Start Of Image marker. this.InputStream.Read(this.markerBuffer, 0, 2); var fileMarker = new PdfJsFileMarker(this.markerBuffer[1], 0); - if (fileMarker.Marker != PdfJsJpegConstants.Markers.SOI) + if (fileMarker.Marker != JpegConstants.Markers.SOI) { throw new ImageFormatException("Missing SOI marker."); } @@ -230,7 +241,7 @@ public void ParseStream(Stream stream, bool metadataOnly = false) this.acHuffmanTables = new PdfJsHuffmanTables(); } - while (fileMarker.Marker != PdfJsJpegConstants.Markers.EOI) + while (fileMarker.Marker != JpegConstants.Markers.EOI) { if (!fileMarker.Invalid) { @@ -239,13 +250,13 @@ public void ParseStream(Stream stream, bool metadataOnly = false) switch (fileMarker.Marker) { - case PdfJsJpegConstants.Markers.SOF0: - case PdfJsJpegConstants.Markers.SOF1: - case PdfJsJpegConstants.Markers.SOF2: + case JpegConstants.Markers.SOF0: + case JpegConstants.Markers.SOF1: + case JpegConstants.Markers.SOF2: this.ProcessStartOfFrameMarker(remaining, fileMarker, metadataOnly); break; - case PdfJsJpegConstants.Markers.SOS: + case JpegConstants.Markers.SOS: if (!metadataOnly) { this.ProcessStartOfScanMarker(); @@ -258,7 +269,7 @@ public void ParseStream(Stream stream, bool metadataOnly = false) return; } - case PdfJsJpegConstants.Markers.DHT: + case JpegConstants.Markers.DHT: if (metadataOnly) { this.InputStream.Skip(remaining); @@ -270,7 +281,7 @@ public void ParseStream(Stream stream, bool metadataOnly = false) break; - case PdfJsJpegConstants.Markers.DQT: + case JpegConstants.Markers.DQT: if (metadataOnly) { this.InputStream.Skip(remaining); @@ -282,7 +293,7 @@ public void ParseStream(Stream stream, bool metadataOnly = false) break; - case PdfJsJpegConstants.Markers.DRI: + case JpegConstants.Markers.DRI: if (metadataOnly) { this.InputStream.Skip(remaining); @@ -294,38 +305,38 @@ public void ParseStream(Stream stream, bool metadataOnly = false) break; - case PdfJsJpegConstants.Markers.APP0: + case JpegConstants.Markers.APP0: this.ProcessApplicationHeaderMarker(remaining); break; - case PdfJsJpegConstants.Markers.APP1: + case JpegConstants.Markers.APP1: this.ProcessApp1Marker(remaining); break; - case PdfJsJpegConstants.Markers.APP2: + case JpegConstants.Markers.APP2: this.ProcessApp2Marker(remaining); break; - case PdfJsJpegConstants.Markers.APP3: - case PdfJsJpegConstants.Markers.APP4: - case PdfJsJpegConstants.Markers.APP5: - case PdfJsJpegConstants.Markers.APP6: - case PdfJsJpegConstants.Markers.APP7: - case PdfJsJpegConstants.Markers.APP8: - case PdfJsJpegConstants.Markers.APP9: - case PdfJsJpegConstants.Markers.APP10: - case PdfJsJpegConstants.Markers.APP11: - case PdfJsJpegConstants.Markers.APP12: - case PdfJsJpegConstants.Markers.APP13: + case JpegConstants.Markers.APP3: + case JpegConstants.Markers.APP4: + case JpegConstants.Markers.APP5: + case JpegConstants.Markers.APP6: + case JpegConstants.Markers.APP7: + case JpegConstants.Markers.APP8: + case JpegConstants.Markers.APP9: + case JpegConstants.Markers.APP10: + case JpegConstants.Markers.APP11: + case JpegConstants.Markers.APP12: + case JpegConstants.Markers.APP13: this.InputStream.Skip(remaining); break; - case PdfJsJpegConstants.Markers.APP14: + case JpegConstants.Markers.APP14: this.ProcessApp14Marker(remaining); break; - case PdfJsJpegConstants.Markers.APP15: - case PdfJsJpegConstants.Markers.COM: + case JpegConstants.Markers.APP15: + case JpegConstants.Markers.COM: this.InputStream.Skip(remaining); break; } @@ -362,11 +373,12 @@ private JpegColorSpace DeduceJpegColorSpace() if (this.ComponentCount == 3) { - if (this.adobe.Equals(default) || this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYCbCr) + if (this.adobe.Equals(default) || this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformYCbCr) { return JpegColorSpace.YCbCr; } - else if (this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformUnknown) + + if (this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformUnknown) { return JpegColorSpace.RGB; } @@ -374,7 +386,7 @@ private JpegColorSpace DeduceJpegColorSpace() if (this.ComponentCount == 4) { - return this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYcck + return this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformYcck ? JpegColorSpace.Ycck : JpegColorSpace.Cmyk; } @@ -387,9 +399,6 @@ private JpegColorSpace DeduceJpegColorSpace() /// private void AssignResolution() { - this.ImageWidth = this.Frame.SamplesPerLine; - this.ImageHeight = this.Frame.Scanlines; - if (this.jFif.XDensity > 0 && this.jFif.YDensity > 0) { this.MetaData.HorizontalResolution = this.jFif.XDensity; @@ -622,59 +631,58 @@ private void ProcessStartOfFrameMarker(int remaining, PdfJsFileMarker frameMarke this.Frame = new PdfJsFrame { - Extended = frameMarker.Marker == PdfJsJpegConstants.Markers.SOF1, - Progressive = frameMarker.Marker == PdfJsJpegConstants.Markers.SOF2, + Extended = frameMarker.Marker == JpegConstants.Markers.SOF1, + Progressive = frameMarker.Marker == JpegConstants.Markers.SOF2, Precision = this.temp[0], Scanlines = (short)((this.temp[1] << 8) | this.temp[2]), SamplesPerLine = (short)((this.temp[3] << 8) | this.temp[4]), ComponentCount = this.temp[5] }; + this.ImageSizeInPixels = new Size(this.Frame.SamplesPerLine, this.Frame.Scanlines); + int maxH = 0; int maxV = 0; int index = 6; this.ComponentCount = this.Frame.ComponentCount; + if (!metadataOnly) { // 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.ColorSpace = this.DeduceJpegColorSpace(); - for (int i = 0; i < this.Frame.ComponentCount; i++) - { - byte hv = this.temp[index + 1]; - int h = hv >> 4; - int v = hv & 15; - - if (maxH < h) + for (int i = 0; i < this.Frame.ComponentCount; i++) { - maxH = h; - } + byte hv = this.temp[index + 1]; + int h = hv >> 4; + int v = hv & 15; - if (maxV < v) - { - maxV = v; - } + if (maxH < h) + { + maxH = h; + } + + if (maxV < v) + { + maxV = v; + } - if (!metadataOnly) - { var component = new PdfJsFrameComponent(this.configuration.MemoryManager, this.Frame, this.temp[index], h, v, this.temp[index + 2], i); this.Frame.Components[i] = component; this.Frame.ComponentIds[i] = component.Id; - } - - index += 3; - } - this.Frame.MaxHorizontalFactor = maxH; - this.Frame.MaxVerticalFactor = maxV; + index += 3; + } - if (!metadataOnly) - { + this.Frame.MaxHorizontalFactor = maxH; + this.Frame.MaxVerticalFactor = maxV; + this.ColorSpace = this.DeduceJpegColorSpace(); this.Frame.InitComponents(); + this.ImageSizeInMCU = new Size(this.Frame.McusPerLine, this.Frame.McusPerColumn); } } @@ -821,7 +829,6 @@ private ushort ReadUint16() private Image PostProcessIntoImage() where TPixel : struct, IPixel { - this.ColorSpace = this.DeduceJpegColorSpace(); using (var postProcessor = new JpegImagePostProcessor(this.configuration.MemoryManager, this)) { var image = new Image(this.configuration, this.ImageWidth, this.ImageHeight, this.MetaData); diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 7cbe862835..0c793d4bc3 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -57,11 +57,11 @@ true - + TextTemplatingFileGenerator Block8x8F.Generated.cs - + TextTemplatingFileGenerator GenericBlock8x8.Generated.cs @@ -87,12 +87,12 @@ - + True True Block8x8F.Generated.tt - + True True GenericBlock8x8.Generated.tt @@ -123,4 +123,7 @@ PorterDuffFunctions.Generated.tt + + + \ 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 47325476cf..f86919dd15 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg.cs @@ -49,7 +49,7 @@ public CoreSize JpegImageSharpOrig() { using (var memoryStream = new MemoryStream(this.jpegBytes)) { - using (var image = Image.Load(memoryStream, new OrigJpegDecoder())) + using (var image = Image.Load(memoryStream, new GolangJpegDecoder())) { 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 a1083e8ebf..c4ee732f5e 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegMultiple.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegMultiple.cs @@ -24,7 +24,7 @@ public class DecodeJpegMultiple : MultiImageBenchmarkBase [Benchmark(Description = "DecodeJpegMultiple - ImageSharp")] public void DecodeJpegImageSharpOrig() { - this.ForEachStream(ms => Image.Load(ms, new OrigJpegDecoder())); + this.ForEachStream(ms => Image.Load(ms, new GolangJpegDecoder())); } [Benchmark(Description = "DecodeJpegMultiple - ImageSharp PDFJs")] diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs index c3c1281001..b6ad20d128 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/IdentifyJpeg.cs @@ -33,7 +33,7 @@ public IImageInfo IdentifyGolang() { using (var memoryStream = new MemoryStream(this.jpegBytes)) { - var decoder = new OrigJpegDecoder(); + var decoder = new GolangJpegDecoder(); return decoder.Identify(Configuration.Default, memoryStream); } diff --git a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs index 5f902ff64d..ef0d55765a 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Jpeg/YCbCrColorConversion.cs @@ -1,14 +1,14 @@ -namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters; + +namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg { using System; using System.Numerics; using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; - using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters; using SixLabors.ImageSharp.Memory; - + [Config(typeof(Config.ShortClr))] public class YCbCrColorConversion { @@ -57,7 +57,7 @@ public void SimdAvx2() JpegColorConverter.FromYCbCrSimdAvx2.ConvertCore(values, this.output); } - + private static Buffer2D[] CreateRandomValues( int componentCount, int inputBufferLength, @@ -81,6 +81,6 @@ private static Buffer2D[] CreateRandomValues( return buffers; } - + } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs b/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs index c4a77acc26..07ae17d754 100644 --- a/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs +++ b/tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs @@ -1,13 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Buffers; using System.Numerics; using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; -using SixLabors.ImageSharp.Formats.Jpeg.Common; + +using SixLabors.ImageSharp.Formats.Jpeg.Components; namespace SixLabors.ImageSharp.Benchmarks { @@ -104,14 +103,14 @@ public static Byte Create(byte[] data) } } } - + public struct Result { internal Block8x8F Y; internal Block8x8F Cb; internal Block8x8F Cr; } - + // The operation is defined as "RGBA -> YCbCr Transform a stream of bytes into a stream of floats" // We need to benchmark the whole operation, to get true results, not missing any side effects! private byte[] inputSourceRGB = null; @@ -200,11 +199,11 @@ public unsafe void RgbaToYcbCrScaledIntegerSimd() float* cbPtr = (float*)&result.Cb; float* crPtr = (float*)&result.Cr; // end of code-bloat block :) - + Vector yCoeffs = new Vector(ScaledCoeffs.Y); Vector cbCoeffs = new Vector(ScaledCoeffs.Cb); Vector crCoeffs = new Vector(ScaledCoeffs.Cr); - + for (int i = 0; i < this.inputSourceRGB.Length; i++) { this.inputSourceRGBAsInteger[i] = this.inputSourceRGB[i]; @@ -217,7 +216,7 @@ public unsafe void RgbaToYcbCrScaledIntegerSimd() Vector y = yCoeffs * rgb; Vector cb = cbCoeffs * rgb; Vector cr = crCoeffs * rgb; - + *yPtr++ = (y[0] + y[1] + y[2]) >> 10; *cbPtr++ = 128 + ((cb[0] - cb[1] + cb[2]) >> 10); *crPtr++ = 128 + ((cr[0] - cr[1] - cr[2]) >> 10); @@ -335,7 +334,7 @@ public unsafe void RgbaToYcbCrScaledInteger() *crPtr++ = 128 + ((cr0 - cr1 - cr2) >> 10); } } - + [Benchmark(Description = "Scaled Integer LUT Conversion")] public unsafe void RgbaToYcbCrScaledIntegerLut() { diff --git a/tests/ImageSharp.Benchmarks/General/Block8x8F_DivideRound.cs b/tests/ImageSharp.Benchmarks/General/Block8x8F_DivideRound.cs index bad87cc11a..fcc5f9a592 100644 --- a/tests/ImageSharp.Benchmarks/General/Block8x8F_DivideRound.cs +++ b/tests/ImageSharp.Benchmarks/General/Block8x8F_DivideRound.cs @@ -5,7 +5,9 @@ using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; -using SixLabors.ImageSharp.Formats.Jpeg.Common; + +using SixLabors.ImageSharp.Formats.Jpeg.Components; + // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Benchmarks.General diff --git a/tests/ImageSharp.Benchmarks/General/Block8x8F_Round.cs b/tests/ImageSharp.Benchmarks/General/Block8x8F_Round.cs index d101bf0509..200af64c25 100644 --- a/tests/ImageSharp.Benchmarks/General/Block8x8F_Round.cs +++ b/tests/ImageSharp.Benchmarks/General/Block8x8F_Round.cs @@ -6,8 +6,7 @@ using BenchmarkDotNet.Attributes; -using SixLabors.ImageSharp; -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; namespace SixLabors.ImageSharp.Benchmarks.General { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/AdobeMarkerTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/AdobeMarkerTests.cs index 2ee9498e09..8b0e89f59d 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/AdobeMarkerTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/AdobeMarkerTests.cs @@ -1,8 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; -using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; +using SixLabors.ImageSharp.Formats.Jpeg; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using Xunit; @@ -25,29 +25,29 @@ public void MarkerLengthIsCorrect() [Fact] public void MarkerReturnsCorrectParsedValue() { - bool isAdobe = AdobeMarker.TryParse(this.bytes, out var marker); + bool isAdobe = AdobeMarker.TryParse(this.bytes, out AdobeMarker marker); Assert.True(isAdobe); Assert.Equal(100, marker.DCTEncodeVersion); Assert.Equal(0, marker.APP14Flags0); Assert.Equal(0, marker.APP14Flags1); - Assert.Equal(OrigJpegConstants.Adobe.ColorTransformYcck, marker.ColorTransform); + Assert.Equal(JpegConstants.Adobe.ColorTransformYcck, marker.ColorTransform); } [Fact] public void MarkerIgnoresIncorrectValue() { - bool isAdobe = AdobeMarker.TryParse(new byte[] { 0, 0, 0, 0 }, out var marker); + bool isAdobe = AdobeMarker.TryParse(new byte[] { 0, 0, 0, 0 }, out AdobeMarker marker); Assert.False(isAdobe); - Assert.Equal(default(AdobeMarker), marker); + Assert.Equal(default, marker); } [Fact] public void MarkerEqualityIsCorrect() { - AdobeMarker.TryParse(this.bytes, out var marker); - AdobeMarker.TryParse(this.bytes, out var marker2); + AdobeMarker.TryParse(this.bytes, out AdobeMarker marker); + AdobeMarker.TryParse(this.bytes, out AdobeMarker marker2); Assert.True(marker.Equals(marker2)); } @@ -55,8 +55,8 @@ public void MarkerEqualityIsCorrect() [Fact] public void MarkerInEqualityIsCorrect() { - AdobeMarker.TryParse(this.bytes, out var marker); - AdobeMarker.TryParse(this.bytes2, out var marker2); + AdobeMarker.TryParse(this.bytes, out AdobeMarker marker); + AdobeMarker.TryParse(this.bytes2, out AdobeMarker marker2); Assert.False(marker.Equals(marker2)); } @@ -64,8 +64,8 @@ public void MarkerInEqualityIsCorrect() [Fact] public void MarkerHashCodeIsReplicable() { - AdobeMarker.TryParse(this.bytes, out var marker); - AdobeMarker.TryParse(this.bytes, out var marker2); + AdobeMarker.TryParse(this.bytes, out AdobeMarker marker); + AdobeMarker.TryParse(this.bytes, out AdobeMarker marker2); Assert.True(marker.GetHashCode().Equals(marker2.GetHashCode())); } @@ -73,8 +73,8 @@ public void MarkerHashCodeIsReplicable() [Fact] public void MarkerHashCodeIsUnique() { - AdobeMarker.TryParse(this.bytes, out var marker); - AdobeMarker.TryParse(this.bytes2, out var marker2); + AdobeMarker.TryParse(this.bytes, out AdobeMarker marker); + AdobeMarker.TryParse(this.bytes2, out AdobeMarker marker2); Assert.False(marker.GetHashCode().Equals(marker2.GetHashCode())); } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs index 4b5cf526b0..aa7d101c0d 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs @@ -4,7 +4,7 @@ // Uncomment this to turn unit tests into benchmarks: //#define BENCHMARKING -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs index ac8bed13b0..e72f4945b7 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs @@ -7,7 +7,7 @@ using System; using System.Diagnostics; -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using Xunit; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs index c7869a6ba8..3df927aeb0 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using Xunit; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs index 1c18df76c6..92b92eb100 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/DCTTests.cs @@ -1,7 +1,7 @@ // ReSharper disable InconsistentNaming using System; -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using Xunit; @@ -102,7 +102,7 @@ public void LLM_TransformIDCT_CompareToAccurate(int seed) var temp = default(Block8x8F); var actual = default(Block8x8F); FastFloatingPointDCT.TransformIDCT(ref source, ref actual, ref temp); - + this.CompareBlocks(expected, actual, 1f); } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs b/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs index 5bb3ded0b1..05ded4341d 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs @@ -3,7 +3,7 @@ using System; -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.PixelFormats; using Xunit; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs index 4e63c97dec..332899e8df 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using Xunit; @@ -27,7 +27,7 @@ public void MarkerLengthIsCorrect() [Fact] public void MarkerReturnsCorrectParsedValue() { - bool isJFif = JFifMarker.TryParse(this.bytes, out var marker); + bool isJFif = JFifMarker.TryParse(this.bytes, out JFifMarker marker); Assert.True(isJFif); Assert.Equal(1, marker.MajorVersion); @@ -40,26 +40,26 @@ public void MarkerReturnsCorrectParsedValue() [Fact] public void MarkerIgnoresIncorrectValue() { - bool isJFif = JFifMarker.TryParse(new byte[] { 0, 0, 0, 0 }, out var marker); + bool isJFif = JFifMarker.TryParse(new byte[] { 0, 0, 0, 0 }, out JFifMarker marker); Assert.False(isJFif); - Assert.Equal(default(JFifMarker), marker); + Assert.Equal(default, marker); } [Fact] public void MarkerIgnoresCorrectHeaderButInvalidDensities() { - bool isJFif = JFifMarker.TryParse(this.bytes3, out var marker); + bool isJFif = JFifMarker.TryParse(this.bytes3, out JFifMarker marker); Assert.False(isJFif); - Assert.Equal(default(JFifMarker), marker); + Assert.Equal(default, marker); } [Fact] public void MarkerEqualityIsCorrect() { - JFifMarker.TryParse(this.bytes, out var marker); - JFifMarker.TryParse(this.bytes, out var marker2); + JFifMarker.TryParse(this.bytes, out JFifMarker marker); + JFifMarker.TryParse(this.bytes, out JFifMarker marker2); Assert.True(marker.Equals(marker2)); } @@ -67,8 +67,8 @@ public void MarkerEqualityIsCorrect() [Fact] public void MarkerInEqualityIsCorrect() { - JFifMarker.TryParse(this.bytes, out var marker); - JFifMarker.TryParse(this.bytes2, out var marker2); + JFifMarker.TryParse(this.bytes, out JFifMarker marker); + JFifMarker.TryParse(this.bytes2, out JFifMarker marker2); Assert.False(marker.Equals(marker2)); } @@ -76,8 +76,8 @@ public void MarkerInEqualityIsCorrect() [Fact] public void MarkerHashCodeIsReplicable() { - JFifMarker.TryParse(this.bytes, out var marker); - JFifMarker.TryParse(this.bytes, out var marker2); + JFifMarker.TryParse(this.bytes, out JFifMarker marker); + JFifMarker.TryParse(this.bytes, out JFifMarker marker2); Assert.True(marker.GetHashCode().Equals(marker2.GetHashCode())); } @@ -85,8 +85,8 @@ public void MarkerHashCodeIsReplicable() [Fact] public void MarkerHashCodeIsUnique() { - JFifMarker.TryParse(this.bytes, out var marker); - JFifMarker.TryParse(this.bytes2, out var marker2); + JFifMarker.TryParse(this.bytes, out JFifMarker marker); + JFifMarker.TryParse(this.bytes2, out JFifMarker marker2); Assert.False(marker.GetHashCode().Equals(marker2.GetHashCode())); } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index d2f0641756..c97d625535 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -6,8 +6,8 @@ using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces.Conversion; -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters; using SixLabors.ImageSharp.Memory; using Xunit; @@ -140,13 +140,13 @@ public void BenchmarkYCbCr(bool simd) JpegColorConverter converter = simd ? (JpegColorConverter)new JpegColorConverter.FromYCbCrSimd() : new JpegColorConverter.FromYCbCrBasic(); // Warm up: - converter.ConvertToRGBA(values, result); + converter.ConvertToRgba(values, result); using (new MeasureGuard(this.Output, $"{converter.GetType().Name} x {times}")) { for (int i = 0; i < times; i++) { - converter.ConvertToRGBA(values, result); + converter.ConvertToRgba(values, result); } } } @@ -162,7 +162,7 @@ public void ConvertFromCmyk(int inputBufferLength, int resultBufferLength, int s JpegColorConverter.ComponentValues values = CreateRandomValues(4, inputBufferLength, seed); var result = new Vector4[resultBufferLength]; - converter.ConvertToRGBA(values, result); + converter.ConvertToRgba(values, result); for (int i = 0; i < resultBufferLength; i++) { @@ -195,7 +195,7 @@ public void ConvertFromGrayScale(int inputBufferLength, int resultBufferLength, JpegColorConverter.ComponentValues values = CreateRandomValues(1, inputBufferLength, seed); var result = new Vector4[resultBufferLength]; - converter.ConvertToRGBA(values, result); + converter.ConvertToRgba(values, result); for (int i = 0; i < resultBufferLength; i++) { @@ -217,7 +217,7 @@ public void ConvertFromRgb(int inputBufferLength, int resultBufferLength, int se JpegColorConverter.ComponentValues values = CreateRandomValues(3, inputBufferLength, seed); var result = new Vector4[resultBufferLength]; - converter.ConvertToRGBA(values, result); + converter.ConvertToRgba(values, result); for (int i = 0; i < resultBufferLength; i++) { @@ -244,7 +244,7 @@ public void ConvertFromYcck(int inputBufferLength, int resultBufferLength, int s JpegColorConverter.ComponentValues values = CreateRandomValues(4, inputBufferLength, seed); var result = new Vector4[resultBufferLength]; - converter.ConvertToRGBA(values, result); + converter.ConvertToRgba(values, result); for (int i = 0; i < resultBufferLength; i++) { @@ -320,7 +320,7 @@ private static void ValidateRgbToYCbCrConversion( JpegColorConverter.ComponentValues values = CreateRandomValues(componentCount, inputBufferLength, seed); var result = new Vector4[resultBufferLength]; - converter.ConvertToRGBA(values, result); + converter.ConvertToRgba(values, result); for (int i = 0; i < resultBufferLength; i++) { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs new file mode 100644 index 0000000000..778459775a --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs @@ -0,0 +1,89 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests.Formats.Jpg +{ + public partial class JpegDecoderTests + { + [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.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); + + using (Image image = provider.GetImage(GolangJpegDecoder)) + { + image.DebugSave(provider); + provider.Utility.TestName = DecodeBaselineJpegOutputName; + image.CompareToReferenceOutput( + this.GetImageComparer(provider), + provider, + appendPixelTypeToFileName: false); + } + + provider.Configuration.MemoryManager.ReleaseRetainedResources(); + } + + [Theory] + [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] + public void DecodeBaselineJpeg_PdfJs(TestImageProvider provider) + where TPixel : struct, IPixel + { + if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) + { + // skipping to avoid OutOfMemoryException on CI + return; + } + + using (Image image = provider.GetImage(PdfJsJpegDecoder)) + { + image.DebugSave(provider); + + provider.Utility.TestName = DecodeBaselineJpegOutputName; + image.CompareToReferenceOutput( + this.GetImageComparer(provider), + provider, + appendPixelTypeToFileName: false); + } + } + + [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) + where TPixel : struct, IPixel + { + // TODO: We need a public ImageDecoderException class in ImageSharp! + Assert.ThrowsAny(() => provider.GetImage(PdfJsJpegDecoder)); + } + + [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.Images.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs new file mode 100644 index 0000000000..539ab73195 --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs @@ -0,0 +1,72 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Collections.Generic; + +namespace SixLabors.ImageSharp.Tests.Formats.Jpg +{ + public partial class JpegDecoderTests + { + public static string[] BaselineTestJpegs = + { + TestImages.Jpeg.Baseline.Calliphora, + TestImages.Jpeg.Baseline.Cmyk, TestImages.Jpeg.Baseline.Ycck, + TestImages.Jpeg.Baseline.Jpeg400, + TestImages.Jpeg.Baseline.Testorig420, + + // BUG: The following image has a high difference compared to the expected output: + // TestImages.Jpeg.Baseline.Jpeg420Small, + + TestImages.Jpeg.Baseline.Jpeg444, + TestImages.Jpeg.Baseline.Bad.BadEOF, + TestImages.Jpeg.Issues.MultiHuffmanBaseline394, + TestImages.Jpeg.Baseline.MultiScanBaselineCMYK, + TestImages.Jpeg.Baseline.Bad.BadRST + }; + + public static string[] ProgressiveTestJpegs = + { + TestImages.Jpeg.Progressive.Fb, + TestImages.Jpeg.Progressive.Progress, + TestImages.Jpeg.Progressive.Festzug, + TestImages.Jpeg.Progressive.Bad.BadEOF, + TestImages.Jpeg.Issues.BadCoeffsProgressive178, + TestImages.Jpeg.Issues.MissingFF00ProgressiveGirl159, + TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159, + TestImages.Jpeg.Issues.BadZigZagProgressive385, + TestImages.Jpeg.Progressive.Bad.ExifUndefType, + TestImages.Jpeg.Issues.NoEoiProgressive517, + TestImages.Jpeg.Issues.BadRstProgressive518, + TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159, + }; + + /// + /// Golang decoder is unable to decode these + /// + public static string[] PdfJsOnly = + { + TestImages.Jpeg.Issues.NoEoiProgressive517, TestImages.Jpeg.Issues.BadRstProgressive518, + TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159 + }; + + private static readonly Dictionary CustomToleranceValues = + new Dictionary + { + // Baseline: + [TestImages.Jpeg.Baseline.Calliphora] = 0.00002f / 100, + [TestImages.Jpeg.Baseline.Bad.BadEOF] = 0.38f / 100, + [TestImages.Jpeg.Baseline.Testorig420] = 0.38f / 100, + [TestImages.Jpeg.Baseline.Bad.BadRST] = 0.0589f / 100, + + // Progressive: + [TestImages.Jpeg.Issues.MissingFF00ProgressiveGirl159] = 0.34f / 100, + [TestImages.Jpeg.Issues.BadCoeffsProgressive178] = 0.38f / 100, + [TestImages.Jpeg.Progressive.Bad.BadEOF] = 0.3f / 100, + [TestImages.Jpeg.Progressive.Festzug] = 0.02f / 100, + [TestImages.Jpeg.Progressive.Fb] = 0.16f / 100, + [TestImages.Jpeg.Progressive.Progress] = 0.31f / 100, + [TestImages.Jpeg.Issues.BadZigZagProgressive385] = 0.23f / 100, + [TestImages.Jpeg.Progressive.Bad.ExifUndefType] = 0.011f / 100, + }; + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs index 7fc949b091..10b098d924 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.MetaData.cs @@ -11,6 +11,7 @@ // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests.Formats.Jpg { + using System; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Formats.Jpeg; @@ -50,7 +51,7 @@ public void MetaDataIsParsedCorrectly_Orig( { TestMetaDataImpl( useIdentify, - OrigJpegDecoder, + GolangJpegDecoder, imagePath, expectedPixelSize, exifProfilePresent, @@ -75,6 +76,18 @@ public void MetaDataIsParsedCorrectly_PdfJs( iccProfilePresent); } + 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); + test(imageInfo); + } + } + private static void TestMetaDataImpl( bool useIdentify, IImageDecoder decoder, @@ -83,51 +96,50 @@ private static void TestMetaDataImpl( bool exifProfilePresent, bool iccProfilePresent) { - 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); + TestImageInfo( + imagePath, + decoder, + useIdentify, + imageInfo => + { + Assert.NotNull(imageInfo); + Assert.NotNull(imageInfo.PixelType); - Assert.NotNull(imageInfo); - Assert.NotNull(imageInfo.PixelType); - - if (useIdentify) - { - Assert.Equal(expectedPixelSize, imageInfo.PixelType.BitsPerPixel); - } - else - { - // When full Image decoding is performed, BitsPerPixel will match TPixel - int bpp32 = Unsafe.SizeOf() * 8; - Assert.Equal(bpp32, imageInfo.PixelType.BitsPerPixel); - } + if (useIdentify) + { + Assert.Equal(expectedPixelSize, imageInfo.PixelType.BitsPerPixel); + } + else + { + // When full Image decoding is performed, BitsPerPixel will match TPixel + int bpp32 = Unsafe.SizeOf() * 8; + Assert.Equal(bpp32, imageInfo.PixelType.BitsPerPixel); + } - ExifProfile exifProfile = imageInfo.MetaData.ExifProfile; + ExifProfile exifProfile = imageInfo.MetaData.ExifProfile; - if (exifProfilePresent) - { - Assert.NotNull(exifProfile); - Assert.NotEmpty(exifProfile.Values); - } - else - { - Assert.Null(exifProfile); - } + if (exifProfilePresent) + { + Assert.NotNull(exifProfile); + Assert.NotEmpty(exifProfile.Values); + } + else + { + Assert.Null(exifProfile); + } - IccProfile iccProfile = imageInfo.MetaData.IccProfile; + IccProfile iccProfile = imageInfo.MetaData.IccProfile; - if (iccProfilePresent) - { - Assert.NotNull(iccProfile); - Assert.NotEmpty(iccProfile.Entries); - } - else - { - Assert.Null(iccProfile); - } - } + if (iccProfilePresent) + { + Assert.NotNull(iccProfile); + Assert.NotEmpty(iccProfile.Entries); + } + else + { + Assert.Null(iccProfile); + } + }); } [Theory] @@ -154,5 +166,31 @@ public void IgnoreMetaData_ControlsWhetherMetaDataIsParsed(bool ignoreMetaData) } } } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void Decoder_Reads_Correct_Resolution_From_Jfif(bool useIdentify) + { + TestImageInfo(TestImages.Jpeg.Baseline.Floorplan, DefaultJpegDecoder, useIdentify, + imageInfo => + { + Assert.Equal(300, imageInfo.MetaData.HorizontalResolution); + Assert.Equal(300, imageInfo.MetaData.VerticalResolution); + }); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void Decoder_Reads_Correct_Resolution_From_Exif(bool useIdentify) + { + TestImageInfo(TestImages.Jpeg.Baseline.Jpeg420Exif, DefaultJpegDecoder, useIdentify, + imageInfo => + { + Assert.Equal(72, imageInfo.MetaData.HorizontalResolution); + Assert.Equal(72, imageInfo.MetaData.VerticalResolution); + }); + } } } \ 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 new file mode 100644 index 0000000000..83983691e2 --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs @@ -0,0 +1,81 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Linq; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests.Formats.Jpg +{ + public partial class JpegDecoderTests + { + public const string DecodeProgressiveJpegOutputName = "DecodeProgressiveJpeg"; + + [Theory] + [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] + public void DecodeProgressiveJpeg_Orig(TestImageProvider provider) + where TPixel : struct, IPixel + { + if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) + { + // skipping to avoid OutOfMemoryException on CI + return; + } + + // Golang decoder is unable to decode these: + if (PdfJsOnly.Any(fn => fn.Contains(provider.SourceFileOrDescription))) + { + return; + } + + // For 32 bit test enviroments: + provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); + + using (Image image = provider.GetImage(GolangJpegDecoder)) + { + image.DebugSave(provider); + + provider.Utility.TestName = DecodeProgressiveJpegOutputName; + image.CompareToReferenceOutput( + this.GetImageComparer(provider), + provider, + appendPixelTypeToFileName: false); + } + + provider.Configuration.MemoryManager.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)) + { + image.DebugSave(provider); + + provider.Utility.TestName = DecodeProgressiveJpegOutputName; + image.CompareToReferenceOutput( + this.GetImageComparer(provider), + provider, + 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 3138300b90..cfd5989f58 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -24,59 +24,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg // TODO: Scatter test cases into multiple test classes public partial class JpegDecoderTests { - public static string[] BaselineTestJpegs = - { - TestImages.Jpeg.Baseline.Calliphora, - TestImages.Jpeg.Baseline.Cmyk, - TestImages.Jpeg.Baseline.Ycck, - TestImages.Jpeg.Baseline.Jpeg400, - TestImages.Jpeg.Baseline.Testorig420, - - // BUG: The following image has a high difference compared to the expected output: - // TestImages.Jpeg.Baseline.Jpeg420Small, - - TestImages.Jpeg.Baseline.Jpeg444, - TestImages.Jpeg.Baseline.Bad.BadEOF, - TestImages.Jpeg.Issues.MultiHuffmanBaseline394, - TestImages.Jpeg.Baseline.MultiScanBaselineCMYK, - TestImages.Jpeg.Baseline.Bad.BadRST - }; - - public static string[] ProgressiveTestJpegs = - { - TestImages.Jpeg.Progressive.Fb, TestImages.Jpeg.Progressive.Progress, - TestImages.Jpeg.Progressive.Festzug, TestImages.Jpeg.Progressive.Bad.BadEOF, - TestImages.Jpeg.Issues.BadCoeffsProgressive178, - TestImages.Jpeg.Issues.MissingFF00ProgressiveGirl159, - TestImages.Jpeg.Issues.BadZigZagProgressive385, - TestImages.Jpeg.Progressive.Bad.ExifUndefType - }; - - public static string[] FalsePositiveIssueJpegs = - { - TestImages.Jpeg.Issues.NoEOI517, - TestImages.Jpeg.Issues.BadRST518, - }; - - private static readonly Dictionary CustomToleranceValues = new Dictionary - { - // Baseline: - [TestImages.Jpeg.Baseline.Calliphora] = 0.00002f / 100, - [TestImages.Jpeg.Baseline.Bad.BadEOF] = 0.38f / 100, - [TestImages.Jpeg.Baseline.Testorig420] = 0.38f / 100, - [TestImages.Jpeg.Baseline.Bad.BadRST] = 0.0589f / 100, - - // Progressive: - [TestImages.Jpeg.Issues.MissingFF00ProgressiveGirl159] = 0.34f / 100, - [TestImages.Jpeg.Issues.BadCoeffsProgressive178] = 0.38f / 100, - [TestImages.Jpeg.Progressive.Bad.BadEOF] = 0.3f / 100, - [TestImages.Jpeg.Progressive.Festzug] = 0.02f / 100, - [TestImages.Jpeg.Progressive.Fb] = 0.16f / 100, - [TestImages.Jpeg.Progressive.Progress] = 0.31f / 100, - [TestImages.Jpeg.Issues.BadZigZagProgressive385] = 0.23f / 100, - [TestImages.Jpeg.Progressive.Bad.ExifUndefType] = 0.011f / 100, - }; - public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Argb32 | PixelTypes.RgbaVector; private const float BaselineTolerance = 0.001F / 100; @@ -115,10 +62,12 @@ public JpegDecoderTests(ITestOutputHelper output) private ITestOutputHelper Output { get; } - private static OrigJpegDecoder OrigJpegDecoder => new OrigJpegDecoder(); + private static GolangJpegDecoder GolangJpegDecoder => new GolangJpegDecoder(); private static PdfJsJpegDecoder PdfJsJpegDecoder => new PdfJsJpegDecoder(); + private static JpegDecoder DefaultJpegDecoder => new JpegDecoder(); + [Fact] public void ParseStream_BasicPropertiesAreCorrect1_PdfJs() { @@ -151,7 +100,7 @@ public void JpegDecoder_IsNotBoundToSinglePixelType(TestImageProvider image = provider.GetImage(decoder)) { image.DebugSave(provider); @@ -163,142 +112,6 @@ public void JpegDecoder_IsNotBoundToSinglePixelType(TestImageProvider(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (SkipTest(provider)) - { - return; - } - - // For 32 bit test enviroments: - provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); - - using (Image image = provider.GetImage(OrigJpegDecoder)) - { - image.DebugSave(provider); - provider.Utility.TestName = DecodeBaselineJpegOutputName; - image.CompareToReferenceOutput( - this.GetImageComparer(provider), - provider, - appendPixelTypeToFileName: false); - } - - provider.Configuration.MemoryManager.ReleaseRetainedResources(); - } - - [Theory] - [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] - public void DecodeBaselineJpeg_PdfJs(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) - { - // skipping to avoid OutOfMemoryException on CI - return; - } - - using (Image image = provider.GetImage(PdfJsJpegDecoder)) - { - image.DebugSave(provider); - - provider.Utility.TestName = DecodeBaselineJpegOutputName; - image.CompareToReferenceOutput( - this.GetImageComparer(provider), - provider, - appendPixelTypeToFileName: false); - } - } - - /// - /// Only can decode these images. - /// - /// The pixel format - /// The test image provider - [Theory] - [WithFileCollection(nameof(FalsePositiveIssueJpegs), PixelTypes.Rgba32)] - public void DecodeFalsePositiveJpeg_PdfJs(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) - { - // skipping to avoid OutOfMemoryException on CI - return; - } - - using (Image image = provider.GetImage(PdfJsJpegDecoder)) - { - image.DebugSave(provider); - image.CompareToReferenceOutput( - ImageComparer.Tolerant(BaselineTolerance), - provider, - appendPixelTypeToFileName: true); - } - } - - [Theory] - [WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)] - public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_Orig(TestImageProvider provider) - where TPixel : struct, IPixel - { - // TODO: We need a public ImageDecoderException class in ImageSharp! - Assert.ThrowsAny(() => provider.GetImage(OrigJpegDecoder)); - } - - public const string DecodeProgressiveJpegOutputName = "DecodeProgressiveJpeg"; - - [Theory] - [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] - public void DecodeProgressiveJpeg_Orig(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (SkipTest(provider)) - { - return; - } - - // For 32 bit test enviroments: - provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); - - using (Image image = provider.GetImage(OrigJpegDecoder)) - { - image.DebugSave(provider); - - provider.Utility.TestName = DecodeProgressiveJpegOutputName; - image.CompareToReferenceOutput( - this.GetImageComparer(provider), - provider, - appendPixelTypeToFileName: false); - } - - provider.Configuration.MemoryManager.ReleaseRetainedResources(); - } - - [Theory] - [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] - public void DecodeProgressiveJpeg_PdfJs(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) - { - // skipping to avoid OutOfMemoryException on CI - return; - } - - using (Image image = provider.GetImage(PdfJsJpegDecoder)) - { - image.DebugSave(provider); - - provider.Utility.TestName = DecodeProgressiveJpegOutputName; - image.CompareToReferenceOutput( - this.GetImageComparer(provider), - provider, - appendPixelTypeToFileName: false); - } - } - private string GetDifferenceInPercentageString(Image image, TestImageProvider provider) where TPixel : struct, IPixel { @@ -321,15 +134,10 @@ private string GetDifferenceInPercentageString(Image image, Test private void CompareJpegDecodersImpl(TestImageProvider provider, string testName) where TPixel : struct, IPixel { - if (TestEnvironment.RunsOnCI) // Debug only test - { - return; - } - this.Output.WriteLine(provider.SourceFileOrDescription); provider.Utility.TestName = testName; - using (Image image = provider.GetImage(OrigJpegDecoder)) + using (Image image = provider.GetImage(GolangJpegDecoder)) { string d = this.GetDifferenceInPercentageString(image, provider); @@ -343,70 +151,6 @@ private void CompareJpegDecodersImpl(TestImageProvider provider, } } - [Theory] - [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] - public void CompareJpegDecoders_Baseline(TestImageProvider provider) - where TPixel : struct, IPixel - { - this.CompareJpegDecodersImpl(provider, DecodeBaselineJpegOutputName); - } - - [Theory] - [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] - public void CompareJpegDecoders_Progressive(TestImageProvider provider) - where TPixel : struct, IPixel - { - this.CompareJpegDecodersImpl(provider, DecodeProgressiveJpegOutputName); - } - - [Theory] - [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio420, 75)] - [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio420, 100)] - [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 75)] - [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 100)] - [WithSolidFilledImages(8, 8, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 100)] - public void DecodeGenerated_Orig( - TestImageProvider provider, - JpegSubsample subsample, - int quality) - where TPixel : struct, IPixel - { - byte[] data; - using (Image image = provider.GetImage()) - { - var encoder = new JpegEncoder { Subsample = subsample, Quality = quality }; - - data = new byte[65536]; - using (var ms = new MemoryStream(data)) - { - image.Save(ms, encoder); - } - } - - var mirror = Image.Load(data, OrigJpegDecoder); - mirror.DebugSave(provider, $"_{subsample}_Q{quality}"); - } - - [Fact] - public void Decoder_Reads_Correct_Resolution_From_Jfif() - { - using (Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage()) - { - Assert.Equal(300, image.MetaData.HorizontalResolution); - Assert.Equal(300, image.MetaData.VerticalResolution); - } - } - - [Fact] - public void Decoder_Reads_Correct_Resolution_From_Exif() - { - using (Image image = TestFile.Create(TestImages.Jpeg.Baseline.Jpeg420Exif).CreateImage()) - { - Assert.Equal(72, image.MetaData.HorizontalResolution); - Assert.Equal(72, image.MetaData.VerticalResolution); - } - } - // DEBUG ONLY! // The PDF.js output should be saved by "tests\ImageSharp.Tests\Formats\Jpg\pdfjs\jpeg-converter.htm" // into "\tests\Images\ActualOutput\JpegDecoderTests\" diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs index ffaccb3f77..7e7518fd44 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs @@ -1,8 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; +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; @@ -21,16 +22,7 @@ public class JpegImagePostProcessorTests TestImages.Jpeg.Baseline.Ycck, TestImages.Jpeg.Baseline.Jpeg400, TestImages.Jpeg.Baseline.Testorig420, - TestImages.Jpeg.Baseline.Jpeg420Small, TestImages.Jpeg.Baseline.Jpeg444, - TestImages.Jpeg.Baseline.Bad.BadEOF, - }; - - public static string[] ProgressiveTestJpegs = - { - TestImages.Jpeg.Progressive.Fb, TestImages.Jpeg.Progressive.Progress, - TestImages.Jpeg.Progressive.Festzug, TestImages.Jpeg.Progressive.Bad.BadEOF, - TestImages.Jpeg.Progressive.Bad.ExifUndefType, }; public JpegImagePostProcessorTests(ITestOutputHelper output) @@ -47,7 +39,6 @@ private static void SaveBuffer(JpegComponentPostProcessor cp, TestImageP { image.DebugSave(provider, $"-C{cp.Component.Index}-"); } - } [Theory] @@ -57,7 +48,7 @@ public void DoProcessorStep(TestImageProvider provider) where TPixel : struct, IPixel { string imageFile = provider.SourceFileOrDescription; - using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile)) + using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(imageFile)) using (var pp = new JpegImagePostProcessor(Configuration.Default.MemoryManager, decoder)) using (var imageFrame = new ImageFrame(Configuration.Default.MemoryManager, decoder.ImageWidth, decoder.ImageHeight)) { @@ -70,16 +61,14 @@ public void DoProcessorStep(TestImageProvider provider) SaveBuffer(cp[2], provider); } } - + [Theory] - [WithFile(TestImages.Jpeg.Baseline.Calliphora, PixelTypes.Rgba32)] - [WithFile(TestImages.Jpeg.Baseline.Jpeg444, PixelTypes.Rgba32)] - [WithFile(TestImages.Jpeg.Baseline.Testorig420, PixelTypes.Rgba32)] + [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] public void PostProcess(TestImageProvider provider) where TPixel : struct, IPixel { string imageFile = provider.SourceFileOrDescription; - using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile)) + using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(imageFile)) using (var pp = new JpegImagePostProcessor(Configuration.Default.MemoryManager, decoder)) using (var image = new Image(decoder.ImageWidth, decoder.ImageHeight)) { @@ -97,7 +86,7 @@ public void PostProcess(TestImageProvider provider) ImageSimilarityReport report = ImageComparer.Exact.CompareImagesOrFrames(referenceImage, image); this.Output.WriteLine($"*** {imageFile} ***"); - this.Output.WriteLine($"Difference: "+ report.DifferencePercentageString); + this.Output.WriteLine($"Difference: {report.DifferencePercentageString}"); // ReSharper disable once PossibleInvalidOperationException Assert.True(report.TotalNormalizedDifference.Value < 0.005f); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs index 49c76dc4ec..b0f342f5ab 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs @@ -38,7 +38,7 @@ public JpegProfilingBenchmarks(ITestOutputHelper output) //[MemberData(nameof(DecodeJpegData))] public void DecodeJpeg_Original(string fileName) { - this.DecodeJpegBenchmarkImpl(fileName, new OrigJpegDecoder()); + this.DecodeJpegBenchmarkImpl(fileName, new GolangJpegDecoder()); } // [Theory] // Benchmark, enable manually diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs index b665d69e88..827a459cde 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs @@ -2,11 +2,12 @@ // Licensed under the Apache License, Version 2.0. using System.Text; - -using SixLabors.ImageSharp.Formats.Jpeg.Common; -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; +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; @@ -29,20 +30,35 @@ public ParseStreamTests(ITestOutputHelper output) [InlineData(TestImages.Jpeg.Baseline.Jpeg400, JpegColorSpace.Grayscale)] [InlineData(TestImages.Jpeg.Baseline.Ycck, JpegColorSpace.Ycck)] [InlineData(TestImages.Jpeg.Baseline.Cmyk, JpegColorSpace.Cmyk)] - public void ColorSpace_IsDeducedCorrectly(string imageFile, object expectedColorSpaceValue) + public void ColorSpace_IsDeducedCorrectlyGolang(string imageFile, object expectedColorSpaceValue) { var expecteColorSpace = (JpegColorSpace)expectedColorSpaceValue; - using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, false)) + using (GolangJpegDecoderCore decoder = JpegFixture.ParseGolangStream(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_1ChannelJpeg() + public void ComponentScalingIsCorrect_1ChannelJpegGolang() { - using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(TestImages.Jpeg.Baseline.Jpeg400, false)) + using (GolangJpegDecoderCore decoder = JpegFixture.ParseGolangStream(TestImages.Jpeg.Baseline.Jpeg400)) { Assert.Equal(1, decoder.ComponentCount); Assert.Equal(1, decoder.Components.Length); @@ -52,11 +68,53 @@ public void ComponentScalingIsCorrect_1ChannelJpeg() Assert.Equal(expectedSizeInBlocks, decoder.ImageSizeInMCU); var uniform1 = new Size(1, 1); - OrigComponent c0 = decoder.Components[0]; + GolangComponent c0 = decoder.Components[0]; VerifyJpeg.VerifyComponent(c0, expectedSizeInBlocks, uniform1, uniform1); } } + [Fact] + public void ComponentScalingIsCorrect_1ChannelJpegPdfJs() + { + using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(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); + PdfJsFrameComponent c0 = decoder.Components[0]; + VerifyJpeg.VerifyComponent(c0, expectedSizeInBlocks, uniform1, uniform1); + } + } + + [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 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)] @@ -64,16 +122,16 @@ public void ComponentScalingIsCorrect_1ChannelJpeg() [InlineData(TestImages.Jpeg.Baseline.Testorig420)] [InlineData(TestImages.Jpeg.Baseline.Ycck)] [InlineData(TestImages.Jpeg.Baseline.Cmyk)] - public void PrintComponentData(string imageFile) + public void PrintComponentDataPdfJs(string imageFile) { var sb = new StringBuilder(); - using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, false)) + using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(imageFile)) { sb.AppendLine(imageFile); sb.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}"); - OrigComponent c0 = decoder.Components[0]; - OrigComponent c1 = decoder.Components[1]; + PdfJsFrameComponent c0 = decoder.Components[0]; + PdfJsFrameComponent c1 = decoder.Components[1]; sb.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}"); sb.AppendLine($"Chroma: {c1.SamplingFactors} BLOCKS: {c1.SizeInBlocks}"); @@ -94,23 +152,64 @@ public void PrintComponentData(string imageFile) [Theory] [MemberData(nameof(ComponentVerificationData))] - public void ComponentScalingIsCorrect_MultiChannelJpeg( + 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( string imageFile, int componentCount, object expectedLumaFactors, object expectedChromaFactors) { - Size fLuma = (Size)expectedLumaFactors; - Size fChroma = (Size)expectedChromaFactors; + var fLuma = (Size)expectedLumaFactors; + var fChroma = (Size)expectedChromaFactors; - using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, false)) + using (PdfJsJpegDecoderCore decoder = JpegFixture.ParsePdfJsStream(imageFile)) { Assert.Equal(componentCount, decoder.ComponentCount); Assert.Equal(componentCount, decoder.Components.Length); - OrigComponent c0 = decoder.Components[0]; - OrigComponent c1 = decoder.Components[1]; - OrigComponent c2 = decoder.Components[2]; + PdfJsFrameComponent c0 = decoder.Components[0]; + PdfJsFrameComponent c1 = decoder.Components[1]; + PdfJsFrameComponent c2 = decoder.Components[2]; var uniform1 = new Size(1, 1); @@ -126,7 +225,7 @@ public void ComponentScalingIsCorrect_MultiChannelJpeg( if (componentCount == 4) { - OrigComponent c3 = decoder.Components[2]; + PdfJsFrameComponent c3 = decoder.Components[2]; VerifyJpeg.VerifyComponent(c3, expectedLumaSizeInBlocks, fLuma, uniform1); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ProfileResolverTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/ProfileResolverTests.cs index fa06f91dab..c908abc505 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ProfileResolverTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ProfileResolverTests.cs @@ -3,7 +3,7 @@ using System.Text; -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using Xunit; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs index b9ae97409c..dd2113624e 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs @@ -1,4 +1,7 @@ -using SixLabors.ImageSharp.Formats.Jpeg.Common; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using Xunit; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs index 11612d3e2b..ce6f0a744f 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs @@ -1,8 +1,8 @@ -// ReSharper disable InconsistentNaming - -using System; +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Formats.Jpeg.Common; +// ReSharper disable InconsistentNaming +using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using Xunit; @@ -36,13 +36,13 @@ public void LLM_ForwardThenInverse(int seed, int startAt) this.CompareBlocks(original, src, 0.1f); } - + // [Fact] public void LLM_CalcConstants() { ReferenceImplementations.LLM_FloatingPoint_DCT.PrintConstants(this.Output); } - + [Theory] [InlineData(42, 1000)] [InlineData(1, 1000)] @@ -76,7 +76,7 @@ public void LLM_IDCT_CompareToIntegerRoundedAccurateImplementation(int seed, int Block8x8F fExpected = iExpected.AsFloatBlock(); Block8x8F fActual = ReferenceImplementations.LLM_FloatingPoint_DCT.TransformIDCT(ref fSource); - + this.CompareBlocks(fExpected, fActual, 2); } @@ -113,7 +113,7 @@ public void GT_IDCT_IsEquivalentTo_AccurateImplementation(int seed, int range) ReferenceImplementations.AccurateDCT.TransformIDCTInplace(intData); float[] dest = new float[64]; - + ReferenceImplementations.GT_FloatingPoint_DCT.iDCT8x8GT(floatSrc, dest); this.CompareBlocks(intData.ConvertAllToFloat(), dest, 1f); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.StandardIntegerDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.StandardIntegerDCT.cs index f249aa93bf..f299807fc7 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.StandardIntegerDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.StandardIntegerDCT.cs @@ -2,7 +2,7 @@ using System; -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using Xunit; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs index 9c134ada9d..811af96757 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs @@ -40,7 +40,7 @@ public SpectralJpegTests(ITestOutputHelper output) public static readonly string[] AllTestJpegs = BaselineTestJpegs.Concat(ProgressiveTestJpegs).ToArray(); - [Theory] + [Theory(Skip = "Debug only, enable manually!")] [WithFileCollection(nameof(AllTestJpegs), PixelTypes.Rgba32)] public void PdfJsDecoder_ParseStream_SaveSpectralResult(TestImageProvider provider) where TPixel : struct, IPixel @@ -58,12 +58,12 @@ public void PdfJsDecoder_ParseStream_SaveSpectralResult(TestImageProvide } } - [Theory] + [Theory(Skip = "Debug only, enable manually!")] [WithFileCollection(nameof(AllTestJpegs), PixelTypes.Rgba32)] public void OriginalDecoder_ParseStream_SaveSpectralResult(TestImageProvider provider) where TPixel : struct, IPixel { - var decoder = new OrigJpegDecoderCore(Configuration.Default, new JpegDecoder()); + var decoder = new GolangJpegDecoderCore(Configuration.Default, new JpegDecoder()); byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes; @@ -81,7 +81,7 @@ private void VerifySpectralCorrectness( LibJpegTools.SpectralData imageSharpData) where TPixel : struct, IPixel { - var libJpegData = LibJpegTools.ExtractSpectralData(provider.SourceFileOrDescription); + LibJpegTools.SpectralData libJpegData = LibJpegTools.ExtractSpectralData(provider.SourceFileOrDescription); bool equality = libJpegData.Equals(imageSharpData); this.Output.WriteLine("Spectral data equality: " + equality); @@ -145,7 +145,7 @@ public void VerifySpectralCorrectness_PdfJs(TestImageProvider pr [Theory] [WithFileCollection(nameof(AllTestJpegs), PixelTypes.Rgba32)] - public void VerifySpectralResults_OriginalDecoder(TestImageProvider provider) + public void VerifySpectralCorrectness_Golang(TestImageProvider provider) where TPixel : struct, IPixel { if (!TestEnvironment.IsWindows) @@ -153,7 +153,7 @@ public void VerifySpectralResults_OriginalDecoder(TestImageProvider(Span data) { - StringBuilder bld = new StringBuilder(); + var bld = new StringBuilder(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) @@ -145,9 +146,9 @@ protected void Print(string msg) } internal void CompareBlocks(Block8x8 a, Block8x8 b, int tolerance) => - this.CompareBlocks(a.AsFloatBlock(), b.AsFloatBlock(), (float)tolerance + 1e-5f); + this.CompareBlocks(a.AsFloatBlock(), b.AsFloatBlock(), tolerance + 1e-5f); - internal void CompareBlocks(Block8x8F a, Block8x8F b, float tolerance) + internal void CompareBlocks(Block8x8F a, Block8x8F b, float tolerance) => this.CompareBlocks(a.ToArray(), b.ToArray(), tolerance); internal void CompareBlocks(Span a, Span b, float tolerance) @@ -170,16 +171,27 @@ internal void CompareBlocks(Span a, Span b, float tolerance) } } - this.Output.WriteLine("TOTAL DIFF: "+totalDifference); + this.Output.WriteLine("TOTAL DIFF: " + totalDifference); Assert.False(failed); } - internal static OrigJpegDecoderCore ParseStream(string testFileName, bool metaDataOnly = false) + internal static GolangJpegDecoderCore ParseGolangStream(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 OrigJpegDecoderCore(Configuration.Default, new JpegDecoder()); + var decoder = new PdfJsJpegDecoderCore(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 45df1d0fc4..90cc45e4aa 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs @@ -1,3 +1,5 @@ +using SixLabors.ImageSharp.Formats.Jpeg.Components; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils @@ -6,8 +8,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils using System.Linq; using System.Numerics; - using SixLabors.ImageSharp.Formats.Jpeg.Common; - using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; using SixLabors.ImageSharp.Memory; @@ -77,7 +77,7 @@ public static ComponentData Load(PdfJsFrameComponent c, int index) return result; } - public static ComponentData Load(OrigComponent c) + public static ComponentData Load(GolangComponent c) { var result = new ComponentData( c.SizeInBlocks.Width, diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs index d11b3d79b1..ae8194e1a9 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs @@ -1,8 +1,11 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + using System; using System.Linq; using System.Numerics; -using SixLabors.ImageSharp.Formats.Jpeg.Common; +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; @@ -37,9 +40,9 @@ public static SpectralData LoadFromImageSharpDecoder(PdfJsJpegDecoderCore decode return new SpectralData(destComponents); } - public static SpectralData LoadFromImageSharpDecoder(OrigJpegDecoderCore decoder) + public static SpectralData LoadFromImageSharpDecoder(GolangJpegDecoderCore decoder) { - OrigComponent[] srcComponents = decoder.Components; + GolangComponent[] srcComponents = decoder.Components; LibJpegTools.ComponentData[] destComponents = srcComponents.Select(LibJpegTools.ComponentData.Load).ToArray(); return new SpectralData(destComponents); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs index fd78d2ece8..3de4673f5d 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs @@ -4,7 +4,7 @@ using System.IO; using System.Numerics; -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { @@ -66,14 +66,14 @@ public static void RunDumpJpegCoeffsTool(string sourceFile, string destFile) string args = $@"""{sourceFile}"" ""{destFile}"""; var process = new Process - { - StartInfo = + { + StartInfo = { FileName = DumpToolFullPath, Arguments = args, WindowStyle = ProcessWindowStyle.Hidden } - }; + }; process.Start(); process.WaitForExit(); } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.AccurateDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.AccurateDCT.cs index 08ef40952b..2712d1933c 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.AccurateDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.AccurateDCT.cs @@ -1,6 +1,6 @@ using System; -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs index e3bae95c82..46f4fe14dc 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs @@ -3,7 +3,7 @@ using System.Numerics; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; using Xunit.Abstractions; @@ -520,7 +520,7 @@ internal static void fDCT1Dllm_32f(Span x, Span y) y[1] = c0 + c3; y[7] = c0 - c3; } - + internal static void fDCT2D_llm( Span s, Span d, diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.StandardIntegerDCT.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.StandardIntegerDCT.cs index 3d2cbe54f7..18c0bdb50e 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.StandardIntegerDCT.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.StandardIntegerDCT.cs @@ -1,7 +1,7 @@ // ReSharper disable InconsistentNaming using System; -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { @@ -88,7 +88,7 @@ public static Block8x8 TransformIDCT(ref Block8x8 block) result.LoadFrom(temp); return result; } - + /// /// Performs a forward DCT on an 8x8 block of coefficients, including a level shift. /// Leave results scaled up by an overall factor of 8. diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs index 3e3a732e75..f5940e05d4 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs @@ -6,7 +6,7 @@ using System; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Components; namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs index d0f7df12ce..296f424fa5 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; -using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; +using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Image/ImageCloneTests.cs b/tests/ImageSharp.Tests/Image/ImageCloneTests.cs index 82864f1562..82da5e2c45 100644 --- a/tests/ImageSharp.Tests/Image/ImageCloneTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageCloneTests.cs @@ -33,7 +33,10 @@ public void CloneAs_ToBgra32(TestImageProvider provider) } } - [Theory] + /// + /// https://github.com/SixLabors/ImageSharp/issues/576 + /// + [Theory(Skip = "See https://github.com/SixLabors/ImageSharp/issues/576")] [WithTestPatternImages(9, 9, PixelTypes.Rgba32)] public void CloneAs_ToBgr24(TestImageProvider provider) { diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 166943c3a0..85f12bc808 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -130,11 +130,12 @@ public class Issues { public const string CriticalEOF214 = "Jpg/issues/Issue214-CriticalEOF.jpg"; public const string MissingFF00ProgressiveGirl159 = "Jpg/issues/Issue159-MissingFF00-Progressive-Girl.jpg"; + public const string MissingFF00ProgressiveBedroom159 = "Jpg/issues/Issue159-MissingFF00-Progressive-Bedroom.jpg"; public const string BadCoeffsProgressive178 = "Jpg/issues/Issue178-BadCoeffsProgressive-Lemon.jpg"; public const string BadZigZagProgressive385 = "Jpg/issues/Issue385-BadZigZag-Progressive.jpg"; public const string MultiHuffmanBaseline394 = "Jpg/issues/Issue394-MultiHuffmanBaseline-Speakers.jpg"; - public const string NoEOI517 = "Jpg/issues/Issue517-No-EOI.jpg"; - public const string BadRST518 = "Jpg/issues/Issue518-Bad-RST.jpg"; + public const string NoEoiProgressive517 = "Jpg/issues/Issue517-No-EOI-Progressive.jpg"; + public const string BadRstProgressive518 = "Jpg/issues/Issue518-Bad-RST-Progressive.jpg"; } public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray(); diff --git a/tests/Images/External b/tests/Images/External index 8ab54f8003..8cff7b09d4 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 8ab54f8003aff94b3a9662b0be46b0062cad6b74 +Subproject commit 8cff7b09d4a3b8d975a35cf04885264e5765e108 diff --git a/tests/Images/Input/Jpg/issues/Issue159-MissingFF00-Progressive-Bedroom.jpg b/tests/Images/Input/Jpg/issues/Issue159-MissingFF00-Progressive-Bedroom.jpg new file mode 100644 index 0000000000..52a5832707 Binary files /dev/null and b/tests/Images/Input/Jpg/issues/Issue159-MissingFF00-Progressive-Bedroom.jpg differ diff --git a/tests/Images/Input/Jpg/issues/Issue517-No-EOI.jpg b/tests/Images/Input/Jpg/issues/Issue517-No-EOI-Progressive.jpg similarity index 100% rename from tests/Images/Input/Jpg/issues/Issue517-No-EOI.jpg rename to tests/Images/Input/Jpg/issues/Issue517-No-EOI-Progressive.jpg diff --git a/tests/Images/Input/Jpg/issues/Issue518-Bad-RST.jpg b/tests/Images/Input/Jpg/issues/Issue518-Bad-RST-Progressive.jpg similarity index 100% rename from tests/Images/Input/Jpg/issues/Issue518-Bad-RST.jpg rename to tests/Images/Input/Jpg/issues/Issue518-Bad-RST-Progressive.jpg