Commit 5fbd0729 authored by Dafna Hirschfeld's avatar Dafna Hirschfeld Committed by Mauro Carvalho Chehab

media: vicodec: Add pixel encoding flags to fwht header

Add flags indicating the pixel encoding - yuv/rgb/hsv to
fwht header and to the pixel info. Use it to enumerate
the supported pixel formats.
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 7248d1ff
...@@ -81,6 +81,12 @@ ...@@ -81,6 +81,12 @@
#define FWHT_FL_COMPONENTS_NUM_MSK GENMASK(18, 16) #define FWHT_FL_COMPONENTS_NUM_MSK GENMASK(18, 16)
#define FWHT_FL_COMPONENTS_NUM_OFFSET 16 #define FWHT_FL_COMPONENTS_NUM_OFFSET 16
#define FWHT_FL_PIXENC_MSK GENMASK(20, 19)
#define FWHT_FL_PIXENC_OFFSET 19
#define FWHT_FL_PIXENC_YUV (1 << FWHT_FL_PIXENC_OFFSET)
#define FWHT_FL_PIXENC_RGB (2 << FWHT_FL_PIXENC_OFFSET)
#define FWHT_FL_PIXENC_HSV (3 << FWHT_FL_PIXENC_OFFSET)
/* /*
* A macro to calculate the needed padding in order to make sure * A macro to calculate the needed padding in order to make sure
* both luma and chroma components resolutions are rounded up to * both luma and chroma components resolutions are rounded up to
......
...@@ -11,32 +11,53 @@ ...@@ -11,32 +11,53 @@
#include "codec-v4l2-fwht.h" #include "codec-v4l2-fwht.h"
static const struct v4l2_fwht_pixfmt_info v4l2_fwht_pixfmts[] = { static const struct v4l2_fwht_pixfmt_info v4l2_fwht_pixfmts[] = {
{ V4L2_PIX_FMT_YUV420, 1, 3, 2, 1, 1, 2, 2, 3, 3}, { V4L2_PIX_FMT_YUV420, 1, 3, 2, 1, 1, 2, 2, 3, 3, FWHT_FL_PIXENC_YUV},
{ V4L2_PIX_FMT_YVU420, 1, 3, 2, 1, 1, 2, 2, 3, 3}, { V4L2_PIX_F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 4, 1, 1, 3, 1, FWHT_FL_PIXENC_RGB},
{ V4L2_PIX_FMT_HSV32, 4, 4, 1, 4, 4, 1, 1, 3, 1}, { V4L2_PIX_FMT_HSV32, 4, 4, 1, 4, 4, 1, 1, 3, 1, FWHT_FL_PIXENC_HSV},
{ V4L2_PIX_FMT_ARGB32, 4, 4, 1, 4, 4, 1, 1, 4, 1}, { V4L2_PIX_FMT_ARGB32, 4, 4, 1, 4, 4, 1, 1, 4, 1, FWHT_FL_PIXENC_RGB},
{ V4L2_PIX_FMT_ABGR32, 4, 4, 1, 4, 4, 1, 1, 4, 1}, { V4L2_PIX_FMT_ABGR32, 4, 4, 1, 4, 4, 1, 1, 4, 1, FWHT_FL_PIXENC_RGB},
{ V4L2_PIX_FMT_GREY, 1, 1, 1, 1, 0, 1, 1, 1, 1}, { V4L2_PIX_FMT_GREY, 1, 1, 1, 1, 0, 1, 1, 1, 1, FWHT_FL_PIXENC_RGB},
}; };
const struct v4l2_fwht_pixfmt_info *v4l2_fwht_default_fmt(u32 width_div,
u32 height_div,
u32 components_num,
u32 pixenc,
unsigned int start_idx)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(v4l2_fwht_pixfmts); i++) {
if (v4l2_fwht_pixfmts[i].width_div == width_div &&
v4l2_fwht_pixfmts[i].height_div == height_div &&
(!pixenc || v4l2_fwht_pixfmts[i].pixenc == pixenc) &&
v4l2_fwht_pixfmts[i].components_num == components_num) {
if (start_idx == 0)
return v4l2_fwht_pixfmts + i;
start_idx--;
}
}
return NULL;
}
const struct v4l2_fwht_pixfmt_info *v4l2_fwht_find_pixfmt(u32 pixelformat) const struct v4l2_fwht_pixfmt_info *v4l2_fwht_find_pixfmt(u32 pixelformat)
{ {
unsigned int i; unsigned int i;
...@@ -188,6 +209,7 @@ int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out) ...@@ -188,6 +209,7 @@ int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
p_hdr->width = htonl(state->visible_width); p_hdr->width = htonl(state->visible_width);
p_hdr->height = htonl(state->visible_height); p_hdr->height = htonl(state->visible_height);
flags |= (info->components_num - 1) << FWHT_FL_COMPONENTS_NUM_OFFSET; flags |= (info->components_num - 1) << FWHT_FL_COMPONENTS_NUM_OFFSET;
flags |= info->pixenc;
if (encoding & FWHT_LUMA_UNENCODED) if (encoding & FWHT_LUMA_UNENCODED)
flags |= FWHT_FL_LUMA_IS_UNCOMPRESSED; flags |= FWHT_FL_LUMA_IS_UNCOMPRESSED;
if (encoding & FWHT_CB_UNENCODED) if (encoding & FWHT_CB_UNENCODED)
...@@ -246,10 +268,15 @@ int v4l2_fwht_decode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out) ...@@ -246,10 +268,15 @@ int v4l2_fwht_decode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
flags = ntohl(p_hdr->flags); flags = ntohl(p_hdr->flags);
if (version == FWHT_VERSION) { if (version == FWHT_VERSION) {
if ((flags & FWHT_FL_PIXENC_MSK) != info->pixenc)
return -EINVAL;
components_num = 1 + ((flags & FWHT_FL_COMPONENTS_NUM_MSK) >> components_num = 1 + ((flags & FWHT_FL_COMPONENTS_NUM_MSK) >>
FWHT_FL_COMPONENTS_NUM_OFFSET); FWHT_FL_COMPONENTS_NUM_OFFSET);
} }
if (components_num != info->components_num)
return -EINVAL;
state->colorspace = ntohl(p_hdr->colorspace); state->colorspace = ntohl(p_hdr->colorspace);
state->xfer_func = ntohl(p_hdr->xfer_func); state->xfer_func = ntohl(p_hdr->xfer_func);
state->ycbcr_enc = ntohl(p_hdr->ycbcr_enc); state->ycbcr_enc = ntohl(p_hdr->ycbcr_enc);
......
...@@ -20,6 +20,7 @@ struct v4l2_fwht_pixfmt_info { ...@@ -20,6 +20,7 @@ struct v4l2_fwht_pixfmt_info {
unsigned int height_div; unsigned int height_div;
unsigned int components_num; unsigned int components_num;
unsigned int planes_num; unsigned int planes_num;
unsigned int pixenc;
}; };
struct v4l2_fwht_state { struct v4l2_fwht_state {
...@@ -45,6 +46,11 @@ struct v4l2_fwht_state { ...@@ -45,6 +46,11 @@ struct v4l2_fwht_state {
const struct v4l2_fwht_pixfmt_info *v4l2_fwht_find_pixfmt(u32 pixelformat); const struct v4l2_fwht_pixfmt_info *v4l2_fwht_find_pixfmt(u32 pixelformat);
const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx); const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx);
const struct v4l2_fwht_pixfmt_info *v4l2_fwht_default_fmt(u32 width_div,
u32 height_div,
u32 components_num,
u32 pixenc,
unsigned int start_idx);
int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out); int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out);
int v4l2_fwht_decode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out); int v4l2_fwht_decode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out);
......
...@@ -395,9 +395,10 @@ static int vidioc_querycap(struct file *file, void *priv, ...@@ -395,9 +395,10 @@ static int vidioc_querycap(struct file *file, void *priv,
return 0; return 0;
} }
static int enum_fmt(struct v4l2_fmtdesc *f, bool is_enc, bool is_out) static int enum_fmt(struct v4l2_fmtdesc *f, struct vicodec_ctx *ctx,
bool is_out)
{ {
bool is_uncomp = (is_enc && is_out) || (!is_enc && !is_out); bool is_uncomp = (ctx->is_enc && is_out) || (!ctx->is_enc && !is_out);
if (V4L2_TYPE_IS_MULTIPLANAR(f->type) && !multiplanar) if (V4L2_TYPE_IS_MULTIPLANAR(f->type) && !multiplanar)
return -EINVAL; return -EINVAL;
...@@ -406,8 +407,16 @@ static int enum_fmt(struct v4l2_fmtdesc *f, bool is_enc, bool is_out) ...@@ -406,8 +407,16 @@ static int enum_fmt(struct v4l2_fmtdesc *f, bool is_enc, bool is_out)
if (is_uncomp) { if (is_uncomp) {
const struct v4l2_fwht_pixfmt_info *info = const struct v4l2_fwht_pixfmt_info *info =
v4l2_fwht_get_pixfmt(f->index); get_q_data(ctx, f->type)->info;
if (ctx->is_enc)
info = v4l2_fwht_get_pixfmt(f->index);
else
info = v4l2_fwht_default_fmt(info->width_div,
info->height_div,
info->components_num,
info->pixenc,
f->index);
if (!info) if (!info)
return -EINVAL; return -EINVAL;
f->pixelformat = info->id; f->pixelformat = info->id;
...@@ -424,7 +433,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, ...@@ -424,7 +433,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
{ {
struct vicodec_ctx *ctx = file2ctx(file); struct vicodec_ctx *ctx = file2ctx(file);
return enum_fmt(f, ctx->is_enc, false); return enum_fmt(f, ctx, false);
} }
static int vidioc_enum_fmt_vid_out(struct file *file, void *priv, static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
...@@ -432,7 +441,7 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv, ...@@ -432,7 +441,7 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
{ {
struct vicodec_ctx *ctx = file2ctx(file); struct vicodec_ctx *ctx = file2ctx(file);
return enum_fmt(f, ctx->is_enc, true); return enum_fmt(f, ctx, true);
} }
static int vidioc_g_fmt(struct vicodec_ctx *ctx, struct v4l2_format *f) static int vidioc_g_fmt(struct vicodec_ctx *ctx, struct v4l2_format *f)
......
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