
    MAi\                       S r SSKJr  SSKJrJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SS	KJr  SS
KJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr   SSK r  " S S5      r% " S S\%5      r& " S S\%5      r' " S S\%5      r( " S S5      r)SS jr*SS S jjr+SS S jjr,S!S jr-S"S jr.S#S jr/S$S jr0g! \! a  r"SSK#J$r$  \$" \"5      r  Sr"C"NvSr"C"ff = f)%z8Functions and classes for heif images to read and write.    )annotations)copydeepcopy)SEEK_SET)Any)Image   )options)HeifCompressionFormat)	MODE_INFO	CtxEncode	MimCImage_exif_from_pillow
_get_bytes_get_heif_meta_get_orientation_for_encoder_get_primary_index_pil_to_supported_mode_retrieve_exif_retrieve_xmp_rotate_pil_xmp_from_pillowget_file_mimetypesave_colorspace_chromaset_orientationN)DeferredErrorc                      \ rS rSr% SrS\S'    S\S'    S r\S 5       r\SS	 j5       r	\S
 5       r
SS jrSS jrSrg)	BaseImage(   z^Base class for :py:class:`HeifImage`, :py:class:`HeifDepthImage` and :py:class:`HeifAuxImage`.tuple[int, int]sizestrmodec                P    UR                   u  U l        U l        Xl        S U l        g N)	size_moder!   r#   _c_image_data)selfc_images     H/var/www/html/land-ocr/venv/lib/python3.13/site-packages/pi_heif/heif.py__init__BaseImage.__init__4   s"    &00	49
    c                :    U R                  5         U R                  $ )zQDecodes image and returns image data.

:returns: ``bytes`` of the decoded image.
)loadr(   r)   s    r+   dataBaseImage.data9   s     			zzr.   c                N    U R                  5         U R                  R                  $ )zStride of the image.

.. note:: from `0.10.0` version this value always will have width * sizeof pixel in default usage mode.

:returns: An Int value indicating the image stride after decoding.
)r0   r'   strider1   s    r+   r5   BaseImage.strideB   s     			}}###r.   c                ~   U R                  5         [        U R                  [        U R                     S   -  5      n[        U R                     S   S::  a  SnO[        US-  5      nSnU R
                  S   U4n[        U R                     S   S:  a  U[        U R                     S   4-  nX2SU R                  S.$ )	zNumpy array interface support.r   r	      z|u1   z<u2   )shapetypestrversionr2   )r0   intr5   r   r#   r!   r2   )r)   widthr<   r;   s       r+   __array_interface__BaseImage.__array_interface__M   s     			DKK)DII"6q"99:TYY"a'G	NEG"&))A,!6TYY"Q&i		*1-//Eq$))TTr.   c                    U R                  5         [        R                  " U R                  U R                  U R
                  SU R                  U R                  5      $ )Helper method to create :external:py:class:`~PIL.Image.Image` class.

:returns: :external:py:class:`~PIL.Image.Image` class created from an image.
raw)r0   r   	frombytesr#   r!   r2   r5   r1   s    r+   	to_pillowBaseImage.to_pillow\   sD    
 			IIIIIIIIKK
 	
r.   c                    U R                   (       d:  U R                  R                  U l         U R                  R                  u  U l        ngg)zMethod to decode image.

.. note:: In normal cases, you should not call this method directly,
    when reading `data` or `stride` property of image will be loaded automatically.
