Skip to content

Commit 6d6a1e2

Browse files
committed
Allow spritesheets for PenRGB565
1 parent 3b03a30 commit 6d6a1e2

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

libraries/pico_graphics/pico_graphics.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,9 @@ namespace pimoroni {
510510
int create_pen_hsv(float h, float s, float v) override;
511511
void set_pixel(const Point &p) override;
512512
void set_pixel_span(const Point &p, uint l) override;
513+
514+
void sprite(void* data, const Point &sprite, const Point &dest, const int scale, const int transparent) override;
515+
513516
static size_t buffer_size(uint w, uint h) {
514517
return w * h * sizeof(RGB565);
515518
}

libraries/pico_graphics/pico_graphics_pen_rgb565.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,27 @@ namespace pimoroni {
3434
*buf++ = color;
3535
}
3636
}
37-
}
37+
38+
39+
void PicoGraphics_PenRGB565::sprite(void* data, const Point &sprite, const Point &dest, const int scale, const int transparent) {
40+
//int sprite_x = (sprite & 0x0f) << 3;
41+
//int sprite_y = (sprite & 0xf0) >> 1;
42+
Point s {
43+
sprite.x << 3,
44+
sprite.y << 3
45+
};
46+
RGB565 *ptr = (RGB565 *)data;
47+
Point o = {0, 0};
48+
for(o.y = 0; o.y < 8 * scale; o.y++) {
49+
Point so = {
50+
0,
51+
o.y / scale
52+
};
53+
for(o.x = 0; o.x < 8 * scale; o.x++) {
54+
so.x = o.x / scale;
55+
color = ptr[(s.y + so.y) * 128 + (s.x + so.x)];
56+
if(color != transparent) pixel(dest + o);
57+
}
58+
}
59+
}
60+
}

micropython/modules/picographics/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ Sprites must be 8x8 pixels arranged in a 128x128 pixel spritesheet. 1-bit transp
510510

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

513+
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.
514+
513515
#### Loading Sprites
514516

515517
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:

0 commit comments

Comments
 (0)