1.0. Curve loader

Revision History
Revision $Revision: 1.0 $ 2011-01-23 r.s

The Curve loader plugin loads the curve files written by the Curve Tool and returns arrays of values for use with gimp-curves-spline or gimp-curves-explicit.

1.0.1. Activate the plugin

You can get to this tool :

  • In Script-Fu with the command (plug-in-curveloader CHANNELS FILENAME).

1.0.2. "Curve loader" options

CHANNELS
0, 1, 2, 3, 4

Only one array and the element count of this array is returned, where 0 represents the value channel, 1 the red channel, 2 the green channel, 3 the blue channel and 4 the alpha channel. You can also use the predefined values HISTOGRAM-VALUE, HISTOGRAM-RED, HISTOGRAM-GREEN, HISTOGRAM-BLUE or HISTOGRAM-ALPHA.

5

Return all channels from the curve file as arrays. The first element is the element count of the value array, then the value array, then the element count of the red array, then the red array ...

FILENAME

The file name of the curve file to be loaded.

1.0.3. "Curve loader" examples

Examples


Return the green channel curve from file mycurve

;to make things a little easier
(define HISTOGRAM-ALL 5)

;get the green curve
(set! results (plug-in-curveloader HISTOGRAM-GREEN "mycurve"))

;first result is always the element count
(set! elements (list-ref results 0))
;then comes the array of values
(set! thearray (list-ref results 1))

;if elements < 256 it's a smooth curve, else a freehand curve
(if (< elements 256)
    (gimp-curves-spline drawable HISTOGRAM-GREEN elements thearray)
    (gimp-curves-explicit drawable HISTOGRAM-GREEN elements thearray)
)

Return the red channel curve from file redcurve

;to make things a little easier
(define HISTOGRAM-ALL 5)

;get the red curve
(set! results (plug-in-curveloader HISTOGRAM-RED "redcurve"))

;first result is always the element count
(set! elements (list-ref results 0))
;then the array of values
(set! thearray (list-ref results 1))

;apply the red curve on the alpha channel
;Warning! fails if there is no alpha channel
(if (< elements 256)
    (gimp-curves-spline drawable HISTOGRAM-ALPHA elements thearray)
    (gimp-curves-explicit drawable HISTOGRAM-ALPHA elements thearray)
)

Apply all channel curves from file allcurves

;to make things a little easier
(define HISTOGRAM-ALL 5)

;get all curves
(set! results (plug-in-curveloader HISTOGRAM-ALL "allcurves"))

;begin arguments
(set! valuenum (list-ref results 0))
(set! valuearray (list-ref results 1))
(set! rednum (list-ref results 2))
(set! redarray (list-ref results 3))
(set! greennum (list-ref results 4))
(set! greenarray (list-ref results 5))
(set! bluenum (list-ref results 6))
(set! bluearray (list-ref results 7))
(set! alphanum (list-ref results 8))
(set! alphaarray (list-ref results 9))
;end arguments

;apply all curves to all channels
(if (< valuenum 256)
    (gimp-curves-spline drawable HISTOGRAM-VALUE valuenum valuearray)
    (gimp-curves-explicit drawable HISTOGRAM-VALUE valuenum valuearray)
)
(if (< rednum 256)
    (gimp-curves-spline drawable HISTOGRAM-RED rednum redarray)
    (gimp-curves-explicit drawable HISTOGRAM-RED rednum redarray)
)
(if (< greennum 256)
    (gimp-curves-spline drawable HISTOGRAM-GREEN greennum greenarray)
    (gimp-curves-explicit drawable HISTOGRAM-GREEN greennum greenarray)
)
(if (< bluenum 256)
    (gimp-curves-spline drawable HISTOGRAM-BLUE bluenum bluearray)
    (gimp-curves-explicit drawable HISTOGRAM-BLUE bluenum bluearray)
)
;Warning! fails if there is no alpha channel
(if (< alphanum 256)
    (gimp-curves-spline drawable HISTOGRAM-ALPHA alphanum alphaarray)
    (gimp-curves-explicit drawable HISTOGRAM-ALPHA alphanum alphaarray)
)

Apply all channel curves from file allcurves, the short way

;to make things a little easier
(define HISTOGRAM-ALL 5)

;get all curves
(set! results (plug-in-curveloader HISTOGRAM-ALL "allcurves"))

;apply all curves to all channels
(while (pair? results)
  (if (< (list-ref results 0) 256)
    (gimp-curves-spline drawable channel (list-ref results 0) (list-ref results 1))
    (gimp-curves-explicit drawable channel (list-ref results 0) (list-ref results 1))
    )
  (set! channel (+ channel 1))
  ;skip alpha if there is no alpha channel
  (if (= (car(gimp-drawable-has-alpha drawable)) FALSE)
    (if (= channel 4) (set! results (cddr results)))
    )
  ;skip alpha if there is no alpha channel
  (set! results (cddr results))
)

Download theexample scheme file and copy it to your scripts folder.

1.0.4. Notes

Supported curve files


Old GIMP curve files, which look like this:

# GIMP Curves File
0 0 -1 -1 -1 -1 -1 -1 -1 -1 60 120 ... 255 255
0 0 ... 80 48 ... 149 192 -1 -1 -1 -1 191 248 ... 255 255
0 0 -1 -1 -1 -1 -1 -1 70 81 ... 159 220 ... 255 255
0 27 ... 255 213
0 0 -1 -1 -1 -1 20 100 ... 255 255

with 34 values per line (dots are for better overview only).
The lines represent the channels value, red, green, blue and alpha.
The values are paired in and out values of colors in the range between 0
and 255. Values of -1 are ignored.

New GIMP curve files, which look like this:

# GIMP curves tool settings

(time 0)
(channel value)
(curve
  (curve-type smooth)
  (n-points 17)
  (points 34 0.000000 0.000000 ... 1.000000 0.735102)
  (n-samples 256)
  (samples 256 0.000000 0.003922 ... 0.992157 0.996078 1.000000))
(time 0)
(channel red)
(curve
  (curve-type smooth)
  (n-points 17)
  (points 34 0.000000 1.000000 ... 0.971053 0.000000)
  (n-samples 256)
  (samples 256 1.000000 0.995962 0.991923 ... 0.000000 0.000000))
(time 0)
(channel green)
(curve
  (curve-type free)
  (n-points 17)
  (points 34 0.000000 0.000000 ... 1.000000 1.000000)
  (n-samples 256)
  (samples 256 0.000000 0.003922 0.007843 ... 0.996078 1.000000))
(time 0)
(channel blue)
(curve
  (curve-type smooth)
  (n-points 17)
  (points 34 0.000000 0.000000 ... -1.000000 -1.000000 1.000000 1.000000)
  (n-samples 256)
  (samples 256 0.000000 0.003922 0.007843 ... 1.000000))
(time 0)
(channel alpha)
(curve
  (curve-type smooth)
  (n-points 17)
  (points 34 0.000000 0.000000 ... 1.000000 1.000000)
  (n-samples 256)
  (samples 256 0.000000 ... 0.937255 0.941176 0.952941 ... 1.000000))

# end of curves tool settings

with 34 or 256 values per channel (dots are for better overview only).
If the curve-type is smooth the plugin will return the smooth curve, else the freeform
curve will be returned. The values are paired (smooth curve) in and out values of
colors in the range between 0.0 and 1.0, therefore multiplied by 255 in the output.
Again values of -1 (in the smooth curve) are ignored.
The file parsing routine does not check for the element count of exactly 34 points in
the smootth curve, so even curves with minimal 2 valid pairs of points will be accepted
(applies to both curve file types).