GIMP Script-fu

Artifact [95bcaa8055]
Login

Artifact 95bcaa805572b876d0101c4f4aba238df6b2d667:


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
   100
   101
   102
   103
   104
   105
   106
   107
   108
   109
   110
   111
   112
   113
   114
   115
   116
; 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* (
        (x 0)
        (y 0)
;        (cos-scaled (* 0.707 (cos (* 45 (/ *pi* 180))))) == 0.5
;        (sin-scaled (* 0.707 (sin (* 45 (/ *pi* 180))))) == 0.5
      )
      (set! x (+ (vector-ref color 0) (* (vector-ref color 2) 0.5)))
      (set! y (+ (vector-ref color 1) (* (vector-ref color 2) 0.5)))
      (set! x (+ x 50))
      (set! y (- 450 y))
      (gimp-drawable-set-pixel drawable x y 4 color)
      )
    )
  (let* (
      (image 0)
      (display 0)
      (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 0)
      (y 0)
      (layer 0)
      (bg 0)
      (bg-axes 0)
      (fg-axes 0)
      (i 0)
      (orig-selection 0)
      (orig-bg (car (gimp-context-get-background)))
      )
    (gimp-image-undo-group-start orig-image)
    (gimp-layer-add-alpha orig-drawable)
    (set! image (car (gimp-image-new width height RGB)))
    (gimp-image-undo-disable image)
    (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! i 255)
    (while (>= i 0)
      (plot-xy bg-axes (vector i 0 0 255))
      (plot-xy bg-axes (vector 0 i 0 255))
      (plot-xy bg-axes (vector 0 0 i 255))
      (plot-xy bg-axes (vector i   255 255 255))
      (plot-xy bg-axes (vector 255 i   255 255))
      (plot-xy bg-axes (vector i   0   255 255))
      (plot-xy bg-axes (vector 0   i   255 255))
      (plot-xy bg-axes (vector 0   255 i   255))
      (plot-xy bg-axes (vector 255 0   i   255))
      (plot-xy fg-axes (vector i   255 0   255))
      (plot-xy fg-axes (vector 255 i   0   255))
      (plot-xy fg-axes (vector 255 255 i   255))
      (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)
        (plot-xy layer (cadr (gimp-drawable-get-pixel orig-drawable x y)))
        (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-image-undo-enable image)
    (gimp-image-undo-group-end orig-image)
    (gimp-displays-flush)
    )
  )

(script-fu-register
  "script-fu-indexed-color-cube"
  "<Image>/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
  )