ó
    oM‡jŽ   ã                   óV   • S SK rS SKrS SKrSSKJr  SSKJr  SSK	J
r
   " S S\5      rg)é    Né   )Úregister_to_config)ÚVaeImageProcessor)ÚPIL_INTERPOLATIONc                   ó¤  ^ • \ rS rSrSr\           SS\S\S\S\\\4   S\	S	\S
\S\S\S\S\	\
-  \\
S4   -  S-  4U 4S jjj5       rS\R                  R                  S\S\S\R                  R                  4S jr  SS\R                  R                  \R                   -  \R$                  -  S\S-  S\S-  S\\\4   4S jjrSrU =r$ )ÚWanAnimateImageProcessoré   a  
Image processor to preprocess the reference (character) image for the Wan Animate model.

Args:
    do_resize (`bool`, *optional*, defaults to `True`):
        Whether to downscale the image's (height, width) dimensions to multiples of `vae_scale_factor`. Can accept
        `height` and `width` arguments from [`image_processor.VaeImageProcessor.preprocess`] method.
    vae_scale_factor (`int`, *optional*, defaults to `8`):
        VAE (spatial) scale factor. If `do_resize` is `True`, the image is automatically resized to multiples of
        this factor.
    vae_latent_channels (`int`, *optional*, defaults to `16`):
        VAE latent channels.
    spatial_patch_size (`tuple[int, int]`, *optional*, defaults to `(2, 2)`):
        The spatial patch size used by the diffusion transformer. For Wan models, this is typically (2, 2).
    resample (`str`, *optional*, defaults to `lanczos`):
        Resampling filter to use when resizing the image.
    do_normalize (`bool`, *optional*, defaults to `True`):
        Whether to normalize the image to [-1,1].
    do_binarize (`bool`, *optional*, defaults to `False`):
        Whether to binarize the image to 0/1.
    do_convert_rgb (`bool`, *optional*, defaults to be `False`):
        Whether to convert the images to RGB format.
    do_convert_grayscale (`bool`, *optional*, defaults to be `False`):
        Whether to convert the images to grayscale format.
    fill_color (`str` or `float` or `tuple[float, ...]`, *optional*, defaults to `None`):
        An optional fill color when `resize_mode` is set to `"fill"`. This will fill the empty space with that
        color instead of filling with data from the image. Any valid `color` argument to `PIL.Image.new` is valid;
        if `None`, will default to filling with data from `image`.
