00001 #include "clip.h"
00002 #include "colormodels.h"
00003 #include "filexml.h"
00004 #include "picon_png.h"
00005 #include "blurzoom.h"
00006 #include "blurzoomwindow.h"
00007
00008 #include <stdint.h>
00009 #include <stdio.h>
00010 #include <string.h>
00011
00012 #include <libintl.h>
00013 #define _(String) gettext(String)
00014 #define gettext_noop(String) String
00015 #define N_(String) gettext_noop (String)
00016
00017 PluginClient* new_plugin(PluginServer *server)
00018 {
00019 return new BlurZoomMain(server);
00020 }
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 BlurZoomConfig::BlurZoomConfig()
00034 {
00035 }
00036
00037 BlurZoomMain::BlurZoomMain(PluginServer *server)
00038 : PluginVClient(server)
00039 {
00040 thread = 0;
00041 defaults = 0;
00042 load_defaults();
00043 }
00044
00045 BlurZoomMain::~BlurZoomMain()
00046 {
00047 if(thread)
00048 {
00049
00050 thread->window->set_done(0);
00051 thread->completion.lock();
00052 delete thread;
00053 }
00054
00055 save_defaults();
00056 if(defaults) delete defaults;
00057 }
00058
00059 char* BlurZoomMain::plugin_title() { return N_("RadioacTV"); }
00060 int BlurZoomMain::is_realtime() { return 1; }
00061
00062 VFrame* BlurZoomMain::new_picon()
00063 {
00064 return new VFrame(picon_png);
00065 }
00066
00067 int BlurZoomMain::load_defaults()
00068 {
00069 return 0;
00070 }
00071
00072 int BlurZoomMain::save_defaults()
00073 {
00074 return 0;
00075 }
00076
00077 void BlurZoomMain::load_configuration()
00078 {
00079 }
00080
00081
00082 void BlurZoomMain::save_data(KeyFrame *keyframe)
00083 {
00084 }
00085
00086 void BlurZoomMain::read_data(KeyFrame *keyframe)
00087 {
00088 }
00089
00090
00091 #define VIDEO_HWIDTH (buf_width/2)
00092 #define VIDEO_HHEIGHT (buf_height/2)
00093
00094
00095 #define MAGIC_THRESHOLD 40
00096 #define RATIO 0.95
00097
00098 void BlurZoomMain::image_set_threshold_y(int threshold)
00099 {
00100 y_threshold = threshold * 7;
00101 }
00102
00103
00104 void BlurZoomMain::set_table()
00105 {
00106 int bits, x, y, tx, ty, xx;
00107 int ptr, prevptr;
00108
00109 prevptr = (int)(0.5 + RATIO * (-VIDEO_HWIDTH) + VIDEO_HWIDTH);
00110
00111 for(xx = 0; xx < (buf_width_blocks); xx++)
00112 {
00113 bits = 0;
00114 for(x = 0; x < 32; x++)
00115 {
00116 ptr = (int)(0.5 + RATIO * (xx * 32 + x - VIDEO_HWIDTH) + VIDEO_HWIDTH);
00117 bits = bits << 1;
00118 if(ptr != prevptr)
00119 bits |= 1;
00120 prevptr = ptr;
00121 }
00122 blurzoomx[xx] = bits;
00123 }
00124
00125 ty = (int)(0.5 + RATIO * (-VIDEO_HHEIGHT) + VIDEO_HHEIGHT);
00126 tx = (int)(0.5 + RATIO* (-VIDEO_HWIDTH) + VIDEO_HWIDTH);
00127 xx = (int)(0.5 + RATIO *( buf_width - 1 - VIDEO_HWIDTH) + VIDEO_HWIDTH);
00128 blurzoomy[0] = ty * buf_width + tx;
00129 prevptr = ty * buf_width + xx;
00130
00131 for(y = 1; y < buf_height; y++)
00132 {
00133 ty = (int)(0.5 + RATIO * (y - VIDEO_HHEIGHT) + VIDEO_HHEIGHT);
00134 blurzoomy[y] = ty * buf_width + tx - prevptr;
00135 prevptr = ty * buf_width + xx;
00136 }
00137 }
00138
00139 void BlurZoomMain::make_palette()
00140 {
00141 int i;
00142
00143 #define DELTA (255 / (COLORS / 2 - 1))
00144
00145 for(i = 0; i < COLORS / 2; i++)
00146 {
00147 palette_r[i] = i * DELTA;
00148 palette_g[i] = i * DELTA;
00149 palette_b[i] = i * DELTA;
00150 }
00151
00152 for(i = 0; i < COLORS / 2; i++)
00153 {
00154 palette_r[i + COLORS / 2] = (i * DELTA);
00155 palette_g[i + COLORS / 2] = (i * DELTA);
00156 palette_b[i + COLORS / 2] = 255;
00157 }
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 int BlurZoomMain::start_realtime()
00179 {
00180 buf_width_blocks = project_frame_w / 32;
00181 buf_width = buf_width_blocks * 32;
00182 buf_height = project_frame_h;
00183 buf_area = buf_width * buf_height;
00184 buf_margin_left = (project_frame_w - buf_width) / 2;
00185 buf_margin_right = project_frame_w - buf_width - buf_margin_left;
00186 blurzoombuf = new unsigned char[buf_area * 2];
00187 blurzoomx = new int[buf_width];
00188 blurzoomy = new int[buf_height];
00189
00190 set_table();
00191 make_palette();
00192
00193 bzero(blurzoombuf, buf_area * 2);
00194
00195
00196 background = new uint16_t[project_frame_w * project_frame_h];
00197 diff = new unsigned char[project_frame_w * project_frame_h];
00198 image_set_threshold_y(MAGIC_THRESHOLD);
00199
00200 blurzoom_server = new BlurZoomServer(this, 1, 1);
00201 return 0;
00202 }
00203
00204 int BlurZoomMain::stop_realtime()
00205 {
00206 delete blurzoom_server;
00207
00208
00209
00210
00211
00212 delete [] blurzoombuf;
00213 delete [] blurzoomx;
00214 delete [] blurzoomy;
00215
00216
00217
00218
00219
00220 delete [] background;
00221 delete [] diff;
00222
00223
00224
00225
00226 return 0;
00227 }
00228
00229 int BlurZoomMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
00230 {
00231 load_configuration();
00232 this->input_ptr = input_ptr;
00233 this->output_ptr = output_ptr;
00234
00235
00236 blurzoom_server->process_packages();
00237
00238 return 0;
00239 }
00240
00241 int BlurZoomMain::show_gui()
00242 {
00243 load_configuration();
00244 thread = new BlurZoomThread(this);
00245 thread->start();
00246 return 0;
00247 }
00248
00249 int BlurZoomMain::set_string()
00250 {
00251 if(thread) thread->window->set_title(gui_string);
00252 return 0;
00253 }
00254
00255 void BlurZoomMain::raise_window()
00256 {
00257 if(thread)
00258 {
00259 thread->window->raise_window();
00260 thread->window->flush();
00261 }
00262 }
00263
00264
00265
00266
00267 BlurZoomServer::BlurZoomServer(BlurZoomMain *plugin, int total_clients, total_packages)
00268 : LoadServer(total_clients, get_total_packages())
00269 {
00270 this->plugin = plugin;
00271 }
00272
00273
00274 LoadClient* BlurZoomServer::new_client()
00275 {
00276 return new BlurZoomClient(this);
00277 }
00278
00279
00280
00281
00282 LoadPackage* BlurZoomServer::new_package()
00283 {
00284 return new BlurZoomPackage;
00285 }
00286
00287
00288
00289 void BlurZoomServer::init_packages()
00290 {
00291 for(int i = 0; i < get_total_packages(); i++)
00292 {
00293 BlurZoomPackage *package = (BlurZoomPackage*)get_package(i);
00294 package->row1 = plugin->input_ptr->get_h() / get_total_packages() * i;
00295 package->row2 = package->row1 + plugin->input_ptr->get_h() / get_total_packages();
00296 if(i >= get_total_packages() - 1)
00297 package->row2 = plugin->input_ptr->get_h();
00298 }
00299 }
00300
00301
00302
00303
00304
00305
00306
00307
00308 BlurZoomClient::BlurZoomClient(BlurZoomServer *server)
00309 : LoadClient(server)
00310 {
00311 this->plugin = server->plugin;
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323 #define IMAGE_BGSUBTRACT_UPDATE_Y(result, \
00324 input_rows, \
00325 type, \
00326 components) \
00327 { \
00328 int i; \
00329 int R, G, B; \
00330 type *p; \
00331 int16_t *q; \
00332 unsigned char *r; \
00333 int v; \
00334 \
00335 q = (int16_t *)background; \
00336 r = diff; \
00337 \
00338 for(i = 0; i < project_frame_h; i++) \
00339 { \
00340 p = input_rows[j]; \
00341 \
00342 for(j = 0; j < project_frame_w; j++) \
00343 { \
00344 if(sizeof(type) == 2) \
00345 { \
00346 R = p[0] >> (8 - 1); \
00347 G = p[1] >> (8 - 2); \
00348 B = p[2] >> 8; \
00349 } \
00350 else \
00351 { \
00352 R = p[0] << 1; \
00353 G = p[1] << 2; \
00354 B = p[2]; \
00355 } \
00356 \
00357 v = (R + G + B) - (int)(*q); \
00358 *q = (int16_t)(R + G + B); \
00359 *r = ((v + y_threshold) >> 24) | ((y_threshold - v) >> 24); \
00360 \
00361 p += components; \
00362 q++; \
00363 r++; \
00364 } \
00365 } \
00366 \
00367 result = diff; \
00368 }
00369
00370
00371
00372
00373 #define BLURZOOM_FINAL(type, components)
00374 {
00375 for(y = 0; y < h; y++)
00376 {
00377 memcpy(output_rows[y],
00378 input_rows[y],
00379 buf_margin_left * plugin->input_ptr->get_bytes_per_pixel());
00380
00381
00382 for(x = 0; x < buf_width; x++)
00383 {
00384 for(c = 0; c < components; c++)
00385 {
00386 a = *src++ & 0xfefeff;
00387 b = palette[*p++];
00388 a += b;
00389 b = a & 0x1010100;
00390 *dest++ = a | (b - (b >> 8));
00391 }
00392 }
00393
00394 memcpy(output_rows[y] + project_frame_w - buf_margin_right,
00395 input_rows[y] + project_frame_w - buf_margin_right,
00396 buf_margin_right * plugin->input_ptr->get_bytes_per_pixel());
00397 }
00398 }
00399
00400
00401
00402 void BlurZoomClient::process_package(LoadPackage *package)
00403 {
00404 BlurZoomPackage *local_package = (BlurZoomPackage*)package;
00405 unsigned char **input_rows = plugin->input_ptr->get_rows() + local_package->row1;
00406 unsigned char **output_rows = plugin->output_ptr->get_rows() + local_package->row1;
00407 int w = plugin->input_ptr->get_w();
00408 int h = local_package->row2 - local_package->row1;
00409 int x, y;
00410 int a, b, c;
00411 unsigned char *diff, *p;
00412
00413 switch(plugin->input_ptr->get_color_model())
00414 {
00415 case BC_RGB888:
00416 case BC_YUV888:
00417 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
00418 input_rows,
00419 uint8_t,
00420 3);
00421 break;
00422 case BC_RGBA8888:
00423 case BC_YUVA8888:
00424 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
00425 input_rows,
00426 uint8_t,
00427 4);
00428 break;
00429 case BC_RGB161616:
00430 case BC_YUV161616:
00431 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
00432 input_rows,
00433 uint16_t,
00434 3);
00435 break;
00436 case BC_RGBA16161616:
00437 case BC_YUVA16161616:
00438 IMAGE_BGSUBTRACT_UPDATE_Y(diff,
00439 input_rows,
00440 uint16_t,
00441 4);
00442 break;
00443 }
00444
00445
00446 diff += buf_margin_left;
00447 p = blurzoombuf;
00448
00449
00450
00451 for(y = 0; y < buf_height; y++)
00452 {
00453 for(x = 0; x < buf_width; x++)
00454 {
00455 p[x] |= diff[x] >> 3;
00456 }
00457
00458 diff += w;
00459 p += buf_width;
00460 }
00461
00462
00463
00464 blurzoomcore();
00465
00466
00467 p = blurzoombuf;
00468
00469
00470
00471 switch(plugin->input_ptr->get_color_model())
00472 {
00473 case BC_RGB888:
00474 case BC_YUV888:
00475 BLURZOOM_FINAL(uint8_t, 3);
00476 break;
00477 case BC_RGBA8888:
00478 case BC_YUVA8888:
00479 BLURZOOM_FINAL(uint8_t, 4);
00480 break;
00481 case BC_RGB161616:
00482 case BC_YUV161616:
00483 BLURZOOM_FINAL(uint16_t, 3);
00484 break;
00485 case BC_RGBA16161616:
00486 case BC_YUVA16161616:
00487 BLURZOOM_FINAL(uint16_t, 4);
00488 break;
00489 }
00490
00491
00492
00493
00494 }
00495
00496
00497
00498 BlurZoomPackage::BlurZoomPackage()
00499 {
00500 }
00501
00502
00503