webp_quality.c (1704B)
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 "../examples/unicode.h" 15 #include "src/webp/types.h" 16 #include "extras/extras.h" 17 #include "imageio/imageio_util.h" 18 19 // Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure. 20 int main(int argc, const char* argv[]) { 21 int c; 22 int quiet = 0; 23 int ok = 1; 24 25 INIT_WARGV(argc, argv); 26 27 for (c = 1; ok && c < argc; ++c) { 28 if (!strcmp(argv[c], "-quiet")) { 29 quiet = 1; 30 } else if (!strcmp(argv[c], "-help") || !strcmp(argv[c], "-h")) { 31 printf("webp_quality [-h][-quiet] webp_files...\n"); 32 FREE_WARGV_AND_RETURN(EXIT_SUCCESS); 33 } else { 34 const char* const filename = (const char*)GET_WARGV(argv, c); 35 const uint8_t* data = NULL; 36 size_t data_size = 0; 37 int q; 38 ok = ImgIoUtilReadFile(filename, &data, &data_size); 39 if (!ok) break; 40 q = VP8EstimateQuality(data, data_size); 41 if (!quiet) WPRINTF("[%s] ", (const W_CHAR*)filename); 42 if (q < 0) { 43 fprintf(stderr, "Not a WebP file, or not a lossy WebP file.\n"); 44 ok = 0; 45 } else { 46 if (!quiet) { 47 printf("Estimated quality factor: %d\n", q); 48 } else { 49 printf("%d\n", q); // just print the number 50 } 51 } 52 free((void*)data); 53 } 54 } 55 FREE_WARGV_AND_RETURN(ok ? EXIT_SUCCESS : EXIT_FAILURE); 56 }