# `FrenchCurve.Png`
[🔗](https://github.com/jaman/french_curve/blob/v0.2.0/lib/french_curve/png.ex#L1)

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))

# `encode`

```elixir
@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.

# `encode_indexed`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
