Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Lypheo/vs-placebo
Browse files Browse the repository at this point in the history
  • Loading branch information
Lypheo committed Apr 23, 2020
2 parents a47a95c + 5daba8c commit 1ac6409
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
libplacebo/
build/
libplacebo/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ For example, to map from [BT.2020, PQ\] (HDR) to traditional [BT.709, BT.1886\]
- ``tone_mapping_algo, tone_mapping_param, desaturation_strength, desaturation_exponent, desaturation_base, max_boost, gamut_warning``:
[Color mapping params](https://github.com/haasn/libplacebo/blob/master/src/include/libplacebo/shaders/colorspace.h#L199).

#### ``placebo.Resample(clip clip[, int width, int height, string filter = "ewa_lanczos", float radius, float clamp, float taper, float blur, float param0, float param1, float sx = 0.0, float sy = 0.0, float antiring = 0.0, int lut_entries = 64, float cutoff = 0.001])``
#### ``placebo.Resample(clip clip[, int width, int height, string filter = "ewa_lanczos", float radius, float clamp, float taper, float blur, float param1, float param2, float sx = 0.0, float sy = 0.0, float antiring = 0.0, int lut_entries = 64, float cutoff = 0.001])``
**Don’t use with non-polar (i.e. not prefixed with “ewa\_”) filters!** Currently they output a slightly shifted image for unknown reasons
(though only for large frames, which makes me suspect a libplacebo bug, but what do I know).

Input needs to be 8 or 16 bit Integer or 32 bit Float

- ``filter``: See [the header](https://github.com/haasn/libplacebo/blob/210131146739e4e84d689f32c17a97b27a6550bd/src/include/libplacebo/filters.h#L187) for possible values (remove the “pl_filter” before the filter name, e.g. ``filter="lanczos"``).
- ``sx``, ``sy``: subpixel shifts
- ``sx``, ``sy``: Top left corner of the source region. Can be used for subpixel shifts
- ``float clamp, float taper, float blur``: [Filter config](https://github.com/haasn/libplacebo/blob/885e89bccfb932d9e8c8659039ab6975e885e996/src/include/libplacebo/filters.h#L148).

- ``float radius, float param0, float param1``: [Kernel config](https://github.com/haasn/libplacebo/blob/885e89bccfb932d9e8c8659039ab6975e885e996/src/include/libplacebo/filters.h#L30-L131).
- ``float radius, float param1, float param2``: [Kernel config](https://github.com/haasn/libplacebo/blob/885e89bccfb932d9e8c8659039ab6975e885e996/src/include/libplacebo/filters.h#L30-L131).
36 changes: 18 additions & 18 deletions resample.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ typedef struct {
int height;
struct pl_sample_filter_params *sampleParams;
struct pl_shader_obj *lut;
float shift_x;
float shift_y;
float src_x;
float src_y;
} RData;

bool do_plane_R(struct priv *p, void* data, int w, int h, const VSAPI *vsapi, float sx, float sy)
Expand All @@ -27,10 +27,10 @@ bool do_plane_R(struct priv *p, void* data, int w, int h, const VSAPI *vsapi, fl
const struct pl_tex *sep_fbo = NULL;
struct pl_sample_src src = (struct pl_sample_src){ .tex = p->tex_in[0], .new_h = h, .new_w = w,
.rect = {
-sx,
-sy,
p->tex_in[0]->params.w - sx,
p->tex_in[0]->params.h - sy,
sx,
sy,
p->tex_in[0]->params.w + sx,
p->tex_in[0]->params.h + sy,
}
};
struct pl_sample_filter_params sampleFilterParams = *d->sampleParams;
Expand Down Expand Up @@ -189,10 +189,10 @@ static const VSFrameRef *VS_CC ResampleGetFrame(int n, int activationReason, voi
.component_map[0] = 0,
};

int shift = d->vi->format->colorFamily == cmYUV && d->vi->format->subSamplingW == 1 && d->vi->format->subSamplingH == 1 && (i == 1 || i == 2);
float subsampling_shift = 0.25f - 0.25f * (float) d->vi->width/ (float) d->width; // FIXME: support other subsampling ratios and chroma locations as well
float sx = (shift ? subsampling_shift : 0.f) + d->shift_x * vsapi->getFrameWidth(frame, i)/d->vi->width;
float sy = d->shift_y * vsapi->getFrameHeight(frame, i)/d->vi->height;
bool shift = d->vi->format->colorFamily == cmYUV && d->vi->format->subSamplingW == 1 && (i == 1 || i == 2);
float subsampling_shift = 0.25f - 0.25f * (float) d->vi->width / (float) d->width; // FIXME: support other subsampling ratios and chroma locations as well
float sx = (shift ? subsampling_shift : 0.f) + d->src_x * vsapi->getFrameWidth(frame, i)/d->vi->width;
float sy = d->src_y * vsapi->getFrameHeight(frame, i)/d->vi->height;
int w = vsapi->getFrameWidth(dst, i), h = vsapi->getFrameHeight(dst, i);
if (reconfig_R(d->vf, &plane, w, h, vsapi))
filter_R(d->vf, vsapi->getWritePtr(dst, i), &plane, d, w, h, vsapi->getStride(dst, i) / d->vi->format->bytesPerSample, vsapi, sx, sy);
Expand Down Expand Up @@ -239,8 +239,8 @@ void VS_CC ResampleCreate(const VSMap *in, VSMap *out, void *userData, VSCore *c
if (err)
d.height = d.vi->height;

d.shift_x = vsapi->propGetFloat(in, "sx", 0, &err);
d.shift_y = vsapi->propGetFloat(in, "sy", 0, &err);
d.src_x = vsapi->propGetFloat(in, "sx", 0, &err);
d.src_y = vsapi->propGetFloat(in, "sy", 0, &err);


struct pl_sample_filter_params *sampleFilterParams = malloc(sizeof(struct pl_sample_filter_params));;
Expand Down Expand Up @@ -289,17 +289,17 @@ void VS_CC ResampleCreate(const VSMap *in, VSMap *out, void *userData, VSCore *c
if (!err)
f->radius = vsapi->propGetFloat(in, "radius", 0, &err);
}
vsapi->propGetFloat(in, "param0", 0, &err);
if (!err)
f->params[0] = vsapi->propGetFloat(in, "param0", 0, &err);
vsapi->propGetFloat(in, "param1", 0, &err);
if (!err)
f->params[1] = vsapi->propGetFloat(in, "param1", 0, &err);
if (!err && f->tunable[0])
f->params[0] = vsapi->propGetFloat(in, "param1", 0, &err);
vsapi->propGetFloat(in, "param2", 0, &err);
if (!err && f->tunable[1])
f->params[1] = vsapi->propGetFloat(in, "param2", 0, &err);
sampleFilterParams->filter.kernel = f;


d.sampleParams = sampleFilterParams;
data = malloc(sizeof(d));
*data = d;
vsapi->createFilter(in, out, "Resample", ResampleInit, ResampleGetFrame, ResampleFree, fmUnordered, 0, data, core);
}
}
10 changes: 3 additions & 7 deletions resample.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
//
// Created by saifu on 4/14/2020.
//

#ifndef P2P_RESAMPLE_H
#define P2P_RESAMPLE_H
#ifndef VS_PLACEBO_RESAMPLE_H
#define VS_PLACEBO_RESAMPLE_H

#include "VapourSynth.h"

void VS_CC ResampleCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi);

#endif //P2P_RESAMPLE_H
#endif //VS_PLACEBO_RESAMPLE_H
2 changes: 1 addition & 1 deletion vs-placebo.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void uninit(void *priv)
VS_EXTERNAL_API(void) VapourSynthPluginInit(VSConfigPlugin configFunc, VSRegisterFunction registerFunc, VSPlugin *plugin) {
configFunc("com.vs.placebo", "placebo", "libplacebo plugin for VapourSynth", VAPOURSYNTH_API_VERSION, 1, plugin);
registerFunc("Deband", "clip:clip;planes:int:opt;iterations:int:opt;threshold:float:opt;radius:float:opt;grain:float:opt;dither:int:opt;dither_algo:int:opt;renderer_api:int:opt", DebandCreate, 0, plugin);
registerFunc("Resample", "clip:clip;width:int;height:int;filter:data:opt;clamp:float:opt;blur:float:opt;taper:float:opt;radius:float:opt;param0:float:opt;param1:float:opt;"
registerFunc("Resample", "clip:clip;width:int;height:int;filter:data:opt;clamp:float:opt;blur:float:opt;taper:float:opt;radius:float:opt;param1:float:opt;param2:float:opt;"
"sx:float:opt;sy:float:opt;antiring:float:opt;lut_entries:int:opt;cutoff:float:opt", ResampleCreate, 0, plugin);
registerFunc("Tonemap", "clip:clip;"
"srcp:int:opt;srct:int:opt;srcl:int:opt;src_peak:float:opt;src_avg:float:opt;src_scale:float:opt;"
Expand Down

0 comments on commit 1ac6409

Please sign in to comment.