A question about libwebp building for ESP32C3

131 views
Skip to first unread message

↕成功

unread,
Dec 9, 2025, 4:59:51 AMDec 9
to webp-d...@webmproject.org
Hi, 
  I am writing for a question about building libwebp for my project on platform of esp32 c3. My project need decoding webp image on esp32 c3. Though there are guide on building about unix and windows platform.  However, nothing can be found about esp32 c3.  Any suggestions is appreciated!

Best Wishes!
Yong Xu

Vincent Rabaud

unread,
Dec 9, 2025, 5:43:44 AMDec 9
to webp-d...@webmproject.org
libwebp is mainly using CMake as a meta build system, so just follow tutorials on how to use an esp32 c3 toolchain with CMake and you should be good to go. E.g. on windows: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/windows-setup.html, or Linux: https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/get-started/linux-macos-setup.html . Then replace their hello-world example with libwebp

--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webp-discuss...@webmproject.org.
To view this discussion visit https://groups.google.com/a/webmproject.org/d/msgid/webp-discuss/31ffb0c0.7fe8.19b027b446b.Coremail.zqxyus%40126.com.

Xu Yong

unread,
Dec 20, 2025, 5:48:29 AM (10 days ago) Dec 20
to WebP Discussion, ↕成功
Thanks for your reply. I have solved the building problem.  When i load full webp file in the buffer, the out of memory error happened. Therefore, i have to use  the incremental decoding of animated webp file for ESP32.  First, i use webpinfo -diag -summary ".\test3.webp" to get the information about the web file as followings (for simplicity, only to show a part of the results)
File: D:\test3.webp
RIFF HEADER:
  File size: 122422
Chunk VP8X at offset     12, length     18
  ICCP: 0
  Alpha: 1
  EXIF: 1
  XMP: 0
  Animation: 1
  Canvas size 240 x 240
Chunk ANIM at offset     30, length     14
  Background color:(ARGB) ff ff ff ff
  Loop count      : 0
Chunk ANMF at offset     44, length   7736
  Offset_X: 0
  Offset_Y: 0
  Width: 240
  Height: 240
  Duration: 40
  Dispose: 0
  Blend: 1
Chunk VP8  at offset     68, length   7712
  Width: 240
  Height: 240
  Alpha: 0
  Animation: 0
  Format: Lossy (1)
Chunk ANMF at offset   7780, length   8260
  Offset_X: 48
  Offset_Y: 44
  Width: 145
  Height: 151
  Duration: 40
  Dispose: 0
  Blend: 0
Chunk ALPH at offset   7804, length     60
---------------------------------------------------------------------------------
According to the frame information, I just want to decode the first frame for demo. The first frame 's VP8 offset is 68, and get the VP8 payload, then, we feed the payload into  WebPINewDecoder, however, when  calling rgba=WebPIDecGetRGB(idec, &last_y, &w, &h, &stride),  the value of rgba is always Null. how to debug the problem.  The following is my demo code and the results of running the code.


  1. const char* path="/littlefs/GIF/test3.webp";
  2. FILE* fp = fopen(path, "rb");
  3.     if (!fp) {
  4.         perror("Failed to open file");
  5.         return ;
  6.     }
  7.     // 1. skip WebP file header (RIFF Header)
  8.     // webp format: 'RIFF' (4 bytes) + Size (4 bytes) + 'WEBP' (4 bytes)
  9. uint32_t riff_tag = read_le32(fp);
  10. uint32_t file_size = read_le32(fp);
  11. uint32_t webp_tag = read_le32(fp);
  12. if (riff_tag != 0x46464952 || webp_tag != 0x50424557) { // "RIFF" and "WEBP"
  13.         printf("Not a valid WebP file.\n");
  14.         fclose(fp);
  15. return ;
  16. }
  17. uint8_t head[4];
  18. fseek(fp, 68, SEEK_SET);
  19. fread(head, 1, 4, fp);
  20. ESP_LOGI("WEBP", "HEAD = %02X %02X %02X %02X", head[0], head[1], head[2], head[3]);
  21. fseek(fp, 68+8, SEEK_SET);
  22. fread(head, 1, 4, fp);
  23. ESP_LOGI("WEBP", "HEAD = %02X %02X %02X %02X", head[0], head[1], head[2], head[3]);
  24. fseek(fp, 68+8, SEEK_SET);
  25. size_t remain1 = 7704;
  26. uint8_t vp8_buf[2048];
  27. WebPDecBuffer output_buffer;
  28. output_buffer.is_external_memory=0;
  29. WebPInitDecBuffer(&output_buffer);
  30. WebPIDecoder* idec = WebPINewDecoder(&output_buffer);
  31. if (!idec) {
  32.         ESP_LOGE("WEBP", "WebPIDecoder initialization failed!");
  33.         return ;
  34.     }
  35. int last_y;
  36. while (remain1 > 0) {
  37.     size_t to_read = remain1 > sizeof(vp8_buf) ? sizeof(vp8_buf) : remain1;
  38.     fread(vp8_buf, 1, to_read, fp);
  39.     remain1 -= to_read;
  40. VP8StatusCode status = WebPIAppend(idec, vp8_buf, to_read);
  41. printf("Status1: %d, \n", status);
  42.         if (status < VP8_STATUS_OK) {
  43.             ESP_LOGE("WEBP", "Error during WebPIAppend: %d", status);
  44.             break;
  45.         }
  46.         int w, h, stride;
  47.         uint8_t* rgba;
  48.         rgba = WebPIDecGetRGB(idec, &last_y, &w, &h, &stride);
  49. printf("Is rgba equals null: %d\n",rgba==NULL);
  50. printf("last_y : %d\n",last_y);
  51. }
