Skip to content

Commit

Permalink
Add AviSynth+ plugin
Browse files Browse the repository at this point in the history
AviSynth+ API V8 required
  • Loading branch information
Frechdachs committed Apr 1, 2022
1 parent 9ef1b02 commit c4bb61d
Show file tree
Hide file tree
Showing 11 changed files with 515 additions and 32 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Descale

VapourSynth plugin to undo upscaling.
Video/Image filter to undo upscaling.

Includes a VapourSynth and Avisynth+ plugin

## Usage

The plugin itself supports every constant input format. If the format is subsampled, left-aligned chroma planes are always assumed.
The VapourSynth plugin itself supports every constant input format. If the format is subsampled, left-aligned chroma planes are always assumed.
The included python wrapper, contrary to using the plugin directly, doesn't descale the chroma planes but scales them normally with `Spline36`.

```
Expand All @@ -23,6 +25,8 @@ descale.Despline64(clip src, int width, int height, float src_left=0.0, float sr
descale.Descale(clip src, int width, int height, str kernel, int taps=3, float b=0.0, float c=0.0, float src_left=0.0, float src_top=0.0, float src_width=width, float src_height=height, int opt=0)
```

The AviSynth+ plugin is used similarly, but without the `descale` namespace.

## How does this work?

Resampling can be described as `A x = b`.
Expand All @@ -33,7 +37,7 @@ To do this, we extend the equation with the transpose of A: `A' A x = A' b`.

`A' A` is now a banded symmetrical m x m matrix and `A' b` is a vector with `m` elements.

This enables us to use LDLT decomposition on `A' A` to get `LD L' = A' A`. LD and L are both triangular matrices.
This enables us to use LDLT decomposition on `A' A` to get `LD L' = A' A`. `LD` and `L` are both triangular matrices.

Then we solve `LD y = A' b` with forward substitution, and finally `L' x = y` with back substitution.

Expand All @@ -42,6 +46,9 @@ We now have the original vector `x`.

## Compilation

By default only the VapourSynth plugin is compiled
To build the Avisynth+ plugin, add `-Dlibtype=avisynth` or `-Dlibtype=both` to the meson command below.

### Linux

```
Expand Down
1 change: 1 addition & 0 deletions cross-mingw-x86_64.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[binaries]
c = 'x86_64-w64-mingw32-gcc'
cpp = 'x86_64-w64-mingw32-g++'
ar = 'x86_64-w64-mingw32-ar'
strip = 'x86_64-w64-mingw32-strip'
pkgconfig = 'x86_64-w64-mingw32-pkg-config'
Expand Down
13 changes: 7 additions & 6 deletions include/descale.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2017-2021 Frechdachs <[email protected]>
* Copyright © 2021-2022 Frechdachs <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
Expand Down Expand Up @@ -51,14 +51,15 @@ typedef enum DescaleOpt
} DescaleOpt;


// Optional struct members should be initialized to 0 if not used
typedef struct DescaleParams
{
enum DescaleMode mode;
int taps;
double param1;
double param2;
double shift;
double active_dim;
int taps; // required if mode is LANCZOS
double param1; // required if mode is BICUBIC
double param2; // required if mode is BICUBIC
double shift; // optional
double active_dim; // always required; usually equal to dst_dim
} DescaleParams;


Expand Down
28 changes: 25 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ cc = meson.get_compiler('c')

includedirs = ['include', 'src']

sources = ['src/descale.c', 'src/vsplugin.c']
sources = ['src/descale.c']

libs = []

deps = []

libtype = get_option('libtype')

if libtype in ['vapoursynth', 'both']
sources += ['src/vsplugin.c']
endif

if libtype in ['avisynth', 'both']
sources += ['src/avsplugin.c']
endif

# Don't require VS to be installed on Windows,
# so we don't need to have VS fully installed
# in our mingw environment. Just the header files
Expand All @@ -25,13 +35,25 @@ if host_machine.system() == 'windows'
m_dep = cc.find_library('m', static: true, required: false)
p_dep = cc.find_library('winpthread', static: true)
deps += [m_dep, p_dep]
installdir = join_paths(get_option('libdir'), 'vapoursynth')
if libtype in ['avisynth', 'both']
deps += [cc.find_library('AviSynth', dirs: meson.current_source_dir())]
endif
if libtype in ['vapoursynth', 'both'] # I'm not sure if it is possible to install
# the _same_ file to multiple directories with meson
installdir = join_paths(get_option('libdir'), 'vapoursynth')
else
installdir = join_paths(get_option('libdir'), 'avisynth')
endif
else
m_dep = cc.find_library('m', required: false)
p_dep = cc.find_library('pthread')
vs = dependency('vapoursynth').partial_dependency(compile_args: true, includes: true)
deps += [m_dep, p_dep, vs]
installdir = join_paths(vs.get_pkgconfig_variable('libdir'), 'vapoursynth')
if libtype in ['vapoursynth', 'both']
installdir = join_paths(vs.get_pkgconfig_variable('libdir'), 'vapoursynth')
else
installdir = join_paths(vs.get_pkgconfig_variable('libdir'), 'avisynth')
endif
endif

if host_machine.cpu_family().startswith('x86')
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('libtype', type: 'combo', choices: ['vapoursynth', 'avisynth', 'both'], value: 'vapoursynth')
Loading

0 comments on commit c4bb61d

Please sign in to comment.