Created
June 18, 2025 20:07
-
-
Save CptLemming/e3774ed202f8c2025ba6b370d8299135 to your computer and use it in GitHub Desktop.
Revisions
-
CptLemming created this gist
Jun 18, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ use image::{ImageBuffer, Rgba}; use imageproc::{map::map_pixels_mut, window::display_image}; const WIDTH: u32 = 500; const HEIGHT: u32 = 500; const NUM_PIXELS: u32 = WIDTH * HEIGHT; const PIXEL_SIZE: u32 = 4; const NUM_BYTES: u32 = NUM_PIXELS * PIXEL_SIZE; fn main() { // let mut data = [0u8; NUM_BYTES as usize]; // let buf = &mut data[..]; let buf = unsafe { let x = 1u8; let ptr = x as *mut _; std::slice::from_raw_parts_mut(ptr, NUM_BYTES as usize) }; let mut image: ImageBuffer<Rgba<u8>, &mut [u8]> = ImageBuffer::from_raw(WIDTH, HEIGHT, buf).expect("No image"); map_pixels_mut(&mut image, |x, y, p| Rgba([100, p.0[1], p.0[2], 255])); display_image("", &image, WIDTH, HEIGHT); }