Skip to content

Commit 5a92a9c

Browse files
committed
PNGDEC: Support for 2bpp indexed PNGs, fix open_RAM.
1 parent c443f8d commit 5a92a9c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

micropython/modules/pngdec/pngdec.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int32_t pngdec_seek_callback(PNGFILE *png, int32_t p) {
9696
void pngdec_open_helper(_PNG_obj_t *self) {
9797
int result = -1;
9898

99-
if(mp_obj_is_str_or_bytes(self->file)){
99+
if(mp_obj_is_str(self->file)){
100100
GET_STR_DATA_LEN(self->file, str, str_len);
101101

102102
result = self->png->open(
@@ -188,10 +188,16 @@ MICROPY_EVENT_POLL_HOOK
188188
uint8_t i = 0;
189189
if(pDraw->iBpp == 8) {
190190
i = *pixel++;
191-
} else {
192-
i = pixel[x / 2];
191+
} else if (pDraw->iBpp == 4) {
192+
i = *pixel;
193193
i >>= (x & 0b1) ? 0 : 4;
194194
i &= 0xf;
195+
if (x & 1) pixel++;
196+
} else {
197+
i = *pixel;
198+
i >>= 6 - ((x & 0b11) << 1);
199+
i &= 0x3;
200+
if ((x & 0b11) == 0b11) pixel++;
195201
}
196202
if(x < target->source.x || x >= target->source.x + target->source.w) continue;
197203
// grab the colour from the palette

0 commit comments

Comments
 (0)