carsales / pyheif

Python 3.6+ interface to libheif library
Apache License 2.0
166 stars 41 forks source link

Get untransformed size if apply_transformations=False #67

Closed homm closed 2 years ago

homm commented 2 years ago

Related: https://github.com/carsales/pyheif/pull/51

homm commented 2 years ago

Some problems here, I'll check it.

#18 29.51         if s[0] >= 0:
#18 29.51             raise ValueError("not enough image data")
#18 29.51         if s[1] != 0:
#18 29.51 >           raise ValueError("cannot decode image data")
#18 29.51 E           ValueError: cannot decode image data
homm commented 2 years ago

So, my investigation. The error is that returned stride for both transformed and untransformed versions is the same which can't be true since stride should depend on the image width.

>>> ispe_size (4032, 3024)
>>> size (3024, 4032)
>>> (heif_file.size, stride, data_length) (3024, 4032) 9072 36578304

>>> ispe_size (4032, 3024)
>>> size (3024, 4032)
>>> (heif_file.size, stride, data_length) (4032, 3024) 9072 27433728

But I believe this is only the symptom of the real problem which is p_options.ignore_transformations flag is totally ignored by libheif (what an irony!). This was fixed only in https://github.com/strukturag/libheif/issues/498, which is not released yet. So in practice this means apply_transformations flag in pyheif is useless.

I've been using libheif's master branch from the beginning and didn't see this problem.

So I'm closing this PR until a new version on libheif will released. Also I hope "expose transformations" also will be included in the upcoming libheif release. Until this, we can show a warning that apply_transformations doesn't take any effect with the current libheif version.