File: test_image_getprojection.py

package info (click to toggle)
pillow 8.1.2%2Bdfsg-0.3%2Bdeb11u2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 65,628 kB
  • sloc: python: 35,630; ansic: 31,009; makefile: 388; javascript: 114; sh: 77
file content (29 lines) | stat: -rw-r--r-- 956 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from PIL import Image

from .helper import hopper


def test_sanity():
    im = hopper()

    projection = im.getprojection()

    assert len(projection) == 2
    assert len(projection[0]) == im.size[0]
    assert len(projection[1]) == im.size[1]

    # 8-bit image
    im = Image.new("L", (10, 10))
    assert im.getprojection()[0] == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    assert im.getprojection()[1] == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    im.paste(255, (2, 4, 8, 6))
    assert im.getprojection()[0] == [0, 0, 1, 1, 1, 1, 1, 1, 0, 0]
    assert im.getprojection()[1] == [0, 0, 0, 0, 1, 1, 0, 0, 0, 0]

    # 32-bit image
    im = Image.new("RGB", (10, 10))
    assert im.getprojection()[0] == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    assert im.getprojection()[1] == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    im.paste(255, (2, 4, 8, 6))
    assert im.getprojection()[0] == [0, 0, 1, 1, 1, 1, 1, 1, 0, 0]
    assert im.getprojection()[1] == [0, 0, 0, 0, 1, 1, 0, 0, 0, 0]