> Subject: [v5 06/24] drm: Add helper to extract lut from struct
> drm_color_lut_32
> 
> From: Chaitanya Kumar Borah <[email protected]>
> 
> Add helper to extract lut values in the precision needed by hardware.
> 
> Signed-off-by: Uma Shankar <[email protected]>
> Signed-off-by: Chaitanya Kumar Borah <[email protected]>
> ---
>  include/drm/drm_color_mgmt.h | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/include/drm/drm_color_mgmt.h b/include/drm/drm_color_mgmt.h
> index ba420444b9f3..b1d12f06fc6e 100644
> --- a/include/drm/drm_color_mgmt.h
> +++ b/include/drm/drm_color_mgmt.h
> @@ -50,6 +50,22 @@ static inline u32 drm_color_lut_extract(u32 user_input,
> int bit_precision)
>                                        (1 << 16) - 1);
>  }
> 
> +/**
> + * drm_color_lut_32_extract - clamp and round LUT entries
> + * @user_input: input value
> + * @bit_precision: number of bits the hw LUT supports
> + *
> + * Extract U0.bit_precision from a U0.32 LUT value.
> + *
> + */
> +static inline u32 drm_color_lut_32_extract(u32 user_input, int
> +bit_precision) {
> +     u64 max = (bit_precision >= 64) ? ~0ULL : (1ULL << bit_precision) - 1;
> +
> +     return DIV_ROUND_CLOSEST_ULL((u64)user_input * max,
> +                                  (1ULL << 32) - 1);

Two problems with this 
First you don't need the (u64) typecast compiler will do it.
Next you'll loose a lot of precision when we look at the edge cases where 
overflow is
Possible so you'll need to make the multiplication safe.

Regards,
Suraj Kandpal

> +}
> +
>  u64 drm_color_ctm_s31_32_to_qm_n(u64 user_input, u32 m, u32 n);
> 
>  void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
> --
> 2.42.0

Reply via email to