Non-destructive layer scaling -> patch!

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

 



I have to work with a lot of website images so I end up doing a lot of resizing.  I kept running into problems though where I would resize a whole set of layers, then find out I made them to large or too small.  But I wouldn't be able to know this until I had them laid out on the image and could visually see the result.  Since git Gimp has support for layer trees now (woo!) I figured this would be the easiest way to implement the feature.  I just got this arranged about 20 minutes ago so I have not done a whole lot of testing.  I also don't really know much about Gimp internals.  I am looking for comments to my approach.  Should I be moving in a different direction?  I would like to add brightness-contrast non-destructive editing next, then maybe some color correction.

To use this:
  1) Make a layer group
  2) Add your source layer to the group
  3) In the layers dialog box, right click on the group layer and select "Edit Layer Attributes" and enter a new width and height
  4) I haven't figured out how to get the display to automatically update, so now you need to Move the layer so it will update.
  5) (If anyone knows what to do about GimpProgress, please let me know - see my FIXME)

Comments and suggestions please!

-Joseph
diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c
index 400944d..a5d1f3e 100644
--- a/app/actions/layers-commands.c
+++ b/app/actions/layers-commands.c
@@ -45,6 +45,10 @@
 #include "core/gimptoolinfo.h"
 #include "core/gimpundostack.h"
 #include "core/gimpprogress.h"
+#ifdef ENABLE_LAYERND
+#include <glib/gprintf.h>
+#include "core/gimpgrouplayernd.h"
+#endif
 
 #include "text/gimptext.h"
 #include "text/gimptext-vectors.h"
@@ -1030,6 +1034,13 @@ layers_edit_layer_response (GtkWidget          *widget,
     {
       GimpLayer   *layer = dialog->layer;
       const gchar *new_name;
+      #ifdef ENABLE_LAYERND
+      const gchar *new_ndscalex;
+      const gchar *new_ndscaley;
+      gint64      d_new_ndscalex;
+      gint64      d_new_ndscaley;
+      GimpGroupLayer *group;
+      #endif
 
       new_name = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
 
@@ -1060,6 +1071,19 @@ layers_edit_layer_response (GtkWidget          *widget,
                         gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->rename_toggle)),
                         NULL);
         }
+        
+        #ifdef ENABLE_LAYERND
+        if ( GIMP_IS_GROUP_LAYER(layer) ) {
+          new_ndscalex = gtk_entry_get_text (GTK_ENTRY (dialog->xscale_entry));
+          new_ndscaley = gtk_entry_get_text (GTK_ENTRY (dialog->yscale_entry));
+          d_new_ndscalex = g_ascii_strtoll(new_ndscalex, NULL, 10);
+          d_new_ndscaley = g_ascii_strtoll(new_ndscaley, NULL, 10);
+          // scale the group itself, not the children
+          gimp_group_layernd_set_scale(layer, (gint) d_new_ndscalex, (gint) d_new_ndscaley);
+          // must force update to the gimp group
+          group = GIMP_GROUP_LAYER(layer);
+        }
+        #endif
     }
 
   gtk_widget_destroy (dialog->dialog);
diff --git a/app/core/gimpgrouplayer.c b/app/core/gimpgrouplayer.c
index e979fb2..f4b4ba1 100644
--- a/app/core/gimpgrouplayer.c
+++ b/app/core/gimpgrouplayer.c
@@ -39,6 +39,10 @@
 #include "gimpprojectable.h"
 #include "gimpprojection.h"
 
+#ifdef ENABLE_LAYERND
+#include "gimpgrouplayernd.h"
+#endif
+
 #include "gimp-intl.h"
 
 
@@ -1026,6 +1030,9 @@ gimp_group_layer_update_size (GimpGroupLayer *group)
                        "y", (gdouble) -y,
                        NULL);
     }
+    #ifdef ENABLE_LAYERND
+    gimp_group_layernd_update(group);
+    #endif
 }
 
 static void
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index d0584aa..19f1656 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -321,6 +321,12 @@ gimp_layer_init (GimpLayer *layer)
   layer->fs.boundary_known = FALSE;
   layer->fs.segs           = NULL;
   layer->fs.num_segs       = 0;
+  
+  #ifdef ENABLE_LAYERND
+  layer->ndmode = 0;
+  layer->ndscalex = 0;
+  layer->ndscaley = 0;
+  #endif
 }
 
 static void
diff --git a/app/core/gimplayer.h b/app/core/gimplayer.h
index c45d245..dcad368 100644
--- a/app/core/gimplayer.h
+++ b/app/core/gimplayer.h
@@ -52,6 +52,12 @@ struct _GimpLayer
     BoundSeg     *segs;               /*  boundary of floating sel       */
     gint          num_segs;           /*  number of segs in boundary     */
   } fs;
