Skip to content

Fix: Apply embedded ICC color profiles when loading images to ensure correct sRGB conversion#11241

Open
Vijay2359 wants to merge 2 commits intoComfy-Org:masterfrom
Vijay2359:fix-loadimage-icc_based
Open

Fix: Apply embedded ICC color profiles when loading images to ensure correct sRGB conversion#11241
Vijay2359 wants to merge 2 commits intoComfy-Org:masterfrom
Vijay2359:fix-loadimage-icc_based

Conversation

@Vijay2359
Copy link

Summary

This PR adds proper ICC color profile handling to the LoadImage node so that non-sRGB images (such as Display-P3, AdobeRGB, ProPhotoRGB, Rec.2020, etc.) are correctly converted to sRGB during loading.

This fixes the color-shift problem reported in:
Fixes #11101

Problem

ComfyUI currently ignores embedded ICC profiles, which causes images in wide-gamut color spaces to appear washed-out or desaturated because they are interpreted as sRGB without conversion.

Solution

This PR:

  • Detects embedded ICC profiles (icc_profile field)
  • Converts the source color space → sRGB using Pillow's ImageCms.profileToProfile()
  • Falls back safely if ICC data is missing or invalid
  • Ensures correct colors in PreviewImage and downstream nodes

Example Patch

import io
from PIL import ImageCms

    try: 
        if "icc_profile" in img.info:
            icc_bytes = img.info["icc_profile"]

            src_profile = ImageCms.ImageCmsProfile(io.BytesIO(icc_bytes))
            dst_profile = ImageCms.createProfile("sRGB")

            img = ImageCms.profileToProfile(
                img,
                src_profile,
                dst_profile,
                outputMode="RGB"
            )
    except Exception as e:
         print("Icc color profile conversion failed:",e)

@Vijay2359
Copy link
Author

#Benefits

Eliminates color shifts when loading P3 / AdobeRGB / ProPhoto images

Matches behavior of color-managed applications (Photoshop, macOS Preview, Chrome, etc.)

No breaking changes for sRGB workflows

Very low overhead; only runs if an ICC profile exists

@comfy-pr-bot
Copy link
Member

Test Evidence Check

⚠️ Warning: Test Explanation Missing

If this PR modifies behavior that requires testing, a test explanation is required. PRs lacking applicable test explanations may not be reviewed until added. Please add test explanations to ensure code quality and prevent regressions.

⚠️ Warning: Visual Documentation Missing

If this PR changes user-facing behavior, visual proof (screen recording or screenshot) is required. PRs without applicable visual documentation may not be reviewed until provided.

You can add it by:

  • GitHub: Drag & drop media directly into the PR description
  • YouTube: Include a link to a short demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Color Space inconsistency

3 participants