[patch] Wishlist #7100 (create layer mask with layer as content)

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

 



Hi!

I'm brand new to this list (again), so sorry if this was asked
five minutes ago...

I have just patched gimp-1.1.28 so that it now can do
what is registered as wish list item #7100
  #7100: [Wishlist] layer mask initialization
in the bug database. (meaning, you can create a new
layer mask and initialize it with a (desaturated) copy
of the layer's content)

Whom do I send this patch to, and did I use the prefered
patch format?

I've searched for this in the developer FAQ, but my
question isn't answered there.

I have added the patch to this mail (it's relatively small).
It can be applied to a vanilla 1.1.28 with
  cd gimp-1.1.28
  patch -p1 -i ../gimp_patch_wishlist_item_#7100.diff

What happens now?  ;)

Greetings,
       Andy

-- 
Andreas Jaekel, CableCats - Foest, Jaekel, Tegethoff GbR
http://www.cablecats.de  Tel.: 030 - 916 11 77 3
diff -r -u gimp-1.1.28/app/apptypes.h gimp-1.1.28-a/app/apptypes.h
--- gimp-1.1.28/app/apptypes.h	Sat Nov 27 15:00:25 1999
+++ gimp-1.1.28-a/app/apptypes.h	Thu Oct 26 13:37:02 2000
@@ -114,7 +114,8 @@
 {
   ADD_WHITE_MASK,
   ADD_BLACK_MASK,
-  ADD_ALPHA_MASK
+  ADD_ALPHA_MASK,
+  ADD_CONTENT_MASK
 } AddMaskType;
 
 /* gradient paint modes */
diff -r -u gimp-1.1.28/app/layer.c gimp-1.1.28-a/app/layer.c
--- gimp-1.1.28/app/layer.c	Sat Aug 19 18:08:56 2000
+++ gimp-1.1.28-a/app/layer.c	Thu Oct 26 13:37:08 2000
@@ -533,10 +533,23 @@
 	{
 	  pixel_region_init (&layerPR, GIMP_DRAWABLE (layer)->tiles, 
 			     0, 0, 
-			     GIMP_DRAWABLE (layer)->width, GIMP_DRAWABLE (layer)->height, 
+			     GIMP_DRAWABLE (layer)->width,
+			     GIMP_DRAWABLE (layer)->height, 
 			     FALSE);
 	  extract_alpha_region (&layerPR, NULL, &maskPR);
 	}
+      break;
+    case ADD_CONTENT_MASK:
+      pixel_region_init (&layerPR, GIMP_DRAWABLE (layer)->tiles, 
+			 0, 0, 
+			 GIMP_DRAWABLE (layer)->width,
+			 GIMP_DRAWABLE (layer)->height, 
+			 FALSE);
+      extract_from_region_to_mask (&layerPR, &maskPR,
+				   GIMP_DRAWABLE (layer)->gimage->cmap,
+				   GIMP_DRAWABLE(layer)->type,
+				   layer_has_alpha (layer));
+
       break;
     }
 
diff -r -u gimp-1.1.28/app/layer_cmds.c gimp-1.1.28-a/app/layer_cmds.c
--- gimp-1.1.28/app/layer_cmds.c	Thu Jun 22 05:23:18 2000
+++ gimp-1.1.28-a/app/layer_cmds.c	Thu Oct 26 13:37:19 2000
@@ -295,7 +295,7 @@
     success = FALSE;
 
   mask_type = args[1].value.pdb_int;
-  if (mask_type < ADD_WHITE_MASK || mask_type > ADD_ALPHA_MASK)
+  if (mask_type < ADD_WHITE_MASK || mask_type > ADD_CONTENT_MASK)
     success = FALSE;
 
   if (success)
@@ -319,7 +319,7 @@
   {
     PDB_INT32,
     "mask_type",
-    "The type of mask: { WHITE_MASK (0), BLACK_MASK (1), ALPHA_MASK (2) }"
+    "The type of mask: { WHITE_MASK (0), BLACK_MASK (1), ALPHA_MASK (2), LAYER_TO_MASK (3) }"
   }
 };
 
@@ -336,7 +336,7 @@
 {
   "gimp_layer_create_mask",
   "Create a layer mask for the specified specified layer.",
-  "This procedure creates a layer mask for the specified layer. Layer masks serve as an additional alpha channel for a layer. Three different types of masks are allowed initially: completely white masks (which will leave the layer fully visible), completely black masks (which will give the layer complete transparency, and the layer's already existing alpha channel (which will leave the layer fully visible, but which may be more useful than a white mask). The layer mask still needs to be added to the layer. This can be done with a call to 'gimage_add_layer_mask'.",
+  "This procedure creates a layer mask for the specified layer. Layer masks serve as an additional alpha channel for a layer. Four different types of masks are allowed initially: completely white masks (which will leave the layer fully visible), completely black masks (which will give the layer complete transparency, the layer's already existing alpha channel (which will leave the layer fully visible, but which may be more useful than a white mask) and a mask containing the layer's data (desturated if necessary). The layer mask still needs to be added to the layer. This can be done with a call to 'gimage_add_layer_mask'.",
   "Spencer Kimball & Peter Mattis",
   "Spencer Kimball & Peter Mattis",
   "1995-1996",
diff -r -u gimp-1.1.28/app/layers_dialog.c gimp-1.1.28-a/app/layers_dialog.c
--- gimp-1.1.28/app/layers_dialog.c	Wed Aug 30 09:20:43 2000
+++ gimp-1.1.28-a/app/layers_dialog.c	Thu Oct 26 13:37:37 2000
@@ -3779,6 +3779,8 @@
 				 (gpointer) ADD_BLACK_MASK, NULL,
 				 _("Layer's Alpha Channel"),
 				 (gpointer) ADD_ALPHA_MASK, NULL,
+				 _("Layer's Content"),
+				 (gpointer) ADD_CONTENT_MASK, NULL,
 				 NULL);
 
   gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
diff -r -u gimp-1.1.28/app/paint_funcs.c gimp-1.1.28-a/app/paint_funcs.c
--- gimp-1.1.28/app/paint_funcs.c	Wed Sep 27 21:23:17 2000
+++ gimp-1.1.28-a/app/paint_funcs.c	Thu Oct 26 13:37:48 2000
@@ -3440,6 +3440,86 @@
 }
 
 
+/* extract_from_region_to_mask
+ *
+ * This function copies a layer's content into a mask. This is
+ * used for creating a new layer mask with the layer's content
+ * as initialization. So we can assume that the layer doesn't
+ * already have a mask and that the destination is a mask, which
+ * has one byte per pixel and no alpha.
+ */
+void
+extract_from_region_to_mask (PixelRegion   *layerPR,
+			     PixelRegion   *maskPR,
+			     unsigned char *cmap,
+			     int           layer_type,
+			     int           has_alpha)
+{
+  GimpImageBaseType type = 0;
+  int bytes = 0;
+  int alpha = 0;
+  void * pr;
+  int h = 0;
+  int w = 0;
+  unsigned char *src = 0;
+  unsigned char *dest = 0;
+  unsigned char *s = 0;
+  unsigned char *d = 0;
+  unsigned char rgb[3];
+  unsigned char gray = 0;
+  int tmp = 0;
+
+  switch (layer_type)
+    {
+    case RGB_GIMAGE: case RGBA_GIMAGE:
+      type  = RGB;
+      break;
+    case GRAY_GIMAGE: case GRAYA_GIMAGE:
+      type  = GRAY;
+      break;
+    case INDEXED_GIMAGE: case INDEXEDA_GIMAGE:
+      type  = INDEXED;
+      break;
+    }
+
+  bytes = layerPR->bytes;
+  alpha = layerPR->bytes - 1;
+  for (pr = pixel_regions_register (3, layerPR, NULL, maskPR);
+       pr != NULL;
+       pr = pixel_regions_process (pr))
+    {
+      s = layerPR->data;
+      d = maskPR->data;
+      
+      h = layerPR->h;
+      while (h --)
+	{
+	  w = layerPR->w;
+	  src = s;
+	  dest = d;
+	  while (w --)
+	    {
+	      map_to_color(type, cmap, src, rgb);
+	      if(has_alpha)
+		{ // apply layer alpha to mask
+		  gray = (rgb[0] + rgb[1] + rgb[2]) / 3;
+		  *dest++ = INT_BLEND(gray, 0, src[alpha], tmp); // always 0
+		}
+	      else
+		{ // simple copy
+		  *dest++ = (rgb[0] + rgb[1] + rgb[2]) / 3;
+		}
+
+	      src += bytes;
+	    }
+	  
+	  s += layerPR->rowstride;
+	  d += maskPR->rowstride;
+	}
+    }
+}
+
+
 void
 extract_from_region (PixelRegion   *src,
 		     PixelRegion   *dest,
diff -r -u gimp-1.1.28/app/paint_funcs.h gimp-1.1.28-a/app/paint_funcs.h
--- gimp-1.1.28/app/paint_funcs.h	Thu Feb 10 22:38:43 2000
+++ gimp-1.1.28-a/app/paint_funcs.h	Thu Oct 26 13:37:57 2000
@@ -476,6 +476,8 @@
 					   PixelRegion *, unsigned char *,
 					   unsigned char *, int, int, int);
 
+void  extract_from_region_to_mask         (PixelRegion *, PixelRegion *,
+					   unsigned char *, int, int);
 
 void  convolve_region                     (PixelRegion *,
 					   PixelRegion *,
diff -r -u gimp-1.1.28/libgimp/gimplayer_pdb.c gimp-1.1.28-a/libgimp/gimplayer_pdb.c
--- gimp-1.1.28/libgimp/gimplayer_pdb.c	Fri Aug 25 01:09:30 2000
+++ gimp-1.1.28-a/libgimp/gimplayer_pdb.c	Thu Oct 26 13:38:35 2000
@@ -122,12 +122,13 @@
  * Create a layer mask for the specified specified layer.
  *
  * This procedure creates a layer mask for the specified layer. Layer
- * masks serve as an additional alpha channel for a layer. Three
+ * masks serve as an additional alpha channel for a layer. Four
  * different types of masks are allowed initially: completely white
  * masks (which will leave the layer fully visible), completely black
- * masks (which will give the layer complete transparency, and the
+ * masks (which will give the layer complete transparency), the
  * layer's already existing alpha channel (which will leave the layer
- * fully visible, but which may be more useful than a white mask). The
+ * fully visible, but which may be more useful than a white mask) and
+ * a mask containing the layer's data (desaturated if neccessary). The
  * layer mask still needs to be added to the layer. This can be done
  * with a call to 'gimage_add_layer_mask'.
  *

[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