diff --git a/src/escpos/image.gleam b/src/escpos/image.gleam index 835cf20..80faf92 100644 --- a/src/escpos/image.gleam +++ b/src/escpos/image.gleam @@ -1,10 +1,13 @@ -//// Module to parse/dither PBM/PGM image to be printed on monochrome +//// Module to parse and dither PBM/PGM images to be printed on monochrome //// printers. //// There are printers that can print grayscale or even color, if //// you want to do that, you'll need to implement that yourself //// and/or leverage the `protocol` module directly. +//// +//// 80mm printers usually have a maximum of 640 dots width. +//// There is no validation so please check your image beforehand. //// -//// Thank you jak for the pgm reading and bayer dithering +//// Thank you jak for the pgm reading and bayer dithering 💕 import gleam/float import gleam/int @@ -58,7 +61,8 @@ pub fn from_pgm(pgm: BitArray) -> Result(GrayscaleImage, ImageError) { use #(width, rest) <- result.try(parse_number(rest, 0)) use #(height, rest) <- result.try(parse_number(rest, 0)) case rest { - <<"255\n", pixels:bytes>> -> Ok(GrayscaleImage(width:, height:, pixels:)) + <<"255\n", pixels:bytes>> -> + Ok(GrayscaleImage(width:, height:, pixels:)) _ -> Error(ParseError) } } @@ -171,7 +175,10 @@ fn dither_bayer( } } -fn dither_map(image: GrayscaleImage, fun: fn(Int, Int, Int) -> Int) -> PrintableImage { +fn dither_map( + image: GrayscaleImage, + fun: fn(Int, Int, Int) -> Int, +) -> PrintableImage { let pixels = dither_loop(image.pixels, image.width, 0, 0, <<>>, fun) |> byte_align_rows(image.width)