9e1cc94dc81f300e430f458b1ccdf198e6807c96
[goodguy/history.git] / cinelerra-5.1 / plugins / bluebanana / bluebanana.C
1 /*
2  * Cinelerra :: Blue Banana - color modification plugin for Cinelerra-CV
3  * Copyright (C) 2012-2013 Monty <monty@xiph.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21 #include <math.h>
22 #include <stdint.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include "bcdisplayinfo.h"
27 #include "bcsignals.h"
28 #include "clip.h"
29 #include "bchash.h"
30 #include "filexml.h"
31 #include "bluebanana.h"
32 #include "bluebananaconfig.h"
33 #include "bluebananawindow.h"
34 #include "keyframe.h"
35 #include "language.h"
36 #include "loadbalance.h"
37 #include "playback3d.h"
38 #include "cicolors.h"
39 #include "vframe.h"
40 #include "workarounds.h"
41
42 class BluebananaMain;
43 class BluebananaEngine;
44 class BluebananaWindow;
45
46 REGISTER_PLUGIN(BluebananaMain)
47
48 BluebananaMain::BluebananaMain(PluginServer *server)
49  : PluginVClient(server)
50 {
51   engine = 0;
52
53   /* be sure a lookup update triggers */
54   lookup_cache.Hsel_lo=-999999;
55   lookup_cache.Ssel_lo=-999999;
56   lookup_cache.Vsel_lo=-999999;
57   lookup_cache.Fsel_lo=-999999;
58
59   lookup_cache.Sadj_lo=-999999;
60   lookup_cache.Vadj_lo=-999999;
61   lookup_cache.Radj_lo=-999999;
62   lookup_cache.Gadj_lo=-999999;
63   lookup_cache.Badj_lo=-999999;
64
65   colormodel=-1;
66
67   ants_counter=0;
68
69   memset(red_histogram,0,sizeof(red_histogram));
70   memset(green_histogram,0,sizeof(green_histogram));
71   memset(blue_histogram,0,sizeof(blue_histogram));
72   memset(hue_histogram,0,sizeof(hue_histogram));
73   memset(sat_histogram,0,sizeof(sat_histogram));
74   memset(value_histogram,0,sizeof(value_histogram));
75 }
76
77 BluebananaMain::~BluebananaMain() {
78
79   // if ants are running, run one more pane update to hide them (gui
80   // is already marked as closed)
81   if(server && server->mwindow && ants_counter>0)
82     server->mwindow->sync_parameters();
83
84   delete engine;
85 }
86
87 const char* BluebananaMain::plugin_title() { return _("Blue Banana"); }
88 int BluebananaMain::is_realtime() { return 1; }
89
90 NEW_WINDOW_MACRO(BluebananaMain, BluebananaWindow)
91 LOAD_CONFIGURATION_MACRO(BluebananaMain, BluebananaConfig)
92
93 void BluebananaMain::render_gui(void *data){
94   if(thread){
95     BluebananaMain *that = (BluebananaMain *)data; // that is server-side
96     BluebananaWindow *window = (BluebananaWindow *)thread->window;
97     window->lock_window("BluebananaMain::render_gui");
98
99     /* push histogram data to gui */
100     window->update_histograms(that);
101
102     /* push any colormodel update to gui */
103     if(that->frame && colormodel != that->frame->get_color_model()){
104       colormodel = that->frame->get_color_model();
105       window->update();
106     }
107
108     window->unlock_window();
109   }
110 }
111
112 void BluebananaMain::update_gui(){
113   if(thread){
114     BluebananaWindow *window = (BluebananaWindow *)thread->window;
115     window->lock_window("BluebananaMain::update_gui");
116     window->flush_config_change();
117     int reconfigure = load_configuration();
118     if(reconfigure)
119       window->update();
120
121     window->unlock_window();
122   }
123 }
124
125 void BluebananaMain::save_data(KeyFrame *keyframe){
126   FileXML output;
127
128   // cause data to be stored directly in text
129   output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
130   output.tag.set_title("BLUEBANANA");
131
132   output.tag.set_property("ACTIVE", config.active);
133   output.tag.set_property("INVERT_SELECTION", config.invert_selection);
134   output.tag.set_property("USE_MASK", config.use_mask);
135   output.tag.set_property("CAPTURE_MASK", config.capture_mask);
136
137   output.tag.set_property("HUE_ACTIVE", config.Hsel_active);
138   output.tag.set_property("HUE_LO", config.Hsel_lo);
139   output.tag.set_property("HUE_HI", config.Hsel_hi);
140   output.tag.set_property("HUE_OVERLAP", config.Hsel_over);
141
142   output.tag.set_property("SATURATION_ACTIVE", config.Ssel_active);
143   output.tag.set_property("SATURATION_LO", config.Ssel_lo);
144   output.tag.set_property("SATURATION_HI", config.Ssel_hi);
145   output.tag.set_property("SATURATION_OVERLAP", config.Ssel_over);
146
147   output.tag.set_property("VALUE_ACTIVE", config.Vsel_active);
148   output.tag.set_property("VALUE_LO", config.Vsel_lo);
149   output.tag.set_property("VALUE_HI", config.Vsel_hi);
150   output.tag.set_property("VALUE_OVERLAP", config.Vsel_over);
151
152   output.tag.set_property("FILL_ACTIVE", config.Fsel_active);
153   output.tag.set_property("FILL_ERODE", config.Fsel_erode);
154   output.tag.set_property("FILL_LO", config.Fsel_lo);
155   output.tag.set_property("FILL_MID", config.Fsel_mid);
156   output.tag.set_property("FILL_HI", config.Fsel_hi);
157   output.tag.set_property("FILL_FEATHER", config.Fsel_over);
158
159   output.tag.set_property("HUE_ADJUST_ACTIVE", config.Hadj_active);
160   output.tag.set_property("HUE_ADJUST", config.Hadj_val);
161
162   output.tag.set_property("SATURATION_ADJUST_ACTIVE", config.Sadj_active);
163   output.tag.set_property("SATURATION_ADJUST_GAMMA", config.Sadj_gamma);
164   output.tag.set_property("SATURATION_ADJUST_LO", config.Sadj_lo);
165   output.tag.set_property("SATURATION_ADJUST_HI", config.Sadj_hi);
166
167   output.tag.set_property("VALUE_ADJUST_ACTIVE", config.Vadj_active);
168   output.tag.set_property("VALUE_ADJUST_GAMMA", config.Vadj_gamma);
169   output.tag.set_property("VALUE_ADJUST_LO", config.Vadj_lo);
170   output.tag.set_property("VALUE_ADJUST_HI", config.Vadj_hi);
171
172   output.tag.set_property("RED_ADJUST_ACTIVE", config.Radj_active);
173   output.tag.set_property("RED_ADJUST_GAMMA", config.Radj_gamma);
174   output.tag.set_property("RED_ADJUST_LO", config.Radj_lo);
175   output.tag.set_property("RED_ADJUST_HI", config.Radj_hi);
176
177   output.tag.set_property("GREEN_ADJUST_ACTIVE", config.Gadj_active);
178   output.tag.set_property("GREEN_ADJUST_GAMMA", config.Gadj_gamma);
179   output.tag.set_property("GREEN_ADJUST_LO", config.Gadj_lo);
180   output.tag.set_property("GREEN_ADJUST_HI", config.Gadj_hi);
181
182   output.tag.set_property("BLUE_ADJUST_ACTIVE", config.Badj_active);
183   output.tag.set_property("BLUE_ADJUST_GAMMA", config.Badj_gamma);
184   output.tag.set_property("BLUE_ADJUST_LO", config.Badj_lo);
185   output.tag.set_property("BLUE_ADJUST_HI", config.Badj_hi);
186
187   output.tag.set_property("OPACITY_ADJUST_ACTIVE", config.Oadj_active);
188   output.tag.set_property("OPACITY_ADJUST", config.Oadj_val);
189   output.tag.set_property("ALPHA_ADJUST_ACTIVE", config.Aadj_active);
190   output.tag.set_property("ALPHA_ADJUST", config.Aadj_val);
191
192   output.append_tag();
193   output.append_newline();
194
195   output.tag.set_title("/BLUEBANANA");
196   output.append_tag();
197   output.append_newline();
198
199   if(keyframe->position==0){
200     /* this will otherwise overwrite the nonauto information as well */
201     output_nonauto(&output);
202   }
203
204   output.terminate_string();
205 }
206
207 // save non-auto data to the default keyframe at zero and does it
208 // without alerting the keyframing mechanism
209 void BluebananaMain::save_nonauto(){
210
211   KeyFrame *default_keyframe=get_prev_keyframe(0);
212   if(default_keyframe){
213     FileXML input;
214     FileXML output;
215     int result = 0;
216
217     input.read_from_string(default_keyframe->get_data());
218     output.set_shared_output(default_keyframe->get_data(), MESSAGESIZE);
219
220     while(!result){
221       result = input.read_tag();
222
223       if(!result &&
224          !input.tag.title_is("BLUEBANANA_NONAUTO") &&
225          !input.tag.title_is("/BLUEBANANA_NONAUTO")){
226         input.tag.write_tag(&output);
227         output.append_newline();
228       }
229     }
230
231     output_nonauto(&output);
232   }
233 }
234
235 void BluebananaMain::output_nonauto(FileXML *output){
236   output->tag.set_title("BLUEBANANA_NONAUTO");
237   output->tag.set_property("MARK", config.mark);
238   output->append_tag();
239   output->tag.set_title("/BLUEBANANA_NONAUTO");
240   output->append_tag();
241   output->append_newline();
242   output->terminate_string();
243 }
244
245 void BluebananaMain::load_nonauto(){
246   /* nonauto data stored in the default keyframe at position 0 */
247   KeyFrame *default_keyframe=get_prev_keyframe(0);
248   if(default_keyframe){
249     FileXML input;
250     int result = 0;
251     input.set_shared_input(default_keyframe->get_data(), strlen(default_keyframe->get_data()));
252
253     while(!result){
254       result = input.read_tag();
255
256       if(!result && input.tag.title_is("BLUEBANANA_NONAUTO")){
257         config.mark = input.tag.get_property("MARK", config.mark);
258       }
259     }
260   }
261 }
262
263
264 void BluebananaMain::read_data(KeyFrame *keyframe){
265   FileXML input;
266   int result = 0;
267
268   input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
269
270   while(!result){
271     result = input.read_tag();
272
273     if(!result && input.tag.title_is("BLUEBANANA")){
274       config.active = input.tag.get_property("ACTIVE", config.active);
275       config.invert_selection = input.tag.get_property("INVERT_SELECTION", config.invert_selection);
276       config.use_mask = input.tag.get_property("USE_MASK", config.use_mask);
277       config.capture_mask = input.tag.get_property("CAPTURE_MASK", config.capture_mask);
278
279       config.Hsel_active = input.tag.get_property("HUE_ACTIVE", config.Hsel_active);
280       config.Hsel_lo = input.tag.get_property("HUE_LO", config.Hsel_lo);
281       config.Hsel_hi = input.tag.get_property("HUE_HI", config.Hsel_hi);
282       config.Hsel_over = input.tag.get_property("HUE_OVERLAP", config.Hsel_over);
283
284       config.Ssel_active = input.tag.get_property("SATURATION_ACTIVE", config.Ssel_active);
285       config.Ssel_lo = input.tag.get_property("SATURATION_LO", config.Ssel_lo);
286       config.Ssel_hi = input.tag.get_property("SATURATION_HI", config.Ssel_hi);
287       config.Ssel_over = input.tag.get_property("SATURATION_OVERLAP", config.Ssel_over);
288
289       config.Vsel_active = input.tag.get_property("VALUE_ACTIVE", config.Vsel_active);
290       config.Vsel_lo = input.tag.get_property("VALUE_LO", config.Vsel_lo);
291       config.Vsel_hi = input.tag.get_property("VALUE_HI", config.Vsel_hi);
292       config.Vsel_over = input.tag.get_property("VALUE_OVERLAP", config.Vsel_over);
293
294       config.Fsel_active = input.tag.get_property("FILL_ACTIVE", config.Fsel_active);
295       config.Fsel_erode = input.tag.get_property("FILL_ERODE", config.Fsel_erode);
296       config.Fsel_lo = input.tag.get_property("FILL_LO", config.Fsel_lo);
297       config.Fsel_mid = input.tag.get_property("FILL_MID", config.Fsel_mid);
298       config.Fsel_hi = input.tag.get_property("FILL_HI", config.Fsel_hi);
299       config.Fsel_over = input.tag.get_property("FILL_FEATHER", config.Fsel_over);
300
301       config.Hadj_active = input.tag.get_property("HUE_ADJUST_ACTIVE", config.Hadj_active);
302       config.Hadj_val = input.tag.get_property("HUE_ADJUST", config.Hadj_val);
303
304       config.Sadj_active = input.tag.get_property("SATURATION_ADJUST_ACTIVE", config.Sadj_active);
305       config.Sadj_gamma = input.tag.get_property("SATURATION_ADJUST_GAMMA", config.Sadj_gamma);
306       config.Sadj_lo = input.tag.get_property("SATURATION_ADJUST_LO", config.Sadj_lo);
307       config.Sadj_hi = input.tag.get_property("SATURATION_ADJUST_HI", config.Sadj_hi);
308
309       config.Vadj_active = input.tag.get_property("VALUE_ADJUST_ACTIVE", config.Vadj_active);
310       config.Vadj_gamma = input.tag.get_property("VALUE_ADJUST_GAMMA", config.Vadj_gamma);
311       config.Vadj_lo = input.tag.get_property("VALUE_ADJUST_LO", config.Vadj_lo);
312       config.Vadj_hi = input.tag.get_property("VALUE_ADJUST_HI", config.Vadj_hi);
313
314       config.Radj_active = input.tag.get_property("RED_ADJUST_ACTIVE", config.Radj_active);
315       config.Radj_gamma = input.tag.get_property("RED_ADJUST_GAMMA", config.Radj_gamma);
316       config.Radj_lo = input.tag.get_property("RED_ADJUST_LO", config.Radj_lo);
317       config.Radj_hi = input.tag.get_property("RED_ADJUST_HI", config.Radj_hi);
318
319       config.Gadj_active = input.tag.get_property("GREEN_ADJUST_ACTIVE", config.Gadj_active);
320       config.Gadj_gamma = input.tag.get_property("GREEN_ADJUST_GAMMA", config.Gadj_gamma);
321       config.Gadj_lo = input.tag.get_property("GREEN_ADJUST_LO", config.Gadj_lo);
322       config.Gadj_hi = input.tag.get_property("GREEN_ADJUST_HI", config.Gadj_hi);
323
324       config.Badj_active = input.tag.get_property("BLUE_ADJUST_ACTIVE", config.Badj_active);
325       config.Badj_gamma = input.tag.get_property("BLUE_ADJUST_GAMMA", config.Badj_gamma);
326       config.Badj_lo = input.tag.get_property("BLUE_ADJUST_LO", config.Badj_lo);
327       config.Badj_hi = input.tag.get_property("BLUE_ADJUST_HI", config.Badj_hi);
328
329       config.Oadj_active = input.tag.get_property("OPACITY_ADJUST_ACTIVE", config.Oadj_active);
330       config.Oadj_val = input.tag.get_property("OPACITY_ADJUST", config.Oadj_val);
331       config.Aadj_active = input.tag.get_property("ALPHA_ADJUST_ACTIVE", config.Aadj_active);
332       config.Aadj_val = input.tag.get_property("ALPHA_ADJUST", config.Aadj_val);
333
334     }
335   }
336
337   load_nonauto();
338 }
339
340 static void select_grow_h(float *hrow, float *vrow, int width){
341   int i;
342
343   /* spread left */
344   for(i=0;i<width-1;i++){
345     if(hrow[i]<hrow[i+1])hrow[i]=hrow[i+1];
346     if(vrow[i]<hrow[i])vrow[i]=hrow[i];
347   }
348   /* spread right */
349   for(i=width-1;i>0;i--){
350     if(hrow[i]<hrow[i-1])hrow[i]=hrow[i-1];
351     if(vrow[i]<hrow[i])vrow[i]=hrow[i];
352   }
353 }
354
355 static void select_shrink_h(float *hrow, float *vrow, int width){
356   int i;
357
358   /* spread left */
359   for(i=0;i<width-1;i++){
360     if(hrow[i]>hrow[i+1])hrow[i]=hrow[i+1];
361     if(vrow[i]>hrow[i])vrow[i]=hrow[i];
362   }
363   /* spread right */
364   for(i=width-1;i>0;i--){
365     if(hrow[i]>hrow[i-1])hrow[i]=hrow[i-1];
366     if(vrow[i]>hrow[i])vrow[i]=hrow[i];
367   }
368 }
369
370 static void select_grow_v(float *row0, float *row1, int width){
371   int i;
372
373   /* spread into 0 */
374   for(i=0;i<width;i++)
375     if(row0[i]<row1[i])row0[i]=row1[i];
376 }
377
378 static void select_shrink_v(float *row0, float *row1, int width){
379   int i;
380
381   /* spread out of 0 */
382   for(i=0;i<width;i++)
383     if(row0[i]>row1[i])row0[i]=row1[i];
384 }
385
386 static void threaded_horizontal(float *in, float *work,
387                                 int width, int height,
388                                 BluebananaEngine *e, int tasks, int passes,
389                                 void(*func)(float *, float *, int)){
390
391   /* these are individually fast operations; here we do in fact make
392      cache region collisions as impossible as we can.  Live with the
393      overhead of the join. */
394   int i,j;
395   e->set_task(tasks,"H_even");
396   j = e->next_task();
397   {
398     int row = (j*2)*height/(tasks*2);
399     int end = (j*2+1)*height/(tasks*2);
400     for(;row<end;row++)
401       for(i=0;i<passes;i++)
402         func(in+row*width,work+row*width,width);
403   }
404   e->wait_task();
405
406   e->set_task(0,"H_odd");
407   {
408     int row = (j*2+1)*height/(tasks*2);
409     int end = (j*2+2)*height/(tasks*2);
410     for(;row<end;row++)
411       for(i=0;i<passes;i++)
412         func(in+row*width,work+row*width,width);
413   }
414   e->wait_task();
415 }
416
417 static void threaded_vertical(float *work, float *temp,
418                               int width, int height,
419                               BluebananaEngine *e, int tasks,
420                               void(*func)(float *, float *, int)){
421
422   /* regions overlap, so this becomes a bit more complex. */
423
424   /* rather than on-demand task allocation, we use the task engine to
425      grab a slot, then reuse this same slot through several joins */
426
427   e->set_task(tasks,"up_odd");
428   int region = e->next_task(); /* grab one slot */
429   int start_row = (region*2)*height/(tasks*2);
430   int mid_row = (region*2+1)*height/(tasks*2);
431   int end_row = (region*2+2)*height/(tasks*2);
432   int row;
433
434   /* spread up, starting at middle row, moving down */
435   /* first task is to save a copy of the un-transformed middle row, as
436      we'll need it for the even pass */
437   memcpy(temp,work+mid_row*width,sizeof(*temp)*width);
438
439   /* odd interleave */
440   for(row=mid_row;row<end_row-1;row++)
441     func(work+row*width,work+(row+1)*width,width);
442   if(end_row<height && row<end_row)
443     func(work+row*width,work+(row+1)*width,width);
444   e->wait_task();
445
446   /* even interleave */
447   e->set_task(0,"up_even");
448   for(row=start_row;row<mid_row-1;row++)
449     func(work+row*width,work+(row+1)*width,width);
450   if(row<mid_row)
451     func(work+row*width,temp,width);
452   e->wait_task();
453
454   /* spread down, starting at mid row and moving up */
455   /* once again, grab a temp vector for the second pass overlap */
456   memcpy(temp,work+mid_row*width,sizeof(*temp)*width);
457
458   /* even interleave */
459   e->set_task(0,"down_even");
460   for(row=mid_row;row>start_row;row--)
461     func(work+row*width,work+(row-1)*width,width);
462   if(start_row>0)
463     func(work+row*width,work+(row-1)*width,width);
464   e->wait_task();
465
466   /* odd interleave */
467   e->set_task(0,"down_odd");
468   for(row=end_row-1;row>mid_row+1;row--)
469     func(work+row*width,work+(row-1)*width,width);
470   if(row>mid_row)
471     func(work+row*width,temp,width);
472   e->wait_task();
473
474   /* done */
475 }
476
477 static float *fill_one(float *in, float *work,
478                       int width, int height,
479                       BluebananaEngine *e, // NULL if we're not threading
480                       char *pattern,
481                       int n){
482   int i,j;
483   int tasks = e?e->get_total_packages():0;
484   float temp[width];
485
486   if(n){
487
488     if(e){
489
490       /* multiple memcpys running at once is occasionally a total
491          cache disaster on Sandy Bridge.  So only one thread gets to
492          copy, the others wait. */
493       e->set_task(1,"fill_memcpy");
494       while((j = e->next_task())>=0){
495         memcpy(work,in,width*height*sizeof(*work));
496       }
497
498     }else{
499       memcpy(work,in,width*height*sizeof(*work));
500     }
501
502
503     for(i=0;i<n;i++){
504       switch(pattern[i]){
505       case 'H': /* grow horizontal */
506         if(e){
507           threaded_horizontal(in, work, width, height, e, tasks, 1, select_grow_h);
508         }else{
509           for(j=0;j<height;j++)
510             select_grow_h(in+j*width,work+j*width,width);
511         }
512         break;
513
514       case 'V': /* grow vertical */
515         if(e){
516           threaded_vertical(work, temp, width, height, e, tasks, select_grow_v);
517         }else{
518           for(j=0;j<height-1;j++)
519             select_grow_v(work+j*width,work+(j+1)*width,width);
520           for(j=height-1;j>0;j--)
521             select_grow_v(work+j*width,work+(j-1)*width,width);
522         }
523         break;
524
525       case 'h': /* shrink horizontal */
526         if(e){
527           threaded_horizontal(in, work, width, height, e, tasks, 1, select_shrink_h);
528         }else{
529           for(j=0;j<height;j++)
530             select_shrink_h(in+j*width,work+j*width,width);
531         }
532         break;
533
534       default: /* shrink vertical */
535
536         if(e){
537           threaded_vertical(work, temp, width, height, e, tasks, select_shrink_v);
538         }else{
539           for(j=0;j<height-1;j++)
540             select_shrink_v(work+j*width,work+(j+1)*width,width);
541           for(j=height-1;j>0;j--)
542             select_shrink_v(work+j*width,work+(j-1)*width,width);
543         }
544         break;
545       }
546     }
547     return work;
548   }else{
549     return in;
550   }
551 }
552
553 static void select_feather_h(float *p, float *dummy, int w){
554   for(int x=0;x<w-1;x++)
555     p[x] = (p[x]+p[x+1])*.5;
556   for(int x=w-1;x>0;x--)
557     p[x] = (p[x]+p[x-1])*.5;
558 }
559
560 static void select_feather_v(float *p0, float *p1, int w){
561   for(int x=0; x<w; x++)
562     p0[x] = (p0[x]+p1[x])*.5;
563 }
564
565 static void feather_one(float *in,
566                         int width, int height,
567                         BluebananaEngine *e, // NULL if we're not threading
568                         int n){
569   int i,j;
570   int tasks = e?e->get_total_packages():0;
571   float temp[width];
572
573   if(e){
574     threaded_horizontal(in, 0, width, height, e, tasks, n, select_feather_h);
575     for(int i=0;i<n;i++)
576       threaded_vertical(in, temp, width, height, e, tasks, select_feather_v);
577   }else{
578     for(j=0;j<height;j++)
579       for(i=0;i<n;i++)
580         select_feather_h(in+j*width,0,width);
581
582     for(i=0;i<n;i++){
583       for(j=0;j<height-1;j++)
584         select_feather_v(in+j*width,in+(j+1)*width,width);
585       for(j=height-1;j>0;j--)
586         select_feather_v(in+j*width,in+(j-1)*width,width);
587     }
588   }
589 }
590
591 /* here and not in the engine as the GUI also uses it (without
592    threading) */
593 float *BluebananaMain::fill_selection(float *in, float *work,
594                                          int width, int height,
595                                          BluebananaEngine *e){
596   float *A=in;
597   float *B=work;
598   float *C;
599
600   C=fill_one(A,B,width,height,e,select_one,select_one_n);
601   C=fill_one(C,(C==A?B:A),width,height,e,select_two,select_two_n);
602   C=fill_one(C,(C==A?B:A),width,height,e,select_three,select_three_n);
603
604   feather_one(C,width,height,e,config.Fsel_over);
605
606   return C;
607 }
608
609
610 int BluebananaMain::process_buffer(VFrame *frame,
611                                    int64_t start_position,
612                                    double frame_rate){
613   ants_counter++;
614
615   SET_TRACE
616   load_configuration();
617   this->frame = frame;
618
619   SET_TRACE
620   update_lookups(1);
621
622   SET_TRACE
623   read_frame(frame, 0, start_position, frame_rate, 0);
624
625   if(!engine)
626     engine = new BluebananaEngine(this, get_project_smp() + 1,
627                                   get_project_smp() + 1);
628   SET_TRACE
629   engine->process_packages(frame);
630
631   // push final histograms to UI if it's up
632   SET_TRACE
633   send_render_gui(this);
634
635   return 0;
636 }
637