📷 A modern, cross-platform, 2D Graphics library for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

136 lines
3.6 KiB

// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Exr;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.Formats.Exr;
[Trait("Format", "Exr")]
public class ImageExtensionsTest
{
[Fact]
public void SaveAsExr_Path()
{
string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageExtensionsTest));
string file = Path.Combine(dir, "SaveAsExr_Path.exr");
using (Image<Rgba32> image = new(10, 10))
{
image.SaveAsExr(file);
}
IImageFormat format = Image.DetectFormat(file);
Assert.True(format is ExrFormat);
}
[Fact]
public async Task SaveAsExrAsync_Path()
{
string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageExtensionsTest));
string file = Path.Combine(dir, "SaveAsExrAsync_Path.exr");
using (Image<Rgba32> image = new(10, 10))
{
await image.SaveAsExrAsync(file);
}
IImageFormat format = Image.DetectFormat(file);
Assert.True(format is ExrFormat);
}
[Fact]
public void SaveAsExr_Path_Encoder()
{
string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageExtensions));
string file = Path.Combine(dir, "SaveAsExr_Path_Encoder.exr");
using (Image<Rgba32> image = new(10, 10))
{
image.SaveAsExr(file, new ExrEncoder());
}
IImageFormat format = Image.DetectFormat(file);
Assert.True(format is ExrFormat);
}
[Fact]
public async Task SaveAsExrAsync_Path_Encoder()
{
string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageExtensions));
string file = Path.Combine(dir, "SaveAsExrAsync_Path_Encoder.exr");
using (Image<Rgba32> image = new(10, 10))
{
await image.SaveAsExrAsync(file, new ExrEncoder());
}
IImageFormat format = Image.DetectFormat(file);
Assert.True(format is ExrFormat);
}
[Fact]
public void SaveAsExr_Stream()
{
using MemoryStream memoryStream = new();
using (Image<Rgba32> image = new(10, 10))
{
image.SaveAsExr(memoryStream);
}
memoryStream.Position = 0;
IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is ExrFormat);
}
[Fact]
public async Task SaveAsExrAsync_StreamAsync()
{
using MemoryStream memoryStream = new();
using (Image<Rgba32> image = new(10, 10))
{
await image.SaveAsExrAsync(memoryStream);
}
memoryStream.Position = 0;
IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is ExrFormat);
}
[Fact]
public void SaveAsExr_Stream_Encoder()
{
using MemoryStream memoryStream = new();
using (Image<Rgba32> image = new(10, 10))
{
image.SaveAsExr(memoryStream, new ExrEncoder());
}
memoryStream.Position = 0;
IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is ExrFormat);
}
[Fact]
public async Task SaveAsExrAsync_Stream_Encoder()
{
using MemoryStream memoryStream = new();
using (Image<Rgba32> image = new(10, 10))
{
await image.SaveAsExrAsync(memoryStream, new ExrEncoder());
}
memoryStream.Position = 0;
IImageFormat format = Image.DetectFormat(memoryStream);
Assert.True(format is ExrFormat);
}
}