From: jaspervdg Date: Sun, 4 Jan 2009 16:07:08 +0000 (+0000) Subject: (Partial) fix to nr-filter-image + some (small) changes to nr-filter-blend and nr... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=790afca15126b9ad007ba17d4dd3e4f98a1ca76c;p=inkscape.git (Partial) fix to nr-filter-image + some (small) changes to nr-filter-blend and nr-filter-composite. --- diff --git a/src/display/nr-filter-blend.cpp b/src/display/nr-filter-blend.cpp index 2a066b563..4645d9bc0 100644 --- a/src/display/nr-filter-blend.cpp +++ b/src/display/nr-filter-blend.cpp @@ -8,8 +8,9 @@ * * Authors: * Niko Kiirala + * Jasper van de Gronde * - * 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; } diff --git a/src/display/nr-filter-composite.cpp b/src/display/nr-filter-composite.cpp index 34a2d2e63..ba25c4a80 100644 --- a/src/display/nr-filter-composite.cpp +++ b/src/display/nr-filter-composite.cpp @@ -25,10 +25,10 @@ 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; diff --git a/src/display/nr-filter-image.cpp b/src/display/nr-filter-image.cpp index 986b6502d..b6830a47a 100644 --- a/src/display/nr-filter-image.cpp +++ b/src/display/nr-filter-image.cpp @@ -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.