-
Notifications
You must be signed in to change notification settings - Fork 0
/
LEDBitmap.cpp
62 lines (53 loc) · 1.35 KB
/
LEDBitmap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "LEDBitmap.h"
LEDBitmap::LEDBitmap(uint8_t const width, uint8_t const height) {
_width = width;
if(width == 0) _width = 8;
_height = height;
if(height == 0) _height = 8;
_data = (uint8_t*)malloc(_height*sizeof(uint8_t));
}
LEDBitmap::LEDBitmap(uint8_t width, uint8_t height, int data[]) {
_width = width;
if(width == 0) _width = 8;
_height = height;
if(height == 0) _height = 8;
_data = (uint8_t*)malloc(_height*sizeof(uint8_t));
for (uint8_t h = 0; h < height; h++) {
uint8_t binary = 0x00;
for (uint8_t w = 0; w < width; w++) {
if(data[w + width*h] >= 1)
binary |= _BV(8 - (w+1));
else
binary &= ~_BV(8 - (w+1));
}
_data[h] = binary;
}
}
LEDBitmap::~LEDBitmap(){
free(_data);
}
uint8_t LEDBitmap::getPixelValue(uint8_t x, uint8_t y) {
uint8_t value = _data[y] >> (8 - (x+1));
return (value && 0x01);
}
void LEDBitmap::setPixelValue(uint8_t x, uint8_t y, uint8_t value) {
_data[y] &= ~_BV(8 - (x+1));
if (value >= 1) {
_data[y] |= _BV(8 - (x+1));
}
}
void LEDBitmap::buildFromBytemap(uint8_t map[]) {
for(uint8_t h = 0; h < _height; h++) {
_data[h] = map[h];
}
}
uint8_t* LEDBitmap::getBitmap() {
return _data;
}
void LEDBitmap::clear() {
for (uint8_t h = 0; h < _height; h++) {
for (uint8_t w = 0; w < _width; w++) {
_data[w + _width*h] = 0;
}
}
}