mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-06 16:56:55 +08:00
convert YUV to YUV with scaling
BUG=none TEST=convert util with YUV source R=ryanpetrie@google.com Review URL: https://webrtc-codereview.appspot.com/1513004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@700 16f28f9a-4ce2-e073-06de-1de4eb20be90
This commit is contained in:
parent
0066be9716
commit
7a1eb83e1b
@ -203,10 +203,24 @@ int main(int argc, const char* argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int org_size = Abs(image_width) * Abs(image_height) * 4; // ARGB
|
bool org_is_yuv = strstr(argv[fileindex_org], "_P420.");
|
||||||
|
bool org_is_argb = strstr(argv[fileindex_org], "_ARGB.");
|
||||||
|
if (!org_is_yuv && !org_is_argb) {
|
||||||
|
fprintf(stderr, "Original format unknown %s\n", argv[fileindex_org]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
int org_size = Abs(image_width) * Abs(image_height) * 4; // ARGB
|
||||||
|
// Input is YUV
|
||||||
|
if (org_is_yuv) {
|
||||||
|
const int y_size = Abs(image_width) * Abs(image_height);
|
||||||
|
const int uv_size = ((Abs(image_width) + 1) / 2) *
|
||||||
|
((Abs(image_height) + 1) / 2);
|
||||||
|
org_size = y_size + 2 * uv_size; // YUV original.
|
||||||
|
}
|
||||||
|
|
||||||
const int dst_size = dst_width * dst_height * 4; // ARGB scaled
|
const int dst_size = dst_width * dst_height * 4; // ARGB scaled
|
||||||
const int y_size = dst_width * dst_height;
|
const int y_size = dst_width * dst_height;
|
||||||
const int uv_size = (dst_width + 1) / 2 * (dst_height + 1) / 2;
|
const int uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2);
|
||||||
const size_t total_size = y_size + 2 * uv_size;
|
const size_t total_size = y_size + 2 * uv_size;
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
_fseeki64(file_org,
|
_fseeki64(file_org,
|
||||||
@ -242,27 +256,49 @@ int main(int argc, const char* argv[]) {
|
|||||||
if (num_frames && number_of_frames >= num_frames)
|
if (num_frames && number_of_frames >= num_frames)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Load original YUV or ARGB frame.
|
||||||
size_t bytes_org = fread(ch_org, sizeof(uint8),
|
size_t bytes_org = fread(ch_org, sizeof(uint8),
|
||||||
static_cast<size_t>(org_size), file_org);
|
static_cast<size_t>(org_size), file_org);
|
||||||
if (bytes_org < static_cast<size_t>(org_size))
|
if (bytes_org < static_cast<size_t>(org_size))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) {
|
for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) {
|
||||||
|
// Scale YUV or ARGB frame.
|
||||||
|
if (org_is_yuv) {
|
||||||
|
int src_width = Abs(image_width);
|
||||||
|
int src_height = Abs(image_height);
|
||||||
|
int half_src_width = (src_width + 1) / 2;
|
||||||
|
int half_src_height = (src_height + 1) / 2;
|
||||||
|
int half_dst_width = (dst_width + 1) / 2;
|
||||||
|
int half_dst_height = (dst_height + 1) / 2;
|
||||||
|
I420Scale(ch_org, src_width,
|
||||||
|
ch_org + src_width * src_height, half_src_width,
|
||||||
|
ch_org + src_width * src_height +
|
||||||
|
half_src_width * half_src_height, half_src_width,
|
||||||
|
image_width, image_height,
|
||||||
|
ch_rec, dst_width,
|
||||||
|
ch_rec + dst_width * dst_height, half_dst_width,
|
||||||
|
ch_rec + dst_width * dst_height +
|
||||||
|
half_dst_width * half_dst_height, half_dst_width,
|
||||||
|
dst_width, dst_height,
|
||||||
|
static_cast<libyuv::FilterMode>(filter));
|
||||||
|
} else {
|
||||||
TileARGBScale(ch_org, Abs(image_width) * 4,
|
TileARGBScale(ch_org, Abs(image_width) * 4,
|
||||||
image_width, image_height,
|
image_width, image_height,
|
||||||
ch_dst, dst_width * 4,
|
ch_dst, dst_width * 4,
|
||||||
dst_width, dst_height,
|
dst_width, dst_height,
|
||||||
static_cast<libyuv::FilterMode>(filter));
|
static_cast<libyuv::FilterMode>(filter));
|
||||||
|
}
|
||||||
|
bool rec_is_yuv = strstr(argv[fileindex_rec + cur_rec], "_P420.");
|
||||||
|
bool rec_is_argb = strstr(argv[fileindex_rec + cur_rec], "_ARGB.");
|
||||||
|
if (!rec_is_yuv && !rec_is_argb) {
|
||||||
|
fprintf(stderr, "Output format unknown %s\n",
|
||||||
|
argv[fileindex_rec + cur_rec]);
|
||||||
|
continue; // Advance to next file.
|
||||||
|
}
|
||||||
|
|
||||||
// Output scaled ARGB.
|
// Convert ARGB to YUV.
|
||||||
if (strstr(argv[fileindex_rec + cur_rec], "_ARGB.")) {
|
if (!org_is_yuv && rec_is_yuv) {
|
||||||
size_t bytes_rec = fwrite(ch_dst, sizeof(uint8),
|
|
||||||
static_cast<size_t>(dst_size),
|
|
||||||
file_rec[cur_rec]);
|
|
||||||
if (bytes_rec < static_cast<size_t>(dst_size))
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
// Output YUV.
|
|
||||||
int half_width = (dst_width + 1) / 2;
|
int half_width = (dst_width + 1) / 2;
|
||||||
int half_height = (dst_height + 1) / 2;
|
int half_height = (dst_height + 1) / 2;
|
||||||
libyuv::ARGBToI420(ch_dst, dst_width * 4,
|
libyuv::ARGBToI420(ch_dst, dst_width * 4,
|
||||||
@ -271,13 +307,22 @@ int main(int argc, const char* argv[]) {
|
|||||||
ch_rec + dst_width * dst_height +
|
ch_rec + dst_width * dst_height +
|
||||||
half_width * half_height, half_width,
|
half_width * half_height, half_width,
|
||||||
dst_width, dst_height);
|
dst_width, dst_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output YUV or ARGB frame.
|
||||||
|
if (rec_is_yuv) {
|
||||||
size_t bytes_rec = fwrite(ch_rec, sizeof(uint8),
|
size_t bytes_rec = fwrite(ch_rec, sizeof(uint8),
|
||||||
static_cast<size_t>(total_size),
|
static_cast<size_t>(total_size),
|
||||||
file_rec[cur_rec]);
|
file_rec[cur_rec]);
|
||||||
if (bytes_rec < static_cast<size_t>(total_size))
|
if (bytes_rec < static_cast<size_t>(total_size))
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
size_t bytes_rec = fwrite(ch_dst, sizeof(uint8),
|
||||||
|
static_cast<size_t>(dst_size),
|
||||||
|
file_rec[cur_rec]);
|
||||||
|
if (bytes_rec < static_cast<size_t>(dst_size))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
printf("%5d", number_of_frames);
|
printf("%5d", number_of_frames);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -307,7 +307,7 @@ int main(int argc, const char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const int y_size = image_width * image_height;
|
const int y_size = image_width * image_height;
|
||||||
const int uv_size = (image_width + 1) / 2 * (image_height + 1) / 2;
|
const int uv_size = ((image_width + 1) / 2) * ((image_height + 1) / 2);
|
||||||
const size_t total_size = y_size + 2 * uv_size; // NOLINT
|
const size_t total_size = y_size + 2 * uv_size; // NOLINT
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
_fseeki64(file_org,
|
_fseeki64(file_org,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user