
    0-Ph;T                     >   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlZ	d dl
mZ d dlmZ d dlmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ dZdZ e j        d          ZdddZ edg ed          z             D ],\  Z Z!de z  ee!<   e!rde z  ee!"                                dz   <   -d-dZ#d-dZ$de%dee%e%f         fdZ& G d d          Z' G d d          Z(d Z)d  Z*d.d"Z+d.d#Z,d-d$Z-d-d%Z.defd&Z/d-d'Z0d-d(Z1d-d)Z2defd*Z3d-d+Z4e+Z5e,Z6e.Z7e0Z8e2Z9e4Z:g d,Z;dS )/    N)Number)Path)Dict)LegacyPlugin)Array)PluginV3   )formats)known_extensionsknown_plugins)RETURN_BYTES)imopen256MB1GBz"^(\d+\.?\d*)\s*([kKMGTPEZY]?i?)B?$) Nr   kMGTPEZYi  i   ic                    | st          d          } | du r|} t          | t                    r| S t                              |           }|"t          d                    |                     |                                \  }}	 t          |          t          |         z  S # t          $ r# t          d                    |                    w xY w)NinfTzEMemory size could not be parsed (is your capitalisation correct?): {}zEMemory size unit not recognised (is your capitalisation correct?): {})
float
isinstancer   mem_rematch
ValueErrorformatgroupssizesKeyError)argdefaultr   numunits        J/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/imageio/v2.py	to_nbytesr$   !   s     Ell
d{{#v 
LLE}44:F3KK
 
 	

 IC
SzzE$K'' 
 
 
44:F4LL
 
 	

s   B" "-Cc                 j    | st          t                     dS t          t          |                     dS )aC  help(name=None)

    Print the documentation of the format specified by name, or a list
    of supported formats if name is omitted.

    Parameters
    ----------
    name : str
        Can be the name of a format, a filename extension, or a full
        filename. See also the :doc:`formats page <../formats/index>`.
    N)printr
   )names    r#   helpr(   >   s3      ggdm    format_namereturnc                 .   d}d}| n	t          |           j                                        t          v r't          |           j                                        }n| t          v r| }n|                                 t          v r|                                 }ny|                                 t          v r|                                 }nId|                                 z   t          v rd|                                 z   }nt          d| d          ||dS )zSplit format into plugin and format

    The V2 API aliases plugins and supported formats. This function
    splits these so that they can be fed separately to `iio.imopen`.

    N.zNo format known by name `z`.)plugin	extension)r   suffixlowerr   r   upper
IndexError)r*   r.   r/   s      r#   decypher_format_argr4   P   s    FI	k			!	'	'	)	)-=	=	=%%,2244				%	%						-	-""$$					 0	0	0%%''			{  ""	"&6	6	6+++---		?V???@@@9555r)   c                       e Zd ZdefdZd Zd Zd Zd Ze	d             Z
e	d             Zd	 Zd
 Zd Zd ZddZd Zd Zd ZdS )LegacyReaderplugin_instancec                     || _         d| _        d| _        t          | j                   j        dk    r#|                    d          |d         |d<   |d= || _        d S Nr   FPillowPluginpilmodemode)instance
last_indexclosedtype__name__get	read_argsselfr7   kwargss      r#   __init__zLegacyReader.__init__n   sd    ' (N::

9%%1#I.F6Ny!r)   c                 T    | j         s| j                                         d| _         d S NTr?   r=   closerE   s    r#   rK   zLegacyReader.close|   +    { 	"M!!!r)   c                     | S N rL   s    r#   	__enter__zLegacyReader.__enter__       r)   c                 .    |                                   d S rO   rK   rE   r@   value	tracebacks       r#   __exit__zLegacyReader.__exit__       

