diff --git a/include/general.h b/include/general.h index 793375039..9450e3782 100644 --- a/include/general.h +++ b/include/general.h @@ -21,11 +21,11 @@ namespace libyuv { // Supported rotation -enum VideoRotationMode +enum RotationMode { kRotateNone = 0, kRotateClockwise = 90, - kRotateCounterClockwise = -90, + kRotateCounterClockwise = 270, kRotate180 = 180, }; @@ -51,6 +51,17 @@ I420Crop(uint8* frame, int src_width, int src_height, int dst_width, int dst_height); +// Rotate I420 frame +int +I420Rotate(const uint8* src_yplane, int src_ystride, + const uint8* src_uplane, int src_ustride, + const uint8* src_vplane, int src_vstride, + uint8* dst_yplane, int dst_ystride, + uint8* dst_uplane, int dst_ustride, + uint8* dst_vplane, int dst_vstride, + int width, int height, + RotationMode mode); + } // namespace libyuv diff --git a/libyuv.gyp b/libyuv.gyp index dd31c0159..b8287e60b 100644 --- a/libyuv.gyp +++ b/libyuv.gyp @@ -33,6 +33,7 @@ 'common/common.h', 'common/constructor_magic.h', 'source/cpu_id.h', + 'source/rotate.h' 'source/row.h', 'source/video_common.h', @@ -42,6 +43,8 @@ 'source/format_conversion.cc', 'source/general.cc', 'source/planar_functions.cc', + 'source/rotate.cc', + 'source/rotate_deinterleave.cc', 'source/row_table.cc', 'source/scale.cc', 'source/video_common.cc', diff --git a/source/general.cc b/source/general.cc index e9af0483c..0759db854 100644 --- a/source/general.cc +++ b/source/general.cc @@ -12,6 +12,10 @@ #include // memcpy(), memset() +#include "planar_functions.h" +#include "rotate.h" + + namespace libyuv { int @@ -305,4 +309,69 @@ I420CropPad(const uint8* src_frame, int src_width, return 0; } +int +I420Rotate(const uint8* src_yplane, int src_ystride, + const uint8* src_uplane, int src_ustride, + const uint8* src_vplane, int src_vstride, + uint8* dst_yplane, int dst_ystride, + uint8* dst_uplane, int dst_ustride, + uint8* dst_vplane, int dst_vstride, + int width, int height, + RotationMode mode) +{ + switch (mode){ + // TODO: should return int + case kRotateNone: + // copy frame + I420Copy(src_yplane, src_ystride, + src_uplane, src_ustride, + src_vplane, src_vstride, + dst_yplane, dst_ystride, + dst_uplane, dst_ustride, + dst_vplane, dst_vstride, + width, height); + return 0; + break; + case kRotateClockwise: + Rotate90(src_yplane, src_ystride, + dst_yplane, dst_ystride, + width, height); + Rotate90(src_uplane, src_ustride, + dst_uplane, dst_ustride, + width, height); + Rotate90(src_vplane, src_vstride, + dst_vplane, dst_vstride, + width, height); + return 0; + break; + case kRotateCounterClockwise: + Rotate270(src_yplane, src_ystride, + dst_yplane, dst_ystride, + width, height); + Rotate270(src_uplane, src_ustride, + dst_uplane, dst_ustride, + width, height); + Rotate270(src_vplane, src_vstride, + dst_vplane, dst_vstride, + width, height); + return 0; + break; + case kRotate180: + Rotate180(src_yplane, src_ystride, + dst_yplane, dst_ystride, + width, height); + Rotate180(src_uplane, src_ustride, + dst_uplane, dst_ustride, + width, height); + Rotate180(src_vplane, src_vstride, + dst_vplane, dst_vstride, + width, height); + return 0; + break; + default: + return -1; + break; + } +} + } // nmaespace libyuv