I work at a project written in Rust that basically mocks a printer. I get printer input, and try to convert it to human readable data (strings, images). So, for reproducing the QR code, I am converting the printer input to BitMap Slices (I created a struct that implements GenericImageView
).
BitmapImageSlice {
height,
width,
buffer: data
}
impl GenericImageView for BitmapImageSlice {
type Pixel = Rgb<u8>;
type InnerImageView = BitmapImageSlice;
fn dimensions(&self) -> (u32, u32) {
(self.width as u32, self.height as u32)
}
fn bounds(&self) -> (u32, u32, u32, u32) {
( 0, 0, self.width as u32, self.height as u32)
}
fn get_pixel(&self, x: u32, y: u32) -> Self::Pixel {
let byte = self.buffer[x as usize];
let bit_position = 7-y;
let bit = 1 << bit_position;
if (byte & bit as u8) > 0{
Rgb([0, 0, 0])
}
else {
Rgb([255, 255, 255])
}
}
fn inner(&self) -> &Self::InnerImageView {
self
}
}
My question is, how can I convert BitMapImageSlice
values to an image encoded in PNG?