GridFlow 0.6.1 - reference index

       

Numbers

Grid Literals

Grid Protocol

Picture Protocol

One-Input Operators

Two-Input Operators



Numbers

High-performance computation requires precise and quite peculiar definitions of numbers and their representation.

Inside most programs, numbers are written down as strings of bits. A bit is either zero or one. Just like the decimal system uses units, tens, hundreds, the binary system uses units, twos, fours, eights, sixteens, and so on.

One notation called integer allows for only integer values to be written (no fractions). when it is unsigned, no negative values may be written. when it is signed, one bit indicates whether the number is positive or negative.

In GridFlow, there are two kinds of numbers:

int32, signed 32-bit integer. values from -2147483648 to 2147483647 (which is from -231 to 231-1). this is used for most computations.

uint8, unsigned 8-bit integer. values from 0 to 255 (which is from 0 to 255). this is the usual size of numbers taken from files and cameras, and written to files and to windows.

 

Grid Literals

In every inlet that accepts a grid, a list may be sent instead; if it consists only of integers, it will be converted to a one-dimensional grid. Else it may contain a single "#" sign and integers on both sides of it, where the ones to the left of it are fed as arguments to an imaginary [@redim] object and the one to the right of it are fed through that [@redim].
 

Grid Protocol

each element of a grid is an int32.

a single-dimensional grid of 3 elements (a triplet) is called dim(3). a three-dimensional grid of 240 rows of 320 columns of triplets is called dim(240,320,3).

There is a sequence in which elements of a Grid are stored and transmitted. Dimension 0 is called "first" and dimension N-1 is called "last". They are called so because if you select a position in the first dimension of a grid, the selected part is of the same shape minus the first dimension; so in dim(240,320,3) if you select row 51 (or whichever valid row number), you get a dim(320,3). if you select a subpart two more times you get to a single number.

At each such level, elements are sent/stored in their numeric order, and are numbered using natural numbers starting at 0. This ordering usually does not matter, but sometimes it does. Most notably, @import, @export and @redim care about it.

On the other hand, order of dimensions usually does matter; this is what distinguishes rows from columns and channels, for example. Most objects care about the distinction.

A grid with only 1 element in a given dimension is different from one lacking that dimension; it won't have the same meaning. You can use this property to your advantage sometimes.

Zero-dimensional grids exist. They are called dim(). They can only contain a single number.

 

Picture Protocol

This section is useful if you want to know what a picture is in terms of a grid.

A picture is a three-dimensional Grid:

  • 0 : rows
  • 1 : columns
  • 2 : channels

Channels for the RGB color model are:

  • 0 : red
  • 1 : green
  • 2 : blue

Because Grids are made of 32-bit integers, a three-channel picture uses 96 bpp (bits per pixel), and have to be downscaled to 24 bpp (or 16 bpp) for display. That huge amount of slack is there because when you create your own effects you often have intermediate results that need to be of higher precision than a normal picture. Especially, results of multiplications are big and should not overflow before you divide them back to normal; and similarly, you can have negative values all over, as long as you take care of them before they get to the display.

In the final conversion, high bits are just ignored. This means: black is 0, maximum is 255, and values wrap like with % 256. If you want to clip them, you may use "@ max 0" and "@ min 255" objects.

 

One-Input Operators

internal nameusual namedescription
absabs absolute value of A
randrand randomly produces a non-negative number below A
sqrtsqrt square root of A, rounded downwards
sqsq A times A
 

Two-Input Operators

In the following table, A is the value entered to the left, and B is the value entered to the right.

Angles are in hundredths of degrees. This means a full circle (two pi radians) is 36000. You convert from degrees to our angles by multiplying by 100. You convert from radians to our angles by multiplying by 18000/pi.

Hyperbolic functions (tanh) work with our angles too, so the same conversions apply.

internal nameusual namedescription
addadd A + B
subsub A - B
busbus B - A
mulmul A * B
divdiv A / B, rounded downwards
vidvid B / A, rounded downwards
modmod A % B, non-negative remainder
domdom B % A, non-negative remainder
oror A or B, bitwise
xorxor A xor B, bitwise
andand A and B, bitwise
shlshl A * (2**(B % 32)), which is left-shifting
shrshr A / (2**(B % 32)), which is right-shifting
sc_orsc_or if A is zero then B else A
sc_andsc_and if A is zero then zero else B
minmin the lowest value in A,B
maxmax the highest value in A,B
cmpcmp -1 when AB.
eqeq is A equal to B ? 1=true, 0=false
nene is A not equal to B ?
gtgt is A greater than B ?
lele is A not greater than B ?
ltlt is A less than B ?
gegeis A not less than B ?
sinsin B * sin(A)
coscos B * cos(A)
atanatan arctan(A/B)
tanhtanh B * tanh(A)
gammagamma floor(pow(a/256.0,256.0/b)*256.0)
powpow A raised to power B
 

GridFlow 0.6.1 Documentation
by Mathieu Bouchard matju@sympatico.ca and
Alexandre Castonguay acastonguay@artengine.ca