Skip to content

Conversation

@JimBobSquarePants
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This pull request adds support for ICC color profile conversion in the WebP decoder and corresponding tests and test images to validate this behavior. It also introduces significant SIMD optimizations for color profile conversions in the Rgb struct and related code, leveraging AVX2 and AVX-512 intrinsics for much faster pixel processing.

WebP Decoder: ICC Profile Conversion Support

  • Modified WebpDecoderCore to attempt ICC profile conversion when decoding images, aligning its behavior with other decoders when ColorProfileHandling.Convert is set.

Testing: New Test Cases and Assets

  • Added new WebP test images containing ICC profiles and corresponding reference PNG outputs to validate ICC profile conversion. [1] [2] [3] [4]
  • Introduced new test cases in WebpDecoderTests to verify that ICC profiles are correctly converted and removed from metadata when ColorProfileHandling.Convert is used. [1] [2]
  • Updated test imports to include new references for WebP and PNG as needed. [1] [2]

SIMD Optimizations for Color Conversion

  • Added AVX2 and AVX-512 intrinsics to accelerate Rgb.ToScaledVector4, Rgb.FromScaledVector4, and the color profile conversion in ColorProfileConverterExtensionsPixelCompatible, resulting in much faster color conversion by processing multiple pixels in parallel. Helper methods for reading/writing SIMD vectors were also added. [1] [2] [3] [4] [5]
  • Ensured that alpha channels are preserved during SIMD color conversions by blending only the RGB channels and leaving alpha untouched.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds ICC profile conversion support to the WebP decoder and introduces AVX2/AVX‑512 SIMD optimizations for RGB/color-profile conversions, plus tests and assets to validate the new behavior.

Changes:

  • Extends WebpDecoderCore to run ICC profile conversion via TryConvertIccProfile after decoding single-frame images.
  • Adds WebP ICC-profile test images and reference PNG outputs, and new WebP decoder tests that validate ICC conversion/removal when ColorProfileHandling.Convert is used.
  • Optimizes Rgb.ToScaledVector4 / Rgb.FromScaledVector4 and ColorProfileConverterExtensionsPixelCompatible.Convert with AVX2/AVX‑512 paths to accelerate RGB vectorization and profile conversion while preserving alpha.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Images/Input/Webp/icc-profiles/Perceptual.webp New WebP test asset with perceptual ICC profile for WebP ICC conversion tests (LFS pointer).
tests/Images/Input/Webp/icc-profiles/Perceptual-cLUT-only.webp New WebP test asset with perceptual cLUT-only ICC profile for ICC conversion tests (LFS pointer).
tests/Images/External/ReferenceOutput/WebpDecoderTests/Decode_WhenColorProfileHandlingIsConvert_ApplyIccProfile_Rgba32_Perceptual.png Reference PNG output for WebP perceptual ICC profile conversion test (LFS pointer).
tests/Images/External/ReferenceOutput/WebpDecoderTests/Decode_WhenColorProfileHandlingIsConvert_ApplyIccProfile_Rgba32_Perceptual-cLUT-only.png Reference PNG output for WebP perceptual cLUT-only ICC profile conversion test (LFS pointer).
tests/ImageSharp.Tests/TestImages.cs Adds Lossy.Icc WebP paths (Perceptual, PerceptualcLUTOnly) so tests can reference the new ICC WebP assets.
tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs Adds ICC conversion test for WebP using the new ICC WebP images and reference PNGs, plus (unused) PNG using directive.
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs Imports WebP namespace (currently unused) in PNG decoder tests while leaving existing ICC tests unchanged.
src/ImageSharp/Formats/Webp/WebpDecoderCore.cs Calls TryConvertIccProfile(image) after parsing optional chunks to align WebP ICC handling with other decoders.
src/ImageSharp/ColorProfiles/Rgb.cs Replaces scalar loops in ToScaledVector4/FromScaledVector4 with AVX2/AVX‑512 SIMD implementations and adds helper read/write intrinsics.
src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsPixelCompatible.cs Optimizes pixel-compatible ICC conversion path with AVX2/AVX‑512 to merge converted RGB back into Vector4 rows while preserving alpha.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JimBobSquarePants JimBobSquarePants merged commit da6d56b into main Jan 28, 2026
11 checks passed
@JimBobSquarePants JimBobSquarePants deleted the js/webp-icc branch January 28, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants