Copyright | (c) Alexey Kuleshevich 2016 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <[email protected]> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Graphics.Image.ColorSpace
Contents
Description
- class (Eq cs, Enum cs, Show cs, Typeable cs) => ColorSpace cs where
- data Pixel cs e
- class (ColorSpace (Opaque cs), ColorSpace cs) => Alpha cs where
- type Opaque cs
- class Elevator e 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)
- data Word8 :: *
- data Word16 :: *
- data Word32 :: *
- data Word64 :: *
ColorSpace
class (Eq cs, Enum cs, Show cs, Typeable cs) => ColorSpace cs 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.
Minimal complete definition
fromChannel, toElt, fromElt, getPxCh, chOp, pxOp, chApp, pxFoldMap, csColour
Associated Types
A concrete Pixel representation for a particular color space.
Instances
class (ColorSpace (Opaque cs), ColorSpace cs) => Alpha cs Source #
A color space that supports transparency.
class Elevator e where Source #
A class with a set of convenient functions that allow for changing precision of channels within pixels, while scaling the values to keep them in an appropriate range.
>>>
let rgb = PixelRGB 0.0 0.5 1.0 :: Pixel RGB Double
>>>
toWord8 rgb
<RGB:(0|128|255)>
Methods
toWord8 :: ColorSpace cs => Pixel cs e -> Pixel cs Word8 Source #
toWord16 :: ColorSpace cs => Pixel cs e -> Pixel cs Word16 Source #
toWord32 :: ColorSpace cs => Pixel cs e -> Pixel cs Word32 Source #
toWord64 :: ColorSpace cs => Pixel cs e -> Pixel cs Word64 Source #
toFloat :: ColorSpace cs => Pixel cs e -> Pixel cs Float Source #
toDouble :: ColorSpace cs => Pixel cs e -> Pixel cs Double Source #
fromDouble :: ColorSpace cs => Pixel cs Double -> Pixel cs e Source #
Luma
Luma or brightness, that is usually denoted as Y'
.
Constructors
Y |
Instances
Luma with Alpha channel.
Instances
class ColorSpace cs => ToY cs where Source #
Conversion to Luma color space.
Minimal complete definition
class (ToY (Opaque cs), Alpha cs) => ToYA cs where Source #
Conversion to Luma from another color space with Alpha channel.
RGB
Red, Green and Blue color space.
Instances
Red, Green and Blue color space with Alpha channel.
Instances
class ColorSpace cs => ToRGB cs where Source #
Conversion to RGB
color space.
Minimal complete definition
class (ToRGB (Opaque cs), Alpha cs) => ToRGBA cs where Source #
Conversion to RGBA
from another color space with Alpha channel.
HSI
Hue, Saturation and Intensity color space.
Hue, Saturation and Intensity color space with Alpha channel.
class ColorSpace cs => ToHSI cs where Source #
Conversion to HSI
color space.
Minimal complete definition
class (ToHSI (Opaque cs), Alpha cs) => ToHSIA cs where Source #
Conversion to HSIA
from another color space with Alpha channel.
CMYK
Cyan, Magenta, Yellow and Black color space.
Instances
Enum CMYK Source # | |
Eq CMYK Source # | |
Show CMYK Source # | |
ColorSpace CMYK Source # | |
Eq e => Eq (Pixel CMYK e) Source # | |
Show e => Show (Pixel CMYK e) Source # | |
ManifestArray arr CMYK Double => Writable (Image arr CMYK Double) TIF Source # | |
ManifestArray arr CMYK Word16 => Writable (Image arr CMYK Word16) TIF Source # | |
ManifestArray arr CMYK Word8 => Writable (Image arr CMYK Word8) TIF Source # | |
ManifestArray arr CMYK Word8 => Writable (Image arr CMYK Word8) JPG Source # | |
Array arr CMYK Word16 => Readable (Image arr CMYK Word16) TIF Source # | |
Array arr CMYK Word8 => Readable (Image arr CMYK Word8) TIF Source # | |
Array arr CMYK Word8 => Readable (Image arr CMYK Word8) JPG Source # | |
data Pixel CMYK Source # | |
type PixelElt CMYK e Source # | |
Cyan, Magenta, Yellow and Black color space with Alpha channel.
Constructors
CyanCMYKA | Cyan |
MagCMYKA | Magenta |
YelCMYKA | Yellow |
KeyCMYKA | Key (Black) |
AlphaCMYKA | Alpha |
class ColorSpace cs => ToCMYK cs where Source #
Conversion to CMYK
color space.
Minimal complete definition
class (ToCMYK (Opaque cs), Alpha cs) => ToCMYKA cs where Source #
Conversion to CMYKA
from another color space with Alpha channel.
YCbCr
Color space is used to encode RGB information and is used in JPEG compression.
Constructors
LumaYCbCr | Luma component (commonly denoted as Y') |
CBlueYCbCr | Blue difference chroma component |
CRedYCbCr | Red difference chroma component |
Instances
Enum YCbCr Source # | |
Eq YCbCr Source # | |
Show YCbCr Source # | |
ColorSpace YCbCr Source # | |
Eq e => Eq (Pixel YCbCr e) Source # | |
Show e => Show (Pixel YCbCr e) Source # | |
ManifestArray arr YCbCr Double => Writable (Image arr YCbCr Double) TIF Source # | |
ManifestArray arr YCbCr Word8 => Writable (Image arr YCbCr Word8) TIF Source # | |
ManifestArray arr YCbCr Word8 => Writable (Image arr YCbCr Word8) JPG Source # | |
Array arr YCbCr Word8 => Readable (Image arr YCbCr Word8) JPG Source # | |
data Pixel YCbCr Source # | |
type PixelElt YCbCr e Source # | |
YCbCr color space with Alpha channel.
Constructors
LumaYCbCrA | Luma component (commonly denoted as Y') |
CBlueYCbCrA | Blue difference chroma component |
CRedYCbCrA | Red difference chroma component |
AlphaYCbCrA | Alpha component. |
class ColorSpace cs => ToYCbCr cs where Source #
Conversion to YCbCr
color space.
Minimal complete definition
class (ToYCbCr (Opaque cs), Alpha cs) => ToYCbCrA cs where Source #
Conversion to YCbCrA
from another color space with Alpha channel.
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.
Constructors
Gray |
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)>
Instances
Under the hood, Binary pixels are represented as Word8
that can only take
values of 0
or 1
.
Instances
Eq Bit Source # | |
Num Bit Source # | |
Ord Bit Source # | |
Array arr Binary Bit => Readable [Image arr Binary Bit] [PBM] Source # | |
Show (Pixel Binary Bit) Source # | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) TIF Source # | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) TGA Source # | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) PNG Source # | |
ManifestArray arr Binary Bit => Writable (Image arr Binary Bit) BMP Source # | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) TIF Source # | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) TGA Source # | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) PNG Source # | |
(Array arr Y Word8, Array arr Binary Bit) => Readable (Image arr Binary Bit) BMP Source # | |
Array arr Binary Bit => Readable (Image arr Binary Bit) PBM Source # | |
data Vector Bit # | |
data MVector s Bit # | |
on :: Pixel Binary Bit Source #
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 #
Convert any pixel to binary pixel.
toImageBinary :: (Array arr cs e, Array arr Binary Bit, Eq (Pixel cs e)) => Image arr cs e -> Image arr Binary Bit Source #
Convert any image to binary image.
fromImageBinary :: (Array arr Binary Bit, Array arr Y Word8) => Image arr Binary Bit -> Image arr Y Word8 Source #
Convert a Binary image to Luma image
Complex
Rectangular form
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.
The Foldable
and Traversable
instances traverse the real part first.
Constructors
~a :+ ~a infix 6 | forms a complex number from its real and imaginary rectangular components. |
Instances
Monad Complex | |
Functor Complex | |
Applicative Complex | |
Foldable Complex | |
Traversable Complex | |
Generic1 Complex | |
Representable Complex | |
Additive Complex | |
Affine Complex | |
Complicated Complex | |
(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) | |
Generic (Complex a) | |
(Default a, RealFloat a) => Default (Complex a) | |
Storable a => Storable (Complex a) | |
NFData a => NFData (Complex a) | |
(RealFloat a, Unbox a) => Unbox (Complex a) | |
type Rep1 Complex | |
type Rep Complex | |
type Diff Complex | |
data MVector s (Complex a) | |
type Rep (Complex a) | |
type Index (Complex a) | |
data Vector (Complex 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
8-bit unsigned integer type
Instances
16-bit unsigned integer type
Instances
32-bit unsigned integer type
Instances
Bounded Word32 | |
Enum Word32 | |
Eq Word32 | |
Integral Word32 | |
Num Word32 | |
Ord Word32 | |
Read Word32 | |
Real Word32 | |
Show Word32 | |
Ix Word32 | |
Lift Word32 | |
Default Word32 | |
Unpackable Word32 | |
Pixel Pixel32 | |
LumaPlaneExtractable Pixel32 | |
PackeablePixel Pixel32 | |
Storable Word32 | |
Bits Word32 | |
FiniteBits Word32 | |
NFData Word32 | |
Hashable Word32 | |
Prim Word32 | |
Unbox Word32 | |
Elt Word32 | |
IArray UArray Word32 | |
Vector Vector Word32 | |
MVector MVector Word32 | |
MArray (STUArray s) Word32 (ST s) | |
type StorageType Word32 | |
type PixelBaseComponent Pixel32 | |
type PackedRepresentation Pixel32 | |
type Unsigned Word32 | |
type Signed Word32 | |
data Vector Word32 | |
data MVector s Word32 | |
64-bit unsigned integer type
Instances
Bounded Word64 | |
Enum Word64 | |
Eq Word64 | |
Integral Word64 | |
Num Word64 | |
Ord Word64 | |
Read Word64 | |
Real Word64 | |
Show Word64 | |
Ix Word64 | |
Lift Word64 | |
Default Word64 | |
Storable Word64 | |
Bits Word64 | |
FiniteBits Word64 | |
NFData Word64 | |
Hashable Word64 | |
Prim Word64 | |
Unbox Word64 | |
Elt Word64 | |
IArray UArray Word64 | |
Vector Vector Word64 | |
MVector MVector Word64 | |
MArray (STUArray s) Word64 (ST s) | |
type Unsigned Word64 | |
type Signed Word64 | |
data Vector Word64 | |
data MVector s Word64 | |
Orphan instances
Elevator Double Source # | Values are scaled to |
Elevator Float Source # | Values are scaled to |
Elevator Word8 Source # | Values are scaled to |
Elevator Word16 Source # | Values are scaled to |
Elevator Word32 Source # | Values are scaled to |
Elevator Word64 Source # | Values are scaled to |
ToYCbCrA RGBA Source # | |
ToYCbCr RGB Source # | |
ToRGBA YCbCrA Source # | |
ToRGBA YA Source # | |
ToRGBA HSIA Source # | |
ToRGBA CMYKA Source # | |
ToRGB YCbCr Source # | |
ToRGB Y Source # | |
ToRGB HSI Source # | |
ToRGB CMYK Source # | |
ToYA YCbCrA Source # | |
ToYA RGBA Source # | |
ToYA HSIA Source # | |
ToY YCbCr Source # | |
ToY RGB Source # | Computes Luma: |
ToY HSI Source # | |
ToY Gray Source # | |
ToY CMYK Source # | |
ToHSIA RGBA Source # | |
ToHSIA YA Source # | |
ToHSI RGB Source # | |
ToHSI Y Source # | |
ToCMYKA RGBA Source # | |
ToCMYK RGB Source # | |