My favorites | Sign in
Project Logo
Project hosting will be READ-ONLY Wednesday at 8am PST due to brief network maintenance.
                
Search
for
Updated Nov 12, 2009 by michael.bedward
Labels: Featured
Jiffle  
Jiffle: a language for image creation and raster algebra

Introduction

The Jiffle scripting language allows you to create images from expressions consisting of mathematical and logical operators, pre-defined and user-defined constants, and data from input images. Using Jiffle you can do many of the things that you otherwise might write a JAI ImageFunction to accomplish, but with much less code.

Jiffle is based on the r.mapcalc language which was developed for raster algebra in GRASS GIS. More information about GRASS and r.mapcalc is available at the OSGeo GRASS web site.

Examples

This jiffle script creates concentric sinusoidal ripples radiating from the centre of the image...

// get coords of image centre using the built-in width()
// and height() functions
xc = width() / 2;
yc = height() / 2;

// get distance of current pixel from centre; the
// jiffle functions x() and y() return current pixel
// coords
dx = (x()-xc)/xc;
dy = (y()-yc)/yc;
d = sqrt(dx^2 + dy^2);

// calculate sin of scaled distance and write to
// the current pixel (note: no explicit loop required)
result = sin(8 * PI * d);

This script creates a chessboard pattern. It also demonstrates some of Jiffle's conditional operators...

// creates an 8 x 8 chessboard pattern

// longest side length
len = width() > height() ? width() : height()

// width of squares
square = floor(len / 8)

edge_pos = square * 8;

odd_row = floor(y() / square) % 2 == 1
odd_col = floor(x() / square) % 2 == 1
inside = x() < edge_pos && y() < edge_pos

// ^| is the XOR operator
result = inside ? (odd_row ^| odd_col) : null


Sign in to add a comment
Hosted by Google Code