Browse Source

LuminanceForwardConverter handles the entire conversion itself

pull/1586/head
Ynse Hoornenborg 5 years ago
parent
commit
26d61124b5
  1. 49
      src/ImageSharp/Formats/Jpeg/Components/Encoder/L8ToYConverter.cs
  2. 14
      src/ImageSharp/Formats/Jpeg/Components/Encoder/LuminanceForwardConverter{TPixel}.cs

49
src/ImageSharp/Formats/Jpeg/Components/Encoder/L8ToYConverter.cs

@ -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
{
/// <summary>
/// Provides 8-bit lookup tables for converting from L8 to Y colorspace.
/// </summary>
internal unsafe struct L8ToYConverter
{
/// <summary>
/// Initializes
/// </summary>
/// <returns>The initialized <see cref="L8ToYConverter"/></returns>
public static L8ToYConverter Create()
{
L8ToYConverter converter = default;
return converter;
}
/// <summary>
/// Optimized method to allocates the correct y, cb, and cr values to the DCT blocks from the given r, g, b values.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ConvertPixelInto(
int l,
ref Block8x8F yResult,
int i) => yResult[i] = l;
public void Convert(Span<L8> 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);
}
}
}
}

14
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
/// </summary>
public Block8x8F Y;
/// <summary>
/// The converter
/// </summary>
private L8ToYConverter converter;
/// <summary>
/// Temporal 8x8 block to hold TPixel data
/// </summary>
@ -37,7 +33,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
public static LuminanceForwardConverter<TPixel> Create()
{
var result = default(LuminanceForwardConverter<TPixel>);
result.converter = L8ToYConverter.Create();
return result;
}
@ -52,8 +47,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
PixelOperations<TPixel>.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;
}
}
}
}

Loading…
Cancel
Save