|
|
|
@ -2,6 +2,10 @@ |
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using SixLabors.ImageSharp.Advanced; |
|
|
|
using SixLabors.ImageSharp.Formats.Jpeg.Common; |
|
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder |
|
|
|
{ |
|
|
|
@ -95,16 +99,16 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder |
|
|
|
/// TODO: Replace this logic with SIMD conversion (similar to the one in the decoder)!
|
|
|
|
/// Optimized method to allocates the correct y, cb, and cr values to the DCT blocks from the given r, g, b values.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="tables">The reference to the tables instance.</param>
|
|
|
|
/// <param name="yBlockRaw">The The luminance block.</param>
|
|
|
|
/// <param name="cbBlockRaw">The red chroma block.</param>
|
|
|
|
/// <param name="crBlockRaw">The blue chroma block.</param>
|
|
|
|
/// <param name="tables">The reference to the tables instance.</param>
|
|
|
|
/// <param name="index">The current index.</param>
|
|
|
|
/// <param name="r">The red value.</param>
|
|
|
|
/// <param name="g">The green value.</param>
|
|
|
|
/// <param name="b">The blue value.</param>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static void Rgb2YCbCr(float* yBlockRaw, float* cbBlockRaw, float* crBlockRaw, ref RgbToYCbCrTables* tables, int index, int r, int g, int b) |
|
|
|
public static void Rgb2YCbCr(RgbToYCbCrTables* tables, float* yBlockRaw, float* cbBlockRaw, float* crBlockRaw, int index, int r, int g, int b) |
|
|
|
{ |
|
|
|
// float y = (0.299F * r) + (0.587F * g) + (0.114F * b);
|
|
|
|
yBlockRaw[index] = (tables->YRTable[r] + tables->YGTable[g] + tables->YBTable[b]) >> ScaleBits; |
|
|
|
@ -116,6 +120,27 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder |
|
|
|
crBlockRaw[index] = (tables->CbBTable[r] + tables->CrGTable[g] + tables->CrBTable[b]) >> ScaleBits; |
|
|
|
} |
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public void ConvertPixelInto(int r, int g, int b, ref float yResult, ref float cbResult, ref float crResult) |
|
|
|
{ |
|
|
|
ref int start = ref Unsafe.As<RgbToYCbCrTables, int>(ref this); |
|
|
|
|
|
|
|
ref int yR = ref start; |
|
|
|
ref int yG = ref Unsafe.Add(ref start, 256 * 1); |
|
|
|
ref int yB = ref Unsafe.Add(ref start, 256 * 2); |
|
|
|
|
|
|
|
ref int cbR = ref Unsafe.Add(ref start, 256 * 3); |
|
|
|
ref int cbG = ref Unsafe.Add(ref start, 256 * 4); |
|
|
|
ref int cbB = ref Unsafe.Add(ref start, 256 * 5); |
|
|
|
|
|
|
|
ref int crG = ref Unsafe.Add(ref start, 256 * 6); |
|
|
|
ref int crB = ref Unsafe.Add(ref start, 256 * 7); |
|
|
|
|
|
|
|
yResult = (Unsafe.Add(ref yR, r) + Unsafe.Add(ref yG, g) + Unsafe.Add(ref yB, b)) >> ScaleBits; |
|
|
|
cbResult = (Unsafe.Add(ref cbR, r) + Unsafe.Add(ref cbG, g) + Unsafe.Add(ref cbB, b)) >> ScaleBits; |
|
|
|
crResult = (Unsafe.Add(ref cbB, r) + Unsafe.Add(ref crG, g) + Unsafe.Add(ref crB, b)) >> ScaleBits; |
|
|
|
} |
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
private static int Fix(float x) |
|
|
|
{ |
|
|
|
@ -128,4 +153,33 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder |
|
|
|
return x >> ScaleBits; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// TODO!
|
|
|
|
internal struct YCbCrForwardConverter<TPixel> |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
public Block8x8F Y; |
|
|
|
|
|
|
|
public Block8x8F Cb; |
|
|
|
|
|
|
|
public Block8x8F Cr; |
|
|
|
|
|
|
|
private RgbToYCbCrTables colorTables; |
|
|
|
|
|
|
|
private GenericBlock8x8<TPixel> pixelBlock; |
|
|
|
|
|
|
|
private GenericBlock8x8<Rgb24> rgbBlock; |
|
|
|
|
|
|
|
public static YCbCrForwardConverter<TPixel> Create() |
|
|
|
{ |
|
|
|
var result = default(YCbCrForwardConverter<TPixel>); |
|
|
|
result.colorTables = RgbToYCbCrTables.Create(); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public void Convert(IPixelSource<TPixel> pixels, int x, int y) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |