2004-10-06 21:47:36 +00:00
|
|
|
; Set Colormap v1.1 September 29, 2004
|
|
|
|
; by Kevin Cozens <kcozens@interlog.com>
|
|
|
|
;
|
|
|
|
; Change the colourmap of an image to the colours in a specified palette.
|
2006-09-29 06:01:39 +00:00
|
|
|
; Included is script-fu-make-cmap-array (available for use in scripts) which
|
2004-10-06 21:47:36 +00:00
|
|
|
; returns an INT8ARRAY containing the colours from a specified palette.
|
2011-10-30 02:37:26 -04:00
|
|
|
; This array can be used as the cmap argument for gimp-image-set-colormap.
|
2004-10-06 21:47:36 +00:00
|
|
|
|
2006-12-09 21:33:38 +00:00
|
|
|
; GIMP - The GNU Image Manipulation Program
|
2004-10-06 21:47:36 +00:00
|
|
|
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
2006-09-30 05:06:28 +00:00
|
|
|
;
|
2009-01-17 22:28:01 +00:00
|
|
|
; This program is free software: you can redistribute it and/or modify
|
2004-10-06 21:47:36 +00:00
|
|
|
; it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
; the Free Software Foundation; either version 3 of the License, or
|
2004-10-06 21:47:36 +00:00
|
|
|
; (at your option) any later version.
|
2006-09-30 05:06:28 +00:00
|
|
|
;
|
2004-10-06 21:47:36 +00:00
|
|
|
; 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.
|
2006-09-30 05:06:28 +00:00
|
|
|
;
|
2004-10-06 21:47:36 +00:00
|
|
|
; You should have received a copy of the GNU General Public License
|
2009-01-17 22:28:01 +00:00
|
|
|
; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-10-06 21:47:36 +00:00
|
|
|
|
2006-09-29 06:01:39 +00:00
|
|
|
(define (script-fu-make-cmap-array palette)
|
2005-05-04 18:38:27 +00:00
|
|
|
(let* (
|
|
|
|
(num-colours (car (gimp-palette-get-info palette)))
|
|
|
|
(cmap (cons-array (* num-colours 3) 'byte))
|
2008-01-15 05:15:08 +00:00
|
|
|
(colour 0)
|
2005-05-04 18:38:27 +00:00
|
|
|
(i 0)
|
|
|
|
)
|
2004-10-06 21:47:36 +00:00
|
|
|
|
|
|
|
(while (< i num-colours)
|
2004-10-06 22:09:23 +00:00
|
|
|
(set! colour (car (gimp-palette-entry-get-color palette i)))
|
2004-10-06 21:47:36 +00:00
|
|
|
(aset cmap (* i 3) (car colour))
|
|
|
|
(aset cmap (+ (* i 3) 1) (cadr colour))
|
|
|
|
(aset cmap (+ (* i 3) 2) (caddr colour))
|
|
|
|
(set! i (+ i 1))
|
|
|
|
)
|
|
|
|
|
|
|
|
cmap
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2006-09-29 06:01:39 +00:00
|
|
|
(define (script-fu-set-cmap img drawable palette)
|
2005-06-01 21:22:49 +00:00
|
|
|
(gimp-image-set-colormap img
|
|
|
|
(* (car (gimp-palette-get-info palette)) 3)
|
2006-09-29 06:01:39 +00:00
|
|
|
(script-fu-make-cmap-array palette))
|
2004-10-06 21:47:36 +00:00
|
|
|
(gimp-displays-flush)
|
|
|
|
)
|
|
|
|
|
2006-09-29 06:01:39 +00:00
|
|
|
(script-fu-register "script-fu-set-cmap"
|
2007-05-04 14:29:19 +00:00
|
|
|
_"Se_t Colormap..."
|
2007-03-09 15:58:01 +00:00
|
|
|
_"Change the colormap of an image to the colors in a specified palette."
|
2004-10-06 21:47:36 +00:00
|
|
|
"Kevin Cozens <kcozens@interlog.com>"
|
|
|
|
"Kevin Cozens"
|
|
|
|
"September 29, 2004"
|
|
|
|
"INDEXED*"
|
|
|
|
SF-IMAGE "Image" 0
|
|
|
|
SF-DRAWABLE "Drawable" 0
|
|
|
|
SF-PALETTE _"Palette" "Default"
|
|
|
|
)
|
2004-11-23 04:01:41 +00:00
|
|
|
|
2007-05-04 14:29:19 +00:00
|
|
|
(script-fu-menu-register "script-fu-set-cmap" "<Image>/Colors/Map/Colormap")
|