-
-
Save Reel-Deal/8504a294547654734d08b75534674587 to your computer and use it in GitHub Desktop.
Fingerprint AviSynth Filter (2013-05-11)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <windows.h> | |
#define AVS_LINKAGE_DLLIMPORT | |
#include "avisynth.h" | |
#pragma comment(lib,"avisynth") | |
class fingerprint : public GenericVideoFilter { | |
unsigned int* buffer; | |
VideoInfo inf; | |
public: | |
fingerprint(PClip _child, IScriptEnvironment* env); | |
~fingerprint(); | |
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); | |
}; | |
fingerprint::fingerprint(PClip _child, IScriptEnvironment* env) : GenericVideoFilter(_child) { | |
inf=_child->GetVideoInfo(); | |
if (!inf.IsRGB32()) env->ThrowError("Input must be RGB32"); | |
vi.width=inf.num_frames; | |
buffer=(unsigned int*)malloc((vi.height*inf.num_frames)<<2); | |
} | |
fingerprint::~fingerprint() { | |
free(buffer); | |
} | |
PVideoFrame __stdcall fingerprint::GetFrame(int n, IScriptEnvironment* env) { | |
int x,y; | |
int r,g,b; | |
int pitch; | |
double div; | |
PVideoFrame src=child->GetFrame(n, env); | |
div=1.0/(src->GetRowSize()>>2); | |
unsigned char* srcp=(unsigned char*)(src->GetReadPtr()); | |
for (y=0; y<src->GetHeight(); y++) { | |
r=g=b=0; | |
for (x=0; x<src->GetRowSize()>>2; x++) { | |
r+=*srcp++; | |
g+=*srcp++; | |
b+=*srcp++; | |
srcp++; | |
} | |
srcp+=src->GetPitch()-src->GetRowSize(); | |
r=r*div; | |
g=g*div; | |
b=b*div; | |
buffer[vi.num_frames*y+n]=b<<16|g<<8|r; | |
} | |
PVideoFrame dst=env->NewVideoFrame(vi); | |
unsigned int* dstp=(unsigned int*)(dst->GetWritePtr()); | |
unsigned int* bufp=buffer; | |
for (y=0; y<dst->GetHeight(); y++) { | |
for (x=0; x<dst->GetRowSize()>>2; x++) { | |
if (x<=n) dstp[x]=bufp[x]; else dstp[x]=0; | |
} | |
dstp+=(dst->GetPitch()>>2); | |
bufp+=inf.num_frames; | |
} | |
return dst; | |
} | |
AVSValue __cdecl Create_simpleselect(AVSValue args, void* user_data, IScriptEnvironment* env) { | |
return new fingerprint(args[0].AsClip(),env); | |
} | |
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) { | |
env->AddFunction("fingerprint", "c", Create_simpleselect, 0); | |
return "fingerprint"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment