From 0dd9b154a1654fc699dcdc3af066c7cce096045a Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Thu, 6 Aug 2026 21:04:25 -0700 Subject: [PATCH 01/20] chore: fail the CodeRabbit status when the review did not run (#15382) --- .coderabbit.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.coderabbit.yaml b/.coderabbit.yaml index 08629ed8e..5f1976bfe 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -11,6 +11,10 @@ reviews: review_status: false review_details: true commit_status: true + # Without this, a review that never happened (rate limit, internal error) + # still posts a green "CodeRabbit" commit status, so a throttled review is + # indistinguishable from a clean one. + fail_commit_status: true collapse_walkthrough: true changed_files_summary: false sequence_diagrams: false From 2340099d93305bfdf4eaa29e9f8d32ec92d3035f Mon Sep 17 00:00:00 2001 From: comfyanonymous <121283862+comfyanonymous@users.noreply.github.com> Date: Thu, 6 Aug 2026 21:26:16 -0700 Subject: [PATCH 02/20] Fix full offload on minimax audio vae. (#15377) --- comfy/ldm/minimax/audio_vae.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/comfy/ldm/minimax/audio_vae.py b/comfy/ldm/minimax/audio_vae.py index a1be63d54..0b9f2b6fc 100644 --- a/comfy/ldm/minimax/audio_vae.py +++ b/comfy/ldm/minimax/audio_vae.py @@ -99,7 +99,7 @@ class UpSample1d(nn.Module): def forward(self, x): _, C, _ = x.shape x = F.pad(x, (self.pad, self.pad), mode="replicate") - x = F.conv_transpose1d(x, self.filter.expand(C, -1, -1).to(x.dtype), stride=self.stride, groups=C).mul_(self.ratio) + x = F.conv_transpose1d(x, comfy.ops.cast_to_input(self.filter.expand(C, -1, -1), x), stride=self.stride, groups=C).mul_(self.ratio) x = x[..., self.pad_left:-self.pad_right] return x @@ -115,7 +115,7 @@ class LowPassFilter1d(nn.Module): def forward(self, x): _, C, _ = x.shape x = F.pad(x, (self.pad_left, self.pad_right), mode="replicate") - return F.conv1d(x, self.filter.expand(C, -1, -1).to(x.dtype), stride=self.stride, groups=C) + return F.conv1d(x, comfy.ops.cast_to_input(self.filter.expand(C, -1, -1), x), stride=self.stride, groups=C) class DownSample1d(nn.Module): From 0ab8332bfa41c695b1c104a6535ff1fde81c7939 Mon Sep 17 00:00:00 2001 From: comfyanonymous <121283862+comfyanonymous@users.noreply.github.com> Date: Fri, 7 Aug 2026 00:33:38 -0700 Subject: [PATCH 03/20] Update comfy-kitchen package version to 0.2.27 (#15388) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 243e65fbd..3abbd138e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,7 +22,7 @@ alembic SQLAlchemy>=2.0.0 filelock av>=16.0.0 -comfy-kitchen==0.2.26 +comfy-kitchen==0.2.27 comfy-aimdo==0.4.13 requests simpleeval>=1.0.0 From 531ea7db139a856a830182694441e9755f0e260a Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Fri, 7 Aug 2026 14:36:12 +0300 Subject: [PATCH 04/20] [Partner Nodes] chore(Gemini,OpenAI): update pricing for image models (#15306) * [Partner Nodes] chore(Gemini): update pricing for Nano Banana image models Signed-off-by: bigcat88 --- comfy_api_nodes/nodes_gemini.py | 8 ++++---- comfy_api_nodes/nodes_openai.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/comfy_api_nodes/nodes_gemini.py b/comfy_api_nodes/nodes_gemini.py index fd9ff04a8..131590751 100644 --- a/comfy_api_nodes/nodes_gemini.py +++ b/comfy_api_nodes/nodes_gemini.py @@ -76,8 +76,8 @@ GEMINI_IMAGE_2_PRICE_BADGE = IO.PriceBadge( $m := widgets.model; $r := widgets.resolution; $isFlash := $contains($m, "nano banana 2"); - $flashPrices := {"1k": 0.0696, "2k": 0.1014, "4k": 0.154}; - $proPrices := {"1k": 0.134, "2k": 0.134, "4k": 0.24}; + $flashPrices := {"1k": 0.0835, "2k": 0.1217, "4k": 0.1848}; + $proPrices := {"1k": 0.1608, "2k": 0.1608, "4k": 0.288}; $prices := $isFlash ? $flashPrices : $proPrices; {"type":"usd","usd": $lookup($prices, $r), "format":{"suffix":"/Image","approximate":true}} ) @@ -1464,10 +1464,10 @@ class GeminiNanoBanana2V2(IO.ComfyNode): expr=""" ( $contains(widgets.model, "lite") - ? {"type":"usd","usd": 0.034, "format":{"suffix":"/Image","approximate":true}} + ? {"type":"usd","usd": 0.0408, "format":{"suffix":"/Image","approximate":true}} : ( $r := $lookup(widgets, "model.resolution"); - $prices := {"1k": 0.0696, "2k": 0.1014, "4k": 0.154}; + $prices := {"1k": 0.0835, "2k": 0.1217, "4k": 0.1848}; {"type":"usd","usd": $lookup($prices, $r), "format":{"suffix":"/Image","approximate":true}} ) ) diff --git a/comfy_api_nodes/nodes_openai.py b/comfy_api_nodes/nodes_openai.py index e73319e84..76915f931 100644 --- a/comfy_api_nodes/nodes_openai.py +++ b/comfy_api_nodes/nodes_openai.py @@ -494,9 +494,9 @@ class OpenAIGPTImage1(IO.ComfyNode): "high": [0.133, 0.22] }, "gpt-image-2": { - "low": [0.0048, 0.019], - "medium": [0.041, 0.168], - "high": [0.165, 0.67] + "low": [0.0058, 0.0228], + "medium": [0.0492, 0.2016], + "high": [0.198, 0.804] } }; $range := $lookup($lookup($ranges, widgets.model), widgets.quality); @@ -792,9 +792,9 @@ class OpenAIGPTImageNodeV2(IO.ComfyNode): "high": [0.133, 0.22] }, "gpt-image-2": { - "low": [0.0048, 0.019], - "medium": [0.041, 0.168], - "high": [0.165, 0.67] + "low": [0.0058, 0.0228], + "medium": [0.0492, 0.2016], + "high": [0.198, 0.804] } }; $range := $lookup($lookup($ranges, widgets.model), $lookup(widgets, "model.quality")); From 93cb5edb98ed77f688a0031b8d02a403db68ea81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Sepp=C3=A4nen?= <40791699+kijai@users.noreply.github.com> Date: Fri, 7 Aug 2026 18:30:21 +0300 Subject: [PATCH 05/20] Fix audio carry to wrappers (#15390) --- comfy/ldm/minimax/model.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/comfy/ldm/minimax/model.py b/comfy/ldm/minimax/model.py index 98bd841db..bc06288ab 100644 --- a/comfy/ldm/minimax/model.py +++ b/comfy/ldm/minimax/model.py @@ -489,14 +489,14 @@ class MiniMaxH3Model(nn.Module): # the sampler carries the audio as (sigma_v / sigma_a) * x_audio; undo it outside # the wrappers so they and the network see the stream's own latent and velocity scale = float((minimax_payload or {}).get("audio_scale", 1.0)) - audio_x = x[1] + audio_src = x[1] if scale != 1.0: shift_v = float(transformer_options.get("minimax_h3_sigma_shift_video", self.sigma_shift_video)) shift_a = float(transformer_options.get("minimax_h3_sigma_shift_audio", self.sigma_shift_audio)) sigma_v = (timestep.flatten()[0] / 1000.0).float().clamp(min=1e-6) sigma_a = time_shift_sigma(sigma_v, shift_v, shift_a) - audio_x = audio_x * (sigma_a / sigma_v).to(audio_x.dtype) - x = [x[0], audio_x] + carry = (sigma_a / sigma_v).to(audio_src.dtype) + x = [x[0], audio_src * carry] out = comfy.patcher_extension.WrapperExecutor.new_class_executor( self._forward, @@ -506,7 +506,7 @@ class MiniMaxH3Model(nn.Module): if scale != 1.0: # d/d(sigma_v) of the carried variable - out[1] = ((1.0 - scale) * audio_x + out[1] = ((1.0 - scale) * (audio_src * carry) + (1.0 + (scale - 1.0) * sigma_a).to(out[1].dtype) * out[1]) return out From 344b43989e8c56b5bb4a66cf028c834192ab59dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Sepp=C3=A4nen?= <40791699+kijai@users.noreply.github.com> Date: Fri, 7 Aug 2026 18:32:57 +0300 Subject: [PATCH 06/20] Support asym w4a8_int (#15308) * support asym w4a8_int * Simplify * Fixes --- comfy/ops.py | 23 +++++++++++++++++++++++ comfy/quant_ops.py | 15 ++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/comfy/ops.py b/comfy/ops.py index 7cf077eea..14599997b 100644 --- a/comfy/ops.py +++ b/comfy/ops.py @@ -1211,6 +1211,26 @@ def _load_quantized_module(module, super_load, state_dict, prefix, local_metadat "quant_group_size": 64, "linear_dtype": layer_conf.get("linear_dtype", params_conf.get("linear_dtype", "int4")), } + elif module.quant_format == "asym_w4a8_int8": + # int4 weight (packed int8 [N,K/2]) + fp8 per-group scale (weight_s_rel), + # fp32 per-channel scale (weight_s_channel) + optional Lloyd-Max codebook. + scale = pop_scale("weight_s_rel") + if scale is None: + raise ValueError(f"Missing W4A8 group scale (weight_s_rel) for layer {layer_name}") + if scale.dtype == torch.uint8: + scale = scale.view(torch.float8_e4m3fn) + params_conf = layer_conf.get("params", {}) + if not isinstance(params_conf, dict): + params_conf = {} + scales = { + "scale": scale, + "s_channel": pop_scale("weight_s_channel"), + "codebook": pop_scale("weight_codebook"), + "group_size": int(layer_conf.get("group_size", params_conf.get("group_size", 16))), + "convrot_groupsize": int( + layer_conf.get("convrot_groupsize", params_conf.get("convrot_groupsize", 256)) + ), + } else: raise ValueError(f"Unsupported quantization format: {module.quant_format}") @@ -1262,6 +1282,9 @@ def _quantized_weight_state_dict(module, sd, prefix, extra_quant_conf=None, extr linear_dtype = getattr(params, "linear_dtype", "int4") if linear_dtype != "int4": quant_conf["linear_dtype"] = linear_dtype + elif module.quant_format == "asym_w4a8_int8": + quant_conf["group_size"] = getattr(params, "group_size", 16) + quant_conf["convrot_groupsize"] = getattr(params, "convrot_groupsize", 256) if extra_quant_conf: quant_conf.update(extra_quant_conf) sd[f"{prefix}comfy_quant"] = torch.tensor(list(json.dumps(quant_conf).encode("utf-8")), dtype=torch.uint8) diff --git a/comfy/quant_ops.py b/comfy/quant_ops.py index 53586956a..6d9112dbb 100644 --- a/comfy/quant_ops.py +++ b/comfy/quant_ops.py @@ -28,6 +28,7 @@ try: TensorCoreNVFP4Layout as _CKNvfp4Layout, TensorCoreConvRotW4A4Layout as _CKTensorCoreConvRotW4A4Layout, TensorWiseINT8Layout as _CKTensorWiseINT8Layout, + AsymW4A8Int8Layout as _CKAsymW4A8Int8Layout, register_layout_op, register_layout_class, get_layout_class, @@ -83,6 +84,9 @@ except ImportError as e: class _CKTensorCoreConvRotW4A4Layout: pass + class _CKAsymW4A8Int8Layout: + pass + def register_layout_class(name, cls): pass @@ -212,7 +216,7 @@ class TensorCoreFP8E5M2Layout(_TensorCoreFP8LayoutBase): TensorCoreFP8Layout = TensorCoreFP8E4M3Layout TensorWiseINT8Layout = _CKTensorWiseINT8Layout TensorCoreConvRotW4A4Layout = _CKTensorCoreConvRotW4A4Layout - +AsymW4A8Int8Layout = _CKAsymW4A8Int8Layout # ============================================================================== # Registry @@ -226,6 +230,7 @@ register_layout_class("TensorWiseINT8Layout", _CKTensorWiseINT8Layout) register_layout_class("TensorCoreConvRotW4A4Layout", _CKTensorCoreConvRotW4A4Layout) if _CK_MXFP8_AVAILABLE: register_layout_class("TensorCoreMXFP8Layout", TensorCoreMXFP8Layout) +register_layout_class("AsymW4A8Int8Layout", _CKAsymW4A8Int8Layout) QUANT_ALGOS = { "float8_e4m3fn": { @@ -268,6 +273,13 @@ QUANT_ALGOS["convrot_w4a4"] = { "quantize_input": False, } +QUANT_ALGOS["asym_w4a8_int8"] = { + "storage_t": torch.int8, + "parameters": {"weight_scale"}, + "comfy_tensor_layout": "AsymW4A8Int8Layout", + "quantize_input": False, +} + # ============================================================================== # Re-exports for backward compatibility @@ -282,6 +294,7 @@ __all__ = [ "TensorCoreNVFP4Layout", "TensorCoreConvRotW4A4Layout", "TensorWiseINT8Layout", + "AsymW4A8Int8Layout", "QUANT_ALGOS", "register_layout_op", ] From 0db869411564d9c1990043042416b6fce2a18f8a Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Fri, 7 Aug 2026 21:28:09 +0300 Subject: [PATCH 07/20] [Partner Nodes] feat(ByteDance): add SeeDance 2.5 model (#15395) * [Partner Nodes] feat(ByteDance): add SeeDance 2.5 model Signed-off-by: Alexander Piskun --- comfy_api_nodes/apis/bytedance.py | 30 +- comfy_api_nodes/nodes_bytedance.py | 493 +++++++++++++++++++---------- 2 files changed, 350 insertions(+), 173 deletions(-) diff --git a/comfy_api_nodes/apis/bytedance.py b/comfy_api_nodes/apis/bytedance.py index 515e124ca..b83bb99ce 100644 --- a/comfy_api_nodes/apis/bytedance.py +++ b/comfy_api_nodes/apis/bytedance.py @@ -95,9 +95,10 @@ class Seedance2TaskCreationRequest(BaseModel): generate_audio: bool | None = Field(None) resolution: str | None = Field(None) ratio: str | None = Field(None) - duration: int | None = Field(None, ge=4, le=15) + duration: int | None = Field(None) seed: int | None = Field(None, ge=0, le=2147483647) watermark: bool | None = Field(None) + output_format: str | None = Field(None) class TaskCreationResponse(BaseModel): @@ -186,6 +187,10 @@ SEEDANCE2_PRICE_PER_1K_TOKENS = { ("dreamina-seedance-2-0-mini", True, "480p"): 0.0021, ("dreamina-seedance-2-0-mini", False, "720p"): 0.0035, ("dreamina-seedance-2-0-mini", True, "720p"): 0.0021, + ("dreamina-seedance-2-5-260628", False, "480p"): 0.0107, + ("dreamina-seedance-2-5-260628", True, "480p"): 0.0064, + ("dreamina-seedance-2-5-260628", False, "720p"): 0.0107, + ("dreamina-seedance-2-5-260628", True, "720p"): 0.0064, } @@ -304,8 +309,31 @@ SEEDANCE2_REF_VIDEO_PIXEL_LIMITS = { "480p": {"min": 409_600, "max": 927_408}, "720p": {"min": 409_600, "max": 927_408}, }, + "dreamina-seedance-2-5-260628": { + "480p": {"min": 409_600, "max": 8_295_044}, + "720p": {"min": 409_600, "max": 8_295_044}, + }, } +SEEDANCE2_REFERENCE_LIMITS_DEFAULT = { + "max_images": 9, + "max_videos": 3, + "max_audios": 3, + "max_total_seconds": 15.1, +} +SEEDANCE2_REFERENCE_LIMITS = { + "dreamina-seedance-2-5-260628": { + "max_images": 30, + "max_videos": 10, + "max_audios": 10, + "max_total_seconds": 30.1, + }, +} + + +def seedance2_reference_limits(model_id: str) -> dict: + return SEEDANCE2_REFERENCE_LIMITS.get(model_id, SEEDANCE2_REFERENCE_LIMITS_DEFAULT) + # The time in this dictionary are given for 10 seconds duration. VIDEO_TASKS_EXECUTION_TIME = { "seedance-1-0-lite-t2v-250428": { diff --git a/comfy_api_nodes/nodes_bytedance.py b/comfy_api_nodes/nodes_bytedance.py index 561d6ae80..f321a496b 100644 --- a/comfy_api_nodes/nodes_bytedance.py +++ b/comfy_api_nodes/nodes_bytedance.py @@ -47,6 +47,7 @@ from comfy_api_nodes.apis.bytedance import ( Text2ImageTaskCreationRequest, Text2VideoTaskCreationRequest, seedance2_price_per_1k_tokens, + seedance2_reference_limits, ) from comfy_api_nodes.util import ( ApiEndpoint, @@ -101,11 +102,18 @@ BYTEPLUS_TASK_STATUS_ENDPOINT = "/proxy/byteplus/api/v3/contents/generations/tas BYTEPLUS_SEEDANCE2_TASK_STATUS_ENDPOINT = "/proxy/byteplus-seedance2/api/v3/contents/generations/tasks" # + /{task_id} SEEDANCE_MODELS = { + "Seedance 2.5": "dreamina-seedance-2-5-260628", "Seedance 2.0": "dreamina-seedance-2-0-260128", "Seedance 2.0 Fast": "dreamina-seedance-2-0-fast-260128", "Seedance 2.0 Mini": "dreamina-seedance-2-0-mini", } +SEEDANCE_MODEL_TOOLTIP = ( + "Seedance 2.5 for the newest model, videos up to 30 seconds and mp4/mov output; " + "Seedance 2.0 for maximum quality and 1080p/4k; Fast for speed optimization; " + "Mini for the fastest, lowest-cost generation." +) + DEPRECATED_MODELS = {"seedance-1-0-lite-t2v-250428", "seedance-1-0-lite-i2v-250428"} @@ -1692,25 +1700,272 @@ def _seedance2_text_inputs(resolutions: list[str], default_ratio: str = "16:9"): ] +def _seedance25_text_inputs(with_ratio: bool = True, with_video_editing: bool = False): + return [ + IO.String.Input( + "prompt", + multiline=True, + default="", + tooltip="Text prompt for video generation. Put spoken lines in double quotes to steer " + "the generated dialogue.", + ), + IO.Combo.Input( + "resolution", + options=["480p", "720p"], + default="720p", + tooltip="Resolution of the output video.", + ), + *( + [ + IO.Combo.Input( + "ratio", + options=["16:9", "4:3", "1:1", "3:4", "9:16", "21:9", "adaptive"], + default="16:9", + tooltip="Aspect ratio of the output video.", + ) + ] + if with_ratio + else [] + ), + IO.Int.Input( + "duration", + default=5, + min=4, + max=30, + step=1, + tooltip="Duration of the output video in seconds (4-30).", + display_mode=IO.NumberDisplay.slider, + ), + IO.Boolean.Input( + "generate_audio", + default=True, + tooltip="Enable audio generation for the output video.", + ), + *( + [ + IO.Boolean.Input( + "video_editing", + default=False, + tooltip="Enable when the prompt edits a connected reference video, for example " + "replacing an object in it. The output then keeps the source clip's own length " + "and aspect ratio, and the duration and ratio widgets are ignored. Leave " + "disabled to generate a new video, or to extend one to the duration you set.", + ) + ] + if with_video_editing + else [] + ), + IO.Combo.Input( + "output_format", + options=["mp4"], + default="mp4", + tooltip="Container format of the output video.", + ), + ] + + +def _seedance25_reference_inputs(): + return [ + *_seedance25_text_inputs(with_video_editing=True), + IO.Autogrow.Input( + "reference_images", + template=IO.Autogrow.TemplateNames( + IO.Image.Input("reference_image"), + names=[f"image_{i}" for i in range(1, 31)], + min=0, + ), + ), + IO.Autogrow.Input( + "reference_videos", + template=IO.Autogrow.TemplateNames( + IO.Video.Input("reference_video"), + names=[f"video_{i}" for i in range(1, 11)], + min=0, + ), + ), + IO.Autogrow.Input( + "reference_audios", + template=IO.Autogrow.TemplateNames( + IO.Audio.Input("reference_audio"), + names=[f"audio_{i}" for i in range(1, 11)], + min=0, + ), + ), + IO.Boolean.Input( + "auto_downscale", + default=True, + optional=True, + tooltip="Automatically downscale reference videos that exceed the model's pixel budget " + "for the selected resolution. Aspect ratio is preserved; videos already within limits are untouched.", + ), + IO.Boolean.Input( + "auto_upscale", + default=False, + advanced=True, + optional=True, + tooltip="Automatically upscale reference videos that are below the model's minimum pixel count " + "for the selected resolution. Aspect ratio is preserved; videos already meeting the minimum are " + "untouched. Note: upscaling a low-resolution source does not add real detail and may produce " + "lower-quality generations.", + ), + IO.Autogrow.Input( + "reference_assets", + template=IO.Autogrow.TemplateNames( + IO.String.Input("reference_asset"), + names=[f"asset_{i}" for i in range(1, 31)], + min=0, + ), + ), + ] + + +def _seedance2_build_request( + model: dict, + model_id: str, + content: list, + seed: int, + watermark: bool, + ratio: str, +) -> Seedance2TaskCreationRequest: + video_editing = bool(model.get("video_editing")) + return Seedance2TaskCreationRequest( + model=model_id, + content=content, + generate_audio=model["generate_audio"], + resolution=model["resolution"], + ratio="adaptive" if video_editing else ratio, + duration=-1 if video_editing else model["duration"], + seed=seed, + watermark=watermark, + output_format=model.get("output_format"), + ) + + +_SEEDANCE2_PRICE_EXPR_TEMPLATE = """ +( + $m := widgets.model; + $res := $lookup(widgets, "model.resolution"); + $ratio := $lookup(widgets, "model.ratio"); + $dur := $lookup(widgets, "model.duration"); + $auto := $lookup(widgets, "model.video_editing") = true; + $hasVideo := __HAS_VIDEO__; + $ready := $type($m) = "string" and $type($res) = "string" and ($auto or $type($dur) = "number"); + $ready ? ( + $contains($m, "2.5") ? ( + $is480 := $res = "480p"; + $perFrame := $ratio = "1:1" ? ($is480 ? 400 : 900) : + $ratio = "4:3" ? ($is480 ? 411.25 : 905.6719) : + $ratio = "3:4" ? ($is480 ? 411.25 : 905.6719) : + $ratio = "21:9" ? ($is480 ? 418.5 : 904.3945) : + ($is480 ? 400.3125 : 900); + $price := $hasVideo ? 0.009152 : 0.015301; + $costFor := function($d) { $floor($perFrame * (24 * $d + 1)) / 1000 * $price }; + $lo := $costFor($auto ? 4 : $dur); + $hi := $costFor(($auto ? 30 : $dur) + ($hasVideo ? 30 : 0)); + $lo = $hi + ? {"type": "usd", "usd": $lo, "format": {"approximate": true}} + : {"type": "range_usd", "min_usd": $lo, "max_usd": $hi, "format": {"approximate": true}} + ) : ( + $rate := $res = "4k" ? 195200 : + $res = "1080p" ? 48800 : + $res = "720p" ? 21600 : 10044; + $noVideoPrice := $res = "4k" ? 0.00572 : + $res = "1080p" ? 0.011011 : + $contains($m, "mini") ? 0.005005 : + $contains($m, "fast") ? 0.008008 : 0.01001; + $videoPrice := $res = "4k" ? 0.003432 : + $res = "1080p" ? 0.006721 : + $contains($m, "mini") ? 0.003003 : + $contains($m, "fast") ? 0.004719 : 0.006149; + $hasVideo + ? {"type": "range_usd", + "min_usd": $ceil($dur * 5 / 3) * $rate * $videoPrice / 1000, + "max_usd": (15 + $dur) * $rate * $videoPrice / 1000, + "format": {"approximate": true}} + : {"type": "usd", "usd": $dur * $rate * $noVideoPrice / 1000, + "format": {"approximate": true}} + ) + ) : undefined +) +""" + + +_SEEDANCE_AUDIO_POLICY_CODE = "OutputAudioSensitiveContentDetected.PolicyViolation" +_SEEDANCE_TASK_TYPE_CONSTRAINT_CODE = "InvalidParameter.TaskTypeConstraint" + + +async def _seedance2_poll_video_task( + cls: type[IO.ComfyNode], + task_id: str, + model_id: str, + resolution: str, + has_video_input: bool, +) -> TaskStatusResponse: + try: + return await poll_op( + cls, + ApiEndpoint(path=f"{BYTEPLUS_SEEDANCE2_TASK_STATUS_ENDPOINT}/{task_id}"), + response_model=TaskStatusResponse, + status_extractor=lambda r: r.status, + price_extractor=_seedance2_price_extractor( + model_id, has_video_input=has_video_input, resolution=resolution + ), + poll_interval=9, + ) + except Exception as exc: + if _SEEDANCE_AUDIO_POLICY_CODE in str(exc): + raise ValueError( + "The provider rejected the audio track this model generated for the video " + "(possible copyright match). The video itself was fine. Turn off generate_audio " + "to get a silent video, or adjust the prompt and try again." + ) from exc + if _SEEDANCE_TASK_TYPE_CONSTRAINT_CODE in str(exc): + raise ValueError( + "Seedance read this prompt as editing the reference video, and an edit always " + "takes its duration and aspect ratio from that video. Enable video_editing on " + "this node and run again, or reword the prompt so it describes a new video " + "rather than a change to the reference one." + ) from exc + raise + + +def _seedance2_price_badge(with_reference_videos: bool) -> IO.PriceBadge: + widgets = ["model", "model.resolution", "model.ratio", "model.duration"] + if with_reference_videos: + widgets.append("model.video_editing") + has_video = ( + '$exists(inputGroups) and $lookup(inputGroups, "model.reference_videos") > 0' + if with_reference_videos + else "false" + ) + return IO.PriceBadge( + depends_on=IO.PriceBadgeDepends( + widgets=widgets, + input_groups=["model.reference_videos"] if with_reference_videos else [], + ), + expr=_SEEDANCE2_PRICE_EXPR_TEMPLATE.replace("__HAS_VIDEO__", has_video), + ) + + class ByteDance2TextToVideoNode(IO.ComfyNode): @classmethod def define_schema(cls): return IO.Schema( node_id="ByteDance2TextToVideoNode", - display_name="ByteDance Seedance 2.0 Text to Video", + display_name="ByteDance Seedance 2.5 Text to Video", category="partner/video/ByteDance", - description="Generate video using Seedance 2.0 models based on a text prompt.", + description="Generate video using Seedance 2.5 or 2.0 models based on a text prompt.", inputs=[ IO.DynamicCombo.Input( "model", options=[ + IO.DynamicCombo.Option("Seedance 2.5", _seedance25_text_inputs()), IO.DynamicCombo.Option("Seedance 2.0", _seedance2_text_inputs(["480p", "720p", "1080p", "4k"])), IO.DynamicCombo.Option("Seedance 2.0 Fast", _seedance2_text_inputs(["480p", "720p"])), IO.DynamicCombo.Option("Seedance 2.0 Mini", _seedance2_text_inputs(["480p", "720p"])), ], - tooltip="Seedance 2.0 for maximum quality; Fast for speed optimization; " - "Mini for the fastest, lowest-cost generation.", + tooltip=SEEDANCE_MODEL_TOOLTIP, ), IO.Int.Input( "seed", @@ -1739,30 +1994,7 @@ class ByteDance2TextToVideoNode(IO.ComfyNode): IO.Hidden.unique_id, ], is_api_node=True, - price_badge=IO.PriceBadge( - depends_on=IO.PriceBadgeDepends(widgets=["model", "model.resolution", "model.duration"]), - expr=""" - ( - $rate480 := 10044; - $rate720 := 21600; - $rate1080 := 48800; - $rate4k := 195200; - $m := widgets.model; - $res := $lookup(widgets, "model.resolution"); - $dur := $lookup(widgets, "model.duration"); - $pricePer1K := $res = "4k" ? 0.00572 : - $res = "1080p" ? 0.011011 : - $contains($m, "mini") ? 0.005005 : - $contains($m, "fast") ? 0.008008 : 0.01001; - $rate := $res = "4k" ? $rate4k : - $res = "1080p" ? $rate1080 : - $res = "720p" ? $rate720 : - $rate480; - $cost := $dur * $rate * $pricePer1K / 1000; - {"type": "usd", "usd": $cost, "format": {"approximate": true}} - ) - """, - ), + price_badge=_seedance2_price_badge(with_reference_videos=False), ) @classmethod @@ -1777,25 +2009,18 @@ class ByteDance2TextToVideoNode(IO.ComfyNode): initial_response = await sync_op( cls, ApiEndpoint(path=BYTEPLUS_TASK_ENDPOINT, method="POST"), - data=Seedance2TaskCreationRequest( - model=model_id, - content=[TaskTextContent(text=model["prompt"])], - generate_audio=model["generate_audio"], - resolution=model["resolution"], + data=_seedance2_build_request( + model, + model_id, + [TaskTextContent(text=model["prompt"])], + seed, + watermark, ratio=model["ratio"], - duration=model["duration"], - seed=seed, - watermark=watermark, ), response_model=TaskCreationResponse, ) - response = await poll_op( - cls, - ApiEndpoint(path=f"{BYTEPLUS_SEEDANCE2_TASK_STATUS_ENDPOINT}/{initial_response.id}"), - response_model=TaskStatusResponse, - status_extractor=lambda r: r.status, - price_extractor=_seedance2_price_extractor(model_id, has_video_input=False, resolution=model["resolution"]), - poll_interval=9, + response = await _seedance2_poll_video_task( + cls, initial_response.id, model_id, model["resolution"], has_video_input=False ) return IO.NodeOutput(await download_url_to_video_output(response.content.video_url)) @@ -1806,13 +2031,15 @@ class ByteDance2FirstLastFrameNode(IO.ComfyNode): def define_schema(cls): return IO.Schema( node_id="ByteDance2FirstLastFrameNode", - display_name="ByteDance Seedance 2.0 First-Last-Frame to Video", + display_name="ByteDance Seedance 2.5 First-Last-Frame to Video", category="partner/video/ByteDance", - description="Generate video using Seedance 2.0 from a first frame image and optional last frame image.", + description="Generate video using Seedance 2.5 or 2.0 from a first frame image " + "and optional last frame image.", inputs=[ IO.DynamicCombo.Input( "model", options=[ + IO.DynamicCombo.Option("Seedance 2.5", _seedance25_text_inputs(with_ratio=False)), IO.DynamicCombo.Option( "Seedance 2.0", _seedance2_text_inputs(["480p", "720p", "1080p", "4k"], default_ratio="adaptive"), @@ -1826,8 +2053,7 @@ class ByteDance2FirstLastFrameNode(IO.ComfyNode): _seedance2_text_inputs(["480p", "720p"], default_ratio="adaptive"), ), ], - tooltip="Seedance 2.0 for maximum quality; Fast for speed optimization; " - "Mini for the fastest, lowest-cost generation.", + tooltip=SEEDANCE_MODEL_TOOLTIP, ), IO.Image.Input( "first_frame", @@ -1880,30 +2106,7 @@ class ByteDance2FirstLastFrameNode(IO.ComfyNode): IO.Hidden.unique_id, ], is_api_node=True, - price_badge=IO.PriceBadge( - depends_on=IO.PriceBadgeDepends(widgets=["model", "model.resolution", "model.duration"]), - expr=""" - ( - $rate480 := 10044; - $rate720 := 21600; - $rate1080 := 48800; - $rate4k := 195200; - $m := widgets.model; - $res := $lookup(widgets, "model.resolution"); - $dur := $lookup(widgets, "model.duration"); - $pricePer1K := $res = "4k" ? 0.00572 : - $res = "1080p" ? 0.011011 : - $contains($m, "mini") ? 0.005005 : - $contains($m, "fast") ? 0.008008 : 0.01001; - $rate := $res = "4k" ? $rate4k : - $res = "1080p" ? $rate1080 : - $res = "720p" ? $rate720 : - $rate480; - $cost := $dur * $rate * $pricePer1K / 1000; - {"type": "usd", "usd": $cost, "format": {"approximate": true}} - ) - """, - ), + price_badge=_seedance2_price_badge(with_reference_videos=False), ) @classmethod @@ -1930,8 +2133,17 @@ class ByteDance2FirstLastFrameNode(IO.ComfyNode): if last_frame is not None and last_frame_asset_id: raise ValueError("Provide only one of last_frame or last_frame_asset_id, not both.") - request_ratio = model["ratio"] - if first_frame_asset_id or last_frame_asset_id: + if model_id == "dreamina-seedance-2-5-260628": + # 2.5 accepts ratio="adaptive" only here and keeps the first frame's own aspect + # (a 1920x1088 frame yields 850x482, not a grid ratio), so pre-sizing the frames to a + # supported pixel pair would crop framing the model would otherwise have preserved. + request_ratio = "adaptive" + if first_frame is not None: + first_frame = _prepare_seedance_image(first_frame) + if last_frame is not None: + last_frame = _prepare_seedance_image(last_frame) + elif first_frame_asset_id or last_frame_asset_id: + request_ratio = model["ratio"] if first_frame is not None: first_frame = _prepare_seedance_image(first_frame) if last_frame is not None: @@ -1997,25 +2209,11 @@ class ByteDance2FirstLastFrameNode(IO.ComfyNode): initial_response = await sync_op( cls, ApiEndpoint(path=BYTEPLUS_TASK_ENDPOINT, method="POST"), - data=Seedance2TaskCreationRequest( - model=model_id, - content=content, - generate_audio=model["generate_audio"], - resolution=model["resolution"], - ratio=request_ratio, - duration=model["duration"], - seed=seed, - watermark=watermark, - ), + data=_seedance2_build_request(model, model_id, content, seed, watermark, ratio=request_ratio), response_model=TaskCreationResponse, ) - response = await poll_op( - cls, - ApiEndpoint(path=f"{BYTEPLUS_SEEDANCE2_TASK_STATUS_ENDPOINT}/{initial_response.id}"), - response_model=TaskStatusResponse, - status_extractor=lambda r: r.status, - price_extractor=_seedance2_price_extractor(model_id, has_video_input=False, resolution=model["resolution"]), - poll_interval=9, + response = await _seedance2_poll_video_task( + cls, initial_response.id, model_id, model["resolution"], has_video_input=False ) return IO.NodeOutput(await download_url_to_video_output(response.content.video_url)) @@ -2101,14 +2299,15 @@ class ByteDance2ReferenceNode(IO.ComfyNode): def define_schema(cls): return IO.Schema( node_id="ByteDance2ReferenceNode", - display_name="ByteDance Seedance 2.0 Reference to Video", + display_name="ByteDance Seedance 2.5 Reference to Video", category="partner/video/ByteDance", - description="Generate, edit, or extend video using Seedance 2.0 with reference images, " - "videos, and audio. Supports multimodal reference, video editing, and video extension.", + description="Generate, edit, or extend video using Seedance 2.5 or 2.0 with reference " + "images, videos, and audio. Supports multimodal reference, video editing, and video extension.", inputs=[ IO.DynamicCombo.Input( "model", options=[ + IO.DynamicCombo.Option("Seedance 2.5", _seedance25_reference_inputs()), IO.DynamicCombo.Option( "Seedance 2.0", _seedance2_reference_inputs(["480p", "720p", "1080p", "4k"], default_ratio="adaptive"), @@ -2122,8 +2321,7 @@ class ByteDance2ReferenceNode(IO.ComfyNode): _seedance2_reference_inputs(["480p", "720p"], default_ratio="adaptive"), ), ], - tooltip="Seedance 2.0 for maximum quality; Fast for speed optimization; " - "Mini for the fastest, lowest-cost generation.", + tooltip=SEEDANCE_MODEL_TOOLTIP, ), IO.Int.Input( "seed", @@ -2152,52 +2350,7 @@ class ByteDance2ReferenceNode(IO.ComfyNode): IO.Hidden.unique_id, ], is_api_node=True, - price_badge=IO.PriceBadge( - depends_on=IO.PriceBadgeDepends( - widgets=["model", "model.resolution", "model.duration"], - input_groups=["model.reference_videos"], - ), - expr=""" - ( - $rate480 := 10044; - $rate720 := 21600; - $rate1080 := 48800; - $rate4k := 195200; - $m := widgets.model; - $hasVideo := $lookup(inputGroups, "model.reference_videos") > 0; - $res := $lookup(widgets, "model.resolution"); - $dur := $lookup(widgets, "model.duration"); - $noVideoPricePer1K := $res = "4k" ? 0.00572 : - $res = "1080p" ? 0.011011 : - $contains($m, "mini") ? 0.005005 : - $contains($m, "fast") ? 0.008008 : 0.01001; - $videoPricePer1K := $res = "4k" ? 0.003432 : - $res = "1080p" ? 0.006721 : - $contains($m, "mini") ? 0.003003 : - $contains($m, "fast") ? 0.004719 : 0.006149; - $rate := $res = "4k" ? $rate4k : - $res = "1080p" ? $rate1080 : - $res = "720p" ? $rate720 : - $rate480; - $noVideoCost := $dur * $rate * $noVideoPricePer1K / 1000; - $minVideoFactor := $ceil($dur * 5 / 3); - $minVideoCost := $minVideoFactor * $rate * $videoPricePer1K / 1000; - $maxVideoCost := (15 + $dur) * $rate * $videoPricePer1K / 1000; - $hasVideo - ? { - "type": "range_usd", - "min_usd": $minVideoCost, - "max_usd": $maxVideoCost, - "format": {"approximate": true} - } - : { - "type": "usd", - "usd": $noVideoCost, - "format": {"approximate": true} - } - ) - """, - ), + price_badge=_seedance2_price_badge(with_reference_videos=True), ) @classmethod @@ -2218,32 +2371,38 @@ class ByteDance2ReferenceNode(IO.ComfyNode): cls, list(reference_assets.values()) ) + model_id = SEEDANCE_MODELS[model["model"]] + limits = seedance2_reference_limits(model_id) + if not reference_images and not reference_videos and not reference_image_assets and not reference_video_assets: - raise ValueError("At least one reference image or video or asset is required.") + if model_id != "dreamina-seedance-2-5-260628" or not (reference_audios or reference_audio_assets): + raise ValueError("At least one reference image or video or asset is required.") total_images = len(reference_images) + len(reference_image_assets) - if total_images > 9: + if total_images > limits["max_images"]: raise ValueError( f"Too many reference images: {total_images} " - f"(images={len(reference_images)}, image assets={len(reference_image_assets)}). Maximum is 9." + f"(images={len(reference_images)}, image assets={len(reference_image_assets)}). " + f"Maximum is {limits['max_images']}." ) total_videos = len(reference_videos) + len(reference_video_assets) - if total_videos > 3: + if total_videos > limits["max_videos"]: raise ValueError( f"Too many reference videos: {total_videos} " - f"(videos={len(reference_videos)}, video assets={len(reference_video_assets)}). Maximum is 3." + f"(videos={len(reference_videos)}, video assets={len(reference_video_assets)}). " + f"Maximum is {limits['max_videos']}." ) total_audios = len(reference_audios) + len(reference_audio_assets) - if total_audios > 3: + if total_audios > limits["max_audios"]: raise ValueError( f"Too many reference audios: {total_audios} " - f"(audios={len(reference_audios)}, audio assets={len(reference_audio_assets)}). Maximum is 3." + f"(audios={len(reference_audios)}, audio assets={len(reference_audio_assets)}). " + f"Maximum is {limits['max_audios']}." ) for key in reference_images: reference_images[key] = _prepare_seedance_image(reference_images[key]) - model_id = SEEDANCE_MODELS[model["model"]] has_video_input = total_videos > 0 if model.get("auto_downscale") and reference_videos: @@ -2271,8 +2430,11 @@ class ByteDance2ReferenceNode(IO.ComfyNode): raise except Exception: pass - if total_video_duration > 15.1: - raise ValueError(f"Total reference video duration is {total_video_duration:.1f}s. Maximum is 15.1 seconds.") + if total_video_duration > limits["max_total_seconds"]: + raise ValueError( + f"Total reference video duration is {total_video_duration:.1f}s. " + f"Maximum is {limits['max_total_seconds']} seconds." + ) total_audio_duration = 0.0 for i, key in enumerate(reference_audios, 1): @@ -2281,8 +2443,11 @@ class ByteDance2ReferenceNode(IO.ComfyNode): if dur < 1.8: raise ValueError(f"Reference audio {i} is too short: {dur:.1f}s. Minimum duration is 1.8 seconds.") total_audio_duration += dur - if total_audio_duration > 15.1: - raise ValueError(f"Total reference audio duration is {total_audio_duration:.1f}s. Maximum is 15.1 seconds.") + if total_audio_duration > limits["max_total_seconds"]: + raise ValueError( + f"Total reference audio duration is {total_audio_duration:.1f}s. " + f"Maximum is {limits['max_total_seconds']} seconds." + ) asset_labels = _build_asset_labels( reference_assets, @@ -2355,27 +2520,11 @@ class ByteDance2ReferenceNode(IO.ComfyNode): initial_response = await sync_op( cls, ApiEndpoint(path=BYTEPLUS_TASK_ENDPOINT, method="POST"), - data=Seedance2TaskCreationRequest( - model=model_id, - content=content, - generate_audio=model["generate_audio"], - resolution=model["resolution"], - ratio=model["ratio"], - duration=model["duration"], - seed=seed, - watermark=watermark, - ), + data=_seedance2_build_request(model, model_id, content, seed, watermark, ratio=model["ratio"]), response_model=TaskCreationResponse, ) - response = await poll_op( - cls, - ApiEndpoint(path=f"{BYTEPLUS_SEEDANCE2_TASK_STATUS_ENDPOINT}/{initial_response.id}"), - response_model=TaskStatusResponse, - status_extractor=lambda r: r.status, - price_extractor=_seedance2_price_extractor( - model_id, has_video_input=has_video_input, resolution=model["resolution"] - ), - poll_interval=9, + response = await _seedance2_poll_video_task( + cls, initial_response.id, model_id, model["resolution"], has_video_input=has_video_input ) return IO.NodeOutput(await download_url_to_video_output(response.content.video_url)) From 6db4fa2fcd38a92d4e0364c917cd8503620e2a74 Mon Sep 17 00:00:00 2001 From: Comfy Org PR Bot Date: Sat, 8 Aug 2026 03:51:34 +0900 Subject: [PATCH 08/20] Bump comfyui-frontend-package to 1.48.7 (#15403) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3abbd138e..c201d9ed4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -comfyui-frontend-package==1.48.6 +comfyui-frontend-package==1.48.7 comfyui-workflow-templates==0.11.31 comfyui-embedded-docs==0.5.9 torch From 8fadc7b5be50eca0f39735cfbb12aa83f7474100 Mon Sep 17 00:00:00 2001 From: Terry Jia Date: Fri, 7 Aug 2026 16:25:37 -0400 Subject: [PATCH 09/20] [Partner Nodes] feat: ImageCompositor node with layer-state compositing, layer from bbox and Seedream Layer Separation node (#15317) --- comfy_api/latest/_io.py | 57 + comfy_api_nodes/apis/bytedance.py | 17 + comfy_api_nodes/nodes_bytedance.py | 370 +++ comfy_extras/compositor_blend.py | 331 +++ comfy_extras/nodes_compositor.py | 852 +++++++ nodes.py | 1 + .../compositor_blend_fixture_gen.py | 111 + .../compositor_blend_golden.json | 2242 +++++++++++++++++ .../compositor_blend_test.py | 157 ++ .../comfy_extras_test/compositor_node_test.py | 72 + 10 files changed, 4210 insertions(+) create mode 100644 comfy_extras/compositor_blend.py create mode 100644 comfy_extras/nodes_compositor.py create mode 100644 tests-unit/comfy_extras_test/compositor_blend_fixture_gen.py create mode 100644 tests-unit/comfy_extras_test/compositor_blend_golden.json create mode 100644 tests-unit/comfy_extras_test/compositor_blend_test.py create mode 100644 tests-unit/comfy_extras_test/compositor_node_test.py diff --git a/comfy_api/latest/_io.py b/comfy_api/latest/_io.py index 58e49d8e2..6d9e08f47 100644 --- a/comfy_api/latest/_io.py +++ b/comfy_api/latest/_io.py @@ -847,6 +847,61 @@ class Load3DAnimation(Load3D): ... +@comfytype(io_type="LAYERS") +class Layers(ComfyTypeIO): + BlendMode = Literal[ + "normal", "multiply", "screen", "overlay", "darken", "lighten", + "color-dodge", "color-burn", "hard-light", "soft-light", "difference", + "exclusion", "linear-dodge", "linear-burn", "vivid-light", "pin-light", + "linear-light", "hard-mix", "subtract", "divide", "grain-extract", + "grain-merge", "hue", "saturation", "color", "luminosity", + ] + + class LayerItem(TypedDict): + image: torch.Tensor + type: Literal["raster"] + x: NotRequired[int] + y: NotRequired[int] + mask: NotRequired[torch.Tensor] + z_index: int + name: NotRequired[str] + opacity: NotRequired[float] + blend_mode: NotRequired["Layers.BlendMode"] + visible: NotRequired[bool] + flip_h: NotRequired[bool] + flip_v: NotRequired[bool] + rotation: NotRequired[float] + w: NotRequired[int] + h: NotRequired[int] + + class Document(TypedDict): + version: int + canvas: NotRequired[tuple[int, int]] + layers: list["Layers.LayerItem"] + + Type = Document + + +@comfytype(io_type="COMPOSITOR") +class Compositor(ComfyTypeIO): + class LayerState(TypedDict): + version: NotRequired[int] + canvas: dict + background: NotRequired[dict] + inputs: NotRequired[list[str]] + order: NotRequired[list[int]] + layers: list[dict] + + Type = LayerState + + class Input(WidgetInput): + def __init__(self, id: str, display_name: str=None, optional=False, tooltip: str=None, + socketless: bool=True, default: dict=None, advanced: bool=None): + super().__init__(id, display_name, optional, tooltip, None, default, socketless, None, None, None, None, advanced) + if default is None: + self.default = {} + + @comfytype(io_type="PHOTOMAKER") class Photomaker(ComfyTypeIO): Type = Any @@ -2403,6 +2458,8 @@ __all__ = [ "Load3DModelInfo", "Load3D", "Load3DAnimation", + "Compositor", + "Layers", "Photomaker", "Point", "FaceAnalysis", diff --git a/comfy_api_nodes/apis/bytedance.py b/comfy_api_nodes/apis/bytedance.py index b83bb99ce..7ee83e5f3 100644 --- a/comfy_api_nodes/apis/bytedance.py +++ b/comfy_api_nodes/apis/bytedance.py @@ -35,6 +35,23 @@ class Seedream4TaskCreationRequest(BaseModel): optimize_prompt_options: Seedream5OptimizePromptOptions | None = None +class Seedream5LayerOptimizePromptOptions(BaseModel): + mode: Literal["standard", "fast"] = Field(...) + + +class Seedream5LayerSeparationRequest(BaseModel): + model: str = Field(...) + prompt: str | None = Field(None) + image: str = Field(..., description="Single image URL") + size: str = Field("auto") + seed: int = Field(..., ge=0, le=2147483647) + response_format: str = Field("url") + output_format: str = Field("png") + layer_decomposition: bool = Field(True) + watermark: bool = Field(False) + optimize_prompt_options: Seedream5LayerOptimizePromptOptions | None = Field(None) + + class ImageTaskCreationResponse(BaseModel): model: str = Field(...) created: int = Field(..., description="Unix timestamp (in seconds) indicating time when the request was created.") diff --git a/comfy_api_nodes/nodes_bytedance.py b/comfy_api_nodes/nodes_bytedance.py index f321a496b..09fc445d8 100644 --- a/comfy_api_nodes/nodes_bytedance.py +++ b/comfy_api_nodes/nodes_bytedance.py @@ -1,3 +1,4 @@ +import asyncio import base64 import hashlib import logging @@ -34,6 +35,8 @@ from comfy_api_nodes.apis.bytedance import ( SeedanceVirtualLibraryCreateAssetRequest, Seedream4Options, Seedream4TaskCreationRequest, + Seedream5LayerOptimizePromptOptions, + Seedream5LayerSeparationRequest, Seedream5OptimizePromptOptions, TaskAudioContent, TaskAudioContentUrl, @@ -75,6 +78,7 @@ from comfy_api_nodes.util import ( validate_video_dimensions, validate_video_duration, ) +from comfy_api_nodes.util.common_exceptions import ProcessingInterrupted from server import PromptServer BYTEPLUS_IMAGE_ENDPOINT = "/proxy/byteplus/api/v3/images/generations" @@ -96,6 +100,8 @@ SEEDREAM_PRESETS = { "seedream-4-0-250828": RECOMMENDED_PRESETS_SEEDREAM_4_0, } +SEEDREAM_LAYER_SEPARATION_MODEL = "seedream-5-0-pro-260628" + # Long-running tasks endpoints(e.g., video) BYTEPLUS_TASK_ENDPOINT = "/proxy/byteplus/api/v3/contents/generations/tasks" BYTEPLUS_TASK_STATUS_ENDPOINT = "/proxy/byteplus/api/v3/contents/generations/tasks" # + /{task_id} @@ -1044,6 +1050,369 @@ class ByteDanceSeedreamNodeV2(IO.ComfyNode): return IO.NodeOutput(torch.cat([await download_url_to_image_tensor(i) for i in urls])) +class ByteDanceSeedreamLayerSeparationNode(IO.ComfyNode): + + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="ByteDanceSeedreamLayerSeparationNode", + display_name="ByteDance Seedream 5.0 Pro Layer Separation", + category="partner/image/ByteDance", + search_aliases=["layer separation", "split layers", "decompose", "cutout", "RGBA layers"], + description=( + "Decompose an image into a background plate plus up to 16 repositionable transparent layers, " + "each with stacking order, bounding box, name and description." + ), + inputs=[ + IO.Image.Input( + "image", + tooltip=( + "The image to separate. Exactly one image, at least 512x512 pixels, aspect ratio " + "between 1:16 and 16:1. Inputs larger than about 4MP are downscaled before upload." + ), + ), + IO.String.Input( + "prompt", + multiline=True, + default="", + tooltip=( + "How to separate the image. Leave empty to auto-detect and separate all major elements. " + "Describe elements in natural language to control the separation, or target exact regions " + "with left top right bottom tags (0-1000 per-mille coordinates)." + ), + ), + IO.Combo.Input( + "size", + options=["auto", "1K", "1.5K", "2K"], + default="auto", + tooltip="Output resolution level. 'auto' follows the input image size (clamped to the 1K-2K range).", + ), + IO.Int.Input( + "seed", + default=0, + min=0, + max=2147483647, + step=1, + display_mode=IO.NumberDisplay.number, + control_after_generate=True, + tooltip="Seed to use for generation.", + ), + IO.Combo.Input( + "prompt_optimization", + options=["standard", "fast"], + default="standard", + optional=True, + advanced=True, + tooltip="Prompt-optimization mode: 'standard' gives higher quality, 'fast' shorter generation time.", + ), + IO.Boolean.Input( + "watermark", + default=False, + optional=True, + advanced=True, + tooltip='Whether to add an "AI generated" watermark to the images.', + ), + IO.Boolean.Input( + "crop_layers", + default=False, + optional=True, + label_on="minimal size", + label_off="full canvas", + tooltip=( + "Geometry of the layers/masks batch outputs (layer_stack is unaffected and always " + "tight). Full canvas: each layer on a base-sized canvas at its bounding-box position - " + "recompose directly with ImageCompositeMasked. Minimal size: each layer cropped to its " + "bounding box (padded to the largest layer for batching) - much smaller tensors; " + "rebuild placement with Layers From Bounding Boxes using the bboxes output." + ), + ), + ], + outputs=[ + IO.Image.Output( + display_name="base_image", + tooltip="The base image (background plate) the layers stack onto.", + ), + IO.Mask.Output( + display_name="base_mask", + tooltip=( + "Transparency of the base image (1 = transparent, LoadImage convention); currently " + "always fully opaque." + ), + ), + IO.Image.Output( + display_name="layers", + tooltip=( + "Transparent layers ordered bottom to top. Full canvas mode: placed on a black " + "base-sized canvas at their bounding-box position. Minimal size mode: cropped to " + "their bounding box, anchored top-left, padded to the largest layer." + ), + ), + IO.Mask.Output( + display_name="masks", + tooltip=( + "Per-layer transparency, index-aligned with the layers batch (1 = transparent, " + "LoadImage convention). For ImageCompositeMasked-style compositing, add InvertMask first." + ), + ), + IO.BoundingBox.Output( + display_name="bboxes", + tooltip=( + "One placement box per layer, index-aligned with the layers batch (feed both, plus " + "masks, into Layers From Bounding Boxes to rebuild per-layer placement): {x, y, width, " + "height, metadata: {name, desc, z_index, native_size, content_rect, flags}}. " + "content_rect = [left, top, width, height] is the layer's content region within its " + "own frame; it lands on the canvas at the box position plus that offset." + ), + ), + IO.Layers.Output( + display_name="layer_stack", + tooltip=( + "Ready-to-edit layer document for Create Layered Image: the base plate plus each " + "element as its own named, tight-cropped layer at its true position and stacking " + "order. Connect directly, or extend with Add Layer." + ), + ), + ], + hidden=[ + IO.Hidden.auth_token_comfy_org, + IO.Hidden.api_key_comfy_org, + IO.Hidden.unique_id, + ], + is_api_node=True, + price_badge=IO.PriceBadge( + depends_on=IO.PriceBadgeDepends(widgets=["size"]), + expr=""" + ( + widgets.size in ["1k", "1.5k"] + ? { + "type": "usd", + "usd": 0.032, + "format": { "suffix": " x images/Run", "approximate": true } + } + : { + "type": "range_usd", + "min_usd": 0.032, + "max_usd": 0.064, + "format": { "suffix": " x images/Run", "approximate": true } + } + ) + """, + ), + ) + + @classmethod + async def execute( + cls, + image: Input.Image, + prompt: str = "", + size: str = "auto", + seed: int = 0, + prompt_optimization: str = "standard", + watermark: bool = False, + crop_layers: bool = False, + ) -> IO.NodeOutput: + if get_number_of_images(image) != 1: + raise ValueError("Only a single input image is supported.") + validate_image_aspect_ratio(image, (1, 16), (16, 1), strict=False) + validate_image_dimensions(image, min_width=512, min_height=512) + + request = Seedream5LayerSeparationRequest( + model=SEEDREAM_LAYER_SEPARATION_MODEL, + prompt=prompt.strip() or None, + image=await upload_image_to_comfyapi(cls, image), + size=size, + seed=seed, + watermark=watermark, + optimize_prompt_options=Seedream5LayerOptimizePromptOptions(mode=prompt_optimization), + ) + response = await sync_op( + cls, + ApiEndpoint(path=BYTEPLUS_IMAGE_ENDPOINT, method="POST"), + response_model=ImageTaskCreationResponse, + data=request, + wait_label="Separating layers", + ) + if response.error: + raise RuntimeError( + f"ByteDance request failed. Code: {response.error['code']}, message: {response.error['message']}" + ) + + def z_index_of(d: dict) -> int: + v = d.get("z_index") + if isinstance(v, bool): + return 1_000_000 + if isinstance(v, (int, float)): + return int(v) + if isinstance(v, str): + try: + return int(v.strip()) + except ValueError: + return 1_000_000 + return 1_000_000 + + data = [d for d in (response.data or []) if isinstance(d, dict)] + if not data or "url" not in data[0]: + raise RuntimeError("Unexpected response: no base image returned.") + base_item = data[0] + if base_item.get("bounding_box") is not None: + logging.warning( + "ByteDance layer separation: base item unexpectedly carries a bounding_box; ignoring it." + ) + if z_index_of(base_item) not in (0, 1_000_000): + raise RuntimeError("Unexpected response: the first item is not the base image.") + layer_items = [d for d in data[1:] if "url" in d] + dropped = len(data) - 1 - len(layer_items) + if dropped > 0: + logging.warning( + "ByteDance layer separation: %d of %d returned elements had no 'url' and were dropped.", + dropped, + len(data) - 1, + ) + if not layer_items: + raise RuntimeError("The model returned no layers. Try a different prompt or input image.") + layer_items.sort(key=z_index_of) + + base_image = (await download_url_to_image_tensor(str(base_item["url"])))[..., :3].contiguous() + height, width = base_image.shape[1], base_image.shape[2] + + specs = [] + for item in layer_items: + flags = [] + bbox = item.get("bounding_box") + absolute = bbox.get("absolute") if isinstance(bbox, dict) else None + if ( + isinstance(absolute, (list, tuple)) + and len(absolute) == 4 + and all(isinstance(v, (int, float)) and not isinstance(v, bool) for v in absolute) + ): + left, top, right, bottom = (int(round(v)) for v in absolute) + rect_w, rect_h = right - left, bottom - top # exclusive right/bottom + if rect_w > width or rect_h > height: + rect_w, rect_h = min(rect_w, width), min(rect_h, height) + flags.append("bbox_clamped") + if rect_w <= 0 or rect_h <= 0: + flags.append("bbox_degenerate") + else: + flags.append("bbox_missing") + left, top, rect_w, rect_h = 0, 0, width, height + specs.append({"item": item, "flags": flags, "left": left, "top": top, + "rect_w": rect_w, "rect_h": rect_h, "native_size": "", "stack_item": None}) + + if crop_layers: + canvas_w = max((s["rect_w"] for s in specs if "bbox_degenerate" not in s["flags"]), default=1) + canvas_h = max((s["rect_h"] for s in specs if "bbox_degenerate" not in s["flags"]), default=1) + else: + canvas_w, canvas_h = width, height + base_mask = torch.zeros((1, height, width)) + layers = torch.zeros((len(specs), canvas_h, canvas_w, 3)) + # Create Layered Image / LoadImage mask convention: 1 = transparent + masks = torch.ones((len(specs), canvas_h, canvas_w)) + + semaphore = asyncio.Semaphore(4) + + async def fetch_and_place(i: int, spec: dict) -> None: + item, flags = spec["item"], spec["flags"] + left, top, rect_w, rect_h = spec["left"], spec["top"], spec["rect_w"], spec["rect_h"] + async with semaphore: + try: + rgba = (await download_url_to_image_tensor(str(item["url"])))[0] + except ProcessingInterrupted: + raise + except Exception as exc: + raise RuntimeError( + f"Failed to download layer {i + 1} of {len(specs)} (name={item.get('name')!r}): {exc} " + "The generation completed and was billed; the response with all layer URLs " + "is in ComfyUI/temp/api_logs/." + ) from exc + spec["native_size"] = f"{rgba.shape[1]}x{rgba.shape[0]}" + if "bbox_degenerate" in flags: + return + if (rgba.shape[1], rgba.shape[0]) != (rect_w, rect_h): + # premultiply before resizing: interpolating straight alpha bleeds the undefined + # colors of transparent pixels into the anti-aliased edges + rgba = rgba.clone() + rgba[..., :3] *= rgba[..., 3:4] + rgba = ( + torch.nn.functional.interpolate( + rgba.permute(2, 0, 1).unsqueeze(0), + size=(rect_h, rect_w), + mode="bilinear", + antialias=True, + ) + .squeeze(0) + .permute(1, 2, 0) + ) + alpha = rgba[..., 3:4] + rgba = torch.cat([rgba[..., :3] / alpha.clamp(min=1e-6), alpha], dim=-1).clamp(0, 1) + flags.append("resized_to_bbox") + # straight (unpremultiplied) RGB: downstream compositing applies the mask itself + if crop_layers: + layers[i, :rect_h, :rect_w] = rgba[..., :3] + masks[i, :rect_h, :rect_w] = 1.0 - rgba[..., 3] + else: + x0, y0 = max(left, 0), max(top, 0) + x1, y1 = min(left + rect_w, width), min(top + rect_h, height) + if x0 < x1 and y0 < y1: + patch = rgba[y0 - top : y1 - top, x0 - left : x1 - left] + layers[i, y0:y1, x0:x1] = patch[..., :3] + masks[i, y0:y1, x0:x1] = 1.0 - patch[..., 3] + else: + flags.append("bbox_out_of_canvas") + zi = z_index_of(item) + stack_item = { + "image": rgba[..., :3].unsqueeze(0).contiguous(), + "type": "raster", + "x": left, + "y": top, + "z_index": zi if zi != 1_000_000 else i + 1, + "mask": (1.0 - rgba[..., 3]).unsqueeze(0), + } + if isinstance(item.get("name"), str): + stack_item["name"] = item["name"] + spec["stack_item"] = stack_item + + await asyncio.gather(*(fetch_and_place(i, s) for i, s in enumerate(specs))) + + stack_items = [{"image": base_image, "type": "raster", "x": 0, "y": 0, "z_index": 0, "name": "background"}] + boxes = [] + for i, s in enumerate(specs): + abnormal = [f for f in s["flags"] if f != "resized_to_bbox"] + if abnormal: + logging.warning( + "ByteDance layer separation: layer %d (%r) flagged %s.", + i + 1, + s["item"].get("name"), + ", ".join(abnormal), + ) + if s["stack_item"] is not None: + stack_items.append(s["stack_item"]) + zi = z_index_of(s["item"]) + # placement box sized to this layer's tensor so Create Layered Image renders it 1:1; + # the true content rect travels in metadata, frame-relative + rect_x, rect_y = (0, 0) if crop_layers else (s["left"], s["top"]) + boxes.append( + { + "x": s["left"] if crop_layers else 0, + "y": s["top"] if crop_layers else 0, + "width": canvas_w, + "height": canvas_h, + "metadata": { + "name": s["item"].get("name"), + "desc": s["item"].get("description"), + "z_index": zi if zi != 1_000_000 else None, + "native_size": s["native_size"], + "content_rect": [rect_x, rect_y, max(s["rect_w"], 0), max(s["rect_h"], 0)], + "flags": s["flags"], + }, + } + ) + # a single frame holding every box: the per-frame BOUNDING_BOX shape for boxes that + # annotate one image, as emitted and consumed by CreateBoundingBoxes + bboxes = [boxes] + layer_stack = {"version": 1, "canvas": (width, height), "layers": stack_items} + return IO.NodeOutput(base_image, base_mask, layers, masks, bboxes, layer_stack) + + class ByteDanceTextToVideoNode(IO.ComfyNode): @classmethod @@ -3036,6 +3405,7 @@ class ByteDanceExtension(ComfyExtension): ByteDanceImageNode, ByteDanceSeedreamNode, ByteDanceSeedreamNodeV2, + ByteDanceSeedreamLayerSeparationNode, ByteDanceTextToVideoNode, ByteDanceImageToVideoNode, ByteDanceFirstLastFrameNode, diff --git a/comfy_extras/compositor_blend.py b/comfy_extras/compositor_blend.py new file mode 100644 index 000000000..13476e781 --- /dev/null +++ b/comfy_extras/compositor_blend.py @@ -0,0 +1,331 @@ +import math +from typing import NamedTuple, Optional, Union + +import numpy as np + +EPSILON = 1e-6 + +LUM_R = 0.2224884 +LUM_G = 0.71690369 +LUM_B = 0.06060791 + +ArrayLike = Union[np.ndarray, float] + + +def srgb_to_linear(c: ArrayLike) -> np.ndarray: + c = np.asarray(c, dtype=np.float32) + high = ((np.maximum(c, 0.0) + 0.055) / 1.055) ** 2.4 + return np.where(c <= 0.04045, c / 12.92, high).astype(np.float32) + + +def linear_to_srgb(c: ArrayLike) -> np.ndarray: + c = np.asarray(c, dtype=np.float32) + high = 1.055 * np.maximum(c, 0.0) ** (1.0 / 2.4) - 0.055 + return np.where(c <= 0.0031308, 12.92 * c, high).astype(np.float32) + + +def luminance(rgb: np.ndarray) -> np.ndarray: + return rgb[..., 0] * LUM_R + rgb[..., 1] * LUM_G + rgb[..., 2] * LUM_B + + +def safe_div(a: ArrayLike, b: ArrayLike) -> np.ndarray: + a, b = np.broadcast_arrays( + np.asarray(a, dtype=np.float32), np.asarray(b, dtype=np.float32) + ) + out = np.zeros(b.shape, dtype=np.float32) + np.divide(a, b, out=out, where=np.abs(b) >= EPSILON) + return out + + +CHANNEL_BLEND = { + "normal": lambda i, l: l, + "multiply": lambda i, l: i * l, + "screen": lambda i, l: 1 - (1 - i) * (1 - l), + "overlay": lambda i, l: np.where(i < 0.5, 2 * i * l, 1 - 2 * (1 - l) * (1 - i)), + "darken": lambda i, l: np.minimum(i, l), + "lighten": lambda i, l: np.maximum(i, l), + "color-dodge": lambda i, l: np.where( + i <= 0, + 0.0, + np.where(1 - l <= EPSILON, 1.0, np.minimum(safe_div(i, 1 - l), 1.0)), + ), + "color-burn": lambda i, l: np.where( + i >= 1, + 1.0, + np.where(l <= EPSILON, 0.0, 1 - np.minimum(safe_div(1 - i, l), 1.0)), + ), + "hard-light": lambda i, l: np.where( + l > 0.5, + np.minimum(1 - (1 - i) * (1 - (l - 0.5) * 2), 1), + np.minimum(i * (l * 2), 1), + ), + "soft-light": lambda i, l: (1 - i) * (i * l) + i * (1 - (1 - i) * (1 - l)), + "difference": lambda i, l: np.abs(i - l), + "exclusion": lambda i, l: 0.5 - 2 * (i - 0.5) * (l - 0.5), + "linear-dodge": lambda i, l: i + l, + "linear-burn": lambda i, l: i + l - 1, + "vivid-light": lambda i, l: np.where( + l <= 0.5, + np.where( + i >= 1, + 1.0, + np.where( + 2 * l <= EPSILON, + 0.0, + np.maximum(1 - safe_div(1 - i, 2 * l), 0.0), + ), + ), + np.where( + i <= 0, + 0.0, + np.where( + 2 * (1 - l) <= EPSILON, + 1.0, + np.minimum(safe_div(i, 2 * (1 - l)), 1.0), + ), + ), + ), + "pin-light": lambda i, l: np.where( + l > 0.5, np.maximum(i, 2 * (l - 0.5)), np.minimum(i, 2 * l) + ), + "linear-light": lambda i, l: i + 2 * l - 1, + "hard-mix": lambda i, l: np.where(i + l < 1, 0.0, 1.0), + "subtract": lambda i, l: np.maximum(i - l, 0), + "divide": lambda i, l: np.clip(i / np.maximum(l, EPSILON), 0, 1), + "grain-extract": lambda i, l: i - l + 0.5, + "grain-merge": lambda i, l: i + l - 0.5, +} + + +def _blend_hue(i: np.ndarray, l: np.ndarray) -> np.ndarray: + src_min = l.min(axis=-1) + src_max = l.max(axis=-1) + src_delta = src_max - src_min + achromatic = src_delta <= EPSILON + dest_max = i.max(axis=-1) + dest_delta = dest_max - i.min(axis=-1) + dest_s = np.where(dest_max != 0, dest_delta / np.where(dest_max != 0, dest_max, 1), 0) + ratio = np.where( + achromatic, 0, dest_s * dest_max / np.where(achromatic, 1, src_delta) + ) + offset = dest_max - src_max * ratio + return np.where(achromatic[..., None], i, l * ratio[..., None] + offset[..., None]) + + +def _blend_saturation(i: np.ndarray, l: np.ndarray) -> np.ndarray: + dest_max = i.max(axis=-1) + dest_delta = dest_max - i.min(axis=-1) + flat = dest_delta <= EPSILON + src_max = l.max(axis=-1) + src_delta = src_max - l.min(axis=-1) + src_s = np.where(src_max != 0, src_delta / np.where(src_max != 0, src_max, 1), 0) + ratio = np.where(flat, 0, src_s * dest_max / np.where(flat, 1, dest_delta)) + offset = (1 - ratio) * dest_max + return np.where( + flat[..., None], + np.broadcast_to(dest_max[..., None], i.shape), + i * ratio[..., None] + offset[..., None], + ) + + +def _blend_color(i: np.ndarray, l: np.ndarray) -> np.ndarray: + dest_l = (i.min(axis=-1) + i.max(axis=-1)) / 2 + src_l = (l.min(axis=-1) + l.max(axis=-1)) / 2 + gray = (np.abs(src_l) <= EPSILON) | (np.abs(1 - src_l) <= EPSILON) + dest_high = dest_l > 0.5 + src_high = src_l > 0.5 + dl = np.minimum(dest_l, 1 - dest_l) + sl = np.minimum(src_l, 1 - src_l) + ratio = dl / np.where(gray, 1, sl) + offset = np.where(dest_high, 1 - 2 * dl, 0) + np.where(src_high, 2 * dl - ratio, 0) + return np.where( + gray[..., None], + np.broadcast_to(dest_l[..., None], i.shape), + l * ratio[..., None] + offset[..., None], + ) + + +def _blend_luminosity(i: np.ndarray, l: np.ndarray) -> np.ndarray: + # Scale the backdrop so it carries the layer's luminance. Where the backdrop + # has no luminance to scale there is no hue or saturation to preserve either, + # so the result is a neutral grey at the layer's luminance - which is also the + # analytic limit of i * lum(l)/lum(i) as a grey backdrop approaches black. + # Guarding the numerator here instead (returning black) makes a luminosity + # layer disappear over dark backdrops; see tests-unit/comfy_extras_test/ + # compositor_blend_golden.json. + lum_i = luminance(i) + lum_l = luminance(l) + degenerate = lum_i <= EPSILON + ratio = np.where(degenerate, 0.0, lum_l / np.where(degenerate, 1.0, lum_i)) + return np.where( + degenerate[..., None], + np.broadcast_to(lum_l[..., None], i.shape), + i * ratio[..., None], + ) + + +HSL_BLEND = { + "hue": _blend_hue, + "saturation": _blend_saturation, + "color": _blend_color, + "luminosity": _blend_luminosity, +} + + +def blend_pixel(blend: str, in_rgb: np.ndarray, layer_rgb: np.ndarray) -> np.ndarray: + in_rgb = np.asarray(in_rgb, dtype=np.float32) + layer_rgb = np.asarray(layer_rgb, dtype=np.float32) + hsl = HSL_BLEND.get(blend) + if hsl is not None: + return np.asarray(hsl(in_rgb, layer_rgb), dtype=np.float32) + fn = CHANNEL_BLEND.get(blend, CHANNEL_BLEND["normal"]) + return np.asarray(fn(in_rgb, layer_rgb), dtype=np.float32) + + +def _composite_union(in_c, layer, comp, cov): + in_a = in_c[..., 3] + layer_a = layer[..., 3] * cov + new_a = layer_a + (1 - layer_a) * in_a + ratio = np.where(new_a != 0, layer_a / np.where(new_a != 0, new_a, 1), 0) + blended = ( + ratio[..., None] + * (in_a[..., None] * (comp - layer[..., :3]) + layer[..., :3] - in_c[..., :3]) + + in_c[..., :3] + ) + keep = (layer_a == 0) | (new_a == 0) + rgb = np.where( + keep[..., None], + in_c[..., :3], + np.where((in_a == 0)[..., None], layer[..., :3], blended), + ) + return np.concatenate([rgb, new_a[..., None]], axis=-1) + + +def _composite_clip_to_backdrop(in_c, layer, comp, cov): + in_a = in_c[..., 3] + layer_a = layer[..., 3] * cov + mixed = comp * layer_a[..., None] + in_c[..., :3] * (1 - layer_a[..., None]) + keep = (in_a == 0) | (layer_a == 0) + rgb = np.where(keep[..., None], in_c[..., :3], mixed) + return np.concatenate([rgb, in_a[..., None]], axis=-1) + + +def _composite_clip_to_layer(in_c, layer, comp, cov): + in_a = in_c[..., 3] + layer_a = layer[..., 3] * cov + mixed = comp * in_a[..., None] + layer[..., :3] * (1 - in_a[..., None]) + rgb = np.where( + (layer_a == 0)[..., None], + in_c[..., :3], + np.where((in_a == 0)[..., None], layer[..., :3], mixed), + ) + return np.concatenate([rgb, layer_a[..., None]], axis=-1) + + +def _composite_intersection(in_c, layer, comp, cov): + new_a = in_c[..., 3] * layer[..., 3] * cov + rgb = np.where((new_a == 0)[..., None], in_c[..., :3], comp) + return np.concatenate([rgb, new_a[..., None]], axis=-1) + + +_COMPOSITE = { + "union": _composite_union, + "clip-to-backdrop": _composite_clip_to_backdrop, + "clip-to-layer": _composite_clip_to_layer, + "intersection": _composite_intersection, +} + + +def run_composite(mode: str, in_c, layer, comp, cov) -> np.ndarray: + fn = _COMPOSITE.get(mode, _composite_union) + return fn(in_c, layer, comp, cov) + + +def _to_space(rgb: np.ndarray, space: str) -> np.ndarray: + return rgb if space == "linear" else linear_to_srgb(rgb) + + +def _from_space(rgb: np.ndarray, space: str) -> np.ndarray: + return rgb if space == "linear" else srgb_to_linear(rgb) + + +class EffectiveMode(NamedTuple): + blend: str + blend_space: str + composite: str + + +_LAYER_MODES = { + "normal": ("linear", "union"), + "multiply": ("linear", "clip-to-backdrop"), + "screen": ("perceptual", "clip-to-backdrop"), + "overlay": ("perceptual", "clip-to-backdrop"), + "darken": ("linear", "clip-to-backdrop"), + "lighten": ("linear", "clip-to-backdrop"), + "color-dodge": ("perceptual", "clip-to-backdrop"), + "color-burn": ("perceptual", "clip-to-backdrop"), + "hard-light": ("perceptual", "clip-to-backdrop"), + "soft-light": ("perceptual", "clip-to-backdrop"), + "difference": ("perceptual", "clip-to-backdrop"), + "exclusion": ("perceptual", "clip-to-backdrop"), + "linear-dodge": ("linear", "clip-to-backdrop"), + "linear-burn": ("perceptual", "clip-to-backdrop"), + "vivid-light": ("perceptual", "clip-to-backdrop"), + "pin-light": ("perceptual", "clip-to-backdrop"), + "linear-light": ("perceptual", "clip-to-backdrop"), + "hard-mix": ("perceptual", "clip-to-backdrop"), + "subtract": ("linear", "clip-to-backdrop"), + "divide": ("linear", "clip-to-backdrop"), + "grain-extract": ("perceptual", "clip-to-backdrop"), + "grain-merge": ("perceptual", "clip-to-backdrop"), + "hue": ("perceptual", "clip-to-backdrop"), + "saturation": ("perceptual", "clip-to-backdrop"), + "color": ("perceptual", "clip-to-backdrop"), + "luminosity": ("linear", "clip-to-backdrop"), +} + + +def resolve_mode(blend: str = "normal") -> EffectiveMode: + blend_space, composite = _LAYER_MODES.get(blend, _LAYER_MODES["normal"]) + return EffectiveMode( + blend=blend, + blend_space=blend_space, + composite=composite, + ) + + +def blend_composite( + mode: EffectiveMode, + backdrop: np.ndarray, + layer: np.ndarray, + opacity: float, + mask: Optional[ArrayLike] = None, +) -> np.ndarray: + backdrop = np.asarray(backdrop, dtype=np.float32) + layer = np.asarray(layer, dtype=np.float32) + cov = opacity * (1.0 if mask is None else mask) + + in_b = _to_space(backdrop[..., :3], mode.blend_space) + layer_b = _to_space(layer[..., :3], mode.blend_space) + comp = _from_space(blend_pixel(mode.blend, in_b, layer_b), mode.blend_space) + + return run_composite(mode.composite, backdrop, layer, comp, cov) + + +def placed_bounds( + x: float, y: float, w: float, h: float, rotation: float +) -> tuple[int, int, int, int]: + cx = x + w / 2 + cy = y + h / 2 + cos = math.cos(rotation) + sin = math.sin(rotation) + hw = w / 2 + hh = h / 2 + corners = ((-hw, -hh), (hw, -hh), (hw, hh), (-hw, hh)) + xs = [cx + dx * cos - dy * sin for dx, dy in corners] + ys = [cy + dx * sin + dy * cos for dx, dy in corners] + bx = math.floor(min(xs)) + by = math.floor(min(ys)) + bw = max(1, math.ceil(max(xs)) - bx) + bh = max(1, math.ceil(max(ys)) - by) + return bx, by, bw, bh diff --git a/comfy_extras/nodes_compositor.py b/comfy_extras/nodes_compositor.py new file mode 100644 index 000000000..10cea3adc --- /dev/null +++ b/comfy_extras/nodes_compositor.py @@ -0,0 +1,852 @@ +import hashlib +import json +import math + +import numpy as np +import torch +from PIL import Image + +from comfy_api.latest import ComfyExtension, io, UI +from comfy_extras.compositor_blend import ( + _LAYER_MODES, + blend_composite, + linear_to_srgb, + placed_bounds, + resolve_mode, + srgb_to_linear, +) +from comfy_extras.color_util import hex_to_rgb +from comfy_extras.nodes_bounding_boxes import boxes_from_input +from nodes import MAX_RESOLUTION +from typing_extensions import override + + +MAX_LAYERS = 50 + + +def document_items(doc) -> list[dict]: + if not isinstance(doc, dict): + return [] + version = doc.get("version") + if version is not None and version != 1: + raise ValueError(f"LAYERS document version {version!r} is not supported") + items = [] + for item in doc.get("layers") or []: + if not isinstance(item, dict): + continue + item_type = item.get("type", "raster") + if item_type != "raster": + raise ValueError(f"LAYERS item type {item_type!r} is not supported yet") + if not isinstance(item.get("image"), torch.Tensor): + continue + blend = item.get("blend_mode") + if blend is not None and blend not in _LAYER_MODES: + raise ValueError(f"LAYERS item blend_mode {blend!r} is not a known blend mode") + items.append(item) + return sorted(items, key=lambda item: _int(item.get("z_index"), 0)) + + +def document_canvas(doc) -> tuple[int, int] | None: + if not isinstance(doc, dict): + return None + canvas = doc.get("canvas") + if not isinstance(canvas, (tuple, list)) or len(canvas) != 2: + return None + w, h = _int(canvas[0], 0), _int(canvas[1], 0) + return (w, h) if w > 0 and h > 0 else None + + +def _int(value, default: int) -> int: + return int(value) if isinstance(value, (int, float)) and not isinstance(value, bool) else default + + +def _bbox_list(bboxes, canvas_width: int, canvas_height: int) -> list[dict]: + if bboxes is None: + return [] + if isinstance(bboxes, str): + text = bboxes.strip() + if not text: + return [] + try: + bboxes = json.loads(text) + except (json.JSONDecodeError, ValueError) as exc: + raise ValueError(f"bboxes string input is not valid JSON: {exc}") from exc + probe = bboxes if isinstance(bboxes, list) else [bboxes] + if probe and isinstance(probe[0], list): + probe = probe[0] + has_elements = any( + isinstance(box, dict) and isinstance(box.get("bbox"), (list, tuple)) + for box in probe + ) + if has_elements and (canvas_width <= 0 or canvas_height <= 0): + raise ValueError( + "normalized element boxes need canvas_width and canvas_height to resolve to pixels" + ) + return boxes_from_input(bboxes, canvas_width, canvas_height) + + +def _item_mask_frame(mask, index: int) -> torch.Tensor | None: + if not isinstance(mask, torch.Tensor): + return None + if mask.shape[0] == 1: + return mask[:1] + if index < mask.shape[0]: + return mask[index : index + 1] + return None + + +def expand_item_frames(items: list[dict]) -> list[dict]: + frames = [] + for item in items: + image = item["image"] + for index in range(image.shape[0]): + width = _int(item.get("w"), 0) + height = _int(item.get("h"), 0) + rotation = item.get("rotation") + frames.append({ + "tensor": image[index : index + 1], + "mask": _item_mask_frame(item.get("mask"), index), + "name": item.get("name") if isinstance(item.get("name"), str) else None, + "x": _int(item.get("x"), 0), + "y": _int(item.get("y"), 0), + "w": width if width > 0 else int(image.shape[2]), + "h": height if height > 0 else int(image.shape[1]), + "rotation": float(rotation) + if isinstance(rotation, (int, float)) and not isinstance(rotation, bool) + else 0.0, + "opacity": item.get("opacity", 1.0), + "blend": item.get("blend_mode", "normal"), + "visible": item.get("visible", True), + "flip_h": bool(item.get("flip_h", False)), + "flip_v": bool(item.get("flip_v", False)), + }) + if len(frames) > MAX_LAYERS: + raise ValueError( + f"Compositor supports at most {MAX_LAYERS} layers, got {len(frames)}" + ) + return frames + + +def frame_alpha( + tensor: torch.Tensor, mask: torch.Tensor | None +) -> torch.Tensor | None: + alpha = tensor[:1, :, :, 3] if tensor.shape[-1] == 4 else None + if mask is None: + return alpha + h, w = tensor.shape[1], tensor.shape[2] + m = mask[:1].to(device=tensor.device, dtype=torch.float32) + if m.shape[1] != h or m.shape[2] != w: + m = torch.nn.functional.interpolate( + m.unsqueeze(1), size=(h, w), mode="bilinear" + ).squeeze(1) + inv = torch.clamp(1.0 - m, 0.0, 1.0) + return inv if alpha is None else alpha * inv + + +def layer_preview_tensor( + tensor: torch.Tensor, alpha: torch.Tensor | None +) -> torch.Tensor: + rgb = tensor[:1, :, :, :3] + if alpha is None: + return rgb + return torch.cat([rgb, alpha.unsqueeze(-1)], dim=-1) + + +def canvas_extent(frames: list[dict]) -> tuple[int, int]: + right = 1 + bottom = 1 + for frame in frames: + bx, by, bw, bh = placed_bounds( + frame["x"], frame["y"], frame["w"], frame["h"], frame["rotation"] + ) + right = max(right, bx + bw) + bottom = max(bottom, by + bh) + return (right, bottom) + + +def input_fingerprints( + frames: list[dict], alphas: list[torch.Tensor | None] +) -> list[str]: + fingerprints = [] + for frame, alpha in zip(frames, alphas): + tensor = frame["tensor"] + rgb = tensor[0, :, :, :3].detach().cpu().numpy() + rgb8 = np.clip(np.rint(rgb * 255.0), 0, 255).astype(np.uint8) + digest = hashlib.sha256() + digest.update(repr(tuple(tensor.shape)).encode()) + digest.update(rgb8.tobytes()) + if alpha is not None: + alpha8 = np.clip( + np.rint(alpha[0].detach().cpu().numpy() * 255.0), 0, 255 + ).astype(np.uint8) + digest.update(alpha8.tobytes()) + digest.update( + repr(( + frame["x"], + frame["y"], + frame["w"], + frame["h"], + frame["rotation"], + frame["opacity"], + frame["blend"], + bool(frame["visible"]), + frame["flip_h"], + frame["flip_v"], + )).encode() + ) + fingerprints.append(digest.hexdigest()[:16]) + return fingerprints + + +def state_from_items(frames: list[dict], canvas: tuple[int, int]) -> dict: + layers = [] + for frame in frames: + layers.append({ + "name": frame["name"], + "visible": bool(frame["visible"]), + "opacity": frame["opacity"], + "blend": frame["blend"], + "flipH": frame["flip_h"], + "flipV": frame["flip_v"], + "transform": { + "x": frame["x"], + "y": frame["y"], + "w": frame["w"], + "h": frame["h"], + "rotation": frame["rotation"], + }, + }) + return { + "canvas": canvas, + "layers": layers, + "inputs": None, + "background": {"color": "#ffffff", "opacity": 1.0, "visible": False}, + } + + +def layer_ui_entries(frames: list[dict]) -> list: + entries = [] + for frame in frames: + entries.append({ + "x": frame["x"], + "y": frame["y"], + "width": int(frame["w"]), + "height": int(frame["h"]), + "rotation": frame["rotation"], + "name": frame["name"], + "visible": bool(frame["visible"]), + "opacity": frame["opacity"] if isinstance(frame["opacity"], (int, float)) else 1.0, + "blend": frame["blend"] if isinstance(frame["blend"], str) else "normal", + "flipH": frame["flip_h"], + "flipV": frame["flip_v"], + }) + return entries + + +_HEX_DIGITS = set("0123456789abcdef") + + +def _normalize_hex_color(value) -> str: + if isinstance(value, str): + text = value.strip().lower() + if text.startswith("#"): + digits = text[1:] + if len(digits) == 3 and set(digits) <= _HEX_DIGITS: + digits = "".join(ch * 2 for ch in digits) + if len(digits) == 6 and set(digits) <= _HEX_DIGITS: + return "#" + digits + return "#ffffff" + + +def _parse_background(entry) -> dict | None: + if not isinstance(entry, dict): + return None + return { + "color": _normalize_hex_color(entry.get("color")), + "opacity": min(max(_number(entry, "opacity", 1.0), 0.0), 1.0), + "visible": bool(entry.get("visible", True)), + } + + +def _parse_order(value, layer_count: int) -> list[int] | None: + if not isinstance(value, list) or not value: + return None + if not all( + isinstance(item, int) and not isinstance(item, bool) for item in value + ): + return None + if sorted(value) != list(range(layer_count)): + return None + return value + + +def layer_state_provided(raw) -> bool: + if isinstance(raw, dict): + return bool(raw) + if isinstance(raw, str): + return raw not in ("", "{}") + return False + + +def parse_layer_state(raw) -> dict | None: + if isinstance(raw, str): + if not raw.strip(): + return None + try: + raw = json.loads(raw) + except (json.JSONDecodeError, ValueError): + return None + if not isinstance(raw, dict): + return None + state = raw + version = state.get("version") + if version is not None and version != 1: + return None + canvas = state.get("canvas") + layers = state.get("layers") + if not isinstance(canvas, dict) or not isinstance(layers, list) or not layers: + return None + try: + w = int(round(float(canvas.get("w")))) + h = int(round(float(canvas.get("h")))) + except (TypeError, ValueError, OverflowError): + return None + if w <= 0 or h <= 0: + return None + inputs = state.get("inputs") + if ( + not isinstance(inputs, list) + or len(inputs) != len(layers) + or not all(isinstance(entry, str) for entry in inputs) + ): + inputs = None + return { + "canvas": (w, h), + "layers": layers, + "inputs": inputs, + "background": _parse_background(state.get("background")), + "order": _parse_order(state.get("order"), len(layers)), + } + + +def _number(source: dict, key: str, default: float) -> float: + value = source.get(key, default) + if not isinstance(value, (int, float)) or not math.isfinite(value): + return float(default) + return float(value) + + +def _clamped_size(value: float, natural: int) -> float: + return float(natural) if value <= 0 else min(value, float(MAX_RESOLUTION)) + + +def _layer_params(entry, natural_w: int, natural_h: int) -> dict: + if not isinstance(entry, dict): + entry = {} + transform = entry.get("transform") + if not isinstance(transform, dict): + transform = {} + blend = entry.get("blend") + return { + "visible": bool(entry.get("visible", True)), + # The layer state is untrusted input: it round-trips through the saved + # workflow and can be posted directly to /prompt. An out-of-range opacity + # would otherwise reach blend_composite as a raw coverage multiplier and + # produce negative or greater-than-white RGB. _parse_background already + # clamps the same field. + "opacity": min(max(_number(entry, "opacity", 1.0), 0.0), 1.0), + "blend": blend if isinstance(blend, str) else "normal", + "x": min(max(_number(transform, "x", 0.0), -MAX_RESOLUTION), MAX_RESOLUTION), + "y": min(max(_number(transform, "y", 0.0), -MAX_RESOLUTION), MAX_RESOLUTION), + "w": _clamped_size(_number(transform, "w", natural_w), natural_w), + "h": _clamped_size(_number(transform, "h", natural_h), natural_h), + "rotation": _number(transform, "rotation", 0.0), + "flip_h": bool(entry.get("flipH", False)), + "flip_v": bool(entry.get("flipV", False)), + } + + +def _prepare_layer_bitmap( + tensor: torch.Tensor, params: dict, alpha: torch.Tensor | None +) -> Image.Image: + frame = tensor[0, :, :, :3].detach().cpu().numpy() + rgb8 = np.clip(np.rint(frame * 255.0), 0, 255).astype(np.uint8) + if alpha is None: + img = Image.fromarray(rgb8, "RGB").convert("RGBA") + else: + alpha8 = np.clip( + np.rint(alpha[0].detach().cpu().numpy() * 255.0), 0, 255 + ).astype(np.uint8) + img = Image.fromarray(np.dstack([rgb8, alpha8]), "RGBA") + if params["flip_h"]: + img = img.transpose(Image.Transpose.FLIP_LEFT_RIGHT) + if params["flip_v"]: + img = img.transpose(Image.Transpose.FLIP_TOP_BOTTOM) + target = (max(1, round(params["w"])), max(1, round(params["h"]))) + if img.size != target: + img = img.resize(target, Image.Resampling.LANCZOS) + if params["rotation"] != 0: + img = img.rotate( + -math.degrees(params["rotation"]), + expand=True, + resample=Image.Resampling.BICUBIC, + fillcolor=(0, 0, 0, 0), + ) + return img + + +def _place_in_bounds(img: Image.Image, bw: int, bh: int) -> np.ndarray: + arr = np.asarray(img, dtype=np.float32) / 255.0 + rgba = np.concatenate([srgb_to_linear(arr[..., :3]), arr[..., 3:4]], axis=-1) + aw, ah = img.size + buf = np.zeros((bh, bw, 4), dtype=np.float32) + ox = (bw - aw) // 2 + oy = (bh - ah) // 2 + dx0, dy0 = max(ox, 0), max(oy, 0) + dx1, dy1 = min(ox + aw, bw), min(oy + ah, bh) + if dx0 < dx1 and dy0 < dy1: + buf[dy0:dy1, dx0:dx1] = rgba[dy0 - oy : dy1 - oy, dx0 - ox : dx1 - ox] + return buf + + +def _fill_background(canvas: np.ndarray, background: dict) -> np.ndarray: + layer = np.empty(canvas.shape, dtype=np.float32) + layer[..., :3] = srgb_to_linear( + np.array(hex_to_rgb(background["color"]), dtype=np.float32) / 255.0 + ) + layer[..., 3] = 1.0 + return blend_composite( + resolve_mode("normal"), canvas, layer, background["opacity"] + ) + + +def composite_from_state( + tensors: list[torch.Tensor], + state: dict, + alphas: list[torch.Tensor | None], +) -> torch.Tensor: + cw, ch = state["canvas"] + if cw > MAX_RESOLUTION or ch > MAX_RESOLUTION: + raise ValueError( + f"Compositor canvas {cw}x{ch} exceeds the maximum supported size of " + f"{MAX_RESOLUTION}x{MAX_RESOLUTION}" + ) + canvas = np.zeros((ch, cw, 4), dtype=np.float32) + background = state.get("background") + if background is not None and background["visible"] and background["opacity"] > 0: + canvas = _fill_background(canvas, background) + layers = state["layers"] + order = state.get("order") or range(len(tensors)) + for index in order: + if index < 0 or index >= len(tensors): + continue + tensor = tensors[index] + entry = layers[index] if index < len(layers) else None + params = _layer_params(entry, tensor.shape[2], tensor.shape[1]) + if not params["visible"]: + continue + img = _prepare_layer_bitmap( + tensor, params, alphas[index] if index < len(alphas) else None + ) + bx, by, bw, bh = placed_bounds( + params["x"], params["y"], params["w"], params["h"], params["rotation"] + ) + buf = _place_in_bounds(img, bw, bh) + x0, y0 = max(bx, 0), max(by, 0) + x1, y1 = min(bx + bw, cw), min(by + bh, ch) + if x0 >= x1 or y0 >= y1: + continue + region = buf[y0 - by : y1 - by, x0 - bx : x1 - bx] + mode = resolve_mode(params["blend"]) + canvas[y0:y1, x0:x1] = blend_composite( + mode, canvas[y0:y1, x0:x1], region, params["opacity"] + ) + rgb = linear_to_srgb(np.clip(canvas[..., :3], 0.0, 1.0)) + alpha = np.clip(canvas[..., 3:4], 0.0, 1.0) + rgba = np.concatenate([rgb, alpha], axis=-1) + return torch.from_numpy(rgba.astype(np.float32)).unsqueeze(0) + + +OPAQUE_EPSILON = 1e-3 + + +def composite_outputs(out: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]: + if out.shape[-1] != 4: + return out, torch.zeros(out.shape[:3], dtype=torch.float32) + alpha = out[..., 3] + if bool((alpha >= 1.0 - OPAQUE_EPSILON).all()): + return out[..., :3], torch.zeros_like(alpha) + return out, torch.clamp(1.0 - alpha, 0.0, 1.0) + + +class ImageCompositor(io.ComfyNode): + @classmethod + def define_schema(cls): + return io.Schema( + node_id="ImageCompositor", + display_name="Create Layered Image", + category="image", + is_experimental=True, + is_output_node=True, + has_intermediate_output=True, + inputs=[ + io.Layers.Input( + "layers", + tooltip="Layer stack to composite; build it with Add Layer. Items are stacked by z_index, batch frames inside an item expand to consecutive layers, and item placement, opacity, and blend mode define the initial composition. Without an explicit document canvas the size is a best-effort maximum extent of the placed layers. A saved composition that matches the current inputs takes priority.", + ), + io.Compositor.Input( + "compositor", + tooltip="Layered composition saved by the compositor editor.", + ), + ], + outputs=[ + io.Image.Output( + tooltip="Composited image. Carries an alpha channel when the composite has transparent areas (e.g. hidden background), otherwise plain RGB." + ), + io.Mask.Output( + tooltip="Transparency of the composite (1 = fully transparent). All zeros when the composite is opaque." + ), + ], + ) + + @classmethod + def execute(cls, layers: io.Layers.Type, compositor: io.Compositor.Type = None) -> io.NodeOutput: + frames = expand_item_frames(document_items(layers)) + tensors = [frame["tensor"] for frame in frames] + alphas = [frame_alpha(frame["tensor"], frame["mask"]) for frame in frames] + + layer_refs = [] + for tensor, alpha in zip(tensors, alphas): + layer_refs.extend( + UI.PreviewImage(layer_preview_tensor(tensor, alpha), cls=cls).values + ) + + fp = input_fingerprints(frames, alphas) + raw_state = compositor + state = parse_layer_state(raw_state) + replay = bool(state is not None and tensors and state["inputs"] == fp) + if replay: + out = composite_from_state(tensors, state, alphas) + elif tensors: + canvas = document_canvas(layers) or canvas_extent(frames) + out = composite_from_state( + tensors, state_from_items(frames, canvas), alphas + ) + else: + out = torch.zeros((1, 64, 64, 3), dtype=torch.float32) + state_stale = layer_state_provided(raw_state) and not replay + out, mask = composite_outputs(out) + + ui_dict = UI.PreviewImage(out, cls=cls).as_dict() + ui_dict["compositor_layers"] = layer_refs + ui_dict["compositor_inputs"] = fp + ui_dict["compositor_bboxes"] = layer_ui_entries(frames) + if state_stale: + ui_dict["compositor_state_stale"] = [True] + return io.NodeOutput(out, mask, ui=ui_dict) + + +class AddLayer(io.ComfyNode): + @classmethod + def define_schema(cls): + return io.Schema( + node_id="AddLayer", + display_name="Add Layer", + category="image", + is_experimental=True, + inputs=[ + io.Layers.Input( + "layers", + optional=True, + tooltip="Layer stack to append to. Leave unconnected to start a new stack.", + ), + io.Image.Input( + "image", + tooltip="Layer content at its native size. A batch expands to consecutive layers.", + ), + io.Mask.Input( + "mask", + optional=True, + tooltip="Transparency mask for this layer. Masked areas (value 1) become transparent, multiplying with any alpha channel the image already carries.", + ), + io.String.Input( + "name", + optional=True, + default="", + tooltip="Layer name shown in the compositor editor.", + ), + io.Int.Input( + "x", + optional=True, + default=0, + min=-MAX_RESOLUTION, + max=MAX_RESOLUTION, + tooltip="Initial horizontal placement on the canvas.", + ), + io.Int.Input( + "y", + optional=True, + default=0, + min=-MAX_RESOLUTION, + max=MAX_RESOLUTION, + tooltip="Initial vertical placement on the canvas.", + ), + io.Float.Input( + "opacity", + optional=True, + default=1.0, + min=0.0, + max=1.0, + step=0.01, + tooltip="Initial layer opacity.", + ), + io.Combo.Input( + "blend_mode", + options=list(_LAYER_MODES), + default="normal", + optional=True, + tooltip="Initial blend mode.", + ), + io.Float.Input( + "rotation", + optional=True, + default=0.0, + min=-360.0, + max=360.0, + step=1.0, + tooltip="Initial rotation in degrees, clockwise.", + ), + io.Int.Input( + "width", + optional=True, + default=0, + min=0, + max=MAX_RESOLUTION, + tooltip="Initial display width. 0 keeps the image's native width.", + ), + io.Int.Input( + "height", + optional=True, + default=0, + min=0, + max=MAX_RESOLUTION, + tooltip="Initial display height. 0 keeps the image's native height.", + ), + io.Int.Input( + "z_index", + optional=True, + default=0, + min=-1000, + max=1000, + tooltip="Stacking override. Layers are stable-sorted by z_index; equal values keep their list order.", + ), + io.Boolean.Input( + "flip_h", + optional=True, + default=False, + tooltip="Flip the layer horizontally.", + ), + io.Boolean.Input( + "flip_v", + optional=True, + default=False, + tooltip="Flip the layer vertically.", + ), + ], + outputs=[ + io.Layers.Output(tooltip="The layer stack with this layer appended."), + ], + ) + + @classmethod + def execute(cls, image: io.Image.Type, layers: io.Layers.Type = None, mask: io.Mask.Type = None, name: str = "", x: int = 0, y: int = 0, opacity: float = 1.0, blend_mode: str = "normal", rotation: float = 0.0, width: int = 0, height: int = 0, z_index: int = 0, flip_h: bool = False, flip_v: bool = False) -> io.NodeOutput: + item: dict = { + "image": image, + "type": "raster", + "x": int(x), + "y": int(y), + "z_index": int(z_index), + } + if mask is not None: + item["mask"] = mask + if name: + item["name"] = name + if opacity != 1.0: + item["opacity"] = float(opacity) + if blend_mode != "normal": + item["blend_mode"] = blend_mode + if rotation != 0.0: + item["rotation"] = math.radians(rotation) + if width > 0: + item["w"] = int(width) + if height > 0: + item["h"] = int(height) + if flip_h: + item["flip_h"] = True + if flip_v: + item["flip_v"] = True + previous = layers if isinstance(layers, dict) else None + document: dict = { + "version": 1, + "layers": [*(previous.get("layers") or []), item] if previous else [item], + } + previous_canvas = document_canvas(previous) + if previous_canvas: + document["canvas"] = previous_canvas + return io.NodeOutput(document) + + +class LayersFromBoundingBoxes(io.ComfyNode): + @classmethod + def define_schema(cls): + return io.Schema( + node_id="LayersFromBoundingBoxes", + display_name="Layers From Bounding Boxes", + category="image", + is_experimental=True, + description=( + "Turn an image batch plus its bounding boxes into a layer stack, one layer per frame, " + "each placed by its own box. Use this when a node emits layers as a batch - a batch " + "carries a single placement for every frame, so the individual positions are otherwise lost." + ), + inputs=[ + io.Image.Input( + "image", + tooltip="Image batch; each frame becomes one layer.", + ), + io.MultiType.Input( + "bboxes", + [io.BoundingBox, io.Array, io.String], + tooltip=( + "Placement boxes, index-aligned with the image batch. Accepts bounding boxes " + "(x, y, width, height), normalized elements (with a 'bbox' - these need " + "canvas_width/canvas_height to resolve to pixels), or a JSON string of either. " + "Frames without a matching box are placed at the origin. A box's width/height " + "scales the layer to fit it. metadata.name (or desc) and metadata.z_index are " + "used when present, and metadata.content_rect (frame-relative) crops the frame " + "to its real content." + ), + ), + io.Mask.Input( + "mask", + optional=True, + tooltip=( + "Per-frame transparency, index-aligned with the image batch " + "(1 = transparent, LoadImage convention)." + ), + ), + io.Layers.Input( + "layers", + optional=True, + tooltip="Layer stack to append to. Leave unconnected to start a new stack.", + ), + io.Boolean.Input( + "crop_to_content", + default=True, + optional=True, + tooltip=( + "Crop each frame to metadata.content_rect where present and place the content " + "at the box position plus the rect offset. Leave on for batches whose frames " + "are padded - it keeps only the real content at its true spot." + ), + ), + io.Int.Input( + "canvas_width", + default=0, + min=0, + max=MAX_RESOLUTION, + optional=True, + tooltip="Document canvas width. 0 derives it from the placed layers.", + ), + io.Int.Input( + "canvas_height", + default=0, + min=0, + max=MAX_RESOLUTION, + optional=True, + tooltip="Document canvas height. 0 derives it from the placed layers.", + ), + ], + outputs=[ + io.Layers.Output(tooltip="The layer stack, ready for Create Layered Image."), + ], + ) + + @classmethod + def execute( + cls, + image: io.Image.Type, + bboxes: io.MultiType.Type, + mask: io.Mask.Type = None, + layers: io.Layers.Type = None, + crop_to_content: bool = True, + canvas_width: int = 0, + canvas_height: int = 0, + ) -> io.NodeOutput: + boxes = _bbox_list(bboxes, canvas_width, canvas_height) + previous = layers if isinstance(layers, dict) else None + items: list[dict] = list((previous.get("layers") or []) if previous else []) + base_z = max((_int(i.get("z_index"), 0) for i in items), default=-1) + 1 + + for index in range(image.shape[0]): + box = boxes[index] if index < len(boxes) else {} + meta = box.get("metadata") if isinstance(box.get("metadata"), dict) else {} + frame = image[index : index + 1] + frame_mask = _item_mask_frame(mask, index) + + x, y = _int(box.get("x"), 0), _int(box.get("y"), 0) + box_w, box_h = _int(box.get("width"), 0), _int(box.get("height"), 0) + cropped = False + rect = meta.get("content_rect") + if crop_to_content and isinstance(rect, (list, tuple)) and len(rect) == 4: + left, top, cw, ch = (_int(v, 0) for v in rect) + left = min(max(left, 0), int(frame.shape[2])) + top = min(max(top, 0), int(frame.shape[1])) + cw = min(max(cw, 0), int(frame.shape[2]) - left) + ch = min(max(ch, 0), int(frame.shape[1]) - top) + if cw > 0 and ch > 0: + frame = frame[:, top : top + ch, left : left + cw] + if frame_mask is not None: + frame_mask = frame_mask[:, top : top + ch, left : left + cw] + x, y = x + left, y + top + cropped = True + + item: dict = { + "image": frame, + "type": "raster", + "x": x, + "y": y, + "z_index": _int(meta.get("z_index"), base_z + index), + } + if not cropped: + if box_w > 0: + item["w"] = box_w + if box_h > 0: + item["h"] = box_h + if frame_mask is not None: + item["mask"] = frame_mask + name = meta.get("name") + if not (isinstance(name, str) and name): + name = meta.get("desc") + if isinstance(name, str) and name: + item["name"] = name + items.append(item) + + document: dict = {"version": 1, "layers": items} + if canvas_width > 0 and canvas_height > 0: + document["canvas"] = (canvas_width, canvas_height) + else: + inherited = document_canvas(previous) + if inherited: + document["canvas"] = inherited + return io.NodeOutput(document) + + +class CompositorExtension(ComfyExtension): + @override + async def get_node_list(self) -> list[type[io.ComfyNode]]: + return [ImageCompositor, AddLayer, LayersFromBoundingBoxes] + + +async def comfy_entrypoint() -> CompositorExtension: + return CompositorExtension() diff --git a/nodes.py b/nodes.py index 08529d8dc..432f04d89 100644 --- a/nodes.py +++ b/nodes.py @@ -2501,6 +2501,7 @@ async def init_builtin_extra_nodes(): "nodes_math.py", "nodes_number_convert.py", "nodes_painter.py", + "nodes_compositor.py", "nodes_curve.py", "nodes_bg_removal.py", "nodes_rtdetr.py", diff --git a/tests-unit/comfy_extras_test/compositor_blend_fixture_gen.py b/tests-unit/comfy_extras_test/compositor_blend_fixture_gen.py new file mode 100644 index 000000000..ea7a110e4 --- /dev/null +++ b/tests-unit/comfy_extras_test/compositor_blend_fixture_gen.py @@ -0,0 +1,111 @@ +"""Regenerate ``compositor_blend_golden.json``. + +The golden file is the *shared contract* for layer blending. Every +implementation of these 26 modes must reproduce it within ``tolerance``: + +* ``comfy_extras/compositor_blend.py`` - numpy, server-side compositing +* ``layerBlend.frag`` - GLSL, the live preview in the layer editor +* any future CPU reference in the frontend + +Run from the repository root:: + + python tests-unit/comfy_extras_test/compositor_blend_fixture_gen.py + +and review the diff. A change to this file is a change to user-visible +blending behaviour in every implementation, so it should never be +regenerated just to make a test pass. +""" + +import json +import os +import sys + +import numpy as np + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..")) + +from comfy_extras.compositor_blend import CHANNEL_BLEND, HSL_BLEND, blend_pixel # noqa: E402 + +GOLDEN_PATH = os.path.join(os.path.dirname(__file__), "compositor_blend_golden.json") + +# Scalar grid for the per-channel modes: both endpoints, the midpoint, values +# just inside each endpoint, and values inside the 1e-6 epsilon guards. +SCALARS = [0.0, 1e-7, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0 - 1e-7, 1.0] + +# Colour pairs for the HSL modes, which read all three channels at once. +COLORS = [ + [0.0, 0.0, 0.0], + [1.0, 1.0, 1.0], + [0.5, 0.5, 0.5], + [1.0, 0.0, 0.0], + [0.0, 0.0, 1.0], + [0.2, 0.4, 0.6], + [0.9, 0.1, 0.35], + [1e-7, 1e-7, 1e-7], + [1e-7, 0.0, 0.0], + [0.05, 0.05, 0.05], +] + + +def _round(value) -> float: + return round(float(value), 7) + + +def build() -> dict: + channel = {} + for mode in CHANNEL_BLEND: + rows = [] + for i in SCALARS: + for l in SCALARS: + out = blend_pixel(mode, np.float32([i] * 3), np.float32([l] * 3)) + rows.append([_round(i), _round(l), _round(np.asarray(out).reshape(3)[0])]) + channel[mode] = rows + hsl = {} + for mode in HSL_BLEND: + rows = [] + for i in COLORS: + for l in COLORS: + out = blend_pixel(mode, np.float32(i), np.float32(l)) + rows.append([ + [_round(v) for v in i], + [_round(v) for v in l], + [_round(v) for v in np.asarray(out).reshape(3)], + ]) + hsl[mode] = rows + return { + "_comment": ( + "Golden blend values shared by comfy_extras/compositor_blend.py and " + "layerBlend.frag. Inputs are unpremultiplied colours already in the " + "blend space; outputs are unclamped (the compositor clamps once, at " + "the end). 'channel' rows are [i, l, out] applied per channel; 'hsl' " + "rows are [rgb_backdrop, rgb_layer, rgb_out]. Regenerate with " + "tests-unit/comfy_extras_test/compositor_blend_fixture_gen.py." + ), + "tolerance": 1e-4, + "channel": channel, + "hsl": hsl, + } + + +def dumps(data: dict) -> str: + """One row per line, so a behaviour change shows up as a readable diff.""" + lines = ["{", f' "_comment": {json.dumps(data["_comment"])},', f' "tolerance": {data["tolerance"]},'] + for section in ("channel", "hsl"): + lines.append(f' "{section}": {{') + modes = sorted(data[section]) + for m_index, mode in enumerate(modes): + lines.append(f' "{mode}": [') + rows = data[section][mode] + for r_index, row in enumerate(rows): + comma = "" if r_index == len(rows) - 1 else "," + lines.append(f" {json.dumps(row)}{comma}") + lines.append(" ]" + ("" if m_index == len(modes) - 1 else ",")) + lines.append(" }" + ("," if section == "channel" else "")) + lines.append("}") + return "\n".join(lines) + "\n" + + +if __name__ == "__main__": + with open(GOLDEN_PATH, "w") as handle: + handle.write(dumps(build())) + sys.stdout.write(f"wrote {GOLDEN_PATH}\n") diff --git a/tests-unit/comfy_extras_test/compositor_blend_golden.json b/tests-unit/comfy_extras_test/compositor_blend_golden.json new file mode 100644 index 000000000..65a06ead7 --- /dev/null +++ b/tests-unit/comfy_extras_test/compositor_blend_golden.json @@ -0,0 +1,2242 @@ +{ + "_comment": "Golden blend values shared by comfy_extras/compositor_blend.py and layerBlend.frag. Inputs are unpremultiplied colours already in the blend space; outputs are unclamped (the compositor clamps once, at the end). 'channel' rows are [i, l, out] applied per channel; 'hsl' rows are [rgb_backdrop, rgb_layer, rgb_out]. Regenerate with tests-unit/comfy_extras_test/compositor_blend_fixture_gen.py.", + "tolerance": 0.0001, + "channel": { + "color-burn": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.0], + [0.0, 0.999, 0.0], + [0.0, 0.9999999, 0.0], + [0.0, 1.0, 0.0], + [1e-07, 0.0, 0.0], + [1e-07, 1e-07, 0.0], + [1e-07, 0.001, 0.0], + [1e-07, 0.25, 0.0], + [1e-07, 0.5, 0.0], + [1e-07, 0.75, 0.0], + [1e-07, 0.999, 0.0], + [1e-07, 0.9999999, 0.0], + [1e-07, 1.0, 1e-07], + [0.001, 0.0, 0.0], + [0.001, 1e-07, 0.0], + [0.001, 0.001, 0.0], + [0.001, 0.25, 0.0], + [0.001, 0.5, 0.0], + [0.001, 0.75, 0.0], + [0.001, 0.999, 0.0], + [0.001, 0.9999999, 0.0009999], + [0.001, 1.0, 0.001], + [0.25, 0.0, 0.0], + [0.25, 1e-07, 0.0], + [0.25, 0.001, 0.0], + [0.25, 0.25, 0.0], + [0.25, 0.5, 0.0], + [0.25, 0.75, 0.0], + [0.25, 0.999, 0.2492493], + [0.25, 0.9999999, 0.2499999], + [0.25, 1.0, 0.25], + [0.5, 0.0, 0.0], + [0.5, 1e-07, 0.0], + [0.5, 0.001, 0.0], + [0.5, 0.25, 0.0], + [0.5, 0.5, 0.0], + [0.5, 0.75, 0.3333333], + [0.5, 0.999, 0.4994995], + [0.5, 0.9999999, 0.4999999], + [0.5, 1.0, 0.5], + [0.75, 0.0, 0.0], + [0.75, 1e-07, 0.0], + [0.75, 0.001, 0.0], + [0.75, 0.25, 0.0], + [0.75, 0.5, 0.5], + [0.75, 0.75, 0.6666666], + [0.75, 0.999, 0.7497498], + [0.75, 0.9999999, 0.75], + [0.75, 1.0, 0.75], + [0.999, 0.0, 0.0], + [0.999, 1e-07, 0.0], + [0.999, 0.001, 1.29e-05], + [0.999, 0.25, 0.9960001], + [0.999, 0.5, 0.998], + [0.999, 0.75, 0.9986667], + [0.999, 0.999, 0.998999], + [0.999, 0.9999999, 0.999], + [0.999, 1.0, 0.999], + [0.9999999, 0.0, 0.0], + [0.9999999, 1e-07, 0.0], + [0.9999999, 0.001, 0.9998808], + [0.9999999, 0.25, 0.9999995], + [0.9999999, 0.5, 0.9999998], + [0.9999999, 0.75, 0.9999998], + [0.9999999, 0.999, 0.9999999], + [0.9999999, 0.9999999, 0.9999999], + [0.9999999, 1.0, 0.9999999], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 1.0], + [1.0, 0.001, 1.0], + [1.0, 0.25, 1.0], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.0], + [1.0, 0.999, 1.0], + [1.0, 0.9999999, 1.0], + [1.0, 1.0, 1.0] + ], + "color-dodge": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.0], + [0.0, 0.999, 0.0], + [0.0, 0.9999999, 0.0], + [0.0, 1.0, 0.0], + [1e-07, 0.0, 1e-07], + [1e-07, 1e-07, 1e-07], + [1e-07, 0.001, 1e-07], + [1e-07, 0.25, 1e-07], + [1e-07, 0.5, 2e-07], + [1e-07, 0.75, 4e-07], + [1e-07, 0.999, 0.0001], + [1e-07, 0.9999999, 1.0], + [1e-07, 1.0, 1.0], + [0.001, 0.0, 0.001], + [0.001, 1e-07, 0.001], + [0.001, 0.001, 0.001001], + [0.001, 0.25, 0.0013333], + [0.001, 0.5, 0.002], + [0.001, 0.75, 0.004], + [0.001, 0.999, 1.0], + [0.001, 0.9999999, 1.0], + [0.001, 1.0, 1.0], + [0.25, 0.0, 0.25], + [0.25, 1e-07, 0.25], + [0.25, 0.001, 0.2502503], + [0.25, 0.25, 0.3333333], + [0.25, 0.5, 0.5], + [0.25, 0.75, 1.0], + [0.25, 0.999, 1.0], + [0.25, 0.9999999, 1.0], + [0.25, 1.0, 1.0], + [0.5, 0.0, 0.5], + [0.5, 1e-07, 0.5000001], + [0.5, 0.001, 0.5005005], + [0.5, 0.25, 0.6666667], + [0.5, 0.5, 1.0], + [0.5, 0.75, 1.0], + [0.5, 0.999, 1.0], + [0.5, 0.9999999, 1.0], + [0.5, 1.0, 1.0], + [0.75, 0.0, 0.75], + [0.75, 1e-07, 0.7500001], + [0.75, 0.001, 0.7507507], + [0.75, 0.25, 1.0], + [0.75, 0.5, 1.0], + [0.75, 0.75, 1.0], + [0.75, 0.999, 1.0], + [0.75, 0.9999999, 1.0], + [0.75, 1.0, 1.0], + [0.999, 0.0, 0.999], + [0.999, 1e-07, 0.9990001], + [0.999, 0.001, 1.0], + [0.999, 0.25, 1.0], + [0.999, 0.5, 1.0], + [0.999, 0.75, 1.0], + [0.999, 0.999, 1.0], + [0.999, 0.9999999, 1.0], + [0.999, 1.0, 1.0], + [0.9999999, 0.0, 0.9999999], + [0.9999999, 1e-07, 1.0], + [0.9999999, 0.001, 1.0], + [0.9999999, 0.25, 1.0], + [0.9999999, 0.5, 1.0], + [0.9999999, 0.75, 1.0], + [0.9999999, 0.999, 1.0], + [0.9999999, 0.9999999, 1.0], + [0.9999999, 1.0, 1.0], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 1.0], + [1.0, 0.001, 1.0], + [1.0, 0.25, 1.0], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.0], + [1.0, 0.999, 1.0], + [1.0, 0.9999999, 1.0], + [1.0, 1.0, 1.0] + ], + "darken": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.0], + [0.0, 0.999, 0.0], + [0.0, 0.9999999, 0.0], + [0.0, 1.0, 0.0], + [1e-07, 0.0, 0.0], + [1e-07, 1e-07, 1e-07], + [1e-07, 0.001, 1e-07], + [1e-07, 0.25, 1e-07], + [1e-07, 0.5, 1e-07], + [1e-07, 0.75, 1e-07], + [1e-07, 0.999, 1e-07], + [1e-07, 0.9999999, 1e-07], + [1e-07, 1.0, 1e-07], + [0.001, 0.0, 0.0], + [0.001, 1e-07, 1e-07], + [0.001, 0.001, 0.001], + [0.001, 0.25, 0.001], + [0.001, 0.5, 0.001], + [0.001, 0.75, 0.001], + [0.001, 0.999, 0.001], + [0.001, 0.9999999, 0.001], + [0.001, 1.0, 0.001], + [0.25, 0.0, 0.0], + [0.25, 1e-07, 1e-07], + [0.25, 0.001, 0.001], + [0.25, 0.25, 0.25], + [0.25, 0.5, 0.25], + [0.25, 0.75, 0.25], + [0.25, 0.999, 0.25], + [0.25, 0.9999999, 0.25], + [0.25, 1.0, 0.25], + [0.5, 0.0, 0.0], + [0.5, 1e-07, 1e-07], + [0.5, 0.001, 0.001], + [0.5, 0.25, 0.25], + [0.5, 0.5, 0.5], + [0.5, 0.75, 0.5], + [0.5, 0.999, 0.5], + [0.5, 0.9999999, 0.5], + [0.5, 1.0, 0.5], + [0.75, 0.0, 0.0], + [0.75, 1e-07, 1e-07], + [0.75, 0.001, 0.001], + [0.75, 0.25, 0.25], + [0.75, 0.5, 0.5], + [0.75, 0.75, 0.75], + [0.75, 0.999, 0.75], + [0.75, 0.9999999, 0.75], + [0.75, 1.0, 0.75], + [0.999, 0.0, 0.0], + [0.999, 1e-07, 1e-07], + [0.999, 0.001, 0.001], + [0.999, 0.25, 0.25], + [0.999, 0.5, 0.5], + [0.999, 0.75, 0.75], + [0.999, 0.999, 0.999], + [0.999, 0.9999999, 0.999], + [0.999, 1.0, 0.999], + [0.9999999, 0.0, 0.0], + [0.9999999, 1e-07, 1e-07], + [0.9999999, 0.001, 0.001], + [0.9999999, 0.25, 0.25], + [0.9999999, 0.5, 0.5], + [0.9999999, 0.75, 0.75], + [0.9999999, 0.999, 0.999], + [0.9999999, 0.9999999, 0.9999999], + [0.9999999, 1.0, 0.9999999], + [1.0, 0.0, 0.0], + [1.0, 1e-07, 1e-07], + [1.0, 0.001, 0.001], + [1.0, 0.25, 0.25], + [1.0, 0.5, 0.5], + [1.0, 0.75, 0.75], + [1.0, 0.999, 0.999], + [1.0, 0.9999999, 0.9999999], + [1.0, 1.0, 1.0] + ], + "difference": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 1e-07], + [0.0, 0.001, 0.001], + [0.0, 0.25, 0.25], + [0.0, 0.5, 0.5], + [0.0, 0.75, 0.75], + [0.0, 0.999, 0.999], + [0.0, 0.9999999, 0.9999999], + [0.0, 1.0, 1.0], + [1e-07, 0.0, 1e-07], + [1e-07, 1e-07, 0.0], + [1e-07, 0.001, 0.0009999], + [1e-07, 0.25, 0.2499999], + [1e-07, 0.5, 0.4999999], + [1e-07, 0.75, 0.7499999], + [1e-07, 0.999, 0.9989999], + [1e-07, 0.9999999, 0.9999998], + [1e-07, 1.0, 0.9999999], + [0.001, 0.0, 0.001], + [0.001, 1e-07, 0.0009999], + [0.001, 0.001, 0.0], + [0.001, 0.25, 0.249], + [0.001, 0.5, 0.499], + [0.001, 0.75, 0.749], + [0.001, 0.999, 0.998], + [0.001, 0.9999999, 0.9989999], + [0.001, 1.0, 0.999], + [0.25, 0.0, 0.25], + [0.25, 1e-07, 0.2499999], + [0.25, 0.001, 0.249], + [0.25, 0.25, 0.0], + [0.25, 0.5, 0.25], + [0.25, 0.75, 0.5], + [0.25, 0.999, 0.749], + [0.25, 0.9999999, 0.7499999], + [0.25, 1.0, 0.75], + [0.5, 0.0, 0.5], + [0.5, 1e-07, 0.4999999], + [0.5, 0.001, 0.499], + [0.5, 0.25, 0.25], + [0.5, 0.5, 0.0], + [0.5, 0.75, 0.25], + [0.5, 0.999, 0.499], + [0.5, 0.9999999, 0.4999999], + [0.5, 1.0, 0.5], + [0.75, 0.0, 0.75], + [0.75, 1e-07, 0.7499999], + [0.75, 0.001, 0.749], + [0.75, 0.25, 0.5], + [0.75, 0.5, 0.25], + [0.75, 0.75, 0.0], + [0.75, 0.999, 0.249], + [0.75, 0.9999999, 0.2499999], + [0.75, 1.0, 0.25], + [0.999, 0.0, 0.999], + [0.999, 1e-07, 0.9989999], + [0.999, 0.001, 0.998], + [0.999, 0.25, 0.749], + [0.999, 0.5, 0.499], + [0.999, 0.75, 0.249], + [0.999, 0.999, 0.0], + [0.999, 0.9999999, 0.0009999], + [0.999, 1.0, 0.001], + [0.9999999, 0.0, 0.9999999], + [0.9999999, 1e-07, 0.9999998], + [0.9999999, 0.001, 0.9989999], + [0.9999999, 0.25, 0.7499999], + [0.9999999, 0.5, 0.4999999], + [0.9999999, 0.75, 0.2499999], + [0.9999999, 0.999, 0.0009999], + [0.9999999, 0.9999999, 0.0], + [0.9999999, 1.0, 1e-07], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 0.9999999], + [1.0, 0.001, 0.999], + [1.0, 0.25, 0.75], + [1.0, 0.5, 0.5], + [1.0, 0.75, 0.25], + [1.0, 0.999, 0.001], + [1.0, 0.9999999, 1e-07], + [1.0, 1.0, 0.0] + ], + "divide": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.0], + [0.0, 0.999, 0.0], + [0.0, 0.9999999, 0.0], + [0.0, 1.0, 0.0], + [1e-07, 0.0, 0.1], + [1e-07, 1e-07, 0.1], + [1e-07, 0.001, 0.0001], + [1e-07, 0.25, 4e-07], + [1e-07, 0.5, 2e-07], + [1e-07, 0.75, 1e-07], + [1e-07, 0.999, 1e-07], + [1e-07, 0.9999999, 1e-07], + [1e-07, 1.0, 1e-07], + [0.001, 0.0, 1.0], + [0.001, 1e-07, 1.0], + [0.001, 0.001, 1.0], + [0.001, 0.25, 0.004], + [0.001, 0.5, 0.002], + [0.001, 0.75, 0.0013333], + [0.001, 0.999, 0.001001], + [0.001, 0.9999999, 0.001], + [0.001, 1.0, 0.001], + [0.25, 0.0, 1.0], + [0.25, 1e-07, 1.0], + [0.25, 0.001, 1.0], + [0.25, 0.25, 1.0], + [0.25, 0.5, 0.5], + [0.25, 0.75, 0.3333333], + [0.25, 0.999, 0.2502503], + [0.25, 0.9999999, 0.25], + [0.25, 1.0, 0.25], + [0.5, 0.0, 1.0], + [0.5, 1e-07, 1.0], + [0.5, 0.001, 1.0], + [0.5, 0.25, 1.0], + [0.5, 0.5, 1.0], + [0.5, 0.75, 0.6666667], + [0.5, 0.999, 0.5005005], + [0.5, 0.9999999, 0.5000001], + [0.5, 1.0, 0.5], + [0.75, 0.0, 1.0], + [0.75, 1e-07, 1.0], + [0.75, 0.001, 1.0], + [0.75, 0.25, 1.0], + [0.75, 0.5, 1.0], + [0.75, 0.75, 1.0], + [0.75, 0.999, 0.7507507], + [0.75, 0.9999999, 0.7500001], + [0.75, 1.0, 0.75], + [0.999, 0.0, 1.0], + [0.999, 1e-07, 1.0], + [0.999, 0.001, 1.0], + [0.999, 0.25, 1.0], + [0.999, 0.5, 1.0], + [0.999, 0.75, 1.0], + [0.999, 0.999, 1.0], + [0.999, 0.9999999, 0.9990001], + [0.999, 1.0, 0.999], + [0.9999999, 0.0, 1.0], + [0.9999999, 1e-07, 1.0], + [0.9999999, 0.001, 1.0], + [0.9999999, 0.25, 1.0], + [0.9999999, 0.5, 1.0], + [0.9999999, 0.75, 1.0], + [0.9999999, 0.999, 1.0], + [0.9999999, 0.9999999, 1.0], + [0.9999999, 1.0, 0.9999999], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 1.0], + [1.0, 0.001, 1.0], + [1.0, 0.25, 1.0], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.0], + [1.0, 0.999, 1.0], + [1.0, 0.9999999, 1.0], + [1.0, 1.0, 1.0] + ], + "exclusion": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 1e-07], + [0.0, 0.001, 0.001], + [0.0, 0.25, 0.25], + [0.0, 0.5, 0.5], + [0.0, 0.75, 0.75], + [0.0, 0.999, 0.999], + [0.0, 0.9999999, 0.9999999], + [0.0, 1.0, 1.0], + [1e-07, 0.0, 1e-07], + [1e-07, 1e-07, 2e-07], + [1e-07, 0.001, 0.0010001], + [1e-07, 0.25, 0.2500001], + [1e-07, 0.5, 0.5], + [1e-07, 0.75, 0.7499999], + [1e-07, 0.999, 0.999], + [1e-07, 0.9999999, 0.9999998], + [1e-07, 1.0, 0.9999999], + [0.001, 0.0, 0.001], + [0.001, 1e-07, 0.0010001], + [0.001, 0.001, 0.001998], + [0.001, 0.25, 0.2505], + [0.001, 0.5, 0.5], + [0.001, 0.75, 0.7495], + [0.001, 0.999, 0.9980021], + [0.001, 0.9999999, 0.9989999], + [0.001, 1.0, 0.999], + [0.25, 0.0, 0.25], + [0.25, 1e-07, 0.2500001], + [0.25, 0.001, 0.2505], + [0.25, 0.25, 0.375], + [0.25, 0.5, 0.5], + [0.25, 0.75, 0.625], + [0.25, 0.999, 0.7495], + [0.25, 0.9999999, 0.7499999], + [0.25, 1.0, 0.75], + [0.5, 0.0, 0.5], + [0.5, 1e-07, 0.5], + [0.5, 0.001, 0.5], + [0.5, 0.25, 0.5], + [0.5, 0.5, 0.5], + [0.5, 0.75, 0.5], + [0.5, 0.999, 0.5], + [0.5, 0.9999999, 0.5], + [0.5, 1.0, 0.5], + [0.75, 0.0, 0.75], + [0.75, 1e-07, 0.7499999], + [0.75, 0.001, 0.7495], + [0.75, 0.25, 0.625], + [0.75, 0.5, 0.5], + [0.75, 0.75, 0.375], + [0.75, 0.999, 0.2505], + [0.75, 0.9999999, 0.2500001], + [0.75, 1.0, 0.25], + [0.999, 0.0, 0.999], + [0.999, 1e-07, 0.999], + [0.999, 0.001, 0.9980021], + [0.999, 0.25, 0.7495], + [0.999, 0.5, 0.5], + [0.999, 0.75, 0.2505], + [0.999, 0.999, 0.001998], + [0.999, 0.9999999, 0.0010001], + [0.999, 1.0, 0.001], + [0.9999999, 0.0, 0.9999999], + [0.9999999, 1e-07, 0.9999998], + [0.9999999, 0.001, 0.9989999], + [0.9999999, 0.25, 0.7499999], + [0.9999999, 0.5, 0.5], + [0.9999999, 0.75, 0.2500001], + [0.9999999, 0.999, 0.0010001], + [0.9999999, 0.9999999, 2e-07], + [0.9999999, 1.0, 1e-07], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 0.9999999], + [1.0, 0.001, 0.999], + [1.0, 0.25, 0.75], + [1.0, 0.5, 0.5], + [1.0, 0.75, 0.25], + [1.0, 0.999, 0.001], + [1.0, 0.9999999, 1e-07], + [1.0, 1.0, 0.0] + ], + "grain-extract": [ + [0.0, 0.0, 0.5], + [0.0, 1e-07, 0.4999999], + [0.0, 0.001, 0.499], + [0.0, 0.25, 0.25], + [0.0, 0.5, 0.0], + [0.0, 0.75, -0.25], + [0.0, 0.999, -0.499], + [0.0, 0.9999999, -0.4999999], + [0.0, 1.0, -0.5], + [1e-07, 0.0, 0.5000001], + [1e-07, 1e-07, 0.5], + [1e-07, 0.001, 0.4990001], + [1e-07, 0.25, 0.2500001], + [1e-07, 0.5, 1e-07], + [1e-07, 0.75, -0.2499999], + [1e-07, 0.999, -0.4989999], + [1e-07, 0.9999999, -0.4999998], + [1e-07, 1.0, -0.4999999], + [0.001, 0.0, 0.501], + [0.001, 1e-07, 0.5009999], + [0.001, 0.001, 0.5], + [0.001, 0.25, 0.251], + [0.001, 0.5, 0.001], + [0.001, 0.75, -0.249], + [0.001, 0.999, -0.498], + [0.001, 0.9999999, -0.4989999], + [0.001, 1.0, -0.499], + [0.25, 0.0, 0.75], + [0.25, 1e-07, 0.7499999], + [0.25, 0.001, 0.749], + [0.25, 0.25, 0.5], + [0.25, 0.5, 0.25], + [0.25, 0.75, 0.0], + [0.25, 0.999, -0.249], + [0.25, 0.9999999, -0.2499999], + [0.25, 1.0, -0.25], + [0.5, 0.0, 1.0], + [0.5, 1e-07, 0.9999999], + [0.5, 0.001, 0.999], + [0.5, 0.25, 0.75], + [0.5, 0.5, 0.5], + [0.5, 0.75, 0.25], + [0.5, 0.999, 0.001], + [0.5, 0.9999999, 1e-07], + [0.5, 1.0, 0.0], + [0.75, 0.0, 1.25], + [0.75, 1e-07, 1.2499999], + [0.75, 0.001, 1.2490001], + [0.75, 0.25, 1.0], + [0.75, 0.5, 0.75], + [0.75, 0.75, 0.5], + [0.75, 0.999, 0.251], + [0.75, 0.9999999, 0.2500001], + [0.75, 1.0, 0.25], + [0.999, 0.0, 1.4990001], + [0.999, 1e-07, 1.4989998], + [0.999, 0.001, 1.498], + [0.999, 0.25, 1.2490001], + [0.999, 0.5, 0.999], + [0.999, 0.75, 0.749], + [0.999, 0.999, 0.5], + [0.999, 0.9999999, 0.4990001], + [0.999, 1.0, 0.499], + [0.9999999, 0.0, 1.4999999], + [0.9999999, 1e-07, 1.4999998], + [0.9999999, 0.001, 1.4989998], + [0.9999999, 0.25, 1.2499999], + [0.9999999, 0.5, 0.9999999], + [0.9999999, 0.75, 0.7499999], + [0.9999999, 0.999, 0.5009999], + [0.9999999, 0.9999999, 0.5], + [0.9999999, 1.0, 0.4999999], + [1.0, 0.0, 1.5], + [1.0, 1e-07, 1.4999999], + [1.0, 0.001, 1.4990001], + [1.0, 0.25, 1.25], + [1.0, 0.5, 1.0], + [1.0, 0.75, 0.75], + [1.0, 0.999, 0.501], + [1.0, 0.9999999, 0.5000001], + [1.0, 1.0, 0.5] + ], + "grain-merge": [ + [0.0, 0.0, -0.5], + [0.0, 1e-07, -0.4999999], + [0.0, 0.001, -0.499], + [0.0, 0.25, -0.25], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.25], + [0.0, 0.999, 0.499], + [0.0, 0.9999999, 0.4999999], + [0.0, 1.0, 0.5], + [1e-07, 0.0, -0.4999999], + [1e-07, 1e-07, -0.4999998], + [1e-07, 0.001, -0.4989999], + [1e-07, 0.25, -0.2499999], + [1e-07, 0.5, 1e-07], + [1e-07, 0.75, 0.2500001], + [1e-07, 0.999, 0.4990001], + [1e-07, 0.9999999, 0.5], + [1e-07, 1.0, 0.5000001], + [0.001, 0.0, -0.499], + [0.001, 1e-07, -0.4989999], + [0.001, 0.001, -0.498], + [0.001, 0.25, -0.249], + [0.001, 0.5, 0.001], + [0.001, 0.75, 0.251], + [0.001, 0.999, 0.5], + [0.001, 0.9999999, 0.5009999], + [0.001, 1.0, 0.501], + [0.25, 0.0, -0.25], + [0.25, 1e-07, -0.2499999], + [0.25, 0.001, -0.249], + [0.25, 0.25, 0.0], + [0.25, 0.5, 0.25], + [0.25, 0.75, 0.5], + [0.25, 0.999, 0.7490001], + [0.25, 0.9999999, 0.7499999], + [0.25, 1.0, 0.75], + [0.5, 0.0, 0.0], + [0.5, 1e-07, 1e-07], + [0.5, 0.001, 0.001], + [0.5, 0.25, 0.25], + [0.5, 0.5, 0.5], + [0.5, 0.75, 0.75], + [0.5, 0.999, 0.9990001], + [0.5, 0.9999999, 0.9999999], + [0.5, 1.0, 1.0], + [0.75, 0.0, 0.25], + [0.75, 1e-07, 0.2500001], + [0.75, 0.001, 0.251], + [0.75, 0.25, 0.5], + [0.75, 0.5, 0.75], + [0.75, 0.75, 1.0], + [0.75, 0.999, 1.2490001], + [0.75, 0.9999999, 1.2499999], + [0.75, 1.0, 1.25], + [0.999, 0.0, 0.499], + [0.999, 1e-07, 0.4990001], + [0.999, 0.001, 0.5], + [0.999, 0.25, 0.7490001], + [0.999, 0.5, 0.9990001], + [0.999, 0.75, 1.2490001], + [0.999, 0.999, 1.498], + [0.999, 0.9999999, 1.4989998], + [0.999, 1.0, 1.4990001], + [0.9999999, 0.0, 0.4999999], + [0.9999999, 1e-07, 0.5], + [0.9999999, 0.001, 0.5009999], + [0.9999999, 0.25, 0.7499999], + [0.9999999, 0.5, 0.9999999], + [0.9999999, 0.75, 1.2499999], + [0.9999999, 0.999, 1.4989998], + [0.9999999, 0.9999999, 1.4999998], + [0.9999999, 1.0, 1.4999999], + [1.0, 0.0, 0.5], + [1.0, 1e-07, 0.5000001], + [1.0, 0.001, 0.501], + [1.0, 0.25, 0.75], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.25], + [1.0, 0.999, 1.4990001], + [1.0, 0.9999999, 1.4999999], + [1.0, 1.0, 1.5] + ], + "hard-light": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.5], + [0.0, 0.999, 0.998], + [0.0, 0.9999999, 0.9999998], + [0.0, 1.0, 1.0], + [1e-07, 0.0, 0.0], + [1e-07, 1e-07, 0.0], + [1e-07, 0.001, 0.0], + [1e-07, 0.25, 1e-07], + [1e-07, 0.5, 1e-07], + [1e-07, 0.75, 0.5000001], + [1e-07, 0.999, 0.998], + [1e-07, 0.9999999, 0.9999998], + [1e-07, 1.0, 1.0], + [0.001, 0.0, 0.0], + [0.001, 1e-07, 0.0], + [0.001, 0.001, 2e-06], + [0.001, 0.25, 0.0005], + [0.001, 0.5, 0.001], + [0.001, 0.75, 0.5005], + [0.001, 0.999, 0.9980021], + [0.001, 0.9999999, 0.9999998], + [0.001, 1.0, 1.0], + [0.25, 0.0, 0.0], + [0.25, 1e-07, 1e-07], + [0.25, 0.001, 0.0005], + [0.25, 0.25, 0.125], + [0.25, 0.5, 0.25], + [0.25, 0.75, 0.625], + [0.25, 0.999, 0.9985], + [0.25, 0.9999999, 0.9999998], + [0.25, 1.0, 1.0], + [0.5, 0.0, 0.0], + [0.5, 1e-07, 1e-07], + [0.5, 0.001, 0.001], + [0.5, 0.25, 0.25], + [0.5, 0.5, 0.5], + [0.5, 0.75, 0.75], + [0.5, 0.999, 0.999], + [0.5, 0.9999999, 0.9999999], + [0.5, 1.0, 1.0], + [0.75, 0.0, 0.0], + [0.75, 1e-07, 2e-07], + [0.75, 0.001, 0.0015], + [0.75, 0.25, 0.375], + [0.75, 0.5, 0.75], + [0.75, 0.75, 0.875], + [0.75, 0.999, 0.9995], + [0.75, 0.9999999, 0.9999999], + [0.75, 1.0, 1.0], + [0.999, 0.0, 0.0], + [0.999, 1e-07, 2e-07], + [0.999, 0.001, 0.001998], + [0.999, 0.25, 0.4995], + [0.999, 0.5, 0.999], + [0.999, 0.75, 0.9995], + [0.999, 0.999, 0.999998], + [0.999, 0.9999999, 1.0], + [0.999, 1.0, 1.0], + [0.9999999, 0.0, 0.0], + [0.9999999, 1e-07, 2e-07], + [0.9999999, 0.001, 0.002], + [0.9999999, 0.25, 0.4999999], + [0.9999999, 0.5, 0.9999999], + [0.9999999, 0.75, 0.9999999], + [0.9999999, 0.999, 1.0], + [0.9999999, 0.9999999, 1.0], + [0.9999999, 1.0, 1.0], + [1.0, 0.0, 0.0], + [1.0, 1e-07, 2e-07], + [1.0, 0.001, 0.002], + [1.0, 0.25, 0.5], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.0], + [1.0, 0.999, 1.0], + [1.0, 0.9999999, 1.0], + [1.0, 1.0, 1.0] + ], + "hard-mix": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.0], + [0.0, 0.999, 0.0], + [0.0, 0.9999999, 0.0], + [0.0, 1.0, 1.0], + [1e-07, 0.0, 0.0], + [1e-07, 1e-07, 0.0], + [1e-07, 0.001, 0.0], + [1e-07, 0.25, 0.0], + [1e-07, 0.5, 0.0], + [1e-07, 0.75, 0.0], + [1e-07, 0.999, 0.0], + [1e-07, 0.9999999, 1.0], + [1e-07, 1.0, 1.0], + [0.001, 0.0, 0.0], + [0.001, 1e-07, 0.0], + [0.001, 0.001, 0.0], + [0.001, 0.25, 0.0], + [0.001, 0.5, 0.0], + [0.001, 0.75, 0.0], + [0.001, 0.999, 1.0], + [0.001, 0.9999999, 1.0], + [0.001, 1.0, 1.0], + [0.25, 0.0, 0.0], + [0.25, 1e-07, 0.0], + [0.25, 0.001, 0.0], + [0.25, 0.25, 0.0], + [0.25, 0.5, 0.0], + [0.25, 0.75, 1.0], + [0.25, 0.999, 1.0], + [0.25, 0.9999999, 1.0], + [0.25, 1.0, 1.0], + [0.5, 0.0, 0.0], + [0.5, 1e-07, 0.0], + [0.5, 0.001, 0.0], + [0.5, 0.25, 0.0], + [0.5, 0.5, 1.0], + [0.5, 0.75, 1.0], + [0.5, 0.999, 1.0], + [0.5, 0.9999999, 1.0], + [0.5, 1.0, 1.0], + [0.75, 0.0, 0.0], + [0.75, 1e-07, 0.0], + [0.75, 0.001, 0.0], + [0.75, 0.25, 1.0], + [0.75, 0.5, 1.0], + [0.75, 0.75, 1.0], + [0.75, 0.999, 1.0], + [0.75, 0.9999999, 1.0], + [0.75, 1.0, 1.0], + [0.999, 0.0, 0.0], + [0.999, 1e-07, 0.0], + [0.999, 0.001, 1.0], + [0.999, 0.25, 1.0], + [0.999, 0.5, 1.0], + [0.999, 0.75, 1.0], + [0.999, 0.999, 1.0], + [0.999, 0.9999999, 1.0], + [0.999, 1.0, 1.0], + [0.9999999, 0.0, 0.0], + [0.9999999, 1e-07, 1.0], + [0.9999999, 0.001, 1.0], + [0.9999999, 0.25, 1.0], + [0.9999999, 0.5, 1.0], + [0.9999999, 0.75, 1.0], + [0.9999999, 0.999, 1.0], + [0.9999999, 0.9999999, 1.0], + [0.9999999, 1.0, 1.0], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 1.0], + [1.0, 0.001, 1.0], + [1.0, 0.25, 1.0], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.0], + [1.0, 0.999, 1.0], + [1.0, 0.9999999, 1.0], + [1.0, 1.0, 1.0] + ], + "lighten": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 1e-07], + [0.0, 0.001, 0.001], + [0.0, 0.25, 0.25], + [0.0, 0.5, 0.5], + [0.0, 0.75, 0.75], + [0.0, 0.999, 0.999], + [0.0, 0.9999999, 0.9999999], + [0.0, 1.0, 1.0], + [1e-07, 0.0, 1e-07], + [1e-07, 1e-07, 1e-07], + [1e-07, 0.001, 0.001], + [1e-07, 0.25, 0.25], + [1e-07, 0.5, 0.5], + [1e-07, 0.75, 0.75], + [1e-07, 0.999, 0.999], + [1e-07, 0.9999999, 0.9999999], + [1e-07, 1.0, 1.0], + [0.001, 0.0, 0.001], + [0.001, 1e-07, 0.001], + [0.001, 0.001, 0.001], + [0.001, 0.25, 0.25], + [0.001, 0.5, 0.5], + [0.001, 0.75, 0.75], + [0.001, 0.999, 0.999], + [0.001, 0.9999999, 0.9999999], + [0.001, 1.0, 1.0], + [0.25, 0.0, 0.25], + [0.25, 1e-07, 0.25], + [0.25, 0.001, 0.25], + [0.25, 0.25, 0.25], + [0.25, 0.5, 0.5], + [0.25, 0.75, 0.75], + [0.25, 0.999, 0.999], + [0.25, 0.9999999, 0.9999999], + [0.25, 1.0, 1.0], + [0.5, 0.0, 0.5], + [0.5, 1e-07, 0.5], + [0.5, 0.001, 0.5], + [0.5, 0.25, 0.5], + [0.5, 0.5, 0.5], + [0.5, 0.75, 0.75], + [0.5, 0.999, 0.999], + [0.5, 0.9999999, 0.9999999], + [0.5, 1.0, 1.0], + [0.75, 0.0, 0.75], + [0.75, 1e-07, 0.75], + [0.75, 0.001, 0.75], + [0.75, 0.25, 0.75], + [0.75, 0.5, 0.75], + [0.75, 0.75, 0.75], + [0.75, 0.999, 0.999], + [0.75, 0.9999999, 0.9999999], + [0.75, 1.0, 1.0], + [0.999, 0.0, 0.999], + [0.999, 1e-07, 0.999], + [0.999, 0.001, 0.999], + [0.999, 0.25, 0.999], + [0.999, 0.5, 0.999], + [0.999, 0.75, 0.999], + [0.999, 0.999, 0.999], + [0.999, 0.9999999, 0.9999999], + [0.999, 1.0, 1.0], + [0.9999999, 0.0, 0.9999999], + [0.9999999, 1e-07, 0.9999999], + [0.9999999, 0.001, 0.9999999], + [0.9999999, 0.25, 0.9999999], + [0.9999999, 0.5, 0.9999999], + [0.9999999, 0.75, 0.9999999], + [0.9999999, 0.999, 0.9999999], + [0.9999999, 0.9999999, 0.9999999], + [0.9999999, 1.0, 1.0], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 1.0], + [1.0, 0.001, 1.0], + [1.0, 0.25, 1.0], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.0], + [1.0, 0.999, 1.0], + [1.0, 0.9999999, 1.0], + [1.0, 1.0, 1.0] + ], + "linear-burn": [ + [0.0, 0.0, -1.0], + [0.0, 1e-07, -0.9999999], + [0.0, 0.001, -0.999], + [0.0, 0.25, -0.75], + [0.0, 0.5, -0.5], + [0.0, 0.75, -0.25], + [0.0, 0.999, -0.001], + [0.0, 0.9999999, -1e-07], + [0.0, 1.0, 0.0], + [1e-07, 0.0, -0.9999999], + [1e-07, 1e-07, -0.9999998], + [1e-07, 0.001, -0.9989999], + [1e-07, 0.25, -0.7499999], + [1e-07, 0.5, -0.4999999], + [1e-07, 0.75, -0.2499999], + [1e-07, 0.999, -0.0009999], + [1e-07, 0.9999999, 0.0], + [1e-07, 1.0, 1e-07], + [0.001, 0.0, -0.999], + [0.001, 1e-07, -0.9989999], + [0.001, 0.001, -0.998], + [0.001, 0.25, -0.749], + [0.001, 0.5, -0.499], + [0.001, 0.75, -0.249], + [0.001, 0.999, 0.0], + [0.001, 0.9999999, 0.0009999], + [0.001, 1.0, 0.001], + [0.25, 0.0, -0.75], + [0.25, 1e-07, -0.7499999], + [0.25, 0.001, -0.749], + [0.25, 0.25, -0.5], + [0.25, 0.5, -0.25], + [0.25, 0.75, 0.0], + [0.25, 0.999, 0.2490001], + [0.25, 0.9999999, 0.2499999], + [0.25, 1.0, 0.25], + [0.5, 0.0, -0.5], + [0.5, 1e-07, -0.4999999], + [0.5, 0.001, -0.499], + [0.5, 0.25, -0.25], + [0.5, 0.5, 0.0], + [0.5, 0.75, 0.25], + [0.5, 0.999, 0.4990001], + [0.5, 0.9999999, 0.4999999], + [0.5, 1.0, 0.5], + [0.75, 0.0, -0.25], + [0.75, 1e-07, -0.2499999], + [0.75, 0.001, -0.249], + [0.75, 0.25, 0.0], + [0.75, 0.5, 0.25], + [0.75, 0.75, 0.5], + [0.75, 0.999, 0.7490001], + [0.75, 0.9999999, 0.7499999], + [0.75, 1.0, 0.75], + [0.999, 0.0, -0.001], + [0.999, 1e-07, -0.0009999], + [0.999, 0.001, 0.0], + [0.999, 0.25, 0.2490001], + [0.999, 0.5, 0.4990001], + [0.999, 0.75, 0.7490001], + [0.999, 0.999, 0.998], + [0.999, 0.9999999, 0.9989998], + [0.999, 1.0, 0.9990001], + [0.9999999, 0.0, -1e-07], + [0.9999999, 1e-07, 0.0], + [0.9999999, 0.001, 0.0009999], + [0.9999999, 0.25, 0.2499999], + [0.9999999, 0.5, 0.4999999], + [0.9999999, 0.75, 0.7499999], + [0.9999999, 0.999, 0.9989998], + [0.9999999, 0.9999999, 0.9999998], + [0.9999999, 1.0, 0.9999999], + [1.0, 0.0, 0.0], + [1.0, 1e-07, 1e-07], + [1.0, 0.001, 0.001], + [1.0, 0.25, 0.25], + [1.0, 0.5, 0.5], + [1.0, 0.75, 0.75], + [1.0, 0.999, 0.9990001], + [1.0, 0.9999999, 0.9999999], + [1.0, 1.0, 1.0] + ], + "linear-dodge": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 1e-07], + [0.0, 0.001, 0.001], + [0.0, 0.25, 0.25], + [0.0, 0.5, 0.5], + [0.0, 0.75, 0.75], + [0.0, 0.999, 0.999], + [0.0, 0.9999999, 0.9999999], + [0.0, 1.0, 1.0], + [1e-07, 0.0, 1e-07], + [1e-07, 1e-07, 2e-07], + [1e-07, 0.001, 0.0010001], + [1e-07, 0.25, 0.2500001], + [1e-07, 0.5, 0.5000001], + [1e-07, 0.75, 0.7500001], + [1e-07, 0.999, 0.9990001], + [1e-07, 0.9999999, 1.0], + [1e-07, 1.0, 1.0000001], + [0.001, 0.0, 0.001], + [0.001, 1e-07, 0.0010001], + [0.001, 0.001, 0.002], + [0.001, 0.25, 0.251], + [0.001, 0.5, 0.501], + [0.001, 0.75, 0.751], + [0.001, 0.999, 1.0], + [0.001, 0.9999999, 1.0009999], + [0.001, 1.0, 1.001], + [0.25, 0.0, 0.25], + [0.25, 1e-07, 0.2500001], + [0.25, 0.001, 0.251], + [0.25, 0.25, 0.5], + [0.25, 0.5, 0.75], + [0.25, 0.75, 1.0], + [0.25, 0.999, 1.2490001], + [0.25, 0.9999999, 1.2499999], + [0.25, 1.0, 1.25], + [0.5, 0.0, 0.5], + [0.5, 1e-07, 0.5000001], + [0.5, 0.001, 0.501], + [0.5, 0.25, 0.75], + [0.5, 0.5, 1.0], + [0.5, 0.75, 1.25], + [0.5, 0.999, 1.4990001], + [0.5, 0.9999999, 1.4999999], + [0.5, 1.0, 1.5], + [0.75, 0.0, 0.75], + [0.75, 1e-07, 0.7500001], + [0.75, 0.001, 0.751], + [0.75, 0.25, 1.0], + [0.75, 0.5, 1.25], + [0.75, 0.75, 1.5], + [0.75, 0.999, 1.7490001], + [0.75, 0.9999999, 1.7499999], + [0.75, 1.0, 1.75], + [0.999, 0.0, 0.999], + [0.999, 1e-07, 0.9990001], + [0.999, 0.001, 1.0], + [0.999, 0.25, 1.2490001], + [0.999, 0.5, 1.4990001], + [0.999, 0.75, 1.7490001], + [0.999, 0.999, 1.998], + [0.999, 0.9999999, 1.9989998], + [0.999, 1.0, 1.9990001], + [0.9999999, 0.0, 0.9999999], + [0.9999999, 1e-07, 1.0], + [0.9999999, 0.001, 1.0009999], + [0.9999999, 0.25, 1.2499999], + [0.9999999, 0.5, 1.4999999], + [0.9999999, 0.75, 1.7499999], + [0.9999999, 0.999, 1.9989998], + [0.9999999, 0.9999999, 1.9999998], + [0.9999999, 1.0, 1.9999999], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 1.0000001], + [1.0, 0.001, 1.001], + [1.0, 0.25, 1.25], + [1.0, 0.5, 1.5], + [1.0, 0.75, 1.75], + [1.0, 0.999, 1.9990001], + [1.0, 0.9999999, 1.9999999], + [1.0, 1.0, 2.0] + ], + "linear-light": [ + [0.0, 0.0, -1.0], + [0.0, 1e-07, -0.9999998], + [0.0, 0.001, -0.998], + [0.0, 0.25, -0.5], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.5], + [0.0, 0.999, 0.998], + [0.0, 0.9999999, 0.9999998], + [0.0, 1.0, 1.0], + [1e-07, 0.0, -0.9999999], + [1e-07, 1e-07, -0.9999997], + [1e-07, 0.001, -0.9979999], + [1e-07, 0.25, -0.4999999], + [1e-07, 0.5, 1e-07], + [1e-07, 0.75, 0.5000001], + [1e-07, 0.999, 0.9980001], + [1e-07, 0.9999999, 0.9999999], + [1e-07, 1.0, 1.0], + [0.001, 0.0, -0.999], + [0.001, 1e-07, -0.9989998], + [0.001, 0.001, -0.997], + [0.001, 0.25, -0.499], + [0.001, 0.5, 0.001], + [0.001, 0.75, 0.501], + [0.001, 0.999, 0.9990001], + [0.001, 0.9999999, 1.0009997], + [0.001, 1.0, 1.0009999], + [0.25, 0.0, -0.75], + [0.25, 1e-07, -0.7499998], + [0.25, 0.001, -0.748], + [0.25, 0.25, -0.25], + [0.25, 0.5, 0.25], + [0.25, 0.75, 0.75], + [0.25, 0.999, 1.2480001], + [0.25, 0.9999999, 1.2499998], + [0.25, 1.0, 1.25], + [0.5, 0.0, -0.5], + [0.5, 1e-07, -0.4999998], + [0.5, 0.001, -0.498], + [0.5, 0.25, 0.0], + [0.5, 0.5, 0.5], + [0.5, 0.75, 1.0], + [0.5, 0.999, 1.4980001], + [0.5, 0.9999999, 1.4999998], + [0.5, 1.0, 1.5], + [0.75, 0.0, -0.25], + [0.75, 1e-07, -0.2499998], + [0.75, 0.001, -0.248], + [0.75, 0.25, 0.25], + [0.75, 0.5, 0.75], + [0.75, 0.75, 1.25], + [0.75, 0.999, 1.7480001], + [0.75, 0.9999999, 1.7499998], + [0.75, 1.0, 1.75], + [0.999, 0.0, -0.001], + [0.999, 1e-07, -0.0009998], + [0.999, 0.001, 0.001], + [0.999, 0.25, 0.4990001], + [0.999, 0.5, 0.9990001], + [0.999, 0.75, 1.4990001], + [0.999, 0.999, 1.997], + [0.999, 0.9999999, 1.9989998], + [0.999, 1.0, 1.9990001], + [0.9999999, 0.0, -1e-07], + [0.9999999, 1e-07, 1e-07], + [0.9999999, 0.001, 0.0019999], + [0.9999999, 0.25, 0.4999999], + [0.9999999, 0.5, 0.9999999], + [0.9999999, 0.75, 1.5], + [0.9999999, 0.999, 1.9979999], + [0.9999999, 0.9999999, 1.9999995], + [0.9999999, 1.0, 2.0], + [1.0, 0.0, 0.0], + [1.0, 1e-07, 2e-07], + [1.0, 0.001, 0.002], + [1.0, 0.25, 0.5], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.5], + [1.0, 0.999, 1.9980001], + [1.0, 0.9999999, 1.9999998], + [1.0, 1.0, 2.0] + ], + "multiply": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.0], + [0.0, 0.999, 0.0], + [0.0, 0.9999999, 0.0], + [0.0, 1.0, 0.0], + [1e-07, 0.0, 0.0], + [1e-07, 1e-07, 0.0], + [1e-07, 0.001, 0.0], + [1e-07, 0.25, 0.0], + [1e-07, 0.5, 1e-07], + [1e-07, 0.75, 1e-07], + [1e-07, 0.999, 1e-07], + [1e-07, 0.9999999, 1e-07], + [1e-07, 1.0, 1e-07], + [0.001, 0.0, 0.0], + [0.001, 1e-07, 0.0], + [0.001, 0.001, 1e-06], + [0.001, 0.25, 0.00025], + [0.001, 0.5, 0.0005], + [0.001, 0.75, 0.00075], + [0.001, 0.999, 0.000999], + [0.001, 0.9999999, 0.001], + [0.001, 1.0, 0.001], + [0.25, 0.0, 0.0], + [0.25, 1e-07, 0.0], + [0.25, 0.001, 0.00025], + [0.25, 0.25, 0.0625], + [0.25, 0.5, 0.125], + [0.25, 0.75, 0.1875], + [0.25, 0.999, 0.24975], + [0.25, 0.9999999, 0.25], + [0.25, 1.0, 0.25], + [0.5, 0.0, 0.0], + [0.5, 1e-07, 1e-07], + [0.5, 0.001, 0.0005], + [0.5, 0.25, 0.125], + [0.5, 0.5, 0.25], + [0.5, 0.75, 0.375], + [0.5, 0.999, 0.4995], + [0.5, 0.9999999, 0.4999999], + [0.5, 1.0, 0.5], + [0.75, 0.0, 0.0], + [0.75, 1e-07, 1e-07], + [0.75, 0.001, 0.00075], + [0.75, 0.25, 0.1875], + [0.75, 0.5, 0.375], + [0.75, 0.75, 0.5625], + [0.75, 0.999, 0.74925], + [0.75, 0.9999999, 0.7499999], + [0.75, 1.0, 0.75], + [0.999, 0.0, 0.0], + [0.999, 1e-07, 1e-07], + [0.999, 0.001, 0.000999], + [0.999, 0.25, 0.24975], + [0.999, 0.5, 0.4995], + [0.999, 0.75, 0.74925], + [0.999, 0.999, 0.998001], + [0.999, 0.9999999, 0.9989999], + [0.999, 1.0, 0.999], + [0.9999999, 0.0, 0.0], + [0.9999999, 1e-07, 1e-07], + [0.9999999, 0.001, 0.001], + [0.9999999, 0.25, 0.25], + [0.9999999, 0.5, 0.4999999], + [0.9999999, 0.75, 0.7499999], + [0.9999999, 0.999, 0.9989999], + [0.9999999, 0.9999999, 0.9999998], + [0.9999999, 1.0, 0.9999999], + [1.0, 0.0, 0.0], + [1.0, 1e-07, 1e-07], + [1.0, 0.001, 0.001], + [1.0, 0.25, 0.25], + [1.0, 0.5, 0.5], + [1.0, 0.75, 0.75], + [1.0, 0.999, 0.999], + [1.0, 0.9999999, 0.9999999], + [1.0, 1.0, 1.0] + ], + "normal": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 1e-07], + [0.0, 0.001, 0.001], + [0.0, 0.25, 0.25], + [0.0, 0.5, 0.5], + [0.0, 0.75, 0.75], + [0.0, 0.999, 0.999], + [0.0, 0.9999999, 0.9999999], + [0.0, 1.0, 1.0], + [1e-07, 0.0, 0.0], + [1e-07, 1e-07, 1e-07], + [1e-07, 0.001, 0.001], + [1e-07, 0.25, 0.25], + [1e-07, 0.5, 0.5], + [1e-07, 0.75, 0.75], + [1e-07, 0.999, 0.999], + [1e-07, 0.9999999, 0.9999999], + [1e-07, 1.0, 1.0], + [0.001, 0.0, 0.0], + [0.001, 1e-07, 1e-07], + [0.001, 0.001, 0.001], + [0.001, 0.25, 0.25], + [0.001, 0.5, 0.5], + [0.001, 0.75, 0.75], + [0.001, 0.999, 0.999], + [0.001, 0.9999999, 0.9999999], + [0.001, 1.0, 1.0], + [0.25, 0.0, 0.0], + [0.25, 1e-07, 1e-07], + [0.25, 0.001, 0.001], + [0.25, 0.25, 0.25], + [0.25, 0.5, 0.5], + [0.25, 0.75, 0.75], + [0.25, 0.999, 0.999], + [0.25, 0.9999999, 0.9999999], + [0.25, 1.0, 1.0], + [0.5, 0.0, 0.0], + [0.5, 1e-07, 1e-07], + [0.5, 0.001, 0.001], + [0.5, 0.25, 0.25], + [0.5, 0.5, 0.5], + [0.5, 0.75, 0.75], + [0.5, 0.999, 0.999], + [0.5, 0.9999999, 0.9999999], + [0.5, 1.0, 1.0], + [0.75, 0.0, 0.0], + [0.75, 1e-07, 1e-07], + [0.75, 0.001, 0.001], + [0.75, 0.25, 0.25], + [0.75, 0.5, 0.5], + [0.75, 0.75, 0.75], + [0.75, 0.999, 0.999], + [0.75, 0.9999999, 0.9999999], + [0.75, 1.0, 1.0], + [0.999, 0.0, 0.0], + [0.999, 1e-07, 1e-07], + [0.999, 0.001, 0.001], + [0.999, 0.25, 0.25], + [0.999, 0.5, 0.5], + [0.999, 0.75, 0.75], + [0.999, 0.999, 0.999], + [0.999, 0.9999999, 0.9999999], + [0.999, 1.0, 1.0], + [0.9999999, 0.0, 0.0], + [0.9999999, 1e-07, 1e-07], + [0.9999999, 0.001, 0.001], + [0.9999999, 0.25, 0.25], + [0.9999999, 0.5, 0.5], + [0.9999999, 0.75, 0.75], + [0.9999999, 0.999, 0.999], + [0.9999999, 0.9999999, 0.9999999], + [0.9999999, 1.0, 1.0], + [1.0, 0.0, 0.0], + [1.0, 1e-07, 1e-07], + [1.0, 0.001, 0.001], + [1.0, 0.25, 0.25], + [1.0, 0.5, 0.5], + [1.0, 0.75, 0.75], + [1.0, 0.999, 0.999], + [1.0, 0.9999999, 0.9999999], + [1.0, 1.0, 1.0] + ], + "overlay": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.0], + [0.0, 0.999, 0.0], + [0.0, 0.9999999, 0.0], + [0.0, 1.0, 0.0], + [1e-07, 0.0, 0.0], + [1e-07, 1e-07, 0.0], + [1e-07, 0.001, 0.0], + [1e-07, 0.25, 1e-07], + [1e-07, 0.5, 1e-07], + [1e-07, 0.75, 2e-07], + [1e-07, 0.999, 2e-07], + [1e-07, 0.9999999, 2e-07], + [1e-07, 1.0, 2e-07], + [0.001, 0.0, 0.0], + [0.001, 1e-07, 0.0], + [0.001, 0.001, 2e-06], + [0.001, 0.25, 0.0005], + [0.001, 0.5, 0.001], + [0.001, 0.75, 0.0015], + [0.001, 0.999, 0.001998], + [0.001, 0.9999999, 0.002], + [0.001, 1.0, 0.002], + [0.25, 0.0, 0.0], + [0.25, 1e-07, 1e-07], + [0.25, 0.001, 0.0005], + [0.25, 0.25, 0.125], + [0.25, 0.5, 0.25], + [0.25, 0.75, 0.375], + [0.25, 0.999, 0.4995], + [0.25, 0.9999999, 0.4999999], + [0.25, 1.0, 0.5], + [0.5, 0.0, 0.0], + [0.5, 1e-07, 1e-07], + [0.5, 0.001, 0.001], + [0.5, 0.25, 0.25], + [0.5, 0.5, 0.5], + [0.5, 0.75, 0.75], + [0.5, 0.999, 0.999], + [0.5, 0.9999999, 0.9999999], + [0.5, 1.0, 1.0], + [0.75, 0.0, 0.5], + [0.75, 1e-07, 0.5000001], + [0.75, 0.001, 0.5005], + [0.75, 0.25, 0.625], + [0.75, 0.5, 0.75], + [0.75, 0.75, 0.875], + [0.75, 0.999, 0.9995], + [0.75, 0.9999999, 0.9999999], + [0.75, 1.0, 1.0], + [0.999, 0.0, 0.998], + [0.999, 1e-07, 0.998], + [0.999, 0.001, 0.9980021], + [0.999, 0.25, 0.9985], + [0.999, 0.5, 0.999], + [0.999, 0.75, 0.9995], + [0.999, 0.999, 0.999998], + [0.999, 0.9999999, 1.0], + [0.999, 1.0, 1.0], + [0.9999999, 0.0, 0.9999998], + [0.9999999, 1e-07, 0.9999998], + [0.9999999, 0.001, 0.9999998], + [0.9999999, 0.25, 0.9999998], + [0.9999999, 0.5, 0.9999999], + [0.9999999, 0.75, 0.9999999], + [0.9999999, 0.999, 1.0], + [0.9999999, 0.9999999, 1.0], + [0.9999999, 1.0, 1.0], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 1.0], + [1.0, 0.001, 1.0], + [1.0, 0.25, 1.0], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.0], + [1.0, 0.999, 1.0], + [1.0, 0.9999999, 1.0], + [1.0, 1.0, 1.0] + ], + "pin-light": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.5], + [0.0, 0.999, 0.998], + [0.0, 0.9999999, 0.9999998], + [0.0, 1.0, 1.0], + [1e-07, 0.0, 0.0], + [1e-07, 1e-07, 1e-07], + [1e-07, 0.001, 1e-07], + [1e-07, 0.25, 1e-07], + [1e-07, 0.5, 1e-07], + [1e-07, 0.75, 0.5], + [1e-07, 0.999, 0.998], + [1e-07, 0.9999999, 0.9999998], + [1e-07, 1.0, 1.0], + [0.001, 0.0, 0.0], + [0.001, 1e-07, 2e-07], + [0.001, 0.001, 0.001], + [0.001, 0.25, 0.001], + [0.001, 0.5, 0.001], + [0.001, 0.75, 0.5], + [0.001, 0.999, 0.998], + [0.001, 0.9999999, 0.9999998], + [0.001, 1.0, 1.0], + [0.25, 0.0, 0.0], + [0.25, 1e-07, 2e-07], + [0.25, 0.001, 0.002], + [0.25, 0.25, 0.25], + [0.25, 0.5, 0.25], + [0.25, 0.75, 0.5], + [0.25, 0.999, 0.998], + [0.25, 0.9999999, 0.9999998], + [0.25, 1.0, 1.0], + [0.5, 0.0, 0.0], + [0.5, 1e-07, 2e-07], + [0.5, 0.001, 0.002], + [0.5, 0.25, 0.5], + [0.5, 0.5, 0.5], + [0.5, 0.75, 0.5], + [0.5, 0.999, 0.998], + [0.5, 0.9999999, 0.9999998], + [0.5, 1.0, 1.0], + [0.75, 0.0, 0.0], + [0.75, 1e-07, 2e-07], + [0.75, 0.001, 0.002], + [0.75, 0.25, 0.5], + [0.75, 0.5, 0.75], + [0.75, 0.75, 0.75], + [0.75, 0.999, 0.998], + [0.75, 0.9999999, 0.9999998], + [0.75, 1.0, 1.0], + [0.999, 0.0, 0.0], + [0.999, 1e-07, 2e-07], + [0.999, 0.001, 0.002], + [0.999, 0.25, 0.5], + [0.999, 0.5, 0.999], + [0.999, 0.75, 0.999], + [0.999, 0.999, 0.999], + [0.999, 0.9999999, 0.9999998], + [0.999, 1.0, 1.0], + [0.9999999, 0.0, 0.0], + [0.9999999, 1e-07, 2e-07], + [0.9999999, 0.001, 0.002], + [0.9999999, 0.25, 0.5], + [0.9999999, 0.5, 0.9999999], + [0.9999999, 0.75, 0.9999999], + [0.9999999, 0.999, 0.9999999], + [0.9999999, 0.9999999, 0.9999999], + [0.9999999, 1.0, 1.0], + [1.0, 0.0, 0.0], + [1.0, 1e-07, 2e-07], + [1.0, 0.001, 0.002], + [1.0, 0.25, 0.5], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.0], + [1.0, 0.999, 1.0], + [1.0, 0.9999999, 1.0], + [1.0, 1.0, 1.0] + ], + "screen": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 1e-07], + [0.0, 0.001, 0.001], + [0.0, 0.25, 0.25], + [0.0, 0.5, 0.5], + [0.0, 0.75, 0.75], + [0.0, 0.999, 0.999], + [0.0, 0.9999999, 0.9999999], + [0.0, 1.0, 1.0], + [1e-07, 0.0, 1e-07], + [1e-07, 1e-07, 2e-07], + [1e-07, 0.001, 0.0010001], + [1e-07, 0.25, 0.2500001], + [1e-07, 0.5, 0.5000001], + [1e-07, 0.75, 0.75], + [1e-07, 0.999, 0.999], + [1e-07, 0.9999999, 0.9999999], + [1e-07, 1.0, 1.0], + [0.001, 0.0, 0.001], + [0.001, 1e-07, 0.0010001], + [0.001, 0.001, 0.001999], + [0.001, 0.25, 0.25075], + [0.001, 0.5, 0.5005], + [0.001, 0.75, 0.75025], + [0.001, 0.999, 0.999001], + [0.001, 0.9999999, 0.9999999], + [0.001, 1.0, 1.0], + [0.25, 0.0, 0.25], + [0.25, 1e-07, 0.2500001], + [0.25, 0.001, 0.25075], + [0.25, 0.25, 0.4375], + [0.25, 0.5, 0.625], + [0.25, 0.75, 0.8125], + [0.25, 0.999, 0.99925], + [0.25, 0.9999999, 0.9999999], + [0.25, 1.0, 1.0], + [0.5, 0.0, 0.5], + [0.5, 1e-07, 0.5000001], + [0.5, 0.001, 0.5005], + [0.5, 0.25, 0.625], + [0.5, 0.5, 0.75], + [0.5, 0.75, 0.875], + [0.5, 0.999, 0.9995], + [0.5, 0.9999999, 0.9999999], + [0.5, 1.0, 1.0], + [0.75, 0.0, 0.75], + [0.75, 1e-07, 0.75], + [0.75, 0.001, 0.75025], + [0.75, 0.25, 0.8125], + [0.75, 0.5, 0.875], + [0.75, 0.75, 0.9375], + [0.75, 0.999, 0.99975], + [0.75, 0.9999999, 1.0], + [0.75, 1.0, 1.0], + [0.999, 0.0, 0.999], + [0.999, 1e-07, 0.999], + [0.999, 0.001, 0.999001], + [0.999, 0.25, 0.99925], + [0.999, 0.5, 0.9995], + [0.999, 0.75, 0.99975], + [0.999, 0.999, 0.999999], + [0.999, 0.9999999, 1.0], + [0.999, 1.0, 1.0], + [0.9999999, 0.0, 0.9999999], + [0.9999999, 1e-07, 0.9999999], + [0.9999999, 0.001, 0.9999999], + [0.9999999, 0.25, 0.9999999], + [0.9999999, 0.5, 0.9999999], + [0.9999999, 0.75, 1.0], + [0.9999999, 0.999, 1.0], + [0.9999999, 0.9999999, 1.0], + [0.9999999, 1.0, 1.0], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 1.0], + [1.0, 0.001, 1.0], + [1.0, 0.25, 1.0], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.0], + [1.0, 0.999, 1.0], + [1.0, 0.9999999, 1.0], + [1.0, 1.0, 1.0] + ], + "soft-light": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.0], + [0.0, 0.999, 0.0], + [0.0, 0.9999999, 0.0], + [0.0, 1.0, 0.0], + [1e-07, 0.0, 0.0], + [1e-07, 1e-07, 0.0], + [1e-07, 0.001, 0.0], + [1e-07, 0.25, 1e-07], + [1e-07, 0.5, 1e-07], + [1e-07, 0.75, 2e-07], + [1e-07, 0.999, 2e-07], + [1e-07, 0.9999999, 2e-07], + [1e-07, 1.0, 2e-07], + [0.001, 0.0, 1e-06], + [0.001, 1e-07, 1e-06], + [0.001, 0.001, 3e-06], + [0.001, 0.25, 0.0005005], + [0.001, 0.5, 0.001], + [0.001, 0.75, 0.0014995], + [0.001, 0.999, 0.001997], + [0.001, 0.9999999, 0.001999], + [0.001, 1.0, 0.001999], + [0.25, 0.0, 0.0625], + [0.25, 1e-07, 0.0625001], + [0.25, 0.001, 0.062875], + [0.25, 0.25, 0.15625], + [0.25, 0.5, 0.25], + [0.25, 0.75, 0.34375], + [0.25, 0.999, 0.437125], + [0.25, 0.9999999, 0.4374999], + [0.25, 1.0, 0.4375], + [0.5, 0.0, 0.25], + [0.5, 1e-07, 0.2500001], + [0.5, 0.001, 0.2505], + [0.5, 0.25, 0.375], + [0.5, 0.5, 0.5], + [0.5, 0.75, 0.625], + [0.5, 0.999, 0.7495], + [0.5, 0.9999999, 0.7499999], + [0.5, 1.0, 0.75], + [0.75, 0.0, 0.5625], + [0.75, 1e-07, 0.5625], + [0.75, 0.001, 0.562875], + [0.75, 0.25, 0.65625], + [0.75, 0.5, 0.75], + [0.75, 0.75, 0.84375], + [0.75, 0.999, 0.937125], + [0.75, 0.9999999, 0.9375], + [0.75, 1.0, 0.9375], + [0.999, 0.0, 0.998001], + [0.999, 1e-07, 0.998001], + [0.999, 0.001, 0.9980031], + [0.999, 0.25, 0.9985005], + [0.999, 0.5, 0.999], + [0.999, 0.75, 0.9994995], + [0.999, 0.999, 0.999997], + [0.999, 0.9999999, 0.999999], + [0.999, 1.0, 0.999999], + [0.9999999, 0.0, 0.9999998], + [0.9999999, 1e-07, 0.9999998], + [0.9999999, 0.001, 0.9999998], + [0.9999999, 0.25, 0.9999998], + [0.9999999, 0.5, 0.9999999], + [0.9999999, 0.75, 0.9999999], + [0.9999999, 0.999, 1.0], + [0.9999999, 0.9999999, 1.0], + [0.9999999, 1.0, 1.0], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 1.0], + [1.0, 0.001, 1.0], + [1.0, 0.25, 1.0], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.0], + [1.0, 0.999, 1.0], + [1.0, 0.9999999, 1.0], + [1.0, 1.0, 1.0] + ], + "subtract": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.0], + [0.0, 0.999, 0.0], + [0.0, 0.9999999, 0.0], + [0.0, 1.0, 0.0], + [1e-07, 0.0, 1e-07], + [1e-07, 1e-07, 0.0], + [1e-07, 0.001, 0.0], + [1e-07, 0.25, 0.0], + [1e-07, 0.5, 0.0], + [1e-07, 0.75, 0.0], + [1e-07, 0.999, 0.0], + [1e-07, 0.9999999, 0.0], + [1e-07, 1.0, 0.0], + [0.001, 0.0, 0.001], + [0.001, 1e-07, 0.0009999], + [0.001, 0.001, 0.0], + [0.001, 0.25, 0.0], + [0.001, 0.5, 0.0], + [0.001, 0.75, 0.0], + [0.001, 0.999, 0.0], + [0.001, 0.9999999, 0.0], + [0.001, 1.0, 0.0], + [0.25, 0.0, 0.25], + [0.25, 1e-07, 0.2499999], + [0.25, 0.001, 0.249], + [0.25, 0.25, 0.0], + [0.25, 0.5, 0.0], + [0.25, 0.75, 0.0], + [0.25, 0.999, 0.0], + [0.25, 0.9999999, 0.0], + [0.25, 1.0, 0.0], + [0.5, 0.0, 0.5], + [0.5, 1e-07, 0.4999999], + [0.5, 0.001, 0.499], + [0.5, 0.25, 0.25], + [0.5, 0.5, 0.0], + [0.5, 0.75, 0.0], + [0.5, 0.999, 0.0], + [0.5, 0.9999999, 0.0], + [0.5, 1.0, 0.0], + [0.75, 0.0, 0.75], + [0.75, 1e-07, 0.7499999], + [0.75, 0.001, 0.749], + [0.75, 0.25, 0.5], + [0.75, 0.5, 0.25], + [0.75, 0.75, 0.0], + [0.75, 0.999, 0.0], + [0.75, 0.9999999, 0.0], + [0.75, 1.0, 0.0], + [0.999, 0.0, 0.999], + [0.999, 1e-07, 0.9989999], + [0.999, 0.001, 0.998], + [0.999, 0.25, 0.749], + [0.999, 0.5, 0.499], + [0.999, 0.75, 0.249], + [0.999, 0.999, 0.0], + [0.999, 0.9999999, 0.0], + [0.999, 1.0, 0.0], + [0.9999999, 0.0, 0.9999999], + [0.9999999, 1e-07, 0.9999998], + [0.9999999, 0.001, 0.9989999], + [0.9999999, 0.25, 0.7499999], + [0.9999999, 0.5, 0.4999999], + [0.9999999, 0.75, 0.2499999], + [0.9999999, 0.999, 0.0009999], + [0.9999999, 0.9999999, 0.0], + [0.9999999, 1.0, 0.0], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 0.9999999], + [1.0, 0.001, 0.999], + [1.0, 0.25, 0.75], + [1.0, 0.5, 0.5], + [1.0, 0.75, 0.25], + [1.0, 0.999, 0.001], + [1.0, 0.9999999, 1e-07], + [1.0, 1.0, 0.0] + ], + "vivid-light": [ + [0.0, 0.0, 0.0], + [0.0, 1e-07, 0.0], + [0.0, 0.001, 0.0], + [0.0, 0.25, 0.0], + [0.0, 0.5, 0.0], + [0.0, 0.75, 0.0], + [0.0, 0.999, 0.0], + [0.0, 0.9999999, 0.0], + [0.0, 1.0, 0.0], + [1e-07, 0.0, 0.0], + [1e-07, 1e-07, 0.0], + [1e-07, 0.001, 0.0], + [1e-07, 0.25, 0.0], + [1e-07, 0.5, 1e-07], + [1e-07, 0.75, 2e-07], + [1e-07, 0.999, 5e-05], + [1e-07, 0.9999999, 1.0], + [1e-07, 1.0, 1.0], + [0.001, 0.0, 0.0], + [0.001, 1e-07, 0.0], + [0.001, 0.001, 0.0], + [0.001, 0.25, 0.0], + [0.001, 0.5, 0.001], + [0.001, 0.75, 0.002], + [0.001, 0.999, 0.5000064], + [0.001, 0.9999999, 1.0], + [0.001, 1.0, 1.0], + [0.25, 0.0, 0.0], + [0.25, 1e-07, 0.0], + [0.25, 0.001, 0.0], + [0.25, 0.25, 0.0], + [0.25, 0.5, 0.25], + [0.25, 0.75, 0.5], + [0.25, 0.999, 1.0], + [0.25, 0.9999999, 1.0], + [0.25, 1.0, 1.0], + [0.5, 0.0, 0.0], + [0.5, 1e-07, 0.0], + [0.5, 0.001, 0.0], + [0.5, 0.25, 0.0], + [0.5, 0.5, 0.5], + [0.5, 0.75, 1.0], + [0.5, 0.999, 1.0], + [0.5, 0.9999999, 1.0], + [0.5, 1.0, 1.0], + [0.75, 0.0, 0.0], + [0.75, 1e-07, 0.0], + [0.75, 0.001, 0.0], + [0.75, 0.25, 0.5], + [0.75, 0.5, 0.75], + [0.75, 0.75, 1.0], + [0.75, 0.999, 1.0], + [0.75, 0.9999999, 1.0], + [0.75, 1.0, 1.0], + [0.999, 0.0, 0.0], + [0.999, 1e-07, 0.0], + [0.999, 0.001, 0.5000064], + [0.999, 0.25, 0.998], + [0.999, 0.5, 0.999], + [0.999, 0.75, 1.0], + [0.999, 0.999, 1.0], + [0.999, 0.9999999, 1.0], + [0.999, 1.0, 1.0], + [0.9999999, 0.0, 0.0], + [0.9999999, 1e-07, 0.0], + [0.9999999, 0.001, 0.9999404], + [0.9999999, 0.25, 0.9999998], + [0.9999999, 0.5, 0.9999999], + [0.9999999, 0.75, 1.0], + [0.9999999, 0.999, 1.0], + [0.9999999, 0.9999999, 1.0], + [0.9999999, 1.0, 1.0], + [1.0, 0.0, 1.0], + [1.0, 1e-07, 1.0], + [1.0, 0.001, 1.0], + [1.0, 0.25, 1.0], + [1.0, 0.5, 1.0], + [1.0, 0.75, 1.0], + [1.0, 0.999, 1.0], + [1.0, 0.9999999, 1.0], + [1.0, 1.0, 1.0] + ] + }, + "hsl": { + "color": [ + [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1.0, 1.0, 1.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.2, 0.4, 0.6], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.9, 0.1, 0.35], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1e-07, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.05, 0.05, 0.05], [0.0, 0.0, 0.0]], + [[1.0, 1.0, 1.0], [0.0, 0.0, 0.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1.0, 0.0, 0.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.0, 0.0, 1.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.2, 0.4, 0.6], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.9, 0.1, 0.35], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1e-07, 1e-07, 1e-07], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1e-07, 0.0, 0.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.05, 0.05, 0.05], [1.0, 1.0, 1.0]], + [[0.5, 0.5, 0.5], [0.0, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1.0, 1.0, 1.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]], + [[0.5, 0.5, 0.5], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]], + [[0.5, 0.5, 0.5], [0.2, 0.4, 0.6], [0.25, 0.5, 0.75]], + [[0.5, 0.5, 0.5], [0.9, 0.1, 0.35], [0.9, 0.1, 0.35]], + [[0.5, 0.5, 0.5], [1e-07, 1e-07, 1e-07], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1e-07, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.05, 0.05, 0.05], [0.5, 0.5, 0.5]], + [[1.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[1.0, 0.0, 0.0], [1.0, 1.0, 1.0], [0.5, 0.5, 0.5]], + [[1.0, 0.0, 0.0], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]], + [[1.0, 0.0, 0.0], [0.2, 0.4, 0.6], [0.25, 0.5, 0.75]], + [[1.0, 0.0, 0.0], [0.9, 0.1, 0.35], [0.9, 0.1, 0.35]], + [[1.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [0.5, 0.5, 0.5]], + [[1.0, 0.0, 0.0], [1e-07, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[1.0, 0.0, 0.0], [0.05, 0.05, 0.05], [0.5, 0.5, 0.5]], + [[0.0, 0.0, 1.0], [0.0, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.0, 0.0, 1.0], [1.0, 1.0, 1.0], [0.5, 0.5, 0.5]], + [[0.0, 0.0, 1.0], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]], + [[0.0, 0.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]], + [[0.0, 0.0, 1.0], [0.2, 0.4, 0.6], [0.25, 0.5, 0.75]], + [[0.0, 0.0, 1.0], [0.9, 0.1, 0.35], [0.9, 0.1, 0.35]], + [[0.0, 0.0, 1.0], [1e-07, 1e-07, 1e-07], [0.5, 0.5, 0.5]], + [[0.0, 0.0, 1.0], [1e-07, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.0, 0.0, 1.0], [0.05, 0.05, 0.05], [0.5, 0.5, 0.5]], + [[0.2, 0.4, 0.6], [0.0, 0.0, 0.0], [0.4, 0.4, 0.4]], + [[0.2, 0.4, 0.6], [1.0, 1.0, 1.0], [0.4, 0.4, 0.4]], + [[0.2, 0.4, 0.6], [0.5, 0.5, 0.5], [0.4, 0.4, 0.4]], + [[0.2, 0.4, 0.6], [1.0, 0.0, 0.0], [0.8, 0.0, 0.0]], + [[0.2, 0.4, 0.6], [0.0, 0.0, 1.0], [0.0, 0.0, 0.8]], + [[0.2, 0.4, 0.6], [0.2, 0.4, 0.6], [0.2, 0.4, 0.6]], + [[0.2, 0.4, 0.6], [0.9, 0.1, 0.35], [0.72, 0.08, 0.28]], + [[0.2, 0.4, 0.6], [1e-07, 1e-07, 1e-07], [0.4, 0.4, 0.4]], + [[0.2, 0.4, 0.6], [1e-07, 0.0, 0.0], [0.4, 0.4, 0.4]], + [[0.2, 0.4, 0.6], [0.05, 0.05, 0.05], [0.4, 0.4, 0.4]], + [[0.9, 0.1, 0.35], [0.0, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.9, 0.1, 0.35], [1.0, 1.0, 1.0], [0.5, 0.5, 0.5]], + [[0.9, 0.1, 0.35], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[0.9, 0.1, 0.35], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]], + [[0.9, 0.1, 0.35], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]], + [[0.9, 0.1, 0.35], [0.2, 0.4, 0.6], [0.25, 0.5, 0.75]], + [[0.9, 0.1, 0.35], [0.9, 0.1, 0.35], [0.9, 0.1, 0.35]], + [[0.9, 0.1, 0.35], [1e-07, 1e-07, 1e-07], [0.5, 0.5, 0.5]], + [[0.9, 0.1, 0.35], [1e-07, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.9, 0.1, 0.35], [0.05, 0.05, 0.05], [0.5, 0.5, 0.5]], + [[1e-07, 1e-07, 1e-07], [0.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1.0, 1.0, 1.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.5, 0.5, 0.5], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1.0, 0.0, 0.0], [2e-07, 0.0, 0.0]], + [[1e-07, 1e-07, 1e-07], [0.0, 0.0, 1.0], [0.0, 0.0, 2e-07]], + [[1e-07, 1e-07, 1e-07], [0.2, 0.4, 0.6], [1e-07, 1e-07, 2e-07]], + [[1e-07, 1e-07, 1e-07], [0.9, 0.1, 0.35], [2e-07, 0.0, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1e-07, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.05, 0.05, 0.05], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [0.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [1.0, 1.0, 1.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [0.5, 0.5, 0.5], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [1.0, 0.0, 0.0], [1e-07, 0.0, 0.0]], + [[1e-07, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1e-07]], + [[1e-07, 0.0, 0.0], [0.2, 0.4, 0.6], [0.0, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [0.9, 0.1, 0.35], [1e-07, 0.0, 0.0]], + [[1e-07, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [1e-07, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [0.05, 0.05, 0.05], [1e-07, 1e-07, 1e-07]], + [[0.05, 0.05, 0.05], [0.0, 0.0, 0.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [1.0, 1.0, 1.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.5, 0.5, 0.5], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [1.0, 0.0, 0.0], [0.1, 0.0, 0.0]], + [[0.05, 0.05, 0.05], [0.0, 0.0, 1.0], [0.0, 0.0, 0.1]], + [[0.05, 0.05, 0.05], [0.2, 0.4, 0.6], [0.025, 0.05, 0.075]], + [[0.05, 0.05, 0.05], [0.9, 0.1, 0.35], [0.09, 0.01, 0.035]], + [[0.05, 0.05, 0.05], [1e-07, 1e-07, 1e-07], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [1e-07, 0.0, 0.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.05, 0.05, 0.05], [0.05, 0.05, 0.05]] + ], + "hue": [ + [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1.0, 1.0, 1.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.2, 0.4, 0.6], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.9, 0.1, 0.35], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1e-07, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.05, 0.05, 0.05], [0.0, 0.0, 0.0]], + [[1.0, 1.0, 1.0], [0.0, 0.0, 0.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1.0, 0.0, 0.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.0, 0.0, 1.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.2, 0.4, 0.6], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.9, 0.1, 0.35], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1e-07, 1e-07, 1e-07], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1e-07, 0.0, 0.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.05, 0.05, 0.05], [1.0, 1.0, 1.0]], + [[0.5, 0.5, 0.5], [0.0, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1.0, 1.0, 1.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1.0, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.0, 0.0, 1.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.2, 0.4, 0.6], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.9, 0.1, 0.35], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1e-07, 1e-07, 1e-07], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1e-07, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.05, 0.05, 0.05], [0.5, 0.5, 0.5]], + [[1.0, 0.0, 0.0], [0.0, 0.0, 0.0], [1.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [1.0, 1.0, 1.0], [1.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.5, 0.5, 0.5], [1.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]], + [[1.0, 0.0, 0.0], [0.2, 0.4, 0.6], [1e-07, 0.5000001, 1.0]], + [[1.0, 0.0, 0.0], [0.9, 0.1, 0.35], [1.0, -1e-07, 0.3124999]], + [[1.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [1.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [1e-07, 0.0, 0.0], [1.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.05, 0.05, 0.05], [1.0, 0.0, 0.0]], + [[0.0, 0.0, 1.0], [0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], + [[0.0, 0.0, 1.0], [1.0, 1.0, 1.0], [0.0, 0.0, 1.0]], + [[0.0, 0.0, 1.0], [0.5, 0.5, 0.5], [0.0, 0.0, 1.0]], + [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]], + [[0.0, 0.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]], + [[0.0, 0.0, 1.0], [0.2, 0.4, 0.6], [1e-07, 0.5000001, 1.0]], + [[0.0, 0.0, 1.0], [0.9, 0.1, 0.35], [1.0, -1e-07, 0.3124999]], + [[0.0, 0.0, 1.0], [1e-07, 1e-07, 1e-07], [0.0, 0.0, 1.0]], + [[0.0, 0.0, 1.0], [1e-07, 0.0, 0.0], [0.0, 0.0, 1.0]], + [[0.0, 0.0, 1.0], [0.05, 0.05, 0.05], [0.0, 0.0, 1.0]], + [[0.2, 0.4, 0.6], [0.0, 0.0, 0.0], [0.2, 0.4, 0.6]], + [[0.2, 0.4, 0.6], [1.0, 1.0, 1.0], [0.2, 0.4, 0.6]], + [[0.2, 0.4, 0.6], [0.5, 0.5, 0.5], [0.2, 0.4, 0.6]], + [[0.2, 0.4, 0.6], [1.0, 0.0, 0.0], [0.6, 0.2, 0.2]], + [[0.2, 0.4, 0.6], [0.0, 0.0, 1.0], [0.2, 0.2, 0.6]], + [[0.2, 0.4, 0.6], [0.2, 0.4, 0.6], [0.2, 0.4, 0.6]], + [[0.2, 0.4, 0.6], [0.9, 0.1, 0.35], [0.6, 0.2, 0.325]], + [[0.2, 0.4, 0.6], [1e-07, 1e-07, 1e-07], [0.2, 0.4, 0.6]], + [[0.2, 0.4, 0.6], [1e-07, 0.0, 0.0], [0.2, 0.4, 0.6]], + [[0.2, 0.4, 0.6], [0.05, 0.05, 0.05], [0.2, 0.4, 0.6]], + [[0.9, 0.1, 0.35], [0.0, 0.0, 0.0], [0.9, 0.1, 0.35]], + [[0.9, 0.1, 0.35], [1.0, 1.0, 1.0], [0.9, 0.1, 0.35]], + [[0.9, 0.1, 0.35], [0.5, 0.5, 0.5], [0.9, 0.1, 0.35]], + [[0.9, 0.1, 0.35], [1.0, 0.0, 0.0], [0.9, 0.1, 0.1]], + [[0.9, 0.1, 0.35], [0.0, 0.0, 1.0], [0.1, 0.1, 0.9]], + [[0.9, 0.1, 0.35], [0.2, 0.4, 0.6], [0.1, 0.4999999, 0.9]], + [[0.9, 0.1, 0.35], [0.9, 0.1, 0.35], [0.9, 0.1, 0.35]], + [[0.9, 0.1, 0.35], [1e-07, 1e-07, 1e-07], [0.9, 0.1, 0.35]], + [[0.9, 0.1, 0.35], [1e-07, 0.0, 0.0], [0.9, 0.1, 0.35]], + [[0.9, 0.1, 0.35], [0.05, 0.05, 0.05], [0.9, 0.1, 0.35]], + [[1e-07, 1e-07, 1e-07], [0.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1.0, 1.0, 1.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.5, 0.5, 0.5], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.0, 0.0, 1.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.2, 0.4, 0.6], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.9, 0.1, 0.35], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1e-07, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.05, 0.05, 0.05], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [0.0, 0.0, 0.0], [1e-07, 0.0, 0.0]], + [[1e-07, 0.0, 0.0], [1.0, 1.0, 1.0], [1e-07, 0.0, 0.0]], + [[1e-07, 0.0, 0.0], [0.5, 0.5, 0.5], [1e-07, 0.0, 0.0]], + [[1e-07, 0.0, 0.0], [1.0, 0.0, 0.0], [1e-07, 0.0, 0.0]], + [[1e-07, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1e-07]], + [[1e-07, 0.0, 0.0], [0.2, 0.4, 0.6], [0.0, 0.0, 1e-07]], + [[1e-07, 0.0, 0.0], [0.9, 0.1, 0.35], [1e-07, -0.0, 0.0]], + [[1e-07, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [1e-07, 0.0, 0.0]], + [[1e-07, 0.0, 0.0], [1e-07, 0.0, 0.0], [1e-07, 0.0, 0.0]], + [[1e-07, 0.0, 0.0], [0.05, 0.05, 0.05], [1e-07, 0.0, 0.0]], + [[0.05, 0.05, 0.05], [0.0, 0.0, 0.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [1.0, 1.0, 1.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.5, 0.5, 0.5], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [1.0, 0.0, 0.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.0, 0.0, 1.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.2, 0.4, 0.6], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.9, 0.1, 0.35], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [1e-07, 1e-07, 1e-07], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [1e-07, 0.0, 0.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.05, 0.05, 0.05], [0.05, 0.05, 0.05]] + ], + "luminosity": [ + [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], + [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.2224884, 0.2224884, 0.2224884]], + [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0606079, 0.0606079, 0.0606079]], + [[0.0, 0.0, 0.0], [0.2, 0.4, 0.6], [0.3676239, 0.3676239, 0.3676239]], + [[0.0, 0.0, 0.0], [0.9, 0.1, 0.35], [0.2931427, 0.2931427, 0.2931427]], + [[0.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07]], + [[0.0, 0.0, 0.0], [1e-07, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.05, 0.05, 0.05], [0.05, 0.05, 0.05]], + [[1.0, 1.0, 1.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[1.0, 1.0, 1.0], [1.0, 0.0, 0.0], [0.2224884, 0.2224884, 0.2224884]], + [[1.0, 1.0, 1.0], [0.0, 0.0, 1.0], [0.0606079, 0.0606079, 0.0606079]], + [[1.0, 1.0, 1.0], [0.2, 0.4, 0.6], [0.3676239, 0.3676239, 0.3676239]], + [[1.0, 1.0, 1.0], [0.9, 0.1, 0.35], [0.2931427, 0.2931427, 0.2931427]], + [[1.0, 1.0, 1.0], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07]], + [[1.0, 1.0, 1.0], [1e-07, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[1.0, 1.0, 1.0], [0.05, 0.05, 0.05], [0.05, 0.05, 0.05]], + [[0.5, 0.5, 0.5], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.5, 0.5, 0.5], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], + [[0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1.0, 0.0, 0.0], [0.2224884, 0.2224884, 0.2224884]], + [[0.5, 0.5, 0.5], [0.0, 0.0, 1.0], [0.0606079, 0.0606079, 0.0606079]], + [[0.5, 0.5, 0.5], [0.2, 0.4, 0.6], [0.3676239, 0.3676239, 0.3676239]], + [[0.5, 0.5, 0.5], [0.9, 0.1, 0.35], [0.2931427, 0.2931427, 0.2931427]], + [[0.5, 0.5, 0.5], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07]], + [[0.5, 0.5, 0.5], [1e-07, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.5, 0.5, 0.5], [0.05, 0.05, 0.05], [0.05, 0.05, 0.05]], + [[1.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [1.0, 1.0, 1.0], [4.4946165, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.5, 0.5, 0.5], [2.2473083, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.2724093, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.2, 0.4, 0.6], [1.6523285, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.9, 0.1, 0.35], [1.3175639, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [4e-07, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [1e-07, 0.0, 0.0], [1e-07, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.05, 0.05, 0.05], [0.2247308, 0.0, 0.0]], + [[0.0, 0.0, 1.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 1.0], [1.0, 1.0, 1.0], [0.0, 0.0, 16.4994965]], + [[0.0, 0.0, 1.0], [0.5, 0.5, 0.5], [0.0, 0.0, 8.2497482]], + [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0], [0.0, 0.0, 3.6709466]], + [[0.0, 0.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]], + [[0.0, 0.0, 1.0], [0.2, 0.4, 0.6], [0.0, 0.0, 6.0656095]], + [[0.0, 0.0, 1.0], [0.9, 0.1, 0.35], [0.0, 0.0, 4.8367066]], + [[0.0, 0.0, 1.0], [1e-07, 1e-07, 1e-07], [0.0, 0.0, 1.6e-06]], + [[0.0, 0.0, 1.0], [1e-07, 0.0, 0.0], [0.0, 0.0, 4e-07]], + [[0.0, 0.0, 1.0], [0.05, 0.05, 0.05], [0.0, 0.0, 0.8249749]], + [[0.2, 0.4, 0.6], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.2, 0.4, 0.6], [1.0, 1.0, 1.0], [0.5440342, 1.0880685, 1.6321028]], + [[0.2, 0.4, 0.6], [0.5, 0.5, 0.5], [0.2720171, 0.5440342, 0.8160514]], + [[0.2, 0.4, 0.6], [1.0, 0.0, 0.0], [0.1210413, 0.2420826, 0.363124]], + [[0.2, 0.4, 0.6], [0.0, 0.0, 1.0], [0.0329728, 0.0659456, 0.0989183]], + [[0.2, 0.4, 0.6], [0.2, 0.4, 0.6], [0.2, 0.4, 0.6]], + [[0.2, 0.4, 0.6], [0.9, 0.1, 0.35], [0.1594797, 0.3189593, 0.478439]], + [[0.2, 0.4, 0.6], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 2e-07]], + [[0.2, 0.4, 0.6], [1e-07, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.2, 0.4, 0.6], [0.05, 0.05, 0.05], [0.0272017, 0.0544034, 0.0816052]], + [[0.9, 0.1, 0.35], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.9, 0.1, 0.35], [1.0, 1.0, 1.0], [3.0701771, 0.3411308, 1.1939578]], + [[0.9, 0.1, 0.35], [0.5, 0.5, 0.5], [1.5350885, 0.1705654, 0.5969789]], + [[0.9, 0.1, 0.35], [1.0, 0.0, 0.0], [0.6830788, 0.0758977, 0.2656418]], + [[0.9, 0.1, 0.35], [0.0, 0.0, 1.0], [0.186077, 0.0206752, 0.0723633]], + [[0.9, 0.1, 0.35], [0.2, 0.4, 0.6], [1.1286706, 0.1254079, 0.4389275]], + [[0.9, 0.1, 0.35], [0.9, 0.1, 0.35], [0.9, 0.1, 0.35]], + [[0.9, 0.1, 0.35], [1e-07, 1e-07, 1e-07], [3e-07, 0.0, 1e-07]], + [[0.9, 0.1, 0.35], [1e-07, 0.0, 0.0], [1e-07, 0.0, 0.0]], + [[0.9, 0.1, 0.35], [0.05, 0.05, 0.05], [0.1535089, 0.0170565, 0.0596979]], + [[1e-07, 1e-07, 1e-07], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[1e-07, 1e-07, 1e-07], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], + [[1e-07, 1e-07, 1e-07], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[1e-07, 1e-07, 1e-07], [1.0, 0.0, 0.0], [0.2224884, 0.2224884, 0.2224884]], + [[1e-07, 1e-07, 1e-07], [0.0, 0.0, 1.0], [0.0606079, 0.0606079, 0.0606079]], + [[1e-07, 1e-07, 1e-07], [0.2, 0.4, 0.6], [0.3676239, 0.3676239, 0.3676239]], + [[1e-07, 1e-07, 1e-07], [0.9, 0.1, 0.35], [0.2931427, 0.2931427, 0.2931427]], + [[1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1e-07, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[1e-07, 1e-07, 1e-07], [0.05, 0.05, 0.05], [0.05, 0.05, 0.05]], + [[1e-07, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[1e-07, 0.0, 0.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], + [[1e-07, 0.0, 0.0], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[1e-07, 0.0, 0.0], [1.0, 0.0, 0.0], [0.2224884, 0.2224884, 0.2224884]], + [[1e-07, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0606079, 0.0606079, 0.0606079]], + [[1e-07, 0.0, 0.0], [0.2, 0.4, 0.6], [0.3676239, 0.3676239, 0.3676239]], + [[1e-07, 0.0, 0.0], [0.9, 0.1, 0.35], [0.2931427, 0.2931427, 0.2931427]], + [[1e-07, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [1e-07, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[1e-07, 0.0, 0.0], [0.05, 0.05, 0.05], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.05, 0.05, 0.05], [1.0, 1.0, 1.0], [0.9999999, 0.9999999, 0.9999999]], + [[0.05, 0.05, 0.05], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[0.05, 0.05, 0.05], [1.0, 0.0, 0.0], [0.2224884, 0.2224884, 0.2224884]], + [[0.05, 0.05, 0.05], [0.0, 0.0, 1.0], [0.0606079, 0.0606079, 0.0606079]], + [[0.05, 0.05, 0.05], [0.2, 0.4, 0.6], [0.3676239, 0.3676239, 0.3676239]], + [[0.05, 0.05, 0.05], [0.9, 0.1, 0.35], [0.2931426, 0.2931426, 0.2931426]], + [[0.05, 0.05, 0.05], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07]], + [[0.05, 0.05, 0.05], [1e-07, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.05, 0.05, 0.05], [0.05, 0.05, 0.05], [0.05, 0.05, 0.05]] + ], + "saturation": [ + [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1.0, 1.0, 1.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.2, 0.4, 0.6], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.9, 0.1, 0.35], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [1e-07, 0.0, 0.0], [0.0, 0.0, 0.0]], + [[0.0, 0.0, 0.0], [0.05, 0.05, 0.05], [0.0, 0.0, 0.0]], + [[1.0, 1.0, 1.0], [0.0, 0.0, 0.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1.0, 0.0, 0.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.0, 0.0, 1.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.2, 0.4, 0.6], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.9, 0.1, 0.35], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1e-07, 1e-07, 1e-07], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1e-07, 0.0, 0.0], [1.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [0.05, 0.05, 0.05], [1.0, 1.0, 1.0]], + [[0.5, 0.5, 0.5], [0.0, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1.0, 1.0, 1.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1.0, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.0, 0.0, 1.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.2, 0.4, 0.6], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.9, 0.1, 0.35], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1e-07, 1e-07, 1e-07], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [1e-07, 0.0, 0.0], [0.5, 0.5, 0.5]], + [[0.5, 0.5, 0.5], [0.05, 0.05, 0.05], [0.5, 0.5, 0.5]], + [[1.0, 0.0, 0.0], [0.0, 0.0, 0.0], [1.0, 1.0, 1.0]], + [[1.0, 0.0, 0.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], + [[1.0, 0.0, 0.0], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0]], + [[1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [1.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.2, 0.4, 0.6], [1.0, 0.3333333, 0.3333333]], + [[1.0, 0.0, 0.0], [0.9, 0.1, 0.35], [1.0, 0.1111112, 0.1111112]], + [[1.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [1.0, 1.0, 1.0]], + [[1.0, 0.0, 0.0], [1e-07, 0.0, 0.0], [1.0, 0.0, 0.0]], + [[1.0, 0.0, 0.0], [0.05, 0.05, 0.05], [1.0, 1.0, 1.0]], + [[0.0, 0.0, 1.0], [0.0, 0.0, 0.0], [1.0, 1.0, 1.0]], + [[0.0, 0.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], + [[0.0, 0.0, 1.0], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0]], + [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]], + [[0.0, 0.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]], + [[0.0, 0.0, 1.0], [0.2, 0.4, 0.6], [0.3333333, 0.3333333, 1.0]], + [[0.0, 0.0, 1.0], [0.9, 0.1, 0.35], [0.1111112, 0.1111112, 1.0]], + [[0.0, 0.0, 1.0], [1e-07, 1e-07, 1e-07], [1.0, 1.0, 1.0]], + [[0.0, 0.0, 1.0], [1e-07, 0.0, 0.0], [0.0, 0.0, 1.0]], + [[0.0, 0.0, 1.0], [0.05, 0.05, 0.05], [1.0, 1.0, 1.0]], + [[0.2, 0.4, 0.6], [0.0, 0.0, 0.0], [0.6, 0.6, 0.6]], + [[0.2, 0.4, 0.6], [1.0, 1.0, 1.0], [0.6, 0.6, 0.6]], + [[0.2, 0.4, 0.6], [0.5, 0.5, 0.5], [0.6, 0.6, 0.6]], + [[0.2, 0.4, 0.6], [1.0, 0.0, 0.0], [0.0, 0.3, 0.6]], + [[0.2, 0.4, 0.6], [0.0, 0.0, 1.0], [0.0, 0.3, 0.6]], + [[0.2, 0.4, 0.6], [0.2, 0.4, 0.6], [0.2, 0.4, 0.6]], + [[0.2, 0.4, 0.6], [0.9, 0.1, 0.35], [0.0666667, 0.3333334, 0.6]], + [[0.2, 0.4, 0.6], [1e-07, 1e-07, 1e-07], [0.6, 0.6, 0.6]], + [[0.2, 0.4, 0.6], [1e-07, 0.0, 0.0], [0.0, 0.3, 0.6]], + [[0.2, 0.4, 0.6], [0.05, 0.05, 0.05], [0.6, 0.6, 0.6]], + [[0.9, 0.1, 0.35], [0.0, 0.0, 0.0], [0.9, 0.9, 0.9]], + [[0.9, 0.1, 0.35], [1.0, 1.0, 1.0], [0.9, 0.9, 0.9]], + [[0.9, 0.1, 0.35], [0.5, 0.5, 0.5], [0.9, 0.9, 0.9]], + [[0.9, 0.1, 0.35], [1.0, 0.0, 0.0], [0.8999999, 0.0, 0.28125]], + [[0.9, 0.1, 0.35], [0.0, 0.0, 1.0], [0.8999999, 0.0, 0.28125]], + [[0.9, 0.1, 0.35], [0.2, 0.4, 0.6], [0.9, 0.3, 0.4875]], + [[0.9, 0.1, 0.35], [0.9, 0.1, 0.35], [0.9, 0.1, 0.35]], + [[0.9, 0.1, 0.35], [1e-07, 1e-07, 1e-07], [0.9, 0.9, 0.9]], + [[0.9, 0.1, 0.35], [1e-07, 0.0, 0.0], [0.8999999, 0.0, 0.28125]], + [[0.9, 0.1, 0.35], [0.05, 0.05, 0.05], [0.9, 0.9, 0.9]], + [[1e-07, 1e-07, 1e-07], [0.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1.0, 1.0, 1.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.5, 0.5, 0.5], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.0, 0.0, 1.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.2, 0.4, 0.6], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.9, 0.1, 0.35], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [1e-07, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 1e-07, 1e-07], [0.05, 0.05, 0.05], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [0.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [1.0, 1.0, 1.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [0.5, 0.5, 0.5], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [1.0, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [0.0, 0.0, 1.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [0.2, 0.4, 0.6], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [0.9, 0.1, 0.35], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [1e-07, 1e-07, 1e-07], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [1e-07, 0.0, 0.0], [1e-07, 1e-07, 1e-07]], + [[1e-07, 0.0, 0.0], [0.05, 0.05, 0.05], [1e-07, 1e-07, 1e-07]], + [[0.05, 0.05, 0.05], [0.0, 0.0, 0.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [1.0, 1.0, 1.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.5, 0.5, 0.5], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [1.0, 0.0, 0.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.0, 0.0, 1.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.2, 0.4, 0.6], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.9, 0.1, 0.35], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [1e-07, 1e-07, 1e-07], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [1e-07, 0.0, 0.0], [0.05, 0.05, 0.05]], + [[0.05, 0.05, 0.05], [0.05, 0.05, 0.05], [0.05, 0.05, 0.05]] + ] + } +} diff --git a/tests-unit/comfy_extras_test/compositor_blend_test.py b/tests-unit/comfy_extras_test/compositor_blend_test.py new file mode 100644 index 000000000..6734ab637 --- /dev/null +++ b/tests-unit/comfy_extras_test/compositor_blend_test.py @@ -0,0 +1,157 @@ +"""Blend-mode parity tests for the compositor. + +The compositor blends in three places: this numpy module (server-side), the +``layerBlend.frag`` GLSL shader (the live preview the user actually sees), and +anything the frontend adds later. They have diverged before, silently, and the +divergences only show up as "the render does not look like the preview". + +``compositor_blend_golden.json`` is the shared contract. This file pins the +numpy implementation to it and additionally spells out, by hand, the boundary +rules that the epsilon guards exist to enforce - so a future refactor of +``safe_div`` cannot quietly re-introduce the old behaviour by regenerating the +fixture. +""" + +import json +import os + +import numpy as np +import pytest + +from comfy_extras.compositor_blend import ( + CHANNEL_BLEND, + HSL_BLEND, + EffectiveMode, + blend_composite, + blend_pixel, + resolve_mode, +) + +GOLDEN_PATH = os.path.join(os.path.dirname(__file__), "compositor_blend_golden.json") + +with open(GOLDEN_PATH) as _handle: + GOLDEN = json.load(_handle) + +TOLERANCE = GOLDEN["tolerance"] + + +def _blend(mode: str, i, l) -> np.ndarray: + return np.asarray( + blend_pixel(mode, np.float32(i), np.float32(l)), dtype=np.float64 + ).reshape(3) + + +def test_golden_covers_every_mode(): + """A new blend mode must arrive with golden values, not silently.""" + assert set(GOLDEN["channel"]) == set(CHANNEL_BLEND) + assert set(GOLDEN["hsl"]) == set(HSL_BLEND) + + +@pytest.mark.parametrize("mode", sorted(CHANNEL_BLEND)) +def test_channel_modes_match_golden(mode): + for i, l, expected in GOLDEN["channel"][mode]: + actual = _blend(mode, [i] * 3, [l] * 3) + assert actual == pytest.approx([expected] * 3, abs=TOLERANCE), ( + f"{mode}(i={i}, l={l}) -> {actual.tolist()}, golden {expected}" + ) + + +@pytest.mark.parametrize("mode", sorted(HSL_BLEND)) +def test_hsl_modes_match_golden(mode): + for i, l, expected in GOLDEN["hsl"][mode]: + actual = _blend(mode, i, l) + assert actual == pytest.approx(expected, abs=TOLERANCE), ( + f"{mode}(i={i}, l={l}) -> {actual.tolist()}, golden {expected}" + ) + + +@pytest.mark.parametrize("mode", sorted(set(CHANNEL_BLEND) | set(HSL_BLEND))) +def test_no_mode_produces_nan_or_inf(mode): + edges = [0.0, 1e-7, 1e-6, 0.5, 1.0 - 1e-7, 1.0] + for i in edges: + for l in edges: + out = _blend(mode, [i, 0.0, 1.0], [l, 1.0, 0.0]) + assert np.all(np.isfinite(out)), f"{mode}(i={i}, l={l}) -> {out.tolist()}" + + +class TestBoundaryRules: + """The rules the epsilon guards encode, written out independently of the fixture.""" + + def test_color_dodge_full_layer_is_white_not_black(self): + # Guarding the denominator returns 0 here, which reads as "the dodge + # layer turned the image black" - the exact inversion CodeRabbit flagged. + assert _blend("color-dodge", [0.5] * 3, [1.0] * 3) == pytest.approx([1.0] * 3) + + def test_color_dodge_black_backdrop_stays_black(self): + assert _blend("color-dodge", [0.0] * 3, [1.0] * 3) == pytest.approx([0.0] * 3) + + def test_color_dodge_is_clamped(self): + assert _blend("color-dodge", [0.6] * 3, [0.9] * 3) == pytest.approx([1.0] * 3) + + def test_color_burn_empty_layer_is_black_not_white(self): + assert _blend("color-burn", [0.5] * 3, [0.0] * 3) == pytest.approx([0.0] * 3) + + def test_color_burn_white_backdrop_stays_white(self): + assert _blend("color-burn", [1.0] * 3, [0.0] * 3) == pytest.approx([1.0] * 3) + + def test_vivid_light_boundaries(self): + assert _blend("vivid-light", [0.5] * 3, [0.0] * 3) == pytest.approx([0.0] * 3) + assert _blend("vivid-light", [0.5] * 3, [1.0] * 3) == pytest.approx([1.0] * 3) + assert _blend("vivid-light", [1.0] * 3, [0.0] * 3) == pytest.approx([1.0] * 3) + assert _blend("vivid-light", [0.0] * 3, [1.0] * 3) == pytest.approx([0.0] * 3) + + def test_divide_by_zero_is_clamped_to_one(self): + assert _blend("divide", [0.5] * 3, [0.0] * 3) == pytest.approx([1.0] * 3) + + def test_luminosity_over_black_takes_the_layer_luminance(self): + # A luminosity layer over a black backdrop must not vanish. There is no + # hue or saturation in the backdrop to preserve, so the result is a + # neutral grey at the layer's luminance. + assert _blend("luminosity", [0.0] * 3, [1.0] * 3) == pytest.approx([1.0] * 3) + assert _blend("luminosity", [0.0] * 3, [0.5] * 3) == pytest.approx([0.5] * 3) + + def test_luminosity_is_continuous_approaching_black(self): + near = _blend("luminosity", [1e-7] * 3, [1.0] * 3) + at = _blend("luminosity", [0.0] * 3, [1.0] * 3) + assert near == pytest.approx(at, abs=TOLERANCE) + + def test_luminosity_preserves_backdrop_chroma(self): + out = _blend("luminosity", [0.4, 0.2, 0.1], [0.5] * 3) + assert out[0] > out[1] > out[2] + + +class TestCompositeAndModeTable: + def test_unknown_blend_mode_falls_back_to_normal(self): + unknown = resolve_mode("not-a-mode") + assert (unknown.blend_space, unknown.composite) == ( + resolve_mode("normal").blend_space, + resolve_mode("normal").composite, + ) + assert _blend("not-a-mode", [0.1, 0.2, 0.3], [0.4, 0.5, 0.6]) == pytest.approx( + _blend("normal", [0.1, 0.2, 0.3], [0.4, 0.5, 0.6]) + ) + + def test_every_blend_mode_has_a_composite_entry(self): + for mode in set(CHANNEL_BLEND) | set(HSL_BLEND): + resolved = resolve_mode(mode) + assert isinstance(resolved, EffectiveMode) + assert resolved.blend == mode + assert resolved.blend_space in ("linear", "perceptual") + assert resolved.composite in ( + "union", + "clip-to-backdrop", + "clip-to-layer", + "intersection", + ) + + def test_normal_over_transparent_backdrop_keeps_the_layer(self): + backdrop = np.zeros((1, 1, 4), dtype=np.float32) + layer = np.float32([[[0.25, 0.5, 0.75, 1.0]]]) + out = blend_composite(resolve_mode("normal"), backdrop, layer, 1.0) + assert out[0, 0].tolist() == pytest.approx([0.25, 0.5, 0.75, 1.0]) + + def test_zero_opacity_is_a_no_op(self): + backdrop = np.float32([[[0.1, 0.2, 0.3, 1.0]]]) + layer = np.float32([[[1.0, 1.0, 1.0, 1.0]]]) + out = blend_composite(resolve_mode("multiply"), backdrop, layer, 0.0) + assert out[0, 0].tolist() == pytest.approx([0.1, 0.2, 0.3, 1.0]) diff --git a/tests-unit/comfy_extras_test/compositor_node_test.py b/tests-unit/comfy_extras_test/compositor_node_test.py new file mode 100644 index 000000000..3a24c4dff --- /dev/null +++ b/tests-unit/comfy_extras_test/compositor_node_test.py @@ -0,0 +1,72 @@ +"""Regression tests for ImageCompositor's handling of untrusted layer state. + +The compositor's `compositor` widget value is persisted into the saved workflow +and is accepted verbatim on `POST /prompt`, so every field in it is untrusted +input, not an internal invariant. +""" + +import numpy as np +import pytest +import torch + +from comfy_extras.nodes_compositor import ( + _layer_params, + composite_from_state, + expand_item_frames, + state_from_items, +) + + +def _solid(color, w=4, h=4) -> torch.Tensor: + frame = np.zeros((h, w, len(color)), dtype=np.float32) + frame[:] = color + return torch.from_numpy(frame).unsqueeze(0) + + +class TestLayerOpacity: + @pytest.mark.parametrize( + ("raw", "expected"), + [(-0.5, 0.0), (0.0, 0.0), (0.25, 0.25), (1.0, 1.0), (3.0, 1.0)], + ) + def test_opacity_is_clamped(self, raw, expected): + assert _layer_params({"opacity": raw}, 4, 4)["opacity"] == expected + + def test_opacity_defaults_to_opaque(self): + assert _layer_params({}, 4, 4)["opacity"] == 1.0 + + def test_out_of_range_opacity_does_not_leak_into_the_next_layer(self): + # The canvas is only clamped once, after every layer has been composited, + # so an out-of-range coverage multiplier on one layer changes the *blend* + # of the layer above it. White at opacity 3.0 over black leaves the canvas + # at 3.0; the multiply above it then reads 3.0 as its backdrop and the + # result is visibly lighter than the same stack at opacity 1.0. + def run(opacity): + state = { + "canvas": (2, 2), + "layers": [{"opacity": opacity}, {"opacity": 1.0, "blend": "multiply"}], + "inputs": None, + "background": {"color": "#000000", "opacity": 1.0, "visible": True}, + "order": None, + } + tensors = [_solid([1.0, 1.0, 1.0], 2, 2), _solid([0.5, 0.5, 0.5], 2, 2)] + return composite_from_state(tensors, state, [None, None])[0, 0, 0, :3] + + assert run(3.0).tolist() == pytest.approx(run(1.0).tolist(), abs=1e-6) + + +class TestGraphOnlyBackground: + def test_default_layout_background_is_hidden(self): + # A visible white background here would make every graph-only run emit a + # white matte instead of transparency. + frames = expand_item_frames([{"image": _solid([1.0, 0.0, 0.0])}]) + state = state_from_items(frames, (4, 4)) + assert state["background"]["visible"] is False + + def test_uncovered_canvas_stays_transparent(self): + tensors = [_solid([1.0, 0.0, 0.0], w=2, h=2)] + frames = expand_item_frames([{"image": tensors[0]}]) + state = state_from_items(frames, (4, 4)) + out = composite_from_state(tensors, state, [None])[0] + assert out.shape[-1] == 4 + assert float(out[0, 0, 3]) == pytest.approx(1.0) + assert float(out[3, 3, 3]) == pytest.approx(0.0) From 2f40b7131cb26c7255d48f6f6d821bd5fd56bedf Mon Sep 17 00:00:00 2001 From: "Daxiong (Lin)" Date: Sat, 8 Aug 2026 04:28:01 +0800 Subject: [PATCH 10/20] chore: update workflow templates to v0.11.34 (#15404) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c201d9ed4..fb0261a9d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ comfyui-frontend-package==1.48.7 -comfyui-workflow-templates==0.11.31 +comfyui-workflow-templates==0.11.34 comfyui-embedded-docs==0.5.9 torch torchsde From 66057c4e59734140da7b58397c22317e2818c043 Mon Sep 17 00:00:00 2001 From: comfyanonymous <121283862+comfyanonymous@users.noreply.github.com> Date: Fri, 7 Aug 2026 15:25:27 -0700 Subject: [PATCH 11/20] Update comfy-kitchen package version to 0.2.28 (#15407) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fb0261a9d..771504af4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,7 +22,7 @@ alembic SQLAlchemy>=2.0.0 filelock av>=16.0.0 -comfy-kitchen==0.2.27 +comfy-kitchen==0.2.28 comfy-aimdo==0.4.13 requests simpleeval>=1.0.0 From 43cb4fffc89bba20ab7bd61467a36d0339338dab Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Fri, 7 Aug 2026 18:29:35 -0400 Subject: [PATCH 12/20] ComfyUI v0.31.0 --- comfyui_version.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/comfyui_version.py b/comfyui_version.py index 3f7ec33bc..7358bab8f 100644 --- a/comfyui_version.py +++ b/comfyui_version.py @@ -1,3 +1,3 @@ # This file is automatically generated by the build process when version is # updated in pyproject.toml. -__version__ = "0.30.0" +__version__ = "0.31.0" diff --git a/pyproject.toml b/pyproject.toml index 4e71b2db6..4f80dc5cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "ComfyUI" -version = "0.30.0" +version = "0.31.0" readme = "README.md" license = { file = "LICENSE" } requires-python = ">=3.10" From cd84f47efe4aedd4e2b97370c21a07db9e50bc96 Mon Sep 17 00:00:00 2001 From: comfyanonymous <121283862+comfyanonymous@users.noreply.github.com> Date: Fri, 7 Aug 2026 19:14:04 -0700 Subject: [PATCH 13/20] Make it easier to debug nested tensors. (#15383) --- comfy/nested_tensor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/comfy/nested_tensor.py b/comfy/nested_tensor.py index 08c7133f8..43835b15f 100644 --- a/comfy/nested_tensor.py +++ b/comfy/nested_tensor.py @@ -83,6 +83,9 @@ class NestedTensor: def layout(self): return self.tensors[0].layout + def __repr__(self): + return f"{type(self).__name__}({self.tensors!r})" + def cat_nested(tensors, *args, **kwargs): cated_tensors = [] From 5599a05fea715cb2aff11f30f5b06e16d0dfa0c4 Mon Sep 17 00:00:00 2001 From: "Daxiong (Lin)" Date: Sat, 8 Aug 2026 10:27:21 +0800 Subject: [PATCH 14/20] chore: update workflow templates to v0.11.37 (#15415) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 771504af4..94cd1c5eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ comfyui-frontend-package==1.48.7 -comfyui-workflow-templates==0.11.34 +comfyui-workflow-templates==0.11.37 comfyui-embedded-docs==0.5.9 torch torchsde From dd79c643a95402136a75a28f6187d843bcf457ed Mon Sep 17 00:00:00 2001 From: comfyanonymous <121283862+comfyanonymous@users.noreply.github.com> Date: Fri, 7 Aug 2026 23:12:21 -0700 Subject: [PATCH 15/20] Minimum officially supported pytorch is now 2.7 (#15413) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8830b62ce..1721cefa5 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ Python 3.14 works but some custom nodes may have issues. The free threaded varia Python 3.13 is very well supported. If you have trouble with some custom node dependencies on 3.13 you can try 3.12 -torch 2.5 is minimally supported but using a newer version is extremely recommended. Some features and optimizations might only work on newer versions. We generally recommend using the latest major version of pytorch with the latest cuda version unless it is less than 2 weeks old. If your pytorch is more than 6 months old, please update it. +torch 2.7 is minimally supported but using a newer version is extremely recommended. Using a cu130 or above version of pytorch is required on Nvidia 20 series and above. Some features and optimizations might only work on newer versions. We generally recommend using the latest major version of pytorch with the latest cuda version unless it is less than 2 weeks old. If your pytorch is more than 6 months old, please update it. ### Instructions: From 00d02f2854892ee5b9808bc2f6348b972017886a Mon Sep 17 00:00:00 2001 From: Terry Jia Date: Sat, 8 Aug 2026 13:50:09 -0400 Subject: [PATCH 16/20] fix: make Create Layered Image discoverable and its flags self-explanatory (#15429) --- comfy_extras/nodes_compositor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/comfy_extras/nodes_compositor.py b/comfy_extras/nodes_compositor.py index 10cea3adc..f66a9feab 100644 --- a/comfy_extras/nodes_compositor.py +++ b/comfy_extras/nodes_compositor.py @@ -486,7 +486,10 @@ class ImageCompositor(io.ComfyNode): node_id="ImageCompositor", display_name="Create Layered Image", category="image", + search_aliases=["compositor", "composite", "layer", "layers", "layer editor", "psd"], is_experimental=True, + # both flags on purpose: terminal compositor graphs must execute (the + # editor needs a run to open), and cache hits must replay the layer UI is_output_node=True, has_intermediate_output=True, inputs=[ @@ -605,7 +608,7 @@ class AddLayer(io.ComfyNode): options=list(_LAYER_MODES), default="normal", optional=True, - tooltip="Initial blend mode.", + tooltip="Initial blend mode, applied against the layers below. On the bottom layer over the default transparent background, non-normal modes produce transparency.", ), io.Float.Input( "rotation", From 9eaba63e1a9f2b27701cf0a0694aeed777da42f5 Mon Sep 17 00:00:00 2001 From: comfyanonymous <121283862+comfyanonymous@users.noreply.github.com> Date: Sat, 8 Aug 2026 14:51:05 -0700 Subject: [PATCH 17/20] Fix upscale models breaking on non dynamic vram low vram. (#15437) --- comfy_extras/nodes_upscale_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comfy_extras/nodes_upscale_model.py b/comfy_extras/nodes_upscale_model.py index a4d692955..d1e0401b9 100644 --- a/comfy_extras/nodes_upscale_model.py +++ b/comfy_extras/nodes_upscale_model.py @@ -72,7 +72,7 @@ class ImageUpscaleWithModel(io.ComfyNode): memory_required = (512 * 512 * 3) * image.element_size() * max(upscale_model.scale, 1.0) * 384.0 #The 384.0 is an estimate of how much some of these models take, TODO: make it more accurate memory_required += image.nelement() * image.element_size() - model_management.load_models_gpu([upscale_model.patcher], memory_required=memory_required) + model_management.load_models_gpu([upscale_model.patcher], memory_required=memory_required, force_full_load=True) in_img = image.movedim(-1,-3).to(device) From a683fa6e577f3f73ab8a0b4d7434173ccaec9c12 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Sat, 8 Aug 2026 18:06:03 -0700 Subject: [PATCH 18/20] Add previewable_outputs_count to /api/jobs (backend half of Media Assets badge fix) (#15148) --- comfy_execution/jobs.py | 30 +++++++++ tests/execution/test_jobs.py | 123 +++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) diff --git a/comfy_execution/jobs.py b/comfy_execution/jobs.py index 34c06363b..60f9b8f90 100644 --- a/comfy_execution/jobs.py +++ b/comfy_execution/jobs.py @@ -197,6 +197,7 @@ def normalize_queue_item(item: tuple, status: str) -> dict: 'priority': priority, 'create_time': create_time, 'outputs_count': 0, + 'previewable_outputs_count': 0, 'workflow_id': workflow_id, }) @@ -215,6 +216,7 @@ def normalize_history_item(prompt_id: str, history_item: dict, include_outputs: outputs = history_item.get('outputs', {}) outputs_count, preview_output = get_outputs_summary(outputs) + previewable_outputs_count = count_previewable_outputs(outputs) execution_error = None execution_start_time = None @@ -251,6 +253,7 @@ def normalize_history_item(prompt_id: str, history_item: dict, include_outputs: 'execution_end_time': execution_end_time, 'execution_error': execution_error, 'outputs_count': outputs_count, + 'previewable_outputs_count': previewable_outputs_count, 'preview_output': preview_output, 'workflow_id': workflow_id, }) @@ -345,6 +348,33 @@ def get_outputs_summary(outputs: dict) -> tuple[int, Optional[dict]]: return count, preview_output or fallback_preview or text_file_fallback or text_fallback +def count_previewable_outputs(outputs: dict) -> int: + """ + Count only outputs that would actually render in the expanded asset view, + i.e. items is_previewable() accepts (image/video/audio/3D/text). Kept + separate from get_outputs_summary()'s outputs_count, which counts every + output item regardless of media type, so a job with a non-previewable + saved file alongside real media (e.g. SaveLatent's .latent output next to + a SaveImage output) doesn't inflate the Media Assets badge beyond what + the expanded view shows. + """ + count = 0 + for node_outputs in outputs.values(): + if not isinstance(node_outputs, dict): + continue + for media_type, items in node_outputs.items(): + if media_type == 'animated' or not isinstance(items, list): + continue + for item in items: + if not isinstance(item, dict): + item = normalize_output_item(item) + if item is None: + continue + if is_previewable(media_type, item): + count += 1 + return count + + def apply_sorting(jobs: list[dict], sort_by: str, sort_order: str) -> list[dict]: """Sort jobs list by specified field and order.""" reverse = (sort_order == 'desc') diff --git a/tests/execution/test_jobs.py b/tests/execution/test_jobs.py index cef2b41cb..ffa069435 100644 --- a/tests/execution/test_jobs.py +++ b/tests/execution/test_jobs.py @@ -10,6 +10,7 @@ from comfy_execution.jobs import ( normalize_output_item, normalize_outputs, get_outputs_summary, + count_previewable_outputs, apply_sorting, has_3d_extension, validate_job_id, @@ -361,6 +362,79 @@ class TestGetOutputsSummary: assert preview['mediaType'] == 'files' +class TestCountPreviewableOutputs: + """Unit tests for count_previewable_outputs() + + Kept separate from get_outputs_summary()'s outputs_count: the Media Assets + badge should reflect only what the expanded asset view actually renders + (previewable outputs), while outputs_count keeps counting every output + item for other consumers. + """ + + def test_empty_outputs(self): + assert count_previewable_outputs({}) == 0 + + def test_previewable_outputs_all_counted(self): + """When every output is previewable, the two counts should match.""" + outputs = { + 'node1': {'images': [{'filename': 'a.png', 'type': 'output'}]}, + 'node2': {'images': [{'filename': 'b.png', 'type': 'output'}]}, + } + outputs_count, _ = get_outputs_summary(outputs) + assert count_previewable_outputs(outputs) == outputs_count == 2 + + def test_save_latent_counted_but_not_previewable(self): + """SaveLatent (nodes.py) emits a real saved file under the 'latents' + media type: {'latents': [{'filename': '..._00001_.latent', + 'subfolder': '', 'type': 'output'}]}. It has no previewable media + type, format, or extension, so it inflates outputs_count without + ever rendering in the expanded asset view.""" + outputs = { + 'node1': { + 'images': [{'filename': 'ComfyUI_00001_.png', 'subfolder': '', 'type': 'output'}] + }, + 'node2': { + 'latents': [{'filename': 'ComfyUI_00001_.latent', 'subfolder': '', 'type': 'output'}] + }, + } + outputs_count, _ = get_outputs_summary(outputs) + assert outputs_count == 2 + assert count_previewable_outputs(outputs) == 1 + + def test_save_text_file_output_is_previewable_by_extension(self): + """SaveText (comfy_extras/nodes_text.py) emits its saved file under a + 'files' media type via ui.SavedResult: {'files': [{'filename': + '..._00001.txt', 'subfolder': ..., 'type': 'output'}]}. The .txt + extension makes it previewable even though 'files' itself isn't a + previewable media type.""" + outputs = { + 'node1': { + 'files': [{'filename': 'ComfyUI_00001.txt', 'subfolder': '', 'type': 'output'}] + } + } + assert count_previewable_outputs(outputs) == 1 + + def test_preview_any_text_tuple_not_counted(self): + """PreviewAny (comfy_extras/nodes_preview_any.py) emits only + {'text': (value,)} with no saved file. Since the value is a tuple, + not a list, it is excluded from both outputs_count and + previewable_outputs_count — matching get_outputs_summary().""" + outputs = { + 'node1': {'text': ('some previewed value',)} + } + outputs_count, _ = get_outputs_summary(outputs) + assert outputs_count == 0 + assert count_previewable_outputs(outputs) == 0 + + def test_string_3d_filename_previewable(self): + """String 3D filenames (e.g. Preview3D) normalize into a previewable + item just like they do for outputs_count.""" + outputs = { + 'node1': {'result': ['preview3d_abc123.glb', None]} + } + assert count_previewable_outputs(outputs) == 1 + + class TestHas3DExtension: """Unit tests for has_3d_extension()""" @@ -447,6 +521,7 @@ class TestNormalizeQueueItem: assert 'execution_error' not in job assert 'preview_output' not in job assert job['outputs_count'] == 0 + assert job['previewable_outputs_count'] == 0 assert job['workflow_id'] == 'workflow-abc' @@ -635,6 +710,54 @@ class TestNormalizeHistoryItem: {'filename': 'photo.png', 'type': 'output', 'subfolder': ''}, ] + def test_previewable_outputs_count_excludes_non_previewable_outputs(self): + """Regression test for the Media Assets badge overcount: a job with an + image (SaveImage) and a SaveLatent output should report previewable_ + outputs_count == 1 while outputs_count == 2, so the frontend badge + (once switched to previewable_outputs_count) matches what the + expanded asset view actually renders.""" + history_item = { + 'prompt': ( + 5, + 'prompt-mixed', + {'nodes': {}}, + {'create_time': 1234567890}, + ['node1', 'node2'], + ), + 'status': {'status_str': 'success', 'completed': True, 'messages': []}, + 'outputs': { + 'node1': { + 'images': [{'filename': 'ComfyUI_00001_.png', 'subfolder': '', 'type': 'output'}] + }, + 'node2': { + 'latents': [{'filename': 'ComfyUI_00001_.latent', 'subfolder': '', 'type': 'output'}] + }, + }, + } + job = normalize_history_item('prompt-mixed', history_item) + + assert job['outputs_count'] == 2 + assert job['previewable_outputs_count'] == 1 + + def test_previewable_outputs_count_zero_pruned_by_prune_dict(self): + """A job with no outputs at all should still report both counts as 0, + not omit the field (prune_dict only strips None, not 0).""" + history_item = { + 'prompt': ( + 5, + 'prompt-empty', + {'nodes': {}}, + {'create_time': 1234567890}, + ['node1'], + ), + 'status': {'status_str': 'success', 'completed': True, 'messages': []}, + 'outputs': {}, + } + job = normalize_history_item('prompt-empty', history_item) + + assert job['outputs_count'] == 0 + assert job['previewable_outputs_count'] == 0 + class TestNormalizeOutputItem: """Unit tests for normalize_output_item()""" From 40e46c711025947f126cccaa1a692a14937a3096 Mon Sep 17 00:00:00 2001 From: chaObserv <154517000+chaObserv@users.noreply.github.com> Date: Sun, 9 Aug 2026 10:06:12 +0800 Subject: [PATCH 19/20] Extend ER-SDE noise scaler by scaling h(t) (#15428) --- comfy_extras/nodes_custom_sampler.py | 36 +++++++++++++++++++--------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/comfy_extras/nodes_custom_sampler.py b/comfy_extras/nodes_custom_sampler.py index e81b6328b..d5aa730d2 100644 --- a/comfy_extras/nodes_custom_sampler.py +++ b/comfy_extras/nodes_custom_sampler.py @@ -591,7 +591,7 @@ class SamplerER_SDE(io.ComfyNode): inputs=[ io.Combo.Input("solver_type", options=["ER-SDE", "Reverse-time SDE", "ODE"]), io.Int.Input("max_stage", default=3, min=1, max=3, advanced=True), - io.Float.Input("eta", default=1.0, min=0.0, max=100.0, step=0.01, round=False, tooltip="Stochastic strength of reverse-time SDE.\nWhen eta=0, it reduces to deterministic ODE. This setting doesn't apply to ER-SDE solver type.", advanced=True), + io.Float.Input("eta", default=1.0, min=0.0, max=10.0, step=0.01, round=False, tooltip="Stochastic strength of SDEs.\nWhen eta=0, they reduce to deterministic ODE.\nLarge eta may cause invalid outputs. If this occurs, try decreasing this value.", advanced=True), io.Float.Input("s_noise", default=1.0, min=0.0, max=100.0, step=0.01, round=False, advanced=True), ], outputs=[io.Sampler.Output()] @@ -599,21 +599,35 @@ class SamplerER_SDE(io.ComfyNode): @classmethod def execute(cls, solver_type, max_stage, eta, s_noise) -> io.NodeOutput: - if solver_type == "ODE" or (solver_type == "Reverse-time SDE" and eta == 0): - eta = 0 - s_noise = 0 + # Extend existing noise scalers phi(x) with eta-controlled noise scalers: + # psi(x) = x**(1-eta) * phi(x)**eta + # where eta is constant and directly scales the h^2(t) contribution. - def reverse_time_sde_noise_scaler(x): + def er_sde_noise_scaler(x: torch.Tensor) -> torch.Tensor: + return x * ((x ** 0.3).exp() + 10.0) ** eta + + def reverse_time_sde_noise_scaler(x: torch.Tensor) -> torch.Tensor: return x ** (eta + 1) - if solver_type == "ER-SDE": - # Use the default one in sample_er_sde() - noise_scaler = None - else: - noise_scaler = reverse_time_sde_noise_scaler + def ode_noise_scaler(x: torch.Tensor) -> torch.Tensor: + return x + + solver_scalers = { + "ER-SDE": er_sde_noise_scaler, + "Reverse-time SDE": reverse_time_sde_noise_scaler, + "ODE": ode_noise_scaler, + } + + if solver_type == "ODE" or eta == 0: + s_noise = 0.0 + solver_type = "ODE" + noise_scaler = solver_scalers[solver_type] sampler_name = "er_sde" - sampler = comfy.samplers.ksampler(sampler_name, {"s_noise": s_noise, "noise_scaler": noise_scaler, "max_stage": max_stage}) + sampler = comfy.samplers.ksampler( + sampler_name, + {"s_noise": s_noise, "noise_scaler": noise_scaler, "max_stage": max_stage}, + ) return io.NodeOutput(sampler) get_sampler = execute From cbbc9dab1f03d0d9a6caa8a8be7d77a7e37e1e44 Mon Sep 17 00:00:00 2001 From: blepping <157360029+blepping@users.noreply.github.com> Date: Sat, 8 Aug 2026 20:38:34 -0600 Subject: [PATCH 20/20] Make a context manager for cast_bias_weight and use it. (#14750) --- comfy/background_removal/birefnet.py | 23 ++- comfy/controlnet.py | 11 +- comfy/ops.py | 241 ++++++++++++--------------- comfy/text_encoders/llama.py | 14 +- 4 files changed, 124 insertions(+), 165 deletions(-) diff --git a/comfy/background_removal/birefnet.py b/comfy/background_removal/birefnet.py index 78a80246e..ba3f710d4 100644 --- a/comfy/background_removal/birefnet.py +++ b/comfy/background_removal/birefnet.py @@ -433,19 +433,16 @@ class DeformableConv2d(nn.Module): def forward(self, x): offset = self.offset_conv(x) modulator = 2. * torch.sigmoid(self.modulator_conv(x)) - weight, bias, offload_info = comfy.ops.cast_bias_weight(self.regular_conv, x, offloadable=True) - - x = deform_conv2d( - input=x, - offset=offset, - weight=weight, - bias=None, - padding=self.padding, - mask=modulator, - stride=self.stride, - ) - comfy.ops.uncast_bias_weight(self.regular_conv, weight, bias, offload_info) - return x + with comfy.ops.CastBiasWeightContext(self.regular_conv, x, offloadable=True) as (weight, _bias): + return deform_conv2d( + input=x, + offset=offset, + weight=weight, + bias=None, + padding=self.padding, + mask=modulator, + stride=self.stride, + ) class BasicDecBlk(nn.Module): def __init__(self, in_channels=64, out_channels=64, inter_channels=64, device=None, dtype=None, operations=None): diff --git a/comfy/controlnet.py b/comfy/controlnet.py index 6dbbaa959..7e35fe027 100644 --- a/comfy/controlnet.py +++ b/comfy/controlnet.py @@ -381,13 +381,10 @@ class ControlLoraOps: self.bias = None def forward(self, input): - weight, bias, offload_stream = comfy.ops.cast_bias_weight(self, input, offloadable=True) - if self.up is not None: - x = torch.nn.functional.linear(input, weight + (torch.mm(self.up.flatten(start_dim=1), self.down.flatten(start_dim=1))).reshape(self.weight.shape).type(input.dtype), bias) - else: - x = torch.nn.functional.linear(input, weight, bias) - comfy.ops.uncast_bias_weight(self, weight, bias, offload_stream) - return x + with comfy.ops.CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): + if self.up is None: + return torch.nn.functional.linear(input, weight, bias) + return torch.nn.functional.linear(input, weight + (torch.mm(self.up.flatten(start_dim=1), self.down.flatten(start_dim=1))).reshape(self.weight.shape).type(input.dtype), bias) class Conv2d(torch.nn.Module, comfy.ops.CastWeightBiasOp): def __init__( diff --git a/comfy/ops.py b/comfy/ops.py index 14599997b..9ec44cfa2 100644 --- a/comfy/ops.py +++ b/comfy/ops.py @@ -452,6 +452,26 @@ def uncast_bias_weight(s, weight, bias, offload_stream): device = bias_a.device os.wait_stream(comfy.model_management.current_stream(device)) +class CastBiasWeightContext: + # When initialized with no arguments or the first is None, the context + # will return the tuple (None, None). + def __init__(self, *args, **kwargs): + self.slf = args[0] if len(args) else None + self.state = (None, None) if self.slf is None else cast_bias_weight(*args, **kwargs) + + def __enter__(self): + result = self.state + if len(result) < 3 or result[2] is None: + # Not offloaded, immediately drop references. + self.state = self.slf = None + return result[:2] + + def __exit__(self, *_args) -> None: + if self.slf is None: + return + slf, state = self.slf, self.state + self.state = self.slf = None + uncast_bias_weight(slf, *state) class CastWeightBiasOp: comfy_cast_weights = False @@ -538,10 +558,8 @@ class disable_weight_init: return None def forward_comfy_cast_weights(self, input): - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - x = torch.nn.functional.linear(input, weight, bias) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): + return torch.nn.functional.linear(input, weight, bias) def forward(self, *args, **kwargs): run_every_op() @@ -555,10 +573,8 @@ class disable_weight_init: return None def forward_comfy_cast_weights(self, input): - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - x = self._conv_forward(input, weight, bias) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): + return self._conv_forward(input, weight, bias) def forward(self, *args, **kwargs): run_every_op() @@ -572,10 +588,8 @@ class disable_weight_init: return None def forward_comfy_cast_weights(self, input): - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - x = self._conv_forward(input, weight, bias) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): + return self._conv_forward(input, weight, bias) def forward(self, *args, **kwargs): run_every_op() @@ -600,10 +614,8 @@ class disable_weight_init: return super()._conv_forward(input, weight, bias, *args, **kwargs) def forward_comfy_cast_weights(self, input, autopad=None): - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - x = self._conv_forward(input, weight, bias, autopad=autopad) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): + return self._conv_forward(input, weight, bias, autopad=autopad) def forward(self, *args, **kwargs): run_every_op() @@ -617,10 +629,8 @@ class disable_weight_init: return None def forward_comfy_cast_weights(self, input): - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - x = torch.nn.functional.group_norm(input, self.num_groups, weight, bias, self.eps) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): + return torch.nn.functional.group_norm(input, self.num_groups, weight, bias, self.eps) def forward(self, *args, **kwargs): run_every_op() @@ -634,12 +644,10 @@ class disable_weight_init: return None def forward_comfy_cast_weights(self, input): - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - running_mean = self.running_mean.to(device=input.device, dtype=weight.dtype) if self.running_mean is not None else None - running_var = self.running_var.to(device=input.device, dtype=weight.dtype) if self.running_var is not None else None - x = torch.nn.functional.batch_norm(input, running_mean, running_var, weight, bias, self.training, self.momentum, self.eps) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): + running_mean = self.running_mean.to(device=input.device, dtype=weight.dtype) if self.running_mean is not None else None + running_var = self.running_var.to(device=input.device, dtype=weight.dtype) if self.running_var is not None else None + return torch.nn.functional.batch_norm(input, running_mean, running_var, weight, bias, self.training, self.momentum, self.eps) def forward(self, *args, **kwargs): run_every_op() @@ -653,15 +661,8 @@ class disable_weight_init: return None def forward_comfy_cast_weights(self, input): - if self.weight is not None: - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - else: - weight = None - bias = None - offload_stream = None - x = torch.nn.functional.layer_norm(input, self.normalized_shape, weight, bias, self.eps) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self if self.weight is not None else None, input, offloadable=True) as (weight, bias): + return torch.nn.functional.layer_norm(input, self.normalized_shape, weight, bias, self.eps) def forward(self, *args, **kwargs): run_every_op() @@ -676,15 +677,8 @@ class disable_weight_init: return None def forward_comfy_cast_weights(self, input): - if self.weight is not None: - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - else: - weight = None - bias = None - offload_stream = None - x = torch.nn.functional.rms_norm(input, self.normalized_shape, weight, self.eps) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self if self.weight is not None else None, input, offloadable=True) as (weight, bias): + return torch.nn.functional.rms_norm(input, self.normalized_shape, weight, self.eps) def forward(self, *args, **kwargs): run_every_op() @@ -703,12 +697,10 @@ class disable_weight_init: input, output_size, self.stride, self.padding, self.kernel_size, num_spatial_dims, self.dilation) - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - x = torch.nn.functional.conv_transpose2d( - input, weight, bias, self.stride, self.padding, - output_padding, self.groups, self.dilation) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): + return torch.nn.functional.conv_transpose2d( + input, weight, bias, self.stride, self.padding, + output_padding, self.groups, self.dilation) def forward(self, *args, **kwargs): run_every_op() @@ -727,12 +719,10 @@ class disable_weight_init: input, output_size, self.stride, self.padding, self.kernel_size, num_spatial_dims, self.dilation) - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - x = torch.nn.functional.conv_transpose1d( - input, weight, bias, self.stride, self.padding, - output_padding, self.groups, self.dilation) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): + return torch.nn.functional.conv_transpose1d( + input, weight, bias, self.stride, self.padding, + output_padding, self.groups, self.dilation) def forward(self, *args, **kwargs): run_every_op() @@ -795,10 +785,8 @@ class disable_weight_init: output_dtype = out_dtype if self.weight.dtype == torch.float16 or self.weight.dtype == torch.bfloat16: out_dtype = None - weight, bias, offload_stream = cast_bias_weight(self, device=input.device, dtype=out_dtype, offloadable=True) - x = torch.nn.functional.embedding(input, weight, self.padding_idx, self.max_norm, self.norm_type, self.scale_grad_by_freq, self.sparse).to(dtype=output_dtype) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self, device=input.device, dtype=out_dtype, offloadable=True) as (weight, bias): + return torch.nn.functional.embedding(input, weight, self.padding_idx, self.max_norm, self.norm_type, self.scale_grad_by_freq, self.sparse).to(dtype=output_dtype) def forward(self, *args, **kwargs): @@ -874,7 +862,6 @@ def fp8_linear(self, input): if input.ndim != 2: return None lora_compute_dtype=comfy.model_management.lora_compute_dtype(input.device) - w, bias, offload_stream = cast_bias_weight(self, input, dtype=dtype, bias_dtype=input_dtype, offloadable=True, compute_dtype=lora_compute_dtype, want_requant=True) scale_weight = torch.ones((), device=input.device, dtype=torch.float32) scale_input = torch.ones((), device=input.device, dtype=torch.float32) @@ -883,15 +870,16 @@ def fp8_linear(self, input): layout_params_input = TensorCoreFP8Layout.Params(scale=scale_input, orig_dtype=input_dtype, orig_shape=tuple(input_fp8.shape)) quantized_input = QuantizedTensor(input_fp8, "TensorCoreFP8Layout", layout_params_input) - # Wrap weight in QuantizedTensor - this enables unified dispatch - # Call F.linear - __torch_dispatch__ routes to fp8_linear handler in quant_ops.py! - layout_params_weight = TensorCoreFP8Layout.Params(scale=scale_weight, orig_dtype=input_dtype, orig_shape=tuple(w.shape)) - quantized_weight = QuantizedTensor(w, "TensorCoreFP8Layout", layout_params_weight) - o = torch.nn.functional.linear(quantized_input, quantized_weight, bias) + with CastBiasWeightContext(self, input, dtype=dtype, bias_dtype=input_dtype, offloadable=True, compute_dtype=lora_compute_dtype, want_requant=True) as (w, bias): + # Wrap weight in QuantizedTensor - this enables unified dispatch + # Call F.linear - __torch_dispatch__ routes to fp8_linear handler in quant_ops.py! + w_shape = tuple(w.shape) + layout_params_weight = TensorCoreFP8Layout.Params(scale=scale_weight, orig_dtype=input_dtype, orig_shape=w_shape) + quantized_weight = QuantizedTensor(w, "TensorCoreFP8Layout", layout_params_weight) + o = torch.nn.functional.linear(quantized_input, quantized_weight, bias) - uncast_bias_weight(self, w, bias, offload_stream) if tensor_3d: - o = o.reshape((input_shape[0], input_shape[1], w.shape[0])) + o = o.reshape((input_shape[0], input_shape[1], w_shape[0])) return o @@ -911,10 +899,8 @@ class fp8_ops(manual_cast): except Exception as e: logging.info("Exception during fp8 op: {}".format(e)) - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - x = torch.nn.functional.linear(input, weight, bias) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): + return torch.nn.functional.linear(input, weight, bias) CUBLAS_IS_AVAILABLE = False try: @@ -930,10 +916,8 @@ if CUBLAS_IS_AVAILABLE: return None def forward_comfy_cast_weights(self, input): - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - x = cublas_half_matmul(input, weight, bias, self._epilogue_str, self.has_bias) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + with CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): + return cublas_half_matmul(input, weight, bias, self._epilogue_str, self.has_bias) def forward(self, *args, **kwargs): run_every_op() @@ -1344,29 +1328,28 @@ def mixed_precision_ops(quant_config={}, compute_dtype=torch.bfloat16, full_prec want_requant=False, weight_only_quant=False, ): - if weight_only_quant: - weight, bias, offload_stream = cast_bias_weight( - self, - input=None, - dtype=self.weight.dtype, - device=input.device, - bias_dtype=input.dtype, - offloadable=True, - compute_dtype=compute_dtype, - want_requant=True, - ) - weight = weight.to(dtype=input.dtype) - else: - weight, bias, offload_stream = cast_bias_weight( + if not weight_only_quant: + with CastBiasWeightContext( self, input, offloadable=True, compute_dtype=compute_dtype, want_requant=want_requant, - ) - x = self._forward(input, weight, bias) - uncast_bias_weight(self, weight, bias, offload_stream) - return x + ) as (weight, bias): + return self._forward(input, weight, bias) + + with CastBiasWeightContext( + self, + input=None, + dtype=self.weight.dtype, + device=input.device, + bias_dtype=input.dtype, + offloadable=True, + compute_dtype=compute_dtype, + want_requant=True, + ) as (weight, bias): + weight = weight.to(dtype=input.dtype) + return self._forward(input, weight, bias) def forward(self, input, *args, **kwargs): run_every_op() @@ -1391,25 +1374,20 @@ def mixed_precision_ops(quant_config={}, compute_dtype=torch.bfloat16, full_prec # Training path: quantized forward with compute_dtype backward via autograd function if (input.requires_grad and _use_quantized and quantize_input): - - weight, bias, offload_stream = cast_bias_weight( + with CastBiasWeightContext( self, input, offloadable=True, compute_dtype=compute_dtype, want_requant=True - ) + ) as (weight, bias): + scale = getattr(self, 'input_scale', None) + if scale is not None: + scale = comfy.model_management.cast_to_device(scale, input.device, None) - scale = getattr(self, 'input_scale', None) - if scale is not None: - scale = comfy.model_management.cast_to_device(scale, input.device, None) - - output = QuantLinearFunc.apply( - input, weight, bias, self.layout_type, scale, compute_dtype - ) - - uncast_bias_weight(self, weight, bias, offload_stream) - return output + return QuantLinearFunc.apply( + input, weight, bias, self.layout_type, scale, compute_dtype + ) # Inference path (unchanged) if _use_quantized and quantize_input: @@ -1520,13 +1498,11 @@ def mixed_precision_ops(quant_config={}, compute_dtype=torch.bfloat16, full_prec """Cast the whole bank once; expert_linear inside reuses the cast. Not re-entrant — do not nest calls on the same instance. """ - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - self._resident_bank = (weight, bias) - try: - yield self - finally: - self._resident_bank = None - uncast_bias_weight(self, weight, bias, offload_stream) + with CastBiasWeightContext(self, input, offloadable=True) as self._resident_bank: + try: + yield self + finally: + self._resident_bank = None def expert_linear(self, input: torch.Tensor, i: int) -> torch.Tensor: """Linear against expert i's weight (with optional bias).""" @@ -1534,11 +1510,8 @@ def mixed_precision_ops(quant_config={}, compute_dtype=torch.bfloat16, full_prec if resident is not None: weight, bias = resident return self._expert_linear_impl(input, weight, bias, i) - weight, bias, offload_stream = cast_bias_weight(self, input, offloadable=True) - try: + with CastBiasWeightContext(self, input, offloadable=True) as (weight, bias): return self._expert_linear_impl(input, weight, bias, i) - finally: - uncast_bias_weight(self, weight, bias, offload_stream) def _expert_linear_impl(self, input, weight, bias, i): if isinstance(weight, QuantizedTensor): @@ -1641,25 +1614,23 @@ def mixed_precision_ops(quant_config={}, compute_dtype=torch.bfloat16, full_prec # Optimized path: lookup in fp8/int8, dequantize only the selected rows. if isinstance(weight, QuantizedTensor) and len(self.weight_function) == 0: - qdata, _, offload_stream = cast_bias_weight(self, device=input.device, dtype=weight.dtype, offloadable=True) - if isinstance(qdata, QuantizedTensor): - params = qdata._params - scale = params.scale - qdata = qdata._qdata - else: - params = weight._params - scale = None + with CastBiasWeightContext(self, device=input.device, dtype=weight.dtype, offloadable=True) as (qdata, _bias): + if isinstance(qdata, QuantizedTensor): + params = qdata._params + scale = params.scale + qdata = qdata._qdata + else: + params = weight._params + scale = None - # int8: per-row scale possible ConvRot, so let the layout do the gather - if self.quant_format == "int8_tensorwise": - x = get_layout_class(self.layout_type).dequantize_embedding(qdata, params, input) - uncast_bias_weight(self, qdata, None, offload_stream) - return x if out_dtype is None else x.to(dtype=out_dtype) + # int8: per-row scale possible ConvRot, so let the layout do the gather + if self.quant_format == "int8_tensorwise": + x = get_layout_class(self.layout_type).dequantize_embedding(qdata, params, input) + return x if out_dtype is None else x.to(dtype=out_dtype) - x = torch.nn.functional.embedding( - input, qdata, self.padding_idx, self.max_norm, - self.norm_type, self.scale_grad_by_freq, self.sparse) - uncast_bias_weight(self, qdata, None, offload_stream) + x = torch.nn.functional.embedding( + input, qdata, self.padding_idx, self.max_norm, + self.norm_type, self.scale_grad_by_freq, self.sparse) target_dtype = out_dtype if out_dtype is not None else weight._params.orig_dtype x = x.to(dtype=target_dtype) if scale is not None and scale != 1.0: diff --git a/comfy/text_encoders/llama.py b/comfy/text_encoders/llama.py index f5c5597ef..371ec1bbc 100644 --- a/comfy/text_encoders/llama.py +++ b/comfy/text_encoders/llama.py @@ -868,16 +868,10 @@ class BaseGenerate: else: module = self.model.embed_tokens - offload_stream = None - if module.comfy_cast_weights: - weight, _, offload_stream = comfy.ops.cast_bias_weight(module, input, offloadable=True) - else: - weight = self.model.embed_tokens.weight.to(x) - - x = torch.nn.functional.linear(input, weight, None) - - comfy.ops.uncast_bias_weight(module, weight, None, offload_stream) - return x + if not module.comfy_cast_weights: + return torch.nn.functional.linear(input, self.model.embed_tokens.weight.to(x), None) + with comfy.ops.CastBiasWeightContext(module, input, offloadable=True) as (weight, _bias): + return torch.nn.functional.linear(input, weight, None) def init_kv_cache(self, batch, max_cache_len, device, execution_dtype): model_config = self.model.config