2022-07-26 03:55:32 +00:00
|
|
|
#include "pico_graphics.hpp"
|
|
|
|
|
|
|
|
namespace pimoroni {
|
2024-10-07 13:36:06 +00:00
|
|
|
PicoGraphics_PenRGB888::PicoGraphics_PenRGB888(uint16_t width, uint16_t height, void *frame_buffer, uint16_t layers)
|
|
|
|
: PicoGraphics(width, height, layers, frame_buffer) {
|
2022-07-26 03:55:32 +00:00
|
|
|
this->pen_type = PEN_RGB888;
|
|
|
|
if(this->frame_buffer == nullptr) {
|
|
|
|
this->frame_buffer = (void *)(new uint8_t[buffer_size(width, height)]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void PicoGraphics_PenRGB888::set_pen(uint c) {
|
2022-08-01 16:07:38 +00:00
|
|
|
color = c;
|
2022-07-26 03:55:32 +00:00
|
|
|
}
|
|
|
|
void PicoGraphics_PenRGB888::set_pen(uint8_t r, uint8_t g, uint8_t b) {
|
2022-08-01 16:07:38 +00:00
|
|
|
src_color = {r, g, b};
|
|
|
|
color = src_color.to_rgb888();
|
2022-07-26 03:55:32 +00:00
|
|
|
}
|
|
|
|
int PicoGraphics_PenRGB888::create_pen(uint8_t r, uint8_t g, uint8_t b) {
|
|
|
|
return RGB(r, g, b).to_rgb888();
|
|
|
|
}
|
2023-02-09 16:13:37 +00:00
|
|
|
int PicoGraphics_PenRGB888::create_pen_hsv(float h, float s, float v) {
|
2023-02-23 12:43:49 +00:00
|
|
|
return RGB::from_hsv(h, s, v).to_rgb888();
|
2023-02-09 16:13:37 +00:00
|
|
|
}
|
2022-07-26 03:55:32 +00:00
|
|
|
void PicoGraphics_PenRGB888::set_pixel(const Point &p) {
|
|
|
|
uint32_t *buf = (uint32_t *)frame_buffer;
|
2024-10-07 14:51:02 +00:00
|
|
|
buf += this->layer_offset;
|
2022-07-26 03:55:32 +00:00
|
|
|
buf[p.y * bounds.w + p.x] = color;
|
|
|
|
}
|
|
|
|
void PicoGraphics_PenRGB888::set_pixel_span(const Point &p, uint l) {
|
|
|
|
// pointer to byte in framebuffer that contains this pixel
|
|
|
|
uint32_t *buf = (uint32_t *)frame_buffer;
|
2024-10-07 14:51:02 +00:00
|
|
|
buf += this->layer_offset;
|
2022-07-26 03:55:32 +00:00
|
|
|
buf = &buf[p.y * bounds.w + p.x];
|
|
|
|
|
|
|
|
while(l--) {
|
|
|
|
*buf++ = color;
|
|
|
|
}
|
|
|
|
}
|
2024-07-22 14:32:33 +00:00
|
|
|
bool PicoGraphics_PenRGB888::render_tile(const Tile *tile) {
|
|
|
|
for(int y = 0; y < tile->h; y++) {
|
|
|
|
uint8_t *palpha = &tile->data[(y * tile->stride)];
|
|
|
|
uint32_t *pdest = &((uint32_t *)frame_buffer)[tile->x + ((tile->y + y) * bounds.w)];
|
|
|
|
for(int x = 0; x < tile->w; x++) {
|
|
|
|
uint8_t alpha = *palpha;
|
|
|
|
|
|
|
|
// TODO: Alpha blending
|
|
|
|
if(alpha == 0) {
|
|
|
|
} else {
|
|
|
|
*pdest = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdest++;
|
|
|
|
palpha++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-07-26 03:55:32 +00:00
|
|
|
}
|