From 161e5c45696e45cab8f437eb9d8c6d7a0c1bb997 Mon Sep 17 00:00:00 2001 From: Frank Barchard Date: Wed, 24 Aug 2016 10:19:14 -0700 Subject: [PATCH] Allow NULL for dst_y in planar formats. BUG=libyuv:631 TEST=unittests build/pass BUG=libyuv:631 TEST=unittests build/pass R=harryjin@google.com Review URL: https://codereview.chromium.org/2271053003 . --- source/convert.cc | 16 +++++++++------- source/convert_from.cc | 18 ++++++++++++------ source/planar_functions.cc | 18 ++++++++++++------ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/source/convert.cc b/source/convert.cc index d0896cfb6..cd667bf56 100644 --- a/source/convert.cc +++ b/source/convert.cc @@ -44,7 +44,7 @@ static int I4xxToI420(const uint8* src_y, int src_stride_y, src_uv_width == 0 || src_uv_height == 0) { return -1; } - // TODO(fbarchard): make Y optional. + // TODO(fbarchard): support NULL for dst_y ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, dst_y, dst_stride_y, dst_y_width, dst_y_height, kFilterBilinear); @@ -70,8 +70,8 @@ int I420Copy(const uint8* src_y, int src_stride_y, int width, int height) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_y || !src_u || !src_v || - !dst_y || !dst_u || !dst_v || + if (!src_u || !src_v || + !dst_u || !dst_v || width <= 0 || height == 0) { return -1; } @@ -167,7 +167,7 @@ int I400ToI420(const uint8* src_y, int src_stride_y, int width, int height) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_y || !dst_y || !dst_u || !dst_v || + if (!dst_u || !dst_v || width <= 0 || height == 0) { return -1; } @@ -178,7 +178,9 @@ int I400ToI420(const uint8* src_y, int src_stride_y, src_y = src_y + (height - 1) * src_stride_y; src_stride_y = -src_stride_y; } - CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + if (dst_y) { + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } SetPlane(dst_u, dst_stride_u, halfwidth, halfheight, 128); SetPlane(dst_v, dst_stride_v, halfwidth, halfheight, 128); return 0; @@ -1435,8 +1437,8 @@ int Android420ToI420(const uint8* src_y, int src_stride_y, const int vu_off = src_v - src_u; int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_y || !src_u || !src_v || - !dst_y || !dst_u || !dst_v || + if (!src_u || !src_v || + !dst_u || !dst_v || width <= 0 || height == 0) { return -1; } diff --git a/source/convert_from.cc b/source/convert_from.cc index 46abdebcd..2341dca95 100644 --- a/source/convert_from.cc +++ b/source/convert_from.cc @@ -46,9 +46,11 @@ static int I420ToI4xx(const uint8* src_y, int src_stride_y, dst_uv_width <= 0 || dst_uv_height <= 0) { return -1; } - ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, - dst_y, dst_stride_y, dst_y_width, dst_y_height, - kFilterBilinear); + if (dst_y) { + ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, + dst_y, dst_stride_y, dst_y_width, dst_y_height, + kFilterBilinear); + } ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u, dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear); @@ -372,7 +374,7 @@ int I420ToNV12(const uint8* src_y, int src_stride_y, // Coalesce rows. int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_y || !src_u || !src_v || !dst_y || !dst_uv || + if (!src_u || !src_v || !dst_uv || width <= 0 || height == 0) { return -1; } @@ -380,7 +382,9 @@ int I420ToNV12(const uint8* src_y, int src_stride_y, if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - dst_y = dst_y + (height - 1) * dst_stride_y; + if (dst_y) { + dst_y = dst_y + (height - 1) * dst_stride_y; + } dst_uv = dst_uv + (halfheight - 1) * dst_stride_uv; dst_stride_y = -dst_stride_y; dst_stride_uv = -dst_stride_uv; @@ -424,7 +428,9 @@ int I420ToNV12(const uint8* src_y, int src_stride_y, } #endif - CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + if (dst_y) { + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } for (y = 0; y < halfheight; ++y) { // Merge a row of U and V into a row of UV. MergeUVRow_(src_u, src_v, dst_uv, halfwidth); diff --git a/source/planar_functions.cc b/source/planar_functions.cc index 237ab6831..811ee5b72 100644 --- a/source/planar_functions.cc +++ b/source/planar_functions.cc @@ -128,8 +128,8 @@ int I422Copy(const uint8* src_y, int src_stride_y, uint8* dst_v, int dst_stride_v, int width, int height) { int halfwidth = (width + 1) >> 1; - if (!src_y || !src_u || !src_v || - !dst_y || !dst_u || !dst_v || + if (!src_u || !src_v || + !dst_u || !dst_v || width <= 0 || height == 0) { return -1; } @@ -143,7 +143,10 @@ int I422Copy(const uint8* src_y, int src_stride_y, src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; } - CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + + if (dst_y) { + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, height); CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, height); return 0; @@ -158,8 +161,8 @@ int I444Copy(const uint8* src_y, int src_stride_y, uint8* dst_u, int dst_stride_u, uint8* dst_v, int dst_stride_v, int width, int height) { - if (!src_y || !src_u || !src_v || - !dst_y || !dst_u || !dst_v || + if (!src_u || !src_v || + !dst_u || !dst_v || width <= 0 || height == 0) { return -1; } @@ -174,7 +177,9 @@ int I444Copy(const uint8* src_y, int src_stride_y, src_stride_v = -src_stride_v; } - CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + if (dst_y) { + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, width, height); CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, width, height); return 0; @@ -214,6 +219,7 @@ int I420ToI400(const uint8* src_y, int src_stride_y, src_y = src_y + (height - 1) * src_stride_y; src_stride_y = -src_stride_y; } + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); return 0; }