Browse Source

Removed precision parameter, removed YccK color space

pull/2120/head
Dmitry Pentin 4 years ago
parent
commit
dfb2053847
  1. 4
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrScalar.cs
  2. 9
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccKScalar.cs
  3. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccKVector.cs
  4. 2
      src/ImageSharp/Formats/Jpeg/Components/Encoder/JpegFrame.cs
  5. 5
      src/ImageSharp/Formats/Jpeg/JpegColorType.cs
  6. 5
      src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
  7. 15
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

4
src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYCbCrScalar.cs

@ -67,8 +67,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
// cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b) // cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b)
// cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b) // cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b)
c0[i] = (0.299f * r) + (0.587f * g) + (0.114f * b); c0[i] = (0.299f * r) + (0.587f * g) + (0.114f * b);
c1[i] = 128 - (0.168736f * r) - (0.331264f * g) + (0.5f * b); c1[i] = halfValue - (0.168736f * r) - (0.331264f * g) + (0.5f * b);
c2[i] = 128 + (0.5f * r) - (0.418688f * g) - (0.081312f * b); c2[i] = halfValue + (0.5f * r) - (0.418688f * g) - (0.081312f * b);
} }
} }
} }

9
src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccKScalar.cs

@ -15,9 +15,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
} }
public override void ConvertToRgbInplace(in ComponentValues values) => public override void ConvertToRgbInplace(in ComponentValues values) =>
ConvertCoreInplace(values, this.MaximumValue, this.HalfValue); ConvertToRgpInplace(values, this.MaximumValue, this.HalfValue);
internal static void ConvertCoreInplace(in ComponentValues values, float maxValue, float halfValue) public override void ConvertFromRgbInplace(in ComponentValues values)
=> throw new NotImplementedException();
public static void ConvertToRgpInplace(in ComponentValues values, float maxValue, float halfValue)
{ {
Span<float> c0 = values.Component0; Span<float> c0 = values.Component0;
Span<float> c1 = values.Component1; Span<float> c1 = values.Component1;
@ -38,8 +41,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
c2[i] = (maxValue - MathF.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero)) * scaledK; c2[i] = (maxValue - MathF.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero)) * scaledK;
} }
} }
public override void ConvertFromRgbInplace(in ComponentValues values) => throw new NotImplementedException();
} }
} }
} }

2
src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromYccKVector.cs

@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
} }
protected override void ConvertCoreInplaceToRgb(in ComponentValues values) => protected override void ConvertCoreInplaceToRgb(in ComponentValues values) =>
FromYccKScalar.ConvertCoreInplace(values, this.MaximumValue, this.HalfValue); FromYccKScalar.ConvertToRgpInplace(values, this.MaximumValue, this.HalfValue);
protected override void ConvertCoreVectorizedInplaceFromRgb(in ComponentValues values) => throw new System.NotImplementedException(); protected override void ConvertCoreVectorizedInplaceFromRgb(in ComponentValues values) => throw new System.NotImplementedException();

2
src/ImageSharp/Formats/Jpeg/Components/Encoder/JpegFrame.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
/// </summary> /// </summary>
internal sealed class JpegFrame : IDisposable internal sealed class JpegFrame : IDisposable
{ {
public JpegFrame(Jpeg.JpegFrameConfig frameConfig, MemoryAllocator allocator, Image image, Decoder.JpegColorSpace colorSpace) public JpegFrame(JpegFrameConfig frameConfig, MemoryAllocator allocator, Image image, Decoder.JpegColorSpace colorSpace)
{ {
this.ColorSpace = colorSpace; this.ColorSpace = colorSpace;

5
src/ImageSharp/Formats/Jpeg/JpegColorType.cs

@ -58,10 +58,5 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// CMYK colorspace (cyan, magenta, yellow, and key black) intended for printing. /// CMYK colorspace (cyan, magenta, yellow, and key black) intended for printing.
/// </summary> /// </summary>
Cmyk = 7, Cmyk = 7,
/// <summary>
/// YCCK colorspace.
/// </summary>
YccK = 8,
} }
} }

5
src/ImageSharp/Formats/Jpeg/JpegEncoder.cs

