aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/MathTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-30 22:34:45 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-30 22:34:45 +0000
commit772813afa62706bd97024430b4505afe4258687a (patch)
treee6b52c6beda743384b3807ec50241899500dda05 /tests/MathTest.cpp
parent30ca0a69e673047fcad1f9f275001fb017f68a31 (diff)
add code to test different premul techniques (disabled right now)
git-svn-id: http://skia.googlecode.com/svn/trunk@1030 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/MathTest.cpp')
-rw-r--r--tests/MathTest.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index 493691e6f7..7a9364f916 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -3,6 +3,40 @@
#include "SkPoint.h"
#include "SkRandom.h"
+#if 0
+static U8CPU premul_fast(U8CPU a, U8CPU x) {
+ return a * x * 32897 >> 23;
+}
+
+static U8CPU premul_trunc(U8CPU a, U8CPU x) {
+ double result = a * x;
+ result /= 255.0;
+ return (unsigned)floor(result + 0.0);
+}
+
+static U8CPU premul_round(U8CPU a, U8CPU x) {
+ double result = a * x;
+ result /= 255.0;
+ return (unsigned)floor(result + 0.5);
+}
+
+static void test_premul(skiatest::Reporter* reporter) {
+ for (int a = 0; a <= 255; a++) {
+ for (int x = 0; x <= 255; x++) {
+ unsigned curr_trunc = SkMulDiv255Trunc(a, x);
+ unsigned curr_round = SkMulDiv255Round(a, x);
+ unsigned fast = premul_fast(a, x);
+ unsigned slow_round = premul_round(a, x);
+ unsigned slow_trunc = premul_trunc(a, x);
+ if (fast != slow || curr != fast) {
+ SkDebugf("---- premul(%d %d) curr=%d fast=%d slow=%d\n", a, x,
+ curr, fast, slow);
+ }
+ }
+ }
+}
+#endif
+
#if defined(SkLONGLONG)
static int symmetric_fixmul(int a, int b) {
int sa = SkExtractSign(a);
@@ -458,6 +492,8 @@ static void TestMath(skiatest::Reporter* reporter) {
}
SkDebugf("SinCos: maximum error = %d\n", maxDiff);
#endif
+
+// test_premul(reporter);
}
#include "TestClassDef.h"