mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-05 17:16:50 +08:00
[utils]: Fix encoder width / stride mismatch
Fix the default width stride value in RGB format. Change-Id: I330bc81bfc5057484a46815d62eccd3fd212a49d Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
@@ -23,10 +23,48 @@
|
||||
|
||||
#include "rk_mpi.h"
|
||||
#include "utils.h"
|
||||
#include "mpp_common.h"
|
||||
#include "mpi_enc_utils.h"
|
||||
|
||||
#define MAX_FILE_NAME_LENGTH 256
|
||||
|
||||
RK_S32 mpi_enc_width_default_stride(RK_S32 width, MppFrameFormat fmt)
|
||||
{
|
||||
RK_S32 stride = 0;
|
||||
|
||||
switch (fmt) {
|
||||
case MPP_FMT_YUV420SP :
|
||||
case MPP_FMT_YUV420P : {
|
||||
stride = MPP_ALIGN(width, 16);
|
||||
} break;
|
||||
case MPP_FMT_YUV422P:
|
||||
case MPP_FMT_YUV422SP:
|
||||
case MPP_FMT_RGB565:
|
||||
case MPP_FMT_BGR565:
|
||||
case MPP_FMT_YUV422_YUYV :
|
||||
case MPP_FMT_YUV422_YVYU :
|
||||
case MPP_FMT_YUV422_UYVY :
|
||||
case MPP_FMT_YUV422_VYUY : {
|
||||
stride = MPP_ALIGN(width * 2, 16);
|
||||
} break;
|
||||
case MPP_FMT_RGB888 :
|
||||
case MPP_FMT_BGR888 : {
|
||||
stride = width * 3;
|
||||
} break;
|
||||
case MPP_FMT_ARGB8888 :
|
||||
case MPP_FMT_ABGR8888:
|
||||
case MPP_FMT_BGRA8888:
|
||||
case MPP_FMT_RGBA8888: {
|
||||
stride = width * 4;
|
||||
} break;
|
||||
default : {
|
||||
mpp_err_f("do not support type %d\n", fmt);
|
||||
} break;
|
||||
}
|
||||
|
||||
return stride;
|
||||
}
|
||||
|
||||
MpiEncTestArgs *mpi_enc_test_cmd_get(void)
|
||||
{
|
||||
MpiEncTestArgs *args = mpp_calloc(MpiEncTestArgs, 1);
|
||||
@@ -92,8 +130,6 @@ MPP_RET mpi_enc_test_cmd_update_by_args(MpiEncTestArgs* cmd, int argc, char **ar
|
||||
case 'w' : {
|
||||
if (next) {
|
||||
cmd->width = atoi(next);
|
||||
if (!cmd->hor_stride)
|
||||
cmd->hor_stride = cmd->width;
|
||||
} else {
|
||||
mpp_err("invalid input width\n");
|
||||
goto PARSE_OPINIONS_OUT;
|
||||
@@ -107,8 +143,6 @@ MPP_RET mpi_enc_test_cmd_update_by_args(MpiEncTestArgs* cmd, int argc, char **ar
|
||||
goto PARSE_OPINIONS_OUT;
|
||||
} else if (next) {
|
||||
cmd->height = atoi(next);
|
||||
if (!cmd->ver_stride)
|
||||
cmd->ver_stride = cmd->height;
|
||||
}
|
||||
} break;
|
||||
case 'u' : {
|
||||
@@ -256,6 +290,12 @@ MPP_RET mpi_enc_test_cmd_update_by_args(MpiEncTestArgs* cmd, int argc, char **ar
|
||||
mpp_err("invalid type %d\n", cmd->type);
|
||||
ret = MPP_NOK;
|
||||
}
|
||||
|
||||
if (!cmd->hor_stride)
|
||||
cmd->hor_stride = mpi_enc_width_default_stride(cmd->width, cmd->format);
|
||||
if (!cmd->ver_stride)
|
||||
cmd->ver_stride = cmd->height;
|
||||
|
||||
if (cmd->width <= 0 || cmd->height <= 0 ||
|
||||
cmd->hor_stride <= 0 || cmd->ver_stride <= 0) {
|
||||
mpp_err("invalid w:h [%d:%d] stride [%d:%d]\n",
|
||||
|
@@ -53,6 +53,8 @@ typedef struct MpiEncTestArgs_t {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
RK_S32 mpi_enc_width_default_stride(RK_S32 width, MppFrameFormat fmt);
|
||||
|
||||
MPP_RET mpi_enc_gen_ref_cfg(MppEncRefCfg ref);
|
||||
MPP_RET mpi_enc_gen_osd_data(MppEncOSDData *osd_data, MppBuffer osd_buf, RK_U32 frame_cnt);
|
||||
MPP_RET mpi_enc_gen_osd_plt(MppEncOSDPlt *osd_plt, RK_U32 *table);
|
||||
|
@@ -263,6 +263,33 @@ void read_frm_crc(FILE *fp, FrmCrc *crc)
|
||||
}
|
||||
}
|
||||
|
||||
static MPP_RET read_with_pixel_width(RK_U8 *buf, RK_S32 width, RK_S32 height,
|
||||
RK_S32 hor_stride, RK_S32 pix_w, FILE *fp)
|
||||
{
|
||||
RK_S32 row;
|
||||
MPP_RET ret = MPP_OK;
|
||||
|
||||
if (hor_stride < width * pix_w) {
|
||||
mpp_err_f("invalid %dbit color config: hor_stride %d is smaller then width %d multiply by 4\n",
|
||||
8 * pix_w, hor_stride, width, pix_w);
|
||||
mpp_err_f("width should be defined by pixel count\n");
|
||||
mpp_err_f("stride should be defined by byte count\n");
|
||||
|
||||
hor_stride = width * pix_w;
|
||||
}
|
||||
|
||||
for (row = 0; row < height; row++) {
|
||||
RK_S32 read_size = fread(buf + row * hor_stride, 1, width * pix_w, fp);
|
||||
if (read_size != width * pix_w) {
|
||||
mpp_err_f("read file failed expect %d vs %d\n",
|
||||
width * pix_w, read_size);
|
||||
ret = MPP_NOK;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -362,9 +389,7 @@ MPP_RET read_image(RK_U8 *buf, FILE *fp, RK_U32 width, RK_U32 height,
|
||||
case MPP_FMT_ABGR8888:
|
||||
case MPP_FMT_BGRA8888:
|
||||
case MPP_FMT_RGBA8888: {
|
||||
for (row = 0; row < height; row++) {
|
||||
read_size = fread(buf_y + row * hor_stride * 4, 1, width * 4, fp);
|
||||
}
|
||||
ret = read_with_pixel_width(buf_y, width, height, hor_stride, 4, fp);
|
||||
} break;
|
||||
case MPP_FMT_YUV422P:
|
||||
case MPP_FMT_YUV422SP:
|
||||
@@ -374,15 +399,11 @@ MPP_RET read_image(RK_U8 *buf, FILE *fp, RK_U32 width, RK_U32 height,
|
||||
case MPP_FMT_YUV422_YVYU :
|
||||
case MPP_FMT_YUV422_UYVY :
|
||||
case MPP_FMT_YUV422_VYUY : {
|
||||
for (row = 0; row < height; row++) {
|
||||
read_size = fread(buf_y + row * hor_stride * 2, 1, width * 2, fp);
|
||||
}
|
||||
ret = read_with_pixel_width(buf_y, width, height, hor_stride, 2, fp);
|
||||
} break;
|
||||
case MPP_FMT_RGB888 :
|
||||
case MPP_FMT_BGR888: {
|
||||
for (row = 0; row < height; row++) {
|
||||
read_size = fread(buf_y + row * hor_stride * 3, 1, width * 3, fp);
|
||||
}
|
||||
ret = read_with_pixel_width(buf_y, width, height, hor_stride, 3, fp);
|
||||
} break;
|
||||
default : {
|
||||
mpp_err_f("read image do not support fmt %d\n", fmt);
|
||||
@@ -462,7 +483,16 @@ MPP_RET fill_image(RK_U8 *buf, RK_U32 width, RK_U32 height,
|
||||
RK_U8 *p = buf_y;
|
||||
RK_U32 pix_w = 3;
|
||||
|
||||
for (y = 0; y < height; y++, p += hor_stride * pix_w) {
|
||||
if (hor_stride < width * pix_w) {
|
||||
mpp_err_f("invalid %dbit color config: hor_stride %d is smaller then width %d multiply by 4\n",
|
||||
8 * pix_w, hor_stride, width, pix_w);
|
||||
mpp_err_f("width should be defined by pixel count\n");
|
||||
mpp_err_f("stride should be defined by byte count\n");
|
||||
|
||||
hor_stride = width * pix_w;
|
||||
}
|
||||
|
||||
for (y = 0; y < height; y++, p += hor_stride) {
|
||||
for (x = 0, i = 0; x < width * pix_w; x += pix_w, i++) {
|
||||
p[x + 0] = i + y + frame_count * 3;
|
||||
p[x + 1] = 128 + i + frame_count * 2;
|
||||
@@ -477,7 +507,16 @@ MPP_RET fill_image(RK_U8 *buf, RK_U32 width, RK_U32 height,
|
||||
RK_U8 *p = buf_y;
|
||||
RK_U32 pix_w = 4;
|
||||
|
||||
for (y = 0; y < height; y++, p += hor_stride * pix_w) {
|
||||
if (hor_stride < width * pix_w) {
|
||||
mpp_err_f("invalid %dbit color config: hor_stride %d is smaller then width %d multiply by 4\n",
|
||||
8 * pix_w, hor_stride, width, pix_w);
|
||||
mpp_err_f("width should be defined by pixel count\n");
|
||||
mpp_err_f("stride should be defined by byte count\n");
|
||||
|
||||
hor_stride = width * pix_w;
|
||||
}
|
||||
|
||||
for (y = 0; y < height; y++, p += hor_stride) {
|
||||
for (x = 0, i = 0; x < width * pix_w; x += pix_w, i++) {
|
||||
p[x + 0] = i + y + frame_count * 3;
|
||||
p[x + 1] = 128 + i + frame_count * 2;
|
||||
|
Reference in New Issue
Block a user