Re: [Synfig-devl] Rv: Cairo implementation roadmap

2012-10-03 Thread Carlos López González
Hi!
This morning I came out with another simper solution for the STRAIGHT method!
It is very exciting!
The code I previously figured out was this:

/// OLD CODE
cairo_save(cr);

// This part would retrieve the current passed surface and copy it on destimage
cairo_surface_t* dest=cairo_get_target(cr);
cairo_surface_flush(dest);
cairo_surface_t* destimage=cairo_surface_map_to_image(dest, NULL);

// Then using destimage width and height create newdest
int w=cairo_image_surface_get_width(destimage);
int h=cairo_image_surface_get_height(destimage);
cairo_surface_t* newdest=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);

// Now I paint destimage to newdest with a 1.0 -alpha mask
cairo_t* destcr=cairo_create(newdest);
cairo_set_source_surface(destcr, destimage, 0, 0);
cairo_paint_with_alpha(destcr, 1.0-alpha);
cairo_destroy(destcr);

// Here I rewrite the newdest to destimage
destcr=cairo_create(destimage);
cairo_set_source_surface(destcr, newdest, 0, 0);
cairo_set_operator(destcr, CAIRO_OPERATOR_SOURCE);
cairo_paint(destcr);
cairo_destroy(destcr);

// and update the cr target (dest)
cairo_surface_unmap_image(dest, destimage);
cairo_surface_mark_dirty(dest);

// destroy and restore
cairo_surface_destroy(newdest);
cairo_restore(cr);

// Finally I paint with he ADD operator using alpha for the current
cairo_t commands
cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
cairo_paint_with_alpha(cr, alpha);

// OLD CODE - end

And I asked my self: Is there other way to fade out a given surface?
The solution I did was: extract image, paint with 1.0-alpha, paint
back and extract back.

I think that I can directly paint on the given surface without need to
map and unmap. Also I've found a way to fade out a surface in a single
operation:

//  NEW CODE
// First save the context status
cairo_save(cr);

// Second paint with the DEST_IN operator.
// It would achieve the following result:
// aR=aA*aB
// xR=xB
// which is exactly to fade out the destination surface
// by the alpha of the source (1.0-alpha in this case)
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0-alpha);
cairo_set_operator(cr, CAIRO_OPERATOR_DEST_IN);
cairo_paint(cr);

// Then restore the cairo context
cairo_restore(cr);

// Then paint using the ADD operator and the alpha value
cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
cairo_paint_with_alpha(cr, alpha);
//  NEW CODE end

I cannot test it right now, but I'm very excited on I have found a way
to perform the desired blending operation with atomic Cairo
instructions!!

Cheers!

2012/10/2 Carlos López González genet...@gmail.com:
 Thanks Konstantin. Your backing helps a lot.

 I've finally figured out how to emulate the STRAIGHT blend method
 operation in Cairo.
 It is an important milestone because I'm confident on being able to
 emulate the Synfig's
 blend methods that aren't directly supported by Cairo just using a
 combination of Cairo's operators.
 This means that the performance when blending can have the full
 benefit of use Cairo native API.
 It is possible that some of the Synfig's blend methods gets difficult
 to emulate or impossible but
 I hope they would be the less used.

 Cheers!

 2012/9/29 Konstantin Dmitriev ksee.zelga...@gmail.com:
 2012/9/29 Carlos López González genet...@gmail.com:
 Hi!
 I've added Cairo support for Shade and Bevel layers.
 Again the results are very similar but slightly slower. These kind of layers
 that manipulate pixels directly doesn't seem to improve much using Cairo
 colors. In fact they loose time doing some unwanted operations (due
 premultiplied and due to need to convert alpha to a 0-1 range) that doesn't
 compensate the supposed speed increase for handling unsigned char in memory.

 I've seen that there are room for some improvements in the Paste Canvas
 layer because in Cairo I didn't clip the Paste Canvas's canvas's context
 because I didn't understand what was doing the Software. Now that I know
 more about Cairo and that I understand what does Paste Canvas do, I could
 try to use clip in Cairo render and so the things should improve the speed
 for all the encapsulated layers that have defined boundaries.

 Hi, Carlos!
 It's awesom to see such a progress.
 From some moment this week I've got a strong feeling that  the
 finished cairo implementation is somewhere near, on the horizon. That
 is awesome. Of course, there's still a lot of work, I understand. But
 it will be such a significant step even if we will not gain desired
 speed increase!
 Please keep your hard work!
 Thank you!
 K.



 --
 http://morevnaproject.org/

 --
 How fast is your code?
 3 out of 4 devs don\\\'t know how their code performs in production.
 Find out how slow your code is with AppDynamics Lite.
 http://ad.doubleclick.net/clk;262219672;13503038;z?
 

