
    
3j                         S SK r S SKJs  Jr  S SKJr  SSKJr  \" SS9 " S S\R                  5      5       r
Sr\" S	S9 " S
 S	\R                  5      5       rg)    N)io   )
comfy_nodeLTXVDilateVideoMask)namec                       \ rS rSrSr\S 5       r\  SS\S\S\R                  S-  S\R                  S-  S	\
R                  4
S
 jj5       rSrg)r      z]Dilates a video mask spatially and/or temporally using max-pooling and thresholds the result.c                 f   [         R                  " SSS[         R                  R                  SSSSSS	9[         R                  R                  S
SSSSS	9[         R                  R                  SSSS9[         R
                  R                  SSSS9/[         R                  R                  S5      /S9$ )Nr   zLightricks/mask_operationszgDilates a video mask spatially and/or temporally using separable max-pooling and thresholds the result.spatial_radiusr   r   i,  z>Half-size of the spatial dilation kernel. Kernel = 2*radius+1.)defaultminmaxtooltiptemporal_radius
   z?Half-size of the temporal dilation kernel. Kernel = 2*radius+1.maskTzDVideo mask to dilate. Either this or image_as_mask must be provided.)optionalr   image_as_maskzNImage to use as mask (channel-averaged). Either this or mask must be provided.node_idcategorydescriptioninputsoutputs)r   SchemaIntInputMaskImageOutputclss    J/home/wildlama/comfy/ComfyUI/custom_nodes/ComfyUI-LTXVideo/vanish_nodes.pydefine_schema!LTXVDilateVideoMask.define_schema   s    yy)1C $\   %]   !b  
 #!l  )6 v&C$
 $	
    Nr   r   r   r   returnc                 \   Uc  Uc  [        S5      eUc  UR                  SS9nUR                  S:X  a  US S 2S S 2S S 2S4   nUS-  S-   nUS-  S-   nUS:  a8  UR                  S5      n[        R
                  " X5SUS9nUR                  S5      nUS:  an  UR                  u  pxn	UR                  SSS5      R                  X-  SU5      n[        R                  " X6SUS9nUR                  XU5      R                  SSS5      nUS	:  R                  5       n[        R                  " U5      $ )
Nz2Either 'mask' or 'image_as_mask' must be provided.)dim   r      r   )kernel_sizestridepaddingg      ?)
ValueErrormeanndim	unsqueezeF
max_pool2dsqueezeshapepermutereshape
max_pool1dfloatr   
NodeOutput)
r"   r   r   r   r   s_kernelt_kernelBHWs
             r#   executeLTXVDilateVideoMask.execute4   s6    <M1QRR< %%"%-D99>1a
#D!A%)"Q&* a<>>!$D<<1nD <<?Da<jjGA!<<1a(001=D<<1oD <<a(00Aq9Ds
!!#}}T""r&    )NN)__name__
__module____qualname____firstlineno____doc__classmethodr$   inttorchTensorr   r<   rB   __static_attributes__rD   r&   r#   r   r      sz    g%
 %
N 
 %)-1$#$# $# llT!	$#
 ||d*$# 
$# $#r&   )f      r   LTXVInpaintPreprocessc                       \ rS rSrSr\S 5       r\S\R                  S\R                  S\	R                  4S j5       rSrg	)
rQ   _   zComposites images with a green (#66FF00) background where mask is active.

If the mask has a single frame it is broadcast to match the video length.
c                     [         R                  " SSS[         R                  R                  SSS9[         R                  R                  SSS9/[         R                  R                  S	5      /S
9$ )NrQ   zLightricks/image_processingz\Composites images with a green background where mask is active, for inpainting conditioning.imagesz4Video frames to composite onto the green background.)r   r   zPMask indicating regions to replace with green. Single-frame masks are broadcast.imager   )r   r   r   r   r   r    r!   s    r#   r$   #LTXVInpaintPreprocess.define_schemaf   st    yy+27 R   n  	 (#
 	
r&   rU   r   r'   c                 B   UR                   S:X  a  US S 2S S 2S S 2S4   nUR                  S   S:X  a3  UR                  S   S:  a   UR                  UR                  S   SS5      n[        UR                  S   UR                  S   5      nUS U nUS U nUR	                  S5      n[
        R                  " [        5      R                  5       R                  UR                  5      S-  nUSU-
  -  UR                  SSSS5      U-  -   n[        R                  " U5      $ )Nr+   r   r   r)   rP      )r2   r7   expandr   r3   rL   tensor_BG_COLOR_RGBr;   todeviceviewr   r<   )r"   rU   r   
min_framesmask_4dbg_colorresults          r#   rB   LTXVInpaintPreprocess.execute~   s     99>1a
#D::a=A&,,q/A"5;;v||AB7DAQ8
KZ $..$<<.44699&--H3N1w;'(--1a*Cg*MM}}V$$r&   rD   N)rE   rF   rG   rH   rI   rJ   r$   rL   rM   r   r<   rB   rN   rD   r&   r#   rQ   rQ   _   sW    
 
 
. %% ll% 
	% %r&   )rL   torch.nn.functionalnn
functionalr4   comfy_api.latestr   nodes_registryr   	ComfyNoder   r\   rQ   rD   r&   r#   <module>rk      si        & &'P#",, P# (P#f  ()2%BLL 2% *2%r&   