Skip to content

Commit 3af2dd7

Browse files
committed
Multiply by inv max value instead of dividing in GeneratePalette
1 parent 5675aa8 commit 3af2dd7

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/ImageSharp/Formats/Tiff/PhotometricInterpretation/PaletteTiffColor{TPixel}.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ internal class PaletteTiffColor<TPixel> : TiffBaseColorDecoder<TPixel>
1919

2020
private readonly TPixel[] palette;
2121

22+
private const float InvMax = 1.0f / 65535F;
23+
2224
/// <param name="bitsPerSample">The number of bits per sample for each pixel.</param>
2325
/// <param name="colorMap">The RGB color lookup table to use for decoding the image.</param>
2426
public PaletteTiffColor(TiffBitsPerSample bitsPerSample, ushort[] colorMap)
@@ -56,9 +58,9 @@ private static TPixel[] GeneratePalette(ushort[] colorMap, int colorCount)
5658

5759
for (int i = 0; i < palette.Length; i++)
5860
{
59-
float r = colorMap[rOffset + i] / 65535F;
60-
float g = colorMap[gOffset + i] / 65535F;
61-
float b = colorMap[bOffset + i] / 65535F;
61+
float r = colorMap[rOffset + i] * InvMax;
62+
float g = colorMap[gOffset + i] * InvMax;
63+
float b = colorMap[bOffset + i] * InvMax;
6264
palette[i].FromScaledVector4(new Vector4(r, g, b, 1.0f));
6365
}
6466

tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation
1313
[Trait("Format", "Tiff")]
1414
public class BlackIsZeroTiffColorTests : PhotometricInterpretationTestBase
1515
{
16-
private static readonly Rgba32 Gray000 = new Rgba32(0, 0, 0, 255);
17-
private static readonly Rgba32 Gray128 = new Rgba32(128, 128, 128, 255);
18-
private static readonly Rgba32 Gray255 = new Rgba32(255, 255, 255, 255);
19-
private static readonly Rgba32 Gray0 = new Rgba32(0, 0, 0, 255);
20-
private static readonly Rgba32 Gray8 = new Rgba32(136, 136, 136, 255);
21-
private static readonly Rgba32 GrayF = new Rgba32(255, 255, 255, 255);
22-
private static readonly Rgba32 Bit0 = new Rgba32(0, 0, 0, 255);
23-
private static readonly Rgba32 Bit1 = new Rgba32(255, 255, 255, 255);
16+
private static readonly Rgba32 Gray000 = new(0, 0, 0, 255);
17+
private static readonly Rgba32 Gray128 = new(128, 128, 128, 255);
18+
private static readonly Rgba32 Gray255 = new(255, 255, 255, 255);
19+
private static readonly Rgba32 Gray0 = new(0, 0, 0, 255);
20+
private static readonly Rgba32 Gray8 = new(136, 136, 136, 255);
21+
private static readonly Rgba32 GrayF = new(255, 255, 255, 255);
22+
private static readonly Rgba32 Bit0 = new(0, 0, 0, 255);
23+
private static readonly Rgba32 Bit1 = new(255, 255, 255, 255);
2424

2525
private static readonly byte[] BilevelBytes4X4 =
2626
{
@@ -30,8 +30,7 @@ public class BlackIsZeroTiffColorTests : PhotometricInterpretationTestBase
3030
0b10010000
3131
};
3232

33-
private static readonly Rgba32[][] BilevelResult4X4 = new[]
34-
{
33+
private static readonly Rgba32[][] BilevelResult4X4 = {
3534
new[] { Bit0, Bit1, Bit0, Bit1 },
3635
new[] { Bit1, Bit1, Bit1, Bit1 },
3736
new[] { Bit0, Bit1, Bit1, Bit1 },

0 commit comments

Comments
 (0)