]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/media/platform/exynos-gsc/gsc-core.c
[media] exynos-gsc: do proper bytesperline and sizeimage calculation
[mirror_ubuntu-bionic-kernel.git] / drivers / media / platform / exynos-gsc / gsc-core.c
index 787bd16c19e55324c1c069c61423d4d58925df64..a6c47deba3b700fc777ded593e26398e56114cd6 100644 (file)
@@ -39,8 +39,8 @@ static const struct gsc_fmt gsc_formats[] = {
                .num_planes     = 1,
                .num_comp       = 1,
        }, {
-               .name           = "XRGB-8-8-8-8, 32 bpp",
-               .pixelformat    = V4L2_PIX_FMT_RGB32,
+               .name           = "BGRX-8-8-8-8, 32 bpp",
+               .pixelformat    = V4L2_PIX_FMT_BGR32,
                .depth          = { 32 },
                .color          = GSC_RGB,
                .num_planes     = 1,
@@ -441,7 +441,7 @@ int gsc_try_fmt_mplane(struct gsc_ctx *ctx, struct v4l2_format *f)
        v4l_bound_align_image(&pix_mp->width, min_w, max_w, mod_x,
                &pix_mp->height, min_h, max_h, mod_y, 0);
        if (tmp_w != pix_mp->width || tmp_h != pix_mp->height)
-               pr_info("Image size has been modified from %dx%d to %dx%d",
+               pr_debug("Image size has been modified from %dx%d to %dx%d\n",
                         tmp_w, tmp_h, pix_mp->width, pix_mp->height);
 
        pix_mp->num_planes = fmt->num_planes;
@@ -451,12 +451,25 @@ int gsc_try_fmt_mplane(struct gsc_ctx *ctx, struct v4l2_format *f)
        else /* SD */
                pix_mp->colorspace = V4L2_COLORSPACE_SMPTE170M;
 
-
        for (i = 0; i < pix_mp->num_planes; ++i) {
-               int bpl = (pix_mp->width * fmt->depth[i]) >> 3;
-               pix_mp->plane_fmt[i].bytesperline = bpl;
-               pix_mp->plane_fmt[i].sizeimage = bpl * pix_mp->height;
+               struct v4l2_plane_pix_format *plane_fmt = &pix_mp->plane_fmt[i];
+               u32 bpl = plane_fmt->bytesperline;
+
+               if (fmt->num_comp == 1 && /* Packed */
+                   (bpl == 0 || (bpl * 8 / fmt->depth[i]) < pix_mp->width))
+                       bpl = pix_mp->width * fmt->depth[i] / 8;
+
+               if (fmt->num_comp > 1 && /* Planar */
+                   (bpl == 0 || bpl < pix_mp->width))
+                       bpl = pix_mp->width;
+
+               if (i != 0 && fmt->num_comp == 3)
+                       bpl /= 2;
 
+               plane_fmt->bytesperline = bpl;
+               plane_fmt->sizeimage = max(pix_mp->width * pix_mp->height *
+                                          fmt->depth[i] / 8,
+                                          plane_fmt->sizeimage);
                pr_debug("[%d]: bpl: %d, sizeimage: %d",
                                i, bpl, pix_mp->plane_fmt[i].sizeimage);
        }