The full, mutable API in the IO monad.
- module Data.Bitmap.Base
- newBitmap :: forall t. PixelComponent t => Size -> NChn -> Maybe Alignment -> IO (Bitmap t)
- newBitmapUninitialized :: forall t. PixelComponent t => Size -> NChn -> Maybe Alignment -> IO (Bitmap t)
- copyBitmapFromPtr :: forall t. PixelComponent t => Size -> NChn -> Padding -> Ptr t -> Maybe Alignment -> IO (Bitmap t)
- bitmapFromForeignPtrUnsafe :: forall t. PixelComponent t => Size -> NChn -> Alignment -> Padding -> ForeignPtr t -> Bitmap t
- withBitmap :: PixelComponent t => Bitmap t -> (Size -> NChn -> Padding -> Ptr t -> IO a) -> IO a
- componentMap :: PixelComponent s => (s -> s) -> Bitmap s -> IO (Bitmap s)
- componentMap' :: (PixelComponent s, PixelComponent t) => (s -> t) -> Bitmap s -> Maybe Alignment -> IO (Bitmap t)
- componentMapInPlace :: PixelComponent s => (s -> s) -> Bitmap s -> IO ()
- copySubImage :: PixelComponent t => Bitmap t -> Offset -> Size -> IO (Bitmap t)
- copySubImage' :: PixelComponent t => Bitmap t -> Offset -> Size -> Size -> Offset -> IO (Bitmap t)
- copySubImageInto :: PixelComponent t => Bitmap t -> Offset -> Size -> Bitmap t -> Offset -> IO ()
- combineChannels :: forall t. PixelComponent t => [Bitmap t] -> Maybe Alignment -> IO (Bitmap t)
- extractChannels :: PixelComponent t => Bitmap t -> Maybe Alignment -> IO [Bitmap t]
- extractSingleChannel :: PixelComponent t => Bitmap t -> Maybe Alignment -> Int -> IO (Bitmap t)
- extractChannelInto :: forall t. PixelComponent t => Bitmap t -> Int -> Bitmap t -> Int -> IO ()
- copyBitmapToByteString :: PixelComponent t => Bitmap t -> IO ByteString
- copyBitmapFromByteString :: forall t. PixelComponent t => ByteString -> Size -> NChn -> Padding -> IO (Bitmap t)
Documentation
module Data.Bitmap.Base
Creating and accessing bitmaps
:: 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.
newBitmapUninitialized :: forall t. PixelComponent t => Size -> NChn -> Maybe Alignment -> IO (Bitmap t)Source
bitmapFromForeignPtrUnsafe :: forall t. PixelComponent t => Size -> NChn -> Alignment -> Padding -> ForeignPtr t -> Bitmap tSource
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.
:: (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
.
componentMapInPlace :: PixelComponent s => (s -> s) -> Bitmap s -> IO ()Source
Cropping and extending
:: 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.
:: 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.
:: 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
combineChannels :: forall t. PixelComponent t => [Bitmap t] -> Maybe Alignment -> IO (Bitmap t)Source
extractChannels :: PixelComponent t => Bitmap t -> Maybe Alignment -> IO [Bitmap t]Source
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.