From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id C7BC210E1D1 for ; Mon, 5 Jun 2023 15:57:01 +0000 (UTC) Message-ID: <4fb26434-4db4-c464-3147-6cebee628164@intel.com> Date: Mon, 5 Jun 2023 21:26:52 +0530 MIME-Version: 1.0 Content-Language: en-US To: Kamil Konieczny , igt-dev@lists.freedesktop.org, Juha-Pekka Heikkila References: <20230531074530.367036-1-swati2.sharma@intel.com> <20230531074530.367036-2-swati2.sharma@intel.com> <20230605151227.jlmimezv2nsci5g4@kamilkon-desk1> From: "Sharma, Swati2" In-Reply-To: <20230605151227.jlmimezv2nsci5g4@kamilkon-desk1> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [igt-dev] [PATCH i-g-t 1/3] lib/igt_fb: round rgb->yuv conversion results List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: Thanks Kamil for pointing this out. Floated patch fixing this https://patchwork.freedesktop.org/patch/541160/ On 05-Jun-23 8:42 PM, Kamil Konieczny wrote: > Hi Swati, > > On 2023-05-31 at 13:15:28 +0530, Swati Sharma wrote: >> Round rgb->yuv conversion results. >> >> Signed-off-by: Ville Syrjala >> Signed-off-by: Swati Sharma >> --- >> lib/igt_fb.c | 25 +++++++++++++++---------- >> 1 file changed, 15 insertions(+), 10 deletions(-) >> >> diff --git a/lib/igt_fb.c b/lib/igt_fb.c >> index 71a199d4..11a5d6c0 100644 >> --- a/lib/igt_fb.c >> +++ b/lib/igt_fb.c >> @@ -3064,11 +3064,16 @@ static void igt_fb_destroy_cairo_shadow_buffer(struct igt_fb *shadow, >> munmap(ptr, shadow->size); >> } >> >> -static uint8_t clamprgb(float val) >> +static uint8_t clamp8(float val) >> { >> return clamp((int)(val + 0.5f), 0, 255); >> } >> >> +static uint8_t clamp16(float val) > ------------- ^ > imho this should be 16, uint16_t as name suggest and > following range is 64K ? > >> +{ >> + return clamp((int)(val + 0.5f), 0, 65535); > ------------------------------------------ ^ > This is 64K. > > Regards, > Kamil > >> +} >> + >> static void read_rgb(struct igt_vec4 *rgb, const uint8_t *rgb24) >> { >> rgb->d[0] = rgb24[2]; >> @@ -3079,9 +3084,9 @@ static void read_rgb(struct igt_vec4 *rgb, const uint8_t *rgb24) >> >> static void write_rgb(uint8_t *rgb24, const struct igt_vec4 *rgb) >> { >> - rgb24[2] = clamprgb(rgb->d[0]); >> - rgb24[1] = clamprgb(rgb->d[1]); >> - rgb24[0] = clamprgb(rgb->d[2]); >> + rgb24[2] = clamp8(rgb->d[0]); >> + rgb24[1] = clamp8(rgb->d[1]); >> + rgb24[0] = clamp8(rgb->d[2]); >> } >> >> struct fb_convert_buf { >> @@ -3401,7 +3406,7 @@ static void convert_rgb24_to_yuv(struct fb_convert *cvt) >> >> rgb_tmp += bpp; >> >> - *y_tmp = yuv.d[0]; >> + *y_tmp = clamp8(yuv.d[0]); >> y_tmp += params.ay_inc; >> >> if ((i % dst_fmt->vsub) || (j % dst_fmt->hsub)) >> @@ -3431,8 +3436,8 @@ static void convert_rgb24_to_yuv(struct fb_convert *cvt) >> read_rgb(&pair_rgb, pair_rgb24); >> pair_yuv = igt_matrix_transform(&m, &pair_rgb); >> >> - *u_tmp = (yuv.d[1] + pair_yuv.d[1]) / 2.0f; >> - *v_tmp = (yuv.d[2] + pair_yuv.d[2]) / 2.0f; >> + *u_tmp = clamp8((yuv.d[1] + pair_yuv.d[1]) / 2.0f); >> + *v_tmp = clamp8((yuv.d[2] + pair_yuv.d[2]) / 2.0f); >> >> u_tmp += params.uv_inc; >> v_tmp += params.uv_inc; >> @@ -3590,7 +3595,7 @@ static void convert_float_to_yuv16(struct fb_convert *cvt, bool alpha) >> >> rgb_tmp += fpp; >> >> - *y_tmp = yuv.d[0]; >> + *y_tmp = clamp16(yuv.d[0]); >> y_tmp += params.ay_inc; >> >> if ((i % dst_fmt->vsub) || (j % dst_fmt->hsub)) >> @@ -3620,8 +3625,8 @@ static void convert_float_to_yuv16(struct fb_convert *cvt, bool alpha) >> read_rgbf(&pair_rgb, pair_float); >> pair_yuv = igt_matrix_transform(&m, &pair_rgb); >> >> - *u_tmp = (yuv.d[1] + pair_yuv.d[1]) / 2.0f; >> - *v_tmp = (yuv.d[2] + pair_yuv.d[2]) / 2.0f; >> + *u_tmp = clamp16((yuv.d[1] + pair_yuv.d[1]) / 2.0f); >> + *v_tmp = clamp16((yuv.d[2] + pair_yuv.d[2]) / 2.0f); >> >> u_tmp += params.uv_inc; >> v_tmp += params.uv_inc; >> -- >> 2.25.1 >>