10 #define _(String) gettext(String)
11 #define gettext_noop(String) String
12 #define N_(String) gettext_noop (String)
14 REGISTER_PLUGIN(ScaleMain)
18 ScaleConfig::ScaleConfig()
25 void ScaleConfig::copy_from(ScaleConfig &src)
29 constrain = src.constrain;
31 int ScaleConfig::equivalent(ScaleConfig &src)
33 return EQUIV(w, src.w) &&
35 constrain == src.constrain;
38 void ScaleConfig::interpolate(ScaleConfig &prev,
42 int64_t current_frame)
44 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
45 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
47 this->w = prev.w * prev_scale + next.w * next_scale;
48 this->h = prev.h * prev_scale + next.h * next_scale;
49 this->constrain = prev.constrain;
59 ScaleMain::ScaleMain(PluginServer *server)
60 : PluginVClient(server)
64 PLUGIN_CONSTRUCTOR_MACRO
67 ScaleMain::~ScaleMain()
69 PLUGIN_DESTRUCTOR_MACRO
71 if(temp_frame) delete temp_frame;
73 if(overlayer) delete overlayer;
77 char* ScaleMain::plugin_title() { return _("Scale"); }
78 int ScaleMain::is_realtime() { return 1; }
80 NEW_PICON_MACRO(ScaleMain)
82 int ScaleMain::load_defaults()
84 char directory[1024], string[1024];
85 // set the default directory
86 sprintf(directory, "%sscale.rc", BCASTDIR);
89 defaults = new Defaults(directory);
92 config.w = defaults->get("WIDTH", config.w);
93 config.h = defaults->get("HEIGHT", config.h);
94 config.constrain = defaults->get("CONSTRAIN", config.constrain);
95 //printf("ScaleMain::load_defaults %f %f\n",config.w , config.h);
98 int ScaleMain::save_defaults()
100 defaults->update("WIDTH", config.w);
101 defaults->update("HEIGHT", config.h);
102 defaults->update("CONSTRAIN", config.constrain);
106 LOAD_CONFIGURATION_MACRO(ScaleMain, ScaleConfig)
109 void ScaleMain::save_data(KeyFrame *keyframe)
113 // cause data to be stored directly in text
114 output.set_shared_string(keyframe->data, MESSAGESIZE);
117 output.tag.set_title("SCALE");
118 output.tag.set_property("WIDTH", config.w);
119 output.tag.set_property("HEIGHT", config.h);
124 output.tag.set_title("CONSTRAIN");
127 output.terminate_string();
128 // data is now in *text
131 void ScaleMain::read_data(KeyFrame *keyframe)
135 input.set_shared_string(keyframe->data, strlen(keyframe->data));
138 config.constrain = 0;
142 result = input.read_tag();
146 if(input.tag.title_is("SCALE"))
148 config.w = input.tag.get_property("WIDTH", config.w);
149 config.h = input.tag.get_property("HEIGHT", config.h);
152 if(input.tag.title_is("CONSTRAIN"))
154 config.constrain = 1;
167 int ScaleMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
169 VFrame *input, *output;
174 load_configuration();
176 //printf("ScaleMain::process_realtime 1 %p\n", input);
177 if(input->get_rows()[0] == output->get_rows()[0])
180 temp_frame = new VFrame(0,
183 input->get_color_model());
184 temp_frame->copy_from(input);
187 //printf("ScaleMain::process_realtime 2 %p\n", input);
191 overlayer = new OverlayFrame(smp + 1);
195 if(config.w == 1 && config.h == 1)
198 if(input->get_rows()[0] != output->get_rows()[0])
200 output->copy_from(input);
206 float center_x, center_y;
207 float in_x1, in_x2, in_y1, in_y2, out_x1, out_x2, out_y1, out_y2;
209 center_x = (float)input_ptr->get_w() / 2;
210 center_y = (float)input_ptr->get_h() / 2;
212 in_x2 = input_ptr->get_w();
214 in_y2 = input_ptr->get_h();
215 out_x1 = (float)center_x - (float)input_ptr->get_w() * config.w / 2;
216 out_x2 = (float)center_x + (float)input_ptr->get_w() * config.w / 2;
217 out_y1 = (float)center_y - (float)input_ptr->get_h() * config.h / 2;
218 out_y2 = (float)center_y + (float)input_ptr->get_h() * config.h / 2;
221 //printf("ScaleMain::process_realtime %f = %d / 2\n", center_x, input_ptr->get_w());
222 //printf("ScaleMain::process_realtime %f = %f + %d * %f / 2\n",
223 // out_x1, center_x, input_ptr->get_w(), config.w);
227 in_x1 += -out_x1 / config.w;
231 if(out_x2 > input_ptr->get_w())
233 in_x2 -= (out_x2 - input_ptr->get_w()) / config.w;
234 out_x2 = input_ptr->get_w();
239 in_y1 += -out_y1 / config.h;
243 if(out_y2 > input_ptr->get_h())
245 in_y2 -= (out_y2 - input_ptr->get_h()) / config.h;
246 out_y2 = input_ptr->get_h();
249 output->clear_frame();
251 // printf("ScaleMain::process_realtime 3 output=%p input=%p config.w=%f config.h=%f"
252 // "%f %f %f %f -> %f %f %f %f\n",
265 overlayer->overlay(output,
277 get_interpolation_type());
284 SHOW_GUI_MACRO(ScaleMain, ScaleThread)
285 RAISE_WINDOW_MACRO(ScaleMain)
286 SET_STRING_MACRO(ScaleMain)
288 void ScaleMain::update_gui()
292 load_configuration();
293 thread->window->lock_window();
294 thread->window->width->update(config.w);
295 thread->window->height->update(config.h);
296 thread->window->constrain->update(config.constrain);
297 thread->window->unlock_window();