[gthumb] started work on a custom high quality scale function



commit 804865ff4c958fce42e3a6b467ac175a6950cfb5
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Aug 16 10:59:42 2012 +0200

    started work on a custom high quality scale function
    
    the cairo scale function quality is poor when downscaling by a factory
    greater than 2.

 extensions/file_tools/Makefile.am            |    2 +
 extensions/file_tools/cairo-scale.c          |   45 ++++++++++++++++++++++++++
 extensions/file_tools/cairo-scale.h          |   37 +++++++++++++++++++++
 extensions/file_tools/gth-file-tool-resize.c |   31 ++++++++++++++---
 4 files changed, 109 insertions(+), 6 deletions(-)
---
diff --git a/extensions/file_tools/Makefile.am b/extensions/file_tools/Makefile.am
index feab2a1..0c60238 100644
--- a/extensions/file_tools/Makefile.am
+++ b/extensions/file_tools/Makefile.am
@@ -10,6 +10,7 @@ ENUM_TYPES =		\
 HEADER_FILES = 				\
 	cairo-blur.h			\
 	cairo-rotate.h			\
+	cairo-scale.h			\
 	gth-file-tool-adjust-colors.h	\
 	gth-file-tool-crop.h		\
 	gth-file-tool-desaturate.h	\
@@ -58,6 +59,7 @@ libfile_tools_la_SOURCES = 		\
 	callbacks.h			\
 	cairo-blur.c			\
 	cairo-rotate.c			\
+	cairo-scale.c			\
 	gth-file-tool-adjust-colors.c	\
 	gth-file-tool-crop.c		\
 	gth-file-tool-desaturate.c	\
diff --git a/extensions/file_tools/cairo-scale.c b/extensions/file_tools/cairo-scale.c
new file mode 100644
index 0000000..db58004
--- /dev/null
+++ b/extensions/file_tools/cairo-scale.c
@@ -0,0 +1,45 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2012 The Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <math.h>
+#include <gthumb.h>
+#include "cairo-scale.h"
+
+
+cairo_surface_t *
+_cairo_image_surface_scale (cairo_surface_t *image,
+			    int              scaled_width,
+			    int              scaled_height,
+			    gboolean         high_quality)
+{
+	GdkPixbuf       *p;
+	GdkPixbuf       *scaled_p;
+	cairo_surface_t *scaled;
+
+	p = _gdk_pixbuf_new_from_cairo_surface (image);
+	scaled_p = _gdk_pixbuf_scale_simple_safe (p, scaled_width, scaled_height, high_quality ? GDK_INTERP_BILINEAR : GDK_INTERP_NEAREST);
+	scaled = _cairo_image_surface_create_from_pixbuf (scaled_p);
+
+	g_object_unref (scaled_p);
+	g_object_unref (p);
+
+	return scaled;
+}
diff --git a/extensions/file_tools/cairo-scale.h b/extensions/file_tools/cairo-scale.h
new file mode 100644
index 0000000..3e6563c
--- /dev/null
+++ b/extensions/file_tools/cairo-scale.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2012 The Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CAIRO_ROTATE_H
+#define CAIRO_ROTATE_H
+
+#include <glib.h>
+#include <gdk/gdk.h>
+
+G_BEGIN_DECLS
+
+cairo_surface_t *  _cairo_image_surface_scale  (cairo_surface_t *image,
+						int              width,
+						int              height,
+						gboolean         high_quality);
+
+G_END_DECLS
+
+#endif /* CAIRO_ROTATE_H */
diff --git a/extensions/file_tools/gth-file-tool-resize.c b/extensions/file_tools/gth-file-tool-resize.c
index 2c5ecd4..332ae86 100644
--- a/extensions/file_tools/gth-file-tool-resize.c
+++ b/extensions/file_tools/gth-file-tool-resize.c
@@ -23,6 +23,8 @@
 #include <math.h>
 #include <gthumb.h>
 #include <extensions/image_viewer/gth-image-viewer-page.h>
+#include <extensions/image_viewer/preferences.h>
+#include "cairo-scale.h"
 #include "gth-file-tool-resize.h"
 #include "preferences.h"
 
@@ -50,7 +52,7 @@ struct _GthFileToolResizePrivate {
 	double           aspect_ratio;
 	int              new_width;
 	int              new_height;
-	cairo_filter_t   filter;
+	gboolean         high_quality;
 	GthUnit          unit;
 };
 
@@ -113,10 +115,16 @@ update_pixbuf_size (GthFileToolResize *self)
 	GtkWidget *viewer_page;
 
 	cairo_surface_destroy (self->priv->new_image);
-	self->priv->new_image = _cairo_image_surface_scale_to (self->priv->original_image,
+
+	/*self->priv->new_image = _cairo_image_surface_scale_to (self->priv->original_image,
 							       self->priv->new_width,
 							       self->priv->new_height,
-							       self->priv->filter);
+							       self->priv->high_quality ? CAIRO_FILTER_GAUSSIAN : CAIRO_FILTER_NEAREST);*/
+
+	self->priv->new_image = _cairo_image_surface_scale (self->priv->original_image,
+							    self->priv->new_width,
+							    self->priv->new_height,
+							    self->priv->high_quality);
 	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);
@@ -184,7 +192,7 @@ static void
 high_quality_checkbutton_toggled_cb (GtkToggleButton   *button,
 				     GthFileToolResize *self)
 {
-	self->priv->filter = gtk_toggle_button_get_active (button) ? CAIRO_FILTER_GAUSSIAN : CAIRO_FILTER_NEAREST;
+	self->priv->high_quality = gtk_toggle_button_get_active (button);
 	update_pixbuf_size (self);
 }
 
@@ -450,7 +458,7 @@ gth_file_tool_resize_get_options (GthFileTool *base)
 	self->priv->new_image = NULL;
 	self->priv->new_width = self->priv->original_width;
 	self->priv->new_height = self->priv->original_height;
-	self->priv->filter = g_settings_get_boolean (self->priv->settings, PREF_RESIZE_HIGH_QUALITY) ? CAIRO_FILTER_GAUSSIAN : CAIRO_FILTER_NEAREST;
+	self->priv->high_quality = g_settings_get_boolean (self->priv->settings, PREF_RESIZE_HIGH_QUALITY);
 	self->priv->unit = g_settings_get_enum (self->priv->settings, PREF_RESIZE_UNIT);
 	self->priv->builder = _gtk_builder_new_from_file ("resize-options.ui", "file_tools");
 
@@ -505,7 +513,7 @@ gth_file_tool_resize_get_options (GthFileTool *base)
 	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("ratio_combobox_box")), self->priv->ratio_combobox, TRUE, TRUE, 0);
 
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("high_quality_checkbutton")),
-				      self->priv->filter != CAIRO_FILTER_NEAREST);
+				      self->priv->high_quality);
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("invert_ratio_checkbutton")),
 				      g_settings_get_boolean (self->priv->settings, PREF_RESIZE_ASPECT_RATIO_INVERT));
 
@@ -566,6 +574,8 @@ gth_file_tool_resize_get_options (GthFileTool *base)
 	gtk_combo_box_set_active (GTK_COMBO_BOX (self->priv->ratio_combobox),
 				  g_settings_get_enum (self->priv->settings, PREF_RESIZE_ASPECT_RATIO));
 
+	gth_image_viewer_set_zoom_quality (GTH_IMAGE_VIEWER (viewer), GTH_ZOOM_QUALITY_LOW);
+
 	return options;
 }
 
@@ -577,6 +587,7 @@ gth_file_tool_resize_destroy_options (GthFileTool *base)
 	GtkWidget         *window;
 	GtkWidget         *viewer_page;
 	GtkWidget         *viewer;
+	GSettings         *viewer_settings;
 
 	self = (GthFileToolResize *) base;
 
@@ -609,6 +620,14 @@ gth_file_tool_resize_destroy_options (GthFileTool *base)
 	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
 	viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
 	gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), NULL);
+
+	/* restore the zoom quality */
+
+	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);
 }
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]