PistonDevelopers / resize

Simple resampling library in pure Rust
http://docs.piston.rs/resize/resize/
MIT License
126 stars 18 forks source link

How to use this crate with a custom pixel format? #27

Closed surma closed 4 years ago

surma commented 4 years ago

I'm trying to use this crate with an image consisting of RGB<f64>. As that type isn't provided by this crate, I defined it myself and implemented PixelFormat:

```rust type RGBF64 = RGB; impl resize::PixelFormat for RGBF64 { type InputPixel = Self; type OutputPixel = Self; type Accumulator = Self; // #[inline(always)] fn new() -> Self::Accumulator { RGB::new(0.,0.,0.) } // #[inline(always)] fn add(&self, acc: &mut Self::Accumulator, inp: Self::InputPixel, coeff: f32) { acc.r += inp.r * coeff; acc.g += inp.g * coeff; acc.b += inp.b * coeff; } // #[inline(always)] fn add_acc(acc: &mut Self::Accumulator, inp: Self::Accumulator, coeff: f32) { acc.r += inp.r * coeff; acc.g += inp.g * coeff; acc.b += inp.b * coeff; } // #[inline(always)] fn into_pixel(&self, acc: Self::Accumulator) -> Self::OutputPixel { acc } } ```

The top-level resize() function is marked as deprecated and says to use new().resize() instead. That function, however, is only implemented for formats that implement PixelFormatBackCompatShim, which is a non-exposed trait. In addition, it is marked as deprecated and recommends to use from_slice(), which doesn't seem to exist (@kornelski said that might have been committed by accident).

How can I use this crate with a custom pixel format?

kornelski commented 4 years ago

I've added f32/f64 pixels in v0.5.2