[media] s5p-jpeg: Prevent JPEG 4:2:0 > YUV 4:2:0 decompression
authorJacek Anaszewski <j.anaszewski@samsung.com>
Thu, 10 Apr 2014 07:32:17 +0000 (04:32 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Tue, 13 May 2014 23:22:06 +0000 (20:22 -0300)
Prevent decompression of a JPEG 4:2:0 with odd width to
the YUV 4:2:0 compliant formats for Exynos4x12 SoCs and
adjust capture format to RGB565 in such a case. This is
required because the configuration would produce a raw
image with broken luma component.

Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/media/platform/s5p-jpeg/jpeg-core.c

index ee561fad48b818c6a2a99a0b5ed9e145d0dee330..6da2c6220353ab6c09c4db83f9d91f500b205123 100644 (file)
@@ -1064,15 +1064,17 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, void *priv,
                return -EINVAL;
        }
 
+       if ((ctx->jpeg->variant->version != SJPEG_EXYNOS4) ||
+           (ctx->mode != S5P_JPEG_DECODE))
+               goto exit;
+
        /*
         * The exynos4x12 device requires resulting YUV image
         * subsampling not to be lower than the input jpeg subsampling.
         * If this requirement is not met then downgrade the requested
         * capture format to the one with subsampling equal to the input jpeg.
         */
-       if ((ctx->jpeg->variant->version == SJPEG_EXYNOS4) &&
-           (ctx->mode == S5P_JPEG_DECODE) &&
-           (fmt->flags & SJPEG_FMT_NON_RGB) &&
+       if ((fmt->flags & SJPEG_FMT_NON_RGB) &&
            (fmt->subsampling < ctx->subsampling)) {
                ret = s5p_jpeg_adjust_fourcc_to_subsampling(ctx->subsampling,
                                                            fmt->fourcc,
@@ -1085,6 +1087,23 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, void *priv,
                                                        FMT_TYPE_CAPTURE);
        }
 
+       /*
+        * Decompression of a JPEG file with 4:2:0 subsampling and odd
+        * width to the YUV 4:2:0 compliant formats produces a raw image
+        * with broken luma component. Adjust capture format to RGB565
+        * in such a case.
+        */
+       if (ctx->subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_420 &&
+           (ctx->out_q.w & 1) &&
+           (pix->pixelformat == V4L2_PIX_FMT_NV12 ||
+            pix->pixelformat == V4L2_PIX_FMT_NV21 ||
+            pix->pixelformat == V4L2_PIX_FMT_YUV420)) {
+               pix->pixelformat = V4L2_PIX_FMT_RGB565;
+               fmt = s5p_jpeg_find_format(ctx, pix->pixelformat,
+                                                       FMT_TYPE_CAPTURE);
+       }
+
+exit:
        return vidioc_try_fmt(f, fmt, ctx, FMT_TYPE_CAPTURE);
 }