o >g$ @sddlZddlZddlZddZGdddZGdddZGdd d ZGd d d Z Gd d d Z GdddZ GdddZ GdddZ GdddZGdddZeeee e e e e eed ZdS)NcCsH|jdd|ddkrtj||d|ddd}tj||dS)Nbilinearcenterr)shapecomfyutilscommon_upscalerepeat_to_batch_size) target_shapelatentrC/home/comdoleger1/zen-flux-style-shape/comfy_extras/nodes_latent.pyreshape_latent_tosrc@,eZdZeddZdZdZdZddZdS) LatentAddcCddddiSNrequiredLATENT)samples1samples2rsrrr INPUT_TYPES zLatentAdd.INPUT_TYPESroplatent/advancedcCs6|}|d}|d}t|j|}|||d<|fSNsamplescopyrrselfrr samples_outs1s2rrrr   z LatentAdd.opN __name__ __module__ __qualname__ classmethodr RETURN_TYPESFUNCTIONCATEGORYrrrrrr   rc@r) LatentSubtractcCrrrrrrrr rzLatentSubtract.INPUT_TYPESrrrcCs6|}|d}|d}t|j|}|||d<|fSr r"r$rrrr)r)zLatentSubtract.opNr*rrrrr3r2r3c@r) LatentMultiplycCsddddddddfd iS) NrrFLOAT?g$$@{Gz?defaultminmaxstep)r! multiplierrrrrrr4szLatentMultiply.INPUT_TYPESrrrcCs"|}|d}|||d<|fSr r#)r%r!r>r&r'rrrr?s zLatentMultiply.opNr*rrrrr43s  r4c@r) LatentInterpolatec CsdddddddddfdiS) Nrrr5r6r8r9)rrratiorrrrrrGszLatentInterpolate.INPUT_TYPESrrrc Cs|}|d}|d}t|j|}tjj|dd}tjj|dd}t||}t||}|||d|} tjj| dd} t| | } | |||d||d<|fS)Nr!rdimr6)r#rrtorchlinalg vector_norm nan_to_num) r%rrrBr&r'r(m1m2tmtstrrrrSs zLatentInterpolate.opNr*rrrrr@Fs  r@c@r) LatentBatchcCrrrrrrrrirzLatentBatch.INPUT_TYPESrbatchz latent/batchc Cs|}|d}|d}|jdd|jddkr*tj||jd|jddd}tj||fdd}||d<|d d d td|jdD|d d d td|jdD|d <|fS) Nr!rrrrrrrC batch_indexcSsg|]}|qSrr).0xrrr {sz%LatentBatch.batch..) r#rrr r rEcatgetrange)r%rrr&r'r(rrrrrOrs HzLatentBatch.batchN) r+r,r-r.rr/r0r1rOrrrrrNhr2rNc@r) LatentBatchSeedBehaviorcCsddddgddifdiS)Nrrrandomfixedr:)r! seed_behaviorrrrrrrsz#LatentBatchSeedBehavior.INPUT_TYPESrrrcCsd|}|d}|dkrd|vr|d|fS|dkr/|ddgd}|g|jd|d<|fS)Nr!rXrPrYr)r#poprUr)r%r!rZr&r batch_numberrrrrs zLatentBatchSeedBehavior.opNr*rrrrrW~s  rWc@0eZdZeddZdZdZdZdZddZ d S) LatentApplyOperationcCddddiS)NrrZLATENT_OPERATION)r! operationrrrrrrz LatentApplyOperation.INPUT_TYPESrrlatent/advanced/operationsTcCs$|}|d}||d|d<|fS)Nr!r r?)r%r!rar&r'rrrrszLatentApplyOperation.opN r+r,r-r.rr/r0r1 EXPERIMENTALrrrrrr^s  r^c@r]) LatentApplyOperationCFGcCr_)NrMODELr`)modelrarrrrrrrbz#LatentApplyOperationCFG.INPUT_TYPESrhpatchrcTcs$|}fdd}|||fS)NcsP|d}t|dkr|d|dd|d|d<|S|dd|d<|S)N conds_outrrrrd)len)argsrlrarrpre_cfg_functions  "z7LatentApplyOperationCFG.patch..pre_cfg_function)clone"set_model_sampler_pre_cfg_function)r%rjramrprrorrks  zLatentApplyOperationCFG.patchN) r+r,r-r.rr/r0r1rfrkrrrrrg  rgc@r]) LatentOperationTonemapReinhardcCsddddddddfiiS) Nrr>r5r6rAgY@r8r9rrrrrrsz*LatentOperationTonemapReinhard.INPUT_TYPESr`rrcTcsfdd}|fS)Ncstjj|ddddddf}||}tj|ddd}tj|ddd}|d|}|d|9}||d}||9}||S) NrrCg|=)rrrT)rDkeepdimr6)rErFrGmeanstd)r kwargsZlatent_vector_magnitudenormalized_latentrxrytopZ new_magnituder>rrtonemap_reinhards   z;LatentOperationTonemapReinhard.op..tonemap_reinhardr)r%r>r~rr}rrs z!LatentOperationTonemapReinhard.opNrerrrrrurtruc@r]) LatentOperationSharpenc Cs:dddddddfddd d d dfdd d d d dfdiS)NrINT rr9r5r6g?r7rAg@r8)sharpen_radiussigmaalpharrrrrrs(z"LatentOperationSharpen.INPUT_TYPESr`rrcTcsfdd}|fS)Nc stjj|ddddddf}||}|jd}dd}tjj||jd}|d}|d9}|||f|d|||f<tj j |fd}tj j j || |ddd|d|d dddd  f} || S) NrrCgư>r)deviceir6reflect)paddinggroups)rErFrGr comfy_extrasZnodes_post_processingZgaussian_kernelrsumnn functionalpadconv2drepeat unsqueeze) r rzZ luminancer{channels kernel_sizekernelrZ padded_imageZ sharpenedrrrrrsharpens     Jz*LatentOperationSharpen.op..sharpenr)r%rrrrrrrrszLatentOperationSharpen.opNrerrrrrs  r) rr3r4r@rNrWr^rgrur) comfy.utilsrZ"comfy_extras.nodes_post_processingrrErrr3r4r@rNrWr^rgrurNODE_CLASS_MAPPINGSrrrrs2"2