From 295804e4b914ac0c5845afd146a14625a51dac0e Mon Sep 17 00:00:00 2001 From: James Zern Date: Thu, 10 Apr 2025 15:03:43 -0700 Subject: [PATCH] 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 --- examples/example_util.c | 28 +-- examples/example_util.h | 8 +- examples/img2webp.c | 4 +- examples/webpinfo.c | 382 +++++++++++++++---------------- examples/webpmux.c | 216 ++++++++--------- tests/fuzzer/webp_info_fuzzer.cc | 8 +- 6 files changed, 323 insertions(+), 323 deletions(-) diff --git a/examples/example_util.c b/examples/example_util.c index fa38d3c2..fe19c9b2 100644 --- a/examples/example_util.c +++ b/examples/example_util.c @@ -66,17 +66,17 @@ float ExUtilGetFloat(const char* const v, int* const error) { static void ResetCommandLineArguments(int argc, const char* argv[], CommandLineArguments* const args) { assert(args != NULL); - args->argc_ = argc; - args->argv_ = argv; - args->own_argv_ = 0; - WebPDataInit(&args->argv_data_); + args->argc = argc; + args->argv = argv; + args->own_argv = 0; + WebPDataInit(&args->argv_data); } void ExUtilDeleteCommandLineArguments(CommandLineArguments* const args) { if (args != NULL) { - if (args->own_argv_) { - WebPFree((void*)args->argv_); - WebPDataClear(&args->argv_data_); + if (args->own_argv) { + WebPFree((void*)args->argv); + WebPDataClear(&args->argv_data); } ResetCommandLineArguments(0, NULL, args); } @@ -98,18 +98,18 @@ int ExUtilInitCommandLineArguments(int argc, const char* argv[], return 0; #endif - if (!ExUtilReadFileToWebPData(argv[0], &args->argv_data_)) { + if (!ExUtilReadFileToWebPData(argv[0], &args->argv_data)) { return 0; } - args->own_argv_ = 1; - args->argv_ = (const char**)WebPMalloc(MAX_ARGC * sizeof(*args->argv_)); - if (args->argv_ == NULL) { + args->own_argv = 1; + args->argv = (const char**)WebPMalloc(MAX_ARGC * sizeof(*args->argv)); + if (args->argv == NULL) { ExUtilDeleteCommandLineArguments(args); return 0; } argc = 0; - for (cur = strtok((char*)args->argv_data_.bytes, sep); + for (cur = strtok((char*)args->argv_data.bytes, sep); cur != NULL; cur = strtok(NULL, sep)) { if (argc == MAX_ARGC) { @@ -118,9 +118,9 @@ int ExUtilInitCommandLineArguments(int argc, const char* argv[], return 0; } assert(strlen(cur) != 0); - args->argv_[argc++] = cur; + args->argv[argc++] = cur; } - args->argc_ = argc; + args->argc = argc; } return 1; } diff --git a/examples/example_util.h b/examples/example_util.h index fe762a4d..407f35c6 100644 --- a/examples/example_util.h +++ b/examples/example_util.h @@ -45,10 +45,10 @@ int ExUtilReadFileToWebPData(const char* const filename, // Command-line arguments typedef struct { - int argc_; - const char** argv_; - WebPData argv_data_; - int own_argv_; + int argc; + const char** argv; + WebPData argv_data; + int own_argv; } CommandLineArguments; // Initializes the structure from the command-line parameters. If there is diff --git a/examples/img2webp.c b/examples/img2webp.c index 97d2669e..829e3f64 100644 --- a/examples/img2webp.c +++ b/examples/img2webp.c @@ -160,8 +160,8 @@ int main(int argc, const char* argv[]) { ok = ExUtilInitCommandLineArguments(argc - 1, argv + 1, &cmd_args); if (!ok) FREE_WARGV_AND_RETURN(EXIT_FAILURE); - argc = cmd_args.argc_; - argv = cmd_args.argv_; + argc = cmd_args.argc; + argv = cmd_args.argv; WebPDataInit(&webp_data); if (!WebPAnimEncoderOptionsInit(&anim_config) || diff --git a/examples/webpinfo.c b/examples/webpinfo.c index ba8f1e12..cbf5a127 100644 --- a/examples/webpinfo.c +++ b/examples/webpinfo.c @@ -32,17 +32,17 @@ #define LOG_ERROR(MESSAGE) \ do { \ - if (webp_info->show_diagnosis_) { \ + if (webp_info->show_diagnosis) { \ fprintf(stderr, "Error: %s\n", MESSAGE); \ } \ } while (0) #define LOG_WARN(MESSAGE) \ do { \ - if (webp_info->show_diagnosis_) { \ + if (webp_info->show_diagnosis) { \ fprintf(stderr, "Warning: %s\n", MESSAGE); \ } \ - ++webp_info->num_warnings_; \ + ++webp_info->num_warnings; \ } while (0) static const char* const kFormats[3] = { @@ -90,36 +90,36 @@ typedef enum ChunkID { } ChunkID; typedef struct { - size_t start_; - size_t end_; - const uint8_t* buf_; + size_t start; + size_t end; + const uint8_t* buf; } MemBuffer; typedef struct { - size_t offset_; - size_t size_; - const uint8_t* payload_; - ChunkID id_; + size_t offset; + size_t size; + const uint8_t* payload; + ChunkID id; } ChunkData; typedef struct WebPInfo { - int canvas_width_; - int canvas_height_; - int loop_count_; - int num_frames_; - int chunk_counts_[CHUNK_TYPES]; - int anmf_subchunk_counts_[3]; // 0 VP8; 1 VP8L; 2 ALPH. - uint32_t bgcolor_; - int feature_flags_; - int has_alpha_; + int canvas_width; + int canvas_height; + int loop_count; + int num_frames; + int chunk_counts[CHUNK_TYPES]; + int anmf_subchunk_counts[3]; // 0 VP8; 1 VP8L; 2 ALPH. + uint32_t bgcolor; + int feature_flags; + int has_alpha; // Used for parsing ANMF chunks. - int frame_width_, frame_height_; - size_t anim_frame_data_size_; - int is_processing_anim_frame_, seen_alpha_subchunk_, seen_image_subchunk_; + int frame_width, frame_height; + size_t anim_frame_data_size; + int is_processing_anim_frame, seen_alpha_subchunk, seen_image_subchunk; // Print output control. - int quiet_, show_diagnosis_, show_summary_; - int num_warnings_; - int parse_bitstream_; + int quiet, show_diagnosis, show_summary; + int num_warnings; + int parse_bitstream; } WebPInfo; static void WebPInfoInit(WebPInfo* const webp_info) { @@ -185,25 +185,25 @@ static int ReadFileToWebPData(const char* const filename, // MemBuffer object. static void InitMemBuffer(MemBuffer* const mem, const WebPData* webp_data) { - mem->buf_ = webp_data->bytes; - mem->start_ = 0; - mem->end_ = webp_data->size; + mem->buf = webp_data->bytes; + mem->start = 0; + mem->end = webp_data->size; } 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) { - return mem->buf_ + mem->start_; + return mem->buf + mem->start; } static void Skip(MemBuffer* const mem, size_t size) { - mem->start_ += size; + mem->start += size; } 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); assert(MemDataSize(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, const WebPInfo* const webp_info) { - const uint8_t* data = chunk_data->payload_; - size_t data_size = chunk_data->size_ - CHUNK_HEADER_SIZE; + const uint8_t* data = chunk_data->payload; + 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 int key_frame = !(bits & 1); const int profile = (bits >> 1) & 7; @@ -347,7 +347,7 @@ static WebPInfoStatus ParseLossyHeader(const ChunkData* const chunk_data, int colorspace, clamp_type; printf(" Parsing lossy bitstream...\n"); // 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) { LOG_ERROR("Unknown profile."); return WEBP_INFO_BITSTREAM_ERROR; @@ -505,8 +505,8 @@ static WebPInfoStatus ParseLosslessTransform(WebPInfo* const webp_info, static WebPInfoStatus ParseLosslessHeader(const ChunkData* const chunk_data, WebPInfo* const webp_info) { - const uint8_t* data = chunk_data->payload_; - size_t data_size = chunk_data->size_ - CHUNK_HEADER_SIZE; + const uint8_t* data = chunk_data->payload; + size_t data_size = chunk_data->size - CHUNK_HEADER_SIZE; uint64_t bit_position = 0; uint64_t* const bit_pos = &bit_position; WebPInfoStatus status; @@ -541,8 +541,8 @@ static WebPInfoStatus ParseLosslessHeader(const ChunkData* const chunk_data, static WebPInfoStatus ParseAlphaHeader(const ChunkData* const chunk_data, WebPInfo* const webp_info) { - const uint8_t* data = chunk_data->payload_; - size_t data_size = chunk_data->size_ - CHUNK_HEADER_SIZE; + const uint8_t* data = chunk_data->payload; + size_t data_size = chunk_data->size - CHUNK_HEADER_SIZE; if (data_size <= ALPHA_HEADER_LEN) { LOG_ERROR("Truncated ALPH chunk."); return WEBP_INFO_TRUNCATED_DATA; @@ -607,14 +607,14 @@ static WebPInfoStatus ParseRIFFHeader(WebPInfo* const webp_info, return WEBP_INFO_PARSE_ERROR; } riff_size += CHUNK_HEADER_SIZE; - if (!webp_info->quiet_) { + if (!webp_info->quiet) { printf("RIFF HEADER:\n"); 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."); - mem->end_ = riff_size; - } else if (riff_size > mem->end_) { + mem->end = riff_size; + } else if (riff_size > mem->end) { LOG_ERROR("Truncated data detected when parsing RIFF payload."); 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."); return WEBP_INFO_TRUNCATED_DATA; } 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 payload_size = ReadMemBufLE32(mem); 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) { if (kWebPChunkTags[i] == fourcc) break; } - chunk_data->offset_ = chunk_start_offset; - chunk_data->size_ = chunk_size; - chunk_data->id_ = (ChunkID)i; - chunk_data->payload_ = GetBuffer(mem); - if (chunk_data->id_ == CHUNK_ANMF) { + chunk_data->offset = chunk_start_offset; + chunk_data->size = chunk_size; + chunk_data->id = (ChunkID)i; + chunk_data->payload = GetBuffer(mem); + if (chunk_data->id == CHUNK_ANMF) { if (payload_size != payload_size_padded) { LOG_ERROR("ANMF chunk size should always be even."); 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, WebPInfo* const webp_info) { - const uint8_t* data = chunk_data->payload_; - if (webp_info->chunk_counts_[CHUNK_VP8] || - webp_info->chunk_counts_[CHUNK_VP8L] || - webp_info->chunk_counts_[CHUNK_VP8X]) { + const uint8_t* data = chunk_data->payload; + if (webp_info->chunk_counts[CHUNK_VP8] || + webp_info->chunk_counts[CHUNK_VP8L] || + webp_info->chunk_counts[CHUNK_VP8X]) { LOG_ERROR("Already seen a VP8/VP8L/VP8X chunk when parsing VP8X chunk."); 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."); return WEBP_INFO_PARSE_ERROR; } - ++webp_info->chunk_counts_[CHUNK_VP8X]; - webp_info->feature_flags_ = *data; + ++webp_info->chunk_counts[CHUNK_VP8X]; + webp_info->feature_flags = *data; data += 4; - webp_info->canvas_width_ = 1 + ReadLE24(&data); - webp_info->canvas_height_ = 1 + ReadLE24(&data); - if (!webp_info->quiet_) { + webp_info->canvas_width = 1 + ReadLE24(&data); + webp_info->canvas_height = 1 + ReadLE24(&data); + if (!webp_info->quiet) { 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_ & ALPHA_FLAG) != 0, - (webp_info->feature_flags_ & EXIF_FLAG) != 0, - (webp_info->feature_flags_ & XMP_FLAG) != 0, - (webp_info->feature_flags_ & ANIMATION_FLAG) != 0); + (webp_info->feature_flags & ICCP_FLAG) != 0, + (webp_info->feature_flags & ALPHA_FLAG) != 0, + (webp_info->feature_flags & EXIF_FLAG) != 0, + (webp_info->feature_flags & XMP_FLAG) != 0, + (webp_info->feature_flags & ANIMATION_FLAG) != 0); 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."); } - 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."); } - 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) { 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, WebPInfo* const webp_info) { - const uint8_t* data = chunk_data->payload_; - if (!webp_info->chunk_counts_[CHUNK_VP8X]) { + const uint8_t* data = chunk_data->payload; + if (!webp_info->chunk_counts[CHUNK_VP8X]) { LOG_ERROR("ANIM chunk detected before VP8X chunk."); 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."); return WEBP_INFO_PARSE_ERROR; } - webp_info->bgcolor_ = ReadLE32(&data); - webp_info->loop_count_ = ReadLE16(&data); - ++webp_info->chunk_counts_[CHUNK_ANIM]; - if (!webp_info->quiet_) { + webp_info->bgcolor = ReadLE32(&data); + webp_info->loop_count = ReadLE16(&data); + ++webp_info->chunk_counts[CHUNK_ANIM]; + if (!webp_info->quiet) { printf(" Background color:(ARGB) %02x %02x %02x %02x\n", - (webp_info->bgcolor_ >> 24) & 0xff, - (webp_info->bgcolor_ >> 16) & 0xff, - (webp_info->bgcolor_ >> 8) & 0xff, - webp_info->bgcolor_ & 0xff); - printf(" Loop count : %d\n", webp_info->loop_count_); + (webp_info->bgcolor >> 24) & 0xff, + (webp_info->bgcolor >> 16) & 0xff, + (webp_info->bgcolor >> 8) & 0xff, + webp_info->bgcolor & 0xff); + 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."); } return WEBP_INFO_OK; @@ -739,17 +739,17 @@ static WebPInfoStatus ProcessANIMChunk(const ChunkData* const chunk_data, static WebPInfoStatus ProcessANMFChunk(const ChunkData* const chunk_data, 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; - if (webp_info->is_processing_anim_frame_) { + if (webp_info->is_processing_anim_frame) { LOG_ERROR("ANMF chunk detected within another ANMF chunk."); 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."); 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."); return WEBP_INFO_TRUNCATED_DATA; } @@ -761,8 +761,8 @@ static WebPInfoStatus ProcessANMFChunk(const ChunkData* const chunk_data, temp = *data; dispose = temp & 1; blend = (temp >> 1) & 1; - ++webp_info->chunk_counts_[CHUNK_ANMF]; - if (!webp_info->quiet_) { + ++webp_info->chunk_counts[CHUNK_ANMF]; + if (!webp_info->quiet) { printf(" Offset_X: %d\n Offset_Y: %d\n Width: %d\n Height: %d\n" " Duration: %d\n Dispose: %d\n Blend: %d\n", 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."); return WEBP_INFO_INVALID_PARAM; } - if ((uint64_t)offset_x + width > (uint64_t)webp_info->canvas_width_ || - (uint64_t)offset_y + height > (uint64_t)webp_info->canvas_height_) { + if ((uint64_t)offset_x + width > (uint64_t)webp_info->canvas_width || + (uint64_t)offset_y + height > (uint64_t)webp_info->canvas_height) { LOG_ERROR("Frame exceeds canvas in ANMF chunk."); return WEBP_INFO_INVALID_PARAM; } - webp_info->is_processing_anim_frame_ = 1; - webp_info->seen_alpha_subchunk_ = 0; - webp_info->seen_image_subchunk_ = 0; - webp_info->frame_width_ = width; - webp_info->frame_height_ = height; - webp_info->anim_frame_data_size_ = - chunk_data->size_ - CHUNK_HEADER_SIZE - ANMF_CHUNK_SIZE; + webp_info->is_processing_anim_frame = 1; + webp_info->seen_alpha_subchunk = 0; + webp_info->seen_image_subchunk = 0; + webp_info->frame_width = width; + webp_info->frame_height = height; + webp_info->anim_frame_data_size = + chunk_data->size - CHUNK_HEADER_SIZE - ANMF_CHUNK_SIZE; return WEBP_INFO_OK; } static WebPInfoStatus ProcessImageChunk(const ChunkData* const chunk_data, 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; const VP8StatusCode vp8_status = - WebPGetFeatures(data, chunk_data->size_, &features); + WebPGetFeatures(data, chunk_data->size, &features); if (vp8_status != VP8_STATUS_OK) { LOG_ERROR("VP8/VP8L bitstream error."); return WEBP_INFO_BITSTREAM_ERROR; } - if (!webp_info->quiet_) { + if (!webp_info->quiet) { assert(features.format >= 0 && features.format <= 2); printf(" Width: %d\n Height: %d\n Alpha: %d\n Animation: %d\n" " Format: %s (%d)\n", features.width, features.height, features.has_alpha, features.has_animation, kFormats[features.format], features.format); } - if (webp_info->is_processing_anim_frame_) { - ++webp_info->anmf_subchunk_counts_[chunk_data->id_ == CHUNK_VP8 ? 0 : 1]; - if (chunk_data->id_ == CHUNK_VP8L && webp_info->seen_alpha_subchunk_) { + if (webp_info->is_processing_anim_frame) { + ++webp_info->anmf_subchunk_counts[chunk_data->id == CHUNK_VP8 ? 0 : 1]; + 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."); return WEBP_INFO_PARSE_ERROR; } - if (webp_info->frame_width_ != features.width || - webp_info->frame_height_ != features.height) { + if (webp_info->frame_width != features.width || + webp_info->frame_height != features.height) { LOG_ERROR("Frame size in VP8/VP8L sub-chunk differs from ANMF header."); 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."); return WEBP_INFO_PARSE_ERROR; } - webp_info->seen_image_subchunk_ = 1; + webp_info->seen_image_subchunk = 1; } else { - if (webp_info->chunk_counts_[CHUNK_VP8] || - webp_info->chunk_counts_[CHUNK_VP8L]) { + if (webp_info->chunk_counts[CHUNK_VP8] || + webp_info->chunk_counts[CHUNK_VP8L]) { LOG_ERROR("Multiple VP8/VP8L chunks detected."); return WEBP_INFO_PARSE_ERROR; } - if (chunk_data->id_ == CHUNK_VP8L && - webp_info->chunk_counts_[CHUNK_ALPHA]) { + if (chunk_data->id == CHUNK_VP8L && + webp_info->chunk_counts[CHUNK_ALPHA]) { LOG_WARN("Both VP8L and ALPH chunks are detected."); } - if (webp_info->chunk_counts_[CHUNK_ANIM] || - webp_info->chunk_counts_[CHUNK_ANMF]) { + if (webp_info->chunk_counts[CHUNK_ANIM] || + webp_info->chunk_counts[CHUNK_ANMF]) { LOG_ERROR("VP8/VP8L chunk and ANIM/ANMF chunk are both detected."); return WEBP_INFO_PARSE_ERROR; } - if (webp_info->chunk_counts_[CHUNK_VP8X]) { - if (webp_info->canvas_width_ != features.width || - webp_info->canvas_height_ != features.height) { + if (webp_info->chunk_counts[CHUNK_VP8X]) { + if (webp_info->canvas_width != features.width || + webp_info->canvas_height != features.height) { LOG_ERROR("Image size in VP8/VP8L chunk differs from VP8X chunk."); return WEBP_INFO_PARSE_ERROR; } } else { - webp_info->canvas_width_ = features.width; - webp_info->canvas_height_ = features.height; - if (webp_info->canvas_width_ < 1 || webp_info->canvas_height_ < 1 || - webp_info->canvas_width_ > MAX_CANVAS_SIZE || - webp_info->canvas_height_ > MAX_CANVAS_SIZE || - (uint64_t)webp_info->canvas_width_ * webp_info->canvas_height_ > + webp_info->canvas_width = features.width; + webp_info->canvas_height = features.height; + if (webp_info->canvas_width < 1 || webp_info->canvas_height < 1 || + webp_info->canvas_width > MAX_CANVAS_SIZE || + webp_info->canvas_height > MAX_CANVAS_SIZE || + (uint64_t)webp_info->canvas_width * webp_info->canvas_height > MAX_IMAGE_AREA) { 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->has_alpha_ |= features.has_alpha; - if (webp_info->parse_bitstream_) { - const int is_lossy = (chunk_data->id_ == CHUNK_VP8); + ++webp_info->num_frames; + webp_info->has_alpha |= features.has_alpha; + if (webp_info->parse_bitstream) { + const int is_lossy = (chunk_data->id == CHUNK_VP8); const WebPInfoStatus status = is_lossy ? ParseLossyHeader(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, WebPInfo* const webp_info) { - if (webp_info->is_processing_anim_frame_) { - ++webp_info->anmf_subchunk_counts_[2]; - if (webp_info->seen_alpha_subchunk_) { + if (webp_info->is_processing_anim_frame) { + ++webp_info->anmf_subchunk_counts[2]; + if (webp_info->seen_alpha_subchunk) { LOG_ERROR("Consecutive ALPH sub-chunks in an ANMF chunk."); 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 " "in an ANMF chunk."); return WEBP_INFO_PARSE_ERROR; } } else { - if (webp_info->chunk_counts_[CHUNK_ANIM] || - webp_info->chunk_counts_[CHUNK_ANMF]) { + if (webp_info->chunk_counts[CHUNK_ANIM] || + webp_info->chunk_counts[CHUNK_ANMF]) { LOG_ERROR("ALPHA chunk and ANIM/ANMF chunk are both detected."); 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."); 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."); 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."); return WEBP_INFO_PARSE_ERROR; } - ++webp_info->chunk_counts_[CHUNK_ALPHA]; + ++webp_info->chunk_counts[CHUNK_ALPHA]; } - webp_info->has_alpha_ = 1; - if (webp_info->parse_bitstream_) { + webp_info->has_alpha = 1; + if (webp_info->parse_bitstream) { const WebPInfoStatus status = ParseAlphaHeader(chunk_data, webp_info); 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, WebPInfo* const webp_info) { (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."); return WEBP_INFO_PARSE_ERROR; } - if (webp_info->chunk_counts_[CHUNK_VP8] || - webp_info->chunk_counts_[CHUNK_VP8L] || - webp_info->chunk_counts_[CHUNK_ANIM]) { + if (webp_info->chunk_counts[CHUNK_VP8] || + webp_info->chunk_counts[CHUNK_VP8L] || + webp_info->chunk_counts[CHUNK_ANIM]) { LOG_ERROR("ICCP chunk detected after image data."); return WEBP_INFO_PARSE_ERROR; } - ++webp_info->chunk_counts_[CHUNK_ICCP]; + ++webp_info->chunk_counts[CHUNK_ICCP]; return WEBP_INFO_OK; } static WebPInfoStatus ProcessChunk(const ChunkData* const chunk_data, WebPInfo* const webp_info) { WebPInfoStatus status = WEBP_INFO_OK; - ChunkID id = chunk_data->id_; - if (chunk_data->id_ == CHUNK_UNKNOWN) { + ChunkID id = chunk_data->id; + if (chunk_data->id == CHUNK_UNKNOWN) { char error_message[50]; 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); } else { - if (!webp_info->quiet_) { + if (!webp_info->quiet) { char tag[4]; - uint32_t fourcc = kWebPChunkTags[chunk_data->id_]; + uint32_t fourcc = kWebPChunkTags[chunk_data->id]; #ifdef WORDS_BIGENDIAN fourcc = (fourcc >> 24) | ((fourcc >> 8) & 0xff00) | ((fourcc << 8) & 0xff0000) | (fourcc << 24); #endif memcpy(tag, &fourcc, sizeof(tag)); printf("Chunk %c%c%c%c at offset %6d, length %6d\n", - tag[0], tag[1], tag[2], tag[3], (int)chunk_data->offset_, - (int)chunk_data->size_); + tag[0], tag[1], tag[2], tag[3], (int)chunk_data->offset, + (int)chunk_data->size); } } switch (id) { @@ -974,21 +974,21 @@ static WebPInfoStatus ProcessChunk(const ChunkData* const chunk_data, break; case CHUNK_EXIF: case CHUNK_XMP: - ++webp_info->chunk_counts_[id]; + ++webp_info->chunk_counts[id]; break; case CHUNK_UNKNOWN: default: break; } - if (webp_info->is_processing_anim_frame_ && id != CHUNK_ANMF) { - if (webp_info->anim_frame_data_size_ == chunk_data->size_) { - if (!webp_info->seen_image_subchunk_) { + if (webp_info->is_processing_anim_frame && id != CHUNK_ANMF) { + if (webp_info->anim_frame_data_size == chunk_data->size) { + if (!webp_info->seen_image_subchunk) { LOG_ERROR("No VP8/VP8L chunk detected in an ANMF chunk."); return WEBP_INFO_PARSE_ERROR; } - webp_info->is_processing_anim_frame_ = 0; - } else if (webp_info->anim_frame_data_size_ > chunk_data->size_) { - webp_info->anim_frame_data_size_ -= chunk_data->size_; + webp_info->is_processing_anim_frame = 0; + } else if (webp_info->anim_frame_data_size > chunk_data->size) { + webp_info->anim_frame_data_size -= chunk_data->size; } else { LOG_ERROR("Truncated data detected when parsing ANMF chunk."); return WEBP_INFO_TRUNCATED_DATA; @@ -998,55 +998,55 @@ static WebPInfoStatus ProcessChunk(const ChunkData* const chunk_data, } 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."); return WEBP_INFO_MISSING_DATA; } - if (webp_info->chunk_counts_[CHUNK_VP8X]) { - const int iccp = !!(webp_info->feature_flags_ & ICCP_FLAG); - const int exif = !!(webp_info->feature_flags_ & EXIF_FLAG); - const int xmp = !!(webp_info->feature_flags_ & XMP_FLAG); - const int animation = !!(webp_info->feature_flags_ & ANIMATION_FLAG); - const int alpha = !!(webp_info->feature_flags_ & ALPHA_FLAG); - if (!alpha && webp_info->has_alpha_) { + if (webp_info->chunk_counts[CHUNK_VP8X]) { + const int iccp = !!(webp_info->feature_flags & ICCP_FLAG); + const int exif = !!(webp_info->feature_flags & EXIF_FLAG); + const int xmp = !!(webp_info->feature_flags & XMP_FLAG); + const int animation = !!(webp_info->feature_flags & ANIMATION_FLAG); + const int alpha = !!(webp_info->feature_flags & ALPHA_FLAG); + if (!alpha && webp_info->has_alpha) { LOG_ERROR("Unexpected alpha data detected."); 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."); } - if (iccp && !webp_info->chunk_counts_[CHUNK_ICCP]) { + if (iccp && !webp_info->chunk_counts[CHUNK_ICCP]) { LOG_ERROR("Missing ICCP chunk."); 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."); 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."); 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."); 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."); 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."); return WEBP_INFO_PARSE_ERROR; } // Incomplete animation frame. - if (webp_info->is_processing_anim_frame_) return WEBP_INFO_MISSING_DATA; - if (!animation && webp_info->num_frames_ > 1) { + if (webp_info->is_processing_anim_frame) return WEBP_INFO_MISSING_DATA; + if (!animation && webp_info->num_frames > 1) { LOG_ERROR("More than 1 frame detected in non-animation file."); return WEBP_INFO_PARSE_ERROR; } - if (animation && (!webp_info->chunk_counts_[CHUNK_ANIM] || - !webp_info->chunk_counts_[CHUNK_ANMF])) { + if (animation && (!webp_info->chunk_counts[CHUNK_ANIM] || + !webp_info->chunk_counts[CHUNK_ANMF])) { LOG_ERROR("No ANIM/ANMF chunk detected in animation file."); return WEBP_INFO_PARSE_ERROR; } @@ -1057,17 +1057,17 @@ static WebPInfoStatus Validate(WebPInfo* const webp_info) { static void ShowSummary(const WebPInfo* const webp_info) { int i; 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 " "EXIF XMP\n"); printf("Chunk counts: "); 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) { printf("%4d %4d %4d ", - webp_info->anmf_subchunk_counts_[0], - webp_info->anmf_subchunk_counts_[1], - webp_info->anmf_subchunk_counts_[2]); + webp_info->anmf_subchunk_counts[0], + webp_info->anmf_subchunk_counts[1], + webp_info->anmf_subchunk_counts[2]); } } printf("\n"); @@ -1090,20 +1090,20 @@ static WebPInfoStatus AnalyzeWebP(WebPInfo* const webp_info, webp_info_status = ProcessChunk(&chunk_data, webp_info); } 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. webp_info_status = Validate(webp_info); Error: - if (!webp_info->quiet_) { + if (!webp_info->quiet) { if (webp_info_status == WEBP_INFO_OK) { printf("No error detected.\n"); } else { printf("Errors detected.\n"); } - if (webp_info->num_warnings_ > 0) { - printf("There were %d warning(s).\n", webp_info->num_warnings_); + if (webp_info->num_warnings > 0) { + printf("There were %d warning(s).\n", webp_info->num_warnings); } } return webp_info_status; @@ -1169,10 +1169,10 @@ int main(int argc, const char* argv[]) { WebPData webp_data; const W_CHAR* in_file = NULL; WebPInfoInit(&webp_info); - webp_info.quiet_ = quiet; - webp_info.show_diagnosis_ = show_diag; - webp_info.show_summary_ = show_summary; - webp_info.parse_bitstream_ = parse_bitstream; + webp_info.quiet = quiet; + webp_info.show_diagnosis = show_diag; + webp_info.show_summary = show_summary; + webp_info.parse_bitstream = parse_bitstream; in_file = GET_WARGV(argv, c); if (in_file == NULL || !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); 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); WebPDataClear(&webp_data); } diff --git a/examples/webpmux.c b/examples/webpmux.c index 49d72641..5a61b005 100644 --- a/examples/webpmux.c +++ b/examples/webpmux.c @@ -87,9 +87,9 @@ typedef enum { } FeatureSubType; typedef struct { - FeatureSubType subtype_; - const char* filename_; - const char* params_; + FeatureSubType subtype; + const char* filename; + const char* params; } FeatureArg; typedef enum { @@ -114,14 +114,14 @@ static const char* const kDescriptions[LAST_FEATURE] = { }; typedef struct { - CommandLineArguments cmd_args_; + CommandLineArguments cmd_args; - ActionType action_type_; - const char* input_; - const char* output_; - FeatureType type_; - FeatureArg* args_; - int arg_count_; + ActionType action_type; + const char* input; + const char* output; + FeatureType type; + FeatureArg* args; + int arg_count; } Config; //------------------------------------------------------------------------------ @@ -132,8 +132,8 @@ static int CountOccurrences(const CommandLineArguments* const args, int i; int num_occurences = 0; - for (i = 0; i < args->argc_; ++i) { - if (!strcmp(args->argv_[i], arg)) { + for (i = 0; i < args->argc; ++i) { + if (!strcmp(args->argv[i], arg)) { ++num_occurences; } } @@ -527,8 +527,8 @@ static int ParseBgcolorArgs(const char* args, uint32_t* const bgcolor) { static void DeleteConfig(Config* const config) { if (config != NULL) { - free(config->args_); - ExUtilDeleteCommandLineArguments(&config->cmd_args_); + free(config->args); + ExUtilDeleteCommandLineArguments(&config->cmd_args); memset(config, 0, sizeof(*config)); } } @@ -605,9 +605,9 @@ static int ValidateCommandLine(const CommandLineArguments* const cmd_args, 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) \ do { \ @@ -637,98 +637,98 @@ static int ParseCommandLine(Config* config, const W_CHAR** const unicode_argv) { int i = 0; int feature_arg_index = 0; int ok = 1; - int argc = config->cmd_args_.argc_; - const char* const* argv = config->cmd_args_.argv_; + int argc = config->cmd_args.argc; + const char* const* argv = config->cmd_args.argv; // Unicode file paths will be used if available. const char* const* wargv = (unicode_argv != NULL) ? (const char**)(unicode_argv + 1) : argv; 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 (!strcmp(argv[i], "-set")) { if (ACTION_IS_NIL) { - config->action_type_ = ACTION_SET; + config->action_type = ACTION_SET; } else { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } ++i; } else if (!strcmp(argv[i], "-duration")) { CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); - if (ACTION_IS_NIL || config->action_type_ == ACTION_DURATION) { - config->action_type_ = ACTION_DURATION; + if (ACTION_IS_NIL || config->action_type == ACTION_DURATION) { + config->action_type = ACTION_DURATION; } else { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } - if (FEATURETYPE_IS_NIL || config->type_ == FEATURE_DURATION) { - config->type_ = FEATURE_DURATION; + if (FEATURETYPE_IS_NIL || config->type == FEATURE_DURATION) { + config->type = FEATURE_DURATION; } else { ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse); } - arg->params_ = argv[i + 1]; + arg->params = argv[i + 1]; ++feature_arg_index; i += 2; } else if (!strcmp(argv[i], "-get")) { if (ACTION_IS_NIL) { - config->action_type_ = ACTION_GET; + config->action_type = ACTION_GET; } else { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } ++i; } else if (!strcmp(argv[i], "-strip")) { if (ACTION_IS_NIL) { - config->action_type_ = ACTION_STRIP; - config->arg_count_ = 0; + config->action_type = ACTION_STRIP; + config->arg_count = 0; } else { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } ++i; } else if (!strcmp(argv[i], "-frame")) { CHECK_NUM_ARGS_AT_LEAST(3, ErrParse); - if (ACTION_IS_NIL || config->action_type_ == ACTION_SET) { - config->action_type_ = ACTION_SET; + if (ACTION_IS_NIL || config->action_type == ACTION_SET) { + config->action_type = ACTION_SET; } else { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } - if (FEATURETYPE_IS_NIL || config->type_ == FEATURE_ANMF) { - config->type_ = FEATURE_ANMF; + if (FEATURETYPE_IS_NIL || config->type == FEATURE_ANMF) { + config->type = FEATURE_ANMF; } else { ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse); } - arg->subtype_ = SUBTYPE_ANMF; - arg->filename_ = wargv[i + 1]; - arg->params_ = argv[i + 2]; + arg->subtype = SUBTYPE_ANMF; + arg->filename = wargv[i + 1]; + arg->params = argv[i + 2]; ++feature_arg_index; i += 3; } else if (!strcmp(argv[i], "-loop") || !strcmp(argv[i], "-bgcolor")) { CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); - if (ACTION_IS_NIL || config->action_type_ == ACTION_SET) { - config->action_type_ = ACTION_SET; + if (ACTION_IS_NIL || config->action_type == ACTION_SET) { + config->action_type = ACTION_SET; } else { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } - if (FEATURETYPE_IS_NIL || config->type_ == FEATURE_ANMF) { - config->type_ = FEATURE_ANMF; + if (FEATURETYPE_IS_NIL || config->type == FEATURE_ANMF) { + config->type = FEATURE_ANMF; } else { ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse); } - arg->subtype_ = + arg->subtype = !strcmp(argv[i], "-loop") ? SUBTYPE_LOOP : SUBTYPE_BGCOLOR; - arg->params_ = argv[i + 1]; + arg->params = argv[i + 1]; ++feature_arg_index; i += 2; } else if (!strcmp(argv[i], "-o")) { CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); - config->output_ = wargv[i + 1]; + config->output = wargv[i + 1]; i += 2; } else if (!strcmp(argv[i], "-info")) { 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); } else { - config->action_type_ = ACTION_INFO; - config->arg_count_ = 0; - config->input_ = wargv[i + 1]; + config->action_type = ACTION_INFO; + config->arg_count = 0; + config->input = wargv[i + 1]; } i += 2; } 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], "--")) { if (i < argc - 1) { ++i; - if (config->input_ == NULL) { - config->input_ = wargv[i]; + if (config->input == NULL) { + config->input = wargv[i]; } else { ERROR_GOTO2("ERROR at '%s': Multiple input files specified.\n", 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") || !strcmp(argv[i], "xmp")) { 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; } else { 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); - arg->filename_ = wargv[i + 1]; + arg->filename = wargv[i + 1]; ++feature_arg_index; i += 2; } else { ++i; } } else if (!strcmp(argv[i], "frame") && - (config->action_type_ == ACTION_GET)) { + (config->action_type == ACTION_GET)) { CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); - config->type_ = FEATURE_ANMF; - arg->params_ = argv[i + 1]; + config->type = FEATURE_ANMF; + arg->params = argv[i + 1]; ++feature_arg_index; i += 2; } else if (!strcmp(argv[i], "loop") && - (config->action_type_ == ACTION_SET)) { + (config->action_type == ACTION_SET)) { CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); - config->type_ = FEATURE_LOOP; - arg->params_ = argv[i + 1]; + config->type = FEATURE_LOOP; + arg->params = argv[i + 1]; ++feature_arg_index; i += 2; } else if (!strcmp(argv[i], "bgcolor") && - (config->action_type_ == ACTION_SET)) { + (config->action_type == ACTION_SET)) { CHECK_NUM_ARGS_AT_LEAST(2, ErrParse); - config->type_ = FEATURE_BGCOLOR; - arg->params_ = argv[i + 1]; + config->type = FEATURE_BGCOLOR; + arg->params = argv[i + 1]; ++feature_arg_index; i += 2; } else { // Assume input file. - if (config->input_ == NULL) { - config->input_ = wargv[i]; + if (config->input == NULL) { + config->input = wargv[i]; } else { ERROR_GOTO2("ERROR at '%s': Multiple input files specified.\n", argv[i], ErrParse); @@ -824,21 +824,21 @@ static int ValidateConfig(Config* const config) { } // 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); } // Input file. - if (config->input_ == NULL) { - if (config->action_type_ != ACTION_SET) { + if (config->input == NULL) { + if (config->action_type != ACTION_SET) { 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); } } // 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); } @@ -854,17 +854,17 @@ static int InitializeConfig(int argc, const char* argv[], Config* const config, memset(config, 0, sizeof(*config)); - ok = ExUtilInitCommandLineArguments(argc, argv, &config->cmd_args_); + ok = ExUtilInitCommandLineArguments(argc, argv, &config->cmd_args); if (!ok) return 0; // 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); } - config->arg_count_ = num_feature_args; - config->args_ = (FeatureArg*)calloc(num_feature_args, sizeof(*config->args_)); - if (config->args_ == NULL) { + config->arg_count = num_feature_args; + config->args = (FeatureArg*)calloc(num_feature_args, sizeof(*config->args)); + if (config->args == NULL) { ERROR_GOTO1("ERROR: Memory allocation error.\n", Err1); } @@ -896,7 +896,7 @@ static int GetFrame(const WebPMux* mux, const Config* config) { WebPMuxFrameInfo info; WebPDataInit(&info.bitstream); - num = ExUtilGetInt(config->args_[0].params_, 10, &parse_error); + num = ExUtilGetInt(config->args[0].params, 10, &parse_error); if (num < 0) { 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); } - ok = WriteWebP(mux_single, config->output_); + ok = WriteWebP(mux_single, config->output); ErrGet: WebPDataClear(&info.bitstream); @@ -936,11 +936,11 @@ static int Process(const Config* config) { WebPMuxError err = WEBP_MUX_OK; int ok = 1; - switch (config->action_type_) { + switch (config->action_type) { case ACTION_GET: { - ok = CreateMux(config->input_, &mux); + ok = CreateMux(config->input, &mux); if (!ok) goto Err2; - switch (config->type_) { + switch (config->type) { case FEATURE_ANMF: ok = GetFrame(mux, config); break; @@ -948,12 +948,12 @@ static int Process(const Config* config) { case FEATURE_ICCP: case FEATURE_EXIF: case FEATURE_XMP: - err = WebPMuxGetChunk(mux, kFourccList[config->type_], &chunk); + err = WebPMuxGetChunk(mux, kFourccList[config->type], &chunk); if (err != WEBP_MUX_OK) { 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; default: @@ -963,7 +963,7 @@ static int Process(const Config* config) { break; } case ACTION_SET: { - switch (config->type_) { + switch (config->type) { case FEATURE_ANMF: { int i; 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", ErrorString(WEBP_MUX_MEMORY_ERROR), Err2); } - for (i = 0; i < config->arg_count_; ++i) { - switch (config->args_[i].subtype_) { + for (i = 0; i < config->arg_count; ++i) { + switch (config->args[i].subtype) { case SUBTYPE_BGCOLOR: { uint32_t bgcolor; - ok = ParseBgcolorArgs(config->args_[i].params_, &bgcolor); + ok = ParseBgcolorArgs(config->args[i].params, &bgcolor); if (!ok) { ERROR_GOTO1("ERROR: Could not parse the background color \n", Err2); @@ -987,7 +987,7 @@ static int Process(const Config* config) { case SUBTYPE_LOOP: { int parse_error = 0; 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) { // Note: This is only a 'necessary' condition for loop_count // to be valid. The 'sufficient' conditioned in checked in @@ -1003,10 +1003,10 @@ static int Process(const Config* config) { case SUBTYPE_ANMF: { WebPMuxFrameInfo frame; frame.id = WEBP_CHUNK_ANMF; - ok = ExUtilReadFileToWebPData(config->args_[i].filename_, + ok = ExUtilReadFileToWebPData(config->args[i].filename, &frame.bitstream); if (!ok) goto Err2; - ok = ParseFrameArgs(config->args_[i].params_, &frame); + ok = ParseFrameArgs(config->args[i].params, &frame); if (!ok) { WebPDataClear(&frame.bitstream); ERROR_GOTO1("ERROR: Could not parse frame properties.\n", @@ -1037,15 +1037,15 @@ static int Process(const Config* config) { case FEATURE_ICCP: case FEATURE_EXIF: case FEATURE_XMP: { - ok = CreateMux(config->input_, &mux); + ok = CreateMux(config->input, &mux); if (!ok) goto Err2; - ok = ExUtilReadFileToWebPData(config->args_[0].filename_, &chunk); + ok = ExUtilReadFileToWebPData(config->args[0].filename, &chunk); if (!ok) goto Err2; - err = WebPMuxSetChunk(mux, kFourccList[config->type_], &chunk, 1); + err = WebPMuxSetChunk(mux, kFourccList[config->type], &chunk, 1); WebPDataClear(&chunk); if (err != WEBP_MUX_OK) { ERROR_GOTO3("ERROR (%s): Could not set the %s.\n", - ErrorString(err), kDescriptions[config->type_], Err2); + ErrorString(err), kDescriptions[config->type], Err2); } break; } @@ -1053,12 +1053,12 @@ static int Process(const Config* config) { WebPMuxAnimParams params = { 0xFFFFFFFF, 0 }; int parse_error = 0; 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) { ERROR_GOTO1("ERROR: Loop count must be in the range 0 to 65535.\n", Err2); } - ok = CreateMux(config->input_, &mux); + ok = CreateMux(config->input, &mux); if (!ok) goto Err2; ok = (WebPMuxGetAnimationParams(mux, ¶ms) == WEBP_MUX_OK); if (!ok) { @@ -1077,12 +1077,12 @@ static int Process(const Config* config) { case FEATURE_BGCOLOR: { WebPMuxAnimParams params = { 0xFFFFFFFF, 0 }; uint32_t bgcolor; - ok = ParseBgcolorArgs(config->args_[0].params_, &bgcolor); + ok = ParseBgcolorArgs(config->args[0].params, &bgcolor); if (!ok) { ERROR_GOTO1("ERROR: Could not parse the background color.\n", Err2); } - ok = CreateMux(config->input_, &mux); + ok = CreateMux(config->input, &mux); if (!ok) goto Err2; ok = (WebPMuxGetAnimationParams(mux, ¶ms) == WEBP_MUX_OK); if (!ok) { @@ -1103,12 +1103,12 @@ static int Process(const Config* config) { break; } } - ok = WriteWebP(mux, config->output_); + ok = WriteWebP(mux, config->output); break; } case ACTION_DURATION: { int num_frames; - ok = CreateMux(config->input_, &mux); + ok = CreateMux(config->input, &mux); if (!ok) goto Err2; err = WebPMuxNumChunks(mux, WEBP_CHUNK_ANMF, &num_frames); ok = (err == WEBP_MUX_OK); @@ -1118,7 +1118,7 @@ static int Process(const Config* config) { if (num_frames == 0) { fprintf(stderr, "Doesn't look like the source is animated. " "Skipping duration setting.\n"); - ok = WriteWebP(mux, config->output_); + ok = WriteWebP(mux, config->output); if (!ok) goto Err2; } else { int i; @@ -1130,11 +1130,11 @@ static int Process(const Config* config) { for (i = 0; i < num_frames; ++i) durations[i] = -1; // Parse intervals to process. - for (i = 0; i < config->arg_count_; ++i) { + for (i = 0; i < config->arg_count; ++i) { int k; int args[3]; 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); ok = (nb_args >= 1); if (!ok) goto Err3; @@ -1178,7 +1178,7 @@ static int Process(const Config* config) { WebPDataClear(&frame.bitstream); } WebPMuxDelete(mux); - ok = WriteWebP(new_mux, config->output_); + ok = WriteWebP(new_mux, config->output); mux = new_mux; // transfer for the WebPMuxDelete() call new_mux = NULL; @@ -1190,24 +1190,24 @@ static int Process(const Config* config) { break; } case ACTION_STRIP: { - ok = CreateMux(config->input_, &mux); + ok = CreateMux(config->input, &mux); if (!ok) goto Err2; - if (config->type_ == FEATURE_ICCP || config->type_ == FEATURE_EXIF || - config->type_ == FEATURE_XMP) { - err = WebPMuxDeleteChunk(mux, kFourccList[config->type_]); + if (config->type == FEATURE_ICCP || config->type == FEATURE_EXIF || + config->type == FEATURE_XMP) { + err = WebPMuxDeleteChunk(mux, kFourccList[config->type]); if (err != WEBP_MUX_OK) { ERROR_GOTO3("ERROR (%s): Could not strip the %s.\n", - ErrorString(err), kDescriptions[config->type_], Err2); + ErrorString(err), kDescriptions[config->type], Err2); } } else { ERROR_GOTO1("ERROR: Invalid feature for action 'strip'.\n", Err2); break; } - ok = WriteWebP(mux, config->output_); + ok = WriteWebP(mux, config->output); break; } case ACTION_INFO: { - ok = CreateMux(config->input_, &mux); + ok = CreateMux(config->input, &mux); if (!ok) goto Err2; ok = (DisplayInfo(mux) == WEBP_MUX_OK); break; diff --git a/tests/fuzzer/webp_info_fuzzer.cc b/tests/fuzzer/webp_info_fuzzer.cc index 3b1c7f2e..881fdfa7 100644 --- a/tests/fuzzer/webp_info_fuzzer.cc +++ b/tests/fuzzer/webp_info_fuzzer.cc @@ -28,10 +28,10 @@ void WebPInfoTest(std::string_view data) { WebPInfo webp_info; WebPInfoInit(&webp_info); - webp_info.quiet_ = 1; - webp_info.show_summary_ = 0; - webp_info.show_diagnosis_ = 0; - webp_info.parse_bitstream_ = 1; + webp_info.quiet = 1; + webp_info.show_summary = 0; + webp_info.show_diagnosis = 0; + webp_info.parse_bitstream = 1; WebPData webp_data = {reinterpret_cast(data.data()), data.size()}; AnalyzeWebP(&webp_info, &webp_data);