o
    ۷i(                     @   sV   d dl Zd dlZd dlmZ ddlmZ ddlmZ ddlm	Z	 G dd deeZ
dS )	    N)Image   )ConfigMixin)
ModelMixin)PIL_INTERPOLATIONc                       s4   e Zd Z fddZddeejj fddZ  ZS )IFWatermarkerc                    s&   t    | dtd d | _d S )Nwatermark_image)>   r	      )super__init__register_buffertorchzeroswatermark_image_as_pil)self	__class__ `/home/ubuntu/vllm_env/lib/python3.10/site-packages/diffusers/pipelines/deepfloyd_if/watermark.pyr      s   

zIFWatermarker.__init__Nimagesc                 C   s(  |d j }|d j}|p|}t|| || }|dk r't|| t|| fn||f\}}d|| }}	|	| d }
t|
d |td|
  |td|
  }}}| jd u rl| jtj	 
 }tj|dd}|| _| jj||ftd	 d d
}|D ]}|j||| || ||f| d d q{|S )Nr      i   g      ?r	      RGBA)modebicubic)reducing_gap)boxmask)heightwidthminintr   r   tor   uint8cpunumpyr   	fromarrayresizer   pastesplit)r   r   sample_sizehwcoefimg_himg_wS1S2Kwm_sizewm_xwm_yr   wm_imgpil_imgr   r   r   apply_watermark   s$   

,0
*zIFWatermarker.apply_watermark)N)	__name__
__module____qualname__r   listPILr   r:   __classcell__r   r   r   r   r   
   s     r   )	PIL.Imager?   r   r   configuration_utilsr   models.modeling_utilsr   utilsr   r   r   r   r   r   <module>   s    