Browse Source

YCbCrForwardConverter<TPixel>

af/merge-core
Anton Firszov 8 years ago
parent
commit
e2cf90e683
  1. 24
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/RgbToYCbCrTables.cs
  2. 23
      src/ImageSharp/Formats/Jpeg/GolangPort/JpegEncoderCore.cs

24
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/RgbToYCbCrTables.cs

@ -9,6 +9,8 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder
{
using System;
/// <summary>
/// Provides 8-bit lookup tables for converting from Rgb to YCbCr colorspace.
/// Methods to build the tables are based on libjpeg implementation.
@ -179,7 +181,29 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder
public void Convert(IPixelSource<TPixel> pixels, int x, int y)
{
this.pixelBlock.LoadAndStretchEdges(pixels, x, y);
Span<Rgb24> rgbSpan = this.rgbBlock.AsSpanUnsafe();
PixelOperations<TPixel>.Instance.ToRgb24(this.pixelBlock.AsSpanUnsafe(), rgbSpan, 64);
ref float yBlockStart = ref Unsafe.As<Block8x8F, float>(ref this.Y);
ref float cbBlockStart = ref Unsafe.As<Block8x8F, float>(ref this.Cb);
ref float crBlockStart = ref Unsafe.As<Block8x8F, float>(ref this.Cr);
ref Rgb24 rgbStart = ref rgbSpan[0];
for (int i = 0; i < 64; i++)
{
ref Rgb24 c = ref Unsafe.Add(ref rgbStart, i);
this.colorTables.ConvertPixelInto(
c.R,
c.G,
c.B,
ref Unsafe.Add(ref yBlockStart, i),
ref Unsafe.Add(ref cbBlockStart, i),
ref Unsafe.Add(ref crBlockStart, i)
);
}
}
}
}

23
src/ImageSharp/Formats/Jpeg/GolangPort/JpegEncoderCore.cs

@ -313,11 +313,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
ref float cbBlockStart = ref Unsafe.As<Block8x8F, float>(ref cbBlock);
ref float crBlockStart = ref Unsafe.As<Block8x8F, float>(ref crBlock);
float* yBlockRaw = (float*) Unsafe.AsPointer(ref yBlock);
float* cbBlockRaw = (float*)Unsafe.AsPointer(ref cbBlock);
float* crBlockRaw = (float*)Unsafe.AsPointer(ref crBlock);
rgbBytes.Reset();
pixels.CopyRGBBytesStretchedTo(rgbBytes, y, x);
ref byte data0 = ref rgbBytes.Bytes[0];
@ -335,14 +330,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
int index = j8 + i;
RgbToYCbCrTables.Rgb2YCbCr(tables, yBlockRaw, cbBlockRaw, crBlockRaw, index, r, g, b);
//tables->ConvertPixelInto(
// r,
// g,
// b,
// ref Unsafe.Add(ref yBlockRaw, index),
// ref Unsafe.Add(ref cbBlockRaw, index),
// ref Unsafe.Add(ref crBlockRaw, index));
// RgbToYCbCrTables.Rgb2YCbCr(tables, yBlockRaw, cbBlockRaw, crBlockRaw, index, r, g, b);
tables->ConvertPixelInto(
r,
g,
b,
ref Unsafe.Add(ref yBlockStart, index),
ref Unsafe.Add(ref cbBlockStart, index),
ref Unsafe.Add(ref crBlockStart, index));
dataIdx += 3;
}
@ -463,6 +458,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
// ReSharper disable once InconsistentNaming
int prevDCY = 0, prevDCCb = 0, prevDCCr = 0;
YCbCrForwardConverter<TPixel> pixelConverter = YCbCrForwardConverter<TPixel>.Create();
fixed (RgbToYCbCrTables* tables = &rgbToYCbCrTables)
{
using (PixelArea<TPixel> rgbBytes = new PixelArea<TPixel>(8, 8, ComponentOrder.Xyz))

Loading…
Cancel
Save