Skip to content

Commit 5a5d23c

Browse files
Update test tolerances to cater for reference decoder bug.
1 parent 2c30c90 commit 5a5d23c

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/ImageSharp/Common/Helpers/Numerics.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ public static void UnPremultiply(ref Vector4 source, Vector4 alpha)
538538
return;
539539
}
540540

541+
// Divide source by alpha if alpha is nonzero, otherwise set all components to match the source value
542+
// Blend the result with the alpha vector to ensure that the alpha component is unchanged
541543
source = WithW(source / alpha, alpha);
542544
}
543545

tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
namespace SixLabors.ImageSharp.Tests.Formats.Tiff;
1414

15+
// Several of the tests in this class comparing images with associated alpha encoding use a high tolerance for comparison.
16+
// This is due to an issue in the reference decoder where it is not correctly checking for a zero alpha component value
17+
// before unpremultying the encoded values. This can lead to incorrect values when the rgb channels contain non-zero values.
18+
// The tests should be manually verified following any changes to the decoder.
1519
[Trait("Format", "Tiff")]
1620
[ValidateDisposedMemoryAllocations]
1721
public class TiffDecoderTests : TiffDecoderBaseTester
@@ -205,8 +209,7 @@ public void TiffDecoder_CanDecode_12Bit_WithAssociatedAlpha<TPixel>(TestImagePro
205209
return;
206210
}
207211

208-
// Note: Using tolerant comparer here, because there is a small difference to the reference decoder probably due to floating point rounding issues.
209-
TestTiffDecoder(provider, useExactComparer: false);
212+
TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.264F);
210213
}
211214

212215
[Theory]
@@ -262,8 +265,7 @@ public void TiffDecoder_CanDecode_20Bit_WithAssociatedAlpha<TPixel>(TestImagePro
262265
return;
263266
}
264267

265-
// Note: Using tolerant comparer here, because there is a small difference to the reference decoder probably due to floating point rounding issues.
266-
TestTiffDecoder(provider, useExactComparer: false);
268+
TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.376F);
267269
}
268270

269271
[Theory]
@@ -289,8 +291,7 @@ public void TiffDecoder_CanDecode_24Bit_WithAssociatedAlpha<TPixel>(TestImagePro
289291
return;
290292
}
291293

292-
// Note: Using tolerant comparer here, because there is a small difference to the reference decoder probably due to floating point rounding issues.
293-
TestTiffDecoder(provider, useExactComparer: false);
294+
TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.405F);
294295
}
295296

296297
[Theory]
@@ -431,8 +432,7 @@ public void TiffDecoder_CanDecode_40Bit_WithAssociatedAlpha<TPixel>(TestImagePro
431432
return;
432433
}
433434

434-
// Note: Using tolerant comparer here, because there is a small difference to the reference decoder probably due to floating point rounding issues.
435-
TestTiffDecoder(provider, useExactComparer: false);
435+
TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.247F);
436436
}
437437

438438
[Theory]
@@ -470,8 +470,7 @@ public void TiffDecoder_CanDecode_48Bit_WithAssociatedAlpha<TPixel>(TestImagePro
470470
return;
471471
}
472472

473-
// Note: Using tolerant comparer here, because there is a small difference to the reference decoder probably due to floating point rounding issues.
474-
TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.0002f);
473+
TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.118F);
475474
}
476475

477476
[Theory]
@@ -500,8 +499,7 @@ public void TiffDecoder_CanDecode_56Bit_WithAssociatedAlpha<TPixel>(TestImagePro
500499
return;
501500
}
502501

503-
// Note: Using tolerant comparer here, because there is a small difference to the reference decoder probably due to floating point rounding issues.
504-
TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.0002f);
502+
TestTiffDecoder(provider, useExactComparer: false, compareTolerance: 0.075F);
505503
}
506504

507505
[Theory]

0 commit comments

Comments
 (0)