Extensions/Comfy-FilmSimulator
ComfyUI Extension

Comfy-FilmSimulator

ComfyUI node: realistic, adaptive film simulation for photographic and cinematic looks.

By zhuyanan·Created 7 months ago·Updated about a month ago· 1
zhuyanan/Comfy-FilmSimulator
Nodes5
On cloudLocal install
CategorySmartHDR
Stars1
Updatedabout a month ago
Readme

Comfy Film Simulator

A small toolkit and pipeline for applying film simulation to RAW/DNG images, producing both HDR and SDR outputs and optionally saving them in modern formats (AVIF/HEIC) with HDR metadata.


End-to-end pipeline (RAW → Film → Save)

This repository includes a convenient Film Pipeline node and helper nodes that make it easy to run the full workflow from a single node or chain the steps manually.

Key nodes

  • DNG Image Reader — Load a DNG/RAW file (supports linear HDR output).
  • Film Simulation V4.1 (HDR Capable) — Apply film simulation in a linear HDR workflow and generate an HDR image plus an SDR preview.
  • HDR Merge (Gainmap) — Compute a smooth gainmap from an SDR/HDR pair and merge to produce a final HDR image suitable for AVIF/HEIC export.
  • Save SDR Preview (PNG/JPEG) — Save the SDR preview (performs linear → sRGB conversion when requested).
  • Save AVIF/HEIC HDR (Native) — Save PQ-encoded AVIF/HEIC using Rec.2020 primaries and optional HDR metadata.
  • Film Pipeline (RAW → Film → Save) — One-node orchestration that reads RAW, applies film simulation, optionally merges SDR+HDR, and saves SDR/HDR files.

Typical interactive workflows

  • Manual (node graph):

    • DNG Image ReaderFilm Simulation V4.1 (HDR Capable)
      • connect preview_sdrSave SDR Preview (PNG/JPEG)
      • connect hdr_imageHDR Merge (Gainmap) (optional) → Save AVIF/HEIC HDR (Native)
  • One-click (single node):

    • Film Pipeline (RAW → Film → Save) — set dng_path or supply an image tensor, configure film and merge parameters, and enable save_sdr / save_hdr as needed.

Programmatic usage example

Below is an example of how to call the FilmPipelineNode programmatically (adjust paths and parameters to your setup):

from comfy_film_simulator.film_pipeline import FilmPipelineNode

pipeline = FilmPipelineNode()

hdr_out, sdr_preview, gainmap_vis, info = pipeline.run_pipeline(
    dng_path="/path/to/input.dng",
    image=None,
    film_preset="Kodak Portra 400",
    wb_temperature_K=5600,
    wb_tint=0.0,
    auto_exposure=True,
    exposure=0.0,
    effect_strength=1.0,
    grain_power=1.0,
    halation_power=1.0,
    local_contrast=0.0,
    is_linear_input=True,
    run_merge=True,
    merge_blur_radius=51,
    merge_max_gain=8.0,
    merge_mix=1.0,
    merge_smoothing_mode="guided",
    save_sdr=True,
    sdr_filename_prefix="preview",
    sdr_format="PNG",
    sdr_quality=95,
    apply_srgb_gamma=True,
    save_hdr=True,
    hdr_filename_prefix="hdr",
    hdr_format="AVIF",
    hdr_quality=90,
    ref_white_nits=203.0
)

print(info)

Notes & recommendations

  • Guided filter (edge-aware smoothing) is used by default for HDR merging when available (OpenCV contrib's ximgproc.guidedFilter). If that package is not available, the pipeline falls back to Gaussian smoothing.
  • The pipeline expects linear, scene-referred inputs for HDR processing. The SDR preview and Save SDR node will convert to sRGB for display when requested.
  • For HDR export, install pillow-heif (to enable HEIF/AVIF saving with Pillow). For guided filtering, install opencv-contrib-python to get the ximgproc module if you want edge-aware merging.

Attribution

The HDR merge and pipeline nodes were conceptually inspired by the projects below. This repository does not copy code verbatim from them; the implementations here are original and borrow only conceptual ideas.

  • https://github.com/jb-jrdn/Hdr-Gainmap
  • https://github.com/zidage/AlcedoStudio