Browse Source

Use luminance quant table for all channel with RGB

pull/1734/head
Brian Popow 5 years ago
parent
commit
612f7914e4
  1. 25
      src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
  2. 24
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

25
src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs

@ -237,9 +237,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The pixel accessor providing access to the image pixels.</param>
/// <param name="luminanceQuantTable">Luminance quantization table provided by the callee.</param>
/// <param name="chrominanceQuantTable">Chrominance quantization table provided by the callee.</param>
/// <param name="cancellationToken">The token to monitor for cancellation.</param>
public void EncodeRgb<TPixel>(Image<TPixel> pixels, ref Block8x8F luminanceQuantTable, ref Block8x8F chrominanceQuantTable, CancellationToken cancellationToken)
public void EncodeRgb<TPixel>(Image<TPixel> pixels, ref Block8x8F luminanceQuantTable, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
{
this.huffmanTables = HuffmanLut.TheHuffmanLut;
@ -247,7 +246,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
var unzig = ZigZag.CreateUnzigTable();
// ReSharper disable once InconsistentNaming
int prevDCY = 0, prevDCCb = 0, prevDCCr = 0;
int prevDCR = 0, prevDCG = 0, prevDCB = 0;
ImageFrame<TPixel> frame = pixels.Frames.RootFrame;
Buffer2D<TPixel> pixelBuffer = frame.PixelBuffer;
@ -264,25 +263,25 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
{
pixelConverter.Convert(x, y, ref currentRows);
prevDCY = this.WriteBlock(
prevDCR = this.WriteBlock(
QuantIndex.Luminance,
prevDCY,
prevDCR,
ref pixelConverter.R,
ref luminanceQuantTable,
ref unzig);
prevDCCb = this.WriteBlock(
QuantIndex.Chrominance,
prevDCCb,
prevDCG = this.WriteBlock(
QuantIndex.Luminance,
prevDCG,
ref pixelConverter.G,
ref chrominanceQuantTable,
ref luminanceQuantTable,
ref unzig);
prevDCCr = this.WriteBlock(
QuantIndex.Chrominance,
prevDCCr,
prevDCB = this.WriteBlock(
QuantIndex.Luminance,
prevDCB,
ref pixelConverter.B,
ref chrominanceQuantTable,
ref luminanceQuantTable,
ref unzig);
}
}

24
src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

@ -160,7 +160,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
scanEncoder.Encode420(image, ref luminanceQuantTable, ref chrominanceQuantTable, cancellationToken);
break;
case JpegColorType.Rgb:
scanEncoder.EncodeRgb(image, ref luminanceQuantTable, ref chrominanceQuantTable, cancellationToken);
scanEncoder.EncodeRgb(image, ref luminanceQuantTable, cancellationToken);
break;
}
}
@ -620,6 +620,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
0x11,
0x11
};
if (this.colorType == JpegColorType.Rgb)
{
chroma = stackalloc byte[]
{
0x00,
0x00,
0x00
};
}
break;
case JpegColorType.YCbCrRatio420:
subsamples = stackalloc byte[]
@ -669,6 +680,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
0x11
};
// Use the same DC/AC tables for all channels for RGB.
if (this.colorType == JpegColorType.Rgb)
{
huffmanId = stackalloc byte[]
{
0x00,
0x00,
0x00
};
}
// Write the SOS (Start Of Scan) marker "\xff\xda" followed by 12 bytes:
// - the marker length "\x00\x0c",
// - the number of components "\x03",

Loading…
Cancel
Save