+
    ƒ°ñjl  ã                  óô   € R t ^ RIHt ^ RIHt ^ RIt^ RIt^t]P                  ! . RO4      t
]P                  ! . RO4      t]3R R lltRR R lltRR R	 lltRR
 R lltRR R lltRR R lltR R ltR# )z8Input/output preprocessing helpers for Depth Anything 3.)Úannotations)ÚTupleNc               ó$   € V ^8„  d   QhRRRRRR/# )é   ÚxÚintÚpatchÚreturn© )Úformats   "ÚIC:\Ai_Coding\apps\studio\ComfyUI\comfy\ldm\depth_anything_3\preprocess.pyÚ__annotate__r      s!   € ÷ 8ñ 8�sð 8 3ð 8¸ñ 8ó    c                ó‚   € W,          V,          pW!,           p\        W0,
          4      \        W,
          4      8:  d   V# T# )N)Úabs)r   r   ÚdownÚups   &&  r   Ú_round_to_patchr      s3   € Ø�J˜%Õ€DØ	�€BÜ�R•V“¤ A¥H£Ô-ˆ2Ð7°4Ð7r   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   Úorig_hr   Úorig_wÚprocess_resÚmethodÚstrr	   zTuple[int, int]r
   )r   s   "r   r   r      s0   € ÷ ñ  ð ¨Sð ¸sð ÈCð Ðkzñ r   c                ól  € VR8X  d   \        W4      pV\        V4      ,          pM3VR8X  d   \        W4      pV\        V4      ,          pM\        RV 24      h\        ^\	        \        \        W,          4      4      4      4      p\        ^\	        \        \        W,          4      4      4      4      pW‡3# )zôCompute (target_h, target_w) for a single image.
upper_bound_resize: scale longest side to process_res, then round each dim to nearest multiple of 14 (default upstream method).
lower_bound_resize: scale shortest side to process_res, then round.Úupper_bound_resizeÚlower_bound_resizez Unsupported process_res_method: )ÚmaxÚfloatÚminÚ
ValueErrorr   r   Úround)	r   r   r   r   ÚlongestÚscaleÚshortestÚnew_wÚnew_hs	   &&&&     r   Úcompute_target_sizer'      s›   € ð
 Ð%Ô%Ü�fÓ%ˆØœe G›nÕ,‰Ø	Ð'Ô	'Ü�vÓ&ˆØœe H›oÕ-‰äÐ;¸F¸8ÐDÓEÐEä�”?¤3¤u¨V­^Ó'<Ó#=Ó>Ó?€EÜ�”?¤3¤u¨V­^Ó'<Ó#=Ó>Ó?€EØˆ<Ðr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úimageútorch.Tensorr   r   r   r   r	   r
   )r   s   "r   r   r   +   s)   € ÷ ñ ˜Lð °sð È#ð Ðiuñ r   c                ó´  € V P                   ^8X  d   V P                  R,          ^8X  g   Q R\        V P                  4       24       hV P                  w  r4rV\        WEW4      w  rxV P	                  R^4      P                  4       p	Wx3WE38w  d1   \        P                  P                  V	P                  4       W‡RR4      p	V	P                  RR4      p	\        P                  V	P                  V	P                  R7      P                  ^^^^4      p
\         P                  V	P                  V	P                  R7      P                  ^^^^4      pWš,
          V,          p	V	# )é   zexpected (B,H,W,3) IMAGE; got ÚlanczosÚdisabledç        ç      ð?)ÚdeviceÚdtypeéÿÿÿÿ)ÚndimÚshapeÚtupler'   ÚmovedimÚ
