From 0b7705c60f369c8ea549e141ec0867913debfdae Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 26 May 2022 14:34:37 +0200 Subject: [PATCH 1/8] Add support for decoding tiff images with CieLab color space --- .../CieLabTiffColor{TPixel}.cs | 46 +++++++++++++++++++ .../TiffColorDecoderFactory{TPixel}.cs | 15 ++++++ .../TiffColorType.cs | 7 ++- .../YCbCrTiffColor{TPixel}.cs | 3 ++ .../Formats/Tiff/TiffDecoderOptionsParser.cs | 20 +++++++- 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs new file mode 100644 index 0000000000..f3d014a46f --- /dev/null +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs @@ -0,0 +1,46 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Numerics; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation +{ + /// + /// Implements decoding pixel data with photometric interpretation of type 'CieLab'. + /// + internal class CieLabTiffColor : TiffBaseColorDecoder + where TPixel : unmanaged, IPixel + { + private readonly ColorSpaceConverter colorSpaceConverter = new(); + + private const float Inv255 = 1.0f / 255.0f; + + /// + public override void Decode(ReadOnlySpan data, Buffer2D pixels, int left, int top, int width, int height) + { + var color = default(TPixel); + int offset = 0; + for (int y = top; y < top + height; y++) + { + Span pixelRow = pixels.DangerousGetRowSpan(y).Slice(left, width); + + for (int x = 0; x < pixelRow.Length; x++) + { + float l = (data[offset] & 0xFF) * 100f * Inv255; + var lab = new CieLab(l, (sbyte)data[offset + 1], (sbyte)data[offset + 2]); + var rgb = this.colorSpaceConverter.ToRgb(lab); + + color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f)); + pixelRow[x] = color; + + offset += 3; + } + } + } + } +} diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs index c95d039461..ce146c9572 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs @@ -385,8 +385,23 @@ public static TiffBaseColorDecoder Create( return new PaletteTiffColor(bitsPerSample, colorMap); case TiffColorType.YCbCr: + DebugGuard.IsTrue( + bitsPerSample.Channels == 3 + && bitsPerSample.Channel2 == 8 + && bitsPerSample.Channel1 == 8 + && bitsPerSample.Channel0 == 8, + "bitsPerSample"); return new YCbCrTiffColor(memoryAllocator, referenceBlackAndWhite, ycbcrCoefficients, ycbcrSubSampling); + case TiffColorType.CieLab: + DebugGuard.IsTrue( + bitsPerSample.Channels == 3 + && bitsPerSample.Channel2 == 8 + && bitsPerSample.Channel1 == 8 + && bitsPerSample.Channel0 == 8, + "bitsPerSample"); + return new CieLabTiffColor(); + default: throw TiffThrowHelper.InvalidColorType(colorType.ToString()); } diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorType.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorType.cs index 6b39224fbd..b5fdcbea9e 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorType.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorType.cs @@ -276,6 +276,11 @@ internal enum TiffColorType /// /// The pixels are stored in YCbCr format as planar. /// - YCbCrPlanar + YCbCrPlanar, + + /// + /// The pixels are stored in CieLab format. + /// + CieLab, } } diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/YCbCrTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/YCbCrTiffColor{TPixel}.cs index 9b37cf16a5..0c9b9360b5 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/YCbCrTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/YCbCrTiffColor{TPixel}.cs @@ -9,6 +9,9 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { + /// + /// Implements decoding pixel data with photometric interpretation of type 'YCbCr'. + /// internal class YCbCrTiffColor : TiffBaseColorDecoder where TPixel : unmanaged, IPixel { diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs index 6d99fed3e1..f1c04a3828 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs @@ -381,7 +381,7 @@ private static void ParseColorType(this TiffDecoderCore options, ExifProfile exi options.ColorMap = exifProfile.GetValue(ExifTag.ColorMap)?.Value; if (options.BitsPerSample.Channels != 3) { - TiffThrowHelper.ThrowNotSupported("The number of samples in the TIFF BitsPerSample entry is not supported."); + TiffThrowHelper.ThrowNotSupported("The number of samples in the TIFF BitsPerSample entry is not supported for YCbCr images."); } ushort bitsPerChannel = options.BitsPerSample.Channel0; @@ -395,6 +395,24 @@ private static void ParseColorType(this TiffDecoderCore options, ExifProfile exi break; } + case TiffPhotometricInterpretation.CieLab: + { + options.ColorType = TiffColorType.CieLab; + + if (options.BitsPerSample.Channels != 3) + { + TiffThrowHelper.ThrowNotSupported("The number of samples in the TIFF BitsPerSample entry is not supported for CieLab images."); + } + + ushort bitsPerChannel = options.BitsPerSample.Channel0; + if (bitsPerChannel != 8) + { + TiffThrowHelper.ThrowNotSupported("Only 8 bits per channel is supported for CieLab images."); + } + + break; + } + default: { TiffThrowHelper.ThrowNotSupported($"The specified TIFF photometric interpretation is not supported: {options.PhotometricInterpretation}"); From bd2b06708bfab897784a7994ee1e4b4280731e89 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 26 May 2022 15:15:13 +0200 Subject: [PATCH 2/8] Undo horizontal predictor for CieLab --- src/ImageSharp/Formats/Tiff/Compression/HorizontalPredictor.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ImageSharp/Formats/Tiff/Compression/HorizontalPredictor.cs b/src/ImageSharp/Formats/Tiff/Compression/HorizontalPredictor.cs index 97bce2b2db..3208a9e505 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/HorizontalPredictor.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/HorizontalPredictor.cs @@ -41,6 +41,7 @@ public static void Undo(Span pixelBytes, int width, TiffColorType colorTyp UndoGray32Bit(pixelBytes, width, isBigEndian); break; case TiffColorType.Rgb888: + case TiffColorType.CieLab: UndoRgb24Bit(pixelBytes, width); break; case TiffColorType.Rgba8888: From 485571a65b9b8f71ab96fc3983cedbfde271c171 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 26 May 2022 16:31:25 +0200 Subject: [PATCH 3/8] Add support for decoding planar tiff with cielab colorspace --- .../CieLabPlanarTiffColor{TPixel}.cs | 49 +++++++++++++++++++ .../TiffColorDecoderFactory{TPixel}.cs | 3 ++ .../TiffColorType.cs | 5 ++ .../YCbCrPlanarTiffColor{TPixel}.cs | 3 ++ .../Formats/Tiff/TiffDecoderOptionsParser.cs | 4 +- 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs new file mode 100644 index 0000000000..b0420f9920 --- /dev/null +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs @@ -0,0 +1,49 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Buffers; +using System.Numerics; +using SixLabors.ImageSharp.ColorSpaces; +using SixLabors.ImageSharp.ColorSpaces.Conversion; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation +{ + /// + /// Implements decoding pixel data with photometric interpretation of type 'CieLab' with the planar configuration. + /// + internal class CieLabPlanarTiffColor : TiffBasePlanarColorDecoder + where TPixel : unmanaged, IPixel + { + private readonly ColorSpaceConverter colorSpaceConverter = new(); + + private const float Inv255 = 1.0f / 255.0f; + + /// + public override void Decode(IMemoryOwner[] data, Buffer2D pixels, int left, int top, int width, int height) + { + Span l = data[0].GetSpan(); + Span a = data[1].GetSpan(); + Span b = data[2].GetSpan(); + + var color = default(TPixel); + int offset = 0; + for (int y = top; y < top + height; y++) + { + Span pixelRow = pixels.DangerousGetRowSpan(y).Slice(left, width); + for (int x = 0; x < pixelRow.Length; x++) + { + var lab = new CieLab((l[offset] & 0xFF) * 100f * Inv255, (sbyte)a[offset], (sbyte)b[offset]); + var rgb = this.colorSpaceConverter.ToRgb(lab); + + color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f)); + pixelRow[x] = color; + + offset++; + } + } + } + } +} diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs index ce146c9572..4b0bca08b8 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs @@ -430,6 +430,9 @@ public static TiffBasePlanarColorDecoder CreatePlanar( case TiffColorType.YCbCrPlanar: return new YCbCrPlanarTiffColor(referenceBlackAndWhite, ycbcrCoefficients, ycbcrSubSampling); + case TiffColorType.CieLabPlanar: + return new CieLabPlanarTiffColor(); + case TiffColorType.Rgb161616Planar: DebugGuard.IsTrue(colorMap == null, "colorMap"); return new Rgb16PlanarTiffColor(byteOrder == ByteOrder.BigEndian); diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorType.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorType.cs index b5fdcbea9e..0c0cc07c8f 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorType.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorType.cs @@ -282,5 +282,10 @@ internal enum TiffColorType /// The pixels are stored in CieLab format. /// CieLab, + + /// + /// The pixels are stored in CieLab format as planar. + /// + CieLabPlanar, } } diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/YCbCrPlanarTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/YCbCrPlanarTiffColor{TPixel}.cs index 465c8fba3a..5e0aecfe15 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/YCbCrPlanarTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/YCbCrPlanarTiffColor{TPixel}.cs @@ -9,6 +9,9 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { + /// + /// Implements decoding pixel data with photometric interpretation of type 'YCbCr' with the planar configuration. + /// internal class YCbCrPlanarTiffColor : TiffBasePlanarColorDecoder where TPixel : unmanaged, IPixel { diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs index f1c04a3828..3da64ad841 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs @@ -397,8 +397,6 @@ private static void ParseColorType(this TiffDecoderCore options, ExifProfile exi case TiffPhotometricInterpretation.CieLab: { - options.ColorType = TiffColorType.CieLab; - if (options.BitsPerSample.Channels != 3) { TiffThrowHelper.ThrowNotSupported("The number of samples in the TIFF BitsPerSample entry is not supported for CieLab images."); @@ -410,6 +408,8 @@ private static void ParseColorType(this TiffDecoderCore options, ExifProfile exi TiffThrowHelper.ThrowNotSupported("Only 8 bits per channel is supported for CieLab images."); } + options.ColorType = options.PlanarConfiguration == TiffPlanarConfiguration.Chunky ? TiffColorType.CieLab : TiffColorType.CieLabPlanar; + break; } From d850aee1bd6c285f8b20c48e07c09df94a8645f7 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 26 May 2022 16:44:34 +0200 Subject: [PATCH 4/8] Add tests for CieLab --- .../Formats/Tiff/TiffDecoderTests.cs | 14 ++++++++++++++ tests/ImageSharp.Tests/TestImages.cs | 5 +++++ .../TiffDecoder_CanDecode_CieLab_Rgba32_CieLab.png | 3 +++ ...ecoder_CanDecode_CieLab_Rgba32_CieLabPlanar.png | 3 +++ ...ieLab_Rgba32_CieLab_lzwcompressed_predictor.png | 3 +++ tests/Images/Input/Tiff/CieLab.tiff | 3 +++ tests/Images/Input/Tiff/CieLabPlanar.tiff | 3 +++ .../Input/Tiff/CieLab_lzwcompressed_predictor.tiff | 3 +++ 8 files changed, 37 insertions(+) create mode 100644 tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLab.png create mode 100644 tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLabPlanar.png create mode 100644 tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLab_lzwcompressed_predictor.png create mode 100644 tests/Images/Input/Tiff/CieLab.tiff create mode 100644 tests/Images/Input/Tiff/CieLabPlanar.tiff create mode 100644 tests/Images/Input/Tiff/CieLab_lzwcompressed_predictor.tiff diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs index b9569c7a46..054a249955 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs @@ -318,6 +318,20 @@ public void TiffDecoder_CanDecode_YCbCr_24Bit(TestImageProvider image.CompareToReferenceOutput(ImageComparer.Exact, provider); } + [Theory] + [WithFile(CieLab, PixelTypes.Rgba32)] + [WithFile(CieLabPlanar, PixelTypes.Rgba32)] + [WithFile(CieLabLzwPredictor, PixelTypes.Rgba32)] + public void TiffDecoder_CanDecode_CieLab(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + // Note: The image from MagickReferenceDecoder does not look right, maybe we are doing something wrong + // converting the pixel data from Magick.NET to our format with CieLab? + using Image image = provider.GetImage(); + image.DebugSave(provider); + image.CompareToReferenceOutput(ImageComparer.Exact, provider); + } + [Theory] [WithFile(FlowerRgb101010Contiguous, PixelTypes.Rgba32)] [WithFile(FlowerRgb101010Planar, PixelTypes.Rgba32)] diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 023efd7076..ed331af30f 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -910,6 +910,11 @@ public static class Tiff public const string Rgba32BitPlanarUnassociatedAlphaBigEndian = "Tiff/RgbaUnassociatedAlphaPlanar32bit_msb.tiff"; public const string Rgba32BitPlanarUnassociatedAlphaLittleEndian = "Tiff/RgbaUnassociatedAlphaPlanar32bit_lsb.tiff"; + // Cie Lab color space. + public const string CieLab = "Tiff/CieLab.tiff"; + public const string CieLabPlanar = "Tiff/CieLabPlanar.tiff"; + public const string CieLabLzwPredictor = "Tiff/CieLab_lzwcompressed_predictor.tiff"; + public const string Issues1716Rgb161616BitLittleEndian = "Tiff/Issues/Issue1716.tiff"; public const string Issues1891 = "Tiff/Issues/Issue1891.tiff"; public const string Issues2123 = "Tiff/Issues/Issue2123.tiff"; diff --git a/tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLab.png b/tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLab.png new file mode 100644 index 0000000000..bdd240663b --- /dev/null +++ b/tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLab.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13bc9da102f85124855217fad757ca907f5d68442e54e3b7039ac048d7b2ad3f +size 25791 diff --git a/tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLabPlanar.png b/tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLabPlanar.png new file mode 100644 index 0000000000..bdd240663b --- /dev/null +++ b/tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLabPlanar.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13bc9da102f85124855217fad757ca907f5d68442e54e3b7039ac048d7b2ad3f +size 25791 diff --git a/tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLab_lzwcompressed_predictor.png b/tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLab_lzwcompressed_predictor.png new file mode 100644 index 0000000000..1938ebe110 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/TiffDecoderTests/TiffDecoder_CanDecode_CieLab_Rgba32_CieLab_lzwcompressed_predictor.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f9481c91c58ca7bbab9de4b9ae95fe4a2197ae4b6ef6b15b72d4858aba3a1a4 +size 25782 diff --git a/tests/Images/Input/Tiff/CieLab.tiff b/tests/Images/Input/Tiff/CieLab.tiff new file mode 100644 index 0000000000..59a667dd5e --- /dev/null +++ b/tests/Images/Input/Tiff/CieLab.tiff @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7542b5b3abe049614f2ddaf78ffe995edac13e768f0b2fc9f324c6ef43b379eb +size 1312046 diff --git a/tests/Images/Input/Tiff/CieLabPlanar.tiff b/tests/Images/Input/Tiff/CieLabPlanar.tiff new file mode 100644 index 0000000000..d964a96947 --- /dev/null +++ b/tests/Images/Input/Tiff/CieLabPlanar.tiff @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28592d9da8d51f60700b7136369d2d6bd40550d5f8c7758e570b5e624c71a3e4 +size 1307488 diff --git a/tests/Images/Input/Tiff/CieLab_lzwcompressed_predictor.tiff b/tests/Images/Input/Tiff/CieLab_lzwcompressed_predictor.tiff new file mode 100644 index 0000000000..2284e1e17f --- /dev/null +++ b/tests/Images/Input/Tiff/CieLab_lzwcompressed_predictor.tiff @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6affced5550e51441c4cde7f1770d4e57cfa594bd271a12f9571359733c2185d +size 55346 From bf4c0dc8876d31c08555428f799d20111b4e87dd Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 26 May 2022 16:48:50 +0200 Subject: [PATCH 5/8] Add CieLab to supported formats for the tiff decoder --- src/ImageSharp/Formats/Tiff/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Tiff/README.md b/src/ImageSharp/Formats/Tiff/README.md index 8cb327a7b0..865b2f9c21 100644 --- a/src/ImageSharp/Formats/Tiff/README.md +++ b/src/ImageSharp/Formats/Tiff/README.md @@ -55,7 +55,7 @@ |TransparencyMask | | | | |Separated (TIFF Extension) | | | | |YCbCr (TIFF Extension) | | Y | | -|CieLab (TIFF Extension) | | | | +|CieLab (TIFF Extension) | | Y | | |IccLab (TechNote 1) | | | | ### Baseline TIFF Tags From 7c8fecaec0239a63f615144c3b2cb20f2c468844 Mon Sep 17 00:00:00 2001 From: Brian Popow <38701097+brianpopow@users.noreply.github.com> Date: Fri, 27 May 2022 11:31:03 +0200 Subject: [PATCH 6/8] Make color converter static MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Günther Foidl --- .../PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs | 2 +- .../Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs index b0420f9920..9e55693e40 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation internal class CieLabPlanarTiffColor : TiffBasePlanarColorDecoder where TPixel : unmanaged, IPixel { - private readonly ColorSpaceConverter colorSpaceConverter = new(); + private static readonly ColorSpaceConverter colorSpaceConverter = new(); private const float Inv255 = 1.0f / 255.0f; diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs index f3d014a46f..546ef8f4f8 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation internal class CieLabTiffColor : TiffBaseColorDecoder where TPixel : unmanaged, IPixel { - private readonly ColorSpaceConverter colorSpaceConverter = new(); + private static readonly ColorSpaceConverter colorSpaceConverter = new(); private const float Inv255 = 1.0f / 255.0f; From 9165efe740b111296143002c7b54efe1bf804919 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 27 May 2022 11:40:52 +0200 Subject: [PATCH 7/8] Fix build issue --- .../CieLabPlanarTiffColor{TPixel}.cs | 4 ++-- .../Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs index 9e55693e40..e92ad0162f 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation internal class CieLabPlanarTiffColor : TiffBasePlanarColorDecoder where TPixel : unmanaged, IPixel { - private static readonly ColorSpaceConverter colorSpaceConverter = new(); + private static readonly ColorSpaceConverter ColorSpaceConverter = new(); private const float Inv255 = 1.0f / 255.0f; @@ -36,7 +36,7 @@ public override void Decode(IMemoryOwner[] data, Buffer2D pixels, for (int x = 0; x < pixelRow.Length; x++) { var lab = new CieLab((l[offset] & 0xFF) * 100f * Inv255, (sbyte)a[offset], (sbyte)b[offset]); - var rgb = this.colorSpaceConverter.ToRgb(lab); + var rgb = ColorSpaceConverter.ToRgb(lab); color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f)); pixelRow[x] = color; diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs index 546ef8f4f8..f4f42c20c4 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation internal class CieLabTiffColor : TiffBaseColorDecoder where TPixel : unmanaged, IPixel { - private static readonly ColorSpaceConverter colorSpaceConverter = new(); + private static readonly ColorSpaceConverter ColorSpaceConverter = new(); private const float Inv255 = 1.0f / 255.0f; @@ -33,7 +33,7 @@ public override void Decode(ReadOnlySpan data, Buffer2D pixels, in { float l = (data[offset] & 0xFF) * 100f * Inv255; var lab = new CieLab(l, (sbyte)data[offset + 1], (sbyte)data[offset + 2]); - var rgb = this.colorSpaceConverter.ToRgb(lab); + var rgb = ColorSpaceConverter.ToRgb(lab); color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f)); pixelRow[x] = color; From a258c472b81310ed181b0d4c60e69b8dd31606d8 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 18 Jul 2022 01:21:40 +0200 Subject: [PATCH 8/8] Fix file header copyright text --- .../PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs | 2 +- .../Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs index e92ad0162f..3baf60e786 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs @@ -1,5 +1,5 @@ // Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. +// Licensed under the Six Labors Split License. using System; using System.Buffers; diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs index f4f42c20c4..5b272b2be5 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs @@ -1,5 +1,5 @@ // Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. +// Licensed under the Six Labors Split License. using System; using System.Numerics;