mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-06 16:56:55 +08:00
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
This commit is contained in:
parent
81ba94f58a
commit
f939fb7661
@ -1,6 +1,6 @@
|
||||
Name: libyuv
|
||||
URL: http://code.google.com/p/libyuv/
|
||||
Version: 1020
|
||||
Version: 1021
|
||||
License: BSD
|
||||
License File: LICENSE
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -116,7 +116,15 @@
|
||||
'LIBYUV_DISABLE_NEON'
|
||||
],
|
||||
}],
|
||||
[ 'OS != "ios"', {
|
||||
'defines': [
|
||||
'HAVE_JPEG',
|
||||
],
|
||||
}],
|
||||
], # conditions
|
||||
'dependencies': [
|
||||
'libyuv.gyp:libyuv',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'cpuid',
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user