media: vicodec: Move raw frame preparation code to a function

Introduce 'prepare_raw_frame' function that fills the values
of a raw frame struct according to the format.

Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
This commit is contained in:
Dafna Hirschfeld 2019-03-06 16:13:30 -05:00 committed by Mauro Carvalho Chehab
parent a04a7a2108
commit 30364c41bd
1 changed files with 109 additions and 96 deletions

View File

@ -75,6 +75,107 @@ const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx)
return v4l2_fwht_pixfmts + idx;
}
static int prepare_raw_frame(struct fwht_raw_frame *rf,
const struct v4l2_fwht_pixfmt_info *info, u8 *buf,
unsigned int size)
{
rf->luma = buf;
rf->width_div = info->width_div;
rf->height_div = info->height_div;
rf->luma_alpha_step = info->luma_alpha_step;
rf->chroma_step = info->chroma_step;
rf->alpha = NULL;
rf->components_num = info->components_num;
switch (info->id) {
case V4L2_PIX_FMT_GREY:
rf->cb = NULL;
rf->cr = NULL;
break;
case V4L2_PIX_FMT_YUV420:
rf->cb = rf->luma + size;
rf->cr = rf->cb + size / 4;
break;
case V4L2_PIX_FMT_YVU420:
rf->cr = rf->luma + size;
rf->cb = rf->cr + size / 4;
break;
case V4L2_PIX_FMT_YUV422P:
rf->cb = rf->luma + size;
rf->cr = rf->cb + size / 2;
break;
case V4L2_PIX_FMT_NV12:
case V4L2_PIX_FMT_NV16:
case V4L2_PIX_FMT_NV24:
rf->cb = rf->luma + size;
rf->cr = rf->cb + 1;
break;
case V4L2_PIX_FMT_NV21:
case V4L2_PIX_FMT_NV61:
case V4L2_PIX_FMT_NV42:
rf->cr = rf->luma + size;
rf->cb = rf->cr + 1;
break;
case V4L2_PIX_FMT_YUYV:
rf->cb = rf->luma + 1;
rf->cr = rf->cb + 2;
break;
case V4L2_PIX_FMT_YVYU:
rf->cr = rf->luma + 1;
rf->cb = rf->cr + 2;
break;
case V4L2_PIX_FMT_UYVY:
rf->cb = rf->luma;
rf->cr = rf->cb + 2;
rf->luma++;
break;
case V4L2_PIX_FMT_VYUY:
rf->cr = rf->luma;
rf->cb = rf->cr + 2;
rf->luma++;
break;
case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_HSV24:
rf->cr = rf->luma;
rf->cb = rf->cr + 2;
rf->luma++;
break;
case V4L2_PIX_FMT_BGR24:
rf->cb = rf->luma;
rf->cr = rf->cb + 2;
rf->luma++;
break;
case V4L2_PIX_FMT_RGB32:
case V4L2_PIX_FMT_XRGB32:
case V4L2_PIX_FMT_HSV32:
rf->cr = rf->luma + 1;
rf->cb = rf->cr + 2;
rf->luma += 2;
break;
case V4L2_PIX_FMT_BGR32:
case V4L2_PIX_FMT_XBGR32:
rf->cb = rf->luma;
rf->cr = rf->cb + 2;
rf->luma++;
break;
case V4L2_PIX_FMT_ARGB32:
rf->alpha = rf->luma;
rf->cr = rf->luma + 1;
rf->cb = rf->cr + 2;
rf->luma += 2;
break;
case V4L2_PIX_FMT_ABGR32:
rf->cb = rf->luma;
rf->cr = rf->cb + 2;
rf->luma++;
rf->alpha = rf->cr + 1;
break;
default:
return -EINVAL;
}
return 0;
}
int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
{
unsigned int size = state->stride * state->coded_height;
@ -89,103 +190,15 @@ int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
if (!info)
return -EINVAL;
rf.luma = p_in;
rf.width_div = info->width_div;
rf.height_div = info->height_div;
rf.luma_alpha_step = info->luma_alpha_step;
rf.chroma_step = info->chroma_step;
rf.alpha = NULL;
rf.components_num = info->components_num;
switch (info->id) {
case V4L2_PIX_FMT_GREY:
rf.cb = NULL;
rf.cr = NULL;
break;
case V4L2_PIX_FMT_YUV420:
rf.cb = rf.luma + size;
rf.cr = rf.cb + size / 4;
chroma_stride /= 2;
break;
case V4L2_PIX_FMT_YVU420:
rf.cr = rf.luma + size;
rf.cb = rf.cr + size / 4;
chroma_stride /= 2;
break;
case V4L2_PIX_FMT_YUV422P:
rf.cb = rf.luma + size;
rf.cr = rf.cb + size / 2;
chroma_stride /= 2;
break;
case V4L2_PIX_FMT_NV12:
case V4L2_PIX_FMT_NV16:
case V4L2_PIX_FMT_NV24:
rf.cb = rf.luma + size;
rf.cr = rf.cb + 1;
break;
case V4L2_PIX_FMT_NV21:
case V4L2_PIX_FMT_NV61:
case V4L2_PIX_FMT_NV42:
rf.cr = rf.luma + size;
rf.cb = rf.cr + 1;
break;
case V4L2_PIX_FMT_YUYV:
rf.cb = rf.luma + 1;
rf.cr = rf.cb + 2;
break;
case V4L2_PIX_FMT_YVYU:
rf.cr = rf.luma + 1;
rf.cb = rf.cr + 2;
break;
case V4L2_PIX_FMT_UYVY:
rf.cb = rf.luma;
rf.cr = rf.cb + 2;
rf.luma++;
break;
case V4L2_PIX_FMT_VYUY:
rf.cr = rf.luma;
rf.cb = rf.cr + 2;
rf.luma++;
break;
case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_HSV24:
rf.cr = rf.luma;
rf.cb = rf.cr + 2;
rf.luma++;
break;
case V4L2_PIX_FMT_BGR24:
rf.cb = rf.luma;
rf.cr = rf.cb + 2;
rf.luma++;
break;
case V4L2_PIX_FMT_RGB32:
case V4L2_PIX_FMT_XRGB32:
case V4L2_PIX_FMT_HSV32:
rf.cr = rf.luma + 1;
rf.cb = rf.cr + 2;
rf.luma += 2;
break;
case V4L2_PIX_FMT_BGR32:
case V4L2_PIX_FMT_XBGR32:
rf.cb = rf.luma;
rf.cr = rf.cb + 2;
rf.luma++;
break;
case V4L2_PIX_FMT_ARGB32:
rf.alpha = rf.luma;
rf.cr = rf.luma + 1;
rf.cb = rf.cr + 2;
rf.luma += 2;
break;
case V4L2_PIX_FMT_ABGR32:
rf.cb = rf.luma;
rf.cr = rf.cb + 2;
rf.luma++;
rf.alpha = rf.cr + 1;
break;
default:
if (prepare_raw_frame(&rf, info, p_in, size))
return -EINVAL;
}
if (info->planes_num == 3)
chroma_stride /= 2;
if (info->id == V4L2_PIX_FMT_NV24 ||
info->id == V4L2_PIX_FMT_NV42)
chroma_stride *= 2;
cf.i_frame_qp = state->i_frame_qp;
cf.p_frame_qp = state->p_frame_qp;