Inky 5.7: Dithered drawing ported from 7.3.

pull/685/head
Phil Howard 2023-02-23 13:57:30 +00:00
rodzic a5b0633469
commit bff2e79a56
2 zmienionych plików z 33 dodań i 15 usunięć

Wyświetl plik

@ -334,7 +334,7 @@ namespace pimoroni {
class PicoGraphics_Pen3Bit : public PicoGraphics {
public:
static const uint16_t palette_size = 8;
uint8_t color;
uint color;
RGB palette[8] = {
/*
{0x2b, 0x2a, 0x37},
@ -365,10 +365,13 @@ namespace pimoroni {
void set_pen(uint c) override;
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
void set_thickness(uint t) override {};
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
int create_pen_hsv(float h, float s, float v) override;
int get_palette_size() override {return palette_size;};
RGB* get_palette() override {return palette;};
void _set_pixel(const Point &p, uint col);
void set_pixel(const Point &p) override;
void set_pixel_span(const Point &p, uint l) override;
void get_dither_candidates(const RGB &col, const RGB *palette, size_t len, std::array<uint8_t, 16> &candidates);

Wyświetl plik

@ -10,12 +10,7 @@ namespace pimoroni {
}
cache_built = false;
}
void PicoGraphics_Pen3Bit::set_pen(uint c) {
color = c & 0xf;
}
void PicoGraphics_Pen3Bit::set_pen(uint8_t r, uint8_t g, uint8_t b) {
}
void PicoGraphics_Pen3Bit::set_pixel(const Point &p) {
void PicoGraphics_Pen3Bit::_set_pixel(const Point &p, uint col) {
uint offset = (bounds.w * bounds.h) / 8;
uint8_t *buf = (uint8_t *)frame_buffer;
@ -25,27 +20,48 @@ namespace pimoroni {
uint8_t *bufB = bufA + offset;
uint8_t *bufC = bufA + offset + offset;
uint8_t cA = (color & 0b100) >> 2;
uint8_t cA = (col & 0b100) >> 2;
*bufA &= ~(1U << bo);
*bufA |= (cA << bo);
uint8_t cB = (color & 0b010) >> 1;
uint8_t cB = (col & 0b010) >> 1;
*bufB &= ~(1U << bo);
*bufB |= (cB << bo);
uint8_t cC = (color & 0b001);
uint8_t cC = (col & 0b001);
*bufC &= ~(1U << bo);
*bufC |= (cC << bo);
}
void PicoGraphics_Pen3Bit::set_pen(uint c) {
color = c;
}
void PicoGraphics_Pen3Bit::set_pen(uint8_t r, uint8_t g, uint8_t b) {
color = RGB(r, g, b).to_rgb888() | 0x7f000000;
}
int PicoGraphics_Pen3Bit::create_pen(uint8_t r, uint8_t g, uint8_t b) {
return RGB(r, g, b).to_rgb888() | 0x7f000000;
}
int PicoGraphics_Pen3Bit::create_pen_hsv(float h, float s, float v) {
return RGB::from_hsv(h, s, v).to_rgb888() | 0x7f000000;
}
void PicoGraphics_Pen3Bit::set_pixel(const Point &p) {
if ((color & 0x7f000000) == 0x7f000000) {
set_pixel_dither(p, RGB(color));
} else {
_set_pixel(p, color);
}
}
void PicoGraphics_Pen3Bit::set_pixel_span(const Point &p, uint l) {
Point lp = p;
while(l--) {
set_pixel(lp);
if ((color & 0x7f000000) == 0x7f000000) {
set_pixel_dither(lp, RGB(color));
} else {
_set_pixel(lp, color);
}
lp.x++;
}
}
void PicoGraphics_Pen3Bit::get_dither_candidates(const RGB &col, const RGB *palette, size_t len, std::array<uint8_t, 16> &candidates) {
RGB error;
for(size_t i = 0; i < candidates.size(); i++) {
@ -87,8 +103,7 @@ namespace pimoroni {
// set the pixel
//color = candidates[pattern[pattern_index]];
color = candidate_cache[cache_key][dither16_pattern[pattern_index]];
set_pixel(p);
_set_pixel(p, candidate_cache[cache_key][dither16_pattern[pattern_index]]);
}
void PicoGraphics_Pen3Bit::frame_convert(PenType type, conversion_callback_func callback) {
if(type == PEN_P4) {