mirror of https://github.com/SixLabors/ImageSharp
21 changed files with 372 additions and 1 deletions
@ -0,0 +1,106 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
using SixLabors.ImageSharp.Formats.Bmp; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|||
using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; |
|||
|
|||
using Xunit; |
|||
|
|||
// ReSharper disable InconsistentNaming
|
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Formats.WebP |
|||
{ |
|||
using SixLabors.ImageSharp.Metadata; |
|||
using static TestImages.Bmp; |
|||
|
|||
public class WebPDecoderTests |
|||
{ |
|||
public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector; |
|||
|
|||
public static readonly string[] MiscBmpFiles = Miscellaneous; |
|||
|
|||
public static readonly string[] BitfieldsBmpFiles = BitFields; |
|||
|
|||
public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles = |
|||
new TheoryData<string, int, int, PixelResolutionUnit> |
|||
{ |
|||
{ Car, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter }, |
|||
{ V5Header, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter }, |
|||
{ RLE8, 2835, 2835, PixelResolutionUnit.PixelsPerMeter } |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(MiscBmpFiles), PixelTypes.Rgba32)] |
|||
public void BmpDecoder_CanDecode_MiscellaneousBitmaps<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage(new BmpDecoder())) |
|||
{ |
|||
image.DebugSave(provider); |
|||
if (TestEnvironment.IsWindows) |
|||
{ |
|||
image.CompareToOriginal(provider); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFile(Bit16Inverted, PixelTypes.Rgba32)] |
|||
[WithFile(Bit8Inverted, PixelTypes.Rgba32)] |
|||
public void BmpDecoder_CanDecode_Inverted<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage(new BmpDecoder())) |
|||
{ |
|||
image.DebugSave(provider); |
|||
image.CompareToOriginal(provider); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(Bit32Rgb, 32)] |
|||
[InlineData(Bit32Rgba, 32)] |
|||
[InlineData(Car, 24)] |
|||
[InlineData(F, 24)] |
|||
[InlineData(NegHeight, 24)] |
|||
[InlineData(Bit16, 16)] |
|||
[InlineData(Bit16Inverted, 16)] |
|||
[InlineData(Bit8, 8)] |
|||
[InlineData(Bit8Inverted, 8)] |
|||
[InlineData(Bit4, 4)] |
|||
[InlineData(Bit1, 1)] |
|||
[InlineData(Bit1Pal1, 1)] |
|||
public void Identify_DetectsCorrectPixelType(string imagePath, int expectedPixelSize) |
|||
{ |
|||
var testFile = TestFile.Create(imagePath); |
|||
using (var stream = new MemoryStream(testFile.Bytes, false)) |
|||
{ |
|||
IImageInfo imageInfo = Image.Identify(stream); |
|||
Assert.NotNull(imageInfo); |
|||
Assert.Equal(expectedPixelSize, imageInfo.PixelType?.BitsPerPixel); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(RatioFiles))] |
|||
public void Decode_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) |
|||
{ |
|||
var testFile = TestFile.Create(imagePath); |
|||
using (var stream = new MemoryStream(testFile.Bytes, false)) |
|||
{ |
|||
var decoder = new BmpDecoder(); |
|||
using (Image<Rgba32> image = decoder.Decode<Rgba32>(Configuration.Default, stream)) |
|||
{ |
|||
ImageMetadata meta = image.Metadata; |
|||
Assert.Equal(xResolution, meta.HorizontalResolution); |
|||
Assert.Equal(yResolution, meta.VerticalResolution); |
|||
Assert.Equal(resolutionUnit, meta.ResolutionUnits); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,116 @@ |
|||
// 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.Metadata; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Processing; |
|||
using SixLabors.ImageSharp.Processing.Processors.Quantization; |
|||
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|||
|
|||
using Xunit; |
|||
using Xunit.Abstractions; |
|||
|
|||
// ReSharper disable InconsistentNaming
|
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Formats.WebP |
|||
{ |
|||
using static TestImages.Bmp; |
|||
|
|||
public class WebPEncoderTests |
|||
{ |
|||
public static readonly TheoryData<BmpBitsPerPixel> BitsPerPixel = |
|||
new TheoryData<BmpBitsPerPixel> |
|||
{ |
|||
BmpBitsPerPixel.Pixel24, |
|||
BmpBitsPerPixel.Pixel32 |
|||
}; |
|||
|
|||
public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles = |
|||
new TheoryData<string, int, int, PixelResolutionUnit> |
|||
{ |
|||
{ Car, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter }, |
|||
{ V5Header, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter }, |
|||
{ RLE8, 2835, 2835, PixelResolutionUnit.PixelsPerMeter } |
|||
}; |
|||
|
|||
public static readonly TheoryData<string, BmpBitsPerPixel> BmpBitsPerPixelFiles = |
|||
new TheoryData<string, BmpBitsPerPixel> |
|||
{ |
|||
{ Car, BmpBitsPerPixel.Pixel24 }, |
|||
{ Bit32Rgb, BmpBitsPerPixel.Pixel32 } |
|||
}; |
|||
|
|||
public WebPEncoderTests(ITestOutputHelper output) => this.Output = output; |
|||
|
|||
private ITestOutputHelper Output { get; } |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(RatioFiles))] |
|||
public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) |
|||
{ |
|||
var options = new BmpEncoder(); |
|||
|
|||
var testFile = TestFile.Create(imagePath); |
|||
using (Image<Rgba32> input = testFile.CreateRgba32Image()) |
|||
{ |
|||
using (var memStream = new MemoryStream()) |
|||
{ |
|||
input.Save(memStream, options); |
|||
|
|||
memStream.Position = 0; |
|||
using (var output = Image.Load<Rgba32>(memStream)) |
|||
{ |
|||
ImageMetadata meta = output.Metadata; |
|||
Assert.Equal(xResolution, meta.HorizontalResolution); |
|||
Assert.Equal(yResolution, meta.VerticalResolution); |
|||
Assert.Equal(resolutionUnit, meta.ResolutionUnits); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithTestPatternImages(nameof(BitsPerPixel), 48, 24, PixelTypes.Rgba32)] |
|||
[WithTestPatternImages(nameof(BitsPerPixel), 47, 8, PixelTypes.Rgba32)] |
|||
[WithTestPatternImages(nameof(BitsPerPixel), 49, 7, PixelTypes.Rgba32)] |
|||
[WithSolidFilledImages(nameof(BitsPerPixel), 1, 1, 255, 100, 50, 255, PixelTypes.Rgba32)] |
|||
[WithTestPatternImages(nameof(BitsPerPixel), 7, 5, PixelTypes.Rgba32)] |
|||
public void Encode_WorksWithDifferentSizes<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|||
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel); |
|||
|
|||
[Theory] |
|||
[WithFile(Bit32Rgb, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)] |
|||
[WithFile(Bit32Rgba, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)] |
|||
[WithFile(WinBmpv4, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)] |
|||
[WithFile(WinBmpv5, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)] |
|||
public void Encode_32Bit_WithV3Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|||
// if supportTransparency is false, a v3 bitmap header will be written
|
|||
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: false); |
|||
|
|||
private static void TestBmpEncoderCore<TPixel>( |
|||
TestImageProvider<TPixel> provider, |
|||
BmpBitsPerPixel bitsPerPixel, |
|||
bool supportTransparency = true, |
|||
ImageComparer customComparer = null) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
// There is no alpha in bmp with less then 32 bits per pixels, so the reference image will be made opaque.
|
|||
if (bitsPerPixel != BmpBitsPerPixel.Pixel32) |
|||
{ |
|||
image.Mutate(c => c.MakeOpaque()); |
|||
} |
|||
|
|||
var encoder = new BmpEncoder { BitsPerPixel = bitsPerPixel, SupportTransparency = supportTransparency }; |
|||
|
|||
// Does DebugSave & load reference CompareToReferenceInput():
|
|||
image.VerifyEncoder(provider, "bmp", bitsPerPixel, encoder, customComparer); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using SixLabors.ImageSharp.Formats.Bmp; |
|||
using Xunit; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Formats.WebP |
|||
{ |
|||
public class WebPFileHeaderTests |
|||
{ |
|||
[Fact] |
|||
public void TestWrite() |
|||
{ |
|||
var header = new BmpFileHeader(1, 2, 3, 4); |
|||
|
|||
var buffer = new byte[14]; |
|||
|
|||
header.WriteTo(buffer); |
|||
|
|||
Assert.Equal("AQACAAAAAwAAAAQAAAA=", Convert.ToBase64String(buffer)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.IO; |
|||
|
|||
using SixLabors.ImageSharp.Formats.Bmp; |
|||
using Xunit; |
|||
|
|||
// ReSharper disable InconsistentNaming
|
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Formats.WebP |
|||
{ |
|||
using static TestImages.Bmp; |
|||
|
|||
public class WebPMetaDataTests |
|||
{ |
|||
[Fact] |
|||
public void CloneIsDeep() |
|||
{ |
|||
var meta = new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Pixel24 }; |
|||
var clone = (BmpMetadata)meta.DeepClone(); |
|||
|
|||
clone.BitsPerPixel = BmpBitsPerPixel.Pixel32; |
|||
|
|||
Assert.False(meta.BitsPerPixel.Equals(clone.BitsPerPixel)); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(WinBmpv2, BmpInfoHeaderType.WinVersion2)] |
|||
[InlineData(WinBmpv3, BmpInfoHeaderType.WinVersion3)] |
|||
[InlineData(WinBmpv4, BmpInfoHeaderType.WinVersion4)] |
|||
[InlineData(WinBmpv5, BmpInfoHeaderType.WinVersion5)] |
|||
[InlineData(Os2v2Short, BmpInfoHeaderType.Os2Version2Short)] |
|||
[InlineData(Rgb32h52AdobeV3, BmpInfoHeaderType.AdobeVersion3)] |
|||
[InlineData(Rgba32bf56AdobeV3, BmpInfoHeaderType.AdobeVersion3WithAlpha)] |
|||
[InlineData(Os2v2, BmpInfoHeaderType.Os2Version2)] |
|||
public void Identify_DetectsCorrectBitmapInfoHeaderType(string imagePath, BmpInfoHeaderType expectedInfoHeaderType) |
|||
{ |
|||
var testFile = TestFile.Create(imagePath); |
|||
using (var stream = new MemoryStream(testFile.Bytes, false)) |
|||
{ |
|||
IImageInfo imageInfo = Image.Identify(stream); |
|||
Assert.NotNull(imageInfo); |
|||
BmpMetadata bitmapMetaData = imageInfo.Metadata.GetFormatMetadata(BmpFormat.Instance); |
|||
Assert.NotNull(bitmapMetaData); |
|||
Assert.Equal(expectedInfoHeaderType, bitmapMetaData.InfoHeaderType); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1 +1 @@ |
|||
Subproject commit 1d3d4e3652dc95bd8bd420346bfe0f189addc587 |
|||
Subproject commit 99a2bc523cd4eb00e37af20d1b2088fa11564c57 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:694f9011eddb7d0f08fc76ddad6b2129f2390d1e44c41a9ed9de0f08bb14c43b |
|||
size 81977 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:ee83dd1211ba339e9a61a9af5e24a9fa5b8168ea448eacf4743bdcc36f58452b |
|||
size 27669 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:8c96ed502862c0adc1f4221da1bd31d0921853f62eebcbbb89fec4e862ecb1de |
|||
size 152634 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:8eff718866d464cd27161e171bb83ad73a05befae0724c2c75a772a7e21ac3b9 |
|||
size 34096 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:0da93a44371abecdc68ad082c73ec633c3cd02d547fe28992403086a9e110946 |
|||
size 99425 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:d8b4596c10a23135931b4e63957eda41e9b3874811d9b724d890b589d66ea12f |
|||
size 30319 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:1ac427ad555ba5898015e8b60396e1852bfc1e9cd7ae5da6dd42c85ea3e169f7 |
|||
size 60600 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:ebf4dc48653bd5f3c5b929ae3a411a0e440eb316aa50c80b1591d98db865bd5a |
|||
size 203135 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:6f354f8954071f0b979a40866de95f2113a6ce54f4fe483c7f2b269c913f0df3 |
|||
size 176969 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:7558b0f5da141787fcc41857743f8bc9417c844e2a19aeaa5fee25f1433abe4e |
|||
size 82697 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:e89d207eff1f1499acd6a5b8dc4a326ecdf3d303e4a7e6fc65c268035326a75f |
|||
size 18840 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:8c7f6772cdaf74fe5dac79d8acd7da48cc3700159f41e9dd2ebae8dd7c81b548 |
|||
size 14412 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:c648a83fa93378259b8c71db58b4f47e5b4bf6f980b7d418346c4a2cf9ad6664 |
|||
size 53817 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:d2b4164bf2facd2b212e5eb15eb3066254c785b35d14d79341d178d8692e6e28 |
|||
size 19440 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:5988b9e71686b385d76c5fba81d09642d1f08a079cabe81d653b025a40abe4f1 |
|||
size 58712 |
|||
Loading…
Reference in new issue