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 < get_total_packages(); i++)
139 AgingPackage *package = (AgingPackage*)get_package(i);
140 package->row1 = plugin->input_ptr->get_h() * i / get_total_packages();
141 package->row2 = plugin->input_ptr->get_h() * (i + 1) / get_total_packages();
152 AgingClient::AgingClient(AgingServer *server)
155 this->plugin = server->plugin;
166 #define COLORAGE(type, components) \
171 for(i = 0; i < h; i++) \
173 for(j = 0; j < w; j++) \
175 for(k = 0; k < 3; k++) \
177 if(sizeof(type) == 4) \
179 a = (int)(((type**)input_rows)[i][j * components + k] * 0xffff); \
180 CLAMP(a, 0, 0xffff); \
183 a = (int)((type**)input_rows)[i][j * components + k]; \
185 if(sizeof(type) == 4) \
187 b = (a & 0xffff) >> 2; \
188 ((type**)output_rows)[i][j * components + k] = \
189 (type)(a - b + 0x1800 + (EffectTV::fastrand() & 0x1000)) / 0xffff; \
192 if(sizeof(type) == 2) \
194 b = (a & 0xffff) >> 2; \
195 ((type**)output_rows)[i][j * components + k] = \
196 (type)(a - b + 0x1800 + (EffectTV::fastrand() & 0x1000)); \
200 b = (a & 0xff) >> 2; \
201 ((type**)output_rows)[i][j * components + k] = \
202 (type)(a - b + 0x18 + ((EffectTV::fastrand() >> 8) & 0x10)); \
209 void AgingClient::coloraging(unsigned char **output_rows,
210 unsigned char **input_rows,
219 COLORAGE(uint8_t, 3);
232 COLORAGE(uint8_t, 4);
237 COLORAGE(uint16_t, 3);
240 case BC_RGBA16161616:
241 case BC_YUVA16161616:
242 COLORAGE(uint16_t, 4);
252 #define SCRATCHES(type, components, chroma) \
254 int i, j, y, y1, y2; \
257 int w_256 = w * 256; \
259 for(i = 0; i < plugin->config.scratch_lines; i++) \
261 if(plugin->config.scratches[i].life) \
263 plugin->config.scratches[i].x = plugin->config.scratches[i].x + plugin->config.scratches[i].dx; \
264 if(plugin->config.scratches[i].x < 0 || plugin->config.scratches[i].x > w_256) \
266 plugin->config.scratches[i].life = 0; \
270 p = (type*)output_rows[0] + \
271 (plugin->config.scratches[i].x >> 8) * \
274 if(plugin->config.scratches[i].init) \
276 y1 = plugin->config.scratches[i].init; \
277 plugin->config.scratches[i].init = 0; \
284 plugin->config.scratches[i].life--; \
285 if(plugin->config.scratches[i].life) \
291 y2 = EffectTV::fastrand() % h; \
294 for(y = y1; y < y2; y++) \
296 for(j = 0; j < (chroma ? 1 : 3); j++) \
298 if(sizeof(type) == 4) \
300 int temp = (int)(p[j] * 0xffff); \
301 CLAMP(temp, 0, 0xffff); \
305 p[j] = (type)(a | (b - (b >> 8))) / 0xffff; \
308 if(sizeof(type) == 2) \
310 int temp = (int)p[j]; \
314 p[j] = (type)(a | (b - (b >> 8))); \
318 int temp = (int)p[j]; \
322 p[j] = (type)(a | (b - (b >> 8))); \
331 p += w * components; \
336 if((EffectTV::fastrand() & 0xf0000000) == 0) \
338 plugin->config.scratches[i].life = 2 + (EffectTV::fastrand() >> 27); \
339 plugin->config.scratches[i].x = EffectTV::fastrand() % (w_256); \
340 plugin->config.scratches[i].dx = ((int)EffectTV::fastrand()) >> 23; \
341 plugin->config.scratches[i].init = (EffectTV::fastrand() % (h - 1)) + 1; \
349 void AgingClient::scratching(unsigned char **output_rows,
357 SCRATCHES(uint8_t, 3, 0);
361 SCRATCHES(float, 3, 0);
365 SCRATCHES(uint8_t, 3, 0x80);
369 SCRATCHES(float, 4, 0);
373 SCRATCHES(uint8_t, 4, 0);
377 SCRATCHES(uint8_t, 4, 0x80);
381 SCRATCHES(uint16_t, 3, 0);
385 SCRATCHES(uint16_t, 3, 0x8000);
388 case BC_RGBA16161616:
389 SCRATCHES(uint16_t, 4, 0);
392 case BC_YUVA16161616:
393 SCRATCHES(uint16_t, 4, 0x8000);
400 #define PITS(type, components, luma, chroma) \
403 int pnum, size, pnumscale; \
406 pnumscale = plugin->config.area_scale * 2; \
408 if(plugin->config.pits_interval) \
410 pnum = pnumscale + (EffectTV::fastrand() % pnumscale); \
411 plugin->config.pits_interval--; \
415 pnum = EffectTV::fastrand() % pnumscale; \
416 if((EffectTV::fastrand() & 0xf8000000) == 0) \
418 plugin->config.pits_interval = (EffectTV::fastrand() >> 28) + 20; \
422 for(i = 0; i < pnum; i++) \
424 x = EffectTV::fastrand() % (w - 1); \
425 y = EffectTV::fastrand() % (h - 1); \
427 size = EffectTV::fastrand() >> 28; \
429 for(j = 0; j < size; j++) \
431 x = x + EffectTV::fastrand() % 3 - 1; \
432 y = y + EffectTV::fastrand() % 3 - 1; \
434 CLAMP(x, 0, w - 1); \
435 CLAMP(y, 0, h - 1); \
436 for(k = 0; k < (chroma ? 1 : 3); k++) \
438 ((type**)output_rows)[y][x * components + k] = luma; \
443 ((type**)output_rows)[y][x * components + 1] = chroma; \
444 ((type**)output_rows)[y][x * components + 2] = chroma; \
456 void AgingClient::pits(unsigned char **output_rows,
464 PITS(uint8_t, 3, 0xc0, 0);
467 PITS(float, 3, (float)0xc0 / 0xff, 0);
470 PITS(uint8_t, 3, 0xc0, 0x80);
474 PITS(float, 4, (float)0xc0 / 0xff, 0);
477 PITS(uint8_t, 4, 0xc0, 0);
480 PITS(uint8_t, 4, 0xc0, 0x80);
484 PITS(uint16_t, 3, 0xc000, 0);
487 PITS(uint16_t, 3, 0xc000, 0x8000);
490 case BC_RGBA16161616:
491 PITS(uint16_t, 4, 0xc000, 0);
493 case BC_YUVA16161616:
494 PITS(uint16_t, 4, 0xc000, 0x8000);
500 #define DUSTS(type, components, luma, chroma) \
507 if(plugin->config.dust_interval == 0) \
509 if((EffectTV::fastrand() & 0xf0000000) == 0) \
511 plugin->config.dust_interval = EffectTV::fastrand() >> 29; \
516 dnum = plugin->config.area_scale * 4 + (EffectTV::fastrand() >> 27); \
518 for(i = 0; i < dnum; i++) \
520 x = EffectTV::fastrand() % w; \
521 y = EffectTV::fastrand() % h; \
522 d = EffectTV::fastrand() >> 29; \
523 len = EffectTV::fastrand() % plugin->config.area_scale + 5; \
525 for(j = 0; j < len; j++) \
527 CLAMP(x, 0, w - 1); \
528 CLAMP(y, 0, h - 1); \
529 for(k = 0; k < (chroma ? 1 : 3); k++) \
531 ((type**)output_rows)[y][x * components + k] = luma; \
536 ((type**)output_rows)[y][x * components + 1] = chroma; \
537 ((type**)output_rows)[y][x * components + 2] = chroma; \
540 y += AgingConfig::dy[d]; \
541 x += AgingConfig::dx[d]; \
543 if(x < 0 || x >= w) break; \
544 if(y < 0 || y >= h) break; \
547 d = (d + EffectTV::fastrand() % 3 - 1) & 7; \
550 plugin->config.dust_interval--; \
556 void AgingClient::dusts(unsigned char **output_rows,
564 DUSTS(uint8_t, 3, 0x10, 0);
568 DUSTS(float, 3, (float)0x10 / 0xff, 0);
572 DUSTS(uint8_t, 3, 0x10, 0x80);
576 DUSTS(float, 4, (float)0x10 / 0xff, 0);
580 DUSTS(uint8_t, 4, 0x10, 0);
584 DUSTS(uint8_t, 4, 0x10, 0x80);
588 DUSTS(uint16_t, 3, 0x1000, 0);
592 DUSTS(uint16_t, 3, 0x1000, 0x8000);
595 case BC_RGBA16161616:
596 DUSTS(uint16_t, 4, 0x1000, 0);
599 case BC_YUVA16161616:
600 DUSTS(uint16_t, 4, 0x1000, 0x8000);
607 void AgingClient::process_package(LoadPackage *package)
609 //printf("AgingClient::process_package 1\n");
610 AgingPackage *local_package = (AgingPackage*)package;
611 unsigned char **input_rows = plugin->input_ptr->get_rows() + local_package->row1;
612 unsigned char **output_rows = plugin->output_ptr->get_rows() + local_package->row1;
614 //printf("AgingClient::process_package 1\n");
615 if(plugin->config.colorage)
616 coloraging(output_rows,
618 plugin->input_ptr->get_color_model(),
619 plugin->input_ptr->get_w(),
620 local_package->row2 - local_package->row1);
621 //printf("AgingClient::process_package 2\n");
622 if(plugin->config.scratch)
623 scratching(output_rows,
624 plugin->input_ptr->get_color_model(),
625 plugin->input_ptr->get_w(),
626 local_package->row2 - local_package->row1);
627 //printf("AgingClient::process_package 3\n");
628 if(plugin->config.pits)
630 plugin->input_ptr->get_color_model(),
631 plugin->input_ptr->get_w(),
632 local_package->row2 - local_package->row1);
633 //printf("AgingClient::process_package 4 %d\n", plugin->config.dust);
634 if(plugin->config.dust)
636 plugin->input_ptr->get_color_model(),
637 plugin->input_ptr->get_w(),
638 local_package->row2 - local_package->row1);
639 //printf("AgingClient::process_package 5\n");
644 AgingPackage::AgingPackage()