JuicyPixels-3.3.9: 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
- class PngPaletteSaveable a where
  - encodePalettedPng :: Image a -> Image Pixel8 -> Either String ByteString
  - encodePalettedPngWithMetadata :: Metadatas -> Image a -> Image Pixel8 -> Either String ByteString
- decodePng :: ByteString -> Either String DynamicImage
- decodePngWithMetadata :: ByteString -> Either String (DynamicImage, Metadatas)
- decodePngWithPaletteAndMetadata :: ByteString -> Either String (PalettedImage, Metadatas)
- writePng :: PngSavable pixel => FilePath -> Image pixel -> IO ()
- encodeDynamicPng :: DynamicImage -> Either String ByteString
- writeDynamicPng :: FilePath -> DynamicImage -> IO (Either String Bool)

# High level functions

class PngSavable a where #

Encode an image into a png if possible.

Minimal complete definition

encodePngWithMetadata

Methods

encodePng :: Image a -> ByteString #

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

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

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 be stored in the `gAMA` chunk.

- `Gamma`

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

- `DpiX`
- `DpiY`

#### Instances

Instances details

PngSavable Pixel16 # |
Instance details Defined in Codec.Picture.Png.Internal.Export Methods encodePng :: Image Pixel16 -> ByteString # encodePngWithMetadata :: Metadatas -> Image Pixel16 -> ByteString #
PngSavable Pixel8 # |
Instance details Defined in Codec.Picture.Png.Internal.Export Methods encodePng :: Image Pixel8 -> ByteString # encodePngWithMetadata :: Metadatas -> Image Pixel8 -> ByteString #
PngSavable PixelRGB16 # |
Instance details Defined in Codec.Picture.Png.Internal.Export Methods encodePng :: Image PixelRGB16 -> ByteString # encodePngWithMetadata :: Metadatas -> Image PixelRGB16 -> ByteString #
PngSavable PixelRGB8 # |
Instance details Defined in Codec.Picture.Png.Internal.Export Methods encodePng :: Image PixelRGB8 -> ByteString # encodePngWithMetadata :: Metadatas -> Image PixelRGB8 -> ByteString #
PngSavable PixelRGBA16 # |
Instance details Defined in Codec.Picture.Png.Internal.Export Methods encodePng :: Image PixelRGBA16 -> ByteString # encodePngWithMetadata :: Metadatas -> Image PixelRGBA16 -> ByteString #
PngSavable PixelRGBA8 # |
Instance details Defined in Codec.Picture.Png.Internal.Export Methods encodePng :: Image PixelRGBA8 -> ByteString # encodePngWithMetadata :: Metadatas -> Image PixelRGBA8 -> ByteString #
PngSavable PixelYA16 # |
Instance details Defined in Codec.Picture.Png.Internal.Export Methods encodePng :: Image PixelYA16 -> ByteString # encodePngWithMetadata :: Metadatas -> Image PixelYA16 -> ByteString #
PngSavable PixelYA8 # |
Instance details Defined in Codec.Picture.Png.Internal.Export Methods encodePng :: Image PixelYA8 -> ByteString # encodePngWithMetadata :: Metadatas -> Image PixelYA8 -> ByteString #

class PngPaletteSaveable a where #

Encode a paletted image into a png if possible.

Minimal complete definition

encodePalettedPngWithMetadata

Methods

encodePalettedPng :: Image a -> Image Pixel8 -> Either String ByteString #

Encode a paletted image as a color indexed 8-bit PNG. the palette must have between 1 and 256 values in it. Accepts `PixelRGB8` and `PixelRGBA8` as palette pixel type

encodePalettedPngWithMetadata :: Metadatas -> Image a -> Image Pixel8 -> Either String ByteString #

Equivalent to `encodePalettedPng` but allow writing of metadatas. See `encodePngWithMetadata` for the details of encoded metadatas Accepts `PixelRGB8` and `PixelRGBA8` as palette pixel type

#### Instances

Instances details

PngPaletteSaveable PixelRGB8 # |
Instance details Defined in Codec.Picture.Png.Internal.Export Methods encodePalettedPng :: Image PixelRGB8 -> Image Pixel8 -> Either String ByteString # encodePalettedPngWithMetadata :: Metadatas -> Image PixelRGB8 -> Image Pixel8 -> Either String ByteString #
PngPaletteSaveable PixelRGBA8 # |
Instance details Defined in Codec.Picture.Png.Internal.Export Methods encodePalettedPng :: Image PixelRGBA8 -> Image Pixel8 -> Either String ByteString # encodePalettedPngWithMetadata :: Metadatas -> Image PixelRGBA8 -> Image Pixel8 -> Either String ByteString #

decodePng :: ByteString -> 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 images:

- `ImageY8`
- `ImageY16`
- `ImageYA8`
- `ImageYA16`
- `ImageRGB8`
- `ImageRGB16`
- `ImageRGBA8`
- `ImageRGBA16`

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

Decode a PNG file with, possibly, separated palette.

decodePngWithPaletteAndMetadata :: ByteString -> Either String (PalettedImage, Metadatas) #

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

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

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

encodeDynamicPng :: DynamicImage -> Either String ByteString #

Encode a dynamic image in PNG if possible, supported images are:

- `ImageY8`
- `ImageY16`
- `ImageYA8`
- `ImageYA16`
- `ImageRGB8`
- `ImageRGB16`
- `ImageRGBA8`
- `ImageRGBA16`

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

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