From 92e93df8dd41007a925c3d12d85119932d3e0b1e Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Wed, 30 Aug 2017 00:05:19 +0200 Subject: [PATCH] organizing classes --- .../Formats/Jpeg/Common/Block8x8F.cs | 1 + .../Common/{ => Decoder}/ComponentUtils.cs | 6 ++-- .../Common/{ => Decoder}/IJpegComponent.cs | 2 +- .../Jpeg/Common/{ => Decoder}/IRawJpegData.cs | 9 ++--- .../JpegComponentPostProcessor.cs | 2 +- .../JpegImagePostProcessor.cs | 2 +- .../Decoder/JpegBlockPostProcessor.cs | 29 ++++++++-------- .../Components/Decoder/OrigComponent.cs | 1 + .../Components/Decoder/OrigJpegScanDecoder.cs | 5 ++- .../Components/Decoder/YCbCrImage.cs | 1 + .../Jpeg/GolangPort/OrigJpegDecoderCore.cs | 1 + .../Components/PdfJsFrameComponent.cs | 1 + .../Formats/Jpg/ComponentUtilsTests.cs | 22 ++++++------ .../Jpg/JpegImagePostProcessorTests.cs | 2 +- .../Jpg/Utils/LibJpegTools.ComponentData.cs | 1 + .../Formats/Jpg/Utils/VerifyJpeg.cs | 34 +++++++++++-------- 16 files changed, 64 insertions(+), 55 deletions(-) rename src/ImageSharp/Formats/Jpeg/Common/{ => Decoder}/ComponentUtils.cs (97%) rename src/ImageSharp/Formats/Jpeg/Common/{ => Decoder}/IJpegComponent.cs (96%) rename src/ImageSharp/Formats/Jpeg/Common/{ => Decoder}/IRawJpegData.cs (72%) rename src/ImageSharp/Formats/Jpeg/Common/{PostProcessing => Decoder}/JpegComponentPostProcessor.cs (97%) rename src/ImageSharp/Formats/Jpeg/Common/{PostProcessing => Decoder}/JpegImagePostProcessor.cs (98%) diff --git a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs index d1783d323b..d542464824 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs @@ -549,6 +549,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common { val += 0.5f; } + dest[i] = (short)val; } } diff --git a/src/ImageSharp/Formats/Jpeg/Common/ComponentUtils.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ComponentUtils.cs similarity index 97% rename from src/ImageSharp/Formats/Jpeg/Common/ComponentUtils.cs rename to src/ImageSharp/Formats/Jpeg/Common/Decoder/ComponentUtils.cs index 0b89dd1645..a051df809d 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/ComponentUtils.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ComponentUtils.cs @@ -1,10 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; - using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder { /// /// Various utilities for and . diff --git a/src/ImageSharp/Formats/Jpeg/Common/IJpegComponent.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs similarity index 96% rename from src/ImageSharp/Formats/Jpeg/Common/IJpegComponent.cs rename to src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs index dcd18f9098..89c400bb08 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/IJpegComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs @@ -1,7 +1,7 @@ using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder { /// /// Common interface to represent raw Jpeg components. diff --git a/src/ImageSharp/Formats/Jpeg/Common/IRawJpegData.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/IRawJpegData.cs similarity index 72% rename from src/ImageSharp/Formats/Jpeg/Common/IRawJpegData.cs rename to src/ImageSharp/Formats/Jpeg/Common/Decoder/IRawJpegData.cs index 9ffd18d50b..afc1472d09 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/IRawJpegData.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/IRawJpegData.cs @@ -1,8 +1,9 @@ -using System.Collections.Generic; -using SixLabors.Primitives; - -namespace SixLabors.ImageSharp.Formats.Jpeg.Common +namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder { + using System.Collections.Generic; + + using SixLabors.Primitives; + internal interface IRawJpegData { Size ImageSizeInPixels { get; } diff --git a/src/ImageSharp/Formats/Jpeg/Common/PostProcessing/JpegComponentPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegComponentPostProcessor.cs similarity index 97% rename from src/ImageSharp/Formats/Jpeg/Common/PostProcessing/JpegComponentPostProcessor.cs rename to src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegComponentPostProcessor.cs index 16071b17cd..585843f8fa 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/PostProcessing/JpegComponentPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegComponentPostProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.PostProcessing +namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder { internal class JpegComponentPostProcessor : IDisposable { diff --git a/src/ImageSharp/Formats/Jpeg/Common/PostProcessing/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs similarity index 98% rename from src/ImageSharp/Formats/Jpeg/Common/PostProcessing/JpegImagePostProcessor.cs rename to src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs index 92ed621e97..535863e4b8 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/PostProcessing/JpegImagePostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs @@ -7,7 +7,7 @@ using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.YCbCrColorSapce using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.PostProcessing +namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder { internal class JpegImagePostProcessor : IDisposable { diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegBlockPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegBlockPostProcessor.cs index 08cf1eb604..7399530997 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegBlockPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegBlockPostProcessor.cs @@ -10,6 +10,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { using System.Runtime.CompilerServices; + using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.Primitives; /// @@ -64,7 +65,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder Block8x8F.QuantizeBlock(b, this.pointers.QuantiazationTable, this.pointers.Unzig); - FastFloatingPointDCT.TransformIDCT(ref *b, ref this.data.ResultBlock, ref this.data.TempBlock); + FastFloatingPointDCT.TransformIDCT(ref *b, ref this.data.WorkspaceBlock1, ref this.data.WorkspaceBlock2); } public void ProcessBlockColorsInto( @@ -75,15 +76,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { this.QuantizeAndTransform(decoder, component, ref sourceBlock); - this.data.ResultBlock.NormalizeColorsInplace(); + this.data.WorkspaceBlock1.NormalizeColorsInplace(); Size divs = component.SubSamplingDivisors; // To conform better to libjpeg we actually NEED TO loose precision here. // This is because they store blocks as Int16 between all the operations. // Unfortunately, we need to emulate this to be "more accurate" :( - this.data.ResultBlock.RoundInplace(); + this.data.WorkspaceBlock1.RoundInplace(); - this.data.ResultBlock.CopyTo(destArea, divs.Width, divs.Height); + this.data.WorkspaceBlock1.CopyTo(destArea, divs.Width, divs.Height); } /// @@ -101,7 +102,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder OrigJpegPixelArea destChannel = decoder.GetDestinationChannel(component.Index); OrigJpegPixelArea destArea = destChannel.GetOffsetedSubAreaForBlock(bx, by); - destArea.LoadColorsFrom(this.pointers.ResultBlock, this.pointers.TempBlock); + destArea.LoadColorsFrom(this.pointers.WorkspaceBlock1, this.pointers.WorkspaceBlock2); } @@ -112,19 +113,19 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder public struct ComputationData { /// - /// Temporal block 1 to store intermediate and/or final computation results + /// Source block /// public Block8x8F SourceBlock; /// /// Temporal block 1 to store intermediate and/or final computation results /// - public Block8x8F ResultBlock; + public Block8x8F WorkspaceBlock1; /// /// Temporal block 2 to store intermediate and/or final computation results /// - public Block8x8F TempBlock; + public Block8x8F WorkspaceBlock2; /// /// The quantization table as @@ -159,14 +160,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder public Block8x8F* SourceBlock; /// - /// Pointer to + /// Pointer to /// - public Block8x8F* ResultBlock; + public Block8x8F* WorkspaceBlock1; /// - /// Pointer to + /// Pointer to /// - public Block8x8F* TempBlock; + public Block8x8F* WorkspaceBlock2; /// /// Pointer to @@ -185,8 +186,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder internal DataPointers(ComputationData* dataPtr) { this.SourceBlock = &dataPtr->SourceBlock; - this.ResultBlock = &dataPtr->ResultBlock; - this.TempBlock = &dataPtr->TempBlock; + this.WorkspaceBlock1 = &dataPtr->WorkspaceBlock1; + this.WorkspaceBlock2 = &dataPtr->WorkspaceBlock2; this.QuantiazationTable = &dataPtr->QuantiazationTable; this.Unzig = dataPtr->Unzig.Data; } diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs index 49bbc8f477..6fb501a652 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs @@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { + using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.Primitives; /// diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs index 660418eb0c..9bab18d09d 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs @@ -3,14 +3,13 @@ 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 Block8x8F = SixLabors.ImageSharp.Formats.Jpeg.Common.Block8x8F; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { - using SixLabors.ImageSharp.Formats.Jpeg.Common; - /// /// Encapsulates the impementation of Jpeg SOS Huffman decoding. See JpegScanDecoder.md! /// diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrImage.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrImage.cs index 72a25ecd77..c56d2d3417 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrImage.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrImage.cs @@ -8,6 +8,7 @@ using SixLabors.Primitives; namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { using SixLabors.ImageSharp.Formats.Jpeg.Common; + using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; /// /// Represents an image made up of three color components (luminance, blue chroma, red chroma) diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs index 3e185db415..6ff71af635 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs @@ -9,6 +9,7 @@ using System.Numerics; using System.Runtime.CompilerServices; using System.Threading.Tasks; using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs index 3320b8a8c4..f60097dc9c 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ComponentUtilsTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/ComponentUtilsTests.cs index 053eadf27e..c5f3dcc73f 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ComponentUtilsTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ComponentUtilsTests.cs @@ -2,15 +2,17 @@ // Licensed under the Apache License, Version 2.0. // ReSharper disable InconsistentNaming -namespace SixLabors.ImageSharp.Tests.Formats.Jpg -{ - using SixLabors.ImageSharp.Formats.Jpeg.Common; - using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; - using SixLabors.Primitives; - using Xunit; - using Xunit.Abstractions; +using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; +using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; +using SixLabors.Primitives; + +using Xunit; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests.Formats.Jpg +{ public class ComponentUtilsTests { public ComponentUtilsTests(ITestOutputHelper output) @@ -27,10 +29,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [InlineData(SubsampleRatio.Ratio422, 2, 1)] [InlineData(SubsampleRatio.Ratio440, 1, 2)] [InlineData(SubsampleRatio.Ratio444, 1, 1)] - internal void CalculateChrominanceSize( - SubsampleRatio ratio, - int expectedDivX, - int expectedDivY) + internal void CalculateChrominanceSize(SubsampleRatio ratio, int expectedDivX, int expectedDivY) { //this.Output.WriteLine($"RATIO: {ratio}"); Size size = ratio.CalculateChrominanceSize(400, 400); @@ -81,6 +80,5 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { this.Output.WriteLine($"{name}: Stride={channel.Stride}"); } - } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs index c1544e5b19..871321df9d 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs @@ -1,6 +1,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { - using SixLabors.ImageSharp.Formats.Jpeg.Common.PostProcessing; + using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs index 1caaa081ea..8ccd2f63c1 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs @@ -5,6 +5,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils 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; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs index 6d0c1ac7e0..d0f7df12ce 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs @@ -1,15 +1,15 @@ -namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils -{ - using System.Collections.Generic; - using System.Linq; +using System.Collections.Generic; +using System.Linq; - using SixLabors.ImageSharp.Formats.Jpeg.Common; - using SixLabors.ImageSharp.PixelFormats; - using SixLabors.Primitives; +using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; - using Xunit; - using Xunit.Abstractions; +using Xunit; +using Xunit.Abstractions; +namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils +{ internal static class VerifyJpeg { internal static void VerifySize(IJpegComponent component, int expectedBlocksX, int expectedBlocksY) @@ -27,12 +27,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils Assert.Equal(expectedSamplingFactors, component.SamplingFactors); Assert.Equal(expectedSubsamplingDivisors, component.SubSamplingDivisors); } - + internal static void VerifyComponentSizes3( IEnumerable components, - int xBc0, int yBc0, - int xBc1, int yBc1, - int xBc2, int yBc2) + int xBc0, + int yBc0, + int xBc1, + int yBc1, + int xBc2, + int yBc2) { IJpegComponent[] c = components.ToArray(); Assert.Equal(3, components.Count()); @@ -42,7 +45,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils VerifySize(c[2], xBc2, yBc2); } - internal static void SaveSpectralImage(TestImageProvider provider, LibJpegTools.SpectralData data, ITestOutputHelper output = null) + internal static void SaveSpectralImage( + TestImageProvider provider, + LibJpegTools.SpectralData data, + ITestOutputHelper output = null) where TPixel : struct, IPixel { foreach (LibJpegTools.ComponentData comp in data.Components)