o
    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deddf fddZdddZd	d
dedej	fddZ
deeee f dee fddZdeej	 fddZ	ddededeeef fddZddedefddZ  ZS )RawPyPluginzA class representing the rawpy plugin.

    Methods
    -------

    .. autosummary::
    :toctree: _plugins/rawpy

    RawPyPlugin.read
    requestreturnNc              
      s   t  | d| _|jjtjkr=zt|	 | _W dS  tj
tjtjfy<   |jtkr2tddtd|j ddw |jjtjkrIt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modeio_moder   readrawpyimreadget_fileNotSupportedErrorLibRawFileUnsupportedErrorLibRawIOError	_uri_typer
   r   raw_uriwrite)selfr   	__class__ P/var/www/html/scripts/venv/lib/python3.10/site-packages/imageio/plugins/rawpy.pyr      s2   	


zRawPyPlugin.__init__c                 C   s   | j r| j   | j  d S N)r   close_requestfinishr%   r(   r(   r)   r+   <   s   
zRawPyPlugin.closer   )indexr/   c                K   s>   z| j jdi |}W n	 ty   Y nw |tu r|d }|S )znRead Raw Image.

        Returns
        -------
        nd_image: ndarray
            The image data
        )N.Nr(   )r   postprocess	ExceptionEllipsis)r%   r/   kwargsnd_imager(   r(   r)   r   B   s   zRawPyPlugin.readndimagec                 C   s   t  )r   )NotImplementedError)r%   r5   r(   r(   r)   r$   W   s   zRawPyPlugin.writec                 c   s(    z|   V  W dS  ty   Y dS w )znLoad the image.

        Returns
        -------
        nd_image: ndarray
            The image data
        N)r   r1   r.   r(   r(   r)   iter[   s   	zRawPyPlugin.iterTexclude_appliedc                 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_height	raw_shapeiwidthiheightpixel_aspectwhite_levelN)r   sizesr9   r:   r;   r<   r=   	raw_imager>   r?   r@   rA   rB   rC   rD   rE   shaperG   rH   rI   rJ   pop)r%   r/   r8   metadata
image_sizer(   r(   r)   rO   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.

        )rM   r>   )r   rK   rB   rC   rL   r>   r   )r%   r/   	ImageSizerB   rC   rM   r>   r(   r(   r)   
properties   s   
zRawPyPlugin.properties)r   N)NTr*   )__name__
__module____qualname____doc__r   r   r+   intnpndarrayr   r   r   r   r   bytesr$   r   r7   boolr   strr   rO   r   rR   __classcell__r(   r(   r&   r)   r      s     
 "

@r   )rV   typingr   r   r   r   r   r   r   r   numpyrX   core.requestr
   r   r   r   core.v3_plugin_apir   r   r   r   r(   r(   r(   r)   <module>   s    $