Re: [Synfig-devl] Rv: Cairo implementation roadmap

2012-10-03 Thread Timothée Giet
Great!

Carlos, you rock :)

2012/10/3 Carlos López González genet...@gmail.com

 Hi!
 This morning I came out with another simper solution for the STRAIGHT
 method!
 It is very exciting!
 The code I previously figured out was this:

 /// OLD CODE
 cairo_save(cr);

 // This part would retrieve the current passed surface and copy it on
 destimage
 cairo_surface_t* dest=cairo_get_target(cr);
 cairo_surface_flush(dest);
 cairo_surface_t* destimage=cairo_surface_map_to_image(dest, NULL);

 // Then using destimage width and height create newdest
 int w=cairo_image_surface_get_width(destimage);
 int h=cairo_image_surface_get_height(destimage);
 cairo_surface_t* newdest=cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
 w, h);

 // Now I paint destimage to newdest with a 1.0 -alpha mask
 cairo_t* destcr=cairo_create(newdest);
 cairo_set_source_surface(destcr, destimage, 0, 0);
 cairo_paint_with_alpha(destcr, 1.0-alpha);
 cairo_destroy(destcr);

 // Here I rewrite the newdest to destimage
 destcr=cairo_create(destimage);
 cairo_set_source_surface(destcr, newdest, 0, 0);
 cairo_set_operator(destcr, CAIRO_OPERATOR_SOURCE);
 cairo_paint(destcr);
 cairo_destroy(destcr);

 // and update the cr target (dest)
 cairo_surface_unmap_image(dest, destimage);
 cairo_surface_mark_dirty(dest);

 // destroy and restore
 cairo_surface_destroy(newdest);
 cairo_restore(cr);

 // Finally I paint with he ADD operator using alpha for the current
 cairo_t commands
 cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
 cairo_paint_with_alpha(cr, alpha);

 // OLD CODE - end

 And I asked my self: Is there other way to fade out a given surface?
 The solution I did was: extract image, paint with 1.0-alpha, paint
 back and extract back.

 I think that I can directly paint on the given surface without need to
 map and unmap. Also I've found a way to fade out a surface in a single
 operation:

 //  NEW CODE
 // First save the context status
 cairo_save(cr);

 // Second paint with the DEST_IN operator.
 // It would achieve the following result:
 // aR=aA*aB
 // xR=xB
 // which is exactly to fade out the destination surface
 // by the alpha of the source (1.0-alpha in this case)
 cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0-alpha);
 cairo_set_operator(cr, CAIRO_OPERATOR_DEST_IN);
 cairo_paint(cr);

 // Then restore the cairo context
 cairo_restore(cr);

 // Then paint using the ADD operator and the alpha value
 cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
 cairo_paint_with_alpha(cr, alpha);
 //  NEW CODE end

 I cannot test it right now, but I'm very excited on I have found a way
 to perform the desired blending operation with atomic Cairo
 instructions!!

 Cheers!

 2012/10/2 Carlos López González genet...@gmail.com:
  Thanks Konstantin. Your backing helps a lot.
 
  I've finally figured out how to emulate the STRAIGHT blend method
  operation in Cairo.
  It is an important milestone because I'm confident on being able to
  emulate the Synfig's
  blend methods that aren't directly supported by Cairo just using a
  combination of Cairo's operators.
  This means that the performance when blending can have the full
  benefit of use Cairo native API.
  It is possible that some of the Synfig's blend methods gets difficult
  to emulate or impossible but
  I hope they would be the less used.
 
  Cheers!
 
  2012/9/29 Konstantin Dmitriev ksee.zelga...@gmail.com:
  2012/9/29 Carlos López González genet...@gmail.com:
  Hi!
  I've added Cairo support for Shade and Bevel layers.
  Again the results are very similar but slightly slower. These kind of
 layers
  that manipulate pixels directly doesn't seem to improve much using
 Cairo
  colors. In fact they loose time doing some unwanted operations (due
  premultiplied and due to need to convert alpha to a 0-1 range) that
 doesn't
  compensate the supposed speed increase for handling unsigned char in
 memory.
 
  I've seen that there are room for some improvements in the Paste Canvas
  layer because in Cairo I didn't clip the Paste Canvas's canvas's
 context
  because I didn't understand what was doing the Software. Now that I
 know
  more about Cairo and that I understand what does Paste Canvas do, I
 could
  try to use clip in Cairo render and so the things should improve the
 speed
  for all the encapsulated layers that have defined boundaries.
 
  Hi, Carlos!
  It's awesom to see such a progress.
  From some moment this week I've got a strong feeling that  the
  finished cairo implementation is somewhere near, on the horizon. That
  is awesome. Of course, there's still a lot of work, I understand. But
  it will be such a significant step even if we will not gain desired
  speed increase!
  Please keep your hard work!
  Thank you!
  K.
 
 
 
  --
  http://morevnaproject.org/
 
 
 --
  How fast is your code?
  

