Encodes raw RGBA pixels as a PNG.
encode/3 writes truecolour with alpha, the format iTerm2's inline-image protocol
takes. encode_indexed/3 writes a palette image, one byte a pixel, for pictures of at
most 256 colours such as pixel art, where it is far smaller. Encoding only; there is no
decoder.
png = FrenchCurve.Png.encode(width, height, FrenchCurve.Raster.to_rgba_binary(raster))
Summary
Functions
Encodes a dense RGBA buffer as a complete PNG binary.
Encodes a dense RGBA buffer, as encode/3 takes it, as a palette PNG: each distinct
colour, alpha included, once in its PLTE and tRNS chunks, and a byte a pixel
deflated by FrenchCurve.Deflate at level (default 6).
Functions
@spec encode(pos_integer(), pos_integer(), binary()) :: binary()
Encodes a dense RGBA buffer as a complete PNG binary.
rgba must be exactly width * height * 4 bytes, four bytes per pixel in red, green,
blue, alpha order and rows top to bottom; a mismatched size raises FunctionClauseError,
as do non-positive dimensions.
The result is an 8-bit-per-channel truecolour-with-alpha PNG whose scanlines all use
filter type 0 and whose pixel data sits in a single IDAT chunk deflated at the fastest
level.
@spec encode_indexed(pos_integer(), pos_integer(), binary(), 1..12) :: {:ok, binary()} | {:error, :too_many_colours}
Encodes a dense RGBA buffer, as encode/3 takes it, as a palette PNG: each distinct
colour, alpha included, once in its PLTE and tRNS chunks, and a byte a pixel
deflated by FrenchCurve.Deflate at level (default 6).
Returns {:error, :too_many_colours} when the buffer has more than 256 colours.