gegl r2942 - in trunk: . operations/common



Author: ok
Date: Sun Feb 22 20:21:20 2009
New Revision: 2942
URL: http://svn.gnome.org/viewvc/gegl?rev=2942&view=rev

Log:
* operations/common/envelopes.h: modified to deal correctly with HDR.
* operations/common/c2g.c: trim and document parameters.
* operations/common/stress.c: trim and document parameters.


Modified:
   trunk/ChangeLog
   trunk/operations/common/c2g.c
   trunk/operations/common/envelopes.h
   trunk/operations/common/stress.c

Modified: trunk/operations/common/c2g.c
==============================================================================
--- trunk/operations/common/c2g.c	(original)
+++ trunk/operations/common/c2g.c	Sun Feb 22 20:21:20 2009
@@ -13,9 +13,9 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
  *
- * Copyright 2007 Ãyvind KolÃs     <oeyvindk hig no>
- *                Ivar Farup       <ivarf hig no>
- *                Allesandro Rizzi <rizzi dti unimi it>
+ * Copyright 2007,2009 Ãyvind KolÃs     <pippin gimp org>
+ *                     Ivar Farup       <ivarf hig no>
+ *                     Allesandro Rizzi <rizzi dti unimi it>
  */
 
 #include "config.h"
@@ -24,21 +24,23 @@
 
 #ifdef GEGL_CHANT_PROPERTIES
 
-gegl_chant_int (radius, _("Radius"), 2, 5000.0, 384,
-                _("Neighbourhood taken into account"))
-gegl_chant_int (samples, _("Samples"), 0, 1000, 3,
-                _("Number of samples to do"))
-gegl_chant_int (iterations, _("Iterations"), 0, 1000, 23,
-                _("Number of iterations (length of exposure)"))
+gegl_chant_int (radius, _("Radius"), 2, 3000.0, 300,
+                _("Neighbourhood taken into account, this is the radius in pixels taken into account when deciding which colors map to which gray values."))
+gegl_chant_int (samples, _("Samples"), 0, 1000, 4,
+                _("Number of samples to do per iteration looking for the range of colors."))
+gegl_chant_int (iterations, _("Iterations"), 0, 1000, 10,
+                _("Number of iterations, a higher number of iterations provides a less noisy results at computational cost."))
+
 gegl_chant_boolean (same_spray, _("Same spray"), FALSE,
                 _("Use the same spray for all pixels"))
-gegl_chant_double (rgamma, _("Radial Gamma"), 0.0, 8.0, 1.8,
-                _("Gamma applied to radial distribution"))
-gegl_chant_double (strength, _("Strength"), -10.0, 10.0, 1.0,
+gegl_chant_double (strength, _("Strength"), 0.0, 1.0, 1.0,
                 _("Amount of correction 0=none 1.0=full"))
+/*
+gegl_chant_double (rgamma, _("Radial Gamma"), 0.0, 8.0, 2.0,
+                _("Gamma applied to radial distribution"))
 gegl_chant_double (gamma, _("Gamma"), 0.0, 10.0, 1.0,
                 _("Post correction gamma."))
-
+*/
 #else
 
 #define GEGL_CHANT_TYPE_AREA_FILTER
@@ -49,6 +51,9 @@
 #include <stdlib.h>
 #include "envelopes.h"
 
+#define RGAMMA 2.0
+#define GAMMA  1.0
+
 static void stress (GeglBuffer *src,
                     GeglBuffer *dst,
                     gint        radius,
@@ -65,7 +70,7 @@
   gfloat *dst_buf;
 
   src_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (src) * 4);
-  dst_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (dst) * 4);
+  dst_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (dst) * 2);
 
   gegl_buffer_get (src, 1.0, NULL, babl_format ("RGBA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
 
@@ -100,7 +105,7 @@
                 {
                   gfloat delta = max_envelope[c]-min_envelope[c];
                   nominator += (pixel[c] - min_envelope[c]) * delta;
-                  denominator += delta*delta;
+                  denominator += delta * delta;
                 }
 
               if (denominator>0.000) /* if we found a range, modify the result */
@@ -118,16 +123,15 @@
 
                 }
             }
