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

Safe Haskell | None
Language | Haskell2010

Codec.Picture.Png

Contents

- High level functions

Description

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 `DynamicImage`s.

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

Synopsis

- class PngSavable a where
  - encodePng :: Image a -> ByteString
  - encodePngWithMetadata :: Metadatas -> Image a -> ByteString
- decodePng :: ByteString -> Either String DynamicImage
- decodePngWithMetadata :: ByteString -> Either String (DynamicImage, Metadatas)
- writePng :: PngSavable pixel => FilePath -> Image pixel -> IO ()
- encodeDynamicPng :: DynamicImage -> Either String ByteString
- encodePalettedPng :: Palette -> Image Pixel8 -> Either String ByteString
- encodePalettedPngWithMetadata :: Metadatas -> Palette -> Image Pixel8 -> Either String ByteString
- writeDynamicPng :: FilePath -> DynamicImage -> IO (Either String Bool)

# High level functions

class PngSavable a where Source

Encode an image into a png if possible.

Minimal complete definition

encodePngWithMetadata

Methods

encodePng :: Image a -> ByteString Source

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

encodePngWithMetadata :: Metadatas -> Image a -> ByteString Source

Encode a png using some metadatas. The following metadata keys will be stored in a `tEXt` field :

- `Title`
- `Description`
- `Author`
- `Copyright`
- `Software`
- `Comment`
- `Disclaimer`
- `Source`
- `Warning`
- `Unknown` using the key present in the constructor.

the followings metadata will bes tored in the `gAMA` chunk.

- `Gamma`

The followings metadata will be stored in a `pHYs` chunk

- `DpiX`
- `DpiY`

Instances

PngSavable PixelRGBA16 Source |
PngSavable PixelRGBA8 Source |
PngSavable PixelRGB16 Source |
PngSavable PixelRGB8 Source |
PngSavable PixelYA16 Source |
PngSavable PixelYA8 Source |
PngSavable Pixel16 Source |
PngSavable Pixel8 Source |

decodePng :: ByteString -> Either String DynamicImage Source

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

decodePngWithMetadata :: ByteString -> Either String (DynamicImage, Metadatas) Source

Same as `decodePng` but also extract meta datas present in the files.

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

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

encodeDynamicPng :: DynamicImage -> Either String ByteString Source

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

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

encodePalettedPng :: Palette -> Image Pixel8 -> Either String ByteString Source

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

encodePalettedPngWithMetadata :: Metadatas -> Palette -> Image Pixel8 -> Either String ByteString Source

Equivalent to `encodePalettedPng` but allow writing of metadatas.

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.