[media] vimc: common: Add vimc_colorimetry_clamp
authorHelen Fornazier <helen.koike@collabora.com>
Mon, 19 Jun 2017 17:00:15 +0000 (14:00 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Fri, 23 Jun 2017 12:06:02 +0000 (09:06 -0300)
Colorimetry value will always be checked in the same way. Adding a
helper macro for that

Signed-off-by: Helen Koike <helen.koike@collabora.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/platform/vimc/vimc-common.h

index 60ebde28f56bc563ad964bc991f3ef80edb369cd..43483eecb116c716619d9901359b45b65fdb14f7 100644 (file)
 #include <media/media-device.h>
 #include <media/v4l2-device.h>
 
+/**
+ * struct vimc_colorimetry_clamp - Adjust colorimetry parameters
+ *
+ * @fmt:               the pointer to struct v4l2_pix_format or
+ *                     struct v4l2_mbus_framefmt
+ *
+ * Entities must check if colorimetry given by the userspace is valid, if not
+ * then set them as DEFAULT
+ */
+#define vimc_colorimetry_clamp(fmt)                                    \
+do {                                                                   \
+       if ((fmt)->colorspace == V4L2_COLORSPACE_DEFAULT                \
+           || (fmt)->colorspace > V4L2_COLORSPACE_DCI_P3) {            \
+               (fmt)->colorspace = V4L2_COLORSPACE_DEFAULT;            \
+               (fmt)->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;              \
+               (fmt)->quantization = V4L2_QUANTIZATION_DEFAULT;        \
+               (fmt)->xfer_func = V4L2_XFER_FUNC_DEFAULT;              \
+       }                                                               \
+       if ((fmt)->ycbcr_enc > V4L2_YCBCR_ENC_SMPTE240M)                \
+               (fmt)->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;              \
+       if ((fmt)->quantization > V4L2_QUANTIZATION_LIM_RANGE)          \
+               (fmt)->quantization = V4L2_QUANTIZATION_DEFAULT;        \
+       if ((fmt)->xfer_func > V4L2_XFER_FUNC_SMPTE2084)                \
+               (fmt)->xfer_func = V4L2_XFER_FUNC_DEFAULT;              \
+} while (0)
+
 /**
  * struct vimc_pix_map - maps media bus code with v4l2 pixel format
  *