OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkColorPriv.h" |
| 9 #include "SkUnPreMultiply.h" |
| 10 #include "Test.h" |
| 11 |
| 12 DEF_TEST(Unpremultiply, reporter) { |
| 13 // Here we test that unpremultiplication is injective: |
| 14 // no two distinct premul colors map to the same unpremul color. |
| 15 |
| 16 // DM exploits this fact to safely hash .pngs instead of the original bitmap
s. |
| 17 |
| 18 // It is sufficient to test red. Green and blue follow the same rules. |
| 19 // This means we have at most 256*256 possible colors to deal with. |
| 20 int hits[256*256]; |
| 21 for (size_t i = 0; i < SK_ARRAY_COUNT(hits); i++) { |
| 22 hits[i] = 0; |
| 23 } |
| 24 |
| 25 for (int a = 0; a < 256; a++) { |
| 26 for (int r = 0; r <= a; r++) { |
| 27 SkPMColor pm = SkPackARGB32(a, r, 0, 0); |
| 28 SkColor upm = SkUnPreMultiply::PMColorToColor(pm); |
| 29 |
| 30 // ARGB -> AR |
| 31 hits[upm >> 16]++; |
| 32 } |
| 33 } |
| 34 |
| 35 for (size_t i = 0; i < SK_ARRAY_COUNT(hits); i++) { |
| 36 REPORTER_ASSERT(reporter, hits[i] < 2); |
| 37 } |
| 38 } |
OLD | NEW |