From d4840d4fe923789ddc0953e8d2781ec8fc99ec36 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Mon, 19 Mar 2012 15:52:55 +0000 Subject: [PATCH] Rotate any format by converting into an I420 buffer and then rotating that BUG=none TEST=none Review URL: https://webrtc-codereview.appspot.com/446009 git-svn-id: http://libyuv.googlecode.com/svn/trunk@217 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- README.chromium | 2 +- include/libyuv/version.h | 2 +- source/convert.cc | 43 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/README.chromium b/README.chromium index 9ee263849..c56327178 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 216 +Version: 217 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 299303e60..e99ad6491 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,7 +11,7 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 216 +#define LIBYUV_VERSION 217 #endif // INCLUDE_LIBYUV_VERSION_H_ diff --git a/source/convert.cc b/source/convert.cc index af4d2693b..fab5b16b9 100644 --- a/source/convert.cc +++ b/source/convert.cc @@ -1588,6 +1588,33 @@ int ConvertToI420(const uint8* sample, size_t sample_size, inv_dst_height = -inv_dst_height; } int r = 0; + + // For formats that need 2 pass rotation, convert into buffer first + bool need_rot = rotation && format != FOURCC_NV12 && + format != FOURCC_NV21 && format != FOURCC_I420 && + format != FOURCC_YV12; + uint8* tmp_y = y; + uint8* tmp_u = u; + uint8* tmp_v = v; + int tmp_y_stride = y_stride; + int tmp_u_stride = u_stride; + int tmp_v_stride = v_stride; + uint8* buf = 0; + int abs_dst_height = (dst_height < 0) ? -dst_height : dst_height; + if (need_rot) { + int y_size = dst_width * abs_dst_height; + int uv_size = ((dst_width + 1) / 2) * ((abs_dst_height + 1) / 2); + buf = new uint8[y_size + uv_size * 2]; + if (!buf) { + return 1; // Out of memory runtime error. + } + y = buf; + u = y + y_size; + v = u + uv_size; + y_stride = dst_width; + u_stride = v_stride = ((dst_width + 1) / 2); + } + switch (format) { // Single plane formats case FOURCC_YUY2: @@ -1870,8 +1897,22 @@ int ConvertToI420(const uint8* sample, size_t sample_size, break; #endif default: - return -1; // unknown fourcc - return failure code. + r = -1; // unknown fourcc - return failure code. } + + if (need_rot) { + if (!r) { + r = I420Rotate(y, y_stride, + u, u_stride, + v, v_stride, + tmp_y, tmp_y_stride, + tmp_u, tmp_u_stride, + tmp_v, tmp_v_stride, + dst_width, abs_dst_height, rotation); + } + delete buf; + } + return r; }