JuicyPixels- Picture loading/serialization (in png, jpeg, bitmap, gif, tiff and radiance)

Safe HaskellNone




Module used for loading & writing 'Portable Network Graphics' (PNG) files.

A high level API is provided. It loads and saves images for you while hiding all the details about PNG chunks.

Basic functions for PNG handling are decodePng, encodePng and encodePalettedPng. Convenience functions are provided for direct file handling and using DynamicImages.

The loader has been validated against the pngsuite (http:www.libpng.orgpubpng/pngsuite.html)


High level functions

class PngSavable a whereSource

Encode an image into a png if possible.


encodePng :: Image a -> ByteStringSource

Transform an image into a png encoded bytestring, ready to be written as a file.

decodePng :: ByteString -> Either String DynamicImageSource

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

writePng :: PngSavable pixel => FilePath -> Image pixel -> IO ()Source

Helper function to directly write an image as a png on disk.

encodePalettedPng :: Palette -> Image Pixel8 -> Either String ByteStringSource

Encode a paletted image as a color indexed 8-bit PNG. the palette must have between 1 and 256 values in it.

encodeDynamicPng :: DynamicImage -> Either String ByteStringSource

Encode a dynamic image in bmp if possible, supported pixel type are :

  • Y8
  • Y16
  • YA8
  • YA16
  • RGB8
  • RGB16
  • RGBA8
  • RGBA16

writeDynamicPng :: FilePath -> DynamicImage -> IO (Either String Bool)Source

Write a dynamic image in a .png image file if possible. The same restriction as encodeDynamicPng apply.