Skip to content

Commit

Permalink
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 c6b5c41 commit 8c55063
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 43 deletions.
6 changes: 5 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

REQUIREMENTS:

Avisyth2.6.0 / Avisynth+r1579 or later
Avisyth2.6.0 / Avisynth+r2005 or later
Windows Vista sp2 or later
Microsoft Visual C++ 2015 Redistributable Packages

Expand Down Expand Up @@ -195,6 +195,10 @@ NOTE:

CHANGE LIST:

v0.1.1 - (2016-07-05)
+ Update avisynth.h to Avisynth+MT r2005
+ CreateMM: allocate temporal buffer at constructor unless the enviroment is not avs+MT.


v0.1 - (2016-05-25)
+ Use buffer pool on avs+ MT.
Expand Down
92 changes: 54 additions & 38 deletions src/CreateMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,42 @@ combine_masks_simd(uint8_t* dstp, const uint8_t* sqp, const uint8_t* shp,
}


AndBuff::AndBuff(int width, int height, size_t align, bool is_plus, ise_t* e) :
pitch((width + 2 + align - 1) & ~(align - 1)), env(e), isPlus(is_plus)
{
size_t size = pitch * (height * 2 + 1);
if (isPlus) {
orig = static_cast<IScriptEnvironment2*>(
env)->Allocate(size, align, AVS_POOLED_ALLOC);
} else {
orig = _mm_malloc(size, align);
}
am0 = reinterpret_cast<uint8_t*>(orig) + pitch;
am1 = am0 + pitch * height;
}

AndBuff::~AndBuff()
{
if (isPlus) {
static_cast<IScriptEnvironment2*>(env)->Free(orig);
} else {
_mm_free(orig);
}
orig = nullptr;
}


CreateMM::CreateMM(PClip mm1, PClip mm2, int _cstr, arch_t arch, bool ip) :
GVFmod(mm1, arch), mmask2(mm2), cstr(_cstr), simd(arch != NO_SIMD),
isPlus(ip)
isPlus(ip), abuff(nullptr)
{
vi.height /= 2;

if (!isPlus) {
abuff = new AndBuff(vi.width, vi.height, align, false, nullptr);
validate(!abuff, "failed to allocate buffer.");
}

switch (arch) {
#if defined(__AVX2__)
case USE_AVX2:
Expand All @@ -197,37 +227,13 @@ CreateMM::CreateMM(PClip mm1, PClip mm2, int _cstr, arch_t arch, bool ip) :
}


struct AndBuff {
ise_t* env;
bool isPlus;
void* orig;
uint8_t* am0;
uint8_t* am1;
const int pitch;

AndBuff(int width, int height, size_t align, bool is_plus, ise_t* e) :
pitch((width + 2 + align - 1) & ~(align - 1)), env(e), isPlus(is_plus)
{
size_t size = pitch * (height * 2 + 1);
if (isPlus) {
orig = static_cast<IScriptEnvironment2*>(
env)->Allocate(size, align, AVS_POOLED_ALLOC);
} else {
orig = _mm_malloc(size, align);
}
am0 = reinterpret_cast<uint8_t*>(orig) + pitch;
am1 = am0 + pitch * height;
}
~AndBuff()
{
if (isPlus) {
static_cast<IScriptEnvironment2*>(env)->Free(orig);
} else {
_mm_free(orig);
}
orig = nullptr;
CreateMM::~CreateMM()
{
if (!isPlus) {
delete abuff;
}
};
}



PVideoFrame __stdcall CreateMM::GetFrame(int n, ise_t* env)
Expand All @@ -237,11 +243,17 @@ PVideoFrame __stdcall CreateMM::GetFrame(int n, ise_t* env)
auto src0 = child->GetFrame(n, env);
auto dst = env->NewVideoFrame(vi, align);

auto buff = AndBuff(vi.width, vi.height, align, isPlus, env);

if (!buff.orig) {
env->ThrowError("TMM: failed to allocate AndBuff.");
uint8_t *am0, *am1;
int bpitch;
AndBuff* b = abuff;
if (isPlus) {
b = new AndBuff(vi.width, vi.height, align, true, env);
if (!b || !b->orig) {
env->ThrowError("TMM: failed to allocate AndBuff.");
}
}
am0 = b->am0; am1 = b->am1;
bpitch = b->pitch;

for (int p = 0; p < numPlanes; ++p) {
const int plane = planes[p];
Expand All @@ -251,15 +263,19 @@ PVideoFrame __stdcall CreateMM::GetFrame(int n, ise_t* env)
uint8_t* dstp = dst->GetWritePtr(plane);
const int dpitch = dst->GetPitch(plane);

and_masks(buff.am0, buff.am1, src0->GetReadPtr(plane),
and_masks(am0, am1, src0->GetReadPtr(plane),
src1->GetReadPtr(plane), src2->GetReadPtr(plane),
buff.pitch, src0->GetPitch(plane), src1->GetPitch(plane),
bpitch, src0->GetPitch(plane), src1->GetPitch(plane),
src2->GetPitch(plane), width, height);

combine_masks(dstp, buff.am0, buff.am1, dpitch, buff.pitch, width,
combine_masks(dstp, am0, am1, dpitch, bpitch, width,
height, cstr);
}

if (isPlus) {
delete b;
}

return dst;
}

Expand Down
15 changes: 13 additions & 2 deletions src/TMM2.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <avisynth.h>


#define TMM2_VERSION "0.1"
#define TMM2_VERSION "0.1.1"



Expand Down Expand Up @@ -102,12 +102,23 @@ class MotionMask : public GVFmod {
};


struct AndBuff {
ise_t* env;
bool isPlus;
void* orig;
uint8_t* am0;
uint8_t* am1;
const int pitch;
AndBuff(int width, int height, size_t align, bool is_plus, ise_t* e);
~AndBuff();
};

class CreateMM : public GVFmod {
PClip mmask2;
const int cstr;
const bool simd;
const bool isPlus;
AndBuff* abuff;

void(__stdcall *and_masks)(
uint8_t* dstp0, uint8_t* dstp1, const uint8_t* srcp0,
Expand All @@ -122,7 +133,7 @@ class CreateMM : public GVFmod {

public:
CreateMM(PClip mm1, PClip mm2, int cstr, arch_t arch, bool is_avsplus);
~CreateMM() {}
~CreateMM();
PVideoFrame __stdcall GetFrame(int n, ise_t* env);
};

Expand Down
5 changes: 3 additions & 2 deletions vs2015/TMM2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<StringPooling>true</StringPooling>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<BufferSecurityCheck>true</BufferSecurityCheck>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
Expand All @@ -127,7 +128,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<StringPooling>true</StringPooling>
</ClCompile>
Expand Down

0 comments on commit 8c55063

Please sign in to comment.