r373: Merged the official release 1.2.1.
[cinelerra_cv.git] / plugins / flash / flash.C
blob64b5aa78a8d85bbff1280ad3ed846353e8e26521
1 #include "flash.h"
2 #include "edl.inc"
3 #include "overlayframe.h"
4 #include "language.h"
5 #include "picon_png.h"
6 #include "vframe.h"
7 #include <stdint.h>
10 PluginClient* new_plugin(PluginServer *server)
12         return new FlashMain(server);
19 FlashMain::FlashMain(PluginServer *server)
20  : PluginVClient(server)
24 FlashMain::~FlashMain()
28 char* FlashMain::plugin_title() { return N_("Flash"); }
29 int FlashMain::is_video() { return 1; }
30 int FlashMain::is_transition() { return 1; }
31 int FlashMain::uses_gui() { return 0; }
33 NEW_PICON_MACRO(FlashMain)
36 #define FLASH(type, temp_type, components, max, chroma_offset) \
37 { \
38         float round_factor = (sizeof(type) < 4) ? 0.5 : 0; \
39         temp_type foreground = (temp_type)(fraction * max + round_factor); \
40         temp_type chroma_foreground = foreground; \
41         if(chroma_offset) chroma_foreground = foreground * chroma_offset / max; \
42         temp_type transparency = max - foreground; \
43  \
44         for(int i = 0; i < h; i++) \
45         { \
46                 type *in_row = (type*)incoming->get_rows()[i]; \
47                 type *out_row = (type*)outgoing->get_rows()[i]; \
48                 if(is_before) \
49                 { \
50                         for(int j = 0; j < w; j++) \
51                         { \
52                                 *out_row = foreground + transparency * *out_row / max; \
53                                 out_row++; \
54                                 *out_row = chroma_foreground + transparency * *out_row / max; \
55                                 out_row++; \
56                                 *out_row = chroma_foreground + transparency * *out_row / max; \
57                                 out_row++; \
58                                 if(components == 4) \
59                                 { \
60                                         *out_row = foreground + transparency * *out_row / max; \
61                                         out_row++; \
62                                 } \
63                         } \
64                 } \
65                 else \
66                 { \
67                         for(int j = 0; j < w; j++) \
68                         { \
69                                 *out_row = foreground + transparency * *in_row / max; \
70                                 out_row++; \
71                                 in_row++; \
72                                 *out_row = chroma_foreground + transparency * *in_row / max; \
73                                 out_row++; \
74                                 in_row++; \
75                                 *out_row = chroma_foreground + transparency * *in_row / max; \
76                                 out_row++; \
77                                 in_row++; \
78                                 if(components == 4) \
79                                 { \
80                                         *out_row = foreground + transparency * *in_row / max; \
81                                         out_row++; \
82                                         in_row++; \
83                                 } \
84                         } \
85                 } \
86         } \
89 int FlashMain::process_realtime(VFrame *incoming, VFrame *outgoing)
91         int half = PluginClient::get_total_len() / 2;
92         int position = half - labs(PluginClient::get_source_position() - half);
93         float fraction = (float)position / half;
94         int is_before = PluginClient::get_source_position() < half;
95         int w = incoming->get_w();
96         int h = incoming->get_h();
98         switch(incoming->get_color_model())
99         {
100                 case BC_RGB888:
101                         FLASH(unsigned char, int, 3, 0xff, 0x0);
102                         break;
103                 case BC_RGB_FLOAT:
104                         FLASH(float, float, 3, 1.0, 0x0);
105                         break;
106                 case BC_RGBA8888:
107                         FLASH(unsigned char, int, 4, 0xff, 0x0);
108                         break;
109                 case BC_RGBA_FLOAT:
110                         FLASH(float, float, 4, 1.0, 0x0);
111                         break;
112                 case BC_YUV888:
113                         FLASH(unsigned char, int, 3, 0xff, 0x80);
114                         break;
115                 case BC_YUVA8888:
116                         FLASH(unsigned char, int, 4, 0xff, 0x80);
117                         break;
118                 case BC_RGB161616:
119                         FLASH(uint16_t, int, 3, 0xffff, 0x0);
120                         break;
121                 case BC_RGBA16161616:
122                         FLASH(uint16_t, int, 4, 0xffff, 0x0);
123                         break;
124                 case BC_YUV161616:
125                         FLASH(uint16_t, int, 3, 0xffff, 0x8000);
126                         break;
127                 case BC_YUVA16161616:
128                         FLASH(uint16_t, int, 4, 0xffff, 0x8000);
129                         break;
130         }
132         return 0;