Browse Source

Multiply by inv max value instead of dividing in GeneratePalette

pull/2134/head
Brian Popow 4 years ago
parent
commit
3af2dd7720
  1. 8
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/PaletteTiffColor{TPixel}.cs
  2. 19
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs

8
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;
/// <param name="bitsPerSample">The number of bits per sample for each pixel.</param>
/// <param name="colorMap">The RGB color lookup table to use for decoding the image.</param>
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));
}

19
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 },

Loading…
Cancel
Save