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

Side by Side Diff: tools/telemetry/telemetry/core/bitmap_unittest.py

Issue 108333004: [telemetry] Implement per-pixel algorithms in Bitmap as a C++ extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: delint Created 7 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 unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import tempfile 5 import tempfile
6 import os 6 import os
7 import unittest 7 import unittest
8 8
9 from telemetry.core import bitmap 9 from telemetry.core import bitmap
10 from telemetry.core import util 10 from telemetry.core import util
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 orig = bitmap.Bitmap(3, 3, 2, pixels) 63 orig = bitmap.Bitmap(3, 3, 2, pixels)
64 orig.Crop(0, 0, 2, 2) 64 orig.Crop(0, 0, 2, 2)
65 temp_file = tempfile.NamedTemporaryFile().name 65 temp_file = tempfile.NamedTemporaryFile().name
66 orig.WritePngFile(temp_file) 66 orig.WritePngFile(temp_file)
67 new_file = bitmap.Bitmap.FromPngFile(temp_file) 67 new_file = bitmap.Bitmap.FromPngFile(temp_file)
68 self.assertTrue(orig.IsEqual(new_file)) 68 self.assertTrue(orig.IsEqual(new_file))
69 69
70 def testIsEqual(self): 70 def testIsEqual(self):
71 bmp = bitmap.Bitmap.FromBase64Png(test_png) 71 bmp = bitmap.Bitmap.FromBase64Png(test_png)
72 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path) 72 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path)
73 self.assertTrue(bmp.IsEqual(file_bmp, tolerance=1))
74 # Zero tolerance IsEqual has a different implementation.
73 self.assertTrue(bmp.IsEqual(file_bmp)) 75 self.assertTrue(bmp.IsEqual(file_bmp))
74 76
75 def testDiff(self): 77 def testDiff(self):
76 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path) 78 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path)
77 file_bmp_2 = bitmap.Bitmap.FromPngFile(test_png_2_path) 79 file_bmp_2 = bitmap.Bitmap.FromPngFile(test_png_2_path)
78 80
79 diff_bmp = file_bmp.Diff(file_bmp) 81 diff_bmp = file_bmp.Diff(file_bmp)
80 82
81 self.assertEquals(2, diff_bmp.width) 83 self.assertEquals(2, diff_bmp.width)
82 self.assertEquals(2, diff_bmp.height) 84 self.assertEquals(2, diff_bmp.height)
(...skipping 12 matching lines...) Expand all
95 diff_bmp.GetPixelColor(1, 1).AssertIsRGB(255, 0, 255) 97 diff_bmp.GetPixelColor(1, 1).AssertIsRGB(255, 0, 255)
96 diff_bmp.GetPixelColor(0, 1).AssertIsRGB(255, 255, 0) 98 diff_bmp.GetPixelColor(0, 1).AssertIsRGB(255, 255, 0)
97 diff_bmp.GetPixelColor(1, 0).AssertIsRGB(0, 0, 255) 99 diff_bmp.GetPixelColor(1, 0).AssertIsRGB(0, 0, 255)
98 100
99 diff_bmp.GetPixelColor(0, 2).AssertIsRGB(255, 255, 255) 101 diff_bmp.GetPixelColor(0, 2).AssertIsRGB(255, 255, 255)
100 diff_bmp.GetPixelColor(1, 2).AssertIsRGB(255, 255, 255) 102 diff_bmp.GetPixelColor(1, 2).AssertIsRGB(255, 255, 255)
101 diff_bmp.GetPixelColor(2, 0).AssertIsRGB(255, 255, 255) 103 diff_bmp.GetPixelColor(2, 0).AssertIsRGB(255, 255, 255)
102 diff_bmp.GetPixelColor(2, 1).AssertIsRGB(255, 255, 255) 104 diff_bmp.GetPixelColor(2, 1).AssertIsRGB(255, 255, 255)
103 diff_bmp.GetPixelColor(2, 2).AssertIsRGB(255, 255, 255) 105 diff_bmp.GetPixelColor(2, 2).AssertIsRGB(255, 255, 255)
104 106
107 def testGetBoundingBox(self):
108 pixels = [0,0,0, 0,0,0, 0,0,0, 0,0,0,
109 0,0,0, 1,0,0, 1,0,0, 0,0,0,
110 0,0,0, 0,0,0, 0,0,0, 0,0,0]
111 bmp = bitmap.Bitmap(3, 4, 3, pixels)
112 box, count = bmp.GetBoundingBox(bitmap.RgbaColor(1, 0, 0))
113 self.assertEquals(box, (1, 1, 2, 1))
114 self.assertEquals(count, 2)
115
116 box, count = bmp.GetBoundingBox(bitmap.RgbaColor(0, 1, 0))
117 self.assertEquals(box, None)
118 self.assertEquals(count, 0)
119
105 def testCrop(self): 120 def testCrop(self):
106 pixels = [0,0,0, 0,0,0, 0,0,0, 0,0,0, 121 pixels = [0,0,0, 0,0,0, 0,0,0, 0,0,0,
107 0,0,0, 1,0,0, 1,0,0, 0,0,0, 122 0,0,0, 1,0,0, 1,0,0, 0,0,0,
108 0,0,0, 0,0,0, 0,0,0, 0,0,0] 123 0,0,0, 0,0,0, 0,0,0, 0,0,0]
109 bmp = bitmap.Bitmap(3, 4, 3, pixels) 124 bmp = bitmap.Bitmap(3, 4, 3, pixels)
110 bmp.Crop(1, 1, 2, 1) 125 bmp.Crop(1, 1, 2, 1)
111 126
112 self.assertEquals(bmp.width, 2) 127 self.assertEquals(bmp.width, 2)
113 self.assertEquals(bmp.height, 1) 128 self.assertEquals(bmp.height, 1)
114 bmp.GetPixelColor(0, 0).AssertIsRGB(1, 0, 0) 129 bmp.GetPixelColor(0, 0).AssertIsRGB(1, 0, 0)
115 bmp.GetPixelColor(1, 0).AssertIsRGB(1, 0, 0) 130 bmp.GetPixelColor(1, 0).AssertIsRGB(1, 0, 0)
116 self.assertEquals(bmp.pixels, bytearray([1,0,0, 1,0,0])) 131 self.assertEquals(bmp.pixels, bytearray([1,0,0, 1,0,0]))
132
133 def testHistogram(self):
134 pixels = [1,2,3, 1,2,3, 1,2,3, 1,2,3,
135 1,2,3, 8,7,6, 5,4,6, 1,2,3,
136 1,2,3, 8,7,6, 5,4,6, 1,2,3]
137 bmp = bitmap.Bitmap(3, 4, 3, pixels)
138 bmp.Crop(1, 1, 2, 2)
139
140 histogram = bmp.ColorHistogram()
141 self.assertEquals(sum(histogram), bmp.width * bmp.height * 3)
142 self.assertEquals(histogram[5], 2)
143 self.assertEquals(histogram[8], 2)
144 self.assertEquals(histogram[4 + 256], 2)
145 self.assertEquals(histogram[7 + 256], 2)
146 self.assertEquals(histogram[6 + 512], 4)
OLDNEW
« 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