@@ -10,12 +10,7 @@ namespace pimoroni {
10
10
}
11
11
cache_built = false ;
12
12
}
13
- void PicoGraphics_Pen3Bit::set_pen (uint c) {
14
- color = c & 0xf ;
15
- }
16
- void PicoGraphics_Pen3Bit::set_pen (uint8_t r, uint8_t g, uint8_t b) {
17
- }
18
- void PicoGraphics_Pen3Bit::set_pixel (const Point &p) {
13
+ void PicoGraphics_Pen3Bit::_set_pixel (const Point &p, uint col) {
19
14
uint offset = (bounds.w * bounds.h ) / 8 ;
20
15
uint8_t *buf = (uint8_t *)frame_buffer;
21
16
@@ -25,27 +20,48 @@ namespace pimoroni {
25
20
uint8_t *bufB = bufA + offset;
26
21
uint8_t *bufC = bufA + offset + offset;
27
22
28
- uint8_t cA = (color & 0b100 ) >> 2 ;
23
+ uint8_t cA = (col & 0b100 ) >> 2 ;
29
24
*bufA &= ~(1U << bo);
30
25
*bufA |= (cA << bo);
31
26
32
- uint8_t cB = (color & 0b010 ) >> 1 ;
27
+ uint8_t cB = (col & 0b010 ) >> 1 ;
33
28
*bufB &= ~(1U << bo);
34
29
*bufB |= (cB << bo);
35
30
36
- uint8_t cC = (color & 0b001 );
31
+ uint8_t cC = (col & 0b001 );
37
32
*bufC &= ~(1U << bo);
38
33
*bufC |= (cC << bo);
39
34
}
40
-
35
+ void PicoGraphics_Pen3Bit::set_pen (uint c) {
36
+ color = c;
37
+ }
38
+ void PicoGraphics_Pen3Bit::set_pen (uint8_t r, uint8_t g, uint8_t b) {
39
+ color = RGB (r, g, b).to_rgb888 () | 0x7f000000 ;
40
+ }
41
+ int PicoGraphics_Pen3Bit::create_pen (uint8_t r, uint8_t g, uint8_t b) {
42
+ return RGB (r, g, b).to_rgb888 () | 0x7f000000 ;
43
+ }
44
+ int PicoGraphics_Pen3Bit::create_pen_hsv (float h, float s, float v) {
45
+ return RGB::from_hsv (h, s, v).to_rgb888 () | 0x7f000000 ;
46
+ }
47
+ void PicoGraphics_Pen3Bit::set_pixel (const Point &p) {
48
+ if ((color & 0x7f000000 ) == 0x7f000000 ) {
49
+ set_pixel_dither (p, RGB (color));
50
+ } else {
51
+ _set_pixel (p, color);
52
+ }
53
+ }
41
54
void PicoGraphics_Pen3Bit::set_pixel_span (const Point &p, uint l) {
42
55
Point lp = p;
43
56
while (l--) {
44
- set_pixel (lp);
57
+ if ((color & 0x7f000000 ) == 0x7f000000 ) {
58
+ set_pixel_dither (lp, RGB (color));
59
+ } else {
60
+ _set_pixel (lp, color);
61
+ }
45
62
lp.x ++;
46
63
}
47
64
}
48
-
49
65
void PicoGraphics_Pen3Bit::get_dither_candidates (const RGB &col, const RGB *palette, size_t len, std::array<uint8_t , 16 > &candidates) {
50
66
RGB error;
51
67
for (size_t i = 0 ; i < candidates.size (); i++) {
@@ -87,8 +103,7 @@ namespace pimoroni {
87
103
88
104
// set the pixel
89
105
// color = candidates[pattern[pattern_index]];
90
- color = candidate_cache[cache_key][dither16_pattern[pattern_index]];
91
- set_pixel (p);
106
+ _set_pixel (p, candidate_cache[cache_key][dither16_pattern[pattern_index]]);
92
107
}
93
108
void PicoGraphics_Pen3Bit::frame_convert (PenType type, conversion_callback_func callback) {
94
109
if (type == PEN_P4) {
0 commit comments