Cauldron2D.Projection.Canvas (Cauldron2D v0.2.2)

Copy Markdown View Source

A framebuffer of RGBA rows that stamps are painted onto, and the stamps themselves.

A canvas is a map from row index to that row's pixels, width * 4 bytes each. A stamp is an image reduced to its opaque runs, %{width, height, runs: [{y, x, pixels}]}, so painting it copies whole runs and skips transparent pixels. paint/4 clips to the canvas.

canvas = Canvas.new(64, 32, {6, 7, 11})
stamp = Canvas.stamp(%{width: 8, height: 8, rgba: rgba})
canvas |> Canvas.paint(stamp, {10, 4}) |> Canvas.to_raster()

Summary

Functions

A fully transparent canvas of width by height, to build a stamp on.

The width by height window of the canvas whose top-left corner is at {x, y}.

The image mirrored left to right.

The image with fun applied to every pixel's four bytes.

The value under key in the ETS table, built by build and kept when absent.

A canvas of width by height filled with colour.

Paint stamp with its top-left corner at {x, y}, clipped to the canvas.

Paints the parallelogram origin + u * across + v * down, u and v running 0..1, taking each pixel from texel.(u, v); a pixel the function answers nil for is left alone, as is one outside the canvas.

pixel mixed towards fog by mix in 0.0..1.0 after its colour is multiplied by factor; a transparent pixel is left alone.

The image at 1 / factor of its size, sampling every factorth pixel.

An image reduced to its opaque runs. A pixel is opaque from alpha 128.

The pixel of a square size texture at u, v in 0.0..1.0.

The canvas as an image, for stamp/1.

The canvas as a raster.

Types

image()

@type image() :: %{width: pos_integer(), height: pos_integer(), rgba: binary()}

stamp()

@type stamp() :: %{
  width: pos_integer(),
  height: pos_integer(),
  runs: [{integer(), integer(), binary()}]
}

t()

@type t() :: %{
  width: pos_integer(),
  height: pos_integer(),
  rows: %{required(non_neg_integer()) => binary()}
}

Functions

blank(width, height)

@spec blank(pos_integer(), pos_integer()) :: t()

A fully transparent canvas of width by height, to build a stamp on.

crop(map, arg1, arg2)

@spec crop(
  t(),
  {non_neg_integer(), non_neg_integer()},
  {pos_integer(), pos_integer()}
) :: t()

The width by height window of the canvas whose top-left corner is at {x, y}.

flip(map)

@spec flip(image()) :: image()

The image mirrored left to right.

map_pixels(image, fun)

@spec map_pixels(image(), (binary() -> binary())) :: image()

The image with fun applied to every pixel's four bytes.

memo(table, key, build)

@spec memo(atom(), term(), (-> term())) :: term()

The value under key in the ETS table, built by build and kept when absent.

new(width, height, arg)

@spec new(pos_integer(), pos_integer(), {byte(), byte(), byte()}) :: t()

A canvas of width by height filled with colour.

paint(canvas, map, arg)

@spec paint(t(), stamp(), {integer(), integer()}) :: t()

Paint stamp with its top-left corner at {x, y}, clipped to the canvas.

quad(canvas, arg1, arg2, arg3, texel)

@spec quad(
  t(),
  {number(), number()},
  {number(), number()},
  {number(), number()},
  (float(), float() ->
     binary() | nil)
) ::
  t()

Paints the parallelogram origin + u * across + v * down, u and v running 0..1, taking each pixel from texel.(u, v); a pixel the function answers nil for is left alone, as is one outside the canvas.

The two edge vectors must not be parallel.

shade(pixel, factor, arg3, mix)

@spec shade(binary(), number(), {byte(), byte(), byte()}, number()) :: binary()

pixel mixed towards fog by mix in 0.0..1.0 after its colour is multiplied by factor; a transparent pixel is left alone.

shrink(image, factor)

@spec shrink(image(), pos_integer()) :: image()

The image at 1 / factor of its size, sampling every factorth pixel.

stamp(map)

@spec stamp(image()) :: stamp()

An image reduced to its opaque runs. A pixel is opaque from alpha 128.

texel(texture, size, u, v)

@spec texel(binary(), pos_integer(), number(), number()) :: binary()

The pixel of a square size texture at u, v in 0.0..1.0.

to_image(map)

@spec to_image(t()) :: image()

The canvas as an image, for stamp/1.

to_raster(map)

@spec to_raster(t()) :: FrenchCurve.Raster.t()

The canvas as a raster.