Browse Source

Encode444 using YCbCrForwardConverter<TPixel>

pull/475/head
Anton Firszov 9 years ago
parent
commit
bcd33b608e
  1. 36
      src/ImageSharp/Formats/Jpeg/GolangPort/JpegEncoderCore.cs

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

@ -232,10 +232,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
this.WriteDefineHuffmanTables(componentCount); this.WriteDefineHuffmanTables(componentCount);
// Write the image data. // Write the image data.
using (PixelAccessor<TPixel> pixels = image.Lock()) this.WriteStartOfScan(image);
{
this.WriteStartOfScan(pixels);
}
// Write the End Of Image marker. // Write the End Of Image marker.
this.buffer[0] = OrigJpegConstants.Markers.XFF; this.buffer[0] = OrigJpegConstants.Markers.XFF;
@ -439,14 +436,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The pixel accessor providing access to the image pixels.</param> /// <param name="pixels">The pixel accessor providing access to the image pixels.</param>
private void Encode444<TPixel>(PixelAccessor<TPixel> pixels) private void Encode444<TPixel>(Image<TPixel> pixels)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
// TODO: Need a JpegScanEncoder<TPixel> class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) // TODO: Need a JpegScanEncoder<TPixel> class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.)
Block8x8F b = default(Block8x8F); // (Partially done with YCbCrForwardConverter<TPixel>)
Block8x8F cb = default(Block8x8F);
Block8x8F cr = default(Block8x8F);
Block8x8F temp1 = default(Block8x8F); Block8x8F temp1 = default(Block8x8F);
Block8x8F temp2 = default(Block8x8F); Block8x8F temp2 = default(Block8x8F);
@ -460,20 +454,16 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
YCbCrForwardConverter<TPixel> pixelConverter = YCbCrForwardConverter<TPixel>.Create(); YCbCrForwardConverter<TPixel> pixelConverter = YCbCrForwardConverter<TPixel>.Create();
fixed (RgbToYCbCrTables* tables = &rgbToYCbCrTables)
{
using (PixelArea<TPixel> rgbBytes = new PixelArea<TPixel>(8, 8, ComponentOrder.Xyz))
{
for (int y = 0; y < pixels.Height; y += 8) for (int y = 0; y < pixels.Height; y += 8)
{ {
for (int x = 0; x < pixels.Width; x += 8) for (int x = 0; x < pixels.Width; x += 8)
{ {
ToYCbCr(pixels, tables, x, y, ref b, ref cb, ref cr, rgbBytes); pixelConverter.Convert(pixels.Frames.RootFrame, x, y);
prevDCY = this.WriteBlock( prevDCY = this.WriteBlock(
QuantIndex.Luminance, QuantIndex.Luminance,
prevDCY, prevDCY,
&b, &pixelConverter.Y,
&temp1, &temp1,
&temp2, &temp2,
&onStackLuminanceQuantTable, &onStackLuminanceQuantTable,
@ -481,7 +471,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
prevDCCb = this.WriteBlock( prevDCCb = this.WriteBlock(
QuantIndex.Chrominance, QuantIndex.Chrominance,
prevDCCb, prevDCCb,
&cb, &pixelConverter.Cb,
&temp1, &temp1,
&temp2, &temp2,
&onStackChrominanceQuantTable, &onStackChrominanceQuantTable,
@ -489,7 +479,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
prevDCCr = this.WriteBlock( prevDCCr = this.WriteBlock(
QuantIndex.Chrominance, QuantIndex.Chrominance,
prevDCCr, prevDCCr,
&cr, &pixelConverter.Cr,
&temp1, &temp1,
&temp2, &temp2,
&onStackChrominanceQuantTable, &onStackChrominanceQuantTable,
@ -497,8 +487,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
} }
} }
} }
}
}
/// <summary> /// <summary>
/// Writes the application header containing the JFIF identifier plus extra data. /// Writes the application header containing the JFIF identifier plus extra data.
@ -866,8 +854,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
/// Writes the StartOfScan marker. /// Writes the StartOfScan marker.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The pixel accessor providing access to the image pixels.</param> /// <param name="image">The pixel accessor providing access to the image pixels.</param>
private void WriteStartOfScan<TPixel>(PixelAccessor<TPixel> pixels) private void WriteStartOfScan<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
// TODO: Need a JpegScanEncoder<TPixel> class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) // TODO: Need a JpegScanEncoder<TPixel> class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.)
@ -877,10 +865,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
switch (this.subsample) switch (this.subsample)
{ {
case JpegSubsample.Ratio444: case JpegSubsample.Ratio444:
this.Encode444(pixels); this.Encode444(image);
break; break;
case JpegSubsample.Ratio420: case JpegSubsample.Ratio420:
using (var pixels = image.Lock())
{
this.Encode420(pixels); this.Encode420(pixels);
}
break; break;
} }

Loading…
Cancel
Save