mirror of https://github.com/SixLabors/ImageSharp
32 changed files with 761 additions and 412 deletions
@ -1,120 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System; |
|
||||
using System.IO; |
|
||||
|
|
||||
using Moq; |
|
||||
|
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
using SixLabors.Primitives; |
|
||||
|
|
||||
using Xunit; |
|
||||
|
|
||||
// ReSharper disable InconsistentNaming
|
|
||||
namespace SixLabors.ImageSharp.Tests |
|
||||
{ |
|
||||
public partial class ImageTests |
|
||||
{ |
|
||||
public class Load_FromBytes : ImageLoadTestBase |
|
||||
{ |
|
||||
private byte[] ByteArray => this.DataStream.ToArray(); |
|
||||
|
|
||||
private ReadOnlySpan<byte> ByteSpan => this.ByteArray.AsSpan(); |
|
||||
|
|
||||
private byte[] ActualImageBytes => TestFile.Create(TestImages.Bmp.F).Bytes; |
|
||||
|
|
||||
private ReadOnlySpan<byte> ActualImageSpan => this.ActualImageBytes.AsSpan(); |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(false)] |
|
||||
[InlineData(true)] |
|
||||
public void BasicCase(bool useSpan) |
|
||||
{ |
|
||||
Image<Rgba32> img = useSpan |
|
||||
? Image.Load(this.TopLevelConfiguration, this.ByteSpan) |
|
||||
: Image.Load(this.TopLevelConfiguration, this.ByteArray); |
|
||||
|
|
||||
Assert.NotNull(img); |
|
||||
Assert.Equal(this.TestFormat.Sample<Rgba32>(), img); |
|
||||
|
|
||||
this.TestFormat.VerifyDecodeCall(this.Marker, this.TopLevelConfiguration); |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(false)] |
|
||||
[InlineData(true)] |
|
||||
public void NonDefaultPixelType(bool useSpan) |
|
||||
{ |
|
||||
Image<Rgb24> img = useSpan |
|
||||
? Image.Load<Rgb24>(this.TopLevelConfiguration, this.ByteSpan) |
|
||||
: Image.Load<Rgb24>(this.TopLevelConfiguration, this.ByteArray); |
|
||||
|
|
||||
Assert.NotNull(img); |
|
||||
Assert.Equal(this.TestFormat.Sample<Rgb24>(), img); |
|
||||
|
|
||||
this.TestFormat.VerifyDecodeCall(this.Marker, this.TopLevelConfiguration); |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(false)] |
|
||||
[InlineData(true)] |
|
||||
public void UseLocalConfiguration(bool useSpan) |
|
||||
{ |
|
||||
Image<Rgba32> img = useSpan |
|
||||
? Image.Load<Rgba32>(this.LocalConfiguration, this.ByteSpan) |
|
||||
: Image.Load<Rgba32>(this.LocalConfiguration, this.ByteArray); |
|
||||
|
|
||||
Assert.NotNull(img); |
|
||||
|
|
||||
this.localDecoder.Verify(x => x.Decode<Rgba32>(this.LocalConfiguration, It.IsAny<Stream>())); |
|
||||
|
|
||||
Assert.Equal(this.DataStream.ToArray(), this.DecodedData); |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(false)] |
|
||||
[InlineData(true)] |
|
||||
public void UseCustomDecoder(bool useSpan) |
|
||||
{ |
|
||||
Image<Rgba32> img = useSpan |
|
||||
? Image.Load<Rgba32>( |
|
||||
this.TopLevelConfiguration, |
|
||||
this.ByteSpan, |
|
||||
this.localDecoder.Object) |
|
||||
: Image.Load<Rgba32>( |
|
||||
this.TopLevelConfiguration, |
|
||||
this.ByteArray, |
|
||||
this.localDecoder.Object); |
|
||||
Assert.NotNull(img); |
|
||||
this.localDecoder.Verify(x => x.Decode<Rgba32>(this.TopLevelConfiguration, It.IsAny<Stream>())); |
|
||||
Assert.Equal(this.DataStream.ToArray(), this.DecodedData); |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(false)] |
|
||||
[InlineData(true)] |
|
||||
public void UseGlobalConfiguration(bool useSpan) |
|
||||
{ |
|
||||
using (Image<Rgba32> img = |
|
||||
useSpan ? Image.Load(this.ActualImageSpan) : Image.Load(this.ActualImageBytes)) |
|
||||
{ |
|
||||
Assert.Equal(new Size(108, 202), img.Size()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(false)] |
|
||||
[InlineData(true)] |
|
||||
public void UseGlobalConfiguration_NonDefaultPixelType(bool useSpan) |
|
||||
{ |
|
||||
using (Image<Rgb24> img = useSpan |
|
||||
? Image.Load<Rgb24>(this.ActualImageSpan) |
|
||||
: Image.Load<Rgb24>(this.ActualImageBytes)) |
|
||||
{ |
|
||||
Assert.Equal(new Size(108, 202), img.Size()); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,119 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
|
||||
|
using SixLabors.ImageSharp.Formats; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests |
||||
|
{ |
||||
|
public partial class ImageTests |
||||
|
{ |
||||
|
public class Load_FromBytes_PassLocalConfiguration : ImageLoadTestBase |
||||
|
{ |
||||
|
private byte[] ByteArray => this.DataStream.ToArray(); |
||||
|
|
||||
|
private ReadOnlySpan<byte> ByteSpan => this.ByteArray.AsSpan(); |
||||
|
|
||||
|
private byte[] ActualImageBytes => TestFile.Create(TestImages.Bmp.F).Bytes; |
||||
|
|
||||
|
private ReadOnlySpan<byte> ActualImageSpan => this.ActualImageBytes.AsSpan(); |
||||
|
|
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Configuration_Bytes_Specific(bool useSpan) |
||||
|
{ |
||||
|
var img = useSpan |
||||
|
? Image.Load<Rgb24>(this.TopLevelConfiguration, this.ByteSpan) |
||||
|
: Image.Load<Rgb24>(this.TopLevelConfiguration, this.ByteArray); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
Assert.Equal(this.TestFormat.Sample<Rgb24>(), img); |
||||
|
|
||||
|
this.TestFormat.VerifySpecificDecodeCall<Rgb24>(this.Marker, this.TopLevelConfiguration); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Configuration_Bytes_Agnostic(bool useSpan) |
||||
|
{ |
||||
|
var img = useSpan |
||||
|
? Image.Load(this.TopLevelConfiguration, this.ByteSpan) |
||||
|
: Image.Load(this.TopLevelConfiguration, this.ByteArray); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
Assert.Equal(this.TestFormat.SampleAgnostic(), img); |
||||
|
|
||||
|
this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Configuration_Bytes_Decoder_Specific(bool useSpan) |
||||
|
{ |
||||
|
TestFormat localFormat = new TestFormat(); |
||||
|
|
||||
|
var img = useSpan ? |
||||
|
Image.Load<Rgba32>(this.TopLevelConfiguration, this.ByteSpan, localFormat.Decoder) : |
||||
|
Image.Load<Rgba32>(this.TopLevelConfiguration, this.ByteArray, localFormat.Decoder); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
localFormat.VerifySpecificDecodeCall<Rgba32>(this.Marker, this.TopLevelConfiguration); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Configuration_Bytes_Decoder_Agnostic(bool useSpan) |
||||
|
{ |
||||
|
TestFormat localFormat = new TestFormat(); |
||||
|
|
||||
|
var img = useSpan ? |
||||
|
Image.Load(this.TopLevelConfiguration, this.ByteSpan, localFormat.Decoder) : |
||||
|
Image.Load(this.TopLevelConfiguration, this.ByteArray, localFormat.Decoder); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
localFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Configuration_Bytes_OutFormat_Specific(bool useSpan) |
||||
|
{ |
||||
|
IImageFormat format; |
||||
|
var img = useSpan ? |
||||
|
Image.Load<Bgr24>(this.TopLevelConfiguration, this.ByteSpan, out format) : |
||||
|
Image.Load<Bgr24>(this.TopLevelConfiguration, this.ByteArray, out format); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
Assert.Equal(this.TestFormat, format); |
||||
|
|
||||
|
this.TestFormat.VerifySpecificDecodeCall<Bgr24>(this.Marker, this.TopLevelConfiguration); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Configuration_Bytes_OutFormat_Agnostic(bool useSpan) |
||||
|
{ |
||||
|
IImageFormat format; |
||||
|
var img = useSpan ? |
||||
|
Image.Load(this.TopLevelConfiguration, this.ByteSpan, out format) : |
||||
|
Image.Load(this.TopLevelConfiguration, this.ByteArray, out format); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
Assert.Equal(this.TestFormat, format); |
||||
|
|
||||
|
this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,101 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
using System.IO; |
||||
|
|
||||
|
using SixLabors.ImageSharp.Formats; |
||||
|
using SixLabors.ImageSharp.Formats.Bmp; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
using SixLabors.Primitives; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests |
||||
|
{ |
||||
|
public partial class ImageTests |
||||
|
{ |
||||
|
public class Load_FromBytes_UseGlobalConfiguration |
||||
|
{ |
||||
|
private static byte[] ByteArray { get; } = TestFile.Create(TestImages.Bmp.F).Bytes; |
||||
|
|
||||
|
private static Span<byte> ByteSpan => new Span<byte>(ByteArray); |
||||
|
|
||||
|
private static void VerifyDecodedImage(Image img) |
||||
|
{ |
||||
|
Assert.Equal(new Size(108, 202), img.Size()); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Bytes_Specific(bool useSpan) |
||||
|
{ |
||||
|
using (var img = useSpan ? Image.Load<Rgba32>(ByteSpan) : Image.Load<Rgba32>(ByteArray)) |
||||
|
{ |
||||
|
VerifyDecodedImage(img); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Bytes_Agnostic(bool useSpan) |
||||
|
{ |
||||
|
using (var img = useSpan ? Image.Load(ByteSpan) : Image.Load(ByteArray)) |
||||
|
{ |
||||
|
VerifyDecodedImage(img); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Bytes_Decoder_Specific(bool useSpan) |
||||
|
{ |
||||
|
using (var img = useSpan ? Image.Load<Rgba32>(ByteSpan, new BmpDecoder()) : Image.Load<Rgba32>(ByteArray, new BmpDecoder())) |
||||
|
{ |
||||
|
VerifyDecodedImage(img); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Bytes_Decoder_Agnostic(bool useSpan) |
||||
|
{ |
||||
|
using (var img = useSpan ? Image.Load(ByteSpan, new BmpDecoder()) : Image.Load(ByteArray, new BmpDecoder())) |
||||
|
{ |
||||
|
VerifyDecodedImage(img); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Bytes_OutFormat_Specific(bool useSpan) |
||||
|
{ |
||||
|
IImageFormat format; |
||||
|
using (var img = useSpan ? Image.Load<Rgba32>(ByteSpan, out format) : Image.Load<Rgba32>(ByteArray, out format)) |
||||
|
{ |
||||
|
VerifyDecodedImage(img); |
||||
|
Assert.IsType<BmpFormat>(format); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(false)] |
||||
|
[InlineData(true)] |
||||
|
public void Bytes_OutFormat_Agnostic(bool useSpan) |
||||
|
{ |
||||
|
IImageFormat format; |
||||
|
using (var img = useSpan ? Image.Load(ByteSpan, out format) : Image.Load(ByteArray, out format)) |
||||
|
{ |
||||
|
VerifyDecodedImage(img); |
||||
|
Assert.IsType<BmpFormat>(format); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,102 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System.IO; |
|
||||
|
|
||||
using SixLabors.ImageSharp.Advanced; |
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
|
|
||||
using Xunit; |
|
||||
// ReSharper disable InconsistentNaming
|
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Tests |
|
||||
{ |
|
||||
using SixLabors.Primitives; |
|
||||
|
|
||||
public partial class ImageTests |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Tests the <see cref="Image"/> class.
|
|
||||
/// </summary>
|
|
||||
public class Load_FromStream : ImageLoadTestBase |
|
||||
{ |
|
||||
[Fact] |
|
||||
public void BasicCase() |
|
||||
{ |
|
||||
var img = Image.Load(this.TopLevelConfiguration, this.DataStream); |
|
||||
|
|
||||
Assert.NotNull(img); |
|
||||
Assert.Equal(this.TestFormat.Sample<Rgba32>(), img); |
|
||||
|
|
||||
this.TestFormat.VerifyDecodeCall(this.Marker, this.TopLevelConfiguration); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void UseGlobalConfiguration() |
|
||||
{ |
|
||||
byte[] data = TestFile.Create(TestImages.Bmp.F).Bytes; |
|
||||
|
|
||||
using (var stream = new MemoryStream(data)) |
|
||||
using (var img = Image.Load(stream)) |
|
||||
{ |
|
||||
Assert.Equal(new Size(108, 202), img.Size()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void NonDefaultPixelTypeImage() |
|
||||
{ |
|
||||
var img = Image.Load<Rgb24>(this.TopLevelConfiguration, this.DataStream); |
|
||||
|
|
||||
Assert.NotNull(img); |
|
||||
Assert.Equal(this.TestFormat.Sample<Rgb24>(), img); |
|
||||
|
|
||||
this.TestFormat.VerifyDecodeCall(this.Marker, this.TopLevelConfiguration); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void NonSeekableStream() |
|
||||
{ |
|
||||
var stream = new NoneSeekableStream(this.DataStream); |
|
||||
var img = Image.Load<Rgba32>(this.TopLevelConfiguration, stream); |
|
||||
|
|
||||
Assert.NotNull(img); |
|
||||
|
|
||||
this.TestFormat.VerifyDecodeCall(this.Marker, this.TopLevelConfiguration); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void UseLocalConfiguration() |
|
||||
{ |
|
||||
Stream stream = new MemoryStream(); |
|
||||
var img = Image.Load<Rgba32>(this.LocalConfiguration, stream); |
|
||||
|
|
||||
Assert.NotNull(img); |
|
||||
|
|
||||
this.localDecoder.Verify(x => x.Decode<Rgba32>(this.LocalConfiguration, stream)); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void UseCustomDecoder() |
|
||||
{ |
|
||||
Stream stream = new MemoryStream(); |
|
||||
var img = Image.Load<Rgba32>(this.TopLevelConfiguration, stream, this.localDecoder.Object); |
|
||||
|
|
||||
Assert.NotNull(img); |
|
||||
this.localDecoder.Verify(x => x.Decode<Rgba32>(this.TopLevelConfiguration, stream)); |
|
||||
} |
|
||||
|
|
||||
// TODO: This should be a png decoder test!
|
|
||||
[Fact] |
|
||||
public void LoadsImageWithoutThrowingCrcException() |
|
||||
{ |
|
||||
var image1Provider = TestImageProvider<Rgba32>.File(TestImages.Png.VersioningImage1); |
|
||||
|
|
||||
using (Image<Rgba32> img = image1Provider.GetImage()) |
|
||||
{ |
|
||||
Assert.Equal(166036, img.Frames.RootFrame.GetPixelSpan().Length); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,93 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System.IO; |
||||
|
|
||||
|
using SixLabors.ImageSharp.Formats; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests |
||||
|
{ |
||||
|
public partial class ImageTests |
||||
|
{ |
||||
|
public class Load_FromStream_PassLocalConfiguration : ImageLoadTestBase |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Configuration_Stream_Specific() |
||||
|
{ |
||||
|
var img = Image.Load<Rgb24>(this.TopLevelConfiguration, this.DataStream); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
Assert.Equal(this.TestFormat.Sample<Rgb24>(), img); |
||||
|
|
||||
|
this.TestFormat.VerifySpecificDecodeCall<Rgb24>(this.Marker, this.TopLevelConfiguration); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Configuration_Stream_Agnostic() |
||||
|
{ |
||||
|
var img = Image.Load(this.TopLevelConfiguration, this.DataStream); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
Assert.Equal(this.TestFormat.SampleAgnostic(), img); |
||||
|
|
||||
|
this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void NonSeekableStream() |
||||
|
{ |
||||
|
var stream = new NoneSeekableStream(this.DataStream); |
||||
|
var img = Image.Load<Rgba32>(this.TopLevelConfiguration, stream); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
|
||||
|
this.TestFormat.VerifySpecificDecodeCall<Rgba32>(this.Marker, this.TopLevelConfiguration); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Configuration_Stream_Decoder_Specific() |
||||
|
{ |
||||
|
Stream stream = new MemoryStream(); |
||||
|
var img = Image.Load<Rgba32>(this.TopLevelConfiguration, stream, this.localDecoder.Object); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
this.localDecoder.Verify(x => x.Decode<Rgba32>(this.TopLevelConfiguration, stream)); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Configuration_Stream_Decoder_Agnostic() |
||||
|
{ |
||||
|
Stream stream = new MemoryStream(); |
||||
|
var img = Image.Load(this.TopLevelConfiguration, stream, this.localDecoder.Object); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, stream)); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Configuration_Stream_OutFormat_Specific() |
||||
|
{ |
||||
|
var img = Image.Load<Rgba32>(this.TopLevelConfiguration, this.DataStream, out IImageFormat format); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
Assert.Equal(this.TestFormat, format); |
||||
|
|
||||
|
this.TestFormat.VerifySpecificDecodeCall<Rgba32>(this.Marker, this.TopLevelConfiguration); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Configuration_Stream_OutFormat_Agnostic() |
||||
|
{ |
||||
|
var img = Image.Load(this.TopLevelConfiguration, this.DataStream, out IImageFormat format); |
||||
|
|
||||
|
Assert.NotNull(img); |
||||
|
Assert.Equal(this.TestFormat, format); |
||||
|
|
||||
|
this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,95 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System.IO; |
||||
|
|
||||
|
using SixLabors.ImageSharp.Formats; |
||||
|
using SixLabors.ImageSharp.Formats.Bmp; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
using SixLabors.Primitives; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests |
||||
|
{ |
||||
|
public partial class ImageTests |
||||
|
{ |
||||
|
public class Load_FromStream_UseDefaultConfiguration |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Stream_Specific() |
||||
|
{ |
||||
|
byte[] data = TestFile.Create(TestImages.Bmp.F).Bytes; |
||||
|
|
||||
|
using (var stream = new MemoryStream(data)) |
||||
|
using (var img = Image.Load<Rgba32>(stream)) |
||||
|
{ |
||||
|
Assert.Equal(new Size(108, 202), img.Size()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Stream_Agnostic() |
||||
|
{ |
||||
|
byte[] data = TestFile.Create(TestImages.Bmp.F).Bytes; |
||||
|
|
||||
|
using (var stream = new MemoryStream(data)) |
||||
|
using (var img = Image.Load(stream)) |
||||
|
{ |
||||
|
Assert.Equal(new Size(108, 202), img.Size()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Stream_OutFormat_Specific() |
||||
|
{ |
||||
|
byte[] data = TestFile.Create(TestImages.Bmp.F).Bytes; |
||||
|
|
||||
|
|
||||
|
using (var stream = new MemoryStream(data)) |
||||
|
using (var img = Image.Load<Rgba32>(stream, out IImageFormat format)) |
||||
|
{ |
||||
|
Assert.Equal(new Size(108, 202), img.Size()); |
||||
|
Assert.IsType<BmpFormat>(format); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Stream_Decoder_Specific() |
||||
|
{ |
||||
|
byte[] data = TestFile.Create(TestImages.Bmp.F).Bytes; |
||||
|
|
||||
|
using (var stream = new MemoryStream(data)) |
||||
|
using (var img = Image.Load<Rgba32>(stream, new BmpDecoder())) |
||||
|
{ |
||||
|
Assert.Equal(new Size(108, 202), img.Size()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Stream_Decoder_Agnostic() |
||||
|
{ |
||||
|
byte[] data = TestFile.Create(TestImages.Bmp.F).Bytes; |
||||
|
|
||||
|
using (var stream = new MemoryStream(data)) |
||||
|
using (var img = Image.Load(stream, new BmpDecoder())) |
||||
|
{ |
||||
|
Assert.Equal(new Size(108, 202), img.Size()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Stream_OutFormat_Agnostic() |
||||
|
{ |
||||
|
byte[] data = TestFile.Create(TestImages.Bmp.F).Bytes; |
||||
|
|
||||
|
using (var stream = new MemoryStream(data)) |
||||
|
using (var img = Image.Load(stream, out IImageFormat format)) |
||||
|
{ |
||||
|
Assert.Equal(new Size(108, 202), img.Size()); |
||||
|
Assert.IsType<BmpFormat>(format); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue