static void
gth_file_tool_adjust_contrast_destroy_options (GthFileTool *base)
{
	GthFileToolAdjustContrast *self;
	GtkWidget                 *window;
	GtkWidget                 *viewer_page;

	self = (GthFileToolAdjustContrast *) base;

	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));
	gth_image_viewer_page_reset_viewer_tool (GTH_IMAGE_VIEWER_PAGE (viewer_page));
	gth_viewer_page_update_sensitivity (GTH_VIEWER_PAGE (viewer_page));

	_g_clear_object (&self->priv->builder);

	_cairo_clear_surface (&self->priv->preview);
	_cairo_clear_surface (&self->priv->destination);
	self->priv->method = GTH_FILTER_GRID_NO_FILTER;
	self->priv->last_applied_method = GTH_FILTER_GRID_NO_FILTER;
}
Ejemplo n.º 2
0
void
gth_image_info_set_image  (GthImageInfo    *image_info,
			   cairo_surface_t *image)
{
	int thumb_w;
	int thumb_h;

	g_return_if_fail (image != NULL);

	_cairo_clear_surface (&image_info->image);
	_cairo_clear_surface (&image_info->thumbnail_original);
	_cairo_clear_surface (&image_info->thumbnail);
	_cairo_clear_surface (&image_info->thumbnail_active);

	image_info->image = cairo_surface_reference (image);
	thumb_w = image_info->original_width = image_info->image_width = cairo_image_surface_get_width (image);
	thumb_h = image_info->original_height = image_info->image_height = cairo_image_surface_get_height (image);
	if (scale_keeping_ratio (&thumb_w, &thumb_h, THUMBNAIL_SIZE, THUMBNAIL_SIZE, FALSE))
		image_info->thumbnail_original = _cairo_image_surface_scale (image,
								 	     thumb_w,
								 	     thumb_h,
								 	     SCALE_FILTER_BEST,
								 	     NULL);
	else
		image_info->thumbnail_original = cairo_surface_reference (image_info->image);

	image_info->thumbnail = cairo_surface_reference (image_info->thumbnail_original);
	image_info->thumbnail_active = _cairo_image_surface_color_shift (image_info->thumbnail, 30);
}
Ejemplo n.º 3
0
static void
gth_file_tool_resize_destroy_options (GthFileTool *base)
{
	GthFileToolResize *self;
	GtkWidget         *window;
	GtkWidget         *viewer_page;
	GtkWidget         *viewer;
	GSettings         *viewer_settings;

	self = (GthFileToolResize *) base;

	if (self->priv->update_size_id != 0) {
		g_source_remove (self->priv->update_size_id);
		self->priv->update_size_id = 0;
	}

	if (self->priv->builder != NULL) {
		int unit;

		/* save the dialog options */

		unit = gtk_combo_box_get_active (GTK_COMBO_BOX (GET_WIDGET ("unit_combobox")));
		g_settings_set_enum (self->priv->settings, PREF_RESIZE_UNIT, unit);
		g_settings_set_double (self->priv->settings, PREF_RESIZE_WIDTH, (float) gtk_spin_button_get_value (GTK_SPIN_BUTTON (GET_WIDGET ("resize_width_spinbutton"))));
		g_settings_set_double (self->priv->settings, PREF_RESIZE_HEIGHT, (float) gtk_spin_button_get_value (GTK_SPIN_BUTTON (GET_WIDGET ("resize_height_spinbutton"))));
		g_settings_set_int (self->priv->settings, PREF_RESIZE_ASPECT_RATIO_WIDTH, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("ratio_w_spinbutton"))));
		g_settings_set_int (self->priv->settings, PREF_RESIZE_ASPECT_RATIO_HEIGHT, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("ratio_h_spinbutton"))));
		g_settings_set_enum (self->priv->settings, PREF_RESIZE_ASPECT_RATIO, gtk_combo_box_get_active (GTK_COMBO_BOX (self->priv->ratio_combobox)));
		g_settings_set_boolean (self->priv->settings, PREF_RESIZE_ASPECT_RATIO_INVERT, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("invert_ratio_checkbutton"))));
		g_settings_set_boolean (self->priv->settings, PREF_RESIZE_HIGH_QUALITY, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("high_quality_checkbutton"))));

		/* destroy the options data */

		_cairo_clear_surface (&self->priv->new_image);
		_cairo_clear_surface (&self->priv->preview);
		_g_clear_object (&self->priv->builder);
	}

	window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
	gth_image_viewer_page_reset_viewer_tool (GTH_IMAGE_VIEWER_PAGE (viewer_page));

	/* restore the zoom quality */

	viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
	viewer_settings = g_settings_new (GTHUMB_IMAGE_VIEWER_SCHEMA);
	gth_image_viewer_set_zoom_quality (GTH_IMAGE_VIEWER (viewer),
					   g_settings_get_enum (viewer_settings, PREF_IMAGE_VIEWER_ZOOM_QUALITY));

	g_object_unref (viewer_settings);
}
static void
gth_file_tool_adjust_contrast_finalize (GObject *object)
{
	GthFileToolAdjustContrast *self;

	g_return_if_fail (object != NULL);
	g_return_if_fail (GTH_IS_FILE_TOOL_ADJUST_CONTRAST (object));

	self = (GthFileToolAdjustContrast *) object;

	_g_clear_object (&self->priv->builder);
	_cairo_clear_surface (&self->priv->preview);
	_cairo_clear_surface (&self->priv->destination);

	G_OBJECT_CLASS (gth_file_tool_adjust_contrast_parent_class)->finalize (object);
}
Ejemplo n.º 5
0
static void
resize_task_completed_cb (GthTask  *task,
			  GError   *error,
			  gpointer  user_data)
{
	GthFileToolResize *self = user_data;
	GtkWidget         *window;
	GtkWidget         *viewer_page;

	self->priv->resize_task = NULL;

	if (self->priv->closing) {
		g_object_unref (task);
		gth_image_viewer_page_tool_reset_image (GTH_IMAGE_VIEWER_PAGE_TOOL (self));
		return;
	}

	if (error != NULL) {
		if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
			update_image_size (self);
		g_object_unref (task);
		return;
	}

	_cairo_clear_surface (&self->priv->new_image);
	self->priv->new_image = gth_image_task_get_destination_surface (GTH_IMAGE_TASK (task));
	if (self->priv->new_image == NULL) {
		g_object_unref (task);
		return;
	}

	window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
	gth_image_viewer_page_set_image (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->new_image, FALSE);

	if (self->priv->apply_to_original) {
		gth_image_history_add_surface (gth_image_viewer_page_get_history (GTH_IMAGE_VIEWER_PAGE (viewer_page)),
					       self->priv->new_image,
					       -1,
					       TRUE);
		gth_viewer_page_focus (GTH_VIEWER_PAGE (viewer_page));
		gth_file_tool_hide_options (GTH_FILE_TOOL (self));
	}
	else {
		update_dimensione_info_label (self,
					      "new_dimensions_label",
					      self->priv->new_width,
					      self->priv->new_height,
					      TRUE);
		update_dimensione_info_label (self,
					      "scale_factor_label",
					      (double) self->priv->new_width / self->priv->original_width,
					      (double) self->priv->new_height / self->priv->original_height,
					      FALSE);
	}

	g_object_unref (task);
}
Ejemplo n.º 6
0
void
gth_image_info_rotate (GthImageInfo *image_info,
		       int           angle)
{
	angle = angle % 360;
	image_info->rotation = GTH_TRANSFORM_NONE;
	switch (angle) {
	case 90:
		image_info->rotation = GTH_TRANSFORM_ROTATE_90;
		break;
	case 180:
		image_info->rotation = GTH_TRANSFORM_ROTATE_180;
		break;
	case 270:
		image_info->rotation = GTH_TRANSFORM_ROTATE_270;
		break;
	default:
		break;
	}

	_cairo_clear_surface (&image_info->thumbnail);
	if (image_info->thumbnail_original != NULL)
		image_info->thumbnail = _cairo_image_surface_transform (image_info->thumbnail_original, image_info->rotation);

	_cairo_clear_surface (&image_info->thumbnail_active);
	if (image_info->thumbnail != NULL)
		image_info->thumbnail_active = _cairo_image_surface_color_shift (image_info->thumbnail, 30);

	if ((angle == 90) || (angle == 270)) {
		image_info->image_width = image_info->original_height;
		image_info->image_height = image_info->original_width;
	}
	else {
		image_info->image_width = image_info->original_width;
		image_info->image_height = image_info->original_height;
	}
}
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;
}