
    9i5                    Z   S r SSKJr  / SQrSSKJrJr  SSKr\(       a  SSKJrJ	r	  SSK
JrJrJr   SSKr S'SS.       S(S	 jjjrSS.S)S
 jjr SSKr S'SS.       S(S jjjrSS.S)S jjr SSKJr   S'SS.       S(S jjjrSS.S)S jjrSS.S*S jjr\  S+SS.         S,S jjj5       r\ S+SS.         S-S jjj5       r  S+SS.         S.S jjjr\          S,S j5       r\          S-S j5       r  S+SS.         S.S jjjr\S/ S.       S/S jj5       r\S/ S.       S0S  jj5       r\S/ S.       S1S! jj5       rS/ S.       S2S" jjr S3SS.           S4S# jjjrSSS$.         S5S% jjr      S6S& jrg! \ a      S'SS.       S(S jjjrSS.S)S jjr GNf = f! \ a      S'SS.       S(S jjjrSS.S)S jjr GNf = f! \ a      S'SS.       S(S jjjrSS.S)S jjr GNf = f)7a   Fallback imagecodecs codecs.

This module provides alternative, pure Python and NumPy implementations of
some functions of the `imagecodecs`_ package. The functions may raise
`NotImplementedError`.

.. _imagecodecs: https://github.com/cgohlke/imagecodecs

    )annotations)bitorder_decodedelta_decodedelta_encodefloat24_decodelzma_decodelzma_encodepackbits_decodepackints_decodepackints_encodezlib_decodezlib_encodezstd_decodezstd_encode)TYPE_CHECKINGoverloadN)AnyLiteral)	ArrayLike	DTypeLikeNDArrayoutc                  [        U [        R                  5      (       a  U R                  5       n [        R
                  " U 5      $ )zCompress LZMA.)
isinstancenumpyndarraytobyteslzmacompressdatalevelr   s      U/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/tifffile/_imagecodecs.pyr	   r	   H   s/     dEMM**<<>D}}T""    c              .    [         R                  " U 5      $ )zDecompress LZMA.)r   
decompressr"   r   s     r$   r   r   T       t$$r%   c                  SSK ngRaise ImportError.r   Nr%   r   )r"   r#   r   r   s       r$   r	   r	   Z   
     	r%   c                  SSK ngr+   r-   )r"   r   r   s      r$   r   r   f       r%   c                  [        U [        R                  5      (       a  U R                  5       n [        R
                  " Xc  S5      $ U5      $ )zCompress Zlib DEFLATE.   )r   r   r   r   zlibr    r!   s      r$   r   r   p   s;     dEMM**<<>D}}T1AA5AAr%   c              .    [         R                  " U 5      $ )zDecompress Zlib DEFLATE.)r3   r'   r(   s     r$   r   r   |   r)   r%   c                  SSK ngr+   r3   )r"   r#   r   r3   s       r$   r   r      r.   r%   c                  SSK ngr+   r6   )r"   r   r3   s      r$   r   r      r0   r%   zstdc                  [        U [        R                  5      (       a  U R                  5       n [        R
                  " XS9$ )zCompress ZSTD.)r#   )r   r   r   r   r9   r    r!   s      r$   r   r      s/     dEMM**<<>D}}T//r%   c              .    [         R                  " U 5      $ )zDecompress ZSTD.)r9   r'   r(   s     r$   r   r      r)   r%   c                  SSK Jn  gr,   r   r8   r%   compressionr9   )r"   r#   r   r9   s       r$   r   r      s
     	%r%   c                  SSK Jn  gr=   r>   )r"   r   r9   s      r$   r   r      s    $r%   c                  / nUR                   nSn  [        XUS-    5      S-   nUS-  nUS:  a  U" XUS-    SU-
  -  5        US-  nOUS:  a  U" XX4-    5        X4-  nMO  ! [         a     Of = f[        U5      $ )a-  Decompress PackBits encoded byte string.

