Ë
    îì�id  ã                   óV   — d dgZ ddlZddlmZ ddlmZmZ dd„Zdd„Z	d	„ Z
dd
„Zdd„Zy)ÚimreadÚimsaveé    N)ÚImageé   )Úimg_as_ubyteÚimg_as_uintc                 óò   — t        | t        «      r9t        | d«      5 }t        j                  |«      }t	        |||¬«      cddd«       S t        j                  | «      }t	        |||¬«      S # 1 sw Y   yxY w)a£  Load an image from file.

    Parameters
    ----------
    fname : str or file
        File name or file-like-object.
    dtype : numpy dtype object or string specifier
        Specifies data type of array elements.
    img_num : int, optional
        Specifies which image to read in a file with multiple images
        (zero-indexed).
    kwargs : keyword pairs, optional
        Addition keyword arguments to pass through.

    Notes
    -----
    Files are read using the Python Imaging Library.
    See PIL docs [1]_ for a list of supported formats.

    References
    ----------
    .. [1] http://pillow.readthedocs.org/en/latest/handbook/image-file-formats.html
    Úrb)ÚdtypeÚimg_numN)Ú
isinstanceÚstrÚopenr   Úpil_to_ndarray)Úfnamer   r   ÚkwargsÚfÚims         úƒ/var/www/ITT-ServiceAPI-Services/ITT-Document-Scan/mrzscanner/mrzenv/lib/python3.12/site-packages/skimage/io/_plugins/pil_plugin.pyr   r   	   sq   € ô0 �%œÔÜ�%˜Óð 	D !Ü—‘˜A“ˆBÜ! "¨E¸7ÔC÷	Dñ 	Dô �Z‰Z˜ÓˆÜ˜b¨°wÔ?Ð?÷	Dð 	Dús   �#A-Á-A6c                 ó”  — 	 | j                  «       d    g }d}d}		 	 | j                  |	«       | }
|�||	k7  r| j                  «       d    |	dz  }	Œ5| j                  dk(  r| j                  d	k(  r|€d
}| j                  dk(  rb|€t        | «      }|r| j                  d«      }
n¢| j                  dk(  r d| j                  v r| j                  d«      }
ns| j                  d«      }
na| j                  dk(  r| j                  d«      }
n@d| j                  v r| j                  d«      }
n | j                  dk(  r| j                  d«      }
| j                  j                  d«      r}| j                  }| j                  j                  d«      rdnd}d| j                  v r|j                  dd«      }t!        j"                  |
j%                  «       |«      }
|ddd…   |
_        nt!        j(                  |
|¬«      }
|j+                  |
«       |	dz  }	|�n�Œòt-        | d«      r&| j.                  r| j.                  j1                  «        |€#t3        |«      dkD  rt!        j(                  |«      S |r|d   S |rt5        d|› �«      ‚y# t        $ r2}d}t        |«      }d| j                  › d|› d|› �}t	        |«      ‚d}~ww xY w# t        $ r Y Œ¸w xY w)zqImport a PIL Image object to an ndarray, in memory.

    Parameters
    ----------
    Refer to ``imread``.

    r   zLhttp://pillow.readthedocs.org/en/latest/installation.html#external-librarieszCould not load 'z' 
