diff options
author | Frank Barchard <fbarchard@google.com> | 2020-04-17 11:08:04 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-04-17 19:22:29 +0000 |
commit | 2f48ffd42b8479181c9019710c62ba13ab5697fc (patch) | |
tree | f6bad6543b554c37966ef79bf907f2b5581d5442 /source/convert_from.cc | |
parent | d4c3f45eb672e7bd008cac3347f3e21c955cbf7d (diff) | |
download | libyuv-2f48ffd42b8479181c9019710c62ba13ab5697fc.tar.gz |
HalfMergeUVPlane function and optimized I444ToNV12 and I444ToNV21
Bug: libyuv:858
Change-Id: Ie1f03a9acaff02ee8059cf1e5c2c2e5afcde8592
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/2154608
Commit-Queue: Frank Barchard <fbarchard@chromium.org>
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Diffstat (limited to 'source/convert_from.cc')
-rw-r--r-- | source/convert_from.cc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/source/convert_from.cc b/source/convert_from.cc index 0c95f1f2..25404afd 100644 --- a/source/convert_from.cc +++ b/source/convert_from.cc @@ -488,7 +488,6 @@ int I420ToUYVY(const uint8_t* src_y, return 0; } -// TODO(fbarchard): test negative height for invert. LIBYUV_API int I420ToNV12(const uint8_t* src_y, int src_stride_y, @@ -502,12 +501,23 @@ int I420ToNV12(const uint8_t* src_y, int dst_stride_uv, int width, int height) { + int halfwidth = (width + 1) / 2; + int halfheight = (height + 1) / 2; if (!src_y || !src_u || !src_v || !dst_y || !dst_uv || width <= 0 || height == 0) { return -1; } - int halfwidth = (width + 1) / 2; - int halfheight = height > 0 ? (height + 1) / 2 : (height - 1) / 2; + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + src_y = src_y + (height - 1) * src_stride_y; + src_u = src_u + (halfheight - 1) * src_stride_u; + src_v = src_v + (halfheight - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } if (dst_y) { CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); } |