The following is result of running the above code (line 49 is to check the return decoded rbga ):
I (3592) WEBP: HEAD = 56 50 38 20
I (3592) WEBP: HEAD = 70 5A 00 9D
Status1: 1,
Is rgba equals null: 1
last_y : 0
Status1: 3,
Is rgba equals null: 1
last_y : 0
Status1: 3,
Is rgba equals null: 1
last_y : 0
Status1: 3,
Is rgba equals null: 1
last_y : 0

Thanks in advance.

Vincent Rabaud

unread,
Dec 22, 2025, 10:09:34 AM (8 days ago) Dec 22
to webp-d...@webmproject.org, ↕成功

--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webp-discuss...@webmproject.org.

Vincent Rabaud

unread,
Dec 24, 2025, 9:06:39 AM (6 days ago) Dec 24
to Xu Yong, WebP Discussion, ↕成功
WebPDemuxPartial allows you to partially decode frames but you always need the beginning of the buffer. What you want is something like the incremental decoder to only decode a few lines at a time: https://chromium.googlesource.com/webm/libwebp/+/refs/tags/v1.6.0/src/webp/decode.h#247 We do not have an incremental API for animations yet.

Do you have a way to mount your file system as RAM ? That might be easier. Something like mmap:

// 1. Open the file
int fd = open(filepath, O_RDONLY);
if (fd == -1) return; // Handle error

// 2. Get file size
struct stat sb;
if (fstat(fd, &sb) == -1) { close(fd); return; }
size_t length = sb.st_size;

// 3. Map the file into memory
// PROT_READ: We only intend to read
// MAP_PRIVATE: Changes (if any) are not written back to disk
const uint8_t* data_ptr = (const uint8_t*)mmap(NULL, length, PROT_READ, MAP_PRIVATE, fd, 0);
if (data_ptr == MAP_FAILED) { close(fd); return; } 

And have your webp_data point to data_ptr with length 

On Tue, Dec 23, 2025 at 12:33 PM Xu Yong <zqx...@gmail.com> wrote:
Thanks for your reply.  According to your recommendation, i  use the following code to decode an animated webp file. Specifically, i first load the the whole file into a WebP_Data structure,  then create an    WebPAnimDecoderNew object pointer dec. However, returned value of dec equals Null. I have checked the error happened because the memory size is
not enough .My esp32's  total memory size is 321296 bytes. What is more,  the webp file's size is about 200k.  Therefore, can i extract frame data one by one for decoding,  and render the decoded data to LCD?
// Code Example:

/*


  1. WebPAnimDecoderOptions dec_options;

  2. WebPAnimDecoderOptionsInit(&dec_options);

  3. // Tune 'dec_options' as needed.

  4. WebPAnimDecoder* dec = WebPAnimDecoderNew(webp_data, &dec_options);

  5. WebPAnimInfo anim_info;

  6. WebPAnimDecoderGetInfo(dec, &anim_info);

  7. for (uint32_t i = 0; i < anim_info.loop_count; ++i) {

  8. while (WebPAnimDecoderHasMoreFrames(dec)) {

  9. uint8_t* buf;

  10. int timestamp;

  11. WebPAnimDecoderGetNext(dec, &buf, &timestamp);

  12. // ... (Render 'buf' based on 'timestamp').

  13. // ... (Do NOT free 'buf', as it is owned by 'dec').

  14. }

  15. WebPAnimDecoderReset(dec);

  16. }

  17. const WebPDemuxer* demuxer = WebPAnimDecoderGetDemuxer(dec);

  18. // ... (Do something using 'demuxer'; e.g. get EXIF/XMP/ICC data).

  19. WebPAnimDecoderDelete(dec);

  20. */

Xu Yong

unread,
Dec 25, 2025, 12:19:19 AM (5 days ago) Dec 25
to WebP Discussion, Vincent Rabaud, ↕成功
Thanks for your reply.  According to your recommendation, i  use the following code to decode an animated webp file. Specifically, i first load the the whole file into a WebP_Data structure,  then create an    WebPAnimDecoderNew object pointer dec. However, returned value of dec equals Null. I have checked the error happened because the memory size is
not enough .My esp32's  total memory size is 321296 bytes. What is more,  the webp file's size is about 200k.  Therefore, can i extract frame data one by one for decoding,  and render the decoded data to LCD?
// Code Example:

/*


  1. WebPAnimDecoderOptions dec_options;

  2. WebPAnimDecoderOptionsInit(&dec_options);

  3. // Tune 'dec_options' as needed.

  4. WebPAnimDecoder* dec = WebPAnimDecoderNew(webp_data, &dec_options);

  5. WebPAnimInfo anim_info;

  6. WebPAnimDecoderGetInfo(dec, &anim_info);

  7. for (uint32_t i = 0; i < anim_info.loop_count; ++i) {

  8. while (WebPAnimDecoderHasMoreFrames(dec)) {

  9. uint8_t* buf;

  10. int timestamp;

  11. WebPAnimDecoderGetNext(dec, &buf, &timestamp);

  12. // ... (Render 'buf' based on 'timestamp').

  13. // ... (Do NOT free 'buf', as it is owned by 'dec').

  14. }

  15. WebPAnimDecoderReset(dec);

  16. }

  17. const WebPDemuxer* demuxer = WebPAnimDecoderGetDemuxer(dec);

  18. // ... (Do something using 'demuxer'; e.g. get EXIF/XMP/ICC data).

  19. WebPAnimDecoderDelete(dec);

  20. */
在2025年12月22日星期一 UTC+8 23:09:34<Vincent Rabaud> 写道:
Reply all
Reply to author
Forward
0 new messages