From 1d48d9cf7bcecb6022a87b3cb13e0fb435bf9b8a Mon Sep 17 00:00:00 2001 From: comfyanonymous <121283862+comfyanonymous@users.noreply.github.com> Date: Thu, 10 Sep 2026 18:52:52 -0700 Subject: [PATCH] Add linear to ImageColorSpace. (#16247) --- comfy_extras/nodes_images.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/comfy_extras/nodes_images.py b/comfy_extras/nodes_images.py index 91a3f990c..be8988976 100644 --- a/comfy_extras/nodes_images.py +++ b/comfy_extras/nodes_images.py @@ -1109,12 +1109,12 @@ def _compress_rgb_gamut(rgb, weights): class ImageColorSpace(IO.ComfyNode): @classmethod def define_schema(cls): - spaces = ["sRGB", "HDR", "HDR PQ"] + spaces = ["sRGB", "HDR", "HDR PQ", "linear"] return IO.Schema( node_id="ImageColorSpace", display_name="Convert Image Color Space", category="image/color", - description="Convert sRGB (Rec.709), HDR (Rec.2020 HLG), and HDR PQ (Rec.2020 PQ). Uses 203-nit SDR white and a 1000-nit HLG reference display. Narrowing tone-maps excess luminance across the batch and compresses out-of-gamut colors. Conversions compute in float32 and return the intermediate device and dtype. Straight alpha is not color-transformed.", + description="Convert sRGB, linear Rec.709, HDR (Rec.2020 HLG), and HDR PQ (Rec.2020 PQ). Linear 1.0 uses the same 203-nit reference white as sRGB; HLG uses a 1000-nit reference display. Linear output and linear-to-HDR conversions preserve extended values without tone mapping. SDR output and PQ-to-HLG conversion tone-map excess luminance across the batch and compress out-of-gamut colors. Conversions compute in float32 and return the intermediate device and dtype. Straight alpha is not color-transformed.", inputs=[ IO.Image.Input("image"), IO.Combo.Input("source", options=spaces, default="sRGB", tooltip="Color space of the input pixels."), @@ -1134,6 +1134,8 @@ class ImageColorSpace(IO.ComfyNode): # Convert to display-linear Rec.2020 in cd/m² (BT.2100 EOTFs). if source == "sRGB": rgb = _convert_rgb_primaries(srgb_to_linear(rgb), _REC709_TO_REC2020) * _SDR_WHITE_NITS + elif source == "linear": + rgb = _convert_rgb_primaries(rgb, _REC709_TO_REC2020) * _SDR_WHITE_NITS elif source == "HDR": rgb = hlg_to_linear(rgb) luminance = _rgb_luminance(rgb, _REC2020_LUMA).clamp_min(0.0) @@ -1145,7 +1147,9 @@ class ImageColorSpace(IO.ComfyNode): else: raise ValueError(f"Unsupported source color space: {source}") - if destination == "sRGB": + if destination == "linear": + rgb = _convert_rgb_primaries(rgb / _SDR_WHITE_NITS, _REC2020_TO_REC709) + elif destination == "sRGB": rgb = _convert_rgb_primaries(rgb / _SDR_WHITE_NITS, _REC2020_TO_REC709) rgb = _tone_map_luminance(rgb, _REC709_LUMA) rgb = _compress_rgb_gamut(rgb, _REC709_LUMA)