Cauldron3D.Texture (Cauldron3D v0.2.0)

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 a tuple of 256 RGBA binaries. 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.

A 768-byte palette as a tuple of 256 opaque RGBA binaries.

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: tuple() | 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.

colours(palette)

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

A 768-byte palette as a tuple of 256 opaque RGBA binaries.

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}.