From f18281ffa0eeb3a6c460c436b852e868680c0e4c Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 28 May 2012 23:02:02 -0700 Subject: [PATCH] WebPReportProgress: use non-encoder specific params Take picture and percent value storage location instead of VP8Encoder. This will allow reuse by the lossless encoder. Change-Id: Ic49dbc800cc3e2df60d20f4ebac277f68ed6031b --- src/enc/alpha.c | 2 +- src/enc/frame.c | 2 +- src/enc/iterator.c | 7 ++++--- src/enc/syntax.c | 5 +++-- src/enc/vp8enci.h | 3 ++- src/enc/webpenc.c | 10 +++++----- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/enc/alpha.c b/src/enc/alpha.c index 626c5a41..ce5f3e8f 100644 --- a/src/enc/alpha.c +++ b/src/enc/alpha.c @@ -311,7 +311,7 @@ int VP8EncFinishAlpha(VP8Encoder* enc) { enc->alpha_data_size_ = (uint32_t)tmp_size; enc->alpha_data_ = tmp_data; } - return WebPReportProgress(enc, enc->percent_ + 20); + return WebPReportProgress(enc->pic_, enc->percent_ + 20, &enc->percent_); } void VP8EncDeleteAlpha(VP8Encoder* enc) { diff --git a/src/enc/frame.c b/src/enc/frame.c index 54bd07b1..bdd36006 100644 --- a/src/enc/frame.c +++ b/src/enc/frame.c @@ -929,7 +929,7 @@ int VP8StatLoop(VP8Encoder* const enc) { } } } - return WebPReportProgress(enc, final_percent); + return WebPReportProgress(enc->pic_, final_percent, &enc->percent_); } //------------------------------------------------------------------------------ diff --git a/src/enc/iterator.c b/src/enc/iterator.c index 16dbe0c1..c1aa3abe 100644 --- a/src/enc/iterator.c +++ b/src/enc/iterator.c @@ -70,9 +70,10 @@ void VP8IteratorInit(VP8Encoder* const enc, VP8EncIterator* const it) { } int VP8IteratorProgress(const VP8EncIterator* const it, int delta) { - if (delta && it->enc_->pic_->progress_hook) { - const int percent = it->percent0_ + delta * it->y_ / (it->enc_->mb_h_ - 1); - return WebPReportProgress(it->enc_, percent); + VP8Encoder* const enc = it->enc_; + if (delta && enc->pic_->progress_hook) { + const int percent = it->percent0_ + delta * it->y_ / (enc->mb_h_ - 1); + return WebPReportProgress(enc->pic_, percent, &enc->percent_); } return 1; } diff --git a/src/enc/syntax.c b/src/enc/syntax.c index 99309c0c..7773c9a7 100644 --- a/src/enc/syntax.c +++ b/src/enc/syntax.c @@ -416,7 +416,8 @@ int VP8EncWrite(VP8Encoder* const enc) { if (size) ok = ok && pic->writer(buf, size, pic); VP8BitWriterWipeOut(enc->parts_ + p); // will free the internal buffer. - ok = ok && WebPReportProgress(enc, enc->percent_ + percent_per_part); + ok = ok && WebPReportProgress(pic, enc->percent_ + percent_per_part, + &enc->percent_); } // Padding byte @@ -425,7 +426,7 @@ int VP8EncWrite(VP8Encoder* const enc) { } enc->coded_size_ = (int)(CHUNK_HEADER_SIZE + riff_size); - ok = ok && WebPReportProgress(enc, final_percent); + ok = ok && WebPReportProgress(pic, final_percent, &enc->percent_); return ok; } diff --git a/src/enc/vp8enci.h b/src/enc/vp8enci.h index 2900db51..b3f7c162 100644 --- a/src/enc/vp8enci.h +++ b/src/enc/vp8enci.h @@ -474,7 +474,8 @@ int VP8StatLoop(VP8Encoder* const enc); // in webpenc.c // Assign an error code to a picture. Return false for convenience. int WebPEncodingSetError(const WebPPicture* const pic, WebPEncodingError error); -int WebPReportProgress(VP8Encoder* const enc, int percent); +int WebPReportProgress(const WebPPicture* const pic, + int percent, int* const percent_store); // in analysis.c // Main analysis loop. Decides the segmentations and complexity. diff --git a/src/enc/webpenc.c b/src/enc/webpenc.c index bbf604d4..28e45f95 100644 --- a/src/enc/webpenc.c +++ b/src/enc/webpenc.c @@ -303,7 +303,7 @@ static void StoreStats(VP8Encoder* const enc) { stats->block_count[i] = enc->block_count_[i]; } } - WebPReportProgress(enc, 100); // done! + WebPReportProgress(enc->pic_, 100, &enc->percent_); // done! } int WebPEncodingSetError(const WebPPicture* const pic, @@ -314,10 +314,10 @@ int WebPEncodingSetError(const WebPPicture* const pic, return 0; } -int WebPReportProgress(VP8Encoder* const enc, int percent) { - if (percent != enc->percent_) { - WebPPicture* const pic = enc->pic_; - enc->percent_ = percent; +int WebPReportProgress(const WebPPicture* const pic, + int percent, int* const percent_store) { + if (percent_store != NULL && percent != *percent_store) { + *percent_store = percent; if (pic->progress_hook && !pic->progress_hook(percent, pic)) { // user abort requested WebPEncodingSetError(pic, VP8_ENC_ERROR_USER_ABORT);