bitmap-0.0.0: A library for handling and manipulating bitmaps.

Data.Bitmap.IO

Contents

Description

The full, mutable API in the IO monad.

Synopsis

Documentation

Creating and accessing bitmaps

newBitmapSource

Arguments

:: forall t . PixelComponent t 
=> Size

(width,height)

-> NChn

number of channels (components/pixel)

-> Maybe Alignment

the row alignment of the new image

-> IO (Bitmap t) 

Note: we cannot guarantee the alignment of the memory block (but typically it is aligned at least to machine word boundary), but what we can guarantee is that the rows are properly padded.

The resulting new bitmap is filled with zeros.

copyBitmapFromPtrSource

Arguments

:: forall t . PixelComponent t 
=> Size

(width,height) of the source

-> NChn

number of channels in the source

-> Padding

source padding

-> Ptr t

the source

-> Maybe Alignment

target alignment

-> IO (Bitmap t) 

withBitmap :: PixelComponent t => Bitmap t -> (Size -> NChn -> Padding -> Ptr t -> IO a) -> IO aSource

withBitmap bitmap $ \(w,h) nchn padding ptr -> ...

Mapping over bitmaps

componentMap :: PixelComponent s => (s -> s) -> Bitmap s -> IO (Bitmap s)Source

Maps a function over each component of each pixel. Warning: this is slow! Use a specialized function if there is one for your task.

Note: We don't do the more general (s->t) here, because then we would have no idea about the padding in the new bitmap. See componentMap' for that.

componentMap'Source

Arguments

:: (PixelComponent s, PixelComponent t) 
=> (s -> t) 
-> Bitmap s

source bitmap

-> Maybe Alignment

row alignment of the resulting bitmap

-> IO (Bitmap t) 

See the comments at componentMap.

Cropping and extending

copySubImageSource

Arguments

:: PixelComponent t 
=> Bitmap t

source image

-> Offset

source rectangle offset

-> Size

source rectangle size

-> IO (Bitmap t) 

Copies a subrectangle of the source image into a new image.

copySubImage'Source

Arguments

:: PixelComponent t 
=> Bitmap t

source image

-> Offset

source rectangle offset

-> Size

source rectangle size

-> Size

target image size

-> Offset

target rectangle offset

-> IO (Bitmap t) 

Copy into a new "black" bitmap; common generalization of crop and extend.

copySubImageIntoSource

Arguments

:: PixelComponent t 
=> Bitmap t

source image

-> Offset

source rectangle offset

-> Size

source rectangle size

-> Bitmap t

target image

-> Offset

target rectangle offset

-> IO () 

The source rectangle may be arbitrary, may or may not intersect the source image in any way. We only copy the intersection of the rectangle with the image.

Manipulating channels

extractSingleChannelSource

Arguments

:: PixelComponent t 
=> Bitmap t

source image

-> Maybe Alignment

target image row alignment

-> Int

source channel index

-> IO (Bitmap t) 

extractChannelIntoSource

Arguments

:: forall t . PixelComponent t 
=> Bitmap t

source image

-> Int

source channel index

-> Bitmap t

target image

-> Int

target channel index

-> IO () 

Conversion to/from ByteString

copyBitmapToByteString :: PixelComponent t => Bitmap t -> IO ByteStringSource

The data is copied, not shared.

copyBitmapFromByteString :: forall t. PixelComponent t => ByteString -> Size -> NChn -> Padding -> IO (Bitmap t)Source

The data is copied, not shared.