Author: Carlos Lopez <[email protected]>
Date: Fri Oct 12 12:30:17 2012 +0200
Cairo operators: add code for Brighten blend method. The result is not exactly
the same and could be fixed later doing pixel operations.
---
synfig-core/src/modules/mod_geometry/rectangle.cpp | 4 +-
synfig-core/src/synfig/cairo_operators.cpp | 43 ++++++++++++++++++++
synfig-core/src/synfig/cairo_operators.h | 5 ++
3 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/synfig-core/src/modules/mod_geometry/rectangle.cpp
b/synfig-core/src/modules/mod_geometry/rectangle.cpp
index 9bb6ad2..b182d7b 100644
--- a/synfig-core/src/modules/mod_geometry/rectangle.cpp
+++ b/synfig-core/src/modules/mod_geometry/rectangle.cpp
@@ -727,7 +727,7 @@ Rectangle::accelerated_cairorender(Context
context,cairo_surface_t *surface,int
// In the case where there is nothing to render...
if (inter.area()<0.00000001)
return true;
-
+ cairo_save(cr);
cairo_set_source_rgba(cr, r, g, b, a);
double width (inter_max[0]-inter_min[0]);
double height(inter_max[1]-inter_min[1]);
@@ -740,7 +740,7 @@ Rectangle::accelerated_cairorender(Context
context,cairo_surface_t *surface,int
cairo_rectangle(cr, inter_min[0], inter_min[1], width, height);
cairo_clip(cr);
cairo_paint_with_alpha_operator(cr, get_amount(), get_blend_method());
- synfig::info("rectangle operator %d", get_blend_method());
+ cairo_restore(cr);
cairo_destroy(cr);
return true;
}
diff --git a/synfig-core/src/synfig/cairo_operators.cpp
b/synfig-core/src/synfig/cairo_operators.cpp
index 55b0f60..4e9645e 100644
--- a/synfig-core/src/synfig/cairo_operators.cpp
+++ b/synfig-core/src/synfig/cairo_operators.cpp
@@ -30,6 +30,7 @@
#endif
#include "cairo_operators.h"
+#include "general.h"
#endif
@@ -71,6 +72,16 @@ void cairo_paint_with_alpha_operator(cairo_t* acr, float
alpha, Color::BlendMeth
cairo_paint_with_alpha(cr, alpha);
break;
}
+ case Color::BLEND_BRIGHTEN:
+ {
+
+ cairo_surface_t*
dest=cairo_copy_target_image(cairo_get_target(cr), alpha);
+ cairo_set_operator(cr, CAIRO_OPERATOR_HSL_LUMINOSITY);
+ cairo_identity_matrix(cr);
+ cairo_mask_surface(cr, dest, 0,0);
+ cairo_surface_destroy(dest);
+ break;
+ }
case Color::BLEND_BEHIND:
{
cairo_set_operator(cr, CAIRO_OPERATOR_DEST_OVER);
@@ -99,6 +110,38 @@ void cairo_paint_with_alpha_operator(cairo_t* acr, float
alpha, Color::BlendMeth
cairo_destroy(cr);
}
+void cairo_copy_surface(cairo_surface_t* source, cairo_surface_t* dest, float
alpha)
+{
+ cairo_t* cr=cairo_create(dest);
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_surface(cr, source, 0, 0);
+ cairo_paint_with_alpha(cr, alpha);
+ cairo_destroy(cr);
+}
+
+cairo_surface_t* cairo_copy_target_image(cairo_surface_t* target, float alpha)
+{
+ cairo_surface_t* targetimage=cairo_surface_map_to_image(target, NULL);
+ cairo_surface_flush(targetimage);
+ int w=cairo_image_surface_get_width(targetimage);
+ int h=cairo_image_surface_get_height(targetimage);
+ cairo_surface_t* image=cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
w, h);
+ cairo_copy_surface(targetimage, image, alpha);
+ cairo_surface_mark_dirty(targetimage);
+ cairo_surface_unmap_image(target, targetimage);
+ return image;
+}
+
+void cairo_surface_mask_alpha(cairo_surface_t* image, float alpha)
+{
+ cairo_t* cr=cairo_create(image);
+ cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
+ cairo_set_operator(cr, CAIRO_OPERATOR_ATOP);
+ cairo_paint_with_alpha(cr, alpha);
+ cairo_destroy(cr);
+
+}
+
/* === M E T H O D S ======================================================= */
diff --git a/synfig-core/src/synfig/cairo_operators.h
b/synfig-core/src/synfig/cairo_operators.h
index 73f3050..43fcdce 100644
--- a/synfig-core/src/synfig/cairo_operators.h
+++ b/synfig-core/src/synfig/cairo_operators.h
@@ -36,6 +36,11 @@
/* === C L A S S E S & S T R U C T S ======================================= */
void cairo_paint_with_alpha_operator(cairo_t* cr, float alpha,
synfig::Color::BlendMethod method);
+void cairo_copy_surface(cairo_surface_t* source, cairo_surface_t* dest, float
alpha=1.0);
+cairo_surface_t* cairo_copy_target_image(cairo_surface_t* target, float
alpha=1.0);
+void cairo_surface_mask_alpha(cairo_surface_t* image, float alpha);
+
+
//void cairo_paint_operator(cairo_t* cr, Color::BlendMethod method);
//void cairo_stroke_operator(cairo_t* cr, Color::BlendMethod method);
//void cairo_fill_operator(cairo_t* cr, Color::BlendMethod method);
------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl