4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "bccmodels.h"
28 #include "flipwindow.h"
34 REGISTER_PLUGIN(FlipMain)
41 FlipConfig::FlipConfig()
47 void FlipConfig::copy_from(FlipConfig &that)
49 flip_horizontal = that.flip_horizontal;
50 flip_vertical = that.flip_vertical;
53 int FlipConfig::equivalent(FlipConfig &that)
55 return flip_horizontal == that.flip_horizontal &&
56 flip_vertical == that.flip_vertical;
59 void FlipConfig::interpolate(FlipConfig &prev,
65 this->flip_horizontal = prev.flip_horizontal;
66 this->flip_vertical = prev.flip_vertical;
78 FlipMain::FlipMain(PluginServer *server)
79 : PluginVClient(server)
89 const char* FlipMain::plugin_title() { return N_("Flip"); }
90 int FlipMain::is_realtime() { return 1; }
93 #define SWAP_PIXELS(type, components, in, out) \
107 if(components == 4) \
115 #define FLIP_MACRO(type, components) \
117 type **input_rows, **output_rows; \
118 type *input_row, *output_row; \
119 input_rows = ((type**)frame->get_rows()); \
120 output_rows = ((type**)frame->get_rows()); \
122 if(config.flip_vertical) \
124 for(i = 0, j = h - 1; i < h / 2; i++, j--) \
126 input_row = input_rows[i]; \
127 output_row = output_rows[j]; \
128 for(k = 0; k < w; k++) \
130 SWAP_PIXELS(type, components, output_row, input_row); \
131 output_row += components; \
132 input_row += components; \
137 if(config.flip_horizontal) \
139 for(i = 0; i < h; i++) \
141 input_row = input_rows[i]; \
142 output_row = output_rows[i] + (w - 1) * components; \
143 for(k = 0; k < w / 2; k++) \
145 SWAP_PIXELS(type, components, output_row, input_row); \
146 input_row += components; \
147 output_row -= components; \
153 int FlipMain::process_buffer(VFrame *frame,
154 int64_t start_position,
158 int w = frame->get_w();
159 int h = frame->get_h();
160 int colormodel = frame->get_color_model();
162 load_configuration();
166 get_source_position(),
174 if(config.flip_vertical || config.flip_horizontal)
184 FLIP_MACRO(unsigned char, 3);
187 FLIP_MACRO(float, 3);
191 FLIP_MACRO(uint16_t, 3);
195 FLIP_MACRO(unsigned char, 4);
198 FLIP_MACRO(float, 4);
200 case BC_RGBA16161616:
201 case BC_YUVA16161616:
202 FLIP_MACRO(uint16_t, 4);
209 NEW_WINDOW_MACRO(FlipMain, FlipWindow)
210 LOAD_CONFIGURATION_MACRO(FlipMain, FlipConfig)
212 void FlipMain::update_gui()
216 load_configuration();
217 thread->window->lock_window();
218 ((FlipWindow*)thread->window)->flip_vertical->update((int)config.flip_vertical);
219 ((FlipWindow*)thread->window)->flip_horizontal->update((int)config.flip_horizontal);
220 thread->window->unlock_window();
224 void FlipMain::save_data(KeyFrame *keyframe)
228 // cause data to be stored directly in text
229 output.set_shared_output(keyframe->xbuf);
230 output.tag.set_title("FLIP");
232 if(config.flip_vertical)
234 output.tag.set_title("VERTICAL");
236 output.tag.set_title("/VERTICAL");
240 if(config.flip_horizontal)
242 output.tag.set_title("HORIZONTAL");
244 output.tag.set_title("/HORIZONTAL");
247 output.tag.set_title("/FLIP");
249 output.append_newline();
250 output.terminate_string();
251 // data is now in *text
254 void FlipMain::read_data(KeyFrame *keyframe)
258 input.set_shared_input(keyframe->xbuf);
261 config.flip_vertical = config.flip_horizontal = 0;
265 result = input.read_tag();
269 if(input.tag.title_is("VERTICAL"))
271 config.flip_vertical = 1;
274 if(input.tag.title_is("HORIZONTAL"))
276 config.flip_horizontal = 1;
283 int FlipMain::handle_opengl()
286 get_output()->to_texture();
287 get_output()->enable_opengl();
288 get_output()->init_screen();
289 get_output()->bind_texture(0);
291 if(config.flip_vertical && !config.flip_horizontal)
293 get_output()->draw_texture(0,
295 get_output()->get_w(),
296 get_output()->get_h(),
298 get_output()->get_h(),
299 get_output()->get_w(),
303 if(config.flip_horizontal && !config.flip_vertical)
305 get_output()->draw_texture(0,
307 get_output()->get_w(),
308 get_output()->get_h(),
309 get_output()->get_w(),
312 get_output()->get_h());
315 if(config.flip_vertical && config.flip_horizontal)
317 get_output()->draw_texture(0,
319 get_output()->get_w(),
320 get_output()->get_h(),
321 get_output()->get_w(),
322 get_output()->get_h(),
327 get_output()->set_opengl_state(VFrame::SCREEN);