
    
3jf=                         S SK r S SKJr  S SKJr  S SKrSSKJr  S r	\" SS9 " S S5      5       r
\" SS9 " S	 S5      5       r\" S
S9 " S S
5      5       rg)    N   )
comfy_nodec                 b    US:  a(  SU-  n[         R                  R                  XU5      S   n U $ )Nr   g333333?)post_processingBlurexecute)imageblur_radiussigmas      C/home/wildlama/comfy/ComfyUI/custom_nodes/ComfyUI-LTXVideo/guide.pyblur_internalr   	   s7    Q
 k!$$,,UGJL    LTXVAddGuideAdvanced)namec                   >    \ rS rSr\S 5       rSrSrSrSr	Sr
S rS	rg
)r      c                 v    SSSSSSSSSS	S
S.4SSSSSS.4SSSSSSS.4SSSSSSS.4/ SQSS04SS/SS04S.0$ )NrequiredCONDITIONINGVAELATENTIMAGEINTr   '  a3  Frame index to start the conditioning at. For single-frame images or videos with 1-8 frames, any frame_idx value is acceptable. For videos with 9+ frames, frame_idx must be divisible by 8, otherwise it will be rounded down to the nearest multiple of 8. Negative values are counted from the end of the video.defaultminmaxtooltipFLOAT      ?        zRStrength of the conditioning. Higher values will make the conditioning more exact.   3   r   ZCRF value for the video. Higher values mean more motion, lower values mean higher quality.r!   r"   r#   stepr$      ZBlur kernel radius size. Higher values mean more motion, lower values mean higher quality.lanczosbislerpnearestbilinearbicubicareaznearest-exactr!   r0   centerdisabled)positivenegativevaelatentr	   	frame_idxstrengthcrfr
   interpolationcrop ss    r   INPUT_TYPES LTXVAddGuideAdvanced.INPUT_TYPES   s     --%##$$#$l	 #&""#w	 #% ! !#	 #$   !#	  	*" #J/)Z1HIw<>
 >	
r   r   r   r   r8   r9   r;   conditioning/video_modelsgeneratea  Adds a conditioning frame or a video at a specific frame index. This node is used to add a keyframe or a video segment which should appear in the generated video at a specified index. It resizes the image to the correct size and applies preprocessing to it.c           
         UR                   u  pnUS   R                  S   U-  US   R                  S   U-  nn[        R                  R	                  UR                  SS5      UUXS9R                  SS5      R                  SS5      n[        R                  " 5       R                  XX5      S   n[        XY5      n[        R                  " 5       R                  UUUUUUUS9$ )	Nsamples      r   r@   r   )r8   r9   r:   r;   r	   r<   r=   )downscale_index_formulashapecomfyutilscommon_upscalemovedimclampnodes_ltLTXVPreprocessr   r   LTXVAddGuide)selfr8   r9   r:   r;   r	   r<   r=   r>   r
   r?   r@   _width_scale_factorheight_scale_factorwidthheights                    r   rI   LTXVAddGuideAdvanced.generatee   s     695P5P229##A&);;9##A&)<< 
 KK&&b!$eV] '  WQ^U1a[ 	 '')11%=a@e1$$&.. / 
 	
r   rA   N__name__
__module____qualname____firstlineno__classmethodrD   RETURN_TYPESRETURN_NAMESCATEGORYFUNCTIONDESCRIPTIONrI   __static_attributes__rA   r   r   r   r      s:    ?
 ?
B >L5L*HH	' $
r   LTXVImgToVideoAdvancedc                   >    \ rS rSr\S 5       rSrSrSrSr	Sr
S rS	rg
)rm      c                     SSSSSSSS[         R                  SS	.4SS
S[         R                  SS	.4SSS[         R                  SS	.4SSSSS.4SSSSSSS.4SSSSSSS.4/ SQSS04SS/SS04SSSSS.4S.0$ ) Nr   r   r   r   r   i   @       )r!   r"   r#   r,   i   a   	      r   i   )r!   r"   r#   r(   r   r)   r*   r+   r-   r.   r/   r!   r0   r6   r7   r%   g?)r8   r9   r:   r	   r^   r_   length
batch_sizer>   r
   r?   r@   r=   )nodesMAX_RESOLUTIONrB   s    r   rD   "LTXVImgToVideoAdvanced.INPUT_TYPES   s    --##&!$33 "	 #&!$33 "	  "1U5I5ISTU  %!Ad&KL#% ! !#	 #$   !#	  	*" #J/)Z1HI$#a&JK{>@
 @	
