Wpf: Fix remaining tests

This commit is contained in:
Ben Olden-Cooligan 2023-12-27 21:36:54 -08:00
parent e52c7ce3bb
commit 8e21493326
4 changed files with 35 additions and 3 deletions

View File

@ -126,7 +126,22 @@ public class WpfImage : IMemoryImage
using var helper = PixelFormatHelper.Create(this, options.PixelFormatHint, minFormat: ImagePixelFormat.Gray8);
var encoder = GetImageEncoder(imageFormat, options);
encoder.Frames.Add(BitmapFrame.Create(helper.Image.Bitmap));
encoder.Save(stream);
SaveMaybeWithoutSeeking(stream, encoder);
}
private static void SaveMaybeWithoutSeeking(Stream stream, BitmapEncoder encoder)
{
if (stream.CanSeek)
{
encoder.Save(stream);
}
else
{
var memoryStream = new MemoryStream();
encoder.Save(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
memoryStream.CopyTo(stream);
}
}
private static BitmapEncoder GetImageEncoder(ImageFileFormat imageFormat, ImageSaveOptions options)

View File

@ -31,6 +31,10 @@ public static class CurrentPlatformFlags
{
p |= PlatformFlags.ImageSharp;
}
if (TestImageContextFactory.Get().ImageType.Name == "WpfImage")
{
p |= PlatformFlags.Wpf;
}
return p;
}
@ -39,4 +43,10 @@ public static class CurrentPlatformFlags
var flags = Get();
return (match & flags) == match;
}
public static bool HasAny(PlatformFlags match)
{
var flags = Get();
return (match & flags) != 0;
}
}

View File

@ -244,7 +244,7 @@ public class LoadSaveTests : ContextualTests
// All optimized values should be less than their unoptimized counterparts.
Assert.True(optimized32Bpp < unoptimized32Bpp);
Assert.True(optimized24Bpp < unoptimized24Bpp);
if (!CurrentPlatformFlags.Has(PlatformFlags.ImageSharp))
if (!CurrentPlatformFlags.HasAny(PlatformFlags.ImageSharp | PlatformFlags.Wpf))
{
Assert.True(optimized8Bpp < unoptimized8Bpp);
Assert.Equal(optimized1Bpp, unoptimized1Bpp);
@ -295,11 +295,14 @@ public class LoadSaveTests : ContextualTests
ImageFileFormat.Png, ".png", "dog_gray_png",
new[] { "dog_gray" }, new[] { ImagePixelFormat.Gray8 }, true
},
// TODO: Can we improve this for WPF?
#if MAC || LINUX
new object[]
{
ImageFileFormat.Png, ".png", "dog_gray_24bit_png",
new[] { "dog_gray" }, new[] { ImagePixelFormat.Gray8 }, false
},
#endif
new object[]
{
ImageFileFormat.Png, ".png", "dog_bw",
@ -363,11 +366,14 @@ public class LoadSaveTests : ContextualTests
ImageFileFormat.Tiff, ".tiff", "dog_gray_tiff",
new[] { "dog_gray" }, new[] { ImagePixelFormat.Gray8 }, true
},
// TODO: Can we improve this for WPF?
#if MAC || LINUX
new object[]
{
ImageFileFormat.Tiff, ".tiff", "dog_gray_24bit_tiff",
new[] { "dog_gray" }, new[] { ImagePixelFormat.Gray8 }, false
},
#endif
new object[]
{
ImageFileFormat.Tiff, ".tiff", "dog_bw_tiff",

View File

@ -9,5 +9,6 @@ public enum PlatformFlags
Linux = 4,
X64 = 8,
Arm64 = 16,
ImageSharp = 32
ImageSharp = 32,
Wpf = 64
}