Reason: 'z'
Please see documentation at: Né   ÚPNGÚIÚuint16ÚPÚLÚtransparencyÚRGBAÚRGBÚ1ÚAÚCMYKúI;16ÚBz>u2z<u2ÚSÚuÚiéÿÿÿÿ)r   ÚfpzCould not find image  #)ÚgetdataÚOSErrorr   ÚfilenameÚ
ValueErrorÚseekÚEOFErrorÚformatÚmodeÚ_palette_is_grayscaleÚconvertÚinfoÚ
startswithÚsizeÚendswithÚreplaceÚnpÚ
frombufferÚtobytesÚshapeÚarrayÚappendÚhasattrr)   ÚcloseÚlenÚ
IndexError)Úimager   r   ÚeÚsiteÚpillow_error_messageÚerror_messageÚframesÚ	grayscaler'   Úframer<   s               r   r   r   *   s²  € ð(à�‰‹˜Òð €FØ€IØ	€AØ
ð	Ø�J‰J�qŒMð ˆàÐ 7¨a¢<Ø�M‰M‹O˜AÒØ�‰FˆAØà�<‰<˜5Ò  U§Z¡Z°3Ò%6¸5¸=ØˆEà�:‰:˜ÒØÐ Ü1°%Ó8�	áØŸ™ cÓ*‘à—<‘< 5Ò(¨^¸u¿z¹zÑ-IØ!ŸM™M¨&Ó1‘Eà!ŸM™M¨%Ó0‘Eà�Z‰Z˜3ÒØ—M‘M #Ó&‰Eà�E—J‘JÑØ—M‘M &Ó)‰Eà�Z‰Z˜6Ò!Ø—M‘M %Ó(ˆEà�:‰:× Ñ  Ô(Ø—J‘JˆEØ"ŸZ™Z×0Ñ0°Ô5‘E¸5ˆEØ�e—j‘jÑ ØŸ™ c¨3Ó/�Ü—M‘M %§-¡-£/°5Ó9ˆEØ¡ " ™+ˆE�Kô —H‘H˜U¨%Ô0ˆEà�‰�eÔØ	ˆQ‰ˆàÐØñi ôl ˆu�dÔ §¢Ø�‰�‰Ôà€œ3˜v›;¨š?Ü�x‰x˜ÓÐÙ	Ø�a‰yÐÙ	ÜÐ2°7°)Ð<Ó=Ð=ð 
øôS ò (Ø]ˆÜ" 1›vÐà˜uŸ~™~Ð.ð /Ø,Ð-ð .,Ø,0¨6ð3ð 	ô
 ˜Ó'Ð'ûð(ûô ò 	Ùð	ús(   ‚I= �J; É=	J8Ê-J3Ê3J8Ê;	KËKc                 ó"  — | j                   dk7  rt        d«      ‚t        j                  | j	                  «       «      j                  d«      }| j                  «       \  }}|||dz    }t        j                  t        j                  |«      d«      S )a  Return True if PIL image in palette mode is grayscale.

    Parameters
    ----------
    pil_image : PIL image
        PIL Image that is in Palette mode.

    Returns
    -------
    is_grayscale : bool
        True if all colors in image palette are gray.
    r   z$pil_image.mode must be equal to "P".)r(   r   r   r   )	r1   r-   r9   ÚasarrayÚ
getpaletteÚreshapeÚ
getextremaÚallcloseÚdiff)Ú	pil_imageÚpaletteÚstartÚstopÚvalid_palettes        r   r2   r2   ‚   s~   € ð ‡~�~˜ÒÜÐ?Ó@Ð@ô �j‰j˜×-Ñ-Ó/Ó0×8Ñ8¸ÓA€Gà×&Ñ&Ó(�K€Eˆ4Ø˜E D¨1¡HÐ-€Mô �;‰;”r—w‘w˜}Ó-¨qÓ1Ð1ó    c                 ó|  — | j                   dk(  r!t        | «      } dddœ| j                  d      }nŒ|dv r{d}| j                  j                  dk(  rt        | «      } na| j                  «       d	k  r5| j                  «       d
k\  r"| j                  t        j                  «      } d}nt        | «      } nt        | «      } d}	 | j                  «       }| j                   dk(  r@t        j                  || j                   j                  «      }	 |j#                  |d|«       |S | j                  d   | j                  d
   f}	 t        j"                  |||«      }|S # t        $ r | j                  «       }Y Œ¢w xY w# t        $ r |j%                  |d|«       Y |S w xY w# t        $ r t        j$                  |||«      }Y |S w xY w)z`Export an ndarray to a PIL object.

    Parameters
    ----------
    Refer to ``imsave``.

    r   r   r   ©r   é   é   )Úpngr   r#   r   é   r   r   Úrawr   )Úndimr   r<   r   Úkindr   ÚmaxÚminÚastyper9   Úuint8r;   ÚAttributeErrorÚtostringr   ÚnewÚTÚ	frombytesÚ
