; 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. (define (script-fu-indexed-color-cube orig-image orig-drawable) (define (plot-xy drawable color) (let* ( (pixel (cons-array 4 'byte)) (r (aref color 0)) (g (aref color 1)) (b (aref color 2)) (x) (y) (cos-scaled (* 0.707 (cos (* 45 (/ *pi* 180))))) (sin-scaled (* 0.707 (sin (* 45 (/ *pi* 180))))) ) (set! x (+ r (* b cos-scaled))) (set! y (+ g (* b sin-scaled))) (set! x (+ x 50)) (set! y (- 450 y)) (aset pixel 0 r) (aset pixel 1 g) (aset pixel 2 b) (aset pixel 3 255) (gimp-drawable-set-pixel drawable x y 4 pixel) ) ) (define (make-color r g b) (let* ( (color (cons-array 3 'byte)) ) (aset color 0 r) (aset color 1 g) (aset color 2 b) color ) ) (let* ( (image) (display) (orig-width (car (gimp-drawable-width orig-drawable))) (orig-height (car (gimp-drawable-height orig-drawable))) (width 500) (height 500) (max-wh (max width height)) (x) (y) (layer) (bg) (bg-axes) (fg-axes) (color) (i) (orig-selection) (orig-bg (car (gimp-context-get-background))) ) (set! image (car (gimp-image-new width height RGB))) (set! display (car (gimp-display-new image))) (set! bg (car (gimp-layer-new image width height RGB-IMAGE "Background" 100 NORMAL-MODE))) (gimp-context-set-background '(127 127 127)) (gimp-drawable-fill bg BACKGROUND-FILL) (gimp-image-add-layer image bg 0) (gimp-context-set-background orig-bg) (set! bg-axes (car (gimp-layer-new image width height RGBA-IMAGE "bg-axes" 100 NORMAL-MODE))) (gimp-drawable-fill bg-axes TRANSPARENT-FILL) (gimp-image-add-layer image bg-axes 0) (set! layer (car (gimp-layer-new image width height RGBA-IMAGE "Color Cube" 100 NORMAL-MODE))) (gimp-drawable-fill layer TRANSPARENT-FILL) (gimp-image-add-layer image layer 0) (set! fg-axes (car (gimp-layer-new image width height RGBA-IMAGE "fg-axes" 100 NORMAL-MODE))) (gimp-drawable-fill fg-axes TRANSPARENT-FILL) (gimp-image-add-layer image fg-axes 0) (set! color (cons-array 3 'byte)) (set! i 255) (while (>= i 0) (plot-xy bg-axes (make-color i 0 0)) (plot-xy bg-axes (make-color 0 i 0))layer (plot-xy bg-axes (make-color 0 0 i)) (plot-xy bg-axes (make-color i 255 255)) (plot-xy bg-axes (make-color 255 i 255)) (plot-xy bg-axes (make-color i 0 255)) (plot-xy bg-axes (make-color 0 i 255)) (plot-xy bg-axes (make-color 0 255 i )) (plot-xy bg-axes (make-color 255 0 i )) (plot-xy fg-axes (make-color i 255 0 )) (plot-xy fg-axes (make-color 255 i 0 )) (plot-xy fg-axes (make-color 255 255 i )) (set! i (- i 1)) ) (gimp-drawable-update bg-axes 0 0 width height) (gimp-drawable-update fg-axes 0 0 width height) (gimp-displays-flush) (set! x 0) (gimp-progress-init "Color Cubing" display) (while (< x orig-width) (set! y 0) (while (< y orig-height) (set! color (cadr (gimp-drawable-get-pixel orig-drawable x y))) (plot-xy layer color) (set! y (+ y 1)) ) (gimp-progress-update (/ x orig-width)) (set! x (+ x 1)) ) (gimp-progress-end) (gimp-drawable-update layer 0 0 width height) (gimp-displays-flush) ) ) (script-fu-register "script-fu-indexed-color-cube" "/Image/Color Cube" "Create a 3-D plot of color data for an Indexed image" "Saul Goode" "Saul Goode" "April 2008" "RGB*" SF-IMAGE "" 0 SF-DRAWABLE "" 0 )