Commit 40f9cd0e authored by fbarchard@google.com's avatar fbarchard@google.com

psnr tool accept files names with _1280x720 as well as .1280x720. And odd widths.

BUG=none
TEST=psnr faces_1280x720_P420.yuv faces_c_1280x720_P420.yuv
Review URL: https://webrtc-codereview.appspot.com/1304007

git-svn-id: http://libyuv.googlecode.com/svn/trunk@652 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent 474e0f05
Name: libyuv Name: libyuv
URL: http://code.google.com/p/libyuv/ URL: http://code.google.com/p/libyuv/
Version: 650 Version: 652
License: BSD License: BSD
License File: LICENSE License File: LICENSE
......
...@@ -11,6 +11,6 @@ ...@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 650 #define LIBYUV_VERSION 652
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
...@@ -56,40 +56,28 @@ int num_rec = 0; ...@@ -56,40 +56,28 @@ int num_rec = 0;
int num_skip_org = 0; int num_skip_org = 0;
int num_skip_rec = 0; int num_skip_rec = 0;
int num_frames = 0; int num_frames = 0;
int do_yscale = 0;
#ifdef _OPENMP #ifdef _OPENMP
int num_threads = 0; int num_threads = 0;
#endif #endif
bool ExtractResolutionFromYuvFilename(const char *name, // Parse PYUV format. ie name.1920x800_24Hz_P420.yuv
int* width_ptr, bool ExtractResolutionFromFilename(const char* name,
int* height_ptr) { int* width_ptr,
// Isolate the .width_heigth. section of the filename by searching for the int* height_ptr) {
// one before last dot in the filename. // Isolate the .width_height. section of the filename by searching for a
int dot1 = -1, dot2 = -1; // dot or underscore followed by a digit.
int i = 0; for (int i = 0; name[i]; ++i) {
while (name[i]) { if ((name[i] == '.' || name[i] == '_') &&
if ('.' == name[i]) { name[i + 1] >= '0' && name[i + 1] <= '9') {
dot1 = dot2; int n = sscanf(name + i + 1, "%dx%d", width_ptr, height_ptr); // NOLINT
dot2 = i; if (2 == n) {
return true;
}
} }
i++;
}
if (-1 == dot1) {
return false;
}
// Parse PYUV format. ie name.1920x800_24Hz_P420.yuv
int args = sscanf(name + dot1, ".%dx%d", width_ptr, height_ptr);
// Parse .width_height.yuv
if (args != 2) {
args = sscanf(name + dot1, ".%d_%d.yuv", width_ptr, height_ptr);
} }
return (2 == args); return false;
} }
// Scale Y channel from 16..240 to 0..255. // Scale Y channel from 16..240 to 0..255.
// This can be useful when comparing codecs that are inconsistant about Y // This can be useful when comparing codecs that are inconsistant about Y
uint8 ScaleY(uint8 y) { uint8 ScaleY(uint8 y) {
...@@ -120,7 +108,6 @@ void PrintHelp(const char * program) { ...@@ -120,7 +108,6 @@ void PrintHelp(const char * program) {
#ifdef _OPENMP #ifdef _OPENMP
printf(" -t <num> ............... Number of threads\n"); printf(" -t <num> ............... Number of threads\n");
#endif #endif
printf(" -yscale ................ Scale org Y values of 16..240 to 0..255\n");
printf(" -n ..................... Show file name\n"); printf(" -n ..................... Show file name\n");
printf(" -v ..................... verbose++\n"); printf(" -v ..................... verbose++\n");
printf(" -q ..................... quiet\n"); printf(" -q ..................... quiet\n");
...@@ -128,7 +115,7 @@ void PrintHelp(const char * program) { ...@@ -128,7 +115,7 @@ void PrintHelp(const char * program) {
exit(0); exit(0);
} }
void ParseOptions(int argc, const char *argv[]) { void ParseOptions(int argc, const char* argv[]) {
if (argc <= 1) PrintHelp(argv[0]); if (argc <= 1) PrintHelp(argv[0]);
for (int c = 1; c < argc; ++c) { for (int c = 1; c < argc; ++c) {
if (!strcmp(argv[c], "-v")) { if (!strcmp(argv[c], "-v")) {
...@@ -148,8 +135,6 @@ void ParseOptions(int argc, const char *argv[]) { ...@@ -148,8 +135,6 @@ void ParseOptions(int argc, const char *argv[]) {
do_lssim = true; do_lssim = true;
} else if (!strcmp(argv[c], "-swap")) { } else if (!strcmp(argv[c], "-swap")) {
do_swap_uv = true; do_swap_uv = true;
} else if (!strcmp(argv[c], "-yscale")) {
do_yscale = true;
} else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) { } else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
PrintHelp(argv[0]); PrintHelp(argv[0]);
} else if (!strcmp(argv[c], "-s") && c + 2 < argc) { } else if (!strcmp(argv[c], "-s") && c + 2 < argc) {
...@@ -164,6 +149,8 @@ void ParseOptions(int argc, const char *argv[]) { ...@@ -164,6 +149,8 @@ void ParseOptions(int argc, const char *argv[]) {
} else if (!strcmp(argv[c], "-t") && c + 1 < argc) { } else if (!strcmp(argv[c], "-t") && c + 1 < argc) {
num_threads = atoi(argv[++c]); // NOLINT num_threads = atoi(argv[++c]); // NOLINT
#endif #endif
} else if (argv[c][0] == '-') {
fprintf(stderr, "Unknown option. %s\n", argv[c]);
} else if (fileindex_org == 0) { } else if (fileindex_org == 0) {
fileindex_org = c; fileindex_org = c;
} else if (fileindex_rec == 0) { } else if (fileindex_rec == 0) {
...@@ -174,33 +161,33 @@ void ParseOptions(int argc, const char *argv[]) { ...@@ -174,33 +161,33 @@ void ParseOptions(int argc, const char *argv[]) {
} }
} }
if (fileindex_org == 0 || fileindex_rec == 0) { if (fileindex_org == 0 || fileindex_rec == 0) {
printf("Missing filenames\n"); fprintf(stderr, "Missing filenames\n");
PrintHelp(argv[0]); PrintHelp(argv[0]);
} }
if (num_skip_org < 0 || num_skip_rec < 0) { if (num_skip_org < 0 || num_skip_rec < 0) {
printf("Skipped frames incorrect\n"); fprintf(stderr, "Skipped frames incorrect\n");
PrintHelp(argv[0]); PrintHelp(argv[0]);
} }
if (num_frames < 0) { if (num_frames < 0) {
printf("Number of frames incorrect\n"); fprintf(stderr, "Number of frames incorrect\n");
PrintHelp(argv[0]); PrintHelp(argv[0]);
} }
if (image_width <= 0 || image_height <=0) { if (image_width <= 0 || image_height <=0) {
int org_width, org_height; int org_width, org_height;
int rec_width, rec_height; int rec_width, rec_height;
bool org_res_avail = ExtractResolutionFromYuvFilename(argv[fileindex_org], bool org_res_avail = ExtractResolutionFromFilename(argv[fileindex_org],
&org_width, &org_width,
&org_height); &org_height);
bool rec_res_avail = ExtractResolutionFromYuvFilename(argv[fileindex_rec], bool rec_res_avail = ExtractResolutionFromFilename(argv[fileindex_rec],
&rec_width, &rec_width,
&rec_height); &rec_height);
if (org_res_avail) { if (org_res_avail) {
if (rec_res_avail) { if (rec_res_avail) {
if ((org_width == rec_width) && (org_height == rec_height)) { if ((org_width == rec_width) && (org_height == rec_height)) {
image_width = org_width; image_width = org_width;
image_height = org_height; image_height = org_height;
} else { } else {
printf("Sequences have different resolutions.\n"); fprintf(stderr, "Sequences have different resolutions.\n");
PrintHelp(argv[0]); PrintHelp(argv[0]);
} }
} else { } else {
...@@ -211,7 +198,7 @@ void ParseOptions(int argc, const char *argv[]) { ...@@ -211,7 +198,7 @@ void ParseOptions(int argc, const char *argv[]) {
image_width = rec_width; image_width = rec_width;
image_height = rec_height; image_height = rec_height;
} else { } else {
printf("Missing dimensions.\n"); fprintf(stderr, "Missing dimensions.\n");
PrintHelp(argv[0]); PrintHelp(argv[0]);
} }
} }
...@@ -227,11 +214,6 @@ bool UpdateMetrics(uint8* ch_org, uint8* ch_rec, ...@@ -227,11 +214,6 @@ bool UpdateMetrics(uint8* ch_org, uint8* ch_rec,
const uint8* const u_rec = ch_rec + y_size; const uint8* const u_rec = ch_rec + y_size;
const uint8* const v_org = ch_org + y_size + (uv_size - uv_offset); const uint8* const v_org = ch_org + y_size + (uv_size - uv_offset);
const uint8* const v_rec = ch_rec + y_size + uv_size; const uint8* const v_rec = ch_rec + y_size + uv_size;
if (do_yscale) {
for (int i = 0; i < image_width*image_height; ++i) {
ch_org[i] = ScaleY(ch_org[i]);
}
}
if (do_psnr) { if (do_psnr) {
double y_err = ComputeSumSquareError(ch_org, ch_rec, y_size); double y_err = ComputeSumSquareError(ch_org, ch_rec, y_size);
double u_err = ComputeSumSquareError(u_org, u_rec, uv_size); double u_err = ComputeSumSquareError(u_org, u_rec, uv_size);
...@@ -287,7 +269,7 @@ bool UpdateMetrics(uint8* ch_org, uint8* ch_rec, ...@@ -287,7 +269,7 @@ bool UpdateMetrics(uint8* ch_org, uint8* ch_rec,
return ismin; return ismin;
} }
int main(int argc, const char *argv[]) { int main(int argc, const char* argv[]) {
ParseOptions(argc, argv); ParseOptions(argc, argv);
if (!do_psnr && !do_ssim) { if (!do_psnr && !do_ssim) {
do_psnr = true; do_psnr = true;
...@@ -309,12 +291,12 @@ int main(int argc, const char *argv[]) { ...@@ -309,12 +291,12 @@ int main(int argc, const char *argv[]) {
} }
// Open all files to compare to // Open all files to compare to
FILE** file_rec = new FILE *[num_rec]; FILE** file_rec = new FILE* [num_rec];
memset(file_rec, 0, num_rec * sizeof(FILE*)); // NOLINT memset(file_rec, 0, num_rec * sizeof(FILE*)); // NOLINT
for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) { for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) {
file_rec[cur_rec] = fopen(argv[fileindex_rec+cur_rec], "rb"); file_rec[cur_rec] = fopen(argv[fileindex_rec + cur_rec], "rb");
if (file_rec[cur_rec] == NULL) { if (file_rec[cur_rec] == NULL) {
fprintf(stderr, "Cannot open %s\n", argv[fileindex_rec+cur_rec]); fprintf(stderr, "Cannot open %s\n", argv[fileindex_rec + cur_rec]);
fclose(file_org); fclose(file_org);
for (int i = 0; i < cur_rec; ++i) { for (int i = 0; i < cur_rec; ++i) {
fclose(file_rec[i]); fclose(file_rec[i]);
...@@ -450,7 +432,7 @@ int main(int argc, const char *argv[]) { ...@@ -450,7 +432,7 @@ int main(int argc, const char *argv[]) {
} }
if (verbose) { if (verbose) {
if (show_name) { if (show_name) {
printf("\t%s", argv[fileindex_rec+cur_rec]); printf("\t%s", argv[fileindex_rec + cur_rec]);
} }
printf("\n"); printf("\n");
} }
...@@ -493,7 +475,7 @@ int main(int argc, const char *argv[]) { ...@@ -493,7 +475,7 @@ int main(int argc, const char *argv[]) {
global_psnr_all, global_psnr_all,
number_of_frames); number_of_frames);
if (show_name) { if (show_name) {
printf("\t%s", argv[fileindex_rec+cur_rec]); printf("\t%s", argv[fileindex_rec + cur_rec]);
} }
printf("\n"); printf("\n");
} }
...@@ -517,7 +499,7 @@ int main(int argc, const char *argv[]) { ...@@ -517,7 +499,7 @@ int main(int argc, const char *argv[]) {
number_of_frames); number_of_frames);
} }
if (show_name) { if (show_name) {
printf("\t%s", argv[fileindex_rec+cur_rec]); printf("\t%s", argv[fileindex_rec + cur_rec]);
} }
printf("\n"); printf("\n");
} }
...@@ -540,7 +522,7 @@ int main(int argc, const char *argv[]) { ...@@ -540,7 +522,7 @@ int main(int argc, const char *argv[]) {
cur_distortion_ssim->min_frame); cur_distortion_ssim->min_frame);
} }
if (show_name) { if (show_name) {
printf("\t%s", argv[fileindex_rec+cur_rec]); printf("\t%s", argv[fileindex_rec + cur_rec]);
} }
printf("\n"); printf("\n");
} }
...@@ -561,7 +543,7 @@ int main(int argc, const char *argv[]) { ...@@ -561,7 +543,7 @@ int main(int argc, const char *argv[]) {
global_mse_all, global_mse_all,
number_of_frames); number_of_frames);
if (show_name) { if (show_name) {
printf("\t%s", argv[fileindex_rec+cur_rec]); printf("\t%s", argv[fileindex_rec + cur_rec]);
} }
printf("\n"); printf("\n");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment