MLK-22507: mxc-jpeg: Return rgb24 pixfmt from decoder when app14 is present
authorMirela Rabulea <mirela.rabulea@nxp.com>
Mon, 26 Aug 2019 15:51:20 +0000 (18:51 +0300)
committerMirela Rabulea <mirela.rabulea@nxp.com>
Fri, 30 Aug 2019 15:20:28 +0000 (18:20 +0300)
When GST receives V4L2_EVENT_SOURCE_CHANGE, it calls g_fmt ioctl and
expects that the driver will report the pixel format.
So far, the driver was unable to distinguish, by looking at the jpeg
SOF marker, if an image is YUV444 or RGB24, both have 3 color components
and no subsampling.
Consider the colorspace is RGB if the transform flag from APP14 marker
segment has the value 0, in mxc_jpeg_parse, if needed, update the pixel
format from yuv444 to rgb24.

Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
Reviewed-by: Robert Chiras <robert.chiras@nxp.com>
drivers/media/platform/imx8/mxc-jpeg.c
drivers/media/platform/imx8/mxc-jpeg.h

index 293ad8c..f6673d9 100644 (file)
@@ -1201,6 +1201,8 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx,
        enum v4l2_buf_type cap_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
        struct mxc_jpeg_stream stream;
        bool notfound = true;
+       bool app14 = false;
+       u8 app14_transform = 0;
        struct mxc_jpeg_sof sof, *psof = 0;
        struct mxc_jpeg_sos *psos = 0;
        u8 byte, *next = 0;
@@ -1246,6 +1248,16 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx,
                        psos = (struct mxc_jpeg_sos *)next;
                        notfound = false;
                        break;
+               case APP14:
+                       app14 = true;
+                       /*
+                        * Application Data Syntax is:
+                        * 2 bytes(APPn:0xFF,0xEE), 2 bytes(Lp), Ap1...ApLp-2
+                        * The transform flag is in Ap12
+                        * stream.loc is now on APPn-0xEE byte
+                        */
+                       app14_transform = *(stream.addr + stream.loc + 12 + 1);
+                       break;
                default:
                        notfound = true;
                }
@@ -1293,6 +1305,15 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx,
        img_fmt = mxc_jpeg_get_image_format(dev, &sof);
        if (img_fmt == MXC_JPEG_INVALID)
                return -EINVAL;
+
+       /*
+        * If the transform flag from APP14 marker is 0, images that are
+        * encoded with 3 components have RGB colorspace, see Recommendation
+        * ITU-T T.872 chapter 6.5.3 APP14 marker segment for colour encoding
+        */
+       if ((img_fmt == MXC_JPEG_YUV444) && app14 && (app14_transform == 0))
+               img_fmt = MXC_JPEG_RGB;
+
        if (mxc_jpeg_imgfmt_to_fourcc(img_fmt, &fourcc)) {
                dev_err(dev, "Fourcc not found for %d", img_fmt);
                return -EINVAL;
index 8bfc62e..5d27643 100644 (file)
@@ -40,6 +40,7 @@
 #define SOF2                           0xC2
 #define SOS                            0xDA
 #define DHT                            0xC4
+#define APP14                          0xEE
 #define MXC_JPEG_ENC_CONF_DONE         1
 #define MXC_JPEG_MAX_PLANES            2