[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 <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2019-03-19 15:54:27 +08:00
parent 6748990389
commit 459eace205
8 changed files with 88 additions and 30 deletions

View File

@@ -196,6 +196,7 @@ MPP_RET mpp_destroy(MppCtx ctx);
// coding type format function // coding type format function
MPP_RET mpp_check_support_format(MppCtxType type, MppCodingType coding); MPP_RET mpp_check_support_format(MppCtxType type, MppCodingType coding);
void mpp_show_support_format(void); void mpp_show_support_format(void);
void mpp_show_color_format(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -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);
}
}

View File

@@ -225,15 +225,15 @@ int main(int argc, char **argv)
ptr = mpp_buffer_get_ptr(src_buf); ptr = mpp_buffer_get_ptr(src_buf);
if (cmd.have_input) { if (cmd.have_input) {
ret = read_yuv_image((RK_U8 *)ptr, fin, cmd.src_w, cmd.src_h, ret = read_image((RK_U8 *)ptr, fin, cmd.src_w, cmd.src_h,
cmd.src_w, cmd.src_h, cmd.dst_fmt); cmd.src_w, cmd.src_h, cmd.dst_fmt);
if (ret) { if (ret) {
mpp_err("failed to read input file ret:%d\n", ret); mpp_err("failed to read input file ret:%d\n", ret);
goto END; goto END;
} }
} else { } else {
ret = fill_yuv_image((RK_U8 *)ptr, cmd.src_w, cmd.src_h, ret = fill_image((RK_U8 *)ptr, cmd.src_w, cmd.src_h,
cmd.src_w, cmd.src_h, cmd.src_fmt, frame_count); cmd.src_w, cmd.src_h, cmd.src_fmt, frame_count);
if (ret) { if (ret) {
mpp_err("failed to fill input buffer ret:%d\n", ret); mpp_err("failed to fill input buffer ret:%d\n", ret);
goto END; goto END;

View File

@@ -618,16 +618,16 @@ MPP_RET test_mpp_run(MpiEncTestData *p)
i = 0; i = 0;
if (p->fp_input) { if (p->fp_input) {
ret = read_yuv_image(buf, p->fp_input, p->width, p->height, ret = read_image(buf, p->fp_input, p->width, p->height,
p->hor_stride, p->ver_stride, p->fmt); p->hor_stride, p->ver_stride, p->fmt);
if (ret == MPP_NOK || feof(p->fp_input)) { if (ret == MPP_NOK || feof(p->fp_input)) {
mpp_log("found last frame. feof %d\n", feof(p->fp_input)); mpp_log("found last frame. feof %d\n", feof(p->fp_input));
p->frm_eos = 1; p->frm_eos = 1;
} else if (ret == MPP_ERR_VALUE) } else if (ret == MPP_ERR_VALUE)
goto RET; goto RET;
} else { } else {
ret = fill_yuv_image(buf, p->width, p->height, p->hor_stride, ret = fill_image(buf, p->width, p->height, p->hor_stride,
p->ver_stride, p->fmt, p->frame_count); p->ver_stride, p->fmt, p->frame_count);
if (ret) if (ret)
goto RET; goto RET;
} }

View File

@@ -362,16 +362,16 @@ MPP_RET test_mpp_run(MpiEncTestData *p)
void *buf = mpp_buffer_get_ptr(p->frm_buf); void *buf = mpp_buffer_get_ptr(p->frm_buf);
if (p->fp_input) { if (p->fp_input) {
ret = read_yuv_image(buf, p->fp_input, p->width, p->height, ret = read_image(buf, p->fp_input, p->width, p->height,
p->hor_stride, p->ver_stride, p->fmt); p->hor_stride, p->ver_stride, p->fmt);
if (ret == MPP_NOK || feof(p->fp_input)) { if (ret == MPP_NOK || feof(p->fp_input)) {
mpp_log("found last frame. feof %d\n", feof(p->fp_input)); mpp_log("found last frame. feof %d\n", feof(p->fp_input));
p->frm_eos = 1; p->frm_eos = 1;
} else if (ret == MPP_ERR_VALUE) } else if (ret == MPP_ERR_VALUE)
goto RET; goto RET;
} else { } else {
ret = fill_yuv_image(buf, p->width, p->height, p->hor_stride, ret = fill_image(buf, p->width, p->height, p->hor_stride,
p->ver_stride, p->fmt, p->frame_count); p->ver_stride, p->fmt, p->frame_count);
if (ret) if (ret)
goto RET; goto RET;
} }
@@ -529,6 +529,7 @@ static void mpi_enc_test_help()
mpp_log("usage: mpi_enc_test [options]\n"); mpp_log("usage: mpi_enc_test [options]\n");
show_options(mpi_enc_cmd); show_options(mpi_enc_cmd);
mpp_show_support_format(); mpp_show_support_format();
mpp_show_color_format();
} }
static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, MpiEncTestCmd* cmd) static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, MpiEncTestCmd* cmd)

View File

@@ -713,18 +713,18 @@ static MPP_RET mpi_rc_codec(MpiRcTestCtx *ctx)
i = 0; i = 0;
if (fp_input) { if (fp_input) {
ret = read_yuv_image(buf, fp_input, ret = read_image(buf, fp_input,
prep_cfg->width, prep_cfg->height, prep_cfg->width, prep_cfg->height,
prep_cfg->hor_stride, prep_cfg->ver_stride, prep_cfg->hor_stride, prep_cfg->ver_stride,
prep_cfg->format); prep_cfg->format);
if (MPP_OK != ret || feof(fp_input)) { if (MPP_OK != ret || feof(fp_input)) {
mpp_log("found last frame\n"); mpp_log("found last frame\n");
frm_eos = 1; frm_eos = 1;
} }
} else { } else {
ret = fill_yuv_image(buf, prep_cfg->width, prep_cfg->height, ret = fill_image(buf, prep_cfg->width, prep_cfg->height,
prep_cfg->hor_stride, prep_cfg->ver_stride, prep_cfg->hor_stride, prep_cfg->ver_stride,
prep_cfg->format, frame_count); prep_cfg->format, frame_count);
if (ret) if (ret)
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }

View File

@@ -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, 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) RK_U32 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt)
{ {
MPP_RET ret = MPP_OK; MPP_RET ret = MPP_OK;
RK_U32 read_size; RK_U32 read_size;
@@ -341,9 +341,9 @@ err:
return ret; return ret;
} }
MPP_RET fill_yuv_image(RK_U8 *buf, RK_U32 width, RK_U32 height, 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 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt,
RK_U32 frame_count) RK_U32 frame_count)
{ {
MPP_RET ret = MPP_OK; MPP_RET ret = MPP_OK;
RK_U8 *buf_y = buf; RK_U8 *buf_y = buf;
@@ -403,6 +403,21 @@ MPP_RET fill_yuv_image(RK_U8 *buf, RK_U32 width, RK_U32 height,
} }
} }
} break; } 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 : { default : {
mpp_err_f("filling function do not support type %d\n", fmt); mpp_err_f("filling function do not support type %d\n", fmt);
ret = MPP_NOK; ret = MPP_NOK;

View File

@@ -59,12 +59,12 @@ void calc_frm_crc(MppFrame frame, FrmCrc *crc);
void write_frm_crc(FILE *fp, FrmCrc *crc); void write_frm_crc(FILE *fp, FrmCrc *crc);
void read_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, MPP_RET read_image(RK_U8 *buf, FILE *fp, RK_U32 width, RK_U32 height,
RK_U32 hor_stride, RK_U32 ver_stride, RK_U32 hor_stride, RK_U32 ver_stride,
MppFrameFormat fmt); MppFrameFormat fmt);
MPP_RET fill_yuv_image(RK_U8 *buf, RK_U32 width, RK_U32 height, 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 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt,
RK_U32 frame_count); RK_U32 frame_count);
typedef struct OpsLine_t { typedef struct OpsLine_t {
RK_U32 index; RK_U32 index;