ArduinoLibs
Public Types | Public Member Functions | Static Public Attributes | Friends
Bitmap Class Reference

Represents a monochrome bitmap within main memory. More...

#include <Bitmap.h>

Inheritance diagram for Bitmap:
DMD

List of all members.

Public Types

typedef uint8_t Color
 Type that represents the color of a pixel in a bitmap.

Public Member Functions

 Bitmap (int width, int height)
 Constructs a new in-memory bitmap that is width x height pixels in size.
 ~Bitmap ()
 Destroys this bitmap.
bool isValid () const
 Returns true if the memory for this bitmap is valid; false otherwise.
int width () const
 Returns the width of the bitmap in pixels.
int height () const
 Returns the height of the bitmap in pixels.
int stride () const
 Returns the number of bytes in each line of the bitmap's data() buffer.
int bitsPerPixel () const
 Returns the number of bits per pixel for the bitmap; always 1.
uint8_t * data ()
 Returns a pointer to the start of the bitmap's data buffer.
const uint8_t * data () const
 Returns a constant pointer to the start of the bitmap's data buffer.This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void clear (Color color=Black)
 Clears the entire bitmap to the specified color.
Color pixel (int x, int y) const
 Returns the color of the pixel at (x, y); either Black or White.
void setPixel (int x, int y, Color color)
 Sets the pixel at (x, y) to color.
void drawLine (int x1, int y1, int x2, int y2, Color color=White)
 Draws a line from (x1, y1) to (x2, y2) in color.
void drawRect (int x1, int y1, int x2, int y2, Color borderColor=White, Color fillColor=NoFill)
 Draws a rectangle from (x1, y1) to (x2, y2), with the outline in borderColor and the interior filled with fillColor.
void drawFilledRect (int x1, int y1, int x2, int y2, Color color=White)
 Draws a filled rectangle from (x1, y1) to (x2, y2) in color.
void drawCircle (int centerX, int centerY, int radius, Color borderColor=White, Color fillColor=NoFill)
 Draws a circle with a specific center (centerX, centerY) and radius, with the outline in borderColor and the interior filled with fillColor.
void drawFilledCircle (int centerX, int centerY, int radius, Color color=White)
 Draws a filled circle with a specific center (centerX, centerY) and radius in color.
void drawBitmap (int x, int y, const Bitmap &bitmap, Color color=White)
 Draws bitmap at (x, y) in color.
void drawBitmap (int x, int y, const prog_uint8_t *bitmap, Color color=White)
 Draws bitmap at (x, y) in color.
void drawInvertedBitmap (int x, int y, const Bitmap &bitmap)
 Draws bitmap at (x, y) in inverted colors.
void drawInvertedBitmap (int x, int y, const prog_uint8_t *bitmap)
 Draws bitmap at (x, y) in inverted colors.
const prog_uint8_t * font () const
 Returns the currently selected font, or null if none selected.
void setFont (const prog_uint8_t *font)
 Sets the font for use with drawText() and drawChar().
Color textColor () const
 Returns the color that will be used for drawing text with drawText() and drawChar(). The default is White.
void setTextColor (Color color)
 Sets the color that will be used for drawing text with drawText() and drawChar().
void drawText (int x, int y, const char *str, int len=-1)
 Draws the len characters of str at (x, y).
void drawText (int x, int y, const String &str, int start=0, int len=-1)
 Draws len characters starting at start from str to the screen at (x, y).
int drawChar (int x, int y, char ch)
 Draws a single character ch at (x, y).
int charWidth (char ch) const
 Returns the width in pixels of ch in the current font().
int textWidth (const char *str, int len=-1) const
 Returns the width in pixels of the len characters of str in the current font(), including inter-character spacing.
int textWidth (const String &str, int start=0, int len=-1) const
 Returns the width in pixels of the len characters of str in the current font(), starting at start, including inter-character spacing.
int textHeight () const
 Returns the height in pixels of the current text drawing font(); or zero if font() is not set.
void copy (int x, int y, int width, int height, Bitmap *dest, int destX, int destY)
 Copies the width x height pixels starting at top-left corner (x, y) to (destX, destY) in the bitmap dest.
void fill (int x, int y, int width, int height, Color color)
 Fills the width x height pixels starting at top-left corner (x, y) with color.
void fill (int x, int y, int width, int height, const prog_uint8_t *pattern, Color color=White)
 Fills the width x height pixels starting at top-left corner (x, y) with the contents of pattern.
void scroll (int dx, int dy, Color fillColor=Black)
 Scrolls the entire contents of the bitmap by dx and dy.
