Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Unified Diff: tests/UnpremultiplyTest.cpp

Issue 549203003: Hash .pngs instead of SkBitmaps. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: gypi Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/tests.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/UnpremultiplyTest.cpp
diff --git a/tests/UnpremultiplyTest.cpp b/tests/UnpremultiplyTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7846a1b370ad4ba7c7fef47ad2a5deed5148c76c
--- /dev/null
+++ b/tests/UnpremultiplyTest.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkColorPriv.h"
+#include "SkUnPreMultiply.h"
+#include "Test.h"
+
+DEF_TEST(Unpremultiply, reporter) {
+ // Here we test that unpremultiplication is injective:
+ // no two distinct premul colors map to the same unpremul color.
+
+ // DM exploits this fact to safely hash .pngs instead of the original bitmaps.
+
+ // It is sufficient to test red. Green and blue follow the same rules.
+ // This means we have at most 256*256 possible colors to deal with.
+ int hits[256*256];
+ for (size_t i = 0; i < SK_ARRAY_COUNT(hits); i++) {
+ hits[i] = 0;
+ }
+
+ for (int a = 0; a < 256; a++) {
+ for (int r = 0; r <= a; r++) {
+ SkPMColor pm = SkPackARGB32(a, r, 0, 0);
+ SkColor upm = SkUnPreMultiply::PMColorToColor(pm);
+
+ // ARGB -> AR
+ hits[upm >> 16]++;
+ }
+ }
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(hits); i++) {
+ REPORTER_ASSERT(reporter, hits[i] < 2);
+ }
+}
« no previous file with comments | « gyp/tests.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698