N)r(   r'   r2   r&   r!   )r)   _s     r+   r0   BaseImage.loadk   s6     zz++DJ==22LDIq r.   )r'   r(   r#   r!   N)returnr>   rK   Image.ImagerK   None)__name__
__module____qualname____firstlineno____doc____annotations__r,   propertyr2   r5   r@   rF   r0   __static_attributes__ r.   r+   r   r   (   sf    h
(
IL

   $ $ U U
3r.   r   c                  B   ^  \ rS rSrSrU 4S jrS rSU 4S jjrSrU =r	$ )HeifDepthImagev   z\Class representing the depth image associated with the :py:class:`~pi_heif.HeifImage` class.c                x   > [         TU ]  U5        UR                  nSU0U l        [	        XR                  5        g )Nmetadata)superr,   r]   infor   )r)   r*   r]   	__class__s      r+   r,   HeifDepthImage.__init__y   s7    ! ))
	 	w		2r.   c           	         SU R                   R                   SU R                  S    SU R                  S    SU R                   S3	$ N< r   xr	   >r`   rP   r!   r#   r1   s    r+   __repr__HeifDepthImage.__repr__   C    4>>**+1TYYq\N!DIIaL>499+UVWWr.   c                b   > [         TU ]  5       nU R                  R                  5       Ul        U$ )rC   )r^   rF   r_   r   r)   imager`   s     r+   rF   HeifDepthImage.to_pillow   s)    
 !#YY^^%
r.   )r_   rL   )
rP   rQ   rR   rS   rT   r,   ri   rF   rW   __classcell__r`   s   @r+   rZ   rZ   v   s    f3X r.   rZ   c                      \ rS rSrSrS rSrg)HeifAuxImage   z`Class representing the auxiliary image associated with the :py:class:`~pi_heif.HeifImage` class.c           	         SU R                   R                   SU R                  S    SU R                  S    SU R                   S3	$ rc   rh   r1   s    r+   ri   HeifAuxImage.__repr__   rk   r.   rX   N)rP   rQ   rR   rS   rT   ri   rW   rX   r.   r+   rs   rs      s    jXr.   rs   c                     ^  \ rS rSrSrU 4S jrS r\SS j5       r\SS j5       r	\	R                  SS j5       r	SU 4S jjrSS	 jrS
rU =r$ )	HeifImage   z7One image in a :py:class:`~pi_heif.HeifFile` container.c                  > [         TU ]  U5        UR                  n[        U5      n[	        U5      n[
        R                  (       a!  UR                   Vs/ s H	  oUc  M  UPM     snO/ n[
        R                  (       a*  UR                   Vs/ s H  oUc  M  [        U5      PM     snO/ n[        UR                  5      [        UR                  5      UUUUS.U l        [
        R                   (       aP  0 nUR"                   H0  n	UR%                  U	5      n
X;  a  / X'   X   R'                  U	5        M2     XR                  S'   [)        U5      nU(       a  X@R                  S'   U(       a  XR                  S'   [+        XR                  5        UR,                  nU(       aA  US   S;   a%  US   U R                  S'   US   U R                  S	'   g US   U R                  S
'   g g s  snf s  snf )N)primary	bit_depthexifr]   
thumbnailsdepth_imagesauxxmpheiftype)rICCprofr2   icc_profileicc_profile_typenclx_profile)r^   r,   r]   r   r   r
   
THUMBNAILSr~   DEPTH_IMAGESdepth_image_listrZ   boolr{   r>   r|   r_   
AUX_IMAGESaux_image_idsget_aux_typeappendr   r   color_profile)r)   r*   r]   r}   r   ir~   r   ctx_aux_infoaux_idaux_type	heif_metar   r`   s                r+   r,   HeifImage.__init__   s   !&//h'H%[b[m[m73E3E'W3Ea3E'Wsu
V]VjVj(@(@R(@1^A(@Rpr 	 GOO,W../ $(
	 L!//"//7/-/L*&--f5	 0
  ,IIe"7+	"IIe )IIfw		2(/(=(=V$(88+8+@		-(0=f0E		,-,9&,A		.) 7 (XRs   G$ G$G)G)c                v   U R                   (       d  [        U R                  [        5      (       a  [	        U R
                  5       S3OSnSU R                  R                   SU R                  S    SU R                  S    SU R                   SU S	[	        U R                  R                  S
/ 5      5       S3$ )Nz bytesnord   re   r   rf   r	    with z image data and r~   z thumbnails>)r(   
isinstancer'   r   lenr2   r`   rP   r!   r#   r_   get)r)   s_bytess     r+   ri   HeifImage.__repr__   s    /3zzZW`=a=aS^$F+gk''($))A,q1a		{ S9,S|R1P-Q,RR^`	
r.   c                F    U R                   R                  SS9S   S   S;   $ )zD``True`` for images with the ``alpha`` channel, ``False`` otherwise.;sepr   )Aa)r#   splitr1   s    r+   	has_alphaHeifImage.has_alpha   s(     yy3'*2.*<<r.   c                X    [        U R                  R                  SS9S   S   S:H  5      $ )zN``True`` for images with ``premultiplied alpha`` channel, ``False`` otherwise.r   r   r   r   r   )r   r#   r   r1   s    r+   premultiplied_alphaHeifImage.premultiplied_alpha   s-     DIIOOO,Q/3s:;;r.   c                    U R                   (       a4  U R                  R                  U(       a  SOSU(       a  SOS5      U l        g g )Nr   r   )r   r#   replacer)   values     r+   r   r      s/    >>		))#CSVWDI r.   c                   > [         TU ]  5       nU R                  R                  5       Ul        [	        UR                  5      UR                  S'   U$ )rC   original_orientation)r^   rF   r_   r   r   rm   s     r+   rF   HeifImage.to_pillow   sA    
 !#YY^^%
-<UZZ-H

)*r.   c                N    U R                   R                  U5      n[        U5      $ )zwMethod to retrieve the auxiliary image at the given ID.

:returns: a :py:class:`~pi_heif.HeifAuxImage` class instance.
)r'   get_aux_imagers   )r)   r   	aux_images      r+   r   HeifImage.get_aux_image   s#    
 MM//7	I&&r.   )r_   r#   rK   r   r   r   rL   )r   r>   rK   rs   )rP   rQ   rR   rS   rT   r,   ri   rV   r   r   setterrF   r   rW   rp   rq   s   @r+   rx   rx      se    A%BN
 = = < < X  X' 'r.   rx   c                  6   \ rS rSrSrSS jr\S 5       r\S 5       r\S 5       r	\S 5       r
\
R                  SS	 j5       r
\S
 5       r\S 5       r\S 5       rSS jrS S jrS rS rS rS rS rS!S jrS"S jrS#S jr\S 5       rS rS rS rS r\rSrg)$HeifFile   a  Representation of the :py:class:`~pi_heif.HeifImage` classes container.

To create :py:class:`~pi_heif.HeifFile` object, use the appropriate factory functions.

* :py:func:`~pi_heif.open_heif`
* :py:func:`~pi_heif.read_heif`
* :py:func:`~pi_heif.from_pillow`
* :py:func:`~pi_heif.from_bytes`

Exceptions that can be raised when working with methods:
    `ValueError`, `EOFError`, `SyntaxError`, `RuntimeError`, `OSError`
Nc                   [        US5      (       a  UR                  S[        5        Uc  / nSnGO[        U5      n[	        U5      nUR                  S5      S:w  a!  [        R                  R                  SS5      nOMUR                  S5      S:w  d  UR                  S5      S:w  a!  [        R                  R                  S	S5      nOSn[        R                  " U[        R                  UUUR                  S
S5      UR                  SS5      UR                  S[        R                  5      U[        R                  5	      nX`l        U V	s/ s H  oc  M  [        U	5      PM     sn	U l        SU l        [%        U R                   5       H.  u  pUR&                  R                  SS5      (       d  M(  Xl        M0     g s  sn	f )Nseekr    avifr   AVIFheicr   HEIFremove_strideThdr_to_16bitreload_sizer{   F)hasattrr   r   r   r   findr
   PREFERRED_DECODERr   _pi_heif	load_fileDECODE_THREADSALLOW_INCORRECT_HEADERSDISABLE_SECURITY_LIMITSmimetyperx   _imagesprimary_index	enumerater_   )r)   fpconvert_hdr_to_8bitbgr_modekwargsimagesr   fp_bytespreferred_decoderr   indexrI   s               r+   r,   HeifFile.__init__   sh   2vGGAx :FH!"~H(2H}}V$*$+$=$=$A$A&"$M!v&",f0E0K$+$=$=$A$A&"$M!$&!''&&#

?D1

>40

='*I*IJ!//
F !?E(Wv!1v(W!$,,/HEvvzz)U++%*" 0 )Xs   F<F<c                H    U R                   U R                     R                  $ )z:attr:`~pi_heif.HeifImage.size` property of the primary :class:`~pi_heif.HeifImage`.

:exception IndexError: If there are no images.
)r   r   r!   r1   s    r+   r!   HeifFile.size       ||D../444r.   c                H    U R                   U R                     R                  $ )z:attr:`~pi_heif.HeifImage.mode` property of the primary :class:`~pi_heif.HeifImage`.

:exception IndexError: If there are no images.
)r   r   r#   r1   s    r+   r#   HeifFile.mode   r   r.   c                H    U R                   U R                     R                  $ )z:attr:`~pi_heif.HeifImage.has_alpha` property of the primary :class:`~pi_heif.HeifImage`.

:exception IndexError: If there are no images.
)r   r   r   r1   s    r+   r   HeifFile.has_alpha(  s     ||D../999r.   c                H    U R                   U R                     R                  $ )z:attr:`~pi_heif.HeifImage.premultiplied_alpha` property of the primary :class:`~pi_heif.HeifImage`.

:exception IndexError: If there are no images.
r   r   r   r1   s    r+   r   HeifFile.premultiplied_alpha0  s     ||D../CCCr.   c                >    XR                   U R                     l        g r%   r   r   s     r+   r   r   8  s    ?DT''(<r.   c                H    U R                   U R                     R                  $ )z:attr:`~pi_heif.HeifImage.data` property of the primary :class:`~pi_heif.HeifImage`.

:exception IndexError: If there are no images.
)r   r   r2   r1   s    r+   r2   HeifFile.data<  r   r.   c                H    U R                   U R                     R                  $ )z:attr:`~pi_heif.HeifImage.stride` property of the primary :class:`~pi_heif.HeifImage`.

:exception IndexError: If there are no images.
)r   r   r5   r1   s    r+   r5   HeifFile.strideD  s     ||D../666r.   c                H    U R                   U R                     R                  $ )zz`info`` dict of the primary :class:`~pi_heif.HeifImage` in the container.

:exception IndexError: If there are no images.
)r   r   r_   r1   s    r+   r_   HeifFile.infoL  r   r.   c                P    U R                   U R                     R                  5       $ )zHelper method to create Pillow :external:py:class:`~PIL.Image.Image`.

:returns: :external:py:class:`~PIL.Image.Image` class created from the primary image.
)r   r   rF   r1   s    r+   rF   HeifFile.to_pillowT  s"    
 ||D../99;;r.   c                2    [        U R                  U40 UD6  g)ar  Saves image(s) under the given fp.

Keyword options can be used to provide additional instructions to the writer.
If a writer does not recognize an option, it is silently ignored.

Supported options:
    ``save_all`` - boolean. Should all images from ``HeiFile`` be saved?
    (default = ``True``)

    ``append_images`` - do the same as in Pillow. Accepts the list of ``HeifImage``

    .. note:: Appended images always will have ``info["primary"]=False``

    ``quality`` - see :py:attr:`~pi_heif.options.QUALITY`

    ``enc_params`` - dictionary with key:value to pass to :ref:`x265 <hevc-encoder>` encoder.

    ``exif`` - override primary image's EXIF with specified.
    Accepts ``None``, ``bytes`` or ``PIL.Image.Exif`` class.

    ``xmp`` - override primary image's XMP with specified. Accepts ``None`` or ``bytes``.

    ``primary_index`` - ignore ``info["primary"]`` and set `PrimaryImage` by index.

    ``chroma`` - custom subsampling value. Possible values: ``444``, ``422`` or ``420`` (``x265`` default).

    ``subsampling`` - synonym for *chroma*. Format is string, compatible with Pillow: ``x:x:x``, e.g. '4:4:4'.

    ``save_nclx_profile`` - boolean, see :py:attr:`~pi_heif.options.SAVE_NCLX_PROFILE`

    ``matrix_coefficients`` - int, nclx profile: color conversion matrix coefficients, default=6 (see h.273)

    ``color_primaries`` - int, nclx profile: color primaries (see h.273)

    ``transfer_characteristic`` - int, nclx profile: transfer characteristics (see h.273)

    ``full_range_flag`` - nclx profile: full range flag, default: 1

:param fp: A filename (string), pathlib.Path object or an object with `write` method.
N)_encode_imagesr   )r)   r   r   s      r+   saveHeifFile.save[  s    R 	t||R262r.   c                    SU R                   R                   S[        U 5       SU  Vs/ s H  n[        U5      PM     sn S3$ s  snf )Nrd   r   z	 images: rg   )r`   rP   r   r"   )r)   r   s     r+   ri   HeifFile.__repr__  sH    4>>**+6#d)IW[F\W[RSs1vW[F\E]]^__F\s   Ac                ,    [        U R                  5      $ r%   )r   r   r1   s    r+   __len__HeifFile.__len__  s    4<<  r.   c              #  8   #    U R                    S h  vN   g  N7fr%   )r   r1   s    r+   __iter__HeifFile.__iter__  s     <<s   c                z    US:  d  U[        U R                  5      :  a  [        SU 35      eU R                  U   $ Nr   zinvalid image index: r   r   
IndexError)r)   r   s     r+   __getitem__HeifFile.__getitem__  s;    19T\\!224UG<==||E""r.   c                x    US:  d  U[        U R                  5      :  a  [        SU 35      eU R                  U	 g r   r   )r)   keys     r+   __delitem__HeifFile.__delitem__  s8    7cS..4SE:;;LLr.   c                h    [        [        XU40 UD65      nU R                  R                  U5        U$ )a  Adds image from bytes to container.

.. note:: Supports ``stride`` value if needed.

:param mode: see :ref:`image-modes`.
:param size: tuple with ``width`` and ``height`` of image.
:param data: bytes object with raw image data.

:returns: :py:class:`~pi_heif.HeifImage` added object.
)rx   r   r   r   )r)   r#   r!   r2   r   added_images         r+   add_frombytesHeifFile.add_frombytes  s2      	$d Ef EFK(r.   c                   UR                  5         U R                  UR                  UR                  UR                  UR
                  S9n[        UR                  5      Ul        UR                  R                  SS5        U$ )zAdd image to the container.

:param image: :py:class:`~pi_heif.HeifImage` class to add from.

:returns: :py:class:`~pi_heif.HeifImage` added object.
)r5   r{   N)	r0   r  r#   r!   r2   r5   r   r_   pop)r)   rn   r  s      r+   add_from_heifHeifFile.add_from_heif  sm     	

((JJJJJJ<<	 ) 
 $EJJ/Y-r.   c                   UR                   S   S::  d  UR                   S   S::  a  [        S5      eUR                  R                  5       n[	        U5      US'   [        U5      nU(       a  X2S'   [        U5      n[        U5      nUb  US:w  a  [        XT5      nUR                  5         U R                  UR                  UR                   UR                  5       5      nS H0  nXqR                  ;   d  M  UR                  U   UR                  U'   M2     S H9  nXqR                  ;   d  M  [        UR                  U   5      UR                  U'   M;     [	        U5      UR                  S'   [        U5      nU(       a  XR                  S'   U$ )zAdd image to the container.

:param image: Pillow :external:py:class:`~PIL.Image.Image` class to add from.

:returns: :py:class:`~pi_heif.HeifImage` added object.
r   r	   zEmpty images are not supported.r}   r   )r|   r~   r   r   )r   r]   )r!   
ValueErrorr_   r   r   r   r   r   r   r0   r  r#   tobytesr   )	r)   rn   r_   r   r   imgr  r  im_xmps	            r+   add_from_pillowHeifFile.add_from_pillow  sY    ::a=AA!!3>??zz (/Vu%K.t4$U++0D0Ic8C
((HHHHKKM

 RCjj (-

3  % R 0Cjj (0C(A  % 0 $5U#; !%(&,U#r.   c                H    U R                   U R                     R                  $ )z+Returns the primary image as a numpy array.)r   r   r@   r1   s    r+   r@   HeifFile.__array_interface__  s     ||D../CCCr.   c                    / nU R                    HJ  n[        UR                  5      nUR                  UR                  UR
                  X2R                  /5        ML     U R                  U R                  U/$ r%   )	r   bytesr2   r   r#   r!   r_   r   r   )r)   im_descimim_datas       r+   __getstate__HeifFile.__getstate__  sZ    ,,BBGGnGNNBGGRWWgww?@  ""DMM7;;r.   c                    U R                  5         Uu  U l        U l        nU H   nUu  pEpgU R                  XEU5      nXxl        M"     g r%   )r,   r   r   r  r_   )	r)   stater   r  im_modeim_sizer  im_infor  s	            r+   __setstate__HeifFile.__setstate__  sH    491DM6G18.Gg,,WwGK& r.   c                    [        5       n[        U R                  5      Ul        U R                  Ul        U R                  Ul        U$ r%   )r   r   r   r   r   )r)   im_copys     r+   __copyHeifFile.__copy  s8    *t||,== $ 2 2r.   c                R    U R                   U R                     R                  U5      $ )z`get_aux_image`` method of the primary :class:`~pi_heif.HeifImage` in the container.

:exception IndexError: If there are no images.
)r   r   r   )r)   r   s     r+   r   HeifFile.get_aux_image  s$    
 ||D../==fEEr.   )r   r   r   )NTFr   rL   rN   )r#   r"   r!   r    )rn   rx   rK   rx   )rn   rM   rK   rx   ) rP   rQ   rR   rS   rT   r,   rV   r!   r#   r   r   r   r2   r5   r_   rF   r   ri   r   r   r   r  r  r  r  r@   r  r#  _HeifFile__copyr   __copy__rW   rX   r.   r+   r   r      s    +D 5 5 5 5 : : D D E  E 5 5 7 7 5 5<)3V`! #

$"H D D<'F Hr.   r   c                J    [        U S5      nUSS S:w  a  g[        U5      S:g  $ )aB  Checks if the given `fp` object contains a supported file type.

:param fp: A filename (string), pathlib.Path object or a file object.
    The file object must implement ``file.read``, ``file.seek``, and ``file.tell`` methods,
    and be opened in binary mode.

:returns: A boolean indicating if the object can be opened.
      r8   s   ftypFr   )r   r   )r   f_datas     r+   is_supportedr1    s1     BFa{gV$**r.   c                    [        XU40 UD6$ )ak  Opens the given HEIF image file.

:param fp: See parameter ``fp`` in :func:`is_supported`
:param convert_hdr_to_8bit: Boolean indicating should 10 bit or 12 bit images
    be converted to 8-bit images during decoding. Otherwise, they will open in 16-bit mode.
    ``Does not affect "monochrome" or "depth images".``
:param bgr_mode: Boolean indicating should be `RGB(A)` images be opened in `BGR(A)` mode.
:param kwargs: **hdr_to_16bit** a boolean value indicating that 10/12-bit image data
    should be converted to 16-bit mode during decoding. `Has lower priority than convert_hdr_to_8bit`!
    Default = **True**

:returns: :py:class:`~pi_heif.HeifFile` object.
:exception ValueError: invalid input data.
:exception EOFError: corrupted image data.
:exception SyntaxError: unsupported feature.
:exception RuntimeError: some other error.
:exception OSError: out of memory.
)r   )r   r   r   r   s       r+   	open_heifr3    s    & BX@@@r.   c                V    [        XU4SS0UD6nU H  nUR                  5         M     U$ )a
  Opens the given HEIF image file and decodes all images.

.. note:: In most cases it is better to call :py:meth:`~pi_heif.open_heif`, and
    let images decoded automatically only when needed.

:param fp: See parameter ``fp`` in :func:`is_supported`
:param convert_hdr_to_8bit: Boolean indicating should 10 bit or 12 bit images
    be converted to 8-bit images during decoding. Otherwise, they will open in 16-bit mode.
    ``Does not affect "monochrome" or "depth images".``
:param bgr_mode: Boolean indicating should be `RGB(A)` images be opened in `BGR(A)` mode.
:param kwargs: **hdr_to_16bit** a boolean value indicating that 10/12-bit image data
    should be converted to 16-bit mode during decoding. `Has lower priority than convert_hdr_to_8bit`!
    Default = **True**

:returns: :py:class:`~pi_heif.HeifFile` object.
:exception ValueError: invalid input data.
:exception EOFError: corrupted image data.
:exception SyntaxError: unsupported feature.
:exception RuntimeError: some other error.
:exception OSError: out of memory.
r   T)r   r0   )r   r   r   r   retr  s         r+   	read_heifr6  (  s2    , 2H
Q$
Q&
QC
 Jr.   c           	     H    [        [        [        XU40 UD65      /U40 UD6  g)a>  Encodes data in a ``fp``.

:param mode: `BGR(A);16`, `RGB(A);16`, LA;16`, `L;16`, `I;16L`, `BGR(A)`, `RGB(A)`, `LA`, `L`
:param size: tuple with ``width`` and ``height`` of an image.
:param data: bytes object with raw image data.
:param fp: A filename (string), pathlib.Path object or an object with ``write`` method.
N)r   rx   r   )r#   r!   r2   r   r   s        r+   encoder8  D  s'     IiDCFCDErTVTr.   c                8   UR                  SS5      nUS:X  a  [        R                  O[        R                  n[        R
                  " 5       U   (       d  [        SU S35      eXR                  S/ 5      -   nUR                  SS5      (       d  US S	 nU(       d  [        S
5      e[        XRR                  S5      5      n[        U40 UD6n[        U5       H  u  pU	R                  5         U	R                  R                  5       n
SU
S'   X:X  a  U
R                  " S0 UD6  SU
S'   U
R                  SS5        UR                   " U	R"                  U	R$                  U	R&                  4S[)        U
5      0U
DSU	R*                  0D6  M     UR-                  U5        g )Nformatr   r   zNo z encoder found.append_imagessave_allTr	   z)Cannot write file with no images as HEIF.r   Fr{   r5   r   image_orientationrX   )r   r   AV1HEVCr   get_lib_infoRuntimeErrorr  r   r   r   r0   r_   r   updater  	add_imager!   r#   r2   r   r5   r   )r   r   r   compressioncompression_formatimages_to_saver   	ctx_writer   r  r_   s              r+   r   r   O  sl   **Xv.K6AV6K.22QfQkQk  ";/S_=>>&,zz/2/N&NN::j$'''+DEE&~zz/7RSM,77IN+
xx}}YKK!&!"DO1HHHHHH	
 ;4@		

 	
 ::	
 ,  NN2r.   c                <    [        5       nUR                  U 5        U$ )zCreates :py:class:`~pi_heif.HeifFile` from a Pillow Image.

:param pil_image: Pillow :external:py:class:`~PIL.Image.Image` class.

:returns: New :py:class:`~pi_heif.HeifFile` object.
)r   r  )	pil_imagerI   s     r+   from_pillowrJ  n  s     	
Ai Hr.   c                B    [        5       nUR                  " XU40 UD6  U$ )a*  Creates :py:class:`~pi_heif.HeifFile` from bytes.

.. note:: Supports ``stride`` value if needed.

:param mode: see :ref:`image-modes`.
:param size: tuple with ``width`` and ``height`` of an image.
:param data: bytes object with raw image data.

:returns: New :py:class:`~pi_heif.HeifFile` object.
)r   r  )r#   r!   r2   r   rI   s        r+   
from_bytesrL  z  s#     	
AOOD//Hr.   r   )TF)rK   r   )r#   r"   r!   r    rK   rO   )r   zlist[HeifImage]rK   rO   )rI  rM   rK   r   )r#   r"   r!   r    rK   r   )1rT   
__future__r   r   r   ior   typingr   PILr   r   r
   	constantsr   miscr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ImportErrorex_deffered_errorr   r   rZ   rs   rx   r   r1  r3  r6  r8  r   rJ  rL  rX   r.   r+   <module>rV     s    > "      ,    &!K3 K3\Y 0X9 XP'	 P'fX Xv+A,8U>	q  !.R H!s   B5 5C;CC