[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240306-louis-vkms-conv-v1-3-5bfe7d129fdd@riseup.net>
Date: Wed, 06 Mar 2024 17:03:10 -0300
From: Arthur Grillo <arthurgrillo@...eup.net>
To: Rodrigo Siqueira <rodrigosiqueiramelo@...il.com>,
Melissa Wen <melissa.srw@...il.com>,
MaĆra Canal <mairacanal@...eup.net>,
Haneen Mohammed <hamohammed.sa@...il.com>, Daniel Vetter <daniel@...ll.ch>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>, Thomas Zimmermann <tzimmermann@...e.de>,
David Airlie <airlied@...il.com>, arthurgrillo@...eup.net,
Jonathan Corbet <corbet@....net>, pekka.paalanen@...oniitty.fi,
Louis Chauvet <louis.chauvet@...tlin.com>
Cc: dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
jeremie.dautheribes@...tlin.com, miquel.raynal@...tlin.com,
thomas.petazzoni@...tlin.com, seanpaul@...gle.com, marcheu@...gle.com,
nicolejadeyee@...gle.com
Subject: [PATCH 3/7] drm/vkmm: Use drm_fixed api
With the new 32.32 values it makes more sense to use drm_fixed functions
than trying to recreate the wheel.
Signed-off-by: Arthur Grillo <arthurgrillo@...eup.net>
---
drivers/gpu/drm/vkms/vkms_formats.c | 54 +++++++++++++++++++------------------
1 file changed, 28 insertions(+), 26 deletions(-)
diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index 55ed3f598bd7..adde53cdea26 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -191,32 +191,34 @@ VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 cb, u8 cr,
struct conversion_matrix *matrix)
{
u8 r, g, b;
- s64 y_16, cb_16, cr_16;
- s64 r_16, g_16, b_16;
-
- y_16 = y - matrix->y_offset;
- cb_16 = cb - 128;
- cr_16 = cr - 128;
-
- r_16 = matrix->matrix[0][0] * y_16 + matrix->matrix[0][1] * cb_16 +
- matrix->matrix[0][2] * cr_16;
- g_16 = matrix->matrix[1][0] * y_16 + matrix->matrix[1][1] * cb_16 +
- matrix->matrix[1][2] * cr_16;
- b_16 = matrix->matrix[2][0] * y_16 + matrix->matrix[2][1] * cb_16 +
- matrix->matrix[2][2] * cr_16;
-
- // rounding the values
- r_16 = r_16 + (1LL << (CONVERSION_MATRIX_FLOAT_DEPTH - 4));
- g_16 = g_16 + (1LL << (CONVERSION_MATRIX_FLOAT_DEPTH - 4));
- b_16 = b_16 + (1LL << (CONVERSION_MATRIX_FLOAT_DEPTH - 4));
-
- r_16 = clamp(r_16, 0, (1LL << (CONVERSION_MATRIX_FLOAT_DEPTH + 8)) - 1);
- g_16 = clamp(g_16, 0, (1LL << (CONVERSION_MATRIX_FLOAT_DEPTH + 8)) - 1);
- b_16 = clamp(b_16, 0, (1LL << (CONVERSION_MATRIX_FLOAT_DEPTH + 8)) - 1);
-
- r = r_16 >> CONVERSION_MATRIX_FLOAT_DEPTH;
- g = g_16 >> CONVERSION_MATRIX_FLOAT_DEPTH;
- b = b_16 >> CONVERSION_MATRIX_FLOAT_DEPTH;
+ s64 fp_y, fp_cb, fp_cr;
+ s64 fp_r, fp_g, fp_b;
+
+ fp_y = y - matrix->y_offset;
+ fp_cb = cb - 128;
+ fp_cr = cr - 128;
+
+ fp_y = drm_int2fixp(fp_y);
+ fp_cb = drm_int2fixp(fp_cb);
+ fp_cr = drm_int2fixp(fp_cr);
+
+ fp_r = drm_fixp_mul(matrix->matrix[0][0], fp_y) +
+ drm_fixp_mul(matrix->matrix[0][1], fp_cb) +
+ drm_fixp_mul(matrix->matrix[0][2], fp_cr);
+ fp_g = drm_fixp_mul(matrix->matrix[1][0], fp_y) +
+ drm_fixp_mul(matrix->matrix[1][1], fp_cb) +
+ drm_fixp_mul(matrix->matrix[1][2], fp_cr);
+ fp_b = drm_fixp_mul(matrix->matrix[2][0], fp_y) +
+ drm_fixp_mul(matrix->matrix[2][1], fp_cb) +
+ drm_fixp_mul(matrix->matrix[2][2], fp_cr);
+
+ fp_r = drm_fixp2int_round(fp_r);
+ fp_g = drm_fixp2int_round(fp_g);
+ fp_b = drm_fixp2int_round(fp_b);
+
+ r = clamp(fp_r, 0, 0xff);
+ g = clamp(fp_g, 0, 0xff);
+ b = clamp(fp_b, 0, 0xff);
return argb_u16_from_u8888(255, r, g, b);
}
--
2.43.0
Powered by blists - more mailing lists