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

Safe Haskell | None
Language | Haskell2010

Codec.Picture.Gif

Contents

- Reading
- Writing

Description

Module implementing GIF decoding.

Synopsis

- decodeGif :: ByteString -> Either String DynamicImage
- decodeGifWithMetadata :: ByteString -> Either String (DynamicImage, Metadatas)
- decodeGifWithPaletteAndMetadata :: ByteString -> Either String (PalettedImage, Metadatas)
- decodeGifImages :: ByteString -> Either String [DynamicImage]
- getDelaysGifImages :: ByteString -> Either String [GifDelay]
- type GifDelay = Int
- data GifDisposalMethod
  - = DisposalAny
  - | DisposalDoNot
  - | DisposalRestoreBackground
  - | DisposalRestorePrevious
  - | DisposalUnknown Word8
- data GifEncode = GifEncode {
  - geWidth :: Int
  - geHeight :: Int
  - gePalette :: Maybe Palette
  - geBackground :: Maybe Int
  - geLooping :: GifLooping
  - geFrames :: [GifFrame]
  }
- data GifFrame = GifFrame {
  - gfXOffset :: Int
  - gfYOffset :: Int
  - gfPalette :: Maybe Palette
  - gfTransparent :: Maybe Int
  - gfDelay :: GifDelay
  - gfDisposal :: GifDisposalMethod
  - gfPixels :: Image Pixel8
  }
- data GifLooping
  - = LoopingNever
  - | LoopingForever
  - | LoopingRepeat Word16
- encodeGifImage :: Image Pixel8 -> ByteString
- encodeGifImageWithPalette :: Image Pixel8 -> Palette -> Either String ByteString
- encodeGifImages :: GifLooping -> [(Palette, GifDelay, Image Pixel8)] -> Either String ByteString
- encodeComplexGifImage :: GifEncode -> Either String ByteString
- writeGifImage :: FilePath -> Image Pixel8 -> IO ()
- writeGifImageWithPalette :: FilePath -> Image Pixel8 -> Palette -> Either String (IO ())
- writeGifImages :: FilePath -> GifLooping -> [(Palette, GifDelay, Image Pixel8)] -> Either String (IO ())
- writeComplexGifImage :: FilePath -> GifEncode -> Either String (IO ())
- greyPalette :: Palette

# Reading

decodeGif :: ByteString -> Either String DynamicImage #

Transform a raw gif image to an image, without modifying the pixels. This function can output the following images:

- `ImageRGB8`
- `ImageRGBA8`

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

Transform a raw gif image to an image, without modifying the pixels. This function can output the following images:

- `ImageRGB8`
- `ImageRGBA8`

Metadatas include Width & Height information.

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

Return the gif image with metadata and palette. The palette is only returned for the first image of an animation and has no transparency.

decodeGifImages :: ByteString -> Either String [DynamicImage] #

Transform a raw gif to a list of images, representing all the images of an animation.

getDelaysGifImages :: ByteString -> Either String [GifDelay] #

Extract a list of frame delays from a raw gif.

# Writing

type GifDelay = Int #

Delay to wait before showing the next Gif image. The delay is expressed in 100th of seconds.

data GifDisposalMethod #

Constructors

DisposalAny |
DisposalDoNot |
DisposalRestoreBackground |
DisposalRestorePrevious |
DisposalUnknown Word8 |

data GifEncode #

GIF image definition for encoding

Constructors

GifEncode |
Fields geWidth :: Int Screen width geHeight :: Int Screen height gePalette :: Maybe Palette Global palette, optional geBackground :: Maybe Int Background color index, optional. If given, a global palette is also required geLooping :: GifLooping Looping behaviour geFrames :: [GifFrame] Image frames

data GifFrame #

An individual image frame in a GIF image

Constructors

GifFrame |
Fields gfXOffset :: Int Image X offset in GIF canvas gfYOffset :: Int Image Y offset in GIF canvas gfPalette :: Maybe Palette Image local palette, optional if a global palette is given gfTransparent :: Maybe Int Transparent color index, optional gfDelay :: GifDelay Frame transition delay, in 1/100ths of a second gfDisposal :: GifDisposalMethod Frame disposal method gfPixels :: Image Pixel8 Image pixels

data GifLooping #

Help to control the behaviour of GIF animation looping.

Constructors

LoopingNever | The animation will stop once the end is reached
LoopingForever | The animation will restart once the end is reached
LoopingRepeat Word16 | The animation will repeat n times before stoping

encodeGifImage :: Image Pixel8 -> ByteString #

Encode a greyscale image to a bytestring.

encodeGifImageWithPalette :: Image Pixel8 -> Palette -> Either String ByteString #

Encode an image with a given palette. Can return errors if the palette is ill-formed.

- A palette must have between 1 and 256 colors

encodeGifImages :: GifLooping -> [(Palette, GifDelay, Image Pixel8)] -> Either String ByteString #

Encode a gif animation to a bytestring.

- Every image must have the same size
- Every palette must have between one and 256 colors.

encodeComplexGifImage :: GifEncode -> Either String ByteString #

Encode a complex gif to a bytestring.

- There must be at least one image.
- The screen and every frame dimensions must be between 1 and 65535.
- Every frame image must fit within the screen bounds.
- Every palette must have between one and 256 colors.
- There must be a global palette or every image must have a local palette.
- The background color index must be present in the global palette.
- Every frame's transparent color index, if set, must be present in the palette used by that frame.
- Every color index used in an image must be present in the palette used by that frame.

writeGifImage :: FilePath -> Image Pixel8 -> IO () #

Write a greyscale in a gif file on the disk.

writeGifImageWithPalette :: FilePath -> Image Pixel8 -> Palette -> Either String (IO ()) #

Write a gif image with a palette to a file.

- A palette must have between 1 and 256 colors

writeGifImages :: FilePath -> GifLooping -> [(Palette, GifDelay, Image Pixel8)] -> Either String (IO ()) #

Write a list of images as a gif animation in a file.

- Every image must have the same size
- Every palette must have between one and 256 colors.

writeComplexGifImage :: FilePath -> GifEncode -> Either String (IO ()) #

greyPalette :: Palette #

Default palette to produce greyscale images.