4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
24 * - Blender Foundation, 2003-2009
25 * - Peter Schlaile <peter [at] schlaile [dot] de> 2005/2006
27 * ***** END GPL LICENSE BLOCK *****
34 #include "MEM_guardedalloc.h"
35 #include "PIL_dynlib.h"
37 #include "BLI_math.h" /* windows needs for M_PI */
39 #include "DNA_scene_types.h"
40 #include "DNA_sequence_types.h"
41 #include "DNA_anim_types.h"
43 #include "BKE_fcurve.h"
45 #include "BKE_plugin_types.h"
46 #include "BKE_sequencer.h"
47 #include "BKE_texture.h"
48 #include "BKE_utildefines.h"
50 #include "IMB_imbuf_types.h"
51 #include "IMB_imbuf.h"
53 #include "RNA_access.h"
56 static void error(const char *UNUSED(error), ...) {}
71 static struct ImBuf * prepare_effect_imbufs(
73 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
78 if (!ibuf1 && !ibuf2 && !ibuf3) {
79 /* hmmm, global float option ? */
80 out = IMB_allocImBuf((short)x, (short)y, 32, IB_rect);
81 } else if ((ibuf1 && ibuf1->rect_float) ||
82 (ibuf2 && ibuf2->rect_float) ||
83 (ibuf3 && ibuf3->rect_float)) {
84 /* if any inputs are rectfloat, output is float too */
86 out = IMB_allocImBuf((short)x, (short)y, 32, IB_rectfloat);
88 out = IMB_allocImBuf((short)x, (short)y, 32, IB_rect);
91 if (ibuf1 && !ibuf1->rect_float && out->rect_float) {
92 IMB_float_from_rect_simple(ibuf1);
94 if (ibuf2 && !ibuf2->rect_float && out->rect_float) {
95 IMB_float_from_rect_simple(ibuf2);
97 if (ibuf3 && !ibuf3->rect_float && out->rect_float) {
98 IMB_float_from_rect_simple(ibuf3);
101 if (ibuf1 && !ibuf1->rect && !out->rect_float) {
102 IMB_rect_from_float(ibuf1);
104 if (ibuf2 && !ibuf2->rect && !out->rect_float) {
105 IMB_rect_from_float(ibuf2);
107 if (ibuf3 && !ibuf3->rect && !out->rect_float) {
108 IMB_rect_from_float(ibuf3);
114 /* **********************************************************************
116 ********************************************************************** */
118 static void open_plugin_seq(PluginSeq *pis, const char *seqname)
121 void* (*alloc_private)();
124 /* to be sure: (is tested for) */
130 pis->instance_private_data = 0;
132 /* clear the error list */
133 PIL_dynlib_get_error_as_string(NULL);
135 /* if(pis->handle) PIL_dynlib_close(pis->handle); */
136 /* pis->handle= 0; */
138 /* open the needed object */
139 pis->handle= PIL_dynlib_open(pis->name);
140 if(test_dlerr(pis->name, pis->name)) return;
142 if (pis->handle != 0) {
143 /* find the address of the version function */
144 version= (int (*)())PIL_dynlib_find_symbol(pis->handle, "plugin_seq_getversion");
145 if (test_dlerr(pis->name, "plugin_seq_getversion")) return;
148 pis->version= version();
149 if (pis->version >= 2 && pis->version <= 6) {
150 int (*info_func)(PluginInfo *);
151 PluginInfo *info= (PluginInfo*) MEM_mallocN(sizeof(PluginInfo), "plugin_info");
153 info_func= (int (*)(PluginInfo *))PIL_dynlib_find_symbol(pis->handle, "plugin_getinfo");
155 if(info_func == NULL) error("No info func");
159 pis->pname= info->name;
160 pis->vars= info->nvars;
161 pis->cfra= info->cfra;
163 pis->varstr= info->varstr;
165 pis->doit= (void(*)(void))info->seq_doit;
171 cp= PIL_dynlib_find_symbol(pis->handle, "seqname");
172 if(cp) strncpy(cp, seqname, 21);
174 printf ("Plugin returned unrecognized version number\n");
178 alloc_private = (void* (*)())PIL_dynlib_find_symbol(
179 pis->handle, "plugin_seq_alloc_private_data");
181 pis->instance_private_data = alloc_private();
184 pis->current_private_data = (void**)
185 PIL_dynlib_find_symbol(
186 pis->handle, "plugin_private_data");
190 static PluginSeq *add_plugin_seq(const char *str, const char *seqname)
196 pis= MEM_callocN(sizeof(PluginSeq), "PluginSeq");
198 strncpy(pis->name, str, FILE_MAXDIR+FILE_MAXFILE);
199 open_plugin_seq(pis, seqname);
202 if(pis->handle==0) error("no plugin: %s", str);
203 else error("in plugin: %s", str);
210 for(a=0; a<pis->vars; a++, varstr++) {
211 if( (varstr->type & FLO)==FLO)
212 pis->data[a]= varstr->def;
213 else if( (varstr->type & INT)==INT)
214 *((int *)(pis->data+a))= (int) varstr->def;
220 static void free_plugin_seq(PluginSeq *pis)
224 /* no PIL_dynlib_close: same plugin can be opened multiple times with 1 handle */
226 if (pis->instance_private_data) {
227 void (*free_private)(void *);
229 free_private = (void (*)(void *))PIL_dynlib_find_symbol(
230 pis->handle, "plugin_seq_free_private_data");
232 free_private(pis->instance_private_data);
239 static void init_plugin(Sequence * seq, const char * fname)
241 seq->plugin= (PluginSeq *)add_plugin_seq(fname, seq->name+2);
245 * FIXME: should query plugin! Could be generator, that needs zero inputs...
247 static int num_inputs_plugin()
252 static void load_plugin(Sequence * seq)
255 open_plugin_seq(seq->plugin, seq->name+2);
259 static void copy_plugin(Sequence * dst, Sequence * src)
262 dst->plugin= MEM_dupallocN(src->plugin);
263 open_plugin_seq(dst->plugin, dst->name+2);
267 static ImBuf * IMB_cast_away_list(ImBuf * i)
272 return (ImBuf*) (((void**) i) + 2);
275 static struct ImBuf * do_plugin_effect(
276 Main *UNUSED(bmain), Scene *UNUSED(scene), Sequence *seq, float cfra,
277 float facf0, float facf1, int x, int y,
278 int UNUSED(preview_render_size),
279 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
284 int use_temp_bufs = 0; /* Are needed since blur.c (and maybe some other
285 old plugins) do very bad stuff
286 with imbuf-internals */
288 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
290 if(seq->plugin && seq->plugin->doit) {
292 if(seq->plugin->cfra)
293 *(seq->plugin->cfra)= cfra;
295 cp = PIL_dynlib_find_symbol(
296 seq->plugin->handle, "seqname");
298 if(cp) strncpy(cp, seq->name+2, 22);
300 if (seq->plugin->current_private_data) {
301 *seq->plugin->current_private_data
302 = seq->plugin->instance_private_data;
305 float_rendering = (out->rect_float != NULL);
307 if (seq->plugin->version<=3 && float_rendering) {
311 ibuf1 = IMB_dupImBuf(ibuf1);
312 IMB_rect_from_float(ibuf1);
313 imb_freerectfloatImBuf(ibuf1);
314 ibuf1->flags &= ~IB_rectfloat;
317 ibuf2 = IMB_dupImBuf(ibuf2);
318 IMB_rect_from_float(ibuf2);
319 imb_freerectfloatImBuf(ibuf2);
320 ibuf2->flags &= ~IB_rectfloat;
323 ibuf3 = IMB_dupImBuf(ibuf3);
324 IMB_rect_from_float(ibuf3);
325 imb_freerectfloatImBuf(ibuf3);
326 ibuf3->flags &= ~IB_rectfloat;
328 if (!out->rect) imb_addrectImBuf(out);
329 imb_freerectfloatImBuf(out);
330 out->flags &= ~IB_rectfloat;
333 if (seq->plugin->version<=2) {
334 if(ibuf1) IMB_convert_rgba_to_abgr(ibuf1);
335 if(ibuf2) IMB_convert_rgba_to_abgr(ibuf2);
336 if(ibuf3) IMB_convert_rgba_to_abgr(ibuf3);
339 if (seq->plugin->version<=4) {
340 ((SeqDoit)seq->plugin->doit)(
341 seq->plugin->data, facf0, facf1, x, y,
342 IMB_cast_away_list(ibuf1),
343 IMB_cast_away_list(ibuf2),
344 IMB_cast_away_list(out),
345 IMB_cast_away_list(ibuf3));
347 ((SeqDoit)seq->plugin->doit)(
348 seq->plugin->data, facf0, facf1, x, y,
349 ibuf1, ibuf2, out, ibuf3);
352 if (seq->plugin->version<=2) {
353 if (!use_temp_bufs) {
354 if(ibuf1) IMB_convert_rgba_to_abgr(ibuf1);
355 if(ibuf2) IMB_convert_rgba_to_abgr(ibuf2);
356 if(ibuf3) IMB_convert_rgba_to_abgr(ibuf3);
358 IMB_convert_rgba_to_abgr(out);
360 if (seq->plugin->version<=3 && float_rendering) {
361 IMB_float_from_rect_simple(out);
365 if (ibuf1) IMB_freeImBuf(ibuf1);
366 if (ibuf2) IMB_freeImBuf(ibuf2);
367 if (ibuf3) IMB_freeImBuf(ibuf3);
373 static int do_plugin_early_out(struct Sequence *UNUSED(seq),
374 float UNUSED(facf0), float UNUSED(facf1))
379 static void free_plugin(struct Sequence * seq)
381 free_plugin_seq(seq->plugin);
385 /* **********************************************************************
387 ********************************************************************** */
389 static void init_alpha_over_or_under(Sequence * seq)
391 Sequence * seq1 = seq->seq1;
392 Sequence * seq2 = seq->seq2;
398 static void do_alphaover_effect_byte(float facf0, float facf1, int x, int y,
399 char * rect1, char *rect2, char *out)
401 int fac2, mfac, fac, fac4;
403 char *rt1, *rt2, *rt;
410 fac2= (int)(256.0*facf0);
411 fac4= (int)(256.0*facf1);
418 /* rt = rt1 over rt2 (alpha from rt1) */
421 mfac= 256 - ( (fac2*rt1[3])>>8 );
423 if(fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2);
424 else if(mfac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt1);
426 tempc= ( fac*rt1[0] + mfac*rt2[0])>>8;
427 if(tempc>255) rt[0]= 255; else rt[0]= tempc;
428 tempc= ( fac*rt1[1] + mfac*rt2[1])>>8;
429 if(tempc>255) rt[1]= 255; else rt[1]= tempc;
430 tempc= ( fac*rt1[2] + mfac*rt2[2])>>8;
431 if(tempc>255) rt[2]= 255; else rt[2]= tempc;
432 tempc= ( fac*rt1[3] + mfac*rt2[3])>>8;
433 if(tempc>255) rt[3]= 255; else rt[3]= tempc;
435 rt1+= 4; rt2+= 4; rt+= 4;
445 mfac= 256 - ( (fac4*rt1[3])>>8 );
447 if(fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2);
448 else if(mfac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt1);
450 tempc= ( fac*rt1[0] + mfac*rt2[0])>>8;
451 if(tempc>255) rt[0]= 255; else rt[0]= tempc;
452 tempc= ( fac*rt1[1] + mfac*rt2[1])>>8;
453 if(tempc>255) rt[1]= 255; else rt[1]= tempc;
454 tempc= ( fac*rt1[2] + mfac*rt2[2])>>8;
455 if(tempc>255) rt[2]= 255; else rt[2]= tempc;
456 tempc= ( fac*rt1[3] + mfac*rt2[3])>>8;
457 if(tempc>255) rt[3]= 255; else rt[3]= tempc;
459 rt1+= 4; rt2+= 4; rt+= 4;
464 static void do_alphaover_effect_float(float facf0, float facf1, int x, int y,
465 float * rect1, float *rect2, float *out)
467 float fac2, mfac, fac, fac4;
469 float *rt1, *rt2, *rt;
484 /* rt = rt1 over rt2 (alpha from rt1) */
487 mfac= 1.0 - (fac2*rt1[3]) ;
490 memcpy(rt, rt2, 4 * sizeof(float));
491 } else if(mfac <=0) {
492 memcpy(rt, rt1, 4 * sizeof(float));
494 rt[0] = fac*rt1[0] + mfac*rt2[0];
495 rt[1] = fac*rt1[1] + mfac*rt2[1];
496 rt[2] = fac*rt1[2] + mfac*rt2[2];
497 rt[3] = fac*rt1[3] + mfac*rt2[3];
499 rt1+= 4; rt2+= 4; rt+= 4;
509 mfac= 1.0 - (fac4*rt1[3]);
512 memcpy(rt, rt2, 4 * sizeof(float));
513 } else if(mfac <= 0.0) {
514 memcpy(rt, rt1, 4 * sizeof(float));
516 rt[0] = fac*rt1[0] + mfac*rt2[0];
517 rt[1] = fac*rt1[1] + mfac*rt2[1];
518 rt[2] = fac*rt1[2] + mfac*rt2[2];
519 rt[3] = fac*rt1[3] + mfac*rt2[3];
521 rt1+= 4; rt2+= 4; rt+= 4;
526 static struct ImBuf * do_alphaover_effect(
527 Main *bmain, Scene *UNUSED(scene), Sequence *UNUSED(seq), float UNUSED(cfra),
528 float facf0, float facf1, int x, int y,
529 int UNUSED(preview_render_size),
530 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
533 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
535 if (out->rect_float) {
536 do_alphaover_effect_float(
538 ibuf1->rect_float, ibuf2->rect_float,
541 do_alphaover_effect_byte(
543 (char*) ibuf1->rect, (char*) ibuf2->rect,
550 /* **********************************************************************
552 ********************************************************************** */
554 void do_alphaunder_effect_byte(
555 float facf0, float facf1, int x, int y, char *rect1,
556 char *rect2, char *out)
558 int fac2, mfac, fac, fac4;
560 char *rt1, *rt2, *rt;
567 fac2= (int)(256.0*facf0);
568 fac4= (int)(256.0*facf1);
575 /* rt = rt1 under rt2 (alpha from rt2) */
577 /* this complex optimalisation is because the
578 * 'skybuf' can be crossed in
580 if(rt2[3]==0 && fac2==256) *( (unsigned int *)rt) = *( (unsigned int *)rt1);
581 else if(rt2[3]==255) *( (unsigned int *)rt) = *( (unsigned int *)rt2);
584 fac= (fac2*(256-mfac))>>8;
586 if(fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2);
588 rt[0]= ( fac*rt1[0] + mfac*rt2[0])>>8;
589 rt[1]= ( fac*rt1[1] + mfac*rt2[1])>>8;
590 rt[2]= ( fac*rt1[2] + mfac*rt2[2])>>8;
591 rt[3]= ( fac*rt1[3] + mfac*rt2[3])>>8;
594 rt1+= 4; rt2+= 4; rt+= 4;
603 if(rt2[3]==0 && fac4==256) *( (unsigned int *)rt) = *( (unsigned int *)rt1);
604 else if(rt2[3]==255) *( (unsigned int *)rt) = *( (unsigned int *)rt2);
607 fac= (fac4*(256-mfac))>>8;
609 if(fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2);
611 rt[0]= ( fac*rt1[0] + mfac*rt2[0])>>8;
612 rt[1]= ( fac*rt1[1] + mfac*rt2[1])>>8;
613 rt[2]= ( fac*rt1[2] + mfac*rt2[2])>>8;
614 rt[3]= ( fac*rt1[3] + mfac*rt2[3])>>8;
617 rt1+= 4; rt2+= 4; rt+= 4;
623 static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y,
624 float *rect1, float *rect2,
627 float fac2, mfac, fac, fac4;
629 float *rt1, *rt2, *rt;
644 /* rt = rt1 under rt2 (alpha from rt2) */
646 /* this complex optimalisation is because the
647 * 'skybuf' can be crossed in
649 if( rt2[3]<=0 && fac2>=1.0) {
650 memcpy(rt, rt1, 4 * sizeof(float));
651 } else if(rt2[3]>=1.0) {
652 memcpy(rt, rt2, 4 * sizeof(float));
655 fac = fac2 * (1.0 - mfac);
658 memcpy(rt, rt2, 4 * sizeof(float));
660 rt[0]= fac*rt1[0] + mfac*rt2[0];
661 rt[1]= fac*rt1[1] + mfac*rt2[1];
662 rt[2]= fac*rt1[2] + mfac*rt2[2];
663 rt[3]= fac*rt1[3] + mfac*rt2[3];
666 rt1+= 4; rt2+= 4; rt+= 4;
675 if(rt2[3]<=0 && fac4 >= 1.0) {
676 memcpy(rt, rt1, 4 * sizeof(float));
678 } else if(rt2[3]>=1.0) {
679 memcpy(rt, rt2, 4 * sizeof(float));
682 fac= fac4*(1.0-mfac);
685 memcpy(rt, rt2, 4 * sizeof(float));
687 rt[0]= fac * rt1[0] + mfac * rt2[0];
688 rt[1]= fac * rt1[1] + mfac * rt2[1];
689 rt[2]= fac * rt1[2] + mfac * rt2[2];
690 rt[3]= fac * rt1[3] + mfac * rt2[3];
693 rt1+= 4; rt2+= 4; rt+= 4;
698 static struct ImBuf* do_alphaunder_effect(
699 Main *UNUSED(bmain), Scene *UNUSED(scene), Sequence *UNUSED(seq), float UNUSED(cfra),
700 float facf0, float facf1, int x, int y,
701 int UNUSED(preview_render_size),
702 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
705 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
707 if (out->rect_float) {
708 do_alphaunder_effect_float(
710 ibuf1->rect_float, ibuf2->rect_float,
713 do_alphaunder_effect_byte(
715 (char*) ibuf1->rect, (char*) ibuf2->rect,
722 /* **********************************************************************
724 ********************************************************************** */
726 void do_cross_effect_byte(float facf0, float facf1, int x, int y,
727 char *rect1, char *rect2,
730 int fac1, fac2, fac3, fac4;
732 char *rt1, *rt2, *rt;
739 fac2= (int)(256.0*facf0);
741 fac4= (int)(256.0*facf1);
749 rt[0]= (fac1*rt1[0] + fac2*rt2[0])>>8;
750 rt[1]= (fac1*rt1[1] + fac2*rt2[1])>>8;
751 rt[2]= (fac1*rt1[2] + fac2*rt2[2])>>8;
752 rt[3]= (fac1*rt1[3] + fac2*rt2[3])>>8;
754 rt1+= 4; rt2+= 4; rt+= 4;
763 rt[0]= (fac3*rt1[0] + fac4*rt2[0])>>8;
764 rt[1]= (fac3*rt1[1] + fac4*rt2[1])>>8;
765 rt[2]= (fac3*rt1[2] + fac4*rt2[2])>>8;
766 rt[3]= (fac3*rt1[3] + fac4*rt2[3])>>8;
768 rt1+= 4; rt2+= 4; rt+= 4;
774 void do_cross_effect_float(float facf0, float facf1, int x, int y,
775 float *rect1, float *rect2, float *out)
777 float fac1, fac2, fac3, fac4;
779 float *rt1, *rt2, *rt;
796 rt[0]= fac1*rt1[0] + fac2*rt2[0];
797 rt[1]= fac1*rt1[1] + fac2*rt2[1];
798 rt[2]= fac1*rt1[2] + fac2*rt2[2];
799 rt[3]= fac1*rt1[3] + fac2*rt2[3];
801 rt1+= 4; rt2+= 4; rt+= 4;
810 rt[0]= fac3*rt1[0] + fac4*rt2[0];
811 rt[1]= fac3*rt1[1] + fac4*rt2[1];
812 rt[2]= fac3*rt1[2] + fac4*rt2[2];
813 rt[3]= fac3*rt1[3] + fac4*rt2[3];
815 rt1+= 4; rt2+= 4; rt+= 4;
821 /* carefull: also used by speed effect! */
823 static struct ImBuf* do_cross_effect(
824 Main *UNUSED(bmain), Scene *UNUSED(scene), Sequence *UNUSED(seq), float UNUSED(cfra),
825 float facf0, float facf1, int x, int y,
826 int UNUSED(preview_render_size),
827 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
830 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
832 if (out->rect_float) {
833 do_cross_effect_float(
835 ibuf1->rect_float, ibuf2->rect_float,
838 do_cross_effect_byte(
840 (char*) ibuf1->rect, (char*) ibuf2->rect,
847 /* **********************************************************************
849 ********************************************************************** */
851 /* copied code from initrender.c */
852 static unsigned short gamtab[65536];
853 static unsigned short igamtab1[256];
854 static int gamma_tabs_init = FALSE;
856 #define RE_GAMMA_TABLE_SIZE 400
858 static float gamma_range_table[RE_GAMMA_TABLE_SIZE + 1];
859 static float gamfactor_table[RE_GAMMA_TABLE_SIZE];
860 static float inv_gamma_range_table[RE_GAMMA_TABLE_SIZE + 1];
861 static float inv_gamfactor_table[RE_GAMMA_TABLE_SIZE];
862 static float color_domain_table[RE_GAMMA_TABLE_SIZE + 1];
863 static float color_step;
864 static float inv_color_step;
865 static float valid_gamma;
866 static float valid_inv_gamma;
868 static void makeGammaTables(float gamma)
870 /* we need two tables: one forward, one backward */
874 valid_inv_gamma = 1.0 / gamma;
875 color_step = 1.0 / RE_GAMMA_TABLE_SIZE;
876 inv_color_step = (float) RE_GAMMA_TABLE_SIZE;
878 /* We could squeeze out the two range tables to gain some memory. */
879 for (i = 0; i < RE_GAMMA_TABLE_SIZE; i++) {
880 color_domain_table[i] = i * color_step;
881 gamma_range_table[i] = pow(color_domain_table[i],
883 inv_gamma_range_table[i] = pow(color_domain_table[i],
887 /* The end of the table should match 1.0 carefully. In order to avoid */
888 /* rounding errors, we just set this explicitly. The last segment may */
889 /* have a different length than the other segments, but our */
890 /* interpolation is insensitive to that. */
891 color_domain_table[RE_GAMMA_TABLE_SIZE] = 1.0;
892 gamma_range_table[RE_GAMMA_TABLE_SIZE] = 1.0;
893 inv_gamma_range_table[RE_GAMMA_TABLE_SIZE] = 1.0;
895 /* To speed up calculations, we make these calc factor tables. They are */
896 /* multiplication factors used in scaling the interpolation. */
897 for (i = 0; i < RE_GAMMA_TABLE_SIZE; i++ ) {
898 gamfactor_table[i] = inv_color_step
899 * (gamma_range_table[i + 1] - gamma_range_table[i]) ;
900 inv_gamfactor_table[i] = inv_color_step
901 * (inv_gamma_range_table[i + 1] - inv_gamma_range_table[i]) ;
904 } /* end of void makeGammaTables(float gamma) */
907 static float gammaCorrect(float c)
912 i = floor(c * inv_color_step);
913 /* Clip to range [0,1]: outside, just do the complete calculation. */
914 /* We may have some performance problems here. Stretching up the LUT */
915 /* may help solve that, by exchanging LUT size for the interpolation. */
916 /* Negative colors are explicitly handled. */
917 if (i < 0) res = -pow(abs(c), valid_gamma);
918 else if (i >= RE_GAMMA_TABLE_SIZE ) res = pow(c, valid_gamma);
919 else res = gamma_range_table[i] +
920 ( (c - color_domain_table[i]) * gamfactor_table[i]);
923 } /* end of float gammaCorrect(float col) */
925 /* ------------------------------------------------------------------------- */
927 static float invGammaCorrect(float col)
932 i = floor(col*inv_color_step);
933 /* Negative colors are explicitly handled. */
934 if (i < 0) res = -pow(abs(col), valid_inv_gamma);
935 else if (i >= RE_GAMMA_TABLE_SIZE) res = pow(col, valid_inv_gamma);
936 else res = inv_gamma_range_table[i] +
937 ( (col - color_domain_table[i]) * inv_gamfactor_table[i]);
940 } /* end of float invGammaCorrect(float col) */
943 static void gamtabs(float gamma)
945 float val, igamma= 1.0f/gamma;
948 /* gamtab: in short, out short */
949 for(a=0; a<65536; a++) {
953 if(gamma==2.0) val= sqrt(val);
954 else if(gamma!=1.0) val= pow(val, igamma);
956 gamtab[a]= (65535.99*val);
958 /* inverse gamtab1 : in byte, out short */
959 for(a=1; a<=256; a++) {
960 if(gamma==2.0) igamtab1[a-1]= a*a-1;
961 else if(gamma==1.0) igamtab1[a-1]= 256*a-1;
964 igamtab1[a-1]= (65535.0*pow(val, gamma)) -1 ;
970 static void build_gammatabs()
972 if (gamma_tabs_init == FALSE) {
974 makeGammaTables(2.0f);
975 gamma_tabs_init = TRUE;
979 static void init_gammacross(Sequence * UNUSED(seq))
983 static void load_gammacross(Sequence * UNUSED(seq))
987 static void free_gammacross(Sequence * UNUSED(seq))
991 static void do_gammacross_effect_byte(float facf0, float UNUSED(facf1),
993 unsigned char *rect1,
994 unsigned char *rect2,
999 unsigned char *rt1, *rt2, *rt;
1002 rt1= (unsigned char *)rect1;
1003 rt2= (unsigned char *)rect2;
1004 rt= (unsigned char *)out;
1006 fac2= (int)(256.0*facf0);
1014 col= (fac1*igamtab1[rt1[0]] + fac2*igamtab1[rt2[0]])>>8;
1015 if(col>65535) rt[0]= 255; else rt[0]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
1016 col=(fac1*igamtab1[rt1[1]] + fac2*igamtab1[rt2[1]])>>8;
1017 if(col>65535) rt[1]= 255; else rt[1]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
1018 col= (fac1*igamtab1[rt1[2]] + fac2*igamtab1[rt2[2]])>>8;
1019 if(col>65535) rt[2]= 255; else rt[2]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
1020 col= (fac1*igamtab1[rt1[3]] + fac2*igamtab1[rt2[3]])>>8;
1021 if(col>65535) rt[3]= 255; else rt[3]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
1023 rt1+= 4; rt2+= 4; rt+= 4;
1032 col= (fac1*igamtab1[rt1[0]] + fac2*igamtab1[rt2[0]])>>8;
1033 if(col>65535) rt[0]= 255; else rt[0]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
1034 col= (fac1*igamtab1[rt1[1]] + fac2*igamtab1[rt2[1]])>>8;
1035 if(col>65535) rt[1]= 255; else rt[1]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
1036 col= (fac1*igamtab1[rt1[2]] + fac2*igamtab1[rt2[2]])>>8;
1037 if(col>65535) rt[2]= 255; else rt[2]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
1038 col= (fac1*igamtab1[rt1[3]] + fac2*igamtab1[rt2[3]])>>8;
1039 if(col>65535) rt[3]= 255; else rt[3]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
1041 rt1+= 4; rt2+= 4; rt+= 4;
1047 static void do_gammacross_effect_float(float facf0, float UNUSED(facf1),
1049 float *rect1, float *rect2,
1054 float *rt1, *rt2, *rt;
1070 fac1 * invGammaCorrect(*rt1)
1071 + fac2 * invGammaCorrect(*rt2));
1082 fac1*invGammaCorrect(*rt1)
1083 + fac2*invGammaCorrect(*rt2));
1090 static struct ImBuf * do_gammacross_effect(
1091 Main *UNUSED(bmain), Scene *UNUSED(scene), Sequence *UNUSED(seq), float UNUSED(cfra),
1092 float facf0, float facf1, int x, int y,
1093 int UNUSED(preview_render_size),
1094 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
1095 struct ImBuf *ibuf3)
1097 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
1101 if (out->rect_float) {
1102 do_gammacross_effect_float(
1104 ibuf1->rect_float, ibuf2->rect_float,
1107 do_gammacross_effect_byte(
1109 (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect,
1110 (unsigned char*) out->rect);
1116 /* **********************************************************************
1118 ********************************************************************** */
1120 static void do_add_effect_byte(float facf0, float facf1, int x, int y,
1121 unsigned char *rect1, unsigned char *rect2,
1124 int col, xo, fac1, fac3;
1125 char *rt1, *rt2, *rt;
1132 fac1= (int)(256.0*facf0);
1133 fac3= (int)(256.0*facf1);
1140 col= rt1[0]+ ((fac1*rt2[0])>>8);
1141 if(col>255) rt[0]= 255; else rt[0]= col;
1142 col= rt1[1]+ ((fac1*rt2[1])>>8);
1143 if(col>255) rt[1]= 255; else rt[1]= col;
1144 col= rt1[2]+ ((fac1*rt2[2])>>8);
1145 if(col>255) rt[2]= 255; else rt[2]= col;
1146 col= rt1[3]+ ((fac1*rt2[3])>>8);
1147 if(col>255) rt[3]= 255; else rt[3]= col;
1149 rt1+= 4; rt2+= 4; rt+= 4;
1158 col= rt1[0]+ ((fac3*rt2[0])>>8);
1159 if(col>255) rt[0]= 255; else rt[0]= col;
1160 col= rt1[1]+ ((fac3*rt2[1])>>8);
1161 if(col>255) rt[1]= 255; else rt[1]= col;
1162 col= rt1[2]+ ((fac3*rt2[2])>>8);
1163 if(col>255) rt[2]= 255; else rt[2]= col;
1164 col= rt1[3]+ ((fac3*rt2[3])>>8);
1165 if(col>255) rt[3]= 255; else rt[3]= col;
1167 rt1+= 4; rt2+= 4; rt+= 4;
1172 static void do_add_effect_float(float facf0, float facf1, int x, int y,
1173 float *rect1, float *rect2,
1178 float *rt1, *rt2, *rt;
1192 *rt = *rt1 + fac1 * (*rt2);
1202 *rt = *rt1 + fac3 * (*rt2);
1209 static struct ImBuf * do_add_effect(Main *UNUSED(bmain), Scene *UNUSED(scene), Sequence *UNUSED(seq), float UNUSED(cfra),
1210 float facf0, float facf1, int x, int y,
1211 int UNUSED(preview_render_size),
1212 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
1213 struct ImBuf *ibuf3)
1215 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
1217 if (out->rect_float) {
1218 do_add_effect_float(
1220 ibuf1->rect_float, ibuf2->rect_float,
1225 (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect,
1226 (unsigned char*) out->rect);
1232 /* **********************************************************************
1234 ********************************************************************** */
1236 static void do_sub_effect_byte(float facf0, float facf1,
1238 char *rect1, char *rect2, char *out)
1240 int col, xo, fac1, fac3;
1241 char *rt1, *rt2, *rt;
1248 fac1= (int)(256.0*facf0);
1249 fac3= (int)(256.0*facf1);
1256 col= rt1[0]- ((fac1*rt2[0])>>8);
1257 if(col<0) rt[0]= 0; else rt[0]= col;
1258 col= rt1[1]- ((fac1*rt2[1])>>8);
1259 if(col<0) rt[1]= 0; else rt[1]= col;
1260 col= rt1[2]- ((fac1*rt2[2])>>8);
1261 if(col<0) rt[2]= 0; else rt[2]= col;
1262 col= rt1[3]- ((fac1*rt2[3])>>8);
1263 if(col<0) rt[3]= 0; else rt[3]= col;
1265 rt1+= 4; rt2+= 4; rt+= 4;
1274 col= rt1[0]- ((fac3*rt2[0])>>8);
1275 if(col<0) rt[0]= 0; else rt[0]= col;
1276 col= rt1[1]- ((fac3*rt2[1])>>8);
1277 if(col<0) rt[1]= 0; else rt[1]= col;
1278 col= rt1[2]- ((fac3*rt2[2])>>8);
1279 if(col<0) rt[2]= 0; else rt[2]= col;
1280 col= rt1[3]- ((fac3*rt2[3])>>8);
1281 if(col<0) rt[3]= 0; else rt[3]= col;
1283 rt1+= 4; rt2+= 4; rt+= 4;
1288 static void do_sub_effect_float(float facf0, float facf1, int x, int y,
1289 float *rect1, float *rect2,
1294 float *rt1, *rt2, *rt;
1308 *rt = *rt1 - fac1 * (*rt2);
1318 *rt = *rt1 - fac3 * (*rt2);
1325 static struct ImBuf * do_sub_effect(
1326 Main *UNUSED(bmain), Scene *UNUSED(scene), Sequence *UNUSED(seq), float UNUSED(cfra),
1327 float facf0, float facf1, int x, int y,
1328 int UNUSED(preview_render_size),
1329 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
1330 struct ImBuf *ibuf3)
1332 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
1334 if (out->rect_float) {
1335 do_sub_effect_float(
1337 ibuf1->rect_float, ibuf2->rect_float,
1342 (char*) ibuf1->rect, (char*) ibuf2->rect,
1348 /* **********************************************************************
1350 ********************************************************************** */
1352 /* Must be > 0 or add precopy, etc to the function */
1356 static void do_drop_effect_byte(float facf0, float facf1, int x, int y,
1357 char *rect2i, char *rect1i,
1360 int height, width, temp, fac, fac1, fac2;
1361 char *rt1, *rt2, *out;
1367 fac1= (int)(70.0*facf0);
1368 fac2= (int)(70.0*facf1);
1370 rt2= (char*) (rect2i + YOFF*width);
1371 rt1= (char*) rect1i;
1373 for (y=0; y<height-YOFF; y++) {
1374 if(field) fac= fac1;
1378 memcpy(out, rt1, sizeof(int)*XOFF);
1382 for (x=XOFF; x<width; x++) {
1383 temp= ((fac*rt2[3])>>8);
1385 *(out++)= MAX2(0, *rt1 - temp); rt1++;
1386 *(out++)= MAX2(0, *rt1 - temp); rt1++;
1387 *(out++)= MAX2(0, *rt1 - temp); rt1++;
1388 *(out++)= MAX2(0, *rt1 - temp); rt1++;
1393 memcpy(out, rt1, sizeof(int)*YOFF*width);
1396 static void do_drop_effect_float(float facf0, float facf1, int x, int y,
1397 float *rect2i, float *rect1i,
1401 float temp, fac, fac1, fac2;
1402 float *rt1, *rt2, *out;
1411 rt2= (rect2i + YOFF*width);
1414 for (y=0; y<height-YOFF; y++) {
1415 if(field) fac= fac1;
1419 memcpy(out, rt1, 4 * sizeof(float)*XOFF);
1423 for (x=XOFF; x<width; x++) {
1426 *(out++)= MAX2(0.0, *rt1 - temp); rt1++;
1427 *(out++)= MAX2(0.0, *rt1 - temp); rt1++;
1428 *(out++)= MAX2(0.0, *rt1 - temp); rt1++;
1429 *(out++)= MAX2(0.0, *rt1 - temp); rt1++;
1434 memcpy(out, rt1, 4 * sizeof(float)*YOFF*width);
1437 /* **********************************************************************
1439 ********************************************************************** */
1441 static void do_mul_effect_byte(float facf0, float facf1, int x, int y,
1442 unsigned char *rect1, unsigned char *rect2,
1446 char *rt1, *rt2, *rt;
1453 fac1= (int)(256.0*facf0);
1454 fac3= (int)(256.0*facf1);
1457 * fac*(a*b) + (1-fac)*a => fac*a*(b-1)+axaux= c*px + py*s ;//+centx
1458 yaux= -s*px + c*py;//+centy
1466 rt[0]= rt1[0] + ((fac1*rt1[0]*(rt2[0]-256))>>16);
1467 rt[1]= rt1[1] + ((fac1*rt1[1]*(rt2[1]-256))>>16);
1468 rt[2]= rt1[2] + ((fac1*rt1[2]*(rt2[2]-256))>>16);
1469 rt[3]= rt1[3] + ((fac1*rt1[3]*(rt2[3]-256))>>16);
1471 rt1+= 4; rt2+= 4; rt+= 4;
1480 rt[0]= rt1[0] + ((fac3*rt1[0]*(rt2[0]-256))>>16);
1481 rt[1]= rt1[1] + ((fac3*rt1[1]*(rt2[1]-256))>>16);
1482 rt[2]= rt1[2] + ((fac3*rt1[2]*(rt2[2]-256))>>16);
1483 rt[3]= rt1[3] + ((fac3*rt1[3]*(rt2[3]-256))>>16);
1485 rt1+= 4; rt2+= 4; rt+= 4;
1490 static void do_mul_effect_float(float facf0, float facf1, int x, int y,
1491 float *rect1, float *rect2,
1496 float *rt1, *rt2, *rt;
1507 * fac*(a*b) + (1-fac)*a => fac*a*(b-1)+a
1515 rt[0]= rt1[0] + fac1*rt1[0]*(rt2[0]-1.0);
1516 rt[1]= rt1[1] + fac1*rt1[1]*(rt2[1]-1.0);
1517 rt[2]= rt1[2] + fac1*rt1[2]*(rt2[2]-1.0);
1518 rt[3]= rt1[3] + fac1*rt1[3]*(rt2[3]-1.0);
1520 rt1+= 4; rt2+= 4; rt+= 4;
1529 rt[0]= rt1[0] + fac3*rt1[0]*(rt2[0]-1.0);
1530 rt[1]= rt1[1] + fac3*rt1[1]*(rt2[1]-1.0);
1531 rt[2]= rt1[2] + fac3*rt1[2]*(rt2[2]-1.0);
1532 rt[3]= rt1[3] + fac3*rt1[3]*(rt2[3]-1.0);
1534 rt1+= 4; rt2+= 4; rt+= 4;
1539 static struct ImBuf * do_mul_effect(
1540 Main *UNUSED(bmain), Scene *UNUSED(scene), Sequence *UNUSED(seq), float UNUSED(cfra),
1541 float facf0, float facf1, int x, int y,
1542 int UNUSED(preview_render_size),
1543 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
1544 struct ImBuf *ibuf3)
1546 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
1548 if (out->rect_float) {
1549 do_mul_effect_float(
1551 ibuf1->rect_float, ibuf2->rect_float,
1556 (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect,
1557 (unsigned char*) out->rect);
1563 /* **********************************************************************
1565 ********************************************************************** */
1567 typedef struct WipeZone {
1576 static void precalc_wipe_zone(WipeZone *wipezone, WipeVars *wipe, int xo, int yo)
1578 wipezone->flip = (wipe->angle < 0);
1579 wipezone->angle = pow(fabs(wipe->angle)/45.0f, log(xo)/log(2.0f));
1582 wipezone->width = (int)(wipe->edgeWidth*((xo+yo)/2.0f));
1583 wipezone->pythangle = 1.0f/sqrt(wipe->angle*wipe->angle + 1.0f);
1585 if(wipe->wipetype == DO_SINGLE_WIPE)
1586 wipezone->invwidth = 1.0f/wipezone->width;
1588 wipezone->invwidth = 1.0f/(0.5f*wipezone->width);
1591 // This function calculates the blur band for the wipe effects
1592 static float in_band(WipeZone *wipezone,float width,float dist,float perc,int side,int dir)
1594 float t1,t2,alpha,percwidth;
1600 percwidth = width * perc;
1602 percwidth = width * (1 - perc);
1607 t1 = dist * wipezone->invwidth; //percentange of width that is
1608 t2 = wipezone->invwidth; //amount of alpha per % point
1611 alpha = (t1*t2*100) + (1-perc); // add point's alpha contrib to current position in wipe
1613 alpha = (1-perc) - (t1*t2*100);
1621 static float check_zone(WipeZone *wipezone, int x, int y,
1622 Sequence *seq, float facf0)
1624 float posx, posy,hyp,hyp2,angle,hwidth,b1,b2,b3,pointdist;
1626 float hyp3,hyp4,b4,b5
1628 float temp1,temp2,temp3,temp4; //some placeholder variables
1629 int xo = wipezone->xo;
1630 int yo = wipezone->yo;
1631 float halfx = xo*0.5f;
1632 float halfy = yo*0.5f;
1633 float widthf,output=0;
1634 WipeVars *wipe = (WipeVars *)seq->effectdata;
1637 if(wipezone->flip) x = xo - x;
1638 angle = wipezone->angle;
1646 posx = xo - facf0 * xo;
1647 posy = yo - facf0 * yo;
1650 switch (wipe->wipetype) {
1651 case DO_SINGLE_WIPE:
1652 width = wipezone->width;
1653 hwidth = width*0.5f;
1658 hyp = fabs(y - posy);
1661 b1 = posy - (-angle)*posx;
1662 b2 = y - (-angle)*x;
1663 hyp = fabs(angle*x+y+(-posy-angle*posx))*wipezone->pythangle;
1674 output = in_band(wipezone,width,hyp,facf0,1,1);
1676 output = in_band(wipezone,width,hyp,facf0,0,1);
1680 output = in_band(wipezone,width,hyp,facf0,0,1);
1682 output = in_band(wipezone,width,hyp,facf0,1,1);
1686 case DO_DOUBLE_WIPE:
1688 facf0 = 1.0f-facf0; // Go the other direction
1690 width = wipezone->width; // calculate the blur width
1691 hwidth = width*0.5f;
1697 hyp = abs(y - posy*0.5f);
1698 hyp2 = abs(y - (yo-posy*0.5f));
1701 b1 = posy*0.5f - (-angle)*posx*0.5f;
1702 b3 = (yo-posy*0.5f) - (-angle)*(xo-posx*0.5f);
1703 b2 = y - (-angle)*x;
1705 hyp = abs(angle*x+y+(-posy*0.5f-angle*posx*0.5f))*wipezone->pythangle;
1706 hyp2 = abs(angle*x+y+(-(yo-posy*0.5f)-angle*(xo-posx*0.5f)))*wipezone->pythangle;
1709 temp1 = xo*(1-facf0*0.5f)-xo*facf0*0.5f;
1710 temp2 = yo*(1-facf0*0.5f)-yo*facf0*0.5f;
1711 pointdist = sqrt(temp1*temp1 + temp2*temp2);
1713 if(b2 < b1 && b2 < b3 ){
1714 if(hwidth < pointdist)
1715 output = in_band(wipezone,hwidth,hyp,facf0,0,1);
1716 } else if(b2 > b1 && b2 > b3 ){
1717 if(hwidth < pointdist)
1718 output = in_band(wipezone,hwidth,hyp2,facf0,0,1);
1720 if( hyp < hwidth && hyp2 > hwidth )
1721 output = in_band(wipezone,hwidth,hyp,facf0,1,1);
1722 else if( hyp > hwidth && hyp2 < hwidth )
1723 output = in_band(wipezone,hwidth,hyp2,facf0,1,1);
1725 output = in_band(wipezone,hwidth,hyp2,facf0,1,1) * in_band(wipezone,hwidth,hyp,facf0,1,1);
1727 if(!wipe->forward)output = 1-output;
1731 temp1: angle of effect center in rads
1732 temp2: angle of line through (halfx,halfy) and (x,y) in rads
1733 temp3: angle of low side of blur
1734 temp4: angle of high side of blur
1736 output = 1.0f - facf0;
1737 widthf = wipe->edgeWidth*2.0f*(float)M_PI;
1738 temp1 = 2.0f * (float)M_PI * facf0;
1741 temp1 = 2.0f*(float)M_PI - temp1;
1747 temp2 = asin(abs(y)/sqrt(x*x + y*y));
1748 if(x <= 0 && y >= 0) temp2 = (float)M_PI - temp2;
1749 else if(x<=0 && y <= 0) temp2 += (float)M_PI;
1750 else if(x >= 0 && y <= 0) temp2 = 2.0f*(float)M_PI - temp2;
1753 temp3 = temp1-(widthf*0.5f)*facf0;
1754 temp4 = temp1+(widthf*0.5f)*(1-facf0);
1756 temp3 = temp1-(widthf*0.5f)*(1-facf0);
1757 temp4 = temp1+(widthf*0.5f)*facf0;
1759 if (temp3 < 0) temp3 = 0;
1760 if (temp4 > 2.0f*(float)M_PI) temp4 = 2.0f*(float)M_PI;
1763 if(temp2 < temp3) output = 0;
1764 else if (temp2 > temp4) output = 1;
1765 else output = (temp2-temp3)/(temp4-temp3);
1766 if(x == 0 && y == 0) output = 1;
1767 if(output != output) output = 1;
1768 if(wipe->forward) output = 1 - output;
1770 /* BOX WIPE IS NOT WORKING YET */
1771 /* case DO_CROSS_WIPE: */
1772 /* BOX WIPE IS NOT WORKING YET */
1775 if(invert)facf0 = 1-facf0;
1777 width = (int)(wipe->edgeWidth*((xo+yo)/2.0));
1778 hwidth = (float)width/2.0;
1779 if (angle == 0)angle = 0.000001;
1780 b1 = posy/2 - (-angle)*posx/2;
1781 b3 = (yo-posy/2) - (-angle)*(xo-posx/2);
1782 b2 = y - (-angle)*x;
1784 hyp = abs(angle*x+y+(-posy/2-angle*posx/2))*wipezone->pythangle;
1785 hyp2 = abs(angle*x+y+(-(yo-posy/2)-angle*(xo-posx/2)))*wipezone->pythangle;
1787 temp1 = xo*(1-facf0/2)-xo*facf0/2;
1788 temp2 = yo*(1-facf0/2)-yo*facf0/2;
1789 pointdist = sqrt(temp1*temp1 + temp2*temp2);
1791 if(b2 < b1 && b2 < b3 ){
1792 if(hwidth < pointdist)
1793 output = in_band(wipezone,hwidth,hyp,facf0,0,1);
1794 } else if(b2 > b1 && b2 > b3 ){
1795 if(hwidth < pointdist)
1796 output = in_band(wipezone,hwidth,hyp2,facf0,0,1);
1798 if( hyp < hwidth && hyp2 > hwidth )
1799 output = in_band(wipezone,hwidth,hyp,facf0,1,1);
1800 else if( hyp > hwidth && hyp2 < hwidth )
1801 output = in_band(wipezone,hwidth,hyp2,facf0,1,1);
1803 output = in_band(wipezone,hwidth,hyp2,facf0,1,1) * in_band(wipezone,hwidth,hyp,facf0,1,1);
1806 if(invert)facf0 = 1-facf0;
1808 b1 = posy/2 - (-angle)*posx/2;
1809 b3 = (yo-posy/2) - (-angle)*(xo-posx/2);
1810 b2 = y - (-angle)*x;
1812 hyp = abs(angle*x+y+(-posy/2-angle*posx/2))*wipezone->pythangle;
1813 hyp2 = abs(angle*x+y+(-(yo-posy/2)-angle*(xo-posx/2)))*wipezone->pythangle;
1815 if(b2 < b1 && b2 < b3 ){
1816 if(hwidth < pointdist)
1817 output *= in_band(wipezone,hwidth,hyp,facf0,0,1);
1818 } else if(b2 > b1 && b2 > b3 ){
1819 if(hwidth < pointdist)
1820 output *= in_band(wipezone,hwidth,hyp2,facf0,0,1);
1822 if( hyp < hwidth && hyp2 > hwidth )
1823 output *= in_band(wipezone,hwidth,hyp,facf0,1,1);
1824 else if( hyp > hwidth && hyp2 < hwidth )
1825 output *= in_band(wipezone,hwidth,hyp2,facf0,1,1);
1827 output *= in_band(wipezone,hwidth,hyp2,facf0,1,1) * in_band(wipezone,hwidth,hyp,facf0,1,1);
1833 if(xo > yo) yo = xo;
1836 if(!wipe->forward) facf0 = 1-facf0;
1838 width = wipezone->width;
1839 hwidth = width*0.5f;
1841 temp1 = (halfx-(halfx)*facf0);
1842 pointdist = sqrt(temp1*temp1 + temp1*temp1);
1844 temp2 = sqrt((halfx-x)*(halfx-x) + (halfy-y)*(halfy-y));
1845 if(temp2 > pointdist) output = in_band(wipezone,hwidth,fabs(temp2-pointdist),facf0,0,1);
1846 else output = in_band(wipezone,hwidth,fabs(temp2-pointdist),facf0,1,1);
1848 if(!wipe->forward) output = 1-output;
1852 if (output < 0) output = 0;
1853 else if(output > 1) output = 1;
1857 static void init_wipe_effect(Sequence *seq)
1859 if(seq->effectdata)MEM_freeN(seq->effectdata);
1860 seq->effectdata = MEM_callocN(sizeof(struct WipeVars), "wipevars");
1863 static int num_inputs_wipe()
1868 static void free_wipe_effect(Sequence *seq)
1870 if(seq->effectdata)MEM_freeN(seq->effectdata);
1871 seq->effectdata = 0;
1874 static void copy_wipe_effect(Sequence *dst, Sequence *src)
1876 dst->effectdata = MEM_dupallocN(src->effectdata);
1879 static void do_wipe_effect_byte(Sequence *seq, float facf0, float UNUSED(facf1),
1881 unsigned char *rect1,
1882 unsigned char *rect2, unsigned char *out)
1885 WipeVars *wipe = (WipeVars *)seq->effectdata;
1887 char *rt1, *rt2, *rt;
1889 precalc_wipe_zone(&wipezone, wipe, x, y);
1891 rt1 = (char *)rect1;
1892 rt2 = (char *)rect2;
1899 float check = check_zone(&wipezone,x,y,seq,facf0);
1902 rt[0] = (int)(rt1[0]*check)+ (int)(rt2[0]*(1-check));
1903 rt[1] = (int)(rt1[1]*check)+ (int)(rt2[1]*(1-check));
1904 rt[2] = (int)(rt1[2]*check)+ (int)(rt2[2]*(1-check));
1905 rt[3] = (int)(rt1[3]*check)+ (int)(rt2[3]*(1-check));
1937 static void do_wipe_effect_float(Sequence *seq, float facf0, float UNUSED(facf1),
1940 float *rect2, float *out)
1943 WipeVars *wipe = (WipeVars *)seq->effectdata;
1945 float *rt1, *rt2, *rt;
1947 precalc_wipe_zone(&wipezone, wipe, x, y);
1957 float check = check_zone(&wipezone,x,y,seq,facf0);
1960 rt[0] = rt1[0]*check+ rt2[0]*(1-check);
1961 rt[1] = rt1[1]*check+ rt2[1]*(1-check);
1962 rt[2] = rt1[2]*check+ rt2[2]*(1-check);
1963 rt[3] = rt1[3]*check+ rt2[3]*(1-check);
1995 static struct ImBuf * do_wipe_effect(
1996 Main *UNUSED(bmain), Scene *UNUSED(scene), Sequence *seq, float UNUSED(cfra),
1997 float facf0, float facf1, int x, int y,
1998 int UNUSED(preview_render_size),
1999 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
2000 struct ImBuf *ibuf3)
2002 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
2004 if (out->rect_float) {
2005 do_wipe_effect_float(seq,
2007 ibuf1->rect_float, ibuf2->rect_float,
2010 do_wipe_effect_byte(seq,
2012 (unsigned char*) ibuf1->rect, (unsigned char*) ibuf2->rect,
2013 (unsigned char*) out->rect);
2018 /* **********************************************************************
2020 ********************************************************************** */
2021 static void init_transform_effect(Sequence *seq)
2023 TransformVars *transform;
2025 if(seq->effectdata)MEM_freeN(seq->effectdata);
2026 seq->effectdata = MEM_callocN(sizeof(struct TransformVars), "transformvars");
2028 transform = (TransformVars *)seq->effectdata;
2030 transform->ScalexIni = 1.0f;
2031 transform->ScaleyIni = 1.0f;
2032 transform->ScalexFin = 1.0f;
2033 transform->ScalexFin = 1.0f;
2035 transform->xIni=0.0f;
2036 transform->xFin=0.0f;
2037 transform->yIni=0.0f;
2038 transform->yFin=0.0f;
2040 transform->rotIni=0.0f;
2041 transform->rotFin=0.0f;
2043 transform->interpolation=1;
2044 transform->percent=1;
2045 transform->uniform_scale=0;
2048 static int num_inputs_transform()
2053 static void free_transform_effect(Sequence *seq)
2055 if(seq->effectdata)MEM_freeN(seq->effectdata);
2056 seq->effectdata = 0;
2059 static void copy_transform_effect(Sequence *dst, Sequence *src)
2061 dst->effectdata = MEM_dupallocN(src->effectdata);
2064 static void transform_image(int x, int y, struct ImBuf *ibuf1, struct ImBuf *out,
2065 float scale_x, float scale_y, float translate_x, float translate_y,
2066 float rotate, int interpolation)
2069 float xt, yt, xr, yr;
2079 for (yi = 0; yi < yo; yi++) {
2080 for (xi = 0; xi < xo; xi++) {
2083 xt = xi-translate_x;
2084 yt = yi-translate_y;
2086 //rotate point with center ref
2090 //scale point with center ref
2094 //undo reference center point
2099 switch(interpolation) {
2101 neareast_interpolation(ibuf1,out, xt,yt,xi,yi);
2104 bilinear_interpolation(ibuf1,out, xt,yt,xi,yi);
2107 bicubic_interpolation(ibuf1,out, xt,yt,xi,yi);
2114 static void do_transform(Scene *scene, Sequence *seq, float UNUSED(facf0), int x, int y,
2115 struct ImBuf *ibuf1,struct ImBuf *out)
2117 TransformVars *transform = (TransformVars *)seq->effectdata;
2118 float scale_x, scale_y, translate_x, translate_y, rotate_radians;
2121 if (transform->uniform_scale) {
2122 scale_x = scale_y = transform->ScalexIni;
2124 scale_x = transform->ScalexIni;
2125 scale_y = transform->ScaleyIni;
2129 if(!transform->percent){
2130 float rd_s = (scene->r.size/100.0f);
2132 translate_x = transform->xIni*rd_s+(x/2.0f);
2133 translate_y = transform->yIni*rd_s+(y/2.0f);
2135 translate_x = x*(transform->xIni/100.0f)+(x/2.0f);
2136 translate_y = y*(transform->yIni/100.0f)+(y/2.0f);
2140 rotate_radians = (M_PI*transform->rotIni)/180.0f;
2142 transform_image(x,y, ibuf1, out, scale_x, scale_y, translate_x, translate_y, rotate_radians, transform->interpolation);
2146 static struct ImBuf * do_transform_effect(
2147 Main *UNUSED(bmain), Scene *scene, Sequence *seq,float UNUSED(cfra),
2148 float facf0, float UNUSED(facf1), int x, int y,
2149 int UNUSED(preview_render_size),
2150 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
2151 struct ImBuf *ibuf3)
2153 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
2155 do_transform(scene, seq, facf0, x, y, ibuf1, out);
2161 /* **********************************************************************
2163 ********************************************************************** */
2165 static void RVBlurBitmap2_byte ( unsigned char* map, int width,int height,
2168 /* MUUUCCH better than the previous blur. */
2169 /* We do the blurring in two passes which is a whole lot faster. */
2170 /* I changed the math arount to implement an actual Gaussian */
2173 /* Watch out though, it tends to misbehaven with large blur values on */
2174 /* a small bitmap. Avoid avoid avoid. */
2175 /*=============================== */
2177 unsigned char* temp=NULL,*swap;
2180 int index, ix, halfWidth;
2181 float fval, k, curColor[3], curColor2[3], weight=0;
2183 /* If we're not really blurring, bail out */
2187 /* Allocate memory for the tempmap and the blur filter matrix */
2188 temp= MEM_mallocN( (width*height*4), "blurbitmaptemp");
2192 /* Allocate memory for the filter elements */
2193 halfWidth = ((quality+1)*blur);
2194 filter = (float *)MEM_mallocN(sizeof(float)*halfWidth*2, "blurbitmapfilter");
2200 /* Apparently we're calculating a bell curve */
2201 /* based on the standard deviation (or radius) */
2202 /* This code is based on an example */
2203 /* posted to comp.graphics.algorithms by */
2204 /* Blancmange (bmange@airdmhor.gen.nz) */
2206 k = -1.0/(2.0*3.14159*blur*blur);
2208 for (ix = 0;ix< halfWidth;ix++){
2209 weight = (float)exp(k*(ix*ix));
2210 filter[halfWidth - ix] = weight;
2211 filter[halfWidth + ix] = weight;
2215 /* Normalize the array */
2217 for (ix = 0;ix< halfWidth*2;ix++)
2220 for (ix = 0;ix< halfWidth*2;ix++)
2224 for (y=0;y<height;y++){
2225 /* Do the left & right strips */
2226 for (x=0;x<halfWidth;x++){
2227 index=(x+y*width)*4;
2229 curColor[0]=curColor[1]=curColor[2]=0;
2230 curColor2[0]=curColor2[1]=curColor2[2]=0;
2232 for (i=x-halfWidth;i<x+halfWidth;i++){
2233 if ((i>=0)&&(i<width)){
2234 curColor[0]+=map[(i+y*width)*4+GlowR]*filter[fx];
2235 curColor[1]+=map[(i+y*width)*4+GlowG]*filter[fx];
2236 curColor[2]+=map[(i+y*width)*4+GlowB]*filter[fx];
2238 curColor2[0]+=map[(width-1-i+y*width)*4+GlowR] *
2240 curColor2[1]+=map[(width-1-i+y*width)*4+GlowG] *
2242 curColor2[2]+=map[(width-1-i+y*width)*4+GlowB] *
2247 temp[index+GlowR]=curColor[0];
2248 temp[index+GlowG]=curColor[1];
2249 temp[index+GlowB]=curColor[2];
2251 temp[((width-1-x+y*width)*4)+GlowR]=curColor2[0];
2252 temp[((width-1-x+y*width)*4)+GlowG]=curColor2[1];
2253 temp[((width-1-x+y*width)*4)+GlowB]=curColor2[2];
2256 /* Do the main body */
2257 for (x=halfWidth;x<width-halfWidth;x++){
2258 index=(x+y*width)*4;
2260 curColor[0]=curColor[1]=curColor[2]=0;
2261 for (i=x-halfWidth;i<x+halfWidth;i++){
2262 curColor[0]+=map[(i+y*width)*4+GlowR]*filter[fx];
2263 curColor[1]+=map[(i+y*width)*4+GlowG]*filter[fx];
2264 curColor[2]+=map[(i+y*width)*4+GlowB]*filter[fx];
2267 temp[index+GlowR]=curColor[0];
2268 temp[index+GlowG]=curColor[1];
2269 temp[index+GlowB]=curColor[2];
2274 swap=temp;temp=map;map=swap;
2277 /* Blur the columns */
2278 for (x=0;x<width;x++){
2279 /* Do the top & bottom strips */
2280 for (y=0;y<halfWidth;y++){
2281 index=(x+y*width)*4;
2283 curColor[0]=curColor[1]=curColor[2]=0;
2284 curColor2[0]=curColor2[1]=curColor2[2]=0;
2285 for (i=y-halfWidth;i<y+halfWidth;i++){
2286 if ((i>=0)&&(i<height)){
2288 curColor[0]+=map[(x+i*width)*4+GlowR]*filter[fy];
2289 curColor[1]+=map[(x+i*width)*4+GlowG]*filter[fy];
2290 curColor[2]+=map[(x+i*width)*4+GlowB]*filter[fy];
2293 curColor2[0]+=map[(x+(height-1-i)*width) *
2294 4+GlowR]*filter[fy];
2295 curColor2[1]+=map[(x+(height-1-i)*width) *
2296 4+GlowG]*filter[fy];
2297 curColor2[2]+=map[(x+(height-1-i)*width) *
2298 4+GlowB]*filter[fy];
2302 temp[index+GlowR]=curColor[0];
2303 temp[index+GlowG]=curColor[1];
2304 temp[index+GlowB]=curColor[2];
2305 temp[((x+(height-1-y)*width)*4)+GlowR]=curColor2[0];
2306 temp[((x+(height-1-y)*width)*4)+GlowG]=curColor2[1];
2307 temp[((x+(height-1-y)*width)*4)+GlowB]=curColor2[2];
2309 /* Do the main body */
2310 for (y=halfWidth;y<height-halfWidth;y++){
2311 index=(x+y*width)*4;
2313 curColor[0]=curColor[1]=curColor[2]=0;
2314 for (i=y-halfWidth;i<y+halfWidth;i++){
2315 curColor[0]+=map[(x+i*width)*4+GlowR]*filter[fy];
2316 curColor[1]+=map[(x+i*width)*4+GlowG]*filter[fy];
2317 curColor[2]+=map[(x+i*width)*4+GlowB]*filter[fy];
2320 temp[index+GlowR]=curColor[0];
2321 temp[index+GlowG]=curColor[1];
2322 temp[index+GlowB]=curColor[2];
2328 swap=temp;temp=map;map=swap;
2335 static void RVBlurBitmap2_float ( float* map, int width,int height,
2338 /* MUUUCCH better than the previous blur. */
2339 /* We do the blurring in two passes which is a whole lot faster. */
2340 /* I changed the math arount to implement an actual Gaussian */
2343 /* Watch out though, it tends to misbehaven with large blur values on */
2344 /* a small bitmap. Avoid avoid avoid. */
2345 /*=============================== */
2347 float* temp=NULL,*swap;
2350 int index, ix, halfWidth;
2351 float fval, k, curColor[3], curColor2[3], weight=0;
2353 /* If we're not really blurring, bail out */
2357 /* Allocate memory for the tempmap and the blur filter matrix */
2358 temp= MEM_mallocN( (width*height*4*sizeof(float)), "blurbitmaptemp");
2362 /* Allocate memory for the filter elements */
2363 halfWidth = ((quality+1)*blur);
2364 filter = (float *)MEM_mallocN(sizeof(float)*halfWidth*2, "blurbitmapfilter");
2370 /* Apparently we're calculating a bell curve */
2371 /* based on the standard deviation (or radius) */
2372 /* This code is based on an example */
2373 /* posted to comp.graphics.algorithms by */
2374 /* Blancmange (bmange@airdmhor.gen.nz) */
2376 k = -1.0/(2.0*3.14159*blur*blur);
2378 for (ix = 0;ix< halfWidth;ix++){
2379 weight = (float)exp(k*(ix*ix));
2380 filter[halfWidth - ix] = weight;
2381 filter[halfWidth + ix] = weight;
2385 /* Normalize the array */
2387 for (ix = 0;ix< halfWidth*2;ix++)
2390 for (ix = 0;ix< halfWidth*2;ix++)
2394 for (y=0;y<height;y++){
2395 /* Do the left & right strips */
2396 for (x=0;x<halfWidth;x++){
2397 index=(x+y*width)*4;
2399 curColor[0]=curColor[1]=curColor[2]=0.0f;
2400 curColor2[0]=curColor2[1]=curColor2[2]=0.0f;
2402 for (i=x-halfWidth;i<x+halfWidth;i++){
2403 if ((i>=0)&&(i<width)){
2404 curColor[0]+=map[(i+y*width)*4+GlowR]*filter[fx];
2405 curColor[1]+=map[(i+y*width)*4+GlowG]*filter[fx];
2406 curColor[2]+=map[(i+y*width)*4+GlowB]*filter[fx];
2408 curColor2[0]+=map[(width-1-i+y*width)*4+GlowR] *
2410 curColor2[1]+=map[(width-1-i+y*width)*4+GlowG] *
2412 curColor2[2]+=map[(width-1-i+y*width)*4+GlowB] *
2417 temp[index+GlowR]=curColor[0];
2418 temp[index+GlowG]=curColor[1];
2419 temp[index+GlowB]=curColor[2];
2421 temp[((width-1-x+y*width)*4)+GlowR]=curColor2[0];
2422 temp[((width-1-x+y*width)*4)+GlowG]=curColor2[1];
2423 temp[((width-1-x+y*width)*4)+GlowB]=curColor2[2];
2426 /* Do the main body */
2427 for (x=halfWidth;x<width-halfWidth;x++){
2428 index=(x+y*width)*4;
2430 curColor[0]=curColor[1]=curColor[2]=0;
2431 for (i=x-halfWidth;i<x+halfWidth;i++){
2432 curColor[0]+=map[(i+y*width)*4+GlowR]*filter[fx];
2433 curColor[1]+=map[(i+y*width)*4+GlowG]*filter[fx];
2434 curColor[2]+=map[(i+y*width)*4+GlowB]*filter[fx];
2437 temp[index+GlowR]=curColor[0];
2438 temp[index+GlowG]=curColor[1];
2439 temp[index+GlowB]=curColor[2];
2444 swap=temp;temp=map;map=swap;
2447 /* Blur the columns */
2448 for (x=0;x<width;x++){
2449 /* Do the top & bottom strips */
2450 for (y=0;y<halfWidth;y++){
2451 index=(x+y*width)*4;
2453 curColor[0]=curColor[1]=curColor[2]=0;
2454 curColor2[0]=curColor2[1]=curColor2[2]=0;
2455 for (i=y-halfWidth;i<y+halfWidth;i++){
2456 if ((i>=0)&&(i<height)){
2458 curColor[0]+=map[(x+i*width)*4+GlowR]*filter[fy];
2459 curColor[1]+=map[(x+i*width)*4+GlowG]*filter[fy];
2460 curColor[2]+=map[(x+i*width)*4+GlowB]*filter[fy];
2463 curColor2[0]+=map[(x+(height-1-i)*width) *
2464 4+GlowR]*filter[fy];
2465 curColor2[1]+=map[(x+(height-1-i)*width) *
2466 4+GlowG]*filter[fy];
2467 curColor2[2]+=map[(x+(height-1-i)*width) *
2468 4+GlowB]*filter[fy];
2472 temp[index+GlowR]=curColor[0];
2473 temp[index+GlowG]=curColor[1];
2474 temp[index+GlowB]=curColor[2];
2475 temp[((x+(height-1-y)*width)*4)+GlowR]=curColor2[0];
2476 temp[((x+(height-1-y)*width)*4)+GlowG]=curColor2[1];
2477 temp[((x+(height-1-y)*width)*4)+GlowB]=curColor2[2];
2479 /* Do the main body */
2480 for (y=halfWidth;y<height-halfWidth;y++){
2481 index=(x+y*width)*4;
2483 curColor[0]=curColor[1]=curColor[2]=0;
2484 for (i=y-halfWidth;i<y+halfWidth;i++){
2485 curColor[0]+=map[(x+i*width)*4+GlowR]*filter[fy];
2486 curColor[1]+=map[(x+i*width)*4+GlowG]*filter[fy];
2487 curColor[2]+=map[(x+i*width)*4+GlowB]*filter[fy];
2490 temp[index+GlowR]=curColor[0];
2491 temp[index+GlowG]=curColor[1];
2492 temp[index+GlowB]=curColor[2];
2498 swap=temp;temp=map;map=swap;
2506 /* Adds two bitmaps and puts the results into a third map. */
2507 /* C must have been previously allocated but it may be A or B. */
2508 /* We clamp values to 255 to prevent weirdness */
2509 /*=============================== */
2510 static void RVAddBitmaps_byte (unsigned char* a, unsigned char* b, unsigned char* c, int width, int height)
2514 for (y=0;y<height;y++){
2515 for (x=0;x<width;x++){
2516 index=(x+y*width)*4;
2517 c[index+GlowR]=MIN2(255,a[index+GlowR]+b[index+GlowR]);
2518 c[index+GlowG]=MIN2(255,a[index+GlowG]+b[index+GlowG]);
2519 c[index+GlowB]=MIN2(255,a[index+GlowB]+b[index+GlowB]);
2520 c[index+GlowA]=MIN2(255,a[index+GlowA]+b[index+GlowA]);
2525 static void RVAddBitmaps_float (float* a, float* b, float* c,
2526 int width, int height)
2530 for (y=0;y<height;y++){
2531 for (x=0;x<width;x++){
2532 index=(x+y*width)*4;
2533 c[index+GlowR]=MIN2(1.0,a[index+GlowR]+b[index+GlowR]);
2534 c[index+GlowG]=MIN2(1.0,a[index+GlowG]+b[index+GlowG]);
2535 c[index+GlowB]=MIN2(1.0,a[index+GlowB]+b[index+GlowB]);
2536 c[index+GlowA]=MIN2(1.0,a[index+GlowA]+b[index+GlowA]);
2541 /* For each pixel whose total luminance exceeds the threshold, */
2542 /* Multiply it's value by BOOST and add it to the output map */
2543 static void RVIsolateHighlights_byte (unsigned char* in, unsigned char* out,
2544 int width, int height, int threshold,
2545 float boost, float clamp)
2551 for(y=0;y< height;y++) {
2552 for (x=0;x< width;x++) {
2553 index= (x+y*width)*4;
2555 /* Isolate the intensity */
2556 intensity=(in[index+GlowR]+in[index+GlowG]+in[index+GlowB]-threshold);
2558 out[index+GlowR]=MIN2(255*clamp, (in[index+GlowR]*boost*intensity)/255);
2559 out[index+GlowG]=MIN2(255*clamp, (in[index+GlowG]*boost*intensity)/255);
2560 out[index+GlowB]=MIN2(255*clamp, (in[index+GlowB]*boost*intensity)/255);
2561 out[index+GlowA]=MIN2(255*clamp, (in[index+GlowA]*boost*intensity)/255);
2572 static void RVIsolateHighlights_float (float* in, float* out,
2573 int width, int height, float threshold,
2574 float boost, float clamp)
2580 for(y=0;y< height;y++) {
2581 for (x=0;x< width;x++) {
2582 index= (x+y*width)*4;
2584 /* Isolate the intensity */
2585 intensity=(in[index+GlowR]+in[index+GlowG]+in[index+GlowB]-threshold);
2587 out[index+GlowR]=MIN2(clamp, (in[index+GlowR]*boost*intensity));
2588 out[index+GlowG]=MIN2(clamp, (in[index+GlowG]*boost*intensity));
2589 out[index+GlowB]=MIN2(clamp, (in[index+GlowB]*boost*intensity));
2590 out[index+GlowA]=MIN2(clamp, (in[index+GlowA]*boost*intensity));
2601 static void init_glow_effect(Sequence *seq)
2605 if(seq->effectdata)MEM_freeN(seq->effectdata);
2606 seq->effectdata = MEM_callocN(sizeof(struct GlowVars), "glowvars");
2608 glow = (GlowVars *)seq->effectdata;
2617 static int num_inputs_glow()
2622 static void free_glow_effect(Sequence *seq)
2624 if(seq->effectdata)MEM_freeN(seq->effectdata);
2625 seq->effectdata = 0;
2628 static void copy_glow_effect(Sequence *dst, Sequence *src)
2630 dst->effectdata = MEM_dupallocN(src->effectdata);
2633 //void do_glow_effect(Cast *cast, float facf0, float facf1, int xo, int yo, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *outbuf, ImBuf *use)
2634 static void do_glow_effect_byte(Sequence *seq, float facf0, float UNUSED(facf1),
2635 int x, int y, char *rect1,
2636 char *rect2, char *out)
2638 unsigned char *outbuf=(unsigned char *)out;
2639 unsigned char *inbuf=(unsigned char *)rect1;
2640 GlowVars *glow = (GlowVars *)seq->effectdata;
2641 int size= 100; // renderdata XXX
2643 RVIsolateHighlights_byte(inbuf, outbuf , x, y, glow->fMini*765, glow->fBoost * facf0, glow->fClamp);
2644 RVBlurBitmap2_byte (outbuf, x, y, glow->dDist * (size / 100.0f),glow->dQuality);
2646 RVAddBitmaps_byte (inbuf , outbuf, outbuf, x, y);
2649 static void do_glow_effect_float(Sequence *seq, float facf0, float UNUSED(facf1),
2651 float *rect1, float *rect2, float *out)
2653 float *outbuf = out;
2654 float *inbuf = rect1;
2655 GlowVars *glow = (GlowVars *)seq->effectdata;
2656 int size= 100; // renderdata XXX
2658 RVIsolateHighlights_float(inbuf, outbuf , x, y, glow->fMini*3.0f, glow->fBoost * facf0, glow->fClamp);
2659 RVBlurBitmap2_float (outbuf, x, y, glow->dDist * (size / 100.0f),glow->dQuality);
2661 RVAddBitmaps_float (inbuf , outbuf, outbuf, x, y);
2664 static struct ImBuf * do_glow_effect(
2665 Main *UNUSED(bmain), Scene *UNUSED(scene), Sequence *seq, float UNUSED(cfra),
2666 float facf0, float facf1, int x, int y,
2667 int UNUSED(preview_render_size),
2668 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
2669 struct ImBuf *ibuf3)
2671 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
2673 if (out->rect_float) {
2674 do_glow_effect_float(seq,
2676 ibuf1->rect_float, ibuf2->rect_float,
2679 do_glow_effect_byte(seq,
2681 (char*) ibuf1->rect, (char*) ibuf2->rect,
2688 /* **********************************************************************
2690 ********************************************************************** */
2692 static void init_solid_color(Sequence *seq)
2696 if(seq->effectdata)MEM_freeN(seq->effectdata);
2697 seq->effectdata = MEM_callocN(sizeof(struct SolidColorVars), "solidcolor");
2699 cv = (SolidColorVars *)seq->effectdata;
2700 cv->col[0] = cv->col[1] = cv->col[2] = 0.5;
2703 static int num_inputs_color()
2708 static void free_solid_color(Sequence *seq)
2710 if(seq->effectdata)MEM_freeN(seq->effectdata);
2711 seq->effectdata = 0;
2714 static void copy_solid_color(Sequence *dst, Sequence *src)
2716 dst->effectdata = MEM_dupallocN(src->effectdata);
2719 static int early_out_color(struct Sequence *UNUSED(seq),
2720 float UNUSED(facf0), float UNUSED(facf1))
2725 static struct ImBuf * do_solid_color(
2726 Main *UNUSED(bmain), Scene *UNUSED(scene), Sequence *seq, float UNUSED(cfra),
2727 float facf0, float facf1, int x, int y,
2728 int UNUSED(preview_render_size),
2729 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
2730 struct ImBuf *ibuf3)
2732 struct ImBuf * out = prepare_effect_imbufs(x, y, ibuf1, ibuf2, ibuf3);
2734 SolidColorVars *cv = (SolidColorVars *)seq->effectdata;
2736 unsigned char *rect;
2740 unsigned char col0[3];
2741 unsigned char col1[3];
2743 col0[0] = facf0 * cv->col[0] * 255;
2744 col0[1] = facf0 * cv->col[1] * 255;
2745 col0[2] = facf0 * cv->col[2] * 255;
2747 col1[0] = facf1 * cv->col[0] * 255;
2748 col1[1] = facf1 * cv->col[1] * 255;
2749 col1[2] = facf1 * cv->col[2] * 255;
2751 rect = (unsigned char *)out->rect;
2753 for(y=0; y<out->y; y++) {
2754 for(x=0; x<out->x; x++, rect+=4) {
2762 for(x=0; x<out->x; x++, rect+=4) {
2771 } else if (out->rect_float) {
2775 col0[0] = facf0 * cv->col[0];
2776 col0[1] = facf0 * cv->col[1];
2777 col0[2] = facf0 * cv->col[2];
2779 col1[0] = facf1 * cv->col[0];
2780 col1[1] = facf1 * cv->col[1];
2781 col1[2] = facf1 * cv->col[2];
2783 rect_float = out->rect_float;
2785 for(y=0; y<out->y; y++) {
2786 for(x=0; x<out->x; x++, rect_float+=4) {
2787 rect_float[0]= col0[0];
2788 rect_float[1]= col0[1];
2789 rect_float[2]= col0[2];
2794 for(x=0; x<out->x; x++, rect_float+=4) {
2795 rect_float[0]= col1[0];
2796 rect_float[1]= col1[1];
2797 rect_float[2]= col1[2];
2806 /* **********************************************************************
2808 ********************************************************************** */
2810 /* no effect inputs for multicam, we use give_ibuf_seq */
2811 static int num_inputs_multicam()
2816 static int early_out_multicam(struct Sequence *UNUSED(seq), float UNUSED(facf0), float UNUSED(facf1))
2821 static struct ImBuf * do_multicam(
2822 Main *bmain, Scene *scene, Sequence *seq, float cfra,
2823 float UNUSED(facf0), float UNUSED(facf1), int x, int y,
2824 int preview_render_size,
2825 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
2826 struct ImBuf *ibuf3)
2831 ListBase * seqbasep;
2833 if (seq->multicam_source == 0 || seq->multicam_source >= seq->machine) {
2841 seqbasep = seq_seqbase(&ed->seqbase, seq);
2846 i = give_ibuf_seqbase(bmain, scene, x, y, cfra, seq->multicam_source,
2847 preview_render_size, seqbasep);
2852 if (input_have_to_preprocess(scene, seq, cfra, x, y)) {
2853 out = IMB_dupImBuf(i);
2862 /* **********************************************************************
2864 ********************************************************************** */
2865 static void init_speed_effect(Sequence *seq)
2867 SpeedControlVars * v;
2869 if(seq->effectdata) MEM_freeN(seq->effectdata);
2870 seq->effectdata = MEM_callocN(sizeof(struct SpeedControlVars),
2871 "speedcontrolvars");
2873 v = (SpeedControlVars *)seq->effectdata;
2874 v->globalSpeed = 1.0;
2876 v->flags |= SEQ_SPEED_INTEGRATE; /* should be default behavior */
2880 static void load_speed_effect(Sequence * seq)
2882 SpeedControlVars * v = (SpeedControlVars *)seq->effectdata;
2888 static int num_inputs_speed()
2893 static void free_speed_effect(Sequence *seq)
2895 SpeedControlVars * v = (SpeedControlVars *)seq->effectdata;
2896 if(v->frameMap) MEM_freeN(v->frameMap);
2897 if(seq->effectdata) MEM_freeN(seq->effectdata);
2898 seq->effectdata = 0;
2901 static void copy_speed_effect(Sequence *dst, Sequence *src)
2903 SpeedControlVars * v;
2904 dst->effectdata = MEM_dupallocN(src->effectdata);
2905 v = (SpeedControlVars *)dst->effectdata;
2910 static int early_out_speed(struct Sequence *UNUSED(seq),
2911 float UNUSED(facf0), float UNUSED(facf1))
2916 static void store_icu_yrange_speed(struct Sequence * seq,
2917 short adrcode, float * ymin, float * ymax)
2919 SpeedControlVars * v = (SpeedControlVars *)seq->effectdata;
2921 /* if not already done, load / initialize data */
2922 get_sequence_effect(seq);
2924 if ((v->flags & SEQ_SPEED_INTEGRATE) != 0) {
2928 if (v->flags & SEQ_SPEED_COMPRESS_IPO_Y) {
2937 void sequence_effect_speed_rebuild_map(Scene *scene, Sequence * seq, int force)
2940 float fallback_fac = 1.0f;
2941 SpeedControlVars * v = (SpeedControlVars *)seq->effectdata;
2944 /* if not already done, load / initialize data */
2945 get_sequence_effect(seq);
2947 if (!(force || seq->len != v->length || !v->frameMap)) {
2950 if (!seq->seq1) { /* make coverity happy and check for (CID 598)
2955 /* XXX - new in 2.5x. should we use the animation system this way?
2956 * The fcurve is needed because many frames need evaluating at once - campbell */
2957 fcu= id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "speed_factor", 0);
2960 if (!v->frameMap || v->length != seq->len) {
2961 if (v->frameMap) MEM_freeN(v->frameMap);
2963 v->length = seq->len;
2965 v->frameMap = MEM_callocN(sizeof(float) * v->length,
2966 "speedcontrol frameMap");
2969 /* if there is no fcurve, use value as simple multiplier */
2971 fallback_fac = seq->speed_fader; /* same as speed_factor in rna*/
2973 if (v->flags & SEQ_SPEED_INTEGRATE) {
2978 v->lastValidFrame = 0;
2980 for (cfra = 1; cfra < v->length; cfra++) {
2982 facf = evaluate_fcurve(fcu, seq->startdisp + cfra);
2984 facf = fallback_fac;
2986 facf *= v->globalSpeed;
2990 if (cursor >= seq->seq1->len) {
2991 v->frameMap[cfra] = seq->seq1->len - 1;
2993 v->frameMap[cfra] = cursor;
2994 v->lastValidFrame = cfra;
3000 v->lastValidFrame = 0;
3001 for (cfra = 0; cfra < v->length; cfra++) {
3004 facf = evaluate_fcurve(fcu, seq->startdisp + cfra);
3006 facf = fallback_fac;
3009 if (v->flags & SEQ_SPEED_COMPRESS_IPO_Y) {
3010 facf *= seq->seq1->len;
3012 facf *= v->globalSpeed;
3014 if (facf >= seq->seq1->len) {
3015 facf = seq->seq1->len - 1;
3017 v->lastValidFrame = cfra;
3019 v->frameMap[cfra] = facf;
3025 simply reuse do_cross_effect for blending...
3027 static void do_speed_effect(Sequence * seq,int cfra,
3028 float facf0, float facf1, int x, int y,
3029 struct ImBuf *ibuf1, struct ImBuf *ibuf2,
3030 struct ImBuf *ibuf3, struct ImBuf *out)
3037 /* **********************************************************************
3038 sequence effect factory
3039 ********************************************************************** */
3042 static void init_noop(struct Sequence *UNUSED(seq))