2016-07-20 21:55:05 +02:00
|
|
|
// Simple tool to roughly evaluate the quality encoding of a webp bitstream
|
|
|
|
//
|
|
|
|
// Result is a *rough* estimation of the quality. You should just consider
|
|
|
|
// the bucket it's in (q > 80? > 50? > 20?) and not take it for face value.
|
|
|
|
/*
|
|
|
|
gcc -o webp_quality webp_quality.c -O3 -I../ -L. -L../imageio \
|
|
|
|
-lexample_util -limagedec -lwebpextras -lwebp -L/opt/local/lib \
|
|
|
|
-lpng -lz -ljpeg -ltiff -lm -lpthread
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "./extras.h"
|
2016-07-21 03:25:00 +02:00
|
|
|
#include "../imageio/imageio_util.h"
|
2016-07-20 21:55:05 +02:00
|
|
|
|
|
|
|
int main(int argc, const char *argv[]) {
|
|
|
|
int c;
|
|
|
|
int quiet = 0;
|
2016-08-20 21:07:31 +02:00
|
|
|
int ok = 1;
|
|
|
|
for (c = 1; ok && c < argc; ++c) {
|
2016-07-20 21:55:05 +02:00
|
|
|
if (!strcmp(argv[c], "-quiet")) {
|
|
|
|
quiet = 1;
|
|
|
|
} else if (!strcmp(argv[c], "-help") || !strcmp(argv[c], "-h")) {
|
|
|
|
printf("webp_quality [-h][-quiet] webp_files...\n");
|
2016-08-20 21:07:31 +02:00
|
|
|
return 0;
|
2016-07-20 21:55:05 +02:00
|
|
|
} else {
|
|
|
|
const char* const filename = argv[c];
|
|
|
|
const uint8_t* data = NULL;
|
|
|
|
size_t data_size = 0;
|
|
|
|
int q;
|
2016-08-20 21:07:31 +02:00
|
|
|
ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
|
|
|
if (!ok) break;
|
2016-07-20 21:55:05 +02:00
|
|
|
q = VP8EstimateQuality(data, data_size);
|
|
|
|
if (!quiet) printf("[%s] ", filename);
|
|
|
|
if (q < 0) {
|
|
|
|
fprintf(stderr, "Not a WebP file, or not a lossy WebP file.\n");
|
2016-08-20 21:07:31 +02:00
|
|
|
ok = 0;
|
2016-07-20 21:55:05 +02:00
|
|
|
} else {
|
|
|
|
if (!quiet) {
|
|
|
|
printf("Estimated quality factor: %d\n", q);
|
|
|
|
} else {
|
|
|
|
printf("%d\n", q); // just print the number
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free((void*)data);
|
|
|
|
}
|
|
|
|
}
|
2016-08-20 21:07:31 +02:00
|
|
|
return ok ? 0 : 1;
|
2016-07-20 21:55:05 +02:00
|
|
|
}
|