From 26d61124b590a64bb85fcebd569cf8bc26e0cd26 Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Mon, 29 Mar 2021 22:13:53 +0200 Subject: [PATCH] LuminanceForwardConverter handles the entire conversion itself --- .../Jpeg/Components/Encoder/L8ToYConverter.cs | 49 ------------------- .../LuminanceForwardConverter{TPixel}.cs | 14 +++--- 2 files changed, 7 insertions(+), 56 deletions(-) delete mode 100644 src/ImageSharp/Formats/Jpeg/Components/Encoder/L8ToYConverter.cs diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/L8ToYConverter.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/L8ToYConverter.cs deleted file mode 100644 index 6d787c58f..000000000 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/L8ToYConverter.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder -{ - /// - /// Provides 8-bit lookup tables for converting from L8 to Y colorspace. - /// - internal unsafe struct L8ToYConverter - { - /// - /// Initializes - /// - /// The initialized - public static L8ToYConverter Create() - { - L8ToYConverter converter = default; - return converter; - } - - /// - /// Optimized method to allocates the correct y, cb, and cr values to the DCT blocks from the given r, g, b values. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ConvertPixelInto( - int l, - ref Block8x8F yResult, - int i) => yResult[i] = l; - - public void Convert(Span l8Span, ref Block8x8F yBlock) - { - ref L8 l8Start = ref l8Span[0]; - - for (int i = 0; i < 64; i++) - { - ref L8 c = ref Unsafe.Add(ref l8Start, i); - - this.ConvertPixelInto( - c.PackedValue, - ref yBlock, - i); - } - } - } -} diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/LuminanceForwardConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/LuminanceForwardConverter{TPixel}.cs index 0b6cde826..cc81130dd 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/LuminanceForwardConverter{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/LuminanceForwardConverter{TPixel}.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; @@ -19,11 +20,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder /// public Block8x8F Y; - /// - /// The converter - /// - private L8ToYConverter converter; - /// /// Temporal 8x8 block to hold TPixel data /// @@ -37,7 +33,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder public static LuminanceForwardConverter Create() { var result = default(LuminanceForwardConverter); - result.converter = L8ToYConverter.Create(); return result; } @@ -52,8 +47,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder PixelOperations.Instance.ToL8(frame.GetConfiguration(), this.pixelBlock.AsSpanUnsafe(), l8Span); ref Block8x8F yBlock = ref this.Y; + ref L8 l8Start = ref l8Span[0]; - this.converter.Convert(l8Span, ref yBlock); + for (int i = 0; i < 64; i++) + { + ref L8 c = ref Unsafe.Add(ref l8Start, i); + yBlock[i] = c.PackedValue; + } } } }