r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / plugins / flash / flash.C
blob20d7df7502fb6be31cee84fe2758ec43b9a6a088
1 #include "flash.h"
2 #include "edl.inc"
3 #include "overlayframe.h"
4 #include "picon_png.h"
5 #include "vframe.h"
6 #include <stdint.h>
8 #include <libintl.h>
9 #define _(String) gettext(String)
10 #define gettext_noop(String) String
11 #define N_(String) gettext_noop (String)
13 PluginClient* new_plugin(PluginServer *server)
15         return new FlashMain(server);
22 FlashMain::FlashMain(PluginServer *server)
23  : PluginVClient(server)
27 FlashMain::~FlashMain()
31 char* FlashMain::plugin_title() { return _("Flash"); }
32 int FlashMain::is_video() { return 1; }
33 int FlashMain::is_transition() { return 1; }
34 int FlashMain::uses_gui() { return 0; }
36 NEW_PICON_MACRO(FlashMain)
39 #define FLASH(type, components, max, chroma_offset) \
40 { \
41         int foreground = (int)(fraction * max + 0.5); \
42         int chroma_foreground = foreground; \
43         if(chroma_offset) chroma_foreground = foreground * chroma_offset / max; \
44         int transparency = max - foreground; \
45 /* printf("FLASH %d %d %d\n", foreground, transparency, is_before); */\
46         for(int i = 0; i < h; i++) \
47         { \
48                 type *in_row = (type*)incoming->get_rows()[i]; \
49                 type *out_row = (type*)outgoing->get_rows()[i]; \
50                 if(is_before) \
51                 { \
52                         for(int j = 0; j < w; j++) \
53                         { \
54                                 *out_row = foreground + transparency * *out_row / max; \
55                                 out_row++; \
56                                 *out_row = chroma_foreground + transparency * *out_row / max; \
57                                 out_row++; \
58                                 *out_row = chroma_foreground + transparency * *out_row / max; \
59                                 out_row++; \
60                                 if(components == 4) \
61                                 { \
62                                         *out_row = foreground + transparency * *out_row / max; \
63                                         out_row++; \
64                                 } \
65                         } \
66                 } \
67                 else \
68                 { \
69                         for(int j = 0; j < w; j++) \
70                         { \
71                                 *out_row = foreground + transparency * *in_row / max; \
72                                 out_row++; \
73                                 in_row++; \
74                                 *out_row = chroma_foreground + transparency * *in_row / max; \
75                                 out_row++; \
76                                 in_row++; \
77                                 *out_row = chroma_foreground + transparency * *in_row / max; \
78                                 out_row++; \
79                                 in_row++; \
80                                 if(components == 4) \
81                                 { \
82                                         *out_row = foreground + transparency * *in_row / max; \
83                                         out_row++; \
84                                         in_row++; \
85                                 } \
86                         } \
87                 } \
88         } \
91 int FlashMain::process_realtime(VFrame *incoming, VFrame *outgoing)
93         int half = PluginClient::get_total_len() / 2;
94         int position = half - labs(PluginClient::get_source_position() - half);
95         float fraction = (float)position / half;
96         int is_before = PluginClient::get_source_position() < half;
97         int w = incoming->get_w();
98         int h = incoming->get_h();
100         switch(incoming->get_color_model())
101         {
102                 case BC_RGB888:
103                         FLASH(unsigned char, 3, 0xff, 0x0);
104                         break;
105                 case BC_RGBA8888:
106                         FLASH(unsigned char, 4, 0xff, 0x0);
107                         break;
108                 case BC_YUV888:
109                         FLASH(unsigned char, 3, 0xff, 0x80);
110                         break;
111                 case BC_YUVA8888:
112                         FLASH(unsigned char, 4, 0xff, 0x80);
113                         break;
114                 case BC_RGB161616:
115                         FLASH(uint16_t, 3, 0xffff, 0x0);
116                         break;
117                 case BC_RGBA16161616:
118                         FLASH(uint16_t, 4, 0xffff, 0x0);
119                         break;
120                 case BC_YUV161616:
121                         FLASH(uint16_t, 3, 0xffff, 0x8000);
122                         break;
123                 case BC_YUVA16161616:
124                         FLASH(uint16_t, 4, 0xffff, 0x8000);
125                         break;
126         }
128         return 0;