Skip to content

Commit

Permalink
PNGDEC: Support for 2bpp indexed PNGs, fix open_RAM.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Sep 4, 2023
1 parent c443f8d commit 5a92a9c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions micropython/modules/pngdec/pngdec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5a92a9c

Please sign in to comment.