Ë
    T^(h$  ã                   óÀ   — d Z ddlmZmZ ddlZddlmZmZ ddl	m
Z
mZmZ ddlmZmZmZmZmZmZmZmZ ddlmZmZmZ  ej4                  e«      Z G d	„ d
e«      Zd
gZy)z"Image processor class for Swin2SR.é    )ÚOptionalÚUnionNé   )ÚBaseImageProcessorÚBatchFeature)Úget_image_sizeÚpadÚto_channel_dimension_format)ÚChannelDimensionÚ
ImageInputÚinfer_channel_dimension_formatÚis_scaled_imageÚmake_list_of_imagesÚto_numpy_arrayÚvalid_imagesÚvalidate_preprocess_arguments)Ú
TensorTypeÚfilter_out_non_signature_kwargsÚloggingc                   óF  ‡ — e Zd ZdZdgZ	 	 	 	 ddedeeef   dededdf
ˆ fd	„Z		 	 dd
e
j                  dedeeeef      deeeef      fd„Z e«       dddddej"                  dfdedee   dee   dee   dee   deeeef      deeef   deeeef      fd„«       Zˆ xZS )ÚSwin2SRImageProcessora  
    Constructs a Swin2SR image processor.

    Args:
        do_rescale (`bool`, *optional*, defaults to `True`):
            Whether to rescale the image by the specified scale `rescale_factor`. Can be overridden by the `do_rescale`
            parameter in the `preprocess` method.
        rescale_factor (`int` or `float`, *optional*, defaults to `1/255`):
            Scale factor to use if rescaling the image. Can be overridden by the `rescale_factor` parameter in the
            `preprocess` method.
    Úpixel_valuesÚ
do_rescaleÚrescale_factorÚdo_padÚpad_sizeÚreturnNc                 ó\   •— t        ‰| �  di |¤Ž || _        || _        || _        || _        y )N© )ÚsuperÚ__init__r   r   r   r   )Úselfr   r   r   r   ÚkwargsÚ	__class__s         €úr/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/swin2sr/image_processing_swin2sr.pyr!   zSwin2SRImageProcessor.__init__6   s2   ø€ ô 	‰ÑÑ"˜6Ò"à$ˆŒØ,ˆÔØˆŒØ ˆ�ó    ÚimageÚsizeÚdata_formatÚinput_data_formatc                 ó„   — t        ||«      \  }}||z  dz   |z  |z
  }||z  dz   |z  |z
  }t        |d|fd|ffd||¬«      S )aÖ  
        Pad an image to make the height and width divisible by `size`.

        Args:
            image (`np.ndarray`):
                Image to pad.
            size (`int`):
                The size to make the height and width divisible by.
            data_format (`str` or `ChannelDimension`, *optional*):
                The channel dimension format for the output image. If unset, the channel dimension format of the input
                image is used. Can be one of:
                - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
            input_data_format (`str` or `ChannelDimension`, *optional*):
                The channel dimension format for the input image. If unset, the channel dimension format is inferred
                from the input image. Can be one of:
                - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.

        Returns:
            `np.ndarray`: The padded image.
        é   r   Ú	symmetric)Úmoder)   r*   )r   r	   )	r"   r'   r(   r)   r*   Ú
