Skip to content

Instantly share code, notes, and snippets.

@CptLemming
Created June 18, 2025 20:07
Show Gist options
  • Select an option

  • Save CptLemming/e3774ed202f8c2025ba6b370d8299135 to your computer and use it in GitHub Desktop.

Select an option

Save CptLemming/e3774ed202f8c2025ba6b370d8299135 to your computer and use it in GitHub Desktop.

Revisions

  1. CptLemming created this gist Jun 18, 2025.
    25 changes: 25 additions & 0 deletions main.rs
    Original 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);
    }