[gthumb] rotate tool: option to select the background color



commit 73b9e32ddb41348cde262b130af68049ee2ca8fb
Author: Stefano Pettini <spettini users sourceforge net>
Date:   Sun May 1 00:02:35 2011 +0100

    rotate tool: option to select the background color

 extensions/file_tools/data/ui/rotate-options.ui |   83 ++++++++++++++++++++++-
 extensions/file_tools/gdk-pixbuf-rotate.c       |   33 +++++-----
 extensions/file_tools/gdk-pixbuf-rotate.h       |    6 ++-
 extensions/file_tools/gth-file-tool-rotate.c    |   67 ++++++++++++++++++-
 4 files changed, 168 insertions(+), 21 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/rotate-options.ui b/extensions/file_tools/data/ui/rotate-options.ui
index bf1ffde..62f11b0 100644
--- a/extensions/file_tools/data/ui/rotate-options.ui
+++ b/extensions/file_tools/data/ui/rotate-options.ui
@@ -118,6 +118,85 @@
               </packing>
             </child>
             <child>
+              <object class="GtkFrame" id="background_frame">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment1">
+                    <property name="visible">True</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkVBox" id="vbox3">
+                        <property name="visible">True</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkHBox" id="hbox1">
+                            <property name="visible">True</property>
+                            <property name="spacing">6</property>
+                            <child>
+                              <object class="GtkRadioButton" id="background_color">
+                                <property name="label">gtk-select-color</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_stock">True</property>
+                                <property name="active">True</property>
+                                <property name="draw_indicator">True</property>
+                              </object>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkColorButton" id="background_color_button">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="title" translatable="yes">Pick a background color</property>
+                                <property name="color">#000000000000</property>
+                              </object>
+                              <packing>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkRadioButton" id="background_transparent">
+                            <property name="label" translatable="yes">Transparent</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="draw_indicator">True</property>
+                            <property name="group">background_color</property>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Background color</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkFrame" id="align_frame">
                 <property name="visible">True</property>
                 <property name="label_xalign">0</property>
@@ -193,7 +272,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">1</property>
+                <property name="position">2</property>
               </packing>
             </child>
             <child>
@@ -339,7 +418,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">2</property>
+                <property name="position">3</property>
               </packing>
             </child>
           </object>
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.c b/extensions/file_tools/gdk-pixbuf-rotate.c
index ebf6207..38a2984 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.c
+++ b/extensions/file_tools/gdk-pixbuf-rotate.c
@@ -36,17 +36,13 @@
 				r = p_src2[RED_PIX]; \
 				g = p_src2[GREEN_PIX]; \
 				b = p_src2[BLUE_PIX]; \
-				\
-				if (n_channels == 4) \
-					a = p_src2[ALPHA_PIX]; \
-				else \
-					a = A0; \
+				a = (n_channels == 4) ? p_src2[ALPHA_PIX] : a0; \
 			} \
 			else { \
-				r = R0; \
-				g = G0; \
-				b = B0; \
-				a = A0; \
+				r = r0; \
+				g = g0; \
+				b = b0; \
+				a = a0; \
 			}
 
 
