imageproc icon indicating copy to clipboard operation
imageproc copied to clipboard

Pixel API

Open theotherphil opened this issue 9 years ago • 3 comments

There are currently quite a few places both in here and in the image library where we do clunky things to get at, operate on, and assign sub pixels of a given Pixel type.

We need at least:

  • Type level operations on Pixels, e.g. get the equivalent type where all channels are of a given floating point type,
  • A wider set of arithmetic operators available on Pixels (so that we can just add p and q, rather than get all their channel values, add those, and set as channels of a pixel r),
    • A handy set of bounds to express when certain operations are possible, e.g. expressing when filtering by a float-valued kernel is appropriate.

Try to replace all current iterations over pixel channels with something nicer.

theotherphil avatar Oct 02 '15 08:10 theotherphil

We should also add helpers to initialise pixels to standard values. PixelType::White, PixelType::Black, etc. For the current Luma and Rgb pixels in the image library, this is the same as zero-initialising or max-value-initialising, but when we add HSL, etc. it won't be.

theotherphil avatar Oct 02 '15 08:10 theotherphil

One could already define

const WHITE: Rgb<u8> = Rgb(data: [255, 255, 255]);

and use

pixel.from_color(WHITE)

using the FromColor trait.

nwin avatar Oct 02 '15 19:10 nwin

Thanks, I hadn't spotted that trait. I'd prefer to not have to impose a bound "where Pixel: FromColor<Rgb>" on these functions though. Black and white at least seem common enough to require from all Pixels.

theotherphil avatar Oct 02 '15 20:10 theotherphil