media: vicodec: Add support for 4 planes formats

Add support for formats with 4 planes: V4L2_PIX_FMT_ABGR32,
V4L2_PIX_FMT_ARGB32.
Also add alpha plane related flags to the header of the encoded file.

Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
[hans.verkuil@cisco.com: fix line-too-long warnings]
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
This commit is contained in:
Dafna Hirschfeld 2018-11-15 06:23:32 -05:00 committed by Mauro Carvalho Chehab
parent 195057196b
commit 16ecf6dff9
4 changed files with 61 additions and 2 deletions

View File

@ -784,6 +784,18 @@ u32 fwht_encode_frame(struct fwht_raw_frame *frm,
encoding |= FWHT_CR_UNENCODED; encoding |= FWHT_CR_UNENCODED;
encoding &= ~FWHT_FRAME_UNENCODED; encoding &= ~FWHT_FRAME_UNENCODED;
} }
if (frm->components_num == 4) {
rlco_max = rlco + size / 2 - 256;
encoding = encode_plane(frm->alpha, ref_frm->alpha, &rlco,
rlco_max, cf, frm->height, frm->width,
frm->luma_alpha_step,
is_intra, next_is_intra);
if (encoding & FWHT_FRAME_UNENCODED)
encoding |= FWHT_ALPHA_UNENCODED;
encoding &= ~FWHT_FRAME_UNENCODED;
}
cf->size = (rlco - cf->rlc_data) * sizeof(*rlco); cf->size = (rlco - cf->rlc_data) * sizeof(*rlco);
return encoding; return encoding;
} }
@ -862,4 +874,8 @@ void fwht_decode_frame(struct fwht_cframe *cf, struct fwht_raw_frame *ref,
decode_plane(cf, &rlco, ref->cr, h, w, decode_plane(cf, &rlco, ref->cr, h, w,
hdr_flags & FWHT_FL_CR_IS_UNCOMPRESSED); hdr_flags & FWHT_FL_CR_IS_UNCOMPRESSED);
} }
if (components_num == 4)
decode_plane(cf, &rlco, ref->alpha, cf->height, cf->width,
hdr_flags & FWHT_FL_ALPHA_IS_UNCOMPRESSED);
} }

View File

