Speed optimization for monochrome conversion

This commit is contained in:
Stephan Hadinger 2021-05-30 19:06:23 +02:00
parent 6a85cd8e67
commit 8cdd327bf2
3 changed files with 26 additions and 20 deletions

View File

@ -1075,15 +1075,16 @@ void uDisplay::setAddrWindow_int(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
} }
} }
#define RGB16_TO_MONO 0x8410
#define CNV_B1_OR ((0x10<<11) | (0x20<<5) | 0x10) #define RGB16_SWAP_TO_MONO 0x1084
static inline uint8_t ulv_color_to1(uint16_t color) { // #define CNV_B1_OR ((0x10<<11) | (0x20<<5) | 0x10)
if (color & CNV_B1_OR) { // static inline uint8_t ulv_color_to1(uint16_t color) {
return 1; // if (color & CNV_B1_OR) {
} // return 1;
else { // }
return 0; // else {
} // return 0;
// }
/* /*
// this needs optimization // this needs optimization
if (((color>>11) & 0x10) || ((color>>5) & 0x20) || (color & 0x10)) { if (((color>>11) & 0x10) || ((color>>5) & 0x20) || (color & 0x10)) {
@ -1092,17 +1093,21 @@ static inline uint8_t ulv_color_to1(uint16_t color) {
else { else {
return 0; return 0;
}*/ }*/
} // }
// convert to mono, these are framebuffer based // convert to mono, these are framebuffer based
void uDisplay::pushColorsMono(uint16_t *data, uint16_t len) { void uDisplay::pushColorsMono(uint16_t *data, uint16_t len, bool rgb16_swap) {
// pixel is white if at least one of the 3 components is above 50%
// this is tested with a simple mask, swapped if needed
uint16_t rgb16_to_mono_mask = rgb16_swap ? RGB16_SWAP_TO_MONO : RGB16_TO_MONO;
for (uint32_t y = seta_yp1; y < seta_yp2; y++) { for (uint32_t y = seta_yp1; y < seta_yp2; y++) {
for (uint32_t x = seta_xp1; x < seta_xp2; x++) { for (uint32_t x = seta_xp1; x < seta_xp2; x++) {
uint16_t color = *data++; uint16_t color = *data++;
if (bpp == 1) color = ulv_color_to1(color); if (bpp == 1) color = (color & rgb16_to_mono_mask) ? 1 : 0;
drawPixel(x, y, color); drawPixel(x, y, color); // todo - inline the method to save speed
len--; len--;
if (!len) return; if (!len) return; // failsafe - exist if len (pixel number) is exhausted
} }
} }
} }
@ -1121,8 +1126,8 @@ void uDisplay::pushColors(uint16_t *data, uint16_t len, boolean not_swapped) {
if (not_swapped == false) { if (not_swapped == false) {
// called from LVGL bytes are swapped // called from LVGL bytes are swapped
if (bpp != 16) { if (bpp != 16) {
lvgl_color_swap(data, len); // lvgl_color_swap(data, len); -- no need to swap anymore, we have inverted the mask
pushColorsMono(data, len); pushColorsMono(data, len, true);
return; return;
} }

View File

@ -218,7 +218,7 @@ class uDisplay : public Renderer {
int16_t rotmap_xmax; int16_t rotmap_xmax;
int16_t rotmap_ymin; int16_t rotmap_ymin;
int16_t rotmap_ymax; int16_t rotmap_ymax;
void pushColorsMono(uint16_t *data, uint16_t len); void pushColorsMono(uint16_t *data, uint16_t len, bool rgb16_swap = false);
#ifdef ESP32 #ifdef ESP32
// dma section // dma section
bool DMA_Enabled = false; bool DMA_Enabled = false;

View File

@ -460,11 +460,12 @@ extern "C" {
int lco_tostring(bvm *vm) { int lco_tostring(bvm *vm) {
lv_color_t lv_color = {}; lv_color_t lv_color = {};
be_getmember(vm, 1, ".p"); be_getmember(vm, 1, ".p");
lv_color = lv_color_from_uint32(be_toint(vm, -1)); uint32_t ntv_color = be_toint(vm, -1);
lv_color = lv_color_from_uint32(ntv_color);
uint32_t color = lv_color_to32(lv_color); uint32_t color = lv_color_to32(lv_color);
be_pop(vm, 1); // remove attribute be_pop(vm, 1); // remove attribute
char s[32]; char s[48];
snprintf(s, sizeof(s), "lv_color(0x%x)", color); snprintf(s, sizeof(s), "lv_color(0x%06x - native:0x%04x)", color, ntv_color);
be_pushnstring(vm, s, strlen(s)); /* make escape string from buffer */ be_pushnstring(vm, s, strlen(s)); /* make escape string from buffer */
be_return(vm); be_return(vm);
} }