
    9i59                         S r SSKrSSKJrJr  SSKJr  SSKJ	r	J
r
JrJr   " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      rg)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                      ^  \ rS rSrSrSrSSS.U 4S jjjr\S 5       rS r	S	 r
 " S
 S\R                  5      r " S S\R                  5      rSrU =r$ )FreeimageFormat%   z$See :mod:`imageio.plugins.freeimage`iN)fifc                .   > [         TU ]  XX4S9  XPl        g )N)
extensionsmodes)super__init___fif)selfnamedescriptionr   r   r   	__class__s         Y/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/imageio/plugins/freeimage.pyr   FreeimageFormat.__init__*   s    zO	    c                     U R                   $ Nr   r   s    r   r   FreeimageFormat.fif.   s    yyr   c                 h   [         R                  " 5       (       a  [        US5      (       d2   [         R                  " UR                  SUR
                  5      Ul        UR                  U R                  :X  a  gUR                  S:X  a  U R                  S:X  a  gg g g ! [         a
    SUl         NRf = f)Nr   rT      )	r   has_libhasattrgetFIFfilename
firstbytesr   	Exceptionr   r   requests     r   	_can_readFreeimageFormat._can_read2   s    ::<<7F++&#%99W-=-=sGDVDV#WGL ||txx'"txx2~  (6"  ! &#%GL&s   1B B10B1c                 Z   [         R                  " 5       (       aS  [        US5      (       d'   [         R                  " UR                  S5      Ul        UR
                  U R                  L a  gg g ! [         a1    UR                  [        :X  a  U R                  Ul         NMSUl         NVf = f)Nr   wr%   T)
