;; Mirror effect - mirrors half of image
(require-primitives "geometry" "image")

(define-effect mirror
  :params (
    (mode :type string :default "left_right")
  )
  (let* ((w (image:width frame))
         (h (image:height frame))
         (hw (floor (/ w 2)))
         (hh (floor (/ h 2))))
    (cond
      ((= mode "left_right")
       (let ((left (image:crop frame 0 0 hw h))
             (result (copy frame)))
         (paste result (geometry:flip-img left "horizontal") hw 0)))

      ((= mode "right_left")
       (let ((right (image:crop frame hw 0 hw h))
             (result (copy frame)))
         (paste result (geometry:flip-img right "horizontal") 0 0)))

      ((= mode "top_bottom")
       (let ((top (image:crop frame 0 0 w hh))
             (result (copy frame)))
         (paste result (geometry:flip-img top "vertical") 0 hh)))

      ((= mode "bottom_top")
       (let ((bottom (image:crop frame 0 hh w hh))
             (result (copy frame)))
         (paste result (geometry:flip-img bottom "vertical") 0 0)))

      (else frame))))