r)   c                 .    |                                   d S rO   rT   rL   s    r#   __del__zLegacyReader.__del__   rY   r)   c                     | j         j        S rO   r=   requestrL   s    r#   r^   zLegacyReader.request       }$$r)   c                      t          d          NzV3 Plugins don't have a format.	TypeErrorrL   s    r#   r   zLegacyReader.format       9:::r)   c                 B    | j                             d          j        S )N.)index)r=   
propertiesn_imagesrL   s    r#   
get_lengthzLegacyReader.get_length   s    }''c'22;;r)   c                     || _          | j        j        dd|i| j        }| j                            |d          }t          ||          S )Nrf   Frf   exclude_appliedrP   )r>   r=   readrC   metadatar   )rE   rf   imgrn   s       r#   get_datazLegacyReader.get_data   sT     dm ??u???=))u)MMS(###r)   c                 <    |                      | j        dz             S Nr	   )rp   r>   rL   s    r#   get_next_datazLegacyReader.get_next_data   s    }}T_q0111r)   c                     |dz
  | _         d S rr   )r>   rE   rf   s     r#   set_image_indexzLegacyReader.set_image_index   s    !)r)   Nc                 :    | j                             |d          S NFrk   )r=   rn   ru   s     r#   get_meta_datazLegacyReader.get_meta_data   s    }%%E5%IIIr)   c              #      K   t          | j                                                  D ]3\  }}| j                            |d          }t	          ||          V  4d S rx   )	enumerater=   iterrn   r   )rE   idxro   rn   s       r#   	iter_datazLegacyReader.iter_data   sl      !$-"4"4"6"677 	' 	'HC}--C-OOHX&&&&&&	' 	'r)   c                 *    |                                  S rO   )r~   rL   s    r#   __iter__zLegacyReader.__iter__   s    ~~r)   c                 *    |                                  S rO   )ri   rL   s    r#   __len__zLegacyReader.__len__   s       r)   rO   )rA   
__module____qualname__r   rG   rK   rQ   rX   r[   propertyr^   r   ri   rp   rs   rv   ry   r~   r   r   rP   r)   r#   r6   r6   m   s"                  
       % % X% ; ; X;< < <$ $ $2 2 2$ $ $J J J J' ' '
     ! ! ! ! !r)   r6   c                   l    e Zd ZdefdZd Zd Zd Zd Ze	d             Z
e	d             Zdd
Zd Zd	S )LegacyWriterr7   c                     || _         d| _        d| _        t          | j                   j        dk    rd|v r|d         |d<   |d= || _        d S r9   )r=   r>   r?   r@   rA   
write_argsrD   s      r#   rG   zLegacyWriter.__init__   sZ    ''>99i6>Q>Q#I.F6Ny! r)   c                 T    | j         s| j                                         d| _         d S rI   rJ   rL   s    r#   rK   zLegacyWriter.close   rM   r)   c                     | S rO   rP   rL   s    r#   rQ   zLegacyWriter.__enter__   rR   r)   c                 .    |                                   d S rO   rT   rU   s       r#   rX   zLegacyWriter.__exit__   rY   r)   c                 .    |                                   d S rO   rT   rL   s    r#   r[   zLegacyWriter.__del__   rY   r)   c                     | j         j        S rO   r]   rL   s    r#   r^   zLegacyWriter.request   r_   r)   c                      t          d          ra   rb   rL   s    r#   r   zLegacyWriter.format   rd   r)   Nc                 ^    |t          j        d            | j        j        |fi | j        S )Nz\V3 Plugins currently don't have a uniform way to write metadata, so any metadata is ignored.)warningswarnr=   writer   )rE   immetas      r#   append_datazLegacyWriter.append_data   sD     M?   #t}"299999r)   c                      t          d          )Nz<V3 Plugins don't have a uniform way to write metadata (yet).)NotImplementedError)rE   r   s     r#   set_meta_datazLegacyWriter.set_meta_data   s    !J
 
 	
r)   rO   )rA   r   r   r   rG   rK   rQ   rX   r[   r   r^   r   r   r   rP   r)   r#   r   r      s        	! 	! 	! 	! 	!  
       % % X% ; ; X;: : : :$
 
 
 
 
r)   r   c                     t          | t          t          f          rdS t          j        |           } | j        dk    rdS | j        dk    r| j        d         dk     rdS dS )NT   F      )r   listtuplenpasarrayndimshapendimages    r#   is_batchr      sf    'D%=)) tj!!G|qu			w}Q/!33u4r)   c                     t          j        |           } t          |           sdS | j        dk    r| j        d         dk    rdS | j        dk    r| j        d         dk     rdS dS )NFr   r   r   T   )r   r   r   r   r   r   s    r#   	is_volumer      sq    j!!GG u|qW]1-22t			w}Q/!33tur)   ?c                     t          |          }d|d<   t          | d|z   fi |}t          |t                    r |j        di |S t          |fi |S )a  get_reader(uri, format=None, mode='?', **kwargs)

    Returns a :class:`.Reader` object which can be used to read data
    and meta data from the specified file.

    Parameters
    ----------
    uri : {str, pathlib.Path, bytes, file}
        The resource to load the image from, e.g. a filename, pathlib.Path,
        http address or file object, see the docs for more info.
    format : str
        The format to use to read the file. By default imageio selects
        the appropriate for you based on the filename and its contents.
    mode : {'i', 'I', 'v', 'V', '?'}
        Used to give the reader a hint on what the user expects (default "?"):
        "i" for an image, "I" for multiple images, "v" for a volume,
        "V" for multiple volumes, "?" for don't care.
    kwargs : ...
        Further keyword arguments are passed to the reader. See :func:`.help`
        to see what arguments are available for a particular format.
    Tlegacy_moderNrP   )r4   r   r   r   legacy_get_readerr6   urir   r<   rF   imopen_args
