PDA

View Full Version : can someone try this code for me


E-Male
24th May 2003, 18:37
since i got a problem compiling filters:
see: http://forum.doom9.org/showthread.php?s=&threadid=54077
could someone test this code for me
it should turn a movie into just black&white (for smaller endcredits)

------------------------------------------------
#include "windows.h"
#include "avisynth.h"
class blackwhite : public GenericVideoFilter {
int edge;
public:
blackwhite(PClip _child, int _edge, IScriptEnvironment* env);
~blackwhite();
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
};
blackwhite::blackwhite(PClip _child, int _edge, IScriptEnvironment* env) :
GenericVideoFilter(_child), edge(_edge) {
}
blackwhite::~blackwhite() {
}
PVideoFrame __stdcall blackwhite::GetFrame(int n, IScriptEnvironment* env) {
PVideoFrame src = child->GetFrame(n, env);
PVideoFrame dst = env->NewVideoFrame(vi);
const unsigned char* srcp = src->GetReadPtr();
unsigned char* dstp = dst->GetWritePtr();
const int dst_pitch = dst->GetPitch();
const int dst_width = dst->GetRowSize();
const int dst_height = dst->GetHeight();
const int src_pitch = src->GetPitch();
const int src_width = src->GetRowSize();
const int src_height = src->GetHeight();
int w, h;
for (h=0; h < src_height;h++) {
for (w = 0; w < src_width; w+=2) {
*((unsigned int *)dstp + w) = 128;
if (*((unsigned int *)srcp + w+1) > edge)
*((unsigned int *)dstp + w+1) = 235;
else
*((unsigned int *)dstp + w+1) = 16;
}
srcp = srcp + src_pitch;
dstp = dstp + dst_pitch;
}
return dst;
}
AVSValue __cdecl Create_blackwhite(AVSValue args, void* user_data, IScriptEnvironment* env) {
return new blackwhite(args[0].AsClip(),
args[1].AsInt(0),
env);
}
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
env->AddFunction("blackwhite", "c[EDGE]i", Create_blackwhite, 0);
return "`blackwhite' blackwhite plugin";
}
------------------------------------------------

i hope someone can compile it
thx in advance
e-male

ARDA
24th May 2003, 18:53
You have already in avisynth greyscale()
it's already done

Arda

Guest
24th May 2003, 19:06
He wants to threshold it, not make a grayscale. I suppose you could do this with Levels().

ARDA
24th May 2003, 19:11
Sorry I've misunderstood

Arda

Si
24th May 2003, 19:23
It compiles but gives a greenish display and then crashes :(

Could be my setup but your casting the pointers to unsigned ints looks a bit suspicious to me when you are only stepping 2 bytes at a time along the horizontal axis (but what do I know ;) )

Whats your basic algorithim description?

regards
Simon

Si
24th May 2003, 19:36
for (w = 0; w < src_width; w+=2) {
*((unsigned char *)dstp + w + 1) = 128;
if (*((unsigned char *)srcp + w) > edge)
*((unsigned char *)dstp + w) = 235;
else
*((unsigned char *)dstp + w) = 16;
}

Seems to give a result (changing to char pointer instead of int and altering assumed byte order to Y1 U Y2 V.

Dll available here (http://www.geocities.com/siwalters_uk/blackwhite.zip) (right-click and save as)

regards
Simon

E-Male
24th May 2003, 20:31
thx
fixes the last warning, but still canīt compile, same error

tried the dll, but get an eror:
VirtualDub Error
LoadPlugin: "c:\...\blackwhite.dll" is not an Avisynth 1.0 plugin
(u:\....avs, line 1)

:((


cu
e-male

Guest
24th May 2003, 21:27
>extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2

The 2 there makes it an Avisynth 2 plugin. Remove the 2 if you are building 1.x plugins.

E-Male
24th May 2003, 21:52
thx
i was just editing sample code

still canīt compile, because of that "asserte" problem
could one of you please...

thx
e-male

p.s. or anyone got an idea how i can compile filters again???

Guest
25th May 2003, 00:22
Mail me the entire zipped up project.

E-Male
25th May 2003, 02:26
thx for all the help

here are my project files:
http://e-rels.dyndns.org/blackwhite.zip

Guest
25th May 2003, 07:23
Look at http://shelob.mordor.net/dgraft/misc/blackwhite.zip

It has two zips in it. One is built for Avisynth 2.5 and one for Avisynth 1.x.

E-Male
25th May 2003, 10:18
thx a lot
i could compile the 1.x code and it does what it should