Log in

View Full Version : need some help with code


Wilbert
26th June 2014, 18:46
Could someone tell me why the code below doesn't work (yes, it's just a test plugin)?
It should take an RGB clip and create a white Y8 clip with the same properties out of it.

The problem is, it doesn't. It leaves the 67%/75% (depending whether you feed it with RGB24/RGB32) upper lines black. I don't understand what is happening or how i should correct it.


#include <windows.h>
#include "avisynth.h"

class Test : public GenericVideoFilter {
VideoInfo vi_luma;
public:
Test(PClip _child, IScriptEnvironment* env);
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
};

Test::Test(PClip _child, IScriptEnvironment* env) :
GenericVideoFilter(_child) {

if (!vi.IsRGB()) {
env->ThrowError("Test: RGB data only!");
}

memset(&vi_luma, 0, sizeof(VideoInfo));
vi_luma = vi;
vi_luma.pixel_type = VideoInfo::CS_Y8;
}

PVideoFrame __stdcall Test::GetFrame(int n, IScriptEnvironment* env) {

PVideoFrame src = child->GetFrame(n, env);
PVideoFrame src_luma = env->NewVideoFrame(vi_luma);

int h,w;
unsigned char* srcp_luma = src_luma->GetWritePtr();
int src_luma_pitch = src_luma->GetPitch();
int src_luma_width = src_luma->GetRowSize();
int src_luma_height = src_luma->GetHeight();

for (h=0; h<src_luma_height; h++) {
for (w=0; w<src_luma_width; w++) {
srcp_luma[w] = 255;
}
srcp_luma += src_luma_pitch;
}

return src_luma;
}

AVSValue __cdecl Create_Test(AVSValue args, void* user_data, IScriptEnvironment* env) {
return new Test(args[0].AsClip(), env);
}

const AVS_Linkage *AVS_linkage = 0;

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit3(IScriptEnvironment* env, const AVS_Linkage* const vectors) {
AVS_linkage = vectors;
env->AddFunction("Test", "c", Create_Test, 0);
return "Test plugin";
}

Gavino
26th June 2014, 20:10
You shouldn't be using a separate variable vi_luma.
Just assign to vi.pixel_type.
Otherwise you will need to provide your own version of GetVideoInfo() - which you haven't done, so Avisynth thinks the output clip is the same type as the input.

Wilbert
26th June 2014, 20:40
You shouldn't be using a separate variable vi_luma.
Just assign to vi.pixel_type.
I know you can do that, but I need the input clip for later processing.

Otherwise you will need to provide your own version of GetVideoInfo() - which you haven't done, so Avisynth thinks the output clip is the same type as the input.
Mm, so i need to implement it by adding the following as public function?

const VideoInfo& __stdcall GetVideoInfo() { return vi_luma; }

Ok, thx for the input.

Gavino
26th June 2014, 21:01
An alternative to implementing your own GetVideoInfo() would be to save the input vi in a separate variable before changing the pixel_type, allowing access to it later.