r   rF   rG   rH   rI   zAdds a conditioning frame or a video at index 0. This node is used to add a keyframe or a video segment which should appear in the generated video at index 0. It resizes the image to the correct size and applies preprocessing to it.c                 8   [         R                  R                  UR                  SS5      XVXS9R                  SS5      n[        R
                  " 5       R                  XI5      S   n[        XJ5      n[        R                  " 5       R                  UUUUUUUUUS9	$ )NrN   r   rO   r   )	r8   r9   r:   r	   r^   r_   rv   rw   r=   )	rR   rS   rT   rU   rW   rX   r   r   LTXVImgToVideo)rZ   r8   r9   r:   r	   r^   r_   rv   rw   r>   r
   r?   r@   r=   s                 r   rI   LTXVImgToVideoAdvanced.generate   s      **MM"a % + 

'!R. 	 '')11%=a@e1&&(00! 1 

 
	
r   rA   Nra   rA   r   r   rm   rm      s<    A
 A
F >L5L*HH	+ 
r   LTXVAddGuideAdvancedAttentionc                   J    \ rS rSrSr\S 5       rSrSrSr	Sr
Sr  SS
 jrSrg	)r~   i  a$  Extended keyframe guide node with per-guide attention strength control.

Same preprocessing as LTXVAddGuideAdvanced (CRF, blur, interpolation, crop),
plus attention_strength and attention_mask inputs to control how strongly
this guide's conditioning influences generation via self-attention.
c                     SSSSSSSSSS	S
.4SSSSSS
.4SSSSSSS.4SSSSSSS.4/ SQSS04SS/SS04SSSSSSS.4S.SSS S!040S".$ )#Nr   r   r   r   r   r   r   r   z`Frame index to start the conditioning at. Negative values are counted from the end of the video.r    r%   r&   r'   z?Strength of the conditioning. Higher values make it more exact.r(   r)   r   z8CRF value. Higher = more motion, lower = higher quality.r+   r-   z)Blur kernel radius. Higher = more motion.r/   r!   r0   r6   r7   g{Gz?zqControls how strongly this guide influences generation via self-attention. 1.0 = full conditioning, 0.0 = ignore.)r8   r9   r:   r;   r	   r<   r=   r>   r
   r?   r@   attention_strengthattention_maskMASKr$   zOptional pixel-space spatial mask. Shape (F, H, W) or (H, W). Values in [0, 1]. Controls per-region conditioning influence. Multiplied by attention_strength.)r   optionalrA   rB   s    r   rD   )LTXVAddGuideAdvancedAttention.INPUT_TYPES
  s    .-%##$$#U #&""#d	 #% ! !#]	 #$   !#N	  	*" #J/)Z1HI#&"" $U	'yIV !!@	#WW
 W	
r   rF   rG   rH   rI   zAdds a conditioning frame/video at a specific frame index with per-guide attention strength control. Same preprocessing as LTXVAddGuideAdvanced, plus attention_strength and optional spatial attention_mask.Nc           
         SSK JnJn  UR                  nUu  nnnUS   n[        R
                  " U5      nUR                  u    nnnnUU-  nUU-  n[        R                  R                  UR                  SS5      UUXS9R                  SS5      R                  SS5      n[        R                  " 5       R                  XX5      S   n[        XY5      n[        R                  R!                  UUUUU5      u  nn[        R                  R#                  UU[%        U5      UU5      u  nnUUR                  S   -   U::  d   S5       e[        R                  R'                  UUUUUUUU5      u  pnnUR                  S   UR                  S	   -  UR                  S
   -  n[)        UR                  SS  5      nU" U5      nU" UUUUUS9nU" UUUUUS9nUUUUS.4$ )Nr   )append_guide_attention_entrynormalize_maskrK   rN   rO   r      z=Conditioning frames exceed the length of the latent sequence.rM   rL   )r   r   )rK   
noise_mask)iclora_attentionr   r   rP   rW   get_noise_maskrQ   rR   rS   rT   rU   rV   rX   r   r   rY   encodeget_latent_indexlenappend_keyframelist) rZ   r8   r9   r:   r;   r	   r<   r=   r>   r
   r?   r@   r   r   r   r   scale_factorsr[   r\   r]   latent_imager   latent_lengthlatent_heightlatent_widthr^   r_   t
latent_idxpre_filter_countguide_latent_shape	norm_masks                                    r   rI   &LTXVAddGuideAdvancedAttention.generateq  s'     	S 335B22i(,,V4
;G;M;M81m]L11!44KK&&b!$eV] '  WQ^U1a[ 	 '')11%=a@e1 $$++}e]
1
 !) 5 5 F FmSZM!
	: #}4	KJ	K4
 !!11	 	5L* 771:
2QWWQZ?!!''!"+.">2	/1$
 01$
 $J?
 	
r   rA   )r&   N)rb   rc   rd   re   __doc__rf   rD   rg   rh   ri   rj   rk   rI   rl   rA   r   r   r~   r~     sM     X
 X
t >L5L*HH	G & W
r   )rR   comfy_extras.nodes_ltrW   "comfy_extras.nodes_post_processingnodes_post_processingr   rx   nodes_registryr   r   r   rm   r~   rA   r   r   <module>r      s     ( <  & '(t
 t
 )t
n )*q
 q
 +q
h 01F
 F
 2F
r   