Fix: Apply embedded ICC color profiles when loading images to ensure correct sRGB conversion
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 comfyanonymous/ComfyUI#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_profilefield) - 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)
#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