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 N_("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 < 3; k++) \
179 if(sizeof(type) == 4) \
181 a = (int)(((type**)input_rows)[i][j * components + k] * 0xffff); \
182 CLAMP(a, 0, 0xffff); \
185 a = (int)((type**)input_rows)[i][j * components + k]; \
187 if(sizeof(type) == 4) \
189 b = (a & 0xffff) >> 2; \
190 ((type**)output_rows)[i][j * components + k] = \
191 (type)(a - b + 0x1800 + (EffectTV::fastrand() & 0x1000)) / 0xffff; \
194 if(sizeof(type) == 2) \
196 b = (a & 0xffff) >> 2; \
197 ((type**)output_rows)[i][j * components + k] = \
198 (type)(a - b + 0x1800 + (EffectTV::fastrand() & 0x1000)); \
202 b = (a & 0xff) >> 2; \
203 ((type**)output_rows)[i][j * components + k] = \
204 (type)(a - b + 0x18 + ((EffectTV::fastrand() >> 8) & 0x10)); \
211 void AgingClient::coloraging(unsigned char **output_rows,
212 unsigned char **input_rows,
221 COLORAGE(uint8_t, 3);
234 COLORAGE(uint8_t, 4);
239 COLORAGE(uint16_t, 3);
242 case BC_RGBA16161616:
243 case BC_YUVA16161616:
244 COLORAGE(uint16_t, 4);
254 #define SCRATCHES(type, components, chroma) \
256 int i, j, y, y1, y2; \
259 int w_256 = w * 256; \
261 for(i = 0; i < plugin->config.scratch_lines; i++) \
263 if(plugin->config.scratches[i].life) \
265 plugin->config.scratches[i].x = plugin->config.scratches[i].x + plugin->config.scratches[i].dx; \
266 if(plugin->config.scratches[i].x < 0 || plugin->config.scratches[i].x > w_256) \
268 plugin->config.scratches[i].life = 0; \
272 p = (type*)output_rows[0] + \
273 (plugin->config.scratches[i].x >> 8) * \
276 if(plugin->config.scratches[i].init) \
278 y1 = plugin->config.scratches[i].init; \
279 plugin->config.scratches[i].init = 0; \
286 plugin->config.scratches[i].life--; \
287 if(plugin->config.scratches[i].life) \
293 y2 = EffectTV::fastrand() % h; \
296 for(y = y1; y < y2; y++) \
298 for(j = 0; j < (chroma ? 1 : 3); j++) \
300 if(sizeof(type) == 4) \
302 int temp = (int)(p[j] * 0xffff); \
303 CLAMP(temp, 0, 0xffff); \
307 p[j] = (type)(a | (b - (b >> 8))) / 0xffff; \
310 if(sizeof(type) == 2) \
312 int temp = (int)p[j]; \
316 p[j] = (type)(a | (b - (b >> 8))); \
320 int temp = (int)p[j]; \
324 p[j] = (type)(a | (b - (b >> 8))); \
333 p += w * components; \
338 if((EffectTV::fastrand() & 0xf0000000) == 0) \
340 plugin->config.scratches[i].life = 2 + (EffectTV::fastrand() >> 27); \
341 plugin->config.scratches[i].x = EffectTV::fastrand() % (w_256); \
342 plugin->config.scratches[i].dx = ((int)EffectTV::fastrand()) >> 23; \
343 plugin->config.scratches[i].init = (EffectTV::fastrand() % (h - 1)) + 1; \
351 void AgingClient::scratching(unsigned char **output_rows,
359 SCRATCHES(uint8_t, 3, 0);
363 SCRATCHES(float, 3, 0);
367 SCRATCHES(uint8_t, 3, 0x80);
371 SCRATCHES(float, 4, 0);
375 SCRATCHES(uint8_t, 4, 0);
379 SCRATCHES(uint8_t, 4, 0x80);
383 SCRATCHES(uint16_t, 3, 0);
387 SCRATCHES(uint16_t, 3, 0x8000);
390 case BC_RGBA16161616:
391 SCRATCHES(uint16_t, 4, 0);
394 case BC_YUVA16161616:
395 SCRATCHES(uint16_t, 4, 0x8000);
402 #define PITS(type, components, luma, chroma) \
405 int pnum, size, pnumscale; \
408 pnumscale = plugin->config.area_scale * 2; \
410 if(plugin->config.pits_interval) \
412 pnum = pnumscale + (EffectTV::fastrand() % pnumscale); \
413 plugin->config.pits_interval--; \
417 pnum = EffectTV::fastrand() % pnumscale; \
418 if((EffectTV::fastrand() & 0xf8000000) == 0) \
420 plugin->config.pits_interval = (EffectTV::fastrand() >> 28) + 20; \
424 for(i = 0; i < pnum; i++) \
426 x = EffectTV::fastrand() % (w - 1); \
427 y = EffectTV::fastrand() % (h - 1); \
429 size = EffectTV::fastrand() >> 28; \
431 for(j = 0; j < size; j++) \
433 x = x + EffectTV::fastrand() % 3 - 1; \
434 y = y + EffectTV::fastrand() % 3 - 1; \
436 CLAMP(x, 0, w - 1); \
437 CLAMP(y, 0, h - 1); \
438 for(k = 0; k < (chroma ? 1 : 3); k++) \
440 ((type**)output_rows)[y][x * components + k] = luma; \
445 ((type**)output_rows)[y][x * components + 1] = chroma; \
446 ((type**)output_rows)[y][x * components + 2] = chroma; \
458 void AgingClient::pits(unsigned char **output_rows,
466 PITS(uint8_t, 3, 0xc0, 0);
469 PITS(float, 3, (float)0xc0 / 0xff, 0);
472 PITS(uint8_t, 3, 0xc0, 0x80);
476 PITS(float, 4, (float)0xc0 / 0xff, 0);
479 PITS(uint8_t, 4, 0xc0, 0);
482 PITS(uint8_t, 4, 0xc0, 0x80);
486 PITS(uint16_t, 3, 0xc000, 0);
489 PITS(uint16_t, 3, 0xc000, 0x8000);
492 case BC_RGBA16161616:
493 PITS(uint16_t, 4, 0xc000, 0);
495 case BC_YUVA16161616:
496 PITS(uint16_t, 4, 0xc000, 0x8000);
502 #define DUSTS(type, components, luma, chroma) \
509 if(plugin->config.dust_interval == 0) \
511 if((EffectTV::fastrand() & 0xf0000000) == 0) \
513 plugin->config.dust_interval = EffectTV::fastrand() >> 29; \
518 dnum = plugin->config.area_scale * 4 + (EffectTV::fastrand() >> 27); \
520 for(i = 0; i < dnum; i++) \
522 x = EffectTV::fastrand() % w; \
523 y = EffectTV::fastrand() % h; \
524 d = EffectTV::fastrand() >> 29; \
525 len = EffectTV::fastrand() % plugin->config.area_scale + 5; \
527 for(j = 0; j < len; j++) \
529 CLAMP(x, 0, w - 1); \
530 CLAMP(y, 0, h - 1); \
531 for(k = 0; k < (chroma ? 1 : 3); k++) \
533 ((type**)output_rows)[y][x * components + k] = luma; \
538 ((type**)output_rows)[y][x * components + 1] = chroma; \
539 ((type**)output_rows)[y][x * components + 2] = chroma; \
542 y += AgingConfig::dy[d]; \
543 x += AgingConfig::dx[d]; \
545 if(x < 0 || x >= w) break; \
546 if(y < 0 || y >= h) break; \
549 d = (d + EffectTV::fastrand() % 3 - 1) & 7; \
552 plugin->config.dust_interval--; \
558 void AgingClient::dusts(unsigned char **output_rows,
566 DUSTS(uint8_t, 3, 0x10, 0);
570 DUSTS(float, 3, (float)0x10 / 0xff, 0);
574 DUSTS(uint8_t, 3, 0x10, 0x80);
578 DUSTS(float, 4, (float)0x10 / 0xff, 0);
582 DUSTS(uint8_t, 4, 0x10, 0);
586 DUSTS(uint8_t, 4, 0x10, 0x80);
590 DUSTS(uint16_t, 3, 0x1000, 0);
594 DUSTS(uint16_t, 3, 0x1000, 0x8000);
597 case BC_RGBA16161616:
598 DUSTS(uint16_t, 4, 0x1000, 0);
601 case BC_YUVA16161616:
602 DUSTS(uint16_t, 4, 0x1000, 0x8000);
609 void AgingClient::process_package(LoadPackage *package)
611 //printf("AgingClient::process_package 1\n");
612 AgingPackage *local_package = (AgingPackage*)package;
613 unsigned char **input_rows = plugin->input_ptr->get_rows() + local_package->row1;
614 unsigned char **output_rows = plugin->output_ptr->get_rows() + local_package->row1;
616 //printf("AgingClient::process_package 1\n");
617 if(plugin->config.colorage)
618 coloraging(output_rows,
620 plugin->input_ptr->get_color_model(),
621 plugin->input_ptr->get_w(),
622 local_package->row2 - local_package->row1);
623 //printf("AgingClient::process_package 2\n");
624 if(plugin->config.scratch)
625 scratching(output_rows,
626 plugin->input_ptr->get_color_model(),
627 plugin->input_ptr->get_w(),
628 local_package->row2 - local_package->row1);
629 //printf("AgingClient::process_package 3\n");
630 if(plugin->config.pits)
632 plugin->input_ptr->get_color_model(),
633 plugin->input_ptr->get_w(),
634 local_package->row2 - local_package->row1);
635 //printf("AgingClient::process_package 4 %d\n", plugin->config.dust);
636 if(plugin->config.dust)
638 plugin->input_ptr->get_color_model(),
639 plugin->input_ptr->get_w(),
640 local_package->row2 - local_package->row1);
641 //printf("AgingClient::process_package 5\n");
646 AgingPackage::AgingPackage()