o
    ·Ïiy  ã                   @  s¼   U d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	 G dd„ de
eƒZejdejd	ejd
ejdejdejdejdejdiZded< G dd„ de	jƒZG dd„ deƒZddd„ZdS )é    )ÚannotationsN)ÚEnum)Úoverride)ÚComfyExtensionÚioc                   @  s,   e Zd ZdZdZdZdZdZdZdZ	dZ
d	S )
ÚAspectRatioz1:1 (Square)z3:2 (Photo)z4:3 (Standard)z16:9 (Widescreen)z21:9 (Ultrawide)z2:3 (Portrait Photo)z3:4 (Portrait Standard)z9:16 (Portrait Widescreen)N)Ú__name__Ú
__module__Ú__qualname__ÚSQUAREÚPHOTO_HÚ
STANDARD_HÚWIDESCREEN_HÚULTRAWIDE_HÚPHOTO_VÚ
STANDARD_VÚWIDESCREEN_V© r   r   ú;/mnt/c/Users/fbmor/ComfyUI/comfy_extras/nodes_resolution.pyr      s    r   )é   r   )é   é   )é   r   )é   é	   )é   r   )r   r   )r   r   )r   r   z"dict[AspectRatio, tuple[int, int]]ÚASPECT_RATIOSc                   @  s*   e Zd ZdZedd„ ƒZedd
d„ƒZdS )ÚResolutionSelectorzBCalculate width and height from aspect ratio and megapixel target.c                 C  s\   t jddddt jjdttjddt jjdd	d
dd
ddgt jjdddt jjdddgdS )Nr   zResolution SelectorÚutilszwCalculate width and height from aspect ratio and megapixel target. Useful for setting up Empty Latent Image dimensions.Úaspect_ratioz+The aspect ratio for the output dimensions.)ÚoptionsÚdefaultÚtooltipÚ
megapixelsg      ð?gš™™™™™¹?g      0@u:   Target total megapixels. 1.0 MP â‰ˆ 1024Ã—1024 for square.)r!   ÚminÚmaxÚstepr"   Úwidthz+Calculated width in pixels (multiple of 8).)r"   Úheightz,Calculated height in pixels (multiple of 8).)Únode_idÚdisplay_nameÚcategoryÚdescriptionÚinputsÚoutputs)	r   ÚSchemaÚComboÚInputr   r   ÚFloatÚIntÚOutput)Úclsr   r   r   Údefine_schema"   s8   üúùÿÿüëz ResolutionSelector.define_schemar   Ústrr#   ÚfloatÚreturnúio.NodeOutputc           	      C  s^   t | \}}|d d }t |||  ¡}t|| d ƒd }t|| d ƒd }t ||¡S )Ni   é   )r   ÚmathÚsqrtÚroundr   Ú
NodeOutput)	r5   r   r#   Úw_ratioÚh_ratioÚtotal_pixelsÚscaler'   r(   r   r   r   ÚexecuteC   s   zResolutionSelector.executeN)r   r7   r#   r8   r9   r:   )r   r	   r
   Ú__doc__Úclassmethodr6   rD   r   r   r   r   r      s    
 r   c                   @  s   e Zd Zeddd„ƒZdS )ÚResolutionExtensionr9   úlist[type[io.ComfyNode]]c                 Ã  s   t gS ©N)r   )Úselfr   r   r   Úget_node_listN   s   €ÿz!ResolutionExtension.get_node_listN)r9   rH   )r   r	   r
   r   rK   r   r   r   r   rG   M   s    rG   r9   c                   Ã  s   t ƒ S rI   )rG   r   r   r   r   Úcomfy_entrypointU   s   €rL   )r9   rG   )Ú
__future__r   r<   Úenumr   Útyping_extensionsr   Úcomfy_api.latestr   r   r7   r   r   r   r   r   r   r   r   r   r   Ú__annotations__Ú	ComfyNoder   rG   rL   r   r   r   r   Ú<module>   s$    ø.