Cauldron3D.Texture (Cauldron3D v0.2.2)

Copy Markdown View Source

A picture, rows top to bottom: indexed colour, one byte per pixel and optionally its own palette, or RGBA, four bytes per pixel.

Cauldron3D.Texture.new(64, 64, pixels)
Cauldron3D.Texture.new(64, 64, pixels, palette)
Cauldron3D.Texture.rgba(64, 64, rgba_pixels)
Cauldron3D.Texture.at(texture, 3, 7)

palette is 768 bytes of red, green and blue, or nil for an indexed texture whose indices are into the palette of whatever it is drawn on; colours is that palette as 1024 bytes of RGBA, four a colour (colour/2 reads one). An RGBA texture's alpha is 0 where it is see-through.

Summary

Functions

The colour index at {x, y} of an indexed texture, wrapping both ways.

Colour index of colours/1's table, as four bytes of RGBA.

A 768-byte palette as 1024 bytes of opaque RGBA, four a colour.

An indexed texture of width by height from its pixels. Raises ArgumentError when the sizes disagree.

An indexed texture of width by height from its pixels and its own 768-byte palette.

An RGBA texture of width by height. Raises ArgumentError when the sizes disagree.

The texture with left columns from its left edge, as two textures {left, rest}.

Types

t()

@type t() :: %Cauldron3D.Texture{
  colours: binary() | nil,
  format: :indexed | :rgba,
  height: pos_integer(),
  palette: binary() | nil,
  pixels: binary(),
  width: pos_integer()
}

Functions

at(texture, x, y)

@spec at(t(), integer(), integer()) :: byte()

The colour index at {x, y} of an indexed texture, wrapping both ways.

colour(colours, index)

@spec colour(binary(), byte()) :: binary()

Colour index of colours/1's table, as four bytes of RGBA.

colours(palette)

@spec colours(binary()) :: binary()

A 768-byte palette as 1024 bytes of opaque RGBA, four a colour.

new(width, height, pixels)

@spec new(pos_integer(), pos_integer(), binary()) :: t()

An indexed texture of width by height from its pixels. Raises ArgumentError when the sizes disagree.

new(width, height, pixels, palette)

@spec new(pos_integer(), pos_integer(), binary(), binary()) :: t()

An indexed texture of width by height from its pixels and its own 768-byte palette.

rgba(width, height, pixels)

@spec rgba(pos_integer(), pos_integer(), binary()) :: t()

An RGBA texture of width by height. Raises ArgumentError when the sizes disagree.

split(texture, left)

@spec split(t(), pos_integer()) :: {t(), t()}

The texture with left columns from its left edge, as two textures {left, rest}.