Author: Carlos Lopez <[email protected]>
Date: Thu Nov 22 20:15:38 2012 +0100
Cairo Operators: When the blend method is not directly supported, use a faster
way of compositing.
---
synfig-core/src/synfig/cairo_operators.cpp | 52 ++++++++++++++++-----------
1 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/synfig-core/src/synfig/cairo_operators.cpp
b/synfig-core/src/synfig/cairo_operators.cpp
index 667da2d..5a5d862 100644
--- a/synfig-core/src/synfig/cairo_operators.cpp
+++ b/synfig-core/src/synfig/cairo_operators.cpp
@@ -233,42 +233,52 @@ void cairo_paint_with_alpha_operator(cairo_t* acr, float
alpha, Color::BlendMeth
}
case Color::BLEND_ADD:
case Color::BLEND_SUBTRACT:
+ case Color::BLEND_DIFFERENCE:
case Color::BLEND_DIVIDE:
case Color::BLEND_ALPHA_BRIGHTEN:
case Color::BLEND_ALPHA_DARKEN:
default:
{
- cairo_surface_t* target=cairo_get_target(cr);
- cairo_surface_t* dest=cairo_copy_target_image(target);
-
- cairo_save(cr);
- cairo_reset_clip(cr);
- cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
- cairo_paint(cr);
- cairo_restore(cr);
-
+ cairo_push_group(cr);
cairo_paint(cr);
+ cairo_pattern_t* pattern=cairo_pop_group(cr);
- CairoSurface cresult(target);
- CairoSurface cdest(dest);
+ cairo_surface_t* source;
+ cairo_status_t status;
+ status=cairo_pattern_get_surface(pattern, &source);
+ if(status)
+ {
+ synfig::info("%s",
cairo_status_to_string(status));
+ return;
+ }
+ CairoSurface csource(source);
+ CairoSurface cdest(cairo_get_target(cr));
assert(cdest.map_cairo_image());
- assert(cresult.map_cairo_image());
-
- int w=cresult.get_w();
- int h=cresult.get_h();
+ assert(csource.map_cairo_image());
+
+ double x1, y1, x2, y2, x0, y0;
+ cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
+ cairo_user_to_device(cr, &x1, &y1);
+ cairo_user_to_device(cr, &x2, &y2);
+ x0=x2<x1?x2:x1;
+ y0=y2<y1?y2:y1;
+
+ int w=csource.get_w();
+ int h=csource.get_h();
+ int h0=(int)y0;
+ int w0=(int)x0;
for(int y=0;y<h;y++)
for(int x=0;x<w;x++)
{
- Color
src=Color(cresult[y][x].demult_alpha());
- Color
dst=Color(cdest[y][x].demult_alpha());
-
cresult[y][x]=CairoColor(Color::blend(src, dst, alpha,
method).clamped()).premult_alpha();
+ Color
src=Color(csource[y][x].demult_alpha());
+ Color
dst=Color(cdest[h0+y][w0+x].demult_alpha());
+
cdest[h0+y][w0+x]=CairoColor(Color::blend(src, dst, alpha,
method).clamped().premult_alpha());
}
-
- cresult.unmap_cairo_image();
+ csource.unmap_cairo_image();
cdest.unmap_cairo_image();
- cairo_surface_destroy(dest);
+ cairo_pattern_destroy(pattern);
break;
}
}
------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl