Safe Haskell | None |
---|---|
Language | Haskell2010 |
- class (Eq cs, Enum cs, Show cs, Typeable cs) => ColorSpace cs where
- type PixelElt cs e
- data Pixel cs e
- fromChannel :: e -> Pixel cs e
- toElt :: Pixel cs e -> PixelElt cs e
- fromElt :: PixelElt cs e -> Pixel cs e
- getPxCh :: Pixel cs e -> cs -> e
- chOp :: (cs -> e' -> e) -> Pixel cs e' -> Pixel cs e
- pxOp :: (e' -> e) -> Pixel cs e' -> Pixel cs e
- chApp :: Pixel cs (e' -> e) -> Pixel cs e' -> Pixel cs e
- pxFoldMap :: Monoid m => (e -> m) -> Pixel cs e -> m
- class (ColorSpace (Opaque cs), ColorSpace cs) => Alpha cs where
- data Y = Y
- data YA
- class ColorSpace cs => ToY cs where
- class (ToY (Opaque cs), Alpha cs) => ToYA cs where
- data RGB
- data RGBA
- class ColorSpace cs => ToRGB cs where
- class (ToRGB (Opaque cs), Alpha cs) => ToRGBA cs where
- data HSI
- data HSIA
- class ColorSpace cs => ToHSI cs where
- class (ToHSI (Opaque cs), Alpha cs) => ToHSIA cs where
- data CMYK
- data CMYKA
- class ColorSpace cs => ToCMYK cs where
- class (ToCMYK (Opaque cs), Alpha cs) => ToCMYKA cs where
- data YCbCr
- data YCbCrA
- class ColorSpace cs => ToYCbCr cs where
- class (ToYCbCr (Opaque cs), Alpha cs) => ToYCbCrA cs where
- data Gray = Gray
- toGrayImages :: (Array arr cs e, Array arr Gray e) => Image arr cs e -> [Image arr Gray e]
- fromGrayImages :: forall arr cs e. (Array arr Gray e, Array arr cs e) => [Image arr Gray e] -> [cs] -> Image arr cs e
- data Binary
- data Bit
- on :: Pixel Binary Bit
- off :: Pixel Binary Bit
- isOn :: Pixel Binary Bit -> Bool
- isOff :: Pixel Binary Bit -> Bool
- fromBool :: Bool -> Pixel Binary Bit
- complement :: Pixel Binary Bit -> Pixel Binary Bit
- toPixelBinary :: (ColorSpace cs, Eq (Pixel cs e), Num e) => Pixel cs e -> Pixel Binary Bit
- fromPixelBinary :: Pixel Binary Bit -> Pixel Y Word8
- toImageBinary :: (Array arr cs e, Array arr Binary Bit, Eq (Pixel cs e)) => Image arr cs e -> Image arr Binary Bit
- fromImageBinary :: (Array arr Binary Bit, Array arr Y Word8) => Image arr Binary Bit -> Image arr Y Word8
- data Complex a :: * -> * = !a :+ !a
- (+:) :: ColorSpace cs => Pixel cs e -> Pixel cs e -> Pixel cs (Complex e)
- realPart :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs e
- imagPart :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs e
- mkPolar :: (ColorSpace cs, RealFloat e) => Pixel cs e -> Pixel cs e -> Pixel cs (Complex e)
- cis :: (ColorSpace cs, RealFloat e) => Pixel cs e -> Pixel cs (Complex e)
- polar :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> (Pixel cs e, Pixel cs e)
- magnitude :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs e
- phase :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs e
- conjugate :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs (Complex e)
- class Functor f => Applicative f where
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- (<$) :: Functor f => forall a b. a -> f b -> f a
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- liftA :: Applicative f => (a -> b) -> f a -> f b
- liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
- liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- data Word8 :: *
- data Word16 :: *
- data Word32 :: *
- data Word64 :: *
ColorSpace
class (Eq cs, Enum cs, Show cs, Typeable cs) => ColorSpace cs where Source
This class has all included color spaces installed into it and is also
intended for implementing any other possible custom color spaces. Every
instance of this class automatically installs an associated Pixel
into
Num
, Fractional
, Floating
, Functor
, Applicative
and Foldable
,
which in turn make it possible to be used by the rest of the library.
Representation of a pixel, such that it can be an element of any Array. Which is usally a tuple of channels or a channel itself for single channel color spaces.
A concrete Pixel representation for a particular color space.
fromChannel :: e -> Pixel cs e Source
Construt a pixel by replicating a same value among all of the channels.
toElt :: Pixel cs e -> PixelElt cs e Source
Convert a Pixel to a representation suitable for storage as an unboxed element, usually a tuple of channels.
fromElt :: PixelElt cs e -> Pixel cs e Source
Convert from an elemnt representation back to a Pixel.
getPxCh :: Pixel cs e -> cs -> e Source
Retrieve Pixel's channel value
chOp :: (cs -> e' -> e) -> Pixel cs e' -> Pixel cs e Source
Map a channel aware function over all Pixel's channels.
pxOp :: (e' -> e) -> Pixel cs e' -> Pixel cs e Source
Map a function over all Pixel's channels.
chApp :: Pixel cs (e' -> e) -> Pixel cs e' -> Pixel cs e Source
Function application to a Pixel.
pxFoldMap :: Monoid m => (e -> m) -> Pixel cs e -> m Source
A pixel eqiuvalent of foldMap
.
class (ColorSpace (Opaque cs), ColorSpace cs) => Alpha cs where Source
getAlpha :: Pixel cs e -> e Source
Get an alpha channel of a transparant pixel.
addAlpha :: e -> Pixel (Opaque cs) e -> Pixel cs e Source
Add an alpha channel of an opaque pixel.
addAlpha 0 (PixelHSI 1 2 3) == PixelHSIA 1 2 3 0
dropAlpha :: Pixel cs e -> Pixel (Opaque cs) e Source
Convert a transparent pixel to an opaque one by dropping the alpha channel.
dropAlpha (PixelRGBA 1 2 3 4) == PixelRGB 1 2 3
Luma
Luma or brightness, that is usually denoted as Y'
.
Luma with Alpha channel.
class ColorSpace cs => ToY cs where Source
class (ToY (Opaque cs), Alpha cs) => ToYA cs where Source
Nothing
RGB
class ColorSpace cs => ToRGB cs where Source
class (ToRGB (Opaque cs), Alpha cs) => ToRGBA cs where Source
Nothing
HSI
class ColorSpace cs => ToHSI cs where Source
class (ToHSI (Opaque cs), Alpha cs) => ToHSIA cs where Source
Nothing
CMYK
Enum CMYK | |
Eq CMYK | |
Show CMYK | |
ColorSpace CMYK | |
ToY CMYK | |
ToRGB CMYK | |
Typeable * CMYK | |
Eq e => Eq (Pixel CMYK e) | |
Show e => Show (Pixel CMYK e) | |
ManifestArray arr CMYK Double => Writable (Image arr CMYK Double) TIF | |
ManifestArray arr CMYK Word16 => Writable (Image arr CMYK Word16) TIF | |
ManifestArray arr CMYK Word8 => Writable (Image arr CMYK Word8) TIF | |
ManifestArray arr CMYK Double => Writable (Image arr CMYK Double) JPG | |
ManifestArray arr CMYK Word8 => Writable (Image arr CMYK Word8) JPG | |
Array arr CMYK Word16 => Readable (Image arr CMYK Word16) TIF | |
Array arr CMYK Word8 => Readable (Image arr CMYK Word8) TIF | |
Array arr CMYK Word8 => Readable (Image arr CMYK Word8) JPG | |
data Pixel CMYK = PixelCMYK !e !e !e !e | |
type PixelElt CMYK e = (e, e, e, e) |
CyanCMYKA | Cyan |
MagCMYKA | Mahenta |
YelCMYKA | Yellow |
KeyCMYKA | Key (Black) |
AlphaCMYKA | Alpha |
class ColorSpace cs => ToCMYK cs where Source
class (ToCMYK (Opaque cs), Alpha cs) => ToCMYKA cs where Source
Nothing
YCbCr
Enum YCbCr | |
Eq YCbCr | |
Show YCbCr | |
ColorSpace YCbCr | |
ToY YCbCr | |
ToRGB YCbCr | |
Typeable * YCbCr | |
Eq e => Eq (Pixel YCbCr e) | |
Show e => Show (Pixel YCbCr e) | |
ManifestArray arr YCbCr Double => Writable (Image arr YCbCr Double) TIF | |
ManifestArray arr YCbCr Word8 => Writable (Image arr YCbCr Word8) TIF | |
ManifestArray arr YCbCr Double => Writable (Image arr YCbCr Double) JPG | |
ManifestArray arr YCbCr Word8 => Writable (Image arr YCbCr Word8) JPG | |
Array arr YCbCr Word8 => Readable (Image arr YCbCr Word8) JPG | |
data Pixel YCbCr = PixelYCbCr !e !e !e | |
type PixelElt YCbCr e = (e, e, e) |
class ColorSpace cs => ToYCbCr cs where Source
class (ToYCbCr (Opaque cs), Alpha cs) => ToYCbCrA cs where Source
Nothing
Gray
This is a signgle channel colorspace, that is designed to hold any channel
from any other colorspace, hence it is not convertible to and from, but
rather is here to allow separation of channels from other multichannel
colorspaces. If you are looking for a true grayscale colorspace
Y
should be used instead.
toGrayImages :: (Array arr cs e, Array arr Gray e) => Image arr cs e -> [Image arr Gray e] Source
Separate an image into a list of images with Gray
pixels containing every
channel from the source image.
>>>
frog <- readImageRGB "images/frog.jpg"
>>>
let [frog_red, frog_green, frog_blue] = toGrayImages frog
>>>
writeImage "images/frog_red.png" $ toImageY frog_red
>>>
writeImage "images/frog_green.jpg" $ toImageY frog_green
>>>
writeImage "images/frog_blue.jpg" $ toImageY frog_blue
fromGrayImages :: forall arr cs e. (Array arr Gray e, Array arr cs e) => [Image arr Gray e] -> [cs] -> Image arr cs e Source
Combine a list of images with Gray
pixels into an image of any color
space, by supplying an order of color space channels.
For example here is a frog with swapped BlueRGB
and GreenRGB
channels.
>>>
writeImage "images/frog_rbg.jpg" $ fromGrayImages [frog_red, frog_green, frog_blue] [RedRGB, BlueRGB, GreenRGB]
It is worth noting though, that separating image channels can be sometimes pretty useful, the same effect as above can be achieved in a much simpler and more efficient way:
map ((PixelRGB r g b) -> PixelRGB r b g) frog
Binary
This is a Binary colorspace, pixel's of which can be created using these constructors:
on
- Represents value
1
orTrue
. It's a foreground pixel and is displayed in black. off
- Represents value
0
orFalse
. It's a background pixel and is displayed in white.
Note, that values are inverted before writing to or reading from file, since
grayscale images represent black as a 0
value and white as 1
on a
[0,1]
scale.
Binary pixels also behave as binary numbers with a size of 1-bit, for instance:
>>>
on + on -- equivalent to: 1 .|. 1
<Binary:(1)>>>>
(on + on) * off -- equivalent to: (1 .|. 1) .&. 0
<Binary:(0)>>>>
(on + on) - on
<Binary:(0)>
Enum Binary | |
Eq Binary | |
Show Binary | |
ColorSpace Binary | |
Typeable * Binary | |
Array arr Binary Bit => Readable [Image arr Binary Bit] [PBM] | |
Eq e => Eq (Pixel Binary e) | |
Show (Pixel Binary Bit) | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) TIF | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) TGA | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) PNG | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) BMP | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) TIF | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) TGA | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) PNG | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) BMP | |
Array arr Binary Bit => Readable (Image arr Binary Bit) PBM | |
data Pixel Binary = PixelBinary !e | |
type PixelElt Binary e = e |
Under the hood, Binary pixels are represented as Word8
that can only take
values of 0
or 1
.
Eq Bit | |
Num Bit | |
Ord Bit | |
Elt Bit | |
Unbox Bit | |
Typeable * Bit | |
Vector Vector Bit | |
MVector MVector Bit | |
Array arr Binary Bit => Readable [Image arr Binary Bit] [PBM] | |
Show (Pixel Binary Bit) | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) TIF | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) TGA | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) PNG | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) BMP | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) TIF | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) TGA | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) PNG | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) BMP | |
Array arr Binary Bit => Readable (Image arr Binary Bit) PBM | |
data Vector Bit = V_Bit (Vector Word8) | |
data MVector s0 Bit = MV_Bit (MVector s Word8) |
Represents value True
or 1
in binary. Often also called a foreground
pixel of an object.
off :: Pixel Binary Bit Source
Represents value False
or 0
in binary. Often also called a background
pixel.
fromBool :: Bool -> Pixel Binary Bit Source
Convert a Bool
to a PixelBin
pixel.
>>>
isOn (fromBool True)
True
complement :: Pixel Binary Bit -> Pixel Binary Bit Source
Invert value of a pixel. Equivalent of not
for Bool's.
toPixelBinary :: (ColorSpace cs, Eq (Pixel cs e), Num e) => Pixel cs e -> Pixel Binary Bit Source
toImageBinary :: (Array arr cs e, Array arr Binary Bit, Eq (Pixel cs e)) => Image arr cs e -> Image arr Binary Bit Source
fromImageBinary :: (Array arr Binary Bit, Array arr Y Word8) => Image arr Binary Bit -> Image arr Y Word8 Source
Complex
Rectangular form
data Complex a :: * -> *
Complex numbers are an algebraic type.
For a complex number z
,
is a number with the magnitude of abs
zz
,
but oriented in the positive real direction, whereas
has the phase of signum
zz
, but unit magnitude.
!a :+ !a infix 6 | forms a complex number from its real and imaginary rectangular components. |
(RealFloat a, Unbox a) => Vector Vector (Complex a) | |
(RealFloat a, Unbox a) => MVector MVector (Complex a) | |
Eq a => Eq (Complex a) | |
RealFloat a => Floating (Complex a) | |
RealFloat a => Fractional (Complex a) | |
Data a => Data (Complex a) | |
RealFloat a => Num (Complex a) | |
Read a => Read (Complex a) | |
Show a => Show (Complex a) | |
(RealFloat a, NFData a) => NFData (Complex a) | |
(RealFloat a, Unbox a) => Unbox (Complex a) | |
Typeable (* -> *) Complex | |
data MVector s (Complex a) = MV_Complex (MVector s (a, a)) | |
data Vector (Complex a) = V_Complex (Vector (a, a)) |
realPart :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs e Source
Extracts the real part of a complex pixel.
imagPart :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs e Source
Extracts the imaginary part of a complex pixel.
Polar form
mkPolar :: (ColorSpace cs, RealFloat e) => Pixel cs e -> Pixel cs e -> Pixel cs (Complex e) Source
Form a complex pixel from polar components of magnitude and phase.
magnitude :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs e Source
The nonnegative magnitude of a complex pixel.
Conjugate
conjugate :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs (Complex e) Source
The conjugate of a complex pixel.
Re-exports
class Functor f => Applicative f where
A functor with application, providing operations to
A minimal complete definition must include implementations of these functions satisfying the following laws:
- identity
pure
id
<*>
v = v- composition
pure
(.)<*>
u<*>
v<*>
w = u<*>
(v<*>
w)- homomorphism
pure
f<*>
pure
x =pure
(f x)- interchange
u
<*>
pure
y =pure
($
y)<*>
u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor
instance for f
will satisfy
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
pure :: a -> f a
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4
Sequential application.
(*>) :: f a -> f b -> f b infixl 4
Sequence actions, discarding the value of the first argument.
(<*) :: f a -> f b -> f a infixl 4
Sequence actions, discarding the value of the second argument.
(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4
A variant of <*>
with the arguments reversed.
liftA :: Applicative f => (a -> b) -> f a -> f b
liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
Lift a binary function to actions.
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
Lift a ternary function to actions.
data Word8 :: *
8-bit unsigned integer type
data Word16 :: *
16-bit unsigned integer type
data Word32 :: *
32-bit unsigned integer type
Bounded Word32 | |
Enum Word32 | |
Eq Word32 | |
Integral Word32 | |
Num Word32 | |
Ord Word32 | |
Read Word32 | |
Real Word32 | |
Show Word32 | |
Ix Word32 | |
Unpackable Word32 | |
Pixel Pixel32 | |
LumaPlaneExtractable Pixel32 | |
PackeablePixel Pixel32 | |
Storable Word32 | |
Bits Word32 | |
FiniteBits Word32 | |
NFData Word32 | |
Prim Word32 | |
Random Word32 | |
Elt Word32 | |
Unbox Word32 | |
Elevator Word32 | Values are scaled to |
Typeable * Word32 | |
BinaryParam Endianness Word32 | |
Vector Vector Word32 | |
MVector MVector Word32 | |
type StorageType Word32 = Word32 | |
type PixelBaseComponent Pixel32 = Word32 | |
type PackedRepresentation Pixel32 = Pixel32 | |
data Vector Word32 = V_Word32 (Vector Word32) | |
data MVector s Word32 = MV_Word32 (MVector s Word32) |
data Word64 :: *
64-bit unsigned integer type
Bounded Word64 | |
Enum Word64 | |
Eq Word64 | |
Integral Word64 | |
Num Word64 | |
Ord Word64 | |
Read Word64 | |
Real Word64 | |
Show Word64 | |
Ix Word64 | |
Storable Word64 | |
Bits Word64 | |
FiniteBits Word64 | |
NFData Word64 | |
Prim Word64 | |
Random Word64 | |
Elt Word64 | |
Unbox Word64 | |
Elevator Word64 | Values are scaled to |
Typeable * Word64 | |
Vector Vector Word64 | |
MVector MVector Word64 | |
data Vector Word64 = V_Word64 (Vector Word64) | |
data MVector s Word64 = MV_Word64 (MVector s Word64) |