diff --git a/examples/cwebp.c b/examples/cwebp.c index ff8d3ea2..7bf4591f 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -140,10 +140,11 @@ static void PrintByteCount(const int bytes[4], int total_size, fprintf(stderr, "| %7d (%.1f%%)\n", total, 100.f * total / total_size); } -static void PrintPercents(const int counts[4], int total) { +static void PrintPercents(const int counts[4]) { int s; + const int total = counts[0] + counts[1] + counts[2] + counts[3]; for (s = 0; s < 4; ++s) { - fprintf(stderr, "| %2d%%", 100 * counts[s] / total); + fprintf(stderr, "| %2d%%", (int)(100. * counts[s] / total + .5)); } fprintf(stderr, "| %7d\n", total); } @@ -212,10 +213,11 @@ static void PrintExtraInfoLossy(const WebPPicture* const pic, int short_output, stats->PSNR[0], stats->PSNR[1], stats->PSNR[2], stats->PSNR[3]); if (total > 0) { int totals[4] = { 0, 0, 0, 0 }; - fprintf(stderr, "block count: intra4: %d\n" - " intra16: %d (-> %.2f%%)\n", - num_i4, num_i16, 100.f * num_i16 / total); - fprintf(stderr, " skipped block: %d (%.2f%%)\n", + fprintf(stderr, "block count: intra4: %6d (%.2f%%)\n" + " intra16: %6d (%.2f%%)\n" + " skipped: %6d (%.2f%%)\n", + num_i4, 100.f * num_i4 / total, + num_i16, 100.f * num_i16 / total, num_skip, 100.f * num_skip / total); fprintf(stderr, "bytes used: header: %6d (%.1f%%)\n" " mode-partition: %6d (%.1f%%)\n", @@ -239,7 +241,7 @@ static void PrintExtraInfoLossy(const WebPPicture* const pic, int short_output, PrintByteCount(stats->residual_bytes[2], stats->coded_size, totals); } fprintf(stderr, " macroblocks: "); - PrintPercents(stats->segment_size, total); + PrintPercents(stats->segment_size); fprintf(stderr, " quantizer: "); PrintValues(stats->segment_quant); fprintf(stderr, " filter level: "); diff --git a/src/enc/frame_enc.c b/src/enc/frame_enc.c index 15a81ae9..1aec376e 100644 --- a/src/enc/frame_enc.c +++ b/src/enc/frame_enc.c @@ -198,7 +198,7 @@ static void SetSegmentProbas(VP8Encoder* const enc) { for (n = 0; n < enc->mb_w_ * enc->mb_h_; ++n) { const VP8MBInfo* const mb = &enc->mb_info_[n]; - p[mb->segment_]++; + ++p[mb->segment_]; } #if !defined(WEBP_DISABLE_STATS) if (enc->pic_->stats != NULL) { @@ -520,6 +520,14 @@ static void StoreSideInfo(const VP8EncIterator* const it) { #endif } +static void ResetSideInfo(const VP8EncIterator* const it) { + VP8Encoder* const enc = it->enc_; + WebPPicture* const pic = enc->pic_; + if (pic->stats != NULL) { + memset(enc->block_count_, 0, sizeof(enc->block_count_)); + } + ResetSSE(enc); +} #else // defined(WEBP_DISABLE_STATS) static void ResetSSE(VP8Encoder* const enc) { (void)enc; @@ -528,10 +536,16 @@ static void StoreSideInfo(const VP8EncIterator* const it) { VP8Encoder* const enc = it->enc_; WebPPicture* const pic = enc->pic_; if (pic->extra_info != NULL) { - memset(pic->extra_info, 0, - enc->mb_w_ * enc->mb_h_ * sizeof(*pic->extra_info)); + if (it->x_ == 0 && it->y_ == 0) { // only do it once, at start + memset(pic->extra_info, 0, + enc->mb_w_ * enc->mb_h_ * sizeof(*pic->extra_info)); + } } } + +static void ResetSideInfo(const VP8EncIterator* const it) { + (void)it; +} #endif // !defined(WEBP_DISABLE_STATS) static double GetPSNR(uint64_t mse, uint64_t size) { @@ -570,7 +584,7 @@ static uint64_t OneStatPass(VP8Encoder* const enc, VP8RDLevel rd_opt, VP8IteratorImport(&it, NULL); if (VP8Decimate(&it, &info, rd_opt)) { // Just record the number of skips and act like skip_proba is not used. - enc->proba_.nb_skip_++; + ++enc->proba_.nb_skip_; } RecordResiduals(&it, &info); size += info.R + info.H; @@ -841,6 +855,9 @@ int VP8EncTokenLoop(VP8Encoder* const enc) { if (enc->max_i4_header_bits_ > 0 && size_p0 > PARTITION0_SIZE_LIMIT) { ++num_pass_left; enc->max_i4_header_bits_ >>= 1; // strengthen header bit limitation... + if (is_last_pass) { + ResetSideInfo(&it); + } continue; // ...and start over } if (is_last_pass) {