예제 #1
0
    def _test_set_access(self, im, color):
        """Are we writing the correct bits into the image?

        Using private interfaces, forcing a capi access and
        a pyaccess for the same image"""
        caccess = im.im.pixel_access(False)
        access = PyAccess.new(im, False)

        w, h = im.size
        for x in range(0, w, 10):
            for y in range(0, h, 10):
                access[(x, y)] = color
                assert color == caccess[(x, y)]

        # Attempt to set the value on a read-only image
        access = PyAccess.new(im, True)
        with pytest.raises(ValueError):
            access[(0, 0)] = color
예제 #2
0
    def _test_set_access(self, im, color):
        """Are we writing the correct bits into the image?

        Using private interfaces, forcing a capi access and
        a pyaccess for the same image"""
        caccess = im.im.pixel_access(False)
        access = PyAccess.new(im, False)

        w, h = im.size
        for x in range(0, w, 10):
            for y in range(0, h, 10):
                access[(x, y)] = color
                self.assertEqual(color, caccess[(x, y)])

        # Attempt to set the value on a read-only image
        access = PyAccess.new(im, True)
        with self.assertRaises(ValueError):
            access[(0, 0)] = color
예제 #3
0
def _test_get_access(im):
    """ Do we get the same thing as the old pixel access """
    """ Using private interfaces, forcing a capi access and a pyaccess for the same image """
    caccess = im.im.pixel_access(False)
    access = PyAccess.new(im, False)

    w, h = im.size
    for x in range(0, w, 10):
        for y in range(0, h, 10):
            assert_equal(access[(x, y)], caccess[(x, y)])
예제 #4
0
def _test_set_access(im, color):
    """ Are we writing the correct bits into the image? """
    """ Using private interfaces, forcing a capi access and a pyaccess for the same image """
    caccess = im.im.pixel_access(False)
    access = PyAccess.new(im, False)

    w, h = im.size
    for x in range(0, w, 10):
        for y in range(0, h, 10):
            access[(x, y)] = color
            assert_equal(color, caccess[(x, y)])
예제 #5
0
def _test_get_access(im):
    """ Do we get the same thing as the old pixel access """

    """ Using private interfaces, forcing a capi access and a pyaccess for the same image """
    caccess = im.im.pixel_access(False)
    access = PyAccess.new(im, False)

    w,h = im.size
    for x in range(0,w,10):
        for y in range(0,h,10):
            assert_equal(access[(x,y)], caccess[(x,y)])
예제 #6
0
    def _test_set_access(self, im, color):
        """Are we writing the correct bits into the image?

        Using private interfaces, forcing a capi access and
        a pyaccess for the same image"""
        caccess = im.im.pixel_access(False)
        access = PyAccess.new(im, False)

        w, h = im.size
        for x in range(0, w, 10):
            for y in range(0, h, 10):
                access[(x, y)] = color
                self.assertEqual(color, caccess[(x, y)])

        # Attempt to set the value on a read-only image
        access = PyAccess.new(im, True)
        try:
            access[(0, 0)] = color
        except ValueError:
            return
        self.fail("Putpixel did not fail on a read-only image")
예제 #7
0
def _test_set_access(im, color):
    """ Are we writing the correct bits into the image? """

    """ Using private interfaces, forcing a capi access and a pyaccess for the same image """
    caccess = im.im.pixel_access(False)
    access = PyAccess.new(im, False)

    w,h = im.size
    for x in range(0,w,10):
        for y in range(0,h,10):
            access[(x,y)] = color
            assert_equal(color, caccess[(x,y)])
예제 #8
0
    def test_direct(self):
        im = hopper()
        im.load()
        # im = Image.new( "RGB", (2000, 2000), (1, 3, 2))
        caccess = im.im.pixel_access(False)
        access = PyAccess.new(im, False)

        self.assertEqual(caccess[(0, 0)], access[(0, 0)])

        print("Size: %sx%s" % im.size)
        timer(iterate_get, 'PyAccess - get', im.size, access)
        timer(iterate_set, 'PyAccess - set', im.size, access)
        timer(iterate_get, 'C-api - get', im.size, caccess)
        timer(iterate_set, 'C-api - set', im.size, caccess)
예제 #9
0
def test_direct():
    im = hopper()
    im.load()
    # im = Image.new( "RGB", (2000, 2000), (1, 3, 2))
    caccess = im.im.pixel_access(False)
    access = PyAccess.new(im, False)

    assert caccess[(0, 0)] == access[(0, 0)]

    print("Size: %sx%s" % im.size)
    timer(iterate_get, "PyAccess - get", im.size, access)
    timer(iterate_set, "PyAccess - set", im.size, access)
    timer(iterate_get, "C-api - get", im.size, caccess)
    timer(iterate_set, "C-api - set", im.size, caccess)
예제 #10
0
    def test_direct(self):
        im = hopper()
        im.load()
        # im = Image.new( "RGB", (2000, 2000), (1, 3, 2))
        caccess = im.im.pixel_access(False)
        access = PyAccess.new(im, False)

        self.assertEqual(caccess[(0, 0)], access[(0, 0)])

        print("Size: %sx%s" % im.size)
        timer(iterate_get, "PyAccess - get", im.size, access)
        timer(iterate_set, "PyAccess - set", im.size, access)
        timer(iterate_get, "C-api - get", im.size, caccess)
        timer(iterate_set, "C-api - set", im.size, caccess)
예제 #11
0
    def _test_get_access(self, im):
        """Do we get the same thing as the old pixel access

        Using private interfaces, forcing a capi access and
        a pyaccess for the same image"""
        caccess = im.im.pixel_access(False)
        access = PyAccess.new(im, False)

        w, h = im.size
        for x in range(0, w, 10):
            for y in range(0, h, 10):
                assert access[(x, y)] == caccess[(x, y)]

        # Access an out-of-range pixel
        with pytest.raises(ValueError):
            access[(access.xsize + 1, access.ysize + 1)]
예제 #12
0
    def _test_get_access(self, im):
        """Do we get the same thing as the old pixel access

        Using private interfaces, forcing a capi access and
        a pyaccess for the same image"""
        caccess = im.im.pixel_access(False)
        access = PyAccess.new(im, False)

        w, h = im.size
        for x in range(0, w, 10):
            for y in range(0, h, 10):
                self.assertEqual(access[(x, y)], caccess[(x, y)])

        # Access an out-of-range pixel
        self.assertRaises(ValueError,
                          lambda: access[(access.xsize+1, access.ysize+1)])
예제 #13
0
 def test_p_putpixel_rgb_rgba(self):
     for color in [(255, 0, 0), (255, 0, 0, 255)]:
         im = Image.new("P", (1, 1), 0)
         access = PyAccess.new(im, False)
         access.putpixel((0, 0), color)
         assert im.convert("RGB").getpixel((0, 0)) == (255, 0, 0)
예제 #14
0
 def test_not_implemented(self):
     assert PyAccess.new(hopper("BGR;15")) is None
예제 #15
0
 def test_p_putpixel_rgb_rgba(self):
     for color in [(255, 0, 0), (255, 0, 0, 255)]:
         im = Image.new("P", (1, 1), 0)
         access = PyAccess.new(im, False)
         access.putpixel((0, 0), color)
         self.assertEqual(im.convert("RGB").getpixel((0, 0)), (255, 0, 0))
예제 #16
0
 def test_not_implemented(self):
     self.assertIsNone(PyAccess.new(hopper("BGR;15")))
예제 #17
0
 def test_not_implemented(self):
     self.assertIsNone(PyAccess.new(hopper("BGR;15")))