gimp r27466 - in trunk: . app/gegl libgimpcolor



Author: martinn
Date: Wed Oct 29 21:25:35 2008
New Revision: 27466
URL: http://svn.gnome.org/viewvc/gimp?rev=27466&view=rev

Log:
* app/gegl/gimpoperationpointlayermode.c
(gimp_operation_point_layer_mode_process): Implemented the layer
modes Hue, Saturation, Color and Value.

Works the same for 100% opaque layers:
 o Hue
 o Saturation
 o Color
 o Value

* libgimpcolor/gimphsl.[ch]: Added gimp_hsl_set().


Modified:
   trunk/ChangeLog
   trunk/app/gegl/gimpoperationpointlayermode.c
   trunk/libgimpcolor/gimphsl.c
   trunk/libgimpcolor/gimphsl.h

Modified: trunk/app/gegl/gimpoperationpointlayermode.c
==============================================================================
--- trunk/app/gegl/gimpoperationpointlayermode.c	(original)
+++ trunk/app/gegl/gimpoperationpointlayermode.c	Wed Oct 29 21:25:35 2008
@@ -24,6 +24,8 @@
 
 #include <gegl-plugin.h>
 
+#include "libgimpcolor/gimpcolor.h"
+
 #include "gegl-types.h"
 
 #include "gimpoperationpointlayermode.h"
@@ -39,6 +41,7 @@
 #define layA lay[A]
 #define outC out[c]
 #define outA out[A]
+#define newC new[c]
 
 #define EACH_CHANNEL(expr)            \
         for (c = RED; c < ALPHA; c++) \
@@ -169,6 +172,104 @@
   gegl_operation_set_format (operation, "aux",    format);
 }
 
