mirror of https://github.com/SixLabors/ImageSharp
4 changed files with 82 additions and 0 deletions
@ -0,0 +1,72 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
using SixLabors.ImageSharp.Formats; |
||||
|
using SixLabors.ImageSharp.Formats.Png; |
||||
|
using SixLabors.ImageSharp.Metadata.Profiles.CICP; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.Cicp; |
||||
|
|
||||
|
public class CicpProfileTests |
||||
|
{ |
||||
|
[Theory] |
||||
|
[WithFile(TestImages.Png.AdamHeadsHlg, PixelTypes.Rgba64)] |
||||
|
public async Task ReadCicpMetadata_FromPng_Works<TPixel>(TestImageProvider<TPixel> provider) |
||||
|
where TPixel : unmanaged, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = await provider.GetImageAsync(PngDecoder.Instance)) |
||||
|
{ |
||||
|
CicpProfile actual = image.Metadata.CicpProfile ?? image.Frames.RootFrame.Metadata.CicpProfile; |
||||
|
CicpProfileContainsExpectedValues(actual); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void WritingPng_PreservesCicpProfile() |
||||
|
{ |
||||
|
// arrange
|
||||
|
using var image = new Image<Rgba32>(1, 1); |
||||
|
var original = new CicpProfile() |
||||
|
{ |
||||
|
ColorPrimaries = CicpColorPrimaries.ItuRBt2020_2, |
||||
|
TransferCharacteristics = CicpTransferCharacteristics.SmpteSt2084, |
||||
|
MatrixCoefficients = CicpMatrixCoefficients.Identity, |
||||
|
FullRange = true, |
||||
|
}; |
||||
|
image.Metadata.CicpProfile = original; |
||||
|
var encoder = new PngEncoder(); |
||||
|
|
||||
|
// act
|
||||
|
using Image<Rgba32> reloadedImage = WriteAndRead(image, encoder); |
||||
|
|
||||
|
// assert
|
||||
|
CicpProfile actual = reloadedImage.Metadata.CicpProfile ?? reloadedImage.Frames.RootFrame.Metadata.CicpProfile; |
||||
|
Assert.NotNull(actual); |
||||
|
Assert.Equal(actual.ColorPrimaries, original.ColorPrimaries); |
||||
|
Assert.Equal(actual.TransferCharacteristics, original.TransferCharacteristics); |
||||
|
Assert.Equal(actual.MatrixCoefficients, original.MatrixCoefficients); |
||||
|
Assert.Equal(actual.FullRange, original.FullRange); |
||||
|
} |
||||
|
|
||||
|
private static void CicpProfileContainsExpectedValues(CicpProfile cicp) |
||||
|
{ |
||||
|
Assert.NotNull(cicp); |
||||
|
Assert.Equal(CicpColorPrimaries.ItuRBt2020_2, cicp.ColorPrimaries); |
||||
|
Assert.Equal(CicpTransferCharacteristics.AribStdB67, cicp.TransferCharacteristics); |
||||
|
Assert.Equal(CicpMatrixCoefficients.Identity, cicp.MatrixCoefficients); |
||||
|
Assert.True(cicp.FullRange); |
||||
|
} |
||||
|
|
||||
|
private static Image<Rgba32> WriteAndRead(Image<Rgba32> image, IImageEncoder encoder) |
||||
|
{ |
||||
|
using (var memStream = new MemoryStream()) |
||||
|
{ |
||||
|
image.Save(memStream, encoder); |
||||
|
image.Dispose(); |
||||
|
|
||||
|
memStream.Position = 0; |
||||
|
return Image.Load<Rgba32>(memStream); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,3 @@ |
|||||
|
version https://git-lfs.github.com/spec/v1 |
||||
|
oid sha256:8c50691da3b3af21ff4f8fc30f1313bc412b84fb0a07a5bf3b8b14eae7581ade |
||||
|
size 201440 |
||||
Loading…
Reference in new issue