esp32displaytest/lib/ExtendedScreen/ExtendedScreen.cpp
2022-03-12 12:33:52 +01:00

58 lines
2.2 KiB
C++

#include "ExtendedScreen.h"
#include <algorithm>
#include <cstdint>
void
ExtendedScreen::drawTransparentBitmap(int16_t x, int16_t y, const bitmap_t& bitmap, const RGB& foreground, const RGB& background) {
_screen->startWrite();
for (int16_t j = 0; j < bitmap.height; j++, y++) {
for (int16_t i = 0; i < bitmap.width; i++) {
uint8_t alpha = bitmap.data[j*bitmap.width+i]; // todo: allow for less than 8 bit per pixel
uint16_t blended_color = foreground.alpha_blend_over_to565(background, alpha);
_screen->writePixel(x + i, y, blended_color);
}
}
_screen->endWrite();
}
void
ExtendedScreen::drawTransparentBitmap(int16_t x, int16_t y, const bitmap_t& bitmap, const RGB& foreground, const RGB& background, const rect_t& rect) {
auto background565 = background.to_565();
_screen->startWrite();
int16_t max_image_width = std::min(static_cast<int16_t>(rect.x + rect.width), static_cast<int16_t>(bitmap.width));
int16_t max_image_height = std::min(static_cast<int16_t>(rect.y + rect.height), static_cast<int16_t>(bitmap.height));
int16_t j = rect.y;
for(; j < 0; j++) {
for (int16_t i = rect.x; i < rect.x + rect.width; i++) {
_screen->writePixel(x + i - rect.x, y + j - rect.y, background565);
}
}
for (; j < max_image_height; j++) {
int16_t i = rect.x;
for (; i < 0; i++) {
_screen->writePixel(x + i - rect.x, y + j - rect.y, background565);
}
for (; i < max_image_width; i++) {
uint8_t alpha = bitmap.data[j*bitmap.width+i]; // todo: allow for less than 8 bit per pixel
uint16_t blended_color = foreground.alpha_blend_over_to565(background, alpha);
_screen->writePixel(x + i - rect.x, y + j - rect.y, blended_color);
}
for (; i < rect.x + rect.width; i++) {
_screen->writePixel(x + i - rect.x, y + j - rect.y, background565);
}
}
for(; j < rect.y + rect.height; j++) {
for (int16_t i = rect.x; i < rect.x + rect.width; i++) {
_screen->writePixel(x + i - rect.x, y + j - rect.y, background565);
}
}
_screen->endWrite();
}