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

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.18. The current list of (partially) supported formats is JPEG, PNG, TGA, BMP, PSD. Please note that the library is not (fully) thread-safe!

Synopsis

Documentation

data Image Source

The type representing a simple rectangular image. Internally it stores the resolution, the pixel format, and the raw pixel data as a strict ByteString.

withImage :: (Integral a, Integral b) => Image -> (Ptr Word8 -> (a, a) -> b -> IO c) -> IO cSource

Access to the raw data. The user action receives a pointer, the spatial resolution and the number of (8-bit) components per pixel.

Data format (bytes per pixel -> components):

  • 1 -> grey
  • 2 -> grey, alpha
  • 3 -> red, green, blue
  • 4 -> red, green, blue, alpha

rawImage :: Image -> ByteStringSource

Access the raw data as a strict ByteString.

resolution :: Integral a => Image -> (a, a)Source

Returns the spatial resolution of an image.

components :: Integral a => Image -> aSource

Returns the number of (8-bit) components per pixel.

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, returns an error message.

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

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