Skip to content

Commit

Permalink
PicoGraphics: Add layer support to PicoVector tile renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Oct 8, 2024
1 parent 5a8b946 commit 2d556d1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
21 changes: 15 additions & 6 deletions libraries/pico_graphics/pico_graphics_pen_rgb332.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace pimoroni {
// Treat our void* frame_buffer as uint8_t
uint8_t *src = (uint8_t *)frame_buffer;

if(this->layers > 1) {
if(this->layers > 1) {
// The size of a single layer
uint offset = this->bounds.w * this->bounds.h;

Expand Down Expand Up @@ -148,14 +148,23 @@ namespace pimoroni {
bool PicoGraphics_PenRGB332::render_tile(const Tile *tile) {
for(int y = 0; y < tile->h; y++) {
uint8_t *palpha = &tile->data[(y * tile->stride)];
uint8_t *pdest = &((uint8_t *)frame_buffer)[tile->x + ((tile->y + y) * bounds.w)];

uint8_t *p_dest = &((uint8_t *)frame_buffer)[tile->x + ((tile->y + y) * bounds.w)];
p_dest += this->layer_offset;

uint8_t *p_layer0 = &((uint8_t *)frame_buffer)[tile->x + ((tile->y + y) * bounds.w)];


for(int x = 0; x < tile->w; x++) {
uint8_t alpha = *palpha;
uint8_t dest = *pdest;
uint8_t dest = *p_dest;
if(dest == 0) {
dest = *p_layer0;
}

// TODO: Try to alpha blend RGB332... somewhat?
if(alpha == 255) {
*pdest = color;
*p_dest = color;
}else if(alpha == 0) {
}else{
// blend tha pixel
Expand All @@ -172,10 +181,10 @@ namespace pimoroni {
uint8_t b = ((sb * alpha) + (db * (255 - alpha))) >> 8;

// recombine the channels
*pdest = (r << 5) | (g << 2) | (b);
*p_dest = (r << 5) | (g << 2) | (b);
}

pdest++;
p_dest++;
palpha++;
}
}
Expand Down
26 changes: 18 additions & 8 deletions libraries/pico_graphics/pico_graphics_pen_rgb565.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace pimoroni {
if(!bounds.contains(p)) return;

uint16_t *buf = (uint16_t *)frame_buffer;
buf += this->layer_offset;

RGB565 blended = RGB(buf[p.y * bounds.w + p.x]).blend(RGB(color), a).to_rgb565();

Expand All @@ -72,14 +73,22 @@ namespace pimoroni {

bool PicoGraphics_PenRGB565::render_tile(const Tile *tile) {
for(int y = 0; y < tile->h; y++) {
uint8_t *palpha = &tile->data[(y * tile->stride)];
uint16_t *pdest = &((uint16_t *)frame_buffer)[tile->x + ((tile->y + y) * bounds.w)];
uint8_t *p_alpha = &tile->data[(y * tile->stride)];

uint16_t *p_dest = &((uint16_t *)frame_buffer)[tile->x + ((tile->y + y) * bounds.w)];
p_dest += this->layer_offset;

uint16_t *p_layer0 = &((uint16_t *)frame_buffer)[tile->x + ((tile->y + y) * bounds.w)];

for(int x = 0; x < tile->w; x++) {
uint16_t dest = *pdest;
uint8_t alpha = *palpha;
uint16_t dest = *p_dest;
if(dest == 0) {
dest = *p_layer0;
}
uint8_t alpha = *p_alpha;

if(alpha == 255) {
*pdest = color;
*p_dest = color;
}else if(alpha == 0) {
}else{
// blend tha pixel
Expand All @@ -96,11 +105,12 @@ namespace pimoroni {
uint8_t b = ((sb * alpha) + (db * (255 - alpha))) >> 8;

// recombine the channels
*pdest = __builtin_bswap16((r << 11) | (g << 5) | (b));
*p_dest = __builtin_bswap16((r << 11) | (g << 5) | (b));
}

pdest++;
palpha++;
p_layer0++;
p_dest++;
p_alpha++;
}
}

Expand Down

0 comments on commit 2d556d1

Please sign in to comment.