~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/src/sequence.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: sequence.c,v 1.8 2003/11/19 22:00:14 ton Exp $
 
2
 * $Id: sequence.c,v 1.24 2005/05/27 12:53:28 ton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
31
31
 */
32
32
 
33
33
#include <string.h>
 
34
#include <math.h>
 
35
#include <stdlib.h>
34
36
 
35
37
#ifdef HAVE_CONFIG_H
36
38
#include <config.h>
37
39
#endif
38
40
 
39
 
#ifdef WIN32
40
 
#include "BLI_winstuff.h"
41
 
#endif
42
 
 
43
41
#include "MEM_guardedalloc.h"
44
42
#include "PIL_dynlib.h"
45
43
 
62
60
#include "BKE_scene.h"
63
61
#include "BKE_ipo.h"
64
62
 
 
63
#include "BSE_filesel.h"
 
64
#include "BIF_interface.h"
 
65
#include "BSE_headerbuttons.h"
65
66
#include "BIF_screen.h"
66
 
#include "BIF_interface.h"
 
67
#include "BIF_space.h"
67
68
#include "BIF_toolbox.h"
68
 
#include "BSE_filesel.h"
69
 
#include "BSE_headerbuttons.h"
 
69
 
70
70
#include "BSE_sequence.h"
71
71
 
72
72
#include "blendef.h"
73
 
#include "render.h"
 
73
#include "render.h"             // talks to entire render API, and igamtab
74
74
 
