Prerequisites
ImageSharp version
4.1.2
Other ImageSharp packages and versions
- SixLabors.ImageSharp.Drawing 3.1.0 - SixLabors.ImageSharp.Web 4.0.1
Environment (Operating system, version and so on)
Windows 11
.NET Framework version
.NET 10.0
Description
When loading a JPEG image with an embedded grayscale ICC profile using ColorProfileHandling.Convert, the image is rendered incorrectly. The colors are flattened to a uniform light gray instead of preserving the original grayscale tones. However, when using ColorProfileHandling.Preserve, the image renders correctly with the expected gray tones.
The issue appears to be in the ICC profile conversion logic when handling grayscale color spaces. The conversion from the grayscale ICC profile to sRGB is not producing the correct pixel values.
Steps to Reproduce
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
// Load image with ColorProfileHandling.Convert (INCORRECT - flattens to light gray)
using var imgConvert = Image.Load(new DecoderOptions
{
ColorProfileHandling = ColorProfileHandling.Convert,
}, "test_image_with_gray_icc_profile.jpg");
imgConvert.Save("converted.jpg");
// Load image with ColorProfileHandling.Preserve (CORRECT - preserves gray tones)
using var imgPreserve = Image.Load(new DecoderOptions
{
ColorProfileHandling = ColorProfileHandling.Preserve,
}, "test_image_with_gray_icc_profile.jpg");
imgPreserve.Save("preserve.jpg");
Images
test_image_with_gray_icc_profile.jpg

test_image_with_gray_icc_profile.converted.jpg

test_image_with_gray_icc_profile.preserve.jpg

Prerequisites
DEBUGandRELEASEmodeImageSharp version
4.1.2
Other ImageSharp packages and versions
Environment (Operating system, version and so on)
Windows 11
.NET Framework version
.NET 10.0
Description
When loading a JPEG image with an embedded grayscale ICC profile using
ColorProfileHandling.Convert, the image is rendered incorrectly. The colors are flattened to a uniform light gray instead of preserving the original grayscale tones. However, when usingColorProfileHandling.Preserve, the image renders correctly with the expected gray tones.The issue appears to be in the ICC profile conversion logic when handling grayscale color spaces. The conversion from the grayscale ICC profile to sRGB is not producing the correct pixel values.
Steps to Reproduce
Images
test_image_with_gray_icc_profile.jpg



test_image_with_gray_icc_profile.converted.jpg
test_image_with_gray_icc_profile.preserve.jpg