View Single Post
Old 11th March 2003, 00:12   #9  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
Minor plea for change: Move colorspace checks to the constructor:
Code:
class SimpleSample : public GenericVideoFilter {

public:
	SimpleSample(PClip _child) : GenericVideoFilter(_child);
}

	PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
};


SimpleSample(PClip _child) : GenericVideoFilter(_child) {
	if (vi.IsPlanar()) // is input not planar
		env->ThrowError("SimpleSample: input to filter must be in YUY2 or RGB");
}
(Also changed YV12 to planar, so that possible future planar formats also will fail). You should perhaps also do a planar version

RGB formats do actually work with the code you've made!

The planar implementation is actually quite easy - you can remove the colorspace check, and do:
Code:
[...]
	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;
	
	//Copy src to dst
	srcp = src->GetReadPtr();
	dstp = dst->GetWritePtr();
	
	for (h=0; h < src_height;h++) {
		for (w = 0; w < src_width; w++)
			*(dstp + w) = *(srcp + w);
		srcp = srcp + src_pitch;
		dstp = dstp + dst_pitch;
	}
	// end copy src to dst

	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);

	//Copy U plane src to dst
	srcp = src->GetReadPtr(PLANAR_U);
	dstp = dst->GetWritePtr(PLANAR_U);

	for (h=0; h < src_heightUV;h++) {
		for (w = 0; w < src_widthUV; w++)
			*(dstp + w) = *(srcp + w);
		srcp = srcp + src_pitchUV;
		dstp = dstp + dst_pitchUV;
	}
	// end copy src to dst

	//Copy V plane src to dst
	srcp = src->GetReadPtr(PLANAR_V);
	dstp = dst->GetWritePtr(PLANAR_V);

	for (h=0; h < src_heightUV;h++) {
		for (w = 0; w < src_widthUV; w++)
			*(dstp + w) = *(srcp + w);
		srcp = srcp + src_pitchUV;
		dstp = dstp + dst_pitchUV;
	}
	// end copy src to dst
[...]
As GetRowSize(PLANAR_U) will return 0 on non-planar images, nothing will be done in these loops, if the image is interleaved (RGB or YUY2).
__________________
Regards, sh0dan // VoxPod

Last edited by sh0dan; 11th March 2003 at 00:22.
sh0dan is offline   Reply With Quote