image_files         r#   
get_readerr     sw    . &f--K!%KS4Z77;77J*l++ 2+z+55f555J11&111r)   c                     t          |          }d|d<   t          | d|z   fi |}t          |t                    r |j        di |S t          |fi |S )a  get_writer(uri, format=None, mode='?', **kwargs)

    Returns a :class:`.Writer` object which can be used to write data
    and meta data to the specified file.

    Parameters
    ----------
    uri : {str, pathlib.Path, file}
        The resource to write the image to, e.g. a filename, pathlib.Path
        or file object, see the docs for more info.
    format : str
        The format to use to write the file. By default imageio selects
        the appropriate for you based on the filename.
    mode : {'i', 'I', 'v', 'V', '?'}
        Used to give the writer a hint on what the user expects (default '?'):
        "i" for an image, "I" for multiple images, "v" for a volume,
        "V" for multiple volumes, "?" for don't care.
    kwargs : ...
        Further keyword arguments are passed to the writer. See :func:`.help`
        to see what arguments are available for a particular format.
    Tr   wNrP   )r4   r   r   r   legacy_get_writerr   r   s         r#   
get_writerr   *  sw    . &f--K!%KS4Z77;77J*l++ 2+z+55f555J11&111r)   c                     t          |          }d|d<   t          | dfi |5 } |j        dddi|}ddd           n# 1 swxY w Y   |S )aX  imread(uri, format=None, **kwargs)

    Reads an image from the specified file. Returns a numpy array, which
    comes with a dict of meta data at its 'meta' attribute.

    Note that the image data is returned as-is, and may not always have
    a dtype of uint8 (and thus may differ from what e.g. PIL returns).

    Parameters
    ----------
    uri : {str, pathlib.Path, bytes, file}
        The resource to load the image from, e.g. a filename, pathlib.Path,
        http address or file object, see the docs for more info.
    format : str
        The format to use to read the file. By default imageio selects
        the appropriate for you based on the filename and its contents.
    kwargs : ...
        Further keyword arguments are passed to the reader. See :func:`.help`
        to see what arguments are available for a particular format.
    Tr   rirf   r   NrP   r4   r   rm   )r   r   rF   r   fileresults         r#   imreadr   N  s    , &f--K!%K	T	)	)[	)	) .T---f--. . . . . . . . . . . . . . . Ms   ?AAc                    t          |          }t          j        |          }t          j        |j        t          j                  s't          d                    |j                            t          |          s|j
        dk     rt          d          t          |          }d|d<   t          | dfi |5 } |j        |fi |cddd           S # 1 swxY w Y   dS )a  imwrite(uri, im, format=None, **kwargs)

    Write an image to the specified file.

    Parameters
    ----------
    uri : {str, pathlib.Path, file}
        The resource to write the image to, e.g. a filename, pathlib.Path
        or file object, see the docs for more info.
    im : numpy.ndarray
        The image data. Must be NxM, NxMx3 or NxMx4.
    format : str
        The format to use to write the file. By default imageio selects
        the appropriate for you based on the filename and its contents.
    kwargs : ...
        Further keyword arguments are passed to the writer. See :func:`.help`
        to see what arguments are available for a particular format.
    zImage is not numeric, but {}.r   z+Image must be 2D (grayscale, RGB, or RGBA).Tr   wiN)r@   r   r   