contiguousÚcomfyÚutilsÚcommon_upscaler   ÚclampÚ_IMAGENET_MEANÚtor1   r2   ÚviewÚ_IMAGENET_STD)r)   r   r   ÚBÚHÚWÚ_Útarget_hÚtarget_wr   ÚmeanÚstds   &&&         r   Úpreprocess_imagerI   +   s!  € Ø�:‰:˜Œ?˜uŸ{™{¨2�°!Ô3ÐjÐ7UÔV[Ð\a×\gÑ\gÓVhÐUiÐ5jÓjÐ3Ø—‘�J€Aˆ!Ü,¨Q°;ÓGÑ€Hð 	�‰�b˜!Ó×'Ñ'Ó)€AØÐ ˜vÔ%ô
 �K‰K×&Ñ& q§w¡w£y°(ÀiÐQ[Ó]ˆØ	�‰��SÓ€Aä×Ñ A§H¡H°A·G±GÐÓ<×AÑAÀ!ÀQÈÈ1ÓM€DÜ
×
Ñ
 !§(¡(°!·'±'Ð
Ó
:×
?Ñ
?ÀÀ1ÀaÈÓ
K€CØ	
��SÕ€AØ€Hr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úsky_predictionr*   Ú	thresholdr   r	   r
   )r   s   "r   r   r   E   s"   € ÷ &ñ &¨ð &À%ð &ÐR^ñ &r   c                ó
   € W8  # )zDBoolean mask: True for non-sky pixels (sky probability < threshold).r
   )rK   rL   s   &&r   Úcompute_non_sky_maskrN   E   s   € àÑ%Ð%r   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )r   Údepthr*   ÚskyrL   r   Úquantiler	   r
   )r   s   "r   r   r   J   s5   € ÷ ñ  ð °<ð ÈEð Ðchð ð  uAñ r   c                óž  € \        WR7      pVP                  4       ^
8:  g   V( P                  4       ^
8:  d   V P                  4       # W,          pVP                  4       R8”  d<   \        P
                  ! ^ VP                  4       RVP                  R7      pWV,          pMTp\        P                  ! Ws4      pV P                  4       p	W‰V( &   V	# )zVClips sky regions to the 99th percentile of non-sky depth. Returns a new depth tensor.)rL   é † ©r1   ©rT   )rN   ÚsumÚcloneÚnumelÚtorchÚrandintr1   rR   )
rP   rQ   rL   rR   Únon_skyÚnon_sky_depthÚidxÚsampledÚ	max_depthÚouts
   &&&&      r   Úapply_sky_aware_cliprb   J   s¥   € ä" 3Ô<€GØ‡{�{ƒ}˜Ô ˜xŸn™nÓ.°"Ô4Ø�{‰{‹}Ðà•N€MØ×ÑÓ˜wÔ&Ü�mŠm˜A˜}×2Ñ2Ó4°jÈ×I]ÑI]Ô^ˆØÕ$‰àˆä—’˜wÓ1€IØ
�+‰+‹-€CØˆˆ�MØ€Jr   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   rP   r*   rQ   ztorch.Tensor | NoneÚlow_quantiler   Úhigh_quantiler	   r
   )r   s   "r   r   r   ]   s;   € ÷ ñ  Lð Ð7Jð Ðafð ð  Dð ð  P\ñ r   c                ó˜  € Ve<   \        V4      pVP                  4       '       d
   W,          pM!V P                  4       pMV P                  4       pVP                  4       R8”  d<   \        P
                  ! ^ VP                  4       RVP                  R7      pWV,          pMTp\        P                  ! Wr4      p\        P                  ! Ws4      p	W˜,
          P                  RR7      p
W,
          V
,          P                  RR4      pRV,
          pVe9   \        V4      ( p\        P                  ! V\        P                  ! V4      V4      pV# )zŒV2-style normalization computes percentile bounds over non-sky pixels (when available), then maps depth into [0, 1] with near = white (1.0).rT   rU   ç�íµ ÷Æ°>©r   r/   r0   rV   )rN   ÚanyÚflattenrY   rZ   r[   r1   rR   r<   ÚwhereÚ
zeros_like)rP   rQ   rd   re   ÚmaskÚvalidr^   ÚsampleÚloÚhiÚrngÚnormÚsky_masks   &&&&         r   Únormalize_depth_v2_styleru   ]   sõ   € à
‚Ü# CÓ(ˆØ�8‰8�:Š:Ø•K‰Eà—M‘M“O‰Eà—‘“ˆà‡{�{ƒ}�wÔÜ�mŠm˜A˜uŸ{™{›}¨jÀÇÁÔNˆØ•‰àˆä	�Š˜Ó	-€BÜ	�Š˜Ó	.€BØ�7�/‰/˜dˆ/Ó
#€CØ�Z˜3Õ×%Ñ% c¨3Ó/€Dà��:€DØ
‚ä(¨Ó-Ð-ˆÜ�{Š{˜8¤U×%5Ò%5°dÓ%;¸TÓBˆØ€Kr   c               ó    € V ^8„  d   QhRRRR/# )r   rP   r*   r	   r
   )r   s   "r   r   r   {   s   € ÷ 6ñ 6 <ð 6°Lñ 6r   c                óÊ   € V P                  RRR7      pV P                  RRR7      pW!,
          P                  RR7      pRW,
          V,          P                  RR4      ,
          # )z@Simple per-frame min/max normalization with near=1.0 convention.T)ÚdimÚkeepdimrg   rh   r0   r/   )éþÿÿÿr3   )ÚaminÚamaxr<   )rP   rp   rq   rr   s   &   r   Únormalize_depth_min_maxr}   {   sW   € à	�‰˜¨$ˆÓ	/€BØ	�‰˜¨$ˆÓ	/€BØ�7�/‰/˜dˆ/Ó
#€CØ�5•: Õ$×+Ñ+¨C°Ó5Õ5Ð5r   )g
×£p=
ß?gÉv¾Ÿ/Ý?g–C‹lçûÙ?)gZd;ßOÍ?gyé&1¬Ì?gÍÌÌÌÌÌÌ?)r   )iø  r   )ç333333Ó?)r~   ç®Gáz®ï?)Ng{®Gáz„?r   )Ú__doc__Ú
__future__r   Útypingr   rZ   Úcomfy.utilsr9   Ú
PATCH_SIZEÚtensorr=   r@   r   r'   rI   rN   rb   ru   r}   r
   r   r   Ú<module>r†      sa   ðÙ >å "å ã ã à€
ð —’Ò3Ó4€Ø—’Ò2Ó3€ð *4÷ 8÷÷&÷4&÷
÷&÷<6r   