fromstring)ÚarrÚ
format_strr1   Úarray_bufferr   Úimage_shapes         r   Úndarray_to_pilro   œ   sž  € ð ‡x�x�1‚}Ü˜3ÓˆØ˜VÑ$ S§Y¡Y¨q¡\Ñ2‰à	�~Ñ	%Øˆà�9‰9�>‰>˜SÒ Ü˜cÓ"‰Cà�W‰W‹Y˜Š_ §¡£¨a¢Ø—*‘*œRŸX™XÓ&ˆCØ‰Dô ˜cÓ"‰Cô ˜3ÓˆØˆð&Ø—{‘{“}ˆð ‡x�x�1‚}Ü�Y‰Y�t˜SŸU™UŸ[™[Ó)ˆð	5Ø�L‰L˜ u¨dÔ3ð €Ið —y‘y ‘| S§Y¡Y¨q¡\Ð2ˆð	CÜ—‘  {°LÓAˆBð €Iøô ò &Ø—|‘|“~Šð&ûô ò 	5Ø�M‰M˜,¨¨tÕ4ð €Ið	5ûô ò 	CÜ×!Ñ! $¨°\ÓB‰BØ€Ið	Cús6   Â>E ÄE4 Ä<F ÅE1Å0E1Å4FÆFÆ F;Æ:F;c                 ó  — t        | t        «      s|€d}t        | t        «      r!| j                  «       j                  d«      rd}t	        j
                  |«      }|j                  j                  dk(  r|j                  t        j                  «      }|j                  dvrt        d|j                  › �«      ‚|j                  dk(  r|j                  d   d	vrt        d
«      ‚t        ||¬«      } |j                  | fd|i|¤Ž y)a=  Save an image to disk.

    Parameters
    ----------
    fname : str or file-like object
        Name of destination file.
    arr : ndarray of uint8 or float
        Array (image) to save.  Arrays of data-type uint8 should have
        values in [0, 255], whereas floating-point arrays must be
        in [0, 1].
    format_str : str
        Format to save as, this is defaulted to PNG if using a file-like
        object; this will be derived from the extension if fname is a string
    kwargs : dict
        Keyword arguments to the Pillow save function (or tifffile save
        function, for Tiff files). These are format dependent. For example,
        Pillow's JPEG save function supports an integer ``quality`` argument
        with values in [1, 95], while TIFFFile supports a ``compress``
        integer argument with values in [0, 9].

    Notes
    -----
    Use the Python Imaging Library.
    See PIL docs [1]_ for a list of other supported formats.
    All images besides single channel PNGs are converted using `img_as_uint8`.
    Single Channel PNGs have the following behavior:
    - Integer values in [0, 255] and Boolean types -> img_as_uint8
    - Floating point and other integers -> img_as_uint16

    References
    ----------
    .. [1] http://pillow.readthedocs.org/en/latest/handbook/image-file-formats.html
    Nr   z.pngÚb)r[   r   zInvalid shape for image array: r   r[   rY   z*Invalid number of channels in image array.)rl   r0   )r   r   Úlowerr7   r9   Ú
asanyarrayr   r`   rc   rd   r_   r-   r<   ro   Úsave)r   rk   rl   r   Úimgs        r   r   r   Í   sÙ   € ôF �eœSÔ! jÐ&8Øˆ
ä�%œÔ %§+¡+£-×"8Ñ"8¸Ô"@Øˆ
ä
�-‰-˜Ó
€Cà
‡y�y‡~�~˜ÒØ�j‰jœŸ™Ó"ˆà
‡x�x�vÑÜÐ:¸3¿9¹9¸+ÐFÓGÐGà
‡x�x�1‚}Ø�9‰9�Q‰<˜vÑ%ÜÐIÓJÐJä
˜¨Ô
4€CØ€C‡H�HˆUÑ0˜:Ð0¨Ó0rW   )NN)N)Ú__all__Únumpyr9   ÚPILr   Úutilr   r   r   r   r2   ro   r   © rW   r   ú<module>r{      s6   ðØ�XÐ
€ã Ý ç -ó@óBU>òp2ó4.ôb61rW   