;;; Script  : BaseShadeToneTint-2.6.scm
;;; Author  : b10h4z4rd
;;; Date    : September 2012
;;; Revision: v-01
;;; 					
;;; Version : v-01
;;; Latest version at: http://www.gimpchat.com/viewtopic.php?f=9&t=5199
;;; Required : Gimp 2.6
;;;
;;; Menu Entries:
;;; <palettes>Copy current Palette to BaseShadeToneTint pallete
;;; <palettes>Copy FG to BaseShadeToneTint pallete
;;;
;;; Description: 
;;; This Script was written to produce either a palette from the current FG Color
;;; by adding the color, a shade, tone and tint of the color to the BaseShadeToneTint palette
;;; or to produce a new BaseShadeToneTint palette of colors, shades, tones and tints of each color in the selected
;;; palette.
;;; 
;;; The idea for this came from he4rty's post "Shade Tone Tint Generator" 
;;; found at http://www.gimpchat.com/viewtopic.php?f=12&t=5189
;;; 
;;; -----------------------------------------------------------------------------
;;; Change Log:
;;; Version-1.0
;;;
; More information can be found at http://www.gimpchat.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-temp-image Tempimage)
	(let* 
		(
			(Shade_Color '(65 65 65))
			(Tone_Color '(128 128 128))
			(Tint_Color '(192 192 192))
			(Layer_Shadow (car (gimp-layer-new Tempimage 60 60 RGBA-IMAGE "Shadow" 75 GRAIN-MERGE-MODE)))
			(Layer_Midtone (car (gimp-layer-new Tempimage 60 60 RGBA-IMAGE "Midtone" 25 VALUE-MODE)))
			(Layer_Highlight (car (gimp-layer-new Tempimage 60 60 RGBA-IMAGE "Highlight" 75 GRAIN-MERGE-MODE)))
		)

		(gimp-image-add-layer Tempimage Layer_Shadow -1)
		(gimp-image-add-layer Tempimage Layer_Midtone -1)
		(gimp-image-add-layer Tempimage Layer_Highlight -1)

		(gimp-image-set-active-layer Tempimage Layer_Shadow)
		(gimp-rect-select
			Tempimage ; image
			0 ; x upper left
			20 ; y upper left
			20 ; width
			40 ; height
			CHANNEL-OP-REPLACE ; select mode
			0
			0.0
		)
		(gimp-context-set-foreground Shade_Color)
		(gimp-edit-fill Layer_Shadow FOREGROUND-FILL)

		(gimp-image-set-active-layer Tempimage Layer_Midtone)
		(gimp-rect-select
			Tempimage ; image
			20 ; x upper left
			20 ; y upper left
			20 ; width
			40 ; height
			CHANNEL-OP-REPLACE ; select mode
			0
			0.0
		)
		(gimp-context-set-foreground Tone_Color)
		(gimp-edit-fill Layer_Midtone FOREGROUND-FILL)

		(gimp-image-set-active-layer Tempimage Layer_Highlight)
		(gimp-rect-select
			Tempimage ; image
			40 ; x upper left
			20 ; y upper left
			20 ; width
			40 ; height
			CHANNEL-OP-REPLACE ; select mode
			0
			0.0
		)
		(gimp-context-set-foreground Tint_Color)
		(gimp-edit-fill Layer_Highlight FOREGROUND-FILL)
		(gimp-selection-none Tempimage)
	)
)
	
(define (script-fu-FG-to-palette)
	(let* 
		(
			(Tempimage (car (gimp-image-new 60 60 RGB)))
			(Current_FG (car (gimp-context-get-foreground )))
			(Layer_Base (car (gimp-layer-new Tempimage 60 60 RGBA-IMAGE "Base" 100 NORMAL-MODE)))
			(Layer_Derived)
		)

		(script-fu-temp-image Tempimage)
		(gimp-image-add-layer Tempimage Layer_Base 0)
		(gimp-image-lower-layer-to-bottom Tempimage Layer_Base)
		(gimp-context-set-foreground Current_FG)
		(gimp-drawable-fill Layer_Base FOREGROUND-FILL)
		(set! Layer_Derived (car (gimp-layer-new-from-visible Tempimage Tempimage "Derived")))
		(gimp-image-add-layer Tempimage Layer_Derived 0)
		(gimp-image-raise-layer-to-top Tempimage Layer_Derived)
		
		(if (eqv? (car (gimp-palettes-get-list "BaseShadeToneTint")) 0)
			(gimp-palette-new "BaseShadeToneTint"))
		(gimp-palette-add-entry "BaseShadeToneTint" "Base" (car (gimp-image-pick-color Tempimage Layer_Derived 0 0 FALSE FALSE 0)))
		(gimp-palette-add-entry "BaseShadeToneTint" "Shade" (car (gimp-image-pick-color Tempimage Layer_Derived 0 20 FALSE FALSE 0)))
		(gimp-palette-add-entry "BaseShadeToneTint" "Tone" (car (gimp-image-pick-color Tempimage Layer_Derived 20 20 FALSE FALSE 0)))
		(gimp-palette-add-entry "BaseShadeToneTint" "Tint" (car (gimp-image-pick-color Tempimage Layer_Derived 40 20 FALSE FALSE 0)))

		(gimp-palette-set-columns "BaseShadeToneTint" 4)
		(gimp-context-set-palette "BaseShadeToneTint")
		(gimp-image-delete Tempimage)
	)
)

(define (script-fu-Palette-to-palette)
	(let* 
		(
			(Loop 0)
			(Num_Colors 0)
			(Selected_Palette)
 			(Tempimage (car (gimp-image-new 60 60 RGB)))
			(Layer_Base (car (gimp-layer-new Tempimage 60 60 RGBA-IMAGE "Base" 100 NORMAL-MODE)))
			(Layer_Derived)
		)

		(script-fu-temp-image Tempimage)

		(set! Selected_Palette (car (gimp-context-get-palette)))
		(set! Num_Colors (car (gimp-palette-get-info Selected_Palette)))
		(set! Loop 0)
		(gimp-image-add-layer Tempimage Layer_Base -1)
		(gimp-image-lower-layer-to-bottom Tempimage Layer_Base)
		(while (< Loop Num_Colors)
			(gimp-context-set-foreground (car (gimp-palette-entry-get-color Selected_Palette Loop)))
			(gimp-drawable-fill Layer_Base FOREGROUND-FILL)	
			(set! Layer_Derived (car (gimp-layer-new-from-visible Tempimage Tempimage "Derived")))
			(gimp-image-add-layer Tempimage Layer_Derived 0)
			(gimp-image-raise-layer-to-top Tempimage Layer_Derived)
			(if (eqv? (car (gimp-palettes-get-list "BaseShadeToneTint")) 0)
				(gimp-palette-new "BaseShadeToneTint"))
			(gimp-image-set-active-layer Tempimage Layer_Derived)
			(gimp-palette-add-entry "BaseShadeToneTint" "Base" (car (gimp-image-pick-color Tempimage Layer_Derived 0 0 FALSE FALSE 0)))
			(gimp-palette-add-entry "BaseShadeToneTint" "Shade" (car (gimp-image-pick-color Tempimage Layer_Derived 0 20 FALSE FALSE 0)))
			(gimp-palette-add-entry "BaseShadeToneTint" "Tone" (car (gimp-image-pick-color Tempimage Layer_Derived 20 20 FALSE FALSE 0)))
			(gimp-palette-add-entry "BaseShadeToneTint" "Tint" (car (gimp-image-pick-color Tempimage Layer_Derived 40 20 FALSE FALSE 0)))
			(set! Loop (+ 1 Loop))
			(gimp-image-remove-layer Tempimage Layer_Derived)
		)
		(gimp-palette-set-columns "BaseShadeToneTint" 4)
		(gimp-context-set-palette "BaseShadeToneTint")
		(gimp-image-delete Tempimage)
	)
)

(script-fu-register
		"script-fu-FG-to-palette"
		"<Palettes>/Copy FG to BaseShadeToneTint Palette"
		"Add the FG color to the Palette"
		"b10h4z4rd"
		"b10h4z4rd"
		"2012"
		""
)
(script-fu-register
		"script-fu-Palette-to-palette"
		"<Palettes>/Copy current Palette to BaseShadeToneTint Palette"
		"Add the selected Palette's colors to the Palette"
		"b10h4z4rd"
		"b10h4z4rd"
		"2012"
		""
)
