From 459eace2054e1f3557e5fcaaff1bd2fc3a20271a Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Tue, 19 Mar 2019 15:54:27 +0800 Subject: [PATCH] [mpp_frame]: Add color format print 1. Add color format print for all supported format. 2. Add RGB color fill function. Change-Id: I79fb3f40402b6fb6e36883c99945e709723aee7d Signed-off-by: Herman Chen --- inc/rk_mpi.h | 1 + mpp/mpi.cpp | 41 +++++++++++++++++++++++++++++++++ mpp/vproc/rga/test/rga_test.cpp | 8 +++---- test/mpi_enc_multi_test.c | 8 +++---- test/mpi_enc_test.c | 9 ++++---- test/mpi_rc_test.c | 14 +++++------ utils/utils.c | 25 ++++++++++++++++---- utils/utils.h | 12 +++++----- 8 files changed, 88 insertions(+), 30 deletions(-) diff --git a/inc/rk_mpi.h b/inc/rk_mpi.h index 22c1fcf4..43f6c51e 100644 --- a/inc/rk_mpi.h +++ b/inc/rk_mpi.h @@ -196,6 +196,7 @@ MPP_RET mpp_destroy(MppCtx ctx); // coding type format function MPP_RET mpp_check_support_format(MppCtxType type, MppCodingType coding); void mpp_show_support_format(void); +void mpp_show_color_format(void); #ifdef __cplusplus } diff --git a/mpp/mpi.cpp b/mpp/mpi.cpp index 4b3b694b..df698622 100644 --- a/mpp/mpi.cpp +++ b/mpp/mpi.cpp @@ -547,3 +547,44 @@ void mpp_show_support_format() } } +typedef struct { + MppFrameFormat format; + const char *name; +} MppFrameFormatInfo; + +static MppFrameFormatInfo color_list[] = { + { MPP_FMT_YUV420SP, "YUV420SP, NV12" }, + { MPP_FMT_YUV420SP_10BIT, "YUV420SP-10bit" }, + { MPP_FMT_YUV422SP, "YUV422SP, NV24" }, + { MPP_FMT_YUV422SP_10BIT, "YUV422SP-10bit" }, + { MPP_FMT_YUV420P, "YUV420P, I420" }, + { MPP_FMT_YUV420SP_VU, "YUV420SP, NV21" }, + { MPP_FMT_YUV422P, "YUV422P, 422P" }, + { MPP_FMT_YUV422SP_VU, "YUV422SP, NV42" }, + { MPP_FMT_YUV422_YUYV, "YUV422-YUYV, YUY2" }, + { MPP_FMT_YUV422_UYVY, "YUV422-UYVY, UYVY" }, + { MPP_FMT_YUV400, "YUV400-Y8, Y800" }, + + { MPP_FMT_RGB565, "RGB565" }, + { MPP_FMT_BGR565, "BGR565" }, + { MPP_FMT_RGB555, "RGB555" }, + { MPP_FMT_BGR555, "BGR555" }, + { MPP_FMT_RGB888, "RGB888" }, + { MPP_FMT_BGR888, "BGR888" }, + + { MPP_FMT_ARGB8888, "ARGB8888" }, + { MPP_FMT_ABGR8888, "ABGR8888" }, +}; + +void mpp_show_color_format() +{ + RK_U32 i = 0; + + mpp_log("mpp color support list:"); + + for (i = 0; i < MPP_ARRAY_ELEMS(color_list); i++) { + MppFrameFormatInfo *info = &color_list[i]; + mpp_log("color: id %-5d 0x%05x %s\n", + info->format, info->format, info->name); + } +} diff --git a/mpp/vproc/rga/test/rga_test.cpp b/mpp/vproc/rga/test/rga_test.cpp index ab570eaa..5c17bf7a 100644 --- a/mpp/vproc/rga/test/rga_test.cpp +++ b/mpp/vproc/rga/test/rga_test.cpp @@ -225,15 +225,15 @@ int main(int argc, char **argv) ptr = mpp_buffer_get_ptr(src_buf); if (cmd.have_input) { - ret = read_yuv_image((RK_U8 *)ptr, fin, cmd.src_w, cmd.src_h, - cmd.src_w, cmd.src_h, cmd.dst_fmt); + ret = read_image((RK_U8 *)ptr, fin, cmd.src_w, cmd.src_h, + cmd.src_w, cmd.src_h, cmd.dst_fmt); if (ret) { mpp_err("failed to read input file ret:%d\n", ret); goto END; } } else { - ret = fill_yuv_image((RK_U8 *)ptr, cmd.src_w, cmd.src_h, - cmd.src_w, cmd.src_h, cmd.src_fmt, frame_count); + ret = fill_image((RK_U8 *)ptr, cmd.src_w, cmd.src_h, + cmd.src_w, cmd.src_h, cmd.src_fmt, frame_count); if (ret) { mpp_err("failed to fill input buffer ret:%d\n", ret); goto END; diff --git a/test/mpi_enc_multi_test.c b/test/mpi_enc_multi_test.c index 9b1a29b5..075a87dd 100644 --- a/test/mpi_enc_multi_test.c +++ b/test/mpi_enc_multi_test.c @@ -618,16 +618,16 @@ MPP_RET test_mpp_run(MpiEncTestData *p) i = 0; if (p->fp_input) { - ret = read_yuv_image(buf, p->fp_input, p->width, p->height, - p->hor_stride, p->ver_stride, p->fmt); + ret = read_image(buf, p->fp_input, p->width, p->height, + p->hor_stride, p->ver_stride, p->fmt); if (ret == MPP_NOK || feof(p->fp_input)) { mpp_log("found last frame. feof %d\n", feof(p->fp_input)); p->frm_eos = 1; } else if (ret == MPP_ERR_VALUE) goto RET; } else { - ret = fill_yuv_image(buf, p->width, p->height, p->hor_stride, - p->ver_stride, p->fmt, p->frame_count); + ret = fill_image(buf, p->width, p->height, p->hor_stride, + p->ver_stride, p->fmt, p->frame_count); if (ret) goto RET; } diff --git a/test/mpi_enc_test.c b/test/mpi_enc_test.c index dbc2e9c2..3f232870 100644 --- a/test/mpi_enc_test.c +++ b/test/mpi_enc_test.c @@ -362,16 +362,16 @@ MPP_RET test_mpp_run(MpiEncTestData *p) void *buf = mpp_buffer_get_ptr(p->frm_buf); if (p->fp_input) { - ret = read_yuv_image(buf, p->fp_input, p->width, p->height, - p->hor_stride, p->ver_stride, p->fmt); + ret = read_image(buf, p->fp_input, p->width, p->height, + p->hor_stride, p->ver_stride, p->fmt); if (ret == MPP_NOK || feof(p->fp_input)) { mpp_log("found last frame. feof %d\n", feof(p->fp_input)); p->frm_eos = 1; } else if (ret == MPP_ERR_VALUE) goto RET; } else { - ret = fill_yuv_image(buf, p->width, p->height, p->hor_stride, - p->ver_stride, p->fmt, p->frame_count); + ret = fill_image(buf, p->width, p->height, p->hor_stride, + p->ver_stride, p->fmt, p->frame_count); if (ret) goto RET; } @@ -529,6 +529,7 @@ static void mpi_enc_test_help() mpp_log("usage: mpi_enc_test [options]\n"); show_options(mpi_enc_cmd); mpp_show_support_format(); + mpp_show_color_format(); } static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, MpiEncTestCmd* cmd) diff --git a/test/mpi_rc_test.c b/test/mpi_rc_test.c index 54f74194..e45f65ed 100644 --- a/test/mpi_rc_test.c +++ b/test/mpi_rc_test.c @@ -713,18 +713,18 @@ static MPP_RET mpi_rc_codec(MpiRcTestCtx *ctx) i = 0; if (fp_input) { - ret = read_yuv_image(buf, fp_input, - prep_cfg->width, prep_cfg->height, - prep_cfg->hor_stride, prep_cfg->ver_stride, - prep_cfg->format); + ret = read_image(buf, fp_input, + prep_cfg->width, prep_cfg->height, + prep_cfg->hor_stride, prep_cfg->ver_stride, + prep_cfg->format); if (MPP_OK != ret || feof(fp_input)) { mpp_log("found last frame\n"); frm_eos = 1; } } else { - ret = fill_yuv_image(buf, prep_cfg->width, prep_cfg->height, - prep_cfg->hor_stride, prep_cfg->ver_stride, - prep_cfg->format, frame_count); + ret = fill_image(buf, prep_cfg->width, prep_cfg->height, + prep_cfg->hor_stride, prep_cfg->ver_stride, + prep_cfg->format, frame_count); if (ret) goto MPP_TEST_OUT; } diff --git a/utils/utils.c b/utils/utils.c index a4c33054..bf5c4bc9 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -261,8 +261,8 @@ void read_frm_crc(FILE *fp, FrmCrc *crc) } } -MPP_RET read_yuv_image(RK_U8 *buf, FILE *fp, RK_U32 width, RK_U32 height, - RK_U32 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt) +MPP_RET read_image(RK_U8 *buf, FILE *fp, RK_U32 width, RK_U32 height, + RK_U32 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt) { MPP_RET ret = MPP_OK; RK_U32 read_size; @@ -341,9 +341,9 @@ err: return ret; } -MPP_RET fill_yuv_image(RK_U8 *buf, RK_U32 width, RK_U32 height, - RK_U32 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt, - RK_U32 frame_count) +MPP_RET fill_image(RK_U8 *buf, RK_U32 width, RK_U32 height, + RK_U32 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt, + RK_U32 frame_count) { MPP_RET ret = MPP_OK; RK_U8 *buf_y = buf; @@ -403,6 +403,21 @@ MPP_RET fill_yuv_image(RK_U8 *buf, RK_U32 width, RK_U32 height, } } } break; + case MPP_FMT_RGB888 : + case MPP_FMT_BGR888 : + case MPP_FMT_ARGB8888 : { + RK_U8 *p = buf_y; + RK_U32 pix_w = (fmt == MPP_FMT_ARGB8888 || fmt == MPP_FMT_ABGR8888) ? 4 : 4; + + for (y = 0; y < height; y++, p += hor_stride * pix_w) { + for (x = 0; x < width; x++) { + p[x * 4 + 0] = x * 3 + 0 + y + frame_count * 3; + p[x * 4 + 1] = x * 3 + 1 + y + frame_count * 3; + p[x * 4 + 2] = x * 3 + 2 + y + frame_count * 3; + p[x * 4 + 3] = 0; + } + } + } break; default : { mpp_err_f("filling function do not support type %d\n", fmt); ret = MPP_NOK; diff --git a/utils/utils.h b/utils/utils.h index 98bc5c9c..8331250e 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -59,12 +59,12 @@ void calc_frm_crc(MppFrame frame, FrmCrc *crc); void write_frm_crc(FILE *fp, FrmCrc *crc); void read_frm_crc(FILE *fp, FrmCrc *crc); -MPP_RET read_yuv_image(RK_U8 *buf, FILE *fp, RK_U32 width, RK_U32 height, - RK_U32 hor_stride, RK_U32 ver_stride, - MppFrameFormat fmt); -MPP_RET fill_yuv_image(RK_U8 *buf, RK_U32 width, RK_U32 height, - RK_U32 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt, - RK_U32 frame_count); +MPP_RET read_image(RK_U8 *buf, FILE *fp, RK_U32 width, RK_U32 height, + RK_U32 hor_stride, RK_U32 ver_stride, + MppFrameFormat fmt); +MPP_RET fill_image(RK_U8 *buf, RK_U32 width, RK_U32 height, + RK_U32 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt, + RK_U32 frame_count); typedef struct OpsLine_t { RK_U32 index;