bitmap-0.0.2: A library for handling and manipulating bitmaps (rectangular pixel arrays).

Safe HaskellSafe-Infered

Data.Bitmap.IO

Contents

Description

The full, mutable API in the IO monad.

Synopsis

Documentation

Mutable bitmap type

data IOBitmap t Source

A mutable Bitmap in the IO Monad. Only the content is mutable, the shape isn't.

Creating and accessing bitmaps

emptyBitmapSource

Arguments

:: PixelComponent t 
=> Size

(width,height)

-> NChn

number of channels (components/pixel)

-> Maybe Alignment

the row alignment of the new image

-> IO (IOBitmap t) 

Synonym for newIOBitmap

cloneBitmapSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Maybe Alignment

target alignment

-> IO (IOBitmap t) 

Clones a bitmap.

emptyCloneBitmapSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source (only dimensions and such is used)

-> Maybe Alignment

target alignment

-> IO (IOBitmap t)

new empty bitmap

Creates an empty bitmap with the same properties as the source.

createSingleChannelBitmapSource

Arguments

:: PixelComponent t 
=> Size

(width,height)

-> Maybe Alignment

the row alignment of the new image

-> (Int -> Int -> t)

the function we will use to fill the bitmap

-> IO (IOBitmap t) 

Creates a new single-channel bitmap, using the given function to compute the pixel values. Warning, this is probably slow!

newIOBitmapSource

Arguments

:: PixelComponent t 
=> Size

(width,height)

-> NChn

number of channels (components/pixel)

-> Maybe Alignment

the row alignment of the new image

-> IO (IOBitmap 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.

At the moment, the default alignment is 4, valid alignments are 1, 2, 4, 8 and 16, and the padding method is compatible with the OpenGL one (that is, the padding is the smallest multiple of a component size such that the next row is aligned).

The resulting new bitmap is filled with zeros.

copyBitmapFromPtrSource

Arguments

:: 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 (IOBitmap t) 

Using bitmaps

withIOBitmap :: PixelComponent t => IOBitmap t -> (Size -> NChn -> Padding -> Ptr t -> IO a) -> IO aSource

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

Mapping over bitmaps

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

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

componentMap'Source

Arguments

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

source bitmap

-> Maybe Alignment

row alignment of the resulting bitmap

-> IO (IOBitmap t) 

Cropping and extending

copySubImageSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Offset

source rectangle offset

-> Size

source rectangle size

-> IO (IOBitmap t) 

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

copySubImage'Source

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Offset

source rectangle offset

-> Size

source rectangle size

-> Size

target image size

-> Offset

target rectangle offset

-> IO (IOBitmap t) 

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

copySubImageIntoSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Offset

source rectangle offset

-> Size

source rectangle size

-> IOBitmap 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.

Flipping and mirroring

flipBitmapSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Maybe Alignment

target image row alignment

-> IO (IOBitmap t) 

Flips the bitmap vertically.

flipBitmapInPlaceSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> IO () 

mirrorBitmapSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Maybe Alignment

target image row alignment

-> IO (IOBitmap t) 

Flips the bitmap horizontally.

mirrorBitmapInPlaceSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> IO () 

Cast

castBitmapSource

Arguments

:: (PixelComponent s, PixelComponent t) 
=> IOBitmap s

source image

-> Maybe Alignment

target image row alignment

-> IO (IOBitmap t) 

Convert a bitmap to one with a different component type.

Manipulating channels

extractSingleChannelSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Maybe Alignment

target image row alignment

-> Int

source channel index

-> IO (IOBitmap t) 

extractChannelIntoSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Int

source channel index

-> IOBitmap t

target image

-> Int

target channel index

-> IO () 

Bilinear resampling

bilinearResampleSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Size

target image size

-> Maybe Alignment

target image alignment

-> IO (IOBitmap t) 

bilinearResampleChannelSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Int

source channel index

-> Size

target image size

-> Maybe Alignment

target image alignment

-> IO (IOBitmap t) 

bilinearResampleChannelIntoSource

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Int

source channel index

-> IOBitmap t

target image

-> Int

target channel index

-> IO () 

Blending

blendBitmapsSource

Arguments

:: PixelComponent t 
=> Float

weight1

-> Float

weight2

-> IOBitmap t

source1 image

-> IOBitmap t

source2 image

-> Maybe Alignment

target alignment

-> IO (IOBitmap t) 

Blends two bitmaps with the given weights; that is, the result is the specified linear combination. If the values are outside the allowed range (this can happen with the Word8, Word16, Word32 types and weights whose sum is bigger than 1, or with a negative weight), then they are clipped. The clipping does not happen with the Float component type.

blendChannelsSource

Arguments

:: PixelComponent t 
=> Float

weight1

-> Float

weight2

-> IOBitmap t

source1 image

-> Int

source1 channel index

-> IOBitmap t

source2 image

-> Int

source2 channel index

-> Maybe Alignment

target alignment

-> IO (IOBitmap t) 

blendChannelsIntoSource

Arguments

:: PixelComponent t 
=> Float

weight1

-> Float

weight2

-> IOBitmap t

source1 image

-> Int

source1 channel index

-> IOBitmap t

source2 image

-> Int

source2 channel index

-> IOBitmap t

target image

-> Int

target channel index

-> IO () 

Gamma correction

powerlawGammaCorrectionSource

Arguments

:: PixelComponent t 
=> Float

gamma

-> IOBitmap t

source bitmap

-> Maybe Alignment

target alignment

-> IO (IOBitmap t) 

This is equivalent to componentMap (c -> c^gamma), except that (^) is defined only for integral exponents; but should be faster anyway.

powerlawGammaCorrectionChannelSource

Arguments

:: PixelComponent t 
=> Float

gamma

-> IOBitmap t

source image

-> Int

source channel index

-> Maybe Alignment

target image alignment

-> IO (IOBitmap t) 

powerlawGammaCorrectionChannelIntoSource

Arguments

:: PixelComponent t 
=> Float

gamma

-> IOBitmap t

source image

-> Int

source channel index

-> IOBitmap t

target image

-> Int

target channel index

-> IO ()