BestResolutionPrimResPriority

This commit is contained in:
Lex Darlog (DRL)
2025-07-13 15:20:20 +05:00
parent 30bb735b71
commit f698f8b102
3 changed files with 100 additions and 31 deletions
+9 -2
View File
@@ -2,20 +2,27 @@
"""
"""
import typing as _t
from .nodes_simple import *
from .nodes_upscale import *
from .nodes_prims import *
NODE_CLASS_MAPPINGS = {
NODE_CLASS_MAPPINGS: _t.Dict[str, type] = {
"BestResolutionFromArea": BestResolutionFromArea,
"BestResolutionFromAreaUpscale": BestResolutionFromAreaUpscale,
"BestResolutionFromAspectRatio": BestResolutionFromAspectRatio,
"BestResolutionSimple": BestResolutionSimple,
"BestResolutionPrimResPriority": BestResolutionPrimResPriority,
}
NODE_DISPLAY_NAME_MAPPINGS = {
NODE_DISPLAY_NAME_MAPPINGS: _t.Dict[str, str] = {
"BestResolutionFromArea": "Best-Res (area)",
"BestResolutionFromAreaUpscale": "Best-Res (area+scale)",
"BestResolutionFromAspectRatio": "Best-Res (ratio)",
"BestResolutionSimple": "Best-Res (simple)",
"BestResolutionPrimResPriority": "Priority (Best-Res)",
}
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
+88
View File
@@ -0,0 +1,88 @@
# encoding: utf-8
"""
Supporting primitive nodes for the pack.
"""
import typing as _t
from inspect import cleandoc as _cleandoc
from frozendict import deepfreeze as _deepfreeze
from .enums import *
# ----------------------------------------------------------
_res_priority_data_type = RoundingPriority.all_values()
_res_priority_data_type_set = set(_res_priority_data_type)
# _priority_in_type = (_IO.BOOLEAN, {
# 'default': True, 'label_on': 'upscaled', 'label_off': 'original',
# 'tooltip': (
# "Which of the resolutions is more important to be as close to the desired as possible:\n\n"
# "When ON, the rounded with/height are first calculated for the UPSCALED resolution - and "
# "only then the original ones are back-tracked from them.\n"
# "When OFF, they're first calculated for the ORIGINAL resolution - and "
# "the upscaled ones are tracked forward from them."
# )
# })
_res_priority_in_type = (
_res_priority_data_type,
{
'default': RoundingPriority.DESIRED.value,
'tooltip': (
"Defines what resolution to prioritize, as well as which order to perform rounding in:\n\n"
"• desired - first, approximate resolutions are calculated for both initial and upscaled size; "
"then, both are rounded. In both cases, the rounded resolution is closest to the desired one, "
"but aspect ratio might differ the most between sizes.\n\n"
"• original - first, initial resolution is calculated and rounded; then, upscaled one is detected from it. "
"Upscaled resolution might differ the most from the desired aspect ratio, but it follows the ratio from "
"initial size as much as possible.\n\n"
"• upscaled - vice versa: first, the rounded upscaled resolution is calculated; then, the initial one "
"back-tracked from it."
)
}
)
_input_types_prim_priority = _deepfreeze({
'required': {
'priority': _res_priority_in_type
},
# 'hidden': {
# 'unique_id': 'UNIQUE_ID',
# },
# 'optional': {},
})
class BestResolutionPrimResPriority:
"""
'priority' selector for "Best Resolution" upscale-nodes.
"""
NODE_NAME = 'BestResolutionPrimResPriority'
CATEGORY = "utils/resolution"
DESCRIPTION = _cleandoc(__doc__)
OUTPUT_NODE = False
FUNCTION = 'main'
RETURN_TYPES = (_res_priority_data_type,)
RETURN_NAMES = ('priority', )
# OUTPUT_TOOLTIPS = ('', )
@classmethod
def INPUT_TYPES(cls):
return _input_types_prim_priority
def main(
self, priority: _t.Union[RoundingPriority, str],
# show: bool,
# unique_id: str = None
):
return (_res_priority_verify(priority), )
def _res_priority_verify(priority: _t.Union[RoundingPriority, str]) -> str:
if priority not in _res_priority_data_type_set:
raise ValueError(f"Invalid value for resolution priority: {priority!r}\nExpected one of: {_res_priority_data_type!r}")
return str(priority)
+3 -29
View File
@@ -21,6 +21,7 @@ from ._funcs import (
from .enums import *
from .node_types import *
from .nodes_simple import _input_types_area
from .nodes_prims import _res_priority_in_type, _res_priority_verify
# ----------------------------------------------------------
@@ -43,35 +44,8 @@ _return_ttips_upscale = _frozendict({
),
})
# __priority_type = (_IO.BOOLEAN, {
# 'default': True, 'label_on': 'upscaled', 'label_off': 'original',
# 'tooltip': (
# "Which of the resolutions is more important to be as close to the desired as possible:\n\n"
# "When ON, the rounded with/height are first calculated for the UPSCALED resolution - and "
# "only then the original ones are back-tracked from them.\n"
# "When OFF, they're first calculated for the ORIGINAL resolution - and "
# "the upscaled ones are tracked forward from them."
# )
# })
__priority_type = (
RoundingPriority.all_values(),
{
'default': RoundingPriority.DESIRED.value,
'tooltip': (
"Defines what resolution to prioritize, as well as which order to perform rounding in:\n\n"
"• desired - first, approximate resolutions are calculated for both initial and upscaled size; "
"then, both are rounded. In both cases, the rounded resolution is closest to the desired one, "
"but aspect ratio might differ the most between sizes.\n\n"
"• original - first, initial resolution is calculated and rounded; then, upscaled one is detected from it. "
"Upscaled resolution might differ the most from the desired aspect ratio, but it follows the ratio from "
"initial size as much as possible.\n\n"
"• upscaled - vice versa: first, the rounded upscaled resolution is calculated; then, the initial one "
"back-tracked from it."
)
}
)
__extra_inputs_for_upscale_only = {
'priority': __priority_type,
'priority': _res_priority_in_type,
'upscale': (_IO.FLOAT, {
'default': 1.5, 'min': 1.0, 'max': _sys.float_info.max, 'step': 0.25, 'round': 0.001,
# 'tooltip': "", # TODO
@@ -135,7 +109,7 @@ class BestResolutionFromAreaUpscale:
width_f, height_f = _float_width_height_from_area(square_size, landscape, aspect_a, aspect_b)
return _upscale_result_from_approx_wh(
width_f, height_f, step,
priority, upscale, up_step,
_res_priority_verify(priority), upscale, up_step,
# show,
unique_id=unique_id, target_square_size=square_size
)