gimp r27396 - in trunk: . app/gegl



Author: martinn
Date: Sat Oct 25 09:47:09 2008
New Revision: 27396
URL: http://svn.gnome.org/viewvc/gimp?rev=27396&view=rev

Log:
* app/gegl/gimpoperationlayermode.c: Make layer modes work on
premultiplied data. This makes compositing 40% faster on my test
image with 10 interlaced Normal and Addition mode layers.

* app/gegl/gimpoperationadditionmode.c: Switch to the
premultiplied algorithm and remove the experimental ones. The new
Addition mode has two important differences over the legacy
Addition mode:

  o Addition mode now really is commutative as the GIMP
    documentation says (this wasn't previously the case).

  o Layers in Addition mode are just as opaque as Normal
    layers. That is, their effect on the composite alpha channel
    is the same. For discussion, refer to bug #387449.


Modified:
   trunk/ChangeLog
   trunk/app/gegl/gimpoperationadditionmode.c
   trunk/app/gegl/gimpoperationlayermode.c

Modified: trunk/app/gegl/gimpoperationadditionmode.c
==============================================================================
--- trunk/app/gegl/gimpoperationadditionmode.c	(original)
+++ trunk/app/gegl/gimpoperationadditionmode.c	Sat Oct 25 09:47:09 2008
@@ -71,37 +71,21 @@
 
   while (samples--)
     {
-#if 1
-      // Wrong, for alpha compositing consistency all layers should
-      // affect alpha in the same way independent of layer mode
-      out[RED]   = in[RED]   + layer[RED]   * layer[ALPHA];
-      out[GREEN] = in[GREEN] + layer[GREEN] * layer[ALPHA];
-      out[BLUE]  = in[BLUE]  + layer[BLUE]  * layer[ALPHA];
-      out[ALPHA] = in[ALPHA];
-#else
-      // A very nice combination of correctness and speed for
-      // premultiplied data without any of the issues the previous
-      // versions had
+      /* To be more mathematically correct we would have to either
+       * adjust the formula for the resulting opacity or adapt the
+       * other channels to the change in opacity. Compare to the
+       * 'plus' compositiong operation in SVG 1.2.
+       *
+       * Since this doesn't matter for completely opaque layers, and
+       * since consistency in how the alpha channel of layers is
+       * interpreted is more important than mathematically correct
+       * results, we don't bother.
+       */
       out[RED]   = in[RED]   + layer[RED];
       out[GREEN] = in[GREEN] + layer[GREEN];
       out[BLUE]  = in[BLUE]  + layer[BLUE];
       out[ALPHA] = in[ALPHA] + layer[ALPHA] - in[ALPHA] * layer[ALPHA];
 
-      // Wrong, doesn't take layer opacity of Addition-mode layer into
-      // account
-      out[RED]   = in[RED]   + layer[RED];
-      out[GREEN] = in[GREEN] + layer[GREEN];
-      out[BLUE]  = in[BLUE]  + layer[BLUE];
-      out[ALPHA] = in[ALPHA];
-
-      // Wrong, toggling visibility of completely transparent
-      // Addition-mode layer changes projection
-      out[RED]   = in[RED]   * in[ALPHA] + layer[RED]   * layer[ALPHA];
-      out[GREEN] = in[GREEN] * in[ALPHA] + layer[GREEN] * layer[ALPHA];
-      out[BLUE]  = in[BLUE]  * in[ALPHA] + layer[BLUE]  * layer[ALPHA];
-      out[ALPHA] = in[ALPHA] + layer[ALPHA] - in[ALPHA] * layer[ALPHA];
-#endif
-
       in    += 4;
       layer += 4;
       out   += 4;

Modified: trunk/app/gegl/gimpoperationlayermode.c
==============================================================================
--- trunk/app/gegl/gimpoperationlayermode.c	(original)
+++ trunk/app/gegl/gimpoperationlayermode.c	Sat Oct 25 09:47:09 2008
@@ -21,6 +21,7 @@
 
 #include "config.h"
 
+#include <babl/babl.h>
 #include <gegl.h>
 
 #include "gegl-types.h"
@@ -28,6 +29,7 @@
 #include "gimpoperationlayermode.h"
 
 
+static void     gimp_operation_layer_mode_prepare (GeglOperation       *operation);
 static gboolean gimp_operation_layer_mode_process (GeglOperation       *operation,
                                                    void                *in_buf,
                                                    void                *aux_buf,
@@ -48,6 +50,8 @@
 
   operation_class->categories = "compositors";
 
+  operation_class->prepare    = gimp_operation_layer_mode_prepare;
+
   point_class->process        = gimp_operation_layer_mode_process;
 }
 
@@ -56,6 +60,16 @@
 {
 }
 
+static void
+gimp_operation_layer_mode_prepare (GeglOperation *operation)
+{
+  Babl *format = babl_format ("RaGaBaA float");
+
+  gegl_operation_set_format (operation, "input",  format);
+  gegl_operation_set_format (operation, "output", format);
+  gegl_operation_set_format (operation, "aux",    format);
+}
+
 static gboolean
 gimp_operation_layer_mode_process (GeglOperation       *operation,
                                    void                *in_buf,



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