From b30698c53c8f736d5602becf71197f8daaa04f33 Mon Sep 17 00:00:00 2001 From: Tammo Hinrichs Date: Fri, 24 Nov 2023 18:09:58 +0100 Subject: [PATCH] Cleanups (capitalization, tests) --- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 2 +- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 2 +- src/ImageSharp/Metadata/ImageFrameMetadata.cs | 2 +- src/ImageSharp/Metadata/ImageMetadata.cs | 2 +- .../Metadata/Profiles/CICP/CicpProfile.cs | 4 +- .../Profiles/CICP/Enums/CicpColorPrimaries.cs | 2 +- .../CICP/Enums/CicpMatrixCoefficients.cs | 2 +- .../CICP/Enums/CicpTransferCharacteristics.cs | 4 +- .../Profiles/CICP/CicpProfileTests.cs | 46 +++++++++++-------- 9 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index acb97ed89..26bcaed27 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -16,7 +16,7 @@ using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Metadata; -using SixLabors.ImageSharp.Metadata.Profiles.CICP; +using SixLabors.ImageSharp.Metadata.Profiles.Cicp; using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Metadata.Profiles.Icc; using SixLabors.ImageSharp.Metadata.Profiles.Xmp; diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 4e8792c0e..3ce6170b5 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -787,7 +787,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable } // by spec, the matrix coefficients must be set to Identity - if (metaData.CicpProfile.MatrixCoefficients != Metadata.Profiles.CICP.CicpMatrixCoefficients.Identity) + if (metaData.CicpProfile.MatrixCoefficients != Metadata.Profiles.Cicp.CicpMatrixCoefficients.Identity) { throw new NotSupportedException("CICP matrix coefficients other than Identity are not supported in PNG"); } diff --git a/src/ImageSharp/Metadata/ImageFrameMetadata.cs b/src/ImageSharp/Metadata/ImageFrameMetadata.cs index f02ef39c4..1c0330d5d 100644 --- a/src/ImageSharp/Metadata/ImageFrameMetadata.cs +++ b/src/ImageSharp/Metadata/ImageFrameMetadata.cs @@ -2,7 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.Metadata.Profiles.CICP; +using SixLabors.ImageSharp.Metadata.Profiles.Cicp; using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Metadata.Profiles.Icc; using SixLabors.ImageSharp.Metadata.Profiles.Iptc; diff --git a/src/ImageSharp/Metadata/ImageMetadata.cs b/src/ImageSharp/Metadata/ImageMetadata.cs index c6ff6fe73..db6e6094e 100644 --- a/src/ImageSharp/Metadata/ImageMetadata.cs +++ b/src/ImageSharp/Metadata/ImageMetadata.cs @@ -2,7 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.Metadata.Profiles.CICP; +using SixLabors.ImageSharp.Metadata.Profiles.Cicp; using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Metadata.Profiles.Icc; using SixLabors.ImageSharp.Metadata.Profiles.Iptc; diff --git a/src/ImageSharp/Metadata/Profiles/CICP/CicpProfile.cs b/src/ImageSharp/Metadata/Profiles/CICP/CicpProfile.cs index 5d6e357c4..2657903df 100644 --- a/src/ImageSharp/Metadata/Profiles/CICP/CicpProfile.cs +++ b/src/ImageSharp/Metadata/Profiles/CICP/CicpProfile.cs @@ -1,10 +1,10 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -namespace SixLabors.ImageSharp.Metadata.Profiles.CICP; +namespace SixLabors.ImageSharp.Metadata.Profiles.Cicp; /// -/// Represents a CICP profile as per ITU-T H.273 / ISO/IEC 23091-2_2019 providing access to color space information +/// Represents a Cicp profile as per ITU-T H.273 / ISO/IEC 23091-2_2019 providing access to color space information /// public sealed class CicpProfile : IDeepCloneable { diff --git a/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpColorPrimaries.cs b/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpColorPrimaries.cs index 390c6a263..bab888dd7 100644 --- a/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpColorPrimaries.cs +++ b/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpColorPrimaries.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -namespace SixLabors.ImageSharp.Metadata.Profiles.CICP; +namespace SixLabors.ImageSharp.Metadata.Profiles.Cicp; #pragma warning disable CA1707 // Underscores in enum members diff --git a/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpMatrixCoefficients.cs b/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpMatrixCoefficients.cs index 6b421ab9b..931beac84 100644 --- a/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpMatrixCoefficients.cs +++ b/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpMatrixCoefficients.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -namespace SixLabors.ImageSharp.Metadata.Profiles.CICP; +namespace SixLabors.ImageSharp.Metadata.Profiles.Cicp; #pragma warning disable CA1707 // Underscores in enum members diff --git a/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpTransferCharacteristics.cs b/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpTransferCharacteristics.cs index f9bc8d90e..86eea0b70 100644 --- a/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpTransferCharacteristics.cs +++ b/src/ImageSharp/Metadata/Profiles/CICP/Enums/CicpTransferCharacteristics.cs @@ -1,9 +1,9 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -namespace SixLabors.ImageSharp.Metadata.Profiles.CICP; +namespace SixLabors.ImageSharp.Metadata.Profiles.Cicp; -#pragma warning disable CA1707 // Underscores in enum members +#pragma warning disable CA1707 // Underscores in enum values /// /// Transfer characteristics according to ITU-T H.273 / ISO/IEC 23091-2_2019 subclause 8.2 diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/CICP/CicpProfileTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/CICP/CicpProfileTests.cs index be215a088..76e2d35c4 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/CICP/CicpProfileTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/CICP/CicpProfileTests.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Png; -using SixLabors.ImageSharp.Metadata.Profiles.CICP; +using SixLabors.ImageSharp.Metadata.Profiles.Cicp; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.Cicp; @@ -15,11 +15,10 @@ public class CicpProfileTests public async Task ReadCicpMetadata_FromPng_Works(TestImageProvider provider) where TPixel : unmanaged, IPixel { - using (Image image = await provider.GetImageAsync(PngDecoder.Instance)) - { - CicpProfile actual = image.Metadata.CicpProfile ?? image.Frames.RootFrame.Metadata.CicpProfile; - CicpProfileContainsExpectedValues(actual); - } + using Image image = await provider.GetImageAsync(PngDecoder.Instance); + + CicpProfile actual = image.Metadata.CicpProfile ?? image.Frames.RootFrame.Metadata.CicpProfile; + CicpProfileContainsExpectedValues(actual); } [Fact] @@ -27,13 +26,7 @@ public class CicpProfileTests { // arrange using var image = new Image(1, 1); - var original = new CicpProfile() - { - ColorPrimaries = CicpColorPrimaries.ItuRBt2020_2, - TransferCharacteristics = CicpTransferCharacteristics.SmpteSt2084, - MatrixCoefficients = CicpMatrixCoefficients.Identity, - FullRange = true, - }; + var original = CreateCicpProfile(); image.Metadata.CicpProfile = original; var encoder = new PngEncoder(); @@ -42,11 +35,7 @@ public class CicpProfileTests // 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); + CicpProfileIsValidAndEqual(actual, original); } private static void CicpProfileContainsExpectedValues(CicpProfile cicp) @@ -58,6 +47,27 @@ public class CicpProfileTests Assert.True(cicp.FullRange); } + private static CicpProfile CreateCicpProfile() + { + var profile = new CicpProfile() + { + ColorPrimaries = CicpColorPrimaries.ItuRBt2020_2, + TransferCharacteristics = CicpTransferCharacteristics.SmpteSt2084, + MatrixCoefficients = CicpMatrixCoefficients.Identity, + FullRange = true, + }; + return profile; + } + + private static void CicpProfileIsValidAndEqual(CicpProfile actual, CicpProfile original) + { + 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 Image WriteAndRead(Image image, IImageEncoder encoder) { using (var memStream = new MemoryStream())