NÚ	do_resizeÚvae_scale_factorÚvae_latent_channelsÚspatial_patch_sizeÚresampleÚreducing_gapÚdo_normalizeÚdo_binarizeÚdo_convert_rgbÚdo_convert_grayscaleÚ
fill_color.c                 óX   >• [         TU ]  5         U	(       a  U
(       a  [        SS5      eg g )Nz«`do_convert_rgb` and `do_convert_grayscale` can not both be set to `True`, if you intended to convert the image into RGB format, please set `do_convert_grayscale = False`.z` if you intended to convert the image into grayscale format, please set `do_convert_rgb = False`)ÚsuperÚ__init__Ú
ValueError)Úselfr
   r   r   r   r   r   r   r   r   r   r   Ú	__class__s               €ÚµC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\diffusers/pipelines/wan/image_processor.pyr   Ú!WanAnimateImageProcessor.__init__8   s3   ø€ ô 	‰ÑÔÞÖ2Üðtàróð ð 3ˆ>ó    ÚimageÚwidthÚheightÚreturnc           	      óø  • X#-  nUR                   UR                  -  nU R                  R                  SL nU R                  R                  =(       d    SnXE:  a  UOUR                   U-  UR                  -  nXE:¼  a  UOUR                  U-  UR                   -  n	UR	                  X‰4[
        U R                  R                     S9n
[        R                  R                  SX#4US9nUR                  X¢S-  US-  -
  US-  U	S-  -
  4S9  U(       aé  XE:  ap  US-  U	S-  -
  nUS:”  a]  UR                  U
R	                  X,4SSUS4S9SS9  UR                  U
R	                  X,4SU
R                  X*R                  4S9SXÉ-   4S9  U$ XE:”  ao  US-  US-  -
  nUS:”  a^  UR                  U
R	                  XÓ4SSSU4S9SS9  UR                  U
R	                  XÓ4U
R                   SU
R                   U4S9XØ-   S4S9  U$ )	aÂ  
Resize the image to fit within the specified width and height, maintaining the aspect ratio, and then center
the image within the dimensions, filling empty with data from image.

Args:
    image (`PIL.Image.Image`):
        The image to resize and fill.
    width (`int`):
        The width to resize the image to.
    height (`int`):
        The height to resize the image to.

Returns:
    `PIL.Image.Image`:
        The resized and filled image.
Nr   )r   ÚRGB)Úcoloré   )Úbox)r   r   )r   r    Úconfigr   Úresizer   r   ÚPILÚImageÚnewÚpaste)r   r   r   r    ÚratioÚ	src_ratioÚfill_with_image_datar   Úsrc_wÚsrc_hÚresizedÚresÚfill_heightÚ
fill_widths                 r   Ú_resize_and_fillÚ)WanAnimateImageProcessor._resize_and_fillO   s  € ð. ‘ˆØ—K‘K %§,¡,Ñ.ˆ	Ø#Ÿ{™{×5Ñ5¸Ð=ÐØ—[‘[×+Ñ+×0¨qˆ
àÓ*‘°·±¸fÑ0DÈÏÉÑ0TˆØÓ,‘°%·,±,ÀÑ2FÈ%Ï+É+Ñ2Uˆà—,‘, ˜~Ô8IÈ$Ï+É+×J^ÑJ^Ñ8_�,Ð`ˆÜ�i‰i�m‰m˜E E ?¸*ˆmÐEˆØ�	‰	�'¨¡
¨U°a©ZÑ 7¸À1¹ÀuÐPQÁzÑ9QÐRˆ	ÑSæØÓ Ø$¨™k¨E°Q©JÑ6�Ø “?Ø—I‘I˜gŸn™n¨eÐ-AÈÈ1ÈeÐUVÐGW˜nÐXÐ^d�IÑeØ—I‘IØŸ™¨Ð';À!ÀWÇ^Á^ÐUZ×\jÑ\jÐAk˜ÐlØ Ñ 3Ð4ð ñ ð ˆ
ð Ó"Ø" a™Z¨%°1©*Ñ4�
Ø “>Ø—I‘I˜gŸn™n¨jÐ-AÈÈ1ÈaÐQWÐGX˜nÐYÐ_e�IÑfØ—I‘IØŸ™¨
Ð';À'Ç-Á-ÐQRÐT[×TaÑTaÐciÐAj˜ÐkØ'Ñ/°Ð3ð ñ ð
 ˆ
r   c                 óP  • Uct  [        U[        R                  R                  5      (       a  UR                  nO>[        U[        R
                  5      (       a  UR                  S   nOUR                  S   nUct  [        U[        R                  R                  5      (       a  UR                  nO>[        U[        R
                  5      (       a  UR                  S   nOUR                  S   nX2-  nX#-  nU R                  R                  U R                  R                  S   -  nU R                  R                  U R                  R                  S   -  n[        [        R                  " XE-  5      5      U-  U-  n[        [        R                  " XE-  5      5      U-  U-  nX#4$ )aÅ  
Returns the height and width of the image, downscaled to the next integer multiple of `vae_scale_factor`.

Args:
    image (`PIL.Image.Image | np.ndarray | torch.Tensor`):
        The image input, which can be a PIL image, NumPy array, or PyTorch tensor. If it is a NumPy array, it
        should have shape `[batch, height, width]` or `[batch, height, width, channels]`. If it is a PyTorch
        tensor, it should have shape `[batch, channels, height, width]`.
    height (`int | None`, *optional*, defaults to `None`):
        The height of the preprocessed image. If `None`, the height of the `image` input will be used.
    width (`int | None`, *optional*, defaults to `None`):
        The width of the preprocessed image. If `None`, the width of the `image` input will be used.

Returns:
    `tuple[int, int]`:
        A tuple containing the height and width, both resized to the nearest integer multiple of
        `vae_scale_factor * spatial_patch_size`.
r%   é   r   r   )Ú
isinstancer)   r*   r    ÚtorchÚTensorÚshaper   r'   r   r   ÚroundÚnpÚsqrt)r   r   r    r   Úmax_areaÚaspect_ratioÚmod_value_hÚmod_value_ws           r   Úget_default_height_widthÚ1WanAnimateImageProcessor.get_default_height_width†   s@  € ð2 ‰>Ü˜%¤§¡§¡×1Ñ1ØŸ™‘Ü˜E¤5§<¡<×0Ñ0ØŸ™ Q™‘àŸ™ Q™�à‰=Ü˜%¤§¡§¡×1Ñ1ØŸ™‘Ü˜E¤5§<¡<×0Ñ0ØŸ™ A™‘àŸ™ A™�à‘>ˆØ‘~ˆØ—k‘k×2Ñ2°T·[±[×5SÑ5SÐTUÑ5VÑVˆØ—k‘k×2Ñ2°T·[±[×5SÑ5SÐTUÑ5VÑVˆô ”r—w’w˜xÑ6Ó7Ó8¸KÑGÈ+ÑUˆÜ”b—g’g˜hÑ5Ó6Ó7¸;ÑFÈÑTˆàˆ}Ðr   © )Té   é   )r%   r%   ÚlanczosNTFFFr   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚboolÚintÚtupleÚstrÚfloatr   r)   r*   r6   r?   Úndarrayr;   r<   rE   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r      sh  ø† ñð< ð Ø !Ø#%Ø.4Ø!Ø Ø!Ø!Ø$Ø%*Ø=>ñàðð ðð !ð	ð
 " # s (™Oðð ðð ðð ðð ðð ðð #ðð ˜%‘K %¨¨s¨
Ñ"3Ñ3°dÑ:÷ó ðð,5à�y‰y�‰ð5ð ð5ð ð	5ð
 
�‰�‰ô5ðt "Ø ñ	2à�y‰y�‰ §¡Ñ+¨e¯l©lÑ:ð2ð �d‘
ð2ð �T‰zð	2ð
 
ˆs�Cˆx‰÷2ó 2r   r   )Únumpyr?   Ú	PIL.Imager)   r;   Úconfiguration_utilsr   Úimage_processorr   Úutilsr   r   rG   r   r   Ú<module>r]      s(   ðó  Û Û å 5Ý 0Ý &ô_Ð0õ _r   