Post Reply 

Is rippling animation reachable from scripts?

Jun 1, 2012, 11:49
Post: #1
Is rippling animation reachable from scripts?
The rippling animation (graphical menu: Filters -> Animation -> Rippling) is cool. I'd like to reach it from script (Scheme) but the interface seems to be only partially implemented. If this is the case, can I imitate the animation result by using other functional plug-ins, perhaps generating one frame at a time? In particular I see there is the function called plug-in-ripple which I suspect that, somehow, could do the job.
Also, the rippling animation function could be (guessing) nothing more than a simple combination of calls to other script-reachable functions without a local "custom" manipulation of the image. This way the animation function could be imitated by script.
Find all posts by this user
Quote this message in a reply
Jun 1, 2012, 12:36
Post: #2
RE: Is rippling animation reachable from scripts?
If you use the script-fu console browser, your will find this script/plugin is documented, see "script-fu-ripply-anim".

That filter is implemented in a 133-lines script (/usr/share/gimp/2.0/scripts/ripply-anim.scm on my Linux).

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Jun 1, 2012, 13:05
Post: #3
RE: Is rippling animation reachable from scripts?
I looked at the plug-in source and found that the interface documented by the script-fu console browser doesn't match the actual interface (there is no run-mode parameter). That was impeding me to make it work.
Find all posts by this user
Quote this message in a reply
Jun 1, 2012, 13:59
Post: #4
RE: Is rippling animation reachable from scripts?
That plug-in only works interactively: it unconditionally attaches the newly-generated image to a display and doesn't return the new image ID to the function caller, making scripting impossible.
I feel both these inconveniences can be addressed with a 2-to-3-lines crack, but unfortunately my Scheme knowledge approximates to zero.

Here is the original plug-in script, with bold commented the lines that have to be modified.

File: /usr/share/gimp/2.0/scripts/ripply-anim.scm Wrote:; "Rippling Image" animation generator (ripply-anim.scm)
; Adam D. Moss (adam@foxbox.org)
; 97/05/18
;
; Designed to be used in conjunction with a plugin capable
; of saving animations (i.e. the GIF plugin).
;

(define (script-fu-ripply-anim img drawable displacement num-frames edge-type)

(define (copy-layer-ripple dest-image dest-drawable source-image source-drawable)
(gimp-selection-all dest-image)
(gimp-edit-clear dest-drawable)
(gimp-selection-none dest-image)
(gimp-selection-all source-image)
(gimp-edit-copy source-drawable)
(gimp-selection-none source-image)
(let ((floating-sel (car (gimp-edit-paste dest-drawable FALSE))))
(gimp-floating-sel-anchor (car (gimp-edit-paste dest-drawable FALSE)))
)
)

(let* (
(width (car (gimp-drawable-width drawable)))
(height (car (gimp-drawable-height drawable)))
(ripple-image (car (gimp-image-new width height GRAY)))
(ripple-layer (car (gimp-layer-new ripple-image width height GRAY-IMAGE "Ripple Texture" 100 NORMAL-MODE)))
(rippletiled-ret 0)
(rippletiled-image 0)
(rippletiled-layer 0)
(remaining-frames 0)
(xpos 0)
(ypos 0)
(xoffset 0)
(yoffset 0)
(dup-image 0)
(layer-name 0)
(this-image 0)
(this-layer 0)
(dup-layer 0)
)

(gimp-context-push)

; this script generates its own displacement map

(gimp-image-undo-disable ripple-image)
(gimp-context-set-background '(127 127 127))
(gimp-image-add-layer ripple-image ripple-layer 0)
(gimp-edit-fill ripple-layer BACKGROUND-FILL)
(plug-in-noisify RUN-NONINTERACTIVE ripple-image ripple-layer FALSE 1.0 1.0 1.0 0.0)
; tile noise
(set! rippletiled-ret (plug-in-tile RUN-NONINTERACTIVE ripple-image ripple-layer (* width 3) (* height 3) TRUE))
(gimp-image-undo-enable ripple-image)
(gimp-image-delete ripple-image)

(set! rippletiled-image (car rippletiled-ret))
(set! rippletiled-layer (cadr rippletiled-ret))
(gimp-image-undo-disable rippletiled-image)

; process tiled noise into usable displacement map
(plug-in-gauss-iir RUN-NONINTERACTIVE rippletiled-image rippletiled-layer 35 TRUE TRUE)
(gimp-equalize rippletiled-layer TRUE)
(plug-in-gauss-rle RUN-NONINTERACTIVE rippletiled-image rippletiled-layer 5 TRUE TRUE)
(gimp-equalize rippletiled-layer TRUE)

; displacement map is now in rippletiled-layer of rippletiled-image

; loop through the desired frames

(set! remaining-frames num-frames)
(set! xpos (/ width 2))
(set! ypos (/ height 2))
(set! xoffset (/ width num-frames))
(set! yoffset (/ height num-frames))

; the variable out-imagestack has to be returned back to the caller.
; perhaps its scope is to be changed
(let* ((out-imagestack (car (gimp-image-new width height RGB))))


(gimp-image-undo-disable out-imagestack)

(while (> remaining-frames 0)
(set! dup-image (car (gimp-image-duplicate rippletiled-image)))
(gimp-image-undo-disable dup-image)
(gimp-image-crop dup-image width height xpos ypos)

(set! layer-name (string-append "Frame "
(number->string (- num-frames remaining-frames) 10)
" (replace)"))
(set! this-layer (car (gimp-layer-new out-imagestack
width height RGB
layer-name 100 NORMAL-MODE)))
(gimp-image-add-layer out-imagestack this-layer 0)

(copy-layer-ripple out-imagestack this-layer img drawable)

(set! dup-layer (car (gimp-image-get-active-layer dup-image)))
(plug-in-displace RUN-NONINTERACTIVE out-imagestack this-layer
displacement displacement
TRUE TRUE dup-layer dup-layer edge-type)

(gimp-image-undo-enable dup-image)
(gimp-image-delete dup-image)

(set! remaining-frames (- remaining-frames 1))
(set! xpos (+ xoffset xpos))
(set! ypos (+ yoffset ypos))
)

(gimp-image-undo-enable rippletiled-image)
(gimp-image-delete rippletiled-image)
(gimp-image-undo-enable out-imagestack)
(gimp-display-new out-imagestack)); this line deleted

(gimp-context-pop)
)
; I believe here should go the return variable, somehow
)

(script-fu-register "script-fu-ripply-anim"
_"_Rippling..."
_"Create a multi-layer image by adding a ripple effect to the current image"
"Adam D. Moss (adam@foxbox.org)"
"Adam D. Moss"
"1997"
"RGB* GRAY*"
SF-IMAGE "Image to animage" 0
SF-DRAWABLE "Drawable to animate" 0
SF-ADJUSTMENT _"Rippling strength" '(3 0 256 1 10 1 0)
SF-ADJUSTMENT _"Number of frames" '(15 0 256 1 10 0 1)
SF-OPTION _"Edge behavior" '(_"Wrap" _"Smear" _"Black")
)

(script-fu-menu-register "script-fu-ripply-anim"
"<Image>/Filters/Animation/Animators")

[/quote
]
Find all posts by this user
Quote this message in a reply
Jun 1, 2012, 17:21
Post: #5
RE: Is rippling animation reachable from scripts?
After too many hours wasted, I converted the script-fu to reply the return value for the ID of the newly created image, so you can make rippling animations from scripts. And this is completely non-interactive.

Code:
; "Rippling Image" animation generator (ripply-anim.scm)
; Adam D. Moss (adam@foxbox.org)
; 97/05/18

(define output-out-imagestack 0)
(define (script-fu-ripply-anim img drawable displacement num-frames edge-type)

  (define (copy-layer-ripple dest-image dest-drawable source-image source-drawable)
    (gimp-selection-all dest-image)
    (gimp-edit-clear dest-drawable)
    (gimp-selection-none dest-image)
    (gimp-selection-all source-image)
    (gimp-edit-copy source-drawable)
    (gimp-selection-none source-image)
    (let ((floating-sel (car (gimp-edit-paste dest-drawable FALSE))))
      (gimp-floating-sel-anchor (car (gimp-edit-paste dest-drawable FALSE)))
    )
  )

  (let* (
        (width (car (gimp-drawable-width drawable)))
        (height (car (gimp-drawable-height drawable)))
        (ripple-image (car (gimp-image-new width height GRAY)))
        (ripple-layer (car (gimp-layer-new ripple-image width height GRAY-IMAGE "Ripple Texture" 100 NORMAL-MODE)))
        (rippletiled-ret 0)
        (rippletiled-image 0)
        (rippletiled-layer 0)
        (remaining-frames 0)
        (xpos 0)
        (ypos 0)
        (xoffset 0)
        (yoffset 0)
        (dup-image 0)
        (layer-name 0)
        (this-image 0)
        (this-layer 0)
        (dup-layer 0)
        )

    (gimp-context-push)

    ; this script generates its own displacement map

    (gimp-image-undo-disable ripple-image)
    (gimp-context-set-background '(127 127 127))
    (gimp-image-add-layer ripple-image ripple-layer 0)
    (gimp-edit-fill ripple-layer BACKGROUND-FILL)
    (plug-in-noisify RUN-NONINTERACTIVE ripple-image ripple-layer FALSE 1.0 1.0 1.0 0.0)
    ; tile noise
    (set! rippletiled-ret (plug-in-tile RUN-NONINTERACTIVE ripple-image ripple-layer (* width 3) (* height 3) TRUE))
    (gimp-image-undo-enable ripple-image)
    (gimp-image-delete ripple-image)

    (set! rippletiled-image (car rippletiled-ret))
    (set! rippletiled-layer (cadr rippletiled-ret))
    (gimp-image-undo-disable rippletiled-image)

    ; process tiled noise into usable displacement map
    (plug-in-gauss-iir RUN-NONINTERACTIVE rippletiled-image rippletiled-layer 35 TRUE TRUE)
    (gimp-equalize rippletiled-layer TRUE)
    (plug-in-gauss-rle RUN-NONINTERACTIVE rippletiled-image rippletiled-layer 5 TRUE TRUE)
    (gimp-equalize rippletiled-layer TRUE)

    ; displacement map is now in rippletiled-layer of rippletiled-image

    ; loop through the desired frames

    (set! remaining-frames num-frames)
    (set! xpos (/ width 2))
    (set! ypos (/ height 2))
    (set! xoffset (/ width num-frames))
    (set! yoffset (/ height num-frames))

    (let* ((out-imagestack (car (gimp-image-new width height RGB))))
    (set! output-out-imagestack out-imagestack)

    (gimp-image-undo-disable out-imagestack)

    (while (> remaining-frames 0)
      (set! dup-image (car (gimp-image-duplicate rippletiled-image)))
      (gimp-image-undo-disable dup-image)
      (gimp-image-crop dup-image width height xpos ypos)

      (set! layer-name (string-append "Frame "
                 (number->string (- num-frames remaining-frames) 10)
                 " (replace)"))
      (set! this-layer (car (gimp-layer-new out-imagestack
                                            width height RGB
                                            layer-name 100 NORMAL-MODE)))
      (gimp-image-add-layer out-imagestack this-layer 0)

      (copy-layer-ripple out-imagestack this-layer img drawable)

      (set! dup-layer (car (gimp-image-get-active-layer dup-image)))
      (plug-in-displace RUN-NONINTERACTIVE out-imagestack this-layer
                        displacement displacement
                        TRUE TRUE dup-layer dup-layer edge-type)

      (gimp-image-undo-enable dup-image)
      (gimp-image-delete dup-image)

      (set! remaining-frames (- remaining-frames 1))
      (set! xpos (+ xoffset xpos))
      (set! ypos (+ yoffset ypos))
    )

    (gimp-image-undo-enable rippletiled-image)
    (gimp-image-delete rippletiled-image)
    (gimp-image-undo-enable out-imagestack)

    (gimp-context-pop)
  )
  output-out-imagestack
)

Note: Never than before I hated Lisp and friends like now.
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Request for these animation scipts/links Harbinger 0 185 Sep 7, 2014 18:52
Last Post: Harbinger
  Seamless animation loop - script needed Harbinger 2 868 Sep 7, 2014 18:41
Last Post: Harbinger
  Scripts on making gore maps Elite Warrior 2 879 Aug 19, 2014 20:22
Last Post: winski
  Debugging Scripts gfb 10 763 Apr 30, 2014 21:21
Last Post: ofnuts
  pythons scripts do not appear michelk 4 436 Mar 2, 2014 20:04
Last Post: ofnuts

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS