Color in ScriptFu
This is a brief explanation of how colors work in ScriptFu.
script-fu/test/tests/pdb/color.scm on
GIMP source. The tests demonstrate exactly how ScriptFu behaves.Representation in Scheme
Colors are represented by lists of numerics, or string names or other string notation.
The base representation is the list representation.
In the string ones, Script-Fu still converts to list RGBA/RGB or list GRAYA/GRAY format under the hood.
    list representation
      
      
    
A color from GIMP is represented in ScriptFu by a list of from one to four numerics, depending on the image mode. The numerics are “components” of the color.
You can also represent colors by lists of numeric in calls to the PDB.
Examples:
- RGBA: (0 0 0 0)
- RGB: (0 0 0)
- Grayscale with alpha: (0 0)
- Grayscale: (0)
    string CSS name representation
      
      
    
Color names can be used in PDB calls to GIMP. Color names must be CSS names.
You can also represent default colors by name when declaring script arguments.
The color name “transparent” is a CSS color name.
You can use color named by “transparent” in calls to the PDB. When setting the context foreground color, it sets to opaque black. When setting pixel of an RGBA image, the pixel is set to black transparent.
    Other string CSS notation
      
      
    
You can also use other string notation to denote a color.
Examples:
- #FFFFFFhexadecimal notation for RGB
- hsl(0, 0, 0)converter function call from HSL values
Colorspace and Precision
While the GIMP app supports many colorspaces and precisions, ScriptFu does not. Generally speaking, ScriptFu has limited support for dealing with colorspace and precision.
Scripts may call any procedures in the PDB that deal with colorspace and precision. Even those, however, can be limited, since part of GIMP color awaraness comes from libgimp and its use of GeglColor, not the PDB.
In short, ScriptFu is not designed for intense and complicated pixel-level operations.
Colorspace
ScriptFu keeps colors in the sRGB colorspace, or grayscale.
GIMP converts colorspace when a ScriptFu script operates on images in other colorspaces.
Precision
ScriptFu keeps colors with 8-bit integer precision. This means a script may suffer loss of precision when processing images of higher precision.
ScriptFu clamps numerics passed to the PDB as color components to the range [0, 255]. Numeric color components received from GIMP are also integers in the range [0,255].
Float numerics may be passed as components of a color, but are converted to integers and clamped.