From a844b9568819d6eb8f3ba12627abef12e30c2642 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Thu, 4 Oct 2012 21:04:27 +0000 Subject: [PATCH] YU12 has a normal fourcc instead of an alias, allowing code to treat it as different, if needed. BUG=112 TEST=unittests still pass Review URL: https://webrtc-codereview.appspot.com/864008 git-svn-id: http://libyuv.googlecode.com/svn/trunk@391 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- README.chromium | 2 +- include/libyuv/version.h | 2 +- include/libyuv/video_common.h | 4 ++-- source/convert.cc | 35 ++++++++++++++++++----------------- source/convert_argb.cc | 29 +++++++++++++++-------------- source/convert_from.cc | 25 +++++++++++++------------ source/video_common.cc | 1 - 7 files changed, 50 insertions(+), 48 deletions(-) diff --git a/README.chromium b/README.chromium index 788705939..8554fdbbe 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 390 +Version: 391 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index ed0a2d5fa..5d851ae4a 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 390 +#define LIBYUV_VERSION 391 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/include/libyuv/video_common.h b/include/libyuv/video_common.h index bae57052b..5d812c980 100644 --- a/include/libyuv/video_common.h +++ b/include/libyuv/video_common.h @@ -45,6 +45,7 @@ enum FourCC { FOURCC_I444 = FOURCC('I', '4', '4', '4'), FOURCC_I411 = FOURCC('I', '4', '1', '1'), FOURCC_I400 = FOURCC('I', '4', '0', '0'), + FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'), // Linux version of I420. FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'), FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'), FOURCC_YV24 = FOURCC('Y', 'V', '2', '4'), @@ -76,7 +77,6 @@ enum FourCC { // Aliases for canonical fourcc codes, replaced with their canonical // equivalents by CanonicalFourCC(). FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'), // Alias for I420. - FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'), // Alias for I420. FOURCC_YU16 = FOURCC('Y', 'U', '1', '6'), // Alias for I422. FOURCC_YU24 = FOURCC('Y', 'U', '2', '4'), // Alias for I444. FOURCC_YUYV = FOURCC('Y', 'U', 'Y', 'V'), // Alias for YUY2. @@ -100,6 +100,7 @@ enum FourCCBpp { FOURCC_BPP_I444 = 24, FOURCC_BPP_I411 = 12, FOURCC_BPP_I400 = 8, + FOURCC_BPP_YU12 = 12, FOURCC_BPP_YV12 = 12, FOURCC_BPP_YV16 = 16, FOURCC_BPP_YV24 = 24, @@ -131,7 +132,6 @@ enum FourCCBpp { // Aliases for canonical fourcc codes, replaced with their canonical // equivalents by CanonicalFourCC(). FOURCC_BPP_IYUV = 12, - FOURCC_BPP_YU12 = 12, FOURCC_BPP_YU16 = 16, FOURCC_BPP_YU24 = 24, FOURCC_BPP_YUYV = 16, diff --git a/source/convert.cc b/source/convert.cc index bbd37367c..cb3ad2a96 100644 --- a/source/convert.cc +++ b/source/convert.cc @@ -1749,9 +1749,9 @@ int ConvertToI420(const uint8* sample, // and then rotate the I420 to the final destination buffer. // For in-place conversion, if destination y is same as source sample, // also enable temporary buffer. - bool need_buf = (rotation && format != FOURCC_NV12 && - format != FOURCC_NV21 && format != FOURCC_I420 && - format != FOURCC_YV12) || y == sample; + bool need_buf = (rotation && format != FOURCC_I420 && + format != FOURCC_NV12 && format != FOURCC_NV21 && + format != FOURCC_YU12 && format != FOURCC_YV12) || y == sample; uint8* tmp_y = y; uint8* tmp_u = u; uint8* tmp_v = v; @@ -1965,21 +1965,22 @@ int ConvertToI420(const uint8* sample, break; // Triplanar formats case FOURCC_I420: + case FOURCC_YU12: case FOURCC_YV12: { const uint8* src_y = sample + (src_width * crop_y + crop_x); const uint8* src_u; const uint8* src_v; int halfwidth = (src_width + 1) / 2; int halfheight = (abs_src_height + 1) / 2; - if (format == FOURCC_I420) { - src_u = sample + src_width * abs_src_height + - (halfwidth * crop_y + crop_x) / 2; + if (format == FOURCC_YV12) { src_v = sample + src_width * abs_src_height + + (halfwidth * crop_y + crop_x) / 2; + src_u = sample + src_width * abs_src_height + halfwidth * (halfheight + crop_y / 2) + crop_x / 2; } else { - src_v = sample + src_width * abs_src_height + - (halfwidth * crop_y + crop_x) / 2; src_u = sample + src_width * abs_src_height + + (halfwidth * crop_y + crop_x) / 2; + src_v = sample + src_width * abs_src_height + halfwidth * (halfheight + crop_y / 2) + crop_x / 2; } r = I420Rotate(src_y, src_width, @@ -1997,15 +1998,15 @@ int ConvertToI420(const uint8* sample, const uint8* src_u; const uint8* src_v; int halfwidth = (src_width + 1) / 2; - if (format == FOURCC_I422) { - src_u = sample + src_width * abs_src_height + - halfwidth * crop_y + crop_x / 2; + if (format == FOURCC_YV16) { src_v = sample + src_width * abs_src_height + + halfwidth * crop_y + crop_x / 2; + src_u = sample + src_width * abs_src_height + halfwidth * (abs_src_height + crop_y) + crop_x / 2; } else { - src_v = sample + src_width * abs_src_height + - halfwidth * crop_y + crop_x / 2; src_u = sample + src_width * abs_src_height + + halfwidth * crop_y + crop_x / 2; + src_v = sample + src_width * abs_src_height + halfwidth * (abs_src_height + crop_y) + crop_x / 2; } r = I422ToI420(src_y, src_width, @@ -2022,12 +2023,12 @@ int ConvertToI420(const uint8* sample, const uint8* src_y = sample + src_width * crop_y + crop_x; const uint8* src_u; const uint8* src_v; - if (format == FOURCC_I444) { - src_u = sample + src_width * (abs_src_height + crop_y) + crop_x; - src_v = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x; - } else { + if (format == FOURCC_YV24) { src_v = sample + src_width * (abs_src_height + crop_y) + crop_x; src_u = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x; + } else { + src_u = sample + src_width * (abs_src_height + crop_y) + crop_x; + src_v = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x; } r = I444ToI420(src_y, src_width, src_u, src_width, diff --git a/source/convert_argb.cc b/source/convert_argb.cc index bdc5ec21e..2f1acf154 100644 --- a/source/convert_argb.cc +++ b/source/convert_argb.cc @@ -1173,21 +1173,22 @@ int ConvertToARGB(const uint8* sample, size_t sample_size, // break; // Triplanar formats case FOURCC_I420: + case FOURCC_YU12: case FOURCC_YV12: { const uint8* src_y = sample + (src_width * crop_y + crop_x); const uint8* src_u; const uint8* src_v; int halfwidth = (src_width + 1) / 2; int halfheight = (abs_src_height + 1) / 2; - if (format == FOURCC_I420) { - src_u = sample + src_width * abs_src_height + - (halfwidth * crop_y + crop_x) / 2; + if (format == FOURCC_YV12) { src_v = sample + src_width * abs_src_height + + (halfwidth * crop_y + crop_x) / 2; + src_u = sample + src_width * abs_src_height + halfwidth * (halfheight + crop_y / 2) + crop_x / 2; } else { - src_v = sample + src_width * abs_src_height + - (halfwidth * crop_y + crop_x) / 2; src_u = sample + src_width * abs_src_height + + (halfwidth * crop_y + crop_x) / 2; + src_v = sample + src_width * abs_src_height + halfwidth * (halfheight + crop_y / 2) + crop_x / 2; } r = I420ToARGB(src_y, src_width, @@ -1203,15 +1204,15 @@ int ConvertToARGB(const uint8* sample, size_t sample_size, const uint8* src_u; const uint8* src_v; int halfwidth = (src_width + 1) / 2; - if (format == FOURCC_I422) { - src_u = sample + src_width * abs_src_height + - halfwidth * crop_y + crop_x / 2; + if (format == FOURCC_YV16) { src_v = sample + src_width * abs_src_height + + halfwidth * crop_y + crop_x / 2; + src_u = sample + src_width * abs_src_height + halfwidth * (abs_src_height + crop_y) + crop_x / 2; } else { - src_v = sample + src_width * abs_src_height + - halfwidth * crop_y + crop_x / 2; src_u = sample + src_width * abs_src_height + + halfwidth * crop_y + crop_x / 2; + src_v = sample + src_width * abs_src_height + halfwidth * (abs_src_height + crop_y) + crop_x / 2; } r = I422ToARGB(src_y, src_width, @@ -1226,12 +1227,12 @@ int ConvertToARGB(const uint8* sample, size_t sample_size, const uint8* src_y = sample + src_width * crop_y + crop_x; const uint8* src_u; const uint8* src_v; - if (format == FOURCC_I444) { - src_u = sample + src_width * (abs_src_height + crop_y) + crop_x; - src_v = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x; - } else { + if (format == FOURCC_YV24) { src_v = sample + src_width * (abs_src_height + crop_y) + crop_x; src_u = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x; + } else { + src_u = sample + src_width * (abs_src_height + crop_y) + crop_x; + src_v = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x; } r = I444ToARGB(src_y, src_width, src_u, src_width, diff --git a/source/convert_from.cc b/source/convert_from.cc index 9d7808d52..bfa56ec80 100644 --- a/source/convert_from.cc +++ b/source/convert_from.cc @@ -1370,17 +1370,18 @@ int ConvertFromI420(const uint8* y, int y_stride, // Triplanar formats // TODO(fbarchard): halfstride instead of halfwidth case FOURCC_I420: + case FOURCC_YU12: case FOURCC_YV12: { int halfwidth = (width + 1) / 2; int halfheight = (height + 1) / 2; uint8* dst_u; uint8* dst_v; - if (format == FOURCC_I420) { - dst_u = dst_sample + width * height; - dst_v = dst_u + halfwidth * halfheight; - } else { + if (format == FOURCC_YV12) { dst_v = dst_sample + width * height; dst_u = dst_v + halfwidth * halfheight; + } else { + dst_u = dst_sample + width * height; + dst_v = dst_u + halfwidth * halfheight; } r = I420Copy(y, y_stride, u, u_stride, @@ -1396,12 +1397,12 @@ int ConvertFromI420(const uint8* y, int y_stride, int halfwidth = (width + 1) / 2; uint8* dst_u; uint8* dst_v; - if (format == FOURCC_I422) { - dst_u = dst_sample + width * height; - dst_v = dst_u + halfwidth * height; - } else { + if (format == FOURCC_YV16) { dst_v = dst_sample + width * height; dst_u = dst_v + halfwidth * height; + } else { + dst_u = dst_sample + width * height; + dst_v = dst_u + halfwidth * height; } r = I420ToI422(y, y_stride, u, u_stride, @@ -1416,12 +1417,12 @@ int ConvertFromI420(const uint8* y, int y_stride, case FOURCC_YV24: { uint8* dst_u; uint8* dst_v; - if (format == FOURCC_I444) { - dst_u = dst_sample + width * height; - dst_v = dst_u + width * height; - } else { + if (format == FOURCC_YV24) { dst_v = dst_sample + width * height; dst_u = dst_v + width * height; + } else { + dst_u = dst_sample + width * height; + dst_v = dst_u + width * height; } r = I420ToI444(y, y_stride, u, u_stride, diff --git a/source/video_common.cc b/source/video_common.cc index 3b702dcd8..616affd1c 100644 --- a/source/video_common.cc +++ b/source/video_common.cc @@ -25,7 +25,6 @@ struct FourCCAliasEntry { static const FourCCAliasEntry kFourCCAliases[] = { {FOURCC_IYUV, FOURCC_I420}, - {FOURCC_YU12, FOURCC_I420}, {FOURCC_YU16, FOURCC_I422}, {FOURCC_YU24, FOURCC_I444}, {FOURCC_YUYV, FOURCC_YUY2},