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

Data.Bitmap.IO

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.

Instances

Instances details
BitmapClass IOBitmap Source # 
Instance details

Defined in Data.Bitmap.Internal

Creating and accessing bitmaps

emptyBitmap Source #

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

cloneBitmap Source #

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Maybe Alignment

target alignment

-> IO (IOBitmap t) 

Clones a bitmap.

emptyCloneBitmap Source #

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.

createSingleChannelBitmap Source #

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!

newIOBitmap Source #

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.

copyBitmapFromPtr Source #

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 a Source #

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

copySubImage Source #

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.

copySubImageInto Source #

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

flipBitmap Source #

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Maybe Alignment

target image row alignment

-> IO (IOBitmap t) 

Flips the bitmap vertically.

flipBitmapInPlace Source #

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> IO () 

mirrorBitmap Source #

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Maybe Alignment

target image row alignment

-> IO (IOBitmap t) 

Flips the bitmap horizontally.

mirrorBitmapInPlace Source #

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> IO () 

Cast

castBitmap Source #

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

extractSingleChannel Source #

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Maybe Alignment

target image row alignment

-> Int

source channel index

-> IO (IOBitmap t) 

extractChannelInto Source #

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Int

source channel index

-> IOBitmap t

target image

-> Int

target channel index

-> IO () 

Bilinear resampling

bilinearResample Source #

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Size

target image size

-> Maybe Alignment

target image alignment

-> IO (IOBitmap t) 

bilinearResampleChannel Source #

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Int

source channel index

-> Size

target image size

-> Maybe Alignment

target image alignment

-> IO (IOBitmap t) 

bilinearResampleChannelInto Source #

Arguments

:: PixelComponent t 
=> IOBitmap t

source image

-> Int

source channel index

-> IOBitmap t

target image

-> Int

target channel index

-> IO () 

Blending

blendBitmaps Source #

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.

blendChannels Source #

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) 

blendChannelsInto Source #

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

powerlawGammaCorrection Source #

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.

powerlawGammaCorrectionChannel Source #

Arguments

:: PixelComponent t 
=> Float

gamma

-> IOBitmap t

source image

-> Int

source channel index

-> Maybe Alignment

target image alignment

-> IO (IOBitmap t) 

powerlawGammaCorrectionChannelInto Source #

Arguments

:: PixelComponent t 
=> Float

gamma

-> IOBitmap t

source image

-> Int

source channel index

-> IOBitmap t

target image

-> Int

target channel index

-> IO ()