Code

(Partial) fix to nr-filter-image + some (small) changes to nr-filter-blend and nr...
authorjaspervdg <jaspervdg@users.sourceforge.net>
Sun, 4 Jan 2009 16:07:08 +0000 (16:07 +0000)
committerjaspervdg <jaspervdg@users.sourceforge.net>
Sun, 4 Jan 2009 16:07:08 +0000 (16:07 +0000)
src/display/nr-filter-blend.cpp
src/display/nr-filter-composite.cpp
src/display/nr-filter-image.cpp

index 2a066b5635ce10a7ea5b8bf75984083481dd1418..4645d9bc063a8bf0493e202e0b54ff4f5f0365b3 100644 (file)
@@ -8,8 +8,9 @@
  *
  * Authors:
  *   Niko Kiirala <niko@kiirala.com>
+ *   Jasper van de Gronde <th.v.d.gronde@hccnet.nl>
  *
- * Copyright (C) 2007 authors
+ * Copyright (C) 2007-2008 authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -57,9 +58,9 @@ namespace Filters {
 inline void
 blend_normal(unsigned char *r, unsigned char const *a, unsigned char const *b)
 {
-    r[0] = NR_NORMALIZE_21((255 - a[3]) * b[0]) + a[0];
-    r[1] = NR_NORMALIZE_21((255 - a[3]) * b[1]) + a[1];
-    r[2] = NR_NORMALIZE_21((255 - a[3]) * b[2]) + a[2];
+    r[0] = NR_COMPOSEPPP_1111(a[0],a[3],b[0]);
+    r[1] = NR_COMPOSEPPP_1111(a[1],a[3],b[1]);
+    r[2] = NR_COMPOSEPPP_1111(a[2],a[3],b[2]);
     SET_ALPHA;
 }
 
@@ -80,9 +81,9 @@ blend_multiply(unsigned char *r, unsigned char const *a, unsigned char const *b)
 inline void
 blend_screen(unsigned char *r, unsigned char const *a, unsigned char const *b)
 {
-    r[0] = NR_NORMALIZE_21(b[0] * 255 + a[0] * 255 - a[0] * b[0]);
-    r[1] = NR_NORMALIZE_21(b[1] * 255 + a[1] * 255 - a[1] * b[1]);
-    r[2] = NR_NORMALIZE_21(b[2] * 255 + a[2] * 255 - a[2] * b[2]);
+    r[0] = NR_NORMALIZE_21((b[0] + a[0]) * 255 - a[0] * b[0]);
+    r[1] = NR_NORMALIZE_21((b[1] + a[1]) * 255 - a[1] * b[1]);
+    r[2] = NR_NORMALIZE_21((b[2] + a[2]) * 255 - a[2] * b[2]);
     SET_ALPHA;
 }
 
@@ -90,12 +91,12 @@ blend_screen(unsigned char *r, unsigned char const *a, unsigned char const *b)
 inline void
 blend_darken(unsigned char *r, unsigned char const *a, unsigned char const *b)
 {
-    r[0] = std::min(NR_NORMALIZE_21((255 - a[3]) * b[0]) + a[0],
-                    NR_NORMALIZE_21((255 - b[3]) * a[0]) + b[0]);
-    r[1] = std::min(NR_NORMALIZE_21((255 - a[3]) * b[1]) + a[1],
-                    NR_NORMALIZE_21((255 - b[3]) * a[1]) + b[1]);
-    r[2] = std::min(NR_NORMALIZE_21((255 - a[3]) * b[2]) + a[2],
-                    NR_NORMALIZE_21((255 - b[3]) * a[2]) + b[2]);
+    r[0] = NR_NORMALIZE_21(std::min(NR_COMPOSEPPP_1112(a[0],a[3],b[0]),
+                                    NR_COMPOSEPPP_1112(b[0],b[3],a[0])));
+    r[1] = NR_NORMALIZE_21(std::min(NR_COMPOSEPPP_1112(a[1],a[3],b[1]),
+                                    NR_COMPOSEPPP_1112(b[1],b[3],a[1])));
+    r[2] = NR_NORMALIZE_21(std::min(NR_COMPOSEPPP_1112(a[2],a[3],b[2]),
+                                    NR_COMPOSEPPP_1112(b[2],b[3],a[2])));
     SET_ALPHA;
 }
 
@@ -103,12 +104,12 @@ blend_darken(unsigned char *r, unsigned char const *a, unsigned char const *b)
 inline void
 blend_lighten(unsigned char *r, unsigned char const *a, unsigned char const *b)
 {
-    r[0] = std::max(NR_NORMALIZE_21((255 - a[3]) * b[0]) + a[0],
-                    NR_NORMALIZE_21((255 - b[3]) * a[0]) + b[0]);
-    r[1] = std::max(NR_NORMALIZE_21((255 - a[3]) * b[1]) + a[1],
-                    NR_NORMALIZE_21((255 - b[3]) * a[1]) + b[1]);
-    r[2] = std::max(NR_NORMALIZE_21((255 - a[3]) * b[2]) + a[2],
-                    NR_NORMALIZE_21((255 - b[3]) * a[2]) + b[2]);
+    r[0] = NR_NORMALIZE_21(std::max(NR_COMPOSEPPP_1112(a[0],a[3],b[0]),
+                                    NR_COMPOSEPPP_1112(b[0],b[3],a[0])));
+    r[1] = NR_NORMALIZE_21(std::max(NR_COMPOSEPPP_1112(a[1],a[3],b[1]),
+                                    NR_COMPOSEPPP_1112(b[1],b[3],a[1])));
+    r[2] = NR_NORMALIZE_21(std::max(NR_COMPOSEPPP_1112(a[2],a[3],b[2]),
+                                    NR_COMPOSEPPP_1112(b[2],b[3],a[2])));
     SET_ALPHA;
 }
 
index 34a2d2e63672c3372e34332c0906f8da6e136214..ba25c4a80c0e77fa9017c9b267d987e4155cca22 100644 (file)
 inline void
 composite_over(unsigned char *r, unsigned char const *a, unsigned char const *b)
 {
-    r[0] = a[0] + NR_NORMALIZE_21(b[0] * (255 - a[3]));
-    r[1] = a[1] + NR_NORMALIZE_21(b[1] * (255 - a[3]));
-    r[2] = a[2] + NR_NORMALIZE_21(b[2] * (255 - a[3]));
-    r[3] = a[3] + NR_NORMALIZE_21(b[3] * (255 - a[3]));
+    r[0] = NR_COMPOSEPPP_1111(a[0],a[3],b[0]);
+    r[1] = NR_COMPOSEPPP_1111(a[1],a[3],b[1]);
+    r[2] = NR_COMPOSEPPP_1111(a[2],a[3],b[2]);
+    r[3] = NR_COMPOSEPPP_1111(a[3],a[3],b[3]);
 }
 
 inline void
@@ -122,19 +122,19 @@ int FilterComposite::render(FilterSlot &slot, FilterUnits const &/*units*/) {
     // Blending modes are defined for premultiplied RGBA values,
     // thus convert them to that format before blending
     if (in1->mode != NR_PIXBLOCK_MODE_R8G8B8A8P) {
-        in1 = new NRPixBlock;
-        nr_pixblock_setup_fast(in1, NR_PIXBLOCK_MODE_R8G8B8A8P,
-                               original_in1->area.x0, original_in1->area.y0,
-                               original_in1->area.x1, original_in1->area.y1,
-                               false);
+        g_warning("in1 conversion");
+        in1 = nr_pixblock_new_fast(NR_PIXBLOCK_MODE_R8G8B8A8P,
+                                   original_in1->area.x0, original_in1->area.y0,
+                                   original_in1->area.x1, original_in1->area.y1,
+                                   false);
         nr_blit_pixblock_pixblock(in1, original_in1);
     }
     if (in2->mode != NR_PIXBLOCK_MODE_R8G8B8A8P) {
-        in2 = new NRPixBlock;
-        nr_pixblock_setup_fast(in2, NR_PIXBLOCK_MODE_R8G8B8A8P,
-                               original_in2->area.x0, original_in2->area.y0,
-                               original_in2->area.x1, original_in2->area.y1,
-                               false);
+        g_warning("in2 conversion");
+        in2 = nr_pixblock_new_fast(NR_PIXBLOCK_MODE_R8G8B8A8P,
+                                   original_in2->area.x0, original_in2->area.y0,
+                                   original_in2->area.x1, original_in2->area.y1,
+                                   false);
         nr_blit_pixblock_pixblock(in2, original_in2);
     }
 
@@ -170,12 +170,10 @@ int FilterComposite::render(FilterSlot &slot, FilterUnits const &/*units*/) {
     }
 
     if (in1 != original_in1) {
-        nr_pixblock_release(in1);
-        delete in1;
+        nr_pixblock_free(in1);
     }
     if (in2 != original_in2) {
-        nr_pixblock_release(in2);
-        delete in2;
+        nr_pixblock_free(in2);
     }
 
     out->empty = FALSE;
index 986b6502d460fe1a72dae6be956333367d857f74..b6830a47a1c2d700365afa45cc02a087ce95f5aa 100644 (file)
@@ -83,7 +83,7 @@ int FilterImage::render(FilterSlot &slot, FilterUnits const &units) {
         nr_arena_item_invoke_update( ai, NULL, &gc,
                                              NR_ARENA_ITEM_STATE_ALL,
                                              NR_ARENA_ITEM_STATE_NONE );
-        nr_pixblock_setup_extern(pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
+        nr_pixblock_setup_extern(pb, NR_PIXBLOCK_MODE_R8G8B8A8P,
                               (int)rect.x0, (int)rect.y0, (int)rect.x1, (int)rect.y1,
                               image_pixbuf, 4 * width, FALSE, FALSE );
 
@@ -141,7 +141,7 @@ int FilterImage::render(FilterSlot &slot, FilterUnits const &units) {
     int x0 = in->area.x0, y0 = in->area.y0;
     int x1 = in->area.x1, y1 = in->area.y1;
     NRPixBlock *out = new NRPixBlock;
-    nr_pixblock_setup_fast(out, in->mode, x0, y0, x1, y1, true);
+    nr_pixblock_setup_fast(out, from_element?NR_PIXBLOCK_MODE_R8G8B8A8P:NR_PIXBLOCK_MODE_R8G8B8A8N, x0, y0, x1, y1, true);
     w = x1 - x0;
 
     // Get the object bounding box. Image is placed with respect to box.