From 198c1de6febaf4d5df66d3b35f2b6498dc4cf777 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 7 Mar 2022 17:33:19 +0100 Subject: [PATCH] Fix issue with 24 bits per channel --- .../Rgba24242424TiffColor{TPixel}.cs | 4 ++-- .../Rgba24PlanarTiffColor{TPixel}.cs | 4 ++-- src/ImageSharp/Formats/Tiff/Utils/TiffUtils.cs | 11 ++++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgba24242424TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgba24242424TiffColor{TPixel}.cs index 30f1d0f75e..71e1f7abd6 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgba24242424TiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgba24242424TiffColor{TPixel}.cs @@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation ulong a = TiffUtils.ConvertToUIntBigEndian(buffer); offset += 3; - pixelRow[x] = TiffUtils.ColorScaleTo32Bit(r, g, b, a, color); + pixelRow[x] = TiffUtils.ColorScaleTo24Bit(r, g, b, a, color); } } else @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation ulong a = TiffUtils.ConvertToUIntLittleEndian(buffer); offset += 3; - pixelRow[x] = TiffUtils.ColorScaleTo32Bit(r, g, b, a, color); + pixelRow[x] = TiffUtils.ColorScaleTo24Bit(r, g, b, a, color); } } } diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgba24PlanarTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgba24PlanarTiffColor{TPixel}.cs index 43b677b77e..03b78c3f87 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgba24PlanarTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgba24PlanarTiffColor{TPixel}.cs @@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation offset += 3; - pixelRow[x] = TiffUtils.ColorScaleTo32Bit(r, g, b, a, color); + pixelRow[x] = TiffUtils.ColorScaleTo24Bit(r, g, b, a, color); } } else @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation offset += 3; - pixelRow[x] = TiffUtils.ColorScaleTo32Bit(r, g, b, a, color); + pixelRow[x] = TiffUtils.ColorScaleTo24Bit(r, g, b, a, color); } } } diff --git a/src/ImageSharp/Formats/Tiff/Utils/TiffUtils.cs b/src/ImageSharp/Formats/Tiff/Utils/TiffUtils.cs index fef4bbe2e4..b7d4b6e7cc 100644 --- a/src/ImageSharp/Formats/Tiff/Utils/TiffUtils.cs +++ b/src/ImageSharp/Formats/Tiff/Utils/TiffUtils.cs @@ -72,6 +72,15 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Utils return color; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static TPixel ColorScaleTo24Bit(ulong r, ulong g, ulong b, ulong a, TPixel color) + where TPixel : unmanaged, IPixel + { + var colorVector = new Vector4(r * Scale24Bit, g * Scale24Bit, b * Scale24Bit, a * Scale24Bit); + color.FromVector4(colorVector); + return color; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPixel ColorScaleTo32Bit(ulong r, ulong g, ulong b, TPixel color) where TPixel : unmanaged, IPixel @@ -85,7 +94,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Utils public static TPixel ColorScaleTo32Bit(ulong r, ulong g, ulong b, ulong a, TPixel color) where TPixel : unmanaged, IPixel { - var colorVector = new Vector4(r * Scale32Bit, g * Scale32Bit, b * Scale32Bit, a); + var colorVector = new Vector4(r * Scale32Bit, g * Scale32Bit, b * Scale32Bit, a * Scale32Bit); color.FromVector4(colorVector); return color; }