From: Mirela Rabulea Date: Mon, 26 Aug 2019 15:51:20 +0000 (+0300) Subject: MLK-22507: mxc-jpeg: Return rgb24 pixfmt from decoder when app14 is present X-Git-Tag: rel_imx_4.19.35_1.1.0~73 X-Git-Url: https://git.somdevices.com/?a=commitdiff_plain;h=6bf880792149920c6a8982b3c30f6a043368154c;p=linux.git MLK-22507: mxc-jpeg: Return rgb24 pixfmt from decoder when app14 is present 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 Reviewed-by: Robert Chiras --- diff --git a/drivers/media/platform/imx8/mxc-jpeg.c b/drivers/media/platform/imx8/mxc-jpeg.c index 293ad8cc823b..f6673d9fde90 100644 --- a/drivers/media/platform/imx8/mxc-jpeg.c +++ b/drivers/media/platform/imx8/mxc-jpeg.c @@ -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; diff --git a/drivers/media/platform/imx8/mxc-jpeg.h b/drivers/media/platform/imx8/mxc-jpeg.h index 8bfc62e4bfd0..5d27643c0fdc 100644 --- a/drivers/media/platform/imx8/mxc-jpeg.h +++ b/drivers/media/platform/imx8/mxc-jpeg.h @@ -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