Skip to content

Commit

Permalink
avisynth: update avisynth.h to Avisynth+MT r2005.
Browse files Browse the repository at this point in the history
also, some cosmetics.
  • Loading branch information
chikuzen committed Jul 5, 2016
1 parent 7cdc1f7 commit 3888148
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 33 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion avisynth/readme.txt
Expand Up @@ -155,7 +155,7 @@ usage:

reqirement:

- Avisynth2.60 or later / Avisynth+ r1578 or greater.
- Avisynth2.60 or later / Avisynth+ r2005 or greater.
- Windows Vista sp2 / 7 sp1 / 8.1 / 10.
- Microsoft Visual C++ 2015 Redistributable Package
- SSE2 capable CPU
Expand Down
68 changes: 40 additions & 28 deletions avisynth/src/CombMask.cpp
Expand Up @@ -342,9 +342,27 @@ expand_mask_simd(uint8_t* dstp, uint8_t* srcp, const int dpitch,
}


Buffer::Buffer(size_t pitch, int height, int hsize, size_t align, bool ip,
ise_t* e) :
env(e), isPlus(ip)
{
size_t size = pitch * height * hsize + align;
orig = alloc_buffer(size, align, isPlus, env);
buffp = reinterpret_cast<uint8_t*>(orig) + align;
}


Buffer::~Buffer()
{
free_buffer(orig, isPlus, env);
}



CombMask::CombMask(PClip c, int cth, int mth, bool ch, arch_t arch, bool e,
int metric, bool plus) :
GVFmod(c, ch, arch, plus), cthresh(cth), mthresh(mth), expand(e)
GVFmod(c, ch, arch, plus), cthresh(cth), mthresh(mth), expand(e),
buff(nullptr)
{
validate(!vi.IsPlanar(), "planar format only.");
validate(metric != 0 && metric != 1, "metric must be set to 0 or 1.");
Expand All @@ -363,6 +381,7 @@ CombMask::CombMask(PClip c, int cth, int mth, bool ch, arch_t arch, bool e,
buffPitch += 2;
}
buffPitch &= (~(align - 1));
needBuff = mthresh > 0 || expand;

switch (arch) {
#if defined(__AVX2__)
Expand Down Expand Up @@ -391,33 +410,24 @@ CombMask::CombMask(PClip c, int cth, int mth, bool ch, arch_t arch, bool e,
if (mthresh > 0 && child->SetCacheHints(CACHE_GET_WINDOW, 0) < 3) {
child->SetCacheHints(CACHE_WINDOW, 3);
}
}


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

class Buffer {
ise_t* env;
bool isPlus;
void* orig;
public:
uint8_t* buffp;

Buffer(size_t pitch, int height, int hsize, size_t align, bool ip, ise_t* e) :
env(e), isPlus(ip)
{
size_t size = pitch * height * hsize + align;
orig = alloc_buffer(size, align, isPlus, env);
buffp = reinterpret_cast<uint8_t*>(orig) + align;
}
}

~Buffer()
{
free_buffer(orig, isPlus, env);

CombMask::~CombMask()
{
if (!isPlus && needBuff) {
delete buff;
}
};
}


PVideoFrame __stdcall CombMask::GetFrame(int n, IScriptEnvironment* env)
PVideoFrame __stdcall CombMask::GetFrame(int n, ise_t* env)
{
static const int planes[] = { PLANAR_Y, PLANAR_U, PLANAR_V };

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

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

Buffer* b = nullptr;
uint8_t *buffp = nullptr, *tmpp = nullptr;
if (mthresh > 0 || expand) {
b = new Buffer(buffPitch, vi.height, mthresh > 0 ? 2 : 1, align,
isPlus, env);
Buffer* b = buff;
uint8_t *buffp, *tmpp;
if (needBuff) {
if (isPlus) {
b = new Buffer(buffPitch, vi.height, mthresh > 0 ? 2 : 1, align,
isPlus, env);
}
buffp = b->buffp;
tmpp = buffp + vi.height * buffPitch;
}
Expand All @@ -447,7 +459,7 @@ PVideoFrame __stdcall CombMask::GetFrame(int n, IScriptEnvironment* env)
const int width = src->GetRowSize(plane);
const int height = src->GetHeight(plane);

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

if (b != nullptr) {
if (isPlus && needBuff) {
delete b;
}

Expand Down
18 changes: 16 additions & 2 deletions avisynth/src/CombMask.h
Expand Up @@ -10,7 +10,7 @@
#include <windows.h>
#include <avisynth.h>

#define CMASK_VERSION "1.0.0"
#define CMASK_VERSION "1.1.0"


typedef IScriptEnvironment ise_t;
Expand All @@ -23,11 +23,23 @@ enum arch_t {
};


class Buffer {
ise_t* env;
bool isPlus;
void* orig;
public:
uint8_t* buffp;
Buffer(size_t pitch, int height, int hsize, size_t align, bool ip, ise_t* e);
~Buffer();
};


class GVFmod : public GenericVideoFilter {
protected:
bool isPlus;
int numPlanes;
size_t align;

GVFmod(PClip c, bool chroma, arch_t a, bool ip) :
GenericVideoFilter(c), align(a == USE_AVX2 ? 32 : 16), isPlus(ip)
{
Expand All @@ -40,7 +52,9 @@ class CombMask : public GVFmod {
int cthresh;
int mthresh;
bool expand;
bool needBuff;
size_t buffPitch;
Buffer* buff;

void (__stdcall *writeCombMask)(
uint8_t* dstp, const uint8_t* srcp, const int dpitch, const int cpitch,
Expand All @@ -62,7 +76,7 @@ class CombMask : public GVFmod {
public:
CombMask(PClip c, int cth, int mth, bool chroma, arch_t arch, bool expand,
int metric, bool is_avsplus);
~CombMask() {}
~CombMask();
PVideoFrame __stdcall GetFrame(int n, ise_t* env);
};

Expand Down
18 changes: 16 additions & 2 deletions avisynth/vs2015/CombMask.vcxproj
Expand Up @@ -43,9 +43,11 @@
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -100,7 +102,7 @@
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<StringPooling>true</StringPooling>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
<Link>
Expand All @@ -111,6 +113,18 @@
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<AdditionalIncludeDirectories>C:\my_projects\AviSynthPlus\avs_core\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<StringPooling>true</StringPooling>
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\src\CombMask.cpp" />
<ClCompile Include="..\src\cpu_check.cpp" />
Expand Down

0 comments on commit 3888148

Please sign in to comment.