-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Picture loading/serialization (in png, jpeg, bitmap, gif, tiff and radiance)
--
--
-- This library can load and store images in PNG,Bitmap, Jpeg, Radiance
-- and read Gif and Tiff images.
@package JuicyPixels
@version 3.1
-- | Module providing the basic types for image manipulation in the
-- library. Defining the types used to store all those _Juicy Pixels_
module Codec.Picture.Types
-- | Image or pixel buffer, the coordinates are assumed to start from the
-- upper-left corner of the image, with the horizontal position first,
-- then the vertical one.
data Image a
Image :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> Vector (PixelBaseComponent a) -> Image a
-- | Width of the image in pixels
imageWidth :: Image a -> {-# UNPACK #-} !Int
-- | Height of the image in pixels.
imageHeight :: Image a -> {-# UNPACK #-} !Int
-- | The real image, to extract pixels at some position you should use the
-- helpers functions.
imageData :: Image a -> Vector (PixelBaseComponent a)
-- | Image or pixel buffer, the coordinates are assumed to start from the
-- upper-left corner of the image, with the horizontal position first,
-- then the vertical one. The image can be transformed in place.
data MutableImage s a
MutableImage :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> STVector s (PixelBaseComponent a) -> MutableImage s a
-- | Width of the image in pixels
mutableImageWidth :: MutableImage s a -> {-# UNPACK #-} !Int
-- | Height of the image in pixels.
mutableImageHeight :: MutableImage s a -> {-# UNPACK #-} !Int
-- | The real image, to extract pixels at some position you should use the
-- helpers functions.
mutableImageData :: MutableImage s a -> STVector s (PixelBaseComponent a)
-- | Type allowing the loading of an image with different pixel structures
data DynamicImage
-- | A greyscale image.
ImageY8 :: (Image Pixel8) -> DynamicImage
-- | A greyscale image with 16bit components
ImageY16 :: (Image Pixel16) -> DynamicImage
-- | A greyscale HDR image
ImageYF :: (Image PixelF) -> DynamicImage
-- | An image in greyscale with an alpha channel.
ImageYA8 :: (Image PixelYA8) -> DynamicImage
-- | An image in greyscale with alpha channel on 16 bits.
ImageYA16 :: (Image PixelYA16) -> DynamicImage
-- | An image in true color.
ImageRGB8 :: (Image PixelRGB8) -> DynamicImage
-- | An image in true color with 16bit depth.
ImageRGB16 :: (Image PixelRGB16) -> DynamicImage
-- | An image with HDR pixels
ImageRGBF :: (Image PixelRGBF) -> DynamicImage
-- | An image in true color and an alpha channel.
ImageRGBA8 :: (Image PixelRGBA8) -> DynamicImage
-- | A true color image with alpha on 16 bits.
ImageRGBA16 :: (Image PixelRGBA16) -> DynamicImage
-- | An image in the colorspace used by Jpeg images.
ImageYCbCr8 :: (Image PixelYCbCr8) -> DynamicImage
-- | An image in the colorspace CMYK
ImageCMYK8 :: (Image PixelCMYK8) -> DynamicImage
-- | An image in the colorspace CMYK and 16 bots precision
ImageCMYK16 :: (Image PixelCMYK16) -> DynamicImage
-- | `O(n)` Yield an immutable copy of an image by making a copy of it
freezeImage :: (Storable (PixelBaseComponent a), PrimMonad m) => MutableImage (PrimState m) a -> m (Image a)
-- | `O(1)` Unsafe convert a mutable image to an immutable one without
-- copying. The mutable image may not be used after this operation.
unsafeFreezeImage :: (Storable (PixelBaseComponent a), PrimMonad m) => MutableImage (PrimState m) a -> m (Image a)
-- | Simple alias for greyscale value in 8 bits.
type Pixel8 = Word8
-- | Simple alias for greyscale value in 16 bits.
type Pixel16 = Word16
-- | Floating greyscale value, the 0 to 255 8 bit range maps to 0 to 1 in
-- this floating version
type PixelF = Float
-- | Pixel type storing Luminance (Y) and alpha information on 8 bits.
-- Value are stored in the following order :
--
--
data PixelYA8
PixelYA8 :: {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> PixelYA8
-- | Pixel type storing Luminance (Y) and alpha information on 16 bits.
-- Value are stored in the following order :
--
--
data PixelYA16
PixelYA16 :: {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> PixelYA16
-- | Pixel type storing classic pixel on 8 bits Value are stored in the
-- following order :
--
--
-- - Red
-- - Green
-- - Blue
--
data PixelRGB8
PixelRGB8 :: {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> PixelRGB8
-- | Pixel type storing pixels on 16 bits Value are stored in the following
-- order :
--
--
-- - Red
-- - Green
-- - Blue
--
data PixelRGB16
PixelRGB16 :: {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> PixelRGB16
-- | Pixel type storing HDR pixel on 32 bits float Value are stored in the
-- following order :
--
--
-- - Red
-- - Green
-- - Blue
--
data PixelRGBF
PixelRGBF :: {-# UNPACK #-} !PixelF -> {-# UNPACK #-} !PixelF -> {-# UNPACK #-} !PixelF -> PixelRGBF
-- | Pixel type storing a classic pixel, with an alpha component. Values
-- are stored in the following order
--
--
-- - Red
-- - Green
-- - Blue
-- - Alpha
--
data PixelRGBA8
PixelRGBA8 :: {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> PixelRGBA8
-- | Pixel type storing a RGB information with an alpha channel on 16 bits.
-- Values are stored in the following order
--
--
-- - Red
-- - Green
-- - Blue
-- - Alpha
--
data PixelRGBA16
PixelRGBA16 :: {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> PixelRGBA16
-- | Pixel storing data in the CMYK colorspace. value are stored in the
-- following order :
--
--
-- - Cyan
-- - Magenta
-- - Yellow
-- - Black
--
data PixelCMYK8
PixelCMYK8 :: {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> PixelCMYK8
-- | Pixel storing data in the CMYK colorspace. value are stored in the
-- following order :
--
--
-- - Cyan
-- - Magenta
-- - Yellow
-- - Black
--
data PixelCMYK16
PixelCMYK16 :: {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> PixelCMYK16
-- | Pixel storing data in the YCbCr colorspace, value are stored in the
-- following order :
--
--
-- - Y (luminance)
-- - Cr
-- - Cb
--
data PixelYCbCr8
PixelYCbCr8 :: {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> PixelYCbCr8
-- | Implement upcasting for pixel types Minimal declaration declaration
-- promotePixel It is strongly recommanded to overload
-- promoteImage to keep performance acceptable
class (Pixel a, Pixel b) => ColorConvertible a b where promoteImage = pixelMap promotePixel
promotePixel :: ColorConvertible a b => a -> b
promoteImage :: ColorConvertible a b => Image a -> Image b
-- | Definition of pixels used in images. Each pixel has a color space, and
-- a representative component (Word8 or Float).
class (Storable (PixelBaseComponent a), Num (PixelBaseComponent a), Eq a) => Pixel a where type family PixelBaseComponent a :: * pixelBaseIndex (Image {imageWidth = w}) x y = (x + y * w) * componentCount (undefined :: a) mutablePixelBaseIndex (MutableImage {mutableImageWidth = w}) x y = (x + y * w) * componentCount (undefined :: a)
componentCount :: Pixel a => a -> Int
colorMap :: Pixel a => (PixelBaseComponent a -> PixelBaseComponent a) -> a -> a
pixelBaseIndex :: Pixel a => Image a -> Int -> Int -> Int
mutablePixelBaseIndex :: Pixel a => MutableImage s a -> Int -> Int -> Int
pixelAt :: Pixel a => Image a -> Int -> Int -> a
readPixel :: (Pixel a, PrimMonad m) => MutableImage (PrimState m) a -> Int -> Int -> m a
writePixel :: (Pixel a, PrimMonad m) => MutableImage (PrimState m) a -> Int -> Int -> a -> m ()
unsafePixelAt :: Pixel a => Vector (PixelBaseComponent a) -> Int -> a
unsafeReadPixel :: (Pixel a, PrimMonad m) => STVector (PrimState m) (PixelBaseComponent a) -> Int -> m a
unsafeWritePixel :: (Pixel a, PrimMonad m) => STVector (PrimState m) (PixelBaseComponent a) -> Int -> a -> m ()
-- | This class abstract colorspace conversion. This conversion can be
-- lossy, which ColorConvertible cannot
class (Pixel a, Pixel b) => ColorSpaceConvertible a b where convertImage = pixelMap convertPixel
convertPixel :: ColorSpaceConvertible a b => a -> b
convertImage :: ColorSpaceConvertible a b => Image a -> Image b
-- | Helper class to help extract a luma plane out of an image or a pixel
class (Pixel a, Pixel (PixelBaseComponent a)) => LumaPlaneExtractable a where extractLumaPlane = pixelMap computeLuma
computeLuma :: LumaPlaneExtractable a => a -> (PixelBaseComponent a)
extractLumaPlane :: LumaPlaneExtractable a => Image a -> Image (PixelBaseComponent a)
-- | Class modeling transparent pixel, should provide a method to combine
-- transparent pixels
class (Pixel a, Pixel b) => TransparentPixel a b | a -> b
dropTransparency :: TransparentPixel a b => a -> b
-- | Helper function to help extract information from dynamic image. To get
-- the width of an dynamic image, you can use the following snippet :
--
--
-- dynWidth :: DynamicImage -> Int
-- dynWidth img = dynamicMap imageWidth img
--
dynamicMap :: (forall pixel. Pixel pixel => Image pixel -> a) -> DynamicImage -> a
-- | map equivalent for an image, working at the pixel level. Little
-- example : a brightness function for an rgb image
--
--
-- brightnessRGB8 :: Int -> Image PixelRGB8 -> Image PixelRGB8
-- brightnessRGB8 add = pixelMap brightFunction
-- where up v = fromIntegral (fromIntegral v + add)
-- brightFunction (PixelRGB8 r g b) =
-- PixelRGB8 (up r) (up g) (up b)
--
pixelMap :: (Pixel a, Pixel b) => (a -> b) -> Image a -> Image b
-- | Fold over the pixel of an image with a raster scan order : from top to
-- bottom, left to right
pixelFold :: Pixel pixel => (acc -> Int -> Int -> pixel -> acc) -> acc -> Image pixel -> acc
-- | For any image with an alpha component (transparency), drop it,
-- returning a pure opaque image.
dropAlphaLayer :: TransparentPixel a b => Image a -> Image b
-- | Create an image using a monadic initializer function. The function
-- will receive value from 0 to width-1 for the x parameter and 0 to
-- height-1 for the y parameter. The coordinate 0,0 is the upper left
-- corner of the image, and (width-1, height-1) the lower right corner.
--
-- The function is called for each pixel in the line from left to right
-- (0 to width - 1) and for each line (0 to height - 1).
withImage :: (Pixel pixel, PrimMonad m) => Int -> Int -> (Int -> Int -> m pixel) -> m (Image pixel)
-- | Create an image given a function to generate pixels. The function will
-- receive value from 0 to width-1 for the x parameter and 0 to height-1
-- for the y parameter. The coordinate 0,0 is the upper left corner of
-- the image, and (width-1, height-1) the lower right corner.
--
-- for example, to create a small gradient image :
--
--
-- imageCreator :: String -> Image PixelRGB8
-- imageCreator path = writePng path $ generateImage pixelRenderer 250 300
-- where pixelRenderer x y = PixelRGB8 x y 128
--
generateImage :: Pixel a => (Int -> Int -> a) -> Int -> Int -> Image a
-- | Create an image given a function to generate pixels. The function will
-- receive value from 0 to width-1 for the x parameter and 0 to height-1
-- for the y parameter. The coordinate 0,0 is the upper left corner of
-- the image, and (width-1, height-1) the lower right corner.
--
-- the acc parameter is a user defined one.
--
-- The function is called for each pixel in the line from left to right
-- (0 to width - 1) and for each line (0 to height - 1).
generateFoldImage :: Pixel a => (acc -> Int -> Int -> (acc, a)) -> acc -> Int -> Int -> (acc, Image a)
-- | Perform a gamma correction for an image with HDR pixels.
gammaCorrection :: PixelF -> Image PixelRGBF -> Image PixelRGBF
-- | Perform a tone mapping operation on an High dynamic range image.
toneMapping :: PixelF -> Image PixelRGBF -> Image PixelRGBF
-- | Class used to describle plane present in the pixel type. If a pixel
-- has a plane description associated, you can use the plane name to
-- extract planes independently.
class ColorPlane pixel planeToken
-- | Define the plane for the red color component
data PlaneRed
PlaneRed :: PlaneRed
-- | Define the plane for the green color component
data PlaneGreen
PlaneGreen :: PlaneGreen
-- | Define the plane for the blue color component
data PlaneBlue
PlaneBlue :: PlaneBlue
-- | Define the plane for the alpha (transparency) component
data PlaneAlpha
PlaneAlpha :: PlaneAlpha
-- | Define the plane for the luma component
data PlaneLuma
PlaneLuma :: PlaneLuma
-- | Define the plane for the Cr component
data PlaneCr
PlaneCr :: PlaneCr
-- | Define the plane for the Cb component
data PlaneCb
PlaneCb :: PlaneCb
-- | Define plane for the cyan component of the CMYK color space.
data PlaneCyan
PlaneCyan :: PlaneCyan
-- | Define plane for the magenta component of the CMYK color space.
data PlaneMagenta
PlaneMagenta :: PlaneMagenta
-- | Define plane for the yellow component of the CMYK color space.
data PlaneYellow
PlaneYellow :: PlaneYellow
-- | Define plane for the black component of the CMYK color space.
data PlaneBlack
PlaneBlack :: PlaneBlack
-- | Extract a color plane from an image given a present plane in the image
-- examples :
--
--
-- extractRedPlane :: Image PixelRGB8-> Image Pixel8
-- extractRedPlane = extractComponent PlaneRed
--
extractComponent :: (Pixel px, Pixel (PixelBaseComponent px), PixelBaseComponent (PixelBaseComponent px) ~ PixelBaseComponent px, ColorPlane px plane) => plane -> Image px -> Image (PixelBaseComponent px)
-- | Extract an image plane of an image, returning an image which can be
-- represented by a gray scale image. If you ask a component out of
-- bound, the error function will be called
unsafeExtractComponent :: (Pixel a, Pixel (PixelBaseComponent a), PixelBaseComponent (PixelBaseComponent a) ~ PixelBaseComponent a) => Int -> Image a -> Image (PixelBaseComponent a)
instance Eq PixelYA8
instance Show PixelYA8
instance Eq PixelYA16
instance Show PixelYA16
instance Eq PixelRGB8
instance Show PixelRGB8
instance Eq PixelRGB16
instance Show PixelRGB16
instance Eq PixelRGBF
instance Show PixelRGBF
instance Eq PixelYCbCr8
instance Show PixelYCbCr8
instance Eq PixelCMYK8
instance Show PixelCMYK8
instance Eq PixelCMYK16
instance Show PixelCMYK16
instance Eq PixelRGBA8
instance Show PixelRGBA8
instance Eq PixelRGBA16
instance Show PixelRGBA16
instance ColorPlane PixelCMYK16 PlaneBlack
instance ColorPlane PixelCMYK16 PlaneYellow
instance ColorPlane PixelCMYK16 PlaneMagenta
instance ColorPlane PixelCMYK16 PlaneCyan
instance ColorSpaceConvertible PixelCMYK16 PixelRGB16
instance Pixel PixelCMYK16
instance ColorPlane PixelCMYK8 PlaneBlack
instance ColorPlane PixelCMYK8 PlaneYellow
instance ColorPlane PixelCMYK8 PlaneMagenta
instance ColorPlane PixelCMYK8 PlaneCyan
instance ColorSpaceConvertible PixelRGB8 PixelCMYK8
instance ColorSpaceConvertible PixelCMYK8 PixelRGB8
instance Pixel PixelCMYK8
instance ColorPlane PixelYCbCr8 PlaneCr
instance ColorPlane PixelYCbCr8 PlaneCb
instance ColorPlane PixelYCbCr8 PlaneLuma
instance ColorSpaceConvertible PixelYCbCr8 PixelRGB8
instance ColorSpaceConvertible PixelRGB8 PixelYCbCr8
instance Pixel a => ColorSpaceConvertible a a
instance Pixel PixelYCbCr8
instance ColorPlane PixelRGBA16 PlaneAlpha
instance ColorPlane PixelRGBA16 PlaneBlue
instance ColorPlane PixelRGBA16 PlaneGreen
instance ColorPlane PixelRGBA16 PlaneRed
instance TransparentPixel PixelRGBA16 PixelRGB16
instance Pixel PixelRGBA16
instance ColorPlane PixelRGBA8 PlaneAlpha
instance ColorPlane PixelRGBA8 PlaneBlue
instance ColorPlane PixelRGBA8 PlaneGreen
instance ColorPlane PixelRGBA8 PlaneRed
instance Pixel PixelRGBA8
instance LumaPlaneExtractable PixelRGB8
instance ColorPlane PixelRGB8 PlaneBlue
instance ColorPlane PixelRGB8 PlaneGreen
instance ColorPlane PixelRGB8 PlaneRed
instance ColorConvertible PixelRGB8 PixelRGBF
instance ColorConvertible PixelRGB8 PixelRGBA8
instance Pixel PixelRGB8
instance LumaPlaneExtractable PixelRGB16
instance ColorConvertible PixelRGB16 PixelRGBA16
instance ColorSpaceConvertible PixelRGB16 PixelCMYK16
instance ColorPlane PixelRGB16 PlaneBlue
instance ColorPlane PixelRGB16 PlaneGreen
instance ColorPlane PixelRGB16 PlaneRed
instance Pixel PixelRGB16
instance ColorPlane PixelRGBF PlaneBlue
instance ColorPlane PixelRGBF PlaneGreen
instance ColorPlane PixelRGBF PlaneRed
instance Pixel PixelRGBF
instance TransparentPixel PixelYA16 Pixel16
instance ColorPlane PixelYA16 PlaneAlpha
instance ColorPlane PixelYA16 PlaneLuma
instance ColorConvertible PixelYA16 PixelRGBA16
instance Pixel PixelYA16
instance LumaPlaneExtractable PixelYA8
instance TransparentPixel PixelYA8 Pixel8
instance ColorPlane PixelYA8 PlaneAlpha
instance ColorPlane PixelYA8 PlaneLuma
instance ColorConvertible PixelYA8 PixelRGBA8
instance ColorConvertible PixelYA8 PixelRGB8
instance Pixel PixelYA8
instance ColorConvertible PixelF PixelRGBF
instance Pixel PixelF
instance ColorConvertible Pixel16 PixelRGBA16
instance ColorConvertible Pixel16 PixelRGB16
instance ColorConvertible Pixel16 PixelYA16
instance Pixel Pixel16
instance ColorConvertible Pixel8 PixelRGBA8
instance ColorConvertible Pixel8 PixelRGB8
instance ColorConvertible Pixel8 Pixel16
instance ColorConvertible Pixel8 PixelF
instance ColorConvertible Pixel8 PixelYA8
instance Pixel Pixel8
instance Pixel a => ColorConvertible a a
instance LumaPlaneExtractable PixelYCbCr8
instance LumaPlaneExtractable PixelRGBA8
instance LumaPlaneExtractable PixelRGBF
instance LumaPlaneExtractable PixelF
instance LumaPlaneExtractable Pixel16
instance LumaPlaneExtractable Pixel8
instance NFData DynamicImage
instance NFData (MutableImage s a)
instance NFData (Image a)
instance TransparentPixel PixelRGBA8 PixelRGB8
-- | Module implementing TIFF decoding.
--
-- Supported compression schemes :
--
--
-- - Uncompressed
-- - PackBits
-- - LZW
--
--
-- Supported bit depth :
--
--
-- - 2 bits
-- - 4 bits
-- - 8 bits
-- - 16 bits
--
module Codec.Picture.Tiff
-- | Transform a raw tiff image to an image, without modifying the
-- underlying pixel type.
--
-- This function can output the following pixel types :
--
--
-- - PixelY8
-- - PixelY16
-- - PixelRGB8
-- - PixelRGB16
-- - PixelCMYK8
-- - PixelCMYK16
--
decodeTiff :: ByteString -> Either String DynamicImage
instance Eq Endianness
instance Show Endianness
instance Eq TiffHeader
instance Show TiffHeader
instance Eq TiffPlanarConfiguration
instance Show TiffPlanarConfiguration
instance Eq TiffCompression
instance Show TiffCompression
instance Eq IfdType
instance Show IfdType
instance Eq TiffTag
instance Show TiffTag
instance Eq ExtendedDirectoryData
instance Show ExtendedDirectoryData
instance Eq TiffSampleFormat
instance Show TiffSampleFormat
instance Eq ImageFileDirectory
instance Show ImageFileDirectory
instance Eq TiffColorspace
instance Show TiffColorspace
instance Unpackable YCbCrSubsampling
instance Unpackable Pack12
instance Unpackable Pack2
instance Unpackable Pack4
instance Unpackable Word16
instance Unpackable Word8
instance Binary TiffHeader
instance Binary Endianness
-- | Module dedicated of Radiance file decompression (.hdr or .pic) file.
-- Radiance file format is used for High dynamic range imaging.
module Codec.Picture.HDR
-- | Decode an HDR (radiance) image, the resulting pixel type can be :
--
--
decodeHDR :: ByteString -> Either String DynamicImage
-- | Encode an High dynamic range image into a radiance image file format.
encodeHDR :: Image PixelRGBF -> ByteString
-- | Write an High dynamic range image into a radiance image file on disk.
writeHDR :: FilePath -> Image PixelRGBF -> IO ()
instance Binary RadianceHeader
instance Binary RadianceFormat
instance Binary RGBE
-- | Module implementing GIF decoding.
module Codec.Picture.Gif
-- | Transform a raw gif image to an image, witout modifying the pixels.
-- This function can output the following pixel types :
--
--
decodeGif :: ByteString -> Either String DynamicImage
-- | Transform a raw gif to a list of images, representing all the images
-- of an animation.
decodeGifImages :: ByteString -> Either String [Image PixelRGB8]
instance Binary GifFile
instance Binary GifHeader
instance Binary ImageDescriptor
instance Binary GifImage
instance Binary GraphicControlExtension
instance Binary LogicalScreenDescriptor
instance Binary GifVersion
-- | Module used for loading & writing 'Portable Network Graphics'
-- (PNG) files. The API has two layers, the high level, which load the
-- image without looking deeply about it and the low level, allowing
-- access to data chunks contained in the PNG image.
--
-- For general use, please use decodePng function.
--
-- The loader has been validated against the pngsuite
-- (http:www.libpng.orgpubpng/pngsuite.html)
module Codec.Picture.Png
-- | Encode an image into a png if possible.
class PngSavable a
encodePng :: PngSavable a => Image a -> ByteString
-- | Transform a raw png image to an image, without modifying the
-- underlying pixel type. If the image is greyscale and < 8 bits, a
-- transformation to RGBA8 is performed. This should change in the
-- future. The resulting image let you manage the pixel types.
--
-- This function can output the following pixel types :
--
--
-- - PixelY8
-- - PixelY16
-- - PixelYA8
-- - PixelYA16
-- - PixelRGB8
-- - PixelRGB16
-- - PixelRGBA8
-- - PixelRGBA16
--
decodePng :: ByteString -> Either String DynamicImage
-- | Helper function to directly write an image as a png on disk.
writePng :: PngSavable pixel => FilePath -> Image pixel -> IO ()
-- | Encode a dynamic image in bmp if possible, supported pixel type are :
--
--
-- - Y8
-- - Y16
-- - YA8
-- - YA16
-- - RGB8
-- - RGB16
-- - RGBA8
-- - RGBA16
--
encodeDynamicPng :: DynamicImage -> Either String ByteString
-- | Write a dynamic image in a .png image file if possible. The same
-- restriction as encodeDynamicPng apply.
writeDynamicPng :: FilePath -> DynamicImage -> IO (Either String Bool)
-- | Module used for JPEG file loading and writing.
module Codec.Picture.Jpg
-- | Try to decompress a jpeg file and decompress. The colorspace is still
-- YCbCr if you want to perform computation on the luma part. You can
-- convert it to RGB using convertImage from the
-- ColorSpaceConvertible typeclass.
--
-- This function can output the following pixel types :
--
--
-- - PixelY8
-- - PixelYCbCr8
--
decodeJpeg :: ByteString -> Either String DynamicImage
-- | Function to call to encode an image to jpeg. The quality factor should
-- be between 0 and 100 (100 being the best quality).
encodeJpegAtQuality :: Word8 -> Image PixelYCbCr8 -> ByteString
-- | Encode an image in jpeg at a reasonnable quality level. If you want
-- better quality or reduced file size, you should use
-- encodeJpegAtQuality
encodeJpeg :: Image PixelYCbCr8 -> ByteString
instance Eq JpgFrameKind
instance Show JpgFrameKind
instance Show JpgComponent
instance Show JpgFrameHeader
instance Show JpgScanSpecification
instance Show JpgScanHeader
instance Show JpgQuantTableSpec
instance Show JpgHuffmanTableSpec
instance Show JpgFrame
instance Show JpgImage
instance Binary JpgScanHeader
instance Binary JpgScanSpecification
instance Binary JpgFrameHeader
instance Binary JpgComponent
instance Binary RestartInterval
instance Binary JpgFrameKind
instance Binary JpgImage
instance Binary JpgHuffmanTableSpec
instance SizeCalculable JpgHuffmanTableSpec
instance Binary JpgQuantTableSpec
instance SizeCalculable JpgQuantTableSpec
instance (SizeCalculable a, Binary a) => Binary (TableList a)
instance SizeCalculable JpgScanHeader
instance SizeCalculable JpgScanSpecification
instance SizeCalculable JpgComponent
instance SizeCalculable JpgFrameHeader
-- | Modules used for Bitmap file (.bmp) file loading and writing
module Codec.Picture.Bitmap
-- | Write an image in a file use the bitmap format.
writeBitmap :: BmpEncodable pixel => FilePath -> Image pixel -> IO ()
-- | Encode an image into a bytestring in .bmp format ready to be written
-- on disk.
encodeBitmap :: BmpEncodable pixel => Image pixel -> ByteString
-- | Try to decode a bitmap image. Right now this function can output the
-- following pixel types :
--
--
decodeBitmap :: ByteString -> Either String DynamicImage
-- | Encode a dynamic image in bmp if possible, supported pixel type are :
--
--
-- - RGB8
-- - RGBA8
-- - Y8
--
encodeDynamicBitmap :: DynamicImage -> Either String ByteString
-- | Write a dynamic image in a .bmp image file if possible. The same
-- restriction as encodeDynamicBitmap apply.
writeDynamicBitmap :: FilePath -> DynamicImage -> IO (Either String Bool)
-- | All the instance of this class can be written as a bitmap file using
-- this library.
class BmpEncodable pixel where defaultPalette _ = BmpPalette []
instance BmpEncodable PixelRGB8
instance BmpEncodable PixelRGBA8
instance BmpEncodable Pixel8
instance Binary BmpInfoHeader
instance Binary BmpHeader
-- | Helper functions to save dynamic images to other file format with
-- automatic color space/sample format conversion done automatically.
module Codec.Picture.Saving
-- | This function will try to do anything to encode an image as JPEG, make
-- all color conversion and such. Equivalent of decodeImage for
-- jpeg encoding
imageToJpg :: Int -> DynamicImage -> ByteString
-- | This function will try to do anything to encode an image as PNG, make
-- all color conversion and such. Equivalent of decodeImage for
-- PNG encoding
imageToPng :: DynamicImage -> ByteString
-- | This function will try to do anything to encode an image as bitmap,
-- make all color conversion and such. Equivalent of decodeImage
-- for Bitmap encoding
imageToBitmap :: DynamicImage -> ByteString
-- | This function will try to do anything to encode an image as RADIANCE,
-- make all color conversion and such. Equivalent of decodeImage
-- for radiance encoding
imageToRadiance :: DynamicImage -> ByteString
-- | Main module for image import/export into various image formats.
--
-- To use the library without thinking about it, look after
-- decodeImage and readImage.
--
-- Generally, the read* functions read the images from a file and try to
-- decode it, and the decode* functions try to decode a bytestring.
--
-- For an easy image writing use the saveBmpImage,
-- saveJpgImage & savePngImage functions
module Codec.Picture
-- | Load an image file without even thinking about it, it does everything
-- as decodeImage
readImage :: FilePath -> IO (Either String DynamicImage)
-- | If you want to decode an image in a bytestring without even thinking
-- in term of format or whatever, this is the function to use. It will
-- try to decode in each known format and if one decoding succeed will
-- return the decoded image in it's own colorspace
decodeImage :: ByteString -> Either String DynamicImage
-- | map equivalent for an image, working at the pixel level. Little
-- example : a brightness function for an rgb image
--
--
-- brightnessRGB8 :: Int -> Image PixelRGB8 -> Image PixelRGB8
-- brightnessRGB8 add = pixelMap brightFunction
-- where up v = fromIntegral (fromIntegral v + add)
-- brightFunction (PixelRGB8 r g b) =
-- PixelRGB8 (up r) (up g) (up b)
--
pixelMap :: (Pixel a, Pixel b) => (a -> b) -> Image a -> Image b
-- | Create an image given a function to generate pixels. The function will
-- receive value from 0 to width-1 for the x parameter and 0 to height-1
-- for the y parameter. The coordinate 0,0 is the upper left corner of
-- the image, and (width-1, height-1) the lower right corner.
--
-- for example, to create a small gradient image :
--
--
-- imageCreator :: String -> Image PixelRGB8
-- imageCreator path = writePng path $ generateImage pixelRenderer 250 300
-- where pixelRenderer x y = PixelRGB8 x y 128
--
generateImage :: Pixel a => (Int -> Int -> a) -> Int -> Int -> Image a
-- | Create an image given a function to generate pixels. The function will
-- receive value from 0 to width-1 for the x parameter and 0 to height-1
-- for the y parameter. The coordinate 0,0 is the upper left corner of
-- the image, and (width-1, height-1) the lower right corner.
--
-- the acc parameter is a user defined one.
--
-- The function is called for each pixel in the line from left to right
-- (0 to width - 1) and for each line (0 to height - 1).
generateFoldImage :: Pixel a => (acc -> Int -> Int -> (acc, a)) -> acc -> Int -> Int -> (acc, Image a)
-- | Create an image using a monadic initializer function. The function
-- will receive value from 0 to width-1 for the x parameter and 0 to
-- height-1 for the y parameter. The coordinate 0,0 is the upper left
-- corner of the image, and (width-1, height-1) the lower right corner.
--
-- The function is called for each pixel in the line from left to right
-- (0 to width - 1) and for each line (0 to height - 1).
withImage :: (Pixel pixel, PrimMonad m) => Int -> Int -> (Int -> Int -> m pixel) -> m (Image pixel)
-- | Save an image to a '.bmp' file, will do everything it can to save an
-- image.
saveBmpImage :: String -> DynamicImage -> IO ()
-- | Save an image to a '.jpg' file, will do everything it can to save an
-- image.
saveJpgImage :: Int -> String -> DynamicImage -> IO ()
-- | Save an image to a '.png' file, will do everything it can to save an
-- image. For example, a simple transcoder to png
--
--
-- transcodeToPng :: FilePath -> FilePath -> IO ()
-- transcodeToPng pathIn pathOut = do
-- eitherImg <- decodeImage pathIn
-- case eitherImg of
-- Left _ -> return ()
-- Right img -> savePngImage pathOut img
--
savePngImage :: String -> DynamicImage -> IO ()
-- | Save an image to a '.hdr' file, will do everything it can to save an
-- image.
saveRadianceImage :: String -> DynamicImage -> IO ()
-- | All the instance of this class can be written as a bitmap file using
-- this library.
class BmpEncodable pixel where defaultPalette _ = BmpPalette []
-- | Write an image in a file use the bitmap format.
writeBitmap :: BmpEncodable pixel => FilePath -> Image pixel -> IO ()
-- | Encode an image into a bytestring in .bmp format ready to be written
-- on disk.
encodeBitmap :: BmpEncodable pixel => Image pixel -> ByteString
-- | Try to load a .bmp file. The colorspace would be RGB or RGBA
readBitmap :: FilePath -> IO (Either String DynamicImage)
-- | Try to decode a bitmap image. Right now this function can output the
-- following pixel types :
--
--
decodeBitmap :: ByteString -> Either String DynamicImage
-- | Encode a dynamic image in bmp if possible, supported pixel type are :
--
--
-- - RGB8
-- - RGBA8
-- - Y8
--
encodeDynamicBitmap :: DynamicImage -> Either String ByteString
-- | Write a dynamic image in a .bmp image file if possible. The same
-- restriction as encodeDynamicBitmap apply.
writeDynamicBitmap :: FilePath -> DynamicImage -> IO (Either String Bool)
-- | Helper function trying to load a gif file from a file on disk.
readGif :: FilePath -> IO (Either String DynamicImage)
-- | Helper function trying to load all the images of an animated gif file.
readGifImages :: FilePath -> IO (Either String [Image PixelRGB8])
-- | Transform a raw gif image to an image, witout modifying the pixels.
-- This function can output the following pixel types :
--
--
decodeGif :: ByteString -> Either String DynamicImage
-- | Transform a raw gif to a list of images, representing all the images
-- of an animation.
decodeGifImages :: ByteString -> Either String [Image PixelRGB8]
-- | Try to load a jpeg file and decompress. The colorspace is still YCbCr
-- if you want to perform computation on the luma part. You can convert
-- it to RGB using colorSpaceConversion
readJpeg :: FilePath -> IO (Either String DynamicImage)
-- | Try to decompress a jpeg file and decompress. The colorspace is still
-- YCbCr if you want to perform computation on the luma part. You can
-- convert it to RGB using convertImage from the
-- ColorSpaceConvertible typeclass.
--
-- This function can output the following pixel types :
--
--
-- - PixelY8
-- - PixelYCbCr8
--
decodeJpeg :: ByteString -> Either String DynamicImage
-- | Encode an image in jpeg at a reasonnable quality level. If you want
-- better quality or reduced file size, you should use
-- encodeJpegAtQuality
encodeJpeg :: Image PixelYCbCr8 -> ByteString
-- | Function to call to encode an image to jpeg. The quality factor should
-- be between 0 and 100 (100 being the best quality).
encodeJpegAtQuality :: Word8 -> Image PixelYCbCr8 -> ByteString
-- | Encode an image into a png if possible.
class PngSavable a
encodePng :: PngSavable a => Image a -> ByteString
-- | Helper function trying to load a png file from a file on disk.
readPng :: FilePath -> IO (Either String DynamicImage)
-- | Transform a raw png image to an image, without modifying the
-- underlying pixel type. If the image is greyscale and < 8 bits, a
-- transformation to RGBA8 is performed. This should change in the
-- future. The resulting image let you manage the pixel types.
--
-- This function can output the following pixel types :
--
--
-- - PixelY8
-- - PixelY16
-- - PixelYA8
-- - PixelYA16
-- - PixelRGB8
-- - PixelRGB16
-- - PixelRGBA8
-- - PixelRGBA16
--
decodePng :: ByteString -> Either String DynamicImage
-- | Helper function to directly write an image as a png on disk.
writePng :: PngSavable pixel => FilePath -> Image pixel -> IO ()
-- | Encode a dynamic image in bmp if possible, supported pixel type are :
--
--
-- - Y8
-- - Y16
-- - YA8
-- - YA16
-- - RGB8
-- - RGB16
-- - RGBA8
-- - RGBA16
--
encodeDynamicPng :: DynamicImage -> Either String ByteString
-- | Write a dynamic image in a .png image file if possible. The same
-- restriction as encodeDynamicPng apply.
writeDynamicPng :: FilePath -> DynamicImage -> IO (Either String Bool)
-- | Transform a raw tiff image to an image, without modifying the
-- underlying pixel type.
--
-- This function can output the following pixel types :
--
--
-- - PixelY8
-- - PixelY16
-- - PixelRGB8
-- - PixelRGB16
-- - PixelCMYK8
-- - PixelCMYK16
--
decodeTiff :: ByteString -> Either String DynamicImage
-- | Try to load a .pic file. The colorspace can only be RGB with floating
-- point precision.
readHDR :: FilePath -> IO (Either String DynamicImage)
-- | Decode an HDR (radiance) image, the resulting pixel type can be :
--
--
decodeHDR :: ByteString -> Either String DynamicImage
-- | Encode an High dynamic range image into a radiance image file format.
encodeHDR :: Image PixelRGBF -> ByteString
-- | Write an High dynamic range image into a radiance image file on disk.
writeHDR :: FilePath -> Image PixelRGBF -> IO ()
-- | Image or pixel buffer, the coordinates are assumed to start from the
-- upper-left corner of the image, with the horizontal position first,
-- then the vertical one.
data Image a
Image :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> Vector (PixelBaseComponent a) -> Image a
-- | Width of the image in pixels
imageWidth :: Image a -> {-# UNPACK #-} !Int
-- | Height of the image in pixels.
imageHeight :: Image a -> {-# UNPACK #-} !Int
-- | The real image, to extract pixels at some position you should use the
-- helpers functions.
imageData :: Image a -> Vector (PixelBaseComponent a)
-- | Type allowing the loading of an image with different pixel structures
data DynamicImage
-- | A greyscale image.
ImageY8 :: (Image Pixel8) -> DynamicImage
-- | A greyscale image with 16bit components
ImageY16 :: (Image Pixel16) -> DynamicImage
-- | A greyscale HDR image
ImageYF :: (Image PixelF) -> DynamicImage
-- | An image in greyscale with an alpha channel.
ImageYA8 :: (Image PixelYA8) -> DynamicImage
-- | An image in greyscale with alpha channel on 16 bits.
ImageYA16 :: (Image PixelYA16) -> DynamicImage
-- | An image in true color.
ImageRGB8 :: (Image PixelRGB8) -> DynamicImage
-- | An image in true color with 16bit depth.
ImageRGB16 :: (Image PixelRGB16) -> DynamicImage
-- | An image with HDR pixels
ImageRGBF :: (Image PixelRGBF) -> DynamicImage
-- | An image in true color and an alpha channel.
ImageRGBA8 :: (Image PixelRGBA8) -> DynamicImage
-- | A true color image with alpha on 16 bits.
ImageRGBA16 :: (Image PixelRGBA16) -> DynamicImage
-- | An image in the colorspace used by Jpeg images.
ImageYCbCr8 :: (Image PixelYCbCr8) -> DynamicImage
-- | An image in the colorspace CMYK
ImageCMYK8 :: (Image PixelCMYK8) -> DynamicImage
-- | An image in the colorspace CMYK and 16 bots precision
ImageCMYK16 :: (Image PixelCMYK16) -> DynamicImage
-- | Definition of pixels used in images. Each pixel has a color space, and
-- a representative component (Word8 or Float).
class (Storable (PixelBaseComponent a), Num (PixelBaseComponent a), Eq a) => Pixel a where type family PixelBaseComponent a :: * pixelBaseIndex (Image {imageWidth = w}) x y = (x + y * w) * componentCount (undefined :: a) mutablePixelBaseIndex (MutableImage {mutableImageWidth = w}) x y = (x + y * w) * componentCount (undefined :: a)
componentCount :: Pixel a => a -> Int
colorMap :: Pixel a => (PixelBaseComponent a -> PixelBaseComponent a) -> a -> a
pixelBaseIndex :: Pixel a => Image a -> Int -> Int -> Int
mutablePixelBaseIndex :: Pixel a => MutableImage s a -> Int -> Int -> Int
pixelAt :: Pixel a => Image a -> Int -> Int -> a
readPixel :: (Pixel a, PrimMonad m) => MutableImage (PrimState m) a -> Int -> Int -> m a
writePixel :: (Pixel a, PrimMonad m) => MutableImage (PrimState m) a -> Int -> Int -> a -> m ()
unsafePixelAt :: Pixel a => Vector (PixelBaseComponent a) -> Int -> a
unsafeReadPixel :: (Pixel a, PrimMonad m) => STVector (PrimState m) (PixelBaseComponent a) -> Int -> m a
unsafeWritePixel :: (Pixel a, PrimMonad m) => STVector (PrimState m) (PixelBaseComponent a) -> Int -> a -> m ()
-- | Simple alias for greyscale value in 8 bits.
type Pixel8 = Word8
-- | Simple alias for greyscale value in 16 bits.
type Pixel16 = Word16
-- | Floating greyscale value, the 0 to 255 8 bit range maps to 0 to 1 in
-- this floating version
type PixelF = Float
-- | Pixel type storing Luminance (Y) and alpha information on 8 bits.
-- Value are stored in the following order :
--
--
data PixelYA8
PixelYA8 :: {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> PixelYA8
-- | Pixel type storing Luminance (Y) and alpha information on 16 bits.
-- Value are stored in the following order :
--
--
data PixelYA16
PixelYA16 :: {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> PixelYA16
-- | Pixel type storing classic pixel on 8 bits Value are stored in the
-- following order :
--
--
-- - Red
-- - Green
-- - Blue
--
data PixelRGB8
PixelRGB8 :: {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> PixelRGB8
-- | Pixel type storing pixels on 16 bits Value are stored in the following
-- order :
--
--
-- - Red
-- - Green
-- - Blue
--
data PixelRGB16
PixelRGB16 :: {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> PixelRGB16
-- | Pixel type storing HDR pixel on 32 bits float Value are stored in the
-- following order :
--
--
-- - Red
-- - Green
-- - Blue
--
data PixelRGBF
PixelRGBF :: {-# UNPACK #-} !PixelF -> {-# UNPACK #-} !PixelF -> {-# UNPACK #-} !PixelF -> PixelRGBF
-- | Pixel type storing a classic pixel, with an alpha component. Values
-- are stored in the following order
--
--
-- - Red
-- - Green
-- - Blue
-- - Alpha
--
data PixelRGBA8
PixelRGBA8 :: {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> PixelRGBA8
-- | Pixel type storing a RGB information with an alpha channel on 16 bits.
-- Values are stored in the following order
--
--
-- - Red
-- - Green
-- - Blue
-- - Alpha
--
data PixelRGBA16
PixelRGBA16 :: {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> PixelRGBA16
-- | Pixel storing data in the YCbCr colorspace, value are stored in the
-- following order :
--
--
-- - Y (luminance)
-- - Cr
-- - Cb
--
data PixelYCbCr8
PixelYCbCr8 :: {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> PixelYCbCr8
-- | Pixel storing data in the CMYK colorspace. value are stored in the
-- following order :
--
--
-- - Cyan
-- - Magenta
-- - Yellow
-- - Black
--
data PixelCMYK8
PixelCMYK8 :: {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> {-# UNPACK #-} !Pixel8 -> PixelCMYK8
-- | Pixel storing data in the CMYK colorspace. value are stored in the
-- following order :
--
--
-- - Cyan
-- - Magenta
-- - Yellow
-- - Black
--
data PixelCMYK16
PixelCMYK16 :: {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> {-# UNPACK #-} !Pixel16 -> PixelCMYK16