;;; Plugin  : Lizard-Breath-v-2.0_RD.scm (for lack of a better name)
;;; Author  : Rod Detmer
;;; Date    : August 15th 2012
;;; Revision: v-02
;;; 	Graechan added shine.scm effect to the filter making it much better				
;;; Version : v-02
;;; Latest version at: http://www.gimpchat.com
;;; Required : Gimp 2.8 or later
;;;
;;; Description: 
;;; Creates a reptile text effect on a user created selected text layer
;;; -----------------------------------------------------------------------------
;;; Change Log:
;;; Version-2.0
;;; Graechan added shine to filter
;;;
; Information can be found at http://www.gimpchat.com or http://www.simplygimp.com
;
; License: GPLv3
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (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.
;
; To view a copy of the GNU General Public License
; visit: http://www.gnu.org/licenses/gpl.html

(define (script-fu-lizard-breath image layer ScaleSize ScaleShape)
  (gimp-image-undo-group-start image)
  (gimp-image-select-item image 0 layer)
  (gimp-context-set-foreground '(35 115 10))
  (gimp-context-set-background '(0 0 0))   
  (gimp-edit-fill layer 0)
  (gimp-layer-resize-to-image-size layer)
  (plug-in-mosaic RUN-NONINTERACTIVE image layer ScaleSize 4 2 0.6 0 120 0.2 0 0 ScaleShape 0 1) 
  (gimp-by-color-select layer '(35 115 10) 15 0 1 0 0 1)
  (plug-in-emboss RUN-NONINTERACTIVE image layer 120 30 5 0)
  (gimp-selection-none image)
  (plug-in-neon RUN-NONINTERACTIVE image layer 1.75 0.25)
  (gimp-context-set-background '(255 255 255))
  (gimp-context-set-foreground '(0 0 0))
  (gimp-image-select-item image 0 layer) 
  (gimp-selection-grow image 2)
  (gimp-selection-border image 2)
  (gimp-context-set-background '(0 0 0))
  (gimp-context-set-foreground '(200 215 20)) 
  (gimp-edit-fill layer 0)   
  (python-layer-fx-drop-shadow 1 image layer '(0 0 0) 69 0 0 0 7 7 120 5 0 0)
  (gimp-context-set-background '(255 255 255))
  (gimp-context-set-foreground '(0 0 0)) 
  (gimp-selection-none image)
 
;;;;Shine added here
  (let* ((shadow-size 8) (shadow-opacity 50) (conserve FALSE))      
  (the-lizard-breath-text-shine image layer shadow-size shadow-opacity conserve))
 
  (gimp-image-undo-group-end image) 
  (gimp-displays-flush image) 
   
)


    ;register menu location and information   

(script-fu-register
"script-fu-lizard-breath"
"<Image>/Script-Fu/Text Effects/lizard-breath"
"creates a reptilian scales effect from a text layer"
"Rod Detmer"
"Rod Detmer"
"August 2012"
"RGB* GRAY*"
SF-IMAGE       "The Image" 0
SF-DRAWABLE    "The Layer" 0
SF-ADJUSTMENT  "Scale Size"            '(13 5 100 1 10 0 SF-SLIDER)
SF-OPTION      "Scale Shape"           '("Squares" "Hexagons" "Octagons and Squares" "Triangles")
)

(define (the-lizard-breath-text-shine image drawable shadow-size shadow-opacity conserve)
                      

(let* (
            ;(image (car (gimp-image-duplicate inImage)))
         (image-layer (car (gimp-image-get-active-layer image)))
         (width (car (gimp-image-width image)))
         (height (car (gimp-image-height image)))
         (sel (car (gimp-selection-is-empty image)))
         (layer-name (car (gimp-drawable-get-name image-layer)))
         (img-layer 0)
         (img-channel 0)
         (bkg-layer 0)
         (shadow-layer 0)
         (tmp-layer 0)
        )
      
      
   (gimp-context-push)
    (gimp-image-undo-group-start image)
   (gimp-context-set-foreground '(0 0 0))
   (gimp-context-set-background '(255 255 255))
   (gimp-layer-add-alpha image-layer)
    (if (= sel TRUE) (gimp-selection-layer-alpha image-layer))
   (set! img-layer (car (gimp-layer-new image width height RGBA-IMAGE "img-layer" 100 NORMAL-MODE)))
   (gimp-image-add-layer image img-layer -1)
   (gimp-drawable-fill img-layer  BACKGROUND-FILL)
   (gimp-edit-fill img-layer FOREGROUND-FILL)
;;;;create channel
   (gimp-selection-save image)
   (set! img-channel (car (gimp-image-get-active-drawable image)))   
   (gimp-channel-set-opacity img-channel 100)   
   (gimp-drawable-set-name img-channel "img-channel")
   (gimp-image-set-active-layer image img-layer)   
   (gimp-drawable-set-name image-layer "Original Image")
   
;;;;create the background layer   
   (set! bkg-layer (car (gimp-layer-new image width height RGBA-IMAGE "Background" 100 NORMAL-MODE)))
    (gimp-image-add-layer image bkg-layer 1)
      

;;;;apply the image effects
    (gimp-context-set-foreground '(0 0 0))
   (gimp-context-set-background '(255 255 255))
   (plug-in-gauss-rle2 RUN-NONINTERACTIVE image img-layer 12 12)
   (plug-in-emboss RUN-NONINTERACTIVE image img-layer 225 84 10 TRUE)   
   (gimp-selection-invert image)
   (gimp-edit-clear img-layer)
   (gimp-selection-invert image)
   (plug-in-colortoalpha RUN-NONINTERACTIVE image img-layer '(254 254 254));;fefefe
   (plug-in-gauss-rle2 RUN-NONINTERACTIVE image img-channel 15 15)
   (plug-in-blur RUN-NONINTERACTIVE image img-layer)
   (gimp-image-set-active-layer image bkg-layer)
   (plug-in-displace RUN-NONINTERACTIVE image bkg-layer 8 8 TRUE TRUE img-channel img-channel 0)
   (gimp-image-remove-layer image bkg-layer)
;;;;create the shadow
(if (> shadow-size 0)
  (begin
    (script-fu-drop-shadow image img-layer shadow-size shadow-size shadow-size '(0 0 0) shadow-opacity FALSE)
    (set! tmp-layer (car (gimp-layer-new image width height RGBA-IMAGE "temp" 100 NORMAL-MODE)))
    (gimp-image-add-layer image tmp-layer -1)
   (gimp-image-raise-layer image tmp-layer)
    (gimp-image-merge-down image tmp-layer CLIP-TO-IMAGE)
   (set! shadow-layer (car (gimp-image-get-active-drawable image)))
   (gimp-image-lower-layer image shadow-layer)
   
   )
)   

(if (= conserve FALSE)
    (begin
   (set! img-layer (car (gimp-image-merge-down image img-layer EXPAND-AS-NECESSARY)))
   (set! img-layer (car (gimp-image-merge-down image img-layer EXPAND-AS-NECESSARY)))
   (gimp-drawable-set-name img-layer layer-name)
   )
   )   

   (gimp-image-remove-channel image img-channel)
   (gimp-selection-none image)
   (gimp-image-undo-group-end image)
   (gimp-context-pop)
    (gimp-displays-flush)

)
)