Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Area.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-07-05 14:16:24 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-08-10 13:49:29 (GMT)
commitde7c55ce9e1c170aa8aeade84bfc30834a277e44 (patch)
tree7081a8425c079e85533baaea84afe8f758374de9 /Area.py
parent292668290231e966bbc3629bd75f5c3853648ec4 (diff)
Port effects functionality to cairo
Grayscale, invert colors and mirror are implemented in this patch. NOTE: Invert colors is showing artifacts.
Diffstat (limited to 'Area.py')
-rw-r--r--Area.py54
1 files changed, 22 insertions, 32 deletions
diff --git a/Area.py b/Area.py
index 6839899..a25d44b 100644
--- a/Area.py
+++ b/Area.py
@@ -70,6 +70,7 @@ import tempfile
import math
import pango
import cairo
+import StringIO
from Desenho import Desenho
from urlparse import urlparse
@@ -1047,43 +1048,32 @@ class Area(gtk.DrawingArea):
def _do_process_internal(self, widget, apply_process):
- width, height = self.window.get_size()
-
if self.is_selected():
- _x, _y, width, height = self.get_selection_bounds()
- temp_pix = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8,
- width, height)
- temp_pix.get_from_drawable(self.pixmap_sel,
- gtk.gdk.colormap_get_system(), 0, 0, 0, 0, width, height)
+ x, y, width, height = self.get_selection_bounds()
+ surface = self.get_selection()
else:
- temp_pix = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8,
- width, height)
- temp_pix.get_from_drawable(self.pixmap,
- gtk.gdk.colormap_get_system(), 0, 0, 0, 0, width, height)
-
- temp_pix = apply_process(temp_pix)
-
- if self.is_selected():
- self.pixmap_sel.draw_pixbuf(self.gc, temp_pix, 0, 0, 0, 0,
- width, height, dither=gtk.gdk.RGB_DITHER_NORMAL,
- x_dither=0, y_dither=0)
+ x, y = 0, 0
+ width, height = self.window.get_size()
+ surface = self.drawing_canvas
- self.pixmap_temp.draw_drawable(self.gc, self.pixmap, 0, 0, 0, 0,
- width, height)
- self.pixmap_temp.draw_drawable(self.gc, self.pixmap_sel,
- 0, 0, self.orig_x, self.orig_y, width, height)
- self.set_selection_bounds(self.orig_x, self.orig_y, width,
- height)
+ # copy from the surface to the pixbuf
+ pixbuf_data = StringIO.StringIO()
+ surface.write_to_png(pixbuf_data)
+ pxb_loader = gtk.gdk.PixbufLoader(image_type='png')
+ pxb_loader.write(pixbuf_data.getvalue())
+ temp_pix = pxb_loader.get_pixbuf()
-# self.pixmap_temp.draw_rectangle(self.gc_selection, False,
-# self.orig_x, self.orig_y, size[0], size[1])
-# self.pixmap_temp.draw_rectangle(self.gc_selection1, False,
-# self.orig_x - 1, self.orig_y - 1, size[0] + 2, size[1] + 2)
+ # process the pixbuf
+ temp_pix = apply_process(temp_pix)
- else:
- self.pixmap.draw_pixbuf(self.gc, temp_pix, 0, 0, 0, 0,
- width, height, dither=gtk.gdk.RGB_DITHER_NORMAL,
- x_dither=0, y_dither=0)
+ # copy from the pixbuf to the drawing context
+ draw_gdk_ctx = gtk.gdk.CairoContext(self.drawing_ctx)
+ draw_gdk_ctx.save()
+ draw_gdk_ctx.translate(x, y)
+ draw_gdk_ctx.set_source_pixbuf(temp_pix, 0, 0)
+ draw_gdk_ctx.paint()
+ draw_gdk_ctx.restore()
+ self.create_selection_surface()
del temp_pix