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

Unified Diff: tools/telemetry/telemetry/image_processing/rgba_color.py

Issue 668753002: [Telemetry] Migrate bitmap.py from bitmaptools.cc to numpy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years 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 | « tools/telemetry/telemetry/image_processing/image_util_unittest.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/image_processing/rgba_color.py
diff --git a/tools/telemetry/telemetry/image_processing/rgba_color.py b/tools/telemetry/telemetry/image_processing/rgba_color.py
new file mode 100644
index 0000000000000000000000000000000000000000..be3cfed7304c3b7abeb7b1f2cfc2958c9fe6ad0e
--- /dev/null
+++ b/tools/telemetry/telemetry/image_processing/rgba_color.py
@@ -0,0 +1,33 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import collections
+
+class RgbaColor(collections.namedtuple('RgbaColor', ['r', 'g', 'b', 'a'])):
+ """Encapsulates an RGBA color retrieved from an image."""
+ def __new__(cls, r, g, b, a=255):
+ return super(RgbaColor, cls).__new__(cls, r, g, b, a)
+
+ def __int__(self):
+ return (self.r << 16) | (self.g << 8) | self.b
+
+ def IsEqual(self, expected_color, tolerance=0):
+ """Verifies that the color is within a given tolerance of
+ the expected color."""
+ r_diff = abs(self.r - expected_color.r)
+ g_diff = abs(self.g - expected_color.g)
+ b_diff = abs(self.b - expected_color.b)
+ a_diff = abs(self.a - expected_color.a)
+ return (r_diff <= tolerance and g_diff <= tolerance
+ and b_diff <= tolerance and a_diff <= tolerance)
+
+ def AssertIsRGB(self, r, g, b, tolerance=0):
+ assert self.IsEqual(RgbaColor(r, g, b), tolerance)
+
+ def AssertIsRGBA(self, r, g, b, a, tolerance=0):
+ assert self.IsEqual(RgbaColor(r, g, b, a), tolerance)
+
+
+WEB_PAGE_TEST_ORANGE = RgbaColor(222, 100, 13)
+WHITE = RgbaColor(255, 255, 255)
« no previous file with comments | « tools/telemetry/telemetry/image_processing/image_util_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698