Programming Reference:BitmapImage Class

From BCI2000 Wiki
Jump to: navigation, search

Location

src/shared/types

Synopsis

A BitmapImage object represents a 15-bit color pixel image, supporting the following operations:

  • Manipulation of individual pixel values,
  • Stream reading/writing in run-length compressed form,
  • Addition/subtraction to support temporal compression of image sequences,
  • Masked copying, using the otherwise unused 16th bit of the color value as a mask.

Methods

BitmapImage(width=0, height=0)

The constructor allocates storage for the specified dimensions, and initializes the image to black.

SetBlack()

Clears all pixels, setting them to black.

SetBackground(BitmapImage)

This function replaces an image's "background" with pixels from the image specified as argument. "Background" pixels are pixels with the most significant bit set to 1.

WriteBinary(ostream), ReadBinary(istream)

Writes/reads the image's data to or from the specified streams. An image's stream representation is always run-length encoded, which is especially efficient in conjunction with temporal compression, i.e. sending sequences of difference images.

Properties

bool Empty (r)

True if at least one of the image's dimensions is 0.

int Width, Height (r)

The image's width and height in pixels.

Pixel Access

Access to individual pixels is provided via an index operator taking x and y coordinate as arguments:

BitmapImage myImage( 10, 10 );
myImage( 3, 4 ) = RGBColor::Red;
RGBColor myPixel = myImage( 5, 6 );

Addition and Subtraction

Computing difference images, and restoring original images from a reference frame followed with difference frames, is possible using addition and subtraction:

 BitmapImage image1, image2;
 BitmapImage diff = image1 - image2;
 diff += image2;

Note that pixels in difference images do not represent differences of individual color values; rather, difference images are computed by treating pixel values as signed 16-bit integers, and subtracting the second image's pixel data from the first one's.

See also

Programming Reference:GraphDisplay Class