Jaded-Encoding-Thaumaturgy / vs-scale

VapourSynth (de)scaling functions
MIT License
10 stars 4 forks source link

`descale`: add fractional resolution support #70

Closed LightArrowsEXE closed 1 year ago

LightArrowsEXE commented 1 year ago

See: https://github.com/YomikoR/GetFnative

For more specific use-cases, pitfalls, and examples, I suggest asking @moelancholy and sam.

Example code of how you currently do fractional rescaling:

    from getfnative import descale_cropping_args  # type:ignore

    # Fractional descale.
    clip_y = get_y(clip)

    de_args = descale_cropping_args(clip_y, src_height=720.2, base_height=722, base_width=get_w(722))
    up_args = de_args | dict(width=clip.width, height=clip.height)
    ss_args = {k: v * 2 for k, v in de_args.items() if str(k).startswith('src_') and isinstance(v, (int, float))}

    descaled = Catrom.descale(clip_y, **de_args)
    upscaled = Catrom.scale(descaled, **up_args)

    cmask = descale_detail_mask(clip_y, upscaled)

    # Reupscaling.
    w2x = Waifu2x(cuda=True, tiles=4, overlap=16, num_streams=2) \
        .scale(descaled, descaled.width * 2, descaled.height * 2)
    scaled = SSIM.scale(w2x, clip.width, clip.height, **ss_args)  # type:ignore

    # Merging with detail mask and denoised chroma.
    scaled = join(core.std.MaskedMerge(scaled, clip_y, cmask), clip)