fix(color): slow scrolling on model select page (#5184)
This commit is contained in:
+13
-18
@@ -498,13 +498,15 @@ coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char *s,
|
||||
|
||||
// Resize and convert to LVGL image data format with alpha blending to
|
||||
// background color
|
||||
void BitmapBuffer::resizeToLVGL(coord_t w, coord_t h, LcdFlags bgColor)
|
||||
void BitmapBuffer::resizeToLVGL(coord_t w, coord_t h)
|
||||
{
|
||||
// Scale values from ARGB4444 to RGB565
|
||||
// Scale values from ARGB4444 to RGB565 with alpha
|
||||
static uint8_t rbcnv[16] = {0, 2, 4, 6, 8, 10, 12, 14,
|
||||
17, 19, 21, 23, 25, 27, 29, 31};
|
||||
static uint8_t gcnv[16] = {0, 4, 8, 13, 17, 21, 25, 29,
|
||||
34, 38, 42, 46, 50, 55, 59, 63};
|
||||
static uint8_t alpha[16] = {0, 17, 34, 51, 68, 85, 102, 119,
|
||||
136, 153, 170, 187, 204, 221, 238, 255};
|
||||
|
||||
float vscale = float(h) / (float)height();
|
||||
float hscale = float(w) / (float)width();
|
||||
@@ -520,33 +522,26 @@ void BitmapBuffer::resizeToLVGL(coord_t w, coord_t h, LcdFlags bgColor)
|
||||
scaledh = height() * scale;
|
||||
}
|
||||
|
||||
pixel_t *ndata =
|
||||
(pixel_t *)malloc(align32(scaledw * scaledh * sizeof(pixel_t)));
|
||||
uint8_t *ndata =
|
||||
(uint8_t *)malloc(align32(scaledw * scaledh * 3));
|
||||
|
||||
if (ndata) {
|
||||
RGB_SPLIT(COLOR_VAL(bgColor), bgRed, bgGreen, bgBlue);
|
||||
uint8_t *dst = ndata;
|
||||
for (int i = 0; i < scaledh; i += 1) {
|
||||
pixel_t *dst = &ndata[i * scaledw];
|
||||
pixel_t *src = &data[(coord_t)(i / scale) * width()];
|
||||
for (int j = 0; j < scaledw; j += 1) {
|
||||
ARGB_SPLIT(src[(coord_t)(j / scale)], a, r, g, b);
|
||||
r = rbcnv[r];
|
||||
g = gcnv[g];
|
||||
b = rbcnv[b];
|
||||
if (a != OPACITY_MAX) {
|
||||
uint8_t bgWeight = OPACITY_MAX - a;
|
||||
r = (bgRed * bgWeight + r * a) / OPACITY_MAX;
|
||||
g = (bgGreen * bgWeight + g * a) / OPACITY_MAX;
|
||||
b = (bgBlue * bgWeight + b * a) / OPACITY_MAX;
|
||||
}
|
||||
*dst++ = RGB_JOIN(r, g, b);
|
||||
auto c = RGB_JOIN(rbcnv[r], gcnv[g], rbcnv[b]);
|
||||
*dst++ = c & 0xFF;
|
||||
*dst++ = c >> 8;
|
||||
*dst++ = alpha[a];
|
||||
}
|
||||
}
|
||||
|
||||
delete data;
|
||||
data = ndata;
|
||||
data = (pixel_t*)ndata;
|
||||
_width = scaledw;
|
||||
_height = scaledh;
|
||||
data_end = data + (scaledw * scaledh);
|
||||
data_end = data + ((scaledw * scaledh * 3 + 1) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -140,7 +140,7 @@ class BitmapBuffer
|
||||
static BitmapBuffer* loadBitmap(const char* filename,
|
||||
BitmapFormats fmt = BMP_INVALID);
|
||||
|
||||
void resizeToLVGL(coord_t w, coord_t h, LcdFlags bgColor);
|
||||
void resizeToLVGL(coord_t w, coord_t h);
|
||||
|
||||
uint8_t* to8bitMask(size_t* size) const;
|
||||
|
||||
|
||||
+1
-10
@@ -95,8 +95,6 @@ const stbi_io_callbacks stbCallbacks = {stbc_read, stbc_skip, stbc_eof};
|
||||
|
||||
BitmapBuffer *BitmapBuffer::loadBitmap(const char *filename, BitmapFormats fmt)
|
||||
{
|
||||
// TRACE(" BitmapBuffer::load_stb(%s)", filename);
|
||||
|
||||
FRESULT result = f_open(&imgFile, filename, FA_OPEN_EXISTING | FA_READ);
|
||||
if (result != FR_OK) {
|
||||
return nullptr;
|
||||
@@ -104,14 +102,7 @@ BitmapBuffer *BitmapBuffer::loadBitmap(const char *filename, BitmapFormats fmt)
|
||||
|
||||
int x, y, nn;
|
||||
stbi_info_from_callbacks(&stbCallbacks, &imgFile, &x, &y, &nn);
|
||||
f_close(&imgFile);
|
||||
// TRACE(" BitmapBuffer::load_stb()----Info File %s, %d, %d, %d", filename,
|
||||
// x, y, nn);
|
||||
|
||||
result = f_open(&imgFile, filename, FA_OPEN_EXISTING | FA_READ);
|
||||
if (result != FR_OK) {
|
||||
return nullptr;
|
||||
}
|
||||
f_lseek(&imgFile, 0);
|
||||
|
||||
int w, h, n;
|
||||
unsigned char *img =
|
||||
|
||||
+4
-4
@@ -245,8 +245,8 @@ void StaticImage::setZoom()
|
||||
// Display image from file system with software scaling
|
||||
// - uglier but much faster than LVGL scaling
|
||||
StaticBitmap::StaticBitmap(Window* parent, const rect_t& rect,
|
||||
LcdFlags bgColor, const char* filename) :
|
||||
Window(parent, rect), bgColor(bgColor)
|
||||
const char* filename) :
|
||||
Window(parent, rect)
|
||||
{
|
||||
setWindowFlag(NO_FOCUS);
|
||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICKABLE);
|
||||
@@ -260,12 +260,12 @@ void StaticBitmap::setSource(const char *filename)
|
||||
if (img) delete img;
|
||||
img = BitmapBuffer::loadBitmap(filename, BMP_ARGB4444);
|
||||
if (img) {
|
||||
img->resizeToLVGL(width(), height(), bgColor);
|
||||
img->resizeToLVGL(width(), height());
|
||||
if (canvas) lv_obj_del(canvas);
|
||||
canvas = lv_canvas_create(lvobj);
|
||||
lv_obj_center(canvas);
|
||||
lv_canvas_set_buffer(canvas, img->getData(), img->width(), img->height(),
|
||||
LV_IMG_CF_TRUE_COLOR);
|
||||
LV_IMG_CF_TRUE_COLOR_ALPHA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -163,7 +163,7 @@ class StaticBitmap : public Window
|
||||
{
|
||||
public:
|
||||
StaticBitmap(Window *parent, const rect_t &rect,
|
||||
LcdFlags bgColor, const char *filename = nullptr);
|
||||
const char *filename = nullptr);
|
||||
~StaticBitmap();
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
@@ -174,7 +174,6 @@ class StaticBitmap : public Window
|
||||
bool hasImage() const;
|
||||
|
||||
protected:
|
||||
LcdFlags bgColor;
|
||||
lv_obj_t *canvas = nullptr;
|
||||
BitmapBuffer *img = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user