void scroll (int x, int y, int width, int height, int dx, int dy, Color fillColor=Black)
 Scrolls the width x height pixels starting at top-left corner (x, y) by dx and dy.
void invert (int x, int y, int width, int height)
 Inverts the width x height pixels starting at top-left corner (x, y).

Static Public Attributes

static const Color Black = 0
 Color value corresponding to "black".
static const Color White = 1
 Color value corresponding to "white". If the bitmap is displayed on a LED array, then it may have a different physical color.
static const Color NoFill = 2
 Special color value that is used with drawRect() and drawCircle() to indicate that the interior of the shape should not be filled. For all other uses, NoFill is equivalent to White.

Friends

class DMD

Detailed Description

Represents a monochrome bitmap within main memory.

Bitmaps are a rectangular arrangement of width() x height() pixels, with each pixel set to either Black or White. The co-ordinate system has origin (0, 0) at the top-left of the bitmap.

Functions within this class can be used to draw various shapes into the bitmap's data() buffer; e.g. drawLine(), drawRect(), drawBitmap(), drawText(), clear(), fill(), etc.

See also:
DMD

Definition at line 32 of file Bitmap.h.


Member Typedef Documentation

Type that represents the color of a pixel in a bitmap.

See also:
Black, White

Definition at line 40 of file Bitmap.h.


Constructor & Destructor Documentation

Bitmap::Bitmap ( int  width,
int  height 
)

Constructs a new in-memory bitmap that is width x height pixels in size.

See also:
width(), height(), isValid()

Definition at line 78 of file Bitmap.cpp.


Member Function Documentation

int Bitmap::bitsPerPixel ( ) const [inline]

Returns the number of bits per pixel for the bitmap; always 1.

See also:
width(), height()

Definition at line 49 of file Bitmap.h.

int Bitmap::charWidth ( char  ch) const

Returns the width in pixels of ch in the current font().

Returns zero if font() is not set, or ch is not present in font().

See also:
drawChar(), font(), textWidth(), textHeight()

Definition at line 640 of file Bitmap.cpp.

void Bitmap::clear ( Color  color = Black)

Clears the entire bitmap to the specified color.

See also:
fill()

Definition at line 164 of file Bitmap.cpp.

void Bitmap::copy ( int  x,
int  y,
int  width,
int  height,
Bitmap dest,
int  destX,
int  destY 
)

Copies the width x height pixels starting at top-left corner (x, y) to (destX, destY) in the bitmap dest.

The dest bitmap can be the same as this object, in which case the copy will be performed in a manner that correctly handles overlapping regions.

If some part of the source region is outside the bounds of this object, then the value Black will be copied to dest for those pixels. This can be used to produce a behaviour similar to scroll() when bitmap is the same as this object.

See also:
drawBitmap(), fill(), scroll()

Definition at line 728 of file Bitmap.cpp.

uint8_t * Bitmap::data ( ) [inline]

Returns a pointer to the start of the bitmap's data buffer.

The data is organized as height() lines of stride() bytes, laid out horizontally across the extent of width() pixels. The most significant bit in each byte has the lowest x value.

Note: bits within the data are 1 for Black and 0 for White, which is the reverse of the constant values. This differs from pixel() which returns the correct constant.

See also:
pixel(), stride()

Definition at line 51 of file Bitmap.h.

void Bitmap::drawBitmap ( int  x,
int  y,
const Bitmap bitmap,
Color  color = White 
)

Draws bitmap at (x, y) in color.

Bits that are set to White in the bitmap are drawn with color. Bits that are set to Black in the bitmap are drawn with the inverse of color. The pixel at (x, y) will be the top-left corner of the drawn image.

Note: bitmap must not be the same as this object or the behaviour will be undefined. To copy a region of a bitmap to elsewhere within the same bitmap, use copy() instead.

See also:
drawInvertedBitmap(), copy()

Definition at line 378 of file Bitmap.cpp.

void Bitmap::drawBitmap ( int  x,
int  y,
const prog_uint8_t *  bitmap,
Color  color = White 
)

Draws bitmap at (x, y) in color.

The bitmap must point to program memory. The first two bytes are the width and height of the bitmap in pixels. The rest of the data contains the pixels for the bitmap, with lines byte-aligned.

Bits that are 1 in the bitmap are drawn with color. Bits that are 0 in the bitmap are drawn with the inverse of color. The pixel at (x, y) will be the top-left corner of the drawn image.

See also:
drawInvertedBitmap(), fill()

Definition at line 415 of file Bitmap.cpp.

int Bitmap::drawChar ( int  x,
int  y,
char  ch 
)

Draws a single character ch at (x, y).