+static void
+gimp_operation_point_layer_mode_get_new_color_hsv (GimpLayerModeEffects  blend_mode,
+                                                   const gfloat         *in,
+                                                   const gfloat         *lay,
+                                                   gfloat               *new)
+{
+  GimpRGB inRGB;
+  GimpHSV inHSV;
+  GimpRGB layRGB;
+  GimpHSV layHSV;
+  GimpRGB newRGB;
+  GimpHSV newHSV;
+
+  gimp_rgb_set (&inRGB,  in[R],  in[G],  in[B]);
+  gimp_rgb_set (&layRGB, lay[R], lay[G], lay[B]);
+
+  gimp_rgb_to_hsv (&inRGB,  &inHSV);
+  gimp_rgb_to_hsv (&layRGB, &layHSV);
+
+  switch (blend_mode)
+    {
+    case GIMP_HUE_MODE:
+      gimp_hsv_set (&newHSV, layHSV.h, inHSV.s,  inHSV.v);
+      break;
+
+    case GIMP_SATURATION_MODE:
+      gimp_hsv_set (&newHSV, inHSV.h,  layHSV.s, inHSV.v);
+      break;
+
+    case GIMP_COLOR_MODE:
+      gimp_hsv_set (&newHSV, layHSV.h, layHSV.s, inHSV.v);
+      break;
+
+    case GIMP_VALUE_MODE:
+      gimp_hsv_set (&newHSV, inHSV.h,  inHSV.s,  layHSV.v);
+      break;
+
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
+  gimp_hsv_to_rgb (&newHSV, &newRGB);
+
+  new[R] = newRGB.r;
+  new[G] = newRGB.g;
+  new[B] = newRGB.b;
+}
+
+static void
+gimp_operation_point_layer_mode_get_new_color_hsl (GimpLayerModeEffects  blend_mode,
+                                                   const gfloat         *in,
+                                                   const gfloat         *lay,
+                                                   gfloat               *new)
+{
+  GimpRGB inRGB;
+  GimpHSL inHSL;
+  GimpRGB layRGB;
+  GimpHSL layHSL;
+  GimpRGB newRGB;
+  GimpHSL newHSL;
+
+  gimp_rgb_set (&inRGB,  in[R],  in[G],  in[B]);
+  gimp_rgb_set (&layRGB, lay[R], lay[G], lay[B]);
+
+  gimp_rgb_to_hsl (&inRGB,  &inHSL);
+  gimp_rgb_to_hsl (&layRGB, &layHSL);
+
+  switch (blend_mode)
+    {
+    case GIMP_HUE_MODE:
+      gimp_hsl_set (&newHSL, layHSL.h, inHSL.s,  inHSL.l);
+      break;
+
+    case GIMP_SATURATION_MODE:
+      gimp_hsl_set (&newHSL, inHSL.h,  layHSL.s, inHSL.l);
+      break;
+
+    case GIMP_COLOR_MODE:
+      gimp_hsl_set (&newHSL, layHSL.h, layHSL.s, inHSL.l);
+      break;
+
+    case GIMP_VALUE_MODE:
+      gimp_hsl_set (&newHSL, inHSL.h,  inHSL.s,  layHSL.l);
+      break;
+
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
+  gimp_hsl_to_rgb (&newHSL, &newRGB);
+
+  new[R] = newRGB.r;
+  new[G] = newRGB.g;
+  new[B] = newRGB.b;
+}
+
 static gboolean
 gimp_operation_point_layer_mode_process (GeglOperation       *operation,
                                          void                *in_buf,
@@ -179,10 +280,11 @@
 {
   GimpOperationPointLayerMode *self = GIMP_OPERATION_POINT_LAYER_MODE (operation);
 
-  gfloat *in  = in_buf;  /* composite of layers below */
-  gfloat *lay = aux_buf; /* layer */
-  gfloat *out = out_buf; /* resulting composite */
-  gint    c   = 0;
+  gfloat *in     = in_buf;  /* composite of layers below */
+  gfloat *lay    = aux_buf; /* layer */
+  gfloat *out    = out_buf; /* resulting composite */
+  gint    c      = 0;
+  gfloat  new[3] = { 0.0, 0.0, 0.0 };
 
   while (samples--)
     {
@@ -363,9 +465,30 @@
 
         case GIMP_HUE_MODE:
         case GIMP_SATURATION_MODE:
-        case GIMP_COLOR_MODE:
         case GIMP_VALUE_MODE:
-          /* TODO */
+          /* Custom SVG 1.2:
+           *
+           * f(Sc, Dc) = New color depending on mode
+           */
+          gimp_operation_point_layer_mode_get_new_color_hsv (self->blend_mode,
+                                                             in,
+                                                             lay,
+                                                             new);
+          EACH_CHANNEL (
+          outC = newC * layA * inA + layC * (1 - inA) + inC * (1 - layA));
+          break;
+
+        case GIMP_COLOR_MODE:
+          /* Custom SVG 1.2:
+           *
+           * f(Sc, Dc) = New color
+           */
+          gimp_operation_point_layer_mode_get_new_color_hsl (self->blend_mode,
+                                                             in,
+                                                             lay,
+                                                             new);
+          EACH_CHANNEL (
+          outC = newC * layA * inA + layC * (1 - inA) + inC * (1 - layA));
           break;
 
         case GIMP_ERASE_MODE:

Modified: trunk/libgimpcolor/gimphsl.c
==============================================================================
--- trunk/libgimpcolor/gimphsl.c	(original)
+++ trunk/libgimpcolor/gimphsl.c	Wed Oct 29 21:25:35 2008
@@ -51,3 +51,19 @@
 {
   return g_memdup (hsl, sizeof (GimpHSL));
 }
+
+
+/*  HSL functions  */
+
+void
+gimp_hsl_set (GimpHSL *hsl,
+              gdouble  h,
+              gdouble  s,
+              gdouble  l)
+{
+  g_return_if_fail (hsl != NULL);
+
+  hsl->h = h;
+  hsl->s = s;
+  hsl->l = l;
+}

Modified: trunk/libgimpcolor/gimphsl.h
==============================================================================
--- trunk/libgimpcolor/gimphsl.h	(original)
+++ trunk/libgimpcolor/gimphsl.h	Wed Oct 29 21:25:35 2008
@@ -33,6 +33,11 @@
 
 GType   gimp_hsl_get_type   (void) G_GNUC_CONST;
 
+void    gimp_hsl_set        (GimpHSL *hsl,
+                             gdouble  h,
+                             gdouble  s,
+                             gdouble  l);
+
 
 G_END_DECLS
 



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