2003-01-01 15:06:10 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2003-01-01 15:06:10 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-01-07 19:13:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2003-01-01 15:06:10 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2003-01-01 15:06:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
|
|
|
|
/* ******************** GLOBAL VARIABLES ***************** */
|
|
|
|
|
|
|
|
|
|
|
|
char name[24]= "scatter";
|
|
|
|
|
|
|
|
/* structure for buttons,
|
|
|
|
* butcode name default min max 0
|
|
|
|
*/
|
|
|
|
|
|
|
|
VarStruct varstr[]= {
|
|
|
|
LABEL, "Input: 1 strip", 0.0, 0.0, 0.0, "",
|
|
|
|
NUM|INT, "seed: ", 1.0, 0.0, 10.0, "Offset in random table",
|
|
|
|
NUMSLI|FLO, "swing: ", 1.0, 0.0, 3.0, "The amplitude, width of the effect",
|
|
|
|
TOG|INT, "wrap", 0.0, 0.0, 1.0, "Cyclic wrap around the left/right edges",
|
|
|
|
NUM|INT, "type: ", 1.0, 0.0, 1.0, "Type 1 is random for each frame",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
int seed;
|
|
|
|
float swing;
|
|
|
|
int wrap;
|
|
|
|
int type;
|
|
|
|
} Cast;
|
|
|
|
|
|
|
|
/* cfra: the current frame */
|
|
|
|
|
|
|
|
float cfra;
|
|
|
|
|
|
|
|
void plugin_seq_doit(Cast *, float, float, int, int, ImBuf *, ImBuf *, ImBuf *, ImBuf *);
|
|
|
|
|
|
|
|
|
|
|
|
/* ******************** Fixed functions ***************** */
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ************************************************************
|
|
|
|
Scatter
|
|
|
|
|
|
|
|
************************************************************ */
|
|
|
|
|
2007-01-19 21:06:35 +00:00
|
|
|
static void rectcpy(ImBuf *dbuf, ImBuf *sbuf,
|
2003-01-01 15:06:10 +00:00
|
|
|
int destx, int desty,
|
2007-01-19 21:06:35 +00:00
|
|
|
int srcx, int srcy, int width, int height)
|
2003-01-01 15:06:10 +00:00
|
|
|
{
|
|
|
|
uint *drect,*srect;
|
2007-01-19 21:06:35 +00:00
|
|
|
float *dfrect, *sfrect;
|
|
|
|
int tmp;
|
2003-01-01 15:06:10 +00:00
|
|
|
|
|
|
|
if (dbuf == 0) return;
|
|
|
|
|
|
|
|
if (destx < 0){
|
|
|
|
srcx -= destx ;
|
|
|
|
width += destx ;
|
|
|
|
destx = 0;
|
|
|
|
}
|
|
|
|
if (srcx < 0){
|
|
|
|
destx -= srcx ;
|
|
|
|
width += destx ;
|
|
|
|
srcx = 0;
|
|
|
|
}
|
|
|
|
if (desty < 0){
|
|
|
|
srcy -= desty ;
|
|
|
|
height += desty ;
|
|
|
|
desty = 0;
|
|
|
|
}
|
|
|
|
if (srcy < 0){
|
|
|
|
desty -= srcy ;
|
|
|
|
height += desty ;
|
|
|
|
srcy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width > dbuf->x - destx) width = dbuf->x - destx;
|
|
|
|
if (height > dbuf->y - desty) height = dbuf->y - desty;
|
|
|
|
if (sbuf){
|
|
|
|
if (width > sbuf->x - srcx) width = sbuf->x - srcx;
|
|
|
|
if (height > sbuf->y - srcy) height = sbuf->y - srcy;
|
2007-01-19 21:06:35 +00:00
|
|
|
srect = sbuf->rect;
|
|
|
|
sfrect = sbuf->rect_float;
|
2003-01-01 15:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (width <= 0) return;
|
|
|
|
if (height <= 0) return;
|
|
|
|
|
|
|
|
drect = dbuf->rect;
|
2007-01-19 21:06:35 +00:00
|
|
|
dfrect = dbuf->rect_float;
|
|
|
|
|
2007-01-24 17:55:53 +00:00
|
|
|
tmp = (desty * dbuf->x + destx);
|
2007-01-19 21:06:35 +00:00
|
|
|
|
2007-01-24 17:55:53 +00:00
|
|
|
if (dbuf->rect_float) dfrect += 4 * tmp;
|
2007-01-19 21:06:35 +00:00
|
|
|
else drect += tmp;
|
2003-01-01 15:06:10 +00:00
|
|
|
|
|
|
|
destx = dbuf->x;
|
|
|
|
|
|
|
|
if (sbuf) {
|
2007-01-24 17:55:53 +00:00
|
|
|
tmp = (srcy * sbuf->x + srcx );
|
|
|
|
if (dbuf->rect_float) sfrect += 4 * tmp;
|
2007-01-19 21:06:35 +00:00
|
|
|
else srect += tmp;
|
2003-01-01 15:06:10 +00:00
|
|
|
srcx = sbuf->x;
|
|
|
|
} else{
|
2007-01-19 21:06:35 +00:00
|
|
|
if (dbuf->rect_float) sfrect = dfrect;
|
|
|
|
else srect = drect;
|
2003-01-01 15:06:10 +00:00
|
|
|
srcx = destx;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;height > 0; height--){
|
2007-01-19 21:06:35 +00:00
|
|
|
if (dbuf->rect_float) {
|
2007-01-24 17:55:53 +00:00
|
|
|
memcpy(dfrect,sfrect, 4 * width * sizeof(float));
|
2007-01-19 21:06:35 +00:00
|
|
|
dfrect += destx;
|
|
|
|
sfrect += srcx;
|
|
|
|
} else {
|
2007-01-24 17:55:53 +00:00
|
|
|
memcpy(drect,srect, width * sizeof(int));
|
2007-01-19 21:06:35 +00:00
|
|
|
drect += destx;
|
|
|
|
srect += srcx;
|
|
|
|
}
|
2003-01-01 15:06:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-19 21:06:35 +00:00
|
|
|
static void fill_out(ImBuf *out, float r, float g, float b, float a)
|
2003-01-01 15:06:10 +00:00
|
|
|
{
|
2007-01-19 21:06:35 +00:00
|
|
|
int tot,x;
|
|
|
|
float *rectf = out->rect_float;
|
|
|
|
unsigned char *rect = (unsigned char *)out->rect;
|
|
|
|
|
|
|
|
tot = out->x * out->y;
|
|
|
|
if (out->rect_float) {
|
|
|
|
for (x = 0;x < tot; x++) {
|
|
|
|
rectf[0] = r;
|
|
|
|
rectf[1] = g;
|
|
|
|
rectf[2] = b;
|
|
|
|
rectf[3] = a;
|
2007-01-24 17:55:53 +00:00
|
|
|
rectf += 4;
|
2007-01-19 21:06:35 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (x=0;x < tot;x++) {
|
|
|
|
rect[0] = (int)(r * 255);
|
|
|
|
rect[1] = (int)(g * 255);
|
|
|
|
rect[2] = (int)(b * 255);
|
|
|
|
rect[3] = (int)(a * 255);
|
|
|
|
rect += 4;
|
|
|
|
}
|
|
|
|
}
|
2003-01-01 15:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void plugin_seq_doit(Cast *cast, float facf0, float facf1, int sx, int sy, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *out, ImBuf *use)
|
|
|
|
{
|
|
|
|
float f1, f2, t1, t2, t3;
|
|
|
|
int x, y, lr;
|
|
|
|
|
|
|
|
/* fill imbuf 'out' with black */
|
2007-01-19 21:06:35 +00:00
|
|
|
fill_out(out, 0,0,0,0);
|
2003-01-01 15:06:10 +00:00
|
|
|
|
2007-01-24 17:55:53 +00:00
|
|
|
|
2003-01-01 15:06:10 +00:00
|
|
|
switch (cast->type) {
|
|
|
|
case 0:
|
|
|
|
srand48(cast->seed);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
srand48(cast->seed + facf0 * 1000);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (y = 0; y < sy; y++) {
|
|
|
|
switch (cast->type) {
|
|
|
|
case 0:
|
|
|
|
if ((y & 1) == 0) {
|
|
|
|
f1 = drand48() - 0.5;
|
|
|
|
f2 = drand48() - 0.5;
|
|
|
|
f1 = cast->swing * f1;
|
|
|
|
f2 = cast->swing * f2;
|
|
|
|
if (cast->wrap) f2 += 1.0;
|
|
|
|
lr = drand48()>0.5;
|
|
|
|
t1 = facf0;
|
|
|
|
} else t1 = facf1;
|
|
|
|
|
|
|
|
t2 = 1.0 - t1;
|
|
|
|
t3 = 3.0 * (f1 * t1 * t1 * t2 + f2 * t1 * t2 * t2);
|
|
|
|
if (cast->wrap) t3 += t2 * t2 * t2;
|
|
|
|
x = sx * t3;
|
|
|
|
if (lr) x = -x;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
f1 = drand48() - 0.5;
|
|
|
|
f1 = f1 * cast->swing;
|
|
|
|
if ((y & 1) == 0) f1 *= facf0;
|
|
|
|
else f1 *= facf1;
|
|
|
|
x = f1 * sx;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-19 21:06:35 +00:00
|
|
|
rectcpy(out, ibuf1, 0, y, x, y, 32767, 1);
|
2003-01-01 15:06:10 +00:00
|
|
|
if (cast->wrap) {
|
2007-01-19 21:06:35 +00:00
|
|
|
rectcpy(out, ibuf1, 0, y, x + sx, y, 32767, 1);
|
|
|
|
rectcpy(out, ibuf1, 0, y, x + sx + sx, y, 32767, 1);
|
|
|
|
rectcpy(out, ibuf1, 0, y, x - sx, y, 32767, 1);
|
|
|
|
rectcpy(out, ibuf1, 0, y, x - sx - sx, y, 32767, 1);
|
2003-01-01 15:06:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|