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.
- const char* path="/littlefs/GIF/test3.webp";
- FILE* fp = fopen(path, "rb");
- if (!fp) {
- perror("Failed to open file");
- return ;
- }
- // 1. skip WebP file header (RIFF Header)
- // webp format: 'RIFF' (4 bytes) + Size (4 bytes) + 'WEBP' (4 bytes)
- uint32_t riff_tag = read_le32(fp);
- uint32_t file_size = read_le32(fp);
- uint32_t webp_tag = read_le32(fp);
- if (riff_tag != 0x46464952 || webp_tag != 0x50424557) { // "RIFF" and "WEBP"
- printf("Not a valid WebP file.\n");
- fclose(fp);
- return ;
- }
- uint8_t head[4];
- fseek(fp, 68, SEEK_SET);
- fread(head, 1, 4, fp);
- ESP_LOGI("WEBP", "HEAD = %02X %02X %02X %02X", head[0], head[1], head[2], head[3]);
- fseek(fp, 68+8, SEEK_SET);
- fread(head, 1, 4, fp);
- ESP_LOGI("WEBP", "HEAD = %02X %02X %02X %02X", head[0], head[1], head[2], head[3]);
- fseek(fp, 68+8, SEEK_SET);
- size_t remain1 = 7704;
- uint8_t vp8_buf[2048];
- WebPDecBuffer output_buffer;
- output_buffer.is_external_memory=0;
- WebPInitDecBuffer(&output_buffer);
- WebPIDecoder* idec = WebPINewDecoder(&output_buffer);
- if (!idec) {
- ESP_LOGE("WEBP", "WebPIDecoder initialization failed!");
- return ;
- }
- int last_y;
- while (remain1 > 0) {
- size_t to_read = remain1 > sizeof(vp8_buf) ? sizeof(vp8_buf) : remain1;
- fread(vp8_buf, 1, to_read, fp);
- remain1 -= to_read;
- VP8StatusCode status = WebPIAppend(idec, vp8_buf, to_read);
- printf("Status1: %d, \n", status);
- if (status < VP8_STATUS_OK) {
- ESP_LOGE("WEBP", "Error during WebPIAppend: %d", status);
- break;
- }
- int w, h, stride;
- uint8_t* rgba;
- rgba = WebPIDecGetRGB(idec, &last_y, &w, &h, &stride);
- printf("Is rgba equals null: %d\n",rgba==NULL);
- printf("last_y : %d\n",last_y);
- }
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.