@ -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 |
|||
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 198 KiB |
|
After Width: | Height: | Size: 173 KiB |
|
After Width: | Height: | Size: 81 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 57 KiB |