Skip to content

Prepare image for use with LVGL #4357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
karunt opened this issue Mar 30, 2025 · 1 comment
Open

Prepare image for use with LVGL #4357

karunt opened this issue Mar 30, 2025 · 1 comment
Labels

Comments

@karunt
Copy link

karunt commented Mar 30, 2025

Question about an existing feature

What are you trying to achieve?

Using ESP32-S3 with RGB565 LCD to display image. Currently, image is converted to raw buffer format in node.js server and then sent to ESP32-S3 over http. But when ESP32-S3 tries to display image using LVGL, the program core dumps and reboots. Can't figure our why that's happening. Relevant code shown below.

When you searched for similar issues, what did you find that might be related?

Haven't found any discussion on this topic yet

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question

Node.js code to modify image to .bin file:

try{
            await sharp(sourceFile)
            .extract({left: 0, top: 0, width: 100, height: 100})
            .resize(480, 480)
            .raw()
            .toBuffer()
            .then(data => fs.writeFileSync('cups01.bin', data));
} catch(err) {console.log('error after saving file: ', err)}

ESP code to retrieve converted image into buffer for display by LVGL:

void display_img(uint8_t *img_buffer, int file_size){

    lv_obj_t *img1 = lv_img_create(lv_scr_act());
    lv_img_dsc_t newImg = {
        .header.always_zero = 0,
        .header.w =480,
        .header.h =480,
        .data_size = file_size,
        .header.cf = LV_IMG_CF_TRUE_COLOR,
        .data = (const uint8_t *)img_buffer
    };
    lv_img_set_src(img1, &newImg);
    
    if (lvgl_port_lock(-1)) {
        lvgl_port_unlock();
    }
}

void http_get(char *file){
    
    int cum_data_read = 0;
    int i = 1;
    int resp_length;
    char *output_buffer = (char *)calloc(sizeof(char), MAX_HTTP_OUTPUT_BUFFER);
    char uri[256];
    snprintf(uri, sizeof(uri), "%s://%s:%s/esp?file=%s", httpServer, httpIpAddress, httpPort, file);
    esp_http_client_config_t config = {
        .url = uri
    };
    esp_http_client_handle_t client = esp_http_client_init(&config);
    esp_http_client_set_method(client, HTTP_METHOD_GET);
    esp_err_t err = esp_http_client_open(client, 0);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
    } else {
        int content_length = esp_http_client_fetch_headers(client);
        uint8_t *image_buffer = (uint8_t *)calloc(content_length, sizeof(uint8_t));

            do {
                resp_length = esp_http_client_read_response(client, output_buffer, MAX_HTTP_OUTPUT_BUFFER);
                if (resp_length >= 0) {
                    memcpy(image_buffer + cum_data_read, output_buffer, resp_length);
                    cum_data_read += resp_length;
                } else {
                    ESP_LOGE(TAG, "Failed to read response");
                }
                i++;
            }
            while (cum_data_read < content_length);

            display_img(image_buffer, cum_data_read);
        }
    }
    esp_http_client_close(client);
}   

Please provide sample image(s) that help explain this question

Can't upload .bin file

@lovell
Copy link
Owner

lovell commented Apr 3, 2025

This might be an alpha channel problem (RGB vs RGBA). Perhaps try adding ensureAlpha or removeAlpha depending on your need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants