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 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 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 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 Color3WayMain::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { need_reconfigure |= load_configuration(); if(!engine) engine = new Color3WayEngine(this, // 1); PluginClient::smp + 1); //printf("Color3WayMain::process_realtime 1 %d\n", need_reconfigure); if(need_reconfigure) { reconfigure(); need_reconfigure = 0; } 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); 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; }
static void app_startup_handler(GApplication *app, gpointer data) { gmpv_handle *ctx = data; const gchar *vid_area_style = ".gmpv-vid-area{background-color: black}"; GSettingsBackend *config_backend; GtkCssProvider *style_provider; gboolean css_loaded; gboolean use_opengl; gboolean config_migrated; gboolean mpvinput_enable; gboolean csd_enable; gboolean dark_theme_enable; gchar *config_file; gchar *mpvinput; setlocale(LC_NUMERIC, "C"); g_set_application_name(_("GNOME MPV")); gtk_window_set_default_icon_name(ICON_NAME); bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); config_file = get_config_file_path(); config_backend = g_keyfile_settings_backend_new ( config_file, CONFIG_ROOT_PATH, CONFIG_ROOT_GROUP ); use_opengl = get_use_opengl(); ctx->mpv_ctx = mpv_create(); ctx->files = NULL; ctx->opengl_ctx = NULL; ctx->opengl_ready = FALSE; ctx->paused = TRUE; ctx->loaded = FALSE; ctx->new_file = TRUE; ctx->sub_visible = TRUE; ctx->init_load = TRUE; ctx->playlist_move_dest = -1; ctx->log_level_list = NULL; ctx->keybind_list = NULL; ctx->config = g_settings_new_with_backend(APP_ID, config_backend); ctx->app = GTK_APPLICATION(app); ctx->gui = MAIN_WINDOW(main_window_new(ctx->app, use_opengl)); ctx->fs_control = NULL; ctx->playlist_store = PLAYLIST_WIDGET(ctx->gui->playlist)->list_store; config_migrated = migrate_config(ctx); style_provider = gtk_css_provider_new(); css_loaded = gtk_css_provider_load_from_data (style_provider, vid_area_style, -1, NULL); if(!css_loaded) { g_warning ("Failed to apply background color css"); } gtk_style_context_add_provider_for_screen ( gtk_window_get_screen(GTK_WINDOW(ctx->gui)), GTK_STYLE_PROVIDER(style_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION ); g_object_unref(style_provider); csd_enable = g_settings_get_boolean (ctx->config, "csd-enable"); dark_theme_enable = g_settings_get_boolean (ctx->config, "dark-theme-enable"); mpvinput_enable = g_settings_get_boolean (ctx->config, "mpv-input-config-enable"); mpvinput = g_settings_get_string (ctx->config, "mpv-input-config-file"); if(csd_enable) { gtk_application_set_app_menu (ctx->app, G_MENU_MODEL(build_app_menu())); main_window_enable_csd(ctx->gui); } else { gtk_application_set_app_menu (ctx->app, NULL); gtk_application_set_menubar (ctx->app, G_MENU_MODEL(build_full_menu())); } gtk_widget_show_all(GTK_WIDGET(ctx->gui)); if(csd_enable) { control_box_set_fullscreen_btn_visible (CONTROL_BOX(ctx->gui->control_box), FALSE); } control_box_set_chapter_enabled (CONTROL_BOX(ctx->gui->control_box), FALSE); if(!main_window_get_use_opengl(ctx->gui)) { ctx->vid_area_wid = get_xid(ctx->gui->vid_area); } g_assert( main_window_get_use_opengl(ctx->gui) || ctx->vid_area_wid != -1 ); main_window_load_state(ctx->gui); setup_accelerators(ctx); setup_dnd_targets(ctx); actionctl_map_actions(ctx); connect_signals(ctx); load_keybind(ctx, mpvinput_enable?mpvinput:NULL, FALSE); mpris_init(ctx); media_keys_init(ctx); g_object_set( ctx->gui->settings, "gtk-application-prefer-dark-theme", dark_theme_enable, NULL ); g_timeout_add( SEEK_BAR_UPDATE_INTERVAL, (GSourceFunc)update_seek_bar, ctx ); if(config_migrated) { GtkWidget *dialog = gtk_message_dialog_new ( GTK_WINDOW(ctx->gui), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, _("Your configuration file has been " "moved to the new location at %s."), config_file ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } g_free(config_file); g_free(mpvinput); }
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 PhotoScaleMain::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { load_configuration(); if(config.use_file) { frame->get_params()->update("AUTOSCALE", 1); frame->get_params()->update("AUTOSCALE_W", config.width); frame->get_params()->update("AUTOSCALE_H", config.height); read_frame(frame, 0, start_position, frame_rate, get_use_opengl()); return 0; } else { frame->get_params()->update("AUTOSCALE", 0); } read_frame(frame, 0, start_position, frame_rate, 0); if(!engine) engine = new PhotoScaleEngine(this, PluginClient::get_project_smp() + 1); engine->process_packages(); // printf("PhotoScaleMain::process_buffer %d %d %d %d %d\n", // __LINE__, // engine->top_border, // engine->bottom_border, // engine->left_border, // engine->right_border); int in_width = engine->right_border - engine->left_border; int in_height = engine->bottom_border - engine->top_border; if(in_width > 0 && in_height > 0 && (engine->top_border > 0 || engine->left_border > 0 || engine->bottom_border < frame->get_h() || engine->right_border < frame->get_w())) { VFrame *temp_frame = new_temp(frame->get_w(), frame->get_h(), frame->get_color_model()); temp_frame->copy_from(frame); if(!overlayer) { overlayer = new OverlayFrame(PluginClient::get_project_smp() + 1); } float scale1 = (float)config.width / in_width; float scale2 = (float)config.height / in_height; float out_x1 = 0; float out_y1 = 0; float out_x2 = 0; float out_y2 = 0; // printf("PhotoScaleMain::process_buffer %d %d %d %d %d\n", // __LINE__, // engine->left_border, // engine->top_border, // engine->right_border, // engine->bottom_border); // printf("PhotoScaleMain::process_buffer %d %f %f\n", __LINE__, scale1, scale2); if(scale1 < scale2) { out_x1 = (float)frame->get_w() / 2 - config.width / 2; out_y1 = (float)frame->get_h() / 2 - in_height * scale1 / 2; out_x2 = (float)frame->get_w() / 2 + config.width / 2; out_y2 = (float)frame->get_h() / 2 + in_height * scale1 / 2; } else { out_x1 = (float)frame->get_w() / 2 - in_width * scale2 / 2; out_y1 = (float)frame->get_h() / 2 - config.height / 2; out_x2 = (float)frame->get_w() / 2 + in_width * scale2 / 2; out_y2 = (float)frame->get_h() / 2 + config.height / 2; } // printf("PhotoScaleMain::process_buffer %d %d %d %d %d\n", // __LINE__, // (int)out_x1, // (int)out_y1, // (int)out_x2, // (int)out_y2); frame->clear_frame(); overlayer->overlay(frame, temp_frame, (float)engine->left_border, (float)engine->top_border, (float)engine->right_border, (float)engine->bottom_border, (float)out_x1, (float)out_y1, (float)out_x2, (float)out_y2, 1, TRANSFER_REPLACE, get_interpolation_type()); } 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; }
int SwapFrames::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { load_configuration(); int64_t new_position = start_position; if(config.on) { if(config.swap_even) { if(new_position % 2) new_position--; else new_position++; } else { if(new_position % 2) new_position++; else new_position--; } } // Recall a frame //printf("SwapFrames::process_buffer %d new_position=%lld\n", __LINE__, new_position); if(buffer && buffer_position == new_position) { //printf("SwapFrames::process_buffer %d\n", __LINE__); frame->copy_from(buffer); } else // Skipped a frame if(new_position > prev_frame + 1) { //printf("SwapFrames::process_buffer %d\n", __LINE__); if(!buffer) buffer = new VFrame(0, -1, frame->get_w(), frame->get_h(), frame->get_color_model(), -1); buffer_position = new_position - 1; read_frame(buffer, 0, buffer_position, frame_rate, 0); read_frame(frame, 0, new_position, frame_rate, get_use_opengl()); prev_frame = new_position; } // Read new frame else { //printf("SwapFrames::process_buffer %d\n", __LINE__); read_frame(frame, 0, new_position, frame_rate, get_use_opengl()); prev_frame = new_position; } return 0; }