mirror of
https://github.com/webmproject/libwebp.git
synced 2025-02-13 15:32:53 +01:00
enc: disable pic->stats/extra_info w/WEBP_DISABLE_STATS
Change-Id: I4ca3fa45710bd6bbe131b2ae047b1e268241657c
This commit is contained in:
parent
541179a9a5
commit
f593d71a64
@ -267,6 +267,7 @@ static int ApplyFiltersAndEncode(const uint8_t* alpha, int width, int height,
|
||||
reduce_levels, effort_level, NULL, &best);
|
||||
}
|
||||
if (ok) {
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
if (stats != NULL) {
|
||||
stats->lossless_features = best.stats.lossless_features;
|
||||
stats->histogram_bits = best.stats.histogram_bits;
|
||||
@ -277,6 +278,9 @@ static int ApplyFiltersAndEncode(const uint8_t* alpha, int width, int height,
|
||||
stats->lossless_hdr_size = best.stats.lossless_hdr_size;
|
||||
stats->lossless_data_size = best.stats.lossless_data_size;
|
||||
}
|
||||
#else
|
||||
(void)stats;
|
||||
#endif
|
||||
*output_size = VP8BitWriterSize(&best.bw);
|
||||
*output = VP8BitWriterBuf(&best.bw);
|
||||
} else {
|
||||
@ -342,10 +346,12 @@ static int EncodeAlpha(VP8Encoder* const enc,
|
||||
ok = ApplyFiltersAndEncode(quant_alpha, width, height, data_size, method,
|
||||
filter, reduce_levels, effort_level, output,
|
||||
output_size, pic->stats);
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
if (pic->stats != NULL) { // need stats?
|
||||
pic->stats->coded_size += (int)(*output_size);
|
||||
enc->sse_[3] = sse;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
WebPSafeFree(quant_alpha);
|
||||
|
@ -200,11 +200,13 @@ static void SetSegmentProbas(VP8Encoder* const enc) {
|
||||
const VP8MBInfo* const mb = &enc->mb_info_[n];
|
||||
p[mb->segment_]++;
|
||||
}
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
if (enc->pic_->stats != NULL) {
|
||||
for (n = 0; n < NUM_MB_SEGMENTS; ++n) {
|
||||
enc->pic_->stats->segment_size[n] = p[n];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (enc->segment_hdr_.num_segments_ > 1) {
|
||||
uint8_t* const probas = enc->proba_.segments_;
|
||||
probas[0] = GetProba(p[0] + p[1], p[2] + p[3]);
|
||||
@ -452,6 +454,8 @@ static int RecordTokens(VP8EncIterator* const it, const VP8ModeScore* const rd,
|
||||
//------------------------------------------------------------------------------
|
||||
// ExtraInfo map / Debug function
|
||||
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
|
||||
#if SEGMENT_VISU
|
||||
static void SetBlock(uint8_t* p, int value, int size) {
|
||||
int y;
|
||||
@ -516,6 +520,20 @@ static void StoreSideInfo(const VP8EncIterator* const it) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#else // defined(WEBP_DISABLE_STATS)
|
||||
static void ResetSSE(VP8Encoder* const enc) {
|
||||
(void)enc;
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
#endif // !defined(WEBP_DISABLE_STATS)
|
||||
|
||||
static double GetPSNR(uint64_t mse, uint64_t size) {
|
||||
return (mse > 0 && size > 0) ? 10. * log10(255. * 255. * size / mse) : 99;
|
||||
}
|
||||
@ -670,6 +688,7 @@ static int PostLoopFinalize(VP8EncIterator* const it, int ok) {
|
||||
}
|
||||
|
||||
if (ok) { // All good. Finish up.
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
if (enc->pic_->stats != NULL) { // finalize byte counters...
|
||||
int i, s;
|
||||
for (i = 0; i <= 2; ++i) {
|
||||
@ -678,6 +697,7 @@ static int PostLoopFinalize(VP8EncIterator* const it, int ok) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
VP8AdjustFilterStrength(it); // ...and store filter stats.
|
||||
} else {
|
||||
// Something bad happened -> need to do some memory cleanup.
|
||||
|
@ -289,11 +289,17 @@ static int GeneratePartition0(VP8Encoder* const enc) {
|
||||
|
||||
pos3 = VP8BitWriterPos(bw);
|
||||
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
if (enc->pic_->stats) {
|
||||
enc->pic_->stats->header_bytes[0] = (int)((pos2 - pos1 + 7) >> 3);
|
||||
enc->pic_->stats->header_bytes[1] = (int)((pos3 - pos2 + 7) >> 3);
|
||||
enc->pic_->stats->alpha_data_size = (int)enc->alpha_data_size_;
|
||||
}
|
||||
#else
|
||||
(void)pos1;
|
||||
(void)pos2;
|
||||
(void)pos3;
|
||||
#endif
|
||||
if (bw->error_) {
|
||||
return WebPEncodingSetError(enc->pic_, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
@ -1562,7 +1562,9 @@ static int EncodeStreamHook(void* input, void* data2) {
|
||||
const CrunchConfig* const crunch_configs = params->crunch_configs_;
|
||||
const int num_crunch_configs = params->num_crunch_configs_;
|
||||
const int red_and_blue_always_zero = params->red_and_blue_always_zero_;
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
WebPAuxStats* const stats = params->stats_;
|
||||
#endif
|
||||
WebPEncodingError err = VP8_ENC_OK;
|
||||
const int quality = (int)config->quality;
|
||||
const int low_effort = (config->method == 0);
|
||||
@ -1704,6 +1706,7 @@ static int EncodeStreamHook(void* input, void* data2) {
|
||||
best_size = VP8LBitWriterNumBytes(bw);
|
||||
// Store the BitWriter.
|
||||
VP8LBitWriterSwap(bw, &bw_best);
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
// Update the stats.
|
||||
if (stats != NULL) {
|
||||
stats->lossless_features = 0;
|
||||
@ -1719,6 +1722,7 @@ static int EncodeStreamHook(void* input, void* data2) {
|
||||
stats->lossless_hdr_size = hdr_size;
|
||||
stats->lossless_data_size = data_size;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// Reset the bit writer for the following iteration if any.
|
||||
if (num_crunch_configs > 1) VP8LBitWriterReset(&bw_init, bw);
|
||||
@ -1828,11 +1832,13 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config,
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
// This line is here and not in the param initialization above to remove a
|
||||
// Clang static analyzer warning.
|
||||
if (picture->stats != NULL) {
|
||||
memcpy(&stats_side, picture->stats, sizeof(stats_side));
|
||||
}
|
||||
#endif
|
||||
// This line is only useful to remove a Clang static analyzer warning.
|
||||
params_side.err_ = VP8_ENC_OK;
|
||||
worker_interface->Launch(&worker_side);
|
||||
@ -1851,9 +1857,11 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config,
|
||||
}
|
||||
if (VP8LBitWriterNumBytes(&bw_side) < VP8LBitWriterNumBytes(bw_main)) {
|
||||
VP8LBitWriterSwap(bw_main, &bw_side);
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
if (picture->stats != NULL) {
|
||||
memcpy(picture->stats, &stats_side, sizeof(*picture->stats));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
if (!ok_main) {
|
||||
@ -1945,11 +1953,13 @@ int VP8LEncodeImage(const WebPConfig* const config,
|
||||
|
||||
if (!WebPReportProgress(picture, 100, &percent)) goto UserAbort;
|
||||
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
// Save size.
|
||||
if (picture->stats != NULL) {
|
||||
picture->stats->coded_size += (int)coded_size;
|
||||
picture->stats->lossless_size = (int)coded_size;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (picture->extra_info != NULL) {
|
||||
const int mb_w = (width + 15) >> 4;
|
||||
|
@ -256,6 +256,7 @@ static int DeleteVP8Encoder(VP8Encoder* enc) {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
static double GetPSNR(uint64_t err, uint64_t size) {
|
||||
return (err > 0 && size > 0) ? 10. * log10(255. * 255. * size / err) : 99.;
|
||||
}
|
||||
@ -270,8 +271,10 @@ static void FinalizePSNR(const VP8Encoder* const enc) {
|
||||
stats->PSNR[3] = (float)GetPSNR(sse[0] + sse[1] + sse[2], size * 3 / 2);
|
||||
stats->PSNR[4] = (float)GetPSNR(sse[3], size);
|
||||
}
|
||||
#endif // !defined(WEBP_DISABLE_STATS)
|
||||
|
||||
static void StoreStats(VP8Encoder* const enc) {
|
||||
#if !defined(WEBP_DISABLE_STATS)
|
||||
WebPAuxStats* const stats = enc->pic_->stats;
|
||||
if (stats != NULL) {
|
||||
int i, s;
|
||||
@ -288,7 +291,9 @@ static void StoreStats(VP8Encoder* const enc) {
|
||||
stats->block_count[i] = enc->block_count_[i];
|
||||
}
|
||||
}
|
||||
#else // defined(WEBP_DISABLE_STATS)
|
||||
WebPReportProgress(enc->pic_, 100, &enc->percent_); // done!
|
||||
#endif // !defined(WEBP_DISABLE_STATS)
|
||||
}
|
||||
|
||||
int WebPEncodingSetError(const WebPPicture* const pic,
|
||||
|
Loading…
x
Reference in New Issue
Block a user