-
Notifications
You must be signed in to change notification settings - Fork 605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invert Alpha method #2257
Comments
I’m not a maintainer of this crate but my first impression is that this feels a bit too niche to be worth adding. As for how to implement this function: you should be able to just use (or copy-paste) https://github.com/image-rs/imageproc/blob/master/src/map.rs#L159-L175 |
@theotherphil sure, but seeing as I'm struggling to even figure out how to do this without a dedicated method, why not implement it for when someone does need it? I don't personally see any downsides to doing it.
I'll give it another shot. I tried with |
I still don't know how I can get a Subpixel from a number. That's all I need to know. @theotherphil that code you linked is from the imageproc crate which has their own Image type with it's own methods (like |
The However, I guess the problem you’re actually having is that you’ve loaded an image into a |
Oh, that makes more sense.
I've actually just copied
Yeah, I figured this would be the case but I don't know how to workaround that at the moment. I think I sort of figured it out by looking at how pub fn invert_alpha<I: GenericImage>(image: &mut I) {
let (width, height) = image.dimensions();
for y in 0..height {
for x in 0..width {
let mut p = image.get_pixel(x, y);
p.apply_with_alpha(
|f| f,
|g| {
let a: u8 = NumCast::from(g).unwrap();
NumCast::from(u8::MAX - a).unwrap()
},
);
image.put_pixel(x, y, p);
}
}
} |
I would like to be able to easily flip the image's Alpha channel with a method provided by the crate.
My specific use case for this functionality is converting certain Blender textures which store Glossiness in the Alpha channel but need to be plugged into the Roughness material input.
Draft
I would like to implement this if possible.
I'm having a bit of trouble figuring out the best way to do this
but I'll keep trying.I have absolutely no idea. any guidance would be very welcome.The text was updated successfully, but these errors were encountered: