+
    œ°³j#3  ã                   ó¶   € ^ RI t ^RIHt ^RIHt ^RIHtHtHt ^RI	H
t
HtHtHtHt ^RIHtHt ^RIHtHt  ! R R	]R
R7      t] ! R R]4      4       tR.tR# )é    N)ÚTorchvisionBackend)ÚBatchFeature)Údivide_to_patchesÚgroup_images_by_shapeÚreorder_images)ÚOPENAI_CLIP_MEANÚOPENAI_CLIP_STDÚ
ImageInputÚPILImageResamplingÚSizeDict)ÚImagesKwargsÚUnpack)Ú
TensorTypeÚauto_docstringc                   ó0   a € ] tR t^ t o RtV 3R ltRtV tR# )ÚStep3p7ImageProcessorKwargsa  
patch_size (`int`, *optional*, defaults to 504):
    Target size (height = width) for each local patch crop.
max_image_size (`int`, *optional*, defaults to 3024):
    Images larger than this (on their longest side) are scaled down uniformly before patch
    planning.
c                ó2   <€ V ^8„  d   Qh/ S[ ;R&   S[ ;R&   # )é   Ú
patch_sizeÚmax_image_size©Úint)ÚformatÚ__classdict__s   "€Úu/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/step3p7/image_processing_step3p7.pyÚ__annotate__Ú(Step3p7ImageProcessorKwargs.__annotate__    s   ø‡ ‚ ñ �Oñ ñ Ñò ó    © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__)r   s   @r   r   r       s   ø‡ € ñ÷ ƒ r   r   F)Útotalc                   ó  a a€ ] tR t^-t oRt]P                  tRRRR/tRt	Rt
Rt]t]tRt]t. ROtRt^t^t]V3R lR	 l4       tV3R
 lR ltRV3R lR lltV3R lR ltV3R lR lt]V3R lV 3R ll4       tV3R ltRt Vt!V ;t"# )ÚStep3p7ImageProcessorzà
Image processor for Step-3.7-Flash.