@ -75,6 +75,7 @@
#define FWHT_FL_CR_IS_UNCOMPRESSED BIT(6) #define FWHT_FL_CR_IS_UNCOMPRESSED BIT(6)
#define FWHT_FL_CHROMA_FULL_HEIGHT BIT(7) #define FWHT_FL_CHROMA_FULL_HEIGHT BIT(7)
#define FWHT_FL_CHROMA_FULL_WIDTH BIT(8) #define FWHT_FL_CHROMA_FULL_WIDTH BIT(8)
#define FWHT_FL_ALPHA_IS_UNCOMPRESSED BIT(9)
/* A 4-values flag - the number of components - 1 */ /* A 4-values flag - the number of components - 1 */
#define FWHT_FL_COMPONENTS_NUM_MSK GENMASK(17, 16) #define FWHT_FL_COMPONENTS_NUM_MSK GENMASK(17, 16)
@ -119,6 +120,7 @@ struct fwht_raw_frame {
#define FWHT_LUMA_UNENCODED BIT(2) #define FWHT_LUMA_UNENCODED BIT(2)
#define FWHT_CB_UNENCODED BIT(3) #define FWHT_CB_UNENCODED BIT(3)
#define FWHT_CR_UNENCODED BIT(4) #define FWHT_CR_UNENCODED BIT(4)
#define FWHT_ALPHA_UNENCODED BIT(5)
u32 fwht_encode_frame(struct fwht_raw_frame *frm, u32 fwht_encode_frame(struct fwht_raw_frame *frm,
struct fwht_raw_frame *ref_frm, struct fwht_raw_frame *ref_frm,

View File

@ -33,6 +33,8 @@ static const struct v4l2_fwht_pixfmt_info v4l2_fwht_pixfmts[] = {
{ V4L2_PIX_FMT_RGB32, 4, 4, 1, 4, 4, 1, 1, 3}, { V4L2_PIX_FMT_RGB32, 4, 4, 1, 4, 4, 1, 1, 3},
{ V4L2_PIX_FMT_XRGB32, 4, 4, 1, 4, 4, 1, 1, 3}, { V4L2_PIX_FMT_XRGB32, 4, 4, 1, 4, 4, 1, 1, 3},
{ V4L2_PIX_FMT_HSV32, 4, 4, 1, 4, 4, 1, 1, 3}, { V4L2_PIX_FMT_HSV32, 4, 4, 1, 4, 4, 1, 1, 3},
{ V4L2_PIX_FMT_ARGB32, 4, 4, 1, 4, 4, 1, 1, 4},
{ V4L2_PIX_FMT_ABGR32, 4, 4, 1, 4, 4, 1, 1, 4},
}; };
@ -146,6 +148,18 @@ int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
rf.cr = rf.cb + 2; rf.cr = rf.cb + 2;
rf.luma++; rf.luma++;
break; 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: default:
return -EINVAL; return -EINVAL;
} }
@ -177,6 +191,8 @@ int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
flags |= FWHT_FL_CB_IS_UNCOMPRESSED; flags |= FWHT_FL_CB_IS_UNCOMPRESSED;
if (encoding & FWHT_CR_UNENCODED) if (encoding & FWHT_CR_UNENCODED)
flags |= FWHT_FL_CR_IS_UNCOMPRESSED; flags |= FWHT_FL_CR_IS_UNCOMPRESSED;
if (encoding & FWHT_ALPHA_UNENCODED)
flags |= FWHT_FL_ALPHA_IS_UNCOMPRESSED;
if (rf.height_div == 1) if (rf.height_div == 1)
flags |= FWHT_FL_CHROMA_FULL_HEIGHT; flags |= FWHT_FL_CHROMA_FULL_HEIGHT;
if (rf.width_div == 1) if (rf.width_div == 1)
@ -356,6 +372,22 @@ int v4l2_fwht_decode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out)
*p++ = 0; *p++ = 0;
} }
break; break;
case V4L2_PIX_FMT_ARGB32:
for (i = 0, p = p_out; i < size; i++) {
*p++ = state->ref_frame.alpha[i];
*p++ = state->ref_frame.cr[i];
*p++ = state->ref_frame.luma[i];
*p++ = state->ref_frame.cb[i];
}
break;
case V4L2_PIX_FMT_ABGR32:
for (i = 0, p = p_out; i < size; i++) {
*p++ = state->ref_frame.cb[i];
*p++ = state->ref_frame.luma[i];
*p++ = state->ref_frame.cr[i];
*p++ = state->ref_frame.alpha[i];
}
break;
default: default:
return -EINVAL; return -EINVAL;
} }

View File

@ -992,9 +992,11 @@ static int vicodec_start_streaming(struct vb2_queue *q,
/* /*
* we don't know ahead how many components are in the encoding type * we don't know ahead how many components are in the encoding type
* V4L2_PIX_FMT_FWHT, so we will allocate space for 3 planes. * V4L2_PIX_FMT_FWHT, so we will allocate space for 4 planes.
*/ */
if (info->id == V4L2_PIX_FMT_FWHT || info->components_num >= 3) if (info->id == V4L2_PIX_FMT_FWHT || info->components_num == 4)
total_planes_size = 2 * size + 2 * (size / chroma_div);
else if (info->components_num == 3)
total_planes_size = size + 2 * (size / chroma_div); total_planes_size = size + 2 * (size / chroma_div);
else else
total_planes_size = size; total_planes_size = size;
@ -1023,6 +1025,13 @@ static int vicodec_start_streaming(struct vb2_queue *q,
state->ref_frame.cb = NULL; state->ref_frame.cb = NULL;
state->ref_frame.cr = NULL; state->ref_frame.cr = NULL;
} }
if (info->id == V4L2_PIX_FMT_FWHT || info->components_num == 4)
state->ref_frame.alpha =
state->ref_frame.cr + size / chroma_div;
else
state->ref_frame.alpha = NULL;
ctx->last_src_buf = NULL; ctx->last_src_buf = NULL;
ctx->last_dst_buf = NULL; ctx->last_dst_buf = NULL;
state->gop_cnt = 0; state->gop_cnt = 0;