Browse Source

Add support for ICC conversion to WEBP

pull/3051/head
James Jackson-South 1 week ago
parent
commit
d9816d12b5
  1. 1
      src/ImageSharp/Formats/Webp/WebpDecoderCore.cs
  2. 1
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  3. 14
      tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs
  4. 6
      tests/ImageSharp.Tests/TestImages.cs
  5. 3
      tests/Images/External/ReferenceOutput/WebpDecoderTests/Decode_WhenColorProfileHandlingIsConvert_ApplyIccProfile_Rgba32_Perceptual-cLUT-only.png
  6. 3
      tests/Images/External/ReferenceOutput/WebpDecoderTests/Decode_WhenColorProfileHandlingIsConvert_ApplyIccProfile_Rgba32_Perceptual.png
  7. 3
      tests/Images/Input/Webp/icc-profiles/Perceptual-cLUT-only.webp
  8. 3
      tests/Images/Input/Webp/icc-profiles/Perceptual.webp

1
src/ImageSharp/Formats/Webp/WebpDecoderCore.cs

@ -122,6 +122,7 @@ internal sealed class WebpDecoderCore : ImageDecoderCore, IDisposable
this.ParseOptionalChunks(stream, metadata, this.webImageInfo.Features, buffer);
}
_ = this.TryConvertIccProfile(image);
return image;
}
}

1
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -5,6 +5,7 @@ using System.Runtime.Intrinsics.X86;
using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Formats.Webp;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities;

14
tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs

@ -3,6 +3,7 @@
using System.Runtime.Intrinsics.X86;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Formats.Webp;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
@ -608,4 +609,17 @@ public class WebpDecoderTests
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
[Theory]
[WithFile(Icc.Perceptual, PixelTypes.Rgba32)]
[WithFile(Icc.PerceptualcLUTOnly, PixelTypes.Rgba32)]
public void Decode_WhenColorProfileHandlingIsConvert_ApplyIccProfile<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(WebpDecoder.Instance, new DecoderOptions { ColorProfileHandling = ColorProfileHandling.Convert });
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
Assert.Null(image.Metadata.IccProfile);
}
}

6
tests/ImageSharp.Tests/TestImages.cs

@ -901,6 +901,12 @@ public static class TestImages
public const string AlphaBlend2 = "Webp/alpha-blend-2.webp";
public const string AlphaBlend3 = "Webp/alpha-blend-3.webp";
public const string AlphaBlend4 = "Webp/alpha-blend-4.webp";
public static class Icc
{
public const string Perceptual = "Webp/icc-profiles/Perceptual.webp";
public const string PerceptualcLUTOnly = "Webp/icc-profiles/Perceptual-cLUT-only.webp";
}
}
public static class Tiff

3
tests/Images/External/ReferenceOutput/WebpDecoderTests/Decode_WhenColorProfileHandlingIsConvert_ApplyIccProfile_Rgba32_Perceptual-cLUT-only.png

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9a2cbd483eed31cf7b410ef1ee45ae78e77b36e5b9c31f87764a1dfdb9c4e5c8
size 79768

3
tests/Images/External/ReferenceOutput/WebpDecoderTests/Decode_WhenColorProfileHandlingIsConvert_ApplyIccProfile_Rgba32_Perceptual.png

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:547f3ddb5bdb3a3cb5c87440b65728be295c2b5f3c10a1b0b44299bb3d80e8d7
size 79651

3
tests/Images/Input/Webp/icc-profiles/Perceptual-cLUT-only.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7b7ef9eedd1b2a4b93f11ac52807c071f7d0a24513008c3e69b0d4a0fd9b70db
size 186596

3
tests/Images/Input/Webp/icc-profiles/Perceptual.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:aad13221b103b60c21a19e7ecfbab047404f25269485d26fc5dee4be11188865
size 189800
Loading…
Cancel
Save