mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 04:18:26 +01:00
webp_quality: detect lossless format and features
lossless bitstream are returned as quality 101 Change-Id: I8b28287169b710ecf8d4d694abbf0cedc6447908
This commit is contained in:
parent
ebee57f4d1
commit
eb98d8d87c
@ -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
|
// Parse a bitstream, search for VP8 (lossy) header and report a
|
||||||
// rough estimation of the quality factor used for compressing the bitstream.
|
// 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.
|
// will return a value of -1.
|
||||||
WEBP_EXTERN(int) VP8EstimateQuality(const uint8_t* const data, size_t size);
|
WEBP_EXTERN(int) VP8EstimateQuality(const uint8_t* const data, size_t size);
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
// Author: Skal (pascal.massimino@gmail.com)
|
// Author: Skal (pascal.massimino@gmail.com)
|
||||||
|
|
||||||
#include "./extras.h"
|
#include "./extras.h"
|
||||||
|
#include "webp/decode.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@ -46,9 +47,16 @@ int VP8EstimateQuality(const uint8_t* const data, size_t size) {
|
|||||||
uint64_t sig = 0x00;
|
uint64_t sig = 0x00;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
int Q = -1;
|
int Q = -1;
|
||||||
|
WebPBitstreamFeatures features;
|
||||||
|
|
||||||
if (data == NULL) return -1;
|
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) {
|
while (pos < size) {
|
||||||
sig = (sig >> 8) | ((uint64_t)data[pos++] << 40);
|
sig = (sig >> 8) | ((uint64_t)data[pos++] << 40);
|
||||||
if ((sig >> 24) == 0x2a019dull) {
|
if ((sig >> 24) == 0x2a019dull) {
|
||||||
|
@ -389,13 +389,13 @@ examples/webpmux: src/mux/libwebpmux.a src/libwebpdecoder.a
|
|||||||
extras/get_disto: extras/get_disto.o
|
extras/get_disto: extras/get_disto.o
|
||||||
extras/get_disto: imageio/libimagedec.a
|
extras/get_disto: imageio/libimagedec.a
|
||||||
extras/get_disto: imageio/libimageio_util.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/get_disto: EXTRA_LIBS += $(CWEBP_LIBS)
|
||||||
|
|
||||||
extras/webp_quality: extras/webp_quality.o
|
extras/webp_quality: extras/webp_quality.o
|
||||||
extras/webp_quality: imageio/libimagedec.a
|
extras/webp_quality: imageio/libimagedec.a
|
||||||
extras/webp_quality: imageio/libimageio_util.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)
|
extras/get_disto: EXTRA_LIBS += $(CWEBP_LIBS)
|
||||||
|
|
||||||
$(OUT_EXAMPLES) $(EXTRA_EXAMPLES) $(OTHER_EXAMPLES):
|
$(OUT_EXAMPLES) $(EXTRA_EXAMPLES) $(OTHER_EXAMPLES):
|
||||||
|
Loading…
Reference in New Issue
Block a user