webp_quality should return '0' in case of success.

-> clarify the return value in case of error

Change-Id: I6f1e675c80d237b302fada28e7612a684b931c7a
This commit is contained in:
Pascal Massimino 2016-08-20 21:07:31 +02:00
parent 7f1b897bee
commit 57a5e3b6a5

View File

@ -18,23 +18,25 @@
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[]) {
int c; int c;
int quiet = 0; int quiet = 0;
for (c = 1; c < argc; ++c) { int ok = 1;
for (c = 1; ok && c < argc; ++c) {
if (!strcmp(argv[c], "-quiet")) { if (!strcmp(argv[c], "-quiet")) {
quiet = 1; quiet = 1;
} else if (!strcmp(argv[c], "-help") || !strcmp(argv[c], "-h")) { } else if (!strcmp(argv[c], "-help") || !strcmp(argv[c], "-h")) {
printf("webp_quality [-h][-quiet] webp_files...\n"); printf("webp_quality [-h][-quiet] webp_files...\n");
return 1; return 0;
} else { } else {
const char* const filename = argv[c]; const char* const filename = argv[c];
const uint8_t* data = NULL; const uint8_t* data = NULL;
size_t data_size = 0; size_t data_size = 0;
int q; int q;
const int ok = ImgIoUtilReadFile(filename, &data, &data_size); ok = ImgIoUtilReadFile(filename, &data, &data_size);
if (!ok) continue; if (!ok) break;
q = VP8EstimateQuality(data, data_size); q = VP8EstimateQuality(data, data_size);
if (!quiet) printf("[%s] ", filename); if (!quiet) printf("[%s] ", filename);
if (q < 0) { if (q < 0) {
fprintf(stderr, "Not a WebP file, or not a lossy WebP file.\n"); fprintf(stderr, "Not a WebP file, or not a lossy WebP file.\n");
ok = 0;
} else { } else {
if (!quiet) { if (!quiet) {
printf("Estimated quality factor: %d\n", q); printf("Estimated quality factor: %d\n", q);
@ -45,5 +47,5 @@ int main(int argc, const char *argv[]) {
free((void*)data); free((void*)data);
} }
} }
return 1; return ok ? 0 : 1;
} }