OLD | NEW |
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 import test | |
10 from telemetry.core import bitmap | 9 from telemetry.core import bitmap |
11 from telemetry.core import util | 10 from telemetry.core import util |
12 | 11 |
13 | 12 |
14 # This is a simple base64 encoded 2x2 PNG which contains, in order, a single | 13 # This is a simple base64 encoded 2x2 PNG which contains, in order, a single |
15 # Red, Yellow, Blue, and Green pixel. | 14 # Red, Yellow, Blue, and Green pixel. |
16 test_png = """ | 15 test_png = """ |
17 iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91 | 16 iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91 |
18 JpzAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACx | 17 JpzAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACx |
19 MBAJqcGAAAABZJREFUCNdj/M/AwPCfgYGB4T/DfwY | 18 MBAJqcGAAAABZJREFUCNdj/M/AwPCfgYGB4T/DfwY |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 file_bmp.GetPixelColor(0, 1).AssertIsRGB(0, 0, 255) | 89 file_bmp.GetPixelColor(0, 1).AssertIsRGB(0, 0, 255) |
91 file_bmp.GetPixelColor(1, 0).AssertIsRGB(255, 255, 0) | 90 file_bmp.GetPixelColor(1, 0).AssertIsRGB(255, 255, 0) |
92 | 91 |
93 def testWritePngToPngFile(self): | 92 def testWritePngToPngFile(self): |
94 orig = bitmap.Bitmap.FromPngFile(test_png_path) | 93 orig = bitmap.Bitmap.FromPngFile(test_png_path) |
95 temp_file = tempfile.NamedTemporaryFile().name | 94 temp_file = tempfile.NamedTemporaryFile().name |
96 orig.WritePngFile(temp_file) | 95 orig.WritePngFile(temp_file) |
97 new_file = bitmap.Bitmap.FromPngFile(temp_file) | 96 new_file = bitmap.Bitmap.FromPngFile(temp_file) |
98 self.assertTrue(orig.IsEqual(new_file)) | 97 self.assertTrue(orig.IsEqual(new_file)) |
99 | 98 |
100 @test.Disabled | |
101 def testWriteCroppedBmpToPngFile(self): | 99 def testWriteCroppedBmpToPngFile(self): |
102 pixels = [255,0,0, 255,255,0, 0,0,0, | 100 pixels = [255,0,0, 255,255,0, 0,0,0, |
103 255,255,0, 0,255,0, 0,0,0] | 101 255,255,0, 0,255,0, 0,0,0] |
104 orig = bitmap.Bitmap(3, 3, 2, pixels) | 102 orig = bitmap.Bitmap(3, 3, 2, pixels) |
105 orig.Crop(0, 0, 2, 2) | 103 orig.Crop(0, 0, 2, 2) |
106 temp_file = tempfile.NamedTemporaryFile().name | 104 temp_file = tempfile.NamedTemporaryFile().name |
107 orig.WritePngFile(temp_file) | 105 orig.WritePngFile(temp_file) |
108 new_file = bitmap.Bitmap.FromPngFile(temp_file) | 106 new_file = bitmap.Bitmap.FromPngFile(temp_file) |
109 self.assertTrue(orig.IsEqual(new_file)) | 107 self.assertTrue(orig.IsEqual(new_file)) |
110 | 108 |
(...skipping 25 matching lines...) Expand all Loading... |
136 diff_bmp.GetPixelColor(1, 1).AssertIsRGB(255, 0, 255) | 134 diff_bmp.GetPixelColor(1, 1).AssertIsRGB(255, 0, 255) |
137 diff_bmp.GetPixelColor(0, 1).AssertIsRGB(255, 255, 0) | 135 diff_bmp.GetPixelColor(0, 1).AssertIsRGB(255, 255, 0) |
138 diff_bmp.GetPixelColor(1, 0).AssertIsRGB(0, 0, 255) | 136 diff_bmp.GetPixelColor(1, 0).AssertIsRGB(0, 0, 255) |
139 | 137 |
140 diff_bmp.GetPixelColor(0, 2).AssertIsRGB(255, 255, 255) | 138 diff_bmp.GetPixelColor(0, 2).AssertIsRGB(255, 255, 255) |
141 diff_bmp.GetPixelColor(1, 2).AssertIsRGB(255, 255, 255) | 139 diff_bmp.GetPixelColor(1, 2).AssertIsRGB(255, 255, 255) |
142 diff_bmp.GetPixelColor(2, 0).AssertIsRGB(255, 255, 255) | 140 diff_bmp.GetPixelColor(2, 0).AssertIsRGB(255, 255, 255) |
143 diff_bmp.GetPixelColor(2, 1).AssertIsRGB(255, 255, 255) | 141 diff_bmp.GetPixelColor(2, 1).AssertIsRGB(255, 255, 255) |
144 diff_bmp.GetPixelColor(2, 2).AssertIsRGB(255, 255, 255) | 142 diff_bmp.GetPixelColor(2, 2).AssertIsRGB(255, 255, 255) |
145 | 143 |
146 @test.Disabled | |
147 def testGetBoundingBox(self): | 144 def testGetBoundingBox(self): |
148 pixels = [0,0,0, 0,0,0, 0,0,0, 0,0,0, | 145 pixels = [0,0,0, 0,0,0, 0,0,0, 0,0,0, |
149 0,0,0, 1,0,0, 1,0,0, 0,0,0, | 146 0,0,0, 1,0,0, 1,0,0, 0,0,0, |
150 0,0,0, 0,0,0, 0,0,0, 0,0,0] | 147 0,0,0, 0,0,0, 0,0,0, 0,0,0] |
151 bmp = bitmap.Bitmap(3, 4, 3, pixels) | 148 bmp = bitmap.Bitmap(3, 4, 3, pixels) |
152 box, count = bmp.GetBoundingBox(bitmap.RgbaColor(1, 0, 0)) | 149 box, count = bmp.GetBoundingBox(bitmap.RgbaColor(1, 0, 0)) |
153 self.assertEquals(box, (1, 1, 2, 1)) | 150 self.assertEquals(box, (1, 1, 2, 1)) |
154 self.assertEquals(count, 2) | 151 self.assertEquals(count, 2) |
155 | 152 |
156 box, count = bmp.GetBoundingBox(bitmap.RgbaColor(0, 1, 0)) | 153 box, count = bmp.GetBoundingBox(bitmap.RgbaColor(0, 1, 0)) |
157 self.assertEquals(box, None) | 154 self.assertEquals(box, None) |
158 self.assertEquals(count, 0) | 155 self.assertEquals(count, 0) |
159 | 156 |
160 @test.Disabled | |
161 def testCrop(self): | 157 def testCrop(self): |
162 pixels = [0,0,0, 1,0,0, 2,0,0, 3,0,0, | 158 pixels = [0,0,0, 1,0,0, 2,0,0, 3,0,0, |
163 0,1,0, 1,1,0, 2,1,0, 3,1,0, | 159 0,1,0, 1,1,0, 2,1,0, 3,1,0, |
164 0,2,0, 1,2,0, 2,2,0, 3,2,0] | 160 0,2,0, 1,2,0, 2,2,0, 3,2,0] |
165 bmp = bitmap.Bitmap(3, 4, 3, pixels) | 161 bmp = bitmap.Bitmap(3, 4, 3, pixels) |
166 bmp.Crop(1, 2, 2, 1) | 162 bmp.Crop(1, 2, 2, 1) |
167 | 163 |
168 self.assertEquals(bmp.width, 2) | 164 self.assertEquals(bmp.width, 2) |
169 self.assertEquals(bmp.height, 1) | 165 self.assertEquals(bmp.height, 1) |
170 bmp.GetPixelColor(0, 0).AssertIsRGB(1, 2, 0) | 166 bmp.GetPixelColor(0, 0).AssertIsRGB(1, 2, 0) |
171 bmp.GetPixelColor(1, 0).AssertIsRGB(2, 2, 0) | 167 bmp.GetPixelColor(1, 0).AssertIsRGB(2, 2, 0) |
172 self.assertEquals(bmp.pixels, bytearray([1,2,0, 2,2,0])) | 168 self.assertEquals(bmp.pixels, bytearray([1,2,0, 2,2,0])) |
173 | 169 |
174 @test.Disabled | |
175 def testHistogram(self): | 170 def testHistogram(self): |
176 pixels = [1,2,3, 1,2,3, 1,2,3, 1,2,3, | 171 pixels = [1,2,3, 1,2,3, 1,2,3, 1,2,3, |
177 1,2,3, 8,7,6, 5,4,6, 1,2,3, | 172 1,2,3, 8,7,6, 5,4,6, 1,2,3, |
178 1,2,3, 8,7,6, 5,4,6, 1,2,3] | 173 1,2,3, 8,7,6, 5,4,6, 1,2,3] |
179 bmp = bitmap.Bitmap(3, 4, 3, pixels) | 174 bmp = bitmap.Bitmap(3, 4, 3, pixels) |
180 bmp.Crop(1, 1, 2, 2) | 175 bmp.Crop(1, 1, 2, 2) |
181 | 176 |
182 histogram = bmp.ColorHistogram() | 177 histogram = bmp.ColorHistogram() |
183 for i in xrange(3): | 178 for i in xrange(3): |
184 self.assertEquals(sum(histogram[i]), bmp.width * bmp.height) | 179 self.assertEquals(sum(histogram[i]), bmp.width * bmp.height) |
185 self.assertEquals(histogram.r[1], 0) | 180 self.assertEquals(histogram.r[1], 0) |
186 self.assertEquals(histogram.r[5], 2) | 181 self.assertEquals(histogram.r[5], 2) |
187 self.assertEquals(histogram.r[8], 2) | 182 self.assertEquals(histogram.r[8], 2) |
188 self.assertEquals(histogram.g[2], 0) | 183 self.assertEquals(histogram.g[2], 0) |
189 self.assertEquals(histogram.g[4], 2) | 184 self.assertEquals(histogram.g[4], 2) |
190 self.assertEquals(histogram.g[7], 2) | 185 self.assertEquals(histogram.g[7], 2) |
191 self.assertEquals(histogram.b[3], 0) | 186 self.assertEquals(histogram.b[3], 0) |
192 self.assertEquals(histogram.b[6], 4) | 187 self.assertEquals(histogram.b[6], 4) |
193 | 188 |
194 @test.Disabled | |
195 def testHistogramIgnoreColor(self): | 189 def testHistogramIgnoreColor(self): |
196 pixels = [1,2,3, 1,2,3, 1,2,3, 1,2,3, | 190 pixels = [1,2,3, 1,2,3, 1,2,3, 1,2,3, |
197 1,2,3, 8,7,6, 5,4,6, 1,2,3, | 191 1,2,3, 8,7,6, 5,4,6, 1,2,3, |
198 1,2,3, 8,7,6, 5,4,6, 1,2,3] | 192 1,2,3, 8,7,6, 5,4,6, 1,2,3] |
199 bmp = bitmap.Bitmap(3, 4, 3, pixels) | 193 bmp = bitmap.Bitmap(3, 4, 3, pixels) |
200 | 194 |
201 histogram = bmp.ColorHistogram(ignore_color=bitmap.RgbaColor(1, 2, 3)) | 195 histogram = bmp.ColorHistogram(ignore_color=bitmap.RgbaColor(1, 2, 3)) |
202 self.assertEquals(histogram.r[1], 0) | 196 self.assertEquals(histogram.r[1], 0) |
203 self.assertEquals(histogram.r[5], 2) | 197 self.assertEquals(histogram.r[5], 2) |
204 self.assertEquals(histogram.r[8], 2) | 198 self.assertEquals(histogram.r[8], 2) |
205 self.assertEquals(histogram.g[2], 0) | 199 self.assertEquals(histogram.g[2], 0) |
206 self.assertEquals(histogram.g[4], 2) | 200 self.assertEquals(histogram.g[4], 2) |
207 self.assertEquals(histogram.g[7], 2) | 201 self.assertEquals(histogram.g[7], 2) |
208 self.assertEquals(histogram.b[3], 0) | 202 self.assertEquals(histogram.b[3], 0) |
209 self.assertEquals(histogram.b[6], 4) | 203 self.assertEquals(histogram.b[6], 4) |
210 | 204 |
211 @test.Disabled | |
212 def testHistogramIgnoreColorTolerance(self): | 205 def testHistogramIgnoreColorTolerance(self): |
213 pixels = [1,2,3, 4,5,6, | 206 pixels = [1,2,3, 4,5,6, |
214 7,8,9, 8,7,6] | 207 7,8,9, 8,7,6] |
215 bmp = bitmap.Bitmap(3, 2, 2, pixels) | 208 bmp = bitmap.Bitmap(3, 2, 2, pixels) |
216 | 209 |
217 histogram = bmp.ColorHistogram(ignore_color=bitmap.RgbaColor(0, 1, 2), | 210 histogram = bmp.ColorHistogram(ignore_color=bitmap.RgbaColor(0, 1, 2), |
218 tolerance=1) | 211 tolerance=1) |
219 self.assertEquals(histogram.r[1], 0) | 212 self.assertEquals(histogram.r[1], 0) |
220 self.assertEquals(histogram.r[4], 1) | 213 self.assertEquals(histogram.r[4], 1) |
221 self.assertEquals(histogram.r[7], 1) | 214 self.assertEquals(histogram.r[7], 1) |
222 self.assertEquals(histogram.r[8], 1) | 215 self.assertEquals(histogram.r[8], 1) |
223 self.assertEquals(histogram.g[2], 0) | 216 self.assertEquals(histogram.g[2], 0) |
224 self.assertEquals(histogram.g[5], 1) | 217 self.assertEquals(histogram.g[5], 1) |
225 self.assertEquals(histogram.g[7], 1) | 218 self.assertEquals(histogram.g[7], 1) |
226 self.assertEquals(histogram.g[8], 1) | 219 self.assertEquals(histogram.g[8], 1) |
227 self.assertEquals(histogram.b[3], 0) | 220 self.assertEquals(histogram.b[3], 0) |
228 self.assertEquals(histogram.b[6], 2) | 221 self.assertEquals(histogram.b[6], 2) |
229 self.assertEquals(histogram.b[9], 1) | 222 self.assertEquals(histogram.b[9], 1) |
230 | 223 |
231 @test.Disabled | |
232 def testHistogramDistanceIgnoreColor(self): | 224 def testHistogramDistanceIgnoreColor(self): |
233 pixels = [1,2,3, 1,2,3, | 225 pixels = [1,2,3, 1,2,3, |
234 1,2,3, 1,2,3] | 226 1,2,3, 1,2,3] |
235 bmp = bitmap.Bitmap(3, 2, 2, pixels) | 227 bmp = bitmap.Bitmap(3, 2, 2, pixels) |
236 | 228 |
237 hist1 = bmp.ColorHistogram(ignore_color=bitmap.RgbaColor(1, 2, 3)) | 229 hist1 = bmp.ColorHistogram(ignore_color=bitmap.RgbaColor(1, 2, 3)) |
238 hist2 = bmp.ColorHistogram() | 230 hist2 = bmp.ColorHistogram() |
239 | 231 |
240 self.assertEquals(hist1.Distance(hist2), 0) | 232 self.assertEquals(hist1.Distance(hist2), 0) |
OLD | NEW |