diff --git a/examples/cwebp.c b/examples/cwebp.c index e0284470..040e804e 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -212,6 +212,8 @@ static void PrintFullLosslessInfo(const WebPAuxStats* const stats, const char* const description) { fprintf(stderr, "Lossless-%s compressed size: %d bytes\n", description, stats->lossless_size); + fprintf(stderr, " * Header size: %d bytes, image data size: %d\n", + stats->lossless_hdr_size, stats->lossless_data_size); if (stats->lossless_features) { fprintf(stderr, " * Lossless features used:"); if (stats->lossless_features & 1) fprintf(stderr, " PREDICTION"); diff --git a/src/enc/vp8l.c b/src/enc/vp8l.c index 891dd01b..1280fd3b 100644 --- a/src/enc/vp8l.c +++ b/src/enc/vp8l.c @@ -558,7 +558,10 @@ static WebPEncodingError EncodeImageInternal(VP8LBitWriter* const bw, VP8LBackwardRefs refs_array[2], int width, int height, int quality, int cache_bits, - int histogram_bits) { + int histogram_bits, + size_t init_byte_position, + int* const hdr_size, + int* const data_size) { WebPEncodingError err = VP8_ENC_OK; const int use_2d_locality = 1; const int use_color_cache = (cache_bits > 0); @@ -579,6 +582,8 @@ static WebPEncodingError EncodeImageInternal(VP8LBitWriter* const bw, sizeof(*histogram_symbols)); assert(histogram_bits >= MIN_HUFFMAN_BITS); assert(histogram_bits <= MAX_HUFFMAN_BITS); + assert(hdr_size != NULL); + assert(data_size != NULL); VP8LBackwardRefsInit(&refs, refs_array[0].block_size_); if (histogram_image == NULL || histogram_symbols == NULL) { @@ -676,9 +681,12 @@ static WebPEncodingError EncodeImageInternal(VP8LBitWriter* const bw, } } + *hdr_size = (int)(VP8LBitWriterNumBytes(bw) - init_byte_position); // Store actual literals. err = StoreImageToBitMask(bw, width, histogram_bits, &refs, histogram_symbols, huffman_codes); + *data_size = + (int)(VP8LBitWriterNumBytes(bw) - init_byte_position - *hdr_size); Error: WebPSafeFree(tokens); @@ -1053,6 +1061,8 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config, const int height = picture->height; VP8LEncoder* const enc = VP8LEncoderNew(config, picture); const size_t byte_position = VP8LBitWriterNumBytes(bw); + int hdr_size = 0; + int data_size = 0; if (enc == NULL) { err = VP8_ENC_ERROR_OUT_OF_MEMORY; @@ -1124,7 +1134,8 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config, err = EncodeImageInternal(bw, enc->argb_, &enc->hash_chain_, enc->refs_, enc->current_width_, height, quality, - enc->cache_bits_, enc->histo_bits_); + enc->cache_bits_, enc->histo_bits_, + byte_position, &hdr_size, &data_size); if (err != VP8_ENC_OK) goto Error; if (picture->stats != NULL) { @@ -1139,6 +1150,8 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config, stats->cache_bits = enc->cache_bits_; stats->palette_size = enc->palette_size_; stats->lossless_size = (int)(VP8LBitWriterNumBytes(bw) - byte_position); + stats->lossless_hdr_size = hdr_size; + stats->lossless_data_size = data_size; } Error: diff --git a/src/webp/encode.h b/src/webp/encode.h index 6947318a..190d9ae2 100644 --- a/src/webp/encode.h +++ b/src/webp/encode.h @@ -20,7 +20,7 @@ extern "C" { #endif -#define WEBP_ENCODER_ABI_VERSION 0x0205 // MAJOR(8b) + MINOR(8b) +#define WEBP_ENCODER_ABI_VERSION 0x0206 // MAJOR(8b) + MINOR(8b) // Note: forward declaring enumerations is not allowed in (strict) C and C++, // the types are left here for reference. @@ -210,8 +210,10 @@ struct WebPAuxStats { int cache_bits; // number of bits for color cache lookup int palette_size; // number of color in palette, if used int lossless_size; // final lossless size + int lossless_hdr_size; // lossless header (transform, huffman etc) size + int lossless_data_size; // lossless image data size - uint32_t pad[4]; // padding for later use + uint32_t pad[2]; // padding for later use }; // Signature for output function. Should return true if writing was successful.