WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

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

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

2 participants