Renders a raster as braille characters, for terminals with no graphics protocol at all.
Each braille character carries eight dots in a 2-wide by 4-tall grid, so one cell stands
in for a 2-by-4 block of pixels and a raster comes out at ceil(width / 2) columns by
ceil(height / 4) rows. A pixel is a lit dot when its alpha reaches the threshold;
colour is per character, averaged over that cell's lit pixels, so detail below one cell
survives in shape but not in colour.
render/2 returns cell rows and to_ansi/1 or to_text/1 turn those into a string.
raster
|> FrenchCurve.Backend.Braille.render()
|> FrenchCurve.Backend.Braille.to_ansi()
|> IO.puts()
Summary
Types
One character cell: the braille grapheme, and the average RGB of its lit pixels or nil
when no pixel in the cell was lit.
Types
@type cell() :: {binary(), FrenchCurve.Raster.color_rgb() | nil}
One character cell: the braille grapheme, and the average RGB of its lit pixels or nil
when no pixel in the cell was lit.
Functions
@spec render( FrenchCurve.Raster.t(), keyword() ) :: [[cell()]]
Renders raster as rows of cell/0, top row first.
Returns ceil(height / 4) rows of ceil(width / 2) cells. Cells at the right and
bottom edges read pixels past the raster bounds, which come back as the background and
so are lit only if the background itself passes the threshold.
Options
:alpha_threshold— the smallest alpha counted as a lit dot, default1. Raise it to drop faint pixels;0lights every pixel including fully transparent ones.
Flattens cell rows to a single newline-separated string with 24-bit colour.
Each coloured cell is wrapped in a truecolour foreground sequence and reset immediately
after, so the string leaves no styling behind. Cells with no lit pixels are emitted bare.
Rows are joined with \n and there is no trailing newline.
Flattens cell rows to one uncoloured string per row, dropping the colours.
Returns a list of binaries, one per row, each of braille characters only.