Skip to content

Commit 1022106

Browse files
committed
PNGDEC: Support for 1bpp.
1 parent ab64fca commit 1022106

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

micropython/modules/pngdec/pngdec.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,23 @@ mp_event_handle_nowait();
186186
} else if (pDraw->iPixelType == PNG_PIXEL_INDEXED) {
187187
for(int x = 0; x < pDraw->iWidth; x++) {
188188
uint8_t i = 0;
189-
if(pDraw->iBpp == 8) {
189+
if(pDraw->iBpp == 8) { // 8bpp
190190
i = *pixel++;
191-
} else if (pDraw->iBpp == 4) {
191+
} else if (pDraw->iBpp == 4) { // 4bpp
192192
i = *pixel;
193193
i >>= (x & 0b1) ? 0 : 4;
194194
i &= 0xf;
195195
if (x & 1) pixel++;
196-
} else {
196+
} else if (pDraw->iBpp == 2) { // 2bpp
197197
i = *pixel;
198198
i >>= 6 - ((x & 0b11) << 1);
199199
i &= 0x3;
200200
if ((x & 0b11) == 0b11) pixel++;
201+
} else { // 1bpp
202+
i = *pixel;
203+
i >>= 7 - (x & 0b111);
204+
i &= 0b1;
205+
if ((x & 0b111) == 0b111) pixel++;
201206
}
202207
if(x < target->source.x || x >= target->source.x + target->source.w) continue;
203208
// grab the colour from the palette
@@ -243,7 +248,6 @@ mp_event_handle_nowait();
243248
}
244249
}
245250
}
246-
247251
} else {
248252
current_graphics->set_pen(r, g, b);
249253
current_graphics->rectangle({current_position.x, current_position.y, scale.x, scale.y});

0 commit comments

Comments
 (0)