static void gth_file_tool_negative_activate (GthFileTool *base) { GtkWidget *window; GtkWidget *viewer_page; GthTask *task; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return; task = gth_image_viewer_task_new (GTH_IMAGE_VIEWER_PAGE (viewer_page), _("Applying changes"), NULL, negative_exec, NULL, NULL, NULL); g_signal_connect (task, "completed", G_CALLBACK (gth_image_viewer_task_set_destination), NULL); gth_browser_exec_task (GTH_BROWSER (window), task, FALSE); }
static void gth_file_tool_equalize_activate (GthFileTool *base) { GtkWidget *window; GtkWidget *viewer_page; EqualizeData *equalize_data; GthTask *task; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return; equalize_data = g_new0 (EqualizeData, 1); task = gth_image_viewer_task_new (GTH_IMAGE_VIEWER_PAGE (viewer_page), _("Equalizing image histogram"), NULL, equalize_exec, NULL, equalize_data, equalize_destroy_data); g_signal_connect (task, "completed", G_CALLBACK (gth_image_viewer_task_set_destination), NULL); gth_browser_exec_task (GTH_BROWSER (window), task, FALSE); }
static void gth_file_tool_negative_activate (GthFileTool *base) { GtkWidget *window; GtkWidget *viewer_page; GtkWidget *viewer; cairo_surface_t *image; NegativeData *negative_data; GthTask *task; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return; viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page)); image = gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (viewer)); if (image == NULL) return; negative_data = g_new0 (NegativeData, 1); negative_data->viewer_page = viewer_page; negative_data->source = cairo_surface_reference (image); task = gth_async_task_new (negative_init, negative_exec, negative_after, negative_data, negative_data_free); gth_browser_exec_task (GTH_BROWSER (window), task, FALSE); g_object_unref (task); }
static void ok_button_clicked_cb (GtkButton *button, GthFileToolSharpen *self) { GtkWidget *window; GtkWidget *viewer_page; SharpenData *sharpen_data; GthTask *task; if (self->priv->apply_event != 0) { g_source_remove (self->priv->apply_event); self->priv->apply_event = 0; } window = gth_file_tool_get_window (GTH_FILE_TOOL (self)); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return; sharpen_data = sharpen_data_new (self); sharpen_data->viewer_page = g_object_ref (viewer_page); sharpen_data->source = cairo_surface_reference (self->priv->source); task = gth_async_task_new (sharpen_before, sharpen_exec, sharpen_after, sharpen_data, sharpen_data_free); gth_browser_exec_task (GTH_BROWSER (gth_file_tool_get_window (GTH_FILE_TOOL (self))), task, FALSE); g_object_unref (task); gth_file_tool_hide_options (GTH_FILE_TOOL (self)); }
GthViewerPage * gth_image_viewer_page_tool_get_page (GthImageViewerPageTool *self) { GtkWidget *window; GthViewerPage *viewer_page; window = gth_file_tool_get_window (GTH_FILE_TOOL (self)); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return NULL; return viewer_page; }
static void gth_file_tool_adjust_contrast_update_sensitivity (GthFileTool *base) { GtkWidget *window; GtkWidget *viewer_page; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) gtk_widget_set_sensitive (GTK_WIDGET (base), FALSE); else gtk_widget_set_sensitive (GTK_WIDGET (base), TRUE); }
static void gth_file_tool_redo_activate (GthFileTool *base) { GtkWidget *window; GtkWidget *viewer_page; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return; gth_image_viewer_page_redo (GTH_IMAGE_VIEWER_PAGE (viewer_page)); }
static void gth_file_tool_redo_update_sensitivity (GthFileTool *base) { GtkWidget *window; GtkWidget *viewer_page; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) gtk_widget_set_sensitive (GTK_WIDGET (base), FALSE); else gtk_widget_set_sensitive (GTK_WIDGET (base), gth_image_history_can_redo (gth_image_viewer_page_get_history (GTH_IMAGE_VIEWER_PAGE (viewer_page)))); }
static void gth_file_tool_adjust_contrast_activate (GthFileTool *base) { GtkWidget *window; GtkWidget *viewer_page; GtkWidget *viewer; cairo_surface_t *image; AdjustContrastData *adjust_contrast_data; GthTask *task; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return; viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page)); image = gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (viewer)); if (image == NULL) return; adjust_contrast_data = g_new0 (AdjustContrastData, 1); adjust_contrast_data->viewer_page = g_object_ref (viewer_page); adjust_contrast_data->source = cairo_surface_reference (image); adjust_contrast_data->lowest = NULL; adjust_contrast_data->highest = NULL; adjust_contrast_data->factor = NULL; task = gth_image_task_new (_("Applying changes"), NULL, adjust_contrast_exec, adjust_contrast_after, adjust_contrast_data, adjust_contrast_data_free); g_signal_connect (task, "completed", G_CALLBACK (image_task_completed_cb), base); gth_browser_exec_task (GTH_BROWSER (window), task, FALSE); }
static void gth_image_viewer_page_tool_activate (GthFileTool *base) { GthImageViewerPageTool *self = (GthImageViewerPageTool *) base; GtkWidget *window; GthViewerPage *viewer_page; /* load the original image */ window = gth_file_tool_get_window (GTH_FILE_TOOL (self)); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return; self->priv->image_task = gth_original_image_task_new (GTH_IMAGE_VIEWER_PAGE (viewer_page)); g_signal_connect (self->priv->image_task, "completed", G_CALLBACK (original_image_task_completed_cb), self); gth_browser_exec_task (GTH_BROWSER (gth_file_tool_get_window (GTH_FILE_TOOL (self))), self->priv->image_task, GTH_TASK_FLAGS_DEFAULT); }
static void gth_file_tool_mirror_activate (GthFileTool *base) { GtkWidget *window; GtkWidget *viewer_page; GtkWidget *viewer; GdkPixbuf *src_pixbuf; GdkPixbuf *dest_pixbuf; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return; viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page)); src_pixbuf = gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (viewer)); if (src_pixbuf == NULL) return; dest_pixbuf = _gdk_pixbuf_transform (src_pixbuf, GTH_TRANSFORM_FLIP_H); gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), dest_pixbuf, TRUE); g_object_unref (dest_pixbuf); }
static void gth_file_tool_rotate_left_activate (GthFileTool *base) { GtkWidget *window; GtkWidget *viewer_page; GtkWidget *viewer; cairo_surface_t *old_image; cairo_surface_t *new_image; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return; viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page)); old_image = gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (viewer)); if (old_image == NULL) return; new_image = _cairo_image_surface_transform (old_image, GTH_TRANSFORM_ROTATE_270); gth_image_viewer_page_set_image (GTH_IMAGE_VIEWER_PAGE (viewer_page), new_image, TRUE); cairo_surface_destroy (new_image); }
static GtkWidget * gth_file_tool_adjust_contrast_get_options (GthFileTool *base) { GthFileToolAdjustContrast *self; GtkWidget *window; GtkWidget *viewer_page; GtkWidget *viewer; cairo_surface_t *source; GtkWidget *options; int width, height; GtkAllocation allocation; GtkWidget *filter_grid; self = (GthFileToolAdjustContrast *) base; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return NULL; _cairo_clear_surface (&self->priv->preview); _cairo_clear_surface (&self->priv->destination); viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page)); source = gth_image_viewer_page_tool_get_source (GTH_IMAGE_VIEWER_PAGE_TOOL (self)); if (source == NULL) return NULL; width = cairo_image_surface_get_width (source); height = cairo_image_surface_get_height (source); gtk_widget_get_allocation (GTK_WIDGET (viewer), &allocation); if (scale_keeping_ratio (&width, &height, PREVIEW_SIZE * allocation.width, PREVIEW_SIZE * allocation.height, FALSE)) self->priv->preview = _cairo_image_surface_scale_fast (source, width, height); else self->priv->preview = cairo_surface_reference (source); self->priv->destination = cairo_surface_reference (self->priv->preview); self->priv->apply_to_original = FALSE; self->priv->closing = FALSE; self->priv->builder = _gtk_builder_new_from_file ("adjust-contrast-options.ui", "file_tools"); options = _gtk_builder_get_widget (self->priv->builder, "options"); gtk_widget_show (options); filter_grid = gth_filter_grid_new (); gth_filter_grid_add_filter (GTH_FILTER_GRID (filter_grid), METHOD_STRETCH_0_5, get_image_task_for_method (METHOD_STRETCH_0_5), _("Stretch"), _("Stretch the histogram trimming the 0.5%")); gth_filter_grid_add_filter (GTH_FILTER_GRID (filter_grid), METHOD_EQUALIZE_SQUARE_ROOT, get_image_task_for_method (METHOD_EQUALIZE_SQUARE_ROOT), _("Equalize"), _("Equalize the histogram using the square root function")); gth_filter_grid_add_filter (GTH_FILTER_GRID (filter_grid), METHOD_EQUALIZE_LINEAR, get_image_task_for_method (METHOD_EQUALIZE_LINEAR), _("Uniform"), _("Equalize the histogram using the linear function")); g_signal_connect (filter_grid, "activated", G_CALLBACK (filter_grid_activated_cb), self); gtk_widget_show (filter_grid); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("filter_grid_box")), filter_grid, TRUE, FALSE, 0); self->priv->preview_tool = gth_preview_tool_new (); gth_preview_tool_set_image (GTH_PREVIEW_TOOL (self->priv->preview_tool), self->priv->preview); gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), self->priv->preview_tool); gth_filter_grid_activate (GTH_FILTER_GRID (filter_grid), METHOD_STRETCH_0_5); gth_filter_grid_generate_previews (GTH_FILTER_GRID (filter_grid), source); return options; }
static GtkWidget * gth_file_tool_grayscale_get_options (GthFileTool *base) { GthFileToolGrayscale *self; GtkWidget *window; GtkWidget *viewer_page; GtkWidget *viewer; cairo_surface_t *source; GtkWidget *options; int width, height; GtkAllocation allocation; self = (GthFileToolGrayscale *) base; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return NULL; cairo_surface_destroy (self->priv->destination); cairo_surface_destroy (self->priv->preview); viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page)); source = gth_image_viewer_page_tool_get_source (GTH_IMAGE_VIEWER_PAGE_TOOL (self)); if (source == NULL) return NULL; width = cairo_image_surface_get_width (source); height = cairo_image_surface_get_height (source); gtk_widget_get_allocation (GTK_WIDGET (viewer), &allocation); if (scale_keeping_ratio (&width, &height, PREVIEW_SIZE * allocation.width, PREVIEW_SIZE * allocation.height, FALSE)) self->priv->preview = _cairo_image_surface_scale_bilinear (source, width, height); else self->priv->preview = cairo_surface_reference (source); self->priv->destination = cairo_surface_reference (self->priv->preview); self->priv->apply_to_original = FALSE; self->priv->closing = FALSE; self->priv->builder = _gtk_builder_new_from_file ("grayscale-options.ui", "file_tools"); options = _gtk_builder_get_widget (self->priv->builder, "options"); gtk_widget_show (options); g_signal_connect (GET_WIDGET ("ok_button"), "clicked", G_CALLBACK (ok_button_clicked_cb), self); g_signal_connect_swapped (GET_WIDGET ("cancel_button"), "clicked", G_CALLBACK (gth_file_tool_cancel), self); g_signal_connect (GET_WIDGET ("brightness_radiobutton"), "clicked", G_CALLBACK (method_changed_cb), self); g_signal_connect (GET_WIDGET ("saturation_radiobutton"), "clicked", G_CALLBACK (method_changed_cb), self); g_signal_connect (GET_WIDGET ("average_radiobutton"), "clicked", G_CALLBACK (method_changed_cb), self); g_signal_connect (GET_WIDGET ("preview_checkbutton"), "toggled", G_CALLBACK (preview_checkbutton_toggled_cb), self); self->priv->preview_tool = gth_preview_tool_new (); gth_preview_tool_set_image (GTH_PREVIEW_TOOL (self->priv->preview_tool), self->priv->preview); gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), self->priv->preview_tool); apply_changes (self); return options; }
gpointer file_tools__gth_browser_file_list_key_press_cb (GthBrowser *browser, GdkEventKey *event) { gpointer result = NULL; GtkWidget *sidebar; GtkWidget *toolbox; GthFileTool *tool = NULL; guint modifiers; GtkWidget *page; sidebar = gth_browser_get_viewer_sidebar (browser); toolbox = gth_sidebar_get_toolbox (GTH_SIDEBAR (sidebar)); if (gth_toolbox_tool_is_active (GTH_TOOLBOX (toolbox))) return NULL; modifiers = gtk_accelerator_get_default_mod_mask (); if (((event->state & modifiers) != 0) && ((event->state & modifiers) != GDK_SHIFT_MASK)) return NULL; page = gth_browser_get_viewer_page (browser); if (! GTH_IS_IMAGE_VIEWER_PAGE (page)) return NULL; if (gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_VIEWER && ! gtk_widget_has_focus (gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (page)))) { return NULL; } switch (event->keyval) { case GDK_KEY_h: tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_ADJUST_CONTRAST); break; case GDK_KEY_l: tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_FLIP); break; case GDK_KEY_m: tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_MIRROR); break; case GDK_KEY_r: tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_ROTATE_RIGHT); break; case GDK_KEY_R: tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_ROTATE_LEFT); break; case GDK_KEY_C: gth_browser_show_viewer_tools (browser); tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_CROP); break; case GDK_KEY_S: gth_browser_show_viewer_tools (browser); tool = (GthFileTool *) gth_toolbox_get_tool (GTH_TOOLBOX (toolbox), GTH_TYPE_FILE_TOOL_RESIZE); break; } if (tool != NULL) { if (gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_BROWSER) gth_window_set_current_page (GTH_WINDOW (browser), GTH_BROWSER_PAGE_VIEWER); gth_file_tool_activate (tool); result = GINT_TO_POINTER (1); } return result; }
static GtkWidget * gth_file_tool_sharpen_get_options (GthFileTool *base) { GthFileToolSharpen *self; GtkWidget *window; GtkWidget *viewer_page; GtkWidget *viewer; GtkWidget *options; GtkWidget *image_navigator; self = (GthFileToolSharpen *) base; window = gth_file_tool_get_window (base); viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window)); if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page)) return NULL; cairo_surface_destroy (self->priv->source); cairo_surface_destroy (self->priv->destination); viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page)); self->priv->source = cairo_surface_reference (gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (viewer))); if (self->priv->source == NULL) return NULL; self->priv->destination = NULL; self->priv->first_allocation = TRUE; self->priv->builder = _gtk_builder_new_from_file ("sharpen-options.ui", "file_tools"); options = _gtk_builder_get_widget (self->priv->builder, "options"); gtk_widget_show (options); self->priv->preview = gth_image_viewer_new (); gth_image_viewer_set_reset_scrollbars (GTH_IMAGE_VIEWER (self->priv->preview), FALSE); gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (self->priv->preview), GTH_FIT_NONE); gth_image_viewer_set_zoom_change (GTH_IMAGE_VIEWER (self->priv->preview), GTH_ZOOM_CHANGE_KEEP_PREV); gth_image_viewer_set_zoom (GTH_IMAGE_VIEWER (self->priv->preview), 1.0); gth_image_viewer_enable_zoom_with_keys (GTH_IMAGE_VIEWER (self->priv->preview), FALSE); gth_image_viewer_set_surface (GTH_IMAGE_VIEWER (self->priv->preview), self->priv->source, -1, -1); image_navigator = gth_image_navigator_new (GTH_IMAGE_VIEWER (self->priv->preview)); gtk_widget_show_all (image_navigator); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("preview_hbox")), image_navigator, TRUE, TRUE, 0); self->priv->amount_adj = gth_color_scale_label_new (GET_WIDGET ("amount_hbox"), GTK_LABEL (GET_WIDGET ("amount_label")), GTH_COLOR_SCALE_DEFAULT, DEFAULT_AMOUNT, 0.0, 500.0, 1.0, 1.0, "%.0f"); self->priv->radius_adj = gth_color_scale_label_new (GET_WIDGET ("radius_hbox"), GTK_LABEL (GET_WIDGET ("radius_label")), GTH_COLOR_SCALE_DEFAULT, DEFAULT_RADIUS, 0.0, 10.0, 1.0, 1.0, "%.0f"); self->priv->threshold_adj = gth_color_scale_label_new (GET_WIDGET ("threshold_hbox"), GTK_LABEL (GET_WIDGET ("threshold_label")), GTH_COLOR_SCALE_DEFAULT, DEFAULT_THRESHOLD, 0.0, 255.0, 1.0, 1.0, "%.0f"); g_signal_connect (GET_WIDGET ("ok_button"), "clicked", G_CALLBACK (ok_button_clicked_cb), self); g_signal_connect_swapped (GET_WIDGET ("cancel_button"), "clicked", G_CALLBACK (gth_file_tool_cancel), self); g_signal_connect (GET_WIDGET ("reset_button"), "clicked", G_CALLBACK (reset_button_clicked_cb), self); g_signal_connect (G_OBJECT (self->priv->radius_adj), "value-changed", G_CALLBACK (value_changed_cb), self); g_signal_connect (G_OBJECT (self->priv->amount_adj), "value-changed", G_CALLBACK (value_changed_cb), self); g_signal_connect (G_OBJECT (self->priv->threshold_adj), "value-changed", G_CALLBACK (value_changed_cb), self); g_signal_connect (GTH_IMAGE_VIEWER (self->priv->preview)->hadj, "value-changed", G_CALLBACK (value_changed_cb), self); g_signal_connect (GTH_IMAGE_VIEWER (self->priv->preview)->vadj, "value-changed", G_CALLBACK (value_changed_cb), self); g_signal_connect (GET_WIDGET ("preview_checkbutton"), "clicked", G_CALLBACK (preview_checkbutton_toggled_cb), self); g_signal_connect_after (self->priv->preview, "size-allocate", G_CALLBACK (preview_size_allocate_cb), self); return options; }