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
(bezier-path points:indexed &opt step:double=0.005) Generate piece-wise, linear path from bezier control points
color constant for black
(blank width:int height:int &opt channel:int=4) Create a new blank image
color constant for blue
(circle img:*Image x:double y:double r:double color:uint32_t) Draw a circle
color constant for clear
(crop img:*Image x1:int y1:int new-width:int new-height:int) Create a smaller sub-image from a larger image
color constant for cyan
(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.
(fill-rect img:*Image x:double y:double width:double height:double color:uint32_t) Fill a rectangle
color constant for green
(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.
color constant for magenta
(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.
(pixel img:*Image x:int y:int) Read a pixel. Slow, be careful to use this in a loop.
(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)
(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
(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.
color constant for red
(resize in:*Image new-width:int new-height:int &opt linear:bool=0) Resize an image, resampling as needed
(resize-into out:*Image in:*Image &opt linear:bool=0) Resize an image into another image, resampling as needed
(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.
(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
(ring img:*Image x:double y:double r-inner:double r-outer:double color:uint32_t) Draw a ring
(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.
(save-jpg path:cstring img:*Image quality:int) Save an image to a file as a jpg
(set-pixel img:*Image x:int y:int color:uint32) Set a pixel. Slow, be careful to use this in a loop.
(stamp dest:*Image src:*Image &opt dx:int=0 dy:int=0) Copy one image onto another
(stamp-blend dest:*Image src:*Image blend-mode:Janet &opt dx:int=0 dy:int=0) Copy on image onto another with blending
(stroke-path img:*Image points:indexed color:uint32_t &opt thickness:double=1 join-end:bool=0) Stroke a line along a path
(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.
(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.
color constant for white
color constant for yellow