diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
index 5468d93c4..4b74400ca 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
@@ -237,9 +237,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
/// The pixel format.
/// The pixel accessor providing access to the image pixels.
/// Luminance quantization table provided by the callee.
- /// Chrominance quantization table provided by the callee.
/// The token to monitor for cancellation.
- public void EncodeRgb(Image pixels, ref Block8x8F luminanceQuantTable, ref Block8x8F chrominanceQuantTable, CancellationToken cancellationToken)
+ public void EncodeRgb(Image pixels, ref Block8x8F luminanceQuantTable, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel
{
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 frame = pixels.Frames.RootFrame;
Buffer2D 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);
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
index 7f411ee53..48b7d267a 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
+++ b/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",