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

    Methods
    -------

    .. autosummary::
    :toctree: _plugins/rawpy

    RawPyPlugin.read
    requestreturnNc                    t                                          |           d| _        |j        j        t
          j        k    r	 t          j        |	                                          | _        dS # t          j
        t          j        t          j        f$ r: |j        t          k    rt          d          dt          d|j         d          dw xY w|j        j        t
          j        k    rt          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__s     U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/imageio/plugins/rawpy.pyr   zRawPyPlugin.__init__   s    	!!!<6;.. #(<0@0@0B0B#C#C   '0#      
 $	11-@   .@go@@@    \!V\11%&GHHdR 21s   +A2 2A Cc                 x    | j         r| j                                          | j                                         d S N)r   close_requestfinishr(   s    r*   r-   zRawPyPlugin.close<   s<     	%""$$$    r   )indexr2   c                p    	  | j         j        di |}n# t          $ r Y nw xY w|t          u r|d         }|S )znRead Raw Image.

        Returns
        -------
        nd_image: ndarray
            The image data
        )N. )r   postprocess	ExceptionEllipsis)r(   r2   kwargsnd_images       r*   r   zRawPyPlugin.readB   s`    	3t'3==f==HH 	 	 	D	 H	*Hs    
""ndimagec                     t                      )r   )NotImplementedError)r(   r:   s     r*   r'   zRawPyPlugin.writeW   s    !###r1   c              #   Z   K   	 |                                  V  dS # t          $ r Y dS w xY w)znLoad the image.

        Returns
        -------
        nd_image: ndarray
            The image data
        N)r   r6   r0   s    r*   iterzRawPyPlugin.iter[   sG      	))++ 	 	 	DD	s    
**Texclude_appliedc                    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<   |rJ|                    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   sizesrA   rB   rC   rD   rE   	raw_imagerF   rG   rH   rI   rJ   rK   rL   rM   shaperO   rP   rQ   rR   pop)r(   r2   r?   metadata
image_sizes        r*   rW   zRawPyPlugin.metadatai   se   ( %+
.2.>.V*+; 	12 "&!1!<#'#3#@ ,0,<,R() ,6<%?!%!1!<!%!1!<&,'. * 4!+!6 $ 0 : @'.(0#-#: "&"2"> 	.LL2D999LL94@@@LLt,,,LL...LL0$777LL$'''LL&&&LLt,,,LLt,,,LLd+++LLt,,,LLd+++LL4(((LLD)))LL---r1   c                     | j         j        }|j        }|j        }||f}| j         j        j        }t          ||          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.

        )rU   rF   )r   rS   rJ   rK   rT   rF   r   )r(   r2   	ImageSizerJ   rK   rU   rF   s          r*   
propertieszRawPyPlugin.properties   sH     $*	_&"(% *0U%8888r1   )r   N)NTr,   )__name__
__module____qualname____doc__r   r   r-   intnpndarrayr   r	   r   r   r   bytesr'   r   r>   boolr   strr   rW   r   r[   __classcell__)r)   s   @r*   r   r      sa       	 	S SD S S S S S S@    $%   S 2:    *$U9d9o#=> $8E? $ $ $ $hrz*     :>> >>26>	c3h> > > >@9 9 9 9 9 9 9 9 9 9 9r1   r   )r_   typingr   r   r   r   r   r   r	   r   numpyra   core.requestr   r   r   r   core.v3_plugin_apir   r   r   r   r4   r1   r*   <module>rk      s     E D D D D D D D D D D D D D D D D D      J J J J J J J J J J J J : : : : : : : :      o9 o9 o9 o9 o9( o9 o9 o9 o9 o9r1   