(E) Bitmap Extensions

Abstract

Bitmap Extension Procedures

bitmap->greymap

(bitmap->greymap <bitmap>) converts the supplied bitmap to a greymap and returns this new generated greymap. Each black pixel in the bitmap becomes a greymap pixel with greylevel 255, each white pixel becomes a greymap pixel with greylevel 0.

[1] (bitmap->greymap (bitmap-create 500 500))
#<greymap orow:-1 ocol:-1 xres:-1 yres:-1 h:500 w:500>
[2]

bitmap->string

(bitmap->string <bitmap>) returns the bitmap pixel data of the given bitmap in a new created string. The string contains all scanlines of the bitmap concatenated while each line is filled up to the byte boundary with bits containing 0.

[1] (bitmap->string (bitmap-create 8 8))
"\000\000\000\000\000\000\000\000"
[2]

bitmap-appendtiff

(bitmap-appendtiff <bitmap> <filename>) appends a new page to the end of the supplied tiff file containing the given bitmap in G4 encoding. If the supplied file does not already exist this function creates the file writing the bitmap to the first page.

[1] (define page (bitmap-create 200 200))
page
[2] (bitmap-appendtiff page "/tmp/example.tiff")
ok
[3] (bitmap-appendtiff page "/tmp/example.tiff")
ok
[4] (system "file /tmp/example.tiff")
/tmp/example.tiff: TIFF image data, little-endian, direntries=12, height=200, bps=1, compression=bi-level group 4, PhotometricIntepretation=WhiteIsZero, orientation=upper-left, width=200
0
[5]

This is the just created tiff file opened with macOS Preview:

MacOS Preview

bitmap-clearpixel

(bitmap-clearpixel! <bitmap> <row> <column>) sets the pixel at the given row and column to zero (white). The bitmap is modified and returned.

[1] (define bitmap (bitmap-create 1 1))
bitmap
[2] (bitmap-clearpixel! bitmap 0 0)
#<bitmap orow:-1 ocol:-1 xres:-1 yres:-1 h:1 w:1>
[3] (bitmap-clearpixel! bitmap 0 1)

ERROR!
  message   : error (dimension?)
  irritant  : #<primitive-procedure bitmap-clearpixel!>
  expression: 1
  continue  : possible, continue with value as value from primitive

Error (? for help) >>