aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>2021-10-30 10:46:09 +0100
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2021-10-30 10:46:09 +0100
commit1d00c48a42a86d46bc61cbe66a7eec0aeaedab61 (patch)
tree7a0177a529e62294579c1c06da2f38a196da61d9
parenta0921e28bc5c05010f5666a9f6817b91b36a3544 (diff)
downloadv4l-utils-1d00c48a42a86d46bc61cbe66a7eec0aeaedab61.tar.gz
v4l2grab: use BT.709 by default on YUV conversion
This is more commonly found those days. Yet, the right approach would be, instead, to add full support for colorspace. So, add a note there, while keeping the BT.601 table too. As the hole idea of v4l2grab is to do quick tests, let's keep using an integer arithimetic, as this should be faster. Yet, let's improve its precision. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
-rw-r--r--contrib/test/v4l2grab.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/contrib/test/v4l2grab.c b/contrib/test/v4l2grab.c
index 70b29da3..1f4a0988 100644
--- a/contrib/test/v4l2grab.c
+++ b/contrib/test/v4l2grab.c
@@ -217,7 +217,7 @@ static void copy_two_pixels(uint32_t fourcc,
case V4L2_PIX_FMT_UYVY:
case V4L2_PIX_FMT_YVYU:
case V4L2_PIX_FMT_VYUY:
- int y_off, u_off, u, v;
+ int32_t y_off, u_off, u, v;
y_off = (fourcc == V4L2_PIX_FMT_YUYV || fourcc == V4L2_PIX_FMT_YVYU) ? 0 : 1;
u_off = (fourcc == V4L2_PIX_FMT_YUYV || fourcc == V4L2_PIX_FMT_UYVY) ? 0 : 1;
@@ -226,11 +226,30 @@ static void copy_two_pixels(uint32_t fourcc,
v = src[1 - y_off][1 - u_off] - 128;
for (i = 0; i < 2; i++) {
- int y = src[i][y_off] - 16;
-
- *(*dst)++ = CLAMP((298 * y + 409 * v + 128) >> 8);
- *(*dst)++ = CLAMP((298 * y - 100 * u - 208 * v + 128) >> 8);
- *(*dst)++ = CLAMP((298 * y + 516 * u + 128) >> 8);
+ int32_t y = src[i][y_off] - 16;
+#if 0
+ /* TODO: add colorspace check logic */
+
+ /*
+ * ITU-R BT.601 matrix:
+ * R = 1.164 * y + 0.0 * u + 1.596 * v
+ * G = 1.164 * y + -0.392 * u + -0.813 * v
+ * B = 1.164 * y + 2.017 * u + 0.0 * v
+ */
+ *(*dst)++ = CLAMP((76284 * y + 104595 * v + 32768) >> 16);
+ *(*dst)++ = CLAMP((76284 * y - 25690 * u - 53281 * v + 32768) >> 16);
+ *(*dst)++ = CLAMP((76284 * y + 132186 * u + 32768) >> 16);
+#else
+ /*
+ * ITU-R BT.709 matrix:
+ * R = 1.164 * y + 0.0 * u + 1.793 * v
+ * G = 1.164 * y + -0.213 * u + -0.533 * v
+ * B = 1.164 * y + 2.112 * u + 0.0 * v
+ */
+ *(*dst)++ = CLAMP((76284 * y + 117506 * v + 32768) >> 16);
+ *(*dst)++ = CLAMP((76284 * y - 13959 * u - 34931 * v + 32768) >> 16);
+ *(*dst)++ = CLAMP((76284 * y + 138412 * u + 32768) >> 16);
+#endif
}
break;
default: