Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f415408 authored by Krishna Chaitanya Parimi's avatar Krishna Chaitanya Parimi Committed by Gerrit - the friendly Code Review server
Browse files

msm: mdss: alter linear_map to incorporate rounding for AD



The helper function linear_map would take the integral part
of the calculated map, thereby causing issues with getting
the same value after consecutive map and inverse map calls.

For ex: linear_map(21, out, 255, 4095) would translate to
        *out = 21 * 4095 / 255 = 337, whereas inverse case
        linear_map(337, out, 4095, 255) would translate to
        *out = 337 * 255 / 4095 = 20

Changing linear_map from ((in * out_max) / in_max) to a more
precise ((2 * (in * out_max) + in_max) / (2 * in_max)) for
incorporating rounding in the integral mapping.

Change-Id: I15cd8aa1326813ce3cb3a426cbb4e78374623c72
Signed-off-by: default avatarKrishna Chaitanya Parimi <cparimi@codeaurora.org>
parent acd5ad63
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -515,7 +515,7 @@ inline int linear_map(int in, int *out, int in_max, int out_max)
{
	if (in < 0 || !out || in_max <= 0 || out_max <= 0)
		return -EINVAL;
	*out = ((in * out_max) / in_max);
	*out = ((2 * (in * out_max) + in_max) / (2 * in_max));
	pr_debug("in = %d, out = %d, in_max = %d, out_max = %d\n",
		in, *out, in_max, out_max);
	if ((in > 0) && (*out == 0))