Update sdk/platform-tools to version 26.0.0.
[android_tools.git] / sdk / platform-tools / systrace / catapult / telemetry / telemetry / util / rgba_color.py
blob84e02356fde33292ca40afb3ced5b7a6d876c557
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import collections
7 class RgbaColor(collections.namedtuple('RgbaColor', ['r', 'g', 'b', 'a'])):
8 """Encapsulates an RGBA color retrieved from an image."""
9 def __new__(cls, r, g, b, a=255):
10 return super(RgbaColor, cls).__new__(cls, r, g, b, a)
12 def __int__(self):
13 return (self.r << 16) | (self.g << 8) | self.b
15 def IsEqual(self, expected_color, tolerance=0):
16 """Verifies that the color is within a given tolerance of
17 the expected color."""
18 r_diff = abs(self.r - expected_color.r)
19 g_diff = abs(self.g - expected_color.g)
20 b_diff = abs(self.b - expected_color.b)
21 a_diff = abs(self.a - expected_color.a)
22 return (r_diff <= tolerance and g_diff <= tolerance
23 and b_diff <= tolerance and a_diff <= tolerance)
25 def AssertIsRGB(self, r, g, b, tolerance=0):
26 assert self.IsEqual(RgbaColor(r, g, b), tolerance)
28 def AssertIsRGBA(self, r, g, b, a, tolerance=0):
29 assert self.IsEqual(RgbaColor(r, g, b, a), tolerance)
32 WEB_PAGE_TEST_ORANGE = RgbaColor(222, 100, 13)
33 WHITE = RgbaColor(255, 255, 255)