-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Picture loading/serialization (in png, jpeg, bitmap, radiance and gif) -- -- -- This library can load and store images in PNG,Bitmap, Jpeg, Radiance -- and read Gif images. @package JuicyPixels @version 3.0 -- | 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 HDR image ImageYF :: (Image PixelF) -> DynamicImage -- | An image in greyscale with an alpha channel. ImageYA8 :: (Image PixelYA8) -> DynamicImage -- | An image in true color. ImageRGB8 :: (Image PixelRGB8) -> DynamicImage -- | An image with HDR pixels ImageRGBF :: (Image PixelRGBF) -> DynamicImage -- | An image in true color and an alpha channel. ImageRGBA8 :: (Image PixelRGBA8) -> DynamicImage -- | An image in the colorspace used by Jpeg images. ImageYCbCr8 :: (Image PixelYCbCr8) -> DynamicImage -- | `O(n)` Yield an immutable copy of an image by making a copy of it freezeImage :: Storable (PixelBaseComponent a) => MutableImage s a -> ST s (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) => MutableImage s a -> ST s (Image a) -- | Simple alias for greyscale value in 8 bits. type Pixel8 = Word8 -- | 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 #-} !Word8 -> {-# UNPACK #-} !Word8 -> PixelYA8 -- | Pixel type storing classic pixel on 8 bits Value are stored in the -- following order : -- -- data PixelRGB8 PixelRGB8 :: {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> PixelRGB8 -- | Pixel type storing HDR pixel on 32 bits float Value are stored in the -- following order : -- -- 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 -- -- data PixelRGBA8 PixelRGBA8 :: {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> PixelRGBA8 -- | Pixel storing data in the YCbCr colorspace, value are stored in the -- following order : -- -- data PixelYCbCr8 PixelYCbCr8 :: {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> 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)) => 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 => MutableImage s a -> Int -> Int -> ST s a writePixel :: Pixel a => MutableImage s a -> Int -> Int -> a -> ST s () -- | 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 -- | 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 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 -- | 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 ColorSpaceConvertible PixelYCbCr8 PixelRGB8 instance ColorSpaceConvertible PixelRGB8 PixelYCbCr8 instance Pixel a => ColorSpaceConvertible a a instance Pixel PixelYCbCr8 instance Pixel PixelRGBA8 instance ColorConvertible PixelRGB8 PixelRGBF instance ColorConvertible PixelRGB8 PixelRGBA8 instance Pixel PixelRGB8 instance Pixel PixelRGBF instance ColorConvertible PixelYA8 PixelRGBA8 instance ColorConvertible PixelYA8 PixelRGB8 instance Pixel PixelYA8 instance ColorConvertible PixelF PixelRGBF instance ColorConvertible Pixel8 PixelRGBA8 instance ColorConvertible Pixel8 PixelRGB8 instance ColorConvertible Pixel8 PixelF instance ColorConvertible Pixel8 PixelYA8 instance Pixel PixelF instance Pixel Pixel8 instance Pixel a => ColorConvertible a a instance LumaPlaneExtractable PixelYCbCr8 instance LumaPlaneExtractable PixelYA8 instance LumaPlaneExtractable PixelRGBA8 instance LumaPlaneExtractable PixelRGBF instance LumaPlaneExtractable PixelRGB8 instance LumaPlaneExtractable PixelF instance LumaPlaneExtractable Pixel8 instance NFData DynamicImage instance NFData (MutableImage s a) instance NFData (Image a) instance TransparentPixel PixelRGBA8 PixelRGB8 instance TransparentPixel PixelYA8 Pixel8 instance ColorPlane PixelRGBA8 PlaneAlpha instance ColorPlane PixelRGBA8 PlaneBlue instance ColorPlane PixelRGBA8 PlaneGreen instance ColorPlane PixelRGBA8 PlaneRed instance ColorPlane PixelRGBF PlaneBlue instance ColorPlane PixelRGBF PlaneGreen instance ColorPlane PixelRGBF PlaneRed instance ColorPlane PixelRGB8 PlaneBlue instance ColorPlane PixelRGB8 PlaneGreen instance ColorPlane PixelRGB8 PlaneRed instance ColorPlane PixelYA8 PlaneAlpha instance ColorPlane PixelYA8 PlaneLuma instance ColorPlane PixelYCbCr8 PlaneCr instance ColorPlane PixelYCbCr8 PlaneCb instance ColorPlane PixelYCbCr8 PlaneLuma -- | 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 : -- -- 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 : -- -- 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 : -- -- 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 : -- -- 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) -- | 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 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 : -- -- 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 : -- -- 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 : -- -- 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 : -- -- 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) -- | 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 HDR image ImageYF :: (Image PixelF) -> DynamicImage -- | An image in greyscale with an alpha channel. ImageYA8 :: (Image PixelYA8) -> DynamicImage -- | An image in true color. ImageRGB8 :: (Image PixelRGB8) -> DynamicImage -- | An image with HDR pixels ImageRGBF :: (Image PixelRGBF) -> DynamicImage -- | An image in true color and an alpha channel. ImageRGBA8 :: (Image PixelRGBA8) -> DynamicImage -- | An image in the colorspace used by Jpeg images. ImageYCbCr8 :: (Image PixelYCbCr8) -> 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)) => 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 => MutableImage s a -> Int -> Int -> ST s a writePixel :: Pixel a => MutableImage s a -> Int -> Int -> a -> ST s () -- | Simple alias for greyscale value in 8 bits. type Pixel8 = Word8 -- | Pixel type storing Luminance (Y) and alpha information on 8 bits. -- Value are stored in the following order : -- -- data PixelYA8 PixelYA8 :: {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> PixelYA8 -- | Pixel type storing classic pixel on 8 bits Value are stored in the -- following order : -- -- data PixelRGB8 PixelRGB8 :: {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> PixelRGB8 -- | Pixel type storing a classic pixel, with an alpha component. Values -- are stored in the following order -- -- data PixelRGBA8 PixelRGBA8 :: {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> PixelRGBA8 -- | Pixel storing data in the YCbCr colorspace, value are stored in the -- following order : -- -- data PixelYCbCr8 PixelYCbCr8 :: {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> {-# UNPACK #-} !Word8 -> PixelYCbCr8