; maxCMY.scm
; by Rob Antonishen
; http://ffaat.pointclark.net

; Version 1.0 (20130304)

; Changes:

; Description
; Performs the maxRGB function in CMY colourspace

; 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.
;
; The GNU Public License is available at
; http://www.gnu.org/copyleft/gpl.html
(define (script-fu-maxCMY img inLayer inAction)
(let* (
        (inAction (- 1 inAction))
		(width (car (gimp-image-width img)))
		(height (car (gimp-image-height img)))
		(decomp 0)
		(temp 0)
        (buff "maxCMYbuff")
		)

	(gimp-context-push)
	(gimp-image-undo-group-start img)
	
    ;flip colourspace
    (set! decomp (plug-in-decompose RUN-NONINTERACTIVE img inLayer "CMY" FALSE))
    (set! temp (car (plug-in-compose RUN-NONINTERACTIVE (car decomp) -1 (cadr decomp) (caddr decomp) -1 "RGB")))
    (gimp-image-delete (car decomp))
    (gimp-image-delete (cadr decomp))
    (gimp-image-delete (caddr decomp))
    
    ;Call maxRGB
    (plug-in-max-rgb RUN-NONINTERACTIVE temp (car (gimp-image-active-drawable temp)) inAction)
 
    ;flip colourspace back
    (set! decomp (plug-in-decompose RUN-NONINTERACTIVE temp (car (gimp-image-active-drawable temp)) "RGB" FALSE))
    (gimp-image-delete temp)
    (set! temp (car (plug-in-compose RUN-NONINTERACTIVE (car decomp) -1 (cadr decomp) (caddr decomp) -1 "CMY")))
    (gimp-image-delete (car decomp))
    (gimp-image-delete (cadr decomp))
    (gimp-image-delete (caddr decomp)) 
	
    (set! buff (car (gimp-edit-named-copy (car (gimp-image-active-drawable temp)) buff)))
    (gimp-floating-sel-anchor (car (gimp-edit-named-paste inLayer buff TRUE)))
    
    (gimp-image-delete temp)

	(gimp-image-undo-group-end img)
	(gimp-displays-flush)
	(gimp-context-pop)
)
)


(script-fu-register "script-fu-maxCMY"
					"<Image>/Colors/Maximum CMY..."
					"Reduce Image to pur Cyan, Magenta, and Yellow"
					"Rob Antonishen"
					"Rob Antonishen"
					"Mar 2013"
					"RGB*"
					SF-IMAGE       "Image"         0
					SF-DRAWABLE    "Drawable"      0
					SF-OPTION      "Hold the " (list "maximal channels" "minimal channels")
					)
