diff --git a/src/mux/anim_encode.c b/src/mux/anim_encode.c index deeb414a..031c7668 100644 --- a/src/mux/anim_encode.c +++ b/src/mux/anim_encode.c @@ -35,70 +35,70 @@ // Stores frame rectangle dimensions. typedef struct { - int x_offset_, y_offset_, width_, height_; + int x_offset, y_offset, width, height; } FrameRectangle; // Used to store two candidates of encoded data for an animation frame. One of // the two will be chosen later. typedef struct { - WebPMuxFrameInfo sub_frame_; // Encoded frame rectangle. - WebPMuxFrameInfo key_frame_; // Encoded frame if it is a key-frame. - int is_key_frame_; // True if 'key_frame' has been chosen. + WebPMuxFrameInfo sub_frame; // Encoded frame rectangle. + WebPMuxFrameInfo key_frame; // Encoded frame if it is a key-frame. + int is_key_frame; // True if 'key_frame' has been chosen. } EncodedFrame; struct WebPAnimEncoder { - const int canvas_width_; // Canvas width. - const int canvas_height_; // Canvas height. - const WebPAnimEncoderOptions options_; // Global encoding options. + const int canvas_width; // Canvas width. + const int canvas_height; // Canvas height. + const WebPAnimEncoderOptions options; // Global encoding options. - FrameRectangle prev_rect_; // Previous WebP frame rectangle. - WebPConfig last_config_; // Cached in case a re-encode is needed. - WebPConfig last_config_reversed_; // If 'last_config_' uses lossless, then + FrameRectangle prev_rect; // Previous WebP frame rectangle. + WebPConfig last_config; // Cached in case a re-encode is needed. + WebPConfig last_config_reversed; // If 'last_config' uses lossless, then // this config uses lossy and vice versa; - // only valid if 'options_.allow_mixed' + // only valid if 'options.allow_mixed' // is true. - WebPPicture* curr_canvas_; // Only pointer; we don't own memory. + WebPPicture* curr_canvas; // Only pointer; we don't own memory. // Canvas buffers. - WebPPicture curr_canvas_copy_; // Possibly modified current canvas. - int curr_canvas_copy_modified_; // True if pixels in 'curr_canvas_copy_' - // differ from those in 'curr_canvas_'. + WebPPicture curr_canvas_copy; // Possibly modified current canvas. + int curr_canvas_copy_modified; // True if pixels in 'curr_canvas_copy' + // differ from those in 'curr_canvas'. - WebPPicture prev_canvas_; // Previous canvas. - WebPPicture prev_canvas_disposed_; // Previous canvas disposed to background. + WebPPicture prev_canvas; // Previous canvas. + WebPPicture prev_canvas_disposed; // Previous canvas disposed to background. // Encoded data. - EncodedFrame* encoded_frames_; // Array of encoded frames. - size_t size_; // Number of allocated frames. - size_t start_; // Frame start index. - size_t count_; // Number of valid frames. - size_t flush_count_; // If >0, 'flush_count' frames starting from + EncodedFrame* encoded_frames; // Array of encoded frames. + size_t size; // Number of allocated frames. + size_t start; // Frame start index. + size_t count; // Number of valid frames. + size_t flush_count; // If >0, 'flush_count' frames starting from // 'start' are ready to be added to mux. // key-frame related. - int64_t best_delta_; // min(canvas size - frame size) over the frames. + int64_t best_delta; // min(canvas size - frame size) over the frames. // Can be negative in certain cases due to // transparent pixels in a frame. - int keyframe_; // Index of selected key-frame relative to 'start_'. - int count_since_key_frame_; // Frames seen since the last key-frame. + int keyframe; // Index of selected key-frame relative to 'start'. + int count_since_key_frame; // Frames seen since the last key-frame. - int first_timestamp_; // Timestamp of the first frame. - int prev_timestamp_; // Timestamp of the last added frame. - int prev_candidate_undecided_; // True if it's not yet decided if previous + int first_timestamp; // Timestamp of the first frame. + int prev_timestamp; // Timestamp of the last added frame. + int prev_candidate_undecided; // True if it's not yet decided if previous // frame would be a sub-frame or a key-frame. // Misc. - int is_first_frame_; // True if first frame is yet to be added/being added. - int got_null_frame_; // True if WebPAnimEncoderAdd() has already been called + int is_first_frame; // True if first frame is yet to be added/being added. + int got_null_frame; // True if WebPAnimEncoderAdd() has already been called // with a NULL frame. - size_t in_frame_count_; // Number of input frames processed so far. - size_t out_frame_count_; // Number of frames added to mux so far. This may be - // different from 'in_frame_count_' due to merging. + size_t in_frame_count; // Number of input frames processed so far. + size_t out_frame_count; // Number of frames added to mux so far. This may be + // different from 'in_frame_count' due to merging. - WebPMux* mux_; // Muxer to assemble the WebP bitstream. - char error_str_[ERROR_STR_MAX_LENGTH]; // Error string. Empty if no error. + WebPMux* mux; // Muxer to assemble the WebP bitstream. + char error_str[ERROR_STR_MAX_LENGTH]; // Error string. Empty if no error. }; // ----------------------------------------------------------------------------- @@ -109,11 +109,11 @@ struct WebPAnimEncoder { // Reset the counters in the WebPAnimEncoder. static void ResetCounters(WebPAnimEncoder* const enc) { - enc->start_ = 0; - enc->count_ = 0; - enc->flush_count_ = 0; - enc->best_delta_ = DELTA_INFINITY; - enc->keyframe_ = KEYFRAME_NONE; + enc->start = 0; + enc->count = 0; + enc->flush_count = 0; + enc->best_delta = DELTA_INFINITY; + enc->keyframe = KEYFRAME_NONE; } static void DisableKeyframes(WebPAnimEncoderOptions* const enc_options) { @@ -210,26 +210,26 @@ static void ClearRectangle(WebPPicture* const picture, static void WebPUtilClearPic(WebPPicture* const picture, const FrameRectangle* const rect) { if (rect != NULL) { - ClearRectangle(picture, rect->x_offset_, rect->y_offset_, - rect->width_, rect->height_); + ClearRectangle(picture, rect->x_offset, rect->y_offset, + rect->width, rect->height); } else { ClearRectangle(picture, 0, 0, picture->width, picture->height); } } static void MarkNoError(WebPAnimEncoder* const enc) { - enc->error_str_[0] = '\0'; // Empty string. + enc->error_str[0] = '\0'; // Empty string. } static void MarkError(WebPAnimEncoder* const enc, const char* str) { - if (snprintf(enc->error_str_, ERROR_STR_MAX_LENGTH, "%s.", str) < 0) { + if (snprintf(enc->error_str, ERROR_STR_MAX_LENGTH, "%s.", str) < 0) { assert(0); // FIX ME! } } static void MarkError2(WebPAnimEncoder* const enc, const char* str, int error_code) { - if (snprintf(enc->error_str_, ERROR_STR_MAX_LENGTH, "%s: %d.", str, + if (snprintf(enc->error_str, ERROR_STR_MAX_LENGTH, "%s: %d.", str, error_code) < 0) { assert(0); // FIX ME! } @@ -253,52 +253,52 @@ WebPAnimEncoder* WebPAnimEncoderNewInternal( MarkNoError(enc); // Dimensions and options. - *(int*)&enc->canvas_width_ = width; - *(int*)&enc->canvas_height_ = height; + *(int*)&enc->canvas_width = width; + *(int*)&enc->canvas_height = height; if (enc_options != NULL) { - *(WebPAnimEncoderOptions*)&enc->options_ = *enc_options; - SanitizeEncoderOptions((WebPAnimEncoderOptions*)&enc->options_); + *(WebPAnimEncoderOptions*)&enc->options = *enc_options; + SanitizeEncoderOptions((WebPAnimEncoderOptions*)&enc->options); } else { - DefaultEncoderOptions((WebPAnimEncoderOptions*)&enc->options_); + DefaultEncoderOptions((WebPAnimEncoderOptions*)&enc->options); } // Canvas buffers. - if (!WebPPictureInit(&enc->curr_canvas_copy_) || - !WebPPictureInit(&enc->prev_canvas_) || - !WebPPictureInit(&enc->prev_canvas_disposed_)) { + if (!WebPPictureInit(&enc->curr_canvas_copy) || + !WebPPictureInit(&enc->prev_canvas) || + !WebPPictureInit(&enc->prev_canvas_disposed)) { goto Err; } - enc->curr_canvas_copy_.width = width; - enc->curr_canvas_copy_.height = height; - enc->curr_canvas_copy_.use_argb = 1; - if (!WebPPictureAlloc(&enc->curr_canvas_copy_) || - !WebPPictureCopy(&enc->curr_canvas_copy_, &enc->prev_canvas_) || - !WebPPictureCopy(&enc->curr_canvas_copy_, &enc->prev_canvas_disposed_)) { + enc->curr_canvas_copy.width = width; + enc->curr_canvas_copy.height = height; + enc->curr_canvas_copy.use_argb = 1; + if (!WebPPictureAlloc(&enc->curr_canvas_copy) || + !WebPPictureCopy(&enc->curr_canvas_copy, &enc->prev_canvas) || + !WebPPictureCopy(&enc->curr_canvas_copy, &enc->prev_canvas_disposed)) { goto Err; } - WebPUtilClearPic(&enc->prev_canvas_, NULL); - enc->curr_canvas_copy_modified_ = 1; + WebPUtilClearPic(&enc->prev_canvas, NULL); + enc->curr_canvas_copy_modified = 1; // Encoded frames. ResetCounters(enc); // Note: one extra storage is for the previous frame. - enc->size_ = enc->options_.kmax - enc->options_.kmin + 1; + enc->size = enc->options.kmax - enc->options.kmin + 1; // We need space for at least 2 frames. But when kmin, kmax are both zero, - // enc->size_ will be 1. So we handle that special case below. - if (enc->size_ < 2) enc->size_ = 2; - enc->encoded_frames_ = - (EncodedFrame*)WebPSafeCalloc(enc->size_, sizeof(*enc->encoded_frames_)); - if (enc->encoded_frames_ == NULL) goto Err; + // enc->size will be 1. So we handle that special case below. + if (enc->size < 2) enc->size = 2; + enc->encoded_frames = + (EncodedFrame*)WebPSafeCalloc(enc->size, sizeof(*enc->encoded_frames)); + if (enc->encoded_frames == NULL) goto Err; - enc->mux_ = WebPMuxNew(); - if (enc->mux_ == NULL) goto Err; + enc->mux = WebPMuxNew(); + if (enc->mux == NULL) goto Err; - enc->count_since_key_frame_ = 0; - enc->first_timestamp_ = 0; - enc->prev_timestamp_ = 0; - enc->prev_candidate_undecided_ = 0; - enc->is_first_frame_ = 1; - enc->got_null_frame_ = 0; + enc->count_since_key_frame = 0; + enc->first_timestamp = 0; + enc->prev_timestamp = 0; + enc->prev_candidate_undecided = 0; + enc->is_first_frame = 1; + enc->got_null_frame = 0; return enc; // All OK. @@ -310,25 +310,25 @@ WebPAnimEncoder* WebPAnimEncoderNewInternal( // Release the data contained by 'encoded_frame'. static void FrameRelease(EncodedFrame* const encoded_frame) { if (encoded_frame != NULL) { - WebPDataClear(&encoded_frame->sub_frame_.bitstream); - WebPDataClear(&encoded_frame->key_frame_.bitstream); + WebPDataClear(&encoded_frame->sub_frame.bitstream); + WebPDataClear(&encoded_frame->key_frame.bitstream); memset(encoded_frame, 0, sizeof(*encoded_frame)); } } void WebPAnimEncoderDelete(WebPAnimEncoder* enc) { if (enc != NULL) { - WebPPictureFree(&enc->curr_canvas_copy_); - WebPPictureFree(&enc->prev_canvas_); - WebPPictureFree(&enc->prev_canvas_disposed_); - if (enc->encoded_frames_ != NULL) { + WebPPictureFree(&enc->curr_canvas_copy); + WebPPictureFree(&enc->prev_canvas); + WebPPictureFree(&enc->prev_canvas_disposed); + if (enc->encoded_frames != NULL) { size_t i; - for (i = 0; i < enc->size_; ++i) { - FrameRelease(&enc->encoded_frames_[i]); + for (i = 0; i < enc->size; ++i) { + FrameRelease(&enc->encoded_frames[i]); } - WebPSafeFree(enc->encoded_frames_); + WebPSafeFree(enc->encoded_frames); } - WebPMuxDelete(enc->mux_); + WebPMuxDelete(enc->mux); WebPSafeFree(enc); } } @@ -339,8 +339,8 @@ void WebPAnimEncoderDelete(WebPAnimEncoder* enc) { // Returns cached frame at the given 'position'. static EncodedFrame* GetFrame(const WebPAnimEncoder* const enc, size_t position) { - assert(enc->start_ + position < enc->size_); - return &enc->encoded_frames_[enc->start_ + position]; + assert(enc->start + position < enc->size); + return &enc->encoded_frames[enc->start + position]; } typedef int (*ComparePixelsFunc)(const uint32_t*, int, const uint32_t*, int, @@ -400,7 +400,7 @@ static WEBP_INLINE int ComparePixelsLossy(const uint32_t* src, int src_step, } static int IsEmptyRect(const FrameRectangle* const rect) { - return (rect->width_ == 0) || (rect->height_ == 0); + return (rect->width == 0) || (rect->height == 0); } static int QualityToMaxDiff(float quality) { @@ -422,113 +422,113 @@ static void MinimizeChangeRectangle(const WebPPicture* const src, // Assumption/correctness checks. assert(src->width == dst->width && src->height == dst->height); - assert(rect->x_offset_ + rect->width_ <= dst->width); - assert(rect->y_offset_ + rect->height_ <= dst->height); + assert(rect->x_offset + rect->width <= dst->width); + assert(rect->y_offset + rect->height <= dst->height); // Left boundary. - for (i = rect->x_offset_; i < rect->x_offset_ + rect->width_; ++i) { + for (i = rect->x_offset; i < rect->x_offset + rect->width; ++i) { const uint32_t* const src_argb = - &src->argb[rect->y_offset_ * src->argb_stride + i]; + &src->argb[rect->y_offset * src->argb_stride + i]; const uint32_t* const dst_argb = - &dst->argb[rect->y_offset_ * dst->argb_stride + i]; + &dst->argb[rect->y_offset * dst->argb_stride + i]; if (compare_pixels(src_argb, src->argb_stride, dst_argb, dst->argb_stride, - rect->height_, max_allowed_diff)) { - --rect->width_; // Redundant column. - ++rect->x_offset_; + rect->height, max_allowed_diff)) { + --rect->width; // Redundant column. + ++rect->x_offset; } else { break; } } - if (rect->width_ == 0) goto NoChange; + if (rect->width == 0) goto NoChange; // Right boundary. - for (i = rect->x_offset_ + rect->width_ - 1; i >= rect->x_offset_; --i) { + for (i = rect->x_offset + rect->width - 1; i >= rect->x_offset; --i) { const uint32_t* const src_argb = - &src->argb[rect->y_offset_ * src->argb_stride + i]; + &src->argb[rect->y_offset * src->argb_stride + i]; const uint32_t* const dst_argb = - &dst->argb[rect->y_offset_ * dst->argb_stride + i]; + &dst->argb[rect->y_offset * dst->argb_stride + i]; if (compare_pixels(src_argb, src->argb_stride, dst_argb, dst->argb_stride, - rect->height_, max_allowed_diff)) { - --rect->width_; // Redundant column. + rect->height, max_allowed_diff)) { + --rect->width; // Redundant column. } else { break; } } - if (rect->width_ == 0) goto NoChange; + if (rect->width == 0) goto NoChange; // Top boundary. - for (j = rect->y_offset_; j < rect->y_offset_ + rect->height_; ++j) { + for (j = rect->y_offset; j < rect->y_offset + rect->height; ++j) { const uint32_t* const src_argb = - &src->argb[j * src->argb_stride + rect->x_offset_]; + &src->argb[j * src->argb_stride + rect->x_offset]; const uint32_t* const dst_argb = - &dst->argb[j * dst->argb_stride + rect->x_offset_]; - if (compare_pixels(src_argb, 1, dst_argb, 1, rect->width_, + &dst->argb[j * dst->argb_stride + rect->x_offset]; + if (compare_pixels(src_argb, 1, dst_argb, 1, rect->width, max_allowed_diff)) { - --rect->height_; // Redundant row. - ++rect->y_offset_; + --rect->height; // Redundant row. + ++rect->y_offset; } else { break; } } - if (rect->height_ == 0) goto NoChange; + if (rect->height == 0) goto NoChange; // Bottom boundary. - for (j = rect->y_offset_ + rect->height_ - 1; j >= rect->y_offset_; --j) { + for (j = rect->y_offset + rect->height - 1; j >= rect->y_offset; --j) { const uint32_t* const src_argb = - &src->argb[j * src->argb_stride + rect->x_offset_]; + &src->argb[j * src->argb_stride + rect->x_offset]; const uint32_t* const dst_argb = - &dst->argb[j * dst->argb_stride + rect->x_offset_]; - if (compare_pixels(src_argb, 1, dst_argb, 1, rect->width_, + &dst->argb[j * dst->argb_stride + rect->x_offset]; + if (compare_pixels(src_argb, 1, dst_argb, 1, rect->width, max_allowed_diff)) { - --rect->height_; // Redundant row. + --rect->height; // Redundant row. } else { break; } } - if (rect->height_ == 0) goto NoChange; + if (rect->height == 0) goto NoChange; if (IsEmptyRect(rect)) { NoChange: - rect->x_offset_ = 0; - rect->y_offset_ = 0; - rect->width_ = 0; - rect->height_ = 0; + rect->x_offset = 0; + rect->y_offset = 0; + rect->width = 0; + rect->height = 0; } } // Snap rectangle to even offsets (and adjust dimensions if needed). static WEBP_INLINE void SnapToEvenOffsets(FrameRectangle* const rect) { - rect->width_ += (rect->x_offset_ & 1); - rect->height_ += (rect->y_offset_ & 1); - rect->x_offset_ &= ~1; - rect->y_offset_ &= ~1; + rect->width += (rect->x_offset & 1); + rect->height += (rect->y_offset & 1); + rect->x_offset &= ~1; + rect->y_offset &= ~1; } typedef struct { - int should_try_; // Should try this set of parameters. - int empty_rect_allowed_; // Frame with empty rectangle can be skipped. - FrameRectangle rect_ll_; // Frame rectangle for lossless compression. - WebPPicture sub_frame_ll_; // Sub-frame pic for lossless compression. - FrameRectangle rect_lossy_; // Frame rectangle for lossy compression. - // Could be smaller than rect_ll_ as pixels + int should_try; // Should try this set of parameters. + int empty_rect_allowed; // Frame with empty rectangle can be skipped. + FrameRectangle rect_ll; // Frame rectangle for lossless compression. + WebPPicture sub_frame_ll; // Sub-frame pic for lossless compression. + FrameRectangle rect_lossy; // Frame rectangle for lossy compression. + // Could be smaller than 'rect_ll' as pixels // with small diffs can be ignored. - WebPPicture sub_frame_lossy_; // Sub-frame pic for lossless compression. + WebPPicture sub_frame_lossy; // Sub-frame pic for lossless compression. } SubFrameParams; static int SubFrameParamsInit(SubFrameParams* const params, int should_try, int empty_rect_allowed) { - params->should_try_ = should_try; - params->empty_rect_allowed_ = empty_rect_allowed; - if (!WebPPictureInit(¶ms->sub_frame_ll_) || - !WebPPictureInit(¶ms->sub_frame_lossy_)) { + params->should_try = should_try; + params->empty_rect_allowed = empty_rect_allowed; + if (!WebPPictureInit(¶ms->sub_frame_ll) || + !WebPPictureInit(¶ms->sub_frame_lossy)) { return 0; } return 1; } static void SubFrameParamsFree(SubFrameParams* const params) { - WebPPictureFree(¶ms->sub_frame_ll_); - WebPPictureFree(¶ms->sub_frame_lossy_); + WebPPictureFree(¶ms->sub_frame_ll); + WebPPictureFree(¶ms->sub_frame_lossy); } // Given previous and current canvas, picks the optimal rectangle for the @@ -551,16 +551,16 @@ static int GetSubRect(const WebPPicture* const prev_canvas, if (empty_rect_allowed) { // No need to get 'sub_frame'. return 1; } else { // Force a 1x1 rectangle. - rect->width_ = 1; - rect->height_ = 1; - assert(rect->x_offset_ == 0); - assert(rect->y_offset_ == 0); + rect->width = 1; + rect->height = 1; + assert(rect->x_offset == 0); + assert(rect->y_offset == 0); } } SnapToEvenOffsets(rect); - return WebPPictureView(curr_canvas, rect->x_offset_, rect->y_offset_, - rect->width_, rect->height_, sub_frame); + return WebPPictureView(curr_canvas, rect->x_offset, rect->y_offset, + rect->width, rect->height, sub_frame); } // Picks optimal frame rectangle for both lossless and lossy compression. The @@ -570,20 +570,20 @@ static int GetSubRects(const WebPPicture* const prev_canvas, int is_first_frame, float quality, SubFrameParams* const params) { // Lossless frame rectangle. - params->rect_ll_.x_offset_ = 0; - params->rect_ll_.y_offset_ = 0; - params->rect_ll_.width_ = curr_canvas->width; - params->rect_ll_.height_ = curr_canvas->height; + params->rect_ll.x_offset = 0; + params->rect_ll.y_offset = 0; + params->rect_ll.width = curr_canvas->width; + params->rect_ll.height = curr_canvas->height; if (!GetSubRect(prev_canvas, curr_canvas, is_key_frame, is_first_frame, - params->empty_rect_allowed_, 1, quality, - ¶ms->rect_ll_, ¶ms->sub_frame_ll_)) { + params->empty_rect_allowed, 1, quality, + ¶ms->rect_ll, ¶ms->sub_frame_ll)) { return 0; } // Lossy frame rectangle. - params->rect_lossy_ = params->rect_ll_; // seed with lossless rect. + params->rect_lossy = params->rect_ll; // seed with lossless rect. return GetSubRect(prev_canvas, curr_canvas, is_key_frame, is_first_frame, - params->empty_rect_allowed_, 0, quality, - ¶ms->rect_lossy_, ¶ms->sub_frame_lossy_); + params->empty_rect_allowed, 0, quality, + ¶ms->rect_lossy, ¶ms->sub_frame_lossy); } static WEBP_INLINE int clip(int v, int min_v, int max_v) { @@ -606,17 +606,17 @@ int WebPAnimEncoderRefineRect( left = clip(*x_offset, 0, curr_canvas->width - 1); bottom = clip(*y_offset + *height, 0, curr_canvas->height); top = clip(*y_offset, 0, curr_canvas->height - 1); - rect.x_offset_ = left; - rect.y_offset_ = top; - rect.width_ = clip(right - left, 0, curr_canvas->width - rect.x_offset_); - rect.height_ = clip(bottom - top, 0, curr_canvas->height - rect.y_offset_); + rect.x_offset = left; + rect.y_offset = top; + rect.width = clip(right - left, 0, curr_canvas->width - rect.x_offset); + rect.height = clip(bottom - top, 0, curr_canvas->height - rect.y_offset); MinimizeChangeRectangle(prev_canvas, curr_canvas, &rect, is_lossless, quality); SnapToEvenOffsets(&rect); - *x_offset = rect.x_offset_; - *y_offset = rect.y_offset_; - *width = rect.width_; - *height = rect.height_; + *x_offset = rect.x_offset; + *y_offset = rect.y_offset; + *width = rect.width; + *height = rect.height; return 1; } @@ -630,7 +630,7 @@ static void DisposeFrameRectangle(int dispose_method, } static uint32_t RectArea(const FrameRectangle* const rect) { - return (uint32_t)rect->width_ * rect->height_; + return (uint32_t)rect->width * rect->height; } static int IsLosslessBlendingPossible(const WebPPicture* const src, @@ -638,10 +638,10 @@ static int IsLosslessBlendingPossible(const WebPPicture* const src, const FrameRectangle* const rect) { int i, j; assert(src->width == dst->width && src->height == dst->height); - assert(rect->x_offset_ + rect->width_ <= dst->width); - assert(rect->y_offset_ + rect->height_ <= dst->height); - for (j = rect->y_offset_; j < rect->y_offset_ + rect->height_; ++j) { - for (i = rect->x_offset_; i < rect->x_offset_ + rect->width_; ++i) { + assert(rect->x_offset + rect->width <= dst->width); + assert(rect->y_offset + rect->height <= dst->height); + for (j = rect->y_offset; j < rect->y_offset + rect->height; ++j) { + for (i = rect->x_offset; i < rect->x_offset + rect->width; ++i) { const uint32_t src_pixel = src->argb[j * src->argb_stride + i]; const uint32_t dst_pixel = dst->argb[j * dst->argb_stride + i]; const uint32_t dst_alpha = dst_pixel >> 24; @@ -662,10 +662,10 @@ static int IsLossyBlendingPossible(const WebPPicture* const src, const int max_allowed_diff_lossy = QualityToMaxDiff(quality); int i, j; assert(src->width == dst->width && src->height == dst->height); - assert(rect->x_offset_ + rect->width_ <= dst->width); - assert(rect->y_offset_ + rect->height_ <= dst->height); - for (j = rect->y_offset_; j < rect->y_offset_ + rect->height_; ++j) { - for (i = rect->x_offset_; i < rect->x_offset_ + rect->width_; ++i) { + assert(rect->x_offset + rect->width <= dst->width); + assert(rect->y_offset + rect->height <= dst->height); + for (j = rect->y_offset; j < rect->y_offset + rect->height; ++j) { + for (i = rect->x_offset; i < rect->x_offset + rect->width; ++i) { const uint32_t src_pixel = src->argb[j * src->argb_stride + i]; const uint32_t dst_pixel = dst->argb[j * dst->argb_stride + i]; const uint32_t dst_alpha = dst_pixel >> 24; @@ -690,10 +690,10 @@ static int IncreaseTransparency(const WebPPicture* const src, int modified = 0; assert(src != NULL && dst != NULL && rect != NULL); assert(src->width == dst->width && src->height == dst->height); - for (j = rect->y_offset_; j < rect->y_offset_ + rect->height_; ++j) { + for (j = rect->y_offset; j < rect->y_offset + rect->height; ++j) { const uint32_t* const psrc = src->argb + j * src->argb_stride; uint32_t* const pdst = dst->argb + j * dst->argb_stride; - for (i = rect->x_offset_; i < rect->x_offset_ + rect->width_; ++i) { + for (i = rect->x_offset; i < rect->x_offset + rect->width; ++i) { if (psrc[i] == pdst[i] && pdst[i] != TRANSPARENT_COLOR) { pdst[i] = TRANSPARENT_COLOR; modified = 1; @@ -716,10 +716,10 @@ static int FlattenSimilarBlocks(const WebPPicture* const src, int i, j; int modified = 0; const int block_size = 8; - const int y_start = (rect->y_offset_ + block_size) & ~(block_size - 1); - const int y_end = (rect->y_offset_ + rect->height_) & ~(block_size - 1); - const int x_start = (rect->x_offset_ + block_size) & ~(block_size - 1); - const int x_end = (rect->x_offset_ + rect->width_) & ~(block_size - 1); + const int y_start = (rect->y_offset + block_size) & ~(block_size - 1); + const int y_end = (rect->y_offset + rect->height) & ~(block_size - 1); + const int x_start = (rect->x_offset + block_size) & ~(block_size - 1); + const int x_end = (rect->x_offset + rect->width) & ~(block_size - 1); assert(src != NULL && dst != NULL && rect != NULL); assert(src->width == dst->width && src->height == dst->height); assert((block_size & (block_size - 1)) == 0); // must be a power of 2 @@ -777,10 +777,10 @@ static int EncodeFrame(const WebPConfig* const config, WebPPicture* const pic, // Struct representing a candidate encoded frame including its metadata. typedef struct { - WebPMemoryWriter mem_; - WebPMuxFrameInfo info_; - FrameRectangle rect_; - int evaluate_; // True if this candidate should be evaluated. + WebPMemoryWriter mem; + WebPMuxFrameInfo info; + FrameRectangle rect; + int evaluate; // True if this candidate should be evaluated. } Candidate; // Generates a candidate encoded frame given a picture and metadata. @@ -795,17 +795,17 @@ static WebPEncodingError EncodeCandidate(WebPPicture* const sub_frame, memset(candidate, 0, sizeof(*candidate)); // Set frame rect and info. - candidate->rect_ = *rect; - candidate->info_.id = WEBP_CHUNK_ANMF; - candidate->info_.x_offset = rect->x_offset_; - candidate->info_.y_offset = rect->y_offset_; - candidate->info_.dispose_method = WEBP_MUX_DISPOSE_NONE; // Set later. - candidate->info_.blend_method = + candidate->rect = *rect; + candidate->info.id = WEBP_CHUNK_ANMF; + candidate->info.x_offset = rect->x_offset; + candidate->info.y_offset = rect->y_offset; + candidate->info.dispose_method = WEBP_MUX_DISPOSE_NONE; // Set later. + candidate->info.blend_method = use_blending ? WEBP_MUX_BLEND : WEBP_MUX_NO_BLEND; - candidate->info_.duration = 0; // Set in next call to WebPAnimEncoderAdd(). + candidate->info.duration = 0; // Set in next call to WebPAnimEncoderAdd(). // Encode picture. - WebPMemoryWriterInit(&candidate->mem_); + WebPMemoryWriterInit(&candidate->mem); if (!config.lossless && use_blending) { // Disable filtering to avoid blockiness in reconstructed frames at the @@ -813,25 +813,25 @@ static WebPEncodingError EncodeCandidate(WebPPicture* const sub_frame, config.autofilter = 0; config.filter_strength = 0; } - if (!EncodeFrame(&config, sub_frame, &candidate->mem_)) { + if (!EncodeFrame(&config, sub_frame, &candidate->mem)) { error_code = sub_frame->error_code; goto Err; } - candidate->evaluate_ = 1; + candidate->evaluate = 1; return error_code; Err: - WebPMemoryWriterClear(&candidate->mem_); + WebPMemoryWriterClear(&candidate->mem); return error_code; } static void CopyCurrentCanvas(WebPAnimEncoder* const enc) { - if (enc->curr_canvas_copy_modified_) { - WebPCopyPixels(enc->curr_canvas_, &enc->curr_canvas_copy_); - enc->curr_canvas_copy_.progress_hook = enc->curr_canvas_->progress_hook; - enc->curr_canvas_copy_.user_data = enc->curr_canvas_->user_data; - enc->curr_canvas_copy_modified_ = 0; + if (enc->curr_canvas_copy_modified) { + WebPCopyPixels(enc->curr_canvas, &enc->curr_canvas_copy); + enc->curr_canvas_copy.progress_hook = enc->curr_canvas->progress_hook; + enc->curr_canvas_copy.user_data = enc->curr_canvas->user_data; + enc->curr_canvas_copy_modified = 0; } } @@ -860,30 +860,30 @@ static WebPEncodingError GenerateCandidates( Candidate* const candidate_lossy = is_dispose_none ? &candidates[LOSSY_DISP_NONE] : &candidates[LOSSY_DISP_BG]; - WebPPicture* const curr_canvas = &enc->curr_canvas_copy_; + WebPPicture* const curr_canvas = &enc->curr_canvas_copy; const WebPPicture* const prev_canvas = - is_dispose_none ? &enc->prev_canvas_ : &enc->prev_canvas_disposed_; + is_dispose_none ? &enc->prev_canvas : &enc->prev_canvas_disposed; int use_blending_ll, use_blending_lossy; int evaluate_ll, evaluate_lossy; CopyCurrentCanvas(enc); use_blending_ll = !is_key_frame && - IsLosslessBlendingPossible(prev_canvas, curr_canvas, ¶ms->rect_ll_); + IsLosslessBlendingPossible(prev_canvas, curr_canvas, ¶ms->rect_ll); use_blending_lossy = !is_key_frame && - IsLossyBlendingPossible(prev_canvas, curr_canvas, ¶ms->rect_lossy_, + IsLossyBlendingPossible(prev_canvas, curr_canvas, ¶ms->rect_lossy, config_lossy->quality); // Pick candidates to be tried. - if (!enc->options_.allow_mixed) { + if (!enc->options.allow_mixed) { evaluate_ll = is_lossless; evaluate_lossy = !is_lossless; - } else if (enc->options_.minimize_size) { + } else if (enc->options.minimize_size) { evaluate_ll = 1; evaluate_lossy = 1; } else { // Use a heuristic for trying lossless and/or lossy compression. - const int num_colors = WebPGetColorPalette(¶ms->sub_frame_ll_, NULL); + const int num_colors = WebPGetColorPalette(¶ms->sub_frame_ll, NULL); evaluate_ll = (num_colors < MAX_COLORS_LOSSLESS); evaluate_lossy = (num_colors >= MIN_COLORS_LOSSY); } @@ -892,25 +892,25 @@ static WebPEncodingError GenerateCandidates( if (evaluate_ll) { CopyCurrentCanvas(enc); if (use_blending_ll) { - enc->curr_canvas_copy_modified_ = - IncreaseTransparency(prev_canvas, ¶ms->rect_ll_, curr_canvas); + enc->curr_canvas_copy_modified = + IncreaseTransparency(prev_canvas, ¶ms->rect_ll, curr_canvas); } - error_code = EncodeCandidate(¶ms->sub_frame_ll_, ¶ms->rect_ll_, + error_code = EncodeCandidate(¶ms->sub_frame_ll, ¶ms->rect_ll, config_ll, use_blending_ll, candidate_ll); if (error_code != VP8_ENC_OK) return error_code; } if (evaluate_lossy) { CopyCurrentCanvas(enc); if (use_blending_lossy) { - enc->curr_canvas_copy_modified_ = - FlattenSimilarBlocks(prev_canvas, ¶ms->rect_lossy_, curr_canvas, + enc->curr_canvas_copy_modified = + FlattenSimilarBlocks(prev_canvas, ¶ms->rect_lossy, curr_canvas, config_lossy->quality); } error_code = - EncodeCandidate(¶ms->sub_frame_lossy_, ¶ms->rect_lossy_, + EncodeCandidate(¶ms->sub_frame_lossy, ¶ms->rect_lossy, config_lossy, use_blending_lossy, candidate_lossy); if (error_code != VP8_ENC_OK) return error_code; - enc->curr_canvas_copy_modified_ = 1; + enc->curr_canvas_copy_modified = 1; } return error_code; } @@ -927,36 +927,36 @@ static void GetEncodedData(const WebPMemoryWriter* const memory, // Sets dispose method of the previous frame to be 'dispose_method'. static void SetPreviousDisposeMethod(WebPAnimEncoder* const enc, WebPMuxAnimDispose dispose_method) { - const size_t position = enc->count_ - 2; + const size_t position = enc->count - 2; EncodedFrame* const prev_enc_frame = GetFrame(enc, position); - assert(enc->count_ >= 2); // As current and previous frames are in enc. + assert(enc->count >= 2); // As current and previous frames are in enc. - if (enc->prev_candidate_undecided_) { + if (enc->prev_candidate_undecided) { assert(dispose_method == WEBP_MUX_DISPOSE_NONE); - prev_enc_frame->sub_frame_.dispose_method = dispose_method; - prev_enc_frame->key_frame_.dispose_method = dispose_method; + prev_enc_frame->sub_frame.dispose_method = dispose_method; + prev_enc_frame->key_frame.dispose_method = dispose_method; } else { - WebPMuxFrameInfo* const prev_info = prev_enc_frame->is_key_frame_ - ? &prev_enc_frame->key_frame_ - : &prev_enc_frame->sub_frame_; + WebPMuxFrameInfo* const prev_info = prev_enc_frame->is_key_frame + ? &prev_enc_frame->key_frame + : &prev_enc_frame->sub_frame; prev_info->dispose_method = dispose_method; } } static int IncreasePreviousDuration(WebPAnimEncoder* const enc, int duration) { - const size_t position = enc->count_ - 1; + const size_t position = enc->count - 1; EncodedFrame* const prev_enc_frame = GetFrame(enc, position); int new_duration; - assert(enc->count_ >= 1); - assert(!prev_enc_frame->is_key_frame_ || - prev_enc_frame->sub_frame_.duration == - prev_enc_frame->key_frame_.duration); - assert(prev_enc_frame->sub_frame_.duration == - (prev_enc_frame->sub_frame_.duration & (MAX_DURATION - 1))); + assert(enc->count >= 1); + assert(!prev_enc_frame->is_key_frame || + prev_enc_frame->sub_frame.duration == + prev_enc_frame->key_frame.duration); + assert(prev_enc_frame->sub_frame.duration == + (prev_enc_frame->sub_frame.duration & (MAX_DURATION - 1))); assert(duration == (duration & (MAX_DURATION - 1))); - new_duration = prev_enc_frame->sub_frame_.duration + duration; + new_duration = prev_enc_frame->sub_frame.duration + duration; if (new_duration >= MAX_DURATION) { // Special case. // Separate out previous frame from earlier merged frames to avoid overflow. // We add a 1x1 transparent frame for the previous frame, with blending on. @@ -979,28 +979,28 @@ static int IncreasePreviousDuration(WebPAnimEncoder* const enc, int duration) { }; const WebPData lossy_1x1 = { lossy_1x1_bytes, sizeof(lossy_1x1_bytes) }; const int can_use_lossless = - (enc->last_config_.lossless || enc->options_.allow_mixed); - EncodedFrame* const curr_enc_frame = GetFrame(enc, enc->count_); - curr_enc_frame->is_key_frame_ = 0; - curr_enc_frame->sub_frame_.id = WEBP_CHUNK_ANMF; - curr_enc_frame->sub_frame_.x_offset = 0; - curr_enc_frame->sub_frame_.y_offset = 0; - curr_enc_frame->sub_frame_.dispose_method = WEBP_MUX_DISPOSE_NONE; - curr_enc_frame->sub_frame_.blend_method = WEBP_MUX_BLEND; - curr_enc_frame->sub_frame_.duration = duration; + (enc->last_config.lossless || enc->options.allow_mixed); + EncodedFrame* const curr_enc_frame = GetFrame(enc, enc->count); + curr_enc_frame->is_key_frame = 0; + curr_enc_frame->sub_frame.id = WEBP_CHUNK_ANMF; + curr_enc_frame->sub_frame.x_offset = 0; + curr_enc_frame->sub_frame.y_offset = 0; + curr_enc_frame->sub_frame.dispose_method = WEBP_MUX_DISPOSE_NONE; + curr_enc_frame->sub_frame.blend_method = WEBP_MUX_BLEND; + curr_enc_frame->sub_frame.duration = duration; if (!WebPDataCopy(can_use_lossless ? &lossless_1x1 : &lossy_1x1, - &curr_enc_frame->sub_frame_.bitstream)) { + &curr_enc_frame->sub_frame.bitstream)) { return 0; } - ++enc->count_; - ++enc->count_since_key_frame_; - enc->flush_count_ = enc->count_ - 1; - enc->prev_candidate_undecided_ = 0; - enc->prev_rect_ = rect; + ++enc->count; + ++enc->count_since_key_frame; + enc->flush_count = enc->count - 1; + enc->prev_candidate_undecided = 0; + enc->prev_rect = rect; } else { // Regular case. // Increase duration of the previous frame by 'duration'. - prev_enc_frame->sub_frame_.duration = new_duration; - prev_enc_frame->key_frame_.duration = new_duration; + prev_enc_frame->sub_frame.duration = new_duration; + prev_enc_frame->key_frame.duration = new_duration; } return 1; } @@ -1016,8 +1016,8 @@ static void PickBestCandidate(WebPAnimEncoder* const enc, int best_idx = -1; size_t best_size = ~0; for (i = 0; i < CANDIDATE_COUNT; ++i) { - if (candidates[i].evaluate_) { - const size_t candidate_size = candidates[i].mem_.size; + if (candidates[i].evaluate) { + const size_t candidate_size = candidates[i].mem.size; if (candidate_size < best_size) { best_idx = i; best_size = candidate_size; @@ -1026,13 +1026,13 @@ static void PickBestCandidate(WebPAnimEncoder* const enc, } assert(best_idx != -1); for (i = 0; i < CANDIDATE_COUNT; ++i) { - if (candidates[i].evaluate_) { + if (candidates[i].evaluate) { if (i == best_idx) { WebPMuxFrameInfo* const dst = is_key_frame - ? &encoded_frame->key_frame_ - : &encoded_frame->sub_frame_; - *dst = candidates[i].info_; - GetEncodedData(&candidates[i].mem_, &dst->bitstream); + ? &encoded_frame->key_frame + : &encoded_frame->sub_frame; + *dst = candidates[i].info; + GetEncodedData(&candidates[i].mem, &dst->bitstream); if (!is_key_frame) { // Note: Previous dispose method only matters for non-keyframes. // Also, we don't want to modify previous dispose method that was @@ -1043,10 +1043,10 @@ static void PickBestCandidate(WebPAnimEncoder* const enc, : WEBP_MUX_DISPOSE_BACKGROUND; SetPreviousDisposeMethod(enc, prev_dispose_method); } - enc->prev_rect_ = candidates[i].rect_; // save for next frame. + enc->prev_rect = candidates[i].rect; // save for next frame. } else { - WebPMemoryWriterClear(&candidates[i].mem_); - candidates[i].evaluate_ = 0; + WebPMemoryWriterClear(&candidates[i].mem); + candidates[i].evaluate = 0; } } } @@ -1063,13 +1063,13 @@ static WebPEncodingError SetFrame(WebPAnimEncoder* const enc, int* const frame_skipped) { int i; WebPEncodingError error_code = VP8_ENC_OK; - const WebPPicture* const curr_canvas = &enc->curr_canvas_copy_; - const WebPPicture* const prev_canvas = &enc->prev_canvas_; + const WebPPicture* const curr_canvas = &enc->curr_canvas_copy; + const WebPPicture* const prev_canvas = &enc->prev_canvas; Candidate candidates[CANDIDATE_COUNT]; const int is_lossless = config->lossless; - const int consider_lossless = is_lossless || enc->options_.allow_mixed; - const int consider_lossy = !is_lossless || enc->options_.allow_mixed; - const int is_first_frame = enc->is_first_frame_; + const int consider_lossless = is_lossless || enc->options.allow_mixed; + const int consider_lossy = !is_lossless || enc->options.allow_mixed; + const int is_first_frame = enc->is_first_frame; // First frame cannot be skipped as there is no 'previous frame' to merge it // to. So, empty rectangle is not allowed for the first frame. @@ -1088,7 +1088,7 @@ static WebPEncodingError SetFrame(WebPAnimEncoder* const enc, // rectangle would be disposed. In that case too, we don't try dispose to // background. const int dispose_bg_possible = - !is_key_frame && !enc->prev_candidate_undecided_; + !is_key_frame && !enc->prev_candidate_undecided; SubFrameParams dispose_none_params; SubFrameParams dispose_bg_params; @@ -1097,8 +1097,8 @@ static WebPEncodingError SetFrame(WebPAnimEncoder* const enc, WebPConfig config_lossy = *config; config_ll.lossless = 1; config_lossy.lossless = 0; - enc->last_config_ = *config; - enc->last_config_reversed_ = config->lossless ? config_lossy : config_ll; + enc->last_config = *config; + enc->last_config_reversed = config->lossless ? config_lossy : config_ll; *frame_skipped = 0; if (!SubFrameParamsInit(&dispose_none_params, 1, empty_rect_allowed_none) || @@ -1115,8 +1115,8 @@ static WebPEncodingError SetFrame(WebPAnimEncoder* const enc, goto Err; } - if ((consider_lossless && IsEmptyRect(&dispose_none_params.rect_ll_)) || - (consider_lossy && IsEmptyRect(&dispose_none_params.rect_lossy_))) { + if ((consider_lossless && IsEmptyRect(&dispose_none_params.rect_ll)) || + (consider_lossy && IsEmptyRect(&dispose_none_params.rect_lossy))) { // Don't encode the frame at all. Instead, the duration of the previous // frame will be increased later. assert(empty_rect_allowed_none); @@ -1126,9 +1126,9 @@ static WebPEncodingError SetFrame(WebPAnimEncoder* const enc, if (dispose_bg_possible) { // Change-rectangle assuming previous frame was DISPOSE_BACKGROUND. - WebPPicture* const prev_canvas_disposed = &enc->prev_canvas_disposed_; + WebPPicture* const prev_canvas_disposed = &enc->prev_canvas_disposed; WebPCopyPixels(prev_canvas, prev_canvas_disposed); - DisposeFrameRectangle(WEBP_MUX_DISPOSE_BACKGROUND, &enc->prev_rect_, + DisposeFrameRectangle(WEBP_MUX_DISPOSE_BACKGROUND, &enc->prev_rect, prev_canvas_disposed); if (!GetSubRects(prev_canvas_disposed, curr_canvas, is_key_frame, @@ -1137,32 +1137,32 @@ static WebPEncodingError SetFrame(WebPAnimEncoder* const enc, error_code = VP8_ENC_ERROR_INVALID_CONFIGURATION; goto Err; } - assert(!IsEmptyRect(&dispose_bg_params.rect_ll_)); - assert(!IsEmptyRect(&dispose_bg_params.rect_lossy_)); + assert(!IsEmptyRect(&dispose_bg_params.rect_ll)); + assert(!IsEmptyRect(&dispose_bg_params.rect_lossy)); - if (enc->options_.minimize_size) { // Try both dispose methods. - dispose_bg_params.should_try_ = 1; - dispose_none_params.should_try_ = 1; + if (enc->options.minimize_size) { // Try both dispose methods. + dispose_bg_params.should_try = 1; + dispose_none_params.should_try = 1; } else if ((is_lossless && - RectArea(&dispose_bg_params.rect_ll_) < - RectArea(&dispose_none_params.rect_ll_)) || + RectArea(&dispose_bg_params.rect_ll) < + RectArea(&dispose_none_params.rect_ll)) || (!is_lossless && - RectArea(&dispose_bg_params.rect_lossy_) < - RectArea(&dispose_none_params.rect_lossy_))) { - dispose_bg_params.should_try_ = 1; // Pick DISPOSE_BACKGROUND. - dispose_none_params.should_try_ = 0; + RectArea(&dispose_bg_params.rect_lossy) < + RectArea(&dispose_none_params.rect_lossy))) { + dispose_bg_params.should_try = 1; // Pick DISPOSE_BACKGROUND. + dispose_none_params.should_try = 0; } } - if (dispose_none_params.should_try_) { + if (dispose_none_params.should_try) { error_code = GenerateCandidates( enc, candidates, WEBP_MUX_DISPOSE_NONE, is_lossless, is_key_frame, &dispose_none_params, &config_ll, &config_lossy); if (error_code != VP8_ENC_OK) goto Err; } - if (dispose_bg_params.should_try_) { - assert(!enc->is_first_frame_); + if (dispose_bg_params.should_try) { + assert(!enc->is_first_frame); assert(dispose_bg_possible); error_code = GenerateCandidates( enc, candidates, WEBP_MUX_DISPOSE_BACKGROUND, is_lossless, is_key_frame, @@ -1176,8 +1176,8 @@ static WebPEncodingError SetFrame(WebPAnimEncoder* const enc, Err: for (i = 0; i < CANDIDATE_COUNT; ++i) { - if (candidates[i].evaluate_) { - WebPMemoryWriterClear(&candidates[i].mem_); + if (candidates[i].evaluate) { + WebPMemoryWriterClear(&candidates[i].mem); } } @@ -1190,8 +1190,8 @@ static WebPEncodingError SetFrame(WebPAnimEncoder* const enc, // Calculate the penalty incurred if we encode given frame as a key frame // instead of a sub-frame. static int64_t KeyFramePenalty(const EncodedFrame* const encoded_frame) { - return ((int64_t)encoded_frame->key_frame_.bitstream.size - - encoded_frame->sub_frame_.bitstream.size); + return ((int64_t)encoded_frame->key_frame.bitstream.size - + encoded_frame->sub_frame.bitstream.size); } static int CacheFrame(WebPAnimEncoder* const enc, @@ -1199,30 +1199,30 @@ static int CacheFrame(WebPAnimEncoder* const enc, int ok = 0; int frame_skipped = 0; WebPEncodingError error_code = VP8_ENC_OK; - const size_t position = enc->count_; + const size_t position = enc->count; EncodedFrame* const encoded_frame = GetFrame(enc, position); - ++enc->count_; + ++enc->count; - if (enc->is_first_frame_) { // Add this as a key-frame. + if (enc->is_first_frame) { // Add this as a key-frame. error_code = SetFrame(enc, config, 1, encoded_frame, &frame_skipped); if (error_code != VP8_ENC_OK) goto End; assert(frame_skipped == 0); // First frame can't be skipped, even if empty. - assert(position == 0 && enc->count_ == 1); - encoded_frame->is_key_frame_ = 1; - enc->flush_count_ = 0; - enc->count_since_key_frame_ = 0; - enc->prev_candidate_undecided_ = 0; + assert(position == 0 && enc->count == 1); + encoded_frame->is_key_frame = 1; + enc->flush_count = 0; + enc->count_since_key_frame = 0; + enc->prev_candidate_undecided = 0; } else { - ++enc->count_since_key_frame_; - if (enc->count_since_key_frame_ <= enc->options_.kmin) { + ++enc->count_since_key_frame; + if (enc->count_since_key_frame <= enc->options.kmin) { // Add this as a frame rectangle. error_code = SetFrame(enc, config, 0, encoded_frame, &frame_skipped); if (error_code != VP8_ENC_OK) goto End; if (frame_skipped) goto Skip; - encoded_frame->is_key_frame_ = 0; - enc->flush_count_ = enc->count_ - 1; - enc->prev_candidate_undecided_ = 0; + encoded_frame->is_key_frame = 0; + enc->flush_count = enc->count - 1; + enc->prev_candidate_undecided = 0; } else { int64_t curr_delta; FrameRectangle prev_rect_key, prev_rect_sub; @@ -1231,103 +1231,103 @@ static int CacheFrame(WebPAnimEncoder* const enc, error_code = SetFrame(enc, config, 0, encoded_frame, &frame_skipped); if (error_code != VP8_ENC_OK) goto End; if (frame_skipped) goto Skip; - prev_rect_sub = enc->prev_rect_; + prev_rect_sub = enc->prev_rect; // Add this as a key-frame to enc, too. error_code = SetFrame(enc, config, 1, encoded_frame, &frame_skipped); if (error_code != VP8_ENC_OK) goto End; assert(frame_skipped == 0); // Key-frame cannot be an empty rectangle. - prev_rect_key = enc->prev_rect_; + prev_rect_key = enc->prev_rect; // Analyze size difference of the two variants. curr_delta = KeyFramePenalty(encoded_frame); - if (curr_delta <= enc->best_delta_) { // Pick this as the key-frame. - if (enc->keyframe_ != KEYFRAME_NONE) { - EncodedFrame* const old_keyframe = GetFrame(enc, enc->keyframe_); - assert(old_keyframe->is_key_frame_); - old_keyframe->is_key_frame_ = 0; + if (curr_delta <= enc->best_delta) { // Pick this as the key-frame. + if (enc->keyframe != KEYFRAME_NONE) { + EncodedFrame* const old_keyframe = GetFrame(enc, enc->keyframe); + assert(old_keyframe->is_key_frame); + old_keyframe->is_key_frame = 0; } - encoded_frame->is_key_frame_ = 1; - enc->prev_candidate_undecided_ = 1; - enc->keyframe_ = (int)position; - enc->best_delta_ = curr_delta; - enc->flush_count_ = enc->count_ - 1; // We can flush previous frames. + encoded_frame->is_key_frame = 1; + enc->prev_candidate_undecided = 1; + enc->keyframe = (int)position; + enc->best_delta = curr_delta; + enc->flush_count = enc->count - 1; // We can flush previous frames. } else { - encoded_frame->is_key_frame_ = 0; - enc->prev_candidate_undecided_ = 0; + encoded_frame->is_key_frame = 0; + enc->prev_candidate_undecided = 0; } // Note: We need '>=' below because when kmin and kmax are both zero, // count_since_key_frame will always be > kmax. - if (enc->count_since_key_frame_ >= enc->options_.kmax) { - enc->flush_count_ = enc->count_ - 1; - enc->count_since_key_frame_ = 0; - enc->keyframe_ = KEYFRAME_NONE; - enc->best_delta_ = DELTA_INFINITY; + if (enc->count_since_key_frame >= enc->options.kmax) { + enc->flush_count = enc->count - 1; + enc->count_since_key_frame = 0; + enc->keyframe = KEYFRAME_NONE; + enc->best_delta = DELTA_INFINITY; } - if (!enc->prev_candidate_undecided_) { - enc->prev_rect_ = - encoded_frame->is_key_frame_ ? prev_rect_key : prev_rect_sub; + if (!enc->prev_candidate_undecided) { + enc->prev_rect = + encoded_frame->is_key_frame ? prev_rect_key : prev_rect_sub; } } } // Update previous to previous and previous canvases for next call. - WebPCopyPixels(enc->curr_canvas_, &enc->prev_canvas_); - enc->is_first_frame_ = 0; + WebPCopyPixels(enc->curr_canvas, &enc->prev_canvas); + enc->is_first_frame = 0; Skip: ok = 1; - ++enc->in_frame_count_; + ++enc->in_frame_count; End: if (!ok || frame_skipped) { FrameRelease(encoded_frame); // We reset some counters, as the frame addition failed/was skipped. - --enc->count_; - if (!enc->is_first_frame_) --enc->count_since_key_frame_; + --enc->count; + if (!enc->is_first_frame) --enc->count_since_key_frame; if (!ok) { MarkError2(enc, "ERROR adding frame. WebPEncodingError", error_code); } } - enc->curr_canvas_->error_code = error_code; // report error_code + enc->curr_canvas->error_code = error_code; // report error_code assert(ok || error_code != VP8_ENC_OK); return ok; } static int FlushFrames(WebPAnimEncoder* const enc) { - while (enc->flush_count_ > 0) { + while (enc->flush_count > 0) { WebPMuxError err; EncodedFrame* const curr = GetFrame(enc, 0); const WebPMuxFrameInfo* const info = - curr->is_key_frame_ ? &curr->key_frame_ : &curr->sub_frame_; - assert(enc->mux_ != NULL); - err = WebPMuxPushFrame(enc->mux_, info, 1); + curr->is_key_frame ? &curr->key_frame : &curr->sub_frame; + assert(enc->mux != NULL); + err = WebPMuxPushFrame(enc->mux, info, 1); if (err != WEBP_MUX_OK) { MarkError2(enc, "ERROR adding frame. WebPMuxError", err); return 0; } - if (enc->options_.verbose) { + if (enc->options.verbose) { fprintf(stderr, "INFO: Added frame. offset:%d,%d dispose:%d blend:%d\n", info->x_offset, info->y_offset, info->dispose_method, info->blend_method); } - ++enc->out_frame_count_; + ++enc->out_frame_count; FrameRelease(curr); - ++enc->start_; - --enc->flush_count_; - --enc->count_; - if (enc->keyframe_ != KEYFRAME_NONE) --enc->keyframe_; + ++enc->start; + --enc->flush_count; + --enc->count; + if (enc->keyframe != KEYFRAME_NONE) --enc->keyframe; } - if (enc->count_ == 1 && enc->start_ != 0) { + if (enc->count == 1 && enc->start != 0) { // Move enc->start to index 0. - const int enc_start_tmp = (int)enc->start_; - EncodedFrame temp = enc->encoded_frames_[0]; - enc->encoded_frames_[0] = enc->encoded_frames_[enc_start_tmp]; - enc->encoded_frames_[enc_start_tmp] = temp; - FrameRelease(&enc->encoded_frames_[enc_start_tmp]); - enc->start_ = 0; + const int enc_start_tmp = (int)enc->start; + EncodedFrame temp = enc->encoded_frames[0]; + enc->encoded_frames[0] = enc->encoded_frames[enc_start_tmp]; + enc->encoded_frames[enc_start_tmp] = temp; + FrameRelease(&enc->encoded_frames[enc_start_tmp]); + enc->start = 0; } return 1; } @@ -1345,10 +1345,10 @@ int WebPAnimEncoderAdd(WebPAnimEncoder* enc, WebPPicture* frame, int timestamp, } MarkNoError(enc); - if (!enc->is_first_frame_) { + if (!enc->is_first_frame) { // Make sure timestamps are non-decreasing (integer wrap-around is OK). const uint32_t prev_frame_duration = - (uint32_t)timestamp - enc->prev_timestamp_; + (uint32_t)timestamp - enc->prev_timestamp; if (prev_frame_duration >= MAX_DURATION) { if (frame != NULL) { frame->error_code = VP8_ENC_ERROR_INVALID_CONFIGURATION; @@ -1360,30 +1360,30 @@ int WebPAnimEncoderAdd(WebPAnimEncoder* enc, WebPPicture* frame, int timestamp, return 0; } // IncreasePreviousDuration() may add a frame to avoid exceeding - // MAX_DURATION which could cause CacheFrame() to over read encoded_frames_ + // MAX_DURATION which could cause CacheFrame() to over read 'encoded_frames' // before the next flush. - if (enc->count_ == enc->size_ && !FlushFrames(enc)) { + if (enc->count == enc->size && !FlushFrames(enc)) { return 0; } } else { - enc->first_timestamp_ = timestamp; + enc->first_timestamp = timestamp; } if (frame == NULL) { // Special: last call. - enc->got_null_frame_ = 1; - enc->prev_timestamp_ = timestamp; + enc->got_null_frame = 1; + enc->prev_timestamp = timestamp; return 1; } - if (frame->width != enc->canvas_width_ || - frame->height != enc->canvas_height_) { + if (frame->width != enc->canvas_width || + frame->height != enc->canvas_height) { frame->error_code = VP8_ENC_ERROR_INVALID_CONFIGURATION; MarkError(enc, "ERROR adding frame: Invalid frame dimensions"); return 0; } if (!frame->use_argb) { // Convert frame from YUV(A) to ARGB. - if (enc->options_.verbose) { + if (enc->options.verbose) { fprintf(stderr, "WARNING: Converting frame from YUV(A) to ARGB format; " "this incurs a small loss.\n"); } @@ -1406,17 +1406,17 @@ int WebPAnimEncoderAdd(WebPAnimEncoder* enc, WebPPicture* frame, int timestamp, } config.lossless = 1; } - assert(enc->curr_canvas_ == NULL); - enc->curr_canvas_ = frame; // Store reference. - assert(enc->curr_canvas_copy_modified_ == 1); + assert(enc->curr_canvas == NULL); + enc->curr_canvas = frame; // Store reference. + assert(enc->curr_canvas_copy_modified == 1); CopyCurrentCanvas(enc); ok = CacheFrame(enc, &config) && FlushFrames(enc); - enc->curr_canvas_ = NULL; - enc->curr_canvas_copy_modified_ = 1; + enc->curr_canvas = NULL; + enc->curr_canvas_copy_modified = 1; if (ok) { - enc->prev_timestamp_ = timestamp; + enc->prev_timestamp = timestamp; } return ok; } @@ -1456,17 +1456,17 @@ WEBP_NODISCARD static int DecodeFrameOntoCanvas( static int FrameToFullCanvas(WebPAnimEncoder* const enc, const WebPMuxFrameInfo* const frame, WebPData* const full_image) { - WebPPicture* const canvas_buf = &enc->curr_canvas_copy_; + WebPPicture* const canvas_buf = &enc->curr_canvas_copy; WebPMemoryWriter mem1, mem2; WebPMemoryWriterInit(&mem1); WebPMemoryWriterInit(&mem2); if (!DecodeFrameOntoCanvas(frame, canvas_buf)) goto Err; - if (!EncodeFrame(&enc->last_config_, canvas_buf, &mem1)) goto Err; + if (!EncodeFrame(&enc->last_config, canvas_buf, &mem1)) goto Err; GetEncodedData(&mem1, full_image); - if (enc->options_.allow_mixed) { - if (!EncodeFrame(&enc->last_config_reversed_, canvas_buf, &mem2)) goto Err; + if (enc->options.allow_mixed) { + if (!EncodeFrame(&enc->last_config_reversed, canvas_buf, &mem2)) goto Err; if (mem2.size < mem1.size) { GetEncodedData(&mem2, full_image); WebPMemoryWriterClear(&mem1); @@ -1494,7 +1494,7 @@ static WebPMuxError OptimizeSingleFrame(WebPAnimEncoder* const enc, WebPData webp_data2; WebPMux* const mux = WebPMuxCreate(webp_data, 0); if (mux == NULL) return WEBP_MUX_BAD_DATA; - assert(enc->out_frame_count_ == 1); + assert(enc->out_frame_count == 1); WebPDataInit(&frame.bitstream); WebPDataInit(&full_image); WebPDataInit(&webp_data2); @@ -1541,40 +1541,40 @@ int WebPAnimEncoderAssemble(WebPAnimEncoder* enc, WebPData* webp_data) { return 0; } - if (enc->in_frame_count_ == 0) { + if (enc->in_frame_count == 0) { MarkError(enc, "ERROR: No frames to assemble"); return 0; } - if (!enc->got_null_frame_ && enc->in_frame_count_ > 1 && enc->count_ > 0) { + if (!enc->got_null_frame && enc->in_frame_count > 1 && enc->count > 0) { // set duration of the last frame to be avg of durations of previous frames. const double delta_time = - (uint32_t)enc->prev_timestamp_ - enc->first_timestamp_; - const int average_duration = (int)(delta_time / (enc->in_frame_count_ - 1)); + (uint32_t)enc->prev_timestamp - enc->first_timestamp; + const int average_duration = (int)(delta_time / (enc->in_frame_count - 1)); if (!IncreasePreviousDuration(enc, average_duration)) { return 0; } } // Flush any remaining frames. - enc->flush_count_ = enc->count_; + enc->flush_count = enc->count; if (!FlushFrames(enc)) { return 0; } // Set definitive canvas size. - mux = enc->mux_; - err = WebPMuxSetCanvasSize(mux, enc->canvas_width_, enc->canvas_height_); + mux = enc->mux; + err = WebPMuxSetCanvasSize(mux, enc->canvas_width, enc->canvas_height); if (err != WEBP_MUX_OK) goto Err; - err = WebPMuxSetAnimationParams(mux, &enc->options_.anim_params); + err = WebPMuxSetAnimationParams(mux, &enc->options.anim_params); if (err != WEBP_MUX_OK) goto Err; // Assemble into a WebP bitstream. err = WebPMuxAssemble(mux, webp_data); if (err != WEBP_MUX_OK) goto Err; - if (enc->out_frame_count_ == 1) { + if (enc->out_frame_count == 1) { err = OptimizeSingleFrame(enc, webp_data); if (err != WEBP_MUX_OK) goto Err; } @@ -1587,26 +1587,26 @@ int WebPAnimEncoderAssemble(WebPAnimEncoder* enc, WebPData* webp_data) { const char* WebPAnimEncoderGetError(WebPAnimEncoder* enc) { if (enc == NULL) return NULL; - return enc->error_str_; + return enc->error_str; } WebPMuxError WebPAnimEncoderSetChunk( WebPAnimEncoder* enc, const char fourcc[4], const WebPData* chunk_data, int copy_data) { if (enc == NULL) return WEBP_MUX_INVALID_ARGUMENT; - return WebPMuxSetChunk(enc->mux_, fourcc, chunk_data, copy_data); + return WebPMuxSetChunk(enc->mux, fourcc, chunk_data, copy_data); } WebPMuxError WebPAnimEncoderGetChunk( const WebPAnimEncoder* enc, const char fourcc[4], WebPData* chunk_data) { if (enc == NULL) return WEBP_MUX_INVALID_ARGUMENT; - return WebPMuxGetChunk(enc->mux_, fourcc, chunk_data); + return WebPMuxGetChunk(enc->mux, fourcc, chunk_data); } WebPMuxError WebPAnimEncoderDeleteChunk( WebPAnimEncoder* enc, const char fourcc[4]) { if (enc == NULL) return WEBP_MUX_INVALID_ARGUMENT; - return WebPMuxDeleteChunk(enc->mux_, fourcc); + return WebPMuxDeleteChunk(enc->mux, fourcc); } // ----------------------------------------------------------------------------- diff --git a/src/mux/muxedit.c b/src/mux/muxedit.c index 48c6834a..0007e50e 100644 --- a/src/mux/muxedit.c +++ b/src/mux/muxedit.c @@ -22,8 +22,8 @@ static void MuxInit(WebPMux* const mux) { assert(mux != NULL); memset(mux, 0, sizeof(*mux)); - mux->canvas_width_ = 0; // just to be explicit - mux->canvas_height_ = 0; + mux->canvas_width = 0; // just to be explicit + mux->canvas_height = 0; } WebPMux* WebPNewInternal(int version) { @@ -45,13 +45,13 @@ static void DeleteAllImages(WebPMuxImage** const wpi_list) { static void MuxRelease(WebPMux* const mux) { assert(mux != NULL); - DeleteAllImages(&mux->images_); - ChunkListDelete(&mux->vp8x_); - ChunkListDelete(&mux->iccp_); - ChunkListDelete(&mux->anim_); - ChunkListDelete(&mux->exif_); - ChunkListDelete(&mux->xmp_); - ChunkListDelete(&mux->unknown_); + DeleteAllImages(&mux->images); + ChunkListDelete(&mux->vp8x); + ChunkListDelete(&mux->iccp); + ChunkListDelete(&mux->anim); + ChunkListDelete(&mux->exif); + ChunkListDelete(&mux->xmp); + ChunkListDelete(&mux->unknown); } void WebPMuxDelete(WebPMux* mux) { @@ -86,12 +86,12 @@ static WebPMuxError MuxSet(WebPMux* const mux, uint32_t tag, assert(!IsWPI(kChunks[idx].id)); ChunkInit(&chunk); - SWITCH_ID_LIST(IDX_VP8X, &mux->vp8x_); - SWITCH_ID_LIST(IDX_ICCP, &mux->iccp_); - SWITCH_ID_LIST(IDX_ANIM, &mux->anim_); - SWITCH_ID_LIST(IDX_EXIF, &mux->exif_); - SWITCH_ID_LIST(IDX_XMP, &mux->xmp_); - SWITCH_ID_LIST(IDX_UNKNOWN, &mux->unknown_); + SWITCH_ID_LIST(IDX_VP8X, &mux->vp8x); + SWITCH_ID_LIST(IDX_ICCP, &mux->iccp); + SWITCH_ID_LIST(IDX_ANIM, &mux->anim); + SWITCH_ID_LIST(IDX_EXIF, &mux->exif); + SWITCH_ID_LIST(IDX_XMP, &mux->xmp); + SWITCH_ID_LIST(IDX_UNKNOWN, &mux->unknown); return err; } #undef SWITCH_ID_LIST @@ -141,11 +141,11 @@ static WebPMuxError GetImageData(const WebPData* const bitstream, const WebPMuxImage* wpi; WebPMux* const mux = WebPMuxCreate(bitstream, 0); if (mux == NULL) return WEBP_MUX_BAD_DATA; - wpi = mux->images_; - assert(wpi != NULL && wpi->img_ != NULL); - *image = wpi->img_->data_; - if (wpi->alpha_ != NULL) { - *alpha = wpi->alpha_->data_; + wpi = mux->images; + assert(wpi != NULL && wpi->img != NULL); + *image = wpi->img->data; + if (wpi->alpha != NULL) { + *alpha = wpi->alpha->data; } WebPMuxDelete(mux); } @@ -158,11 +158,11 @@ static WebPMuxError DeleteChunks(WebPChunk** chunk_list, uint32_t tag) { assert(chunk_list); while (*chunk_list) { WebPChunk* const chunk = *chunk_list; - if (chunk->tag_ == tag) { + if (chunk->tag == tag) { *chunk_list = ChunkDelete(chunk); err = WEBP_MUX_OK; } else { - chunk_list = &chunk->next_; + chunk_list = &chunk->next; } } return err; @@ -213,8 +213,8 @@ static WebPMuxError AddDataToChunkList( return err; } -// Extracts image & alpha data from the given bitstream and then sets wpi.alpha_ -// and wpi.img_ appropriately. +// Extracts image & alpha data from the given bitstream and then sets wpi.alpha +// and wpi.img appropriately. static WebPMuxError SetAlphaAndImageChunks( const WebPData* const bitstream, int copy_data, WebPMuxImage* const wpi) { int is_lossless = 0; @@ -225,10 +225,10 @@ static WebPMuxError SetAlphaAndImageChunks( if (err != WEBP_MUX_OK) return err; if (alpha.bytes != NULL) { err = AddDataToChunkList(&alpha, copy_data, kChunks[IDX_ALPHA].tag, - &wpi->alpha_); + &wpi->alpha); if (err != WEBP_MUX_OK) return err; } - err = AddDataToChunkList(&image, copy_data, image_tag, &wpi->img_); + err = AddDataToChunkList(&image, copy_data, image_tag, &wpi->img); if (err != WEBP_MUX_OK) return err; return MuxImageFinalize(wpi) ? WEBP_MUX_OK : WEBP_MUX_INVALID_ARGUMENT; } @@ -243,9 +243,9 @@ WebPMuxError WebPMuxSetImage(WebPMux* mux, const WebPData* bitstream, return WEBP_MUX_INVALID_ARGUMENT; } - if (mux->images_ != NULL) { + if (mux->images != NULL) { // Only one 'simple image' can be added in mux. So, remove present images. - DeleteAllImages(&mux->images_); + DeleteAllImages(&mux->images); } MuxImageInit(&wpi); @@ -253,7 +253,7 @@ WebPMuxError WebPMuxSetImage(WebPMux* mux, const WebPData* bitstream, if (err != WEBP_MUX_OK) goto Err; // Add this WebPMuxImage to mux. - err = MuxImagePush(&wpi, &mux->images_); + err = MuxImagePush(&wpi, &mux->images); if (err != WEBP_MUX_OK) goto Err; // All is well. @@ -278,10 +278,10 @@ WebPMuxError WebPMuxPushFrame(WebPMux* mux, const WebPMuxFrameInfo* info, return WEBP_MUX_INVALID_ARGUMENT; } - if (mux->images_ != NULL) { - const WebPMuxImage* const image = mux->images_; - const uint32_t image_id = (image->header_ != NULL) ? - ChunkGetIdFromTag(image->header_->tag_) : WEBP_CHUNK_IMAGE; + if (mux->images != NULL) { + const WebPMuxImage* const image = mux->images; + const uint32_t image_id = (image->header != NULL) ? + ChunkGetIdFromTag(image->header->tag) : WEBP_CHUNK_IMAGE; if (image_id != info->id) { return WEBP_MUX_INVALID_ARGUMENT; // Conflicting frame types. } @@ -290,7 +290,7 @@ WebPMuxError WebPMuxPushFrame(WebPMux* mux, const WebPMuxFrameInfo* info, MuxImageInit(&wpi); err = SetAlphaAndImageChunks(&info->bitstream, copy_data, &wpi); if (err != WEBP_MUX_OK) goto Err; - assert(wpi.img_ != NULL); // As SetAlphaAndImageChunks() was successful. + assert(wpi.img != NULL); // As SetAlphaAndImageChunks() was successful. { WebPData frame; @@ -305,16 +305,16 @@ WebPMuxError WebPMuxPushFrame(WebPMux* mux, const WebPMuxFrameInfo* info, err = WEBP_MUX_INVALID_ARGUMENT; goto Err; } - err = CreateFrameData(wpi.width_, wpi.height_, &tmp, &frame); + err = CreateFrameData(wpi.width, wpi.height, &tmp, &frame); if (err != WEBP_MUX_OK) goto Err; // Add frame chunk (with copy_data = 1). - err = AddDataToChunkList(&frame, 1, tag, &wpi.header_); - WebPDataClear(&frame); // frame owned by wpi.header_ now. + err = AddDataToChunkList(&frame, 1, tag, &wpi.header); + WebPDataClear(&frame); // frame owned by wpi.header now. if (err != WEBP_MUX_OK) goto Err; } // Add this WebPMuxImage to mux. - err = MuxImagePush(&wpi, &mux->images_); + err = MuxImagePush(&wpi, &mux->images); if (err != WEBP_MUX_OK) goto Err; // All is well. @@ -367,8 +367,8 @@ WebPMuxError WebPMuxSetCanvasSize(WebPMux* mux, err = MuxDeleteAllNamedData(mux, kChunks[IDX_VP8X].tag); if (err != WEBP_MUX_OK && err != WEBP_MUX_NOT_FOUND) return err; - mux->canvas_width_ = width; - mux->canvas_height_ = height; + mux->canvas_width = width; + mux->canvas_height = height; return WEBP_MUX_OK; } @@ -382,7 +382,7 @@ WebPMuxError WebPMuxDeleteChunk(WebPMux* mux, const char fourcc[4]) { WebPMuxError WebPMuxDeleteFrame(WebPMux* mux, uint32_t nth) { if (mux == NULL) return WEBP_MUX_INVALID_ARGUMENT; - return MuxImageDeleteNth(&mux->images_, nth); + return MuxImageDeleteNth(&mux->images, nth); } //------------------------------------------------------------------------------ @@ -391,9 +391,9 @@ WebPMuxError WebPMuxDeleteFrame(WebPMux* mux, uint32_t nth) { static WebPMuxError GetFrameInfo( const WebPChunk* const frame_chunk, int* const x_offset, int* const y_offset, int* const duration) { - const WebPData* const data = &frame_chunk->data_; + const WebPData* const data = &frame_chunk->data; const size_t expected_data_size = ANMF_CHUNK_SIZE; - assert(frame_chunk->tag_ == kChunks[IDX_ANMF].tag); + assert(frame_chunk->tag == kChunks[IDX_ANMF].tag); assert(frame_chunk != NULL); if (data->size != expected_data_size) return WEBP_MUX_INVALID_ARGUMENT; @@ -407,7 +407,7 @@ static WebPMuxError GetImageInfo(const WebPMuxImage* const wpi, int* const x_offset, int* const y_offset, int* const duration, int* const width, int* const height) { - const WebPChunk* const frame_chunk = wpi->header_; + const WebPChunk* const frame_chunk = wpi->header; WebPMuxError err; assert(wpi != NULL); assert(frame_chunk != NULL); @@ -417,8 +417,8 @@ static WebPMuxError GetImageInfo(const WebPMuxImage* const wpi, if (err != WEBP_MUX_OK) return err; // Get width and height from VP8/VP8L chunk. - if (width != NULL) *width = wpi->width_; - if (height != NULL) *height = wpi->height_; + if (width != NULL) *width = wpi->width; + if (height != NULL) *height = wpi->height; return WEBP_MUX_OK; } @@ -429,16 +429,16 @@ static WebPMuxError GetAdjustedCanvasSize(const WebPMux* const mux, assert(mux != NULL); assert(width != NULL && height != NULL); - wpi = mux->images_; + wpi = mux->images; assert(wpi != NULL); - assert(wpi->img_ != NULL); + assert(wpi->img != NULL); - if (wpi->next_ != NULL) { + if (wpi->next != NULL) { int max_x = 0, max_y = 0; - // if we have a chain of wpi's, header_ is necessarily set - assert(wpi->header_ != NULL); + // if we have a chain of wpi's, header is necessarily set + assert(wpi->header != NULL); // Aggregate the bounding box for animation frames. - for (; wpi != NULL; wpi = wpi->next_) { + for (; wpi != NULL; wpi = wpi->next) { int x_offset = 0, y_offset = 0, duration = 0, w = 0, h = 0; const WebPMuxError err = GetImageInfo(wpi, &x_offset, &y_offset, &duration, &w, &h); @@ -455,8 +455,8 @@ static WebPMuxError GetAdjustedCanvasSize(const WebPMux* const mux, *height = max_y; } else { // For a single image, canvas dimensions are same as image dimensions. - *width = wpi->width_; - *height = wpi->height_; + *width = wpi->width; + *height = wpi->height; } return WEBP_MUX_OK; } @@ -476,9 +476,9 @@ static WebPMuxError CreateVP8XChunk(WebPMux* const mux) { const WebPMuxImage* images = NULL; assert(mux != NULL); - images = mux->images_; // First image. - if (images == NULL || images->img_ == NULL || - images->img_->data_.bytes == NULL) { + images = mux->images; // First image. + if (images == NULL || images->img == NULL || + images->img->data.bytes == NULL) { return WEBP_MUX_INVALID_ARGUMENT; } @@ -488,17 +488,17 @@ static WebPMuxError CreateVP8XChunk(WebPMux* const mux) { if (err != WEBP_MUX_OK && err != WEBP_MUX_NOT_FOUND) return err; // Set flags. - if (mux->iccp_ != NULL && mux->iccp_->data_.bytes != NULL) { + if (mux->iccp != NULL && mux->iccp->data.bytes != NULL) { flags |= ICCP_FLAG; } - if (mux->exif_ != NULL && mux->exif_->data_.bytes != NULL) { + if (mux->exif != NULL && mux->exif->data.bytes != NULL) { flags |= EXIF_FLAG; } - if (mux->xmp_ != NULL && mux->xmp_->data_.bytes != NULL) { + if (mux->xmp != NULL && mux->xmp->data.bytes != NULL) { flags |= XMP_FLAG; } - if (images->header_ != NULL) { - if (images->header_->tag_ == kChunks[IDX_ANMF].tag) { + if (images->header != NULL) { + if (images->header->tag == kChunks[IDX_ANMF].tag) { // This is an image with animation. flags |= ANIMATION_FLAG; } @@ -517,15 +517,15 @@ static WebPMuxError CreateVP8XChunk(WebPMux* const mux) { return WEBP_MUX_INVALID_ARGUMENT; } - if (mux->canvas_width_ != 0 || mux->canvas_height_ != 0) { - if (width > mux->canvas_width_ || height > mux->canvas_height_) { + if (mux->canvas_width != 0 || mux->canvas_height != 0) { + if (width > mux->canvas_width || height > mux->canvas_height) { return WEBP_MUX_INVALID_ARGUMENT; } - width = mux->canvas_width_; - height = mux->canvas_height_; + width = mux->canvas_width; + height = mux->canvas_height; } - if (flags == 0 && mux->unknown_ == NULL) { + if (flags == 0 && mux->unknown == NULL) { // For simple file format, VP8X chunk should not be added. return WEBP_MUX_OK; } @@ -556,17 +556,17 @@ static WebPMuxError MuxCleanup(WebPMux* const mux) { if (err != WEBP_MUX_OK) return err; if (num_frames == 1) { WebPMuxImage* frame = NULL; - err = MuxImageGetNth((const WebPMuxImage**)&mux->images_, 1, &frame); + err = MuxImageGetNth((const WebPMuxImage**)&mux->images, 1, &frame); if (err != WEBP_MUX_OK) return err; // We know that one frame does exist. assert(frame != NULL); - if (frame->header_ != NULL && - ((mux->canvas_width_ == 0 && mux->canvas_height_ == 0) || - (frame->width_ == mux->canvas_width_ && - frame->height_ == mux->canvas_height_))) { - assert(frame->header_->tag_ == kChunks[IDX_ANMF].tag); - ChunkDelete(frame->header_); // Removes ANMF chunk. - frame->header_ = NULL; + if (frame->header != NULL && + ((mux->canvas_width == 0 && mux->canvas_height == 0) || + (frame->width == mux->canvas_width && + frame->height == mux->canvas_height))) { + assert(frame->header->tag == kChunks[IDX_ANMF].tag); + ChunkDelete(frame->header); // Removes ANMF chunk. + frame->header = NULL; num_frames = 0; } } @@ -585,7 +585,7 @@ static size_t ImageListDiskSize(const WebPMuxImage* wpi_list) { size_t size = 0; while (wpi_list != NULL) { size += MuxImageDiskSize(wpi_list); - wpi_list = wpi_list->next_; + wpi_list = wpi_list->next; } return size; } @@ -594,7 +594,7 @@ static size_t ImageListDiskSize(const WebPMuxImage* wpi_list) { static uint8_t* ImageListEmit(const WebPMuxImage* wpi_list, uint8_t* dst) { while (wpi_list != NULL) { dst = MuxImageEmit(wpi_list, dst); - wpi_list = wpi_list->next_; + wpi_list = wpi_list->next; } return dst; } @@ -622,23 +622,23 @@ WebPMuxError WebPMuxAssemble(WebPMux* mux, WebPData* assembled_data) { if (err != WEBP_MUX_OK) return err; // Allocate data. - size = ChunkListDiskSize(mux->vp8x_) + ChunkListDiskSize(mux->iccp_) - + ChunkListDiskSize(mux->anim_) + ImageListDiskSize(mux->images_) - + ChunkListDiskSize(mux->exif_) + ChunkListDiskSize(mux->xmp_) - + ChunkListDiskSize(mux->unknown_) + RIFF_HEADER_SIZE; + size = ChunkListDiskSize(mux->vp8x) + ChunkListDiskSize(mux->iccp) + + ChunkListDiskSize(mux->anim) + ImageListDiskSize(mux->images) + + ChunkListDiskSize(mux->exif) + ChunkListDiskSize(mux->xmp) + + ChunkListDiskSize(mux->unknown) + RIFF_HEADER_SIZE; data = (uint8_t*)WebPSafeMalloc(1ULL, size); if (data == NULL) return WEBP_MUX_MEMORY_ERROR; // Emit header & chunks. dst = MuxEmitRiffHeader(data, size); - dst = ChunkListEmit(mux->vp8x_, dst); - dst = ChunkListEmit(mux->iccp_, dst); - dst = ChunkListEmit(mux->anim_, dst); - dst = ImageListEmit(mux->images_, dst); - dst = ChunkListEmit(mux->exif_, dst); - dst = ChunkListEmit(mux->xmp_, dst); - dst = ChunkListEmit(mux->unknown_, dst); + dst = ChunkListEmit(mux->vp8x, dst); + dst = ChunkListEmit(mux->iccp, dst); + dst = ChunkListEmit(mux->anim, dst); + dst = ImageListEmit(mux->images, dst); + dst = ChunkListEmit(mux->exif, dst); + dst = ChunkListEmit(mux->xmp, dst); + dst = ChunkListEmit(mux->unknown, dst); assert(dst == data + size); // Validate mux. diff --git a/src/mux/muxi.h b/src/mux/muxi.h index 3c542f93..0058c05a 100644 --- a/src/mux/muxi.h +++ b/src/mux/muxi.h @@ -34,41 +34,41 @@ extern "C" { // Chunk object. typedef struct WebPChunk WebPChunk; struct WebPChunk { - uint32_t tag_; - int owner_; // True if *data_ memory is owned internally. + uint32_t tag; + int owner; // True if *data memory is owned internally. // VP8X, ANIM, and other internally created chunks // like ANMF are always owned. - WebPData data_; - WebPChunk* next_; + WebPData data; + WebPChunk* next; }; // MuxImage object. Store a full WebP image (including ANMF chunk, ALPH // chunk and VP8/VP8L chunk), typedef struct WebPMuxImage WebPMuxImage; struct WebPMuxImage { - WebPChunk* header_; // Corresponds to WEBP_CHUNK_ANMF. - WebPChunk* alpha_; // Corresponds to WEBP_CHUNK_ALPHA. - WebPChunk* img_; // Corresponds to WEBP_CHUNK_IMAGE. - WebPChunk* unknown_; // Corresponds to WEBP_CHUNK_UNKNOWN. - int width_; - int height_; - int has_alpha_; // Through ALPH chunk or as part of VP8L. - int is_partial_; // True if only some of the chunks are filled. - WebPMuxImage* next_; + WebPChunk* header; // Corresponds to WEBP_CHUNK_ANMF. + WebPChunk* alpha; // Corresponds to WEBP_CHUNK_ALPHA. + WebPChunk* img; // Corresponds to WEBP_CHUNK_IMAGE. + WebPChunk* unknown; // Corresponds to WEBP_CHUNK_UNKNOWN. + int width; + int height; + int has_alpha; // Through ALPH chunk or as part of VP8L. + int is_partial; // True if only some of the chunks are filled. + WebPMuxImage* next; }; // Main mux object. Stores data chunks. struct WebPMux { - WebPMuxImage* images_; - WebPChunk* iccp_; - WebPChunk* exif_; - WebPChunk* xmp_; - WebPChunk* anim_; - WebPChunk* vp8x_; + WebPMuxImage* images; + WebPChunk* iccp; + WebPChunk* exif; + WebPChunk* xmp; + WebPChunk* anim; + WebPChunk* vp8x; - WebPChunk* unknown_; - int canvas_width_; - int canvas_height_; + WebPChunk* unknown; + int canvas_width; + int canvas_height; }; // CHUNK_INDEX enum: used for indexing within 'kChunks' (defined below) only. @@ -136,10 +136,10 @@ WebPMuxError ChunkSetHead(WebPChunk* const chunk, WebPChunk** const chunk_list); // *chunk_list. WebPMuxError ChunkAppend(WebPChunk* const chunk, WebPChunk*** const chunk_list); -// Releases chunk and returns chunk->next_. +// Releases chunk and returns chunk->next. WebPChunk* ChunkRelease(WebPChunk* const chunk); -// Deletes given chunk & returns chunk->next_. +// Deletes given chunk & returns chunk->next. WebPChunk* ChunkDelete(WebPChunk* const chunk); // Deletes all chunks in the given chunk list. @@ -153,7 +153,7 @@ static WEBP_INLINE size_t SizeWithPadding(size_t chunk_size) { // Size of a chunk including header and padding. static WEBP_INLINE size_t ChunkDiskSize(const WebPChunk* chunk) { - const size_t data_size = chunk->data_.size; + const size_t data_size = chunk->data.size; return SizeWithPadding(data_size); } diff --git a/src/mux/muxinternal.c b/src/mux/muxinternal.c index 75b6b416..708becf6 100644 --- a/src/mux/muxinternal.c +++ b/src/mux/muxinternal.c @@ -45,16 +45,16 @@ int WebPGetMuxVersion(void) { void ChunkInit(WebPChunk* const chunk) { assert(chunk); memset(chunk, 0, sizeof(*chunk)); - chunk->tag_ = NIL_TAG; + chunk->tag = NIL_TAG; } WebPChunk* ChunkRelease(WebPChunk* const chunk) { WebPChunk* next; if (chunk == NULL) return NULL; - if (chunk->owner_) { - WebPDataClear(&chunk->data_); + if (chunk->owner) { + WebPDataClear(&chunk->data); } - next = chunk->next_; + next = chunk->next; ChunkInit(chunk); return next; } @@ -92,8 +92,8 @@ CHUNK_INDEX ChunkGetIndexFromFourCC(const char fourcc[4]) { // Returns next chunk in the chunk list with the given tag. static WebPChunk* ChunkSearchNextInList(WebPChunk* chunk, uint32_t tag) { - while (chunk != NULL && chunk->tag_ != tag) { - chunk = chunk->next_; + while (chunk != NULL && chunk->tag != tag) { + chunk = chunk->next; } return chunk; } @@ -104,7 +104,7 @@ WebPChunk* ChunkSearchList(WebPChunk* first, uint32_t nth, uint32_t tag) { if (first == NULL) return NULL; while (--iter != 0) { - WebPChunk* next_chunk = ChunkSearchNextInList(first->next_, tag); + WebPChunk* next_chunk = ChunkSearchNextInList(first->next, tag); if (next_chunk == NULL) break; first = next_chunk; } @@ -125,13 +125,13 @@ WebPMuxError ChunkAssignData(WebPChunk* chunk, const WebPData* const data, if (data != NULL) { if (copy_data) { // Copy data. - if (!WebPDataCopy(data, &chunk->data_)) return WEBP_MUX_MEMORY_ERROR; - chunk->owner_ = 1; // Chunk is owner of data. + if (!WebPDataCopy(data, &chunk->data)) return WEBP_MUX_MEMORY_ERROR; + chunk->owner = 1; // Chunk is owner of data. } else { // Don't copy data. - chunk->data_ = *data; + chunk->data = *data; } } - chunk->tag_ = tag; + chunk->tag = tag; return WEBP_MUX_OK; } @@ -147,8 +147,8 @@ WebPMuxError ChunkSetHead(WebPChunk* const chunk, new_chunk = (WebPChunk*)WebPSafeMalloc(1ULL, sizeof(*new_chunk)); if (new_chunk == NULL) return WEBP_MUX_MEMORY_ERROR; *new_chunk = *chunk; - chunk->owner_ = 0; - new_chunk->next_ = NULL; + chunk->owner = 0; + new_chunk->next = NULL; *chunk_list = new_chunk; return WEBP_MUX_OK; } @@ -162,9 +162,9 @@ WebPMuxError ChunkAppend(WebPChunk* const chunk, err = ChunkSetHead(chunk, *chunk_list); } else { WebPChunk* last_chunk = **chunk_list; - while (last_chunk->next_ != NULL) last_chunk = last_chunk->next_; - err = ChunkSetHead(chunk, &last_chunk->next_); - if (err == WEBP_MUX_OK) *chunk_list = &last_chunk->next_; + while (last_chunk->next != NULL) last_chunk = last_chunk->next; + err = ChunkSetHead(chunk, &last_chunk->next); + if (err == WEBP_MUX_OK) *chunk_list = &last_chunk->next; } return err; } @@ -188,13 +188,13 @@ void ChunkListDelete(WebPChunk** const chunk_list) { // Chunk serialization methods. static uint8_t* ChunkEmit(const WebPChunk* const chunk, uint8_t* dst) { - const size_t chunk_size = chunk->data_.size; + const size_t chunk_size = chunk->data.size; assert(chunk); - assert(chunk->tag_ != NIL_TAG); - PutLE32(dst + 0, chunk->tag_); + assert(chunk->tag != NIL_TAG); + PutLE32(dst + 0, chunk->tag); PutLE32(dst + TAG_SIZE, (uint32_t)chunk_size); assert(chunk_size == (uint32_t)chunk_size); - memcpy(dst + CHUNK_HEADER_SIZE, chunk->data_.bytes, chunk_size); + memcpy(dst + CHUNK_HEADER_SIZE, chunk->data.bytes, chunk_size); if (chunk_size & 1) dst[CHUNK_HEADER_SIZE + chunk_size] = 0; // Add padding. return dst + ChunkDiskSize(chunk); @@ -203,7 +203,7 @@ static uint8_t* ChunkEmit(const WebPChunk* const chunk, uint8_t* dst) { uint8_t* ChunkListEmit(const WebPChunk* chunk_list, uint8_t* dst) { while (chunk_list != NULL) { dst = ChunkEmit(chunk_list, dst); - chunk_list = chunk_list->next_; + chunk_list = chunk_list->next; } return dst; } @@ -212,7 +212,7 @@ size_t ChunkListDiskSize(const WebPChunk* chunk_list) { size_t size = 0; while (chunk_list != NULL) { size += ChunkDiskSize(chunk_list); - chunk_list = chunk_list->next_; + chunk_list = chunk_list->next; } return size; } @@ -228,14 +228,14 @@ void MuxImageInit(WebPMuxImage* const wpi) { WebPMuxImage* MuxImageRelease(WebPMuxImage* const wpi) { WebPMuxImage* next; if (wpi == NULL) return NULL; - // There should be at most one chunk of header_, alpha_, img_ but we call + // There should be at most one chunk of 'header', 'alpha', 'img' but we call // ChunkListDelete to be safe - ChunkListDelete(&wpi->header_); - ChunkListDelete(&wpi->alpha_); - ChunkListDelete(&wpi->img_); - ChunkListDelete(&wpi->unknown_); + ChunkListDelete(&wpi->header); + ChunkListDelete(&wpi->alpha); + ChunkListDelete(&wpi->img); + ChunkListDelete(&wpi->unknown); - next = wpi->next_; + next = wpi->next; MuxImageInit(wpi); return next; } @@ -248,9 +248,9 @@ static WebPChunk** GetChunkListFromId(const WebPMuxImage* const wpi, WebPChunkId id) { assert(wpi != NULL); switch (id) { - case WEBP_CHUNK_ANMF: return (WebPChunk**)&wpi->header_; - case WEBP_CHUNK_ALPHA: return (WebPChunk**)&wpi->alpha_; - case WEBP_CHUNK_IMAGE: return (WebPChunk**)&wpi->img_; + case WEBP_CHUNK_ANMF: return (WebPChunk**)&wpi->header; + case WEBP_CHUNK_ALPHA: return (WebPChunk**)&wpi->alpha; + case WEBP_CHUNK_IMAGE: return (WebPChunk**)&wpi->img; default: return NULL; } } @@ -258,13 +258,13 @@ static WebPChunk** GetChunkListFromId(const WebPMuxImage* const wpi, int MuxImageCount(const WebPMuxImage* wpi_list, WebPChunkId id) { int count = 0; const WebPMuxImage* current; - for (current = wpi_list; current != NULL; current = current->next_) { + for (current = wpi_list; current != NULL; current = current->next) { if (id == WEBP_CHUNK_NIL) { ++count; // Special case: count all images. } else { const WebPChunk* const wpi_chunk = *GetChunkListFromId(current, id); if (wpi_chunk != NULL) { - const WebPChunkId wpi_chunk_id = ChunkGetIdFromTag(wpi_chunk->tag_); + const WebPChunkId wpi_chunk_id = ChunkGetIdFromTag(wpi_chunk->tag); if (wpi_chunk_id == id) ++count; // Count images with a matching 'id'. } } @@ -272,7 +272,7 @@ int MuxImageCount(const WebPMuxImage* wpi_list, WebPChunkId id) { return count; } -// Outputs a pointer to 'prev_wpi->next_', +// Outputs a pointer to 'prev_wpi->next', // where 'prev_wpi' is the pointer to the image at position (nth - 1). // Returns true if nth image was found. static int SearchImageToGetOrDelete(WebPMuxImage** wpi_list, uint32_t nth, @@ -290,7 +290,7 @@ static int SearchImageToGetOrDelete(WebPMuxImage** wpi_list, uint32_t nth, WebPMuxImage* const cur_wpi = *wpi_list; ++count; if (count == nth) return 1; // Found. - wpi_list = &cur_wpi->next_; + wpi_list = &cur_wpi->next; *location = wpi_list; } return 0; // Not found. @@ -304,17 +304,17 @@ WebPMuxError MuxImagePush(const WebPMuxImage* wpi, WebPMuxImage** wpi_list) { while (*wpi_list != NULL) { WebPMuxImage* const cur_wpi = *wpi_list; - if (cur_wpi->next_ == NULL) break; - wpi_list = &cur_wpi->next_; + if (cur_wpi->next == NULL) break; + wpi_list = &cur_wpi->next; } new_wpi = (WebPMuxImage*)WebPSafeMalloc(1ULL, sizeof(*new_wpi)); if (new_wpi == NULL) return WEBP_MUX_MEMORY_ERROR; *new_wpi = *wpi; - new_wpi->next_ = NULL; + new_wpi->next = NULL; if (*wpi_list != NULL) { - (*wpi_list)->next_ = new_wpi; + (*wpi_list)->next = new_wpi; } else { *wpi_list = new_wpi; } @@ -361,23 +361,23 @@ WebPMuxError MuxImageGetNth(const WebPMuxImage** wpi_list, uint32_t nth, // Size of an image. size_t MuxImageDiskSize(const WebPMuxImage* const wpi) { size_t size = 0; - if (wpi->header_ != NULL) size += ChunkDiskSize(wpi->header_); - if (wpi->alpha_ != NULL) size += ChunkDiskSize(wpi->alpha_); - if (wpi->img_ != NULL) size += ChunkDiskSize(wpi->img_); - if (wpi->unknown_ != NULL) size += ChunkListDiskSize(wpi->unknown_); + if (wpi->header != NULL) size += ChunkDiskSize(wpi->header); + if (wpi->alpha != NULL) size += ChunkDiskSize(wpi->alpha); + if (wpi->img != NULL) size += ChunkDiskSize(wpi->img); + if (wpi->unknown != NULL) size += ChunkListDiskSize(wpi->unknown); return size; } // Special case as ANMF chunk encapsulates other image chunks. static uint8_t* ChunkEmitSpecial(const WebPChunk* const header, size_t total_size, uint8_t* dst) { - const size_t header_size = header->data_.size; + const size_t header_size = header->data.size; const size_t offset_to_next = total_size - CHUNK_HEADER_SIZE; - assert(header->tag_ == kChunks[IDX_ANMF].tag); - PutLE32(dst + 0, header->tag_); + assert(header->tag == kChunks[IDX_ANMF].tag); + PutLE32(dst + 0, header->tag); PutLE32(dst + TAG_SIZE, (uint32_t)offset_to_next); assert(header_size == (uint32_t)header_size); - memcpy(dst + CHUNK_HEADER_SIZE, header->data_.bytes, header_size); + memcpy(dst + CHUNK_HEADER_SIZE, header->data.bytes, header_size); if (header_size & 1) { dst[CHUNK_HEADER_SIZE + header_size] = 0; // Add padding. } @@ -390,12 +390,12 @@ uint8_t* MuxImageEmit(const WebPMuxImage* const wpi, uint8_t* dst) { // 2. ALPH chunk (if present). // 3. VP8/VP8L chunk. assert(wpi); - if (wpi->header_ != NULL) { - dst = ChunkEmitSpecial(wpi->header_, MuxImageDiskSize(wpi), dst); + if (wpi->header != NULL) { + dst = ChunkEmitSpecial(wpi->header, MuxImageDiskSize(wpi), dst); } - if (wpi->alpha_ != NULL) dst = ChunkEmit(wpi->alpha_, dst); - if (wpi->img_ != NULL) dst = ChunkEmit(wpi->img_, dst); - if (wpi->unknown_ != NULL) dst = ChunkListEmit(wpi->unknown_, dst); + if (wpi->alpha != NULL) dst = ChunkEmit(wpi->alpha, dst); + if (wpi->img != NULL) dst = ChunkEmit(wpi->img, dst); + if (wpi->unknown != NULL) dst = ChunkListEmit(wpi->unknown, dst); return dst; } @@ -404,8 +404,8 @@ uint8_t* MuxImageEmit(const WebPMuxImage* const wpi, uint8_t* dst) { int MuxHasAlpha(const WebPMuxImage* images) { while (images != NULL) { - if (images->has_alpha_) return 1; - images = images->next_; + if (images->has_alpha) return 1; + images = images->next; } return 0; } @@ -421,12 +421,12 @@ uint8_t* MuxEmitRiffHeader(uint8_t* const data, size_t size) { WebPChunk** MuxGetChunkListFromId(const WebPMux* mux, WebPChunkId id) { assert(mux != NULL); switch (id) { - case WEBP_CHUNK_VP8X: return (WebPChunk**)&mux->vp8x_; - case WEBP_CHUNK_ICCP: return (WebPChunk**)&mux->iccp_; - case WEBP_CHUNK_ANIM: return (WebPChunk**)&mux->anim_; - case WEBP_CHUNK_EXIF: return (WebPChunk**)&mux->exif_; - case WEBP_CHUNK_XMP: return (WebPChunk**)&mux->xmp_; - default: return (WebPChunk**)&mux->unknown_; + case WEBP_CHUNK_VP8X: return (WebPChunk**)&mux->vp8x; + case WEBP_CHUNK_ICCP: return (WebPChunk**)&mux->iccp; + case WEBP_CHUNK_ANIM: return (WebPChunk**)&mux->anim; + case WEBP_CHUNK_EXIF: return (WebPChunk**)&mux->exif; + case WEBP_CHUNK_XMP: return (WebPChunk**)&mux->xmp; + default: return (WebPChunk**)&mux->unknown; } } @@ -470,7 +470,7 @@ WebPMuxError MuxValidate(const WebPMux* const mux) { if (mux == NULL) return WEBP_MUX_INVALID_ARGUMENT; // Verify mux has at least one image. - if (mux->images_ == NULL) return WEBP_MUX_INVALID_ARGUMENT; + if (mux->images == NULL) return WEBP_MUX_INVALID_ARGUMENT; err = WebPMuxGetFeatures(mux, &flags); if (err != WEBP_MUX_OK) return err; @@ -503,15 +503,15 @@ WebPMuxError MuxValidate(const WebPMux* const mux) { return WEBP_MUX_INVALID_ARGUMENT; } if (!has_animation) { - const WebPMuxImage* images = mux->images_; + const WebPMuxImage* images = mux->images; // There can be only one image. - if (images == NULL || images->next_ != NULL) { + if (images == NULL || images->next != NULL) { return WEBP_MUX_INVALID_ARGUMENT; } // Size must match. - if (mux->canvas_width_ > 0) { - if (images->width_ != mux->canvas_width_ || - images->height_ != mux->canvas_height_) { + if (mux->canvas_width > 0) { + if (images->width != mux->canvas_width || + images->height != mux->canvas_height) { return WEBP_MUX_INVALID_ARGUMENT; } } @@ -519,7 +519,7 @@ WebPMuxError MuxValidate(const WebPMux* const mux) { } // Verify either VP8X chunk is present OR there is only one elem in - // mux->images_. + // mux->images. err = ValidateChunk(mux, IDX_VP8X, NO_FLAG, flags, 1, &num_vp8x); if (err != WEBP_MUX_OK) return err; err = ValidateChunk(mux, IDX_VP8, NO_FLAG, flags, -1, &num_images); @@ -528,7 +528,7 @@ WebPMuxError MuxValidate(const WebPMux* const mux) { // ALPHA_FLAG & alpha chunk(s) are consistent. // Note: ALPHA_FLAG can be set when there is actually no Alpha data present. - if (MuxHasAlpha(mux->images_)) { + if (MuxHasAlpha(mux->images)) { if (num_vp8x > 0) { // VP8X chunk is present, so it should contain ALPHA_FLAG. if (!(flags & ALPHA_FLAG)) return WEBP_MUX_INVALID_ARGUMENT; diff --git a/src/mux/muxread.c b/src/mux/muxread.c index aa406c1a..9a7ba7c6 100644 --- a/src/mux/muxread.c +++ b/src/mux/muxread.c @@ -26,7 +26,7 @@ const WebPChunk* const chunk = ChunkSearchList((LIST), nth, \ kChunks[(INDEX)].tag); \ if (chunk) { \ - *data = chunk->data_; \ + *data = chunk->data; \ return WEBP_MUX_OK; \ } else { \ return WEBP_MUX_NOT_FOUND; \ @@ -41,11 +41,11 @@ static WebPMuxError MuxGet(const WebPMux* const mux, CHUNK_INDEX idx, assert(!IsWPI(kChunks[idx].id)); WebPDataInit(data); - SWITCH_ID_LIST(IDX_VP8X, mux->vp8x_); - SWITCH_ID_LIST(IDX_ICCP, mux->iccp_); - SWITCH_ID_LIST(IDX_ANIM, mux->anim_); - SWITCH_ID_LIST(IDX_EXIF, mux->exif_); - SWITCH_ID_LIST(IDX_XMP, mux->xmp_); + SWITCH_ID_LIST(IDX_VP8X, mux->vp8x); + SWITCH_ID_LIST(IDX_ICCP, mux->iccp); + SWITCH_ID_LIST(IDX_ANIM, mux->anim); + SWITCH_ID_LIST(IDX_EXIF, mux->exif); + SWITCH_ID_LIST(IDX_XMP, mux->xmp); assert(idx != IDX_UNKNOWN); return WEBP_MUX_NOT_FOUND; } @@ -77,9 +77,9 @@ static WebPMuxError ChunkVerifyAndAssign(WebPChunk* chunk, } int MuxImageFinalize(WebPMuxImage* const wpi) { - const WebPChunk* const img = wpi->img_; - const WebPData* const image = &img->data_; - const int is_lossless = (img->tag_ == kChunks[IDX_VP8L].tag); + const WebPChunk* const img = wpi->img; + const WebPData* const image = &img->data; + const int is_lossless = (img->tag == kChunks[IDX_VP8L].tag); int w, h; int vp8l_has_alpha = 0; const int ok = is_lossless ? @@ -88,29 +88,29 @@ int MuxImageFinalize(WebPMuxImage* const wpi) { assert(img != NULL); if (ok) { // Ignore ALPH chunk accompanying VP8L. - if (is_lossless && (wpi->alpha_ != NULL)) { - ChunkDelete(wpi->alpha_); - wpi->alpha_ = NULL; + if (is_lossless && (wpi->alpha != NULL)) { + ChunkDelete(wpi->alpha); + wpi->alpha = NULL; } - wpi->width_ = w; - wpi->height_ = h; - wpi->has_alpha_ = vp8l_has_alpha || (wpi->alpha_ != NULL); + wpi->width = w; + wpi->height = h; + wpi->has_alpha = vp8l_has_alpha || (wpi->alpha != NULL); } return ok; } static int MuxImageParse(const WebPChunk* const chunk, int copy_data, WebPMuxImage* const wpi) { - const uint8_t* bytes = chunk->data_.bytes; - size_t size = chunk->data_.size; + const uint8_t* bytes = chunk->data.bytes; + size_t size = chunk->data.size; const uint8_t* const last = (bytes == NULL) ? NULL : bytes + size; WebPChunk subchunk; size_t subchunk_size; - WebPChunk** unknown_chunk_list = &wpi->unknown_; + WebPChunk** unknown_chunk_list = &wpi->unknown; ChunkInit(&subchunk); - assert(chunk->tag_ == kChunks[IDX_ANMF].tag); - assert(!wpi->is_partial_); + assert(chunk->tag == kChunks[IDX_ANMF].tag); + assert(!wpi->is_partial); // ANMF. { @@ -120,12 +120,12 @@ static int MuxImageParse(const WebPChunk* const chunk, int copy_data, // be at least 'hdr_size'. if (size < hdr_size) goto Fail; if (ChunkAssignData(&subchunk, &temp, copy_data, - chunk->tag_) != WEBP_MUX_OK) { + chunk->tag) != WEBP_MUX_OK) { goto Fail; } } - if (ChunkSetHead(&subchunk, &wpi->header_) != WEBP_MUX_OK) goto Fail; - wpi->is_partial_ = 1; // Waiting for ALPH and/or VP8/VP8L chunks. + if (ChunkSetHead(&subchunk, &wpi->header) != WEBP_MUX_OK) goto Fail; + wpi->is_partial = 1; // Waiting for ALPH and/or VP8/VP8L chunks. // Rest of the chunks. subchunk_size = ChunkDiskSize(&subchunk) - CHUNK_HEADER_SIZE; @@ -138,20 +138,20 @@ static int MuxImageParse(const WebPChunk* const chunk, int copy_data, copy_data) != WEBP_MUX_OK) { goto Fail; } - switch (ChunkGetIdFromTag(subchunk.tag_)) { + switch (ChunkGetIdFromTag(subchunk.tag)) { case WEBP_CHUNK_ALPHA: - if (wpi->alpha_ != NULL) goto Fail; // Consecutive ALPH chunks. - if (ChunkSetHead(&subchunk, &wpi->alpha_) != WEBP_MUX_OK) goto Fail; - wpi->is_partial_ = 1; // Waiting for a VP8 chunk. + if (wpi->alpha != NULL) goto Fail; // Consecutive ALPH chunks. + if (ChunkSetHead(&subchunk, &wpi->alpha) != WEBP_MUX_OK) goto Fail; + wpi->is_partial = 1; // Waiting for a VP8 chunk. break; case WEBP_CHUNK_IMAGE: - if (wpi->img_ != NULL) goto Fail; // Only 1 image chunk allowed. - if (ChunkSetHead(&subchunk, &wpi->img_) != WEBP_MUX_OK) goto Fail; + if (wpi->img != NULL) goto Fail; // Only 1 image chunk allowed. + if (ChunkSetHead(&subchunk, &wpi->img) != WEBP_MUX_OK) goto Fail; if (!MuxImageFinalize(wpi)) goto Fail; - wpi->is_partial_ = 0; // wpi is completely filled. + wpi->is_partial = 0; // wpi is completely filled. break; case WEBP_CHUNK_UNKNOWN: - if (wpi->is_partial_) { + if (wpi->is_partial) { goto Fail; // Encountered an unknown chunk // before some image chunks. } @@ -166,7 +166,7 @@ static int MuxImageParse(const WebPChunk* const chunk, int copy_data, bytes += subchunk_size; size -= subchunk_size; } - if (wpi->is_partial_) goto Fail; + if (wpi->is_partial) goto Fail; return 1; Fail: @@ -249,29 +249,29 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data, goto Err; } data_size = ChunkDiskSize(&chunk); - id = ChunkGetIdFromTag(chunk.tag_); + id = ChunkGetIdFromTag(chunk.tag); switch (id) { case WEBP_CHUNK_ALPHA: - if (wpi->alpha_ != NULL) goto Err; // Consecutive ALPH chunks. - if (ChunkSetHead(&chunk, &wpi->alpha_) != WEBP_MUX_OK) goto Err; - wpi->is_partial_ = 1; // Waiting for a VP8 chunk. + if (wpi->alpha != NULL) goto Err; // Consecutive ALPH chunks. + if (ChunkSetHead(&chunk, &wpi->alpha) != WEBP_MUX_OK) goto Err; + wpi->is_partial = 1; // Waiting for a VP8 chunk. break; case WEBP_CHUNK_IMAGE: - if (ChunkSetHead(&chunk, &wpi->img_) != WEBP_MUX_OK) goto Err; + if (ChunkSetHead(&chunk, &wpi->img) != WEBP_MUX_OK) goto Err; if (!MuxImageFinalize(wpi)) goto Err; - wpi->is_partial_ = 0; // wpi is completely filled. + wpi->is_partial = 0; // wpi is completely filled. PushImage: - // Add this to mux->images_ list. - if (MuxImagePush(wpi, &mux->images_) != WEBP_MUX_OK) goto Err; + // Add this to mux->images list. + if (MuxImagePush(wpi, &mux->images) != WEBP_MUX_OK) goto Err; MuxImageInit(wpi); // Reset for reading next image. break; case WEBP_CHUNK_ANMF: - if (wpi->is_partial_) goto Err; // Previous wpi is still incomplete. + if (wpi->is_partial) goto Err; // Previous wpi is still incomplete. if (!MuxImageParse(&chunk, copy_data, wpi)) goto Err; ChunkRelease(&chunk); goto PushImage; default: // A non-image chunk. - if (wpi->is_partial_) goto Err; // Encountered a non-image chunk before + if (wpi->is_partial) goto Err; // Encountered a non-image chunk before // getting all chunks of an image. if (chunk_list_ends[id] == NULL) { chunk_list_ends[id] = @@ -280,8 +280,8 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data, if (ChunkAppend(&chunk, &chunk_list_ends[id]) != WEBP_MUX_OK) goto Err; if (id == WEBP_CHUNK_VP8X) { // grab global specs if (data_size < CHUNK_HEADER_SIZE + VP8X_CHUNK_SIZE) goto Err; - mux->canvas_width_ = GetLE24(data + 12) + 1; - mux->canvas_height_ = GetLE24(data + 15) + 1; + mux->canvas_width = GetLE24(data + 12) + 1; + mux->canvas_height = GetLE24(data + 15) + 1; } break; } @@ -291,7 +291,7 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data, } // Incomplete image. - if (wpi->is_partial_) goto Err; + if (wpi->is_partial) goto Err; // Validate mux if complete. if (MuxValidate(mux) != WEBP_MUX_OK) goto Err; @@ -311,8 +311,8 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data, // Validates that the given mux has a single image. static WebPMuxError ValidateForSingleImage(const WebPMux* const mux) { - const int num_images = MuxImageCount(mux->images_, WEBP_CHUNK_IMAGE); - const int num_frames = MuxImageCount(mux->images_, WEBP_CHUNK_ANMF); + const int num_images = MuxImageCount(mux->images, WEBP_CHUNK_IMAGE); + const int num_frames = MuxImageCount(mux->images, WEBP_CHUNK_ANMF); if (num_images == 0) { // No images in mux. @@ -342,18 +342,18 @@ static WebPMuxError MuxGetCanvasInfo(const WebPMux* const mux, w = GetLE24(data.bytes + 4) + 1; h = GetLE24(data.bytes + 7) + 1; } else { - const WebPMuxImage* const wpi = mux->images_; + const WebPMuxImage* const wpi = mux->images; // Grab user-forced canvas size as default. - w = mux->canvas_width_; - h = mux->canvas_height_; + w = mux->canvas_width; + h = mux->canvas_height; if (w == 0 && h == 0 && ValidateForSingleImage(mux) == WEBP_MUX_OK) { // single image and not forced canvas size => use dimension of first frame assert(wpi != NULL); - w = wpi->width_; - h = wpi->height_; + w = wpi->width; + h = wpi->height; } if (wpi != NULL) { - if (wpi->has_alpha_) f |= ALPHA_FLAG; + if (wpi->has_alpha) f |= ALPHA_FLAG; } } if (w * (uint64_t)h >= MAX_IMAGE_AREA) return WEBP_MUX_BAD_DATA; @@ -396,29 +396,29 @@ static WebPMuxError SynthesizeBitstream(const WebPMuxImage* const wpi, uint8_t* dst; // Allocate data. - const int need_vp8x = (wpi->alpha_ != NULL); + const int need_vp8x = (wpi->alpha != NULL); const size_t vp8x_size = need_vp8x ? CHUNK_HEADER_SIZE + VP8X_CHUNK_SIZE : 0; - const size_t alpha_size = need_vp8x ? ChunkDiskSize(wpi->alpha_) : 0; + const size_t alpha_size = need_vp8x ? ChunkDiskSize(wpi->alpha) : 0; // Note: No need to output ANMF chunk for a single image. const size_t size = RIFF_HEADER_SIZE + vp8x_size + alpha_size + - ChunkDiskSize(wpi->img_); + ChunkDiskSize(wpi->img); uint8_t* const data = (uint8_t*)WebPSafeMalloc(1ULL, size); if (data == NULL) return WEBP_MUX_MEMORY_ERROR; - // There should be at most one alpha_ chunk and exactly one img_ chunk. - assert(wpi->alpha_ == NULL || wpi->alpha_->next_ == NULL); - assert(wpi->img_ != NULL && wpi->img_->next_ == NULL); + // There should be at most one alpha chunk and exactly one img chunk. + assert(wpi->alpha == NULL || wpi->alpha->next == NULL); + assert(wpi->img != NULL && wpi->img->next == NULL); // Main RIFF header. dst = MuxEmitRiffHeader(data, size); if (need_vp8x) { - dst = EmitVP8XChunk(dst, wpi->width_, wpi->height_, ALPHA_FLAG); // VP8X. - dst = ChunkListEmit(wpi->alpha_, dst); // ALPH. + dst = EmitVP8XChunk(dst, wpi->width, wpi->height, ALPHA_FLAG); // VP8X. + dst = ChunkListEmit(wpi->alpha, dst); // ALPH. } // Bitstream. - dst = ChunkListEmit(wpi->img_, dst); + dst = ChunkListEmit(wpi->img, dst); assert(dst == data + size); // Output. @@ -441,9 +441,9 @@ WebPMuxError WebPMuxGetChunk(const WebPMux* mux, const char fourcc[4], return MuxGet(mux, idx, 1, chunk_data); } else { // An unknown chunk type. const WebPChunk* const chunk = - ChunkSearchList(mux->unknown_, 1, ChunkGetTagFromFourCC(fourcc)); + ChunkSearchList(mux->unknown, 1, ChunkGetTagFromFourCC(fourcc)); if (chunk == NULL) return WEBP_MUX_NOT_FOUND; - *chunk_data = chunk->data_; + *chunk_data = chunk->data; return WEBP_MUX_OK; } } @@ -457,18 +457,18 @@ static WebPMuxError MuxGetImageInternal(const WebPMuxImage* const wpi, info->dispose_method = WEBP_MUX_DISPOSE_NONE; info->blend_method = WEBP_MUX_BLEND; // Extract data for related fields. - info->id = ChunkGetIdFromTag(wpi->img_->tag_); + info->id = ChunkGetIdFromTag(wpi->img->tag); return SynthesizeBitstream(wpi, &info->bitstream); } static WebPMuxError MuxGetFrameInternal(const WebPMuxImage* const wpi, WebPMuxFrameInfo* const frame) { - const int is_frame = (wpi->header_->tag_ == kChunks[IDX_ANMF].tag); + const int is_frame = (wpi->header->tag == kChunks[IDX_ANMF].tag); const WebPData* frame_data; if (!is_frame) return WEBP_MUX_INVALID_ARGUMENT; - assert(wpi->header_ != NULL); // Already checked by WebPMuxGetFrame(). + assert(wpi->header != NULL); // Already checked by WebPMuxGetFrame(). // Get frame chunk. - frame_data = &wpi->header_->data_; + frame_data = &wpi->header->data; if (frame_data->size < kChunks[IDX_ANMF].size) return WEBP_MUX_BAD_DATA; // Extract info. frame->x_offset = 2 * GetLE24(frame_data->bytes + 0); @@ -480,7 +480,7 @@ static WebPMuxError MuxGetFrameInternal(const WebPMuxImage* const wpi, (bits & 1) ? WEBP_MUX_DISPOSE_BACKGROUND : WEBP_MUX_DISPOSE_NONE; frame->blend_method = (bits & 2) ? WEBP_MUX_NO_BLEND : WEBP_MUX_BLEND; } - frame->id = ChunkGetIdFromTag(wpi->header_->tag_); + frame->id = ChunkGetIdFromTag(wpi->header->tag); return SynthesizeBitstream(wpi, &frame->bitstream); } @@ -494,11 +494,11 @@ WebPMuxError WebPMuxGetFrame( } // Get the nth WebPMuxImage. - err = MuxImageGetNth((const WebPMuxImage**)&mux->images_, nth, &wpi); + err = MuxImageGetNth((const WebPMuxImage**)&mux->images, nth, &wpi); if (err != WEBP_MUX_OK) return err; // Get frame info. - if (wpi->header_ == NULL) { + if (wpi->header == NULL) { return MuxGetImageInternal(wpi, frame); } else { return MuxGetFrameInternal(wpi, frame); @@ -535,8 +535,8 @@ static CHUNK_INDEX ChunkGetIndexFromId(WebPChunkId id) { static int CountChunks(const WebPChunk* const chunk_list, uint32_t tag) { int count = 0; const WebPChunk* current; - for (current = chunk_list; current != NULL; current = current->next_) { - if (tag == NIL_TAG || current->tag_ == tag) { + for (current = chunk_list; current != NULL; current = current->next) { + if (tag == NIL_TAG || current->tag == tag) { count++; // Count chunks whose tags match. } } @@ -550,7 +550,7 @@ WebPMuxError WebPMuxNumChunks(const WebPMux* mux, } if (IsWPI(id)) { - *num_elements = MuxImageCount(mux->images_, id); + *num_elements = MuxImageCount(mux->images, id); } else { WebPChunk* const* chunk_list = MuxGetChunkListFromId(mux, id); const CHUNK_INDEX idx = ChunkGetIndexFromId(id);