Code Monkey home page Code Monkey logo

vapoursynth-jincresize's Introduction

VapourSynth-JincResize

Build Status

Description

JincResize is a resizer plugin for VapourSynth, works by Jinc function and elliptical weighted averaging (EWA). Support 8-16 bit and 32 bit sample type. Support YUV color family.

The repo is ported from AviSynth plugin and based on EWA-Resampling-VS.

If want to learn more about Jinc, you can read the post (Simplified Chinese / 简体中文).

Usage

core.jinc.JincResize(clip clip, int width, int height[, int tap, float src_left, float src_top,
                     float src_width, float src_height, int quant_x, int quant_y, float blur])
  • clip
    • Required parameter.
    • Clip to process.
    • Integer sample type of 8-16 bit depth and float sample type of 32 bit depth is supported.
  • width
    • Required parameter.
    • The width of output.
  • height
    • Required parameter.
    • The height of output.
  • tap
    • Optional parameter. Range: 1–16. Default: 3.
    • Corresponding to different zero points of Jinc function.
    • The recommended value is 3, 4, 6, 8, which is similar to the AviSynth plugin, Jinc36Resize, Jinc64Resize, Jinc128Resize, Jinc256Resize.
  • src_left
    • Optional parameter. Default: 0.0.
    • Cropping of the left edge respectively, in pixels, before resizing.
  • src_top
    • Optional parameter. Default: 0.0.
    • Cropping of the top edge respectively, in pixels, before resizing.
  • src_width
    • Optional parameter. Default: the width of input.
    • If > 0, setting the width of the clip before resizing.
    • If <= 0, setting the cropping of the right edge respectively, before resizing.
  • src_height
    • Optional parameter. Default: the height of input.
    • If > 0, setting the height of the clip before resizing.
    • If <= 0, setting the cropping of the bottom edge respectively, before resizing.
  • quant_x
  • quant_y
    • Optional parameter. Default: 256.
    • Controls sub-pixel quantization.
  • blur
    • Optional parameter. Default: 0.9812505644269356.
    • Blur processing, it can reduce side effects.
    • To achieve blur, the value should less than 1.
    • If don't have relevant knowledge or experience, had better not modify the parameter.

Tips

JincResize will lead to ringing. A solution is to use de-ringing as post-processing, such as HQDeringmod() in havsfunc. A simple example as follows.

from vapoursynth import core
import havfunc as haf

# src is a 720p clip
dst = core.jinc.JincResize(src, 1920, 1080)
dst = haf.HQDeringmod(dst)

Compilation

Windows

x86_64-w64-mingw32-g++ -shared -static -std=c++17 -O3 -march=native JincResize.cpp -o JincResize.dll

VapourSynth.h and VSHelper.h is need. You can get them from here or your VapourSynth installation directory (VapourSynth/sdk/include/vapoursynth).

Linux

meson build
ninja -C build

or directly

g++ -shared -fPIC -std=c++17 -O3 -march=native JincResize.cpp -o JincResize.so

Windows and Linux using Github Actions

1.Fork this repository.

2.Enable Github Actions on your fork: Settings tab -> Actions -> General -> Allow all actions and reusable workflows -> Save button.

3.Edit (if necessary) the file .github/workflows/CI.yml on your fork modifying the environment variable VapourSynth version:

env:
  VAPOURSYNTH_VERSION: <SET_YOUR_VERSION>

4.Go to the GitHub Actions tab on your fork, select CI workflow and press the Run workflow button (if you modified the .github/workflows/CI.yml file, a workflow will be already running and no need to run a new one).

When the workflow is completed you will be able to download the artifacts generated (Windows and Linux versions) from the run.

Download Nightly Builds

GitHub Actions Artifacts ONLY can be downloaded by GitHub logged users.

Nightly builds are built automatically by GitHub Actions (GitHub's integrated CI/CD tool) every time a new commit is pushed to the master branch or a pull request is created.

To download the latest nightly build, go to the GitHub Actions tab, enter the last run of workflow CI, and download the artifacts generated (Windows and Linux versions) from the run.

Acknowledgement

EWA-Resampling-VS: https://github.com/Lypheo/EWA-Resampling-VS

AviSynth plugin: https://github.com/AviSynth/jinc-resize

vapoursynth-jincresize's People

Contributors

bittor7x0 avatar kiyamou avatar luglio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vapoursynth-jincresize's Issues

Downscaling first and upscaling next, output is abnormal in the bottom and right

(Only found at r6 version)

When downscaling first and upscaling next, output will be abnormal in the bottom and right of scene, such as

# clip is 1080p

clip = core.fmtc.resample(clip, 1280, 720)
clip = core.jinc.JincResize(clip, 1920, 1080)

However, if the original clip is 720p, not downscaled in the same script, upscaling will be normal.

Abnormal black points on white words when 16bit or 8bit input

There are abnormal black points on white words when 16bit or 8bit input.

16bit or 8bit input has the bug, while 9-15bit and 32bit input are normal. r6.1 and earlier versions are normal.

sample

Because 9-15bit input are normal, guess the algorithm itself doesn't have problems. So the bug may be related with type conversion, such as the follow codes.

dstp[x] = static_cast<T>(clamp(result, 0.f, peak + 1.f));

Rewrite like this:

dstp[x] = static_cast<T>(result);

Before rewriting, the pixel value of black points is 0. After rewriting, the pixel values of black points are very small number but not 0.

At first, I guess that some bug makes the pixel value become negative. However, I try this code:

dstp[x] = static_cast<T>(clamp(std::abs(result), 0.f, peak + 1.f)); 

The result is same with original code, the pixel value of black points is 0.

Update: After adding AVX2 for convolution (636e700 and 92470b4), the bug is still.

Oh no

When I said “Unfinished, unusably slow. Don’t use.”, I meant it, lol. It still has a lot of problems, most notably that it’s completely useless because nnedi3 is both faster and produces higher quality upscales. On top of that, it doesn’t sample from a proper ellipse when resizing to a different aspect ratio but instead always uses a cirlce. Further, it doesn’t handle borders very well (ideally, the edges should either be extended or mirrored when sampling outside of the image. Instead, it currently just truncates the kernel).
You might wanna port https://github.com/AviSynth/jinc-resize instead for a much more complete and much faster implementation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.