PistonDevelopers/resize

How to use this crate with a custom pixel format?

surma opened this issue · 1 comments

surma commented

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:

type RGBF64 = RGB<f64>;

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?

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