diff --git a/extras/extras.h b/extras/extras.h index cc324e9f..6bb7d02a 100644 --- a/extras/extras.h +++ b/extras/extras.h @@ -46,7 +46,9 @@ WEBP_EXTERN(int) WebPImportRGB4444(const uint8_t* rgb4444, WebPPicture* pic); // Parse a bitstream, search for VP8 (lossy) header and report a // rough estimation of the quality factor used for compressing the bitstream. -// Any error (invalid bitstream, lossless compression, incomplete header, etc.) +// If the bitstream is in lossless format, the special value '101' is returned. +// Otherwise (lossy bitstream), the returned value is in the range [0..100]. +// Any error (invalid bitstream, animated WebP, incomplete header, etc.) // will return a value of -1. WEBP_EXTERN(int) VP8EstimateQuality(const uint8_t* const data, size_t size); diff --git a/extras/quality_estimate.c b/extras/quality_estimate.c index 1466ce92..ee7ab5f8 100644 --- a/extras/quality_estimate.c +++ b/extras/quality_estimate.c @@ -12,6 +12,7 @@ // Author: Skal (pascal.massimino@gmail.com) #include "./extras.h" +#include "webp/decode.h" #include @@ -46,9 +47,16 @@ int VP8EstimateQuality(const uint8_t* const data, size_t size) { uint64_t sig = 0x00; int ok = 0; int Q = -1; + WebPBitstreamFeatures features; if (data == NULL) return -1; + if (WebPGetFeatures(data, size, &features) != VP8_STATUS_OK) { + return -1; // invalid file + } + if (features.format == 2) return 101; // lossless + if (features.format == 0 || features.has_animation) return -1; // mixed + while (pos < size) { sig = (sig >> 8) | ((uint64_t)data[pos++] << 40); if ((sig >> 24) == 0x2a019dull) { diff --git a/makefile.unix b/makefile.unix index 5a6d8b14..f1fa8ddb 100644 --- a/makefile.unix +++ b/makefile.unix @@ -389,13 +389,13 @@ examples/webpmux: src/mux/libwebpmux.a src/libwebpdecoder.a extras/get_disto: extras/get_disto.o extras/get_disto: imageio/libimagedec.a extras/get_disto: imageio/libimageio_util.a -extras/get_disto: src/libwebp.a $(EXTRA_LIB) +extras/get_disto: $(EXTRA_LIB) src/libwebp.a extras/get_disto: EXTRA_LIBS += $(CWEBP_LIBS) extras/webp_quality: extras/webp_quality.o extras/webp_quality: imageio/libimagedec.a extras/webp_quality: imageio/libimageio_util.a -extras/webp_quality: src/libwebp.a $(EXTRA_LIB) +extras/webp_quality: $(EXTRA_LIB) src/libwebp.a extras/get_disto: EXTRA_LIBS += $(CWEBP_LIBS) $(OUT_EXAMPLES) $(EXTRA_EXAMPLES) $(OTHER_EXAMPLES):