Janet 1.41.2-0fea20c Documentation
(Other Versions: 1.41.1 1.40.1 1.40.0 1.39.1 1.38.0 1.37.1 1.36.0 1.35.0 1.34.0 1.31.0 1.29.1 1.28.0 1.27.0 1.26.0 1.25.1 1.24.0 1.23.0 1.22.0 1.21.0 1.20.0 1.19.0 1.18.1 1.17.1 1.16.1 1.15.0 1.13.1 1.12.2 1.11.1 1.10.1 1.9.1 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )

gfx2d

NOTE: Beta-quality - apis may change.

Various simple CPU-based 2d graphics tools suitable for demos, visulizations, and charting. The module generates C code which then is further compiled. It can also be used to generate "shaders" by evaluating this file with `(dyn :shader-compile)` set, which disables a number of functions and allows passing in a pixel shader stub.

Leans on the underlying C compiler for optimization - recommended to be used with `JANET_BUILD_TYPE=native janet-pm install` to take advantage of the best available vectorization.

This module doesn't presume any color-space, with the exception of when saving images to formats like PNG, which guarantees the sRGB color space. Most operations do not do blending - those that do also specify the color space in the blending modes. Unless otherwise specified, blending is done in a "linear" color space.

Includes: * Saving and loading to and from several common image file formats. * Image blitting * Blend modes * Cropping imges * Read/Set individual pixels * Built in simple text rendering * Image resizing * Stroke and Fill paths * Bezier curves * Pixel shader abstraction with spork/cjanet

Reference

gfx2d/bezier-path gfx2d/black gfx2d/blank gfx2d/blue gfx2d/circle gfx2d/clear gfx2d/copy gfx2d/crop gfx2d/cyan gfx2d/diff gfx2d/draw-simple-text gfx2d/fill-path gfx2d/fill-rect gfx2d/green gfx2d/image-from-pointer gfx2d/load gfx2d/magenta gfx2d/measure-simple-text gfx2d/pixel gfx2d/plot gfx2d/plot-path gfx2d/plot-ring gfx2d/red gfx2d/resize gfx2d/resize-into gfx2d/rgb gfx2d/rgb-pre-mul gfx2d/ring gfx2d/save gfx2d/save-bmp gfx2d/save-jpg gfx2d/save-png gfx2d/save-tga gfx2d/set-pixel gfx2d/stamp gfx2d/stamp-blend gfx2d/stroke-path gfx2d/unpack gfx2d/viewport gfx2d/white gfx2d/yellow


gfx2d/bezier-path cfunction source
(bezier-path points:indexed &opt step:double=0.005)

Generate piece-wise, linear path from bezier control points

gfx2d/black number
color constant for black

gfx2d/blank cfunction source
(blank width:int height:int &opt channel:int=4)

Create a new blank image

gfx2d/blue number
color constant for blue

gfx2d/circle cfunction source
(circle img:*Image x:double y:double r:double color:uint32_t)

Draw a circle

gfx2d/clear number
color constant for clear

gfx2d/copy cfunction source
(copy img:*Image)

Create a duplicate image

gfx2d/crop cfunction source
(crop img:*Image x1:int y1:int new-width:int new-height:int)

Create a smaller sub-image from a larger image

gfx2d/cyan number
color constant for cyan

gfx2d/diff cfunction source
(diff a:*Image b:*Image)

Take the difference of two images

gfx2d/draw-simple-text cfunction source
(draw-simple-text img:*Image x:double y:double text:cstring color:uint32_t &opt (font-name keyword (janet-ckeyword "default")) xscale:int=1 yscale:int=1 orientation:int=0)

Draw text with a default, bitmap on an image. Font should be one of :default, :tall, or :olive.

gfx2d/fill-path cfunction source
(fill-path img:*Image points:indexed color:uint32_t)

Fill a path

gfx2d/fill-rect cfunction source
(fill-rect img:*Image x:double y:double width:double height:double color:uint32_t)

Fill a rectangle

gfx2d/green number
color constant for green

