From 99018450025044648e2ad6b61c0184632707c6ce Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 3 Oct 2019 03:19:22 +0200 Subject: [PATCH] [System.Drawing.Common] Relax IconTests.CorrectColorDepthExtracted test (dotnet/corefx#41495) * [System.Drawing.Common] Relax IconTests.CorrectColorDepthExtracted to work on newer libgdiplus on Unix * Address PR comment Commit migrated from https://github.com/dotnet/corefx/commit/a50e056c5a62fb6dfe2e9475be47b93d33661700 --- .../System.Drawing.Common/tests/IconTests.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Drawing.Common/tests/IconTests.cs b/src/libraries/System.Drawing.Common/tests/IconTests.cs index 6263f93..40489ae 100644 --- a/src/libraries/System.Drawing.Common/tests/IconTests.cs +++ b/src/libraries/System.Drawing.Common/tests/IconTests.cs @@ -861,8 +861,23 @@ namespace System.Drawing.Tests switch (expectedBitDepth) { case 32: - Assert.Equal(0x879EE532u, (uint)bitmap.GetPixel(0, 0).ToArgb()); - Assert.Equal(0x661CD8B7u, (uint)bitmap.GetPixel(0, 31).ToArgb()); + if (!PlatformDetection.IsWindows) + { + // libgdiplus on Unix doesn't natively support ARGB32 format. It + // uses the Cairo library which represents the bitmaps as PARGB32 + // with individual channels premultiplied with the alpha channel. + // When converting back and forth it results in slight loss of + // precision so allow both original and rounded values here. + uint color = (uint)bitmap.GetPixel(0, 0).ToArgb(); + Assert.True(color == 0x879EE532u || color == 0x879EE431u, color.ToString("x")); + color = (uint)bitmap.GetPixel(0, 31).ToArgb(); + Assert.True(color == 0x661CD8B7u || color == 0x661BD7B6u, color.ToString("x")); + } + else + { + Assert.Equal(0x879EE532u, (uint)bitmap.GetPixel(0, 0).ToArgb()); + Assert.Equal(0x661CD8B7u, (uint)bitmap.GetPixel(0, 31).ToArgb()); + } break; case 16: case 8: -- 2.7.4