FixImage Documentation

This library allows you to use and draw 2D images.

Features:

Format

All images are stored in ARGB format. Each pixel is 32-bit integer divided into four 8bit quantities. The order of channels is A,R,G,B (from highest order to lowest). For example, a fully opaque yellow color is 0xFFFFFF00.

The alpha channel determines how translucent the pixel is. The format uses premultiplied alpha which means that color channels are multiplied with alpha (as if represented in the normalized 0-1 range). For example a half-transparent yellow color is 0x80808000. This allows for correct filtering and better performance. You can think of it as the more transparent the pixel is the less important the color is up into a fully transparent pixel where the color is completely meaningless.

As a side-effect this format also supports additive blending (with smooth transition between normal and additive blending when filtering), simply use zero alpha and non-zero color channels, it will be just added into the image instead of blending. However this is not supported for all operations (for example gamma adjusted rendering requires to convert back to normal representation).

Shaders

Some drawing functions accept shaders. These are small special purpose code fragments optimized for computing the resulting color. The syntax looks like this:

use "image/shaders"; // at the beginning of the file
use "classes";
...
var factor = 128;
p.fill_rect(0, 0, 100, 100, Shader {
    var color = sample_bilinear(img, tr, CLAMP_X|CLAMP_Y);
    blend(mix(color, 0x00000000, factor) * 0x80808080);
});
The shader is created using the Shader {} construct. The body can contain these statements:
var name = <expression>;
blend(<expression>);
replace(<expression>);
That means you can declare variables and issue either blending with the output, or replacing the output with the color derived from the expression.

In expressions you can use hexadecimal literals to directly provide constant color (in premultiplied format), or use the rgb and argb functions to convert from the normal format. You can directly reference outside variables by an identifier, or if it's a more complex expression you can wrap it in $(...) fragment (the body is normal FixScript code). You can use parenthesis in the expressions to group operations as needed, you can add/subtract/multiply pixel values (each component is processed separately using saturation arithmetic).

You can use these functions:

sample_nearest(img: Image, tr: Transform[, flags])
sample_bilinear(img: Image, tr: Transform[, flags])
sample_bicubic(img: Image, tr: Transform[, flags])
Samples pixel values from given image and transform. Optionally you can use these flags (delimited by |):
CLAMP - clamp both X & Y coordinates at the edges of the image
CLAMP_X - clamp the X coordinate at the edges of the image
CLAMP_Y - clamp the Y coordinate at the edges of the image
mix(var1, var2, factor)
Returns mixed color between variables var1 and var2 using the outside variable factor (with values between 0 and 256 inclusively).

Classes

Global functions
C API