summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJason Simmons <jsimmons@google.com>2011-06-29 13:48:39 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-06-29 13:48:39 -0700
commit9e1fb41b4fbfbd190560cf48f24939703a13eca5 (patch)
tree8621dd8dd0a0e32e8883dbdaa02b1610018b05c4 /include
parent5c226b835812630d9dc67ca02ca03dddaee5b6c7 (diff)
parentaa11965bd55b8344104ebb0c9ebf39ee0cced03f (diff)
downloadframeworks_base-9e1fb41b4fbfbd190560cf48f24939703a13eca5.zip
frameworks_base-9e1fb41b4fbfbd190560cf48f24939703a13eca5.tar.gz
frameworks_base-9e1fb41b4fbfbd190560cf48f24939703a13eca5.tar.bz2
Merge "Add a linear transform library to libutils"
Diffstat (limited to 'include')
-rw-r--r--include/utils/LinearTransform.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/include/utils/LinearTransform.h b/include/utils/LinearTransform.h
new file mode 100644
index 0000000..04cb355
--- /dev/null
+++ b/include/utils/LinearTransform.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _LIBS_UTILS_LINEAR_TRANSFORM_H
+#define _LIBS_UTILS_LINEAR_TRANSFORM_H
+
+#include <stdint.h>
+
+namespace android {
+
+// LinearTransform defines a structure which hold the definition of a
+// transformation from single dimensional coordinate system A into coordinate
+// system B (and back again). Values in A and in B are 64 bit, the linear
+// scale factor is expressed as a rational number using two 32 bit values.
+//
+// Specifically, let
+// f(a) = b
+// F(b) = f^-1(b) = a
+// then
+//
+// f(a) = (((a - a_zero) * a_to_b_numer) / a_to_b_denom) + b_zero;
+//
+// and
+//
+// F(b) = (((b - b_zero) * a_to_b_denom) / a_to_b_numer) + a_zero;
+//
+struct LinearTransform {
+ int64_t a_zero;
+ int64_t b_zero;
+ int32_t a_to_b_numer;
+ uint32_t a_to_b_denom;
+
+ // Transform from A->B
+ // Returns true on success, or false in the case of a singularity or an
+ // overflow.
+ bool doForwardTransform(int64_t a_in, int64_t* b_out) const;
+
+ // Transform from B->A
+ // Returns true on success, or false in the case of a singularity or an
+ // overflow.
+ bool doReverseTransform(int64_t b_in, int64_t* a_out) const;
+
+ // Helpers which will reduce the fraction N/D using Euclid's method.
+ template <class T> static void reduce(T* N, T* D);
+ static void reduce(int32_t* N, uint32_t* D);
+};
+
+
+}
+
+#endif // _LIBS_UTILS_LINEAR_TRANSFORM_H