22Functions and classes for heif images to read and write.
33"""
44
5- from typing import Any , Dict , Iterator , List , Union
5+ from typing import Any , Dict , Iterator , List , Optional , Union
66from weakref import ref
77
88from _pillow_heif_cffi import ffi , lib
@@ -388,15 +388,13 @@ class HeifFile:
388388
389389 .. note:: To get an empty container to fill up later, create a class with no parameters."""
390390
391- def __init__ (
392- self , heif_ctx : Union [LibHeifCtx , HeifCtxAsDict ] = None , img_ids : List [int ] = None , main_id : int = None
393- ):
394- if heif_ctx is None :
395- heif_ctx = HeifCtxAsDict ("" , (0 , 0 ), None )
391+ def __init__ (self , heif_ctx : Optional [LibHeifCtx ] = None ):
392+ self .mimetype = ""
396393 self .images : List [HeifImage ] = []
397- self .mimetype = heif_ctx .mimetype if isinstance (heif_ctx , LibHeifCtx ) else ""
398- if img_ids :
399- for img_id in img_ids :
394+ if isinstance (heif_ctx , LibHeifCtx ):
395+ self .mimetype = heif_ctx .mimetype
396+ main_id = heif_ctx .get_main_img_id ()
397+ for img_id in heif_ctx .get_top_images_ids ():
400398 self .images .append (HeifImage (heif_ctx , img_id , img_id == main_id ))
401399
402400 @property
@@ -816,8 +814,7 @@ def open_heif(fp, convert_hdr_to_8bit=True) -> HeifFile:
816814 :returns: An :py:class:`~pillow_heif.HeifFile` object.
817815 :exception HeifError: If file is corrupted or is not in Heif format."""
818816
819- heif_ctx = LibHeifCtx (fp , convert_hdr_to_8bit )
820- return HeifFile (heif_ctx , heif_ctx .get_top_images_ids (), heif_ctx .get_main_img_id ())
817+ return HeifFile (LibHeifCtx (fp , convert_hdr_to_8bit ))
821818
822819
823820def read_heif (fp , convert_hdr_to_8bit = True ) -> HeifFile :
@@ -833,9 +830,7 @@ def read_heif(fp, convert_hdr_to_8bit=True) -> HeifFile:
833830 :returns: An :py:class:`~pillow_heif.HeifFile` object.
834831 :exception HeifError: If file is corrupted or is not in Heif format."""
835832
836- heif_file = open_heif (fp , convert_hdr_to_8bit )
837- heif_file .load (everything = True )
838- return heif_file
833+ return open_heif (fp , convert_hdr_to_8bit ).load (everything = True )
839834
840835
841836def from_pillow (pil_image : Image .Image , load_one : bool = False , ignore_primary = True ) -> HeifFile :
0 commit comments