U
    qh4                     @  s<   d dl mZ d dlZd dlZd dlmZ G dd deZdS )    )annotationsN)OpRunc                   @  s   e Zd ZddddddZdS )	ImageDecoderRGBz
np.ndarrayztuple[np.ndarray])encodedreturnc              
   C  s   zdd l }W n, tk
r8 } ztd|W 5 d }~X Y nX |jt| }|dkr|t|d d d d d d df }nP|dkrt|}n<|dkr|	d}t|}tj
|dd	}ntd
|d|fS )Nr   zYPillow must be installed to use the reference implementation of the ImageDecoder operatorZBGRr   Z	GrayscaleL   )Zaxiszpixel_format=z is not supported.)Z	PIL.ImageImportErrorZImageopenioBytesIOtobytesnparrayconvertZexpand_dims
ValueError)selfr   Zpixel_formatZPILeimgdecoded r   G/tmp/pip-unpacked-wheel-xnis5xre/onnx/reference/ops/op_image_decoder.py_run   s&    $

zImageDecoder._runN)r   )__name__
__module____qualname__r   r   r   r   r   r      s   r   )
__future__r   r   Znumpyr   Zonnx.reference.op_runr   r   r   r   r   r   <module>   s   