use image::{ImageFormat, ImageReader, Pixel}; fn main() { println!("cargo:rerun-if-changed=script.ld"); println!("cargo:rerun-if-changed=icons/handshake_14x14.gif"); println!("cargo:rerun-if-changed=icons/mask_14x14.gif"); let path = std::path::PathBuf::from("icons"); let reader = ImageReader::open(path.join("handshake_14x14.gif")).unwrap(); let img = reader.decode().unwrap(); let mut gray = img.into_luma8(); // Apply mask let mask = ImageReader::open(path.join("mask_14x14.gif")) .unwrap() .decode() .unwrap() .into_luma8(); for (x, y, mask_pixel) in mask.enumerate_pixels() { let mask_value = mask_pixel[0]; let mut gray_pixel = *gray.get_pixel(x, y); if mask_value == 0 { gray_pixel = image::Luma([0]); } else { gray_pixel.invert(); } gray.put_pixel(x, y, gray_pixel); } let glyph_path = std::path::PathBuf::from("glyphs"); gray.save_with_format(glyph_path.join("home_nano_nbgl.png"), ImageFormat::Png) .unwrap(); }