Upstream mulDiv255Ceil() from WebKit to the skia repository.
(Patch by Noel Gordon (noel.gordon@gmail.com))
Review URL: http://codereview.appspot.com/3466042
git-svn-id: http://skia.googlecode.com/svn/trunk@632 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index 4bfbd94..2555d73 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -171,6 +171,19 @@
#endif
}
+static void test_muldiv255ceiling(skiatest::Reporter* reporter) {
+ for (int c = 0; c <= 255; c++) {
+ for (int a = 0; a <= 255; a++) {
+ int product = (c * a + 255);
+ int expected_ceiling = (product + (product >> 8)) >> 8;
+ int webkit_ceiling = (c * a + 254) / 255;
+ REPORTER_ASSERT(reporter, expected_ceiling == webkit_ceiling);
+ int skia_ceiling = SkMulDiv255Ceiling(c, a);
+ REPORTER_ASSERT(reporter, skia_ceiling == webkit_ceiling);
+ }
+ }
+}
+
static void test_copysign(skiatest::Reporter* reporter) {
static const int32_t gTriples[] = {
// x, y, expected result
@@ -237,6 +250,7 @@
#endif
test_muldiv255(reporter);
+ test_muldiv255ceiling(reporter);
test_copysign(reporter);
{