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))
    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)
示例#2
0
    def testHistogramDistanceIgnoreColor(self):
        pixels = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]
        bmp = bitmap.Bitmap(3, 2, 2, pixels)

        hist1 = bmp.ColorHistogram(ignore_color=bitmap.RgbaColor(1, 2, 3))
        hist2 = bmp.ColorHistogram()

        self.assertEquals(hist1.Distance(hist2), 0)
  def testHistogramIgnoreColor(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)

    histogram = bmp.ColorHistogram(ignore_color=bitmap.RgbaColor(1, 2, 3))
    self.assertEquals(histogram.r[1], 0)
    self.assertEquals(histogram.r[5], 2)
    self.assertEquals(histogram.r[8], 2)
    self.assertEquals(histogram.g[2], 0)
    self.assertEquals(histogram.g[4], 2)
    self.assertEquals(histogram.g[7], 2)
    self.assertEquals(histogram.b[3], 0)
    self.assertEquals(histogram.b[6], 4)
示例#4
0
    def testHistogramIgnoreColorTolerance(self):
        pixels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6]
        bmp = bitmap.Bitmap(3, 2, 2, pixels)

        histogram = bmp.ColorHistogram(ignore_color=bitmap.RgbaColor(0, 1, 2),
                                       tolerance=1)
        self.assertEquals(histogram.r[1], 0)
        self.assertEquals(histogram.r[4], 1)
        self.assertEquals(histogram.r[7], 1)
        self.assertEquals(histogram.r[8], 1)
        self.assertEquals(histogram.g[2], 0)
        self.assertEquals(histogram.g[5], 1)
        self.assertEquals(histogram.g[7], 1)
        self.assertEquals(histogram.g[8], 1)
        self.assertEquals(histogram.b[3], 0)
        self.assertEquals(histogram.b[6], 2)
        self.assertEquals(histogram.b[9], 1)
def _CompareScreenshotSamples(screenshot, expectations, device_pixel_ratio):
    for expectation in expectations:
        location = expectation["location"]
        x = location[0] * device_pixel_ratio
        y = location[1] * device_pixel_ratio

        if x < 0 or y < 0 or x > screenshot.width or y > screenshot.height:
            raise page_test.Failure(
                'Expected pixel location [%d, %d] is out of range on [%d, %d] image'
                % (x, y, screenshot.width, screenshot.height))

        actual_color = screenshot.GetPixelColor(x, y)
        expected_color = bitmap.RgbaColor(expectation["color"][0],
                                          expectation["color"][1],
                                          expectation["color"][2])
        if not actual_color.IsEqual(expected_color, expectation["tolerance"]):
            raise page_test.Failure('Expected pixel at ' + str(location) +
                                    ' to be ' + str(expectation["color"]) +
                                    " but got [" + str(actual_color.r) + ", " +
                                    str(actual_color.g) + ", " +
                                    str(actual_color.b) + "]")
示例#6
0
    def StopVideoCapture(self):
        """Stops recording video of the tab's contents.

    This looks for the color flash in the first frame to establish the
    tab contents boundaries and then omits that frame.

    Yields:
      (time_ms, bitmap) tuples representing each video keyframe. Only the first
      frame in a run of sequential duplicate bitmaps is included.
        time_ms is milliseconds since navigationStart.
        bitmap is a telemetry.core.Bitmap.
    """
        content_box = None
        for timestamp, bmp in self.browser.platform.StopVideoCapture():
            if not content_box:
                content_box = bmp.GetBoundingBox(
                    bitmap.RgbaColor(*_CONTENT_FLASH_COLOR), tolerance=4)

                assert content_box, 'Failed to find tab contents in first video frame.'

                # We assume arbitrarily that tabs are all larger than 200x200. If this
                # fails it either means that assumption has changed or something is
                # awry with our bounding box calculation.
                assert content_box.width > 200 and content_box.height > 200, \
                    'Unexpectedly small tab contents'

                # Since Telemetry doesn't know how to resize the window, we assume
                # that we should always get the same content box for a tab. If this
                # fails, it meas either that assumption has changed or something is
                # awry with our bounding box calculation.
                if self._previous_tab_contents_bounding_box:
                    assert self._previous_tab_contents_bounding_box == content_box, \
                        'Unexpected change in tab contents box.'
                self._previous_tab_contents_bounding_box = content_box

                continue

            bmp.Crop(content_box)
            # TODO(tonyg): Translate timestamp into navigation timing space.
            yield timestamp, bmp