Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 26th June 2014, 18:46   #1  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,308
need some help with code

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.

Code:
#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";
}
Wilbert is offline   Reply With Quote
Old 26th June 2014, 20:10   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
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.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 26th June 2014, 20:40   #3  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,308
Quote:
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.

Quote:
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.
Wilbert is offline   Reply With Quote
Old 26th June 2014, 21:01   #4  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
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.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 19:42.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.