From ec44ed0758871db896d9c7d5c09f7084ddea1c7a Mon Sep 17 00:00:00 2001 From: John Grossman Date: Wed, 27 Jun 2012 15:34:43 -0700 Subject: [PATCH] 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 Change-Id: Id90e18f685c61c1a89fd91c32adcf01363b3e8f3 Signed-off-by: John Grossman --- libs/utils/LinearTransform.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/utils/LinearTransform.cpp b/libs/utils/LinearTransform.cpp index d752415cf..b7d28d4b3 100644 --- a/libs/utils/LinearTransform.cpp +++ b/libs/utils/LinearTransform.cpp @@ -114,6 +114,7 @@ static bool linear_transform_s64_to_s64( 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 @@ static bool linear_transform_s64_to_s64( 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 @@ bool LinearTransform::doForwardTransform(int64_t a_in, int64_t* b_out) const { a_zero, a_to_b_numer, a_to_b_denom, + false, b_zero, b_out); } @@ -201,8 +203,9 @@ bool LinearTransform::doReverseTransform(int64_t b_in, int64_t* a_out) const { 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); }