ArduinoLibs
|
Represents a monochrome bitmap within main memory. More...
#include <Bitmap.h>
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 |
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.
Bitmap::Bitmap | ( | int | width, |
int | height | ||
) |
Constructs a new in-memory bitmap that is width x height pixels in size.
Definition at line 88 of file Bitmap.cpp.
|
inline |
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().
Definition at line 650 of file Bitmap.cpp.
Clears the entire bitmap to the specified color.
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.
Definition at line 738 of file Bitmap.cpp.
|
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.
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.
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.
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.
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.
Definition at line 334 of file Bitmap.cpp.
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).
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).
|
inline |
Draws bitmap at (x, y) in inverted colors.
This is a convenience function that is equivalent to drawBitmap(x, y, bitmap, Black).
|
inline |
Draws bitmap at (x, y) in inverted colors.
This is a convenience function that is equivalent to drawBitmap(x, y, bitmap, Black).
Draws a line from (x1, y1) to (x2, y2) in color.
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.
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.
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.
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.
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.
Definition at line 785 of file Bitmap.cpp.
|
inline |
Returns the currently selected font, or null if none selected.
|
inline |
Returns the height of the bitmap in pixels.
void Bitmap::invert | ( | int | x, |
int | y, | ||
int | width, | ||
int | height | ||
) |
Inverts the width x height pixels starting at top-left corner (x, y).
Definition at line 902 of file Bitmap.cpp.
|
inline |
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.
Definition at line 191 of file Bitmap.cpp.
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.
Definition at line 841 of file Bitmap.cpp.
|
inline |
Sets the font for use with drawText() and drawChar().
New fonts can be generated with GLCDFontCreator2.
void Bitmap::setPixel | ( | int | x, |
int | y, | ||
Color | color | ||
) |
|
inline |
Sets the color that will be used for drawing text with drawText() and drawChar().
|
inline |
|
inline |
Returns the color that will be used for drawing text with drawText() and drawChar(). The default is White.
int Bitmap::textHeight | ( | ) | const |
Returns the height in pixels of the current text drawing font(); or zero if font() is not set.
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.
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.
Definition at line 697 of file Bitmap.cpp.
|
inline |
Returns the width of the bitmap in pixels.
|
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.