def colorspace_conversion(
clip: vs.VideoNode,
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,
) -> vs.VideoNode:
func = FunctionUtil(clip, colorspace_conversion, bitdepth=32)
resample_kwargs = dict[str, Any]()
if matrix is not None:
if matrix_in is not None:
func.work_clip = Matrix.from_param(matrix_in).apply(func.work_clip) # pyright: ignore[reportAttributeAccessIssue]
matrix = Matrix.from_param(matrix, colorspace_conversion)
resample_kwargs |= {"matrix": matrix}
if transfer is not None:
if transfer_in is not None:
func.work_clip = Transfer.from_param(transfer_in).apply(func.work_clip) # pyright: ignore[reportAttributeAccessIssue]
transfer = Transfer.from_param(transfer, colorspace_conversion)
resample_kwargs |= {"transfer": transfer}
if primaries is not None:
if primaries_in is not None:
func.work_clip = Primaries.from_param(primaries_in).apply(func.work_clip) # pyright: ignore[reportAttributeAccessIssue]
primaries = Primaries.from_param(primaries, colorspace_conversion)
resample_kwargs |= {"primaries": primaries}
if color_range is not None:
if color_range_in is not None:
func.work_clip = ColorRange.from_param(color_range_in).apply(func.work_clip) # pyright: ignore[reportAttributeAccessIssue]
color_range = ColorRange.from_param(color_range, colorspace_conversion)
resample_kwargs |= {"range": color_range.value_zimg}
converted = Point().resample(func.work_clip, func.work_clip, **resample_kwargs)
return func.return_clip(converted)