Commit 30364c41 authored by Dafna Hirschfeld's avatar Dafna Hirschfeld Committed by Mauro Carvalho Chehab

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: default avatarDafna Hirschfeld <dafna3@gmail.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent a04a7a21
...@@ -75,117 +75,130 @@ const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx) ...@@ -75,117 +75,130 @@ const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx)
return v4l2_fwht_pixfmts + idx; return v4l2_fwht_pixfmts + idx;
} }
int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out) static int prepare_raw_frame(struct fwht_raw_frame *rf,
const struct v4l2_fwht_pixfmt_info *info, u8 *buf,
unsigned int size)
{ {
unsigned int size = state->stride * state->coded_height; rf->luma = buf;
unsigned int chroma_stride = state->stride; rf->width_div = info->width_div;
const struct v4l2_fwht_pixfmt_info *info = state->info; rf->height_div = info->height_div;
struct fwht_cframe_hdr *p_hdr; rf->luma_alpha_step = info->luma_alpha_step;
struct fwht_cframe cf; rf->chroma_step = info->chroma_step;
struct fwht_raw_frame rf; rf->alpha = NULL;
u32 encoding; rf->components_num = info->components_num;
u32 flags = 0;
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) { switch (info->id) {
case V4L2_PIX_FMT_GREY: case V4L2_PIX_FMT_GREY:
rf.cb = NULL; rf->cb = NULL;
rf.cr = NULL; rf->cr = NULL;
break; break;
case V4L2_PIX_FMT_YUV420: case V4L2_PIX_FMT_YUV420:
rf.cb = rf.luma + size; rf->cb = rf->luma + size;
rf.cr = rf.cb + size / 4; rf->cr = rf->cb + size / 4;
chroma_stride /= 2;
break; break;
case V4L2_PIX_FMT_YVU420: case V4L2_PIX_FMT_YVU420:
rf.cr = rf.luma + size; rf->cr = rf->luma + size;
rf.cb = rf.cr + size / 4; rf->cb = rf->cr + size / 4;
chroma_stride /= 2;
break; break;
case V4L2_PIX_FMT_YUV422P: case V4L2_PIX_FMT_YUV422P:
rf.cb = rf.luma + size; rf->cb = rf->luma + size;
rf.cr = rf.cb + size / 2; rf->cr = rf->cb + size / 2;
chroma_stride /= 2;
break; break;
case V4L2_PIX_FMT_NV12: case V4L2_PIX_FMT_NV12:
case V4L2_PIX_FMT_NV16: case V4L2_PIX_FMT_NV16:
case V4L2_PIX_FMT_NV24: case V4L2_PIX_FMT_NV24:
rf.cb = rf.luma + size; rf->cb = rf->luma + size;
rf.cr = rf.cb + 1; rf->cr = rf->cb + 1;
break; break;
case V4L2_PIX_FMT_NV21: case V4L2_PIX_FMT_NV21:
case V4L2_PIX_FMT_NV61: case V4L2_PIX_FMT_NV61:
case V4L2_PIX_FMT_NV42: case V4L2_PIX_FMT_NV42:
rf.cr = rf.luma + size; rf->cr = rf->luma + size;
rf.cb = rf.cr + 1; rf->cb = rf->cr + 1;
break; break;
case V4L2_PIX_FMT_YUYV: case V4L2_PIX_FMT_YUYV:
rf.cb = rf.luma + 1; rf->cb = rf->luma + 1;
rf.cr = rf.cb + 2; rf->cr = rf->cb + 2;
break; break;
case V4L2_PIX_FMT_YVYU: case V4L2_PIX_FMT_YVYU:
rf.cr = rf.luma + 1; rf->cr = rf->luma + 1;
rf.cb = rf.cr + 2; rf->cb = rf->cr + 2;
break; break;
case V4L2_PIX_FMT_UYVY: case V4L2_PIX_FMT_UYVY:
rf.cb = rf.luma; rf->cb = rf->luma;
rf.cr = rf.cb + 2; rf->cr = rf->cb + 2;
rf.luma++; rf->luma++;
break; break;
case V4L2_PIX_FMT_VYUY: case V4L2_PIX_FMT_VYUY:
rf.cr = rf.luma; rf->cr = rf->luma;
rf.cb = rf.cr + 2; rf->cb = rf->cr + 2;
rf.luma++; rf->luma++;
break; break;
case V4L2_PIX_FMT_RGB24: case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_HSV24: case V4L2_PIX_FMT_HSV24:
rf.cr = rf.luma; rf->cr = rf->luma;
rf.cb = rf.cr + 2; rf->cb = rf->cr + 2;
rf.luma++; rf->luma++;
break; break;
case V4L2_PIX_FMT_BGR24: case V4L2_PIX_FMT_BGR24:
rf.cb = rf.luma; rf->cb = rf->luma;
rf.cr = rf.cb + 2; rf->cr = rf->cb + 2;
rf.luma++; rf->luma++;
break; break;
case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_RGB32:
case V4L2_PIX_FMT_XRGB32: case V4L2_PIX_FMT_XRGB32:
case V4L2_PIX_FMT_HSV32: case V4L2_PIX_FMT_HSV32:
rf.cr = rf.luma + 1; rf->cr = rf->luma + 1;
rf.cb = rf.cr + 2; rf->cb = rf->cr + 2;
rf.luma += 2; rf->luma += 2;
break; break;
case V4L2_PIX_FMT_BGR32: case V4L2_PIX_FMT_BGR32:
case V4L2_PIX_FMT_XBGR32: case V4L2_PIX_FMT_XBGR32:
rf.cb = rf.luma; rf->cb = rf->luma;
rf.cr = rf.cb + 2; rf->cr = rf->cb + 2;
rf.luma++; rf->luma++;
break; break;
case V4L2_PIX_FMT_ARGB32: case V4L2_PIX_FMT_ARGB32:
rf.alpha = rf.luma; rf->alpha = rf->luma;
rf.cr = rf.luma + 1; rf->cr = rf->luma + 1;
rf.cb = rf.cr + 2; rf->cb = rf->cr + 2;
rf.luma += 2; rf->luma += 2;
break; break;
case V4L2_PIX_FMT_ABGR32: case V4L2_PIX_FMT_ABGR32:
rf.cb = rf.luma; rf->cb = rf->luma;
rf.cr = rf.cb + 2; rf->cr = rf->cb + 2;
rf.luma++; rf->luma++;
rf.alpha = rf.cr + 1; rf->alpha = rf->cr + 1;
break; break;
default: default:
return -EINVAL; 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;
unsigned int chroma_stride = state->stride;
const struct v4l2_fwht_pixfmt_info *info = state->info;
struct fwht_cframe_hdr *p_hdr;
struct fwht_cframe cf;
struct fwht_raw_frame rf;
u32 encoding;
u32 flags = 0;
if (!info)
return -EINVAL;
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.i_frame_qp = state->i_frame_qp;
cf.p_frame_qp = state->p_frame_qp; cf.p_frame_qp = state->p_frame_qp;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment