예제 #1
0
    def test_resize_bilinear_down_simple_completely_transparent(self):
        transparent = Color(255, 255, 255, 0)
        img = image_factory([[transparent, transparent], [transparent, transparent]])
        img = img.resize(1, 1, resample_algorithm=bilinear)

        # testing this because a naive implementation can cause div/0 error
        self.assertImage(img, [[Color(0, 0, 0, 0)]])
예제 #2
0
 def test_resize_bilinear_up_simple(self):
     img = image_factory([[Red, Blue], [Blue, Green]])
     img = img.resize(4, 4, resample_algorithm=bilinear)
     self.assertImage(
         img,
         [[Red, Red, Blue, Blue], [Red, Red, Blue, Blue], [Blue, Blue, Green, Green], [Blue, Blue, Green, Green]],
     )
예제 #3
0
 def test_resize_nearest_up(self):
     img = image_factory([[Red, Blue], [Blue, Green]])
     img = img.resize(4, 4)
     self.assertImage(
         img,
         [[Red, Red, Blue, Blue], [Red, Red, Blue, Blue], [Blue, Blue, Green, Green], [Blue, Blue, Green, Green]],
     )
예제 #4
0
    def test_resize_bilinear_down_proportional_transparent(self):
        transparent = Color(255, 255, 255, 0)
        img = image_factory([[Red, Red, transparent], [Red, Red, transparent], [transparent, transparent, transparent]])
        img = img.resize(2, 2, resample_algorithm=bilinear)

        #  - the alpha values get blended equally.
        #  - all non-alpha channels get multiplied by their alpha, so the
        #    transparent pixel does not contribute to the result.
        self.assertImage(img, [[Red, Color(255, 0, 0, 64)], [Color(255, 0, 0, 64), Color(255, 0, 0, 16)]])
예제 #5
0
    def test_resize_bilinear_down_simple_transparent(self):
        transparent = Color(255, 255, 255, 0)
        img = image_factory([[Red, Blue], [Blue, transparent]])
        img = img.resize(1, 1, resample_algorithm=bilinear)

        #  - the alpha values get blended equally.
        #  - all non-alpha channels get multiplied by their alpha, so the
        #    transparent pixel does not contribute to the result.
        self.assertImage(img, [[Color(85, 0, 170, 191)]])
예제 #6
0
    def test_resize_bilinear_down_simple_completely_transparent(self):
        img = image_factory([
            [transparent, transparent],
            [transparent, transparent],
        ])
        img = img.resize(1, 1, resample_algorithm=bilinear)

        # testing this because a naive implementation can cause div/0 error
        self.assertImage(img, [[Color(0, 0, 0, 0)]])
예제 #7
0
 def test_resize_bilinear_no_change(self):
     img = image_factory([
         [Red, Blue],
         [Blue, Green],
     ])
     img = img.resize(2, 2, resample_algorithm=bilinear)
     self.assertImage(img, [
         [Red, Blue],
         [Blue, Green],
     ])
예제 #8
0
 def test_resize_bilinear_no_change(self):
     img = image_factory([
         [Red, Blue],
         [Blue, Green],
     ])
     img = img.resize(2, 2, resample_algorithm=bilinear)
     self.assertImage(img, [
         [Red, Blue],
         [Blue, Green],
     ])
예제 #9
0
 def test_affine_rotate_bilinear_90(self):
     img = image_factory([
         [Red, Blue],
         [Blue, Blue],
     ])
     img = img.rotate(90, resample_algorithm=bilinear)
     self.assertImage(img, [
         [Blue, Blue],
         [Red, Blue],
     ])
예제 #10
0
 def test_resize_bilinear_down_simple(self):
     img = image_factory([[Red, Blue], [Blue, Green]])
     img = img.resize(1, 1, resample_algorithm=bilinear)
     self.assertImage(
         img,
         [
             # all the colors blended equally
             [Color(64, 32, 128, 255)]
         ],
     )
예제 #11
0
 def test_affine_rotate_nearest_90(self):
     img = image_factory([
         [Red, Blue],
         [Blue, Blue],
     ])
     img = img.rotate(90)
     self.assertImage(img, [
         [Blue, Blue],
         [Red, Blue],
     ])
예제 #12
0
 def test_affine_rotate_nearest_90(self):
     img = image_factory([
         [Red, Blue],
         [Blue, Blue],
     ])
     img = img.rotate(90)
     self.assertImage(img, [
         [Blue, Blue],
         [Red, Blue],
     ])
예제 #13
0
 def test_affine_rotate_bilinear_90(self):
     img = image_factory([
         [Red, Blue],
         [Blue, Blue],
     ])
     img = img.rotate(90, resample_algorithm=bilinear)
     self.assertImage(img, [
         [Blue, Blue],
         [Red, Blue],
     ])
예제 #14
0
    def test_resize_bilinear_down_simple_transparent(self):
        img = image_factory([
            [Red, Blue],
            [Blue, transparent],
        ])
        img = img.resize(1, 1, resample_algorithm=bilinear)

        #  - the alpha values get blended equally.
        #  - all non-alpha channels get multiplied by their alpha, so the
        #    transparent pixel does not contribute to the result.
        self.assertImage(img, [[Color(85, 0, 170, 191)]])
예제 #15
0
 def test_resize_nearest_down_transparent(self):
     img = image_factory([
         [Red, Green, Blue],
         [Green, Blue, Red],
         [Blue, Red, transparent],
     ])
     img = img.resize(2, 2)
     self.assertImage(img, [
         [Red, Blue],
         [Blue, transparent],
     ])
