Ë
    Eü´j59  ã                   ó²   — d Z ddlZddlmZmZ ddlmZ ddlm	Z	m
Z
mZmZ  G d„ d	e«      Z G d
„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Zy)ag  Read/Write images using FreeImage.

Backend Library: `FreeImage <https://freeimage.sourceforge.io/>`_

.. note::
    To use this plugin you have to install its backend::

        imageio_download_bin freeimage

    or you can download the backend using the function::

        imageio.plugins.freeimage.download()

Each Freeimage format has the ``flags`` keyword argument. See the `Freeimage
documentation <https://freeimage.sourceforge.io/>`_ for more information.

Parameters
----------
flags : int
    A freeimage-specific option. In most cases we provide explicit
    parameters for influencing image reading.

é    Né   )ÚFormatÚimage_as_uint)ÚRETURN_BYTESé   )ÚFNAME_PER_PLATFORMÚIO_FLAGSÚdownloadÚfic                   óž   ‡ — e Zd ZdZdZdddœˆ fd„Zed„ «       Zd„ Zd„ Z	 G d	„ d
e
j                  «      Z G d„ de
j                  «      Zˆ xZS )ÚFreeimageFormatz$See :mod:`imageio.plugins.freeimage`ÚiN)Úfifc                ó:   •— t         ‰| �  ||||¬«       || _        y )N)Ú
extensionsÚmodes)ÚsuperÚ__init__Ú_fif)ÚselfÚnameÚdescriptionr   r   r   Ú	__class__s         €úW/root/workspace/ytshorts/venv/lib/python3.12/site-packages/imageio/plugins/freeimage.pyr   zFreeimageFormat.__init__*   s    ø€ Ü‰Ñ˜˜{°zÈÐÔOØˆ�	ó    c                 ó   — | j                   S ©N)r   ©r   s    r   r   zFreeimageFormat.fif.   s   € à�y‰yÐr   c                 óH  — t        j                  «       rxt        |d«      s1	 t        j                  |j                  d|j
                  «      |_        |j                  | j                  k(  ry|j                  dk(  r| j                  dk(  ryy y y # t        $ r
 d|_        Y ŒNw xY w)Nr   ÚréÿÿÿÿTé   é   )	r   Úhas_libÚhasattrÚgetFIFÚfilenameÚ
firstbytesr   Ú	Exceptionr   ©r   Úrequests     r   Ú	_can_readzFreeimageFormat._can_read2   s�   € ä�:‰:Œ<Ü˜7 FÔ+ð&Ü#%§9¡9¨W×-=Ñ-=¸sÀG×DVÑDVÓ#W�G”Lð �|‰|˜tŸx™xÒ'ØØ—‘ Ò" t§x¡x°2¢~ð ð (6Ð"ð øô !ò &Ø#%�G–Lð&ús   ¢0B ÂB!Â B!c                 ó:  — t        j                  «       rLt        |d«      s&	 t        j                  |j                  d«      |_        |j
                  | j                  u ryy y # t        $ r/ |j                  t        k(  r| j                  |_        nd|_        Y ŒRw xY w)Nr   Úwr!   T)
r   r$   r%   r&   r'   r   Ú
ValueErrorÚraw_urir   r   r*   s     r   Ú
_can_writezFreeimageFormat._can_writeA   s�   € ä�:‰:Œ<Ü˜7 FÔ+ð*Ü#%§9¡9¨W×-=Ñ-=¸sÓ#C�G”Lð �|‰|˜tŸx™xÑ'Øð (ð øô "ò *Ø—‘¬,Ò6Ø'+§x¡x˜�à')˜œùð	*ús   ¢%A" Á"5BÂBc                   ó,   — e Zd Zd„ Zdd„Zd„ Zd„ Zd„ Zy)úFreeimageFormat.Readerc                  ó   — y)Nr   © r   s    r   Ú_get_lengthz"FreeimageFormat.Reader._get_lengthR   s   € Ør   c                 óò   — t        j                  | j                  j                  | j                  j
                  |«      | _        | j                  j                  | j                  j                  «       «       y r   )	r   Úcreate_bitmapr+   r'   Úformatr   Ú_bmÚload_from_filenameÚget_local_filename©r   Úflagss     r   Ú_openzFreeimageFormat.Reader._openU   sJ   € Ü×'Ñ'¨¯©×(=Ñ(=¸t¿{¹{¿¹ÐPUÓVˆDŒHØ�H‰H×'Ñ'¨¯©×(GÑ(GÓ(IÕJr   c                 ó8   — | j                   j                  «        y r   )r:   Úcloser   s    r   Ú_closezFreeimageFormat.Reader._closeY   s   € Ø�H‰H�N‰NÕr   c                 óŠ   — |dk7  rt        d«      ‚| j                  j                  «       | j                  j                  «       fS )Nr   z+This format only supports singleton images.)Ú
