o
    iP                     @   s   d 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 ddlmZ z
ddlmZmZ W n	 ey9   Y nw zdd	lZd
ZW n eyM   dZY nw ejdejdejdejdiZejejgZejejgZdedefddZdededefddZ d	S )zUse Pillow <https://github.com/python-pillow/Pillow> to decompress encoded
*Pixel Data*.

This module is not intended to be used directly.
    )BytesIO)castuid)_passes_version_check)PhotometricInterpretation)DecodeRunner)ImagefeaturesNTF)pillow>=10.0)numpyr   r   returnc                 C   sB   t ddsdS | tv rttdS | tv rttdotS dS )zeReturn ``True`` if a pixel data decoder for `uid` is available for use,
    ``False`` otherwise.
    PIL)
   r   Fjpgjpg_2000)r   _LIBJPEG_SYNTAXESboolr
   check_codec_OPENJPEG_SYNTAXESHAVE_NPr    r   T/mnt/sdb/aimis/docanh/lib/python3.10/site-packages/pydicom/pixels/decoders/pillow.pyis_available(   s   
r   srcrunnerc           
      C   s  |j }|tjkr|jdkrtdtjt| dd}|tv r6|j	dkr/d|j
vr/|d|j tt| S |d|j}d	|  k rGdkrPn n|d
d n'd|  k rZdkrsn td|j	dkrltd| d|d
d ntdt| }~|j}tj|d|j d}|j}|ddr|d|}|r|jdkr||}|td|jd  8 }|j|  }	rtj||	|d |jtjtj fv r|dtj! tt| S )z;Return the decoded image data in `src` as a :class:`bytes`.   zIPillow does not support 'JPEG Extended' for samples with 12-bit precision)JPEGJPEG2000)formats   adobe_transformYCbCrj2k_precisionr   bits_allocated   zPillow cannot decode z -bit multi-sample data correctlyz?only (0028,0101) 'Bits Stored' values of up to 16 are supportedu)dtypeapply_j2k_sign_correctionFj2k_is_signed   )outphotometric_interpretation)"transfer_syntaxr   JPEGExtended12Bitbits_storedNotImplementedErrorr	   openr   r   samples_per_pixelinfodraftsizer   bytestobytes
get_option
set_option
ValueError	bytearraypixel_dtypenp
frombufferitemsizepixel_representationviewint32r$   right_shiftr,   PIYBR_ICTYBR_RCTRGB)
r   r   tsyntaximage	precisionbufferr'   arr	is_signed	bit_shiftr   r   r   _decode_frame8   sR   

	


rO   )!__doc__ior   typingr   pydicomr   pydicom.pixels.utilsr   pydicom.pixels.commonr   rD   pydicom.pixels.decoders.baser   r   r	   r
   ImportErrorr   r=   r   JPEGBaseline8Bitr.   JPEG2000Losslessr   DECODER_DEPENDENCIESr   r   strr   r   r6   rO   r   r   r   r   <module>   s6   