From 10221066ddf79a1b9ea9920e295cc821f835bac8 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Tue, 27 Feb 2024 13:26:30 +0000 Subject: [PATCH 1/2] PNGDEC: Support for 1bpp. --- micropython/modules/pngdec/pngdec.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/micropython/modules/pngdec/pngdec.cpp b/micropython/modules/pngdec/pngdec.cpp index 03903219..7c44ba6b 100644 --- a/micropython/modules/pngdec/pngdec.cpp +++ b/micropython/modules/pngdec/pngdec.cpp @@ -186,18 +186,23 @@ mp_event_handle_nowait(); } else if (pDraw->iPixelType == PNG_PIXEL_INDEXED) { for(int x = 0; x < pDraw->iWidth; x++) { uint8_t i = 0; - if(pDraw->iBpp == 8) { + if(pDraw->iBpp == 8) { // 8bpp i = *pixel++; - } else if (pDraw->iBpp == 4) { + } else if (pDraw->iBpp == 4) { // 4bpp i = *pixel; i >>= (x & 0b1) ? 0 : 4; i &= 0xf; if (x & 1) pixel++; - } else { + } else if (pDraw->iBpp == 2) { // 2bpp i = *pixel; i >>= 6 - ((x & 0b11) << 1); i &= 0x3; if ((x & 0b11) == 0b11) pixel++; + } else { // 1bpp + i = *pixel; + i >>= 7 - (x & 0b111); + i &= 0b1; + if ((x & 0b111) == 0b111) pixel++; } if(x < target->source.x || x >= target->source.x + target->source.w) continue; // grab the colour from the palette @@ -243,7 +248,6 @@ mp_event_handle_nowait(); } } } - } else { current_graphics->set_pen(r, g, b); current_graphics->rectangle({current_position.x, current_position.y, scale.x, scale.y}); From c4f70df1cf8909d0c0d0fa4845a23bcdd900e953 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Tue, 27 Feb 2024 13:54:25 +0000 Subject: [PATCH 2/2] Pen1BitY: Correct RGB to dither lookup conversion. --- libraries/pico_graphics/pico_graphics_pen_1bitY.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/pico_graphics/pico_graphics_pen_1bitY.cpp b/libraries/pico_graphics/pico_graphics_pen_1bitY.cpp index ea4afe99..6fc2cb8c 100644 --- a/libraries/pico_graphics/pico_graphics_pen_1bitY.cpp +++ b/libraries/pico_graphics/pico_graphics_pen_1bitY.cpp @@ -15,7 +15,7 @@ namespace pimoroni { } void PicoGraphics_Pen1BitY::set_pen(uint8_t r, uint8_t g, uint8_t b) { - color = std::max(r, std::max(g, b)); + color = std::max(r, std::max(g, b)) >> 4; } void PicoGraphics_Pen1BitY::set_pixel(const Point &p) {