IndexErrorr:   Úget_image_dataÚget_meta_data©r   Úindexs     r   Ú	_get_dataz FreeimageFormat.Reader._get_data\   s:   € Ø˜ŠzÜ Ð!NÓOÐOØ—8‘8×*Ñ*Ó,¨d¯h©h×.DÑ.DÓ.FÐFÐFr   c                 óX   — |�|dk(  s
t        «       ‚| j                  j                  «       S )Nr   )rD   r:   rF   rG   s     r   Ú_get_meta_dataz%FreeimageFormat.Reader._get_meta_dataa   s(   € Ø�M U¨a¢ZÜ “lÐ"Ø—8‘8×)Ñ)Ó+Ð+r   N©r   )Ú__name__Ú
__module__Ú__qualname__r6   r?   rB   rI   rK   r5   r   r   ÚReaderr3   Q   s   „ ò	ó	Kò	ò	Gó
	,r   rP   c                   ó&   — e Zd Zdd„Zd„ Zd„ Zd„ Zy)úFreeimageFormat.Writerc                 ó<   — || _         d | _        d| _        i | _        y )NF)Ú_flagsr:   Ú_is_setÚ_metar=   s     r   r?   zFreeimageFormat.Writer._openi   s   € ØˆDŒKØˆDŒHØ ˆDŒLØˆD�Jr   c                 óè   — | j                   j                  | j                  «       | j                   j                  | j                  j                  «       «       | j                   j                  «        y r   )r:   Úset_meta_datarV   Úsave_to_filenamer+   r<   rA   r   s    r   rB   zFreeimageFormat.Writer._closeo   sE   € à�H‰H×"Ñ" 4§:¡:Ô.à�H‰H×%Ñ% d§l¡l×&EÑ&EÓ&GÔHØ�H‰H�N‰NÕr   c                 óÊ  — | j                   sd| _         nt        d«      ‚|j                  dk(  r|j                  d   dk(  r|d d …d d …df   }| j                  €it        j                  | j                  j                  | j                  j                  | j                  «      | _        | j                  j                  |«       | j                  j                  |«       || _        y )NTz1Singleton image; can only append image data once.é   r!   r   r   )rU   ÚRuntimeErrorÚndimÚshaper:   r   r8   r+   r'   r9   r   rT   ÚallocateÚset_image_datarV   ©r   ÚimÚmetas      r   Ú_append_dataz#FreeimageFormat.Writer._append_datav   s³   € à—<’<Ø#�•ä"ØJóð ð �w‰w˜!Š| §¡¨¡°Ò 1Øšš1˜a˜‘[�à�x‰xÐÜ×+Ñ+Ø—L‘L×)Ñ)¨4¯;©;¯?©?¸D¿K¹Kó�”ð —‘×!Ñ! "Ô%à�H‰H×#Ñ# BÔ'ð ˆD�Jr   c                 ó   — || _         y r   )rV   )r   rc   s     r   Ú_set_meta_dataz%FreeimageFormat.Writer._set_meta_data�   s	   € ØˆD�Jr   NrL   )rM   rN   rO   r?   rB   rd   rf   r5   r   r   ÚWriterrR   h   s   „ ó	ò	ò	ó.	r   rg   )NN)rM   rN   rO   Ú__doc__Ú_modesr   Úpropertyr   r,   r1   r   rP   rg   Ú__classcell__)r   s   @r   r   r   %   sZ   ø„ Ù.à€FðÈdö ð ñó ðòòô ,�—‘ô ,ô.&�—‘÷ &ð &r   r   c                   ó:   — e Zd ZdZ G d„ dej
                  «      Zy)ÚFreeimageBmpFormata®  A BMP format based on the Freeimage library.

    This format supports grayscale, RGB and RGBA images.

    The freeimage plugin requires a `freeimage` binary. If this binary
    not available on the system, it can be downloaded manually from
    <https://github.com/imageio/imageio-binaries> by either

    - the command line script ``imageio_download_bin freeimage``
    - the Python method ``imageio.plugins.freeimage.download()``

    Parameters for saving
    ---------------------
    compression : bool
        Whether to compress the bitmap using RLE when saving. Default False.
        It seems this does not always work, but who cares, you should use
        PNG anyway.

    c                   ó   — e Zd Zdd„Zd„ Zy)úFreeimageBmpFormat.Writerc                 óª   — t        |«      }|r|t        j                  z  }n|t        j                  z  }t        j
                  j                  | |«      S r   )Úintr	   ÚBMP_SAVE_RLEÚBMP_DEFAULTr   rg   r?   )r   r>   Úcompressions      r   r?   zFreeimageBmpFormat.Writer._open­   sG   € ä˜“JˆEÙØœ×.Ñ.Ñ.‘àœ×-Ñ-Ñ-�ä"×)Ñ)×/Ñ/°°eÓ<Ð<r   c                 ó^   — t        |d¬«      }t        j                  j                  | ||«      S )Né   ©Úbitdepth)r   r   rg   rd   ra   s      r   rd   z&FreeimageBmpFormat.Writer._append_data·   s)   € Ü˜r¨AÔ.ˆBÜ"×)Ñ)×6Ñ6°t¸RÀÓFÐFr   N)r   F©rM   rN   rO   r?   rd   r5   r   r   rg   ro   ¬   s   „ ó	=ó	Gr   rg   N©rM   rN   rO   rh   r   rg   r5   r   r   rm   rm   —   s   „ ñô(G�×'Ñ'õ Gr   rm   c                   ód   — e Zd ZdZ G d„ dej
                  «      Z G d„ dej                  «      Zy)ÚFreeimagePngFormataY  A PNG format based on the Freeimage library.

    This format supports grayscale, RGB and RGBA images.

    The freeimage plugin requires a `freeimage` binary. If this binary
    not available on the system, it can be downloaded manually from
    <https://github.com/imageio/imageio-binaries> by either

    - the command line script ``imageio_download_bin freeimage``
    - the Python method ``imageio.plugins.freeimage.download()``

    Parameters for reading
    ----------------------
    ignoregamma : bool
        Avoid gamma correction. Default True.

    Parameters for saving
    ---------------------
    compression : {0, 1, 6, 9}
        The compression factor. Higher factors result in more
        compression at the cost of speed. Note that PNG compression is
        always lossless. Default 9.
    quantize : int
        If specified, turn the given RGB or RGBA image in a paletted image
        for more efficient storage. The value should be between 2 and 256.
        If the value of 0 the image is not quantized.
    interlaced : bool
        Save using Adam7 interlacing. Default False.
    c                   ó   — e Zd Zdd„Zy)úFreeimagePngFormat.Readerc                 ó‚   — t        |«      }|r|t        j                  z  }t        j                  j                  | |«      S r   )rq   r	   ÚPNG_IGNOREGAMMAr   rP   r?   )r   r>   Úignoregammas      r   r?   zFreeimagePngFormat.Reader._openÜ   s7   € ä˜“JˆEÙØœ×1Ñ1Ñ1�ä"×)Ñ)×/Ñ/°°eÓ<Ð<r   N©r   T©rM   rN   rO   r?   r5   r   r   rP   r~   Û   ó   „ ô	=r   rP   c                   ó   — e Zd Zdd„Zd„ Zy)úFreeimagePngFormat.Writerc                 óB  — t         j                  t         j                  t         j                  t         j                  dœ}t        |«      }|r|t         j                  z  }	 |||   z  }t        j                  j                  | |«      S # t        $ r t        d«      ‚w xY w)N)r   r   é   é	   z&Png compression must be 0, 1, 6, or 9.)r	   ÚPNG_Z_NO_COMPRESSIONÚPNG_Z_BEST_SPEEDÚPNG_Z_DEFAULT_COMPRESSIONÚPNG_Z_BEST_COMPRESSIONrq   ÚPNG_INTERLACEDÚKeyErrorr/   r   rg   r?   )r   r>   rt   ÚquantizeÚ
