Skip to content

Commit d48fd92

Browse files
committed
Test stock pyheif, drop older pyheif versions
1 parent a1038de commit d48fd92

File tree

6 files changed

+26
-55
lines changed

6 files changed

+26
-55
lines changed

.github/workflows/Check.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ jobs:
1010
python: ['3.8', '3.11']
1111
pillow: [prod, latest]
1212
libheif: ['1.16.2-6ee6762-3f6b709', '1.18.2-bf35e9e-47f4fc0']
13-
pyheif: ['', '0.7.1']
13+
pyheif: ['', '0.8.0']
1414
exclude:
1515
- python: '3.11'
16-
pyheif: '0.7.1'
16+
pyheif: '0.8.0'
1717
- libheif: '1.18.2-bf35e9e-47f4fc0'
18-
pyheif: '0.7.1'
18+
pyheif: '0.8.0'
1919

2020
steps:
2121
- uses: actions/checkout@v2

HeifImagePlugin.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
from pyheif.error import HeifError
1212

1313

14-
try:
15-
from pyheif.transformations import Transformations
16-
except ImportError:
17-
Transformations = None
18-
19-
2014
@dataclass
2115
class LibheifError:
2216
code: int
@@ -159,7 +153,7 @@ def _open_heif_file(self, apply_transformations):
159153

160154
def _open(self):
161155
self.tile = []
162-
self.heif_file = self._open_heif_file(Transformations is None)
156+
self.heif_file = self._open_heif_file(False)
163157

164158
def load(self):
165159
heif_file, self.heif_file = self.heif_file, None
@@ -183,8 +177,7 @@ def load(self):
183177
self.load_prepare()
184178

185179
if heif_file.data:
186-
if Transformations is not None:
187-
heif_file = _crop_heif_file(heif_file)
180+
heif_file = _crop_heif_file(heif_file)
188181
self.frombytes(heif_file.data, "raw", (self.mode, heif_file.stride))
189182

190183
heif_file.data = None

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ This is not a big library but if you want to contribute is very easy!
5050

5151
## Changelog
5252

53-
### 0.6.3
53+
### 0.7.0
5454

55-
* Depends on pyheif>=0.8.0
55+
* Depends on pyheif>=0.8.0, drop older versions support
5656

5757
### 0.6.2
5858

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from setuptools import setup
55

66

7-
__version__ = '0.6.3'
7+
__version__ = '0.7.0'
88

99
github_url = 'https://github.com/uploadcare'
1010
package_name = 'heif-image-plugin'

tests/test_reading.py

+13-15
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import pytest
66
from PIL import Image, ImageCms, ImageOps
77
from pyheif.error import HeifError
8+
from pyheif.transformations import Transformations
89

9-
from HeifImagePlugin import Transformations, check_heif_magic
10+
from HeifImagePlugin import check_heif_magic
1011

1112
from . import avg_diff, respath
1213

