From d387c6f64028ff181c83e67ba6a938ebdace78b6 Mon Sep 17 00:00:00 2001 From: Ming Qian Date: Wed, 6 Apr 2022 10:47:33 +0100 Subject: [PATCH] media: imx-jpeg: Correct the pixel format of rgb 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 Reviewed-by: Mirela Rabulea Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.h | 4 +-- drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c | 34 +++++++++++------------ drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.h b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.h index ae70d3a..d838e87 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.h +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.h @@ -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" diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c index 9ce1e78..25b888b 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c @@ -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; } diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h index f53f004..7cbf602 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h @@ -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 -- 2.7.4