modify clr btn 16 plugins, add regdmp for sigtraps, rework mask_engine, mask rotate...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / maskengine.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
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.
15  *
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
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bcsignals.h"
23 #include "condition.h"
24 #include "clip.h"
25 #include "maskauto.h"
26 #include "maskautos.h"
27 #include "maskengine.h"
28 #include "mutex.h"
29 #include "transportque.inc"
30 #include "vframe.h"
31
32 #include <math.h>
33 #include <stdint.h>
34 #include <string.h>
35
36 MaskPackage::MaskPackage()
37 {
38 }
39
40 MaskPackage::~MaskPackage()
41 {
42 }
43
44 MaskUnit::MaskUnit(MaskEngine *engine)
45  : LoadClient(engine)
46 {
47         this->engine = engine;
48         this->temp = 0;
49 }
50
51 MaskUnit::~MaskUnit()
52 {
53         if( temp ) delete temp;
54 }
55
56
57 #define OVERSAMPLE 8
58
59 void MaskUnit::draw_line_clamped(VFrame *frame,
60         int x1, int y1, int x2, int y2, unsigned char k)
61 {
62         int draw_x1, draw_y1;
63         int draw_x2, draw_y2;
64
65         if( y2 < y1 ) {
66                 draw_x1 = x2;  draw_y1 = y2;
67                 draw_x2 = x1;  draw_y2 = y1;
68         }
69         else {
70                 draw_x1 = x1;  draw_y1 = y1;
71                 draw_x2 = x2;  draw_y2 = y2;
72         }
73
74         unsigned char **rows = (unsigned char**)frame->get_rows();
75
76         if( draw_y2 != draw_y1 ) {
77                 float slope = ((float)draw_x2 - draw_x1) / ((float)draw_y2 - draw_y1);
78                 int w = frame->get_w() - 1;
79                 int h = frame->get_h();
80
81                 for( float y = draw_y1; y < draw_y2; y++ ) {
82                         if( y >= 0 && y < h ) {
83                                 int x = (int)((y - draw_y1) * slope + draw_x1);
84                                 int y_i = (int)y;
85                                 int x_i = CLIP(x, 0, w);
86
87                                 if( rows[y_i][x_i] == k )
88                                         rows[y_i][x_i] = 0;
89                                 else
90                                         rows[y_i][x_i] = k;
91                         }
92                 }
93         }
94 }
95
96 void MaskUnit::blur_strip(double *val_p, double *val_m,
97         double *dst, double *src, int size, int max)
98 {
99         double *sp_p = src;
100         double *sp_m = src + size - 1;
101         double *vp = val_p;
102         double *vm = val_m + size - 1;
103         double initial_p = sp_p[0];
104         double initial_m = sp_m[0];
105
106 //printf("MaskUnit::blur_strip %d\n", size);
107         for( int k = 0; k < size; k++ ) {
108                 int terms = (k < 4) ? k : 4;
109                 int l;
110                 for( l = 0; l <= terms; l++ ) {
111                         *vp += n_p[l] * sp_p[-l] - d_p[l] * vp[-l];
112                         *vm += n_m[l] * sp_m[l] - d_m[l] * vm[l];
113                 }
114
115                 for( ; l <= 4; l++) {
116                         *vp += (n_p[l] - bd_p[l]) * initial_p;
117                         *vm += (n_m[l] - bd_m[l]) * initial_m;
118                 }
119                 sp_p++;  sp_m--;
120                 vp++;    vm--;
121         }
122
123         for( int i = 0; i < size; i++ ) {
124                 double sum = val_p[i] + val_m[i];
125                 CLAMP(sum, 0, max);
126                 dst[i] = sum;
127         }
128 }
129
130 void MaskUnit::do_feather(VFrame *output, VFrame *input, double feather,
131                 int start_y, int end_y, int start_x, int end_x)
132 {
133 //printf("MaskUnit::do_feather %f\n", feather);
134 // Get constants
135         double constants[8];
136         double div;
137         double std_dev = sqrt(-(double)(feather * feather) / (2 * log(1.0 / 255.0)));
138         div = sqrt(2 * M_PI) * std_dev;
139         constants[0] = -1.783 / std_dev;
140         constants[1] = -1.723 / std_dev;
141         constants[2] = 0.6318 / std_dev;
142         constants[3] = 1.997  / std_dev;
143         constants[4] = 1.6803 / div;
144         constants[5] = 3.735 / div;
145         constants[6] = -0.6803 / div;
146         constants[7] = -0.2598 / div;
147
148         n_p[0] = constants[4] + constants[6];
149         n_p[1] = exp(constants[1]) *
150                                 (constants[7] * sin(constants[3]) -
151                                 (constants[6] + 2 * constants[4]) * cos(constants[3])) +
152                                 exp(constants[0]) *
153                                 (constants[5] * sin(constants[2]) -
154                                 (2 * constants[6] + constants[4]) * cos(constants[2]));
155
156         n_p[2] = 2 * exp(constants[0] + constants[1]) *
157                                 ((constants[4] + constants[6]) * cos(constants[3]) *
158                                 cos(constants[2]) - constants[5] *
159                                 cos(constants[3]) * sin(constants[2]) -
160                                 constants[7] * cos(constants[2]) * sin(constants[3])) +
161                                 constants[6] * exp(2 * constants[0]) +
162                                 constants[4] * exp(2 * constants[1]);
163
164         n_p[3] = exp(constants[1] + 2 * constants[0]) *
165                                 (constants[7] * sin(constants[3]) -
166                                 constants[6] * cos(constants[3])) +
167                                 exp(constants[0] + 2 * constants[1]) *
168                                 (constants[5] * sin(constants[2]) - constants[4] *
169                                 cos(constants[2]));
170         n_p[4] = 0.0;
171
172         d_p[0] = 0.0;
173         d_p[1] = -2 * exp(constants[1]) * cos(constants[3]) -
174                                 2 * exp(constants[0]) * cos(constants[2]);
175
176         d_p[2] = 4 * cos(constants[3]) * cos(constants[2]) *
177                                 exp(constants[0] + constants[1]) +
178                                 exp(2 * constants[1]) + exp (2 * constants[0]);
179
180         d_p[3] = -2 * cos(constants[2]) * exp(constants[0] + 2 * constants[1]) -
181                                 2 * cos(constants[3]) * exp(constants[1] + 2 * constants[0]);
182
183         d_p[4] = exp(2 * constants[0] + 2 * constants[1]);
184
185         for( int i = 0; i < 5; i++ ) d_m[i] = d_p[i];
186
187         n_m[0] = 0.0;
188         for( int i = 1; i <= 4; i++ )
189                 n_m[i] = n_p[i] - d_p[i] * n_p[0];
190
191         double sum_n_p, sum_n_m, sum_d;
192         double a, b;
193
194         sum_n_p = 0.0;
195         sum_n_m = 0.0;
196         sum_d = 0.0;
197         for( int i = 0; i < 5; i++ ) {
198                 sum_n_p += n_p[i];
199                 sum_n_m += n_m[i];
200                 sum_d += d_p[i];
201         }
202
203         a = sum_n_p / (1 + sum_d);
204         b = sum_n_m / (1 + sum_d);
205
206         for( int i = 0; i < 5; i++ ) {
207                 bd_p[i] = d_p[i] * a;
208                 bd_m[i] = d_m[i] * b;
209         }
210 #define DO_FEATHER(type, max) { \
211         int frame_w = input->get_w(); \
212         int frame_h = input->get_h(); \
213         int size = MAX(frame_w, frame_h); \
214         double *src = new double[size]; \
215         double *dst = new double[size]; \
216         double *val_p = new double[size]; \
217         double *val_m = new double[size]; \
218         type **in_rows = (type**)input->get_rows(); \
219         type **out_rows = (type**)output->get_rows(); \
220         int j; \
221  \
222 /* printf("DO_FEATHER 1\n"); */ \
223         if( end_x > start_x ) { \
224                 for( j = start_x; j < end_x; j++ ) { \
225         /* printf("DO_FEATHER 1.1 %d\n", j); */ \
226                         bzero(val_p, sizeof(double) * frame_h); \
227                         bzero(val_m, sizeof(double) * frame_h); \
228                         for( int k = 0; k < frame_h; k++ ) { \
229                                 src[k] = (double)in_rows[k][j]; \
230                         } \
231                         blur_strip(val_p, val_m, dst, src, frame_h, max); \
232                         for( int k = 0; k < frame_h; k++ ) { \
233                                 out_rows[k][j] = (type)dst[k]; \
234                         } \
235                 } \
236         } \
237         if( end_y > start_y ) { \
238                 for( j = start_y; j < end_y; j++ ) { \
239         /* printf("DO_FEATHER 2 %d\n", j); */ \
240                         bzero(val_p, sizeof(double) * frame_w); \
241                         bzero(val_m, sizeof(double) * frame_w); \
242                         for( int k = 0; k < frame_w; k++ ) { \
243                                 src[k] = (double)out_rows[j][k]; \
244                         } \
245                         blur_strip(val_p, val_m, dst, src, frame_w, max); \
246                         for( int k = 0; k < frame_w; k++ ) { \
247                                 out_rows[j][k] = (type)dst[k]; \
248                         } \
249                 } \
250         } \
251 /* printf("DO_FEATHER 3\n"); */ \
252         delete [] src; \
253         delete [] dst; \
254         delete [] val_p; \
255         delete [] val_m; \
256 /* printf("DO_FEATHER 4\n"); */ \
257 }
258
259 //printf("do_feather %d\n", frame->get_color_model());
260         switch( input->get_color_model() ) {
261         case BC_A8:
262                 DO_FEATHER(unsigned char, 0xff);
263                 break;
264         case BC_A16:
265                 DO_FEATHER(uint16_t, 0xffff);
266                 break;
267         case BC_A_FLOAT:
268                 DO_FEATHER(float, 1);
269                 break;
270         }
271 }
272
273 void MaskUnit::process_package(LoadPackage *package)
274 {
275         MaskPackage *ptr = (MaskPackage*)package;
276         float engine_value = engine->value;
277         int engine_mode = engine->mode;
278
279         if( engine->recalculate && engine->step == DO_MASK ) {
280                 VFrame *mask = engine->feather > 0 ? engine->temp_mask : engine->mask;
281 // Generated oversampling frame
282                 int mask_w = mask->get_w();
283                 //int mask_h = mask->get_h();
284                 int oversampled_package_w = mask_w * OVERSAMPLE;
285                 int oversampled_package_h = (ptr->end_y - ptr->start_y) * OVERSAMPLE;
286                 if( temp &&
287                     (temp->get_w() != oversampled_package_w ||
288                      temp->get_h() != oversampled_package_h) ) {
289                         delete temp;  temp = 0;
290                 }
291                 if( !temp ) {
292                         temp = new VFrame(oversampled_package_w, oversampled_package_h, BC_A8, 0);
293                 }
294                 temp->clear_frame();
295 // Draw oversampled region of polygons on temp
296                 for( int k=0; k<engine->point_sets.total; ++k ) {
297                         int old_x, old_y;
298                         unsigned char max = k + 1;
299                         ArrayList<MaskPoint*> *points = engine->point_sets.values[k];
300
301                         if( points->total < 3 ) continue;
302 //printf("MaskUnit::process_package 2 %d %d\n", k, points->total);
303                         for( int i=0; i<points->total; ++i ) {
304                                 MaskPoint *point1 = points->values[i];
305                                 MaskPoint *point2 = (i >= points->total - 1) ?
306                                         points->values[0] :
307                                         points->values[i + 1];
308
309                                 float x, y;
310                                 int segments = (int)(sqrt(SQR(point1->x - point2->x) + SQR(point1->y - point2->y)));
311                                 if( point1->control_x2 == 0 &&
312                                         point1->control_y2 == 0 &&
313                                         point2->control_x1 == 0 &&
314                                         point2->control_y1 == 0 )
315                                         segments = 1;
316                                 float x0 = point1->x;
317                                 float y0 = point1->y;
318                                 float x1 = point1->x + point1->control_x2;
319                                 float y1 = point1->y + point1->control_y2;
320                                 float x2 = point2->x + point2->control_x1;
321                                 float y2 = point2->y + point2->control_y1;
322                                 float x3 = point2->x;
323                                 float y3 = point2->y;
324
325                                 for( int j = 0; j <= segments; j++ ) {
326                                         float t = (float)j / segments;
327                                         float tpow2 = t * t;
328                                         float tpow3 = t * t * t;
329                                         float invt = 1 - t;
330                                         float invtpow2 = invt * invt;
331                                         float invtpow3 = invt * invt * invt;
332
333                                         x = (        invtpow3 * x0
334                                                 + 3 * t     * invtpow2 * x1
335                                                 + 3 * tpow2 * invt     * x2
336                                                 +     tpow3            * x3);
337                                         y = (        invtpow3 * y0
338                                                 + 3 * t     * invtpow2 * y1
339                                                 + 3 * tpow2 * invt     * y2
340                                                 +     tpow3            * y3);
341
342                                         y -= ptr->start_y;
343                                         x *= OVERSAMPLE;
344                                         y *= OVERSAMPLE;
345
346                                         if( j > 0 ) {
347                                                 draw_line_clamped(temp, old_x, old_y, (int)x, (int)y, max);
348                                         }
349
350                                         old_x = (int)x;
351                                         old_y = (int)y;
352                                 }
353                         }
354 // Fill in the polygon in the horizontal direction
355                         for( int i=0; i<oversampled_package_h; ++i ) {
356                                 unsigned char *row = (unsigned char*)temp->get_rows()[i];
357                                 int value = 0, total = 0;
358
359                                 for( int j=0; j<oversampled_package_w; ++j )
360                                         if( row[j] == max ) ++total;
361
362                                 if( total > 1 ) {
363                                         if( total & 0x1 ) --total;
364                                         for( int j=0; j<oversampled_package_w; ++j ) {
365                                                 if( row[j]==max && total>0 ) {
366                                                         --total;
367                                                         value = value ? 0 : max;
368                                                 }
369                                                 else if( value )
370                                                         row[j] = value;
371                                         }
372                                 }
373                         }
374                 }
375 #define DOWNSAMPLE(type, temp_type, value, v) do { \
376 for( int y=0; y<ptr->end_y-ptr->start_y; ++y ) { \
377         type *output_row = (type*)mask->get_rows()[y + ptr->start_y]; \
378         unsigned char **input_rows = (unsigned char**)temp->get_rows() + y * OVERSAMPLE; \
379         for( int x=0; x<mask_w; ++x ) { \
380                 temp_type total = 0; \
381 /* Accumulate pixel */ \
382                 for( int k=0; k<OVERSAMPLE; ++k ) { \
383                         unsigned char *input_vector = input_rows[k] + x * OVERSAMPLE; \
384                         for( int l=0; l<OVERSAMPLE; ++l ) { \
385                                 total += (input_vector[l] ? value : 0); \
386                         } \
387                 } \
388 /* Divide pixel */ \
389                 total /= OVERSAMPLE * OVERSAMPLE; \
390                 output_row[x] = v; \
391         } \
392 } } while(0)
393
394                 if( engine_value < 0 ) {
395                         engine_value = -engine_value;
396                         engine_mode = 1-engine_mode;
397                 }
398 // Downsample polygon
399                 switch( mask->get_color_model() ) {
400                 case BC_A8: {
401                         unsigned char value;
402                         value = (int)(engine_value / 100 * 0xff);
403                         if( engine->value >= 0 )
404                                 DOWNSAMPLE(unsigned char, int64_t, value, total);
405                         else
406                                 DOWNSAMPLE(unsigned char, int64_t, value, value-total);
407                         break; }
408
409                 case BC_A16: {
410                         uint16_t value;
411                         value = (int)(engine_value / 100 * 0xffff);
412                         if( engine->value >= 0 )
413                                 DOWNSAMPLE(uint16_t, int64_t, value, total);
414                         else
415                                 DOWNSAMPLE(uint16_t, int64_t, value, value-total);
416                         break; }
417
418                 case BC_A_FLOAT: {
419                         float value;
420                         value = engine_value / 100;
421                         if( engine->value >= 0 )
422                                 DOWNSAMPLE(float, double, value, total);
423                         else
424                                 DOWNSAMPLE(float, double, value, value-total);
425                         break; }
426                 }
427         }
428
429         if( engine->step == DO_X_FEATHER && engine->recalculate && // Feather polygon
430             engine->feather > 0 ) {
431                 do_feather(engine->mask,
432                         engine->temp_mask, engine->feather,
433                         ptr->start_y, ptr->end_y, 0, 0);
434 //printf("MaskUnit::process_package 3 %f\n", engine->feather);
435         }
436
437         if( engine->step == DO_Y_FEATHER && engine->recalculate && // Feather polygon
438             engine->feather > 0 ) {
439                 do_feather(engine->mask,
440                         engine->temp_mask, engine->feather,
441                         0, 0, ptr->start_x, ptr->end_x);
442         }
443
444         if( engine->step == DO_APPLY ) { // Apply mask
445 #define APPLY_MASK_ALPHA(cmodel, type, max, components, do_yuv, a, b) \
446 case cmodel: \
447 for( int y=ptr->start_y; y<ptr->end_y; ++y ) { \
448         type *output_row = (type*)engine->output->get_rows()[y]; \
449         type *mask_row = (type*)engine->mask->get_rows()[y]; \
450         int chroma_offset = (int)(max + 1) / 2; \
451         for( int x=0; x<mask_w; ++x ) { \
452                 int m = mask_row[x], n = max-m; \
453                 if( components == 4 ) { \
454                         output_row[x*4 + 3] = output_row[x*4 + 3]*a / max; \
455                 } \
456                 else { \
457                         output_row[x*3 + 0] = output_row[x*3 + 0]*a / max; \
458                         output_row[x*3 + 1] = output_row[x*3 + 1]*a / max; \
459                         output_row[x*3 + 2] = output_row[x*3 + 2]*a / max; \
460                         if( do_yuv ) { \
461                                 output_row[x*3 + 1] += chroma_offset*b / max; \
462                                 output_row[x*3 + 2] += chroma_offset*b / max; \
463                         } \
464                 } \
465         } \
466 } break
467
468 #define MASK_ALPHA(mode, a, b) \
469 case mode: \
470         switch( engine->output->get_color_model() ) { \
471         APPLY_MASK_ALPHA(BC_RGB888, unsigned char, 0xff, 3, 0, a, b); \
472         APPLY_MASK_ALPHA(BC_RGB_FLOAT, float, 1.0, 3, 0, a, b); \
473         APPLY_MASK_ALPHA(BC_YUV888, unsigned char, 0xff, 3, 1, a, b); \
474         APPLY_MASK_ALPHA(BC_RGBA_FLOAT, float, 1.0, 4, 0, a, b); \
475         APPLY_MASK_ALPHA(BC_YUVA8888, unsigned char, 0xff, 4, 1, a, b); \
476         APPLY_MASK_ALPHA(BC_RGBA8888, unsigned char, 0xff, 4, 0, a, b); \
477         APPLY_MASK_ALPHA(BC_RGB161616, uint16_t, 0xffff, 3, 0, a, b); \
478         APPLY_MASK_ALPHA(BC_YUV161616, uint16_t, 0xffff, 3, 1, a, b); \
479         APPLY_MASK_ALPHA(BC_YUVA16161616, uint16_t, 0xffff, 4, 1, a, b); \
480         APPLY_MASK_ALPHA(BC_RGBA16161616, uint16_t, 0xffff, 4, 0, a, b); \
481 } break
482
483 //printf("MaskUnit::process_package 1 %d\n", engine->mode);
484                 int mask_w = engine->mask->get_w();
485                 switch( engine_mode ) {
486                 MASK_ALPHA(MASK_MULTIPLY_ALPHA, m, n);
487                 MASK_ALPHA(MASK_SUBTRACT_ALPHA, n, m);
488                 }
489         }
490 }
491
492
493 MaskEngine::MaskEngine(int cpus)
494  : LoadServer(cpus, cpus * OVERSAMPLE * 2)
495 // : LoadServer(1, OVERSAMPLE * 2)
496 {
497         mask = 0;
498 }
499
500 MaskEngine::~MaskEngine()
501 {
502         if( mask ) {
503                 delete mask;
504                 delete temp_mask;
505         }
506
507         for( int i = 0; i < point_sets.total; i++ ) {
508                 ArrayList<MaskPoint*> *points = point_sets.values[i];
509                 points->remove_all_objects();
510         }
511         point_sets.remove_all_objects();
512 }
513
514 int MaskEngine::points_equivalent(ArrayList<MaskPoint*> *new_points,
515         ArrayList<MaskPoint*> *points)
516 {
517 //printf("MaskEngine::points_equivalent %d %d\n", new_points->total, points->total);
518         if( new_points->total != points->total ) return 0;
519
520         for( int i = 0; i < new_points->total; i++ ) {
521                 if( !(*new_points->values[i] == *points->values[i]) ) return 0;
522         }
523
524         return 1;
525 }
526
527 void MaskEngine::do_mask(VFrame *output,
528         int64_t start_position_project,
529         MaskAutos *keyframe_set,
530         MaskAuto *keyframe,
531         MaskAuto *default_auto)
532 {
533         int new_color_model = 0;
534         recalculate = 0;
535
536         switch( output->get_color_model() ) {
537         case BC_RGB_FLOAT:
538         case BC_RGBA_FLOAT:
539                 new_color_model = BC_A_FLOAT;
540                 break;
541
542         case BC_RGB888:
543         case BC_RGBA8888:
544         case BC_YUV888:
545         case BC_YUVA8888:
546                 new_color_model = BC_A8;
547                 break;
548
549         case BC_RGB161616:
550         case BC_RGBA16161616:
551         case BC_YUV161616:
552         case BC_YUVA16161616:
553                 new_color_model = BC_A16;
554                 break;
555         }
556
557 // Determine if recalculation is needed
558 SET_TRACE
559
560         if( mask &&
561             (mask->get_w() != output->get_w() ||
562              mask->get_h() != output->get_h() ||
563              mask->get_color_model() != new_color_model) ) {
564                 delete mask;
565                 delete temp_mask;
566                 mask = 0;
567                 recalculate = 1;
568         }
569
570         if( !recalculate ) {
571                 if( point_sets.total != keyframe_set->total_submasks(start_position_project,
572                         PLAY_FORWARD) )
573                         recalculate = 1;
574         }
575
576         if( !recalculate ) {
577                 for( int i=0,n=keyframe_set->total_submasks(start_position_project, PLAY_FORWARD);
578                                 i<n && !recalculate; ++i ) {
579                         ArrayList<MaskPoint*> new_points;
580                         keyframe_set->get_points(&new_points, i,
581                                 start_position_project, PLAY_FORWARD);
582                         if( !points_equivalent(&new_points, point_sets.values[i]) )
583                                 recalculate = 1;
584                         new_points.remove_all_objects();
585                 }
586         }
587
588         int new_value = keyframe_set->get_value(start_position_project,
589                 PLAY_FORWARD);
590         float new_feather = keyframe_set->get_feather(start_position_project,
591                 PLAY_FORWARD);
592
593         if( recalculate ||
594                 !EQUIV(new_feather, feather) ||
595                 !EQUIV(new_value, value) ) {
596                 recalculate = 1;
597                 if( !mask ) {
598                         mask = new VFrame(output->get_w(), output->get_h(),
599                                         new_color_model, 0);
600                         temp_mask = new VFrame(output->get_w(), output->get_h(),
601                                         new_color_model, 0);
602                 }
603                 if( new_feather > 0 )
604                         temp_mask->clear_frame();
605                 else
606                         mask->clear_frame();
607
608                 for( int i = 0; i < point_sets.total; i++ ) {
609                         ArrayList<MaskPoint*> *points = point_sets.values[i];
610                         points->remove_all_objects();
611                 }
612                 point_sets.remove_all_objects();
613
614                 for( int i = 0;
615                         i < keyframe_set->total_submasks(start_position_project,
616                                 PLAY_FORWARD);
617                         i++ ) {
618                         ArrayList<MaskPoint*> *new_points = new ArrayList<MaskPoint*>;
619                         keyframe_set->get_points(new_points,
620                                 i,
621                                 start_position_project,
622                                 PLAY_FORWARD);
623                         point_sets.append(new_points);
624                 }
625         }
626
627
628
629         this->output = output;
630         this->mode = default_auto->mode;
631         this->feather = new_feather;
632         this->value = new_value;
633
634
635 // Run units
636 SET_TRACE
637         step = DO_MASK;
638         process_packages();
639         step = DO_Y_FEATHER;
640         process_packages();
641         step = DO_X_FEATHER;
642         process_packages();
643         step = DO_APPLY;
644         process_packages();
645 SET_TRACE
646
647
648 }
649
650 void MaskEngine::init_packages()
651 {
652 SET_TRACE
653 //printf("MaskEngine::init_packages 1\n");
654         int x0 = 0, y0 = 0, i = 0, n = get_total_packages();
655         int out_w = output->get_w(), out_h = output->get_h();
656 SET_TRACE
657         while( i < n ) {
658                 MaskPackage *ptr = (MaskPackage*)get_package(i++);
659                 int x1 = (out_w * i) / n, y1 = (out_h * i) / n;
660                 ptr->start_x = x0;  ptr->end_x = x1;
661                 ptr->start_y = y0;  ptr->end_y = y1;
662                 x0 = x1;  y0 = y1;
663         }
664 SET_TRACE
665 //printf("MaskEngine::init_packages 2\n");
666 }
667
668 LoadClient* MaskEngine::new_client()
669 {
670         return new MaskUnit(this);
671 }
672
673 LoadPackage* MaskEngine::new_package()
674 {
675         return new MaskPackage;
676 }
677