Module

Puregrain.Pixel

Package
purescript-puregrain
Repository
roman-mkh/puregrain

Pixel types: a single gray channel (Gray, a plain Number), RGB and RGBA, with channel values on the 0–255 scale by convention.

Error diffusion adds and subtracts error, so a pixel type must be a Ring, and Scalable by the kernel's Number weights. MapChannels lets a one-channel quantizer work on every channel of a pixel (see Puregrain.Quantize.perChannel), and ColorChannels lets a pixel be converted to light and back, alpha excepted (see Puregrain.Gamma).

#Gray Source

type Gray = Number

A gray pixel: one channel, a plain Number, from 0 (black) to 255 (white) by convention.

#RGB Source

newtype RGB

A color pixel: red, green and blue, each from 0 to 255 by convention. Adds, subtracts and scales channel by channel, as error diffusion needs.

Constructors

Instances

#RGBA Source

newtype RGBA

A color pixel with alpha: as RGB, plus a, which error diffusion treats like the other channels.

Constructors

Instances

#Scalable Source

class (Ring a) <= Scalable a  where

A pixel type that error diffusion can scale by a kernel's weights. With Ring, for adding and subtracting error, it's what ditherImage needs from a pixel type.

Members

  • scale :: Number -> a -> a

    Multiplies every channel by a weight.

    • Number: the weight, a kernel's share of the error.
    • a: the pixel.

Instances

#MapChannels Source

class MapChannels a  where

A pixel type whose channels can be mapped one by one: what Puregrain.Quantize.perChannel needs to run a one-channel quantizer on every channel. Laws, as for any functor-like mapping:

mapChannels identity == identity
mapChannels (f <<< g) == mapChannels f <<< mapChannels g

Members

  • mapChannels :: (Number -> Number) -> a -> a

    Applies the function to every channel, independently.

    • Number -> Number: the function for one channel.
    • a: the pixel.

Instances

#ColorChannels Source

class ColorChannels a  where

A pixel type whose color channels can be mapped one by one, leaving any other channel as it is: what converting a pixel between stored values and light needs (Puregrain.Gamma.toLight and fromLight), since alpha isn't on a light curve. Laws, as for MapChannels:

mapColorChannels identity == identity
mapColorChannels (f <<< g) == mapColorChannels f <<< mapColorChannels g

Members

  • mapColorChannels :: (Number -> Number) -> a -> a

    Applies the function to every color channel, independently.

    • Number -> Number: the function for one channel.
    • a: the pixel.

Instances