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

Allow spritesheets for PenRGB565 #959

Merged
merged 1 commit into from
Oct 25, 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
3 changes: 3 additions & 0 deletions libraries/pico_graphics/pico_graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ namespace pimoroni {
int create_pen_hsv(float h, float s, float v) override;
void set_pixel(const Point &p) override;
void set_pixel_span(const Point &p, uint l) override;

void sprite(void* data, const Point &sprite, const Point &dest, const int scale, const int transparent) override;

static size_t buffer_size(uint w, uint h) {
return w * h * sizeof(RGB565);
}
Expand Down
25 changes: 24 additions & 1 deletion libraries/pico_graphics/pico_graphics_pen_rgb565.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,27 @@ namespace pimoroni {
*buf++ = color;
}
}
}


void PicoGraphics_PenRGB565::sprite(void* data, const Point &sprite, const Point &dest, const int scale, const int transparent) {
//int sprite_x = (sprite & 0x0f) << 3;
//int sprite_y = (sprite & 0xf0) >> 1;
Point s {
sprite.x << 3,
sprite.y << 3
};
RGB565 *ptr = (RGB565 *)data;
Point o = {0, 0};
for(o.y = 0; o.y < 8 * scale; o.y++) {
Point so = {
0,
o.y / scale
};
for(o.x = 0; o.x < 8 * scale; o.x++) {
so.x = o.x / scale;
color = ptr[(s.y + so.y) * 128 + (s.x + so.x)];
if(color != transparent) pixel(dest + o);
}
}
}
}
2 changes: 2 additions & 0 deletions micropython/modules/picographics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ Sprites must be 8x8 pixels arranged in a 128x128 pixel spritesheet. 1-bit transp

We've prepared some RGB332-compatible sprite assets for you, but you can use `spritesheet-to-rgb332.py <filename>` to convert your own.

For higher quality you can use RGB565 Spritesheets on some devices, like the Tufty2040, but try using a lower spritesheet resolution of up to 128x96 pixels to not exceed device memory.

#### Loading Sprites

You'll need to include the [pen_type](#supported-graphics-modes-pen-type) in the import statement, and define the pen_type before using loading the spritesheet:
Expand Down