Skip to content

Commit d831074

Browse files
authored
Merge pull request #907 from pimoroni/patch-pngdec-1bit
Fixes for PNGDEC on Badger 2040 / Badger 2040 W
2 parents ab64fca + c4f70df commit d831074

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

libraries/pico_graphics/pico_graphics_pen_1bitY.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace pimoroni {
1515
}
1616

1717
void PicoGraphics_Pen1BitY::set_pen(uint8_t r, uint8_t g, uint8_t b) {
18-
color = std::max(r, std::max(g, b));
18+
color = std::max(r, std::max(g, b)) >> 4;
1919
}
2020

2121
void PicoGraphics_Pen1BitY::set_pixel(const Point &p) {

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)