r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / plugins / flip / flip.C
blob6d86ce3074215111c3f74e8f93c8801b49d1e8ca
1 #include "clip.h"
2 #include "colormodels.h"
3 #include "defaults.h"
4 #include "filexml.h"
5 #include "flip.h"
6 #include "flipwindow.h"
7 #include "picon_png.h"
9 #include <stdint.h>
10 #include <string.h>
12 #include <libintl.h>
13 #define _(String) gettext(String)
14 #define gettext_noop(String) String
15 #define N_(String) gettext_noop (String)
17 REGISTER_PLUGIN(FlipMain)
24 FlipConfig::FlipConfig()
26         flip_horizontal = 0;
27         flip_vertical = 0;
30 void FlipConfig::copy_from(FlipConfig &that)
32         flip_horizontal = that.flip_horizontal;
33         flip_vertical = that.flip_vertical;
36 int FlipConfig::equivalent(FlipConfig &that)
38         return flip_horizontal == that.flip_horizontal &&
39                 flip_vertical == that.flip_vertical;
42 void FlipConfig::interpolate(FlipConfig &prev, 
43         FlipConfig &next, 
44         long prev_frame, 
45         long next_frame, 
46         long current_frame)
48         this->flip_horizontal = prev.flip_horizontal;
49         this->flip_vertical = prev.flip_vertical;
61 FlipMain::FlipMain(PluginServer *server)
62  : PluginVClient(server)
64         PLUGIN_CONSTRUCTOR_MACRO
67 FlipMain::~FlipMain()
69         PLUGIN_DESTRUCTOR_MACRO
72 char* FlipMain::plugin_title() { return _("Flip"); }
73 int FlipMain::is_realtime() { return 1; }
74         
76 #define SWAP_PIXELS(components, in, out) \
77 { \
78         in[0] ^= out[0]; \
79         out[0] ^= in[0]; \
80         in[0] ^= out[0]; \
81  \
82         in[1] ^= out[1]; \
83         out[1] ^= in[1]; \
84         in[1] ^= out[1]; \
85  \
86         in[2] ^= out[2]; \
87         out[2] ^= in[2]; \
88         in[2] ^= out[2]; \
89  \
90         if(components == 4) \
91         { \
92                 in[3] ^= out[3]; \
93                 out[3] ^= in[3]; \
94                 in[3] ^= out[3]; \
95         } \
98 #define FLIP_MACRO(type, components) \
99 { \
100         type **input_rows, **output_rows; \
101         type *input_row, *output_row; \
102         input_rows = ((type**)input_ptr->get_rows()); \
103         output_rows = ((type**)output_ptr->get_rows()); \
105         if(config.flip_vertical) \
106         { \
107                 for(i = 0, j = h - 1; i < h / 2; i++, j--) \
108                 { \
109                         input_row = input_rows[i]; \
110                         output_row = output_rows[j]; \
111                         for(k = 0; k < w; k++) \
112                         { \
113                                 SWAP_PIXELS(components, output_row, input_row); \
114                                 output_row += components; \
115                                 input_row += components; \
116                         } \
117                 } \
118         } \
120         if(config.flip_horizontal) \
121         { \
122                 for(i = 0; i < h; i++) \
123                 { \
124                         input_row = input_rows[i]; \
125                         output_row = output_rows[i] + (w - 1) * components; \
126                         for(k = 0; k < w / 2; k++) \
127                         { \
128                                 SWAP_PIXELS(components, output_row, input_row); \
129                                 input_row += components; \
130                                 output_row -= components; \
131                         } \
132                 } \
133         } \
136 int FlipMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
138         int i, j, k, l;
139         int w = input_ptr->get_w();
140         int h = input_ptr->get_h();
141         int colormodel = input_ptr->get_color_model();
143         load_configuration();
144         switch(colormodel)
145         {
146                 case BC_RGB888:
147                 case BC_YUV888:
148                         FLIP_MACRO(unsigned char, 3);
149                         break;
150                 case BC_RGB161616:
151                 case BC_YUV161616:
152                         FLIP_MACRO(uint16_t, 3);
153                         break;
154                 case BC_RGBA8888:
155                 case BC_YUVA8888:
156                         FLIP_MACRO(unsigned char, 4);
157                         break;
158                 case BC_RGBA16161616:
159                 case BC_YUVA16161616:
160                         FLIP_MACRO(uint16_t, 4);
161                         break;
162         }
163         return 0;
167 SHOW_GUI_MACRO(FlipMain, FlipThread)
169 RAISE_WINDOW_MACRO(FlipMain)
171 SET_STRING_MACRO(FlipMain)
173 NEW_PICON_MACRO(FlipMain)
175 LOAD_CONFIGURATION_MACRO(FlipMain, FlipConfig)
177 void FlipMain::update_gui()
179         if(thread)
180         {
181                 load_configuration();
182                 thread->window->lock_window();
183                 thread->window->flip_vertical->update((int)config.flip_vertical);
184                 thread->window->flip_horizontal->update((int)config.flip_horizontal);
185                 thread->window->unlock_window();
186         }
189 void FlipMain::save_data(KeyFrame *keyframe)
191         FileXML output;
193 // cause data to be stored directly in text
194         output.set_shared_string(keyframe->data, MESSAGESIZE);
195         output.tag.set_title("FLIP");
196         output.append_tag();
197         if(config.flip_vertical)
198         {
199                 output.tag.set_title("VERTICAL");
200                 output.append_tag();
201         }
203         if(config.flip_horizontal)
204         {       
205                 output.tag.set_title("HORIZONTAL");
206                 output.append_tag();
207         }
208         output.terminate_string();
209 // data is now in *text
212 void FlipMain::read_data(KeyFrame *keyframe)
214         FileXML input;
216         input.set_shared_string(keyframe->data, strlen(keyframe->data));
218         int result = 0;
219         config.flip_vertical = config.flip_horizontal = 0;
221         while(!result)
222         {
223                 result = input.read_tag();
225                 if(!result)
226                 {
227                         if(input.tag.title_is("VERTICAL"))
228                         {
229                                 config.flip_vertical = 1;
230                         }
231                         else
232                         if(input.tag.title_is("HORIZONTAL"))
233                         {
234                                 config.flip_horizontal = 1;
235                         }
236                 }
237         }
240 int FlipMain::load_defaults()
242         char directory[BCTEXTLEN], string[BCTEXTLEN];
243 // set the default directory
244         sprintf(directory, "%sflip.rc", BCASTDIR);
246 // load the defaults
247         defaults = new Defaults(directory);
248         defaults->load();
250         config.flip_horizontal = defaults->get("FLIP_HORIZONTAL", config.flip_horizontal);
251         config.flip_vertical = defaults->get("FLIP_VERTICAL", config.flip_vertical);
252         return 0;
255 int FlipMain::save_defaults()
257         defaults->update("FLIP_HORIZONTAL", config.flip_horizontal);
258         defaults->update("FLIP_VERTICAL", config.flip_vertical);
259         defaults->save();
260         return 0;