00001 #include "clip.h"
00002 #include "colormodels.h"
00003 #include "bchash.h"
00004 #include "filexml.h"
00005 #include "flip.h"
00006 #include "flipwindow.h"
00007 #include "language.h"
00008 #include "picon_png.h"
00009
00010 #include <stdint.h>
00011 #include <string.h>
00012
00013 REGISTER_PLUGIN(FlipMain)
00014
00015
00016
00017
00018
00019
00020 FlipConfig::FlipConfig()
00021 {
00022 flip_horizontal = 0;
00023 flip_vertical = 0;
00024 }
00025
00026 void FlipConfig::copy_from(FlipConfig &that)
00027 {
00028 flip_horizontal = that.flip_horizontal;
00029 flip_vertical = that.flip_vertical;
00030 }
00031
00032 int FlipConfig::equivalent(FlipConfig &that)
00033 {
00034 return flip_horizontal == that.flip_horizontal &&
00035 flip_vertical == that.flip_vertical;
00036 }
00037
00038 void FlipConfig::interpolate(FlipConfig &prev,
00039 FlipConfig &next,
00040 long prev_frame,
00041 long next_frame,
00042 long current_frame)
00043 {
00044 this->flip_horizontal = prev.flip_horizontal;
00045 this->flip_vertical = prev.flip_vertical;
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 FlipMain::FlipMain(PluginServer *server)
00058 : PluginVClient(server)
00059 {
00060 PLUGIN_CONSTRUCTOR_MACRO
00061 }
00062
00063 FlipMain::~FlipMain()
00064 {
00065 PLUGIN_DESTRUCTOR_MACRO
00066 }
00067
00068 char* FlipMain::plugin_title() { return N_("Flip"); }
00069 int FlipMain::is_realtime() { return 1; }
00070
00071
00072 #define SWAP_PIXELS(type, components, in, out) \
00073 { \
00074 type temp = in[0]; \
00075 in[0] = out[0]; \
00076 out[0] = temp; \
00077 \
00078 temp = in[1]; \
00079 in[1] = out[1]; \
00080 out[1] = temp; \
00081 \
00082 temp = in[2]; \
00083 in[2] = out[2]; \
00084 out[2] = temp; \
00085 \
00086 if(components == 4) \
00087 { \
00088 temp = in[3]; \
00089 in[3] = out[3]; \
00090 out[3] = temp; \
00091 } \
00092 }
00093
00094 #define FLIP_MACRO(type, components) \
00095 { \
00096 type **input_rows, **output_rows; \
00097 type *input_row, *output_row; \
00098 input_rows = ((type**)frame->get_rows()); \
00099 output_rows = ((type**)frame->get_rows()); \
00100 \
00101 if(config.flip_vertical) \
00102 { \
00103 for(i = 0, j = h - 1; i < h / 2; i++, j--) \
00104 { \
00105 input_row = input_rows[i]; \
00106 output_row = output_rows[j]; \
00107 for(k = 0; k < w; k++) \
00108 { \
00109 SWAP_PIXELS(type, components, output_row, input_row); \
00110 output_row += components; \
00111 input_row += components; \
00112 } \
00113 } \
00114 } \
00115 \
00116 if(config.flip_horizontal) \
00117 { \
00118 for(i = 0; i < h; i++) \
00119 { \
00120 input_row = input_rows[i]; \
00121 output_row = output_rows[i] + (w - 1) * components; \
00122 for(k = 0; k < w / 2; k++) \
00123 { \
00124 SWAP_PIXELS(type, components, output_row, input_row); \
00125 input_row += components; \
00126 output_row -= components; \
00127 } \
00128 } \
00129 } \
00130 }
00131
00132 int FlipMain::process_buffer(VFrame *frame,
00133 int64_t start_position,
00134 double frame_rate)
00135 {
00136 int i, j, k, l;
00137 int w = frame->get_w();
00138 int h = frame->get_h();
00139 int colormodel = frame->get_color_model();
00140
00141 load_configuration();
00142
00143 read_frame(frame,
00144 0,
00145 get_source_position(),
00146 get_framerate(),
00147 get_use_opengl());
00148
00149
00150
00151 if(get_use_opengl())
00152 {
00153 if(config.flip_vertical || config.flip_horizontal)
00154 return run_opengl();
00155 else
00156 return 0;
00157 }
00158
00159 switch(colormodel)
00160 {
00161 case BC_RGB888:
00162 case BC_YUV888:
00163 FLIP_MACRO(unsigned char, 3);
00164 break;
00165 case BC_RGB_FLOAT:
00166 FLIP_MACRO(float, 3);
00167 break;
00168 case BC_RGB161616:
00169 case BC_YUV161616:
00170 FLIP_MACRO(uint16_t, 3);
00171 break;
00172 case BC_RGBA8888:
00173 case BC_YUVA8888:
00174 FLIP_MACRO(unsigned char, 4);
00175 break;
00176 case BC_RGBA_FLOAT:
00177 FLIP_MACRO(float, 4);
00178 break;
00179 case BC_RGBA16161616:
00180 case BC_YUVA16161616:
00181 FLIP_MACRO(uint16_t, 4);
00182 break;
00183 }
00184 return 0;
00185 }
00186
00187
00188 SHOW_GUI_MACRO(FlipMain, FlipThread)
00189
00190 RAISE_WINDOW_MACRO(FlipMain)
00191
00192 SET_STRING_MACRO(FlipMain)
00193
00194 NEW_PICON_MACRO(FlipMain)
00195
00196 LOAD_CONFIGURATION_MACRO(FlipMain, FlipConfig)
00197
00198 void FlipMain::update_gui()
00199 {
00200 if(thread)
00201 {
00202 load_configuration();
00203 thread->window->lock_window();
00204 thread->window->flip_vertical->update((int)config.flip_vertical);
00205 thread->window->flip_horizontal->update((int)config.flip_horizontal);
00206 thread->window->unlock_window();
00207 }
00208 }
00209
00210 void FlipMain::save_data(KeyFrame *keyframe)
00211 {
00212 FileXML output;
00213
00214
00215 output.set_shared_string(keyframe->data, MESSAGESIZE);
00216 output.tag.set_title("FLIP");
00217 output.append_tag();
00218 if(config.flip_vertical)
00219 {
00220 output.tag.set_title("VERTICAL");
00221 output.append_tag();
00222 output.tag.set_title("/VERTICAL");
00223 output.append_tag();
00224 }
00225
00226 if(config.flip_horizontal)
00227 {
00228 output.tag.set_title("HORIZONTAL");
00229 output.append_tag();
00230 output.tag.set_title("/HORIZONTAL");
00231 output.append_tag();
00232 }
00233 output.tag.set_title("/FLIP");
00234 output.append_tag();
00235 output.terminate_string();
00236
00237 }
00238
00239 void FlipMain::read_data(KeyFrame *keyframe)
00240 {
00241 FileXML input;
00242
00243 input.set_shared_string(keyframe->data, strlen(keyframe->data));
00244
00245 int result = 0;
00246 config.flip_vertical = config.flip_horizontal = 0;
00247
00248 while(!result)
00249 {
00250 result = input.read_tag();
00251
00252 if(!result)
00253 {
00254 if(input.tag.title_is("VERTICAL"))
00255 {
00256 config.flip_vertical = 1;
00257 }
00258 else
00259 if(input.tag.title_is("HORIZONTAL"))
00260 {
00261 config.flip_horizontal = 1;
00262 }
00263 }
00264 }
00265 }
00266
00267 int FlipMain::load_defaults()
00268 {
00269 char directory[BCTEXTLEN], string[BCTEXTLEN];
00270
00271 sprintf(directory, "%sflip.rc", BCASTDIR);
00272
00273
00274 defaults = new BC_Hash(directory);
00275 defaults->load();
00276
00277 config.flip_horizontal = defaults->get("FLIP_HORIZONTAL", config.flip_horizontal);
00278 config.flip_vertical = defaults->get("FLIP_VERTICAL", config.flip_vertical);
00279 return 0;
00280 }
00281
00282 int FlipMain::save_defaults()
00283 {
00284 defaults->update("FLIP_HORIZONTAL", config.flip_horizontal);
00285 defaults->update("FLIP_VERTICAL", config.flip_vertical);
00286 defaults->save();
00287 return 0;
00288 }
00289
00290 int FlipMain::handle_opengl()
00291 {
00292 #ifdef HAVE_GL
00293 get_output()->to_texture();
00294 get_output()->enable_opengl();
00295 get_output()->init_screen();
00296 get_output()->bind_texture(0);
00297
00298 if(config.flip_vertical && !config.flip_horizontal)
00299 {
00300 get_output()->draw_texture(0,
00301 0,
00302 get_output()->get_w(),
00303 get_output()->get_h(),
00304 0,
00305 get_output()->get_h(),
00306 get_output()->get_w(),
00307 0);
00308 }
00309
00310 if(config.flip_horizontal && !config.flip_vertical)
00311 {
00312 get_output()->draw_texture(0,
00313 0,
00314 get_output()->get_w(),
00315 get_output()->get_h(),
00316 get_output()->get_w(),
00317 0,
00318 0,
00319 get_output()->get_h());
00320 }
00321
00322 if(config.flip_vertical && config.flip_horizontal)
00323 {
00324 get_output()->draw_texture(0,
00325 0,
00326 get_output()->get_w(),
00327 get_output()->get_h(),
00328 get_output()->get_w(),
00329 get_output()->get_h(),
00330 0,
00331 0);
00332 }
00333
00334 get_output()->set_opengl_state(VFrame::SCREEN);
00335 #endif
00336 }
00337
00338
00339