-              for (c=0; c<3;c++)
-                dst_buf[dst_offset+c] = gray;
-              dst_buf[dst_offset+3] = src_buf[src_offset+3];
+              dst_buf[dst_offset+0] = gray;
+              dst_buf[dst_offset+1] = src_buf[src_offset+3];
           }
 
           src_offset+=4;
-          dst_offset+=4;
+          dst_offset+=2;
         }
     }
-  gegl_buffer_set (dst, NULL, babl_format ("RGBA float"), dst_buf, GEGL_AUTO_ROWSTRIDE);
+  gegl_buffer_set (dst, NULL, babl_format ("YA float"), dst_buf, GEGL_AUTO_ROWSTRIDE);
   g_free (src_buf);
   g_free (dst_buf);
 }
@@ -137,6 +141,7 @@
   GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
   area->left = area->right = area->top = area->bottom =
       ceil (GEGL_CHANT_PROPERTIES (operation)->radius);
+  gegl_operation_set_format (operation, "output", babl_format ("YA float"));
 }
 
 static GeglRectangle
@@ -163,9 +168,9 @@
           o->samples,
           o->iterations,
           o->same_spray,
-          o->rgamma,
+          /*o->rgamma*/RGAMMA,
           o->strength,
-          o->gamma);
+          /*o->gamma*/GAMMA);
 
   return  TRUE;
 }
@@ -192,8 +197,9 @@
   operation_class->name        = "gegl:c2g";
   operation_class->categories  = "enhance";
   operation_class->description =
-        _("Color to grayscale conversion, uses spatial color differences "
-          "to perform local grayscale contrast enhancement.");
+        _("Color to grayscale conversion, uses envelopes formed from spatial "
+         " color differences to perform color-feature preserving grayscale "
+         " spatial contrast enhancement.");
 }
 
 #endif

Modified: trunk/operations/common/envelopes.h
==============================================================================
--- trunk/operations/common/envelopes.h	(original)
+++ trunk/operations/common/envelopes.h	Sun Feb 22 20:21:20 2009
@@ -11,12 +11,11 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
  *
- * Copyright 2007 Ãyvind KolÃs     <pippin gimp org>
+ * Copyright 2007, 2009 Ãyvind KolÃs     <pippin gimp org>
  */
 
-#define ANGLE_PRIME  95273
-#define RADIUS_PRIME 29537
-#define SCALE_PRIME 85643
+#define ANGLE_PRIME  95273  /* the lookuptables are sized as primes to avoid  */
+#define RADIUS_PRIME 29537  /* repetitions when they are used cyclcly simulatnously */
 
 static gfloat   lut_cos[ANGLE_PRIME];
 static gfloat   lut_sin[ANGLE_PRIME];
@@ -122,7 +121,7 @@
 
         sample (buf, width, height, u, v, pixel);
 
-        if (pixel[3]>0.0)
+        if (pixel[3]>0.0) /* ignore fully transparent pixels */
           {
             for (c=0;c<3;c++)
               {
@@ -146,26 +145,27 @@
     }
 }
 
