diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-05-15 03:15:20 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-05-15 03:15:20 +0000 |
commit | 61548af20b13116d7434bfc981af21206bf4b578 (patch) | |
tree | 15421faf5c7b9194cc887ca4f063b3bad9d44226 | |
parent | 2436ae4f8cfa468cc76a26704ff3624db250363b (diff) | |
parent | bfa54adbdf2daca20c7bd4ccaa870b41d4553ec3 (diff) | |
download | libyuv-android10-tests-release.tar.gz |
Snap for 5567188 from bfa54adbdf2daca20c7bd4ccaa870b41d4553ec3 to qt-releaseandroid-vts-10.0_r9android-vts-10.0_r8android-vts-10.0_r7android-vts-10.0_r6android-vts-10.0_r5android-vts-10.0_r4android-vts-10.0_r3android-vts-10.0_r2android-vts-10.0_r16android-vts-10.0_r15android-vts-10.0_r14android-vts-10.0_r13android-vts-10.0_r12android-vts-10.0_r11android-vts-10.0_r10android-vts-10.0_r1android-security-10.0.0_r75android-security-10.0.0_r74android-security-10.0.0_r73android-security-10.0.0_r72android-security-10.0.0_r71android-security-10.0.0_r70android-security-10.0.0_r69android-security-10.0.0_r68android-security-10.0.0_r67android-security-10.0.0_r66android-security-10.0.0_r65android-security-10.0.0_r64android-security-10.0.0_r63android-security-10.0.0_r62android-security-10.0.0_r61android-security-10.0.0_r60android-security-10.0.0_r59android-security-10.0.0_r58android-security-10.0.0_r57android-security-10.0.0_r56android-security-10.0.0_r55android-security-10.0.0_r54android-security-10.0.0_r53android-security-10.0.0_r52android-security-10.0.0_r51android-security-10.0.0_r50android-security-10.0.0_r49android-security-10.0.0_r48android-cts-10.0_r9android-cts-10.0_r8android-cts-10.0_r7android-cts-10.0_r6android-cts-10.0_r5android-cts-10.0_r4android-cts-10.0_r3android-cts-10.0_r2android-cts-10.0_r16android-cts-10.0_r15android-cts-10.0_r14android-cts-10.0_r13android-cts-10.0_r12android-cts-10.0_r11android-cts-10.0_r10android-cts-10.0_r1android-10.0.0_r6android-10.0.0_r5android-10.0.0_r47android-10.0.0_r46android-10.0.0_r4android-10.0.0_r3android-10.0.0_r2android-10.0.0_r17android-10.0.0_r11android-10.0.0_r10android-10.0.0_r1android10-tests-releaseandroid10-security-releaseandroid10-s3-releaseandroid10-s2-releaseandroid10-s1-releaseandroid10-release
Change-Id: I9eb91ecff3d967a00fbfee384c918f2aa2a01b5c
-rw-r--r-- | OWNERS | 1 | ||||
-rw-r--r-- | files/include/libyuv/convert_argb.h | 54 | ||||
-rw-r--r-- | files/source/convert_argb.cc | 216 | ||||
-rw-r--r-- | files/unit_test/convert_test.cc | 2 |
4 files changed, 249 insertions, 24 deletions
@@ -1,3 +1,4 @@ fbarchard@google.com phoglund@google.com magjed@google.com +chz@google.com diff --git a/files/include/libyuv/convert_argb.h b/files/include/libyuv/convert_argb.h index f43a5060..6bdfd95c 100644 --- a/files/include/libyuv/convert_argb.h +++ b/files/include/libyuv/convert_argb.h @@ -58,8 +58,8 @@ int I420ToABGR(const uint8* src_y, int src_stride_u, const uint8* src_v, int src_stride_v, - uint8* dst_argb, - int dst_stride_argb, + uint8* dst_abgr, + int dst_stride_abgr, int width, int height); @@ -190,6 +190,28 @@ int NV21ToARGB(const uint8* src_y, int width, int height); +// Convert NV12 to ABGR. +LIBYUV_API +int NV12ToABGR(const uint8* src_y, + int src_stride_y, + const uint8* src_uv, + int src_stride_uv, + uint8* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert NV21 to ABGR. +LIBYUV_API +int NV21ToABGR(const uint8* src_y, + int src_stride_y, + const uint8* src_uv, + int src_stride_uv, + uint8* dst_abgr, + int dst_stride_abgr, + int width, + int height); + // Convert M420 to ARGB. LIBYUV_API int M420ToARGB(const uint8* src_m420, @@ -410,6 +432,34 @@ int MJPGToARGB(const uint8* sample, int dst_height); #endif +// Convert Android420 to ARGB. +LIBYUV_API +int Android420ToARGB(const uint8* src_y, + int src_stride_y, + const uint8* src_u, + int src_stride_u, + const uint8* src_v, + int src_stride_v, + int src_pixel_stride_uv, + uint8* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert Android420 to ABGR. +LIBYUV_API +int Android420ToABGR(const uint8* src_y, + int src_stride_y, + const uint8* src_u, + int src_stride_u, + const uint8* src_v, + int src_stride_v, + int src_pixel_stride_uv, + uint8* dst_abgr, + int dst_stride_abgr, + int width, + int height); + // Convert camera sample to ARGB with cropping, rotation and vertical flip. // "src_size" is needed to parse MJPG. // "dst_stride_argb" number of bytes in a row of the dst_argb plane. diff --git a/files/source/convert_argb.cc b/files/source/convert_argb.cc index 5007bdb9..983be578 100644 --- a/files/source/convert_argb.cc +++ b/files/source/convert_argb.cc @@ -1295,16 +1295,16 @@ int ARGB4444ToARGB(const uint8* src_argb4444, return 0; } -// Convert NV12 to ARGB. -LIBYUV_API -int NV12ToARGB(const uint8* src_y, - int src_stride_y, - const uint8* src_uv, - int src_stride_uv, - uint8* dst_argb, - int dst_stride_argb, - int width, - int height) { +// Convert NV12 to ARGB with matrix +static int NV12ToARGBMatrix(const uint8* src_y, + int src_stride_y, + const uint8* src_uv, + int src_stride_uv, + uint8* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; void (*NV12ToARGBRow)(const uint8* y_buf, const uint8* uv_buf, uint8* rgb_buf, const struct YuvConstants* yuvconstants, int width) = @@ -1360,7 +1360,7 @@ int NV12ToARGB(const uint8* src_y, #endif for (y = 0; y < height; ++y) { - NV12ToARGBRow(src_y, src_uv, dst_argb, &kYuvI601Constants, width); + NV12ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width); dst_argb += dst_stride_argb; src_y += src_stride_y; if (y & 1) { @@ -1370,16 +1370,16 @@ int NV12ToARGB(const uint8* src_y, return 0; } -// Convert NV21 to ARGB. -LIBYUV_API -int NV21ToARGB(const uint8* src_y, - int src_stride_y, - const uint8* src_uv, - int src_stride_uv, - uint8* dst_argb, - int dst_stride_argb, - int width, - int height) { +// Convert NV21 to ARGB with matrix +static int NV21ToARGBMatrix(const uint8* src_y, + int src_stride_y, + const uint8* src_uv, + int src_stride_uv, + uint8* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; void (*NV21ToARGBRow)(const uint8* y_buf, const uint8* uv_buf, uint8* rgb_buf, const struct YuvConstants* yuvconstants, int width) = @@ -1427,7 +1427,7 @@ int NV21ToARGB(const uint8* src_y, #endif for (y = 0; y < height; ++y) { - NV21ToARGBRow(src_y, src_uv, dst_argb, &kYuvI601Constants, width); + NV21ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width); dst_argb += dst_stride_argb; src_y += src_stride_y; if (y & 1) { @@ -1437,6 +1437,64 @@ int NV21ToARGB(const uint8* src_y, return 0; } +// Convert NV12 to ARGB. +LIBYUV_API +int NV12ToARGB(const uint8* src_y, + int src_stride_y, + const uint8* src_uv, + int src_stride_uv, + uint8* dst_argb, + int dst_stride_argb, + int width, + int height) { + return NV12ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_argb, + dst_stride_argb, &kYuvI601Constants, width, height); +} + +// Convert NV21 to ARGB. +LIBYUV_API +int NV21ToARGB(const uint8* src_y, + int src_stride_y, + const uint8* src_uv, + int src_stride_uv, + uint8* dst_argb, + int dst_stride_argb, + int width, + int height) { + return NV21ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_argb, + dst_stride_argb, &kYuvI601Constants, width, height); +} + +// Convert NV12 to ABGR. +// To output ABGR instead of ARGB swap the UV and use a mirrored yuv matrix. +// To swap the UV use NV12 instead of NV21.LIBYUV_API +LIBYUV_API +int NV12ToABGR(const uint8* src_y, + int src_stride_y, + const uint8* src_uv, + int src_stride_uv, + uint8* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return NV21ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, dst_abgr, + dst_stride_abgr, &kYvuI601Constants, width, height); +} + +// Convert NV21 to ABGR. +LIBYUV_API +int NV21ToABGR(const uint8* src_y, + int src_stride_y, + const uint8* src_vu, + int src_stride_vu, + uint8* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return NV12ToARGBMatrix(src_y, src_stride_y, src_vu, src_stride_vu, dst_abgr, + dst_stride_abgr, &kYvuI601Constants, width, height); +} + // Convert M420 to ARGB. LIBYUV_API int M420ToARGB(const uint8* src_m420, @@ -1647,6 +1705,120 @@ int UYVYToARGB(const uint8* src_uyvy, } return 0; } +static void WeavePixels(const uint8* src_u, + const uint8* src_v, + int src_pixel_stride_uv, + uint8* dst_uv, + int width) { + int i; + for (i = 0; i < width; ++i) { + dst_uv[0] = *src_u; + dst_uv[1] = *src_v; + dst_uv += 2; + src_u += src_pixel_stride_uv; + src_v += src_pixel_stride_uv; + } +} + +// Convert Android420 to ARGB. +LIBYUV_API +int Android420ToARGBMatrix(const uint8* src_y, + int src_stride_y, + const uint8* src_u, + int src_stride_u, + const uint8* src_v, + int src_stride_v, + int src_pixel_stride_uv, + uint8* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + uint8* dst_uv; + const ptrdiff_t vu_off = src_v - src_u; + int halfwidth = (width + 1) >> 1; + int halfheight = (height + 1) >> 1; + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } + + // I420 + if (src_pixel_stride_uv == 1) { + return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + yuvconstants, width, height); + // NV21 + } else if (src_pixel_stride_uv == 2 && vu_off == -1 && + src_stride_u == src_stride_v) { + return NV21ToARGBMatrix(src_y, src_stride_y, src_v, src_stride_v, dst_argb, + dst_stride_argb, yuvconstants, width, height); + // NV12 + } else if (src_pixel_stride_uv == 2 && vu_off == 1 && + src_stride_u == src_stride_v) { + return NV12ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, dst_argb, + dst_stride_argb, yuvconstants, width, height); + } + + // General case fallback creates NV12 + align_buffer_64(plane_uv, halfwidth * 2 * halfheight); + dst_uv = plane_uv; + for (y = 0; y < halfheight; ++y) { + WeavePixels(src_u, src_v, src_pixel_stride_uv, dst_uv, halfwidth); + src_u += src_stride_u; + src_v += src_stride_v; + dst_uv += halfwidth * 2; + } + NV12ToARGBMatrix(src_y, src_stride_y, plane_uv, halfwidth * 2, dst_argb, + dst_stride_argb, yuvconstants, width, height); + free_aligned_buffer_64(plane_uv); + return 0; +} + +// Convert Android420 to ARGB. +LIBYUV_API +int Android420ToARGB(const uint8* src_y, + int src_stride_y, + const uint8* src_u, + int src_stride_u, + const uint8* src_v, + int src_stride_v, + int src_pixel_stride_uv, + uint8* dst_argb, + int dst_stride_argb, + int width, + int height) { + return Android420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, src_pixel_stride_uv, dst_argb, + dst_stride_argb, &kYuvI601Constants, width, + height); +} + +// Convert Android420 to ABGR. +LIBYUV_API +int Android420ToABGR(const uint8* src_y, + int src_stride_y, + const uint8* src_u, + int src_stride_u, + const uint8* src_v, + int src_stride_v, + int src_pixel_stride_uv, + uint8* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return Android420ToARGBMatrix(src_y, src_stride_y, src_v, src_stride_v, src_u, + src_stride_u, src_pixel_stride_uv, dst_abgr, + dst_stride_abgr, &kYvuI601Constants, width, + height); +} #ifdef __cplusplus } // extern "C" diff --git a/files/unit_test/convert_test.cc b/files/unit_test/convert_test.cc index 04d5a404..41564351 100644 --- a/files/unit_test/convert_test.cc +++ b/files/unit_test/convert_test.cc @@ -735,6 +735,8 @@ TESTQPLANARTOB(I420Alpha, 2, 2, ABGR, 4, 4, 1, 2) TESTBIPLANARTOB(NV12, 2, 2, ARGB, 4, 2) TESTBIPLANARTOB(NV21, 2, 2, ARGB, 4, 2) +TESTBIPLANARTOB(NV12, 2, 2, ABGR, 4, 2) +TESTBIPLANARTOB(NV21, 2, 2, ABGR, 4, 2) TESTBIPLANARTOB(NV12, 2, 2, RGB565, 2, 9) #ifdef DO_THREE_PLANES |