stb-image-0.2.1: A wrapper around Sean Barrett's JPEG/PNG decoder

Safe HaskellSafe-Infered

Codec.Image.STB

Description

A wrapper around stb_image, Sean Barrett's public domain JPEG/PNG decoder. The original can be found at http://nothings.org/stb_image.c. The version of stb_image used here is stbi-1.33. The current list of (partially) supported formats is JPEG, PNG, TGA, BMP, PSD.

Please note that the library is not (fully) thread-safe! Furthermore, the library does not give any guarantee in case of invalid input; in particular it is a security risk to load untrusted image files.

Synopsis

Documentation

data Bitmap t

A bitmap.

decodeImage :: ByteString -> IO (Either String Image)Source

Decodes an image from a compressed format stored in a strict ByteString. Supported formats (see stb_image.c for details!):

  • JPEG baseline (no JPEG progressive, no oddball channel decimations)
  • PNG 8-bit only (8 bit per component, that is)
  • BMP non-1bpp, non-RLE
  • TGA (not sure what subset, if a subset)
  • PSD (composite view only, no extra channels)

If the operation fails, we return an error message.

decodeImage' :: Int -> ByteString -> IO (Either String Image)Source

Decodes an image, with the number of components per pixel forced by the user.

loadImage :: FilePath -> IO (Either String Image)Source

Loads an image from a file. Catches IO exceptions and converts them to an error message.

loadImage' :: FilePath -> Int -> IO (Either String Image)Source

Force the number of components in the image.