interlacedÚcompression_maps         r   r?   zFreeimagePngFormat.Writer._openç   sš   € ä×0Ñ0Ü×,Ñ,Ü×5Ñ5Ü×2Ñ2ñ	ˆOô ˜“JˆEÙØœ×0Ñ0Ñ0�ðKØ˜¨Ñ5Ñ5�ô #×)Ñ)×/Ñ/°°eÓ<Ð<øô ò KÜ Ð!IÓJÐJðKús   Á!B	 Â	Bc                 ó  — t        |j                  «      dk(  rt        |d¬«      }nt        |d¬«      }t        j                  j                  | ||«       t        | j                  j                  j                  dd«      «      }|sy |j                  dk(  r|j                  d   dk(  st        d	«      ‚|d
k  s|dkD  rt        d«      ‚| j                  j                  d|«      }| j                  j                  «        || _        y )NÚuint16é   rw   rv   r�   Fr[   r!   zCan only quantize RGB imagesr   é   z!PNG quantize param must be 2..256r   )ÚstrÚdtyper   r   rg   rd   rq   r+   ÚkwargsÚgetr]   r^   r/   r:   r�   rA   )r   rb   rc   ÚqÚbms        r   rd   z&FreeimagePngFormat.Writer._append_dataù   sÓ   € Ü�2—8‘8‹} Ò(Ü" 2°Ô3‘ä" 2°Ô2�Ü×"Ñ"×/Ñ/°°b¸$Ô?ä�D—L‘L×'Ñ'×+Ñ+¨J¸Ó>Ó?ˆAÙØØ—g‘g ’l r§x¡x°¡|°qÒ'8Ü Ð!?Ó@Ð@Ø�Q’˜!˜cš'Ü Ð!DÓEÐEà—X‘X×&Ñ& q¨!Ó,�Ø—‘—‘Ô Ø�•r   N)r   r‰   r   Fry   r5   r   r   rg   r†   æ   s   „ ó	=ó$	r   rg   N©rM   rN   rO   rh   r   rP   rg   r5   r   r   r|   r|   ¼   s+   „ ñô<=�×'Ñ'ô =ô$�×'Ñ'õ $r   r|   c                   ód   — e Zd ZdZ G d„ dej
                  «      Z G d„ dej                  «      Zy)ÚFreeimageJpegFormataA  A JPEG format based on the Freeimage library.

    This format supports grayscale and RGB images.

    The freeimage plugin requires a `freeimage` binary. If this binary
    not available on the system, it can be downloaded manually from
    <https://github.com/imageio/imageio-binaries> by either

    - the command line script ``imageio_download_bin freeimage``
    - the Python method ``imageio.plugins.freeimage.download()``

    Parameters for reading
    ----------------------
    exifrotate : bool
        Automatically rotate the image according to the exif flag.
        Default True. If 2 is given, do the rotation in Python instead
        of freeimage.
    quickread : bool
        Read the image more quickly, at the expense of quality.
        Default False.

    Parameters for saving
    ---------------------
    quality : scalar
        The compression factor of the saved image (1..100), higher
        numbers result in higher quality but larger file size. Default 75.
    progressive : bool
        Save as a progressive JPEG file (e.g. for images on the web).
        Default False.
    optimize : bool
        On saving, compute optimal Huffman coding tables (can reduce a
        few percent of file size). Default False.
    baseline : bool
        Save basic JPEG, without metadata or any markers. Default False.

    c                   ó    — e Zd Zdd„Zd„ Zd„ Zy)úFreeimageJpegFormat.Readerc                 ó¶   — t        |«      }|r|dk7  r|t        j                  z  }|s|t        j                  z  }t        j
                  j                  | |«      S )Nr   )rq   r	   ÚJPEG_EXIFROTATEÚJPEG_ACCURATEr   rP   r?   )r   r>   Ú
exifrotateÚ	quickreads       r   r?   z FreeimageJpegFormat.Reader._open4  sP   € ä˜“JˆEÙ˜j¨AšoØœ×1Ñ1Ñ1�ÙØœ×/Ñ/Ñ/�ä"×)Ñ)×/Ñ/°°eÓ<Ð<r   c                 ót   — t         j                  j                  | |«      \  }}| j                  ||«      }||fS r   )r   rP   rI   Ú_rotate)r   rH   rb   rc   s       r   rI   z$FreeimageJpegFormat.Reader._get_data>  s7   € Ü&×-Ñ-×7Ñ7¸¸eÓD‰HˆB�Ø—‘˜b $Ó'ˆBØ�t�8ˆOr   c                 ód  — | j                   j                  j                  dd«      dk(  rv	 |d   d   }|dv r	 |dv rt        j                  |d«      }|dv rt        j                  |d	«      }|d
v rt        j                  |«      }|dv rt        j
                  |«      }|S |S # t        $ r Y |S w xY w)aN  Use Orientation information from EXIF meta data to
            orient the image correctly. Freeimage is also supposed to
            support that, and I am pretty sure it once did, but now it
            does not, so let's just do it in Python.
            Edit: and now it works again, just leave in place as a fallback.
            r¥   Nr   Ú	EXIF_MAINÚOrientation)r   r   )r[   é   )é   rˆ   r[   )r"   rv   )r   r¬   r­   r"   )r+   r™   rš   ÚnpÚrot90Úfliplrr�   )r   rb   rc   Úoris       r   r¨   z"FreeimageJpegFormat.Reader._rotateC  s¼   € ð �|‰|×"Ñ"×&Ñ& |°TÓ:¸aÒ?ð+Ø˜{Ñ+¨MÑ:�Cð
 ˜f‘}ØØ˜f‘}ÜŸX™X b¨!›_˜Ø˜f‘}ÜŸX™X b¨!›_˜Ø˜f‘}ÜŸX™X b›\˜Ø˜lÑ*ÜŸY™Y r›]˜ØˆI�2ˆIøô  ò Øð ˆIðús   «B" Â"	B/Â.B/N)r   TF)rM   rN   rO   r?   rI   r¨   r5   r   r   rP   r¡   3  s   „ ó	=ò	ó
	r   rP   c                   ó   — e Zd Z	 dd„Zd„ Zy)úFreeimageJpegFormat.Writerc                 ó   — t        |«      }|dk  s|dkD  rt        d«      ‚t        |«      }||z  }|r|t        j                  z  }|r|t        j                  z  }|r|t        j
                  z  }t        j                  j                  | |«      S )Nr   éd   z)JPEG quality should be between 1 and 100.)	rq   r/   r	   ÚJPEG_PROGRESSIVEÚJPEG_OPTIMIZEÚJPEG_BASELINEr   rg   r?   )r   r>   ÚqualityÚprogressiveÚoptimizeÚbaselines         r   r?   z FreeimageJpegFormat.Writer._open`  s‹   € ô ˜'“lˆGØ˜Š{˜g¨šmÜ Ð!LÓMÐMä˜“JˆEØ�WÑˆEÙØœ×2Ñ2Ñ2�ÙØœ×/Ñ/Ñ/�ÙØœ×/Ñ/Ñ/�ä"×)Ñ)×/Ñ/°°eÓ<Ð<r   c                 ó¶   — |j                   dk(  r|j                  d   dk(  rt        d«      ‚t        |d¬«      }t        j
                  j                  | ||«      S )Nr[   r!   r¬   z$JPEG does not support alpha channel.rv   rw   )r]   r^   ÚIOErrorr   r   rg   rd   ra   s      r   rd   z'FreeimageJpegFormat.Writer._append_datas  sO   € Ø�w‰w˜!Š| §¡¨¡°Ò 1ÜÐDÓEÐEÜ˜r¨AÔ.ˆBÜ"×)Ñ)×6Ñ6°t¸RÀÓFÐFr   N)r   éK   FFFry   r5   r   r   rg   r³   _  s   „ àSXó	=ó&	Gr   rg   Nr�   r5   r   r   rŸ   rŸ     s/   „ ñ#ôJ(�×'Ñ'ô (ôXG�×'Ñ'õ Gr   rŸ   c                   ó:   — e Zd ZdZ G d„ dej
                  «      Zy)ÚFreeimagePnmFormatal  A PNM format based on the Freeimage library.

    This format supports single bit (PBM), grayscale (PGM) and RGB (PPM)
    images, even with ASCII or binary coding.

    The freeimage plugin requires a `freeimage` binary. If this binary
    not available on the system, it can be downloaded manually from
    <https://github.com/imageio/imageio-binaries> by either

    - the command line script ``imageio_download_bin freeimage``
    - the Python method ``imageio.plugins.freeimage.download()``

    Parameters for saving
    ---------------------
    use_ascii : bool
        Save with ASCII coding. Default True.
    c                   ó   — e Zd Zdd„Zy)úFreeimagePnmFormat.Writerc                 ó‚   — t        |«      }|r|t        j                  z  }t        j                  j                  | |«      S r   )rq   r	   ÚPNM_SAVE_ASCIIr   rg   r?   )r   r>   Ú	use_asciis      r   r?   zFreeimagePnmFormat.Writer._openŽ  s7   € ä˜“JˆEÙØœ×0Ñ0Ñ0�ä"×)Ñ)×/Ñ/°°eÓ<Ð<r   Nr‚   rƒ   r5   r   r   rg   rÃ   �  r„   r   rg   Nrz   r5   r   r   rÁ   rÁ   z  s   „ ñô$=�×'Ñ'õ =r   rÁ   )rh   Únumpyr®   Úcorer   r   Úcore.requestr   Ú
_freeimager   r	   r
   r   r   rm   r|   rŸ   rÁ   r5   r   r   ú<module>rË      se   ðñó0 ç (Ý 'ß BÓ Bô
i�fô iôd"G˜ô "GôJN˜ô NôbjG˜/ô jGôZ=˜õ =r   