basic functions for rxing-cli

This commit is contained in:
Henry Schimke
2023-01-07 14:03:48 -06:00
parent dbd2ec9a39
commit 23942e7db2
5 changed files with 65 additions and 3 deletions

View File

@@ -662,3 +662,24 @@ impl fmt::Display for BitMatrix {
write!(f, "{}", self.toString("X ", " "))
}
}
#[cfg(feature = "image")]
impl From<BitMatrix> for image::DynamicImage {
fn from(value: BitMatrix) -> Self {
(&value).into()
}
}
#[cfg(feature = "image")]
impl From<&BitMatrix> for image::DynamicImage {
fn from(value: &BitMatrix) -> Self {
let mut pixels = image::ImageBuffer::new(value.width, value.height);
for y in 0..value.height {
for x in 0..value.width {
pixels.put_pixel(x, y, image::Luma([if value.get(x, y) {u8::MIN} else {u8::MAX} ]));
}
}
pixels.into()
}
}