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

Unified Diff: tools/telemetry/telemetry/core/bitmap_unittest.py

Issue 130153003: [telemetry] Implement per-pixel algorithms in Bitmap as a C++ extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove blank from <(output_path) Created 6 years, 11 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 | « tools/telemetry/telemetry/core/bitmap.py ('k') | tools/telemetry/telemetry/core/bitmaptools/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f51e83dd16f8eb51d85ed7e9d0d7bf2e9749f0f7 100644
--- a/tools/telemetry/telemetry/core/bitmap_unittest.py
+++ b/tools/telemetry/telemetry/core/bitmap_unittest.py
@@ -70,6 +70,8 @@ class BitmapTest(unittest.TestCase):
def testIsEqual(self):
bmp = bitmap.Bitmap.FromBase64Png(test_png)
file_bmp = bitmap.Bitmap.FromPngFile(test_png_path)
+ self.assertTrue(bmp.IsEqual(file_bmp, tolerance=1))
+ # Zero tolerance IsEqual has a different implementation.
self.assertTrue(bmp.IsEqual(file_bmp))
def testDiff(self):
@@ -102,15 +104,43 @@ class BitmapTest(unittest.TestCase):
diff_bmp.GetPixelColor(2, 1).AssertIsRGB(255, 255, 255)
diff_bmp.GetPixelColor(2, 2).AssertIsRGB(255, 255, 255)
- def testCrop(self):
+ 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)
- bmp.Crop(1, 1, 2, 1)
+ box, count = bmp.GetBoundingBox(bitmap.RgbaColor(1, 0, 0))
+ 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, 1,0,0, 2,0,0, 3,0,0,
+ 0,1,0, 1,1,0, 2,1,0, 3,1,0,
+ 0,2,0, 1,2,0, 2,2,0, 3,2,0]
+ bmp = bitmap.Bitmap(3, 4, 3, pixels)
+ bmp.Crop(1, 2, 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]))
+ bmp.GetPixelColor(0, 0).AssertIsRGB(1, 2, 0)
+ bmp.GetPixelColor(1, 0).AssertIsRGB(2, 2, 0)
+ self.assertEquals(bmp.pixels, bytearray([1,2,0, 2,2,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)
« no previous file with comments | « tools/telemetry/telemetry/core/bitmap.py ('k') | tools/telemetry/telemetry/core/bitmaptools/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698