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!
- data Image
- withImage :: (Integral a, Integral b) => Image -> (Ptr Word8 -> (a, a) -> b -> IO c) -> IO c
- rawImage :: Image -> ByteString
- resolution :: Integral a => Image -> (a, a)
- components :: Integral a => Image -> a
- decodeImage :: ByteString -> IO (Either String Image)
- loadImage :: FilePath -> IO (Either String Image)
Documentation
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.