o
    j;                     @   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 )
zRead/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modeZio_moder   readrawpyZimreadZget_fileZNotSupportedErrorZLibRawFileUnsupportedErrorZLibRawIOErrorZ	_uri_typer
   r   Zraw_uriwrite)selfr   	__class__ V/var/www/html/Deteccion_Ine/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'   kwargsZnd_imager    r    r!   r   B   s   zRawPyPlugin.readndimagec                 C   s   t  )r   )NotImplementedError)r   r,   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   r)   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_heightZ	raw_shapeiwidthiheightpixel_aspectwhite_levelN)r   sizesr0   r1   r2   r3   r4   	raw_imager5   r6   r7   r8   r9   r:   r;   r<   shaper=   r>   r?   r@   pop)r   r'   r/   metadataZ
image_sizer    r    r!   rE   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.

        )rC   r5   )r   rA   r9   r:   rB   r5   r   )r   r'   Z	ImageSizer9   r:   rC   r5   r    r    r!   
properties   s   
zRawPyPlugin.properties)r   N)NTr"   )__name__
__module____qualname____doc__r   r   r#   intnpZndarrayr   r   r   r   r   bytesr   r   r.   boolr   strr   rE   r   rF   __classcell__r    r    r   r!   r      s     
 "

@r   )rJ   typingr   r   r   r   r   r   r   r   numpyrL   Zcore.requestr
   r   r   r   Zcore.v3_plugin_apir   r   r   r   r    r    r    r!   <module>   s    $