/* Description: This plugin dynamically changes the frame aspect ratio. It works on one strip as input. Author: Andrew McCargar (andrew@outsideworld.org) Website: http://www.outsideworld.org/projects/blender/plugins.html Licensing: Public Domain Last Modified: Thus Dec 24 23:41:35 EST 2009 */ #include "math.h" #include "plugin.h" char name[24]= "Letterboxer"; /* structure for buttons, * butcode name default min max 0 */ VarStruct varstr[]= { LABEL, "Start values %", 0.0, 0.0, 0.0, "", NUM|FLO, "left ", 0.0, 0.0, 100.0, "Percent of frame to crop from the left", NUM|FLO, "right ", 0.0, 0.0, 100.0, "Percent of frame to crop from the right", NUM|FLO, "x offset ", 0.0, -100.0, 100.0, "Percent of horizontal offset", NUM|FLO, "top ", 0.0, 0.0, 100.0, "Percent of frame to crop from the top", NUM|FLO, "bottom ", 0.0, 0.0, 100.0, "Percent of frame to crop from the bottom", NUM|FLO, "y offset ", 0.0, -100.0, 100.0, "Percent of vertical offset", LABEL, "End values %", 0.0, 0.0, 0.0, "", NUM|FLO, "left ", 0.0, 0.0, 100.0, "Percent of frame to crop from the left", NUM|FLO, "right ", 0.0, 0.0, 100.0, "Percent of frame to crop from the right", NUM|FLO, "x offset ", 0.0, -100.0, 100.0, "Percent of horizontal offset", NUM|FLO, "top ", 0.0, 0.0, 100.0, "Percent of frame to crop from the top", NUM|FLO, "bottom ", 0.0, 0.0, 100.0, "Percent of frame to crop from the bottom", NUM|FLO, "y offset ", 0.0, -100.0, 100.0, "Percent of vertical offset", LABEL, "Fill color ", 0.0, 0.0, 0.0, "", NUM|INT, "Red ", 0.0, 0.0, 255.0, "Red value for the fill color", NUM|INT, "Green ", 0.0, 0.0, 255.0, "Green value for the fill color", NUM|INT, "Blue ", 0.0, 0.0, 255.0, "Blue value for the fill color", NUM|INT, "Alpha ", 0.0, 0.0, 255.0, "Alpha value for the fill color", }; /* The cast struct is for input in the main doit function Varstr and Cast must have the same variables in the same order */ typedef struct Cast { int dummy; /* because of the 'label' button */ float lstart; float rstart; float xstart; float tstart; float bstart; float ystart; int dummya; /* because of the 'label' button */ float lfinal; float rfinal; float xfinal; float tfinal; float bfinal; float yfinal; int dummyb; /* because of the 'label' button */ int red; int green; int blue; int alpha; } Cast; /* cfra: the current frame */ float cfra; void plugin_seq_doit(Cast *, float, float, int, int, ImBuf *, ImBuf *, ImBuf *, ImBuf *); int plugin_seq_getversion(void) { return B_PLUGIN_VERSION; } void plugin_but_changed(int but) { } void plugin_init() { } void plugin_getinfo(PluginInfo *info) { info->name= name; info->nvars= sizeof(varstr)/sizeof(VarStruct); info->cfra= &cfra; info->varstr= varstr; info->init= plugin_init; info->seq_doit= (SeqDoit) plugin_seq_doit; info->callback= plugin_but_changed; } /* local function prototypes */ /* end of local function prototypes */ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width, int height, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *outbuf, ImBuf *use) { char *in1= (char *)ibuf1->rect; char *out= (char *)outbuf->rect; int x, y, z; /*counter variables*/ int u = (width * height); int left = (width*(0.01*(facf0*(cast->lfinal - cast->lstart) + cast->lstart))); int right = (width*(0.01*(facf0*(cast->rfinal - cast->rstart) + cast->rstart))); int top = (height*(0.01*(facf0*(cast->tfinal - cast->tstart) + cast->tstart))); int bottom = (height*(0.01*(facf0*(cast->bfinal - cast->bstart) + cast->bstart))); int rwidth = (width - right); int theight = (height - top); /* test if there's anything to do */ if (((left + right) >= width)||((top + bottom) >= height)) { for (z=0;zred; *out++ = cast->green; *out++ = cast->blue; *out++ = cast->alpha; } return; } for (y=0;y= theight|| y < bottom|| x < left|| x >= rwidth) { *out++ = cast->red; *out++ = cast->green; *out++ = cast->blue; *out++ = cast->alpha; in1 += 4; } else { *out++ = *in1++; *out++ = *in1++; *out++ = *in1++; *out++ = *in1++; } } } }