int ReadAnimatedImage(const char filename[], AnimatedImage* const image, int dump_frames, const char dump_folder[]) { int ok = 0; WebPData webp_data; WebPDataInit(&webp_data); memset(image, 0, sizeof(*image)); if (!ExUtilReadFile(filename, &webp_data.bytes, &webp_data.size)) { fprintf(stderr, "Error reading file: %s\n", filename); return 0; } if (IsWebP(&webp_data)) { ok = ReadAnimatedWebP(filename, &webp_data, image, dump_frames, dump_folder); } else if (IsGIF(&webp_data)) { ok = ReadAnimatedGIF(filename, image, dump_frames, dump_folder); } else { fprintf(stderr, "Unknown file type: %s. Supported file types are WebP and GIF\n", filename); ok = 0; } if (!ok) ClearAnimatedImage(image); WebPDataClear(&webp_data); return ok; }
static int ReadFileToWebPData(const char* const filename, WebPData* const webp_data) { const uint8_t* data; size_t size; if (!ExUtilReadFile(filename, &data, &size)) return 0; webp_data->bytes = data; webp_data->size = size; return 1; }