Re: [Synfig-devl] Rv: Cairo implementation roadmap

2012-10-03 Thread Joshua Bell
Agreed. You're a legend, Carlos.

Timothée Giet anim...@gmail.com wrote:

Great!

Carlos, you rock :)

2012/10/3 Carlos López González genet...@gmail.com

 Hi!
 This morning I came out with another simper solution for the STRAIGHT
 method!
 It is very exciting!
 The code I previously figured out was this:

 /// OLD CODE
 cairo_save(cr);

 // This part would retrieve the current passed surface and copy it on
 destimage
 cairo_surface_t* dest=cairo_get_target(cr);
 cairo_surface_flush(dest);
 cairo_surface_t* destimage=cairo_surface_map_to_image(dest, NULL);

 // Then using destimage width and height create newdest
 int w=cairo_image_surface_get_width(destimage);
 int h=cairo_image_surface_get_height(destimage);
 cairo_surface_t*
newdest=cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
 w, h);

 // Now I paint destimage to newdest with a 1.0 -alpha mask
 cairo_t* destcr=cairo_create(newdest);
 cairo_set_source_surface(destcr, destimage, 0, 0);
 cairo_paint_with_alpha(destcr, 1.0-alpha);
 cairo_destroy(destcr);

 // Here I rewrite the newdest to destimage
 destcr=cairo_create(destimage);
 cairo_set_source_surface(destcr, newdest, 0, 0);
 cairo_set_operator(destcr, CAIRO_OPERATOR_SOURCE);
 cairo_paint(destcr);
 cairo_destroy(destcr);

 // and update the cr target (dest)
 cairo_surface_unmap_image(dest, destimage);
 cairo_surface_mark_dirty(dest);

 // destroy and restore
 cairo_surface_destroy(newdest);
 cairo_restore(cr);

 // Finally I paint with he ADD operator using alpha for the current
 cairo_t commands
 cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
 cairo_paint_with_alpha(cr, alpha);

 // OLD CODE - end

 And I asked my self: Is there other way to fade out a given surface?
 The solution I did was: extract image, paint with 1.0-alpha, paint
 back and extract back.

 I think that I can directly paint on the given surface without need
to
 map and unmap. Also I've found a way to fade out a surface in a
single
 operation:

 //  NEW CODE
 // First save the context status
 cairo_save(cr);

 // Second paint with the DEST_IN operator.
 // It would achieve the following result:
 // aR=aA*aB
 // xR=xB
 // which is exactly to fade out the destination surface
 // by the alpha of the source (1.0-alpha in this case)
 cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0-alpha);
 cairo_set_operator(cr, CAIRO_OPERATOR_DEST_IN);
 cairo_paint(cr);

 // Then restore the cairo context
 cairo_restore(cr);

 // Then paint using the ADD operator and the alpha value
 cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
 cairo_paint_with_alpha(cr, alpha);
 //  NEW CODE end

 I cannot test it right now, but I'm very excited on I have found a
