From 70cb21cf5c7147bb9e815f1624a6653664e7edff Mon Sep 17 00:00:00 2001 From: xufuji456 Date: Tue, 12 Jul 2022 14:26:52 +0800 Subject: [PATCH] Feature: convert nv12(yuv420sp) to yuv420p --- app/src/main/cpp/yuv/yuv_converter.cpp | 12 ++++++++++-- app/src/main/cpp/yuv/yuv_converter.h | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/yuv/yuv_converter.cpp b/app/src/main/cpp/yuv/yuv_converter.cpp index 16fe7ba..39f85ce 100644 --- a/app/src/main/cpp/yuv/yuv_converter.cpp +++ b/app/src/main/cpp/yuv/yuv_converter.cpp @@ -114,7 +114,15 @@ static void nv21_to_yuv420p(int8_t *dst, int8_t *src, int len) { } } -static void yuv420p_rotate90(int8_t *dst, int8_t *src, int width, int height) { +static void nv12_to_yuv420p(int8_t *dst, int8_t *src, int len) { + memcpy(dst, src, len); // y + for (int i = 0; i < len / 4; ++i) { + *(dst + len + i) = *(src + len + i * 2); // u + *(dst + len * 5 / 4 + i) = *(src + len + i * 2 + 1); // v + } +} + +static void yuv420p_rotate90(int8_t *dst, const int8_t *src, int width, int height) { int n = 0; int wh = width * height; int half_width = width / 2; @@ -139,7 +147,7 @@ static void yuv420p_rotate90(int8_t *dst, int8_t *src, int width, int height) { } } -static void yuv420p_rotate180(int8_t *dst, int8_t *src, int width, int height) { +static void yuv420p_rotate180(int8_t *dst, const int8_t *src, int width, int height) { int n = 0; int half_width = width / 2; int half_height = height / 2; diff --git a/app/src/main/cpp/yuv/yuv_converter.h b/app/src/main/cpp/yuv/yuv_converter.h index 8e1b60a..14a904a 100644 --- a/app/src/main/cpp/yuv/yuv_converter.h +++ b/app/src/main/cpp/yuv/yuv_converter.h @@ -21,4 +21,12 @@ static void yuv420p_rotate(int8_t *dst, int8_t *src, int width, int height, int */ static void nv21_to_yuv420p(int8_t *dst, int8_t *src, int len); +/** + * convert NV12 to YUV420P + * @param dst data of yuv420p + * @param src data of nv12 + * @param len width*height + */ +static void nv12_to_yuv420p(int8_t *dst, int8_t *src, int len); + #endif //FFMPEGANDROID_YUV_CONVERTER_H