Utils: Fix a bug in the linear transformation code.
Hand merge from ics-aah
> Utils: Fix a bug in the linear transformation code.
>
> Fix a bug where an incorrect result would be computed if you used the
> linear transformation code to do a reverse transformation (from B's
> domain into A's domain) when the scaler fraction was negative.
>
> Change-Id: I8e5f109314d235a177ab41f65d3c4cd08cff78be
> Signed-off-by: John Grossman <johngro@google.com>
Change-Id: Id90e18f685c61c1a89fd91c32adcf01363b3e8f3
Signed-off-by: John Grossman <johngro@google.com>
diff --git a/libs/utils/LinearTransform.cpp b/libs/utils/LinearTransform.cpp
index d752415..b7d28d4 100644
--- a/libs/utils/LinearTransform.cpp
+++ b/libs/utils/LinearTransform.cpp
@@ -114,6 +114,7 @@
int64_t basis1,
int32_t N,
uint32_t D,
+ bool invert_frac,
int64_t basis2,
int64_t* out) {
uint64_t scaled, res;
@@ -137,8 +138,8 @@
is_neg = !is_neg;
if (!scale_u64_to_u64(abs_val,
- ABS(N),
- D,
+ invert_frac ? D : ABS(N),
+ invert_frac ? ABS(N) : D,
&scaled,
is_neg))
return false; // overflow/undeflow
@@ -191,6 +192,7 @@
a_zero,
a_to_b_numer,
a_to_b_denom,
+ false,
b_zero,
b_out);
}
@@ -201,8 +203,9 @@
return linear_transform_s64_to_s64(b_in,
b_zero,
- a_to_b_denom,
a_to_b_numer,
+ a_to_b_denom,
+ true,
a_zero,
a_out);
}