
    9i)F                        S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
\
R                  " S5      rS\R                  ;   r\R                  R!                  \R                  R#                  \5      5      rS rSS jrSS jr " S	 S
\R.                  5      r\rS r " S S\5      r " S S\5      r " S S\5      rSS jrS r S r!S r"S r#g)z
Various utilities for imageio
    )OrderedDictNimageio__pypy__c                  R     SSK Jn  U" U 0 UD6$ ! [         a    [        S5      ef = f)zCompatibility function for the urlopen function. Raises an
RuntimeError if urlopen could not be imported (which can occur in
frozen applications.
r   )urlopenzCould not import urlopen.)urllib.requestr   ImportErrorRuntimeError)argskwargsr   s      Q/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/imageio/core/util.pyr   r      s9    
8* D#F##  86778s    &c                 R    Sn[         R                  UR                  XX!5      5        g )Nz`Lossy conversion from {} to {}. {} Convert image to {} prior to saving to suppress this warning.)loggerwarningformat)p1p2extrats       r   _precision_warnr   %   s%    	+  NN188BE./    c                 L   U(       d  Sn[        U [        R                  5      (       d  [        S5      eUS:X  a  [        R                  nO"US:X  a  [        R
                  nO[        S5      e[        U R                  5      nUR                  nU R                  [        R                  :X  a  US:X  d$  U R                  [        R
                  :X  a  US:X  a  U $ UR                  S5      (       a  [        R                  " U 5      S:  ae  [        R                  " U 5      S::  aK  [        X4S5        U R                  [        R                  5      [        R                  " S	U5      S-
  -  S
-   n GOU R                  [        R
                  :X  a+  US:X  a%  [        X4S5        [        R                   " U S5      n GOU R                  [        R"                  :X  a;  [        UUSR%                  SU-
  5      5        [        R                   " U SU-
  5      n GO9U R                  [        R&                  :X  a:  [        UUSR%                  SU-
  5      5        [        R                   " U SU-
  5      n O[        R                  " U 5      n[        R                  " U 5      n[        R(                  " U5      (       d  [        S5      e[        R(                  " U5      (       d  [        S5      eXe:X  a  U R                  U5      $ [        X4SR%                  XV5      5        U R                  S5      n X-
  Xe-
  -  [        R                  " S	U5      S-
  -  S
-   n [        R                  " U 5      S:  d   e[        R                  " U 5      [        R                  " S	U5      :  d   eU R                  U5      $ )a  Convert the given image to uint (default: uint8)

If the dtype already matches the desired format, it is returned
as-is. If the image is float, and all values are between 0 and 1,
the values are multiplied by np.power(2.0, bitdepth). In all other
situations, the values are scaled such that the minimum value
becomes 0 and the maximum value becomes np.power(2.0, bitdepth)-1
(255 for 8-bit and 65535 for 16-bit).
   zImage must be a numpy array   zBitdepth must be either 8 or 16floatr      zRange [0, 1].g       @gA?zLosing 8 bits of resolution.zLosing {} bits of resolution.    @   z!Minimum image value is not finitez!Maximum image value is not finitezRange [{}, {}].float64)
isinstancenpndarray
ValueErroruint8uint16strdtype__name__
startswithnanminnanmaxr   astyper   powerright_shiftuint32r   uint64isfinite)imbitdepthout_type
dtype_str1
dtype_str2mimas          r   image_as_uintr9   -   s    b"**%%6771}88	R99:;;RXXJ""J
BHHQ
BII(b. 	W%%"))B-1*<2RSAS
@YYrzz"bhhsH&=&AB[P	RYY	8q=
0NO^^B"	RYY	+222=A	

 ^^BX.	RYY	+222=A	

 ^^BX.YYr]YYr]{{2@AA{{2@AA899X&&
0A0H0H0PQYYy!g"'"bhhsH&=&AB[P99R=A99R=288C222299Xr   c                   H    \ rS rSrSrS
S jrS r\S 5       rS r	S
S jr
S	rg)Arrayo   zArray(array, meta=None)

A subclass of np.ndarray that has a meta attribute. Get the dictionary
that contains the meta data using ``im.meta``. Convert to a plain numpy
array using ``np.asarray(im)``.

Nc                 .   [        U[        R                  5      (       d  [        S5      eUb   [        U[        5      (       d  [        S5      eUb  UO[        US0 5      n UR                  U 5      nUR                  U5        U$ ! [         a    Us $ f = f)NzArray expects a numpy array.z%Array expects meta data to be a dict.meta)	r    r!   r"   r#   dictgetattrviewAttributeError
_copy_meta)clsarrayr>   obs       r   __new__Array.__new__x   s    %,,;<<
4 6 6DEE'tWUFB-G	CB 	d		  	L	s   !B BBc                     [        5       U l        UR                  5        H3  u  p#[        U[        5      (       a  [        U5      nX0R                  U'   M5     g)z0Make a 2-level deep copy of the meta dictionary.N)Dict_metaitemsr    r?   )selfr>   keyvals       r   rC   Array._copy_meta   s>    V


HC#t$$3i!JJsO %r   c                     U R                   $ )z*The dict with the meta data of this image.rK   rM   s    r   r>   
Array.meta   s     zzr   c                     [        U[        5      (       a  U R                  UR                  5        gU R                  0 5        g)zGSo the meta info is maintained when doing calculations with
the array.
N)r    r;   rC   r>   )rM   rF   s     r   __array_finalize__Array.__array_finalize__   s-     b%  OOBGG$OOBr   c                     UR                   (       d  UR                  R                  U5      $ UR                   U R                   :w  a  UR                  [        R
                  S9$ [        U[        5      (       d  [        XR                  5      $ U$ )zrSo that we return a native numpy array (or scalar) when a
reducting ufunc is applied (such as sum(), std(), etc.)
type)	shaper'   rZ   rA   r!   r"   r    r;   r>   )rM   outcontexts      r   __array_wrap__Array.__array_wrap__   sd     yy99>>#&&YY$**$888,,C''ii((Jr   rR   N)r(   
__module____qualname____firstlineno____doc__rG   rC   propertyr>   rV   r^   __static_attributes__ r   r   r;   r;   o   s/     "   r   r;   c                     [        U [        R                  5      (       a:  [        (       a  U R	                  5       n U R                  [        R                  S9nU$ [        R                  " U 5      $ )zPypy-safe version of np.asarray. Pypy's np.asarray consumes a
*lot* of memory if the given array is an ndarray subclass. This
function does not.
rY   )r    r!   r"   IS_PYPYcopyrA   asarray)aplains     r   rk   rk      sL    
 !RZZ  7ABJJ'::a=r   c                   ^    \ rS rSrSr\" \" 5       5      r\" \" 5       5      r	S r
S rS rSrg)rJ      a  A dict in which the keys can be get and set as if they were
attributes. Very convenient in combination with autocompletion.

This Dict still behaves as much as possible as a normal dict, and
keys can be anything that are otherwise valid keys. However,
keys that are not valid identifiers or that are names of the dict
class (such as 'items' and 'copy') cannot be get/set as attributes.
c                 b     [         R                  X5      $ ! [         a    X;   a  X   s $ e f = fr`   )object__getattribute__rB   )rM   rN   s     r   rr   Dict.__getattribute__   s7    	**455 	{y 		s    ..c                     U[         R                  ;   a<  U[         R                  ;  a  [        R                  " XU5      $ [        SSU-  -   5      eX U'   g )Nz!Reserved name, this key can only zbe set via ``d[%r] = X``)rJ   __reserved_names____pure_names__r   __setattr__rB   )rM   rN   rO   s      r   rw   Dict.__setattr__   sW    $)))$---"..t#>>$70367  Ir   c                     S nU R                  5        Vs/ s H+  n[        U[        5      (       d  M  U" U5      (       d  M)  UPM-     nn[        R                  U-   $ s  snf )Nc                 `    [        [        R                  " SU [        R                  5      5      $ )Nz
[a-z_]\w*$)boolrematchI)xs    r   isidentifier"Dict.__dir__.<locals>.isidentifier   s    244899r   )keysr    r&   rJ   ru   )rM   r   knamess       r   __dir__Dict.__dir__   sL    	: !IIKTKqJq#,><PQ?KT&&.. Us   AAArg   N)r(   ra   rb   rc   rd   dirr   ru   r?   rv   rr   rw   r   rf   rg   r   r   rJ   rJ      s0     []+[N/r   rJ   c                   p    \ rS rSrSrS rSS jrS rSS jrS r	SS	 jr
SS
 jrS rS rS rS rS rSrg)BaseProgressIndicator   a  BaseProgressIndicator(name)

A progress indicator helps display the progress of a task to the
user. Progress can be pending, running, finished or failed.

Each task has:
  * a name - a short description of what needs to be done.
  * an action - the current action in performing the task (e.g. a subtask)
  * progress - how far the task is completed
  * max - max number of progress units. If 0, the progress is indefinite
  * unit - the units in which the progress is counted
  * status - 0: pending, 1: in progress, 2: finished, 3: failed

This class defines an abstract interface. Subclasses should implement
_start, _stop, _update_progress(progressText), _write(message).
c                 V    Xl         SU l        SU l        SU l        SU l        SU l        g )N r   )_name_action_unit_max_status_last_progress_update)rM   names     r   __init__BaseProgressIndicator.__init__   s+    

	%&"r   c                     U R                   S:X  a  U R                  5         Xl        X l        X0l        SU l        SU l         U R                  5         g)zzstart(action='', unit='', max=0)

Start the progress. Optionally specify an action, a unit,
and a maximum progress value.
r   r   N)r   finishr   r   r   	_progress_start)rM   actionunitmaxs       r   startBaseProgressIndicator.start  s?     <<1KKM
	r   c                     U R                   $ )z^status()

Get the status of the progress - 0: pending, 1: in progress,
2: finished, 3: failed
)r   rS   s    r   statusBaseProgressIndicator.status  s     ||r   c                    Xl         U(       d'  [        R                  " 5       U R                  -
  S:  d  g[        R                  " 5       U l        U R                  =(       d    SnSnUS:X  a  SU-  nOeU R                  S:  a-  S[        U5      -  U R                  -  nSXR                  X54-  nO(US:  a"  [        U[
        5      (       a  S	X4-  nOS
X4-  nU R                  U5        g)zset_progress(progress=0, force=False)

Set the current progress. To avoid unnecessary progress updates
this will only have a visual effect if the time since the last
update is > 0.1 seconds, or if force is True.
g?Nr   %z%2.1f%%r   d   z%i/%i %s (%2.1f%%)z%0.4g %sz%i %s)r   timer   r   r   r   r    _update_progress)rM   progressforcer   progressTextpercents         r   set_progress"BaseProgressIndicator.set_progress  s     "$))+(B(BBSH%)YY["zzR3;$x/LYY]E(O+dii7G/8YY2VVL\(E**)X,<<&()99l+r   c                 @    U R                  U R                  U-   5        g)zNincrease_progress(extra_progress)

Increase the progress by a certain amount.
N)r   r   )rM   extra_progresss     r   increase_progress'BaseProgressIndicator.increase_progress6  s    
 	$..>9:r   Nc                     U R                  U R                  S5        SU l        U R                  5         Ub  U R	                  U5        gg)z{finish(message=None)

Finish the progress, optionally specifying a message. This will
not set the progress to the maximum.
T   Nr   r   r   _stop_writerM   messages     r   r   BaseProgressIndicator.finish=  s?     	$..$/

KK  r   c                     U R                  U R                  S5        SU l        U R                  5         SU=(       d    S-   nU R	                  U5        g)zWfail(message=None)

Stop the progress with a failure, optionally specifying a message.
T   zFAIL r   Nr   r   s     r   failBaseProgressIndicator.failI  sB    
 	$..$/

W]+Gr   c                 d    U R                   [        :X  a  [        U5        gU R                  U5      $ )zEwrite(message)

Write a message during progress (such as a warning).
N)	__class__r   printr   r   s     r   writeBaseProgressIndicator.writeT  s'    
 >>22'N;;w''r   c                     g r`   rg   rS   s    r   r   BaseProgressIndicator._starta      r   c                     g r`   rg   rS   s    r   r   BaseProgressIndicator._stopd  r   r   c                     g r`   rg   )rM   r   s     r   r   &BaseProgressIndicator._update_progressg  r   r   c                     g r`   rg   r   s     r   r   BaseProgressIndicator._writej  r   r   )r   r   r   r   r   r   r   )r   r   r   )r   Fr`   )r(   ra   rb   rc   rd   r   r   r   r   r   r   r   r   r   r   r   r   rf   rg   r   r   r   r      sC    "' ,8;
!		(r   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	StdoutProgressIndicatorin  zStdoutProgressIndicator(name)

A progress indicator that shows the progress in stdout. It
assumes that the tty can appropriately deal with backspace
characters.
c                 B   Su  U l         U l        U R                  (       a$  U R                  < SU R                  < S3U l         OSU R                  -  U l         [        R
                  R                  U R                   5        [        R
                  R                  5         g )N)r   r   z (z): z%s: )_chars_prefix_charsr   r   sysstdoutr   flushrS   s    r   r   StdoutProgressIndicator._startv  sf    *0'DK<<04

DLL!ID!'$**!4D

++,

r   c                 .   U(       d'  Su  p#pEX#X4XEXR0nUR                  U R                  U5      nS[        U R                  5      -  nXl        [        R                  R                  XpR                  -   5        [        R                  R                  5         g )Nz-\|/)getr   lenr   r   r   r   )rM   r   i1i2i3i4MdelCharss           r   r   (StdoutProgressIndicator._update_progress  sq    $NBB0A55b1L#dkk**"

KK/0

r   c                     S=U l         U l        [        R                  R	                  S5        [        R                  R                  5         g )Nr   
)r   r   r   r   r   r   rS   s    r   r   StdoutProgressIndicator._stop  s3    +--d(



r   c                 F   S[        U R                  U R                  -   5      -  n[        R                  R                  US-   U-   S-   5        [        R                  R                  U R                  U R                  -   5        [        R                  R                  5         g )Nr   z  r   )r   r   r   r   r   r   r   )rM   r   r   s      r   r   StdoutProgressIndicator._write  sq    #d004;;>??

D72T9:

++dkk9:

r   )r   r   N)
r(   ra   rb   rc   rd   r   r   r   r   rf   rg   r   r   r   r   n  s    

r   r   c                 .   [         R                  " SS5      nUcE  [         R                  R                  S5      n[         R                  R	                  U5      (       d  SnSn[
        R                  R                  S5      (       aI  [         R                  " S5      [         R                  " S5      pTU(       a  U=(       d    UO
U=(       d    UnOE[
        R                  R                  S5      (       a!  [         R                  R                  US	S
5      nU(       a$  [         R                  R	                  U5      (       d  Un[
        R                  n[        [
        SS5      (       aJ  [         R                  R                  [         R                  R                  [
        R                  5      5      nS H  n[         R                  R                  [         R                  R                  Xg5      5      n[         R                  R	                  U5      (       d  Me   [        [         R                  R                  US5      S5      R                  5         [         R                   " [         R                  R                  US5      5        Un  O   U (       aq  X2:X  a  SU R%                  S5      -   n [         R                  R                  X05      n[         R                  R	                  U5      (       d  [         R&                  " USS9  U$ ! ["         a     GM`  f = f)av  appdata_dir(appname=None, roaming=False)

Get the path to the application directory, where applications are allowed
to write user specific files (e.g. configurations). For non-user specific
data, consider using common_appdata_dir().
If appname is given, a subdir is appended (and created if necessary).
If roaming is True, will prefer a roaming directory (Windows Vista/7).
IMAGEIO_USERDIRN~z/var/tmpwinLOCALAPPDATAAPPDATAdarwinLibraryzApplication Supportfrozen)settingsz../settingsz
test.writewb.T)exist_ok)osgetenvpath
expanduserisdirr   platformr)   joinprefixr@   abspathdirname
executableopencloseremoveIOErrorlstripmakedirs)	appnameroaminguserDirr   path1path2r   reldir	localpaths	            r   appdata_dirr	    s    ii)40G''$$S)ww}}W%% G D
||u%%yy0"))I2Fu#*%		 	 	*	*ww||GY0EFRWW]]4(( ZZFsHd##!@A-GGOOBGGLL$@A	77==##RWW\\)\:DAGGI		"'',,y,?@ ! . ?GNN3//Gww||D*ww}}T""KKt, K  s   A,L
LLc                  ,   [        5       /n  U R                  [        S5      5        [	        [
        SS5      (       a[  U R                  [        R                  R                  [        R                  R                  [
        R                  5      5      5        U $ [
        R                  (       aW  [
        R                  S   (       a?  U R                  [        R                  R                  [
        R                  S   5      5        U $ ! [         a     Nf = f)aj  resource_dirs()

Get a list of directories where imageio resources may be located.
The first directory in this list is the "resources" directory in
the package itself. The second directory is the appdata directory
(~/.imageio on Linux). The list further contains the application
directory (for frozen apps), and may include additional directories
in the future.
r   r   Nr   )resource_package_dirappendr	  	Exceptionr@   r   r   r   r   r   r   )dirss    r   resource_dirsr    s     !"#DK	*+ sHd##BGGOOBGGOOCNN$CDE K 
chhqkBGGOOCHHQK01K  s   D 
DDc                  X    SSK n [        U R                  R                  S5      S-  5      $ )zpackage_dir

Get the resources directory in the imageio package installation
directory.

Notes
-----
This is a convenience method that is used by `resource_dirs` and
imageio entry point scripts.
r   Nr   	resources)importlib.resourcesr&   r  files)	importlibs    r   r  r    s(     y""((3kABBr   c                  t   [         R                  R                  S5      (       a  Sn Ov[         R                  R                  S5      (       a  Sn OO[         R                  R                  S5      (       a  Sn O([         R                  R                  S5      (       a  Sn Og	U [        R                  " S
5      S-  -  $ )zget_platform()

Get a string that specifies the platform more specific than
sys.platform does. The result can be: linux32, linux64, win32,
win64, osx32, osx64. Other platforms may be added in the future.
linuxzlinux%ir   zwin%ir   zosx%ifreebsdz	freebsd%iNPr   )r   r   r)   structcalcsize)plats    r   get_platformr    s     ||w''		 	 	'	'		 	 	*	*		 	 	+	+6??3'!+,,r   c           	          SSK nU R                  S5      n[        [        U5      5       H6  nUR                  R                  SR                  USUS-    5      5      b  M6    g   g)z-Check to see if a python module is available.r   Nr   r   FT)r  splitranger   util	find_specr   )module_namer  
name_partsis       r   
has_moduler%    sY    ""3'J3z?#>>##CHHZ!a%-@$ABJ $ r   )r   r`   )NF)$rd   collectionsr   numpyr!   r   r|   r  r   r   logging	getLoggerr   builtin_module_namesri   r   r   r   __file__THIS_DIRr   r   r9   r"   r;   Imagerk   rJ   rq   r   r   r	  r  r  r  r%  rg   r   r   <module>r.     s   
 $  	 	  
   
		9	%
00
077??277??845	$0?D:BJJ :z 	
)/; )/XCF CL)3 )Z6r2C -,r   