-static void compute_envelopes (gfloat  *buf,
-                               gint     width,
-                               gint     height,
-                               gint     x,
-                               gint     y,
-                               gint     radius,
-                               gint     samples,
-                               gint     iterations,
-                               gboolean same_spray,
-                               gdouble  rgamma,
-                               gfloat  *min_envelope,
-                               gfloat  *max_envelope)
+static inline void compute_envelopes (gfloat  *buf,
+                                      gint     width,
+                                      gint     height,
+                                      gint     x,
+                                      gint     y,
+                                      gint     radius,
+                                      gint     samples,
+                                      gint     iterations,
+                                      gboolean same_spray,
+                                      gdouble  rgamma,
+                                      gfloat  *min_envelope,
+                                      gfloat  *max_envelope)
 {
   gint    i;
   gint    c;
-  /*gfloat  range_avg[4]  = {0,0,0,0};*/
-  gfloat  dark_avg[4]   = {0,0,0,0};
-  gfloat  bright_avg[4] = {0,0,0,0};
-  /*gfloat *pixel = buf + (width*y+x)*4;*/
+  gfloat  range_sum[4]               = {0,0,0,0};
+  gfloat  relative_brightness_sum[4] = {0,0,0,0};
+  gfloat *pixel = buf + (width*y+x)*4;
 
+  /* compute lookuptables for the gamma, currently not used/exposed
+   * as a tweakable property */
   compute_luts(rgamma);
 
   if (same_spray)
@@ -176,7 +176,7 @@
 
   for (i=0;i<iterations;i++)
     {
-      gfloat min[3], max[3];      /* sampled min/max */
+      gfloat min[3], max[3];
 
       sample_min_max (buf,
                       width,
@@ -187,37 +187,32 @@
 
       for (c=0;c<3;c++)
         {
-          /*gfloat range, bright, dark;
+          gfloat range, relative_brightness;
 
           range = max[c] - min[c];
 
           if (range>0.0)
             {
-              bright = (max[c] - pixel[c]) / range;
-              dark = (pixel[c] - min[c]) / range;
+              relative_brightness = (pixel[c] - min[c]) / range;
             }
           else
             {
-              bright = 0.5;
-              dark = 0.5;
-            }*/
+              relative_brightness = 0.5;
+            }
 
-          dark_avg[c] += min[c];
-          bright_avg[c] += max[c];
+          relative_brightness_sum[c] += relative_brightness;
+          range_sum[c] += range;
         }
     }
 
     for (c=0;c<3;c++)
       {
-        dark_avg[c]   /= iterations;
-        bright_avg[c] /= iterations;
+        gfloat relative_brightness = relative_brightness_sum[c] / iterations;
+        gfloat range               = range_sum[c] / iterations;
+        
+        if (max_envelope)
+          max_envelope[c] = pixel[c] + (1.0 - relative_brightness) * range;
+        if (min_envelope)
+          min_envelope[c] = pixel[c] - relative_brightness * range;
       }
-
-    if (max_envelope)
-      for (c=0;c<3;c++)
-        max_envelope[c] = bright_avg[c];/*pixel[c] + bright_avg[c] * range_avg[c];*/
-
-    if (min_envelope)
-      for (c=0;c<3;c++)
-        min_envelope[c] = dark_avg[c];/*pixel[c] - dark_avg[c] * range_avg[c];*/
 }

Modified: trunk/operations/common/stress.c
==============================================================================
--- trunk/operations/common/stress.c	(original)
+++ trunk/operations/common/stress.c	Sun Feb 22 20:21:20 2009
@@ -24,20 +24,26 @@
 
 #ifdef GEGL_CHANT_PROPERTIES
 
-gegl_chant_int (radius, _("Radius"), 2, 5000.0, 300,
-                _("Neighbourhood taken into account"))
-gegl_chant_int (samples, _("Samples"), 0, 1000, 10,
-                _("Number of samples to do"))
+gegl_chant_int (radius, _("Radius"), 2, 3000.0, 300,
+                _("Neighbourhood taken into account, for enhancement ideal values are close to the longest side of the image, increasing this increases the runtime."))
+gegl_chant_int (samples, _("Samples"), 0, 1000, 4,
+                _("Number of samples to do per iteration looking for the range of colors."))
 gegl_chant_int (iterations, _("Iterations"), 0, 1000, 10,
-                _("Number of iterations (length of exposure)"))
-gegl_chant_boolean (same_spray, _("Same spray"), TRUE,
-                    _("Use the same spray for all pixels"))
+                _("Number of iterations, a higher number of iterations provides a less noisy rendering at computational cost."))
+
+
+gegl_chant_boolean (same_spray, _("Same spray"), FALSE,
+                _("Use the same neighbourhood for all pixels, this can speed up computation but also introduces halos with clones of the image unless the number of iterations is high."))
+/*
+
 gegl_chant_double (rgamma, _("Radial Gamma"), 0.0, 8.0, 2.0,
-                   _("Gamma applied to radial distribution"))
-gegl_chant_double (strength, _("Strength"), -10.0, 10.0, 1.0,
-                   _("Amount of correction 0=none 1.0=full"))
+                _("Gamma applied to radial distribution"))
 gegl_chant_double (gamma, _("Gamma"), 0.0, 10.0, 1.0,
-                   _("Post correction gamma"))
+                _("Post correction gamma"))
+
+*/
+
+
 
 #else
 
