コード例 #1
0
    def testDiff(self):
        file_bmp = image_util.FromPngFile(test_png_path)
        file_bmp_2 = image_util.FromPngFile(test_png_2_path)

        diff_bmp = image_util.Diff(file_bmp, file_bmp)

        self.assertEquals(2, image_util.Width(diff_bmp))
        self.assertEquals(2, image_util.Height(diff_bmp))

        image_util.GetPixelColor(diff_bmp, 0, 0).AssertIsRGB(0, 0, 0)
        image_util.GetPixelColor(diff_bmp, 1, 1).AssertIsRGB(0, 0, 0)
        image_util.GetPixelColor(diff_bmp, 0, 1).AssertIsRGB(0, 0, 0)
        image_util.GetPixelColor(diff_bmp, 1, 0).AssertIsRGB(0, 0, 0)

        diff_bmp = image_util.Diff(file_bmp, file_bmp_2)

        self.assertEquals(3, image_util.Width(diff_bmp))
        self.assertEquals(3, image_util.Height(diff_bmp))

        image_util.GetPixelColor(diff_bmp, 0, 0).AssertIsRGB(0, 255, 255)
        image_util.GetPixelColor(diff_bmp, 1, 1).AssertIsRGB(255, 0, 255)
        image_util.GetPixelColor(diff_bmp, 0, 1).AssertIsRGB(255, 255, 0)
        image_util.GetPixelColor(diff_bmp, 1, 0).AssertIsRGB(0, 0, 255)

        image_util.GetPixelColor(diff_bmp, 0, 2).AssertIsRGB(255, 255, 255)
        image_util.GetPixelColor(diff_bmp, 1, 2).AssertIsRGB(255, 255, 255)
        image_util.GetPixelColor(diff_bmp, 2, 0).AssertIsRGB(255, 255, 255)
        image_util.GetPixelColor(diff_bmp, 2, 1).AssertIsRGB(255, 255, 255)
        image_util.GetPixelColor(diff_bmp, 2, 2).AssertIsRGB(255, 255, 255)
コード例 #2
0
    def testReadFromPngFile(self):
        file_bmp = image_util.FromPngFile(test_png_path)

        self.assertEquals(2, image_util.Width(file_bmp))
        self.assertEquals(2, image_util.Height(file_bmp))

        image_util.GetPixelColor(file_bmp, 0, 0).AssertIsRGB(255, 0, 0)
        image_util.GetPixelColor(file_bmp, 1, 1).AssertIsRGB(0, 255, 0)
        image_util.GetPixelColor(file_bmp, 0, 1).AssertIsRGB(0, 0, 255)
        image_util.GetPixelColor(file_bmp, 1, 0).AssertIsRGB(255, 255, 0)
コード例 #3
0
    def testReadFromBase64Png(self):
        bmp = image_util.FromBase64Png(test_png)

        self.assertEquals(2, image_util.Width(bmp))
        self.assertEquals(2, image_util.Height(bmp))

        image_util.GetPixelColor(bmp, 0, 0).AssertIsRGB(255, 0, 0)
        image_util.GetPixelColor(bmp, 1, 1).AssertIsRGB(0, 255, 0)
        image_util.GetPixelColor(bmp, 0, 1).AssertIsRGB(0, 0, 255)
        image_util.GetPixelColor(bmp, 1, 0).AssertIsRGB(255, 255, 0)
コード例 #4
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 = image_util.FromRGBPixels(4, 3, pixels)
    bmp = image_util.Crop(bmp, 1, 2, 2, 1)

    self.assertEquals(2, image_util.Width(bmp))
    self.assertEquals(1, image_util.Height(bmp))
    image_util.GetPixelColor(bmp, 0, 0).AssertIsRGB(1, 2, 0)
    image_util.GetPixelColor(bmp, 1, 0).AssertIsRGB(2, 2, 0)
    self.assertEquals(image_util.Pixels(bmp), bytearray([1, 2, 0, 2, 2, 0]))
コード例 #5
0
def _CompareScreenshotSamples(screenshot, expectations, device_pixel_ratio):
    for expectation in expectations:
        location = expectation["location"]
        x = int(location[0] * device_pixel_ratio)
        y = int(location[1] * device_pixel_ratio)

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

        actual_color = image_util.GetPixelColor(screenshot, x, y)
        expected_color = rgba_color.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 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 = image_util.FromRGBPixels(4, 3, pixels)
    bmp = image_util.Crop(bmp, 1, 1, 2, 2)

    hist = image_util.GetColorHistogram(bmp)
    for i in xrange(3):
      self.assertEquals(sum(hist[i]),
                        image_util.Width(bmp) * image_util.Height(bmp))
    self.assertEquals(hist.r[1], 0)
    self.assertEquals(hist.r[5], 2)
    self.assertEquals(hist.r[8], 2)
    self.assertEquals(hist.g[2], 0)
    self.assertEquals(hist.g[4], 2)
    self.assertEquals(hist.g[7], 2)
    self.assertEquals(hist.b[3], 0)
    self.assertEquals(hist.b[6], 4)