Returns the width of the character in pixels so that higher-order functions like drawText() can advance x to the location of the next character to be drawn. The width does not include inter-character spacing.

The position (x, y) will be the upper-left pixel of the drawn character.

See also:
drawText(), textColor(), font(), charWidth()

Definition at line 575 of file Bitmap.cpp.

void Bitmap::drawCircle ( int  centerX,
int  centerY,
int  radius,
Color  borderColor = White,
Color  fillColor = NoFill 
)

Draws a circle with a specific center (centerX, centerY) and radius, with the outline in borderColor and the interior filled with fillColor.

If fillColor is NoFill, then the interior is not filled.

See also:
drawFilledCircle(), drawLine(), drawRect()

Definition at line 324 of file Bitmap.cpp.

void Bitmap::drawFilledCircle ( int  centerX,
int  centerY,
int  radius,
Color  color = White 
) [inline]

Draws a filled circle with a specific center (centerX, centerY) and radius in color.

This is a convenience function that is equivalent to drawCircle(centerX, centerY, radius, color, color).

See also:
drawCircle(), drawFilledRect()

Definition at line 118 of file Bitmap.h.

void Bitmap::drawFilledRect ( int  x1,
int  y1,
int  x2,
int  y2,
Color  color = White 
) [inline]

Draws a filled rectangle from (x1, y1) to (x2, y2) in color.

This is a convenience function that is equivalent to drawRect(x1, y1, x2, y2, color, color).

See also:
drawRect(), drawFilledCircle()

Definition at line 113 of file Bitmap.h.

void Bitmap::drawInvertedBitmap ( int  x,
int  y,
const Bitmap bitmap 
) [inline]

Draws bitmap at (x, y) in inverted colors.

This is a convenience function that is equivalent to drawBitmap(x, y, bitmap, Black).

See also:
drawBitmap()

Definition at line 123 of file Bitmap.h.

void Bitmap::drawInvertedBitmap ( int  x,
int  y,
const prog_uint8_t *  bitmap 
) [inline]

Draws bitmap at (x, y) in inverted colors.

This is a convenience function that is equivalent to drawBitmap(x, y, bitmap, Black).

See also:
drawBitmap()

Definition at line 128 of file Bitmap.h.

void Bitmap::drawLine ( int  x1,
int  y1,
int  x2,
int  y2,
Color  color = White 
)

Draws a line from (x1, y1) to (x2, y2) in color.

See also:
drawRect(), drawCircle()

Definition at line 215 of file Bitmap.cpp.

void Bitmap::drawRect ( int  x1,
int  y1,
int  x2,
int  y2,
Color  borderColor = White,
Color  fillColor = NoFill 
)

Draws a rectangle from (x1, y1) to (x2, y2), with the outline in borderColor and the interior filled with fillColor.

If fillColor is NoFill, then the interior is not filled.

See also:
drawFilledRect(), drawLine(), drawCircle(), fill()

Definition at line 276 of file Bitmap.cpp.

void Bitmap::drawText ( int  x,
int  y,
const char *  str,
int  len = -1 
)

Draws the len characters of str at (x, y).

If len is less than zero, then the actual length of str will be used.

The position (x, y) will be the upper-left pixel of the first character that is drawn.

See also:
drawChar(), textColor(), font()

Definition at line 516 of file Bitmap.cpp.

void Bitmap::drawText ( int  x,
int  y,
const String &  str,
int  start = 0,
int  len = -1 
)

Draws len characters starting at start from str to the screen at (x, y).

If len is less than zero, then the actual length of str will be used.

The position (x, y) will be the upper-left pixel of the first character that is drawn.

See also:
drawChar(), textColor(), font()

Definition at line 545 of file Bitmap.cpp.

void Bitmap::fill ( int  x,
int  y,
int  width,
int  height,
Color  color 
)

Fills the width x height pixels starting at top-left corner (x, y) with color.

See also:
copy(), clear(), invert(), drawRect()

Definition at line 752 of file Bitmap.cpp.

void Bitmap::fill ( int  x,
int  y,
int  width,
int  height,
const prog_uint8_t *  pattern,
Color  color = White 
)

Fills the width x height pixels starting at top-left corner (x, y) with the contents of pattern.

The pattern must point to program memory. The first two bytes are the width and height of the pattern in pixels. The rest of the data contains the pixels for the pattern, with lines byte-aligned.

Bits that are 1 in the pattern are drawn with color. Bits that are 0 in the pattern are drawn with the inverse of color.

See also:
drawBitmap(), clear(), invert()

Definition at line 775 of file Bitmap.cpp.

const prog_uint8_t * Bitmap::font ( ) const [inline]

Returns the currently selected font, or null if none selected.

See also:
setFont(), drawText(), drawChar(), charWidth()

Definition at line 70 of file Bitmap.h.

int Bitmap::height ( ) const [inline]

Returns the height of the bitmap in pixels.

See also:
width(), bitsPerPixel()

Definition at line 47 of file Bitmap.h.

void Bitmap::invert ( int  x,
int  y,
int  width,
int  height 
)

Inverts the width x height pixels starting at top-left corner (x, y).

See also:
fill()

Definition at line 892 of file Bitmap.cpp.

bool Bitmap::isValid ( ) const [inline]

Returns true if the memory for this bitmap is valid; false otherwise.

This function can be called just after the constructor to determine if the memory for the bitmap was allocated successfully.

Definition at line 38 of file Bitmap.h.

Bitmap::Color Bitmap::pixel ( int  x,
int  y 
) const

Returns the color of the pixel at (x, y); either Black or White.

Returns Black if x or y is out of range.

See also:
setPixel(), data()

Definition at line 181 of file Bitmap.cpp.

void Bitmap::scroll ( int  dx,
int  dy,
Color  fillColor = Black 
) [inline]

Scrolls the entire contents of the bitmap by dx and dy.

If dx is 2 and dy is -1, then the region will be scrolled two pixels to the right and one pixel up. Pixels that are uncovered by the scroll are filled with fillColor.

See also:
copy(), fill()

Definition at line 133 of file Bitmap.h.

void Bitmap::scroll ( int  x,
int  y,
int  width,
int  height,
int  dx,
int  dy,
Color  fillColor = Black 
)

Scrolls the width x height pixels starting at top-left corner (x, y) by dx and dy.

If dx is 2 and dy is -1, then the region will be scrolled two pixels to the right and one pixel up. Pixels that are uncovered by the scroll are filled with fillColor.

See also:
copy(), fill()

Definition at line 831 of file Bitmap.cpp.

void Bitmap::setFont ( const prog_uint8_t *  font) [inline]

Sets the font for use with drawText() and drawChar().

 #include <DejaVuSans9.h>

 display.setFont(DejaVuSans9);
 display.drawText(0, 0, "Hello");

New fonts can be generated with GLCDFontCreator2.

See also:
font(), drawText(), drawChar()

Definition at line 71 of file Bitmap.h.

void Bitmap::setPixel ( int  x,
int  y,
Color  color 
)

Sets the pixel at (x, y) to color.

See also:
pixel()

Definition at line 198 of file Bitmap.cpp.

void Bitmap::setTextColor ( Color  textColor) [inline]

Sets the color that will be used for drawing text with drawText() and drawChar().

See also:
textColor(), drawText(), drawChar()

Definition at line 74 of file Bitmap.h.

int Bitmap::stride ( ) const [inline]

Returns the number of bytes in each line of the bitmap's data() buffer.

See also:
width(), bitsPerPixel(), data()

Definition at line 48 of file Bitmap.h.

Color Bitmap::textColor ( ) const [inline]

Returns the color that will be used for drawing text with drawText() and drawChar(). The default is White.

See also:
setTextColor(), drawText(), drawChar()

Definition at line 73 of file Bitmap.h.

int Bitmap::textHeight ( ) const

Returns the height in pixels of the current text drawing font(); or zero if font() is not set.

See also:
font(), charWidth(), textWidth()

Definition at line 706 of file Bitmap.cpp.

int Bitmap::textWidth ( const char *  str,
int  len = -1 
) const

Returns the width in pixels of the len characters of str in the current font(), including inter-character spacing.

If len is less than zero, then the actual length of str will be used.

See also:
drawText(), charWidth(), textHeight()

Definition at line 665 of file Bitmap.cpp.

int Bitmap::textWidth ( const String &  str,
int  start = 0,
int  len = -1 
) const

Returns the width in pixels of the len characters of str in the current font(), starting at start, including inter-character spacing.

If len is less than zero, then the actual length of str will be used.

See also:
drawText(), charWidth(), textHeight()

Definition at line 687 of file Bitmap.cpp.

int Bitmap::width ( ) const [inline]

Returns the width of the bitmap in pixels.

See also:
height(), stride(), bitsPerPixel()

Definition at line 46 of file Bitmap.h.


Member Data Documentation

Bitmap::White = 1 [static]

Color value corresponding to "white". If the bitmap is displayed on a LED array, then it may have a different physical color.

Note: while the value of this constant is 1, the bitmap itself stores white pixels as 0 and black as 1 because the DMD display uses 1 to indicate a pixel being off.

Definition at line 43 of file Bitmap.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator