···11-//// Module to parse/dither PBM/PGM image to be printed on monochrome
11+//// Module to parse and dither PBM/PGM images to be printed on monochrome
22//// printers.
33//// There are printers that can print grayscale or even color, if
44//// you want to do that, you'll need to implement that yourself
55//// and/or leverage the `protocol` module directly.
66+////
77+//// 80mm printers usually have a maximum of 640 dots width.
88+//// There is no validation so please check your image beforehand.
69////
77-//// Thank you jak for the pgm reading and bayer dithering
1010+//// Thank you jak for the pgm reading and bayer dithering 💕
811912import gleam/float
1013import gleam/int
···5861 use #(width, rest) <- result.try(parse_number(rest, 0))
5962 use #(height, rest) <- result.try(parse_number(rest, 0))
6063 case rest {
6161- <<"255\n", pixels:bytes>> -> Ok(GrayscaleImage(width:, height:, pixels:))
6464+ <<"255\n", pixels:bytes>> ->
6565+ Ok(GrayscaleImage(width:, height:, pixels:))
6266 _ -> Error(ParseError)
6367 }
6468 }
···171175 }
172176}
173177174174-fn dither_map(image: GrayscaleImage, fun: fn(Int, Int, Int) -> Int) -> PrintableImage {
178178+fn dither_map(
179179+ image: GrayscaleImage,
180180+ fun: fn(Int, Int, Int) -> Int,
181181+) -> PrintableImage {
175182 let pixels =
176183 dither_loop(image.pixels, image.width, 0, 0, <<>>, fun)
177184 |> byte_align_rows(image.width)