@@ -162,13 +158,12 @@ _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
 static GdkPixbuf*
 rotate (GdkPixbuf *src_pixbuf,
 	double     angle,
-	gboolean   high_quality)
+	gboolean   high_quality,
+	guchar     r0,
+	guchar     g0,
+	guchar     b0,
+	guchar     a0)
 {
-	const guchar R0 = 0;
-	const guchar G0 = 0;
-	const guchar B0 = 0;
-	const guchar A0 = 0;
-
 	GdkPixbuf *new_pixbuf;
 
 	double     angle_rad;
@@ -319,7 +314,11 @@ _gdk_pixbuf_rotate_get_align_angle (gboolean vertical,
 GdkPixbuf*
 _gdk_pixbuf_rotate (GdkPixbuf *src_pixbuf,
 		    double     angle,
-		    gboolean   high_quality)
+		    gboolean   high_quality,
+		    guchar     r0,
+		    guchar     g0,
+		    guchar     b0,
+		    guchar     a0)
 {
 	GdkPixbuf *new_pixbuf;
 
@@ -334,7 +333,7 @@ _gdk_pixbuf_rotate (GdkPixbuf *src_pixbuf,
 		new_pixbuf = gdk_pixbuf_rotate_simple (src_pixbuf, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
 	}
 	else {
-		new_pixbuf = rotate (src_pixbuf, -angle, high_quality);
+		new_pixbuf = rotate (src_pixbuf, -angle, high_quality, r0, g0, b0, a0);
 	}
 
 	return new_pixbuf;
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.h b/extensions/file_tools/gdk-pixbuf-rotate.h
index 01db0e8..f12efcf 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.h
+++ b/extensions/file_tools/gdk-pixbuf-rotate.h
@@ -45,7 +45,11 @@ double _gdk_pixbuf_rotate_get_align_angle (gboolean vertical,
 
 GdkPixbuf* _gdk_pixbuf_rotate (GdkPixbuf *src_pixbuf,
 			       double     angle,
-			       gboolean   high_quality);
+			       gboolean   high_quality,
+			       guchar     r0,
+			       guchar     g0,
+			       guchar     b0,
+			       guchar     a0);
 
 G_END_DECLS
 
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index 07419ac..7bb72f6 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -38,10 +38,14 @@ static gpointer parent_class = NULL;
 struct _GthFileToolRotatePrivate {
 	GdkPixbuf        *src_pixbuf;
 	GdkPixbuf        *rotate_pixbuf;
+	gboolean          has_alpha;
 	GtkBuilder       *builder;
 	GtkWidget        *options;
 	GtkAdjustment    *rotation_angle_adj;
 	GtkWidget        *high_quality;
+	GtkWidget        *background_color;
+	GtkWidget        *background_color_button;
+	GtkWidget        *background_transparent;
 	GtkWidget        *enable_guided_crop;
 	gboolean          crop_enabled;
 	GtkWidget        *show_grid;
@@ -242,6 +246,8 @@ apply_cb (gpointer user_data)
 	GtkWidget         *viewer_page;
 	double             rotation_angle;
 	gboolean           high_quality;
+	GdkColor           background_color;
+	guchar             r0, g0, b0, a0;
 
 	if (self->priv->apply_event != 0) {
 		g_source_remove (self->priv->apply_event);
@@ -254,8 +260,29 @@ apply_cb (gpointer user_data)
 	rotation_angle = gtk_adjustment_get_value (self->priv->rotation_angle_adj);
 	high_quality = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->high_quality));
 
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->background_color))) {
+
+		gtk_color_button_get_color (GTK_COLOR_BUTTON (self->priv->background_color_button), &background_color);
+
+		r0 = background_color.red >> 8;
+		g0 = background_color.green >> 8;
+		b0 = background_color.blue >> 8;
+		
+		if (self->priv->has_alpha)
+			a0 = gtk_color_button_get_alpha (GTK_COLOR_BUTTON (self->priv->background_color_button)) >> 8;
+		else
+			a0 = 0;
+	}
+	else {
+		r0 = 0;
+		g0 = 0;
+		b0 = 0;
+		a0 = 0;
+	}
+
 	_g_object_unref (self->priv->rotate_pixbuf);
-	self->priv->rotate_pixbuf = _gdk_pixbuf_rotate (self->priv->src_pixbuf, rotation_angle, high_quality);
+	self->priv->rotate_pixbuf = _gdk_pixbuf_rotate (self->priv->src_pixbuf, rotation_angle, high_quality, r0, g0, b0, a0);
+
 	gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->rotate_pixbuf, FALSE);
 
 	update_crop_parameters (self);
@@ -407,6 +434,16 @@ value_changed_cb (GtkAdjustment     *adj,
 
 
 static void
+background_color_changed_cb (GtkAdjustment     *adj,
+		             GthFileToolRotate *self)
+{
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->background_color), TRUE);
+	
+	value_changed_cb (adj, self);
+}
+
+
+static void
 selector_selected_cb (GthImageSelector  *selector,
 		      int                x,
 		      int                y,
@@ -459,6 +496,22 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 							       0.0, -90.0, 90.0, 0.1, 1.0, 1);
 
 	self->priv->high_quality = _gtk_builder_get_widget (self->priv->builder, "high_quality");
+
+	self->priv->background_color = _gtk_builder_get_widget (self->priv->builder, "background_color");
+	self->priv->background_color_button = _gtk_builder_get_widget (self->priv->builder, "background_color_button");
+	self->priv->background_transparent = _gtk_builder_get_widget (self->priv->builder, "background_transparent");
+
+	self->priv->has_alpha = gdk_pixbuf_get_n_channels (self->priv->src_pixbuf) == 4;
+
+	if (self->priv->has_alpha) {
+		gtk_color_button_set_use_alpha (GTK_COLOR_BUTTON (self->priv->background_color_button), TRUE);
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->background_transparent), TRUE);
+	}
+	else {
+		gtk_widget_set_sensitive (GET_WIDGET ("background_transparent"), FALSE);
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->background_color), TRUE);
+	}
+
 	self->priv->show_grid = _gtk_builder_get_widget (self->priv->builder, "show_grid");
 	self->priv->enable_guided_crop = _gtk_builder_get_widget (self->priv->builder, "enable_guided_crop");
 	self->priv->keep_aspect_ratio = _gtk_builder_get_widget (self->priv->builder, "keep_aspect_ratio");
@@ -522,6 +575,18 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 			  "value-changed",
 			  G_CALLBACK (value_changed_cb),
 			  self);
+	g_signal_connect (G_OBJECT (self->priv->background_color),
+			  "toggled",
+			  G_CALLBACK (value_changed_cb),
+			  self);
+	g_signal_connect (G_OBJECT (self->priv->background_color_button),
+			  "color-set",
+			  G_CALLBACK (background_color_changed_cb),
+			  self);
+	g_signal_connect (G_OBJECT (self->priv->background_transparent),
+			  "toggled",
+			  G_CALLBACK (value_changed_cb),
+			  self);
 	g_signal_connect (G_OBJECT (self->priv->crop_p1_adj),
 			  "value-changed",
 			  G_CALLBACK (crop_parameters_changed_cb),



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