From 12b4b83cb6df5499d0b2211ae8ddf4d6b7e88363 Mon Sep 17 00:00:00 2001 From: Dmitry Pentin Date: Sun, 30 May 2021 18:21:36 +0300 Subject: [PATCH] 444 converter fixes --- .../YCbCrForwardConverter444{TPixel}.cs | 42 ++++++------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter444{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter444{TPixel}.cs index 58bb1d559d..8fef553026 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter444{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter444{TPixel}.cs @@ -16,6 +16,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder internal ref struct YCbCrForwardConverter444 where TPixel : unmanaged, IPixel { + // TODO: documentation + private const int RgbSpanByteSize = 8 * 8 * 3; + // TODO: documentation + private const int PixelSpanSize = 8 * 8; + + /// /// The Y component /// @@ -37,29 +43,26 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder private RgbToYCbCrConverterLut colorTables; /// - /// Temporal 8x8 block to hold TPixel data + /// Temporal 64-byte span to hold unconverted TPixel data /// private Span pixelSpan; /// - /// Temporal RGB block + /// Temporal 64-byte span to hold converted Rgb24 data /// private Span rgbSpan; - public Span twinBlocksY; - public static YCbCrForwardConverter444 Create() { var result = default(YCbCrForwardConverter444); // creating rgb pixel bufferr // TODO: this is subject to discuss - const int twoBlocksByteSizeWithPadding = 384 + 8; // converter.Convert comments for +8 padding - result.rgbSpan = MemoryMarshal.Cast(new byte[twoBlocksByteSizeWithPadding].AsSpan()); - // TODO: this size should be configurable - result.pixelSpan = new TPixel[128].AsSpan(); + // converter.Convert comments for +8 padding + result.rgbSpan = MemoryMarshal.Cast(new byte[RgbSpanByteSize + 8].AsSpan()); - result.twinBlocksY = new Block8x8F[2].AsSpan(); + // TODO: this is subject to discuss + result.pixelSpan = new TPixel[PixelSpanSize].AsSpan(); // Avoid creating lookup tables, when vectorized converter is supported if (!RgbToYCbCrConverterVectorized.IsSupported) @@ -93,26 +96,5 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder this.colorTables.Convert(this.rgbSpan, ref yBlock, ref cbBlock, ref crBlock); } } - - /// - /// Converts a 8x8 image area inside 'pixels' at position (x,y) placing the result members of the structure (, , ) - /// - public void Convert420(ImageFrame frame, int x, int y, ref RowOctet currentRows, int idx) - { - Memory.Buffer2D buffer = frame.PixelBuffer; - YCbCrForwardConverter.LoadAndStretchEdges(currentRows, this.pixelSpan, new Point(x, y), new Size(16, 8), new Size(buffer.Width, buffer.Height)); - - PixelOperations.Instance.ToRgb24(frame.GetConfiguration(), this.pixelSpan, this.rgbSpan); - - if (RgbToYCbCrConverterVectorized.IsSupported) - { - RgbToYCbCrConverterVectorized.Convert420_16x8(this.rgbSpan, this.twinBlocksY, ref this.Cb, ref this.Cr, idx); - } - else - { - throw new NotSupportedException("This is not yet implemented"); - //this.colorTables.Convert(this.rgbSpan, ref yBlock, ref cbBlock, ref crBlock); - } - } } }