2 #include "colormodels.h"
6 #include "agingwindow.h"
15 #define _(String) gettext(String)
16 #define gettext_noop(String) String
17 #define N_(String) gettext_noop (String)
23 REGISTER_PLUGIN(AgingMain)
30 int AgingConfig::dx[] = { 1, 1, 0, -1, -1, -1, 0, 1};
31 int AgingConfig::dy[] = { 0, -1, -1, -1, 0, 1, 1, 1};
33 AgingConfig::AgingConfig()
46 AgingMain::AgingMain(PluginServer *server)
47 : PluginVClient(server)
49 PLUGIN_CONSTRUCTOR_MACRO
53 AgingMain::~AgingMain()
55 PLUGIN_DESTRUCTOR_MACRO
56 if(aging_server) delete aging_server;
59 char* AgingMain::plugin_title() { return _("AgingTV"); }
60 int AgingMain::is_realtime() { return 1; }
62 NEW_PICON_MACRO(AgingMain)
64 SHOW_GUI_MACRO(AgingMain, AgingThread)
66 SET_STRING_MACRO(AgingMain)
68 RAISE_WINDOW_MACRO(AgingMain)
70 int AgingMain::load_defaults()
75 int AgingMain::save_defaults()
80 void AgingMain::load_configuration()
85 void AgingMain::save_data(KeyFrame *keyframe)
89 void AgingMain::read_data(KeyFrame *keyframe)
94 int AgingMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
96 //printf("AgingMain::process_realtime 1\n");
98 //printf("AgingMain::process_realtime 1\n");
99 this->input_ptr = input_ptr;
100 this->output_ptr = output_ptr;
102 if(!aging_server) aging_server = new AgingServer(this,
103 PluginClient::smp + 1,
104 PluginClient::smp + 1);
105 aging_server->process_packages();
106 //printf("AgingMain::process_realtime 2\n");
113 AgingServer::AgingServer(AgingMain *plugin, int total_clients, int total_packages)
114 : LoadServer(1, 1 /* total_clients, total_packages */)
116 this->plugin = plugin;
120 LoadClient* AgingServer::new_client()
122 return new AgingClient(this);
128 LoadPackage* AgingServer::new_package()
130 return new AgingPackage;
135 void AgingServer::init_packages()
137 for(int i = 0; i < total_packages; i++)
139 AgingPackage *package = (AgingPackage*)packages[i];
140 package->row1 = plugin->input_ptr->get_h() / total_packages * i;
141 package->row2 = package->row1 + plugin->input_ptr->get_h() / total_packages;
142 if(i >= total_packages - 1)
143 package->row2 = plugin->input_ptr->get_h();
154 AgingClient::AgingClient(AgingServer *server)
157 this->plugin = server->plugin;
168 #define COLORAGE(type, components) \
173 for(i = 0; i < h; i++) \
175 for(j = 0; j < w; j++) \
177 for(k = 0; k < components; k++) \
179 a = ((type**)input_rows)[i][j * components + k]; \
183 if(sizeof(type) == 2) \
185 b = (a & 0xffff) >> 2; \
186 ((type**)output_rows)[i][j * components + k] = \
187 a - b + 0x1800 + (EffectTV::fastrand() & 0x1000); \
191 b = (a & 0xff) >> 2; \
192 ((type**)output_rows)[i][j * components + k] = \
193 a - b + 0x18 + ((EffectTV::fastrand() >> 8) & 0x10); \
198 ((type**)output_rows)[i][j * components + k] = a; \
205 void AgingClient::coloraging(unsigned char **output_rows,
206 unsigned char **input_rows,
215 COLORAGE(uint8_t, 3);
220 COLORAGE(uint8_t, 4);
225 COLORAGE(uint16_t, 3);
228 case BC_RGBA16161616:
229 case BC_YUVA16161616:
230 COLORAGE(uint16_t, 4);
240 #define SCRATCHES(type, components, chroma) \
242 int i, j, y, y1, y2; \
244 int w_256 = w * 256; \
246 for(i = 0; i < plugin->config.scratch_lines; i++) \
248 if(plugin->config.scratches[i].life) \
250 plugin->config.scratches[i].x = plugin->config.scratches[i].x + plugin->config.scratches[i].dx; \
251 if(plugin->config.scratches[i].x < 0 || plugin->config.scratches[i].x > w_256) \
253 plugin->config.scratches[i].life = 0; \
257 p = (type*)output_rows[0] + \
258 (plugin->config.scratches[i].x >> 8) * \
261 if(plugin->config.scratches[i].init) \
263 y1 = plugin->config.scratches[i].init; \
264 plugin->config.scratches[i].init = 0; \
271 plugin->config.scratches[i].life--; \
272 if(plugin->config.scratches[i].life) \
278 y2 = EffectTV::fastrand() % h; \
281 for(y = y1; y < y2; y++) \
283 for(j = 0; j < (chroma ? 1 : 3); j++) \
285 if(sizeof(type) == 2) \
290 p[j] = a | (b - (b >> 8)); \
297 p[j] = a | (b - (b >> 8)); \
306 p += w * components; \
311 if((EffectTV::fastrand() & 0xf0000000) == 0) \
313 plugin->config.scratches[i].life = 2 + (EffectTV::fastrand() >> 27); \
314 plugin->config.scratches[i].x = EffectTV::fastrand() % (w_256); \
315 plugin->config.scratches[i].dx = ((int)EffectTV::fastrand()) >> 23; \
316 plugin->config.scratches[i].init = (EffectTV::fastrand() % (h - 1)) + 1; \
324 void AgingClient::scratching(unsigned char **output_rows,
332 SCRATCHES(uint8_t, 3, 0);
336 SCRATCHES(uint8_t, 3, 0x80);
340 SCRATCHES(uint8_t, 4, 0);
344 SCRATCHES(uint8_t, 4, 0x80);
348 SCRATCHES(uint16_t, 3, 0);
352 SCRATCHES(uint16_t, 3, 0x8000);
355 case BC_RGBA16161616:
356 SCRATCHES(uint16_t, 4, 0);
359 case BC_YUVA16161616:
360 SCRATCHES(uint16_t, 4, 0x8000);
367 #define PITS(type, components, chroma) \
370 int pnum, size, pnumscale; \
373 pnumscale = plugin->config.area_scale * 2; \
375 if(plugin->config.pits_interval) \
377 pnum = pnumscale + (EffectTV::fastrand() % pnumscale); \
378 plugin->config.pits_interval--; \
382 pnum = EffectTV::fastrand() % pnumscale; \
383 if((EffectTV::fastrand() & 0xf8000000) == 0) \
385 plugin->config.pits_interval = (EffectTV::fastrand() >> 28) + 20; \
389 for(i = 0; i < pnum; i++) \
391 x = EffectTV::fastrand() % (w - 1); \
392 y = EffectTV::fastrand() % (h - 1); \
394 size = EffectTV::fastrand() >> 28; \
396 for(j = 0; j < size; j++) \
398 x = x + EffectTV::fastrand() % 3 - 1; \
399 y = y + EffectTV::fastrand() % 3 - 1; \
401 CLAMP(x, 0, w - 1); \
402 CLAMP(y, 0, h - 1); \
403 for(k = 0; k < (chroma ? 1 : 3); k++) \
404 ((type**)output_rows)[y][x * components + k] = 0xc0; \
408 ((type**)output_rows)[y][x * components + 1] = chroma; \
409 ((type**)output_rows)[y][x * components + 2] = chroma; \
421 void AgingClient::pits(unsigned char **output_rows,
432 PITS(uint8_t, 3, 0x80);
439 PITS(uint8_t, 4, 0x80);
443 PITS(uint16_t, 3, 0);
446 PITS(uint16_t, 3, 0x8000);
449 case BC_RGBA16161616:
450 PITS(uint16_t, 4, 0);
452 case BC_YUVA16161616:
453 PITS(uint16_t, 4, 0x8000);
459 #define DUSTS(type, components, chroma) \
466 if(plugin->config.dust_interval == 0) \
468 if((EffectTV::fastrand() & 0xf0000000) == 0) \
470 plugin->config.dust_interval = EffectTV::fastrand() >> 29; \
475 dnum = plugin->config.area_scale * 4 + (EffectTV::fastrand() >> 27); \
477 for(i = 0; i < dnum; i++) \
479 x = EffectTV::fastrand() % w; \
480 y = EffectTV::fastrand() % h; \
481 d = EffectTV::fastrand() >> 29; \
482 len = EffectTV::fastrand() % plugin->config.area_scale + 5; \
484 for(j = 0; j < len; j++) \
486 CLAMP(x, 0, w - 1); \
487 CLAMP(y, 0, h - 1); \
488 for(k = 0; k < (chroma ? 1 : 3); k++) \
489 ((type**)output_rows)[y][x * components + k] = 0x10; \
493 ((type**)output_rows)[y][x * components + 1] = chroma; \
494 ((type**)output_rows)[y][x * components + 2] = chroma; \
497 y += AgingConfig::dy[d]; \
498 x += AgingConfig::dx[d]; \
500 if(x < 0 || x >= w) break; \
501 if(y < 0 || y >= h) break; \
504 d = (d + EffectTV::fastrand() % 3 - 1) & 7; \
507 plugin->config.dust_interval--; \
513 void AgingClient::dusts(unsigned char **output_rows,
521 DUSTS(uint8_t, 3, 0);
525 DUSTS(uint8_t, 3, 0x80);
529 DUSTS(uint8_t, 4, 0);
533 DUSTS(uint8_t, 4, 0x80);
537 DUSTS(uint16_t, 3, 0);
541 DUSTS(uint16_t, 3, 0x8000);
544 case BC_RGBA16161616:
545 DUSTS(uint16_t, 4, 0);
548 case BC_YUVA16161616:
549 DUSTS(uint16_t, 4, 0x8000);
556 void AgingClient::process_package(LoadPackage *package)
558 //printf("AgingClient::process_package 1\n");
559 AgingPackage *local_package = (AgingPackage*)package;
560 unsigned char **input_rows = plugin->input_ptr->get_rows() + local_package->row1;
561 unsigned char **output_rows = plugin->output_ptr->get_rows() + local_package->row1;
563 //printf("AgingClient::process_package 1\n");
564 if(plugin->config.colorage)
565 coloraging(output_rows,
567 plugin->input_ptr->get_color_model(),
568 plugin->input_ptr->get_w(),
569 local_package->row2 - local_package->row1);
570 //printf("AgingClient::process_package 2\n");
571 if(plugin->config.scratch)
572 scratching(output_rows,
573 plugin->input_ptr->get_color_model(),
574 plugin->input_ptr->get_w(),
575 local_package->row2 - local_package->row1);
576 //printf("AgingClient::process_package 3\n");
577 if(plugin->config.pits)
579 plugin->input_ptr->get_color_model(),
580 plugin->input_ptr->get_w(),
581 local_package->row2 - local_package->row1);
582 //printf("AgingClient::process_package 4 %d\n", plugin->config.dust);
583 if(plugin->config.dust)
585 plugin->input_ptr->get_color_model(),
586 plugin->input_ptr->get_w(),
587 local_package->row2 - local_package->row1);
588 //printf("AgingClient::process_package 5\n");
593 AgingPackage::AgingPackage()