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"
29 #include "burnwindow.h"
37 REGISTER_PLUGIN(BurnMain)
50 BurnConfig::BurnConfig()
57 BurnMain::BurnMain(PluginServer *server)
58 : PluginVClient(server)
73 if(buffer) delete [] buffer;
74 if(burn_server) delete burn_server;
75 if(effecttv) delete effecttv;
79 const char* BurnMain::plugin_title() { return _("BurningTV"); }
80 int BurnMain::is_realtime() { return 1; }
83 NEW_WINDOW_MACRO(BurnMain, BurnWindow)
86 int BurnMain::load_configuration()
89 //printf("BurnMain::load_configuration %d\n", source_position);
93 void BurnMain::save_data(KeyFrame *keyframe)
97 void BurnMain::read_data(KeyFrame *keyframe)
105 void BurnMain::HSItoRGB(double H,
113 double T, Rv, Gv, Bv;
116 Rv = 1 + S * sin(T - 2 * M_PI / 3);
118 Bv = 1 + S * sin(T + 2 * M_PI / 3);
121 *r = (int)CLIP(Rv * T, 0, 255);
122 *g = (int)CLIP(Gv * T, 0, 255);
123 *b = (int)CLIP(Bv * T, 0, 255);
127 void BurnMain::make_palette(int color_model)
131 for(i = 0; i < MAXCOLOR; i++)
133 HSItoRGB(4.6 - 1.5 * i / MAXCOLOR,
134 (double)i / MAXCOLOR,
135 (double)i / MAXCOLOR,
143 //printf("BurnMain::make_palette %d %d %d %d\n", i, palette[0][i], palette[1][i], palette[2][i]);
147 for(i = MAXCOLOR; i < 256; i++)
159 //printf("BurnMain::make_palette %d %d %d %d\n", i, palette[0][i], palette[1][i], palette[2][i]);
166 int BurnMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
168 this->input_ptr = input_ptr;
169 this->output_ptr = output_ptr;
171 load_configuration();
175 effecttv = new EffectTV(input_ptr->get_w(), input_ptr->get_h());
176 buffer = (unsigned char *)new unsigned char[input_ptr->get_w() * input_ptr->get_h()];
177 make_palette(input_ptr->get_color_model());
179 effecttv->image_set_threshold_y(config.threshold);
182 burn_server = new BurnServer(this, 1, 1);
187 bzero(buffer, input_ptr->get_w() * input_ptr->get_h());
188 effecttv->image_bgset_y(input_ptr);
190 burn_server->process_packages();
193 // if(total >= config.recycle * project_frame_rate) total = 0;
199 BurnServer::BurnServer(BurnMain *plugin, int total_clients, int total_packages)
200 : LoadServer(total_clients, total_packages)
202 this->plugin = plugin;
206 LoadClient* BurnServer::new_client()
208 return new BurnClient(this);
214 LoadPackage* BurnServer::new_package()
216 return new BurnPackage;
221 void BurnServer::init_packages()
223 for(int i = 0; i < get_total_packages(); i++)
225 BurnPackage *package = (BurnPackage*)get_package(i);
226 package->row1 = plugin->input_ptr->get_h() * i / get_total_packages();
227 package->row2 = plugin->input_ptr->get_h() * (i + 1) / get_total_packages();
238 BurnClient::BurnClient(BurnServer *server)
241 this->plugin = server->plugin;
252 #define BURN(type, components, is_yuv) \
255 type **rows = (type**)input_rows; \
256 for(y = 0; y < height; y++) \
258 for(x = 1; x < width - 1; x++) \
260 if(sizeof(type) == 4) \
262 a1 = (int)(rows[0][i * components] * 0xff); \
263 a2 = (int)(rows[0][i * components + 1] * 0xff); \
264 a3 = (int)(rows[0][i * components + 2] * 0xff); \
265 CLAMP(a1, 0, 0xff); \
266 CLAMP(a2, 0, 0xff); \
267 CLAMP(a3, 0, 0xff); \
268 b1 = plugin->palette[0][plugin->buffer[i]]; \
269 b2 = plugin->palette[1][plugin->buffer[i]]; \
270 b3 = plugin->palette[2][plugin->buffer[i]]; \
277 rows[0][i * components] = (type)(a1 | (b1 - (b1 >> 8))) / 0xff; \
278 rows[0][i * components + 1] = (type)(a2 | (b2 - (b2 >> 8))) / 0xff; \
279 rows[0][i * components + 2] = (type)(a3 | (b3 - (b3 >> 8))) / 0xff; \
282 if(sizeof(type) == 2) \
284 a1 = ((int)rows[0][i * components + 0]) >> 8; \
285 a2 = ((int)rows[0][i * components + 1]) >> 8; \
286 a3 = ((int)rows[0][i * components + 2]) >> 8; \
287 b1 = plugin->palette[0][plugin->buffer[i]]; \
288 b2 = plugin->palette[1][plugin->buffer[i]]; \
289 b3 = plugin->palette[2][plugin->buffer[i]]; \
290 if(is_yuv) plugin->yuv->yuv_to_rgb_8(a1, a2, a3); \
297 a1 = (a1 | (b1 - (b1 >> 8))); \
298 a2 = (a2 | (b2 - (b2 >> 8))); \
299 a3 = (a3 | (b3 - (b3 >> 8))); \
302 CLAMP(a1, 0, 0xff); \
303 CLAMP(a2, 0, 0xff); \
304 CLAMP(a3, 0, 0xff); \
305 plugin->yuv->rgb_to_yuv_8(a1, a2, a3); \
307 rows[0][i * components + 0] = a1 | (a1 << 8); \
308 rows[0][i * components + 1] = a2 | (a2 << 8); \
309 rows[0][i * components + 2] = a3 | (a3 << 8); \
313 a1 = (int)rows[0][i * components + 0]; \
314 a2 = (int)rows[0][i * components + 1]; \
315 a3 = (int)rows[0][i * components + 2]; \
316 b1 = plugin->palette[0][plugin->buffer[i]]; \
317 b2 = plugin->palette[1][plugin->buffer[i]]; \
318 b3 = plugin->palette[2][plugin->buffer[i]]; \
319 if(is_yuv) plugin->yuv->yuv_to_rgb_8(a1, a2, a3); \
326 a1 = (a1 | (b1 - (b1 >> 8))); \
327 a2 = (a2 | (b2 - (b2 >> 8))); \
328 a3 = (a3 | (b3 - (b3 >> 8))); \
331 CLAMP(a1, 0, 0xff); \
332 CLAMP(a2, 0, 0xff); \
333 CLAMP(a3, 0, 0xff); \
334 plugin->yuv->rgb_to_yuv_8(a1, a2, a3); \
336 rows[0][i * components + 0] = a1; \
337 rows[0][i * components + 1] = a2; \
338 rows[0][i * components + 2] = a3; \
349 void BurnClient::process_package(LoadPackage *package)
351 BurnPackage *local_package = (BurnPackage*)package;
352 unsigned char **input_rows = plugin->input_ptr->get_rows() + local_package->row1;
353 //unsigned char **output_rows = plugin->output_ptr->get_rows() + local_package->row1;
354 int width = plugin->input_ptr->get_w();
355 int height = local_package->row2 - local_package->row1;
357 //int pitch = width * plugin->input_ptr->get_bytes_per_pixel();
362 diff = plugin->effecttv->image_bgsubtract_y(input_rows,
363 plugin->input_ptr->get_color_model());
365 for(x = 1; x < width - 1; x++)
368 for(y = 0; y < height - 1; y++)
370 unsigned int w = diff[y * width + x];
371 plugin->buffer[y * width + x] |= v ^ w;
376 for(x = 1; x < width - 1; x++)
380 for(y = 1; y < height; y++)
382 int v = plugin->buffer[i];
384 if(v < plugin->config.decay)
385 plugin->buffer[i - width] = 0;
387 plugin->buffer[i - width + EffectTV::fastrand() % 3 - 1] =
388 v - (EffectTV::fastrand() & plugin->config.decay);
396 switch(plugin->input_ptr->get_color_model())
421 BURN(uint16_t, 3, 0);
424 BURN(uint16_t, 3, 1);
427 case BC_RGBA16161616:
428 BURN(uint16_t, 4, 0);
430 case BC_YUVA16161616:
431 BURN(uint16_t, 4, 1);
440 BurnPackage::BurnPackage()