r   r(   r)   r*   r+   r   
ValueErrorraw_urir   r   r.   s     r   
_can_writeFreeimageFormat._can_writeA   s    ::<<7F++*#%99W-=-=s#CGL ||txx' (  " *,6'+xx')	*s   &A/ //B* B*)B*c                   6    \ rS rSrS rS	S jrS rS rS rSr	g)
FreeimageFormat.ReaderQ   c                     g)Nr    r!   s    r   _get_length"FreeimageFormat.Reader._get_lengthR   s    r   c                     [         R                  " U R                  R                  U R                  R
                  U5      U l        U R                  R                  U R                  R                  5       5        g r   )	r   create_bitmapr/   r+   formatr   _bmload_from_filenameget_local_filenamer   flagss     r   _openFreeimageFormat.Reader._openU   sJ    ''(=(=t{{PUVDHHH''(G(G(IJr   c                 8    U R                   R                  5         g r   )rB   closer!   s    r   _closeFreeimageFormat.Reader._closeY   s    HHNNr   c                     US:w  a  [        S5      eU R                  R                  5       U R                  R                  5       4$ )Nr   z+This format only supports singleton images.)
IndexErrorrB   get_image_dataget_meta_datar   indexs     r   	_get_data FreeimageFormat.Reader._get_data\   s:    z !NOO88**,dhh.D.D.FFFr   c                 \    Ub  US:X  d
  [        5       eU R                  R                  5       $ )Nr   )rN   rB   rP   rQ   s     r   _get_meta_data%FreeimageFormat.Reader._get_meta_dataa   s(    MUaZ l"88))++r   rB   Nr   )
__name__
__module____qualname____firstlineno__r=   rG   rK   rS   rV   __static_attributes__r<   r   r   Readerr9   Q   s    		K		G
	,r   r_   c                   0    \ rS rSrSS jrS rS rS rSrg)	FreeimageFormat.Writerh   c                 :    Xl         S U l        SU l        0 U l        g )NF)_flagsrB   _is_set_metarE   s     r   rG   FreeimageFormat.Writer._openi   s    KDH DLDJr   c                     U R                   R                  U R                  5        U R                   R                  U R                  R                  5       5        U R                   R                  5         g r   )rB   set_meta_datarf   save_to_filenamer/   rD   rJ   r!   s    r   rK   FreeimageFormat.Writer._closeo   sE    HH""4::.HH%%dll&E&E&GHHHNNr   c                    U R                   (       d  SU l         O[        S5      eUR                  S:X  a  UR                  S   S:X  a  US S 2S S 2S4   nU R                  cj  [
        R                  " U R                  R                  U R                  R                  U R                  5      U l        U R                  R                  U5        U R                  R                  U5        X l        g )NTz1Singleton image; can only append image data once.   r%   r   r   )re   RuntimeErrorndimshaperB   r   r@   r/   r+   rA   r   rd   allocateset_image_datarf   r   immetas      r   _append_data#FreeimageFormat.Writer._append_datav   s    <<#"J  ww!| 11a[xx++LL))4;;??DKK !!"%HH##B' Jr   c                     Xl         g r   )rf   )r   ru   s     r   _set_meta_data%FreeimageFormat.Writer._set_meta_data   s    Jr   )rB   rd   re   rf   NrY   )	rZ   r[   r\   r]   rG   rK   rv   ry   r^   r<   r   r   Writerra   h   s    			.	r   r{   r    )NN)rZ   r[   r\   r]   __doc___modesr   propertyr   r0   r6   r   r_   r{   r^   __classcell__)r   s   @r   r   r   %   s_    .Fd     , ,.& & &r   r   c                   B    \ rS rSrSr " S S\R                  5      rSrg)FreeimageBmpFormat   az  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                   $    \ rS rSrSS jrS rSrg)FreeimageBmpFormat.Writer   c                     [        U5      nU(       a  U[        R                  -  nOU[        R                  -  n[        R
                  R                  X5      $ r   )intr	   BMP_SAVE_RLEBMP_DEFAULTr   r{   rG   )r   rF   compressions      r   rG   FreeimageBmpFormat.Writer._open   sE    JE...---"))//<<r   c                 V    [        USS9n[        R                  R                  XU5      $ )N   bitdepth)r   r   r{   rv   rs   s      r   rv   &FreeimageBmpFormat.Writer._append_data   s'    rA.B"))66tFFr   r<   N)r   FrZ   r[   r\   r]   rG   rv   r^   r<   r   r   r{   r      s    	=	Gr   r{   r<   NrZ   r[   r\   r]   r|   r   r{   r^   r<   r   r   r   r      s    (G'' Gr   r   c                   l    \ rS rSrSr " S S\R                  5      r " S S\R                  5      rSrg)	FreeimagePngFormat   a  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                       \ rS rSrSS jrSrg)FreeimagePngFormat.Reader   c                     [        U5      nU(       a  U[        R                  -  n[        R                  R                  X5      $ r   )r   r	   PNG_IGNOREGAMMAr   r_   rG   )r   rF   ignoregammas      r   rG   FreeimagePngFormat.Reader._open   s5    JE111"))//<<r   r<   Nr   TrZ   r[   r\   r]   rG   r^   r<   r   r   r_   r          	=r   r_   c                   $    \ rS rSrSS jrS rSrg)FreeimagePngFormat.Writer   c                 J   [         R                  [         R                  [         R                  [         R                  S.n[        U5      nU(       a  U[         R                  -  n XU   -  n[        R                  R                  X5      $ ! [         a    [        S5      ef = f)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_COMPRESSIONr   PNG_INTERLACEDKeyErrorr4   r   r{   rG   )r   rF   r   quantize
interlacedcompression_maps         r   rG   FreeimagePngFormat.Writer._open   s    00,,5522	O JE000K55 #))//<<  K !IJJKs   &B B"c                    [        UR                  5      S:X  a  [        USS9nO
[        USS9n[        R                  R                  XU5        [        U R                  R                  R                  SS5      5      nU(       d  g UR                  S:X  a  UR                  S   S:X  d  [        S	5      eUS
:  d  US:  a  [        S5      eU R                  R                  SU5      nU R                  R                  5         X@l        g )Nuint16   r   r   r   Frm   r%   zCan only quantize RGB imagesr      z!PNG quantize param must be 2..256r   )strdtyper   r   r{   rv   r   r/   kwargsgetro   rp   r4   rB   r   rJ   )r   rt   ru   qbms        r   rv   &FreeimagePngFormat.Writer._append_data   s    288}("23"22""//$?DLL''++J>?Agglrxx|q'8 !?@@Q!c' !DEEXX&&q!, r   rX   N)r   r   r   Fr   r<   r   r   r{   r      s    	=$	r   r{   r<   N	rZ   r[   r\   r]   r|   r   r_   r{   r^   r<   r   r   r   r      s+    <='' =$'' $r   r   c                   l    \ rS rSrSr " S S\R                  5      r " S S\R                  5      rSrg)	FreeimageJpegFormati  a  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                   *    \ rS rSrSS jrS rS rSrg)FreeimageJpegFormat.Readeri3  c                     [        U5      nU(       a  US:w  a  U[        R                  -  nU(       d  U[        R                  -  n[        R
                  R                  X5      $ )Nr   )r   r	   JPEG_EXIFROTATEJPEG_ACCURATEr   r_   rG   )r   rF   
exifrotate	quickreads       r   rG    FreeimageJpegFormat.Reader._open4  sN    JEjAo111///"))//<<r   c                 l    [         R                  R                  X5      u  p#U R                  X#5      nX#4$ r   )r   r_   rS   _rotate)r   rR   rt   ru   s       r   rS   $FreeimageJpegFormat.Reader._get_data>  s/    &--77DHBb'B8Or   c                    U R                   R                  R                  SS5      S:X  a   US   S   nUS;   a   US;   a  [        R                  " US5      nUS;   a  [        R                  " US	5      nUS
;   a  [        R                  " U5      nUS;   a  [        R
                  " U5      nU$ U$ ! [         a     U$ f = f)a  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   )rm      )   r   rm   )r&   r   )r   r   r   r&   )r/   r   r   nprot90fliplrr   )r   rt   ru   oris       r   r   "FreeimageJpegFormat.Reader._rotateC  s     ||""&&|T:a?+{+M:C
 f}f}XXb!_f}XXb!_f}XXb\l*YYr]I2I    Is   B1 1
B?>B?r<   N)r   TF)rZ   r[   r\   r]   rG   rS   r   r^   r<   r   r   r_   r   3  s    	=	
	r   r_   c                   &    \ rS rSr SS jrS rSrg)FreeimageJpegFormat.Writeri_  c                 >   [        U5      nUS:  d  US:  a  [        S5      e[        U5      nX-  nU(       a  U[        R                  -  nU(       a  U[        R                  -  nU(       a  U[        R
                  -  n[        R                  R                  X5      $ )Nr   d   z)JPEG quality should be between 1 and 100.)	r   r4   r	   JPEG_PROGRESSIVEJPEG_OPTIMIZEJPEG_BASELINEr   r{   rG   )r   rF   qualityprogressiveoptimizebaselines         r   rG    FreeimageJpegFormat.Writer._open`  s     'lG{gm !LMMJEE222//////"))//<<r   c                     UR                   S:X  a  UR                  S   S:X  a  [        S5      e[        USS9n[        R
                  R                  XU5      $ )Nrm   r%   r   z$JPEG does not support alpha channel.r   r   )ro   rp   IOErrorr   r   r{   rv   rs   s      r   rv   'FreeimageJpegFormat.Writer._append_datas  sM    ww!| 1DEErA.B"))66tFFr   r<   N)r   K   FFFr   r<   r   r   r{   r   _  s    SX	=&	Gr   r{   r<   Nr   r<   r   r   r   r     s/    #J('' (XG'' Gr   r   c                   B    \ rS rSrSr " S S\R                  5      rSrg)FreeimagePnmFormatiz  a<  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                       \ rS rSrSS jrSrg)FreeimagePnmFormat.Writeri  c                     [        U5      nU(       a  U[        R                  -  n[        R                  R                  X5      $ r   )r   r	   PNM_SAVE_ASCIIr   r{   rG   )r   rF   	use_asciis      r   rG   FreeimagePnmFormat.Writer._open  s5    JE000"))//<<r   r<   Nr   r   r<   r   r   r{   r     r   r   r{   r<   Nr   r<   r   r   r   r   z  s    $='' =r   r   )r|   numpyr   corer   r   core.requestr   
_freeimager   r	   r
   r   r   r   r   r   r   r<   r   r   <module>r      se   0  ( ' B B
if id"G "GJN NbjG/ jGZ= =r   