Skip to content

Commit 3888148

Browse files
committed
avisynth: update avisynth.h to Avisynth+MT r2005.
also, some cosmetics.
1 parent 7cdc1f7 commit 3888148

File tree

5 files changed

+73
-33
lines changed

5 files changed

+73
-33
lines changed
File renamed without changes.

avisynth/readme.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ usage:
155155

156156
reqirement:
157157

158-
- Avisynth2.60 or later / Avisynth+ r1578 or greater.
158+
- Avisynth2.60 or later / Avisynth+ r2005 or greater.
159159
- Windows Vista sp2 / 7 sp1 / 8.1 / 10.
160160
- Microsoft Visual C++ 2015 Redistributable Package
161161
- SSE2 capable CPU

avisynth/src/CombMask.cpp

+40-28
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,27 @@ expand_mask_simd(uint8_t* dstp, uint8_t* srcp, const int dpitch,
342342
}
343343

344344

345+
Buffer::Buffer(size_t pitch, int height, int hsize, size_t align, bool ip,
346+
ise_t* e) :
347+
env(e), isPlus(ip)
348+
{
349+
size_t size = pitch * height * hsize + align;
350+
orig = alloc_buffer(size, align, isPlus, env);
351+
buffp = reinterpret_cast<uint8_t*>(orig) + align;
352+
}
353+
354+
355+
Buffer::~Buffer()
356+
{
357+
free_buffer(orig, isPlus, env);
358+
}
359+
360+
361+
345362
CombMask::CombMask(PClip c, int cth, int mth, bool ch, arch_t arch, bool e,
346363
int metric, bool plus) :
347-
GVFmod(c, ch, arch, plus), cthresh(cth), mthresh(mth), expand(e)
364+
GVFmod(c, ch, arch, plus), cthresh(cth), mthresh(mth), expand(e),
365+
buff(nullptr)
348366
{
349367
validate(!vi.IsPlanar(), "planar format only.");
350368
validate(metric != 0 && metric != 1, "metric must be set to 0 or 1.");
@@ -363,6 +381,7 @@ CombMask::CombMask(PClip c, int cth, int mth, bool ch, arch_t arch, bool e,
363381
buffPitch += 2;
364382
}
365383
buffPitch &= (~(align - 1));
384+
needBuff = mthresh > 0 || expand;
366385

367386
switch (arch) {
368387
#if defined(__AVX2__)
@@ -391,33 +410,24 @@ CombMask::CombMask(PClip c, int cth, int mth, bool ch, arch_t arch, bool e,
391410
if (mthresh > 0 && child->SetCacheHints(CACHE_GET_WINDOW, 0) < 3) {
392411
child->SetCacheHints(CACHE_WINDOW, 3);
393412
}
394-
}
395-
396413

414+
if (!isPlus && needBuff) {
415+
buff = new Buffer(buffPitch, vi.height, mthresh > 0 ? 2 : 1, align,
416+
false, nullptr);
397417

398-
class Buffer {
399-
ise_t* env;
400-
bool isPlus;
401-
void* orig;
402-
public:
403-
uint8_t* buffp;
404-
405-
Buffer(size_t pitch, int height, int hsize, size_t align, bool ip, ise_t* e) :
406-
env(e), isPlus(ip)
407-
{
408-
size_t size = pitch * height * hsize + align;
409-
orig = alloc_buffer(size, align, isPlus, env);
410-
buffp = reinterpret_cast<uint8_t*>(orig) + align;
411418
}
419+
}
412420

413-
~Buffer()
414-
{
415-
free_buffer(orig, isPlus, env);
421+
422+
CombMask::~CombMask()
423+
{
424+
if (!isPlus && needBuff) {
425+
delete buff;
416426
}
417-
};
427+
}
418428

419429

420-
PVideoFrame __stdcall CombMask::GetFrame(int n, IScriptEnvironment* env)
430+
PVideoFrame __stdcall CombMask::GetFrame(int n, ise_t* env)
421431
{
422432
static const int planes[] = { PLANAR_Y, PLANAR_U, PLANAR_V };
423433

@@ -428,11 +438,13 @@ PVideoFrame __stdcall CombMask::GetFrame(int n, IScriptEnvironment* env)
428438

429439
PVideoFrame dst = env->NewVideoFrame(vi, align);
430440

431-
Buffer* b = nullptr;
432-
uint8_t *buffp = nullptr, *tmpp = nullptr;
433-
if (mthresh > 0 || expand) {
434-
b = new Buffer(buffPitch, vi.height, mthresh > 0 ? 2 : 1, align,
435-
isPlus, env);
441+
Buffer* b = buff;
442+
uint8_t *buffp, *tmpp;
443+
if (needBuff) {
444+
if (isPlus) {
445+
b = new Buffer(buffPitch, vi.height, mthresh > 0 ? 2 : 1, align,
446+
isPlus, env);
447+
}
436448
buffp = b->buffp;
437449
tmpp = buffp + vi.height * buffPitch;
438450
}
@@ -447,7 +459,7 @@ PVideoFrame __stdcall CombMask::GetFrame(int n, IScriptEnvironment* env)
447459
const int width = src->GetRowSize(plane);
448460
const int height = src->GetHeight(plane);
449461

450-
if (b == nullptr) {
462+
if (!needBuff) {
451463
writeCombMask(dstp, srcp, dpitch, spitch, cthresh, width, height);
452464
continue;
453465
}
@@ -473,7 +485,7 @@ PVideoFrame __stdcall CombMask::GetFrame(int n, IScriptEnvironment* env)
473485
expandMask(dstp, buffp, dpitch, buffPitch, width, height);
474486
}
475487

476-
if (b != nullptr) {
488+
if (isPlus && needBuff) {
477489
delete b;
478490
}
479491

avisynth/src/CombMask.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <windows.h>
1111
#include <avisynth.h>
1212

13-
#define CMASK_VERSION "1.0.0"
13+
#define CMASK_VERSION "1.1.0"
1414

1515

1616
typedef IScriptEnvironment ise_t;
@@ -23,11 +23,23 @@ enum arch_t {
2323
};
2424

2525

26+
class Buffer {
27+
ise_t* env;
28+
bool isPlus;
29+
void* orig;
30+
public:
31+
uint8_t* buffp;
32+
Buffer(size_t pitch, int height, int hsize, size_t align, bool ip, ise_t* e);
33+
~Buffer();
34+
};
35+
36+
2637
class GVFmod : public GenericVideoFilter {
2738
protected:
2839
bool isPlus;
2940
int numPlanes;
3041
size_t align;
42+
3143
GVFmod(PClip c, bool chroma, arch_t a, bool ip) :
3244
GenericVideoFilter(c), align(a == USE_AVX2 ? 32 : 16), isPlus(ip)
3345
{
@@ -40,7 +52,9 @@ class CombMask : public GVFmod {
4052
int cthresh;
4153
int mthresh;
4254
bool expand;
55+
bool needBuff;
4356
size_t buffPitch;
57+
Buffer* buff;
4458

4559
void (__stdcall *writeCombMask)(
4660
uint8_t* dstp, const uint8_t* srcp, const int dpitch, const int cpitch,
@@ -62,7 +76,7 @@ class CombMask : public GVFmod {
6276
public:
6377
CombMask(PClip c, int cth, int mth, bool chroma, arch_t arch, bool expand,
6478
int metric, bool is_avsplus);
65-
~CombMask() {}
79+
~CombMask();
6680
PVideoFrame __stdcall GetFrame(int n, ise_t* env);
6781
};
6882

avisynth/vs2015/CombMask.vcxproj

+16-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
<PlatformToolset>v140</PlatformToolset>
4444
</PropertyGroup>
4545
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
46-
<ConfigurationType>Application</ConfigurationType>
46+
<ConfigurationType>DynamicLibrary</ConfigurationType>
4747
<UseDebugLibraries>false</UseDebugLibraries>
4848
<PlatformToolset>v140</PlatformToolset>
49+
<CharacterSet>MultiByte</CharacterSet>
50+
<WholeProgramOptimization>true</WholeProgramOptimization>
4951
</PropertyGroup>
5052
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
5153
<ImportGroup Label="ExtensionSettings">
@@ -100,7 +102,7 @@
100102
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
101103
<OmitFramePointers>true</OmitFramePointers>
102104
<StringPooling>true</StringPooling>
103-
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
105+
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
104106
<FloatingPointModel>Fast</FloatingPointModel>
105107
</ClCompile>
106108
<Link>
@@ -111,6 +113,18 @@
111113
<OptimizeReferences>true</OptimizeReferences>
112114
</Link>
113115
</ItemDefinitionGroup>
116+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
117+
<ClCompile>
118+
<AdditionalIncludeDirectories>C:\my_projects\AviSynthPlus\avs_core\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
119+
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
120+
<IntrinsicFunctions>true</IntrinsicFunctions>
121+
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
122+
<OmitFramePointers>true</OmitFramePointers>
123+
<StringPooling>true</StringPooling>
124+
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
125+
<FloatingPointModel>Fast</FloatingPointModel>
126+
</ClCompile>
127+
</ItemDefinitionGroup>
114128
<ItemGroup>
115129
<ClCompile Include="..\src\CombMask.cpp" />
116130
<ClCompile Include="..\src\cpu_check.cpp" />

0 commit comments

Comments
 (0)