U
    ?h<                     @   s   d Z ddlmZmZmZmZmZmZmZ ddl	Z	ddl
ZddlmZmZmZmZ ddlmZmZ ddlmZ G dd	 d	eZdS )
z Read/Write images using rawpy.

rawpy is an easy-to-use Python wrapper for the LibRaw library.
It also contains some extra functionality for finding and repairing hot/dead pixels.
    )AnyDictIteratorListOptionalTupleUnionN   )	URI_BYTESInitializationErrorIOModeRequest)ImagePropertiesPluginV3)	ArrayLikec                       s   e Zd ZdZedd fddZddddZd	d
eej	dddZ
eeee f ee dddZeej	 dddZdeeeeef dddZdeedddZ  ZS )RawPyPluginzA class representing the rawpy plugin.

    Methods
    -------

    .. autosummary::
    :toctree: _plugins/rawpy

    RawPyPlugin.read
    N)requestreturnc              
      s   t  | d| _|jjtjkrzt|	 | _W q tj
tjtjfk
r~   |jtkrftddntd|j ddY qX n|jjtjkrtdddS )zInstantiates a new rawpy plugin object

        Parameters
        ----------
        request: Request
            A request object representing the resource to be operated on.
        Nz&RawPy can not read the provided bytes.zRawPy can not read .RawPy does not support writing.)super__init___image_filemodeZio_moder   readrawpyZimreadZget_fileZNotSupportedErrorZLibRawFileUnsupportedErrorZLibRawIOErrorZ	_uri_typer
   r   Zraw_uriwrite)selfr   	__class__ G/var/www/html/venv/lib/python3.8/site-packages/imageio/plugins/rawpy.pyr      s.    	

zRawPyPlugin.__init__)r   c                 C   s   | j r| j   | j  d S )N)r   close_requestfinishr   r    r    r!   r"   <   s    
zRawPyPlugin.closer   )index)r&   r   c                K   s<   z| j jf |}W n tk
r&   Y nX |tkr8|d }|S )znRead Raw Image.

        Returns
        -------
        nd_image: ndarray
            The image data
        )N.)r   postprocess	ExceptionEllipsis)r   r&   kwargsZnd_imager    r    r!   r   B   s    zRawPyPlugin.read)ndimager   c                 C   s
   t  dS )r   N)NotImplementedError)r   r+   r    r    r!   r   W   s    zRawPyPlugin.writec                 c   s(   z|   V  W n tk
r"   Y nX dS )znLoad the image.

        Returns
        -------
        nd_image: ndarray
            The image data
        N)r   r(   r%   r    r    r!   iter[   s    	zRawPyPlugin.iterT)r&   exclude_appliedr   c                 C   s  i }| j j}| j j|d< | j j|d< | j j|d< | j j|d< | j j|d< | j jj|d< |j	|d< | j j
|d< | j j|d	< |j|d
< |j|d< |j|d< |j|d< | j jj|d< |j|d< |j|d< |j|d< | j j|d< |r|dd |dd |dd |dd |dd |dd |dd |dd |d	d |dd |dd |dd |dd |dd |dd |S )a  Read ndimage metadata.

        Parameters
        ----------
        exclude_applied : bool
            If True, exclude metadata fields that are applied to the image while
            reading. For example, if the binary data contains a rotation flag,
            the image is rotated by default and the rotation flag is excluded
            from the metadata to avoid confusion.

        Returns
        -------
        metadata : dict
            A dictionary of format-specific metadata.

        black_level_per_channelcamera_white_level_per_channel
color_desccolor_matrixdaylight_whitebalancedtypeflip
num_colors
tone_curvewidthheight	raw_width
raw_heightZ	raw_shapeiwidthiheightpixel_aspectwhite_levelN)r   sizesr/   r0   r1   r2   r3   	raw_imager4   r5   r6   r7   r8   r9   r:   r;   shaper<   r=   r>   r?   pop)r   r&   r.   metadataZ
image_sizer    r    r!   rD   i   sL    







zRawPyPlugin.metadatac                 C   s2   | j j}|j}|j}||f}| j jj}t||dS )a  Standardized ndimage metadata

        Returns
        -------
        properties : ImageProperties
            A dataclass filled with standardized image metadata.

        Notes
        -----
        This does not decode pixel data and is fast for large images.

        )rB   r4   )r   r@   r8   r9   rA   r4   r   )r   r&   Z	ImageSizer8   r9   rB   r4   r    r    r!   
properties   s    
zRawPyPlugin.properties)NT)N)__name__
__module____qualname____doc__r   r   r"   intnpZndarrayr   r   r   r   r   bytesr   r   r-   boolr   strr   rD   r   rE   __classcell__r    r    r   r!   r      s         
@r   )rI   typingr   r   r   r   r   r   r   r   numpyrK   Zcore.requestr
   r   r   r   Zcore.v3_plugin_apir   r   r   r   r    r    r    r!   <module>   s   $