ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
Bitmap Class Reference

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

#include <Bitmap.h>

Inheritance diagram for Bitmap:
DMD

Public Types

typedef uint8_t Color
 Type that represents the color of a pixel in a bitmap. More...
 
typedef PGM_VOID_P ProgMem
 Type that represents a bitmap within program memory.
 
typedef PGM_VOID_P Font
 Type that represents a font within program memory.
 

Public Member Functions

 Bitmap (int width, int height)
 Constructs a new in-memory bitmap that is width x height pixels in size. More...
 
 ~Bitmap ()
 Destroys this bitmap.
 
bool isValid () const
 Returns true if the memory for this bitmap is valid; false otherwise. More...
 
int width () const
 Returns the width of the bitmap in pixels. More...
 
int height () const
 Returns the height of the bitmap in pixels. More...
 
int stride () const
 Returns the number of bytes in each line of the bitmap's data() buffer. More...
 
int bitsPerPixel () const
 Returns the number of bits per pixel for the bitmap; always 1. More...
 
uint8_t * data ()
 Returns a pointer to the start of the bitmap's data buffer. More...
 
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. More...
 
Color pixel (int x, int y) const
 Returns the color of the pixel at (x, y); either Black or White. More...
 
void setPixel (int x, int y, Color color)
 Sets the pixel at (x, y) to color. More...
 
void drawLine (int x1, int y1, int x2, int y2, Color color=White)
 Draws a line from (x1, y1) to (x2, y2) in color. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void drawBitmap (int x, int y, const Bitmap &bitmap, Color color=White)
 Draws bitmap at (x, y) in color. More...
 
void drawBitmap (int x, int y, Bitmap::ProgMem bitmap, Color color=White)
 Draws bitmap at (x, y) in color. More...
 
void drawInvertedBitmap (int x, int y, const Bitmap &bitmap)
 Draws bitmap at (x, y) in inverted colors. More...
 
void drawInvertedBitmap (int x, int y, Bitmap::ProgMem bitmap)
 Draws bitmap at (x, y) in inverted colors. More...
 
Font font () const
 Returns the currently selected font, or null if none selected. More...
 
void setFont (Font font)
 Sets the font for use with drawText() and drawChar(). More...
 
Color textColor () const
 Returns the color that will be used for drawing text with drawText() and drawChar(). The default is White. More...
 
void setTextColor (Color color)
 Sets the color that will be used for drawing text with drawText() and drawChar(). More...
 
void drawText (int x, int y, const char *str, int len=-1)
 Draws the len characters of str at (x, y). More...
 
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). More...
 
int drawChar (int x, int y, char ch)
 Draws a single character ch at (x, y). More...
 
int charWidth (char ch) const
 Returns the width in pixels of ch in the current font(). More...
 
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. More...
 
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. More...
 
int textHeight () const
 Returns the height in pixels of the current text drawing font(); or zero if font() is not set. More...
 
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. More...
 
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. More...
 
void fill (int x, int y, int width, int height, Bitmap::ProgMem pattern, Color color=White)
 Fills the width x height pixels starting at top-left corner (x, y) with the contents of pattern. More...
 
void scroll (int dx, int dy, Color fillColor=Black)
 Scrolls the entire contents of the bitmap by dx and dy. More...
 
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. More...
 
void invert (int x, int y, int width, int height)
 Inverts the width x height pixels starting at top-left corner (x, y). More...
 

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. More...
 
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 88 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 51 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 650 of file Bitmap.cpp.

void Bitmap::clear ( Color  color = Black)

Clears the entire bitmap to the specified color.

See Also
fill()

Definition at line 174 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 738 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 53 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 388 of file Bitmap.cpp.

void Bitmap::drawBitmap ( int  x,
int  y,
Bitmap::ProgMem  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 425 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 585 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 334 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 120 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 115 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 125 of file Bitmap.h.

void Bitmap::drawInvertedBitmap ( int  x,
int  y,
Bitmap::ProgMem  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 130 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 225 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 286 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 526 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 555 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 762 of file Bitmap.cpp.

void Bitmap::fill ( int  x,
int  y,
int  width,
int  height,
Bitmap::ProgMem  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 785 of file Bitmap.cpp.

Font Bitmap::font ( ) const
inline

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

See Also
setFont(), drawText(), drawChar(), charWidth()

Definition at line 72 of file Bitmap.h.

int Bitmap::height ( ) const
inline

Returns the height of the bitmap in pixels.

See Also
width(), bitsPerPixel()

Definition at line 49 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 902 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 191 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 135 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 841 of file Bitmap.cpp.

void Bitmap::setFont ( Font  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 73 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 208 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 76 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 50 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 75 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 716 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 675 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 697 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 48 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 45 of file Bitmap.h.


The documentation for this class was generated from the following files: