Esempio n. 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)]])
Esempio n. 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]],
     )
Esempio n. 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]],
     )
Esempio n. 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)]])
Esempio n. 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)]])
Esempio n. 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)]])
Esempio n. 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],
     ])
Esempio n. 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],
     ])
Esempio n. 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],
     ])
Esempio n. 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)]
         ],
     )
Esempio n. 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],
     ])
Esempio n. 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],
     ])
Esempio n. 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],
     ])
Esempio n. 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)]])
Esempio n. 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],
     ])
Esempio n. 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)],
         ],
     )
Esempio n. 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)],
     ])
Esempio n. 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],
     ])
Esempio n. 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)]
         ])
Esempio n. 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],
     ])
Esempio n. 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],
     ])
Esempio n. 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)],
     ])
Esempio n. 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],
     ])
Esempio n. 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],
     ])
Esempio n. 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)],
        ])
Esempio n. 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)
         ],
     ])
Esempio n. 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]])