예제 #16
0
 def test_resize_bilinear_up_proportional(self):
     img = image_factory([[Red, Blue], [Blue, Green]])
     img = img.resize(3, 3, resample_algorithm=bilinear)
     self.assertImage(
         img,
         [
             [(177, 4, 71, 255), (106, 11, 128, 255), (0, 21, 212, 255)],
             [(106, 11, 128, 255), (64, 32, 128, 255), (0, 64, 128, 255)],
             [(0, 21, 212, 255), (0, 64, 128, 255), (0, 128, 0, 255)],
         ],
     )
예제 #17
0
 def test_resize_bilinear_down_proportional(self):
     img = image_factory([
         [Red, Red, Blue],
         [Red, Red, Blue],
         [Blue, Blue, Blue],
     ])
     img = img.resize(2, 2, resample_algorithm=bilinear)
     self.assertImage(img, [
         [Red, Color(64, 0, 191, 255)],
         [Color(64, 0, 191, 255), Color(16, 0, 239, 255)],
     ])
예제 #18
0
 def test_resize_nearest_down_transparent(self):
     img = image_factory([
         [Red, Green, Blue],
         [Green, Blue, Red],
         [Blue, Red, transparent],
     ])
     img = img.resize(2, 2)
     self.assertImage(img, [
         [Red, Blue],
         [Blue, transparent],
     ])
예제 #19
0
 def test_resize_bilinear_down_simple(self):
     img = image_factory([
         [Red, Blue],
         [Blue, Green],
     ])
     img = img.resize(1, 1, resample_algorithm=bilinear)
     self.assertImage(
         img,
         [
             # all the colors blended equally
             [Color(64, 32, 128, 255)]
         ])
예제 #20
0
 def test_resize_nearest_up(self):
     img = image_factory([
         [Red, Blue],
         [Blue, Green],
     ])
     img = img.resize(4, 4)
     self.assertImage(img, [
         [Red, Red, Blue, Blue],
         [Red, Red, Blue, Blue],
         [Blue, Blue, Green, Green],
         [Blue, Blue, Green, Green],
     ])
예제 #21
0
 def test_resize_bilinear_up_simple(self):
     img = image_factory([
         [Red, Blue],
         [Blue, Green],
     ])
     img = img.resize(4, 4, resample_algorithm=bilinear)
     self.assertImage(img, [
         [Red, Red, Blue, Blue],
         [Red, Red, Blue, Blue],
         [Blue, Blue, Green, Green],
         [Blue, Blue, Green, Green],
     ])
예제 #22
0
 def test_resize_bilinear_down_proportional(self):
     img = image_factory([
         [Red, Red, Blue],
         [Red, Red, Blue],
         [Blue, Blue, Blue],
     ])
     img = img.resize(2, 2, resample_algorithm=bilinear)
     self.assertImage(img, [
         [Red, Color(64, 0, 191, 255)],
         [Color(64, 0, 191, 255),
          Color(16, 0, 239, 255)],
     ])
예제 #23
0
 def test_transparent_background(self):
     img = image_factory([
         [Red, Red, Blue, Blue],
         [Red, Red, Blue, Blue],
         [Blue, Blue, Red, Red],
         [Blue, Blue, Red, Red],
     ])
     img = img.resize(2, 2, resize_canvas=False)
     self.assertImage(img, [
         [Red, Blue, transparent, transparent],
         [Blue, Red, transparent, transparent],
         [transparent, transparent, transparent, transparent],
         [transparent, transparent, transparent, transparent],
     ])
예제 #24
0
 def test_transparent_background(self):
     img = image_factory([
         [Red, Red, Blue, Blue],
         [Red, Red, Blue, Blue],
         [Blue, Blue, Red, Red],
         [Blue, Blue, Red, Red],
     ])
     img = img.resize(2, 2, resize_canvas=False)
     self.assertImage(img, [
         [Red, Blue, transparent, transparent],
         [Blue, Red, transparent, transparent],
         [transparent, transparent, transparent, transparent],
         [transparent, transparent, transparent, transparent],
     ])
예제 #25
0
    def test_resize_bilinear_down_proportional_transparent(self):
        img = image_factory([
            [Red, Red, transparent],
            [Red, Red, transparent],
            [transparent, transparent, transparent],
        ])
        img = img.resize(2, 2, resample_algorithm=bilinear)

        #  - the alpha values get blended equally.
        #  - all non-alpha channels get multiplied by their alpha, so the
        #    transparent pixel does not contribute to the result.
        self.assertImage(img, [
            [Red, Color(255, 0, 0, 64)],
            [Color(255, 0, 0, 64), Color(255, 0, 0, 16)],
        ])
예제 #26
0
 def test_resize_bilinear_up_proportional(self):
     img = image_factory([
         [Red, Blue],
         [Blue, Green],
     ])
     img = img.resize(3, 3, resample_algorithm=bilinear)
     self.assertImage(img, [
         [
             Color(177, 4, 71, 255),
             Color(106, 11, 128, 255),
             Color(0, 21, 212, 255)
         ],
         [
             Color(106, 11, 128, 255),
             Color(64, 32, 128, 255),
             Color(0, 64, 128, 255)
         ],
         [
             Color(0, 21, 212, 255),
             Color(0, 64, 128, 255),
             Color(0, 128, 0, 255)
         ],
     ])
예제 #27
0
 def test_resize_nearest_down(self):
     img = image_factory([[Red, Green, Blue], [Green, Blue, Red], [Blue, Red, Green]])
     img = img.resize(2, 2)
     self.assertImage(img, [[Red, Blue], [Blue, Green]])