Skip to content

Commit

Permalink
Rearranged subsampling assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere authored and bgilbert committed Nov 27, 2023
1 parent ae1d5e6 commit 9ea6d9e
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@ def test_rgb(self):
def getchannels(im):
return tuple(v[0] for v in im.layer)

im = self.roundtrip(hopper())
assert getchannels(im) == (1, 2, 3)
im = self.roundtrip(hopper(), keep_rgb=True)
assert getchannels(im) == (ord("R"), ord("G"), ord("B"))
assert_image_similar(hopper(), im, 12)
im = hopper()
im_ycbcr = self.roundtrip(im)
assert getchannels(im_ycbcr) == (1, 2, 3)

im_rgb = self.roundtrip(im, keep_rgb=True)
assert getchannels(im_rgb) == (ord("R"), ord("G"), ord("B"))
assert_image_similar(im, im_rgb, 12)

@pytest.mark.parametrize(
"test_image_path",
Expand Down Expand Up @@ -434,31 +436,26 @@ def getsampling(im):
# experimental API
im = self.roundtrip(hopper(), subsampling=-1) # default
assert getsampling(im) == (2, 2, 1, 1, 1, 1)
im = self.roundtrip(hopper(), subsampling=0) # 4:4:4
assert getsampling(im) == (1, 1, 1, 1, 1, 1)
im = self.roundtrip(hopper(), subsampling=1) # 4:2:2
assert getsampling(im) == (2, 1, 1, 1, 1, 1)
im = self.roundtrip(hopper(), subsampling=2) # 4:2:0
assert getsampling(im) == (2, 2, 1, 1, 1, 1)
for subsampling in (0, "4:4:4"):
im = self.roundtrip(hopper(), subsampling=subsampling)
assert getsampling(im) == (1, 1, 1, 1, 1, 1)
for subsampling in (1, "4:2:2"):
im = self.roundtrip(hopper(), subsampling=subsampling)
assert getsampling(im) == (2, 1, 1, 1, 1, 1)
for subsampling in (2, "4:2:0", "4:1:1"):
im = self.roundtrip(hopper(), subsampling=subsampling)
assert getsampling(im) == (2, 2, 1, 1, 1, 1)

im = self.roundtrip(hopper(), subsampling=3) # default (undefined)
assert getsampling(im) == (2, 2, 1, 1, 1, 1)

im = self.roundtrip(hopper(), subsampling="4:4:4")
# RGB colorspace, no subsampling by default
im = self.roundtrip(hopper(), subsampling=3, keep_rgb=True)
assert getsampling(im) == (1, 1, 1, 1, 1, 1)
im = self.roundtrip(hopper(), subsampling="4:2:2")
assert getsampling(im) == (2, 1, 1, 1, 1, 1)
im = self.roundtrip(hopper(), subsampling="4:2:0")
assert getsampling(im) == (2, 2, 1, 1, 1, 1)
im = self.roundtrip(hopper(), subsampling="4:1:1")
assert getsampling(im) == (2, 2, 1, 1, 1, 1)

with pytest.raises(TypeError):
self.roundtrip(hopper(), subsampling="1:1:1")

# RGB colorspace, no subsampling by default
im = self.roundtrip(hopper(), subsampling=3, keep_rgb=True)
assert getsampling(im) == (1, 1, 1, 1, 1, 1)

def test_exif(self):
with Image.open("Tests/images/pil_sample_rgb.jpg") as im:
info = im._getexif()
Expand Down

0 comments on commit 9ea6d9e

Please sign in to comment.