-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplugin.cpp
105 lines (78 loc) · 3.18 KB
/
plugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
plugin.cpp
This file is a part of VS_AvsReader
Copyright (C) 2016 Oka Motofumi
Author: Oka Motofumi (chikuzen.mo at gmail dot com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Libav; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "AvsReader.h"
#include "myvshelper.h"
static const VSFrameRef* VS_CC
get_frame(int n, int activation_reason, void **instance_data, void **,
VSFrameContext *frame_ctx, VSCore *core, const VSAPI *api)
{
if (activation_reason != arInitial) {
return nullptr;
}
auto d = reinterpret_cast<AvsReader*>(*instance_data);
try {
return d->getFrame(n, core, api, frame_ctx);
} catch (AvisynthError e) {
api->setFilterError(e.msg, frame_ctx);
}
return nullptr;
}
static void VS_CC
free_filter(void* instance_data, VSCore*, const VSAPI*)
{
delete reinterpret_cast<AvsReader*>(instance_data);
}
static void VS_CC
init_filter(VSMap*, VSMap*, void** instance_data, VSNode* node, VSCore*,
const VSAPI* api)
{
auto d = reinterpret_cast<AvsReader*>(*instance_data);
api->setVideoInfo(d->getVSVideoInfo(), d->getNumOutputs(), node);
}
static void VS_CC
create_avsr(const VSMap* in, VSMap* out, void* user_data, VSCore* core,
const VSAPI* api)
{
const char* mode = reinterpret_cast<char*>(user_data);
int bd = get_arg("bitdepth", 8, 0, in, api);
const char* input =
get_arg(mode[0] == 'E' ? "lines" : "script", "", 0, in, api);
bool alpha = get_arg("alpha", true, 0, in, api);
try {
validate(bd != 8 && bd != 9 && bd != 10 && bd != 16,
"invalid bitdepth was specified.");
validate(strlen(input) < 1, "zero length avs.");
auto d = AvsReader::create(input, bd, alpha, mode, core, api);
api->createFilter(in, out, mode, init_filter, get_frame, free_filter,
fmSerial, 0, d, core);
} catch (std::string& e) {
auto msg = std::string(mode) + ": " + e;
api->setError(out, msg.c_str());
}
}
extern "C" __declspec(dllexport) void VS_CC
VapourSynthPluginInit(VSConfigPlugin conf, VSRegisterFunction reg, VSPlugin* p)
{
conf("chikuzen.does.not.have.his.own.domain.avsr", "avsr",
"AviSynth Script Reader for VapourSynth v" VSAVSREADER_VERSION,
VAPOURSYNTH_API_VERSION, 1, p);
reg("Import", "script:data;bitdepth:int:opt;alpha:int:opt;", create_avsr,
"Import", p);
reg("Eval", "lines:data;bitdepth:int:opt;alpha:int:opt;", create_avsr,
"Eval", p);
}