repa-devil-0.3.2.5: Support for image reading and writing of Repa arrays using in-place FFI calls

Copyright(c) Don Stewart 2011, Raphael Javaux 2012
LicenseBSD3
MaintainerDon Stewart <dons00@gmail.com> , Raphael Javaux <raphaeljavaux@gmail.com
Stabilityprovisional
PortabilityRepa interface to the DevIL image loading library.
Safe HaskellNone
LanguageHaskell98

Data.Array.Repa.IO.DevIL

Contents

Description

Read and write images in many formats, representing them in Haskell as a 3-dimensional repa array. Image parsing and decoding is done by the Developers Image Library, DevIL.

  • Many formats are supported, including .png, .bmp, .jpg, .tif
  • Image format parsing is determined by the filepath extension type.
  • Only RGB, RGBA, BGR, BGRA and Greyscale images are supported.

Example: read a .png file into a repa array, and write it out as a .jpg

main = runIL $ do
         x <- readImage "/tmp/y.png" 
         writeImage "/tmp/x.jpg" x

Note that as DevIL is stateful, we ensure the library is initialized by running image manipulation functions in the IL monad, a wrapper over IO that ensures the library has been initialized. It is a type error to call image functions outside of the IL monad.

Synopsis

The Image array type

data Image Source

RGBA, RGB, BGRA and BGR images are 3D repa arrays where indices are Z :. row :. column :. color channel. Grey images are 2D repa arrays.

The origin (Z :. 0 :. 0) is on the lower left point of the image.

The IL monad

data IL a Source

The IL monad. Provides statically-guaranteed access to an initialized IL context.

runIL :: IL a -> IO a Source

Running code in the IL monad. This is a simple wrapper over IO that guarantees the DevIL library has been initialized before you run functions on it.

Image IO

readImage :: FilePath -> IL Image Source

Reads an image into a repa array. It uses directly the C array using the repa's foreign arrays wrapper.

Example:

main = do
   x <- runIL $ readImage "/tmp/x.png"
   .. operations on x ..

Note: The image input type is determined by the filename extension.

writeImage :: FilePath -> Image -> IL () Source

Writes an Image to a file. The image array must be represented as foreign buffers. You can use copyS or copyP to convert the array.

Note: The image output type is determined by the filename extension.