From 5a92a9c73505a8cb8fa3320a1605379e8892a05c Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Mon, 4 Sep 2023 13:55:15 +0100 Subject: [PATCH] PNGDEC: Support for 2bpp indexed PNGs, fix open_RAM. --- micropython/modules/pngdec/pngdec.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/micropython/modules/pngdec/pngdec.cpp b/micropython/modules/pngdec/pngdec.cpp index 90a34f3d..735c9ba8 100644 --- a/micropython/modules/pngdec/pngdec.cpp +++ b/micropython/modules/pngdec/pngdec.cpp @@ -96,7 +96,7 @@ int32_t pngdec_seek_callback(PNGFILE *png, int32_t p) { void pngdec_open_helper(_PNG_obj_t *self) { int result = -1; - if(mp_obj_is_str_or_bytes(self->file)){ + if(mp_obj_is_str(self->file)){ GET_STR_DATA_LEN(self->file, str, str_len); result = self->png->open( @@ -188,10 +188,16 @@ MICROPY_EVENT_POLL_HOOK uint8_t i = 0; if(pDraw->iBpp == 8) { i = *pixel++; - } else { - i = pixel[x / 2]; + } else if (pDraw->iBpp == 4) { + i = *pixel; i >>= (x & 0b1) ? 0 : 4; i &= 0xf; + if (x & 1) pixel++; + } else { + i = *pixel; + i >>= 6 - ((x & 0b11) << 1); + i &= 0x3; + if ((x & 0b11) == 0b11) pixel++; } if(x < target->source.x || x >= target->source.x + target->source.w) continue; // grab the colour from the palette