summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPascal Massimino <pascal.massimino@gmail.com>2017-01-24 22:46:01 -0800
committerPascal Massimino <pascal.massimino@gmail.com>2017-01-24 23:05:33 -0800
commitb045013970d64fb6d2984a9af8f2a034721a2a0c (patch)
tree6af87ad5c3d83960f78a3f71718bb93ae99f9257
parent0ad3b4efa89fbdc0bc5ec4b156ede3abb2bbefa6 (diff)
downloadlibwebp-b045013970d64fb6d2984a9af8f2a034721a2a0c.tar.gz
ReadImage(): restore size reporting
That was useful for printing rd-curves. Change-Id: Idd641d94633f1f88bad2e29494b3d99c4c02fa30
-rw-r--r--extras/get_disto.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/extras/get_disto.c b/extras/get_disto.c
index ba70336c..ab1b0516 100644
--- a/extras/get_disto.c
+++ b/extras/get_disto.c
@@ -27,12 +27,13 @@
#include "../imageio/image_dec.h"
#include "../imageio/imageio_util.h"
-static int ReadPicture(const char* const filename, WebPPicture* const pic,
- int keep_alpha) {
+static size_t ReadPicture(const char* const filename, WebPPicture* const pic,
+ int keep_alpha) {
const uint8_t* data = NULL;
size_t data_size = 0;
WebPImageReader reader = NULL;
- int ok;
+ int ok = ImgIoUtilReadFile(filename, &data, &data_size);
+ if (!ok) goto End;
pic->use_argb = 1; // force ARGB
@@ -40,20 +41,17 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
// Try to decode the file using WIC falling back to the other readers for
// e.g., WebP.
ok = ReadPictureWithWIC(filename, pic, keep_alpha, NULL);
- if (ok) return 1;
+ if (ok) goto End;
#endif
- ok = ImgIoUtilReadFile(filename, &data, &data_size);
- if (!ok) goto Error;
-
reader = WebPGuessImageReader(data, data_size);
ok = reader(data, data_size, pic, keep_alpha, NULL);
- Error:
+ End:
if (!ok) {
fprintf(stderr, "Error! Could not process file %s\n", filename);
}
free((void*)data);
- return ok;
+ return ok ? data_size : 0;
}
static void RescalePlane(uint8_t* plane, int width, int height,
@@ -228,6 +226,7 @@ static void Help(void) {
int main(int argc, const char *argv[]) {
WebPPicture pic1, pic2;
+ size_t size1 = 0, size2 = 0;
int ret = 1;
float disto[5];
int type = 0;
@@ -278,12 +277,10 @@ int main(int argc, const char *argv[]) {
Help();
goto End;
}
- if (!ReadPicture(name1, &pic1, 1)) {
- goto End;
- }
- if (!ReadPicture(name2, &pic2, 1)) {
- goto End;
- }
+ size1 = ReadPicture(name1, &pic1, 1);
+ size2 = ReadPicture(name1, &pic2, 1);
+ if (size1 == 0 || size2 == 0) goto End;
+
if (!keep_alpha) {
WebPBlendAlpha(&pic1, 0x00000000);
WebPBlendAlpha(&pic2, 0x00000000);
@@ -293,7 +290,8 @@ int main(int argc, const char *argv[]) {
fprintf(stderr, "Error while computing the distortion.\n");
goto End;
}
- printf("%.2f %.2f %.2f %.2f %.2f\n",
+ printf("%u %.2f %.2f %.2f %.2f %.2f\n",
+ (unsigned int)size1,
disto[4], disto[0], disto[1], disto[2], disto[3]);
if (output != NULL) {