blob: 69c6f2689dbf7139880b1a007650b2029b457e4a [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@google.com83acbe02011-04-22 19:18:20 +00008#include "Test.h"
9#include "SkColor.h"
10#include "SkUnPreMultiply.h"
11
12static void test_premul(skiatest::Reporter* reporter) {
13 for (int a = 0; a <= 255; a++) {
14 for (int x = 0; x <= 255; x++) {
15 SkColor c0 = SkColorSetARGB(a, x, x, x);
16 SkPMColor p0 = SkPreMultiplyColor(c0);
17
18 SkColor c1 = SkUnPreMultiply::PMColorToColor(p0);
19 SkPMColor p1 = SkPreMultiplyColor(c1);
20
21 // we can't promise that c0 == c1, since c0 -> p0 is a many to one
22 // function, however, we can promise that p0 -> c1 -> p1 : p0 == p1
23 REPORTER_ASSERT(reporter, p0 == p1);
reed@google.com75595d92011-05-03 21:27:49 +000024
25 {
26 int ax = SkMulDiv255Ceiling(x, a);
27 REPORTER_ASSERT(reporter, ax <= a);
28 }
reed@google.com83acbe02011-04-22 19:18:20 +000029 }
30 }
31}
32
33
34static void TestColor(skiatest::Reporter* reporter) {
35 test_premul(reporter);
36}
37
38#include "TestClassDef.h"
39DEFINE_TESTCLASS("Color", ColorTestClass, TestColor)