7920b622a395c1a4f37aec4f34a6cf81fe64d1a0
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / shapewipe / shapewipe.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 "bcdisplayinfo.h"
23 #include "bchash.h"
24 #include "cstrdup.h"
25 #include "edl.inc"
26 #include "filesystem.h"
27 #include "filexml.h"
28 #include "language.h"
29 #include "overlayframe.h"
30 #include "theme.h"
31 #include "vframe.h"
32 #include "shapewipe.h"
33
34 #include <png.h>
35 #include <math.h>
36 #include <stdint.h>
37 #include <string.h>
38
39 #define SHAPE_SEARCHPATH "/shapes"
40 #define DEFAULT_SHAPE "circle"
41 // feather slider range log2 = -10 .. -1 == 9.8e-4 .. 0.5
42 #define SHAPE_FLOG_MIN -10.
43 #define SHAPE_FLOG_MAX -1.
44 #define SHAPE_FMIN expf(M_LN2*SHAPE_FLOG_MIN)
45 #define SHAPE_FMAX expf(M_LN2*SHAPE_FLOG_MAX)
46
47 REGISTER_PLUGIN(ShapeWipeMain)
48
49 ShapeWipeConfig::ShapeWipeConfig()
50 {
51         direction = 0;
52         feather = SHAPE_FMIN;
53         preserve_aspect = 0;
54         strcpy(shape_name, DEFAULT_SHAPE);
55 }
56 ShapeWipeConfig::~ShapeWipeConfig()
57 {
58 }
59
60 void ShapeWipeConfig::read_xml(KeyFrame *keyframe)
61 {
62         FileXML input;
63         input.set_shared_input(keyframe->xbuf);
64
65         while( !input.read_tag() ) {
66                 if( input.tag.title_is("SHAPEWIPE") ) {
67                         direction = input.tag.get_property("DIRECTION", direction);
68                         feather = input.tag.get_property("FEATHER", feather);
69                         preserve_aspect = input.tag.get_property("PRESERVE_ASPECT", preserve_aspect);
70                         input.tag.get_property("SHAPE_NAME", shape_name);
71                 }
72         }
73 }
74 void ShapeWipeConfig::save_xml(KeyFrame *keyframe)
75 {
76         FileXML output;
77         output.set_shared_output(keyframe->xbuf);
78         output.tag.set_title("SHAPEWIPE");
79         output.tag.set_property("DIRECTION", direction);
80         output.tag.set_property("FEATHER", feather);
81         output.tag.set_property("PRESERVE_ASPECT", preserve_aspect);
82         output.tag.set_property("SHAPE_NAME", shape_name);
83         output.append_tag();
84         output.tag.set_title("/SHAPEWIPE");
85         output.append_tag();
86         output.terminate_string();
87 }
88
89
90 ShapeWipeW2B::ShapeWipeW2B(ShapeWipeMain *plugin,
91         ShapeWipeWindow *window, int x, int y)
92  : BC_Radial(x, y, plugin->config.direction == 0, _("White to Black"))
93 {
94         this->plugin = plugin;
95         this->window = window;
96 }
97
98 int ShapeWipeW2B::handle_event()
99 {
100         update(1);
101         plugin->config.direction = 0;
102         window->right->update(0);
103         plugin->send_configure_change();
104         return 0;
105 }
106
107 ShapeWipeB2W::ShapeWipeB2W(ShapeWipeMain *plugin,
108         ShapeWipeWindow *window, int x, int y)
109  : BC_Radial(x, y, plugin->config.direction == 1, _("Black to White"))
110 {
111         this->plugin = plugin;
112         this->window = window;
113 }
114
115 int ShapeWipeB2W::handle_event()
116 {
117         update(1);
118         plugin->config.direction = 1;
119         window->left->update(0);
120         plugin->send_configure_change();
121         return 0;
122 }
123
124
125 ShapeWipePreserveAspectRatio::ShapeWipePreserveAspectRatio(ShapeWipeMain *plugin,
126         ShapeWipeWindow *window, int x, int y)
127  : BC_CheckBox (x, y, plugin->config.preserve_aspect, _("Preserve shape aspect ratio"))
128 {
129         this->plugin = plugin;
130         this->window = window;
131 }
132
133 int ShapeWipePreserveAspectRatio::handle_event()
134 {
135         plugin->config.preserve_aspect = get_value();
136         plugin->send_configure_change();
137         return 0;
138 }
139
140
141 ShapeWipeTumble::ShapeWipeTumble(ShapeWipeMain *client,
142         ShapeWipeWindow *window, int x, int y)
143  : BC_Tumbler(x, y)
144 {
145         this->client = client;
146         this->window = window;
147         set_increment(0.01);
148 }
149
150 int ShapeWipeTumble::handle_up_event()
151 {
152         window->prev_shape();
153         return 1;
154 }
155
156 int ShapeWipeTumble::handle_down_event()
157 {
158         window->next_shape();
159         return 0;
160 }
161
162
163 ShapeWipeFeather::ShapeWipeFeather(ShapeWipeMain *client,
164                 ShapeWipeWindow *window, int x, int y)
165  : BC_TumbleTextBox(window,
166                 bclip(client->config.feather, SHAPE_FMIN, SHAPE_FMAX),
167                 SHAPE_FMIN, SHAPE_FMAX, x, y, 64, 3)
168 {
169         this->client = client;
170         this->window = window;
171 }
172
173 int ShapeWipeFeather::handle_event()
174 {
175         float v = atof(get_text());
176         bclamp(v, SHAPE_FMIN, SHAPE_FMAX);
177         client->config.feather = v;
178         float sv = log(v)/M_LN2;
179         window->shape_fslider->update(sv);
180         client->send_configure_change();
181         return 1;
182 }
183
184 ShapeWipeFSlider::ShapeWipeFSlider(ShapeWipeMain *client,
185                 ShapeWipeWindow *window, int x, int y, int w)
186  : BC_FSlider(x, y, 0, w, w, SHAPE_FLOG_MIN, SHAPE_FLOG_MAX,
187         log(bclip(client->config.feather, SHAPE_FMIN, SHAPE_FMAX))/M_LN2)
188 {
189         this->client = client;
190         this->window = window;
191         set_precision(0.001);
192         set_pagination(0.01, 0.1);
193         enable_show_value(0);
194 }
195
196 int ShapeWipeFSlider::handle_event()
197 {
198         float v = get_value();
199         float vv = exp(M_LN2*v);
200         client->config.feather = vv;
201         window->shape_feather->update(vv);
202         client->send_configure_change();
203         return 1;
204 }
205
206 ShapeWipeReset::ShapeWipeReset(ShapeWipeMain *client,
207                 ShapeWipeWindow *window, int x, int y)
208  : BC_Button(x, y, client->get_theme()->get_image_set("reset_button"))
209 {
210         this->client = client;
211         this->window = window;
212         set_tooltip(_("Reset feather"));
213 }
214
215 int ShapeWipeReset::handle_event()
216 {
217         window->shape_fslider->update(SHAPE_FLOG_MIN);
218         float v = SHAPE_FMIN;
219         window->shape_feather->update(v);
220         client->config.feather = v;
221         client->send_configure_change();
222         return 1;
223 }
224
225 ShapeWipeShape::ShapeWipeShape(ShapeWipeMain *client,
226                 ShapeWipeWindow *window, int x, int y,
227                 int text_w, int list_h)
228  : BC_PopupTextBox(window, &window->shapes, client->config.shape_name,
229         x, y, text_w, list_h)
230 {
231         this->client = client;
232         this->window = window;
233 }
234
235 int ShapeWipeShape::handle_event()
236 {
237         strcpy(client->config.shape_name, get_text());
238         client->send_configure_change();
239         return 1;
240 }
241
242
243 ShapeWipeWindow::ShapeWipeWindow(ShapeWipeMain *plugin)
244  : PluginClientWindow(plugin, 425, 215, 425, 215, 0)
245 {
246         this->plugin = plugin;
247         shape_feather = 0;
248 }
249
250 ShapeWipeWindow::~ShapeWipeWindow()
251 {
252         shapes.remove_all_objects();
253         delete shape_feather;
254 }
255
256
257 void ShapeWipeWindow::create_objects()
258 {
259         BC_Title *title = 0;
260         lock_window("ShapeWipeWindow::create_objects");
261         int pad = 10, margin = 10;
262         int x = margin, y = margin;
263         int ww = get_w() - 2*margin;
264
265         plugin->init_shapes();
266         for( int i=0; i<plugin->shape_titles.size(); ++i ) {
267                 shapes.append(new BC_ListBoxItem(plugin->shape_titles.get(i)));
268         }
269
270         BC_TitleBar *bar;
271         add_subwindow(bar = new BC_TitleBar(x, y, ww, x+ww/12,
272                 pad, _("Wipe"), MEDIUMFONT));
273         y += bar->get_h() + pad;
274
275         add_subwindow(title = new BC_Title(x, y, _("Shape:")));
276         int x1 = 85, x2 = 355, x3 = 386;
277         shape_text = new ShapeWipeShape(plugin, this, x1, y, x2-x1, 200);
278         shape_text->create_objects();
279         add_subwindow(new ShapeWipeTumble(plugin, this, x3, y));
280         y += shape_text->get_h() + pad;
281
282         x = margin;
283         add_subwindow(title = new BC_Title(x, y, _("Feather:")));
284         x = x1;
285         shape_feather = new ShapeWipeFeather(plugin, this, x, y);
286         shape_feather->create_objects();
287         shape_feather->set_log_floatincrement(1);
288         x += shape_feather->get_w() + 2*pad;
289         add_subwindow(shape_fslider = new ShapeWipeFSlider(plugin, this, x, y, x2-x));
290         add_subwindow(shape_reset = new ShapeWipeReset(plugin, this, x3, y));
291         y += shape_fslider->get_h() + pad;
292
293         x = margin;
294         ShapeWipePreserveAspectRatio *aspect_ratio;
295         add_subwindow(aspect_ratio = new ShapeWipePreserveAspectRatio(
296                 plugin, this, x, y));
297         y += aspect_ratio->get_h() + pad;
298
299         add_subwindow(bar = new BC_TitleBar(x, y, ww, x+ww/12,
300                 pad, _("Direction"), MEDIUMFONT));
301         y += bar->get_h() + pad;
302         x = margin;
303         add_subwindow(left = new ShapeWipeW2B(plugin, this, x, y));
304         y += left->get_h();
305         add_subwindow(right = new ShapeWipeB2W(plugin, this, x, y));
306
307         show_window();
308         unlock_window();
309 }
310
311 void ShapeWipeWindow::next_shape()
312 {
313         ShapeWipeConfig &config = plugin->config;
314         int k = plugin->shape_titles.size();
315         while( --k>=0 && strcmp(plugin->shape_titles.get(k),config.shape_name) );
316
317         if( k >= 0 ) {
318                 if( ++k >= plugin->shape_titles.size() ) k = 0;
319                 strcpy(config.shape_name, plugin->shape_titles.get(k));
320                 shape_text->update(config.shape_name);
321         }
322         client->send_configure_change();
323 }
324
325 void ShapeWipeWindow::prev_shape()
326 {
327         ShapeWipeConfig &config = plugin->config;
328         int k = plugin->shape_titles.size();
329         while( --k>=0 && strcmp(plugin->shape_titles.get(k),config.shape_name) );
330
331         if( k >= 0 ) {
332                 if( --k < 0 ) k = plugin->shape_titles.size()-1;
333                 strcpy(config.shape_name, plugin->shape_titles.get(k));
334                 shape_text->update(config.shape_name);
335         }
336         client->send_configure_change();
337 }
338
339
340 ShapeWipeMain::ShapeWipeMain(PluginServer *server)
341  : PluginVClient(server)
342 {
343         input = 0;
344         output = 0;
345         engine = 0;
346         current_filename[0] = '\0';
347         current_name[0] = 0;
348         pattern_image = 0;
349         min_value = 255;
350         max_value = 0;
351         last_preserve_aspect = 0;
352         shapes_initialized = 0;
353         shape_paths.set_array_delete();
354         shape_titles.set_array_delete();
355 }
356
357 ShapeWipeMain::~ShapeWipeMain()
358 {
359         reset_pattern_image();
360         shape_paths.remove_all_objects();
361         shape_titles.remove_all_objects();
362         delete engine;
363 }
364
365 const char* ShapeWipeMain::plugin_title() { return N_("Shape Wipe"); }
366 int ShapeWipeMain::is_transition() { return 1; }
367 int ShapeWipeMain::uses_gui() { return 1; }
368
369 NEW_WINDOW_MACRO(ShapeWipeMain, ShapeWipeWindow);
370
371 void ShapeWipeMain::read_data(KeyFrame *keyframe)
372 {
373         config.read_xml(keyframe);
374 }
375 void ShapeWipeMain::save_data(KeyFrame *keyframe)
376 {
377         config.save_xml(keyframe);
378 }
379
380 void ShapeWipeMain::init_shapes()
381 {
382         if( !shapes_initialized ) {
383                 FileSystem fs;
384                 fs.set_filter("*.png");
385                 char shape_path[BCTEXTLEN];
386                 sprintf(shape_path, "%s%s", get_plugin_dir(), SHAPE_SEARCHPATH);
387                 fs.update(shape_path);
388
389                 for( int i=0; i<fs.total_files(); ++i ) {
390                         FileItem *file_item = fs.get_entry(i);
391                         if( !file_item->get_is_dir() ) {
392                                 shape_paths.append(cstrdup(file_item->get_path()));
393                                 char *ptr = cstrdup(file_item->get_name());
394                                 char *ptr2 = strrchr(ptr, '.');
395                                 if(ptr2) *ptr2 = 0;
396                                 shape_titles.append(ptr);
397                         }
398                 }
399
400                 shapes_initialized = 1;
401         }
402 }
403
404
405 int ShapeWipeMain::load_configuration()
406 {
407         read_data(get_prev_keyframe(get_source_position()));
408         return 1;
409 }
410
411 int ShapeWipeMain::read_pattern_image(char *shape_name,
412                 int new_frame_width, int new_frame_height)
413 {
414         png_byte header[8];
415         int is_png;
416         int row, col;
417         int pixel_width;
418         unsigned char value;
419         png_uint_32 width;
420         png_uint_32 height;
421         png_byte color_type;
422         png_byte bit_depth;
423         png_structp png_ptr = 0;
424         png_infop info_ptr = 0;
425         png_infop end_info = 0;
426         png_bytep *image = 0;
427         FILE *fp = 0;
428         frame_width = new_frame_width;
429         frame_height = new_frame_height;
430         int ret = 0;
431
432 // Convert name to filename
433         int k = shape_paths.size();
434         while( --k>=0 && strcmp(shape_titles[k], shape_name) );
435         if( k < 0 ) ret = 1;
436         if( !ret ) {
437                 strcpy(current_filename, shape_paths[k]);
438                 fp = fopen(current_filename, "rb");
439                 if( !fp ) ret = 1;
440         }
441         if( !ret ) {
442                 fread(header, 1, 8, fp);
443                 is_png = !png_sig_cmp(header, 0, 8);
444                 if( !is_png ) ret = 1;
445         }
446         if( !ret ) {
447                 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
448                 if( !png_ptr ) ret = 1;
449         }
450         if( !ret ) {
451                 /* Tell libpng we already checked the first 8 bytes */
452                 png_set_sig_bytes(png_ptr, 8);
453                 info_ptr = png_create_info_struct(png_ptr);
454                 if( !info_ptr ) ret = 1;
455         }
456         if( !ret ) {
457                 end_info = png_create_info_struct(png_ptr);
458                 if( !end_info ) ret = 1;
459         }
460         if( !ret ) {
461                 png_init_io(png_ptr, fp);
462                 png_read_info(png_ptr, info_ptr);
463
464                 color_type = png_get_color_type(png_ptr, info_ptr);
465                 bit_depth = png_get_bit_depth(png_ptr, info_ptr);
466                 width  = png_get_image_width (png_ptr, info_ptr);
467                 height = png_get_image_height(png_ptr, info_ptr);
468
469                 /* Skip the alpha channel if present
470                 * stripping alpha currently doesn't work in conjunction with
471                 * converting to grayscale in libpng */
472                 pixel_width = color_type & PNG_COLOR_MASK_ALPHA ? 2 : 1;
473                 /* Convert 16 bit data to 8 bit */
474                 if( bit_depth == 16 ) png_set_strip_16(png_ptr);
475                 /* Expand to 1 pixel per byte if necessary */
476                 if( bit_depth < 8 ) png_set_packing(png_ptr);
477
478                 /* Convert to grayscale */
479                 if( color_type == PNG_COLOR_TYPE_RGB ||
480                     color_type == PNG_COLOR_TYPE_RGB_ALPHA )
481                         png_set_rgb_to_gray_fixed(png_ptr, 1, -1, -1);
482
483                 /* Allocate memory to hold the original png image */
484                 image = (png_bytep*)new png_bytep[height];
485                 for( row=0; row<(int)height; ++row )
486                         image[row] = new png_byte[width*pixel_width];
487
488                 /* Allocate memory for the pattern image that will actually be
489                 * used for the wipe */
490                 pattern_image = new  unsigned char*[frame_height];
491
492                 png_read_image(png_ptr, image);
493                 png_read_end(png_ptr, end_info);
494
495                 double row_factor, col_factor;
496                 double row_offset = 0.5, col_offset = 0.5;      // for rounding
497
498                 if( config.preserve_aspect && aspect_w && aspect_h ) {
499                         row_factor = (height-1)/aspect_h;
500                         col_factor = (width-1)/aspect_w;
501                         if( row_factor < col_factor )
502                                 col_factor = row_factor;
503                         else
504                                 row_factor = col_factor;
505                         row_factor *= aspect_h/(double)(frame_height-1);
506                         col_factor *= aspect_w/(double)(frame_width-1);
507
508                         // center the pattern over the frame
509                         row_offset += (height-1-(frame_height-1)*row_factor)/2;
510                         col_offset += (width-1-(frame_width-1)*col_factor)/2;
511                 }
512                 else {
513                         // Stretch (or shrink) the pattern image to fill the frame
514                         row_factor = (double)(height-1)/(double)(frame_height-1);
515                         col_factor = (double)(width-1)/(double)(frame_width-1);
516                 }
517                 // first, determine range min..max
518                 for( int y=0; y<frame_height; ++y ) {
519                         row = (int)(row_factor*y + row_offset);
520                         for( int x=0; x<frame_width; ++x ) {
521                                 col = (int)(col_factor*x + col_offset)*pixel_width;
522                                 value = image[row][col];
523                                 if( value < min_value ) min_value = value;
524                                 if( value > max_value ) max_value = value;
525                         }
526                 }
527                 int range = max_value - min_value;
528                 if( !range ) range = 1;
529                 // scale to fade normalized pattern_image
530                 for( int y=0; y<frame_height; ++y ) {
531                         row = (int)(row_factor*y + row_offset);
532                         pattern_image[y] = new unsigned char[frame_width];
533                         for( int x=0; x<frame_width; ++x ) {
534                                 col = (int)(col_factor*x + col_offset)*pixel_width;
535                                 value = image[row][col];
536                                 pattern_image[y][x] = 0xff*(value - min_value) / range;
537                         }
538                 }
539         }
540
541         if( png_ptr || info_ptr || end_info )
542                 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
543         if( fp )
544                 fclose(fp);
545         if( image ) {
546                 for( row=0; row<(int)height; ++row )
547                         delete [] image[row];
548                 delete [] image;
549         }
550         return ret;
551 }
552
553 void ShapeWipeMain::reset_pattern_image()
554 {
555         if( pattern_image ) {
556                 for( int y=0; y<frame_height; ++y )
557                         delete [] pattern_image[y];
558                 delete [] pattern_image;  pattern_image = 0;
559                 min_value = 255;
560                 max_value = 0;  // updated in read_pattern_image
561         }
562 }
563
564 #define SHAPEBLEND(type, components, tmp_type) { \
565         float scale = feather ? 1/feather : 0xff; \
566         type  **in_rows = (type**)input->get_rows(); \
567         type **out_rows = (type**)output->get_rows(); \
568         for( int y=y1; y<y2; ++y ) { \
569                 type *in_row = (type*) in_rows[y]; \
570                 type *out_row = (type*)out_rows[y]; \
571                 unsigned char *pattern_row = pattern_image[y]; \
572                 for( int x=0; x<w; ++x ) { \
573                         tmp_type d = (pattern_row[x] - threshold) * scale; \
574                         if( d > 0xff ) d = 0xff; \
575                         else if( d < -0xff ) d = -0xff; \
576                         tmp_type a = (d + 0xff) / 2, b = 0xff - a; \
577                         for( int i=0; i<components; ++i ) { \
578                                 type ic = in_row[i], oc = out_row[i]; \
579                                 out_row[i] = (ic * a + oc * b) / 0xff; \
580                         } \
581                         in_row += components; out_row += components; \
582                 } \
583         } \
584 }
585
586 int ShapeWipeMain::process_realtime(VFrame *input, VFrame *output)
587 {
588         this->input = input;
589         this->output = output;
590         int w = input->get_w();
591         int h = input->get_h();
592         init_shapes();
593         load_configuration();
594
595         if( strncmp(config.shape_name, current_name, BCTEXTLEN) ||
596             config.preserve_aspect != last_preserve_aspect ) {
597                 reset_pattern_image();
598         }
599         if ( !pattern_image ) {
600                 if( read_pattern_image(config.shape_name, w, h) ) {
601                         fprintf(stderr, _("Shape Wipe: cannot load shape %s\n"),
602                                 current_filename);
603                         current_filename[0] = 0;
604                         return 0;
605                 }
606                 strncpy(current_name, config.shape_name, BCTEXTLEN);
607                 last_preserve_aspect = config.preserve_aspect;
608         }
609
610         float fade = (float)PluginClient::get_source_position() /
611                 (float)PluginClient::get_total_len();
612         if( !config.direction ) fade = 1 - fade;
613         threshold = fade * 0xff;
614
615         int slices = w*h/0x40000+1;
616         int max_slices = BC_Resources::machine_cpus/2;
617         if( slices > max_slices ) slices = max_slices;
618         if( slices < 1 ) slices = 1;
619         if( engine && engine->get_total_clients() != slices ) {
620                 delete engine;  engine = 0;
621         }
622         if( !engine )
623                 engine = new ShapeEngine(this, slices, slices);
624
625         engine->process_packages();
626         return 0;
627 }
628
629
630 ShapePackage::ShapePackage()
631  : LoadPackage()
632 {
633 }
634
635 ShapeUnit::ShapeUnit(ShapeEngine *server) : LoadClient(server)
636 {
637         this->server = server;
638 }
639
640 ShapeUnit::~ShapeUnit()
641 {
642 }
643
644 void ShapeUnit::process_package(LoadPackage *package)
645 {
646         VFrame *input = server->plugin->input;
647         VFrame *output = server->plugin->output;
648         int w = input->get_w();
649
650         unsigned char **pattern_image = server->plugin->pattern_image;
651         unsigned char threshold = server->plugin->threshold;
652         float feather = server->plugin->config.feather;
653         ShapePackage *pkg = (ShapePackage*)package;
654         int y1 = pkg->y1, y2 = pkg->y2;
655
656         switch(input->get_color_model()) {
657         case BC_RGB_FLOAT:
658                 SHAPEBLEND(float, 3, float)
659                 break;
660         case BC_RGB888:
661         case BC_YUV888:
662                 SHAPEBLEND(unsigned char, 3, int)
663                 break;
664         case BC_RGBA_FLOAT:
665                 SHAPEBLEND(float, 4, float)
666                 break;
667         case BC_RGBA8888:
668         case BC_YUVA8888:
669                 SHAPEBLEND(unsigned char, 4, int)
670                 break;
671         case BC_RGB161616:
672         case BC_YUV161616:
673                 SHAPEBLEND(uint16_t, 3, int64_t)
674                 break;
675         case BC_RGBA16161616:
676         case BC_YUVA16161616:
677                 SHAPEBLEND(uint16_t, 4, int64_t)
678                 break;
679         }
680 }
681
682
683 ShapeEngine::ShapeEngine(ShapeWipeMain *plugin,
684         int total_clients, int total_packages)
685  : LoadServer(total_clients, total_packages)
686 {
687         this->plugin = plugin;
688 }
689
690 ShapeEngine::~ShapeEngine()
691 {
692 }
693
694
695 void ShapeEngine::init_packages()
696 {
697         int y = 0, h1 = plugin->input->get_h()-1;
698         int total_packages = get_total_packages();
699         for(int i = 0; i<total_packages; ) {
700                 ShapePackage *pkg = (ShapePackage*)get_package(i++);
701                 pkg->y1 = y;
702                 y = h1 * i / total_packages;
703                 pkg->y2 = y;
704         }
705 }
706
707 LoadClient* ShapeEngine::new_client()
708 {
709         return new ShapeUnit(this);
710 }
711
712 LoadPackage* ShapeEngine::new_package()
713 {
714         return new ShapePackage;
715 }
716