00001 #include "clip.h"
00002 #include "filexml.h"
00003 #include "picon_png.h"
00004 #include "translate.h"
00005 #include "translatewin.h"
00006
00007 #include <string.h>
00008
00009 #include <libintl.h>
00010 #define _(String) gettext(String)
00011 #define gettext_noop(String) String
00012 #define N_(String) gettext_noop (String)
00013
00014
00015 REGISTER_PLUGIN(TranslateMain)
00016
00017 TranslateConfig::TranslateConfig()
00018 {
00019 in_x = 0;
00020 in_y = 0;
00021 in_w = 720;
00022 in_h = 480;
00023 out_x = 0;
00024 out_y = 0;
00025 out_w = 720;
00026 out_h = 480;
00027 }
00028
00029 int TranslateConfig::equivalent(TranslateConfig &that)
00030 {
00031 return EQUIV(in_x, that.in_x) &&
00032 EQUIV(in_y, that.in_y) &&
00033 EQUIV(in_w, that.in_w) &&
00034 EQUIV(in_h, that.in_h) &&
00035 EQUIV(out_x, that.out_x) &&
00036 EQUIV(out_y, that.out_y) &&
00037 EQUIV(out_w, that.out_w) &&
00038 EQUIV(out_h, that.out_h);
00039 }
00040
00041 void TranslateConfig::copy_from(TranslateConfig &that)
00042 {
00043 in_x = that.in_x;
00044 in_y = that.in_y;
00045 in_w = that.in_w;
00046 in_h = that.in_h;
00047 out_x = that.out_x;
00048 out_y = that.out_y;
00049 out_w = that.out_w;
00050 out_h = that.out_h;
00051 }
00052
00053 void TranslateConfig::interpolate(TranslateConfig &prev,
00054 TranslateConfig &next,
00055 int64_t prev_frame,
00056 int64_t next_frame,
00057 int64_t current_frame)
00058 {
00059 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
00060 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
00061
00062 this->in_x = prev.in_x * prev_scale + next.in_x * next_scale;
00063 this->in_y = prev.in_y * prev_scale + next.in_y * next_scale;
00064 this->in_w = prev.in_w * prev_scale + next.in_w * next_scale;
00065 this->in_h = prev.in_h * prev_scale + next.in_h * next_scale;
00066 this->out_x = prev.out_x * prev_scale + next.out_x * next_scale;
00067 this->out_y = prev.out_y * prev_scale + next.out_y * next_scale;
00068 this->out_w = prev.out_w * prev_scale + next.out_w * next_scale;
00069 this->out_h = prev.out_h * prev_scale + next.out_h * next_scale;
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079 TranslateMain::TranslateMain(PluginServer *server)
00080 : PluginVClient(server)
00081 {
00082 temp_frame = 0;
00083 overlayer = 0;
00084 PLUGIN_CONSTRUCTOR_MACRO
00085 }
00086
00087 TranslateMain::~TranslateMain()
00088 {
00089 PLUGIN_DESTRUCTOR_MACRO
00090
00091 if(temp_frame) delete temp_frame;
00092 temp_frame = 0;
00093 if(overlayer) delete overlayer;
00094 overlayer = 0;
00095 }
00096
00097 char* TranslateMain::plugin_title() { return N_("Translate"); }
00098 int TranslateMain::is_realtime() { return 1; }
00099
00100 NEW_PICON_MACRO(TranslateMain)
00101
00102 int TranslateMain::load_defaults()
00103 {
00104 char directory[1024], string[1024];
00105
00106 sprintf(directory, "%stranslate.rc", BCASTDIR);
00107
00108
00109 defaults = new BC_Hash(directory);
00110 defaults->load();
00111
00112
00113 config.in_x = defaults->get("IN_X", config.in_x);
00114 config.in_y = defaults->get("IN_Y", config.in_y);
00115 config.in_w = defaults->get("IN_W", config.in_w);
00116 config.in_h = defaults->get("IN_H", config.in_h);
00117 config.out_x = defaults->get("OUT_X", config.out_x);
00118 config.out_y = defaults->get("OUT_Y", config.out_y);
00119 config.out_w = defaults->get("OUT_W", config.out_w);
00120 config.out_h = defaults->get("OUT_H", config.out_h);
00121 }
00122
00123 int TranslateMain::save_defaults()
00124 {
00125 defaults->update("IN_X", config.in_x);
00126 defaults->update("IN_Y", config.in_y);
00127 defaults->update("IN_W", config.in_w);
00128 defaults->update("IN_H", config.in_h);
00129 defaults->update("OUT_X", config.out_x);
00130 defaults->update("OUT_Y", config.out_y);
00131 defaults->update("OUT_W", config.out_w);
00132 defaults->update("OUT_H", config.out_h);
00133 defaults->save();
00134 }
00135
00136 LOAD_CONFIGURATION_MACRO(TranslateMain, TranslateConfig)
00137
00138 void TranslateMain::save_data(KeyFrame *keyframe)
00139 {
00140 FileXML output;
00141
00142
00143 output.set_shared_string(keyframe->data, MESSAGESIZE);
00144
00145
00146 output.tag.set_title("TRANSLATE");
00147 output.tag.set_property("IN_X", config.in_x);
00148 output.tag.set_property("IN_Y", config.in_y);
00149 output.tag.set_property("IN_W", config.in_w);
00150 output.tag.set_property("IN_H", config.in_h);
00151 output.tag.set_property("OUT_X", config.out_x);
00152 output.tag.set_property("OUT_Y", config.out_y);
00153 output.tag.set_property("OUT_W", config.out_w);
00154 output.tag.set_property("OUT_H", config.out_h);
00155 output.append_tag();
00156 output.tag.set_title("/TRANSLATE");
00157 output.append_tag();
00158
00159 output.terminate_string();
00160
00161 }
00162
00163 void TranslateMain::read_data(KeyFrame *keyframe)
00164 {
00165 FileXML input;
00166
00167 input.set_shared_string(keyframe->data, strlen(keyframe->data));
00168
00169 int result = 0;
00170
00171 while(!result)
00172 {
00173 result = input.read_tag();
00174
00175 if(!result)
00176 {
00177 if(input.tag.title_is("TRANSLATE"))
00178 {
00179 config.in_x = input.tag.get_property("IN_X", config.in_x);
00180 config.in_y = input.tag.get_property("IN_Y", config.in_y);
00181 config.in_w = input.tag.get_property("IN_W", config.in_w);
00182 config.in_h = input.tag.get_property("IN_H", config.in_h);
00183 config.out_x = input.tag.get_property("OUT_X", config.out_x);
00184 config.out_y = input.tag.get_property("OUT_Y", config.out_y);
00185 config.out_w = input.tag.get_property("OUT_W", config.out_w);
00186 config.out_h = input.tag.get_property("OUT_H", config.out_h);
00187 }
00188 }
00189 }
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199 int TranslateMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
00200 {
00201 VFrame *input, *output;
00202
00203
00204 input = input_ptr;
00205 output = output_ptr;
00206
00207 load_configuration();
00208
00209
00210 if(input->get_rows()[0] == output->get_rows()[0])
00211 {
00212 if(!temp_frame)
00213 temp_frame = new VFrame(0,
00214 input_ptr->get_w(),
00215 input_ptr->get_h(),
00216 input->get_color_model());
00217 temp_frame->copy_from(input);
00218 input = temp_frame;
00219 }
00220
00221
00222
00223 if(!overlayer)
00224 {
00225 overlayer = new OverlayFrame(smp + 1);
00226 }
00227
00228 output->clear_frame();
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 overlayer->overlay(output,
00246 input,
00247 config.in_x,
00248 config.in_y,
00249 config.in_x + config.in_w,
00250 config.in_y + config.in_h,
00251 config.out_x,
00252 config.out_y,
00253 config.out_x + config.out_w,
00254 config.out_y + config.out_h,
00255 1,
00256 TRANSFER_REPLACE,
00257 get_interpolation_type());
00258
00259 }
00260
00261
00262
00263
00264 SHOW_GUI_MACRO(TranslateMain, TranslateThread)
00265
00266 RAISE_WINDOW_MACRO(TranslateMain)
00267
00268 SET_STRING_MACRO(TranslateMain)
00269
00270 void TranslateMain::update_gui()
00271 {
00272 if(thread)
00273 {
00274 if(load_configuration())
00275 {
00276 thread->window->lock_window();
00277 thread->window->in_x->update(config.in_x);
00278 thread->window->in_y->update(config.in_y);
00279 thread->window->in_w->update(config.in_w);
00280 thread->window->in_h->update(config.in_h);
00281 thread->window->out_x->update(config.out_x);
00282 thread->window->out_y->update(config.out_y);
00283 thread->window->out_w->update(config.out_w);
00284 thread->window->out_h->update(config.out_h);
00285 thread->window->unlock_window();
00286 }
00287 }
00288 }