diff options
author | fbarchard@google.com <fbarchard@google.com@16f28f9a-4ce2-e073-06de-1de4eb20be90> | 2014-06-25 16:54:20 +0000 |
---|---|---|
committer | fbarchard@google.com <fbarchard@google.com@16f28f9a-4ce2-e073-06de-1de4eb20be90> | 2014-06-25 16:54:20 +0000 |
commit | f939fb7661a9058686191df0bfe663036e55d28c (patch) | |
tree | 941fa38fe2c7bb9390fedde3728ebddb76ea2edc | |
parent | 81ba94f58a4393a18299348e5dfe14d521b0469b (diff) | |
download | libyuv-f939fb7661a9058686191df0bfe663036e55d28c.tar.gz |
psnr tool accept jpeg files as well as raw YUV
BUG=339
TESTED=psnr.exe feet.jpg bluechicken.jpg
R=harryjin@google.com
Review URL: https://webrtc-codereview.appspot.com/12839006
git-svn-id: http://libyuv.googlecode.com/svn/trunk@1021 16f28f9a-4ce2-e073-06de-1de4eb20be90
-rw-r--r-- | README.chromium | 2 | ||||
-rw-r--r-- | include/libyuv/version.h | 2 | ||||
-rw-r--r-- | libyuv_test.gyp | 8 | ||||
-rw-r--r-- | util/psnr_main.cc | 66 |
4 files changed, 74 insertions, 4 deletions
diff --git a/README.chromium b/README.chromium index fe7357c..0a150d4 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 1020 +Version: 1021 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 7023c36..4053fd0 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 1020 +#define LIBYUV_VERSION 1021 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/libyuv_test.gyp b/libyuv_test.gyp index e7e9e76..6b1527b 100644 --- a/libyuv_test.gyp +++ b/libyuv_test.gyp @@ -116,7 +116,15 @@ 'LIBYUV_DISABLE_NEON' ], }], + [ 'OS != "ios"', { + 'defines': [ + 'HAVE_JPEG', + ], + }], ], # conditions + 'dependencies': [ + 'libyuv.gyp:libyuv', + ], }, { 'target_name': 'cpuid', diff --git a/util/psnr_main.cc b/util/psnr_main.cc index 9cee5f8..ae8ee01 100644 --- a/util/psnr_main.cc +++ b/util/psnr_main.cc @@ -32,6 +32,9 @@ #include "./psnr.h" #include "./ssim.h" +#ifdef HAVE_JPEG +#include "libyuv/convert.h" +#endif struct metric { double y, u, v, all; @@ -75,6 +78,29 @@ bool ExtractResolutionFromFilename(const char* name, } } } + +#ifdef HAVE_JPEG + // Try parsing file as a jpeg. + FILE* const file_org = fopen(name, "rb"); + if (file_org == NULL) { + fprintf(stderr, "Cannot open %s\n", name); + return false; + } + fseek(file_org, 0, SEEK_END); + size_t total_size = ftell(file_org); + fseek(file_org, 0, SEEK_SET); + uint8* const ch_org = new uint8[total_size]; + memset(ch_org, 0, total_size); + size_t bytes_org = fread(ch_org, sizeof(uint8), total_size, file_org); + fclose(file_org); + if (bytes_org == total_size) { + if (0 == libyuv::MJPGSize(ch_org, total_size, width_ptr, height_ptr)) { + delete[] ch_org; + return true; + } + } + delete[] ch_org; +#endif // HAVE_JPEG return false; } @@ -386,14 +412,50 @@ int main(int argc, const char* argv[]) { break; size_t bytes_org = fread(ch_org, sizeof(uint8), total_size, file_org); - if (bytes_org < total_size) + if (bytes_org < total_size) { +#ifdef HAVE_JPEG + // Try parsing file as a jpeg. + uint8* const ch_jpeg = new uint8[bytes_org]; + memcpy(ch_jpeg, ch_org, bytes_org); + + if (0 != libyuv::MJPGToI420(ch_jpeg, bytes_org, + ch_org, image_width, + ch_org + y_size, image_width / 2, + ch_org + y_size + uv_size, image_width / 2, + image_width, image_height, + image_width, image_height)) { + delete[] ch_jpeg; + break; + } + delete[] ch_jpeg; +#else break; +#endif // HAVE_JPEG + } for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) { size_t bytes_rec = fread(ch_rec, sizeof(uint8), total_size, file_rec[cur_rec]); - if (bytes_rec < total_size) + if (bytes_rec < total_size) { +#ifdef HAVE_JPEG + // Try parsing file as a jpeg. + uint8* const ch_jpeg = new uint8[bytes_rec]; + memcpy(ch_jpeg, ch_rec, bytes_rec); + + if (0 != libyuv::MJPGToI420(ch_jpeg, bytes_rec, + ch_rec, image_width, + ch_rec + y_size, image_width / 2, + ch_rec + y_size + uv_size, image_width / 2, + image_width, image_height, + image_width, image_height)) { + delete[] ch_jpeg; + break; + } + delete[] ch_jpeg; +#else break; +#endif // HAVE_JPEG + } if (verbose) { printf("%5d", number_of_frames); |