;;; Plugin  : script-fu-colored-pencil-plus_RD
;;; Author  : Rod Detmer
;;; Date    : November 2015
;;; Revision: None
;;; 					
;;; Version : 1.0
;;; Latest version at: http://www.gimpchat.com
;;; Required : Gimp 2.8 or later
;;;
;;; Description: 
;;; creates a colored pencil with optional color mode layer type effect on an image.
;;; -----------------------------------------------------------------------------
;;;
;;; License:
;;; 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 2 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.
;;; 
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

(define (script-fu-original-colored-pencil-plus_RD image drawable 
                                             fillcolorlayer 
											 contrast 
											 pencillayer 
											 masklayer 
											 layer_mode 
											 masklayeropacity
											 colorlayeropacity
											 coloredpencilopacity)
  
  (gimp-context-push)  
  (gimp-image-undo-group-start image)
  
    (let* (
		  (width (car (gimp-image-width image)))
		  (height (car (gimp-image-height image)))
		  (unsharpmask (car (gimp-layer-new-from-visible image image "Unsharp Mask")))
		  (untouched (car (gimp-layer-new-from-visible image image "Untouched")))		  
          (colorlayer (car (gimp-layer-new image width height 1 "Color Layer" 100 0)))
          (coloredpencillayer (car (gimp-layer-new-from-visible image image "Painted layer")))		  				 
		  )

   ;add the visible image to a new layer 
  (gimp-image-add-layer image unsharpmask 0)  
  (gimp-image-add-layer image coloredpencillayer 1)
  (gimp-image-add-layer image colorlayer 2)  
  (gimp-image-add-layer image untouched 4)
   


  
  

  (gimp-context-set-foreground fillcolorlayer) ;set coloored layer fill color
  (gimp-edit-fill colorlayer 0) ;fill colored layer with color  
  (gimp-layer-set-opacity colorlayer colorlayeropacity)  
  
    ;effect on new layer
  ;(plug-in-gimpressionist 1 image coloredpencillayer "grafiteforpencilcolor")
  (plug-in-neon RUN-NONINTERACTIVE image coloredpencillayer 1.0 1.0)
  (plug-in-unsharp-mask RUN-NONINTERACTIVE image unsharpmask 0.1 contrast 0)
  (gimp-layer-set-opacity unsharpmask masklayeropacity)

  (gimp-layer-set-opacity coloredpencillayer coloredpencilopacity)
  (gimp-layer-set-mode unsharpmask masklayer)
  (gimp-layer-set-mode colorlayer layer_mode)
  (gimp-layer-set-mode coloredpencillayer pencillayer)  
  
  ;display the new image
  (gimp-displays-flush image)
  
  (gimp-context-pop)
  (gimp-image-undo-group-end image)
    )
  
)


(script-fu-register
 "script-fu-original-colored-pencil-plus_RD"
 "<Image>/Rod/Artistic/Original Colored Pencil Plus"
 "Creates a colored pencil type effect with a color overlay. By turning off the colored and unsharp mask layers you cab get close to a David hill type effect."
 "Rod Detmer"
 "Rod Detmer"
 "November 2015" 
 "RGB*"
SF-IMAGE "The Image" 0
SF-DRAWABLE "The Drawable" 0
SF-COLOR "Layer Color" '(0 0 0) ;23 44 2 and 78 28 107 are also good overcolors
SF-ADJUSTMENT "Contrast" '(3.75 0.0 10.0 1 10 0 SF-Spinner)
SF-ENUM "Colored Pencil Layer Mode" '("LayerModeEffects" "subtract-mode")                          
SF-ENUM "Unsharp Mask Layer Mode" '("LayerModeEffects" "divide-mode") 
SF-ENUM "Color Layer Mode" '("LayerModeEffects" "overlay-mode") 
SF-ADJUSTMENT "Mask Layer Opacity" '(54 0.0 100.0 1 10 0 SF-Spinner)
SF-ADJUSTMENT "Color Layer Opacity" '(46 0.0 100.0 1 10 0 SF-Spinner)
SF-ADJUSTMENT "Colored Pencil Layer Opacity" '(100 0.0 100.0 1 10 0 SF-Spinner)
)
;
;(script-fu-menu-register "script-fu-colored-pencil-plus_RD" "<Image>/Rod/Artistic")
