LED matrix library for http://goo.gl/y6VnO6
Revision 1:b528f8e32726, committed 2014-02-18
- Comitter:
- Yihui Xiong
- Date:
- Tue Feb 18 10:51:13 2014 +0800
- Parent:
- 0:13728deac7a7
- Commit message:
- bug fix
Changed in this revision
LEDMatrix.cpp | Show annotated file Show diff for this revision Revisions of this file |
LEDMatrix.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 13728deac7a7 -r b528f8e32726 LEDMatrix.cpp --- a/LEDMatrix.cpp Fri Nov 08 06:45:52 2013 +0000 +++ b/LEDMatrix.cpp Tue Feb 18 10:51:13 2014 +0800 @@ -60,8 +60,8 @@ ASSERT(width > x); ASSERT(height > y); - uint8_t *byte = displaybuf + x * 8 + y / 8; - uint8_t bit = y % 8; + uint8_t *byte = displaybuf + x / 8 + y * width / 8; + uint8_t bit = x % 8; if (pixel) { *byte |= 0x80 >> bit; @@ -79,17 +79,15 @@ } } -void LEDMatrix::drawImage(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t *image) +void LEDMatrix::drawImage(uint16_t xoffset, uint16_t yoffset, uint16_t width, uint16_t height, const uint8_t *image) { - ASSERT(0 == ((x2 - x1) % 8)); - - for (uint16_t x = x1; x < x2; x++) { - for (uint16_t y = y1; y < y2; y++) { - uint8_t *byte = image + x * 8 + y / 8; - uint8_t bit = 7 - (y % 8); + for (uint16_t y = 0; y < height; y++) { + for (uint16_t x = 0; x < width; x++) { + const uint8_t *byte = image + (x + y * width) / 8; + uint8_t bit = 7 - x % 8; uint8_t pixel = (*byte >> bit) & 1; - drawPoint(x, y, pixel); + drawPoint(x + xoffset, y + yoffset, pixel); } } } @@ -124,7 +122,7 @@ uint8_t *head = displaybuf + row * (width / 8); for (uint8_t line = 0; line < (height / 16); line++) { uint8_t *ptr = head; - head += line * width * 2; + head += width * 2; // width * 16 / 8 for (uint8_t byte = 0; byte < (width / 8); byte++) { uint8_t pixels = *ptr;
diff -r 13728deac7a7 -r b528f8e32726 LEDMatrix.h --- a/LEDMatrix.h Fri Nov 08 06:45:52 2013 +0000 +++ b/LEDMatrix.h Tue Feb 18 10:51:13 2014 +0800 @@ -53,11 +53,11 @@ /** * draw a image - * @param (x1, y1) top-left position - * @param (x2, y2) bottom-right position, not included in the rect + * @param (xoffset, yoffset) top-left offset of image + * @param (width, height) image's width and height * @param pixels contents, 1 bit to 1 led */ - void drawImage(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t *image); + void drawImage(uint16_t xoffset, uint16_t yoffset, uint16_t width, uint16_t height, const uint8_t *image); /** * Set screen buffer to zero