Skip to content

Commit f2a419e

Browse files
Fix HDR output issue with negative values in Convert Image Color Space. (#16565)
1 parent 8308c3b commit f2a419e

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎comfy_extras/nodes_images.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ def define_schema(cls):
11381138
node_id="ImageColorSpace",
11391139
display_name="Convert Image Color Space",
11401140
category="image/color",
1141-
description="Convert sRGB, linear Rec.709, HDR (Rec.2020 HLG), HDR PQ (Rec.2020 PQ), HDR LogC3, and HDR ACEScct. LogC3 uses the EI 800 curve with Rec.709 primaries and codes clamped to [0, 1]. ACEScct uses AP1 primaries and D60 white, with Bradford adaptation to D65. Convert LogC3 or ACEScct to linear for EXR saving. Linear 1.0 uses the same 203-nit reference white as sRGB; HLG uses a 1000-nit reference display. Linear and ACEScct outputs 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.",
1141+
description="Convert sRGB, linear Rec.709, HDR (Rec.2020 HLG), HDR PQ (Rec.2020 PQ), HDR LogC3, and HDR ACEScct. LogC3 uses the EI 800 curve with Rec.709 primaries and codes clamped to [0, 1]. ACEScct uses AP1 primaries and D60 white, with Bradford adaptation to D65. Convert LogC3 or ACEScct to linear for EXR saving. Linear 1.0 uses the same 203-nit reference white as sRGB; HLG uses a 1000-nit reference display. Linear and ACEScct outputs preserve extended values. Linear-to-HDR conversions preserve highlights without tone mapping; HLG and PQ outputs clip negative channels. 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.",
11421142
inputs=[
11431143
IO.Image.Input("image"),
11441144
IO.Combo.Input("source", options=spaces, default="sRGB", tooltip="Color space of the input pixels."),
@@ -1200,7 +1200,8 @@ def execute(cls, image, source, destination) -> IO.NodeOutput:
12001200
rgb = _compress_rgb_gamut(rgb, _REC709_LUMA)
12011201
rgb = torch.where(rgb <= 0.0031308, rgb * 12.92, 1.055 * rgb.pow(1.0 / 2.4) - 0.055)
12021202
elif destination == "HDR":
1203-
rgb = rgb / _HLG_PEAK_NITS
1203+
# Clip negative channels before luminance to avoid amplifying out-of-gamut shadows.
1204+
rgb = (rgb / _HLG_PEAK_NITS).clamp_min(0.0)
12041205
if source == "HDR PQ":
12051206
rgb = _tone_map_luminance(rgb, _REC2020_LUMA)
12061207
luminance = _rgb_luminance(rgb, _REC2020_LUMA).clamp_min(torch.finfo(rgb.dtype).tiny)

0 commit comments

Comments
 (0)