From 434bff4603b0c805c66e13fa2027f9345fde1e45 Mon Sep 17 00:00:00 2001 From: Changhuang Liang Date: Tue, 27 Jun 2023 14:54:41 +0800 Subject: [PATCH] package: starfive: v4l2_test: Add ayuv to nv12 Add ayuv to nv12. Signed-off-by: Changhuang Liang --- package/starfive/v4l2_test/common.c | 6 ++- package/starfive/v4l2_test/convert.c | 60 ++++++++++++++++++++++++++ package/starfive/v4l2_test/convert.h | 1 + package/starfive/v4l2_test/v4l2_test.c | 16 +++++++ 4 files changed, 81 insertions(+), 2 deletions(-) diff --git a/package/starfive/v4l2_test/common.c b/package/starfive/v4l2_test/common.c index 1e48846e..e5d642b1 100644 --- a/package/starfive/v4l2_test/common.c +++ b/package/starfive/v4l2_test/common.c @@ -115,6 +115,10 @@ uint32_t v4l2fmt_to_drmfmt(uint32_t v4l2_fmt) case V4L2_PIX_FMT_NV12: drm_fmt = DRM_FORMAT_NV12; break; + /*add for jh7110 debug*/ + case V4L2_PIX_FMT_AYUV32: + drm_fmt = DRM_FORMAT_NV12; + break; default: drm_fmt = DRM_FORMAT_NV21; LOG(STF_LEVEL_WARN, "drm not support the V4L2_format\n"); @@ -318,5 +322,3 @@ void jpegWrite(uint8_t* img, char* jpegFilename, // close output file fclose(outfile); } - - diff --git a/package/starfive/v4l2_test/convert.c b/package/starfive/v4l2_test/convert.c index 4231ffa4..cb3118e9 100644 --- a/package/starfive/v4l2_test/convert.c +++ b/package/starfive/v4l2_test/convert.c @@ -859,3 +859,63 @@ int convert_rgb888_to_rgb(const uint8_t *inBuf, uint8_t *outBuf, int imgWidth, i free(tmp); return 0; } + +enum AYUV +{ + AYUV_V = 0, + AYUV_U = 1, + AYUV_Y = 2, + AYUV_A = 3, +}; + +int convert_ayuv32_to_nv12(const uint8_t *inBuf, uint8_t *outBuf, int imgWidth, int imgHeight) +{ + int i, j; + unsigned int uv_start_index = imgWidth * imgHeight, frameWidthProd4 = imgWidth * 4; + unsigned int frameWidthDiv2 = imgWidth / 2, frameWidthDiv4 = imgWidth / 4; + unsigned int rowsFrameWidth, rowsFrameWidthProd4, rowsFrameWidthProd4ColsProd4, rowsAdd1FrameWidthProd4ColsProd4; + unsigned int uvStartIndexRowsFrameWidthDiv2, uvStartIndexRowsFrameWidthDiv2Cols; + int dstSize = imgWidth * imgHeight * 3 / 2; + + /* 1. Execute the AYUVToNV12 algorithm. */ + /* Y/U/V components extraction for even index i */ + for (i = 0; i < imgHeight; i += 2) + { + rowsFrameWidth = i * imgWidth; + rowsFrameWidthProd4 = i * frameWidthProd4; + uvStartIndexRowsFrameWidthDiv2 = uv_start_index + i * frameWidthDiv2; + for (j = 0; j < frameWidthDiv4; j++) + { + /* Y components extraction for even index i */ + outBuf[rowsFrameWidth + j] = inBuf[rowsFrameWidthProd4 + j * 4 + AYUV_Y]; + + rowsFrameWidthProd4ColsProd4 = rowsFrameWidthProd4 + j * 16; + rowsAdd1FrameWidthProd4ColsProd4 = rowsFrameWidthProd4ColsProd4 + frameWidthProd4; + uvStartIndexRowsFrameWidthDiv2Cols = uvStartIndexRowsFrameWidthDiv2 + j * 4; + + /* UV components extraction for even index i: processing 4 elements every time */ + outBuf[uvStartIndexRowsFrameWidthDiv2Cols] = inBuf[rowsFrameWidthProd4ColsProd4 + 1]; + outBuf[uvStartIndexRowsFrameWidthDiv2Cols + 1] = inBuf[rowsAdd1FrameWidthProd4ColsProd4]; + outBuf[uvStartIndexRowsFrameWidthDiv2Cols + 2] = inBuf[rowsFrameWidthProd4ColsProd4 + 9]; + outBuf[uvStartIndexRowsFrameWidthDiv2Cols + 3] = inBuf[rowsAdd1FrameWidthProd4ColsProd4 + 8]; + + } + for (; j < imgWidth; j++) + { + outBuf[rowsFrameWidth + j] = inBuf[rowsFrameWidthProd4 + j * 4 + AYUV_Y]; + } + } + + /* Y components extraction for odd index i */ + for (i = 1; i < imgHeight; i += 2) + { + rowsFrameWidth = i * imgWidth; + rowsFrameWidthProd4 = i * frameWidthProd4; + for (j = 0; j < imgWidth; j++) + { + outBuf[rowsFrameWidth + j] = inBuf[rowsFrameWidthProd4 + j * 4 + AYUV_Y]; + } + } + + return 0; +} \ No newline at end of file diff --git a/package/starfive/v4l2_test/convert.h b/package/starfive/v4l2_test/convert.h index 00907dc7..0f0260ee 100644 --- a/package/starfive/v4l2_test/convert.h +++ b/package/starfive/v4l2_test/convert.h @@ -16,6 +16,7 @@ extern int convert_yuyv_to_rgb(const uint8_t *inBuf, uint8_t *outBuf, int imgWid extern int convert_yuv444_to_rgb(uint8_t *inBuf, uint8_t *outBuf, int imgWidth, int imgHeight, int cvtMethod); extern int convert_rgb565_to_rgb(const uint8_t *inBuf, uint8_t *outBuf, int imgWidth, int imgHeight, int cvtMethod); extern int convert_rgb888_to_rgb(const uint8_t *inBuf, uint8_t *outBuf, int imgWidth, int imgHeight, int cvtMethod); +extern int convert_ayuv32_to_nv12(const uint8_t *inBuf, uint8_t *outBuf, int imgWidth, int imgHeight); extern void update_videocvt_param(int distype, int scr_width, int scr_height, int scr_bpp, int scr_size); diff --git a/package/starfive/v4l2_test/v4l2_test.c b/package/starfive/v4l2_test/v4l2_test.c index 4b8363a0..759c6adb 100644 --- a/package/starfive/v4l2_test/v4l2_test.c +++ b/package/starfive/v4l2_test/v4l2_test.c @@ -379,6 +379,18 @@ static void imageProcess(const uint8_t* inbuf, uint8_t* outbuf, sprintf(filename, "raw-%d-BGGR16.raw", s_frmcnt); write_file(filename, (const uint8_t *)dst, in_width * in_height * 2); s_frmcnt++; + break; + case V4L2_PIX_FMT_AYUV32: + if (gp_cfg_param->jpegFilename && gp_cfg_param->rec_fp) { + fwrite(inbuf, in_imagesize, 1, gp_cfg_param->rec_fp); + } + + if (outbuf) { + if ((STF_DISP_DRM == disp_type) && (out_format == V4L2_PIX_FMT_NV12)) { + convert_ayuv32_to_nv12(inbuf, outbuf, in_width, in_height); + } + } + break; default: LOG(STF_LEVEL_ERR, "unknow in_format\n"); @@ -776,6 +788,7 @@ static void usage(FILE* fp, int argc, char** argv) " 8: V4L2_PIX_FMT_SGRBG12\n" " 9: V4L2_PIX_FMT_SGBRG12\n" " 10: V4L2_PIX_FMT_SBGGR12\n" + " 11: V4L2_PIX_FMT_AYUV32\n" " default: V4L2_PIX_FMT_NV12\n" "-t | --distype set display type, default 0\n" " 0: Not display\n" @@ -948,6 +961,9 @@ void parse_options(int argc, char **argv, ConfigParam_t *cfg_param) case 10: value = V4L2_PIX_FMT_SBGGR12; break; + case 11: + value = V4L2_PIX_FMT_AYUV32; + break; default: value = V4L2_PIX_FMT_RGB565; break;