diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/PaletteTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/PaletteTiffColor{TPixel}.cs
index ad5793084..d0ab2383d 100644
--- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/PaletteTiffColor{TPixel}.cs
+++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/PaletteTiffColor{TPixel}.cs
@@ -19,6 +19,8 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
private readonly TPixel[] palette;
+ private const float InvMax = 1.0f / 65535F;
+
/// The number of bits per sample for each pixel.
/// The RGB color lookup table to use for decoding the image.
public PaletteTiffColor(TiffBitsPerSample bitsPerSample, ushort[] colorMap)
@@ -56,9 +58,9 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
for (int i = 0; i < palette.Length; i++)
{
- float r = colorMap[rOffset + i] / 65535F;
- float g = colorMap[gOffset + i] / 65535F;
- float b = colorMap[bOffset + i] / 65535F;
+ float r = colorMap[rOffset + i] * InvMax;
+ float g = colorMap[gOffset + i] * InvMax;
+ float b = colorMap[bOffset + i] * InvMax;
palette[i].FromScaledVector4(new Vector4(r, g, b, 1.0f));
}
diff --git a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs
index 38611c6f3..d4964cf77 100644
--- a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs
@@ -13,14 +13,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation
[Trait("Format", "Tiff")]
public class BlackIsZeroTiffColorTests : PhotometricInterpretationTestBase
{
- private static readonly Rgba32 Gray000 = new Rgba32(0, 0, 0, 255);
- private static readonly Rgba32 Gray128 = new Rgba32(128, 128, 128, 255);
- private static readonly Rgba32 Gray255 = new Rgba32(255, 255, 255, 255);
- private static readonly Rgba32 Gray0 = new Rgba32(0, 0, 0, 255);
- private static readonly Rgba32 Gray8 = new Rgba32(136, 136, 136, 255);
- private static readonly Rgba32 GrayF = new Rgba32(255, 255, 255, 255);
- private static readonly Rgba32 Bit0 = new Rgba32(0, 0, 0, 255);
- private static readonly Rgba32 Bit1 = new Rgba32(255, 255, 255, 255);
+ private static readonly Rgba32 Gray000 = new(0, 0, 0, 255);
+ private static readonly Rgba32 Gray128 = new(128, 128, 128, 255);
+ private static readonly Rgba32 Gray255 = new(255, 255, 255, 255);
+ private static readonly Rgba32 Gray0 = new(0, 0, 0, 255);
+ private static readonly Rgba32 Gray8 = new(136, 136, 136, 255);
+ private static readonly Rgba32 GrayF = new(255, 255, 255, 255);
+ private static readonly Rgba32 Bit0 = new(0, 0, 0, 255);
+ private static readonly Rgba32 Bit1 = new(255, 255, 255, 255);
private static readonly byte[] BilevelBytes4X4 =
{
@@ -30,8 +30,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation
0b10010000
};
- private static readonly Rgba32[][] BilevelResult4X4 = new[]
- {
+ private static readonly Rgba32[][] BilevelResult4X4 = {
new[] { Bit0, Bit1, Bit0, Bit1 },
new[] { Bit1, Bit1, Bit1, Bit1 },
new[] { Bit0, Bit1, Bit1, Bit1 },