A Color Script component would be like the current Map Script and Curve Script components, except that it would not return a stream of data, but instead it would return a single color value, like a Color Control component does.
For example, here's a simple Map Script that finds the maximum alpha level in an image. It operates on a per-pixel basis, and can't return alphaMax for use anywhere, because it only returns a stream of pixel data. This limits it to creating Image Maps only.
Code |
---|
function prepare()
alphaMax = 0;
end;
function get_sample(x, y)
local r, g, b, a = get_sample_map(x, y, SOURCE);
if a > alphaMax then
alphaMax = a;
end;
return r, g, b, a;
end;
|
I propose adding a Color Script component which operates like this:
Code |
---|
function prepare()
alphaMax = 0;
end;
function process_sample(x, y)
-- This is called for each pixel. It returns nothing.
local r, g, b, a = get_sample_map(x, y, SOURCE);
if a > alphaMax then
alphaMax = a;
end;
end;
function get_color()
-- This is only run after all process_sample calls are complete.
-- It returns a single r, g, b, a value, like a color component.
-- Here we return alphaMax for r, g, b, and 1 for a.
return alphaMax, alphaMax, alphaMax, 1;
end;
|
While this looks like the Map Script component with a minor change, this minor change actually opens up a huge amount of new possibilities.
The action of finding the maximum alpha value in an image, which is shown in my example above, is currently impossible to do in Filter Forge. There are no built-in components with this functionality. When I needed this for a filter I was working on, I was disappointed to find that this basic image processing ability is simply not supported and there is no way to script it.
I ran into many other cases like this which needed a single value generated from analyzing pixel data. Filter Forge offers little in this area of image processing. The Maximum Level, and Minimum Level components are along this line, but they only work for the external image data.
With a Color Script component, Filter Forge becomes much more powerful.