Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

map_colors is not a full replacement for map_rgb #137

Open
kornelski opened this issue Oct 14, 2024 · 1 comment
Open

map_colors is not a full replacement for map_rgb #137

kornelski opened this issue Oct 14, 2024 · 1 comment

Comments

@kornelski
Copy link
Owner

map_rgb on RGBA<T, A> uses a From for the A type to make it match T, allowing code like px.map_colors(|c| c as f32 * px.a as f32) to just work and update alpha.

map_colors is just for the colors, and results in an annoying RGBA<f32, u8>.

https://docs.rs/rgb/0.8.90-alpha.2/rgb/trait.HetPixel.html#tymethod.map_colors

Should it also convert alpha? Should there be another method?

@ripytide
Copy link
Contributor

I'm a bit confused by the use-case, can you provide an example using concrete types since your example uses generic types but then also does as casts so I'm assuming it's not generic?

How about this?

use rgb::{HetPixel, Pixel, Rgba};

fn main() {
    let px: Rgba<u8> = Rgba {
        r: 0,
        g: 10,
        b: 10,
        a: 255,
    };

    let px = px.map(f32::from);
    let px = px.map_colors(|c| c * px.a);
    print!("{px}");
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants