gyth
24th May 2012, 22:56
I'm working on a plugin and it seems to be working.
I was wondering if this was an ok way to resize the frame using the C plugin.
Am I was releasing everything I need to?
When does/should frame2 get released?
#include "../avisynth_c.h"
#include <stdlib.h>
#include <string.h>
//
// ng_smush
//
AVS_VideoFrame * AVSC_CC smush_get_frame (AVS_FilterInfo * p, int n)
{
AVS_VideoFrame *frame, *frame2;
int pitch, width, height;
frame = avs_get_frame(p->child, n);
pitch = avs_get_pitch(frame);
height = avs_get_height(frame);
width = p->vi.width;
frame2 = avs_subframe(p->env, frame, 0, pitch, 4 * width, height);
avs_release_video_frame(frame);
return frame2;
}
int ng_shift(AVS_FilterInfo * p){
AVS_VideoFrame *frame;
int pitch, width, height, accum, x, y, shift;
const BYTE * data;
frame = avs_get_frame(p->child, 0);
pitch = avs_get_pitch(frame);
height = avs_get_height(frame);
width = p->vi.width;
data = avs_get_read_ptr(frame);
shift = 0;
for (x = width-1; x >= width/2; x--) {
accum = 0;
for (y = 0; y != height; y++) {
accum |= data[4*x + 1 + pitch*y];
}
if (0 == accum) {
shift++;
} else {
break;
}
}
avs_release_video_frame(frame);
return shift;
}
AVS_Value AVSC_CC ng_smush (AVS_ScriptEnvironment * env,
AVS_Value args, void * dg)
{
AVS_Value v;
AVS_FilterInfo * fi;
AVS_Clip * new_clip = avs_new_c_filter(env, &fi, avs_array_elt(args, 0), 1);
if (avs_is_rgb32(&fi->vi)) {
fi->vi.width -= ng_shift(fi);
fi->get_frame = smush_get_frame;
v = avs_new_value_clip(new_clip);
} else {
v = avs_new_value_error("Video Must be RGB32!");
}
avs_release_clip(new_clip);
return v;
}
//
//
//
const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment * env)
{
avs_add_function(env, "ng_smush", "c", ng_smush, 0);
return "http://www.youtube.com/user/nanogyth";
}
I was wondering if this was an ok way to resize the frame using the C plugin.
Am I was releasing everything I need to?
When does/should frame2 get released?
#include "../avisynth_c.h"
#include <stdlib.h>
#include <string.h>
//
// ng_smush
//
AVS_VideoFrame * AVSC_CC smush_get_frame (AVS_FilterInfo * p, int n)
{
AVS_VideoFrame *frame, *frame2;
int pitch, width, height;
frame = avs_get_frame(p->child, n);
pitch = avs_get_pitch(frame);
height = avs_get_height(frame);
width = p->vi.width;
frame2 = avs_subframe(p->env, frame, 0, pitch, 4 * width, height);
avs_release_video_frame(frame);
return frame2;
}
int ng_shift(AVS_FilterInfo * p){
AVS_VideoFrame *frame;
int pitch, width, height, accum, x, y, shift;
const BYTE * data;
frame = avs_get_frame(p->child, 0);
pitch = avs_get_pitch(frame);
height = avs_get_height(frame);
width = p->vi.width;
data = avs_get_read_ptr(frame);
shift = 0;
for (x = width-1; x >= width/2; x--) {
accum = 0;
for (y = 0; y != height; y++) {
accum |= data[4*x + 1 + pitch*y];
}
if (0 == accum) {
shift++;
} else {
break;
}
}
avs_release_video_frame(frame);
return shift;
}
AVS_Value AVSC_CC ng_smush (AVS_ScriptEnvironment * env,
AVS_Value args, void * dg)
{
AVS_Value v;
AVS_FilterInfo * fi;
AVS_Clip * new_clip = avs_new_c_filter(env, &fi, avs_array_elt(args, 0), 1);
if (avs_is_rgb32(&fi->vi)) {
fi->vi.width -= ng_shift(fi);
fi->get_frame = smush_get_frame;
v = avs_new_value_clip(new_clip);
} else {
v = avs_new_value_error("Video Must be RGB32!");
}
avs_release_clip(new_clip);
return v;
}
//
//
//
const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment * env)
{
avs_add_function(env, "ng_smush", "c", ng_smush, 0);
return "http://www.youtube.com/user/nanogyth";
}