@@ -45,6 +51,10 @@
 #define GEGL_CHANT_C_FILE       "stress.c"
 
 #include "gegl-chant.h"
+
+#define RGAMMA   2.0
+#define GAMMA    1.0
+
 #include <math.h>
 #include <stdlib.h>
 #include "envelopes.h"
@@ -56,7 +66,6 @@
                     gint        iterations,
                     gboolean    same_spray,
                     gdouble     rgamma,
-                    gdouble     strength,
                     gdouble     gamma)
 {
   gint x,y;
@@ -64,6 +73,10 @@
   gfloat *src_buf;
   gfloat *dst_buf;
 
+  /* this use of huge linear buffers should be avoided and
+   * most probably would lead to great speed ups
+   */
+
   src_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (src) * 4);
   dst_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (dst) * 4);
 
@@ -87,31 +100,30 @@
                              same_spray,
                              rgamma,
                              min_envelope, max_envelope);
-         {
-          gint c;
-          gfloat pixel[3];
-          for (c=0;c<3;c++)
-            {
-              pixel[c] = center_pix[c];
-              if (min_envelope[c]!=max_envelope[c])
+           {
+              gint c;
+              gfloat pixel[3];
+              for (c=0;c<3;c++)
+                {
+                  pixel[c] = center_pix[c];
+                  if (min_envelope[c]!=max_envelope[c])
+                    {
+                      gfloat scaled = (pixel[c]-min_envelope[c])/(max_envelope[c]-min_envelope[c]);
+                      pixel[c] = scaled;
+                    }
+                }
+              if (gamma==1.0)
+                {
+                  for (c=0; c<3;c++)
+                    dst_buf[dst_offset+c] = pixel[c];
+                }
+              else
                 {
-                  gfloat scaled = (pixel[c]-min_envelope[c])/(max_envelope[c]-min_envelope[c]);
-                  pixel[c] *= (1.0-strength);
-                  pixel[c] = strength * scaled;
+                  for (c=0; c<3;c++)
+                    dst_buf[dst_offset+c] = pow(pixel[c],gamma);
                 }
-            }
-          if (gamma==1.0)
-            {
-              for (c=0; c<3;c++)
-                dst_buf[dst_offset+c] = pixel[c];
-            }
-          else
-            {
-              for (c=0; c<3;c++)
-                dst_buf[dst_offset+c] = pow(pixel[c],gamma);
-            }
-          dst_buf[dst_offset+c] = center_pix[c];
-         }
+              dst_buf[dst_offset+c] = center_pix[c];
+           }
           src_offset+=4;
           dst_offset+=4;
         }
@@ -155,9 +167,8 @@
           o->samples,
           o->iterations,
           o->same_spray,
-          o->rgamma,
-          o->strength,
-          o->gamma);
+          RGAMMA, /*o->rgamma,*/
+          GAMMA/*o->gamma*/);
 
   return  TRUE;
 }
@@ -174,7 +185,7 @@
 
   filter_class->process = process;
   operation_class->prepare  = prepare;
-  /* we override defined region to avoid growing the size of what is defined
+  /* we override get_bounding_box to avoid growing the size of what is defined
    * by the filter. This also allows the tricks used to treat alpha==0 pixels
    * in the image as source data not to be skipped by the stochastic sampling
    * yielding correct edge behavior.



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