examples,cosmetics: rm struct member '_' suffix

This is a follow up to:
ee8e8c62 Fix member naming for VP8LHistogram

This better matches Google style and clears some clang-tidy warnings.

Change-Id: If6a77a316e36a6d87abaa69692a34374ba6aed4f
This commit is contained in:
James Zern 2025-04-10 15:03:43 -07:00
parent 5225592f6b
commit 295804e4b9
6 changed files with 323 additions and 323 deletions

View File

@ -66,17 +66,17 @@ float ExUtilGetFloat(const char* const v, int* const error) {
static void ResetCommandLineArguments(int argc, const char* argv[], static void ResetCommandLineArguments(int argc, const char* argv[],
CommandLineArguments* const args) { CommandLineArguments* const args) {
assert(args != NULL); assert(args != NULL);
args->argc_ = argc; args->argc = argc;
args->argv_ = argv; args->argv = argv;
args->own_argv_ = 0; args->own_argv = 0;
WebPDataInit(&args->argv_data_); WebPDataInit(&args->argv_data);
} }
void ExUtilDeleteCommandLineArguments(CommandLineArguments* const args) { void ExUtilDeleteCommandLineArguments(CommandLineArguments* const args) {
if (args != NULL) { if (args != NULL) {
if (args->own_argv_) { if (args->own_argv) {
WebPFree((void*)args->argv_); WebPFree((void*)args->argv);
WebPDataClear(&args->argv_data_); WebPDataClear(&args->argv_data);
} }
ResetCommandLineArguments(0, NULL, args); ResetCommandLineArguments(0, NULL, args);
} }
@ -98,18 +98,18 @@ int ExUtilInitCommandLineArguments(int argc, const char* argv[],
return 0; return 0;
#endif #endif
if (!ExUtilReadFileToWebPData(argv[0], &args->argv_data_)) { if (!ExUtilReadFileToWebPData(argv[0], &args->argv_data)) {
return 0; return 0;
} }
args->own_argv_ = 1; args->own_argv = 1;
args->argv_ = (const char**)WebPMalloc(MAX_ARGC * sizeof(*args->argv_)); args->argv = (const char**)WebPMalloc(MAX_ARGC * sizeof(*args->argv));
if (args->argv_ == NULL) { if (args->argv == NULL) {
ExUtilDeleteCommandLineArguments(args); ExUtilDeleteCommandLineArguments(args);
return 0; return 0;
} }
argc = 0; argc = 0;
for (cur = strtok((char*)args->argv_data_.bytes, sep); for (cur = strtok((char*)args->argv_data.bytes, sep);
cur != NULL; cur != NULL;
cur = strtok(NULL, sep)) { cur = strtok(NULL, sep)) {
if (argc == MAX_ARGC) { if (argc == MAX_ARGC) {
@ -118,9 +118,9 @@ int ExUtilInitCommandLineArguments(int argc, const char* argv[],
return 0; return 0;
} }
assert(strlen(cur) != 0); assert(strlen(cur) != 0);
args->argv_[argc++] = cur; args->argv[argc++] = cur;
} }
args->argc_ = argc; args->argc = argc;
} }
return 1; return 1;
} }

View File

@ -45,10 +45,10 @@ int ExUtilReadFileToWebPData(const char* const filename,
// Command-line arguments // Command-line arguments
typedef struct { typedef struct {
int argc_; int argc;
const char** argv_; const char** argv;
WebPData argv_data_; WebPData argv_data;
int own_argv_; int own_argv;
} CommandLineArguments; } CommandLineArguments;
// Initializes the structure from the command-line parameters. If there is // Initializes the structure from the command-line parameters. If there is

View File

@ -160,8 +160,8 @@ int main(int argc, const char* argv[]) {
ok = ExUtilInitCommandLineArguments(argc - 1, argv + 1, &cmd_args); ok = ExUtilInitCommandLineArguments(argc - 1, argv + 1, &cmd_args);
if (!ok) FREE_WARGV_AND_RETURN(EXIT_FAILURE); if (!ok) FREE_WARGV_AND_RETURN(EXIT_FAILURE);
argc = cmd_args.argc_; argc = cmd_args.argc;
argv = cmd_args.argv_; argv = cmd_args.argv;
WebPDataInit(&webp_data); WebPDataInit(&webp_data);
if (!WebPAnimEncoderOptionsInit(&anim_config) || if (!WebPAnimEncoderOptionsInit(&anim_config) ||

View File

@ -32,17 +32,17 @@
#define LOG_ERROR(MESSAGE) \ #define LOG_ERROR(MESSAGE) \
do { \ do { \
if (webp_info->show_diagnosis_) { \ if (webp_info->show_diagnosis) { \
fprintf(stderr, "Error: %s\n", MESSAGE); \ fprintf(stderr, "Error: %s\n", MESSAGE); \
} \ } \
} while (0) } while (0)
#define LOG_WARN(MESSAGE) \ #define LOG_WARN(MESSAGE) \
do { \ do { \
if (webp_info->show_diagnosis_) { \ if (webp_info->show_diagnosis) { \
fprintf(stderr, "Warning: %s\n", MESSAGE); \ fprintf(stderr, "Warning: %s\n", MESSAGE); \
} \ } \
++webp_info->num_warnings_; \ ++webp_info->num_warnings; \
} while (0) } while (0)
static const char* const kFormats[3] = { static const char* const kFormats[3] = {
@ -90,36 +90,36 @@ typedef enum ChunkID {
} ChunkID; } ChunkID;
typedef struct { typedef struct {
size_t start_; size_t start;
size_t end_; size_t end;
const uint8_t* buf_; const uint8_t* buf;
} MemBuffer; } MemBuffer;
typedef struct { typedef struct {
size_t offset_; size_t offset;
size_t size_; size_t size;
const uint8_t* payload_; const uint8_t* payload;
ChunkID id_; ChunkID id;
} ChunkData; } ChunkData;
typedef struct WebPInfo { typedef struct WebPInfo {
int canvas_width_; int canvas_width;
int canvas_height_; int canvas_height;
int loop_count_; int loop_count;
int num_frames_; int num_frames;
int chunk_counts_[CHUNK_TYPES]; int chunk_counts[CHUNK_TYPES];
int anmf_subchunk_counts_[3]; // 0 VP8; 1 VP8L; 2 ALPH. int anmf_subchunk_counts[3]; // 0 VP8; 1 VP8L; 2 ALPH.
uint32_t bgcolor_; uint32_t bgcolor;
int feature_flags_; int feature_flags;
int has_alpha_; int has_alpha;
// Used for parsing ANMF chunks. // Used for parsing ANMF chunks.
int frame_width_, frame_height_; int frame_width, frame_height;
size_t anim_frame_data_size_; size_t anim_frame_data_size;
int is_processing_anim_frame_, seen_alpha_subchunk_, seen_image_subchunk_; int is_processing_anim_frame, seen_alpha_subchunk, seen_image_subchunk;
// Print output control. // Print output control.
int quiet_, show_diagnosis_, show_summary_; int quiet, show_diagnosis, show_summary;
int num_warnings_; int num_warnings;
int parse_bitstream_; int parse_bitstream;
} WebPInfo; } WebPInfo;
static void WebPInfoInit(WebPInfo* const webp_info) { static void WebPInfoInit(WebPInfo* const webp_info) {
@ -185,25 +185,25 @@ static int ReadFileToWebPData(const char* const filename,
// MemBuffer object. // MemBuffer object.
static void InitMemBuffer(MemBuffer* const mem, const WebPData* webp_data) { static void InitMemBuffer(MemBuffer* const mem, const WebPData* webp_data) {
mem->buf_ = webp_data->bytes; mem->buf = webp_data->bytes;
mem->start_ = 0; mem->start = 0;
mem->end_ = webp_data->size; mem->end = webp_data->size;
} }
static size_t MemDataSize(const MemBuffer* const mem) { static size_t MemDataSize(const MemBuffer* const mem) {
return (mem->end_ - mem->start_); return (mem->end - mem->start);
} }
static const uint8_t* GetBuffer(MemBuffer* const mem) { static const uint8_t* GetBuffer(MemBuffer* const mem) {
return mem->buf_ + mem->start_; return mem->buf + mem->start;
} }
static void Skip(MemBuffer* const mem, size_t size) { static void Skip(MemBuffer* const mem, size_t size) {
mem->start_ += size; mem->start += size;
} }
static uint32_t ReadMemBufLE32(MemBuffer* const mem) { static uint32_t ReadMemBufLE32(MemBuffer* const mem) {
const uint8_t* const data = mem->buf_ + mem->start_; const uint8_t* const data = mem->buf + mem->start;
const uint32_t val = GetLE32(data); const uint32_t val = GetLE32(data);
assert(MemDataSize(mem) >= 4); assert(MemDataSize(mem) >= 4);
Skip(mem, 4); Skip(mem, 4);
@ -334,8 +334,8 @@ static WebPInfoStatus ParseLossyFilterHeader(const WebPInfo* const webp_info,
static WebPInfoStatus ParseLossyHeader(const ChunkData* const chunk_data, static WebPInfoStatus ParseLossyHeader(const ChunkData* const chunk_data,
const WebPInfo* const webp_info) { const WebPInfo* const webp_info) {
const uint8_t* data = chunk_data->payload_; const uint8_t* data = chunk_data->payload;
size_t data_size = chunk_data->size_ - CHUNK_HEADER_SIZE; size_t data_size = chunk_data->size - CHUNK_HEADER_SIZE;
const uint32_t bits = (uint32_t)data[0] | (data[1] << 8) | (data[2] << 16); const uint32_t bits = (uint32_t)data[0] | (data[1] << 8) | (data[2] << 16);
const int key_frame = !(bits & 1); const int key_frame = !(bits & 1);
const int profile = (bits >> 1) & 7; const int profile = (bits >> 1) & 7;
@ -347,7 +347,7 @@ static WebPInfoStatus ParseLossyHeader(const ChunkData* const chunk_data,
int colorspace, clamp_type; int colorspace, clamp_type;
printf(" Parsing lossy bitstream...\n"); printf(" Parsing lossy bitstream...\n");
// Calling WebPGetFeatures() in ProcessImageChunk() should ensure this. // Calling WebPGetFeatures() in ProcessImageChunk() should ensure this.
assert(chunk_data->size_ >= CHUNK_HEADER_SIZE + 10); assert(chunk_data->size >= CHUNK_HEADER_SIZE + 10);
if (profile > 3) { if (profile > 3) {
LOG_ERROR("Unknown profile."); LOG_ERROR("Unknown profile.");
return WEBP_INFO_BITSTREAM_ERROR; return WEBP_INFO_BITSTREAM_ERROR;
@ -505,8 +505,8 @@ static WebPInfoStatus ParseLosslessTransform(WebPInfo* const webp_info,
static WebPInfoStatus ParseLosslessHeader(const ChunkData* const chunk_data, static WebPInfoStatus ParseLosslessHeader(const ChunkData* const chunk_data,
WebPInfo* const webp_info) { WebPInfo* const webp_info) {
const uint8_t* data = chunk_data->payload_; const uint8_t* data = chunk_data->payload;
size_t data_size = chunk_data->size_ - CHUNK_HEADER_SIZE; size_t data_size = chunk_data->size - CHUNK_HEADER_SIZE;
uint64_t bit_position = 0; uint64_t bit_position = 0;
uint64_t* const bit_pos = &bit_position; uint64_t* const bit_pos = &bit_position;
WebPInfoStatus status; WebPInfoStatus status;
@ -541,8 +541,8 @@ static WebPInfoStatus ParseLosslessHeader(const ChunkData* const chunk_data,
static WebPInfoStatus ParseAlphaHeader(const ChunkData* const chunk_data, static WebPInfoStatus ParseAlphaHeader(const ChunkData* const chunk_data,
WebPInfo* const webp_info) { WebPInfo* const webp_info) {
const uint8_t* data = chunk_data->payload_; const uint8_t* data = chunk_data->payload;
size_t data_size = chunk_data->size_ - CHUNK_HEADER_SIZE; size_t data_size = chunk_data->size - CHUNK_HEADER_SIZE;
if (data_size <= ALPHA_HEADER_LEN) { if (data_size <= ALPHA_HEADER_LEN) {
LOG_ERROR("Truncated ALPH chunk."); LOG_ERROR("Truncated ALPH chunk.");
return WEBP_INFO_TRUNCATED_DATA; return WEBP_INFO_TRUNCATED_DATA;
@ -607,14 +607,14 @@ static WebPInfoStatus ParseRIFFHeader(WebPInfo* const webp_info,
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
riff_size += CHUNK_HEADER_SIZE; riff_size += CHUNK_HEADER_SIZE;
if (!webp_info->quiet_) { if (!webp_info->quiet) {
printf("RIFF HEADER:\n"); printf("RIFF HEADER:\n");
printf(" File size: %6d\n", (int)riff_size); printf(" File size: %6d\n", (int)riff_size);
} }
if (riff_size < mem->end_) { if (riff_size < mem->end) {
LOG_WARN("RIFF size is smaller than the file size."); LOG_WARN("RIFF size is smaller than the file size.");
mem->end_ = riff_size; mem->end = riff_size;
} else if (riff_size > mem->end_) { } else if (riff_size > mem->end) {
LOG_ERROR("Truncated data detected when parsing RIFF payload."); LOG_ERROR("Truncated data detected when parsing RIFF payload.");
return WEBP_INFO_TRUNCATED_DATA; return WEBP_INFO_TRUNCATED_DATA;
} }
@ -630,7 +630,7 @@ static WebPInfoStatus ParseChunk(const WebPInfo* const webp_info,
LOG_ERROR("Truncated data detected when parsing chunk header."); LOG_ERROR("Truncated data detected when parsing chunk header.");
return WEBP_INFO_TRUNCATED_DATA; return WEBP_INFO_TRUNCATED_DATA;
} else { } else {
const size_t chunk_start_offset = mem->start_; const size_t chunk_start_offset = mem->start;
const uint32_t fourcc = ReadMemBufLE32(mem); const uint32_t fourcc = ReadMemBufLE32(mem);
const uint32_t payload_size = ReadMemBufLE32(mem); const uint32_t payload_size = ReadMemBufLE32(mem);
const uint32_t payload_size_padded = payload_size + (payload_size & 1); const uint32_t payload_size_padded = payload_size + (payload_size & 1);
@ -647,11 +647,11 @@ static WebPInfoStatus ParseChunk(const WebPInfo* const webp_info,
for (i = 0; i < CHUNK_TYPES; ++i) { for (i = 0; i < CHUNK_TYPES; ++i) {
if (kWebPChunkTags[i] == fourcc) break; if (kWebPChunkTags[i] == fourcc) break;
} }
chunk_data->offset_ = chunk_start_offset; chunk_data->offset = chunk_start_offset;
chunk_data->size_ = chunk_size; chunk_data->size = chunk_size;
chunk_data->id_ = (ChunkID)i; chunk_data->id = (ChunkID)i;
chunk_data->payload_ = GetBuffer(mem); chunk_data->payload = GetBuffer(mem);
if (chunk_data->id_ == CHUNK_ANMF) { if (chunk_data->id == CHUNK_ANMF) {
if (payload_size != payload_size_padded) { if (payload_size != payload_size_padded) {
LOG_ERROR("ANMF chunk size should always be even."); LOG_ERROR("ANMF chunk size should always be even.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
@ -670,39 +670,39 @@ static WebPInfoStatus ParseChunk(const WebPInfo* const webp_info,
static WebPInfoStatus ProcessVP8XChunk(const ChunkData* const chunk_data, static WebPInfoStatus ProcessVP8XChunk(const ChunkData* const chunk_data,
WebPInfo* const webp_info) { WebPInfo* const webp_info) {
const uint8_t* data = chunk_data->payload_; const uint8_t* data = chunk_data->payload;
if (webp_info->chunk_counts_[CHUNK_VP8] || if (webp_info->chunk_counts[CHUNK_VP8] ||
webp_info->chunk_counts_[CHUNK_VP8L] || webp_info->chunk_counts[CHUNK_VP8L] ||
webp_info->chunk_counts_[CHUNK_VP8X]) { webp_info->chunk_counts[CHUNK_VP8X]) {
LOG_ERROR("Already seen a VP8/VP8L/VP8X chunk when parsing VP8X chunk."); LOG_ERROR("Already seen a VP8/VP8L/VP8X chunk when parsing VP8X chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (chunk_data->size_ != VP8X_CHUNK_SIZE + CHUNK_HEADER_SIZE) { if (chunk_data->size != VP8X_CHUNK_SIZE + CHUNK_HEADER_SIZE) {
LOG_ERROR("Corrupted VP8X chunk."); LOG_ERROR("Corrupted VP8X chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
++webp_info->chunk_counts_[CHUNK_VP8X]; ++webp_info->chunk_counts[CHUNK_VP8X];
webp_info->feature_flags_ = *data; webp_info->feature_flags = *data;
data += 4; data += 4;
webp_info->canvas_width_ = 1 + ReadLE24(&data); webp_info->canvas_width = 1 + ReadLE24(&data);
webp_info->canvas_height_ = 1 + ReadLE24(&data); webp_info->canvas_height = 1 + ReadLE24(&data);
if (!webp_info->quiet_) { if (!webp_info->quiet) {
printf(" ICCP: %d\n Alpha: %d\n EXIF: %d\n XMP: %d\n Animation: %d\n", printf(" ICCP: %d\n Alpha: %d\n EXIF: %d\n XMP: %d\n Animation: %d\n",
(webp_info->feature_flags_ & ICCP_FLAG) != 0, (webp_info->feature_flags & ICCP_FLAG) != 0,
(webp_info->feature_flags_ & ALPHA_FLAG) != 0, (webp_info->feature_flags & ALPHA_FLAG) != 0,
(webp_info->feature_flags_ & EXIF_FLAG) != 0, (webp_info->feature_flags & EXIF_FLAG) != 0,
(webp_info->feature_flags_ & XMP_FLAG) != 0, (webp_info->feature_flags & XMP_FLAG) != 0,
(webp_info->feature_flags_ & ANIMATION_FLAG) != 0); (webp_info->feature_flags & ANIMATION_FLAG) != 0);
printf(" Canvas size %d x %d\n", printf(" Canvas size %d x %d\n",
webp_info->canvas_width_, webp_info->canvas_height_); webp_info->canvas_width, webp_info->canvas_height);
} }
if (webp_info->canvas_width_ > MAX_CANVAS_SIZE) { if (webp_info->canvas_width > MAX_CANVAS_SIZE) {
LOG_WARN("Canvas width is out of range in VP8X chunk."); LOG_WARN("Canvas width is out of range in VP8X chunk.");
} }
if (webp_info->canvas_height_ > MAX_CANVAS_SIZE) { if (webp_info->canvas_height > MAX_CANVAS_SIZE) {
LOG_WARN("Canvas height is out of range in VP8X chunk."); LOG_WARN("Canvas height is out of range in VP8X chunk.");
} }
if ((uint64_t)webp_info->canvas_width_ * webp_info->canvas_height_ > if ((uint64_t)webp_info->canvas_width * webp_info->canvas_height >
MAX_IMAGE_AREA) { MAX_IMAGE_AREA) {
LOG_WARN("Canvas area is out of range in VP8X chunk."); LOG_WARN("Canvas area is out of range in VP8X chunk.");
} }
@ -711,27 +711,27 @@ static WebPInfoStatus ProcessVP8XChunk(const ChunkData* const chunk_data,
static WebPInfoStatus ProcessANIMChunk(const ChunkData* const chunk_data, static WebPInfoStatus ProcessANIMChunk(const ChunkData* const chunk_data,
WebPInfo* const webp_info) { WebPInfo* const webp_info) {
const uint8_t* data = chunk_data->payload_; const uint8_t* data = chunk_data->payload;
if (!webp_info->chunk_counts_[CHUNK_VP8X]) { if (!webp_info->chunk_counts[CHUNK_VP8X]) {
LOG_ERROR("ANIM chunk detected before VP8X chunk."); LOG_ERROR("ANIM chunk detected before VP8X chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (chunk_data->size_ != ANIM_CHUNK_SIZE + CHUNK_HEADER_SIZE) { if (chunk_data->size != ANIM_CHUNK_SIZE + CHUNK_HEADER_SIZE) {
LOG_ERROR("Corrupted ANIM chunk."); LOG_ERROR("Corrupted ANIM chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
webp_info->bgcolor_ = ReadLE32(&data); webp_info->bgcolor = ReadLE32(&data);
webp_info->loop_count_ = ReadLE16(&data); webp_info->loop_count = ReadLE16(&data);
++webp_info->chunk_counts_[CHUNK_ANIM]; ++webp_info->chunk_counts[CHUNK_ANIM];
if (!webp_info->quiet_) { if (!webp_info->quiet) {
printf(" Background color:(ARGB) %02x %02x %02x %02x\n", printf(" Background color:(ARGB) %02x %02x %02x %02x\n",
(webp_info->bgcolor_ >> 24) & 0xff, (webp_info->bgcolor >> 24) & 0xff,
(webp_info->bgcolor_ >> 16) & 0xff, (webp_info->bgcolor >> 16) & 0xff,
(webp_info->bgcolor_ >> 8) & 0xff, (webp_info->bgcolor >> 8) & 0xff,
webp_info->bgcolor_ & 0xff); webp_info->bgcolor & 0xff);
printf(" Loop count : %d\n", webp_info->loop_count_); printf(" Loop count : %d\n", webp_info->loop_count);
} }
if (webp_info->loop_count_ > MAX_LOOP_COUNT) { if (webp_info->loop_count > MAX_LOOP_COUNT) {
LOG_WARN("Loop count is out of range in ANIM chunk."); LOG_WARN("Loop count is out of range in ANIM chunk.");
} }
return WEBP_INFO_OK; return WEBP_INFO_OK;
@ -739,17 +739,17 @@ static WebPInfoStatus ProcessANIMChunk(const ChunkData* const chunk_data,
static WebPInfoStatus ProcessANMFChunk(const ChunkData* const chunk_data, static WebPInfoStatus ProcessANMFChunk(const ChunkData* const chunk_data,
WebPInfo* const webp_info) { WebPInfo* const webp_info) {
const uint8_t* data = chunk_data->payload_; const uint8_t* data = chunk_data->payload;
int offset_x, offset_y, width, height, duration, blend, dispose, temp; int offset_x, offset_y, width, height, duration, blend, dispose, temp;
if (webp_info->is_processing_anim_frame_) { if (webp_info->is_processing_anim_frame) {
LOG_ERROR("ANMF chunk detected within another ANMF chunk."); LOG_ERROR("ANMF chunk detected within another ANMF chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (!webp_info->chunk_counts_[CHUNK_ANIM]) { if (!webp_info->chunk_counts[CHUNK_ANIM]) {
LOG_ERROR("ANMF chunk detected before ANIM chunk."); LOG_ERROR("ANMF chunk detected before ANIM chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (chunk_data->size_ <= CHUNK_HEADER_SIZE + ANMF_CHUNK_SIZE) { if (chunk_data->size <= CHUNK_HEADER_SIZE + ANMF_CHUNK_SIZE) {
LOG_ERROR("Truncated data detected when parsing ANMF chunk."); LOG_ERROR("Truncated data detected when parsing ANMF chunk.");
return WEBP_INFO_TRUNCATED_DATA; return WEBP_INFO_TRUNCATED_DATA;
} }
@ -761,8 +761,8 @@ static WebPInfoStatus ProcessANMFChunk(const ChunkData* const chunk_data,
temp = *data; temp = *data;
dispose = temp & 1; dispose = temp & 1;
blend = (temp >> 1) & 1; blend = (temp >> 1) & 1;
++webp_info->chunk_counts_[CHUNK_ANMF]; ++webp_info->chunk_counts[CHUNK_ANMF];
if (!webp_info->quiet_) { if (!webp_info->quiet) {
printf(" Offset_X: %d\n Offset_Y: %d\n Width: %d\n Height: %d\n" printf(" Offset_X: %d\n Offset_Y: %d\n Width: %d\n Height: %d\n"
" Duration: %d\n Dispose: %d\n Blend: %d\n", " Duration: %d\n Dispose: %d\n Blend: %d\n",
offset_x, offset_y, width, height, duration, dispose, blend); offset_x, offset_y, width, height, duration, dispose, blend);
@ -775,92 +775,92 @@ static WebPInfoStatus ProcessANMFChunk(const ChunkData* const chunk_data,
LOG_ERROR("Invalid offset parameters in ANMF chunk."); LOG_ERROR("Invalid offset parameters in ANMF chunk.");
return WEBP_INFO_INVALID_PARAM; return WEBP_INFO_INVALID_PARAM;
} }
if ((uint64_t)offset_x + width > (uint64_t)webp_info->canvas_width_ || if ((uint64_t)offset_x + width > (uint64_t)webp_info->canvas_width ||
(uint64_t)offset_y + height > (uint64_t)webp_info->canvas_height_) { (uint64_t)offset_y + height > (uint64_t)webp_info->canvas_height) {
LOG_ERROR("Frame exceeds canvas in ANMF chunk."); LOG_ERROR("Frame exceeds canvas in ANMF chunk.");
return WEBP_INFO_INVALID_PARAM; return WEBP_INFO_INVALID_PARAM;
} }
webp_info->is_processing_anim_frame_ = 1; webp_info->is_processing_anim_frame = 1;
webp_info->seen_alpha_subchunk_ = 0; webp_info->seen_alpha_subchunk = 0;
webp_info->seen_image_subchunk_ = 0; webp_info->seen_image_subchunk = 0;
webp_info->frame_width_ = width; webp_info->frame_width = width;
webp_info->frame_height_ = height; webp_info->frame_height = height;
webp_info->anim_frame_data_size_ = webp_info->anim_frame_data_size =
chunk_data->size_ - CHUNK_HEADER_SIZE - ANMF_CHUNK_SIZE; chunk_data->size - CHUNK_HEADER_SIZE - ANMF_CHUNK_SIZE;
return WEBP_INFO_OK; return WEBP_INFO_OK;
} }
static WebPInfoStatus ProcessImageChunk(const ChunkData* const chunk_data, static WebPInfoStatus ProcessImageChunk(const ChunkData* const chunk_data,
WebPInfo* const webp_info) { WebPInfo* const webp_info) {
const uint8_t* data = chunk_data->payload_ - CHUNK_HEADER_SIZE; const uint8_t* data = chunk_data->payload - CHUNK_HEADER_SIZE;
WebPBitstreamFeatures features; WebPBitstreamFeatures features;
const VP8StatusCode vp8_status = const VP8StatusCode vp8_status =
WebPGetFeatures(data, chunk_data->size_, &features); WebPGetFeatures(data, chunk_data->size, &features);
if (vp8_status != VP8_STATUS_OK) { if (vp8_status != VP8_STATUS_OK) {
LOG_ERROR("VP8/VP8L bitstream error."); LOG_ERROR("VP8/VP8L bitstream error.");
return WEBP_INFO_BITSTREAM_ERROR; return WEBP_INFO_BITSTREAM_ERROR;
} }
if (!webp_info->quiet_) { if (!webp_info->quiet) {
assert(features.format >= 0 && features.format <= 2); assert(features.format >= 0 && features.format <= 2);
printf(" Width: %d\n Height: %d\n Alpha: %d\n Animation: %d\n" printf(" Width: %d\n Height: %d\n Alpha: %d\n Animation: %d\n"
" Format: %s (%d)\n", " Format: %s (%d)\n",
features.width, features.height, features.has_alpha, features.width, features.height, features.has_alpha,
features.has_animation, kFormats[features.format], features.format); features.has_animation, kFormats[features.format], features.format);
} }
if (webp_info->is_processing_anim_frame_) { if (webp_info->is_processing_anim_frame) {
++webp_info->anmf_subchunk_counts_[chunk_data->id_ == CHUNK_VP8 ? 0 : 1]; ++webp_info->anmf_subchunk_counts[chunk_data->id == CHUNK_VP8 ? 0 : 1];
if (chunk_data->id_ == CHUNK_VP8L && webp_info->seen_alpha_subchunk_) { if (chunk_data->id == CHUNK_VP8L && webp_info->seen_alpha_subchunk) {
LOG_ERROR("Both VP8L and ALPH sub-chunks are present in an ANMF chunk."); LOG_ERROR("Both VP8L and ALPH sub-chunks are present in an ANMF chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (webp_info->frame_width_ != features.width || if (webp_info->frame_width != features.width ||
webp_info->frame_height_ != features.height) { webp_info->frame_height != features.height) {
LOG_ERROR("Frame size in VP8/VP8L sub-chunk differs from ANMF header."); LOG_ERROR("Frame size in VP8/VP8L sub-chunk differs from ANMF header.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (webp_info->seen_image_subchunk_) { if (webp_info->seen_image_subchunk) {
LOG_ERROR("Consecutive VP8/VP8L sub-chunks in an ANMF chunk."); LOG_ERROR("Consecutive VP8/VP8L sub-chunks in an ANMF chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
webp_info->seen_image_subchunk_ = 1; webp_info->seen_image_subchunk = 1;
} else { } else {
if (webp_info->chunk_counts_[CHUNK_VP8] || if (webp_info->chunk_counts[CHUNK_VP8] ||
webp_info->chunk_counts_[CHUNK_VP8L]) { webp_info->chunk_counts[CHUNK_VP8L]) {
LOG_ERROR("Multiple VP8/VP8L chunks detected."); LOG_ERROR("Multiple VP8/VP8L chunks detected.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (chunk_data->id_ == CHUNK_VP8L && if (chunk_data->id == CHUNK_VP8L &&
webp_info->chunk_counts_[CHUNK_ALPHA]) { webp_info->chunk_counts[CHUNK_ALPHA]) {
LOG_WARN("Both VP8L and ALPH chunks are detected."); LOG_WARN("Both VP8L and ALPH chunks are detected.");
} }
if (webp_info->chunk_counts_[CHUNK_ANIM] || if (webp_info->chunk_counts[CHUNK_ANIM] ||
webp_info->chunk_counts_[CHUNK_ANMF]) { webp_info->chunk_counts[CHUNK_ANMF]) {
LOG_ERROR("VP8/VP8L chunk and ANIM/ANMF chunk are both detected."); LOG_ERROR("VP8/VP8L chunk and ANIM/ANMF chunk are both detected.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (webp_info->chunk_counts_[CHUNK_VP8X]) { if (webp_info->chunk_counts[CHUNK_VP8X]) {
if (webp_info->canvas_width_ != features.width || if (webp_info->canvas_width != features.width ||
webp_info->canvas_height_ != features.height) { webp_info->canvas_height != features.height) {
LOG_ERROR("Image size in VP8/VP8L chunk differs from VP8X chunk."); LOG_ERROR("Image size in VP8/VP8L chunk differs from VP8X chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
} else { } else {
webp_info->canvas_width_ = features.width; webp_info->canvas_width = features.width;
webp_info->canvas_height_ = features.height; webp_info->canvas_height = features.height;
if (webp_info->canvas_width_ < 1 || webp_info->canvas_height_ < 1 || if (webp_info->canvas_width < 1 || webp_info->canvas_height < 1 ||
webp_info->canvas_width_ > MAX_CANVAS_SIZE || webp_info->canvas_width > MAX_CANVAS_SIZE ||
webp_info->canvas_height_ > MAX_CANVAS_SIZE || webp_info->canvas_height > MAX_CANVAS_SIZE ||
(uint64_t)webp_info->canvas_width_ * webp_info->canvas_height_ > (uint64_t)webp_info->canvas_width * webp_info->canvas_height >
MAX_IMAGE_AREA) { MAX_IMAGE_AREA) {
LOG_WARN("Invalid parameters in VP8/VP8L chunk."); LOG_WARN("Invalid parameters in VP8/VP8L chunk.");
} }
} }
++webp_info->chunk_counts_[chunk_data->id_]; ++webp_info->chunk_counts[chunk_data->id];
} }
++webp_info->num_frames_; ++webp_info->num_frames;
webp_info->has_alpha_ |= features.has_alpha; webp_info->has_alpha |= features.has_alpha;
if (webp_info->parse_bitstream_) { if (webp_info->parse_bitstream) {
const int is_lossy = (chunk_data->id_ == CHUNK_VP8); const int is_lossy = (chunk_data->id == CHUNK_VP8);
const WebPInfoStatus status = const WebPInfoStatus status =
is_lossy ? ParseLossyHeader(chunk_data, webp_info) is_lossy ? ParseLossyHeader(chunk_data, webp_info)
: ParseLosslessHeader(chunk_data, webp_info); : ParseLosslessHeader(chunk_data, webp_info);
@ -871,41 +871,41 @@ static WebPInfoStatus ProcessImageChunk(const ChunkData* const chunk_data,
static WebPInfoStatus ProcessALPHChunk(const ChunkData* const chunk_data, static WebPInfoStatus ProcessALPHChunk(const ChunkData* const chunk_data,
WebPInfo* const webp_info) { WebPInfo* const webp_info) {
if (webp_info->is_processing_anim_frame_) { if (webp_info->is_processing_anim_frame) {
++webp_info->anmf_subchunk_counts_[2]; ++webp_info->anmf_subchunk_counts[2];
if (webp_info->seen_alpha_subchunk_) { if (webp_info->seen_alpha_subchunk) {
LOG_ERROR("Consecutive ALPH sub-chunks in an ANMF chunk."); LOG_ERROR("Consecutive ALPH sub-chunks in an ANMF chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
webp_info->seen_alpha_subchunk_ = 1; webp_info->seen_alpha_subchunk = 1;
if (webp_info->seen_image_subchunk_) { if (webp_info->seen_image_subchunk) {
LOG_ERROR("ALPHA sub-chunk detected after VP8 sub-chunk " LOG_ERROR("ALPHA sub-chunk detected after VP8 sub-chunk "
"in an ANMF chunk."); "in an ANMF chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
} else { } else {
if (webp_info->chunk_counts_[CHUNK_ANIM] || if (webp_info->chunk_counts[CHUNK_ANIM] ||
webp_info->chunk_counts_[CHUNK_ANMF]) { webp_info->chunk_counts[CHUNK_ANMF]) {
LOG_ERROR("ALPHA chunk and ANIM/ANMF chunk are both detected."); LOG_ERROR("ALPHA chunk and ANIM/ANMF chunk are both detected.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (!webp_info->chunk_counts_[CHUNK_VP8X]) { if (!webp_info->chunk_counts[CHUNK_VP8X]) {
LOG_ERROR("ALPHA chunk detected before VP8X chunk."); LOG_ERROR("ALPHA chunk detected before VP8X chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (webp_info->chunk_counts_[CHUNK_VP8]) { if (webp_info->chunk_counts[CHUNK_VP8]) {
LOG_ERROR("ALPHA chunk detected after VP8 chunk."); LOG_ERROR("ALPHA chunk detected after VP8 chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (webp_info->chunk_counts_[CHUNK_ALPHA]) { if (webp_info->chunk_counts[CHUNK_ALPHA]) {
LOG_ERROR("Multiple ALPHA chunks detected."); LOG_ERROR("Multiple ALPHA chunks detected.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
++webp_info->chunk_counts_[CHUNK_ALPHA]; ++webp_info->chunk_counts[CHUNK_ALPHA];
} }
webp_info->has_alpha_ = 1; webp_info->has_alpha = 1;
if (webp_info->parse_bitstream_) { if (webp_info->parse_bitstream) {
const WebPInfoStatus status = ParseAlphaHeader(chunk_data, webp_info); const WebPInfoStatus status = ParseAlphaHeader(chunk_data, webp_info);
if (status != WEBP_INFO_OK) return status; if (status != WEBP_INFO_OK) return status;
} }
@ -915,41 +915,41 @@ static WebPInfoStatus ProcessALPHChunk(const ChunkData* const chunk_data,
static WebPInfoStatus ProcessICCPChunk(const ChunkData* const chunk_data, static WebPInfoStatus ProcessICCPChunk(const ChunkData* const chunk_data,
WebPInfo* const webp_info) { WebPInfo* const webp_info) {
(void)chunk_data; (void)chunk_data;
if (!webp_info->chunk_counts_[CHUNK_VP8X]) { if (!webp_info->chunk_counts[CHUNK_VP8X]) {
LOG_ERROR("ICCP chunk detected before VP8X chunk."); LOG_ERROR("ICCP chunk detected before VP8X chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (webp_info->chunk_counts_[CHUNK_VP8] || if (webp_info->chunk_counts[CHUNK_VP8] ||
webp_info->chunk_counts_[CHUNK_VP8L] || webp_info->chunk_counts[CHUNK_VP8L] ||
webp_info->chunk_counts_[CHUNK_ANIM]) { webp_info->chunk_counts[CHUNK_ANIM]) {
LOG_ERROR("ICCP chunk detected after image data."); LOG_ERROR("ICCP chunk detected after image data.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
++webp_info->chunk_counts_[CHUNK_ICCP]; ++webp_info->chunk_counts[CHUNK_ICCP];
return WEBP_INFO_OK; return WEBP_INFO_OK;
} }
static WebPInfoStatus ProcessChunk(const ChunkData* const chunk_data, static WebPInfoStatus ProcessChunk(const ChunkData* const chunk_data,
WebPInfo* const webp_info) { WebPInfo* const webp_info) {
WebPInfoStatus status = WEBP_INFO_OK; WebPInfoStatus status = WEBP_INFO_OK;
ChunkID id = chunk_data->id_; ChunkID id = chunk_data->id;
if (chunk_data->id_ == CHUNK_UNKNOWN) { if (chunk_data->id == CHUNK_UNKNOWN) {
char error_message[50]; char error_message[50];
snprintf(error_message, 50, "Unknown chunk at offset %6d, length %6d", snprintf(error_message, 50, "Unknown chunk at offset %6d, length %6d",
(int)chunk_data->offset_, (int)chunk_data->size_); (int)chunk_data->offset, (int)chunk_data->size);
LOG_WARN(error_message); LOG_WARN(error_message);
} else { } else {
if (!webp_info->quiet_) { if (!webp_info->quiet) {
char tag[4]; char tag[4];
uint32_t fourcc = kWebPChunkTags[chunk_data->id_]; uint32_t fourcc = kWebPChunkTags[chunk_data->id];
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
fourcc = (fourcc >> 24) | ((fourcc >> 8) & 0xff00) | fourcc = (fourcc >> 24) | ((fourcc >> 8) & 0xff00) |
((fourcc << 8) & 0xff0000) | (fourcc << 24); ((fourcc << 8) & 0xff0000) | (fourcc << 24);
#endif #endif
memcpy(tag, &fourcc, sizeof(tag)); memcpy(tag, &fourcc, sizeof(tag));
printf("Chunk %c%c%c%c at offset %6d, length %6d\n", printf("Chunk %c%c%c%c at offset %6d, length %6d\n",
tag[0], tag[1], tag[2], tag[3], (int)chunk_data->offset_, tag[0], tag[1], tag[2], tag[3], (int)chunk_data->offset,
(int)chunk_data->size_); (int)chunk_data->size);
} }
} }
switch (id) { switch (id) {
@ -974,21 +974,21 @@ static WebPInfoStatus ProcessChunk(const ChunkData* const chunk_data,
break; break;
case CHUNK_EXIF: case CHUNK_EXIF:
case CHUNK_XMP: case CHUNK_XMP:
++webp_info->chunk_counts_[id]; ++webp_info->chunk_counts[id];
break; break;
case CHUNK_UNKNOWN: case CHUNK_UNKNOWN:
default: default:
break; break;
} }
if (webp_info->is_processing_anim_frame_ && id != CHUNK_ANMF) { if (webp_info->is_processing_anim_frame && id != CHUNK_ANMF) {
if (webp_info->anim_frame_data_size_ == chunk_data->size_) { if (webp_info->anim_frame_data_size == chunk_data->size) {
if (!webp_info->seen_image_subchunk_) { if (!webp_info->seen_image_subchunk) {
LOG_ERROR("No VP8/VP8L chunk detected in an ANMF chunk."); LOG_ERROR("No VP8/VP8L chunk detected in an ANMF chunk.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
webp_info->is_processing_anim_frame_ = 0; webp_info->is_processing_anim_frame = 0;
} else if (webp_info->anim_frame_data_size_ > chunk_data->size_) { } else if (webp_info->anim_frame_data_size > chunk_data->size) {
webp_info->anim_frame_data_size_ -= chunk_data->size_; webp_info->anim_frame_data_size -= chunk_data->size;
} else { } else {
LOG_ERROR("Truncated data detected when parsing ANMF chunk."); LOG_ERROR("Truncated data detected when parsing ANMF chunk.");
return WEBP_INFO_TRUNCATED_DATA; return WEBP_INFO_TRUNCATED_DATA;
@ -998,55 +998,55 @@ static WebPInfoStatus ProcessChunk(const ChunkData* const chunk_data,
} }
static WebPInfoStatus Validate(WebPInfo* const webp_info) { static WebPInfoStatus Validate(WebPInfo* const webp_info) {
if (webp_info->num_frames_ < 1) { if (webp_info->num_frames < 1) {
LOG_ERROR("No image/frame detected."); LOG_ERROR("No image/frame detected.");
return WEBP_INFO_MISSING_DATA; return WEBP_INFO_MISSING_DATA;
} }
if (webp_info->chunk_counts_[CHUNK_VP8X]) { if (webp_info->chunk_counts[CHUNK_VP8X]) {
const int iccp = !!(webp_info->feature_flags_ & ICCP_FLAG); const int iccp = !!(webp_info->feature_flags & ICCP_FLAG);
const int exif = !!(webp_info->feature_flags_ & EXIF_FLAG); const int exif = !!(webp_info->feature_flags & EXIF_FLAG);
const int xmp = !!(webp_info->feature_flags_ & XMP_FLAG); const int xmp = !!(webp_info->feature_flags & XMP_FLAG);
const int animation = !!(webp_info->feature_flags_ & ANIMATION_FLAG); const int animation = !!(webp_info->feature_flags & ANIMATION_FLAG);
const int alpha = !!(webp_info->feature_flags_ & ALPHA_FLAG); const int alpha = !!(webp_info->feature_flags & ALPHA_FLAG);
if (!alpha && webp_info->has_alpha_) { if (!alpha && webp_info->has_alpha) {
LOG_ERROR("Unexpected alpha data detected."); LOG_ERROR("Unexpected alpha data detected.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (alpha && !webp_info->has_alpha_) { if (alpha && !webp_info->has_alpha) {
LOG_WARN("Alpha flag is set with no alpha data present."); LOG_WARN("Alpha flag is set with no alpha data present.");
} }
if (iccp && !webp_info->chunk_counts_[CHUNK_ICCP]) { if (iccp && !webp_info->chunk_counts[CHUNK_ICCP]) {
LOG_ERROR("Missing ICCP chunk."); LOG_ERROR("Missing ICCP chunk.");
return WEBP_INFO_MISSING_DATA; return WEBP_INFO_MISSING_DATA;
} }
if (exif && !webp_info->chunk_counts_[CHUNK_EXIF]) { if (exif && !webp_info->chunk_counts[CHUNK_EXIF]) {
LOG_ERROR("Missing EXIF chunk."); LOG_ERROR("Missing EXIF chunk.");
return WEBP_INFO_MISSING_DATA; return WEBP_INFO_MISSING_DATA;
} }
if (xmp && !webp_info->chunk_counts_[CHUNK_XMP]) { if (xmp && !webp_info->chunk_counts[CHUNK_XMP]) {
LOG_ERROR("Missing XMP chunk."); LOG_ERROR("Missing XMP chunk.");
return WEBP_INFO_MISSING_DATA; return WEBP_INFO_MISSING_DATA;
} }
if (!iccp && webp_info->chunk_counts_[CHUNK_ICCP]) { if (!iccp && webp_info->chunk_counts[CHUNK_ICCP]) {
LOG_ERROR("Unexpected ICCP chunk detected."); LOG_ERROR("Unexpected ICCP chunk detected.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (!exif && webp_info->chunk_counts_[CHUNK_EXIF]) { if (!exif && webp_info->chunk_counts[CHUNK_EXIF]) {
LOG_ERROR("Unexpected EXIF chunk detected."); LOG_ERROR("Unexpected EXIF chunk detected.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (!xmp && webp_info->chunk_counts_[CHUNK_XMP]) { if (!xmp && webp_info->chunk_counts[CHUNK_XMP]) {
LOG_ERROR("Unexpected XMP chunk detected."); LOG_ERROR("Unexpected XMP chunk detected.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
// Incomplete animation frame. // Incomplete animation frame.
if (webp_info->is_processing_anim_frame_) return WEBP_INFO_MISSING_DATA; if (webp_info->is_processing_anim_frame) return WEBP_INFO_MISSING_DATA;
if (!animation && webp_info->num_frames_ > 1) { if (!animation && webp_info->num_frames > 1) {
LOG_ERROR("More than 1 frame detected in non-animation file."); LOG_ERROR("More than 1 frame detected in non-animation file.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
if (animation && (!webp_info->chunk_counts_[CHUNK_ANIM] || if (animation && (!webp_info->chunk_counts[CHUNK_ANIM] ||
!webp_info->chunk_counts_[CHUNK_ANMF])) { !webp_info->chunk_counts[CHUNK_ANMF])) {
LOG_ERROR("No ANIM/ANMF chunk detected in animation file."); LOG_ERROR("No ANIM/ANMF chunk detected in animation file.");
return WEBP_INFO_PARSE_ERROR; return WEBP_INFO_PARSE_ERROR;
} }
@ -1057,17 +1057,17 @@ static WebPInfoStatus Validate(WebPInfo* const webp_info) {
static void ShowSummary(const WebPInfo* const webp_info) { static void ShowSummary(const WebPInfo* const webp_info) {
int i; int i;
printf("Summary:\n"); printf("Summary:\n");
printf("Number of frames: %d\n", webp_info->num_frames_); printf("Number of frames: %d\n", webp_info->num_frames);
printf("Chunk type : VP8 VP8L VP8X ALPH ANIM ANMF(VP8 /VP8L/ALPH) ICCP " printf("Chunk type : VP8 VP8L VP8X ALPH ANIM ANMF(VP8 /VP8L/ALPH) ICCP "
"EXIF XMP\n"); "EXIF XMP\n");
printf("Chunk counts: "); printf("Chunk counts: ");
for (i = 0; i < CHUNK_TYPES; ++i) { for (i = 0; i < CHUNK_TYPES; ++i) {
printf("%4d ", webp_info->chunk_counts_[i]); printf("%4d ", webp_info->chunk_counts[i]);
if (i == CHUNK_ANMF) { if (i == CHUNK_ANMF) {
printf("%4d %4d %4d ", printf("%4d %4d %4d ",
webp_info->anmf_subchunk_counts_[0], webp_info->anmf_subchunk_counts[0],
webp_info->anmf_subchunk_counts_[1], webp_info->anmf_subchunk_counts[1],
webp_info->anmf_subchunk_counts_[2]); webp_info->anmf_subchunk_counts[2]);
} }
} }
printf("\n"); printf("\n");
@ -1090,20 +1090,20 @@ static WebPInfoStatus AnalyzeWebP(WebPInfo* const webp_info,
webp_info_status = ProcessChunk(&chunk_data, webp_info); webp_info_status = ProcessChunk(&chunk_data, webp_info);
} }
if (webp_info_status != WEBP_INFO_OK) goto Error; if (webp_info_status != WEBP_INFO_OK) goto Error;
if (webp_info->show_summary_) ShowSummary(webp_info); if (webp_info->show_summary) ShowSummary(webp_info);
// Final check. // Final check.
webp_info_status = Validate(webp_info); webp_info_status = Validate(webp_info);
Error: Error:
if (!webp_info->quiet_) { if (!webp_info->quiet) {
if (webp_info_status == WEBP_INFO_OK) { if (webp_info_status == WEBP_INFO_OK) {
printf("No error detected.\n"); printf("No error detected.\n");
} else { } else {
printf("Errors detected.\n"); printf("Errors detected.\n");
} }
if (webp_info->num_warnings_ > 0) { if (webp_info->num_warnings > 0) {
printf("There were %d warning(s).\n", webp_info->num_warnings_); printf("There were %d warning(s).\n", webp_info->num_warnings);
} }
} }
return webp_info_status; return webp_info_status;
@ -1169,10 +1169,10 @@ int main(int argc, const char* argv[]) {
WebPData webp_data; WebPData webp_data;
const W_CHAR* in_file = NULL; const W_CHAR* in_file = NULL;
WebPInfoInit(&webp_info); WebPInfoInit(&webp_info);
webp_info.quiet_ = quiet; webp_info.quiet = quiet;
webp_info.show_diagnosis_ = show_diag; webp_info.show_diagnosis = show_diag;
webp_info.show_summary_ = show_summary; webp_info.show_summary = show_summary;
webp_info.parse_bitstream_ = parse_bitstream; webp_info.parse_bitstream = parse_bitstream;
in_file = GET_WARGV(argv, c); in_file = GET_WARGV(argv, c);
if (in_file == NULL || if (in_file == NULL ||
!ReadFileToWebPData((const char*)in_file, &webp_data)) { !ReadFileToWebPData((const char*)in_file, &webp_data)) {
@ -1180,7 +1180,7 @@ int main(int argc, const char* argv[]) {
WFPRINTF(stderr, "Failed to open input file %s.\n", in_file); WFPRINTF(stderr, "Failed to open input file %s.\n", in_file);
continue; continue;
} }
if (!webp_info.quiet_) WPRINTF("File: %s\n", in_file); if (!webp_info.quiet) WPRINTF("File: %s\n", in_file);
webp_info_status = AnalyzeWebP(&webp_info, &webp_data); webp_info_status = AnalyzeWebP(&webp_info, &webp_data);
WebPDataClear(&webp_data); WebPDataClear(&webp_data);
} }

View File

@ -87,9 +87,9 @@ typedef enum {
} FeatureSubType; } FeatureSubType;
typedef struct { typedef struct {
FeatureSubType subtype_; FeatureSubType subtype;
const char* filename_; const char* filename;
const char* params_; const char* params;
} FeatureArg; } FeatureArg;
typedef enum { typedef enum {
@ -114,14 +114,14 @@ static const char* const kDescriptions[LAST_FEATURE] = {
}; };
typedef struct { typedef struct {
CommandLineArguments cmd_args_; CommandLineArguments cmd_args;
ActionType action_type_; ActionType action_type;
const char* input_; const char* input;
const char* output_; const char* output;
FeatureType type_; FeatureType type;
FeatureArg* args_; FeatureArg* args;
int arg_count_; int arg_count;
} Config; } Config;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -132,8 +132,8 @@ static int CountOccurrences(const CommandLineArguments* const args,
int i; int i;
int num_occurences = 0; int num_occurences = 0;
for (i = 0; i < args->argc_; ++i) { for (i = 0; i < args->argc; ++i) {
if (!strcmp(args->argv_[i], arg)) { if (!strcmp(args->argv[i], arg)) {
++num_occurences; ++num_occurences;
} }
} }
@ -527,8 +527,8 @@ static int ParseBgcolorArgs(const char* args, uint32_t* const bgcolor) {
static void DeleteConfig(Config* const config) { static void DeleteConfig(Config* const config) {
if (config != NULL) { if (config != NULL) {
free(config->args_); free(config->args);
ExUtilDeleteCommandLineArguments(&config->cmd_args_); ExUtilDeleteCommandLineArguments(&config->cmd_args);
memset(config, 0, sizeof(*config)); memset(config, 0, sizeof(*config));
} }
} }
@ -605,9 +605,9 @@ static int ValidateCommandLine(const CommandLineArguments* const cmd_args,
return ok; return ok;
} }
#define ACTION_IS_NIL (config->action_type_ == NIL_ACTION) #define ACTION_IS_NIL (config->action_type == NIL_ACTION)
#define FEATURETYPE_IS_NIL (config->type_ == NIL_FEATURE) #define FEATURETYPE_IS_NIL (config->type == NIL_FEATURE)
#define CHECK_NUM_ARGS_AT_LEAST(NUM, LABEL) \ #define CHECK_NUM_ARGS_AT_LEAST(NUM, LABEL) \
do { \ do { \
@ -637,98 +637,98 @@ static int ParseCommandLine(Config* config, const W_CHAR** const unicode_argv) {
int i = 0; int i = 0;
int feature_arg_index = 0; int feature_arg_index = 0;
int ok = 1; int ok = 1;
int argc = config->cmd_args_.argc_; int argc = config->cmd_args.argc;
const char* const* argv = config->cmd_args_.argv_; const char* const* argv = config->cmd_args.argv;
// Unicode file paths will be used if available. // Unicode file paths will be used if available.
const char* const* wargv = const char* const* wargv =
(unicode_argv != NULL) ? (const char**)(unicode_argv + 1) : argv; (unicode_argv != NULL) ? (const char**)(unicode_argv + 1) : argv;
while (i < argc) { while (i < argc) {
FeatureArg* const arg = &config->args_[feature_arg_index]; FeatureArg* const arg = &config->args[feature_arg_index];
if (argv[i][0] == '-') { // One of the action types or output. if (argv[i][0] == '-') { // One of the action types or output.
if (!strcmp(argv[i], "-set")) { if (!strcmp(argv[i], "-set")) {
if (ACTION_IS_NIL) { if (ACTION_IS_NIL) {
config->action_type_ = ACTION_SET; config->action_type = ACTION_SET;
} else { } else {
ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse);
} }
++i; ++i;
} else if (!strcmp(argv[i], "-duration")) { } else if (!strcmp(argv[i], "-duration")) {
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
if (ACTION_IS_NIL || config->action_type_ == ACTION_DURATION) { if (ACTION_IS_NIL || config->action_type == ACTION_DURATION) {
config->action_type_ = ACTION_DURATION; config->action_type = ACTION_DURATION;
} else { } else {
ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse);
} }
if (FEATURETYPE_IS_NIL || config->type_ == FEATURE_DURATION) { if (FEATURETYPE_IS_NIL || config->type == FEATURE_DURATION) {
config->type_ = FEATURE_DURATION; config->type = FEATURE_DURATION;
} else { } else {
ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse); ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse);
} }
arg->params_ = argv[i + 1]; arg->params = argv[i + 1];
++feature_arg_index; ++feature_arg_index;
i += 2; i += 2;
} else if (!strcmp(argv[i], "-get")) { } else if (!strcmp(argv[i], "-get")) {
if (ACTION_IS_NIL) { if (ACTION_IS_NIL) {
config->action_type_ = ACTION_GET; config->action_type = ACTION_GET;
} else { } else {
ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse);
} }
++i; ++i;
} else if (!strcmp(argv[i], "-strip")) { } else if (!strcmp(argv[i], "-strip")) {
if (ACTION_IS_NIL) { if (ACTION_IS_NIL) {
config->action_type_ = ACTION_STRIP; config->action_type = ACTION_STRIP;
config->arg_count_ = 0; config->arg_count = 0;
} else { } else {
ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse);
} }
++i; ++i;
} else if (!strcmp(argv[i], "-frame")) { } else if (!strcmp(argv[i], "-frame")) {
CHECK_NUM_ARGS_AT_LEAST(3, ErrParse); CHECK_NUM_ARGS_AT_LEAST(3, ErrParse);
if (ACTION_IS_NIL || config->action_type_ == ACTION_SET) { if (ACTION_IS_NIL || config->action_type == ACTION_SET) {
config->action_type_ = ACTION_SET; config->action_type = ACTION_SET;
} else { } else {
ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse);
} }
if (FEATURETYPE_IS_NIL || config->type_ == FEATURE_ANMF) { if (FEATURETYPE_IS_NIL || config->type == FEATURE_ANMF) {
config->type_ = FEATURE_ANMF; config->type = FEATURE_ANMF;
} else { } else {
ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse); ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse);
} }
arg->subtype_ = SUBTYPE_ANMF; arg->subtype = SUBTYPE_ANMF;
arg->filename_ = wargv[i + 1]; arg->filename = wargv[i + 1];
arg->params_ = argv[i + 2]; arg->params = argv[i + 2];
++feature_arg_index; ++feature_arg_index;
i += 3; i += 3;
} else if (!strcmp(argv[i], "-loop") || !strcmp(argv[i], "-bgcolor")) { } else if (!strcmp(argv[i], "-loop") || !strcmp(argv[i], "-bgcolor")) {
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
if (ACTION_IS_NIL || config->action_type_ == ACTION_SET) { if (ACTION_IS_NIL || config->action_type == ACTION_SET) {
config->action_type_ = ACTION_SET; config->action_type = ACTION_SET;
} else { } else {
ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse);
} }
if (FEATURETYPE_IS_NIL || config->type_ == FEATURE_ANMF) { if (FEATURETYPE_IS_NIL || config->type == FEATURE_ANMF) {
config->type_ = FEATURE_ANMF; config->type = FEATURE_ANMF;
} else { } else {
ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse); ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse);
} }
arg->subtype_ = arg->subtype =
!strcmp(argv[i], "-loop") ? SUBTYPE_LOOP : SUBTYPE_BGCOLOR; !strcmp(argv[i], "-loop") ? SUBTYPE_LOOP : SUBTYPE_BGCOLOR;
arg->params_ = argv[i + 1]; arg->params = argv[i + 1];
++feature_arg_index; ++feature_arg_index;
i += 2; i += 2;
} else if (!strcmp(argv[i], "-o")) { } else if (!strcmp(argv[i], "-o")) {
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
config->output_ = wargv[i + 1]; config->output = wargv[i + 1];
i += 2; i += 2;
} else if (!strcmp(argv[i], "-info")) { } else if (!strcmp(argv[i], "-info")) {
CHECK_NUM_ARGS_EXACTLY(2, ErrParse); CHECK_NUM_ARGS_EXACTLY(2, ErrParse);
if (config->action_type_ != NIL_ACTION) { if (config->action_type != NIL_ACTION) {
ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse);
} else { } else {
config->action_type_ = ACTION_INFO; config->action_type = ACTION_INFO;
config->arg_count_ = 0; config->arg_count = 0;
config->input_ = wargv[i + 1]; config->input = wargv[i + 1];
} }
i += 2; i += 2;
} else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help")) { } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help")) {
@ -746,8 +746,8 @@ static int ParseCommandLine(Config* config, const W_CHAR** const unicode_argv) {
} else if (!strcmp(argv[i], "--")) { } else if (!strcmp(argv[i], "--")) {
if (i < argc - 1) { if (i < argc - 1) {
++i; ++i;
if (config->input_ == NULL) { if (config->input == NULL) {
config->input_ = wargv[i]; config->input = wargv[i];
} else { } else {
ERROR_GOTO2("ERROR at '%s': Multiple input files specified.\n", ERROR_GOTO2("ERROR at '%s': Multiple input files specified.\n",
argv[i], ErrParse); argv[i], ErrParse);
@ -765,43 +765,43 @@ static int ParseCommandLine(Config* config, const W_CHAR** const unicode_argv) {
if (!strcmp(argv[i], "icc") || !strcmp(argv[i], "exif") || if (!strcmp(argv[i], "icc") || !strcmp(argv[i], "exif") ||
!strcmp(argv[i], "xmp")) { !strcmp(argv[i], "xmp")) {
if (FEATURETYPE_IS_NIL) { if (FEATURETYPE_IS_NIL) {
config->type_ = (!strcmp(argv[i], "icc")) ? FEATURE_ICCP : config->type = (!strcmp(argv[i], "icc")) ? FEATURE_ICCP :
(!strcmp(argv[i], "exif")) ? FEATURE_EXIF : FEATURE_XMP; (!strcmp(argv[i], "exif")) ? FEATURE_EXIF : FEATURE_XMP;
} else { } else {
ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse); ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse);
} }
if (config->action_type_ == ACTION_SET) { if (config->action_type == ACTION_SET) {
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
arg->filename_ = wargv[i + 1]; arg->filename = wargv[i + 1];
++feature_arg_index; ++feature_arg_index;
i += 2; i += 2;
} else { } else {
++i; ++i;
} }
} else if (!strcmp(argv[i], "frame") && } else if (!strcmp(argv[i], "frame") &&
(config->action_type_ == ACTION_GET)) { (config->action_type == ACTION_GET)) {
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
config->type_ = FEATURE_ANMF; config->type = FEATURE_ANMF;
arg->params_ = argv[i + 1]; arg->params = argv[i + 1];
++feature_arg_index; ++feature_arg_index;
i += 2; i += 2;
} else if (!strcmp(argv[i], "loop") && } else if (!strcmp(argv[i], "loop") &&
(config->action_type_ == ACTION_SET)) { (config->action_type == ACTION_SET)) {
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
config->type_ = FEATURE_LOOP; config->type = FEATURE_LOOP;
arg->params_ = argv[i + 1]; arg->params = argv[i + 1];
++feature_arg_index; ++feature_arg_index;
i += 2; i += 2;
} else if (!strcmp(argv[i], "bgcolor") && } else if (!strcmp(argv[i], "bgcolor") &&
(config->action_type_ == ACTION_SET)) { (config->action_type == ACTION_SET)) {
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
config->type_ = FEATURE_BGCOLOR; config->type = FEATURE_BGCOLOR;
arg->params_ = argv[i + 1]; arg->params = argv[i + 1];
++feature_arg_index; ++feature_arg_index;
i += 2; i += 2;
} else { // Assume input file. } else { // Assume input file.
if (config->input_ == NULL) { if (config->input == NULL) {
config->input_ = wargv[i]; config->input = wargv[i];
} else { } else {
ERROR_GOTO2("ERROR at '%s': Multiple input files specified.\n", ERROR_GOTO2("ERROR at '%s': Multiple input files specified.\n",
argv[i], ErrParse); argv[i], ErrParse);
@ -824,21 +824,21 @@ static int ValidateConfig(Config* const config) {
} }
// Feature type. // Feature type.
if (FEATURETYPE_IS_NIL && config->action_type_ != ACTION_INFO) { if (FEATURETYPE_IS_NIL && config->action_type != ACTION_INFO) {
ERROR_GOTO1("ERROR: No feature specified.\n", ErrValidate2); ERROR_GOTO1("ERROR: No feature specified.\n", ErrValidate2);
} }
// Input file. // Input file.
if (config->input_ == NULL) { if (config->input == NULL) {
if (config->action_type_ != ACTION_SET) { if (config->action_type != ACTION_SET) {
ERROR_GOTO1("ERROR: No input file specified.\n", ErrValidate2); ERROR_GOTO1("ERROR: No input file specified.\n", ErrValidate2);
} else if (config->type_ != FEATURE_ANMF) { } else if (config->type != FEATURE_ANMF) {
ERROR_GOTO1("ERROR: No input file specified.\n", ErrValidate2); ERROR_GOTO1("ERROR: No input file specified.\n", ErrValidate2);
} }
} }
// Output file. // Output file.
if (config->output_ == NULL && config->action_type_ != ACTION_INFO) { if (config->output == NULL && config->action_type != ACTION_INFO) {
ERROR_GOTO1("ERROR: No output file specified.\n", ErrValidate2); ERROR_GOTO1("ERROR: No output file specified.\n", ErrValidate2);
} }
@ -854,17 +854,17 @@ static int InitializeConfig(int argc, const char* argv[], Config* const config,
memset(config, 0, sizeof(*config)); memset(config, 0, sizeof(*config));
ok = ExUtilInitCommandLineArguments(argc, argv, &config->cmd_args_); ok = ExUtilInitCommandLineArguments(argc, argv, &config->cmd_args);
if (!ok) return 0; if (!ok) return 0;
// Validate command-line arguments. // Validate command-line arguments.
if (!ValidateCommandLine(&config->cmd_args_, &num_feature_args)) { if (!ValidateCommandLine(&config->cmd_args, &num_feature_args)) {
ERROR_GOTO1("Exiting due to command-line parsing error.\n", Err1); ERROR_GOTO1("Exiting due to command-line parsing error.\n", Err1);
} }
config->arg_count_ = num_feature_args; config->arg_count = num_feature_args;
config->args_ = (FeatureArg*)calloc(num_feature_args, sizeof(*config->args_)); config->args = (FeatureArg*)calloc(num_feature_args, sizeof(*config->args));
if (config->args_ == NULL) { if (config->args == NULL) {
ERROR_GOTO1("ERROR: Memory allocation error.\n", Err1); ERROR_GOTO1("ERROR: Memory allocation error.\n", Err1);
} }
@ -896,7 +896,7 @@ static int GetFrame(const WebPMux* mux, const Config* config) {
WebPMuxFrameInfo info; WebPMuxFrameInfo info;
WebPDataInit(&info.bitstream); WebPDataInit(&info.bitstream);
num = ExUtilGetInt(config->args_[0].params_, 10, &parse_error); num = ExUtilGetInt(config->args[0].params, 10, &parse_error);
if (num < 0) { if (num < 0) {
ERROR_GOTO1("ERROR: Frame/Fragment index must be non-negative.\n", ErrGet); ERROR_GOTO1("ERROR: Frame/Fragment index must be non-negative.\n", ErrGet);
} }
@ -921,7 +921,7 @@ static int GetFrame(const WebPMux* mux, const Config* config) {
ErrorString(err), ErrGet); ErrorString(err), ErrGet);
} }
ok = WriteWebP(mux_single, config->output_); ok = WriteWebP(mux_single, config->output);
ErrGet: ErrGet:
WebPDataClear(&info.bitstream); WebPDataClear(&info.bitstream);
@ -936,11 +936,11 @@ static int Process(const Config* config) {
WebPMuxError err = WEBP_MUX_OK; WebPMuxError err = WEBP_MUX_OK;
int ok = 1; int ok = 1;
switch (config->action_type_) { switch (config->action_type) {
case ACTION_GET: { case ACTION_GET: {
ok = CreateMux(config->input_, &mux); ok = CreateMux(config->input, &mux);
if (!ok) goto Err2; if (!ok) goto Err2;
switch (config->type_) { switch (config->type) {
case FEATURE_ANMF: case FEATURE_ANMF:
ok = GetFrame(mux, config); ok = GetFrame(mux, config);
break; break;
@ -948,12 +948,12 @@ static int Process(const Config* config) {
case FEATURE_ICCP: case FEATURE_ICCP:
case FEATURE_EXIF: case FEATURE_EXIF:
case FEATURE_XMP: case FEATURE_XMP:
err = WebPMuxGetChunk(mux, kFourccList[config->type_], &chunk); err = WebPMuxGetChunk(mux, kFourccList[config->type], &chunk);
if (err != WEBP_MUX_OK) { if (err != WEBP_MUX_OK) {
ERROR_GOTO3("ERROR (%s): Could not get the %s.\n", ERROR_GOTO3("ERROR (%s): Could not get the %s.\n",
ErrorString(err), kDescriptions[config->type_], Err2); ErrorString(err), kDescriptions[config->type], Err2);
} }
ok = WriteData(config->output_, &chunk); ok = WriteData(config->output, &chunk);
break; break;
default: default:
@ -963,7 +963,7 @@ static int Process(const Config* config) {
break; break;
} }
case ACTION_SET: { case ACTION_SET: {
switch (config->type_) { switch (config->type) {
case FEATURE_ANMF: { case FEATURE_ANMF: {
int i; int i;
WebPMuxAnimParams params = { 0xFFFFFFFF, 0 }; WebPMuxAnimParams params = { 0xFFFFFFFF, 0 };
@ -972,11 +972,11 @@ static int Process(const Config* config) {
ERROR_GOTO2("ERROR (%s): Could not allocate a mux object.\n", ERROR_GOTO2("ERROR (%s): Could not allocate a mux object.\n",
ErrorString(WEBP_MUX_MEMORY_ERROR), Err2); ErrorString(WEBP_MUX_MEMORY_ERROR), Err2);
} }
for (i = 0; i < config->arg_count_; ++i) { for (i = 0; i < config->arg_count; ++i) {
switch (config->args_[i].subtype_) { switch (config->args[i].subtype) {
case SUBTYPE_BGCOLOR: { case SUBTYPE_BGCOLOR: {
uint32_t bgcolor; uint32_t bgcolor;
ok = ParseBgcolorArgs(config->args_[i].params_, &bgcolor); ok = ParseBgcolorArgs(config->args[i].params, &bgcolor);
if (!ok) { if (!ok) {
ERROR_GOTO1("ERROR: Could not parse the background color \n", ERROR_GOTO1("ERROR: Could not parse the background color \n",
Err2); Err2);
@ -987,7 +987,7 @@ static int Process(const Config* config) {
case SUBTYPE_LOOP: { case SUBTYPE_LOOP: {
int parse_error = 0; int parse_error = 0;
const int loop_count = const int loop_count =
ExUtilGetInt(config->args_[i].params_, 10, &parse_error); ExUtilGetInt(config->args[i].params, 10, &parse_error);
if (loop_count < 0 || loop_count > 65535) { if (loop_count < 0 || loop_count > 65535) {
// Note: This is only a 'necessary' condition for loop_count // Note: This is only a 'necessary' condition for loop_count
// to be valid. The 'sufficient' conditioned in checked in // to be valid. The 'sufficient' conditioned in checked in
@ -1003,10 +1003,10 @@ static int Process(const Config* config) {
case SUBTYPE_ANMF: { case SUBTYPE_ANMF: {
WebPMuxFrameInfo frame; WebPMuxFrameInfo frame;
frame.id = WEBP_CHUNK_ANMF; frame.id = WEBP_CHUNK_ANMF;
ok = ExUtilReadFileToWebPData(config->args_[i].filename_, ok = ExUtilReadFileToWebPData(config->args[i].filename,
&frame.bitstream); &frame.bitstream);
if (!ok) goto Err2; if (!ok) goto Err2;
ok = ParseFrameArgs(config->args_[i].params_, &frame); ok = ParseFrameArgs(config->args[i].params, &frame);
if (!ok) { if (!ok) {
WebPDataClear(&frame.bitstream); WebPDataClear(&frame.bitstream);
ERROR_GOTO1("ERROR: Could not parse frame properties.\n", ERROR_GOTO1("ERROR: Could not parse frame properties.\n",
@ -1037,15 +1037,15 @@ static int Process(const Config* config) {
case FEATURE_ICCP: case FEATURE_ICCP:
case FEATURE_EXIF: case FEATURE_EXIF:
case FEATURE_XMP: { case FEATURE_XMP: {
ok = CreateMux(config->input_, &mux); ok = CreateMux(config->input, &mux);
if (!ok) goto Err2; if (!ok) goto Err2;
ok = ExUtilReadFileToWebPData(config->args_[0].filename_, &chunk); ok = ExUtilReadFileToWebPData(config->args[0].filename, &chunk);
if (!ok) goto Err2; if (!ok) goto Err2;
err = WebPMuxSetChunk(mux, kFourccList[config->type_], &chunk, 1); err = WebPMuxSetChunk(mux, kFourccList[config->type], &chunk, 1);
WebPDataClear(&chunk); WebPDataClear(&chunk);
if (err != WEBP_MUX_OK) { if (err != WEBP_MUX_OK) {
ERROR_GOTO3("ERROR (%s): Could not set the %s.\n", ERROR_GOTO3("ERROR (%s): Could not set the %s.\n",
ErrorString(err), kDescriptions[config->type_], Err2); ErrorString(err), kDescriptions[config->type], Err2);
} }
break; break;
} }
@ -1053,12 +1053,12 @@ static int Process(const Config* config) {
WebPMuxAnimParams params = { 0xFFFFFFFF, 0 }; WebPMuxAnimParams params = { 0xFFFFFFFF, 0 };
int parse_error = 0; int parse_error = 0;
const int loop_count = const int loop_count =
ExUtilGetInt(config->args_[0].params_, 10, &parse_error); ExUtilGetInt(config->args[0].params, 10, &parse_error);
if (loop_count < 0 || loop_count > 65535 || parse_error) { if (loop_count < 0 || loop_count > 65535 || parse_error) {
ERROR_GOTO1("ERROR: Loop count must be in the range 0 to 65535.\n", ERROR_GOTO1("ERROR: Loop count must be in the range 0 to 65535.\n",
Err2); Err2);
} }
ok = CreateMux(config->input_, &mux); ok = CreateMux(config->input, &mux);
if (!ok) goto Err2; if (!ok) goto Err2;
ok = (WebPMuxGetAnimationParams(mux, &params) == WEBP_MUX_OK); ok = (WebPMuxGetAnimationParams(mux, &params) == WEBP_MUX_OK);
if (!ok) { if (!ok) {
@ -1077,12 +1077,12 @@ static int Process(const Config* config) {
case FEATURE_BGCOLOR: { case FEATURE_BGCOLOR: {
WebPMuxAnimParams params = { 0xFFFFFFFF, 0 }; WebPMuxAnimParams params = { 0xFFFFFFFF, 0 };
uint32_t bgcolor; uint32_t bgcolor;
ok = ParseBgcolorArgs(config->args_[0].params_, &bgcolor); ok = ParseBgcolorArgs(config->args[0].params, &bgcolor);
if (!ok) { if (!ok) {
ERROR_GOTO1("ERROR: Could not parse the background color.\n", ERROR_GOTO1("ERROR: Could not parse the background color.\n",
Err2); Err2);
} }
ok = CreateMux(config->input_, &mux); ok = CreateMux(config->input, &mux);
if (!ok) goto Err2; if (!ok) goto Err2;
ok = (WebPMuxGetAnimationParams(mux, &params) == WEBP_MUX_OK); ok = (WebPMuxGetAnimationParams(mux, &params) == WEBP_MUX_OK);
if (!ok) { if (!ok) {
@ -1103,12 +1103,12 @@ static int Process(const Config* config) {
break; break;
} }
} }
ok = WriteWebP(mux, config->output_); ok = WriteWebP(mux, config->output);
break; break;
} }
case ACTION_DURATION: { case ACTION_DURATION: {
int num_frames; int num_frames;
ok = CreateMux(config->input_, &mux); ok = CreateMux(config->input, &mux);
if (!ok) goto Err2; if (!ok) goto Err2;
err = WebPMuxNumChunks(mux, WEBP_CHUNK_ANMF, &num_frames); err = WebPMuxNumChunks(mux, WEBP_CHUNK_ANMF, &num_frames);
ok = (err == WEBP_MUX_OK); ok = (err == WEBP_MUX_OK);
@ -1118,7 +1118,7 @@ static int Process(const Config* config) {
if (num_frames == 0) { if (num_frames == 0) {
fprintf(stderr, "Doesn't look like the source is animated. " fprintf(stderr, "Doesn't look like the source is animated. "
"Skipping duration setting.\n"); "Skipping duration setting.\n");
ok = WriteWebP(mux, config->output_); ok = WriteWebP(mux, config->output);
if (!ok) goto Err2; if (!ok) goto Err2;
} else { } else {
int i; int i;
@ -1130,11 +1130,11 @@ static int Process(const Config* config) {
for (i = 0; i < num_frames; ++i) durations[i] = -1; for (i = 0; i < num_frames; ++i) durations[i] = -1;
// Parse intervals to process. // Parse intervals to process.
for (i = 0; i < config->arg_count_; ++i) { for (i = 0; i < config->arg_count; ++i) {
int k; int k;
int args[3]; int args[3];
int duration, start, end; int duration, start, end;
const int nb_args = ExUtilGetInts(config->args_[i].params_, const int nb_args = ExUtilGetInts(config->args[i].params,
10, 3, args); 10, 3, args);
ok = (nb_args >= 1); ok = (nb_args >= 1);
if (!ok) goto Err3; if (!ok) goto Err3;
@ -1178,7 +1178,7 @@ static int Process(const Config* config) {
WebPDataClear(&frame.bitstream); WebPDataClear(&frame.bitstream);
} }
WebPMuxDelete(mux); WebPMuxDelete(mux);
ok = WriteWebP(new_mux, config->output_); ok = WriteWebP(new_mux, config->output);
mux = new_mux; // transfer for the WebPMuxDelete() call mux = new_mux; // transfer for the WebPMuxDelete() call
new_mux = NULL; new_mux = NULL;
@ -1190,24 +1190,24 @@ static int Process(const Config* config) {
break; break;
} }
case ACTION_STRIP: { case ACTION_STRIP: {
ok = CreateMux(config->input_, &mux); ok = CreateMux(config->input, &mux);
if (!ok) goto Err2; if (!ok) goto Err2;
if (config->type_ == FEATURE_ICCP || config->type_ == FEATURE_EXIF || if (config->type == FEATURE_ICCP || config->type == FEATURE_EXIF ||
config->type_ == FEATURE_XMP) { config->type == FEATURE_XMP) {
err = WebPMuxDeleteChunk(mux, kFourccList[config->type_]); err = WebPMuxDeleteChunk(mux, kFourccList[config->type]);
if (err != WEBP_MUX_OK) { if (err != WEBP_MUX_OK) {
ERROR_GOTO3("ERROR (%s): Could not strip the %s.\n", ERROR_GOTO3("ERROR (%s): Could not strip the %s.\n",
ErrorString(err), kDescriptions[config->type_], Err2); ErrorString(err), kDescriptions[config->type], Err2);
} }
} else { } else {
ERROR_GOTO1("ERROR: Invalid feature for action 'strip'.\n", Err2); ERROR_GOTO1("ERROR: Invalid feature for action 'strip'.\n", Err2);
break; break;
} }
ok = WriteWebP(mux, config->output_); ok = WriteWebP(mux, config->output);
break; break;
} }
case ACTION_INFO: { case ACTION_INFO: {
ok = CreateMux(config->input_, &mux); ok = CreateMux(config->input, &mux);
if (!ok) goto Err2; if (!ok) goto Err2;
ok = (DisplayInfo(mux) == WEBP_MUX_OK); ok = (DisplayInfo(mux) == WEBP_MUX_OK);
break; break;

View File

@ -28,10 +28,10 @@
void WebPInfoTest(std::string_view data) { void WebPInfoTest(std::string_view data) {
WebPInfo webp_info; WebPInfo webp_info;
WebPInfoInit(&webp_info); WebPInfoInit(&webp_info);
webp_info.quiet_ = 1; webp_info.quiet = 1;
webp_info.show_summary_ = 0; webp_info.show_summary = 0;
webp_info.show_diagnosis_ = 0; webp_info.show_diagnosis = 0;
webp_info.parse_bitstream_ = 1; webp_info.parse_bitstream = 1;
WebPData webp_data = {reinterpret_cast<const uint8_t *>(data.data()), WebPData webp_data = {reinterpret_cast<const uint8_t *>(data.data()),
data.size()}; data.size()};
AnalyzeWebP(&webp_info, &webp_data); AnalyzeWebP(&webp_info, &webp_data);