91 , _stride((width + 7) / 8)
97 unsigned int size = _stride * _height;
98 fb = (uint8_t *)malloc(size);
100 memset(fb, 0xFF, size);
176 unsigned int size = _stride * _height;
178 memset(fb, 0xFF, size);
180 memset(fb, 0x00, size);
193 if (((
unsigned int)x) >= ((
unsigned int)_width) ||
194 ((
unsigned int)y) >= ((
unsigned int)_height))
196 uint8_t *ptr = fb + y * _stride + (x >> 3);
197 if (*ptr & ((uint8_t)0x80) >> (x & 0x07))
210 if (((
unsigned int)x) >= ((
unsigned int)_width) ||
211 ((
unsigned int)y) >= ((
unsigned int)_height))
213 uint8_t *ptr = fb + y * _stride + (x >> 3);
215 *ptr &= ~(((uint8_t)0x80) >> (x & 0x07));
217 *ptr |= (((uint8_t)0x80) >> (x & 0x07));
232 int d, incrE, incrNE;
248 incrNE = 2 * (dy - dx);
263 incrNE = 2 * (dx - dy);
299 if (fillColor == borderColor) {
300 fill(x1, y1, x2 - x1 + 1, y2 - y1 + 1, fillColor);
302 drawLine(x1, y1, x2, y1, borderColor);
304 drawLine(x2, y1 + 1, x2, y2, borderColor);
306 drawLine(x2 - 1, y2, x1, y2, borderColor);
308 drawLine(x1, y2 - 1, x1, y1 + 1, borderColor);
310 fill(x1 + 1, y1 + 1, x2 - x1 - 1, y2 - y1 - 1, fillColor);
345 int deltaSE = 5 - 2 * radius;
346 drawCirclePoints(centerX, centerY, radius, x, y, borderColor, fillColor);
359 drawCirclePoints(centerX, centerY, radius, x, y, borderColor, fillColor);
390 int w = bitmap.
width();
393 Color invColor = !color;
394 for (uint8_t by = 0; by < h; ++by) {
395 const uint8_t *line = bitmap.
data() + by * s;
397 uint8_t value = *line++;
398 for (uint8_t bx = 0; bx < w; ++bx) {
427 uint8_t w = pgm_read_byte(bitmap);
428 uint8_t s = (w + 7) >> 3;
429 uint8_t h = pgm_read_byte(bitmap + 1);
430 Color invColor = !color;
431 for (uint8_t by = 0; by < h; ++by) {
432 const uint8_t *line = ((
const uint8_t *)bitmap) + 2 + by * s;
434 uint8_t value = pgm_read_byte(line);
435 for (uint8_t bx = 0; bx < w; ++bx) {
444 value = pgm_read_byte(line);
509 #define fontIsFixed(font) (pgm_read_byte((font)) == 0 && \
510 pgm_read_byte((font) + 1) == 0)
511 #define fontWidth(font) (pgm_read_byte((font) + 2))
512 #define fontHeight(font) (pgm_read_byte((font) + 3))
513 #define fontFirstChar(font) (pgm_read_byte((font) + 4))
514 #define fontCharCount(font) (pgm_read_byte((font) + 5))
530 uint8_t
height = fontHeight(_font);
536 fill(x, y, 1, height, !_textColor);
559 uint8_t
height = fontHeight(_font);
561 len = str.length() - start;
565 fill(x, y, 1, height, !_textColor);
587 uint8_t
height = fontHeight(_font);
592 fill(x, y, spaceWidth, height, !_textColor);
595 uint8_t first = fontFirstChar(_font);
596 uint8_t count = fontCharCount(_font);
597 uint8_t index = (uint8_t)ch;
598 if (index < first || index >= (first + count))
601 uint8_t heightBytes = (height + 7) >> 3;;
603 const uint8_t *image;
604 if (fontIsFixed(_font)) {
606 width = fontWidth(_font);
607 image = ((
const uint8_t *)_font) + 6 + index * heightBytes *
width;
610 width = pgm_read_byte(_font + 6 + index);
611 image = ((
const uint8_t *)_font) + 6 + count;
612 for (uint8_t temp = 0; temp < index; ++temp) {
615 image += pgm_read_byte(_font + 6 + temp) * heightBytes;
618 if ((x + width) <= 0 || (y + height) <= 0)
620 Color invColor = !_textColor;
621 for (uint8_t cx = 0; cx <
width; ++cx) {
622 for (uint8_t cy = 0; cy < heightBytes; ++cy) {
623 uint8_t value = pgm_read_byte(image + cy * width + cx);
625 if (heightBytes > 1 && cy == (heightBytes - 1))
629 for (uint8_t bit = 0; bit < 8; ++bit) {
630 if ((posn + bit) >= (cy * 8) && (posn + bit) <= height) {
632 setPixel(x + cx, y + posn + bit, _textColor);
634 setPixel(x + cx, y + posn + bit, invColor);
652 uint8_t index = (uint8_t)ch;
655 uint8_t first = fontFirstChar(_font);
656 uint8_t count = fontCharCount(_font);
659 if (index < first || index >= (first + count))
661 if (fontIsFixed(_font))
662 return fontWidth(_font);
664 return pgm_read_byte(_font + 6 + (index - first));
701 len = str.length() - start;
719 return fontHeight(_font);
743 blit(x, y, x + width - 1, y + height - 1, destX, destY);
747 for (
int tempx = 0; tempx <
width; ++tempx)
765 for (
int temp = 0; temp <
width; ++temp)
787 uint8_t w = pgm_read_byte(pattern);
788 uint8_t s = (w + 7) >> 3;
789 uint8_t h = pgm_read_byte(pattern + 1);
792 Color invColor = !color;
793 for (
int tempy = 0; tempy <
height; ++tempy) {
794 const uint8_t *startLine = ((
const uint8_t *)pattern) + 2 + (tempy % h) * s;
795 const uint8_t *line = startLine;
797 uint8_t value = pgm_read_byte(line++);
799 for (
int tempx = 0; tempx <
width; ++tempx) {
801 setPixel(x + tempx, y + tempy, color);
803 setPixel(x + tempx, y + tempy, invColor);
807 value = pgm_read_byte(line++);
813 value = pgm_read_byte(line++);
856 if ((x + width) > _width)
858 if ((y + height) > _height)
859 height = _height - y;
860 if (width <= 0 || height <= 0)
866 blit(x - dx, y - dy, x + width - 1 + dx, y + height - 1 + dy, x, y);
868 blit(x, y - dy, x + width - 1 - dx, y + height - 1 + dy, x + dx, y);
871 blit(x - dx, y, x + width - 1 + dx, y + height - 1 - dy, x, y + dy);
873 blit(x, y, x + width - 1 - dx, y + height - 1 - dy, x + dx, y + dy);
878 fill(x, y + height + dy, width, -dy, fillColor);
880 fill(x + width + dx, y, -dx, height + dy, fillColor);
882 fill(x, y, dx, height + dy, fillColor);
884 fill(x, y, width, -dy, fillColor);
886 fill(x + width + dx, y + dy, -dx, height - dy, fillColor);
888 fill(x, y + dy, dx, height - dy, fillColor);
890 fill(x + width + dx, y, -dx, height, fillColor);
892 fill(x, y, dx, height, fillColor);
905 for (
int tempx = x + width - 1; tempx >= x; --tempx)
912 void Bitmap::blit(
int x1,
int y1,
int x2,
int y2,
int x3,
int y3)
914 if (y3 < y1 || (y1 == y3 && x3 <= x1)) {
915 for (
int tempy = y1; tempy <= y2; ++tempy) {
916 int y = y1 - tempy + y3;
918 for (
int tempx = x1; tempx <= x2; ++tempx)
922 for (
int tempy = y2; tempy >= y1; --tempy) {
923 int y = y1 - tempy + y3;
925 for (
int tempx = x2; tempx >= x1; --tempx)
931 void Bitmap::drawCirclePoints(
int centerX,
int centerY,
int radius,
int x,
int y, Color borderColor, Color fillColor)
934 setPixel(centerX + x, centerY + y, borderColor);
935 setPixel(centerX + y, centerY + x, borderColor);
936 setPixel(centerX + y, centerY - x, borderColor);
937 setPixel(centerX + x, centerY - y, borderColor);
938 setPixel(centerX - x, centerY - y, borderColor);
939 setPixel(centerX - y, centerY - x, borderColor);
940 setPixel(centerX - y, centerY + x, borderColor);
941 setPixel(centerX - x, centerY + y, borderColor);
942 if (fillColor !=
NoFill) {
944 drawLine(centerX - x + 1, centerY + y, centerX + x - 1, centerY + y, fillColor);
945 drawLine(centerX - y + 1, centerY + x, centerX + y - 1, centerY + x, fillColor);
946 drawLine(centerX - x + 1, centerY - y, centerX + x - 1, centerY - y, fillColor);
947 drawLine(centerX - y + 1, centerY - x, centerX + y - 1, centerY - x, fillColor);
948 }
else if (radius == 1) {
949 setPixel(centerX, centerY, fillColor);
953 setPixel(centerX + x, centerY + y, borderColor);
954 setPixel(centerX + y, centerY - x, borderColor);
955 setPixel(centerX - x, centerY - y, borderColor);
956 setPixel(centerX - y, centerY + x, borderColor);
957 if (fillColor !=
NoFill) {
959 drawLine(centerX - x + 1, centerY + y, centerX + x - 1, centerY + y, fillColor);
960 drawLine(centerX - x + 1, centerY - y, centerX + x - 1, centerY - y, fillColor);
961 }
else if (radius == 1) {
962 setPixel(centerX, centerY, fillColor);