Commit fa8880be authored by Sylwester Nawrocki's avatar Sylwester Nawrocki Committed by Mauro Carvalho Chehab

[media] s5p-fimc: Fix bytesperline value for V4L2_PIX_FMT_YUV420M format

Make sure bytesperline for Cb, Cr planes for V4L2_PIX_FMT_YUV420M
format is half of the Y plane value, rather than having same
bytesperline for all planes.
While at it, simplify the bytesperline parameter handling by
storing it when image format is set and returning those values
when getting the format, instead of recalculating bytesperline
from intermediate parameters.
Reported-by: default avatarSebastian Dröge <sebastian.droege@collabora.co.uk>
Signed-off-by: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 33133ea7
...@@ -950,9 +950,9 @@ static int fimc_cap_g_fmt_mplane(struct file *file, void *fh, ...@@ -950,9 +950,9 @@ static int fimc_cap_g_fmt_mplane(struct file *file, void *fh,
struct v4l2_format *f) struct v4l2_format *f)
{ {
struct fimc_dev *fimc = video_drvdata(file); struct fimc_dev *fimc = video_drvdata(file);
struct fimc_ctx *ctx = fimc->vid_cap.ctx;
return fimc_fill_format(&ctx->d_frame, f); __fimc_get_format(&fimc->vid_cap.ctx->d_frame, f);
return 0;
} }
static int fimc_cap_try_fmt_mplane(struct file *file, void *fh, static int fimc_cap_try_fmt_mplane(struct file *file, void *fh,
...@@ -1074,8 +1074,10 @@ static int __fimc_capture_set_format(struct fimc_dev *fimc, ...@@ -1074,8 +1074,10 @@ static int __fimc_capture_set_format(struct fimc_dev *fimc,
return ret; return ret;
} }
for (i = 0; i < ff->fmt->memplanes; i++) for (i = 0; i < ff->fmt->memplanes; i++) {
ff->bytesperline[i] = pix->plane_fmt[i].bytesperline;
ff->payload[i] = pix->plane_fmt[i].sizeimage; ff->payload[i] = pix->plane_fmt[i].sizeimage;
}
set_frame_bounds(ff, pix->width, pix->height); set_frame_bounds(ff, pix->width, pix->height);
/* Reset the composition rectangle if not yet configured */ /* Reset the composition rectangle if not yet configured */
......
...@@ -691,7 +691,7 @@ void fimc_alpha_ctrl_update(struct fimc_ctx *ctx) ...@@ -691,7 +691,7 @@ void fimc_alpha_ctrl_update(struct fimc_ctx *ctx)
v4l2_ctrl_unlock(ctrl); v4l2_ctrl_unlock(ctrl);
} }
int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f) void __fimc_get_format(struct fimc_frame *frame, struct v4l2_format *f)
{ {
struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp; struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
int i; int i;
...@@ -704,19 +704,9 @@ int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f) ...@@ -704,19 +704,9 @@ int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f)
pixm->num_planes = frame->fmt->memplanes; pixm->num_planes = frame->fmt->memplanes;
for (i = 0; i < pixm->num_planes; ++i) { for (i = 0; i < pixm->num_planes; ++i) {
int bpl = frame->f_width; pixm->plane_fmt[i].bytesperline = frame->bytesperline[i];
if (frame->fmt->colplanes == 1) /* packed formats */ pixm->plane_fmt[i].sizeimage = frame->payload[i];
bpl = (bpl * frame->fmt->depth[0]) / 8;
pixm->plane_fmt[i].bytesperline = bpl;
if (frame->fmt->flags & FMT_FLAGS_COMPRESSED) {
pixm->plane_fmt[i].sizeimage = frame->payload[i];
continue;
}
pixm->plane_fmt[i].sizeimage = (frame->o_width *
frame->o_height * frame->fmt->depth[i]) / 8;
} }
return 0;
} }
void fimc_fill_frame(struct fimc_frame *frame, struct v4l2_format *f) void fimc_fill_frame(struct fimc_frame *frame, struct v4l2_format *f)
...@@ -765,9 +755,16 @@ void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height, ...@@ -765,9 +755,16 @@ void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
if (fmt->colplanes == 1 && /* Packed */ if (fmt->colplanes == 1 && /* Packed */
(bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width)) (bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width))
bpl = (pix->width * fmt->depth[0]) / 8; bpl = (pix->width * fmt->depth[0]) / 8;
/*
if (i == 0) /* Same bytesperline for each plane. */ * Currently bytesperline for each plane is same, except
* V4L2_PIX_FMT_YUV420M format. This calculation may need
* to be changed when other multi-planar formats are added
* to the fimc_formats[] array.
*/
if (i == 0)
bytesperline = bpl; bytesperline = bpl;
else if (i == 1 && fmt->memplanes == 3)
bytesperline /= 2;
plane_fmt->bytesperline = bytesperline; plane_fmt->bytesperline = bytesperline;
plane_fmt->sizeimage = max((pix->width * pix->height * plane_fmt->sizeimage = max((pix->width * pix->height *
......
...@@ -265,6 +265,7 @@ struct fimc_vid_buffer { ...@@ -265,6 +265,7 @@ struct fimc_vid_buffer {
* @width: image pixel width * @width: image pixel width
* @height: image pixel weight * @height: image pixel weight
* @payload: image size in bytes (w x h x bpp) * @payload: image size in bytes (w x h x bpp)
* @bytesperline: bytesperline value for each plane
* @paddr: image frame buffer physical addresses * @paddr: image frame buffer physical addresses
* @dma_offset: DMA offset in bytes * @dma_offset: DMA offset in bytes
* @fmt: fimc color format pointer * @fmt: fimc color format pointer
...@@ -279,6 +280,7 @@ struct fimc_frame { ...@@ -279,6 +280,7 @@ struct fimc_frame {
u32 width; u32 width;
u32 height; u32 height;
unsigned int payload[VIDEO_MAX_PLANES]; unsigned int payload[VIDEO_MAX_PLANES];
unsigned int bytesperline[VIDEO_MAX_PLANES];
struct fimc_addr paddr; struct fimc_addr paddr;
struct fimc_dma_offset dma_offset; struct fimc_dma_offset dma_offset;
struct fimc_fmt *fmt; struct fimc_fmt *fmt;
...@@ -637,7 +639,7 @@ int fimc_ctrls_create(struct fimc_ctx *ctx); ...@@ -637,7 +639,7 @@ int fimc_ctrls_create(struct fimc_ctx *ctx);
void fimc_ctrls_delete(struct fimc_ctx *ctx); void fimc_ctrls_delete(struct fimc_ctx *ctx);
void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active); void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active);
void fimc_alpha_ctrl_update(struct fimc_ctx *ctx); void fimc_alpha_ctrl_update(struct fimc_ctx *ctx);
int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f); void __fimc_get_format(struct fimc_frame *frame, struct v4l2_format *f);
void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height, void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
struct v4l2_pix_format_mplane *pix); struct v4l2_pix_format_mplane *pix);
struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code, struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code,
......
...@@ -294,7 +294,8 @@ static int fimc_m2m_g_fmt_mplane(struct file *file, void *fh, ...@@ -294,7 +294,8 @@ static int fimc_m2m_g_fmt_mplane(struct file *file, void *fh,
if (IS_ERR(frame)) if (IS_ERR(frame))
return PTR_ERR(frame); return PTR_ERR(frame);
return fimc_fill_format(frame, f); __fimc_get_format(frame, f);
return 0;
} }
static int fimc_try_fmt_mplane(struct fimc_ctx *ctx, struct v4l2_format *f) static int fimc_try_fmt_mplane(struct fimc_ctx *ctx, struct v4l2_format *f)
...@@ -389,8 +390,8 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void *fh, ...@@ -389,8 +390,8 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void *fh,
fimc_alpha_ctrl_update(ctx); fimc_alpha_ctrl_update(ctx);
for (i = 0; i < frame->fmt->colplanes; i++) { for (i = 0; i < frame->fmt->colplanes; i++) {
frame->payload[i] = frame->bytesperline[i] = pix->plane_fmt[i].bytesperline;
(pix->width * pix->height * frame->fmt->depth[i]) / 8; frame->payload[i] = pix->plane_fmt[i].sizeimage;
} }
fimc_fill_frame(frame, f); fimc_fill_frame(frame, 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