use image::{ImageBuffer, Rgba};
use super::super::{QRMatrix, Module};
#[inline]
fn is_dark(module: &Module) -> bool {
module.is_dark()
}
pub fn render_png(matrix: &QRMatrix, size_px: u32, quiet_zone: bool) -> ImageBuffer<Rgba<u8>, Vec<u8>> {
let margin = if quiet_zone { 4 } else { 0 };
let matrix_size = matrix.size() as u32;
let total_size = matrix_size + margin * 2;
let module_size = size_px / total_size;
let mut img: ImageBuffer<Rgba<u8>, Vec<u8>> = ImageBuffer::from_pixel(
size_px,
size_px,
Rgba([255, 255, 255, 255]),
);
let x_offset = margin * module_size;
let y_offset = margin * module_size;
for j in 0..matrix_size {
for i in 0..matrix_size {
if is_dark(&matrix.get(i as usize, j as usize)) {
for dy in 0..module_size {
for dx in 0..module_size {
let px = x_offset + i * module_size + dx;
let py = y_offset + j * module_size + dy;
img.put_pixel(px, py, Rgba([0, 0, 0, 255]));
}
}
}
}
}
img
}