@ -53,10 +53,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
public class JpegFrameConfig public class JpegFrameConfig
{ {
public JpegFrameConfig(JpegColorType colorType, int precision) public JpegFrameConfig(JpegColorType colorType)
{ {
this.ColorType = colorType; this.ColorType = colorType;
this.Precision = precision;
int componentCount = GetComponentCountFromColorType(colorType); int componentCount = GetComponentCountFromColorType(colorType);
this.Components = new JpegComponentConfig[componentCount]; this.Components = new JpegComponentConfig[componentCount];
@ -85,8 +84,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
public JpegColorType ColorType { get; } public JpegColorType ColorType { get; }
public int Precision { get; }
public JpegComponentConfig[] Components { get; } public JpegComponentConfig[] Components { get; }
public JpegFrameConfig PopulateComponent(int index, byte id, int hsf, int vsf, int quantIndex, int dcIndex, int acIndex) public JpegFrameConfig PopulateComponent(int index, byte id, int hsf, int vsf, int quantIndex, int dcIndex, int acIndex)

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

@ -87,12 +87,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
ImageMetadata metadata = image.Metadata; ImageMetadata metadata = image.Metadata;
JpegMetadata jpegMetadata = metadata.GetJpegMetadata(); JpegMetadata jpegMetadata = metadata.GetJpegMetadata();
// Compute number of components based on color type in options.
int componentCount = (this.colorType == JpegColorType.Luminance) ? 1 : 3;
// TODO: Right now encoder writes both quantization tables for grayscale images - we shouldn't do that // TODO: Right now encoder writes both quantization tables for grayscale images - we shouldn't do that
// Initialize the quantization tables. // Initialize the quantization tables.
this.InitQuantizationTables(componentCount, jpegMetadata, out Block8x8F luminanceQuantTable, out Block8x8F chrominanceQuantTable); this.InitQuantizationTables(this.frameConfig.Components.Length, jpegMetadata, out Block8x8F luminanceQuantTable, out Block8x8F chrominanceQuantTable);
// Write the Start Of Image marker. // Write the Start Of Image marker.
this.WriteStartOfImage(); this.WriteStartOfImage();
@ -116,13 +113,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
this.WriteDefineQuantizationTables(ref luminanceQuantTable, ref chrominanceQuantTable); this.WriteDefineQuantizationTables(ref luminanceQuantTable, ref chrominanceQuantTable);
// Write the image dimensions. // Write the image dimensions.
this.WriteStartOfFrame(image.Width, image.Height, this.frameConfig.Components); this.WriteStartOfFrame(image.Width, image.Height, this.frameConfig);
// Write the Huffman tables. // Write the Huffman tables.
this.WriteDefineHuffmanTables(componentCount); this.WriteDefineHuffmanTables(this.frameConfig.Components.Length);
// Write the scan header. // Write the scan header.
this.WriteStartOfScan(componentCount, this.frameConfig.Components); this.WriteStartOfScan(this.frameConfig.Components.Length, this.frameConfig.Components);
var frame = new Components.Encoder.JpegFrame(this.frameConfig, Configuration.Default.MemoryAllocator, image, GetTargetColorSpace(this.frameConfig.ColorType)); var frame = new Components.Encoder.JpegFrame(this.frameConfig, Configuration.Default.MemoryAllocator, image, GetTargetColorSpace(this.frameConfig.ColorType));
var quantTables = new Block8x8F[] { luminanceQuantTable, chrominanceQuantTable }; var quantTables = new Block8x8F[] { luminanceQuantTable, chrominanceQuantTable };
@ -636,8 +633,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <param name="height">The height of the image.</param> /// <param name="height">The height of the image.</param>
/// <param name="componentCount">The number of components in a pixel.</param> /// <param name="componentCount">The number of components in a pixel.</param>
/// <param name="componentIds">The component Id's.</param> /// <param name="componentIds">The component Id's.</param>
private void WriteStartOfFrame(int width, int height, JpegComponentConfig[] components) private void WriteStartOfFrame(int width, int height, JpegFrameConfig frame)
{ {
JpegComponentConfig[] components = frame.Components;
// Length (high byte, low byte), 8 + components * 3. // Length (high byte, low byte), 8 + components * 3.
int markerlen = 8 + (3 * components.Length); int markerlen = 8 + (3 * components.Length);
this.WriteMarkerHeader(JpegConstants.Markers.SOF0, markerlen); this.WriteMarkerHeader(JpegConstants.Markers.SOF0, markerlen);

Loading…
Cancel
Save