a
    áñhn  ã                	   @   s&  d dl Z d dlZd dlmZ d dlZdZ�ze e 	e 
e¡d¡¡ZejjejjfZej ee¡Ze d¡Zejdk�rd dlZd dlZejddd�Zeed	ƒZe d
¡Zejej_ erÂejej!_ edu�re !ej"dd¡Z#e#du �re $e %¡ ¡Z&e& j'dej"› d�7  _'e&‚e e¡ edu�r6e j( )ej"¡ dZW n e*e+f�yP   Y n0 e,e j-dœdd„Z.e,e j-ddœdd„Z/e j-e j-dœdd„Z0d+e j-e1e j-dœdd„Z2d,e j-e,e1dœdd„Z3e j-e j-dœdd„Z4d-e j-e1e j-d!œd"d#„Z5d.e j-e,e1d$œd%d&„Z6e j-e j-dœd'd(„Z7e,e j-dœd)d*„Z8dS )/é    NFz..ÚimageÚntzkernel32.dllT)Úuse_last_errorZAddDllDirectoryé   i   z Error loading "z" or any or its dependencies.)ÚpathÚreturnc                 C   s   t jj | ¡}|S )zÊ
    Reads and outputs the bytes contents of a file as a uint8 Tensor
    with one dimension.

    Arguments:
        path (str): the path to the file to be read

    Returns:
        data (Tensor)
    )ÚtorchÚopsr   Ú	read_file©r   Údata© r   úT/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torchvision/io/image.pyr
   2   s    r
   )Úfilenamer   r   c                 C   s   t jj | |¡ dS )zá
    Writes the contents of a uint8 tensor with one dimension to a
    file.

    Arguments:
        filename (str): the path to the file to be written
        data (Tensor): the contents to be written to the output file
    N)r   r	   r   Ú
write_file)r   r   r   r   r   r   A   s    	r   )Úinputr   c                 C   s   t jj | ¡}|S )a<  
    Decodes a PNG image into a 3 dimensional RGB Tensor.
    The values of the output tensor are uint8 between 0 and 255.

    Arguments:
        input (Tensor[1]): a one dimensional uint8 tensor containing
    the raw bytes of the PNG image.

    Returns:
        output (Tensor[3, image_height, image_width])
    )r   r	   r   Ú
decode_png©r   Úoutputr   r   r   r   M   s    r   é   )r   Úcompression_levelr   c                 C   s   t jj | |¡}|S )a  
    Takes an input tensor in CHW layout and returns a buffer with the contents
    of its corresponding PNG file.

    Parameters
    ----------
    input: Tensor[channels, image_height, image_width]
        int8 image tensor of `c` channels, where `c` must 3 or 1.
    compression_level: int
        Compression factor for the resulting file, it must be a number
        between 0 and 9. Default: 6

    Returns
    -------
    output: Tensor[1]
        A one dimensional int8 tensor that contains the raw bytes of the
        PNG file.
    )r   r	   r   Ú
encode_png)r   r   r   r   r   r   r   ]   s    r   )r   r   r   c                 C   s   t | |ƒ}t||ƒ dS )aÈ  
    Takes an input tensor in CHW layout (or HW in the case of grayscale images)
    and saves it in a PNG file.

    Parameters
    ----------
    input: Tensor[channels, image_height, image_width]
        int8 image tensor of `c` channels, where `c` must be 1 or 3.
    filename: str
        Path to save the image.
    compression_level: int
        Compression factor for the resulting file, it must be a number
        between 0 and 9. Default: 6
    N)r   r   )r   r   r   r   r   r   r   Ú	write_pngt   s    
r   c                 C   s   t jj | ¡}|S )a<  
    Decodes a JPEG image into a 3 dimensional RGB Tensor.
    The values of the output tensor are uint8 between 0 and 255.
    Arguments:
        input (Tensor[1]): a one dimensional uint8 tensor containing
    the raw bytes of the JPEG image.
    Returns:
        output (Tensor[3, image_height, image_width])
    )r   r	   r   Údecode_jpegr   r   r   r   r   ‡   s    
r   éK   )r   Úqualityr   c                 C   s,   |dk s|dkrt dƒ‚tjj | |¡}|S )a  
    Takes an input tensor in CHW layout and returns a buffer with the contents
    of its corresponding JPEG file.

    Parameters
    ----------
    input: Tensor[channels, image_height, image_width])
        int8 image tensor of `c` channels, where `c` must be 1 or 3.
    quality: int
        Quality of the resulting JPEG file, it must be a number between
        1 and 100. Default: 75

    Returns
    -------
    output: Tensor[1]
        A one dimensional int8 tensor that contains the raw bytes of the
        JPEG file.
    r   éd   z;Image quality should be a positive number between 1 and 100)Ú
ValueErrorr   r	   r   Úencode_jpeg)r   r   r   r   r   r   r   •   s    r   )r   r   r   c                 C   s   t | |ƒ}t||ƒ dS )a�  
    Takes an input tensor in CHW layout and saves it in a JPEG file.

    Parameters
    ----------
    input: Tensor[channels, image_height, image_width]
        int8 image tensor of `c` channels, where `c` must be 1 or 3.
    filename: str
        Path to save the image.
    quality: int
        Quality of the resulting JPEG file, it must be a number
        between 1 and 100. Default: 75
    N)r   r   )r   r   r   r   r   r   r   Ú
write_jpeg°   s    
r   c                 C   s   t jj | ¡}|S )a²  
    Detects whether an image is a JPEG or PNG and performs the appropriate
    operation to decode the image into a 3 dimensional RGB Tensor.

    The values of the output tensor are uint8 between 0 and 255.

    Parameters
    ----------
    input: Tensor
        a one dimensional uint8 tensor containing the raw bytes of the
        PNG or JPEG image.

    Returns
    -------
    output: Tensor[3, image_height, image_width]
    )r   r	   r   Údecode_imager   r   r   r   r    Â   s    r    c                 C   s   t | ƒ}t|ƒS )a#  
    Reads a JPEG or PNG image into a 3 dimensional RGB Tensor.
    The values of the output tensor are uint8 between 0 and 255.

    Parameters
    ----------
    path: str
        path of the JPEG or PNG image.

    Returns
    -------
    output: Tensor[3, image_height, image_width]
    )r
   r    r   r   r   r   Ú
read_image×   s    r!   )r   )r   )r   )r   )9r   ÚosÚos.pathr   ZospZimportlib.machineryÚ	importlibZ_HAS_IMAGE_OPTÚabspathÚjoinÚdirnameÚ__file__Úlib_dirÚ	machineryÚExtensionFileLoaderÚEXTENSION_SUFFIXESÚloader_detailsÚ
FileFinderZ	extfinderÚ	find_specZ	ext_specsÚnameÚctypesÚsysÚWinDLLÚkernel32ÚhasattrZwith_load_library_flagsZSetErrorModeZprev_error_modeÚc_void_pZLoadLibraryWÚrestypeZLoadLibraryExWÚoriginÚresZWinErrorZget_last_errorÚerrÚstrerrorr	   Zload_libraryÚImportErrorÚOSErrorÚstrZTensorr
   r   r   Úintr   r   r   r   r   r    r!   r   r   r   r   Ú<module>   sT   þ