75
75
Sequence *seq_arr[MAXSEQ+1];
76
76
int seqrectx, seqrecty;
81
81
{
82
82
        int (*version)();
83
83
        char *cp;
84
 
        
 
84
 
85
85
        /* to be sure: (is tested for) */
86
86
        pis->doit= 0;
87
87
        pis->pname= 0;
88
88
        pis->varstr= 0;
89
89
        pis->cfra= 0;
90
90
        pis->version= 0;
91
 
        
 
91
 
92
92
        /* clear the error list */
93
93
        PIL_dynlib_get_error_as_string(NULL);
94
 
        
 
94
 
95
95
        /* if(pis->handle) PIL_dynlib_close(pis->handle); */
96
96
        /* pis->handle= 0; */
97
97
 
98
98
        /* open the needed object */
99
99
        pis->handle= PIL_dynlib_open(pis->name);
100
100
        if(test_dlerr(pis->name, pis->name)) return;
101
 
        
 
101
 
102
102
        if (pis->handle != 0) {
103
103
                /* find the address of the version function */
104
104
                version= (int (*)())PIL_dynlib_find_symbol(pis->handle, "plugin_seq_getversion");
105
105
                if (test_dlerr(pis->name, "plugin_seq_getversion")) return;
106
 
                
 
106
 
107
107
                if (version != 0) {
108
108
                        pis->version= version();
109
109
                        if (pis->version==2 || pis->version==3) {
129
129
                                MEM_freeN(info);
130
130
 
131
131
                                cp= PIL_dynlib_find_symbol(pis->handle, "seqname");
132
 
                                if(cp) strcpy(cp, seqname);
 
132
                                if(cp) strncpy(cp, seqname, 21);
133
133
                        } else {
134
134
                                printf ("Plugin returned unrecognized version number\n");
135
135
                                return;
143
143
        PluginSeq *pis;
144
144
        VarStruct *varstr;
145
145
        int a;
146
 
        
 
146
 
147
147
        pis= MEM_callocN(sizeof(PluginSeq), "PluginSeq");
148
 
        
149
 
        strcpy(pis->name, str);
 
148
 
 
149
        strncpy(pis->name, str, FILE_MAXDIR+FILE_MAXFILE);
150
150
        open_plugin_seq(pis, seqname);
151
 
        
 
151
 
152
152
        if(pis->doit==0) {
153
153
                if(pis->handle==0) error("no plugin: %s", str);
154
154
                else error("in plugin: %s", str);
155
155
                MEM_freeN(pis);
156
156
                return 0;
157
157
        }
158
 
        
 
158
 
159
159
        /* default values */
160
160
        varstr= pis->varstr;
161
161
        for(a=0; a<pis->vars; a++, varstr++) {
172
172
{
173
173
 
174
174
        if(pis==0) return;
175
 
        
 
175
 
176
176
        /* no PIL_dynlib_close: same plugin can be opened multiple times with 1 handle */
177
 
        MEM_freeN(pis); 
 
177
        MEM_freeN(pis);
178
178
}
179
179
 
180
180
/* ***************** END PLUGIN ************************ */
185
185
        int a;
186
186
 
187
187
        seo= se;
188
 
        
 
188
 
189
189
        for(a=0; a<len; a++, se++) {
190
190
                if(se->ibuf && se->ok!=2) IMB_freeImBuf(se->ibuf);
191
191
        }
202
202
                printf("error: negative users in strip\n");
203
203
                return;
204
204
        }
205
 
        
 
205
 
206
206
        if(strip->stripdata) {
207
207
                free_stripdata(strip->len, strip->stripdata);
208
208
        }
223
223
void free_sequence(Sequence *seq)
224
224
{
225
225
        extern Sequence *last_seq;
226
 
        
 
226
 
227
227
        if(seq->strip) free_strip(seq->strip);
 
228
        if(seq->effectdata) MEM_freeN(seq->effectdata);
228
229
 
229
230
        if(seq->anim) IMB_free_anim(seq->anim);
230
 
        
 
231
 
231
232
        free_plugin_seq(seq->plugin);
232
 
        
 
233
 
233
234
        if(seq==last_seq) last_seq= 0;
234
 
        
 
235
 
235
236
        MEM_freeN(seq);
236
237
}
237
238
 
238
239
void do_seq_count(ListBase *seqbase, int *totseq)
239
240
{
240
241
        Sequence *seq;
241
 
        
 
242
 
242
243
        seq= seqbase->first;
243
244
        while(seq) {
244
245
                (*totseq)++;
250
251
void do_build_seqar(ListBase *seqbase, Sequence ***seqar, int depth)
251
252
{
252
253
        Sequence *seq;
253
 
        
 
254
 
254
255
        seq= seqbase->first;
255
256
        while(seq) {
256
257
                seq->depth= depth;
264
265
void build_seqar(ListBase *seqbase, Sequence  ***seqar, int *totseq)
265
266
{
266
267
        Sequence **tseqar;
267
 
        
 
268
 
268
269
        *totseq= 0;
269
270
        do_seq_count(seqbase, totseq);
270
 
        
 
271
 
271
272
        if(*totseq==0) {
272
273
                *seqar= 0;
273
274
                return;
274
275
        }
275
276
        *seqar= MEM_mallocN(sizeof(void *)* *totseq, "seqar");
276
277
        tseqar= *seqar;
277
 
        
 
278
 
278
279
        do_build_seqar(seqbase, seqar, 0);
279
280
        *seqar= tseqar;
280
281
}
283
284
{
284
285
        MetaStack *ms;
285
286
        Sequence *seq;
286
 
        
 
287
 
287
288
        if(ed==0) return;
288
289
 
289
290
        WHILE_SEQ(&ed->seqbase) {
290
291
                free_sequence(seq);
291
292
        }
292
293
        END_SEQ
293
 
        
 
294
 
294
295
        while( (ms= ed->metastack.first) ) {
295
296
                BLI_remlink(&ed->metastack, ms);
296
297
                MEM_freeN(ms);
297
298
        }
298
 
        
 
299
 
299
300
        MEM_freeN(ed);
300
301
}
301
302
 
303
304
{
304
305
        Sequence *seqm;
305
306
        int min, max;
306
 
        
 
307
 
307
308
        /* check all metas recursively */
308
309
        seqm= seq->seqbase.first;
309
310
        while(seqm) {
310
311
                if(seqm->seqbase.first) calc_sequence(seqm);
311
312
                seqm= seqm->next;
312
313
        }
313
 
        
 
314
 
314
315
        /* effects and meta: automatic start and end */
315
 
        
 
316
 
316
317
        if(seq->type & SEQ_EFFECT) {
317
318
                /* pointers */
318
319
                if(seq->seq2==0) seq->seq2= seq->seq1;
319
320
                if(seq->seq3==0) seq->seq3= seq->seq1;
320
 
        
 
321
 
321
322
                /* effecten go from seq1 -> seq2: test */
322
 
                
 
323
 
323
324
                /* we take the largest start and smallest end */
324
 
                
 
325
 
325
326
                // seq->start= seq->startdisp= MAX2(seq->seq1->startdisp, seq->seq2->startdisp);
326
327
                // seq->enddisp= MIN2(seq->seq1->enddisp, seq->seq2->enddisp);
327
328
 
328
329
                seq->start= seq->startdisp= MAX3(seq->seq1->startdisp, seq->seq2->startdisp, seq->seq3->startdisp);
329
330
                seq->enddisp= MIN3(seq->seq1->enddisp, seq->seq2->enddisp, seq->seq3->enddisp);
330
331
                seq->len= seq->enddisp - seq->startdisp;
331
 
                
 
332
 
332
333
                if(seq->strip && seq->len!=seq->strip->len) {
333
334
                        new_stripdata(seq);
334
335
                }
347
348
                                }
348
349
                                seq->start= min;
349
350
                                seq->len= max-min;
350
 
                
 
351
 
351
352
                                if(seq->strip && seq->len!=seq->strip->len) {
352
353
                                        new_stripdata(seq);
353
354
                                }
354
355
                        }
355
356
                }
356
 
                
357
 
                
 
357
 
 
358
 
358
359
                if(seq->startofs && seq->startstill) seq->startstill= 0;
359
360
                if(seq->endofs && seq->endstill) seq->endstill= 0;
360
 
        
 
361
 
361
362
                seq->startdisp= seq->start + seq->startofs - seq->startstill;
362
363
                seq->enddisp= seq->start+seq->len - seq->endofs + seq->endstill;
363
 
                
 
364
 
364
365
                seq->handsize= 10.0;    /* 10 frames */
365
366
                if( seq->enddisp-seq->startdisp < 20 ) {
366
367
                        seq->handsize= (float)(0.5*(seq->enddisp-seq->startdisp));
377
378
        ListBase seqbase, effbase;
378
379
        Editing *ed;
379
380
        Sequence *seq, *seqt;
380
 
        
 
381
 
381
382
        ed= G.scene->ed;
382
383
        if(ed==0) return;
383
 
        
 
384
 
384
385
        seqbase.first= seqbase.last= 0;
385
386
        effbase.first= effbase.last= 0;
386
 
        
 
387
 
387
388
        while( (seq= ed->seqbasep->first) ) {
388
389
                BLI_remlink(ed->seqbasep, seq);
389
 
                
 
390
 
390
391
                if(seq->type & SEQ_EFFECT) {
391
392
                        seqt= effbase.first;
392
393
                        while(seqt) {
410
411
                        if(seqt==0) BLI_addtail(&seqbase, seq);
411
412
                }
412
413
        }
413
 
        
 
414
 
414
415
        addlisttolist(&seqbase, &effbase);
415
416
        *(ed->seqbasep)= seqbase;
416
417
}
421
422
        Scene *sce1;
422
423
        Editing *ed;
423
424
        Sequence *seq;
424
 
        
 
425
 
425
426
        /* when a scene is deleted: test all seqs */
426
 
        
 
427
 
427
428
        sce1= G.main->scene.first;
428
429
        while(sce1) {
429
430
                if(sce1!=sce && sce1->ed) {
430
431
                        ed= sce1->ed;
431
 
                        
 
432
 
432
433
                        WHILE_SEQ(&ed->seqbase) {
433
 
                                
 
434
 
434
435
                                if(seq->scene==sce) seq->scene= 0;
435
 
                                
 
436
 
436
437
                        }
437
438
                        END_SEQ
438
439
                }
439
 
                
 
440
 
440
441
                sce1= sce1->id.next;
441
442
        }
442
443
}
448
449
        int fac2, mfac, fac, fac4;
449
450
        int xo, tempc;
450
451
        char *rt1, *rt2, *rt;
451
 
        
 
452
 
452
453
        xo= x;
453
454
        rt1= (char *)rect1;
454
455
        rt2= (char *)rect2;
455
456
        rt= (char *)out;
456
 
        
 
457
 
457
458
        fac2= (int)(256.0*facf0);
458
459
        fac4= (int)(256.0*facf1);
459
460
 
460
461
        while(y--) {
461
 
                        
 
462
 
462
463
                x= xo;
463
464
                while(x--) {
464
 
                        
465
 
                        /* rt = rt1 over rt2  (alpha from rt1) */       
466
 
                        
 
465
 
 
466
                        /* rt = rt1 over rt2  (alpha from rt1) */
 
467
 
467
468
                        fac= fac2;
468
469
                        mfac= 256 - ( (fac2*rt1[3])>>8 );
469
 
                        
 
470
 
470
471
                        if(fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2);
471
472
                        else if(mfac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt1);
472
473
                        else {
481
482
                        }
482
483
                        rt1+= 4; rt2+= 4; rt+= 4;
483
484
                }
484
 
                
 
485
 
485
486
                if(y==0) break;
486
487
                y--;
487
 
                
 
488
 
488
489
                x= xo;
489
490
                while(x--) {
490
 
                                
 
491
 
491
492
                        fac= fac4;
492
493
                        mfac= 256 - ( (fac4*rt1[3])>>8 );
493
 
                        
 
494
 
494
495
                        if(fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2);
495
496
                        else if(mfac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt1);
496
497
                        else {
513
514
        int fac2, mfac, fac, fac4;
514
515
        int xo;
515
516
        char *rt1, *rt2, *rt;
516
 
        
 
517
 
517
518
        xo= x;
518
519
        rt1= (char *)rect1;
519
520
        rt2= (char *)rect2;
520
521
        rt= (char *)out;
521
 
        
 
522
 
522
523
        fac2= (int)(256.0*facf0);
523
524
        fac4= (int)(256.0*facf1);
524
525
 
525
526
        while(y--) {
526
 
                        
 
527
 
527
528
                x= xo;
528
529
                while(x--) {
529
 
                        
 
530
 
530
531
                        /* rt = rt1 under rt2  (alpha from rt2) */
531
 
                        
532
 
                        /* this complex optimalisation is because the 
 
532
 
 
533
                        /* this complex optimalisation is because the
533
534
                         * 'skybuf' can be crossed in
534
535
                         */
535
536
                        if(rt2[3]==0 && fac2==256) *( (unsigned int *)rt) = *( (unsigned int *)rt1);
537
538
                        else {
538
539
                                mfac= rt2[3];
539
540
                                fac= (fac2*(256-mfac))>>8;
540
 
                                
 
541
 
541
542
                                if(fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2);
542
543
                                else {
543
544
                                        rt[0]= ( fac*rt1[0] + mfac*rt2[0])>>8;
560
561
                        else {
561
562
                                mfac= rt2[3];
562
563
                                fac= (fac4*(256-mfac))>>8;
563
 
                                
 
564
 
564
565
                                if(fac==0) *( (unsigned int *)rt) = *( (unsigned int *)rt2);
565
566
                                else {
566
567
                                        rt[0]= ( fac*rt1[0] + mfac*rt2[0])>>8;
580
581
        int fac1, fac2, fac3, fac4;
581
582
        int xo;
582
583
        char *rt1, *rt2, *rt;
583
 
        
 
584
 
584
585
        xo= x;
585
586
        rt1= (char *)rect1;
586
587
        rt2= (char *)rect2;
587
588
        rt= (char *)out;
588
 
        
 
589
 
589
590
        fac2= (int)(256.0*facf0);
590
591
        fac1= 256-fac2;
591
592
        fac4= (int)(256.0*facf1);
592
593
        fac3= 256-fac4;
593
 
        
 
594
 
594
595
        while(y--) {
595
 
                        
 
596
 
596
597
                x= xo;
597
598
                while(x--) {
598
 
        
 
599
 
599
600
                        rt[0]= (fac1*rt1[0] + fac2*rt2[0])>>8;
600
601
                        rt[1]= (fac1*rt1[1] + fac2*rt2[1])>>8;
601
602
                        rt[2]= (fac1*rt1[2] + fac2*rt2[2])>>8;
602
603
                        rt[3]= (fac1*rt1[3] + fac2*rt2[3])>>8;
603
 
                        
 
604
 
604
605
                        rt1+= 4; rt2+= 4; rt+= 4;
605
606
                }
606
 
                
 
607
 
607
608
                if(y==0) break;
608
609
                y--;
609
 
                
 
610
 
610
611
                x= xo;
611
612
                while(x--) {
612
 
        
 
613
 
613
614
                        rt[0]= (fac3*rt1[0] + fac4*rt2[0])>>8;
614
615
                        rt[1]= (fac3*rt1[1] + fac4*rt2[1])>>8;
615
616
                        rt[2]= (fac3*rt1[2] + fac4*rt2[2])>>8;
616
617
                        rt[3]= (fac3*rt1[3] + fac4*rt2[3])>>8;
617
 
                        
 
618
 
618
619
                        rt1+= 4; rt2+= 4; rt+= 4;
619
620
                }
620
 
                
 
621
 
621
622
        }
622
623
}
623
624
 
624
625
void do_gammacross_effect(float facf0, float facf1, int x, int y, unsigned int *rect1, unsigned int *rect2, unsigned int *out)
625
626
{
626
 
/*      extern unsigned short *igamtab1, *gamtab; render.h */
627
627
        int fac1, fac2, col;
628
628
        int xo;
629
629
        char *rt1, *rt2, *rt;
630
 
        
 
630
 
631
631
        xo= x;
632
632
        rt1= (char *)rect1;
633
633
        rt2= (char *)rect2;
634
634
        rt= (char *)out;
635
 
        
 
635
 
636
636
        fac2= (int)(256.0*facf0);
637
637
        fac1= 256-fac2;
638
 
        
 
638
 
639
639
        while(y--) {
640
 
                        
 
640
 
641
641
                x= xo;
642
642
                while(x--) {
643
 
        
 
643
 
644
644
                        col= (fac1*igamtab1[rt1[0]] + fac2*igamtab1[rt2[0]])>>8;
645
645
                        if(col>65535) rt[0]= 255; else rt[0]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
646
646
                        col=(fac1*igamtab1[rt1[1]] + fac2*igamtab1[rt2[1]])>>8;
649
649
                        if(col>65535) rt[2]= 255; else rt[2]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
650
650
                        col= (fac1*igamtab1[rt1[3]] + fac2*igamtab1[rt2[3]])>>8;
651
651
                        if(col>65535) rt[3]= 255; else rt[3]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
652
 
                        
 
652
 
653
653
                        rt1+= 4; rt2+= 4; rt+= 4;
654
654
                }
655
 
                
 
655
 
656
656
                if(y==0) break;
657
657
                y--;
658
 
                
 
658
 
659
659
                x= xo;
660
660
                while(x--) {
661
 
        
 
661
 
662
662
                        col= (fac1*igamtab1[rt1[0]] + fac2*igamtab1[rt2[0]])>>8;
663
663
                        if(col>65535) rt[0]= 255; else rt[0]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
664
664
                        col= (fac1*igamtab1[rt1[1]] + fac2*igamtab1[rt2[1]])>>8;
667
667
                        if(col>65535) rt[2]= 255; else rt[2]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
668
668
                        col= (fac1*igamtab1[rt1[3]] + fac2*igamtab1[rt2[3]])>>8;
669
669
                        if(col>65535) rt[3]= 255; else rt[3]= ( (char *)(gamtab+col))[MOST_SIG_BYTE];
670
 
                        
 
670
 
671
671
                        rt1+= 4; rt2+= 4; rt+= 4;
672
672
                }
673
 
                
 
673
 
674
674
        }
675
675
}
676
676
 
678
678
{
679
679
        int col, xo, fac1, fac3;
680
680
        char *rt1, *rt2, *rt;
681
 
        
 
681
 
682
682
        xo= x;
683
683
        rt1= (char *)rect1;
684
684
        rt2= (char *)rect2;
685
685
        rt= (char *)out;
686
 
        
 
686
 
687
687
        fac1= (int)(256.0*facf0);
688
688
        fac3= (int)(256.0*facf1);
689
 
        
 
689
 
690
690
        while(y--) {
691
 
                        
 
691
 
692
692
                x= xo;
693
693
                while(x--) {
694
694
 
700
700
                        if(col>255) rt[2]= 255; else rt[2]= col;
701
701
                        col= rt1[3]+ ((fac1*rt2[3])>>8);
702
702
                        if(col>255) rt[3]= 255; else rt[3]= col;
703
 
        
 
703
 
704
704
                        rt1+= 4; rt2+= 4; rt+= 4;
705
705
                }
706
706
 
707
707
                if(y==0) break;
708
708
                y--;
709
 
                
 
709
 
710
710
                x= xo;
711
711
                while(x--) {
712
 
        
 
712
 
713
713
                        col= rt1[0]+ ((fac3*rt2[0])>>8);
714
714
                        if(col>255) rt[0]= 255; else rt[0]= col;
715
715
                        col= rt1[1]+ ((fac3*rt2[1])>>8);
718
718
                        if(col>255) rt[2]= 255; else rt[2]= col;
719
719
                        col= rt1[3]+ ((fac3*rt2[3])>>8);
720
720
                        if(col>255) rt[3]= 255; else rt[3]= col;
721
 
        
 
721
 
722
722
                        rt1+= 4; rt2+= 4; rt+= 4;
723
723
                }
724
724
        }
728
728
{
729
729
        int col, xo, fac1, fac3;
730
730
        char *rt1, *rt2, *rt;
731
 
        
 
731
 
732
732
        xo= x;
733
733
        rt1= (char *)rect1;
734
734
        rt2= (char *)rect2;
735
735
        rt= (char *)out;
736
 
        
 
736
 
737
737
        fac1= (int)(256.0*facf0);
738
738
        fac3= (int)(256.0*facf1);
739
 
        
 
739
 
740
740
        while(y--) {
741
 
                        
 
741
 
742
742
                x= xo;
743
743
                while(x--) {
744
744
 
750
750
                        if(col<0) rt[2]= 0; else rt[2]= col;
751
751
                        col= rt1[3]- ((fac1*rt2[3])>>8);
752
752
                        if(col<0) rt[3]= 0; else rt[3]= col;
753
 
        
 
753
 
754
754
                        rt1+= 4; rt2+= 4; rt+= 4;
755
755
                }
756
756
 
757
757
                if(y==0) break;
758
758
                y--;
759
 
                
 
759
 
760
760
                x= xo;
761
761
                while(x--) {
762
 
        
 
762
 
763
763
                        col= rt1[0]- ((fac3*rt2[0])>>8);
764
764
                        if(col<0) rt[0]= 0; else rt[0]= col;
765
765
                        col= rt1[1]- ((fac3*rt2[1])>>8);
768
768
                        if(col<0) rt[2]= 0; else rt[2]= col;
769
769
                        col= rt1[3]- ((fac3*rt2[3])>>8);
770
770
                        if(col<0) rt[3]= 0; else rt[3]= col;
771
 
        
 
771
 
772
772
                        rt1+= 4; rt2+= 4; rt+= 4;
773
773
                }
774
774
        }
783
783
        int height, width, temp, fac, fac1, fac2;
784
784
        char *rt1, *rt2, *out;
785
785
        int field= 1;
786
 
        
 
786
 
787
787
        width= x;
788
788
        height= y;
789
 
                
 
789
 
790
790
        fac1= (int)(70.0*facf0);
791
791
        fac2= (int)(70.0*facf1);
792
 
        
 
792
 
793
793
        rt2= (char*) (rect2i + YOFF*width);
794
794
        rt1= (char*) rect1i;
795
795
        out= (char*) outi;
796
796
        for (y=0; y<height-YOFF; y++) {
797
 
                if(field) fac= fac1; 
 
797
                if(field) fac= fac1;
798
798
                else fac= fac2;
799
799
                field= !field;
800
800
 
822
822
        int col, xo, yo, temp, fac1, fac3;
823
823
        int xofs= -8, yofs= 8;
824
824
        char *rt1, *rt2, *rt;
825
 
        
 
825
 
826
826
        xo= x;
827
827
        yo= y;
828
 
        
 
828
 
829
829
        rt2= (char *)(rect2 + yofs*x + xofs);
830
 
        
 
830
 
831
831
        rt1= (char *)rect1;
832
832
        rt= (char *)out;
833
 
        
 
833
 
834
834
        fac1= (int)(70.0*facf0);
835
835
        fac3= (int)(70.0*facf1);
836
 
        
 
836
 
837
837
        while(y-- > 0) {
838
 
                
 
838
 
839
839
                temp= y-yofs;
840
840
                if(temp > 0 && temp < yo) {
841
 
                
 
841
 
842
842
                        x= xo;
843
843
                        while(x--) {
844
 
                                        
 
844
 
845
845
                                temp= x+xofs;
846
846
                                if(temp > 0 && temp < xo) {
847
 
                                
 
847
 
848
848
                                        temp= ((fac1*rt2[3])>>8);
849
 
                
 
849
 
850
850
                                        col= rt1[0]- temp;
851
851
                                        if(col<0) rt[0]= 0; else rt[0]= col;
852
852
                                        col= rt1[1]- temp;
856
856
                                        col= rt1[3]- temp;
857
857
                                        if(col<0) rt[3]= 0; else rt[3]= col;
858
858
                                }
859
 
                                else *( (unsigned int *)rt) = *( (unsigned int *)rt1);  
860
 
                                
 
859
                                else *( (unsigned int *)rt) = *( (unsigned int *)rt1);
 
860
 
861
861
                                rt1+= 4; rt2+= 4; rt+= 4;
862
862
                        }
863
863
                }
864
864
                else {
865
865
                        x= xo;
866
866
                        while(x--) {
867
 
                                *( (unsigned int *)rt) = *( (unsigned int *)rt1);       
 
867
                                *( (unsigned int *)rt) = *( (unsigned int *)rt1);
868
868
                                rt1+= 4; rt2+= 4; rt+= 4;
869
869
                        }
870
870
                }
871
 
        
 
871
 
872
872
                if(y==0) break;
873
873
                y--;
874
 
                        
 
874
 
875
875
                temp= y-yofs;
876
876
                if(temp > 0 && temp < yo) {
877
 
                        
 
877
 
878
878
                        x= xo;
879
879
                        while(x--) {
880
 
                                
 
880
 
881
881
                                temp= x+xofs;
882
882
                                if(temp > 0 && temp < xo) {
883
 
                                
 
883
 
884
884
                                        temp= ((fac3*rt2[3])>>8);
885
 
                                        
 
885
 
886
886
                                        col= rt1[0]- temp;
887
887
                                        if(col<0) rt[0]= 0; else rt[0]= col;
888
888
                                        col= rt1[1]- temp;
892
892
                                        col= rt1[3]- temp;
893
893
                                        if(col<0) rt[3]= 0; else rt[3]= col;
894
894
                                }
895
 
                                else *( (unsigned int *)rt) = *( (unsigned int *)rt1);  
896
 
                                
 
895
                                else *( (unsigned int *)rt) = *( (unsigned int *)rt1);
 
896
 
897
897
                                rt1+= 4; rt2+= 4; rt+= 4;
898
898
                        }
899
899
                }
900
900
                else {
901
901
                        x= xo;
902
902
                        while(x--) {
903
 
                                *( (unsigned int *)rt) = *( (unsigned int *)rt1);       
 
903
                                *( (unsigned int *)rt) = *( (unsigned int *)rt1);
904
904
                                rt1+= 4; rt2+= 4; rt+= 4;
905
905
                        }
906
906
                }
912
912
{
913
913
        int  xo, fac1, fac3;
914
914
        char *rt1, *rt2, *rt;
915
 
        
 
915
 
916
916
        xo= x;
917
917
        rt1= (char *)rect1;
918
918
        rt2= (char *)rect2;
919
919
        rt= (char *)out;
920
 
        
 
920
 
921
921
        fac1= (int)(256.0*facf0);
922
922
        fac3= (int)(256.0*facf1);
923
 
        
 
923
 
924
924
        /* formula:
925
925
         *              fac*(a*b) + (1-fac)*a  => fac*a*(b-1)+a
926
926
         */
927
 
        
 
927
 
928
928
        while(y--) {
929
 
                        
 
929
 
930
930
                x= xo;
931
931
                while(x--) {
932
 
                        
 
932
 
933
933
                        rt[0]= rt1[0] + ((fac1*rt1[0]*(rt2[0]-256))>>16);
934
934
                        rt[1]= rt1[1] + ((fac1*rt1[1]*(rt2[1]-256))>>16);
935
935
                        rt[2]= rt1[2] + ((fac1*rt1[2]*(rt2[2]-256))>>16);
940
940
 
941
941
                if(y==0) break;
942
942
                y--;
943
 
                
 
943
 
944
944
                x= xo;
945
945
                while(x--) {
946
 
        
 
946
 
947
947
                        rt[0]= rt1[0] + ((fac3*rt1[0]*(rt2[0]-256))>>16);
948
948
                        rt[1]= rt1[1] + ((fac3*rt1[1]*(rt2[1]-256))>>16);
949
949
                        rt[2]= rt1[2] + ((fac3*rt1[2]*(rt2[2]-256))>>16);
950
950
                        rt[3]= rt1[3] + ((fac3*rt1[3]*(rt2[3]-256))>>16);
951
 
        
 
951
 
952
952
                        rt1+= 4; rt2+= 4; rt+= 4;
953
953
                }
954
954
        }
955
955
}
956
956
 
 
957
// This function calculates the blur band for the wipe effects
 
958
float in_band(float width,float dist, float perc,int side,int dir){
 
959
        
 
960
        float t1,t2,alpha,percwidth;
 
961
        if(width == 0)
 
962
                return (float)side;
 
963
        if(side == 1)
 
964
                percwidth = width * perc;
 
965
        else
 
966
                percwidth = width * (1 - perc);
 
967
        
 
968
        if(width < dist)
 
969
                return side;
 
970
        
 
971
        t1 = dist / width;  //percentange of width that is
 
972
        t2 = 1 / width;  //amount of alpha per % point
 
973
        
 
974
        if(side == 1)
 
975
                alpha = (t1*t2*100) + (1-perc); // add point's alpha contrib to current position in wipe
 
976
        else
 
977
                alpha = (1-perc) - (t1*t2*100);
 
978
        
 
979
        if(dir == 0)
 
980
                alpha = 1-alpha;
 
981
        return alpha;
 
982
}
 
983
 
 
984
float check_zone(int x, int y, int xo, int yo, Sequence *seq, float facf0) {
 
985
 
 
986
   float posx, posy,hyp,hyp2,angle,hwidth,b1,b2,b3,pointdist;
 
987
   /*some future stuff
 
988
   float hyp3,hyp4,b4,b5           
 
989
   */
 
990
   float temp1,temp2,temp3,temp4; //some placeholder variables
 
991
   float halfx = xo/2;
 
992
   float halfy = yo/2;
 
993
   float widthf,output=0;
 
994
   WipeVars *wipe = (WipeVars *)seq->effectdata;
 
995
   int width;
 
996
 
 
997
        angle = wipe->angle;
 
998
        if(angle < 0){
 
999
                x = xo-x;
 
1000
                //y = yo-y
 
1001
                }
 
1002
        angle = pow(fabs(angle)/45,log(xo)/log(2));
 
1003
 
 
1004
        posy = facf0 * yo;
 
1005
        if(wipe->forward){
 
1006
                posx = facf0 * xo;
 
1007
                posy = facf0 * yo;
 
1008
        } else{
 
1009
                posx = xo - facf0 * xo;
 
1010
                posy = yo - facf0 * yo;
 
1011
        }
 
1012
   switch (wipe->wipetype) {
 
1013
       case DO_SINGLE_WIPE:
 
1014
         width = (int)(wipe->edgeWidth*((xo+yo)/2.0));
 
1015
         hwidth = (float)width/2.0;       
 
1016
                
 
1017
         if (angle == 0.0)angle = 0.000001;
 
1018
         b1 = posy - (-angle)*posx;
 
1019
         b2 = y - (-angle)*x;
 
1020
         hyp  = fabs(angle*x+y+(-posy-angle*posx))/sqrt(angle*angle+1);
 
1021
         if(angle < 0){
 
1022
                 temp1 = b1;
 
1023
                 b1 = b2;
 
1024
                 b2 = temp1;
 
1025
         }
 
1026
         if(wipe->forward){      
 
1027
                     if(b1 < b2)
 
1028
                                output = in_band(width,hyp,facf0,1,1);
 
1029
                 else
 
1030
                                output = in_band(width,hyp,facf0,0,1);
 
1031
                 }
 
1032
                 else{   
 
1033
                 if(b1 < b2)
 
1034
                                output = in_band(width,hyp,facf0,0,1);
 
1035
                 else
 
1036
                                output = in_band(width,hyp,facf0,1,1);
 
1037
                 }
 
1038
                 break;
 
1039
         
 
1040
         
 
1041
          case DO_DOUBLE_WIPE:
 
1042
                 if(!wipe->forward)facf0 = 1-facf0;   // Go the other direction
 
1043
 
 
1044
             width = (int)(wipe->edgeWidth*((xo+yo)/2.0));  // calculate the blur width
 
1045
             hwidth = (float)width/2.0;       
 
1046
             if (angle == 0)angle = 0.000001;
 
1047
             b1 = posy/2 - (-angle)*posx/2;
 
1048
             b3 = (yo-posy/2) - (-angle)*(xo-posx/2);
 
1049
             b2 = y - (-angle)*x;
 
1050
 
 
1051
             hyp = abs(angle*x+y+(-posy/2-angle*posx/2))/sqrt(angle*angle+1);
 
1052
             hyp2 = abs(angle*x+y+(-(yo-posy/2)-angle*(xo-posx/2)))/sqrt(angle*angle+1);
 
1053
             
 
1054
             temp1 = xo*(1-facf0/2)-xo*facf0/2;
 
1055
             temp2 = yo*(1-facf0/2)-yo*facf0/2;
 
1056
                 pointdist = sqrt(temp1*temp1 + temp2*temp2);
 
1057
 
 
1058
                         if(b2 < b1 && b2 < b3 ){
 
1059
                                if(hwidth < pointdist)
 
1060
                                        output = in_band(hwidth,hyp,facf0,0,1);
 
1061
                        }
 
1062
                         else if(b2 > b1 && b2 > b3 ){
 
1063
                                if(hwidth < pointdist)
 
1064
                                        output = in_band(hwidth,hyp2,facf0,0,1);        
 
1065
                        } 
 
1066
                     else{
 
1067
                         if(  hyp < hwidth && hyp2 > hwidth )
 
1068
                                 output = in_band(hwidth,hyp,facf0,1,1);
 
1069
                         else if(  hyp > hwidth && hyp2 < hwidth )
 
1070
                                         output = in_band(hwidth,hyp2,facf0,1,1);
 
1071
                                 else
 
1072
                                         output = in_band(hwidth,hyp2,facf0,1,1) * in_band(hwidth,hyp,facf0,1,1);
 
1073
                     }
 
1074
                     if(!wipe->forward)output = 1-output;
 
1075
         break;     
 
1076
         case DO_CLOCK_WIPE:
 
1077
                        /*
 
1078
                                temp1: angle of effect center in rads
 
1079
                                temp2: angle of line through (halfx,halfy) and (x,y) in rads
 
1080
                                temp3: angle of low side of blur
 
1081
                                temp4: angle of high side of blur
 
1082
                        */
 
1083
                        output = 1-facf0;
 
1084
                        widthf = wipe->edgeWidth*2*3.14159;
 
1085
                        temp1 = 2 * 3.14159 * facf0;
 
1086
                        
 
1087
                        if(wipe->forward){
 
1088
                                temp1 = 2*3.14159-temp1;
 
1089
                        }
 
1090
                        
 
1091
                        x = x - halfx;
 
1092
                        y = y - halfy;
 
1093
 
 
1094
                        temp2 = asin(abs(y)/sqrt(x*x + y*y));
 
1095
                        if(x <= 0 && y >= 0)
 
1096
                                temp2 = 3.14159 - temp2;
 
1097
                        else if(x<=0 && y <= 0)
 
1098
                                temp2 += 3.14159;
 
1099
                        else if(x >= 0 && y <= 0)
 
1100
                                temp2 = 2*3.14159 - temp2;
 
1101
                        
 
1102
                        if(wipe->forward){
 
1103
                                temp3 = temp1-(widthf/2)*facf0;
 
1104
                                temp4 = temp1+(widthf/2)*(1-facf0);
 
1105
                        }
 
1106
                        else{
 
1107
                                temp3 = temp1-(widthf/2)*(1-facf0);
 
1108
                                temp4 = temp1+(widthf/2)*facf0;
 
1109
                        }
 
1110
                        if (temp3 < 0)  temp3 = 0;
 
1111
                        if (temp4 > 2*3.14159) temp4 = 2*3.14159;
 
1112
                        
 
1113
                        
 
1114
                        if(temp2 < temp3)
 
1115
                                output = 0;
 
1116
                        else if (temp2 > temp4)
 
1117
                                output = 1;
 
1118
                        else
 
1119
                                output = (temp2-temp3)/(temp4-temp3);
 
1120
                        if(x == 0 && y == 0){
 
1121
                                output = 1;
 
1122
                        }
 
1123
                        if(output != output)
 
1124
                                output = 1;
 
1125
                        if(wipe->forward)
 
1126
                                output = 1 - output;
 
1127
        break;
 
1128
        /* BOX WIPE IS NOT WORKING YET */
 
1129
     /* case DO_CROSS_WIPE: */
 
1130
        /* BOX WIPE IS NOT WORKING YET */
 
1131
     /* case DO_BOX_WIPE: 
 
1132
                 if(invert)facf0 = 1-facf0;
 
1133
 
 
1134
             width = (int)(wipe->edgeWidth*((xo+yo)/2.0));
 
1135
             hwidth = (float)width/2.0;       
 
1136
             if (angle == 0)angle = 0.000001;
 
1137
             b1 = posy/2 - (-angle)*posx/2;
 
1138
             b3 = (yo-posy/2) - (-angle)*(xo-posx/2);
 
1139
             b2 = y - (-angle)*x;
 
1140
 
 
1141
             hyp = abs(angle*x+y+(-posy/2-angle*posx/2))/sqrt(angle*angle+1);
 
1142
             hyp2 = abs(angle*x+y+(-(yo-posy/2)-angle*(xo-posx/2)))/sqrt(angle*angle+1);
 
1143
             
 
1144
             temp1 = xo*(1-facf0/2)-xo*facf0/2;
 
1145
             temp2 = yo*(1-facf0/2)-yo*facf0/2;
 
1146
                 pointdist = sqrt(temp1*temp1 + temp2*temp2);
 
1147
 
 
1148
                         if(b2 < b1 && b2 < b3 ){
 
1149
                                if(hwidth < pointdist)
 
1150
                                        output = in_band(hwidth,hyp,facf0,0,1);
 
1151
                        }
 
1152
                         else if(b2 > b1 && b2 > b3 ){
 
1153
                                if(hwidth < pointdist)
 
1154
                                        output = in_band(hwidth,hyp2,facf0,0,1);        
 
1155
                        } 
 
1156
                     else{
 
1157
                         if(  hyp < hwidth && hyp2 > hwidth )
 
1158
                                 output = in_band(hwidth,hyp,facf0,1,1);
 
1159
                         else if(  hyp > hwidth && hyp2 < hwidth )
 
1160
                                         output = in_band(hwidth,hyp2,facf0,1,1);
 
1161
                                 else
 
1162
                                         output = in_band(hwidth,hyp2,facf0,1,1) * in_band(hwidth,hyp,facf0,1,1);
 
1163
                     }
 
1164
                 if(invert)facf0 = 1-facf0;
 
1165
             angle = -1/angle;
 
1166
             b1 = posy/2 - (-angle)*posx/2;
 
1167
             b3 = (yo-posy/2) - (-angle)*(xo-posx/2);
 
1168
             b2 = y - (-angle)*x;
 
1169
 
 
1170
             hyp = abs(angle*x+y+(-posy/2-angle*posx/2))/sqrt(angle*angle+1);
 
1171
             hyp2 = abs(angle*x+y+(-(yo-posy/2)-angle*(xo-posx/2)))/sqrt(angle*angle+1);
 
1172
           
 
1173
                 if(b2 < b1 && b2 < b3 ){
 
1174
                                if(hwidth < pointdist)
 
1175
                                        output *= in_band(hwidth,hyp,facf0,0,1);
 
1176
                        }
 
1177
                         else if(b2 > b1 && b2 > b3 ){
 
1178
                                if(hwidth < pointdist)
 
1179
                                        output *= in_band(hwidth,hyp2,facf0,0,1);       
 
1180
                        } 
 
1181
                     else{
 
1182
                         if(  hyp < hwidth && hyp2 > hwidth )
 
1183
                                 output *= in_band(hwidth,hyp,facf0,1,1);
 
1184
                         else if(  hyp > hwidth && hyp2 < hwidth )
 
1185
                                         output *= in_band(hwidth,hyp2,facf0,1,1);
 
1186
                                 else
 
1187
                                         output *= in_band(hwidth,hyp2,facf0,1,1) * in_band(hwidth,hyp,facf0,1,1);
 
1188
                     }
 
1189
                     
 
1190
         break;*/
 
1191
      case DO_IRIS_WIPE:
 
1192
         if(xo > yo) yo = xo;
 
1193
         else xo = yo;
 
1194
         
 
1195
                if(!wipe->forward)
 
1196
                        facf0 = 1-facf0;
 
1197
 
 
1198
             width = (int)(wipe->edgeWidth*((xo+yo)/2.0));
 
1199
             hwidth = (float)width/2.0; 
 
1200
             
 
1201
         temp1 = (halfx-(halfx)*facf0);     
 
1202
                 pointdist = sqrt(temp1*temp1 + temp1*temp1);
 
1203
                 
 
1204
                 temp2 = sqrt((halfx-x)*(halfx-x)  +  (halfy-y)*(halfy-y));
 
1205
                 if(temp2 > pointdist)
 
1206
                         output = in_band(hwidth,fabs(temp2-pointdist),facf0,0,1);
 
1207
                 else
 
1208
                         output = in_band(hwidth,fabs(temp2-pointdist),facf0,1,1);
 
1209
                 
 
1210
                if(!wipe->forward)
 
1211
                        output = 1-output;
 
1212
                        
 
1213
         break;
 
1214
   }
 
1215
   if     (output < 0) output = 0;
 
1216
   else if(output > 1) output = 1;
 
1217
   return output;
 
1218
}
 
1219
 
 
1220
void init_wipe_effect(Sequence *seq)
 
1221
{
 
1222
        if(seq->effectdata)MEM_freeN(seq->effectdata);
 
1223
        seq->effectdata = MEM_callocN(sizeof(struct WipeVars), "wipevars");
 
1224
}
 
1225
 
 
1226
void do_wipe_effect(Sequence *seq, float facf0, float facf1, int x, int y, unsigned int *rect1, unsigned int *rect2, unsigned int *out)
 
1227
{
 
1228
        int xo, yo;
 
1229
        char *rt1, *rt2, *rt;
 
1230
        rt1 = (char *)rect1;
 
1231
        rt2 = (char *)rect2;
 
1232
        rt = (char *)out;
 
1233
 
 
1234
        xo = x;
 
1235
        yo = y;
 
1236
        for(y=0;y<yo;y++) {
 
1237
 
 
1238
      for(x=0;x<xo;x++) {
 
1239
                        float check = check_zone(x,y,xo,yo,seq,facf0);
 
1240
                        if (check) {
 
1241
                                if (rt1) {
 
1242
                                        rt[0] = (int)(rt1[0]*check)+ (int)(rt2[0]*(1-check));
 
1243
                                        rt[1] = (int)(rt1[1]*check)+ (int)(rt2[1]*(1-check));
 
1244
                                        rt[2] = (int)(rt1[2]*check)+ (int)(rt2[2]*(1-check));
 
1245
                                        rt[3] = (int)(rt1[3]*check)+ (int)(rt2[3]*(1-check));
 
1246
                                } else {
 
1247
                                        rt[0] = 0;
 
1248
                                        rt[1] = 0;
 
1249
                                        rt[2] = 0;
 
1250
                                        rt[3] = 255;
 
1251
                                }
 
1252
                        } else {
 
1253
                                if (rt2) {
 
1254
                                        rt[0] = rt2[0];
 
1255
                                        rt[1] = rt2[1];
 
1256
                                        rt[2] = rt2[2];
 
1257
                                        rt[3] = rt2[3];
 
1258
                                } else {
 
1259
                                        rt[0] = 0;
 
1260
                                        rt[1] = 0;
 
1261
                                        rt[2] = 0;
 
1262
                                        rt[3] = 255;
 
1263
                                }
 
1264
                        }
 
1265
 
 
1266
                        rt+=4;
 
1267
                        if(rt1 !=NULL){
 
1268
                                rt1+=4;
 
1269
                        }
 
1270
                        if(rt2 !=NULL){
 
1271
                                rt2+=4;
 
1272
                        }
 
1273
                }
 
1274
        }
 
1275
}
 
1276
 
 
1277
/* Glow Functions */
 
1278
 
 
1279
void RVBlurBitmap2 ( unsigned char* map, int width,int height,float blur,
 
1280
   int quality)
 
1281
/*      MUUUCCH better than the previous blur. */
 
1282
/*      We do the blurring in two passes which is a whole lot faster. */
 
1283
/*      I changed the math arount to implement an actual Gaussian */
 
1284
/*      distribution. */
 
1285
/* */
 
1286
/*      Watch out though, it tends to misbehaven with large blur values on */
 
1287
/*      a small bitmap.  Avoid avoid avoid. */
 
1288
/*=============================== */
 
1289
{
 
1290
        unsigned char*  temp=NULL,*swap;
 
1291
        float   *filter=NULL;
 
1292
        int     x,y,i,fx,fy;
 
1293
        int     index, ix, halfWidth;
 
1294
        float   fval, k, curColor[3], curColor2[3], weight=0;
 
1295
 
 
1296
        /*      If we're not really blurring, bail out */
 
1297
        if (blur<=0)
 
1298
                return;
 
1299
 
 
1300
        /*      Allocate memory for the tempmap and the blur filter matrix */
 
1301
        temp= MEM_mallocN( (width*height*4), "blurbitmaptemp");
 
1302
        if (!temp)
 
1303
                return;
 
1304
 
 
1305
        /*      Allocate memory for the filter elements */
 
1306
        halfWidth = ((quality+1)*blur);
 
1307
        filter = (float *)MEM_mallocN(sizeof(float)*halfWidth*2, "blurbitmapfilter");
 
1308
        if (!filter){
 
1309
                MEM_freeN (temp);
 
1310
                return;
 
1311
        }
 
1312
 
 
1313
        /*      Apparently we're calculating a bell curve */
 
1314
        /*      based on the standard deviation (or radius) */
 
1315
        /*      This code is based on an example */
 
1316
        /*      posted to comp.graphics.algorithms by */
 
1317
        /*      Blancmange (bmange@airdmhor.gen.nz) */
 
1318
 
 
1319
        k = -1.0/(2.0*3.14159*blur*blur);
 
1320
        fval=0;
 
1321
        for (ix = 0;ix< halfWidth;ix++){
 
1322
                weight = (float)exp(k*(ix*ix));
 
1323
                filter[halfWidth - ix] = weight;
 
1324
                filter[halfWidth + ix] = weight;
 
1325
        }
 
1326
        filter[0] = weight;
 
1327
 
 
1328
        /*      Normalize the array */
 
1329
        fval=0;
 
1330
        for (ix = 0;ix< halfWidth*2;ix++)
 
1331
                fval+=filter[ix];
 
1332
 
 
1333
        for (ix = 0;ix< halfWidth*2;ix++)
 
1334
                filter[ix]/=fval;
 
1335
 
 
1336
        /*      Blur the rows */
 
1337
        for (y=0;y<height;y++){
 
1338
                /*      Do the left & right strips */
 
1339
                for (x=0;x<halfWidth;x++){
 
1340
                        index=(x+y*width)*4;
 
1341
                        fx=0;
 
1342
                        curColor[0]=curColor[1]=curColor[2]=0;
 
1343
                        curColor2[0]=curColor2[1]=curColor2[2]=0;
 
1344
 
 
1345
                        for (i=x-halfWidth;i<x+halfWidth;i++){
 
1346
                           if ((i>=0)&&(i<width)){
 
1347
                                curColor[0]+=map[(i+y*width)*4+GlowR]*filter[fx];
 
1348
                                curColor[1]+=map[(i+y*width)*4+GlowG]*filter[fx];
 
1349
                                curColor[2]+=map[(i+y*width)*4+GlowB]*filter[fx];
 
1350
 
 
1351
                                curColor2[0]+=map[(width-1-i+y*width)*4+GlowR] *
 
1352
                                   filter[fx];
 
1353
                                curColor2[1]+=map[(width-1-i+y*width)*4+GlowG] *
 
1354
                                   filter[fx];
 
1355
                                curColor2[2]+=map[(width-1-i+y*width)*4+GlowB] *
 
1356
                                   filter[fx];
 
1357
                                }
 
1358
                                fx++;
 
1359
                        }
 
1360
                        temp[index+GlowR]=curColor[0];
 
1361
                        temp[index+GlowG]=curColor[1];
 
1362
                        temp[index+GlowB]=curColor[2];
 
1363
 
 
1364
                        temp[((width-1-x+y*width)*4)+GlowR]=curColor2[0];
 
1365
                        temp[((width-1-x+y*width)*4)+GlowG]=curColor2[1];
 
1366
                        temp[((width-1-x+y*width)*4)+GlowB]=curColor2[2];
 
1367
 
 
1368
                }
 
1369
                /*      Do the main body */
 
1370
                for (x=halfWidth;x<width-halfWidth;x++){
 
1371
                        index=(x+y*width)*4;
 
1372
                        fx=0;
 
1373
                        curColor[0]=curColor[1]=curColor[2]=0;
 
1374
                        for (i=x-halfWidth;i<x+halfWidth;i++){
 
1375
                                curColor[0]+=map[(i+y*width)*4+GlowR]*filter[fx];
 
1376
                                curColor[1]+=map[(i+y*width)*4+GlowG]*filter[fx];
 
1377
                                curColor[2]+=map[(i+y*width)*4+GlowB]*filter[fx];
 
1378
                                fx++;
 
1379
                        }
 
1380
                        temp[index+GlowR]=curColor[0];
 
1381
                        temp[index+GlowG]=curColor[1];
 
1382
                        temp[index+GlowB]=curColor[2];
 
1383
                }
 
1384
        }
 
1385
 
 
1386
        /*      Swap buffers */
 
1387
        swap=temp;temp=map;map=swap;
 
1388
 
 
1389
 
 
1390
        /*      Blur the columns */
 
1391
        for (x=0;x<width;x++){
 
1392
                /*      Do the top & bottom strips */
 
1393
                for (y=0;y<halfWidth;y++){
 
1394
                        index=(x+y*width)*4;
 
1395
                        fy=0;
 
1396
                        curColor[0]=curColor[1]=curColor[2]=0;
 
1397
                        curColor2[0]=curColor2[1]=curColor2[2]=0;
 
1398
                        for (i=y-halfWidth;i<y+halfWidth;i++){
 
1399
                                if ((i>=0)&&(i<height)){
 
1400
                                   /*   Bottom */
 
1401
                                   curColor[0]+=map[(x+i*width)*4+GlowR]*filter[fy];
 
1402
                                   curColor[1]+=map[(x+i*width)*4+GlowG]*filter[fy];
 
1403
                                   curColor[2]+=map[(x+i*width)*4+GlowB]*filter[fy];
 
1404
 
 
1405
                                   /*   Top */
 
1406
                                   curColor2[0]+=map[(x+(height-1-i)*width) *
 
1407
                                      4+GlowR]*filter[fy];
 
1408
                                   curColor2[1]+=map[(x+(height-1-i)*width) *
 
1409
                                      4+GlowG]*filter[fy];
 
1410
                                   curColor2[2]+=map[(x+(height-1-i)*width) *
 
1411
                                      4+GlowB]*filter[fy];
 
1412
                                }
 
1413
                                fy++;
 
1414
                        }
 
1415
                        temp[index+GlowR]=curColor[0];
 
1416
                        temp[index+GlowG]=curColor[1];
 
1417
                        temp[index+GlowB]=curColor[2];
 
1418
                        temp[((x+(height-1-y)*width)*4)+GlowR]=curColor2[0];
 
1419
                        temp[((x+(height-1-y)*width)*4)+GlowG]=curColor2[1];
 
1420
                        temp[((x+(height-1-y)*width)*4)+GlowB]=curColor2[2];
 
1421
                }
 
1422
                /*      Do the main body */
 
1423
                for (y=halfWidth;y<height-halfWidth;y++){
 
1424
                        index=(x+y*width)*4;
 
1425
                        fy=0;
 
1426
                        curColor[0]=curColor[1]=curColor[2]=0;
 
1427
                        for (i=y-halfWidth;i<y+halfWidth;i++){
 
1428
                                curColor[0]+=map[(x+i*width)*4+GlowR]*filter[fy];
 
1429
                                curColor[1]+=map[(x+i*width)*4+GlowG]*filter[fy];
 
1430
                                curColor[2]+=map[(x+i*width)*4+GlowB]*filter[fy];
 
1431
                                fy++;
 
1432
                        }
 
1433
                        temp[index+GlowR]=curColor[0];
 
1434
                        temp[index+GlowG]=curColor[1];
 
1435
                        temp[index+GlowB]=curColor[2];
 
1436
                }
 
1437
        }
 
1438
 
 
1439
 
 
1440
        /*      Swap buffers */
 
1441
        swap=temp;temp=map;map=swap;
 
1442
 
 
1443
        /*      Tidy up  */
 
1444
        MEM_freeN (filter);
 
1445
        MEM_freeN (temp);
 
1446
}
 
1447
 
 
1448
 
 
1449
/*      Adds two bitmaps and puts the results into a third map. */
 
1450
/*      C must have been previously allocated but it may be A or B. */
 
1451
/*      We clamp values to 255 to prevent weirdness */
 
1452
/*=============================== */
 
1453
void RVAddBitmaps (unsigned char* a, unsigned char* b, unsigned char* c, int width, int height)
 
1454
{
 
1455
        int     x,y,index;
 
1456
 
 
1457
        for (y=0;y<height;y++){
 
1458
                for (x=0;x<width;x++){
 
1459
                        index=(x+y*width)*4;
 
1460
                        c[index+GlowR]=MIN2(255,a[index+GlowR]+b[index+GlowR]);
 
1461
                        c[index+GlowG]=MIN2(255,a[index+GlowG]+b[index+GlowG]);
 
1462
                        c[index+GlowB]=MIN2(255,a[index+GlowB]+b[index+GlowB]);
 
1463
                        c[index+GlowA]=MIN2(255,a[index+GlowA]+b[index+GlowA]);
 
1464
                }
 
1465
        }
 
1466
}
 
1467
 
 
1468
/*      For each pixel whose total luminance exceeds the threshold, */
 
1469
/*      Multiply it's value by BOOST and add it to the output map */
 
1470
void RVIsolateHighlights (unsigned char* in, unsigned char* out, int width, int height, int threshold, float boost, float clamp)
 
1471
{
 
1472
        int x,y,index;
 
1473
        int     intensity;
 
1474
 
 
1475
 
 
1476
        for(y=0;y< height;y++) {
 
1477
                for (x=0;x< width;x++) {
 
1478
                   index= (x+y*width)*4;
 
1479
 
 
1480
                   /*   Isolate the intensity */
 
1481
                   intensity=(in[index+GlowR]+in[index+GlowG]+in[index+GlowB]-threshold);
 
1482
                   if (intensity>0){
 
1483
                        out[index+GlowR]=MIN2(255*clamp, (in[index+GlowR]*boost*intensity)/255);
 
1484
                        out[index+GlowG]=MIN2(255*clamp, (in[index+GlowG]*boost*intensity)/255);
 
1485
                        out[index+GlowB]=MIN2(255*clamp, (in[index+GlowB]*boost*intensity)/255);
 
1486
                        }
 
1487
                        else{
 
1488
                                out[index+GlowR]=0;
 
1489
                                out[index+GlowG]=0;
 
1490
                                out[index+GlowB]=0;
 
1491
                        }
 
1492
                }
 
1493
        }
 
1494
}
 
1495
 
 
1496
void init_glow_effect(Sequence *seq)
 
1497
{
 
1498
        GlowVars *glow;
 
1499
 
 
1500
        if(seq->effectdata)MEM_freeN(seq->effectdata);
 
1501
        seq->effectdata = MEM_callocN(sizeof(struct GlowVars), "glowvars");
 
1502
 
 
1503
        glow = (GlowVars *)seq->effectdata;
 
1504
        glow->fMini = 0.25;
 
1505
        glow->fClamp = 1.0;
 
1506
        glow->fBoost = 0.5;
 
1507
        glow->dDist = 3.0;
 
1508
        glow->dQuality = 3;
 
1509
        glow->bNoComp = 0;
 
1510
}
 
1511
 
 
1512
 
 
1513
//void do_glow_effect(Cast *cast, float facf0, float facf1, int xo, int yo, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *outbuf, ImBuf *use)
 
1514
void do_glow_effect(Sequence *seq, float facf0, float facf1, int x, int y, unsigned int *rect1, unsigned int *rect2, unsigned int *out)
 
1515
{
 
1516
        unsigned char *outbuf=(unsigned char *)out;
 
1517
        unsigned char *inbuf=(unsigned char *)rect1;
 
1518
        GlowVars *glow = (GlowVars *)seq->effectdata;
 
1519
 
 
1520
        RVIsolateHighlights     (inbuf, outbuf , x, y, glow->fMini*765, glow->fBoost, glow->fClamp);
 
1521
        RVBlurBitmap2 (outbuf, x, y, glow->dDist,glow->dQuality);
 
1522
        if (!glow->bNoComp)
 
1523
                RVAddBitmaps (inbuf , outbuf, outbuf, x, y);
 
1524
}
 
1525
 
957
1526
void make_black_ibuf(ImBuf *ibuf)
958
1527
{
959
1528
        unsigned int *rect;
960
 
        int tot;        
961
 
        
 
1529
        int tot;
 
1530
 
962
1531
        if(ibuf==0 || ibuf->rect==0) return;
963
 
        
 
1532
 
964
1533
        tot= ibuf->x*ibuf->y;
965
1534
        rect= ibuf->rect;
966
1535
        while(tot--) *(rect++)= 0;
967
 
        
 
1536
 
968
1537
}
969
1538
 
970
1539
void multibuf(ImBuf *ibuf, float fmul)
971
1540
{
972
1541
        char *rt;
973
1542
        int a, mul, icol;
974
 
        
 
1543
 
975
1544
        mul= (int)(256.0*fmul);
976
1545
 
977
1546
        a= ibuf->x*ibuf->y;
978
1547
        rt= (char *)ibuf->rect;
979
1548
        while(a--) {
980
 
                
 
1549
 
981
1550
                icol= (mul*rt[0])>>8;
982
1551
                if(icol>254) rt[0]= 255; else rt[0]= icol;
983
1552
                icol= (mul*rt[1])>>8;
986
1555
                if(icol>254) rt[2]= 255; else rt[2]= icol;
987
1556
                icol= (mul*rt[3])>>8;
988
1557
                if(icol>254) rt[3]= 255; else rt[3]= icol;
989
 
                
 
1558
 
990
1559
                rt+= 4;
991
1560
        }
992
1561
}
997
1566
        float fac, facf;
998
1567
        int x, y;
999
1568
        char *cp;
1000
 
        
 
1569
 
1001
1570
        if(se->se1==0 || se->se2==0 || se->se3==0) {
1002
1571
                make_black_ibuf(se->ibuf);
1003
1572
                return;
1004
1573
        }
1005
 
        
 
1574
 
1006
1575
        /* if metastrip: other se's */
1007
1576
        if(se->se1->ok==2) se1= se->se1->se1;
1008
1577
        else se1= se->se1;
1009
1578
 
1010
1579
        if(se->se2->ok==2) se2= se->se2->se1;
1011
1580
        else se2= se->se2;
1012
 
        
 
1581
 
1013
1582
        if(se->se3->ok==2) se3= se->se3->se1;
1014
1583
        else se3= se->se3;
1015
 
        
 
1584
 
1016
1585
        if(se1==0 || se2==0 || se3==0 || se1->ibuf==0 || se2->ibuf==0 || se3->ibuf==0) {
1017
1586
                make_black_ibuf(se->ibuf);
1018
1587
                return;
1019
1588
        }
1020
 
        
 
1589
 
1021
1590
        x= se2->ibuf->x;
1022
1591
        y= se2->ibuf->y;
1023
 
        
 
1592
 
1024
1593
        if(seq->ipo && seq->ipo->curve.first) {
1025
1594
                do_seq_ipo(seq);
1026
1595
                fac= seq->facf0;
1027
1596
                facf= seq->facf1;
1028
1597
        }
1029
 
        else if ELEM3( seq->type, SEQ_CROSS, SEQ_GAMCROSS, SEQ_PLUGIN) {
 
1598
        else if ( seq->type==SEQ_CROSS || seq->type==SEQ_GAMCROSS || seq->type==SEQ_PLUGIN || seq->type==SEQ_WIPE) {
1030
1599
                fac= (float)(cfra - seq->startdisp);
1031
1600
                facf= (float)(fac+0.5);
1032
1601
                fac /= seq->len;
1035
1604
        else {
1036
1605
                fac= facf= 1.0;
1037
1606
        }
1038
 
        
 
1607
 
1039
1608
        if( G.scene->r.mode & R_FIELDS ); else facf= fac;
1040
 
        
 
1609
 
1041
1610
        switch(seq->type) {
1042
1611
        case SEQ_CROSS:
1043
1612
                do_cross_effect(fac, facf, x, y, se1->ibuf->rect, se2->ibuf->rect, se->ibuf->rect);
1064
1633
        case SEQ_ALPHAUNDER:
1065
1634
                do_alphaunder_effect(fac, facf, x, y, se1->ibuf->rect, se2->ibuf->rect, se->ibuf->rect);
1066
1635
                break;
 
1636
        case SEQ_WIPE:
 
1637
                do_wipe_effect(seq, fac, facf, x, y, se1->ibuf->rect, se2->ibuf->rect, se->ibuf->rect);
 
1638
                break;
 
1639
        case SEQ_GLOW:
 
1640
                do_glow_effect(seq, fac, facf, x, y, se1->ibuf->rect, se2->ibuf->rect, se->ibuf->rect);
 
1641
                break;
1067
1642
        case SEQ_PLUGIN:
1068
1643
                if(seq->plugin && seq->plugin->doit) {
1069
 
                        
 
1644
 
1070
1645
                        if((G.f & G_PLAYANIM)==0) waitcursor(1);
1071
1646
 
1072
1647
                        if(seq->plugin->cfra) *(seq->plugin->cfra)= frame_to_float(CFRA);
1073
1648
 
1074
1649
                        cp= PIL_dynlib_find_symbol(seq->plugin->handle, "seqname");
1075
 
                        if(cp) strcpy(cp, seq->name+2);
 
1650
                        if(cp) strncpy(cp, seq->name+2, 22);
1076
1651
 
1077
1652
                        if (seq->plugin->version<=2) {
1078
1653
                                if(se1->ibuf) IMB_convert_rgba_to_abgr(se1->ibuf->x*se1->ibuf->y, se1->ibuf->rect);
1080
1655
                                if(se3->ibuf) IMB_convert_rgba_to_abgr(se3->ibuf->x*se3->ibuf->y, se3->ibuf->rect);
1081
1656
                        }
1082
1657
 
1083
 
                        ((SeqDoit)seq->plugin->doit)(seq->plugin->data, fac, facf, x, y,   
1084
 
                                                se1->ibuf, se2->ibuf, se->ibuf, se3->ibuf); 
 
1658
                        ((SeqDoit)seq->plugin->doit)(seq->plugin->data, fac, facf, x, y,
 
1659
                                                se1->ibuf, se2->ibuf, se->ibuf, se3->ibuf);
1085
1660
 
1086
1661
                        if (seq->plugin->version<=2) {
1087
1662
                                if(se1->ibuf) IMB_convert_rgba_to_abgr(se1->ibuf->x*se1->ibuf->y, se1->ibuf->rect);
1094
1669
                }
1095
1670
                break;
1096
1671
        }
1097
 
        
 
1672
 
1098
1673
}
1099
1674
 
1100
1675
int evaluate_seq_frame(int cfra)
1102
1677
        Sequence *seq;
1103
1678
        Editing *ed;
1104
1679
        int totseq=0;
1105
 
        
 
1680
 
1106
1681
        memset(seq_arr, 0, 4*MAXSEQ);
1107
 
        
 
1682
 
1108
1683
        ed= G.scene->ed;
1109
1684
        if(ed==0) return 0;
1110
 
        
 
1685
 
1111
1686
        seq= ed->seqbasep->first;
1112
1687
        while(seq) {
1113
1688
                if(seq->startdisp <=cfra && seq->enddisp > cfra) {
1116
1691
                }
1117
1692
                seq= seq->next;
1118
1693
        }
1119
 
        
 
1694
 
1120
1695
        return totseq;
1121
1696
}
1122
1697
 
1125
1700
        Strip *strip;
1126
1701
        StripElem *se;
1127
1702
        int nr;
1128
 
        
 
1703
 
1129
1704
        strip= seq->strip;
1130
1705
        se= strip->stripdata;
1131
 
        
 
1706
 
1132
1707
        if(se==0) return 0;
1133
1708
        if(seq->startdisp >cfra || seq->enddisp <= cfra) return 0;
1134
 
        
 
1709
 
1135
1710
        if(cfra <= seq->start) nr= 0;
1136
1711
        else if(cfra >= seq->start+seq->len-1) nr= seq->len-1;
1137
1712
        else nr= cfra-seq->start;
1138
 
        
 
1713
 
1139
1714
        se+= nr;
1140
1715
        se->nr= nr;
1141
 
        
 
1716
 
1142
1717
        return se;
1143
1718
}
1144
1719
 
1149
1724
        ListBase *tempbase;
1150
1725
        StripElem *se;
1151
1726
        int a, cfra, b;
1152
 
        
 
1727
 
1153
1728
        /* sets all ->se1 pointers in stripdata, to read the ibuf from it */
1154
 
        
 
1729
 
1155
1730
        ed= G.scene->ed;
1156
1731
        if(ed==0) return;
1157
 
        
 
1732
 
1158
1733
        tempbase= ed->seqbasep;
1159
1734
        ed->seqbasep= &seqm->seqbase;
1160
 
        
 
1735
 
1161
1736
        se= seqm->strip->stripdata;
1162
1737
        for(a=0; a<seqm->len; a++, se++) {
1163
1738
                cfra= a+seqm->start;
1164
1739
                if(evaluate_seq_frame(cfra)) {
1165
 
                        
 
1740
 
1166
1741
                        /* we take the upper effect strip or the lowest imagestrip/metastrip */
1167
1742
                        seqim= seqeff= 0;
1168
 
                        
 
1743
 
1169
1744
                        for(b=1; b<MAXSEQ; b++) {
1170
1745
                                if(seq_arr[b]) {
1171
1746
                                        seq= seq_arr[b];
1182
1757
                        if(seqeff) seq= seqeff;
1183
1758
                        else if(seqim) seq= seqim;
1184
1759
                        else seq= 0;
1185
 
                        
 
1760
 
1186
1761
                        if(seq) {
1187
1762
                                se->se1= give_stripelem(seq, cfra);
1188
1763
                        }
1200
1775
void do_seq_count_cfra(ListBase *seqbase, int *totseq, int cfra)
1201
1776
{
1202
1777
        Sequence *seq;
1203
 
        
 
1778
 
1204
1779
        seq= seqbase->first;
1205
1780
        while(seq) {
1206
1781
                if(seq->startdisp <=cfra && seq->enddisp > cfra) {
1207
1782
 
1208
1783
                        if(seq->seqbase.first) {
1209
 
                                
 
1784
 
1210
1785
                                if(cfra< seq->start) do_seq_count_cfra(&seq->seqbase, totseq, seq->start);
1211
1786
                                else if(cfra> seq->start+seq->len-1) do_seq_count_cfra(&seq->seqbase, totseq, seq->start+seq->len-1);
1212
1787
                                else do_seq_count_cfra(&seq->seqbase, totseq, cfra);
1225
1800
        Scene *oldsce;
1226
1801
        unsigned int *rectot;
1227
1802
        int oldx, oldy, oldcfra, doseq;
1228
 
        char name[FILE_MAXDIR];
 
1803
        char name[FILE_MAXDIR+FILE_MAXFILE];
 
1804
 
 
1805
        if(seqar==NULL) return;
1229
1806
        
1230
1807
        seq= seqbase->first;
1231
1808
        while(seq) {
1232
 
                
 
1809
 
1233
1810
                /* set at zero because free_imbuf_seq... */
1234
1811
                seq->curelem= 0;
1235
1812
 
1236
1813
                if ((seq->type == SEQ_SOUND) && (seq->ipo)
1237
1814
                  &&(seq->startdisp<=cfra+2) && (seq->enddisp>cfra)) do_seq_ipo(seq);
1238
 
                
 
1815
 
1239
1816
                if(seq->startdisp <=cfra && seq->enddisp > cfra) {
1240
 
                
 
1817
 
1241
1818
                        if(seq->seqbase.first) {
1242
1819
                                if(cfra< seq->start) do_build_seqar_cfra(&seq->seqbase, seqar, seq->start);
1243
1820
                                else if(cfra> seq->start+seq->len-1) do_build_seqar_cfra(&seq->seqbase, seqar, seq->start+seq->len-1);
1246
1823
 
1247
1824
                        **seqar= seq;
1248
1825
                        (*seqar)++;
1249
 
                        
 
1826
 
1250
1827
                        se=seq->curelem= give_stripelem(seq, cfra);
1251
1828
 
1252
1829
                        if(se) {
1259
1836
                                }
1260
1837
                                else if(seq->type == SEQ_SOUND) {
1261
1838
                                        se->ok= 2;
1262
 
                                }                               
 
1839
                                }
1263
1840
                                else if(seq->type & SEQ_EFFECT) {
1264
 
                                
 
1841
 
1265
1842
                                        /* test if image is too small: reload */
1266
1843
                                        if(se->ibuf) {
1267
1844
                                                if(se->ibuf->x < seqrectx || se->ibuf->y < seqrecty) {
1269
1846
                                                        se->ibuf= 0;
1270
1847
                                                }
1271
1848
                                        }
1272
 
                                        
 
1849
 
1273
1850
                                        /* does the effect should be recalculated? */
1274
 
                                        
 
1851
 
1275
1852
                                        if(se->ibuf==0 || (se->se1 != seq->seq1->curelem) || (se->se2 != seq->seq2->curelem) || (se->se3 != seq->seq3->curelem)) {
1276
1853
                                                se->se1= seq->seq1->curelem;
1277
1854
                                                se->se2= seq->seq2->curelem;
1278
1855
                                                se->se3= seq->seq3->curelem;
1279
 
                                                
 
1856
 
1280
1857
                                                if(se->ibuf==0) se->ibuf= IMB_allocImBuf((short)seqrectx, (short)seqrecty, 32, IB_rect, 0);
1281
 
                        
 
1858
 
1282
1859
                                                do_effect(cfra, seq, se);
1283
1860
                                        }
1284
 
                                        
 
1861
 
1285
1862
                                        /* test size */
1286
1863
                                        if(se->ibuf) {
1287
1864
                                                if(se->ibuf->x != seqrectx || se->ibuf->y != seqrecty ) {
1288
 
                                                        if(G.scene->r.mode & R_OSA) 
 
1865
                                                        if(G.scene->r.mode & R_OSA)
1289
1866
                                                                IMB_scaleImBuf(se->ibuf, (short)seqrectx, (short)seqrecty);
1290
 
                                                        else 
 
1867
                                                        else
1291
1868
                                                                IMB_scalefastImBuf(se->ibuf, (short)seqrectx, (short)seqrecty);
1292
1869
                                                }
1293
1870
                                        }
1294
1871
                                }
1295
1872
                                else if(seq->type < SEQ_EFFECT) {
1296
 
                                        
 
1873
 
1297
1874
                                        if(se->ibuf) {
1298
1875
                                                /* test if image too small: reload */
1299
1876
                                                if(se->ibuf->x < seqrectx || se->ibuf->y < seqrecty) {
1305
1882
 
1306
1883
                                        if(seq->type==SEQ_IMAGE) {
1307
1884
                                                if(se->ok && se->ibuf==0) {
1308
 
                                                
 
1885
 
1309
1886
                                                        /* if playanim or render: no waitcursor */
1310
1887
                                                        if((G.f & G_PLAYANIM)==0) waitcursor(1);
1311
 
                                                
1312
 
                                                        strcpy(name, seq->strip->dir);
1313
 
                                                        strcat(name, se->name);
 
1888
 
 
1889
                                                        strncpy(name, seq->strip->dir, FILE_MAXDIR-1);
 
1890
                                                        strncat(name, se->name, FILE_MAXFILE);
1314
1891
                                                        BLI_convertstringcode(name, G.sce, G.scene->r.cfra);
1315
1892
                                                        se->ibuf= IMB_loadiffname(name, IB_rect);
1316
1893
 
1317
1894
                                                        if((G.f & G_PLAYANIM)==0) waitcursor(0);
1318
 
                                                        
 
1895
 
1319
1896
                                                        if(se->ibuf==0) se->ok= 0;
1320
1897
                                                        else {
1321
 
                                                                if(se->ibuf->depth==32 && se->ibuf->zbuf==0) converttopremul(se->ibuf);
 
1898
                                                                if(seq->flag & SEQ_MAKE_PREMUL) {
 
1899
                                                                        if(se->ibuf->depth==32 && se->ibuf->zbuf==0) converttopremul(se->ibuf);
 
1900
                                                                }
1322
1901
                                                                seq->strip->orx= se->ibuf->x;
1323
1902
                                                                seq->strip->ory= se->ibuf->y;
 
1903
                                                                if(seq->flag & SEQ_FILTERY) IMB_filtery(se->ibuf);
 
1904
                                                                if(seq->mul==0.0) seq->mul= 1.0;
 
1905
                                                                if(seq->mul != 1.0) multibuf(se->ibuf, seq->mul);
1324
1906
                                                        }
1325
1907
                                                }
1326
1908
                                        }
1327
1909
                                        else if(seq->type==SEQ_MOVIE) {
1328
1910
                                                if(se->ok && se->ibuf==0) {
1329
 
                                                
 
1911
 
1330
1912
                                                        /* if playanim r render: no waitcursor */
1331
1913
                                                        if((G.f & G_PLAYANIM)==0) waitcursor(1);
1332
 
                                                
 
1914
 
1333
1915
                                                        if(seq->anim==0) {
1334
 
                                                                strcpy(name, seq->strip->dir);
1335
 
                                                                strcat(name, seq->strip->stripdata->name);
 
1916
                                                                strncpy(name, seq->strip->dir, FILE_MAXDIR-1);
 
1917
                                                                strncat(name, seq->strip->stripdata->name, FILE_MAXFILE-1);
1336
1918
                                                                BLI_convertstringcode(name, G.sce, G.scene->r.cfra);
1337
 
                                                                
 
1919
 
1338
1920
                                                                seq->anim = openanim(name, IB_rect);
1339
1921
                                                        }
1340
1922
                                                        if(seq->anim) {
1341
1923
                                                                se->ibuf = IMB_anim_absolute(seq->anim, se->nr);
1342
1924
                                                        }
1343
 
                                                        
 
1925
 
1344
1926
                                                        if(se->ibuf==0) se->ok= 0;
1345
1927
                                                        else {
1346
 
                                                                if(se->ibuf->depth==32) converttopremul(se->ibuf);
 
1928
                                                                if(seq->flag & SEQ_MAKE_PREMUL) {
 
1929
                                                                        if(se->ibuf->depth==32) converttopremul(se->ibuf);
 
1930
                                                                }
1347
1931
                                                                seq->strip->orx= se->ibuf->x;
1348
1932
                                                                seq->strip->ory= se->ibuf->y;
1349
1933
                                                                if(seq->flag & SEQ_FILTERY) IMB_filtery(se->ibuf);
1350
1934
                                                                if(seq->mul==0.0) seq->mul= 1.0;
1351
1935
                                                                if(seq->mul != 1.0) multibuf(se->ibuf, seq->mul);
1352
1936
                                                        }
1353
 
                                                        if((G.f & G_PLAYANIM)==0) waitcursor(0);                                                        
 
1937
                                                        if((G.f & G_PLAYANIM)==0) waitcursor(0);
1354
1938
                                                }
1355
1939
                                        }
1356
 
                                        else if(seq->type==SEQ_SCENE && se->ibuf==0) {
 
1940
                                        else if(seq->type==SEQ_SCENE && se->ibuf==0 && seq->scene) {    // scene can be NULL after deletions
1357
1941
                                                View3D *vd;
 
1942
                                                int redisplay= (!G.background && !(R.flag & R_RENDERING));
1358
1943
                                                
1359
1944
                                                oldsce= G.scene;
1360
1945
                                                set_scene_bg(seq->scene);
1361
 
                                                
 
1946
 
1362
1947
                                                /* prevent eternal loop */
1363
1948
                                                doseq= G.scene->r.scemode & R_DOSEQ;
1364
1949
                                                G.scene->r.scemode &= ~R_DOSEQ;
1365
 
                                                
 
1950
 
1366
1951
                                                /* store stuffies */
1367
1952
                                                oldcfra= CFRA; CFRA= seq->sfra + se->nr;
1368
1953
                                                waitcursor(1);
1369
 
                                                
1370
 
                                                rectot= R.rectot; R.rectot= 0;
 
1954
 
 
1955
                                                rectot= R.rectot; R.rectot= NULL;
1371
1956
                                                oldx= R.rectx; oldy= R.recty;
1372
1957
                                                /* needed because current 3D window cannot define the layers, like in a background render */
1373
1958
                                                vd= G.vd;
1374
 
                                                G.vd= 0;
1375
 
                                                
 
1959
                                                G.vd= NULL;
 
1960
 
1376
1961
                                                RE_initrender(NULL);
1377
 
                                                if (!G.background) {
 
1962
                                                if (redisplay) {
 
1963
                                                        mainwindow_make_active();
1378
1964
                                                        if(R.r.mode & R_FIELDS) update_for_newframe_muted();
1379
1965
                                                        R.flag= 0;
1380
 
                                                        
 
1966
 
1381
1967
                                                        free_filesel_spec(G.scene->r.pic);
1382
1968
                                                }
1383
1969
 
1387
1973
                                                        se->ibuf->zbuf= (int *)R.rectz;
1388
1974
                                                        /* make sure ibuf frees it */
1389
1975
                                                        se->ibuf->mall |= IB_zbuf;
1390
 
                                                        R.rectz= 0;
 
1976
                                                        R.rectz= NULL;
1391
1977
                                                }
1392
 
                                                
 
1978
 
1393
1979
                                                /* and restore */
1394
1980
                                                G.vd= vd;
1395
 
                                                
 
1981
 
1396
1982
                                                if((G.f & G_PLAYANIM)==0) waitcursor(0);
1397
1983
                                                CFRA= oldcfra;
1398
1984
                                                if(R.rectot) MEM_freeN(R.rectot);
1400
1986
                                                R.rectx=oldx; R.recty=oldy;
1401
1987
                                                G.scene->r.scemode |= doseq;
1402
1988
                                                set_scene_bg(oldsce);
1403
 
                                                
 
1989
 
1404
1990
                                                /* restore!! */
1405
1991
                                                R.rectx= seqrectx;
1406
1992
                                                R.recty= seqrecty;
1407
 
                                                
 
1993
 
1408
1994
                                                /* added because this flag is checked for
1409
1995
                                                 * movie writing when rendering an anim.
1410
1996
                                                 * very convoluted. fix. -zr
1411
1997
                                                 */
1412
1998
                                                R.r.imtype= G.scene->r.imtype;
1413
1999
                                        }
1414
 
                                        
 
2000
 
1415
2001
                                        /* size test */
1416
2002
                                        if(se->ibuf) {
1417
2003
                                                if(se->ibuf->x != seqrectx || se->ibuf->y != seqrecty ) {
1418
 
                                                
 
2004
 
1419
2005
                                                        if (G.scene->r.mode & R_FIELDS) {
1420
 
                                                                
 
2006
 
1421
2007
                                                                if (seqrecty > 288) IMB_scalefieldImBuf(se->ibuf, (short)seqrectx, (short)seqrecty);
1422
2008
                                                                else {
1423
2009
                                                                        IMB_de_interlace(se->ibuf);
1424
2010
 
1425
 
                                                                        if(G.scene->r.mode & R_OSA) 
 
2011
                                                                        if(G.scene->r.mode & R_OSA)
1426
2012
                                                                                IMB_scaleImBuf(se->ibuf, (short)seqrectx, (short)seqrecty);
1427
 
                                                                        else 
 
2013
                                                                        else
1428
2014
                                                                                IMB_scalefastImBuf(se->ibuf, (short)seqrectx, (short)seqrecty);
1429
2015
                                                                }
1430
2016
                                                        }
1431
2017
                                                        else {
1432
 
                                                                if(G.scene->r.mode & R_OSA) 
 
2018
                                                                if(G.scene->r.mode & R_OSA)
1433
2019
                                                                        IMB_scaleImBuf(se->ibuf,(short)seqrectx, (short)seqrecty);
1434
 
                                                                else 
 
2020
                                                                else
1435
2021
                                                                        IMB_scalefastImBuf(se->ibuf, (short)seqrectx, (short)seqrecty);
1436
2022
                                                        }
1437
2023
                                                }
1463
2049
        do_seq_count_cfra(ed->seqbasep, &totseq, cfra);
1464
2050
 
1465
2051
        if(totseq==0) return 0;
1466
 
        
 
2052
 
1467
2053
        seqrectx= (G.scene->r.size*G.scene->r.xsch)/100;
1468
2054
        if(G.scene->r.mode & R_PANORAMA) seqrectx*= G.scene->r.xparts;
1469
2055
        seqrecty= (G.scene->r.size*G.scene->r.ysch)/100;
1471
2057
 
1472
2058
        /* tseqar is neede because in do_build_... the pointer changes */
1473
2059
        seqar= tseqar= MEM_callocN(sizeof(void *)*totseq, "seqar");
1474
 
        
 
2060
 
1475
2061
        /* this call loads and makes the ibufs */
1476
2062
        do_build_seqar_cfra(ed->seqbasep, &seqar, cfra);
1477
2063
        seqar= tseqar;
1478
 
        
 
2064
 
1479
2065
        for(seqnr=0; seqnr<totseq; seqnr++) {
1480
 
                seq= seqar[seqnr];              
 
2066
                seq= seqar[seqnr];
1481
2067
 
1482
2068
                se= seq->curelem;
1483
2069
                if((seq->type != SEQ_SOUND) && (se)) {
1484
2070
                        if(seq->type==SEQ_META) {
1485
 
                                
 
2071
 
1486
2072
                                /* bottom strip! */
1487
2073
                                if(seqfirst==0) seqfirst= seq;
1488
2074
                                else if(seqfirst->depth > seq->depth) seqfirst= seq;
1489
2075
                                else if(seqfirst->machine > seq->machine) seqfirst= seq;
1490
 
                                
 
2076
 
1491
2077
                        }
1492
2078
                        else if(seq->type & SEQ_EFFECT) {
1493
 
                                
 
2079
 
1494
2080
                                /* top strip! */
1495
2081
                                if(seqfirst==0) seqfirst= seq;
1496
2082
                                else if(seqfirst->depth > seq->depth) seqfirst= seq;
1497
2083
                                else if(seqfirst->machine < seq->machine) seqfirst= seq;
1498
 
                                
 
2084
 
1499
2085
 
1500
2086
                        }
1501
2087
                        else if(seq->type < SEQ_EFFECT) {       /* images */
1502
 
                                
 
2088
 
1503
2089
                                /* bottom strip! a feature that allows you to store junk in locations above */
1504
 
                                
 
2090
 
1505
2091
                                if(seqfirst==0) seqfirst= seq;
1506
2092
                                else if(seqfirst->depth > seq->depth) seqfirst= seq;
1507
2093
                                else if(seqfirst->machine > seq->machine) seqfirst= seq;
1508
 
                                
 
2094
 
1509
2095
                        }
1510
2096
                }
1511
2097
        }
1512
 
        
1513
 
        MEM_freeN(seqar);       
1514
 
        
 
2098
 
 
2099
        MEM_freeN(seqar);
 
2100
 
1515
2101
        if(!seqfirst) return 0;
1516
2102
        if(!seqfirst->curelem) return 0;
1517
2103
        return seqfirst->curelem->ibuf;
1524
2110
        StripElem *se;
1525
2111
        Editing *ed;
1526
2112
        int a;
1527
 
        
 
2113
 
1528
2114
        ed= G.scene->ed;
1529
2115
        if(ed==0) return;
1530
 
        
1531
 
        WHILE_SEQ(&ed->seqbase) {               
1532
 
                
 
2116
 
 
2117
        WHILE_SEQ(&ed->seqbase) {
 
2118
 
1533
2119
                if(seq->strip) {
1534
 
                
 
2120
 
1535
2121
                        if(seq->type & SEQ_EFFECT) {
1536
2122
                                se= seq->strip->stripdata;
1537
2123
                                for(a=0; a<seq->len; a++, se++) {
1554
2140
        StripElem *se;
1555
2141
        Editing *ed;
1556
2142
        int a;
1557
 
        
 
2143
 
1558
2144
        ed= G.scene->ed;
1559
2145
        if(ed==0) return;
1560
 
        
1561
 
        WHILE_SEQ(&ed->seqbase) {               
1562
 
                
 
2146
 
 
2147
        WHILE_SEQ(&ed->seqbase) {
 
2148
 
1563
2149
                if(seq->strip) {
1564
 
                
 
2150
 
1565
2151
                        if( seq->type==SEQ_META ) {
1566
2152
                                ;
1567
2153
                        }
1576
2162
                                        }
1577
2163
                                }
1578
2164
                        }
1579
 
                        
 
2165
 
1580
2166
                        if(seq->type==SEQ_MOVIE) {
1581
2167
                                if(seq->startdisp > cfra || seq->enddisp < cfra) {
1582
2168
                                        if(seq->anim) {
1596
2182
        StripElem *se;
1597
2183
        Editing *ed;
1598
2184
        int a;
1599
 
        
 
2185
 
1600
2186
        ed= G.scene->ed;
1601
2187
        if(ed==0) return;
1602
 
        
1603
 
        WHILE_SEQ(&ed->seqbase) {               
1604
 
                
 
2188
 
 
2189
        WHILE_SEQ(&ed->seqbase) {
 
2190
 
1605
2191
                if(seq->strip) {
1606
 
                
 
2192
 
1607
2193
                        if( seq->type==SEQ_META ) {
1608
2194
                                ;
1609
2195
                        }
1618
2204
                                        }
1619
2205
                                }
1620
2206
                        }
1621
 
                        
 
2207
 
1622
2208
                        if(seq->type==SEQ_MOVIE) {
1623
2209
                                if(seq->anim) {
1624
2210
                                        IMB_free_anim(seq->anim);
1634
2220
{
1635
2221
/*      static ImBuf *lastibuf=0; */
1636
2222
        ImBuf *ibuf;
1637
 
        
 
2223
 
1638
2224
        /* copy image into R.rectot */
1639
 
        
 
2225
 
1640
2226
        G.f |= G_PLAYANIM;      /* waitcursor patch */
1641
 
        
 
2227
 
1642
2228
        ibuf= give_ibuf_seq(CFRA);
1643
2229
        if(ibuf) {
1644
 
        
 
2230
 
1645
2231
                memcpy(R.rectot, ibuf->rect, 4*R.rectx*R.recty);
1646
 
                
 
2232
 
1647
2233
                /* if (ibuf->zbuf) { */
1648
2234
                /*      if (R.rectz) freeN(R.rectz); */
1649
2235
                /*      R.rectz = BLI_dupallocN(ibuf->zbuf); */
1650
2236
                /* } */
1651
 
                
 
2237
 
1652
2238
                free_imbuf_seq_except(CFRA);
1653
2239
        }
1654
2240
        G.f &= ~G_PLAYANIM;
1655
 
        
 
2241
 
1656
2242
}