@@ -69,8 +70,7 @@ def test_open_image_metadata(open_mock):
6970
m.size = (10, 20)
7071
m.mode = 'RGB'
7172
m.data = b'rgb' * 10 * 20
72-
if Transformations is not None:
73-
m.transformations = Transformations(10, 20)
73+
m.transformations = Transformations(10, 20)
7474
m.metadata = [
7575
{'type': 'foo', 'data': 'bar'},
7676
{'type': 'bar', 'data': 'foo'},
@@ -102,25 +102,23 @@ def test_check_heif_magic_wrong():
102102
def test_orientation(orientation, orientation_ref_image):
103103
image = Image.open(respath('orientation', f'Landscape_{orientation}.heic'))
104104

105-
if Transformations is not None:
106-
# There should be exif in each image, even if Orientation is 0
107-
assert 'exif' in image.info
105+
# There should be exif in each image, even if Orientation is 0
106+
assert 'exif' in image.info
108107

109-
# There should be Orientation tag for each image
110-
exif = image.getexif()
111-
assert 0x0112 in exif
108+
# There should be Orientation tag for each image
109+
exif = image.getexif()
110+
assert 0x0112 in exif
112111

113-
# And this orientation should be the same as in filename
114-
assert exif[0x0112] == orientation
112+
# And this orientation should be the same as in filename
113+
assert exif[0x0112] == orientation
115114

116115
# Transposed image shoud be Landscape
117116
transposed = ImageOps.exif_transpose(image)
118117
assert transposed.size == (600, 450)
119118

120-
if Transformations is not None:
121-
# Image should change after transposition
122-
if orientation != 1:
123-
assert image != transposed
119+
# Image should change after transposition
120+
if orientation != 1:
121+
assert image != transposed
124122

125123
# The average diff between transposed and original image should be small
126124
avg_diffs = avg_diff(transposed, orientation_ref_image, threshold=20)

tests/test_transformations.py

+5-25
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
from unittest import mock
22

3-
import pyheif
4-
import pytest
53
from PIL import Image
64
from pyheif import open as pyheif_open
7-
8-
from HeifImagePlugin import Transformations
5+
from pyheif.transformations import Transformations
96

107
from . import avg_diff, respath
118

129

13-
skip_no_transformations = pytest.mark.skipif(
14-
Transformations is None,
15-
reason="pyheif doesn't support transformations")
16-
17-
skip_libheif_not_16 = pytest.mark.skipif(
18-
pyheif.libheif_version() < '1.16.0',
19-
reason="libheif < 1.16.0 can't decode odd sizes")
20-
21-
2210
def open_with_custom_meta(path, *, exif_data=None, exif=None, crop=None, orientation=0):
2311
def my_pyheif_open(*args, **kwargs):
2412
nonlocal exif_data
@@ -32,11 +20,10 @@ def my_pyheif_open(*args, **kwargs):
3220
heif.metadata = [{'type': 'Exif', 'data': exif_data}]
3321
else:
3422
heif.metadata = None
35-
if Transformations is not None:
36-
heif.transformations = Transformations(*heif.size)
37-
heif.transformations.orientation_tag = orientation
38-
if crop:
39-
heif.transformations.crop = crop
23+
heif.transformations = Transformations(*heif.size)
24+
heif.transformations.orientation_tag = orientation
25+
if crop:
26+
heif.transformations.crop = crop
4027
return heif
4128

4229
with mock.patch('pyheif.open') as open_mock:
@@ -52,14 +39,12 @@ def test_no_orientation_and_no_exif():
5239
assert 'exif' not in image.info
5340

5441

55-
@skip_no_transformations
5642
def test_empty_exif():
5743
image = open_with_custom_meta(respath('test2.heic'), exif_data=b'', orientation=1)
5844
assert 'exif' in image.info
5945
assert image.getexif()[274] == 1
6046

6147

62-
@skip_no_transformations
6348
def test_broken_exif():
6449
broken = b'Exif\x00\x00II*\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00'
6550
image = open_with_custom_meta(respath('test2.heic'),
@@ -68,7 +53,6 @@ def test_broken_exif():
6853
assert image.getexif()[274] == 1
6954

7055

71-
@skip_no_transformations
7256
def test_orientation_and_no_exif():
7357
image = open_with_custom_meta(respath('test2.heic'), orientation=7)
7458

@@ -84,7 +68,6 @@ def test_no_orientation_and_exif_with_rotation():
8468
assert image.getexif()[274] == 7
8569

8670

87-
@skip_no_transformations
8871
def test_orientation_and_exif_with_rotation():
8972
# Orientation tag from file should suppress Exif value
9073
image = open_with_custom_meta(
@@ -94,7 +77,6 @@ def test_orientation_and_exif_with_rotation():
9477
assert image.getexif()[274] == 1
9578

9679

97-
@skip_no_transformations
9880
def test_orientation_and_exif_without_rotation():
9981
image = open_with_custom_meta(
10082
respath('test2.heic'), orientation=1, exif={270: "Sample image"})
@@ -103,7 +85,6 @@ def test_orientation_and_exif_without_rotation():
10385
assert image.getexif()[274] == 1
10486

10587

106-
@skip_no_transformations
10788
def test_crop_on_load():
10889
ref_image = Image.open(respath('test2.heic'))
10990
assert ref_image.size == (1280, 720)
@@ -117,7 +98,6 @@ def test_crop_on_load():
11798
assert image.copy() == ref_image.crop((99, 33, 611, 289))
11899

119100

120-
@skip_libheif_not_16
121101
def test_fallback_to_transforms():
122102
# Image with 695x472 color and 696x472 alpha with crop
123103
image = Image.open(respath('unreadable-wo-transf.heic'))

0 commit comments

Comments
 (0)