Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for PNGDEC on Badger 2040 / Badger 2040 W #907

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/pico_graphics/pico_graphics_pen_1bitY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace pimoroni {
}

void PicoGraphics_Pen1BitY::set_pen(uint8_t r, uint8_t g, uint8_t b) {
color = std::max(r, std::max(g, b));
color = std::max(r, std::max(g, b)) >> 4;
}

void PicoGraphics_Pen1BitY::set_pixel(const Point &p) {
Expand Down
12 changes: 8 additions & 4 deletions micropython/modules/pngdec/pngdec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,23 @@ mp_event_handle_nowait();
} else if (pDraw->iPixelType == PNG_PIXEL_INDEXED) {
for(int x = 0; x < pDraw->iWidth; x++) {
uint8_t i = 0;
if(pDraw->iBpp == 8) {
if(pDraw->iBpp == 8) { // 8bpp
i = *pixel++;
} else if (pDraw->iBpp == 4) {
} else if (pDraw->iBpp == 4) { // 4bpp
i = *pixel;
i >>= (x & 0b1) ? 0 : 4;
i &= 0xf;
if (x & 1) pixel++;
} else {
} else if (pDraw->iBpp == 2) { // 2bpp
i = *pixel;
i >>= 6 - ((x & 0b11) << 1);
i &= 0x3;
if ((x & 0b11) == 0b11) pixel++;
} else { // 1bpp
i = *pixel;
i >>= 7 - (x & 0b111);
i &= 0b1;
if ((x & 0b111) == 0b111) pixel++;
}
if(x < target->source.x || x >= target->source.x + target->source.w) continue;
// grab the colour from the palette
Expand Down Expand Up @@ -243,7 +248,6 @@ mp_event_handle_nowait();
}
}
}

} else {
current_graphics->set_pen(r, g, b);
current_graphics->rectangle({current_position.x, current_position.y, scale.x, scale.y});
Expand Down
Loading