>>> packbits_decode(b'\x80\x80')  # NOP
b''
>>> packbits_decode(b'\x02123')
b'123'
>>> packbits_decode(
...     b'\xfe\xaa\x02\x80\x00\x2a\xfd\xaa\x03\x80\x00\x2a\x22\xf7\xaa'
... )[:-5]
b'\xaa\xaa\xaa\x80\x00*\xaa\xaa\xaa\xaa\x80\x00*"\xaa\xaa\xaa\xaa\xaa'

r         i  )extendord	TypeErrorbytes)encodedr   
out_extendins        r$   r
   r
      s     CJ	AGA&'!+AFA3w7q1u-q9:QS7qu-.   :s   AA" "
A/.A/c                  g N r"   axisdistr   s       r$   r   r      s     r%   c                  g rN   rO   rP   s       r$   r   r           r%   c              J   US:w  a  [        SU< S35      e[        U [        [        45      (       aa  [        R
                  " U [        R                  S9n [        R                  " U SS9n[        R                  " USU S   5      R                  5       $ U R                  nUR                  S:X  a*  U R                  UR                   SUR                   35      n [        R                  " XS9n[        S	5      /U R                   -  nSXa'   [        R                  " USU [#        U5         US9nU R                  R$                  (       d:  UR'                  S
5      nUR                  UR                  R)                  5       5      nUR                  S:X  a  UR                  U5      $ U$ )zEncode Delta.rB   zdelta_encode with dist=# requires the 'imagecodecs' packagedtyper   )rQ   fuNT)NotImplementedErrorr   rG   	bytearrayr   
frombufferuint8diffinsertr   rX   kindview	byteorderitemsizeslicendimtupleisnativebyteswapnewbyteorder)r"   rQ   rR   r   r_   rX   keys          r$   r   r      sS    qy!&'JK
 	
 $	*++EKK8zz$Q'||D!T!W-5577JJEzzSyyEOO,Aenn-=>?::d&D#Dk]TYY6CCI<<aeCj!1=D::}}T"yy0023zzSyyKr%   c                  g rN   rO   rP   s       r$   r   r          r%   c                  g rN   rO   rP   s       r$   r   r     rT   r%   c                 US:w  a  [        SU< S35      eUb  UR                  R                  (       d  Sn[        U [        [
        45      (       aV  [        R                  " U [        R                  S9n [        R                  " U S[        R                  US9R                  5       $ U R                  R                  S:X  a  U R                  R                  (       d  [        S	U R                  < S35      eU R                  U R                  R                   S
U R                  R                    35      n[        R                  " XAUR                  S9nUR                  U R                  5      $ [        R                  " XU R                  US9$ )zDecode Delta.rB   zdelta_decode with dist=rV   NrW   r   )rQ   rX   r   rY   zdelta_decode with rZ   )rQ   rX   )r[   flags	writeabler   rG   r\   r   r]   r^   cumsumr   rX   ra   rh   rb   rc   rd   )r"   rQ   rR   r   rb   s        r$   r   r     s?    qy!&'JK
 	
 syy22$	*++EKK8||q

')	 zz#zz""%$TZZN 35 5  yyDJJ0014::3F3F2GHI||D4::>yy$$<<tzzs r%   )r   	_bitorderc                  g rN   rO   r"   r   rs   s      r$   r   r   ?  rm   r%   c                  g rN   rO   ru   s      r$   r   r   E  s     r%   c                  g rN   rO   ru   s      r$   r   r   K  rT   r%   c                 U(       dF  UR                  S5        UR                  [        R                  " US   [        R                  S95        [	        U [
        [        45      (       a  U R                  US   5      $  U R                  S5      n[        R                  " US   X3S9  U $ ! [         a  n[        S5      UeSnAff = f)	a  Reverse bits in each byte of bytes or numpy array.

Decode data where pixels with lower column values are stored in the
lower-order bits of the bytes (TIFF FillOrder is LSB2MSB).

Parameters:
    data:
        Data to bit-reversed. If bytes type, a new bit-reversed
        bytes is returned. NumPy arrays are bit-reversed in-place.

Examples:
    >>> bitorder_decode(b'\x01\x64')
    b'\x80&'
    >>> data = numpy.array([1, 666], dtype='uint16')
    >>> _ = bitorder_decode(data)
    >>> data
    array([  128, 16473], dtype=uint16)

s    @ `P0pH(hX8xD$dT4tL,l\<|B"bR2r
J*jZ:zF&fV6vN.n^>~A!aQ1q	I)iY9yE%eU5uM-m]=}C#cS3sK+k[;{G'gW7wO/o_?r   rW   r^   rB   r   z<bitorder_decode of slices requires the 'imagecodecs' packageN)appendr   r]   r^   r   rG   r\   	translaterb   take
ValueErrorr[   )r"   r   rs   rb   excs        r$   r   r   Q  s    4 !	
  	)))A,ekkJK$	*++~~il++yy!

9Q<0 !J
	s   >*B) )
C3B??Cc              ^   US:X  a}  [         R                  " U S5      n[         R                  " U5      nUS-  (       a5  UR                  SUSUS-  -
  -   5      nUSS2SU24   R                  S5      nUR	                  U5      $ US;   a  [         R                  " X5      $ [        SU S35      e)	a  Decompress bytes to array of integers.

This implementation only handles itemsizes 1, 8, 16, 32, and 64 bits.
Install the Imagecodecs package for decoding other integer sizes.

Parameters:
    data:
        Data to decompress.
    dtype:
        Numpy boolean or integer type.
    bitspersample:
        Number of bits per integer.
    runlen:
        Number of consecutive integers after which to start at next byte.

Examples:
    >>> packints_decode(b'a', 'B', 1)
    array([0, 1, 1, 0, 0, 0, 0, 1], dtype=uint8)

rB   z|B   rL   N)r          @   zpackints_decode of z0-bit integers requires the 'imagecodecs' package)r   r]   
unpackbitsreshapeastyper[   )r"   rX   bitspersamplerunlenr   
data_arrays         r$   r   r     s    : %%dD1
%%j1
A:#++B!fqj.0IJJ#AwwJ/77;J  ''',,

m_ -- 	- r%   )rQ   r   c                  [        S5      e)zTightly pack integers.z2packints_encode requires the 'imagecodecs' packager[   )r"   r   rQ   r   s       r$   r   r     s     < r%   c                   [        S5      e)z"Return float32 array from float24.z1float24_decode requires the 'imagecodecs' packager   )r"   rc   s     r$   r   r     s     ; r%   rN   )r#   z
int | Noner"   bytes | NDArray[Any]r   r   returnrG   )r"   rG   r   r   r   rG   )rH   rG   r   r   r   rG   )rL   rB   )
rQ   intrR   r   r"   bytes | bytearrayr   r   r   rG   )
rQ   r   rR   r   r"   NDArray[Any]r   r   r   r   )
rQ   r   rR   r   r"    bytes | bytearray | NDArray[Any]r   r   r   r   )r"   rG   r   r   rs   	list[Any]r   rG   )r"   r\   r   r   rs   r   r   r\   )r"   r   r   r   rs   r   r   r   )r"   r   r   r   rs   r   r   r   )r   )rX   r   r   r   r   r   r"   rG   r   r   r   r   )
r"   r   r   r   rQ   r   r   r   r   r   )rc   zLiteral['>', '<']r"   rG   r   r   ) __doc__
__future__r   __all__typingr   r   r   r   r   numpy.typingr   r   r   r   r	   r   ImportErrorr3   r   r   r?   r9   r   r   r
   r   r   r   r   r   r   rO   r%   r$   <module>r      sZ  @ #  + #::%
 !
#
 
# 
#"
#
 
# 

# 37 %2&
 !
B
 
B 
B"
B
 
B 

B 37 %4% 
 !
0
 
0 
0"
0
 
0 

0 37 %2 6: B 
 	   	
 
  
 
78HL!$14
BE 
 	   	
* 
 B 
&)14
>A
 

 
!$,/
9< 
 	   	
* 
 D 
"&r
3<
 

 
&*2
 #7@ 

 
)-b
#&:C 
 6
*6 
	6
 6 &6| ) ) ) 	)
 )
) 
) )b 

  
 0
Y  
 !

 
 
"

 
 

 37  P   !

 
 
"

 
 

 37  R  
 !

 
 
"

 
 

 37  s5    F2  G 5"H 2"GG"H H"H*)H*