+
+  #ifdef ENABLE_LAYERND
+  gint            ndmode;
+  gint            ndscalex;
+  gint            ndscaley;
+  #endif
 };
 
 struct _GimpLayerClass
diff --git a/app/dialogs/layer-options-dialog.c b/app/dialogs/layer-options-dialog.c
index 2e0ba8d..1d94b7e 100644
--- a/app/dialogs/layer-options-dialog.c
+++ b/app/dialogs/layer-options-dialog.c
@@ -29,6 +29,12 @@
 #include "core/gimpimage.h"
 #include "core/gimplayer.h"
 
+#ifdef ENABLE_LAYERND
+#include "core/gimpgrouplayer.h"
+#include "core/gimpgrouplayernd.h"
+#include "base/boundary.h"
+#endif
+
 #include "text/gimptext.h"
 #include "text/gimptextlayer.h"
 
@@ -70,6 +76,11 @@ layer_options_dialog_new (GimpImage    *image,
   GtkWidget          *spinbutton;
   GtkWidget          *frame;
   GtkWidget          *button;
+  #ifdef ENABLE_LAYERND
+  BoundSeg           *layer_boundary;
+  gint                layer_numsegs;
+  gchar              *str;
+  #endif
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
   g_return_val_if_fail (layer == NULL || GIMP_IS_LAYER (layer), NULL);
@@ -113,12 +124,20 @@ layer_options_dialog_new (GimpImage    *image,
                      vbox);
   gtk_widget_show (vbox);
 
+  #ifdef ENABLE_LAYERND
+  if ( GIMP_IS_GROUP_LAYER(layer) ) {
+    table = gtk_table_new (layer ? 3 : 3, 2, FALSE);
+  } else {
+  #endif
   table = gtk_table_new (layer ? 1 : 3, 2, FALSE);
+  #ifdef ENABLE_LAYERND
+  }
+  #endif
   gtk_table_set_col_spacing (GTK_TABLE (table), 0, 6);
   gtk_table_set_row_spacing (GTK_TABLE (table), 0, 6);
   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
   gtk_widget_show (table);
-
+  
   /*  The name label and entry  */
   options->name_entry = gtk_entry_new ();
   gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
@@ -128,6 +147,40 @@ layer_options_dialog_new (GimpImage    *image,
   gtk_entry_set_activates_default (GTK_ENTRY (options->name_entry), TRUE);
   gtk_entry_set_text (GTK_ENTRY (options->name_entry), layer_name);
 
+  #ifdef ENABLE_LAYERND
+  if ( GIMP_IS_GROUP_LAYER(layer) )
+    {
+      if ( !(layer->ndmode & GIMP_GROUP_LAYERND_MODE_SCALE) ) {
+        layer_boundary = gimp_layer_boundary(layer, &layer_numsegs);
+        options->xscale = (layer_boundary[1].x2 - layer_boundary[1].x1);
+        options->yscale = (layer_boundary[0].y2 - layer_boundary[0].y1);
+      } else {
+        layer_boundary = NULL;
+        options->xscale = layer->ndscalex;
+        options->yscale = layer->ndscaley;
+      }
+
+      options->xscale_entry = gtk_entry_new ();
+      gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
+                                _("X Scale:"), 0.0, 0.5,
+                                options->xscale_entry, 1, FALSE);
+      str = g_strdup_printf("%d", options->xscale);
+      gtk_entry_set_text (GTK_ENTRY (options->xscale_entry), str);
+      g_free(str);
+
+      options->yscale_entry = gtk_entry_new ();
+      gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
+                                _("Y Scale:"), 0.0, 0.5,
+                                options->yscale_entry, 1, FALSE);
+      str = g_strdup_printf("%d", options->yscale);
+      gtk_entry_set_text (GTK_ENTRY (options->yscale_entry), str);
+      g_free(str);
+
+      if ( layer_boundary ) g_free(layer_boundary);
+  
+    }
+  #endif
+
   if (! layer)
     {
       gdouble xres;
diff --git a/app/dialogs/layer-options-dialog.h b/app/dialogs/layer-options-dialog.h
index f841bf2..a444ad8 100644
--- a/app/dialogs/layer-options-dialog.h
+++ b/app/dialogs/layer-options-dialog.h
@@ -35,6 +35,13 @@ struct _LayerOptionsDialog
   GimpImage    *image;
   GimpContext  *context;
   GimpLayer    *layer;
+  #ifdef ENABLE_LAYERND
+  GtkWidget    *xscale_entry;
+  GtkWidget    *yscale_entry;
+  
+  gint          xscale;
+  gint          yscale;
+  #endif
 };
 
 
_______________________________________________
Gimp-developer mailing list
Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux