difference-clouds.scm 3.08 KB
Newer Older
1 2 3
; Plugin for the GNU Image Manipulation Program
; Copyright (C) 2006 Martin Nordholts
;
4
; This program is free software: you can redistribute it and/or modify
5
; it under the terms of the GNU General Public License as published by
6
; the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
15
; along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
;
; Renders Difference Clouds onto a layer, i.e. solid noise merged down with the
; Difference Mode
;

(define (script-fu-difference-clouds image
                                     drawable)

  (let* ((draw-offset-x (car (gimp-drawable-offsets drawable)))
         (draw-offset-y (cadr (gimp-drawable-offsets drawable)))
         (has-sel       (car (gimp-drawable-mask-intersect drawable)))
         (sel-offset-x  (cadr (gimp-drawable-mask-intersect drawable)))
         (sel-offset-y  (caddr (gimp-drawable-mask-intersect drawable)))
         (width         (cadddr (gimp-drawable-mask-intersect drawable)))
         (height        (caddr (cddr (gimp-drawable-mask-intersect drawable))))
         (type          (car (gimp-drawable-type-with-alpha drawable)))
32
         (diff-clouds  -1)
33 34 35 36 37 38
         (offset-x      0)
         (offset-y      0)
        )

    (gimp-image-undo-group-start image)

39 40
    ; Create the cloud layer
    (set! diff-clouds (car (gimp-layer-new image width height type
41
                                             "Clouds" 100 LAYER-MODE-DIFFERENCE)))
42

43
    ; Add the cloud layer above the current layer
44
    (gimp-image-insert-layer image diff-clouds 0 -1)
45 46

    ; Clear the layer (so there are no noise in it)
47
    (gimp-drawable-fill diff-clouds FILL-TRANSPARENT)
48

49
    ; Selections are relative to the drawable; adjust the final offset
50 51 52 53
    (set! offset-x (+ draw-offset-x sel-offset-x))
    (set! offset-y (+ draw-offset-y sel-offset-y))

    ; Offset the clouds layer
54
    (if (gimp-item-is-layer drawable)
55
      (gimp-item-transform-translate diff-clouds offset-x offset-y))
56 57

    ; Show the solid noise dialog
58
    (plug-in-solid-noise SF-RUN-MODE image diff-clouds 0 0 0 1 4.0 4.0)
59 60 61 62 63

    ; Merge the clouds layer with the layer below
    (gimp-image-merge-down image diff-clouds EXPAND-AS-NECESSARY)

    (gimp-image-undo-group-end image)
64 65

    (gimp-displays-flush)
66 67 68 69 70 71 72 73 74 75 76 77 78 79
  )
)

(script-fu-register "script-fu-difference-clouds"
                    _"Difference Clouds..."
                    _"Solid noise applied with Difference layer mode"
                    "Martin Nordholts <enselic@hotmail.com>"
                    "Martin Nordholts"
                    "2006/10/25"
                    "RGB* GRAY*"
                    SF-IMAGE       "Image"           0
                    SF-DRAWABLE    "Drawable"        0)

(script-fu-menu-register "script-fu-difference-clouds"
80
			 "<Image>/Filters/Render/Noise")