aboutsummaryrefslogtreecommitdiff
path: root/source/rotate.cc
diff options
context:
space:
mode:
Diffstat (limited to 'source/rotate.cc')
-rw-r--r--source/rotate.cc80
1 files changed, 58 insertions, 22 deletions
diff --git a/source/rotate.cc b/source/rotate.cc
index 3678b80a..3f8332c3 100644
--- a/source/rotate.cc
+++ b/source/rotate.cc
@@ -8,6 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <assert.h>
+
#include "libyuv/rotate.h"
#include "libyuv/convert.h"
@@ -140,6 +142,9 @@ void RotatePlane180(const uint8_t* src,
int height) {
// Swap top and bottom row and mirror the content. Uses a temporary row.
align_buffer_64(row, width);
+ assert(row);
+ if (!row)
+ return;
const uint8_t* src_bot = src + src_stride * (height - 1);
uint8_t* dst_bot = dst + dst_stride * (height - 1);
int half_height = (height + 1) >> 1;
@@ -543,24 +548,29 @@ static void RotatePlane180_16(const uint16_t* src,
int dst_stride,
int width,
int height) {
- // Swap top and bottom row and mirror the content. Uses a temporary row.
- align_buffer_64_16(row, width);
const uint16_t* src_bot = src + src_stride * (height - 1);
uint16_t* dst_bot = dst + dst_stride * (height - 1);
int half_height = (height + 1) >> 1;
int y;
+ // Swap top and bottom row and mirror the content. Uses a temporary row.
+ align_buffer_64(row, width * 2);
+ uint16_t* row_tmp = (uint16_t*)row;
+ assert(row);
+ if (!row)
+ return;
+
// Odd height will harmlessly mirror the middle row twice.
for (y = 0; y < half_height; ++y) {
- CopyRow_16_C(src, row, width); // Copy top row into buffer
- MirrorRow_16_C(src_bot, dst, width); // Mirror bottom row into top row
- MirrorRow_16_C(row, dst_bot, width); // Mirror buffer into bottom row
+ CopyRow_16_C(src, row_tmp, width); // Copy top row into buffer
+ MirrorRow_16_C(src_bot, dst, width); // Mirror bottom row into top row
+ MirrorRow_16_C(row_tmp, dst_bot, width); // Mirror buffer into bottom row
src += src_stride;
dst += dst_stride;
src_bot -= src_stride;
dst_bot -= dst_stride;
}
- free_aligned_buffer_64_16(row);
+ free_aligned_buffer_64(row);
}
LIBYUV_API
@@ -690,6 +700,7 @@ int I422Rotate(const uint8_t* src_y,
enum RotationMode mode) {
int halfwidth = (width + 1) >> 1;
int halfheight = (height + 1) >> 1;
+ int r;
if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || !dst_y ||
!dst_u || !dst_v) {
return -1;
@@ -725,23 +736,35 @@ int I422Rotate(const uint8_t* src_y,
case kRotate90:
RotatePlane90(src_u, src_stride_u, dst_y, dst_stride_y, halfwidth,
height);
- ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_u, dst_stride_u,
- halfheight, width, kFilterBilinear);
+ r = ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_u,
+ dst_stride_u, halfheight, width, kFilterBilinear);
+ if (r != 0) {
+ return r;
+ }
RotatePlane90(src_v, src_stride_v, dst_y, dst_stride_y, halfwidth,
height);
- ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_v, dst_stride_v,
- halfheight, width, kFilterLinear);
+ r = ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_v,
+ dst_stride_v, halfheight, width, kFilterLinear);
+ if (r != 0) {
+ return r;
+ }
RotatePlane90(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
return 0;
case kRotate270:
RotatePlane270(src_u, src_stride_u, dst_y, dst_stride_y, halfwidth,
height);
- ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_u, dst_stride_u,
- halfheight, width, kFilterBilinear);
+ r = ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_u,
+ dst_stride_u, halfheight, width, kFilterBilinear);
+ if (r != 0) {
+ return r;
+ }
RotatePlane270(src_v, src_stride_v, dst_y, dst_stride_y, halfwidth,
height);
- ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_v, dst_stride_v,
- halfheight, width, kFilterLinear);
+ r = ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_v,
+ dst_stride_v, halfheight, width, kFilterLinear);
+ if (r != 0) {
+ return r;
+ }
RotatePlane270(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
return 0;
case kRotate180:
@@ -1055,6 +1078,7 @@ int I210Rotate(const uint16_t* src_y,
enum RotationMode mode) {
int halfwidth = (width + 1) >> 1;
int halfheight = (height + 1) >> 1;
+ int r;
if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || !dst_y ||
!dst_u || !dst_v) {
return -1;
@@ -1090,23 +1114,35 @@ int I210Rotate(const uint16_t* src_y,
case kRotate90:
RotatePlane90_16(src_u, src_stride_u, dst_y, dst_stride_y, halfwidth,
height);
- ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_u, dst_stride_u,
- halfheight, width, kFilterBilinear);
+ r = ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_u,
+ dst_stride_u, halfheight, width, kFilterBilinear);
+ if (r != 0) {
+ return r;
+ }
RotatePlane90_16(src_v, src_stride_v, dst_y, dst_stride_y, halfwidth,
height);
- ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_v, dst_stride_v,
- halfheight, width, kFilterLinear);
+ r = ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_v,
+ dst_stride_v, halfheight, width, kFilterLinear);
+ if (r != 0) {
+ return r;
+ }
RotatePlane90_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
return 0;
case kRotate270:
RotatePlane270_16(src_u, src_stride_u, dst_y, dst_stride_y, halfwidth,
height);
- ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_u, dst_stride_u,
- halfheight, width, kFilterBilinear);
+ r = ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_u,
+ dst_stride_u, halfheight, width, kFilterBilinear);
+ if (r != 0) {
+ return r;
+ }
RotatePlane270_16(src_v, src_stride_v, dst_y, dst_stride_y, halfwidth,
height);
- ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_v, dst_stride_v,
- halfheight, width, kFilterLinear);
+ r = ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_v,
+ dst_stride_v, halfheight, width, kFilterLinear);
+ if (r != 0) {
+ return r;
+ }
RotatePlane270_16(src_y, src_stride_y, dst_y, dst_stride_y, width,
height);
return 0;