2 #include "colormodels.h"
6 #include "blurzoomwindow.h"
13 #define _(String) gettext(String)
14 #define gettext_noop(String) String
15 #define N_(String) gettext_noop (String)
17 PluginClient* new_plugin(PluginServer *server)
19 return new BlurZoomMain(server);
33 BlurZoomConfig::BlurZoomConfig()
37 BlurZoomMain::BlurZoomMain(PluginServer *server)
38 : PluginVClient(server)
45 BlurZoomMain::~BlurZoomMain()
49 // Set result to 0 to indicate a server side close
50 thread->window->set_done(0);
51 thread->completion.lock();
56 if(defaults) delete defaults;
59 char* BlurZoomMain::plugin_title() { return _("RadioacTV"); }
60 int BlurZoomMain::is_realtime() { return 1; }
62 VFrame* BlurZoomMain::new_picon()
64 return new VFrame(picon_png);
67 int BlurZoomMain::load_defaults()
72 int BlurZoomMain::save_defaults()
77 void BlurZoomMain::load_configuration()
82 void BlurZoomMain::save_data(KeyFrame *keyframe)
86 void BlurZoomMain::read_data(KeyFrame *keyframe)
91 #define VIDEO_HWIDTH (buf_width/2)
92 #define VIDEO_HHEIGHT (buf_height/2)
95 #define MAGIC_THRESHOLD 40
98 void BlurZoomMain::image_set_threshold_y(int threshold)
100 y_threshold = threshold * 7; /* fake-Y value is timed by 7 */
104 void BlurZoomMain::set_table()
106 int bits, x, y, tx, ty, xx;
109 prevptr = (int)(0.5 + RATIO * (-VIDEO_HWIDTH) + VIDEO_HWIDTH);
111 for(xx = 0; xx < (buf_width_blocks); xx++)
114 for(x = 0; x < 32; x++)
116 ptr = (int)(0.5 + RATIO * (xx * 32 + x - VIDEO_HWIDTH) + VIDEO_HWIDTH);
122 blurzoomx[xx] = bits;
125 ty = (int)(0.5 + RATIO * (-VIDEO_HHEIGHT) + VIDEO_HHEIGHT);
126 tx = (int)(0.5 + RATIO* (-VIDEO_HWIDTH) + VIDEO_HWIDTH);
127 xx = (int)(0.5 + RATIO *( buf_width - 1 - VIDEO_HWIDTH) + VIDEO_HWIDTH);
128 blurzoomy[0] = ty * buf_width + tx;
129 prevptr = ty * buf_width + xx;
131 for(y = 1; y < buf_height; y++)
133 ty = (int)(0.5 + RATIO * (y - VIDEO_HHEIGHT) + VIDEO_HHEIGHT);
134 blurzoomy[y] = ty * buf_width + tx - prevptr;
135 prevptr = ty * buf_width + xx;
139 void BlurZoomMain::make_palette()
143 #define DELTA (255 / (COLORS / 2 - 1))
145 for(i = 0; i < COLORS / 2; i++)
147 palette_r[i] = i * DELTA;
148 palette_g[i] = i * DELTA;
149 palette_b[i] = i * DELTA;
152 for(i = 0; i < COLORS / 2; i++)
154 palette_r[i + COLORS / 2] = (i * DELTA);
155 palette_g[i + COLORS / 2] = (i * DELTA);
156 palette_b[i + COLORS / 2] = 255;
178 int BlurZoomMain::start_realtime()
180 buf_width_blocks = project_frame_w / 32;
181 buf_width = buf_width_blocks * 32;
182 buf_height = project_frame_h;
183 buf_area = buf_width * buf_height;
184 buf_margin_left = (project_frame_w - buf_width) / 2;
185 buf_margin_right = project_frame_w - buf_width - buf_margin_left;
186 blurzoombuf = new unsigned char[buf_area * 2];
187 blurzoomx = new int[buf_width];
188 blurzoomy = new int[buf_height];
193 bzero(blurzoombuf, buf_area * 2);
196 background = new uint16_t[project_frame_w * project_frame_h];
197 diff = new unsigned char[project_frame_w * project_frame_h];
198 image_set_threshold_y(MAGIC_THRESHOLD);
200 blurzoom_server = new BlurZoomServer(this, 1, 1);
204 int BlurZoomMain::stop_realtime()
206 delete blurzoom_server;
212 delete [] blurzoombuf;
220 delete [] background;
229 int BlurZoomMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
231 load_configuration();
232 this->input_ptr = input_ptr;
233 this->output_ptr = output_ptr;
236 blurzoom_server->process_packages();
241 int BlurZoomMain::show_gui()
243 load_configuration();
244 thread = new BlurZoomThread(this);
249 int BlurZoomMain::set_string()
251 if(thread) thread->window->set_title(gui_string);
255 void BlurZoomMain::raise_window()
259 thread->window->raise_window();
260 thread->window->flush();
267 BlurZoomServer::BlurZoomServer(BlurZoomMain *plugin, int total_clients, int total_packages)
268 : LoadServer(total_clients, total_packages)
270 this->plugin = plugin;
274 LoadClient* BlurZoomServer::new_client()
276 return new BlurZoomClient(this);
282 LoadPackage* BlurZoomServer::new_package()
284 return new BlurZoomPackage;
289 void BlurZoomServer::init_packages()
291 for(int i = 0; i < total_packages; i++)
293 BlurZoomPackage *package = (BlurZoomPackage*)packages[i];
294 package->row1 = plugin->input_ptr->get_h() / total_packages * i;
295 package->row2 = package->row1 + plugin->input_ptr->get_h() / total_packages;
296 if(i >= total_packages - 1)
297 package->row2 = plugin->input_ptr->get_h();
308 BlurZoomClient::BlurZoomClient(BlurZoomServer *server)
311 this->plugin = server->plugin;
322 /* Background image is refreshed every frame */
323 #define IMAGE_BGSUBTRACT_UPDATE_Y(result, \
335 q = (int16_t *)background; \
338 for(i = 0; i < project_frame_h; i++) \
342 for(j = 0; j < project_frame_w; j++) \
344 if(sizeof(type) == 2) \
346 R = p[0] >> (8 - 1); \
347 G = p[1] >> (8 - 2); \
357 v = (R + G + B) - (int)(*q); \
358 *q = (int16_t)(R + G + B); \
359 *r = ((v + y_threshold) >> 24) | ((y_threshold - v) >> 24); \
373 #define BLURZOOM_FINAL(type, components)
375 for(y = 0; y < h; y++)
377 memcpy(output_rows[y],
379 buf_margin_left * plugin->input_ptr->get_bytes_per_pixel());
382 for(x = 0; x < buf_width; x++)
384 for(c = 0; c < components; c++)
386 a = *src++ & 0xfefeff;
390 *dest++ = a | (b - (b >> 8));
394 memcpy(output_rows[y] + project_frame_w - buf_margin_right,
395 input_rows[y] + project_frame_w - buf_margin_right,
396 buf_margin_right * plugin->input_ptr->get_bytes_per_pixel());
402 void BlurZoomClient::process_package(LoadPackage *package)
404 BlurZoomPackage *local_package = (BlurZoomPackage*)package;
405 unsigned char **input_rows = plugin->input_ptr->get_rows() + local_package->row1;
406 unsigned char **output_rows = plugin->output_ptr->get_rows() + local_package->row1;
407 int w = plugin->input_ptr->get_w();
408 int h = local_package->row2 - local_package->row1;
411 unsigned char *diff, *p;
413 switch(plugin->input_ptr->get_color_model())
417 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
424 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
431 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
436 case BC_RGBA16161616:
437 case BC_YUVA16161616:
438 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
446 diff += buf_margin_left;
451 for(y = 0; y < buf_height; y++)
453 for(x = 0; x < buf_width; x++)
455 p[x] |= diff[x] >> 3;
463 // Assembly language only
471 switch(plugin->input_ptr->get_color_model())
475 BLURZOOM_FINAL(uint8_t, 3);
479 BLURZOOM_FINAL(uint8_t, 4);
483 BLURZOOM_FINAL(uint16_t, 3);
485 case BC_RGBA16161616:
486 case BC_YUVA16161616:
487 BLURZOOM_FINAL(uint16_t, 4);
498 BlurZoomPackage::BlurZoomPackage()