| Index: third_party/libwebp/dec/vp8.c
|
| diff --git a/third_party/libwebp/dec/vp8.c b/third_party/libwebp/dec/vp8.c
|
| index bfd0e8f9d3827ad77469d9ef8137acfadddcd7ab..47249d64b04d50b87e5c5e1371e1fb982375dc1e 100644
|
| --- a/third_party/libwebp/dec/vp8.c
|
| +++ b/third_party/libwebp/dec/vp8.c
|
| @@ -17,7 +17,8 @@
|
| #include "./vp8i.h"
|
| #include "./vp8li.h"
|
| #include "./webpi.h"
|
| -#include "../utils/bit_reader.h"
|
| +#include "../utils/bit_reader_inl.h"
|
| +#include "../utils/utils.h"
|
|
|
| //------------------------------------------------------------------------------
|
|
|
| @@ -44,10 +45,10 @@ int VP8InitIoInternal(VP8Io* const io, int version) {
|
| }
|
|
|
| VP8Decoder* VP8New(void) {
|
| - VP8Decoder* const dec = (VP8Decoder*)calloc(1, sizeof(*dec));
|
| + VP8Decoder* const dec = (VP8Decoder*)WebPSafeCalloc(1ULL, sizeof(*dec));
|
| if (dec != NULL) {
|
| SetOk(dec);
|
| - WebPWorkerInit(&dec->worker_);
|
| + WebPGetWorkerInterface()->Init(&dec->worker_);
|
| dec->ready_ = 0;
|
| dec->num_parts_ = 1;
|
| }
|
| @@ -68,7 +69,7 @@ const char* VP8StatusMessage(VP8Decoder* const dec) {
|
| void VP8Delete(VP8Decoder* const dec) {
|
| if (dec != NULL) {
|
| VP8Clear(dec);
|
| - free(dec);
|
| + WebPSafeFree(dec);
|
| }
|
| }
|
|
|
| @@ -317,7 +318,6 @@ int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io) {
|
|
|
| VP8ResetProba(&dec->proba_);
|
| ResetSegmentHeader(&dec->segment_hdr_);
|
| - dec->segment_ = 0; // default for intra
|
| }
|
|
|
| // Check if we have all the partition #0 available, and initialize dec->br_
|
| @@ -363,28 +363,6 @@ int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io) {
|
|
|
| VP8ParseProba(br, dec);
|
|
|
| -#ifdef WEBP_EXPERIMENTAL_FEATURES
|
| - // Extensions
|
| - if (dec->pic_hdr_.colorspace_) {
|
| - const size_t kTrailerSize = 8;
|
| - const uint8_t kTrailerMarker = 0x01;
|
| - const uint8_t* ext_buf = buf - kTrailerSize;
|
| - size_t size;
|
| -
|
| - if (frm_hdr->partition_length_ < kTrailerSize ||
|
| - ext_buf[kTrailerSize - 1] != kTrailerMarker) {
|
| - return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR,
|
| - "RIFF: Inconsistent extra information.");
|
| - }
|
| -
|
| - // Layer
|
| - size = (ext_buf[0] << 0) | (ext_buf[1] << 8) | (ext_buf[2] << 16);
|
| - dec->layer_data_size_ = size;
|
| - dec->layer_data_ = NULL; // will be set later
|
| - dec->layer_colorspace_ = ext_buf[3];
|
| - }
|
| -#endif
|
| -
|
| // sanitized state
|
| dec->ready_ = 1;
|
| return 1;
|
| @@ -479,8 +457,8 @@ static int ParseResiduals(VP8Decoder* const dec,
|
| VP8MB* const mb, VP8BitReader* const token_br) {
|
| VP8BandProbas (* const bands)[NUM_BANDS] = dec->proba_.bands_;
|
| const VP8BandProbas* ac_proba;
|
| - const VP8QuantMatrix* const q = &dec->dqm_[dec->segment_];
|
| VP8MBData* const block = dec->mb_data_ + dec->mb_x_;
|
| + const VP8QuantMatrix* const q = &dec->dqm_[block->segment_];
|
| int16_t* dst = block->coeffs_;
|
| VP8MB* const left_mb = dec->mb_info_ - 1;
|
| uint8_t tnz, lnz;
|
| @@ -570,26 +548,10 @@ static int ParseResiduals(VP8Decoder* const dec,
|
| // Main loop
|
|
|
| int VP8DecodeMB(VP8Decoder* const dec, VP8BitReader* const token_br) {
|
| - VP8BitReader* const br = &dec->br_;
|
| VP8MB* const left = dec->mb_info_ - 1;
|
| VP8MB* const mb = dec->mb_info_ + dec->mb_x_;
|
| VP8MBData* const block = dec->mb_data_ + dec->mb_x_;
|
| - int skip;
|
| -
|
| - // Note: we don't save segment map (yet), as we don't expect
|
| - // to decode more than 1 keyframe.
|
| - if (dec->segment_hdr_.update_map_) {
|
| - // Hardcoded tree parsing
|
| - dec->segment_ = !VP8GetBit(br, dec->proba_.segments_[0]) ?
|
| - VP8GetBit(br, dec->proba_.segments_[1]) :
|
| - 2 + VP8GetBit(br, dec->proba_.segments_[2]);
|
| - }
|
| - skip = dec->use_skip_proba_ ? VP8GetBit(br, dec->skip_p_) : 0;
|
| -
|
| - VP8ParseIntraMode(br, dec);
|
| - if (br->eof_) {
|
| - return 0;
|
| - }
|
| + int skip = dec->use_skip_proba_ ? block->skip_ : 0;
|
|
|
| if (!skip) {
|
| skip = ParseResiduals(dec, mb, token_br);
|
| @@ -604,7 +566,7 @@ int VP8DecodeMB(VP8Decoder* const dec, VP8BitReader* const token_br) {
|
|
|
| if (dec->filter_type_ > 0) { // store filter info
|
| VP8FInfo* const finfo = dec->f_info_ + dec->mb_x_;
|
| - *finfo = dec->fstrengths_[dec->segment_][block->is_i4x4_];
|
| + *finfo = dec->fstrengths_[block->segment_][block->is_i4x4_];
|
| finfo->f_inner_ |= !skip;
|
| }
|
|
|
| @@ -624,6 +586,10 @@ static int ParseFrame(VP8Decoder* const dec, VP8Io* io) {
|
| // Parse bitstream for this row.
|
| VP8BitReader* const token_br =
|
| &dec->parts_[dec->mb_y_ & (dec->num_parts_ - 1)];
|
| + if (!VP8ParseIntraModeRow(&dec->br_, dec)) {
|
| + return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA,
|
| + "Premature end-of-partition0 encountered.");
|
| + }
|
| for (; dec->mb_x_ < dec->mb_w_; ++dec->mb_x_) {
|
| if (!VP8DecodeMB(dec, token_br)) {
|
| return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA,
|
| @@ -638,17 +604,8 @@ static int ParseFrame(VP8Decoder* const dec, VP8Io* io) {
|
| }
|
| }
|
| if (dec->mt_method_ > 0) {
|
| - if (!WebPWorkerSync(&dec->worker_)) return 0;
|
| - }
|
| -
|
| - // Finish
|
| -#ifdef WEBP_EXPERIMENTAL_FEATURES
|
| - if (dec->layer_data_size_ > 0) {
|
| - if (!VP8DecodeLayer(dec)) {
|
| - return 0;
|
| - }
|
| + if (!WebPGetWorkerInterface()->Sync(&dec->worker_)) return 0;
|
| }
|
| -#endif
|
|
|
| return 1;
|
| }
|
| @@ -697,12 +654,10 @@ void VP8Clear(VP8Decoder* const dec) {
|
| if (dec == NULL) {
|
| return;
|
| }
|
| - if (dec->mt_method_ > 0) {
|
| - WebPWorkerEnd(&dec->worker_);
|
| - }
|
| + WebPGetWorkerInterface()->End(&dec->worker_);
|
| ALPHDelete(dec->alph_dec_);
|
| dec->alph_dec_ = NULL;
|
| - free(dec->mem_);
|
| + WebPSafeFree(dec->mem_);
|
| dec->mem_ = NULL;
|
| dec->mem_size_ = 0;
|
| memset(&dec->br_, 0, sizeof(dec->br_));
|
|
|