media: imx-jpeg: Correct the pixel format of rgb
authorMing Qian <ming.qian@nxp.com>
Wed, 6 Apr 2022 09:47:33 +0000 (10:47 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Sun, 24 Apr 2022 07:48:29 +0000 (08:48 +0100)
The hardware is capable of encoding/decoding RGB and ARGB formats
in whatever order the color components are,
but the resulting jpegs look good
if we start with raw data in BGR/ABGR order,
so we will further only support V4L2_PIX_FMT_BGR24 and V4L2_PIX_FMT_ABGR32.

Signed-off-by: Ming Qian <ming.qian@nxp.com>
Reviewed-by: Mirela Rabulea <mirela.rabulea@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.h
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h

index ae70d3a0dc24353c1a061dd0f45bb793b7557192..d838e875616c35a5c7176cd75f90cdd81f40daa2 100644 (file)
@@ -102,11 +102,11 @@ enum mxc_jpeg_image_format {
        MXC_JPEG_INVALID = -1,
        MXC_JPEG_YUV420 = 0x0, /* 2 Plannar, Y=1st plane UV=2nd plane */
        MXC_JPEG_YUV422 = 0x1, /* 1 Plannar, YUYV sequence */
-       MXC_JPEG_RGB    = 0x2, /* RGBRGB packed format */
+       MXC_JPEG_BGR    = 0x2, /* BGR packed format */
        MXC_JPEG_YUV444 = 0x3, /* 1 Plannar, YUVYUV sequence */
        MXC_JPEG_GRAY = 0x4, /* Y8 or Y12 or Single Component */
        MXC_JPEG_RESERVED = 0x5,
-       MXC_JPEG_ARGB   = 0x6,
+       MXC_JPEG_ABGR   = 0x6,
 };
 
 #include "mxc-jpeg.h"
index 9ce1e78f5d303acad9c1c1ac75233b5c47ebee5c..25b888bcaa674dd0c62e671f63198ccd8e404b6c 100644 (file)
@@ -8,7 +8,7 @@
  * Baseline and extended sequential jpeg decoding is supported.
  * Progressive jpeg decoding is not supported by the IP.
  * Supports encode and decode of various formats:
- *     YUV444, YUV422, YUV420, RGB, ARGB, Gray
+ *     YUV444, YUV422, YUV420, BGR, ABGR, Gray
  * YUV420 is the only multi-planar format supported.
  * Minimum resolution is 64 x 64, maximum 8192 x 8192.
  * To achieve 8192 x 8192, modify in defconfig: CONFIG_CMA_SIZE_MBYTES=320
@@ -73,8 +73,8 @@ static const struct mxc_jpeg_fmt mxc_formats[] = {
                .flags          = MXC_JPEG_FMT_TYPE_ENC,
        },
        {
-               .name           = "RGB", /*RGBRGB packed format*/
-               .fourcc         = V4L2_PIX_FMT_RGB24,
+               .name           = "BGR", /*BGR packed format*/
+               .fourcc         = V4L2_PIX_FMT_BGR24,
                .subsampling    = V4L2_JPEG_CHROMA_SUBSAMPLING_444,
                .nc             = 3,
                .depth          = 24,
@@ -84,8 +84,8 @@ static const struct mxc_jpeg_fmt mxc_formats[] = {
                .flags          = MXC_JPEG_FMT_TYPE_RAW,
        },
        {
-               .name           = "ARGB", /* ARGBARGB packed format */
-               .fourcc         = V4L2_PIX_FMT_ARGB32,
+               .name           = "ABGR", /* ABGR packed format */
+               .fourcc         = V4L2_PIX_FMT_ABGR32,
                .subsampling    = V4L2_JPEG_CHROMA_SUBSAMPLING_444,
                .nc             = 4,
                .depth          = 32,
@@ -408,10 +408,10 @@ static enum mxc_jpeg_image_format mxc_jpeg_fourcc_to_imgfmt(u32 fourcc)
                return MXC_JPEG_YUV420;
        case V4L2_PIX_FMT_YUV24:
                return MXC_JPEG_YUV444;
-       case V4L2_PIX_FMT_RGB24:
-               return MXC_JPEG_RGB;
-       case V4L2_PIX_FMT_ARGB32:
-               return MXC_JPEG_ARGB;
+       case V4L2_PIX_FMT_BGR24:
+               return MXC_JPEG_BGR;
+       case V4L2_PIX_FMT_ABGR32:
+               return MXC_JPEG_ABGR;
        default:
                return MXC_JPEG_INVALID;
        }
@@ -684,11 +684,11 @@ static int mxc_jpeg_fixup_sof(struct mxc_jpeg_sof *sof,
                sof->comp[0].h = 0x2;
                break;
        case V4L2_PIX_FMT_YUV24:
-       case V4L2_PIX_FMT_RGB24:
+       case V4L2_PIX_FMT_BGR24:
        default:
                sof->components_no = 3;
                break;
-       case V4L2_PIX_FMT_ARGB32:
+       case V4L2_PIX_FMT_ABGR32:
                sof->components_no = 4;
                break;
        case V4L2_PIX_FMT_GREY:
@@ -716,11 +716,11 @@ static int mxc_jpeg_fixup_sos(struct mxc_jpeg_sos *sos,
                sos->components_no = 3;
                break;
        case V4L2_PIX_FMT_YUV24:
-       case V4L2_PIX_FMT_RGB24:
+       case V4L2_PIX_FMT_BGR24:
        default:
                sos->components_no = 3;
                break;
-       case V4L2_PIX_FMT_ARGB32:
+       case V4L2_PIX_FMT_ABGR32:
                sos->components_no = 4;
                break;
        case V4L2_PIX_FMT_GREY:
@@ -751,8 +751,8 @@ static unsigned int mxc_jpeg_setup_cfg_stream(void *cfg_stream_vaddr,
        memcpy(cfg + offset, jpeg_soi, ARRAY_SIZE(jpeg_soi));
        offset += ARRAY_SIZE(jpeg_soi);
 
-       if (fourcc == V4L2_PIX_FMT_RGB24 ||
-           fourcc == V4L2_PIX_FMT_ARGB32) {
+       if (fourcc == V4L2_PIX_FMT_BGR24 ||
+           fourcc == V4L2_PIX_FMT_ABGR32) {
                memcpy(cfg + offset, jpeg_app14, sizeof(jpeg_app14));
                offset += sizeof(jpeg_app14);
        } else {
@@ -1190,9 +1190,9 @@ static u32 mxc_jpeg_get_image_format(struct device *dev,
         * encoded with 3 components have RGB colorspace, see Recommendation
         * ITU-T T.872 chapter 6.5.3 APP14 marker segment for colour encoding
         */
-       if (fourcc == V4L2_PIX_FMT_YUV24 || fourcc == V4L2_PIX_FMT_RGB24) {
+       if (fourcc == V4L2_PIX_FMT_YUV24 || fourcc == V4L2_PIX_FMT_BGR24) {
                if (header->app14_tf == V4L2_JPEG_APP14_TF_CMYK_RGB)
-                       fourcc = V4L2_PIX_FMT_RGB24;
+                       fourcc = V4L2_PIX_FMT_BGR24;
                else
                        fourcc = V4L2_PIX_FMT_YUV24;
        }
index f53f004ba851dccd535232c2b52e3cb011a9640d..7cbf602c7eeac9594057711d3ecd63330eb3f589 100644 (file)
@@ -17,7 +17,7 @@
 #define MXC_JPEG_FMT_TYPE_RAW          1
 #define MXC_JPEG_DEFAULT_WIDTH         1280
 #define MXC_JPEG_DEFAULT_HEIGHT                720
-#define MXC_JPEG_DEFAULT_PFMT          V4L2_PIX_FMT_RGB24
+#define MXC_JPEG_DEFAULT_PFMT          V4L2_PIX_FMT_BGR24
 #define MXC_JPEG_MIN_WIDTH             64
 #define MXC_JPEG_MIN_HEIGHT            64
 #define MXC_JPEG_MAX_WIDTH             0x2000