;; Neon Glow effect - glowing edge effect
(require-primitives "image" "blending")

(define-effect neon_glow
  :params (
    (edge_low :type int :default 50 :range [10 200])
    (edge_high :type int :default 150 :range [50 300])
    (glow_radius :type int :default 15 :range [1 50])
    (glow_intensity :type int :default 2 :range [0.5 5])
    (background :type float :default 0.3 :range [0 1])
  )
  (let* ((edge-img (image:edge-detect frame edge_low edge_high))
         (glow (image:blur edge-img glow_radius))
         ;; Intensify the glow
         (bright-glow (map-pixels glow
                        (lambda (x y c)
                          (rgb (clamp (* (red c) glow_intensity) 0 255)
                               (clamp (* (green c) glow_intensity) 0 255)
                               (clamp (* (blue c) glow_intensity) 0 255))))))
    (blending:blend-mode (blending:blend-images frame (make-image (image:width frame) (image:height frame) (list 0 0 0))
                              (- 1 background))
                bright-glow
                "screen")))
