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

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: added comment that IsEqual does not compare alpha 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 orig = bitmap.Bitmap.FromPngFile(test_png_path) 54 orig = bitmap.Bitmap.FromPngFile(test_png_path)
55 temp_file = tempfile.NamedTemporaryFile().name 55 temp_file = tempfile.NamedTemporaryFile().name
56 orig.WritePngFile(temp_file) 56 orig.WritePngFile(temp_file)
57 new_file = bitmap.Bitmap.FromPngFile(temp_file) 57 new_file = bitmap.Bitmap.FromPngFile(temp_file)
58 self.assertTrue(orig.IsEqual(new_file)) 58 self.assertTrue(orig.IsEqual(new_file))
59 59
60 def testWriteCroppedBmpToPngFile(self): 60 def testWriteCroppedBmpToPngFile(self):
61 pixels = [255,0,0, 255,255,0, 0,0,0, 61 pixels = [255,0,0, 255,255,0, 0,0,0,
62 255,255,0, 0,255,0, 0,0,0] 62 255,255,0, 0,255,0, 0,0,0]
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)) 73 self.assertTrue(bmp.IsEqual(file_bmp))
74 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
74 75
75 def testDiff(self): 76 def testDiff(self):
76 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path) 77 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path)
77 file_bmp_2 = bitmap.Bitmap.FromPngFile(test_png_2_path) 78 file_bmp_2 = bitmap.Bitmap.FromPngFile(test_png_2_path)
78 79
79 diff_bmp = file_bmp.Diff(file_bmp) 80 diff_bmp = file_bmp.Diff(file_bmp)
80 81
81 self.assertEquals(2, diff_bmp.width) 82 self.assertEquals(2, diff_bmp.width)
82 self.assertEquals(2, diff_bmp.height) 83 self.assertEquals(2, diff_bmp.height)
83 84
(...skipping 11 matching lines...) Expand all
95 diff_bmp.GetPixelColor(1, 1).AssertIsRGB(255, 0, 255) 96 diff_bmp.GetPixelColor(1, 1).AssertIsRGB(255, 0, 255)
96 diff_bmp.GetPixelColor(0, 1).AssertIsRGB(255, 255, 0) 97 diff_bmp.GetPixelColor(0, 1).AssertIsRGB(255, 255, 0)
97 diff_bmp.GetPixelColor(1, 0).AssertIsRGB(0, 0, 255) 98 diff_bmp.GetPixelColor(1, 0).AssertIsRGB(0, 0, 255)
98 99
99 diff_bmp.GetPixelColor(0, 2).AssertIsRGB(255, 255, 255) 100 diff_bmp.GetPixelColor(0, 2).AssertIsRGB(255, 255, 255)
100 diff_bmp.GetPixelColor(1, 2).AssertIsRGB(255, 255, 255) 101 diff_bmp.GetPixelColor(1, 2).AssertIsRGB(255, 255, 255)
101 diff_bmp.GetPixelColor(2, 0).AssertIsRGB(255, 255, 255) 102 diff_bmp.GetPixelColor(2, 0).AssertIsRGB(255, 255, 255)
102 diff_bmp.GetPixelColor(2, 1).AssertIsRGB(255, 255, 255) 103 diff_bmp.GetPixelColor(2, 1).AssertIsRGB(255, 255, 255)
103 diff_bmp.GetPixelColor(2, 2).AssertIsRGB(255, 255, 255) 104 diff_bmp.GetPixelColor(2, 2).AssertIsRGB(255, 255, 255)
104 105
106 def testGetBoundingBox(self):
107 pixels = [0,0,0, 0,0,0, 0,0,0, 0,0,0,
108 0,0,0, 1,0,0, 1,0,0, 0,0,0,
109 0,0,0, 0,0,0, 0,0,0, 0,0,0]
110 bmp = bitmap.Bitmap(3, 4, 3, pixels)
111 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
112 self.assertEquals(box, (1, 1, 2, 1))
113 self.assertEquals(count, 2)
114
115 box, count = bmp.GetBoundingBox(bitmap.RgbaColor(0, 1, 0))
116 self.assertEquals(box, None)
117 self.assertEquals(count, 0)
118
105 def testCrop(self): 119 def testCrop(self):
106 pixels = [0,0,0, 0,0,0, 0,0,0, 0,0,0, 120 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, 121 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] 122 0,0,0, 0,0,0, 0,0,0, 0,0,0]
109 bmp = bitmap.Bitmap(3, 4, 3, pixels) 123 bmp = bitmap.Bitmap(3, 4, 3, pixels)
110 bmp.Crop(1, 1, 2, 1) 124 bmp.Crop((1, 1, 2, 1))
111 125
112 self.assertEquals(bmp.width, 2) 126 self.assertEquals(bmp.width, 2)
113 self.assertEquals(bmp.height, 1) 127 self.assertEquals(bmp.height, 1)
114 bmp.GetPixelColor(0, 0).AssertIsRGB(1, 0, 0) 128 bmp.GetPixelColor(0, 0).AssertIsRGB(1, 0, 0)
115 bmp.GetPixelColor(1, 0).AssertIsRGB(1, 0, 0) 129 bmp.GetPixelColor(1, 0).AssertIsRGB(1, 0, 0)
116 self.assertEquals(bmp.pixels, bytearray([1,0,0, 1,0,0])) 130 self.assertEquals(bmp.pixels, bytearray([1,0,0, 1,0,0]))
131
132 def testHistogram(self):
133 pixels = [1,2,3, 1,2,3, 1,2,3, 1,2,3,
134 1,2,3, 8,7,6, 5,4,6, 1,2,3,
135 1,2,3, 8,7,6, 5,4,6, 1,2,3]
136 bmp = bitmap.Bitmap(3, 4, 3, pixels)
137 bmp.Crop((1, 1, 2, 2))
138
139 histogram = bmp.ColorHistogram()
140 self.assertEquals(sum(histogram), bmp.width * bmp.height * 3)
141 self.assertEquals(histogram[5], 2)
142 self.assertEquals(histogram[8], 2)
143 self.assertEquals(histogram[4 + 256], 2)
144 self.assertEquals(histogram[7 + 256], 2)
145 self.assertEquals(histogram[6 + 512], 4)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698