-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixelbuffer.cpp
More file actions
59 lines (48 loc) · 1.24 KB
/
Copy pathpixelbuffer.cpp
File metadata and controls
59 lines (48 loc) · 1.24 KB
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
#include <Arduino.h>
#include "pixelbuffer.h"
byte pixels[rows*(columns/8)] = {};
static byte* pixelptr = (byte*) pixels;
static byte pixelmask = 0x80;
inline byte makeindex(int row, int column) __attribute__((always_inline));
inline byte makemask(int column) __attribute__((always_inline));
static inline byte makeindex(int row, int column) {
return row*(columns/8)+column/8;
}
static inline byte makemask(int column) {
return 0x80>>(column&7);
}
void setpixel(int row, int column, bool state) {
if (row<0 || column<0 || row>=rows || column>=columns) return;
byte index = makeindex(row, column);
byte mask = makemask(column);
if (state)
pixels[index] |= mask;
else
pixels[index] &= ~mask;
}
void clearpixels() {
for(int row=0; row<rows; row++) {
for (byte column = 0; column < columns-8; column++) {
setpixel(row, column, false);
}
}
}
void seekpixel(int row = 0, int column = 0) {
pixelptr = (byte*)pixels+makeindex(row, column);
pixelmask = makemask(column);
}
void nextpixel() {
pixelmask >>= 1;
if(!pixelmask) {
pixelmask = 0x80;
++pixelptr;
}
}
void skippixel(int count) {
while(count--) nextpixel();
}
bool readpixel() {
bool isset = *pixelptr & pixelmask;
nextpixel();
return isset;
}