Simple haskell script that inverts (creates a negative of) a given .bmp
image. The original miage must be:
- 24 bpp pixel size
- Uncompressed
title | original | negative |
---|---|---|
bmp_24 | ||
color wheel | ![]() |
![]() |
snail | ![]() |
![]() |
blackbuck | ![]() |
![]() |
marbles |
Example images can be found in /images
directory. /images/unsupported
images contain examples of unsupported .bmp
images.
- Install the executable using
cabal install
- Run the exectuable using
bmp-negative {PATH_TO_BMP_IMAGE}
-h
flag for help message
- Image will be generated in the same directory as the original image.
- Script imports the
.bmp
image as aByteString
and converts is to a[Byte]
or byte array. - Split the byte array as
(Header,PixelData)
.- Initially, the header data is parsed. Check whether application accepts the given
.bmp
. - Parse the
PixelData
.- We can consider it as an array of
Row
s. - Each
Row
is a byte array ofRGB
color bytes andPadding
bytes. - The number of
Padding
bytes isrowSize - 3 * width
, whererowSize = div (width * 24 + 31) 32 * 4
- We can consider it as an array of
- Relevent type alias' here:
type BmpImage = (Header,PixelData) type Header = [Byte] type PixelData = [Row] type Row = (RGB,Padding) type RGB = [Byte] type Padding = [Byte]
- Initially, the header data is parsed. Check whether application accepts the given
- Invert the image. It's a simple operation of
255 - b
, whereb
is an RGB color byte. - Write the new
BmpImage
as a new.bmp
.