Added extensions to save textures to files

このコミットが含まれているのは:
Sergio Pedri committed 2021-05-12 11:33:05 +02:00
1 親 c66ac3fe19
コミット f31ac94bf9
5ファイル変更
+294 -1

検索条件に一致するファイルはありません

+54
ファイルの表示
@@ -9,6 +9,7 @@ using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SixLabors.ImageSharp;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
using ImageSharpL8 = SixLabors.ImageSharp.PixelFormats.L8;
namespace ComputeSharp.Tests
{
@@ -46,6 +47,59 @@ namespace ComputeSharp.Tests
TolerantImageComparer.AssertEqual(original, loaded, 0.0000032f);
}
[CombinatorialTestMethod]
[AllDevices]
public void SaveRgba32AsJpeg(Device device)
{
string
path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging"),
expectedPath = Path.Combine(path, "city.jpg"),
actualPath = Path.Combine(path, "city_rgba32_saved.jpg");
using ReadOnlyTexture2D<Rgba32, Float4> texture = device.Get().AllocateReadOnlyTexture2D<Rgba32, Float4>(expectedPath);
texture.Save(actualPath);
TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.00001023f);
}
[CombinatorialTestMethod]
[AllDevices]
public void SaveBgra32AsJpeg(Device device)
{
string
path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging"),
expectedPath = Path.Combine(path, "city.jpg"),
actualPath = Path.Combine(path, "city_bgra32_saved.jpg");
using ReadOnlyTexture2D<Bgra32, Float4> texture = device.Get().AllocateReadOnlyTexture2D<Bgra32, Float4>(expectedPath);
texture.Save(actualPath);
TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.00001023f);
}
[CombinatorialTestMethod]
[AllDevices]
public void SaveR8AsJpeg(Device device)
{
string
path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging"),
sourcePath = Path.Combine(path, "city.jpg"),
expectedPath = Path.Combine(path, "city_r8_reference.jpg"),
actualPath = Path.Combine(path, "city_r8_saved.jpg");
using ReadOnlyTexture2D<R8, float> texture = device.Get().AllocateReadOnlyTexture2D<R8, float>(sourcePath);
texture.Save(actualPath);
using Image<ImageSharpL8> original = Image.Load<ImageSharpL8>(sourcePath);
original.Save(expectedPath);
TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.00004037f);
}
/// <summary>
/// An tolerant image comparer type, from <see href="https://github.com/SixLabors/ImageSharp">ImageSharp</see>.
/// </summary>