TwistedBrush User Guide

Lua Script Filters

A Lua script filter in TwistedBrush is a small piece code written in the Lua programming language that can be used to quickly implement image processing filters right within TwistedBrush.

The Lua scripting filter is designed to be somewhat compatible with the gluas plug-ins used in The Gimp image editing software package. The gluas plugin system was developed by Øyvind Kolås. There is a nice tutorial of gluas titled Image Processing with gluas a large part is applicable to TwistedBrush and most (if not all) of the sample scripts shown should work within TwistedBrush.

An excellent online book covering all the details of the Lua programming language can be found here.

 In case you haven't determined this yet, this topic and programming of filters with Lua is designed for those with computer programming experience. However, this doesn't limited anyone from using filters that are either included with TwistedBrush or shared from developers.

The support for Lua for scripting filters was added to TwistedBrush in 15.05. Included are a handful of scripts mostly for example purposes.

Example of a Lua Script Filter that does a simple invert (negative)
invert_filter_sample.jpg
-- Invert colors
for y = 0, height - 1 do
  for x = 0, width - 1 do
    local r, g, b
   
r, g, b = get_rgb(x, y)
   
r = 1 - r
   
g = 1 - g
   
b = 1 - b
   
set_rgb(x, y, r, g, b)
 
end
end

 

gluas compatible APIs
v = get_value(x, y)

set_value(x, y, v)

r, g, b = get_rgb(x, y)

set_rgb(x, y, r, g, b)

r, g, b, a = get_rgba(x, y)

set_rgba(x, y)

h, s, v = get_hsv(x, y)

set_hsv(x, y, h, s, v)

h, s, l = get_hsl(x, y)

set_hsl(x, y, h, s, l)

l, a, b = get_lab(x, y)

set_lab(x, y)

c, m, y, k = get_cmyk(x, y)

set_cmyk(x, y, c, m, y, k)

flush()

progress(v)  // only a stub, progress is not shown in TwistedBrush

TwistedBrush specific APIs
a = get_alpha(x, y)

set_alpha(x, y, a)

r, g, b = get_color()  // Gets the current brush color

r, g, b = get_color1() // Gets the current color from slot 1

r, g, b = get_color2() // Gets the current color from slot 2

r, g, b = get_color3() // Gets the current color from slot 3

r, g, b = get_color4() // Gets the current color from slot 4

single_buffer()        // All functions work from the same buffer

message_box(message, title) // Display message box


merge(merge_mode, opacity)  // Like the flush() method but a merge mode and opacity can be specified for the merging of the destination buffer back into the source buffer. The valid merge modes are defined as MERGE_NORMAL, MERGE_MULTIPLY, MERGE_SCREEN, MERGE_DARKEN, MERGE_LIGHTEN, MERGE_DIFFERENCE, MERGE_NEGATION, MERGE_EXCLUSION, MERGE_OVERLAY, MERGE_HARD_LIGHT, MERGE_SOFT_LIGHT, MERGE_DODGE, MERGE_BURN, MERGE_REFLECT, MERGE_GLOW, MERGE_ADD, MERGE_SUBTRACT, MERGE_TEXTURIZE, MERGE_TEXTURIZE2, MERGE_TEXTURIZE3.

gluas compatible global variables
width
height
bound_x0   // Always 0 in TwistedBrush
bound_y0   // Always 0 in TwistedBrush
bound_x1   // Always width - 1 in TwistedBrush
bound_y1   // Always height - 1 in TwistedBrush

TwistedBrush specific variables
slideVal1  // The slideValx values come from gui sliders when defined.
slideVal2
slideVal3
slideVal4
slideVal5
slideVal6

flagVal1   // The flagValx values come from the gui checkboxes
flagVal2
flagVal3
flagVal4
flagVal5
flagVal6

 

TwistedBrush specific directives
Within a comment in the Lua script a directive can be defined for creating up to 6 user slider controls and up to 6 check box controls that appear within the TwistedBrush Filter dialog. This allows users to dynamically adjust values in the script without ever needing to look at a script. In addition this also allows for the filters to be recorded like all the other filters in TwistedBrush. The format of this directives are:
--@TBCONFIG SLIDER: name, default value
--@TBCONFIG FLAG: name, default value

For example these three lines in a script will define three sliders Red, Green and Blue with values of a middle gray.
--@TBCONFIG SLIDER: Red, 50.0
--@TBCONFIG SLIDER: Green, 50.0
--@TBCONFIG SLIDER: Blue, 50.0

Here is the Filter dialog that shows the sliders that will be created based on the directives. However, the sample image shows values of 100.0 for each rather than the default shown above (it's a screen shot from a different example)

lua_filter_cap1.jpg 

 If the Edit Script button is pressed the script can be edited within TwistedBrush, deleted or saved to a new name. Of course a text editor of your choice could also be used outside of TwistedBrush.

lua_filter_cap02.png

 

Editions: TwistedBrush Pro Studio
Also See:
External Links:
The Lua Programming Language
Gluas defined with many samples as used in The Gimp 
DogLua (gluas) as used in PDPro with more examples 
Lua Scripting (gluas) as used in Artweaver with yet more examples 

Site

Changes
Index
Search

User

Log In
Register

 
 

Last Modified 2008-02-16