🖨️ esc/pos implementation in gleam

docs: width warning

okk.moe 7feaf208 8361a99e

verified
+11 -4
+11 -4
src/escpos/image.gleam
··· 1 - //// Module to parse/dither PBM/PGM image to be printed on monochrome 1 + //// Module to parse and dither PBM/PGM images to be printed on monochrome 2 2 //// printers. 3 3 //// There are printers that can print grayscale or even color, if 4 4 //// you want to do that, you'll need to implement that yourself 5 5 //// and/or leverage the `protocol` module directly. 6 + //// 7 + //// 80mm printers usually have a maximum of 640 dots width. 8 + //// There is no validation so please check your image beforehand. 6 9 //// 7 - //// Thank you jak for the pgm reading and bayer dithering 10 + //// Thank you jak for the pgm reading and bayer dithering 💕 8 11 9 12 import gleam/float 10 13 import gleam/int ··· 58 61 use #(width, rest) <- result.try(parse_number(rest, 0)) 59 62 use #(height, rest) <- result.try(parse_number(rest, 0)) 60 63 case rest { 61 - <<"255\n", pixels:bytes>> -> Ok(GrayscaleImage(width:, height:, pixels:)) 64 + <<"255\n", pixels:bytes>> -> 65 + Ok(GrayscaleImage(width:, height:, pixels:)) 62 66 _ -> Error(ParseError) 63 67 } 64 68 } ··· 171 175 } 172 176 } 173 177 174 - fn dither_map(image: GrayscaleImage, fun: fn(Int, Int, Int) -> Int) -> PrintableImage { 178 + fn dither_map( 179 + image: GrayscaleImage, 180 + fun: fn(Int, Int, Int) -> Int, 181 + ) -> PrintableImage { 175 182 let pixels = 176 183 dither_loop(image.pixels, image.width, 0, 0, <<>>, fun) 177 184 |> byte_align_rows(image.width)