Having a problem getting this to update the pixels:
pub fn apply_alpha_threshold(img: &mut image::DynamicImage, threshold: u8) {
const CLEARPIXEL: image::Rgba::<u8> = image::Rgba::<u8>([0,0,0,0]); // transparent pixel
let (width, height) = img.dimensions();
for x in 0..width {
for y in 0..height {
let pixel = img.get_pixel(x,y);
if pixel.to_rgba()[3] < threshold { // if below threshold
img.put_pixel(x,y,CLEARPIXEL); // set to clear
}
}
}
}
which is called by:
let mut image = image::io::Reader::open(texturefile(uuid,&"png"))?.decode()?;
image::imageops::flip_vertical_in_place(&mut image);
apply_alpha_threshold(&mut image, 128);
let rgba = image.to_rgba8();
// Onward to display.
This runs, but does not affect the image.
Do I need to do something to flush the working buffer back to the image structure, as in Python's image library?
I tried using get_pixel_mut, as documented here. But that's unimplemented now, and panics. See line 1906 of dynimage.rs.