Once you know how to write a Jiffle script, the next thing you’ll want to do is run it. Jiffle provides a number of ways to do that. All of them involve these basic steps:
Although you write your script in the Jiffle language, you run it from within Java (or possibly another JVM language such as Groovy).
Using JiffleBuilder is the easiest way to get started with Jiffle. Let’s look at running the following script which :
This script implements a MAX filter: a 3x3 kernel is placed over each pixel in the input image, represented by the variable src, and the maximum value found is written to the output image, represented by dest [*].
Now let’s look at a Java method which takes the script (in the form of a file) and an input image, and uses JiffleBuilder to run the script, returning the resulting image to the caller.
public RenderedImage buildAndRunScript(File scriptFile, RenderedImage inputImage)
throws JiffleException {
JiffleBuilder builder = new JiffleBuilder();
builder.script(scriptFile).source("src", inputImage);
builder.dest("dest", inputImage.getWidth(), inputImage.getHeight());
builder.run();
return builder.getImage("dest");
}