U
    ?hO.                     @  s  d Z ddlmZ ddddddd	d
dddgZddlmZmZmZ ddlZz<ddl	Z	d=ddddddddZ
dddddddZW nD ek
r   d>ddddddddZ
dddddddZY nX z<ddlZd?ddddddddZdddddddZW nF ek
rJ   d@ddddddddZdddddddZY nX ddddddd	ZedAddd"d"d#dd$d%dZedBddd"d"d&d&d$d'dZdCddd"d"d(dd$d)dZed"d"d#d*dd+d,dZed"d"d&d*d&d+d-dZdDddd"d"d(dd$d.dZedg d/d#d0dd1d2dZedg d/d&d0d&d1d3dZdg d/d(d0dd1d4dZdEddd5d"d"dd&d6d7d
ZdFddd"d"d&dd8d9dZd:dd&d;d<dZdS )GzFallback 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)AnyLiteraloverloadNoutz
int | Nonezbytes | numpy.ndarraybytes)leveldatareturnc               C  s   t | tjr|  } t| S )zCompress LZMA.)
isinstancenumpyndarraytobyteslzmacompressr   r   r    r   G/var/www/html/venv/lib/python3.8/site-packages/tifffile/_imagecodecs.pyr   A   s    )r   r   c               C  s
   t | S )zDecompress LZMA.)r   
decompressr   r   r   r   r   r   I   s    c               C  s   ddl }dS zRaise ImportError.r   N    r   )r   r   r   r   r   r   r   r   O   s    c               C  s   ddl }dS r"   r$   )r   r   r   r   r   r   r   W   s    c               C  s,   t | tjr|  } t| |dkr&dn|S )zCompress Zlib DEFLATE.N   )r   r   r   r   zlibr   r   r   r   r   r   a   s    c               C  s
   t | S )zDecompress Zlib DEFLATE.)r&   r    r!   r   r   r   r   i   s    c               C  s   ddl }dS r"   r&   )r   r   r   r&   r   r   r   r   p   s    c               C  s   ddl }dS r"   r'   )r   r   r&   r   r   r   r   x   s    )encodedr   c               C  s   g }|j }d}zxt| ||d  d }|d7 }|dkr^|| ||d  d|   |d7 }q|dk r|| |||   ||7 }qW n tk
r   Y nX t|S )aS  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	TypeErrorr   )r(   r   Z
out_extendinr   r   r   r	      s    
r)   intzbytes | bytearray)axisdistr   r   c               C  s   d S Nr   r   r2   r3   r   r   r   r   r      s    znumpy.ndarrayc               C  s   d S r4   r   r5   r   r   r   r      s    z!bytes | bytearray | numpy.ndarrayc               C  s   |dkrt d|dt| ttfrZtj| tjd} tj| dd}t|d| d 	 S | j
}|jdkr| |j d|j } tj| |d}td	g| j }d||< tj|d| t| |d}| j
js|d
 }|jdkr||S |S )zEncode Delta.r)   zdelta_encode with dist=# requires the 'imagecodecs' packagedtyper   )r2   fuNT)NotImplementedErrorr   r   	bytearrayr   
frombufferuint8diffinsertr   r8   kindview	byteorderitemsizeslicendimtupleisnativebyteswapZnewbyteorder)r   r2   r3   r   r?   r8   keyr   r   r   r      s(    	



r   )r2   r3   r   r   r   c               C  s   d S r4   r   r5   r   r   r   r      s    c               C  s   d S r4   r   r5   r   r   r   r      s    c               C  s   |dkrt d|d|dk	r,|jjs,d}t| ttfrbtj| tjd} tj	| dtj|d
 S | jjdkr| jjst 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=r6   Nr7   r   )r2   r8   r   r9   zdelta_decode with r:   )r2   r8   )r;   flagsZ	writeabler   r   r<   r   r=   r>   Zcumsumr   r8   rA   rH   rB   rC   rD   )r   r2   r3   r   rB   r   r   r   r      s$    	
)r   	_bitorderz	list[Any])r   rL   r   c               C  s   d S r4   r   r   r   rL   r   r   r   r      s    c               C  s   d S r4   r   rM   r   r   r   r     s    c            
   C  s   |s(| d | tj|d tjd t| ttfrD| |d S z$| d}tj	|d ||d | W S  t
k
r } ztd|W 5 d}~X Y nX dS )	aK  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   r7   r>   r)   r   z<bitorder_decode of slices requires the 'imagecodecs' packageN)appendr   r=   r>   r   r   r<   	translaterB   Ztake
ValueErrorr;   )r   r   rL   rB   excr   r   r   r     s$    
znumpy.dtype | str)r8   bitspersamplerunlenr   r   c               C  s   |dkrbt | d}t |}|d rX|d|d|d   }|ddd|f d}||S |dkrvt | |S td| ddS )	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   r0   N)rT          @   zpackints_decode of z0-bit integers requires the 'imagecodecs' package)r   r=   Z
unpackbitsZreshapeZastyper;   )r   r8   rR   rS   r   Z
data_arrayr   r   r   r
   A  s    


)rR   r2   r   r   c               C  s   t ddS )zTightly pack integers.z2packints_encode requires the 'imagecodecs' packageNr;   )r   rR   r2   r   r   r   r   r   m  s    zLiteral[('>', '<')])rC   r   r   c                C  s   t ddS )z"Return float32 array from float24.z1float24_decode requires the 'imagecodecs' packageNrX   )r   rC   r   r   r   r   v  s    )N)N)N)N)r0   r)   )r0   r)   )r0   r)   )r0   r)   )r   )r0   )__doc__
__future__r   __all__typingr   r   r   r   r   r   r   ImportErrorr&   r   r   r	   r   r   r   r
   r   r   r   r   r   r   <module>    s   
    !      	   	    
> - 	