way
 to perform the desired blending operation with atomic Cairo
 instructions!!

 Cheers!

 2012/10/2 Carlos López González genet...@gmail.com:
  Thanks Konstantin. Your backing helps a lot.
 
  I've finally figured out how to emulate the STRAIGHT blend method
  operation in Cairo.
  It is an important milestone because I'm confident on being able to
  emulate the Synfig's
  blend methods that aren't directly supported by Cairo just using a
  combination of Cairo's operators.
  This means that the performance when blending can have the full
  benefit of use Cairo native API.
  It is possible that some of the Synfig's blend methods gets
difficult
  to emulate or impossible but
  I hope they would be the less used.
 
  Cheers!
 
  2012/9/29 Konstantin Dmitriev ksee.zelga...@gmail.com:
  2012/9/29 Carlos López González genet...@gmail.com:
  Hi!
  I've added Cairo support for Shade and Bevel layers.
  Again the results are very similar but slightly slower. These
kind of
 layers
  that manipulate pixels directly doesn't seem to improve much
using
 Cairo
  colors. In fact they loose time doing some unwanted operations
(due
  premultiplied and due to need to convert alpha to a 0-1 range)
that
 doesn't
  compensate the supposed speed increase for handling unsigned char
in
 memory.
 
  I've seen that there are room for some improvements in the Paste
Canvas
  layer because in Cairo I didn't clip the Paste Canvas's canvas's
 context
  because I didn't understand what was doing the Software. Now that
I
 know
  more about Cairo and that I understand what does Paste Canvas do,
I
 could
  try to use clip in Cairo render and so the things should improve
the
 speed
  for all the encapsulated layers that have defined boundaries.
 
  Hi, Carlos!
  It's awesom to see such a progress.
  From some moment this week I've got a strong feeling that  the
  finished cairo implementation is somewhere near, on the horizon.
That
  is awesome. Of course, there's still a lot of work, I understand.
But
  it will be such a significant step even if we will not gain
desired
  speed increase!
  Please keep your hard work!
  Thank you!
  K.
 
 
 
  --
  http://morevnaproject.org/
 
 


[Synfig-devl] Carlos Lopez : Cairo operators: simplify the Straight method

2012-10-03 Thread root
Author: Carlos Lopez genet...@gmail.com
Date:   Wed Oct  3 22:00:37 2012 +0200

Cairo operators: simplify the Straight method

---

 synfig-core/src/synfig/cairo_operators.cpp |   28 +---
 1 files changed, 5 insertions(+), 23 deletions(-)

diff --git a/synfig-core/src/synfig/cairo_operators.cpp 
b/synfig-core/src/synfig/cairo_operators.cpp
index 42311fd..55b0f60 100644
--- a/synfig-core/src/synfig/cairo_operators.cpp
+++ b/synfig-core/src/synfig/cairo_operators.cpp
@@ -61,32 +61,14 @@ void cairo_paint_with_alpha_operator(cairo_t* acr, float 
alpha, Color::BlendMeth
{
cairo_save(cr);

-   cairo_surface_t* dest=cairo_get_target(cr);
-   cairo_surface_flush(dest);
-   cairo_surface_t* 
destimage=cairo_surface_map_to_image(dest, NULL);
-   int w=cairo_image_surface_get_width(destimage);
-   int h=cairo_image_surface_get_height(destimage);
-   cairo_surface_t* 
newdest=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
+   cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0-alpha);
+   cairo_set_operator(cr, CAIRO_OPERATOR_DEST_IN);
+   cairo_paint(cr);

-   cairo_t* destcr=cairo_create(newdest);
-   cairo_set_source_surface(destcr, destimage, 0, 0);
-   cairo_paint_with_alpha(destcr, 1.0-alpha);
-   cairo_destroy(destcr);
-   
-   destcr=cairo_create(destimage);
-   cairo_set_source_surface(destcr, newdest, 0, 0);
-   cairo_set_operator(destcr, CAIRO_OPERATOR_SOURCE);
-   cairo_paint(destcr);
-   cairo_destroy(destcr);
-   
-   cairo_surface_unmap_image(dest, destimage);
-   cairo_surface_mark_dirty(dest);
-   
-   cairo_surface_destroy(newdest);
cairo_restore(cr);
-
+   
cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
-   cairo_paint_with_alpha(cr, alpha);
+   cairo_paint_with_alpha(cr, alpha);  
break;
}
case Color::BLEND_BEHIND:


--
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
Synfig-devl@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synfig-devl