4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "bccmodels.h"
27 #include "flipwindow.h"
33 REGISTER_PLUGIN(FlipMain)
40 FlipConfig::FlipConfig()
46 void FlipConfig::copy_from(FlipConfig &that)
48 flip_horizontal = that.flip_horizontal;
49 flip_vertical = that.flip_vertical;
52 int FlipConfig::equivalent(FlipConfig &that)
54 return flip_horizontal == that.flip_horizontal &&
55 flip_vertical == that.flip_vertical;
58 void FlipConfig::interpolate(FlipConfig &prev,
64 this->flip_horizontal = prev.flip_horizontal;
65 this->flip_vertical = prev.flip_vertical;
77 FlipMain::FlipMain(PluginServer *server)
78 : PluginVClient(server)
88 const char* FlipMain::plugin_title() { return _("Flip"); }
89 int FlipMain::is_realtime() { return 1; }
92 #define SWAP_PIXELS(type, components, in, out) \
106 if(components == 4) \
114 #define FLIP_MACRO(type, components) \
116 type **input_rows, **output_rows; \
117 type *input_row, *output_row; \
118 input_rows = ((type**)frame->get_rows()); \
119 output_rows = ((type**)frame->get_rows()); \
121 if(config.flip_vertical) \
123 for(i = 0, j = h - 1; i < h / 2; i++, j--) \
125 input_row = input_rows[i]; \
126 output_row = output_rows[j]; \
127 for(k = 0; k < w; k++) \
129 SWAP_PIXELS(type, components, output_row, input_row); \
130 output_row += components; \
131 input_row += components; \
136 if(config.flip_horizontal) \
138 for(i = 0; i < h; i++) \
140 input_row = input_rows[i]; \
141 output_row = output_rows[i] + (w - 1) * components; \
142 for(k = 0; k < w / 2; k++) \
144 SWAP_PIXELS(type, components, output_row, input_row); \
145 input_row += components; \
146 output_row -= components; \
152 int FlipMain::process_buffer(VFrame *frame,
153 int64_t start_position,
157 int w = frame->get_w();
158 int h = frame->get_h();
159 int colormodel = frame->get_color_model();
161 load_configuration();
165 get_source_position(),
173 if(config.flip_vertical || config.flip_horizontal)
183 FLIP_MACRO(unsigned char, 3);
186 FLIP_MACRO(float, 3);
190 FLIP_MACRO(uint16_t, 3);
194 FLIP_MACRO(unsigned char, 4);
197 FLIP_MACRO(float, 4);
199 case BC_RGBA16161616:
200 case BC_YUVA16161616:
201 FLIP_MACRO(uint16_t, 4);
208 NEW_WINDOW_MACRO(FlipMain, FlipWindow)
209 LOAD_CONFIGURATION_MACRO(FlipMain, FlipConfig)
211 void FlipMain::update_gui()
215 load_configuration();
216 thread->window->lock_window();
217 ((FlipWindow*)thread->window)->flip_vertical->update((int)config.flip_vertical);
218 ((FlipWindow*)thread->window)->flip_horizontal->update((int)config.flip_horizontal);
219 thread->window->unlock_window();
223 void FlipMain::save_data(KeyFrame *keyframe)
227 // cause data to be stored directly in text
228 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
229 output.tag.set_title("FLIP");
231 if(config.flip_vertical)
233 output.tag.set_title("VERTICAL");
237 if(config.flip_horizontal)
239 output.tag.set_title("HORIZONTAL");
242 output.terminate_string();
243 // data is now in *text
246 void FlipMain::read_data(KeyFrame *keyframe)
250 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
253 config.flip_vertical = config.flip_horizontal = 0;
257 result = input.read_tag();
261 if(input.tag.title_is("VERTICAL"))
263 config.flip_vertical = 1;
266 if(input.tag.title_is("HORIZONTAL"))
268 config.flip_horizontal = 1;
275 int FlipMain::handle_opengl()
278 get_output()->to_texture();
279 get_output()->enable_opengl();
280 get_output()->init_screen();
281 get_output()->bind_texture(0);
283 if(config.flip_vertical && !config.flip_horizontal)
285 get_output()->draw_texture(0,
287 get_output()->get_w(),
288 get_output()->get_h(),
290 get_output()->get_h(),
291 get_output()->get_w(),
295 if(config.flip_horizontal && !config.flip_vertical)
297 get_output()->draw_texture(0,
299 get_output()->get_w(),
300 get_output()->get_h(),
301 get_output()->get_w(),
304 get_output()->get_h());
307 if(config.flip_vertical && config.flip_horizontal)
309 get_output()->draw_texture(0,
311 get_output()->get_w(),
312 get_output()->get_h(),
313 get_output()->get_w(),
314 get_output()->get_h(),
319 get_output()->set_opengl_state(VFrame::SCREEN);