gfx2d/image-from-pointer cfunction source
(image-from-pointer memory:*void width:int height:int &opt channel:int=4 stride:int=0)

Create a new image from a pointer to foreign memory.
It is up to the user to correctly size, allocate, and free the backing memory.

gfx2d/load cfunction source
(load path:cstring)

Load an image from disk into a buffer

gfx2d/magenta number
color constant for magenta

gfx2d/measure-simple-text cfunction source
(measure-simple-text text:cstring &opt (font-name keyword (janet-ckeyword "default")) xscale:int=1 yscale:int=1 orientation:int=0)

Return the height and width of text as a tuple. Font should be one of :default, :tall, or :olive.

gfx2d/pixel cfunction source
(pixel img:*Image x:int y:int)

Read a pixel. Slow, be careful to use this in a loop.

gfx2d/plot cfunction source
(plot img:*Image x1:double y1:double x2:double y2:double color:uint32_t &opt stipple-cycle:int=0 stipple-on:int=0)

Draw a 1 pixel line from (x1, y1) to (x2, y2)

gfx2d/plot-path cfunction source
(plot-path img:*Image points:indexed color:uint32_t &opt stipple-cycle:int=0 stipple-on:int=0 join-end:bool=0)

Plot 1 pixel lines over a path

gfx2d/plot-ring cfunction source
(plot-ring img:*Image x:int y:int r:int color:uint32_t)

Plot a 1 pixel thick ring around (x, y) with radius r.

gfx2d/red number
color constant for red

gfx2d/resize cfunction source
(resize in:*Image new-width:int new-height:int &opt linear:bool=0)

Resize an image, resampling as needed

gfx2d/resize-into cfunction source
(resize-into out:*Image in:*Image &opt linear:bool=0)

Resize an image into another image, resampling as needed

gfx2d/rgb cfunction source
(rgb r:double g:double b:double &opt a:double=1.0)

Make an RGB color constant from components. Each component is a number from 0 to 1.

gfx2d/rgb-pre-mul cfunction source
(rgb-pre-mul r:double g:double b:double &opt a:double=1.0)

Make an RRB color constants from components and premultiply the alpha

gfx2d/ring cfunction source
(ring img:*Image x:double y:double r-inner:double r-outer:double color:uint32_t)

Draw a ring

gfx2d/save cfunction source
(save path:cstring img:*Image &opt quality:int=100)

Save an image to a file, auto-detecting the format. Supports PNG, BMP, TGA, and JPEG.

gfx2d/save-bmp cfunction source
(save-bmp path:cstring img:*Image)

Save an image to a file as a bmp

gfx2d/save-jpg cfunction source
(save-jpg path:cstring img:*Image quality:int)

Save an image to a file as a jpg

gfx2d/save-png cfunction source
(save-png path:cstring img:*Image)

Save an image to a file as a png

gfx2d/save-tga cfunction source
(save-tga path:cstring img:*Image)

Save an image to a file as a tga

gfx2d/set-pixel cfunction source
(set-pixel img:*Image x:int y:int color:uint32)

Set a pixel. Slow, be careful to use this in a loop.

gfx2d/stamp cfunction source
(stamp dest:*Image src:*Image &opt dx:int=0 dy:int=0)

Copy one image onto another

gfx2d/stamp-blend cfunction source
(stamp-blend dest:*Image src:*Image blend-mode:Janet &opt dx:int=0 dy:int=0)

Copy on image onto another with blending

gfx2d/stroke-path cfunction source
(stroke-path img:*Image points:indexed color:uint32_t &opt thickness:double=1 join-end:bool=0)

Stroke a line along a path

gfx2d/unpack cfunction source
(unpack img:*Image)

Extract the :width (integer), :height (integer), :channels (integer 1-4),
stride (integer), and underlying :data (buffer) from an image and return a struct.

gfx2d/viewport cfunction source
(viewport img:*Image x:int y:int width:int height:int &opt allow-trimming:bool=0)

Create a new image that shares backing memory with another image. This allow parallel drawing in different threads.

gfx2d/white number
color constant for white

gfx2d/yellow number
color constant for yellow