Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/test_vsutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def test_get_w(self):
self.assertEqual(vsutil.get_w(480, only_even=False), 853)
self.assertEqual(vsutil.get_w(1080, 4 / 3), 1440)
self.assertEqual(vsutil.get_w(1080), 1920)
self.assertEqual(vsutil.get_w(849, mod=4), 1508)

def test_iterate(self):
def double_number(x: int) -> int:
Expand Down
17 changes: 13 additions & 4 deletions vsutil/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def get_subsampling(clip: vs.VideoNode, /) -> Union[None, str]:
raise ValueError('Unknown subsampling.')


def get_w(height: int, aspect_ratio: float = 16 / 9, *, only_even: bool = True) -> int:
def get_w(height: int, aspect_ratio: float = 16 / 9, *, only_even: Optional[bool] = None, mod: Optional[int] = None) -> int:
"""Calculates the width for a clip with the given height and aspect ratio.

>>> get_w(720)
Expand All @@ -107,13 +107,22 @@ def get_w(height: int, aspect_ratio: float = 16 / 9, *, only_even: bool = True)
:param only_even: Will return the nearest even integer.
``True`` by default because it imitates the math behind most standard resolutions
(e.g. 854x480).
This parameter has been deprecated in favor of the ``mod`` param. For old behavior
use ``mod=2`` for ``True`` and ``mod=1`` for ``False``
:param mod: Ensure output is divisible by this number, for when subsampling or filter
restrictions set specific requirements (e.g. 4 for interlaced content).
Defaults to 2 to mimic the math behind most standard resolutions.
Any values passed to this argument will override ``only_even`` behavior!

:return: Calculated width based on input `height`.
"""
width = height * aspect_ratio
if only_even:
return round(width / 2) * 2
return round(width)
if only_even is not None:
import warnings
warnings.warn("only_even is deprecated.", DeprecationWarning)

mod = func.fallback(mod, 2 if only_even in [None, True] else 1)
return round(width / mod) * mod


def is_image(filename: str, /) -> bool:
Expand Down
Loading