Each input image is split into a global down-scaled view plus zero or more
local patch crops via a sliding-window strategy, then every sub-image is
resized and normalised independently.
ÚheightiØ  Úwidthiø  TiÐ  c                ó,   <€ V ^8„  d   QhRS[ RS[ RS[/# )r   r,   r+   Úreturn)r   Úbool)r   r   s   "€r   r   Ú"Step3p7ImageProcessor.__annotate__J   s'   ø€ ÷ Sñ S¡#ð S©sð S±tñ Sr   c                ód   € \        W4      ^ 8  ;'       d    \        W,          W,          4      ^8„  # )zH`True` for near-degenerate images (min side < 32px, aspect ratio > 4:1).)ÚminÚmax)r,   r+   s   &&r   Ú_is_extreme_aspectÚ(Step3p7ImageProcessor._is_extreme_aspectI   s-   € ô �5Ó! BÑ&×RÐR¬3¨u­~¸v½~Ó+NÐQRÑ+RÐRr   c                óŠ   <€ V ^8„  d   QhRS[ RS[ RS[ RS[ RS[S[S[ S[ 3,          S[S[ S[ 3,          S[ S[ S[ S[3,          /# )r   r,   r+   Ú
image_sizer   r.   )r   Útupler/   )r   r   s   "€r   r   r0   N   s^   ø€ ÷ >wñ >wÙð>wÙ"%ð>wÙ36ð>wÙDGð>wá	‰u‘S™#�X�¡¡c©3 h¥±±c¹3ÁÐDÕ	Eñ>wr   c                ó*  a€ V P                  W4      pV'       d   \        W4      ;r\        W!4      V P                  8”  d>   V P                  \        W!4      ,          p\        W,          4      \        W&,          4      r!\	        W!4      \        W!4      r‡Wƒ8:  d   W‡,          R8”  d   TM^ oMW‡,          ^8”  d   \	        Wt4      oMVoS^ 8X  d   W3W3^ ^ ^ V3# V3R lW3 4       w  rš\        ^V	S,          4      p\        ^V
S,          4      pW3Wš3SW¼V3# )u%  Compute the sliding-window patch layout for one image.

Unlike models with a fixed tile size (Idefics3, LLaVA-NeXT), Step3p7
adapts the window size to the image's aspect ratio, so this cannot be
reduced to a simple ``ceil(h / tile) Ã— ceil(w / tile)`` formula.

Step 1 = normalise extreme inputs:
  - extreme-aspect images (min_side < 32, ratio > 4) are squared
  - images larger than ``max_image_size`` are scaled down uniformly

Step 2 â€” choose window size from the normalised aspect ratio:
  - fits in global view (long_side â‰¤ image_size): tile only if elongated
    (long_side / short_side > 1.5), using short_side as the window
  - very elongated (ratio > 4): ``min(short_side, patch_size)``
  - standard case: ``patch_size``

Step 3 â€” snap each dimension to the nearest window multiple
  (snap up when the remainder exceeds 20 % of the window size).

Returns:
    global_width_height: ``(width, height)`` to resize the global view to before squaring
    crop_width_height: ``(crop_width, crop_height)`` snapped dimensions for patch extraction
    window_size: tile side length (``0`` â†’ no local patches)
    num_patches_x: number of patches along the width
    num_patches_y: number of patches along the height
    needs_square_pad: whether the raw image must be zero-padded to a square before resizing
g      ø?c              3   ó†   <"  € T F6  pVS8¼  d)   SVS,          VS,          R S,          8„  ,           ,          MTx € K8  	  R# 5i)gš™™™™™É?Nr   )Ú.0ÚdimÚwindow_sizes   & €r   Ú	<genexpr>Ú6Step3p7ImageProcessor._plan_patches.<locals>.<genexpr>‚   sL   øé € ð #
ñ '�ð ˜+Ô%ð ˜s kÕ1°S¸;Õ5FÈÈ{ÕIZÑ5ZÕ[Ö\àôó 'ùs   ƒ>A)r4   r3   r   r   r2   )Úselfr,   r+   r7   r   Úneeds_square_padÚscaleÚ
short_sideÚ	long_sideÚ
crop_widthÚcrop_heightÚnum_patches_xÚnum_patches_yr=   s   &&&&&        @r   Ú_plan_patchesÚ#Step3p7ImageProcessor._plan_patchesN   s  ø€ ð>  ×2Ñ2°5ÓAÐßÜ  Ó/Ð/ˆEÜˆvÓ × 3Ñ 3Ô3Ø×'Ñ'¬#¨fÓ*<Õ<ˆEÜ ¥Ó.´°FµNÓ0C�6ä # FÓ 2´C¸Ó4F�Ið Ô"Ø(1Õ(>ÀÔ(D™*È!‰KØÕ# aÔ'Ü˜jÓ5‰Kà$ˆKà˜!ÔØ�? U O°Q¸¸1Ð>NÐNÐNô#
ð ‘ó#
Ñˆ
ô ˜A˜z¨[Õ8Ó9ˆÜ˜A˜{¨kÕ9Ó:ˆØˆ Ð 9¸;ÈÐfvÐvÐvr   c                ó,   <€ V ^8„  d   QhRS[ RS[ RS[ /# )r   r+   r,   r.   r   )r   r   s   "€r   r   r0   Ž   s#   ø€ ÷ -ñ -±#ð -¹cð -ÑZ]ñ -r   c                óâ   € T;'       g    / pVP                  RV P                  4      pVR,          pVP                  RV P                  4      pV P                  W!WV4      R,          w  rxWx,          # )zBReturn the number of local patches for an image of the given size.Úsizer+   r   :é   é   N)ÚgetrM   r   rI   )	r@   r+   r,   Úimages_kwargsrM   r7   r   rG   rH   s	   &&&&     r   Úget_number_of_image_patchesÚ1Step3p7ImageProcessor.get_number_of_image_patchesŽ   sh   € à%×+Ð+¨ˆØ× Ñ  ¨¯©Ó3ˆØ˜(•^ˆ
Ø"×&Ñ& |°T·_±_ÓEˆ
Ø'+×'9Ñ'9¸%ÈÓ'`ÐadÕ'eÑ$ˆØÕ,Ð,r   c                ó    <€ V ^8„  d   QhRS[ P                  RS[RS[RRRS[S[ P                  S[S[ P                  ,          S[S[3,          /# )r   Úimgr7   r   Úresampler   r.   )ÚtorchÚTensorr   r8   Úlist)r   r   s   "€r   r   r0   —   sc   ø€ ÷ +Añ +Aá�\‰\ð+Añ ð+Añ ð	+Að
 'ð+Añ 
‰u�|‰|™T¡%§,¡,Õ/±±cÐ9Õ	:ñ+Ar   c                ó  € VP                   w  rVpV P                  WvW#4      w  w  r‰w  r«ppppV'       d2   \        Wv4      pV P                  V.\	        VVR7      R7      ^ ,          pVP                  ^ 4      pV P                  V\	        W˜R7      VR7      pV P                  V\	        W"R7      VR7      P                  ^ 4      pV^ 8X  d   V. WÞ3# V P                  V\	        WºR7      VR7      P                  ^ 4      p\        VVR7      pVVWÞ3# )aJ  Step3p7-specific cropping: square-pad extreme aspect ratios, resize the global view,
and slice out raw (pre-final-resize) local-patch tiles per `_plan_patches`'s layout.

Returns the resized global view, the list of raw local-patch tensors (still at
`window_size`, not yet resized to `patch_size`), and the patch grid dimensions.
©r+   r,   )Úpad_size©rV   )r   )	ÚshaperI   r3   Úpadr   Ú	unsqueezeÚresizeÚsqueezer   )r@   rU   r7   r   rV   Ú_r+   r,   Úglobal_widthÚglobal_heightrE   rF   r=   rG   rH   rA   ÚsideÚ	img_batchÚ
global_imgÚimg_for_cropÚpatchess   &&&&&                r   Ú_get_image_patchesÚ(Step3p7ImageProcessor._get_image_patches—   s  € ð Ÿ9™9Ñˆ�5ð ×Ñ˜u¨jÓEñ	
Ù)ˆ\Ù%ˆZØØØØ÷ Ü�uÓ%ˆDØ—(‘(˜C˜5¬8¸4ÀtÔ+L�(ÓMÈaÕPˆCà—M‘M !Ó$ˆ	ð —[‘[ ¬H¸MÔ,^Ðiq�[Órˆ
Ø—[‘[ ¬X¸ZÔ-ZÐem�[Ón×vÑvØó
ˆ
ð ˜!ÔØ˜r =Ð?Ð?à—{‘{Ø”x {ÔEÐPXð #ó 
ç
‰'�!‹*ð 	ô $ L¸[ÔIˆØ˜7 MÐ@Ð@r   c                óÖ   <€ V ^8„  d   QhRS[ R,          RS[RS[RS[RS[S[ S[,          ,          R,          RS[S[ S[,          ,          R,          R	R
RS[RS[RS[R,          RRRS[/# )r   Úimagesztorch.TensorÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanNÚ	image_stdrV   r   rM   r   Údisable_groupingÚreturn_tensorszstr | TensorType | Noner.   )rY   r/   Úfloatr   r   r   )r   r   s   "€r   r   r0   Ä   s¶   ø€ ÷ Iñ Iá�^Õ$ðIñ ðIñ ð	Iñ
 ðIñ ™D¡�KÕ'¨$Õ.ðIñ ™4¡�;Õ&¨Õ-ðIð 'ðIñ ðIñ ðIñ  �+ðIð 2ðIñ 
ñIr   c                ó  € VP                   p. . . . 3w  rïppV F³  pV P                  VWÙV4      w  ppppVP                  V4       VP                  \        V4      4       VP                  V4       TP                  \	        V4       UUu. uF5  p\	        V4       F#  pVV^,
          8H  ;'       d    VV^,
          8  NK%  	  K7  	  upp4       Kµ  	  V P                  \        P                  ! V4      W#WEV4      pRVRV/p\        VVR7      p\        V^ R7      pV'       d×   \        VRV
R7      w  ppVP                  4        F;  w  pp V P                  V \        W™R7      VR7      p!V P                  V!W#WEV4      VV&   K=  	  \        VVRR	7      p"\        P                  ! V" U#U$u. uF  p#V# F  p$V$NK  	  K  	  up$p#4      VR
&   V U%u. uF$  p%V%R.V\        V%4      ,
          ,          ,           NK&  	  up%VR&   V# u uppi u up$p#i u up%i )é   Úpixel_valuesÚnum_local_patches)ÚdataÚtensor_type)ÚdefaultT)Ú	is_nestedrt   r[   r]   )r~   Úpixel_values_localFÚpatch_newline_masks)r+   rk   ÚappendÚlenÚrangeÚrescale_and_normalizerW   Ústackr   r3   r   Úitemsra   r   r   )&r@   rn   ro   rp   rq   rr   rs   rV   rM   r   rt   ru   Úkwargsr7   Úglobal_imagesÚnested_patchesrz   r€   rU   rh   rj   rG   rH   ÚrowÚcolÚglobal_stackr{   ÚresultÚmax_patchesÚgrouped_patchesÚgrouped_indexr^   Ústacked_patchesÚresizedÚnested_pixel_values_localÚper_image_patchesÚpatchÚmasks&   &&&&&&&&&&&&,                         r   Ú_preprocessÚ!Step3p7ImageProcessor._preprocessÄ   sM  € ð —[‘[ˆ
ØPRÐTVÐXZÐ\^ÐP^ÑMˆÐ'8Ð:MãˆCØ@D×@WÑ@WØ�Z¨XóAÑ=ˆJ˜ °ð × Ñ  Ô,Ø×$Ñ$¤S¨£\Ô2Ø×!Ñ! 'Ô*à×&Ñ&ô  % ]Ô3ôá3˜Ü$ ]Ö3˜ð ˜=¨1Õ,Ñ,×HÐH°°}ÀqÕ7HÑ1HÒHá3ñ IÙ3òöñ ð" ×1Ñ1Ü�KŠK˜Ó&¨
ÀLÐ^gó
ˆð
 ˜LØÐ!2ð
ˆô  4°^ÔDˆäÐ+°QÔ7ˆßô .CØ¨$ÐAQô.Ñ*ˆO˜]ð +:×*?Ñ*?Ö*AÑ&��ØŸ+™+Ø#¤X°ZÔ%RÐ]eð &ó �ð *.×)CÑ)CØ˜Z¸ÐS\ó*� Ó&ñ	 +Bô )7°ÈÐaeÔ(fÐ%ô ,1¯;ª;Ù0IÔiÑ0IÐ,ÓWhÈe“ÑWh‘Ñ0IÒió,ˆFÐ'Ñ(ñ
 H[ó-ÙGZ¸t�˜�w +´°D³	Õ"9Õ:×:Ð:ÑGZñ-ˆFÐ(Ñ)ð ˆùó]ùóP jùò-s   Â	%G8Â/G8Æ#G>
Ç*Hc                ó<   <€ V ^8„  d   QhRS[ RS[S[,          RS[/# )r   rn   r‡   r.   )r
   r   r   r   )r   r   s   "€r   r   r0     s)   ø€ ÷ 4ñ 4¡ð 4±vÑ>YÕ7Zð 4Ñ_kñ 4r   c                ó&   <€ \         SV `  ! V3/ VB # ©N)ÚsuperÚ
preprocess)r@   rn   r‡   Ú	__class__s   &&,€r   r�   Ú Step3p7ImageProcessor.preprocess  s   ø€ ä‰wÒ! &Ñ3¨FÑ3Ð3r   c                ó‚   <€ V ^8„  d   Qh/ S[ ;R&   S[S[,          ;R&   S[S[,          ;R&   S[ ;R&   S[ ;R&   S[ ;R&   # )r   r   rr   rs   r   Úvision_patch_sizeÚdownsampler_stride)r   rY   rv   )r   r   s   "€r   r   r0   -   s[   ø‡ ‚ ñ Ññ ñ ‘U•Ñ.ñ ñ  ‘E�{Ñ,ñ! ñ* Ññ+ ñ2 Ññ3 ñ4 Ñò5 r   r   )ry   r   rz   r›   )#r    r!   r"   r#   r$   r   ÚBILINEARrV   rM   r   ro   rq   r   rr   r	   rs   Údo_convert_rgbr   Úvalid_kwargsÚmodel_input_namesr   r¡   r¢   Ústaticmethodr4   rI   rR   rk   r—   r   r�   r%   r&   r'   Ú__classcell__)rž   r   s   @@r   r*   r*   -   sÇ   ù‡ € ñð "×*Ñ*€HØ�c˜7 CÐ(€DØ€JØ€JØ€LØ.€JØ,€IØ€NØ.€LÚSÐà€Nð  ÐØÐà÷Só ðS÷>wð >w÷@-ò -÷+Að +A÷ZIð IðV ÷4ò 4ó ð4÷G … r   r*   )rW   Úimage_processing_backendsr   Úimage_processing_utilsr   Úimage_transformsr   r   r   Úimage_utilsr   r	   r
   r   r   Úprocessing_utilsr   r   Úutilsr   r   r   r*   Ú__all__r   r   r   Ú<module>r°      sZ   ðó, å ;Ý 2ß XÑ Xß fÕ fß 4ß /ô
 ,°eõ 
ð ôc4Ð.ó c4ó ðc4ðL #Ð
#‚r   