o
    h4                     @  s  d Z ddlmZ g dZddlmZmZ ddlZer*ddlmZm	Z	 ddl
mZmZ zddlZ	dJdddKddZdddLddZW n ey]   	dJdddKddZdddLddZY nw zddlZ	dJdddKddZdddLddZW n ey   	dJdddKddZdddLddZY nw zddlmZ 	dJdddKddZdddLd d!ZW n ey   	dJdddKd"dZdddLd#d!ZY nw dddMd%d&Ze	'	(dNdddOd-d.Ze	(dNdddPd0d.Z	'	(dNdddQd2d.ZedOd3d4ZedPd5d4Z	'	(dNdddQd6d4Zedg d7dRd:d;Zedg d7dSd<d;Zdg d7dTd=d;Z	dUdddVdBdCZ	'dWdddXdDdEZdYdHdIZdS )Za   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)	DTypeLikeNDArrayoutlevel
int | Nonedatabytes | NDArray[Any]r   r   returnbytesc               C  s   t | tjr
|  } t| S )zCompress LZMA.)
isinstancenumpyndarraytobyteslzmacompressr   r   r    r%   P/var/www/html/scripts/venv/lib/python3.10/site-packages/tifffile/_imagecodecs.pyr   H   s   
r   c               C  
   t | S )zDecompress LZMA.)r"   
decompressr   r   r%   r%   r&   r   T      
r   c               C     ddl }dS Raise ImportError.r   N    r"   )r   r   r   r"   r%   r%   r&   r   Z      c               C     ddl }dS r,   r/   )r   r   r"   r%   r%   r&   r   f      c               C  s.   t | tjr
|  } t| |du rdS |S )zCompress Zlib DEFLATE.N   )r   r   r    r!   zlibr#   r$   r%   r%   r&   r   p   s   r   c               C  r'   )zDecompress Zlib DEFLATE.)r4   r(   r)   r%   r%   r&   r   |   r*   r   c               C  r+   r,   r4   )r   r   r   r4   r%   r%   r&   r      r0   c               C  r1   r,   r5   )r   r   r4   r%   r%   r&   r      r2   zstdc               C  s"   t | tjr
|  } tj| |dS )zCompress ZSTD.)r   )r   r   r    r!   r7   r#   r$   r%   r%   r&   r      s   r   c               C  r'   )zDecompress ZSTD.)r7   r(   r)   r%   r%   r&   r      r*   r   c               C  s   ddl m} dS r-   r   r6   r.   compressionr7   )r   r   r   r7   r%   r%   r&   r      s   c               C  s   ddl m} dS r8   r9   )r   r   r7   r%   r%   r&   r      s   encodedc               C  s   g }|j }d}z;	 t| ||d  d }|d7 }|dkr0|| ||d  d|   |d7 }n|dk rB|| |||   ||7 }q	 tyN   Y t|S w )aQ  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   T      i  )extendord	TypeErrorr   )r;   r   
out_extendinr%   r%   r&   r	      s$   
r	   r<   axisintdistbytes | bytearrayc               C     d S Nr%   r   rE   rG   r   r%   r%   r&   r      s   r   NDArray[Any]c               C  rI   rJ   r%   rK   r%   r%   r&   r          bytes | bytearray | NDArray[Any]c               C  s   |dkrt d|dt| ttfr-tj| tjd} tj| dd}t|d| d 	 S | j
}|jdkrA| |j d|j } tj| |d}td	g| j }d||< tj|d| t| |d}| j
jsr|d
}||j
 }|jdkr|||S |S )zEncode Delta.r<   zdelta_encode with dist=# requires the 'imagecodecs' packagedtyper   )rE   fuNT)NotImplementedErrorr   r   	bytearrayr   
frombufferuint8diffinsertr!   rQ   kindview	byteorderitemsizeslicendimtupleisnativebyteswapnewbyteorder)r   rE   rG   r   rX   rQ   keyr%   r%   r&   r      s*   	




c               C  rI   rJ   r%   rK   r%   r%   r&   r     rM   r   c               C  rI   rJ   r%   rK   r%   r%   r&   r     rM   c               C  s   |dkrt d|d|dur|jjsd}t| ttfr1tj| tjd} tj	| dtj|d
 S | jjdkra| jjsDt d	| jd| | jj d
| jj }tj	|||jd}|| jS tj	| || j|dS )zDecode Delta.r<   zdelta_decode with dist=rO   NrP   r   )rE   rQ   r   rR   zdelta_decode with rS   )rE   rQ   )rT   flags	writeabler   r   rU   r   rV   rW   cumsumr!   rQ   rZ   ra   r[   r\   r]   )r   rE   rG   r   r[   r%   r%   r&   r     s0   	


)r   	_bitorderrh   	list[Any]c               C  rI   rJ   r%   r   r   rh   r%   r%   r&   r   ?  rM   r   c               C  rI   rJ   r%   rj   r%   r%   r&   r   E  rM   c            
   C  s   |s| d | tj|d tjd t| ttfr"| |d S z| d}tj	|d ||d | W S  t
yE } ztd|d}~ww )	aO  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   rP   rW   r<   r   z<bitorder_decode of slices requires the 'imagecodecs' packageN)appendr   rV   rW   r   r   rU   	translater[   take
ValueErrorrT   )r   r   rh   r[   excr%   r%   r&   r   K  s&   
rQ   r   bitspersamplerunlenc               C  s   |dkr1t | d}t |}|d r,|d|d|d   }|ddd|f d}||S |dv r;t | |S td| d)	aA  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)

    r<   z|B   rD   N)rr          @   zpackints_decode of z0-bit integers requires the 'imagecodecs' package)r   rV   
unpackbitsreshapeastyperT   )r   rQ   rp   rq   r   
data_arrayr%   r%   r&   r
     s   


r
   c               C     t d)zTightly pack integers.z2packints_encode requires the 'imagecodecs' packagerT   )r   rp   rE   r   r%   r%   r&   r     s   	r   r\   Literal['>', '<']c                C  rz   )z"Return float32 array from float24.z1float24_decode requires the 'imagecodecs' packager{   )r   r\   r%   r%   r&   r     s   r   rJ   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )r;   r   r   r   r   r   )rD   r<   )
rE   rF   rG   rF   r   rH   r   r   r   r   )
rE   rF   rG   rF   r   rL   r   r   r   rL   )
rE   rF   rG   rF   r   rN   r   r   r   r   )r   rH   r   r   rh   ri   r   r   )r   rL   r   r   rh   ri   r   rL   )r   rN   r   r   rh   ri   r   r   )r   )rQ   r   rp   rF   rq   rF   r   r   r   r   r   rL   )rD   )
rp   rF   rE   rF   r   rL   r   r   r   r   )r\   r|   r   r   r   rL   )__doc__
__future__r   __all__typingr   r   r   r   r   numpy.typingr   r   r"   r   r   ImportErrorr4   r   r   r:   r7   r   r   r	   r   r   r   r
   r   r   r%   r%   r%   r&   <module>   s   
!
!"	>0