Browse Source

organizing classes

af/merge-core
Anton Firszov 9 years ago
parent
commit
92e93df8dd
  1. 1
      src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs
  2. 6
      src/ImageSharp/Formats/Jpeg/Common/Decoder/ComponentUtils.cs
  3. 2
      src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs
  4. 9
      src/ImageSharp/Formats/Jpeg/Common/Decoder/IRawJpegData.cs
  5. 2
      src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegComponentPostProcessor.cs
  6. 2
      src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs
  7. 29
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegBlockPostProcessor.cs
  8. 1
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs
  9. 5
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigJpegScanDecoder.cs
  10. 1
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrImage.cs
  11. 1
      src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs
  12. 1
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs
  13. 22
      tests/ImageSharp.Tests/Formats/Jpg/ComponentUtilsTests.cs
  14. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs
  15. 1
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs
  16. 34
      tests/ImageSharp.Tests/Formats/Jpg/Utils/VerifyJpeg.cs

1
src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs

@ -549,6 +549,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
{
val += 0.5f;
}
dest[i] = (short)val;
}
}

6
src/ImageSharp/Formats/Jpeg/Common/ComponentUtils.cs → 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
{
/// <summary>
/// Various utilities for <see cref="SubsampleRatio"/> and <see cref="IJpegComponent"/>.

2
src/ImageSharp/Formats/Jpeg/Common/IJpegComponent.cs → 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
{
/// <summary>
/// Common interface to represent raw Jpeg components.

9
src/ImageSharp/Formats/Jpeg/Common/IRawJpegData.cs → 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; }

2
src/ImageSharp/Formats/Jpeg/Common/PostProcessing/JpegComponentPostProcessor.cs → 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
{

2
src/ImageSharp/Formats/Jpeg/Common/PostProcessing/JpegImagePostProcessor.cs → 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
{

29
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;
/// <summary>
@ -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);
}
/// <summary>
@ -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
{
/// <summary>
/// Temporal block 1 to store intermediate and/or final computation results
/// Source block
/// </summary>
public Block8x8F SourceBlock;
/// <summary>
/// Temporal block 1 to store intermediate and/or final computation results
/// </summary>
public Block8x8F ResultBlock;
public Block8x8F WorkspaceBlock1;
/// <summary>
/// Temporal block 2 to store intermediate and/or final computation results
/// </summary>
public Block8x8F TempBlock;
public Block8x8F WorkspaceBlock2;
/// <summary>
/// The quantization table as <see cref="Block8x8F"/>
@ -159,14 +160,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
public Block8x8F* SourceBlock;
/// <summary>
/// Pointer to <see cref="ComputationData.ResultBlock"/>
/// Pointer to <see cref="ComputationData.WorkspaceBlock1"/>
/// </summary>
public Block8x8F* ResultBlock;
public Block8x8F* WorkspaceBlock1;
/// <summary>
/// Pointer to <see cref="ComputationData.TempBlock"/>
/// Pointer to <see cref="ComputationData.WorkspaceBlock2"/>
/// </summary>
public Block8x8F* TempBlock;
public Block8x8F* WorkspaceBlock2;
/// <summary>
/// Pointer to <see cref="ComputationData.QuantiazationTable"/>
@ -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;
}

1
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;
/// <inheritdoc cref="IJpegComponent" />

5
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;
/// <summary>
/// Encapsulates the impementation of Jpeg SOS Huffman decoding. See JpegScanDecoder.md!
///

1
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;
/// <summary>
/// Represents an image made up of three color components (luminance, blue chroma, red chroma)

1
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;

1
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;

22
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}");
}
}
}

2
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;

1
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;

34
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<IJpegComponent> 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<TPixel>(TestImageProvider<TPixel> provider, LibJpegTools.SpectralData data, ITestOutputHelper output = null)
internal static void SaveSpectralImage<TPixel>(
TestImageProvider<TPixel> provider,
LibJpegTools.SpectralData data,
ITestOutputHelper output = null)
where TPixel : struct, IPixel<TPixel>
{
foreach (LibJpegTools.ComponentData comp in data.Components)

Loading…
Cancel
Save