E-Male
20th January 2005, 23:59
i wrote a plug-in that creates gradient masks
here you can find it
http://forum.doom9.org/showthread.php?s=&threadid=87791&perpage=20&pagenumber=6
the problem is that c has no effect on odd frames in mode 1, 2 & 3, even frames are fine
i'll post you the part of the code that should be the problem [=no effect in odd frames] (and i got no idea why!!)
as well as the whole code
switch (d) {
case 1:
break;
case 2:
a=(src_width-1)-a;
break;
case 3:
a=(src_width-1)-a;
b=(src_height-1)-b;
break;
case 4:
b=(src_height-1)-b;
break;
}
#include "stdafx.h"
#include "avisynth.h"
class maskmaker : public GenericVideoFilter {
int m, d;
float a, b, c;
public:
maskmaker(PClip _child, int _m, int _d, float _a, float _b, float _c, IScriptEnvironment* env);
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
};
maskmaker::maskmaker(PClip _child, int _m, int _d, float _a, float _b, float _c, IScriptEnvironment* env) :
GenericVideoFilter(_child), m(_m), d(_d), a(_a), b(_b), c(_c) {
if (m<1)
env->ThrowError("m<1");
if (m>4)
env->ThrowError("m>4");
if (d<1)
env->ThrowError("d<1");
if (d>4)
env->ThrowError("d>4");
}
PVideoFrame __stdcall maskmaker::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();
float res;
if (m!=4)
switch (d) {
case 1:
break;
case 2:
a=(src_width-1)-a;
break;
case 3:
a=(src_width-1)-a;
b=(src_height-1)-b;
break;
case 4:
b=(src_height-1)-b;
break;
}
for (int h=0; h < src_height;h++) {
for (int w = 0; w < src_width; w++)
{
switch (m) {
case 1:
res = ((w-a)*(w-a))+((h-b)*(h-b));
res/=c;
break;
case 2:
if(abs(w-a)>abs(h-b))
res=abs(w-a);
else
res=abs(h-b);
res/=c;
break;
case 3:
res = abs(w-a)+abs(h-b);
res/=c;
break;
case 4:
if ( d==4)
res = abs(w-a);
if ( d==2)
res = abs(w-((src_width-1)-a));
if ( d==1)
res = abs(h-a);
if ( d==3)
res = abs(h-((src_height-1)-a));
res/=b;
break;
}
if (res < 0)
res = 0;
if (res > 255)
res = 255;
*(dstp + w) = res;
}
srcp = srcp + src_pitch;
dstp = dstp + dst_pitch;
}
const int dst_pitchUV = dst->GetPitch(PLANAR_U);
const int dst_widthUV = dst->GetRowSize(PLANAR_U);
const int dst_heightUV = dst->GetHeight(PLANAR_U);
const int src_pitchUV = src->GetPitch(PLANAR_U);
const int src_widthUV = src->GetRowSize(PLANAR_U);
const int src_heightUV = src->GetHeight(PLANAR_U);
srcp = src->GetReadPtr(PLANAR_U);
dstp = dst->GetWritePtr(PLANAR_U);
for (int h=0; h < src_heightUV;h++) {
for (int w = 0; w < src_widthUV; w++)
{
*(dstp + w) = 128;
}
srcp = srcp + src_pitchUV;
dstp = dstp + dst_pitchUV;
}
srcp = src->GetReadPtr(PLANAR_V);
dstp = dst->GetWritePtr(PLANAR_V);
for (int h=0; h < src_heightUV;h++) {
for (int w = 0; w < src_widthUV; w++)
{
*(dstp + w) = 128;
}
srcp = srcp + src_pitchUV;
dstp = dstp + dst_pitchUV;
}
return dst;
}
AVSValue __cdecl Create_maskmaker(AVSValue args, void* user_data, IScriptEnvironment* env) {
return new maskmaker(args[0].AsClip(),args[1].AsInt(1),args[2].AsInt(1),args[3].AsFloat(1),args[4].AsFloat(1),args[5].AsFloat(1),env);
}
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
env->AddFunction("maskmaker", "c[m]i[d]i[a]f[b]f[c]f", Create_maskmaker, 0);
return "maskmaker";
}
here you can find it
http://forum.doom9.org/showthread.php?s=&threadid=87791&perpage=20&pagenumber=6
the problem is that c has no effect on odd frames in mode 1, 2 & 3, even frames are fine
i'll post you the part of the code that should be the problem [=no effect in odd frames] (and i got no idea why!!)
as well as the whole code
switch (d) {
case 1:
break;
case 2:
a=(src_width-1)-a;
break;
case 3:
a=(src_width-1)-a;
b=(src_height-1)-b;
break;
case 4:
b=(src_height-1)-b;
break;
}
#include "stdafx.h"
#include "avisynth.h"
class maskmaker : public GenericVideoFilter {
int m, d;
float a, b, c;
public:
maskmaker(PClip _child, int _m, int _d, float _a, float _b, float _c, IScriptEnvironment* env);
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
};
maskmaker::maskmaker(PClip _child, int _m, int _d, float _a, float _b, float _c, IScriptEnvironment* env) :
GenericVideoFilter(_child), m(_m), d(_d), a(_a), b(_b), c(_c) {
if (m<1)
env->ThrowError("m<1");
if (m>4)
env->ThrowError("m>4");
if (d<1)
env->ThrowError("d<1");
if (d>4)
env->ThrowError("d>4");
}
PVideoFrame __stdcall maskmaker::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();
float res;
if (m!=4)
switch (d) {
case 1:
break;
case 2:
a=(src_width-1)-a;
break;
case 3:
a=(src_width-1)-a;
b=(src_height-1)-b;
break;
case 4:
b=(src_height-1)-b;
break;
}
for (int h=0; h < src_height;h++) {
for (int w = 0; w < src_width; w++)
{
switch (m) {
case 1:
res = ((w-a)*(w-a))+((h-b)*(h-b));
res/=c;
break;
case 2:
if(abs(w-a)>abs(h-b))
res=abs(w-a);
else
res=abs(h-b);
res/=c;
break;
case 3:
res = abs(w-a)+abs(h-b);
res/=c;
break;
case 4:
if ( d==4)
res = abs(w-a);
if ( d==2)
res = abs(w-((src_width-1)-a));
if ( d==1)
res = abs(h-a);
if ( d==3)
res = abs(h-((src_height-1)-a));
res/=b;
break;
}
if (res < 0)
res = 0;
if (res > 255)
res = 255;
*(dstp + w) = res;
}
srcp = srcp + src_pitch;
dstp = dstp + dst_pitch;
}
const int dst_pitchUV = dst->GetPitch(PLANAR_U);
const int dst_widthUV = dst->GetRowSize(PLANAR_U);
const int dst_heightUV = dst->GetHeight(PLANAR_U);
const int src_pitchUV = src->GetPitch(PLANAR_U);
const int src_widthUV = src->GetRowSize(PLANAR_U);
const int src_heightUV = src->GetHeight(PLANAR_U);
srcp = src->GetReadPtr(PLANAR_U);
dstp = dst->GetWritePtr(PLANAR_U);
for (int h=0; h < src_heightUV;h++) {
for (int w = 0; w < src_widthUV; w++)
{
*(dstp + w) = 128;
}
srcp = srcp + src_pitchUV;
dstp = dstp + dst_pitchUV;
}
srcp = src->GetReadPtr(PLANAR_V);
dstp = dst->GetWritePtr(PLANAR_V);
for (int h=0; h < src_heightUV;h++) {
for (int w = 0; w < src_widthUV; w++)
{
*(dstp + w) = 128;
}
srcp = srcp + src_pitchUV;
dstp = dstp + dst_pitchUV;
}
return dst;
}
AVSValue __cdecl Create_maskmaker(AVSValue args, void* user_data, IScriptEnvironment* env) {
return new maskmaker(args[0].AsClip(),args[1].AsInt(1),args[2].AsInt(1),args[3].AsFloat(1),args[4].AsFloat(1),args[5].AsFloat(1),env);
}
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
env->AddFunction("maskmaker", "c[m]i[d]i[a]f[b]f[c]f", Create_maskmaker, 0);
return "maskmaker";
}