issubdtypedtypenumberr   r   rA   r   r   r4   r   r   )r   r   r   rF   imtr   r   s          r#   imwriter   m  s#   * r((C	BB=29-- O8??MMNNN|| Hrw{{FGGG%f--K!%K	T	)	)[	)	) (Ttz"''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   :CCCc           	         t          |t                    }t                      }d}t          |          }d|d<   t	          | dfi |5 } |j        di |D ]V}	|                    |	           ||	j        z  }||k    r/t          d	                    t          |                              W	 ddd           n# 1 swxY w Y   t          |          dk    rt          |d                   r
g |d         }|S )	a  mimread(uri, format=None, memtest="256MB", **kwargs)

    Reads multiple images from the specified file. Returns a list of
    numpy arrays, each with a dict of meta data at its 'meta' attribute.

    Parameters
    ----------
    uri : {str, pathlib.Path, bytes, file}
        The resource to load the images from, e.g. a filename,pathlib.Path,
        http address or file object, see the docs for more info.
    format : str
        The format to use to read the file. By default imageio selects
        the appropriate for you based on the filename and its contents.
    memtest : {bool, int, float, str}
        If truthy, this function will raise an error if the resulting
        list of images consumes greater than the amount of memory specified.
        This is to protect the system from using so much memory that it needs
        to resort to swapping, and thereby stall the computer. E.g.
        ``mimread('hunger_games.avi')``.

        If the argument is a number, that will be used as the threshold number
        of bytes.

        If the argument is a string, it will be interpreted as a number of bytes with
        SI/IEC prefixed units (e.g. '1kB', '250MiB', '80.3YB').

        - Units are case sensitive
        - k, M etc. represent a 1000-fold change, where Ki, Mi etc. represent 1024-fold
        - The "B" is optional, but if present, must be capitalised

        If the argument is True, the default will be used, for compatibility reasons.

        Default: '256MB'
    kwargs : ...
        Further keyword arguments are passed to the reader. See :func:`.help`
        to see what arguments are available for a particular format.
    r   Tr   rIimageio.mimread() has read over {}B of image data.
Stopped to avoid memory problems. Use imageio.get_reader(), increase threshold, or memtest=FalseNr	   rP   )r$   MEMTEST_DEFAULT_MIMr   r4   r   r|   appendnbytesRuntimeErrorr   intlenr   
r   r   memtestrF   nbyte_limitimagesr   r   r   images
             r#   mimreadr     sc   P G%899KVVFF%f--K!%K	T	)	)[	)	) TTY(((( 
	 
	EMM%   el"F##"VV\V\K((W W   $
	               6{{aHVAY//6!9M   A%B::B>B>c                     t          |          st          d          t          |          }d|d<   t          | dfi |5 } |j        |fddi|cddd           S # 1 swxY w Y   dS )a  mimwrite(uri, ims, format=None, **kwargs)

    Write multiple images to the specified file.

    Parameters
    ----------
    uri : {str, pathlib.Path, file}
        The resource to write the images to, e.g. a filename, pathlib.Path
        or file object, see the docs for more info.
    ims : sequence of numpy arrays
        The image data. Each array must be NxM, NxMx3 or NxMx4.
    format : str
        The format to use to read the file. By default imageio selects
        the appropriate for you based on the filename and its contents.
    kwargs : ...
        Further keyword arguments are passed to the writer. See :func:`.help`
        to see what arguments are available for a particular format.
    z*Image data must be a sequence of ndimages.Tr   wIr   N)r   r   r4   r   r   )r   imsr   rF   r   r   s         r#   mimwriter     s    ( C== GEFFF%f--K!%K	T	)	)[	)	) 8Ttz#777778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s   AA"%A"c                     t          |          }d|d<   t          | dfi |5 } |j        dddi|cddd           S # 1 swxY w Y   dS )a  volread(uri, format=None, **kwargs)

    Reads a volume from the specified file. Returns a numpy array, which
    comes with a dict of meta data at its 'meta' attribute.

    Parameters
    ----------
    uri : {str, pathlib.Path, bytes, file}
        The resource to load the volume from, e.g. a filename, pathlib.Path,
        http address or file object, see the docs for more info.
    format : str
        The format to use to read the file. By default imageio selects
        the appropriate for you based on the filename and its contents.
    kwargs : ...
        Further keyword arguments are passed to the reader. See :func:`.help`
        to see what arguments are available for a particular format.
    Tr   rvrf   r   NrP   r   )r   r   rF   r   r   s        r#   volreadr     s    & &f--K!%K	T	)	)[	)	) ,Tty++q+F++, , , , , , , , , , , , , , , , , ,s   ?AAc                     t          j        |          }t          |          st          d          t	          |          }d|d<   t          | dfi |5 } |j        |fddi|cddd           S # 1 swxY w Y   dS )a  volwrite(uri, vol, format=None, **kwargs)

    Write a volume to the specified file.

    Parameters
    ----------
    uri : {str, pathlib.Path, file}
        The resource to write the image to, e.g. a filename, pathlib.Path
        or file object, see the docs for more info.
    vol : numpy.ndarray
        The image data. Must be NxMxL (or NxMxLxK if each voxel is a tuple).
    format : str
        The format to use to read the file. By default imageio selects
        the appropriate for you based on the filename and its contents.
    kwargs : ...
        Further keyword arguments are passed to the writer. See :func:`.help`
        to see what arguments are available for a particular format.
    1Image must be 3D, or 4D if each voxel is a tuple.Tr   wvr   FN)r   r   r   r   r4   r   r   )r   r   r   rF   r   r   s         r#   volwriter     s    * 
BBR== NLMMM%f--K!%K	T	)	)[	)	) 8Ttz"77u7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s   A22A69A6c           	         t          |t                    }t                      }d}t          |          }d|d<   t	          | dfi |5 } |j        di |D ]V}	|                    |	           ||	j        z  }||k    r/t          d	                    t          |                              W	 ddd           n# 1 swxY w Y   |S )a  mvolread(uri, format=None, memtest='1GB', **kwargs)

    Reads multiple volumes from the specified file. Returns a list of
    numpy arrays, each with a dict of meta data at its 'meta' attribute.

    Parameters
    ----------
    uri : {str, pathlib.Path, bytes, file}
        The resource to load the volumes from, e.g. a filename, pathlib.Path,
        http address or file object, see the docs for more info.
    format : str
        The format to use to read the file. By default imageio selects
        the appropriate for you based on the filename and its contents.
    memtest : {bool, int, float, str}
        If truthy, this function will raise an error if the resulting
        list of images consumes greater than the amount of memory specified.
        This is to protect the system from using so much memory that it needs
        to resort to swapping, and thereby stall the computer. E.g.
        ``mimread('hunger_games.avi')``.

        If the argument is a number, that will be used as the threshold number
        of bytes.

        If the argument is a string, it will be interpreted as a number of bytes with
        SI/IEC prefixed units (e.g. '1kB', '250MiB', '80.3YB').

        - Units are case sensitive
        - k, M etc. represent a 1000-fold change, where Ki, Mi etc. represent 1024-fold
        - The "B" is optional, but if present, must be capitalised

        If the argument is True, the default will be used, for compatibility reasons.

        Default: '1GB'
    kwargs : ...
        Further keyword arguments are passed to the reader. See :func:`.help`
        to see what arguments are available for a particular format.
    r   Tr   rVr   NrP   )r$   MEMTEST_DEFAULT_MVOLr   r4   r   r|   r   r   r   r   r   r   s
             r#   mvolreadr   1  s4   P G%9::KVVFF%f--K!%K	T	)	)[	)	) TTY(((( 
	 
	EMM%   el"F##"VV\V\K((W W   $
	               Mr   c                     |D ] }t          |          st          d          !t          |          }d|d<   t          | dfi |5 } |j        |fddi|cddd           S # 1 swxY w Y   dS )a  mvolwrite(uri, vols, format=None, **kwargs)

    Write multiple volumes to the specified file.

    Parameters
    ----------
    uri : {str, pathlib.Path, file}
        The resource to write the volumes to, e.g. a filename, pathlib.Path
        or file object, see the docs for more info.
    ims : sequence of numpy arrays
        The image data. Each array must be NxMxL (or NxMxLxK if each
        voxel is a tuple).
    format : str
        The format to use to read the file. By default imageio selects
        the appropriate for you based on the filename and its contents.
    kwargs : ...
        Further keyword arguments are passed to the writer. See :func:`.help`
        to see what arguments are available for a particular format.
    r   Tr   wVr   N)r   r   r4   r   r   )r   r   r   rF   r   r   r   s          r#   	mvolwriter   o  s    *  R R}} 	RPQQQ	R &f--K!%K	T	)	)[	)	) 8Ttz#777778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s   A##A'*A')r   r   r   r   r   r   r   r   r(   r   r   r   rO   )Nr   )<rer   numbersr   pathlibr   typingr   numpyr   "imageio.core.legacy_plugin_wrapperr   imageio.core.utilr   imageio.core.v3_plugin_apir   r   r
   configr   r   corer   core.imopenr   r   r   compiler   r   r{   r   r   sir2   r$   r(   strr4   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   rm   saveimsavemimsavevolsavemvolsave__all__rP   r)   r#   <module>r      sJ   
			                        ; ; ; ; ; ; # # # # # # / / / / / /       3 3 3 3 3 3 3 3               
9	:	:aYtdd:...// * *EAraE"I	 *"&'bhhjj3
 
 
 
:   $6S 6T#s(^ 6 6 6 6:@! @! @! @! @! @! @! @!F8
 8
 8
 8
 8
 8
 8
 8
v
 
 

 
 
 2 2 2 2D2 2 2 2H   > (  (  (  (L &9 ? ? ? ?D8 8 8 8@, , , ,28 8 8 8F '; ; ; ; ;|8 8 8 8@ 	

  r)   