Index: tools/telemetry/telemetry/core/bitmap_unittest.py |
diff --git a/tools/telemetry/telemetry/core/bitmap_unittest.py b/tools/telemetry/telemetry/core/bitmap_unittest.py |
index 618faa018f43c1a17d102fa1c28caa6def7188d4..5eb40b991786bf25d3a16c063e622904d60e7336 100644 |
--- a/tools/telemetry/telemetry/core/bitmap_unittest.py |
+++ b/tools/telemetry/telemetry/core/bitmap_unittest.py |
@@ -61,7 +61,7 @@ class BitmapTest(unittest.TestCase): |
pixels = [255,0,0, 255,255,0, 0,0,0, |
255,255,0, 0,255,0, 0,0,0] |
orig = bitmap.Bitmap(3, 3, 2, pixels) |
- orig.Crop(0, 0, 2, 2) |
+ orig.Crop((0, 0, 2, 2)) |
temp_file = tempfile.NamedTemporaryFile().name |
orig.WritePngFile(temp_file) |
new_file = bitmap.Bitmap.FromPngFile(temp_file) |
@@ -71,6 +71,7 @@ class BitmapTest(unittest.TestCase): |
bmp = bitmap.Bitmap.FromBase64Png(test_png) |
file_bmp = bitmap.Bitmap.FromPngFile(test_png_path) |
self.assertTrue(bmp.IsEqual(file_bmp)) |
+ self.assertTrue(bmp.IsEqual(file_bmp), 1) |
tonyg
2013/12/12 22:17:48
I don't understand, why the second test? Maybe a m
szym
2013/12/12 22:54:12
Leftover from when Equal had two distinct codepath
|
def testDiff(self): |
file_bmp = bitmap.Bitmap.FromPngFile(test_png_path) |
@@ -102,15 +103,43 @@ class BitmapTest(unittest.TestCase): |
diff_bmp.GetPixelColor(2, 1).AssertIsRGB(255, 255, 255) |
diff_bmp.GetPixelColor(2, 2).AssertIsRGB(255, 255, 255) |
+ def testGetBoundingBox(self): |
+ pixels = [0,0,0, 0,0,0, 0,0,0, 0,0,0, |
+ 0,0,0, 1,0,0, 1,0,0, 0,0,0, |
+ 0,0,0, 0,0,0, 0,0,0, 0,0,0] |
+ bmp = bitmap.Bitmap(3, 4, 3, pixels) |
+ box, count = bmp.GetBoundingBox(bitmap.RgbaColor(1, 0, 0)) |
tonyg
2013/12/12 22:17:48
Should this really return count? I don't understan
szym
2013/12/12 22:54:12
See Tab.StopVideoCapture. Checking pixel count is
|
+ self.assertEquals(box, (1, 1, 2, 1)) |
+ self.assertEquals(count, 2) |
+ |
+ box, count = bmp.GetBoundingBox(bitmap.RgbaColor(0, 1, 0)) |
+ self.assertEquals(box, None) |
+ self.assertEquals(count, 0) |
+ |
def testCrop(self): |
pixels = [0,0,0, 0,0,0, 0,0,0, 0,0,0, |
0,0,0, 1,0,0, 1,0,0, 0,0,0, |
0,0,0, 0,0,0, 0,0,0, 0,0,0] |
bmp = bitmap.Bitmap(3, 4, 3, pixels) |
- bmp.Crop(1, 1, 2, 1) |
+ bmp.Crop((1, 1, 2, 1)) |
self.assertEquals(bmp.width, 2) |
self.assertEquals(bmp.height, 1) |
bmp.GetPixelColor(0, 0).AssertIsRGB(1, 0, 0) |
bmp.GetPixelColor(1, 0).AssertIsRGB(1, 0, 0) |
self.assertEquals(bmp.pixels, bytearray([1,0,0, 1,0,0])) |
+ |
+ def testHistogram(self): |
+ pixels = [1,2,3, 1,2,3, 1,2,3, 1,2,3, |
+ 1,2,3, 8,7,6, 5,4,6, 1,2,3, |
+ 1,2,3, 8,7,6, 5,4,6, 1,2,3] |
+ bmp = bitmap.Bitmap(3, 4, 3, pixels) |
+ bmp.Crop((1, 1, 2, 2)) |
+ |
+ histogram = bmp.ColorHistogram() |
+ self.assertEquals(sum(histogram), bmp.width * bmp.height * 3) |
+ self.assertEquals(histogram[5], 2) |
+ self.assertEquals(histogram[8], 2) |
+ self.assertEquals(histogram[4 + 256], 2) |
+ self.assertEquals(histogram[7 + 256], 2) |
+ self.assertEquals(histogram[6 + 512], 4) |