int HueEffect::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { load_configuration(); read_frame(frame, 0, start_position, frame_rate, get_use_opengl()); this->input = frame; this->output = frame; if(EQUIV(config.hue, 0) && EQUIV(config.saturation, 0) && EQUIV(config.value, 0)) { return 0; } else { if(get_use_opengl()) { run_opengl(); return 0; } if(!engine) engine = new HueEngine(this, PluginClient::smp + 1); engine->process_packages(); } return 0; }
int ChromaKey::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { SET_TRACE load_configuration(); this->input = frame; this->output = frame; read_frame(frame, 0, start_position, frame_rate, get_use_opengl()); if(EQUIV(config.threshold, 0)) { return 1; } else { if(get_use_opengl()) return run_opengl(); if(!engine) engine = new ChromaKeyServer(this); engine->process_packages(); } SET_TRACE return 1; }
int ThresholdMain::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { load_configuration(); int use_opengl = get_use_opengl() && (!config.plot || !gui_open()); read_frame(frame, 0, get_source_position(), get_framerate(), use_opengl); if(use_opengl) return run_opengl(); send_render_gui(frame); if(!threshold_engine) threshold_engine = new ThresholdEngine(this); threshold_engine->process_packages(frame); return 0; }
int BrightnessMain::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { load_configuration(); read_frame(frame, 0, start_position, frame_rate, get_use_opengl()); // Use hardware if(get_use_opengl()) { run_opengl(); return 0; } if(!engine) engine = new BrightnessEngine(this, PluginClient::smp + 1); this->input = frame; this->output = frame; if(!EQUIV(config.brightness, 0) || !EQUIV(config.contrast, 0)) { engine->process_packages(); } return 0; }
int FlipMain::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { int i, j, k, l; int w = frame->get_w(); int h = frame->get_h(); int colormodel = frame->get_color_model(); load_configuration(); read_frame(frame, 0, get_source_position(), get_framerate(), get_use_opengl()); if(get_use_opengl()) { if(config.flip_vertical || config.flip_horizontal) return run_opengl(); else return 0; } switch(colormodel) { case BC_RGB888: case BC_YUV888: FLIP_MACRO(unsigned char, 3); break; case BC_RGB_FLOAT: FLIP_MACRO(float, 3); break; case BC_RGB161616: case BC_YUV161616: FLIP_MACRO(uint16_t, 3); break; case BC_RGBA8888: case BC_YUVA8888: FLIP_MACRO(unsigned char, 4); break; case BC_RGBA_FLOAT: FLIP_MACRO(float, 4); break; case BC_RGBA16161616: case BC_YUVA16161616: FLIP_MACRO(uint16_t, 4); break; } return 0; }
int ChromaKeyHSV::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { load_configuration(); this->input = frame; this->output = frame; read_frame(frame, 0, start_position, frame_rate, get_use_opengl()); if(get_use_opengl()) return run_opengl(); if(!engine) engine = new ChromaKeyServer(this); engine->process_packages(); return 0; }
int LensMain::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { VFrame *input; load_configuration(); if(get_use_opengl()) { input = frame; } else { input = new_temp(frame->get_w(), frame->get_h(), frame->get_color_model()); } read_frame(input, 0, start_position, frame_rate, get_use_opengl()); if(get_use_opengl()) { run_opengl(); return 0; } else { if(!engine) engine = new LensEngine(this); engine->process_packages(); if(config.draw_guides) { // Draw center #define CENTER_H 20 #define CENTER_W 20 #define DRAW_GUIDES(components, type, max) \ { \ type **rows = (type**)get_output()->get_rows(); \ if(center_x >= 0 && center_x < w || \ center_y >= 0 && center_y < h) \ { \ type *hrow = rows[center_y] + components * (center_x - CENTER_W / 2); \ for(int i = center_x - CENTER_W / 2; i <= center_x + CENTER_W / 2; i++) \ { \ if(i >= 0 && i < w) \ { \ hrow[0] = max - hrow[0]; \ hrow[1] = max - hrow[1]; \ hrow[2] = max - hrow[2]; \ hrow += components; \ } \ } \ \ for(int i = center_y - CENTER_W / 2; i <= center_y + CENTER_W / 2; i++) \ { \ if(i >= 0 && i < h) \ { \ type *vrow = rows[i] + center_x * components; \ vrow[0] = max - vrow[0]; \ vrow[1] = max - vrow[1]; \ vrow[2] = max - vrow[2]; \ } \ } \ } \ } int w = get_output()->get_w(); int h = get_output()->get_h(); int center_x = (int)(config.center_x * w / 100); int center_y = (int)(config.center_y * h / 100); switch(get_output()->get_color_model()) { case BC_RGB_FLOAT: DRAW_GUIDES(3, float, 1.0) break; case BC_RGBA_FLOAT: DRAW_GUIDES(4, float, 1.0) break; case BC_RGB888: DRAW_GUIDES(3, unsigned char, 0xff) break; case BC_RGBA8888: DRAW_GUIDES(4, unsigned char, 0xff) break; case BC_YUV888: DRAW_GUIDES(3, unsigned char, 0xff) break; case BC_YUVA8888: DRAW_GUIDES(4, unsigned char, 0xff) break; } } }
int FreezeFrameMain::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { int64_t previous_first_frame = first_frame_position; load_configuration(); // Just entered frozen range if(!first_frame && config.enabled) { if(!first_frame) first_frame = new VFrame(0, -1, frame->get_w(), frame->get_h(), frame->get_color_model(), -1); //printf("FreezeFrameMain::process_buffer 1 %lld\n", first_frame_position); read_frame(first_frame, 0, get_direction() == PLAY_REVERSE ? first_frame_position + 1 : first_frame_position, frame_rate, get_use_opengl()); if(get_use_opengl()) return run_opengl(); frame->copy_from(first_frame); } else // Still not frozen if(!first_frame && !config.enabled) { read_frame(frame, 0, start_position, frame_rate, get_use_opengl()); } else // Just left frozen range if(first_frame && !config.enabled) { delete first_frame; first_frame = 0; read_frame(frame, 0, start_position, frame_rate, get_use_opengl()); } else // Still frozen if(first_frame && config.enabled) { // Had a keyframe in frozen range. Load new first frame if(previous_first_frame != first_frame_position) { read_frame(first_frame, 0, get_direction() == PLAY_REVERSE ? first_frame_position + 1 : first_frame_position, frame_rate, get_use_opengl()); } if(get_use_opengl()) return run_opengl(); frame->copy_from(first_frame); } // Line double to support interlacing // if(config.line_double && config.enabled) // { // for(int i = 0; i < frame->get_h() - 1; i += 2) // { // memcpy(frame->get_rows()[i + 1], // frame->get_rows()[i], // frame->get_bytes_per_line()); // } // } return 0; }
int ColorBalanceMain::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { need_reconfigure |= load_configuration(); //printf("ColorBalanceMain::process_realtime 1 %d\n", need_reconfigure); if(need_reconfigure) { if(!engine) { total_engines = PluginClient::smp + 1; engine = new ColorBalanceEngine*[total_engines]; for(int i = 0; i < total_engines; i++) { engine[i] = new ColorBalanceEngine(this); engine[i]->start(); } } reconfigure(); need_reconfigure = 0; } frame->get_params()->update("COLORBALANCE_PRESERVE", config.preserve); frame->get_params()->update("COLORBALANCE_CYAN", calculate_transfer(config.cyan)); frame->get_params()->update("COLORBALANCE_MAGENTA", calculate_transfer(config.magenta)); frame->get_params()->update("COLORBALANCE_YELLOW", calculate_transfer(config.yellow)); read_frame(frame, 0, get_source_position(), get_framerate(), get_use_opengl()); int aggregate_interpolate = 0; int aggregate_gamma = 0; get_aggregation(&aggregate_interpolate, &aggregate_gamma); if(!EQUIV(config.cyan, 0) || !EQUIV(config.magenta, 0) || !EQUIV(config.yellow, 0) || (get_use_opengl() && (aggregate_interpolate || aggregate_gamma))) { if(get_use_opengl()) { //get_output()->dump_stacks(); // Aggregate if(next_effect_is("Histogram")) return 0; return run_opengl(); } for(int i = 0; i < total_engines; i++) { engine[i]->start_process_frame(frame, frame, frame->get_h() * i / total_engines, frame->get_h() * (i + 1) / total_engines); } for(int i = 0; i < total_engines; i++) { engine[i]->wait_process_frame(); } } return 0; }
int DissolveMain::process_realtime(VFrame *incoming, VFrame *outgoing) { fade = (float)PluginClient::get_source_position() / PluginClient::get_total_len(); // Use hardware if(get_use_opengl()) { run_opengl(); return 0; } // Use software if(!overlayer) overlayer = new OverlayFrame(get_project_smp() + 1); // There is a problem when dissolving from a big picture to a small picture. // In order to make it dissolve correctly, we have to manually decrese alpha of big picture. switch (outgoing->get_color_model()) { case BC_RGBA8888: case BC_YUVA8888: { uint8_t** data_rows = (uint8_t **)outgoing->get_rows(); int w = outgoing->get_w(); int h = outgoing->get_h(); for(int i = 0; i < h; i++) { uint8_t* alpha_chan = data_rows[i] + 3; for(int j = 0; j < w; j++) { *alpha_chan = (uint8_t) (*alpha_chan * (1-fade)); alpha_chan+=4; } } break; } case BC_YUVA16161616: { uint16_t** data_rows = (uint16_t **)outgoing->get_rows(); int w = outgoing->get_w(); int h = outgoing->get_h(); for(int i = 0; i < h; i++) { uint16_t* alpha_chan = data_rows[i] + 3; // 3 since this is uint16_t for(int j = 0; j < w; j++) { *alpha_chan = (uint16_t)(*alpha_chan * (1-fade)); alpha_chan += 8; } } break; } case BC_RGBA_FLOAT: { float** data_rows = (float **)outgoing->get_rows(); int w = outgoing->get_w(); int h = outgoing->get_h(); for(int i = 0; i < h; i++) { float* alpha_chan = data_rows[i] + 3; // 3 since this is floats for(int j = 0; j < w; j++) { *alpha_chan = *alpha_chan * (1-fade); alpha_chan += sizeof(float); } } break; } default: break; } overlayer->overlay(outgoing, incoming, 0, 0, incoming->get_w(), incoming->get_h(), 0, 0, incoming->get_w(), incoming->get_h(), fade, TRANSFER_NORMAL, NEAREST_NEIGHBOR); return 0; }
int Overlay::process_buffer(VFrame **frame, int64_t start_position, double frame_rate) { load_configuration(); printf("Overlay::process_buffer mode=%d\n", config.mode); if(!temp) temp = new VFrame(0, -1, frame[0]->get_w(), frame[0]->get_h(), frame[0]->get_color_model(), -1); if(!overlayer) overlayer = new OverlayFrame(get_project_smp() + 1); int step; VFrame *output; if(config.direction == OverlayConfig::BOTTOM_FIRST) { input_layer1 = get_total_buffers() - 1; input_layer2 = -1; step = -1; } else { input_layer1 = 0; input_layer2 = get_total_buffers(); step = 1; } if(config.output_layer == OverlayConfig::TOP) { output_layer = 0; } else { output_layer = get_total_buffers() - 1; } // Direct copy the first layer output = frame[output_layer]; read_frame(output, input_layer1, start_position, frame_rate, get_use_opengl()); if(get_total_buffers() == 1) return 0; current_layer = input_layer1; if(get_use_opengl()) run_opengl(); for(int i = input_layer1 + step; i != input_layer2; i += step) { read_frame(temp, i, start_position, frame_rate, get_use_opengl()); // Call the opengl handler once for each layer if(get_use_opengl()) { current_layer = i; run_opengl(); } else { overlayer->overlay(output, temp, 0, 0, output->get_w(), output->get_h(), 0, 0, output->get_w(), output->get_h(), 1, config.mode, NEAREST_NEIGHBOR); } } return 0; }