old_heightÚ	old_widthÚ
pad_heightÚ	pad_widths	            r%   r	   zSwin2SRImageProcessor.padE   sq   € ô: !/¨uÐ6GÓ HÑˆ
�IØ  DÑ(¨1Ñ,°Ñ4°zÑAˆ
Ø $Ñ&¨Ñ*¨dÑ2°YÑ>ˆ	äØØ�ˆ_˜q )˜nÐ-ØØ#Ø/ô
ð 	
r&   ÚimagesÚreturn_tensorsc	                 óˆ  — |�|n| j                   }|�|n| j                  }|�|n| j                  }|�|n| j                  }t	        |«      }t        |«      st        d«      ‚t        ||||¬«       |D �	cg c]  }	t        |	«      ‘Œ }}	|r#t        |d   «      rt        j                  d«       |€t        |d   «      }|r!|D �	cg c]  }	| j                  |	||¬«      ‘Œ }}	|r!|D �	cg c]  }	| j                  |	||¬«      ‘Œ }}	|D �	cg c]  }	t        |	||¬«      ‘Œ }}	d|i}
t!        |
|¬	«      S c c}	w c c}	w c c}	w c c}	w )
a 
  
        Preprocess an image or batch of images.

        Args:
            images (`ImageInput`):
                Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
                passing in images with pixel values between 0 and 1, set `do_rescale=False`.
            do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
                Whether to rescale the image values between [0 - 1].
            rescale_factor (`float`, *optional*, defaults to `self.rescale_factor`):
                Rescale factor to rescale the image by if `do_rescale` is set to `True`.
            do_pad (`bool`, *optional*, defaults to `True`):
                Whether to pad the image to make the height and width divisible by `window_size`.
            pad_size (`int`, *optional*, defaults to 32):
                The size of the sliding window for the local attention.
            return_tensors (`str` or `TensorType`, *optional*):
                The type of tensors to return. Can be one of:
                - Unset: Return a list of `np.ndarray`.
                - `TensorType.TENSORFLOW` or `'tf'`: Return a batch of typ, input_data_format=input_data_formate
                  `tf.Tensor`.
                - `TensorType.PYTORCH` or `'pt'`: Return a batch of type `torch.Tensor`.
                - `TensorType.NUMPY` or `'np'`: Return a batch of type `np.ndarray`.
                - `TensorType.JAX` or `'jax'`: Return a batch of type `jax.numpy.ndarray`.
            data_format (`ChannelDimension` or `str`, *optional*, defaults to `ChannelDimension.FIRST`):
                The channel dimension format for the output image. Can be one of:
                - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
                - Unset: Use the channel dimension format of the input image.
            input_data_format (`ChannelDimension` or `str`, *optional*):
                The channel dimension format for the input image. If unset, the channel dimension format is inferred
                from the input image. Can be one of:
                - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
                - `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
        zkInvalid image type. Must be of type PIL.Image.Image, numpy.ndarray, torch.Tensor, tf.Tensor or jax.ndarray.)r   r   r   Úsize_divisibilityr   z­It looks like you are trying to rescale already rescaled images. If the input images have pixel values between 0 and 1, set `do_rescale=False` to avoid rescaling them again.)r'   Úscaler*   )r(   r*   )Úinput_channel_dimr   )ÚdataÚtensor_type)r   r   r   r   r   r   Ú
ValueErrorr   r   r   ÚloggerÚwarning_oncer   Úrescaler	   r
   r   )r"   r3   r   r   r   r   r4   r)   r*   r'   r9   s              r%   Ú
preprocessz Swin2SRImageProcessor.preprocessn   s†  € ð^ $.Ð#9‘Z¸t¿¹ˆ
Ø+9Ð+E™È4×K^ÑK^ˆØ!Ð-‘°4·;±;ˆØ'Ð3‘8¸¿¹ˆä$ VÓ,ˆä˜FÔ#Üð:óð ô 	&Ø!Ø)ØØ&õ		
ð 6<Ö<¨E”. Õ'Ð<ˆÐ<áœ/¨&°©)Ô4Ü×Ñðsôð
 Ð$ä >¸vÀa¹yÓ IÐáð $öàð —‘ 5°ÐRc�ÕdðˆFð ñ
 ØgmÖnÐ^c�d—h‘h˜u¨8ÐGX�hÕYÐnˆFÐnð ouö
ØejÔ'¨¨{ÐN_Ö`ð
ˆð 
ð  Ð'ˆÜ °>ÔBÐBùò5 =ùòùò oùò
s   Á5D0ÃD5Ã'D:ÄD?)Tgp?Té   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úmodel_input_namesÚboolr   ÚintÚfloatr!   ÚnpÚndarrayr   Ústrr   r	   r   ÚFIRSTr   r   r?   Ú__classcell__)r$   s   @r%   r   r   '   s‡  ø„ ñ
ð (Ð(Ðð  Ø,3ØØñ!àð!ð ˜c 5˜jÑ)ð!ð ð	!ð
 ð!ð 
õ!ð& ?CØDHñ'
à�z‰zð'
ð ð'
ð ˜e CÐ)9Ð$9Ñ:Ñ;ð	'
ð
 $ E¨#Ð/?Ð*?Ñ$@ÑAó'
ñR %Ó&ð &*Ø*.Ø!%Ø"&Ø;?Ø4D×4JÑ4JØDHñ\Càð\Cð ˜T‘Nð\Cð ! ™ð	\Cð
 ˜‘ð\Cð ˜3‘-ð\Cð !  s¨J Ñ!7Ñ8ð\Cð ˜3Ð 0Ð0Ñ1ð\Cð $ E¨#Ð/?Ð*?Ñ$@ÑAò\Có 'ô\Cr&   r   )rD   Útypingr   r   ÚnumpyrI   Úimage_processing_utilsr   r   Úimage_transformsr   r	   r
   Úimage_utilsr   r   r   r   r   r   r   r   Úutilsr   r   r   Ú
get_loggerrA   r<   r   Ú__all__r   r&   r%   ú<module>rV      sa   ðñ )ç "ã ç Fß PÑ P÷	÷ 	ó 	÷ JÑ Ið 
ˆ×	Ñ	˜HÓ	%€ôdCÐ.ô dCðN #Ð
#�r&   