From 475d87d767faae597c8ce4410a63b739d7a493c2 Mon Sep 17 00:00:00 2001 From: James Zern Date: Fri, 27 Jul 2012 19:53:16 -0700 Subject: [PATCH] WebPEncode: clear stats at the start of encode also relocate user_data from WebPAuxStats to the WebPPicture struct to make clearing easier while placing it closer to the progress hook with which it's used. prior to this change some spurious lossless data could be reported in the lossy (sans alpha) encoding case. additionally user_data could be lost during lossless encoding. Change-Id: I929fae3dfde4d445ff81bbaad51445ea586dd80b --- examples/cwebp.c | 4 ++-- src/enc/webpenc.c | 2 ++ src/webp/encode.h | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/cwebp.c b/examples/cwebp.c index 9f933cff..c1a5b13c 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -779,7 +779,7 @@ static int DumpPicture(const WebPPicture* const picture, const char* PGM_name) { static int ProgressReport(int percent, const WebPPicture* const picture) { printf("[%s]: %3d %% \r", - (char*)picture->stats->user_data, percent); + (char*)picture->user_data, percent); fflush(stdout); return 1; // all ok } @@ -1125,7 +1125,7 @@ int main(int argc, const char *argv[]) { } if (!quiet) { picture.stats = &stats; - stats.user_data = (void*)in_file; + picture.user_data = (void*)in_file; } // Compress diff --git a/src/enc/webpenc.c b/src/enc/webpenc.c index a00ac640..8649ce2d 100644 --- a/src/enc/webpenc.c +++ b/src/enc/webpenc.c @@ -344,6 +344,8 @@ int WebPEncode(const WebPConfig* config, WebPPicture* pic) { if (pic->width > WEBP_MAX_DIMENSION || pic->height > WEBP_MAX_DIMENSION) return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); + if (pic->stats != NULL) memset(pic->stats, 0, sizeof(*pic->stats)); + if (!config->lossless) { VP8Encoder* enc = NULL; if (pic->y == NULL || pic->u == NULL || pic->v == NULL) { diff --git a/src/webp/encode.h b/src/webp/encode.h index 1ee42819..18e433d4 100644 --- a/src/webp/encode.h +++ b/src/webp/encode.h @@ -170,9 +170,6 @@ typedef struct { int alpha_data_size; // size of the transparency data int layer_data_size; // size of the enhancement layer data - void* user_data; // this field is free to be set to any value and - // used during callbacks (like progress-report e.g.). - // lossless encoder statistics uint32_t lossless_features; // bit0:predictor bit1:cross-color transform // bit2:subtract-green bit3:color indexing @@ -299,6 +296,9 @@ struct WebPPicture { // If not NULL, report progress during encoding. WebPProgressHook progress_hook; + void* user_data; // this field is free to be set to any value and + // used during callbacks (like progress-report e.g.). + uint32_t pad3[3]; // padding for later use // Unused for now: original samples (for non-YUV420 modes)