4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "bccmodels.h"
27 #include "blurzoomwindow.h"
34 PluginClient* new_plugin(PluginServer *server)
36 return new BlurZoomMain(server);
50 BlurZoomConfig::BlurZoomConfig()
54 BlurZoomMain::BlurZoomMain(PluginServer *server)
55 : PluginVClient(server)
59 BlurZoomMain::~BlurZoomMain()
63 char* BlurZoomMain::plugin_title() { return _("RadioacTV"); }
64 int BlurZoomMain::is_realtime() { return 1; }
66 NEW_WINDOW_MACRO(BlurZoomMain, BlurZoomWindow)
69 int BlurZoomMain::load_configuration()
75 void BlurZoomMain::save_data(KeyFrame *keyframe)
79 void BlurZoomMain::read_data(KeyFrame *keyframe)
84 #define VIDEO_HWIDTH (buf_width/2)
85 #define VIDEO_HHEIGHT (buf_height/2)
88 #define MAGIC_THRESHOLD 40
91 void BlurZoomMain::image_set_threshold_y(int threshold)
93 y_threshold = threshold * 7; /* fake-Y value is timed by 7 */
97 void BlurZoomMain::set_table()
99 int bits, x, y, tx, ty, xx;
102 prevptr = (int)(0.5 + RATIO * (-VIDEO_HWIDTH) + VIDEO_HWIDTH);
104 for(xx = 0; xx < (buf_width_blocks); xx++)
107 for(x = 0; x < 32; x++)
109 ptr = (int)(0.5 + RATIO * (xx * 32 + x - VIDEO_HWIDTH) + VIDEO_HWIDTH);
115 blurzoomx[xx] = bits;
118 ty = (int)(0.5 + RATIO * (-VIDEO_HHEIGHT) + VIDEO_HHEIGHT);
119 tx = (int)(0.5 + RATIO* (-VIDEO_HWIDTH) + VIDEO_HWIDTH);
120 xx = (int)(0.5 + RATIO *( buf_width - 1 - VIDEO_HWIDTH) + VIDEO_HWIDTH);
121 blurzoomy[0] = ty * buf_width + tx;
122 prevptr = ty * buf_width + xx;
124 for(y = 1; y < buf_height; y++)
126 ty = (int)(0.5 + RATIO * (y - VIDEO_HHEIGHT) + VIDEO_HHEIGHT);
127 blurzoomy[y] = ty * buf_width + tx - prevptr;
128 prevptr = ty * buf_width + xx;
132 void BlurZoomMain::make_palette()
136 #define DELTA (255 / (COLORS / 2 - 1))
138 for(i = 0; i < COLORS / 2; i++)
140 palette_r[i] = i * DELTA;
141 palette_g[i] = i * DELTA;
142 palette_b[i] = i * DELTA;
145 for(i = 0; i < COLORS / 2; i++)
147 palette_r[i + COLORS / 2] = (i * DELTA);
148 palette_g[i + COLORS / 2] = (i * DELTA);
149 palette_b[i + COLORS / 2] = 255;
171 int BlurZoomMain::start_realtime()
173 buf_width_blocks = project_frame_w / 32;
174 buf_width = buf_width_blocks * 32;
175 buf_height = project_frame_h;
176 buf_area = buf_width * buf_height;
177 buf_margin_left = (project_frame_w - buf_width) / 2;
178 buf_margin_right = project_frame_w - buf_width - buf_margin_left;
179 blurzoombuf = new unsigned char[buf_area * 2];
180 blurzoomx = new int[buf_width];
181 blurzoomy = new int[buf_height];
186 bzero(blurzoombuf, buf_area * 2);
189 background = new uint16_t[project_frame_w * project_frame_h];
190 diff = new unsigned char[project_frame_w * project_frame_h];
191 image_set_threshold_y(MAGIC_THRESHOLD);
193 blurzoom_server = new BlurZoomServer(this, 1, 1);
197 int BlurZoomMain::stop_realtime()
199 delete blurzoom_server;
205 delete [] blurzoombuf;
213 delete [] background;
222 int BlurZoomMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
224 load_configuration();
225 this->input_ptr = input_ptr;
226 this->output_ptr = output_ptr;
229 blurzoom_server->process_packages();
238 BlurZoomServer::BlurZoomServer(BlurZoomMain *plugin, int total_clients, total_packages)
239 : LoadServer(total_clients, get_total_packages())
241 this->plugin = plugin;
245 LoadClient* BlurZoomServer::new_client()
247 return new BlurZoomClient(this);
253 LoadPackage* BlurZoomServer::new_package()
255 return new BlurZoomPackage;
260 void BlurZoomServer::init_packages()
262 for(int i = 0; i < get_total_packages(); i++)
264 BlurZoomPackage *package = (BlurZoomPackage*)get_package(i);
265 package->row1 = plugin->input_ptr->get_h() / get_total_packages() * i;
266 package->row2 = package->row1 + plugin->input_ptr->get_h() / get_total_packages();
267 if(i >= get_total_packages() - 1)
268 package->row2 = plugin->input_ptr->get_h();
279 BlurZoomClient::BlurZoomClient(BlurZoomServer *server)
282 this->plugin = server->plugin;
293 /* Background image is refreshed every frame */
294 #define IMAGE_BGSUBTRACT_UPDATE_Y(result, \
306 q = (int16_t *)background; \
309 for(i = 0; i < project_frame_h; i++) \
313 for(j = 0; j < project_frame_w; j++) \
315 if(sizeof(type) == 2) \
317 R = p[0] >> (8 - 1); \
318 G = p[1] >> (8 - 2); \
328 v = (R + G + B) - (int)(*q); \
329 *q = (int16_t)(R + G + B); \
330 *r = ((v + y_threshold) >> 24) | ((y_threshold - v) >> 24); \
344 #define BLURZOOM_FINAL(type, components)
346 for(y = 0; y < h; y++)
348 memcpy(output_rows[y],
350 buf_margin_left * plugin->input_ptr->get_bytes_per_pixel());
353 for(x = 0; x < buf_width; x++)
355 for(c = 0; c < components; c++)
357 a = *src++ & 0xfefeff;
361 *dest++ = a | (b - (b >> 8));
365 memcpy(output_rows[y] + project_frame_w - buf_margin_right,
366 input_rows[y] + project_frame_w - buf_margin_right,
367 buf_margin_right * plugin->input_ptr->get_bytes_per_pixel());
373 void BlurZoomClient::process_package(LoadPackage *package)
375 BlurZoomPackage *local_package = (BlurZoomPackage*)package;
376 unsigned char **input_rows = plugin->input_ptr->get_rows() + local_package->row1;
377 unsigned char **output_rows = plugin->output_ptr->get_rows() + local_package->row1;
378 int w = plugin->input_ptr->get_w();
379 int h = local_package->row2 - local_package->row1;
382 unsigned char *diff, *p;
384 switch(plugin->input_ptr->get_color_model())
388 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
395 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
402 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
407 case BC_RGBA16161616:
408 case BC_YUVA16161616:
409 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
417 diff += buf_margin_left;
422 for(y = 0; y < buf_height; y++)
424 for(x = 0; x < buf_width; x++)
426 p[x] |= diff[x] >> 3;
434 // Assembly language only
442 switch(plugin->input_ptr->get_color_model())
446 BLURZOOM_FINAL(uint8_t, 3);
450 BLURZOOM_FINAL(uint8_t, 4);
454 BLURZOOM_FINAL(uint16_t, 3);
456 case BC_RGBA16161616:
457 case BC_YUVA16161616:
458 BLURZOOM_FINAL(uint16_t, 4);
469 BlurZoomPackage::BlurZoomPackage()