Skip to content

Commit

Permalink
colorspace_conversion: rename param, add from_param
Browse files Browse the repository at this point in the history
  • Loading branch information
LightArrowsEXE committed Sep 14, 2024
1 parent d364c20 commit 5dd8413
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions vsadjust/colorspace.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Any

from vskernels import Point
from vstools import ColorRange, DitherType, Matrix, Primaries, Transfer, vs
from vstools import (ColorRange, ColorRangeT, DitherType, Matrix, MatrixT,
Primaries, PrimariesT, Transfer, TransferT, vs)

__all__ = [
'colorspace_conversion'
Expand All @@ -10,14 +11,10 @@

def colorspace_conversion(
clip: vs.VideoNode,
matrix: Matrix = None,
transfer: Transfer = None,
primaries: Primaries = None,
range: ColorRange = None,
matrix_in: Matrix = None,
transfer_in: Transfer = None,
primaries_in: Primaries = None,
range_in: ColorRange = None,
matrix: MatrixT | None = None, transfer: TransferT | None = None,
primaries: PrimariesT | None = None, color_range: ColorRangeT | None = None,
matrix_in: MatrixT | None = None, transfer_in: TransferT | None = None,
primaries_in: PrimariesT | None = None, color_range_in: ColorRangeT | None = None,
dither_type: DitherType = DitherType.AUTO,
) -> vs.VideoNode:

Expand All @@ -26,21 +23,33 @@ def colorspace_conversion(
if matrix is not None:
if matrix_in is not None:
clip = Matrix.from_param(matrix_in).apply(clip)

matrix = Matrix.from_param(matrix, colorspace_conversion)

resample_kwargs |= dict(matrix=matrix)

if transfer is not None:
if transfer_in is not None:
clip = Transfer.from_param(transfer_in).apply(clip)

transfer = Transfer.from_param(transfer, colorspace_conversion)

resample_kwargs |= dict(transfer=transfer)

if primaries is not None:
if primaries_in is not None:
clip = Primaries.from_param(primaries_in).apply(clip)

primaries = Primaries.from_param(primaries, colorspace_conversion)

resample_kwargs |= dict(primaries=primaries)

if range is not None:
if range_in is not None:
clip = ColorRange.from_param(range_in).apply(clip)
resample_kwargs |= dict(range=range.value_zimg)
if color_range is not None:
if color_range_in is not None:
clip = ColorRange.from_param(color_range_in).apply(clip)

color_range = ColorRange.from_param(color_range, colorspace_conversion)

resample_kwargs |= dict(range=color_range.value_zimg)

return Point.resample(clip, clip, **resample_kwargs)

0 comments on commit 5dd8413

Please sign in to comment.