| 1 |
// Simple tool to roughly evaluate the quality encoding of a webp bitstream |
| 2 |
// |
| 3 |
// Result is a *rough* estimation of the quality. You should just consider |
| 4 |
// the bucket it's in (q > 80? > 50? > 20?) and not take it for face value. |
| 5 |
/* |
| 6 |
gcc -o webp_quality webp_quality.c -O3 -I../ -L. -L../imageio \ |
| 7 |
-limageio_util -lwebpextras -lwebp -lm -lpthread |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <stdio.h> |
| 11 |
#include <stdlib.h> |
| 12 |
#include <string.h> |
| 13 |
|
| 14 |
#include "extras/extras.h" |
| 15 |
#include "imageio/imageio_util.h" |
| 16 |
#include "../examples/unicode.h" |
| 17 |
|
| 18 |
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure. |
| 19 |
int main(int argc, const char* argv[]) { |
| 20 |
int c; |
| 21 |
int quiet = 0; |
| 22 |
int ok = 1; |
| 23 |
|
| 24 |
INIT_WARGV(argc, argv); |
| 25 |
|
| 26 |
for (c = 1; ok && c < argc; ++c) { |
| 27 |
if (!strcmp(argv[c], "-quiet")) { |
| 28 |
quiet = 1; |
| 29 |
} else if (!strcmp(argv[c], "-help") || !strcmp(argv[c], "-h")) { |
| 30 |
printf("webp_quality [-h][-quiet] webp_files...\n"); |
| 31 |
FREE_WARGV_AND_RETURN(EXIT_SUCCESS); |
| 32 |
} else { |
| 33 |
const char* const filename = (const char*)GET_WARGV(argv, c); |
| 34 |
const uint8_t* data = NULL; |
| 35 |
size_t data_size = 0; |
| 36 |
int q; |
| 37 |
ok = ImgIoUtilReadFile(filename, &data, &data_size); |
| 38 |
if (!ok) break; |
| 39 |
q = VP8EstimateQuality(data, data_size); |
| 40 |
if (!quiet) WPRINTF("[%s] ", (const W_CHAR*)filename); |
| 41 |
if (q < 0) { |
| 42 |
fprintf(stderr, "Not a WebP file, or not a lossy WebP file.\n"); |
| 43 |
ok = 0; |
| 44 |
} else { |
| 45 |
if (!quiet) { |
| 46 |
printf("Estimated quality factor: %d\n", q); |
| 47 |
} else { |
| 48 |
printf("%d\n", q); // just print the number |
| 49 |
} |
| 50 |
} |
| 51 |
free((void*)data); |
| 52 |
} |
| 53 |
} |
| 54 |
FREE_WARGV_AND_RETURN(ok ? EXIT_SUCCESS : EXIT_FAILURE); |
| 55 |
} |