kornelski / rust-rgb

struct RGB for sharing pixels between crates
https://lib.rs/rgb
MIT License
97 stars 19 forks source link

Add Pixel Trait and first implementation. #80

Closed ripytide closed 3 months ago

ripytide commented 3 months ago

Is my usage of core::mem::transmute() safe here? I couldn't find non-unsafe way of doing this.

If this is okay then I'll add implementations for the other Pixel types.

ripytide commented 3 months ago

I've managed to generically implement the map() function using a PixelExt trait with a generic associated type. It's the easiest way I could find.

ripytide commented 3 months ago

Okay this time I've switched to HomogenousPixel and HeterogeneousPixel traits following the discussion in #79. This way we're able to provide the map() map_colors() and map_alpha() functions!

Does this fit your requirements @kornelski?

kornelski commented 3 months ago

That's an interesting approach. I'm a bit worried how type errors may look like when this is used incorrectly, but let's roll with this for now.