Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorC. Scott Ananian <cscott@cscott.net>2011-11-10 23:33:09 (GMT)
committer C. Scott Ananian <cscott@cscott.net>2011-11-10 23:33:09 (GMT)
commit79f5678feeb16910c27ac6c24e93ca0f8b479c8d (patch)
tree71e79afc594338dd56f1d2dea5737cf30e993272
parent5a01e94347c1cd78b0deb4fc64c649536ae6ac1f (diff)
Fix 'read pixel' operation under GTK3 (now faster in GTK2 as well).
-rw-r--r--TurtleArt/tacanvas.py14
-rw-r--r--util/gtkcompat.py11
2 files changed, 16 insertions, 9 deletions
diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py
index ac20092..8b294a9 100644
--- a/TurtleArt/tacanvas.py
+++ b/TurtleArt/tacanvas.py
@@ -700,16 +700,12 @@ class TurtleGraphics:
h = self.tw.turtle_canvas.get_height()
if x < 0 or x > (w - 1) or y < 0 or y > (h - 1):
return(-1, -1, -1, -1)
- # Map the cairo surface onto a pixmap
- pixmap = gtk.gdk.Pixmap(None, w, h, 24)
- cr = pixmap.cairo_create()
- cr.set_source_surface(self.tw.turtle_canvas, 0, 0)
- cr.paint()
+ # Map the cairo surface onto a pixbuf
+ pixbuf = Gdk.pixbuf_get_from_surface(self.tw.turtle_canvas,
+ x, y, 1, 1)
# Read the pixel
- pixel = pixmap.get_image(x, y, 1, 1).get_pixel(0, 0)
- return(int((pixel & 0xFF0000) >> 16),
- int((pixel & 0x00FF00) >> 8),
- int((pixel & 0x0000FF) >> 0), 0)
+ pixels = pixbuf.get_pixels()
+ return (ord(pixels[0]), ord(pixels[1]), ord(pixels[2]), 0)
else:
return(-1, -1, -1, -1)
diff --git a/util/gtkcompat.py b/util/gtkcompat.py
index c188a13..87622b8 100644
--- a/util/gtkcompat.py
+++ b/util/gtkcompat.py
@@ -29,6 +29,7 @@ except ValueError, ImportError:
import gconf
import pango as Pango
import pangocairo as PangoCairo
+ import cairo
Gdk = Gtk.gdk
Rectangle = Gdk.Rectangle
@@ -42,6 +43,16 @@ except ValueError, ImportError:
Gdk.cairo_set_source_pixbuf = \
lambda cr, img, x, y: cr.set_source_pixbuf(img, x, y)
+ def gdk_pixbuf_get_from_surface(surface, x, y, w, h):
+ pixmap = Gdk.Pixmap(None, w, h, 24)
+ cr = pixmap.cairo_create()
+ cr.set_source_surface(surface, -x, -y)
+ cr.rectangle(0,0,w,h);
+ cr.set_operator(cairo.OPERATOR_SOURCE)
+ cr.fill()
+ cmap = Gdk.colormap_get_system()
+ return Gdk.pixbuf_get_from_drawable(None, pixmap, cmap, 0, 0, 0, 0, w, h)
+ Gdk.pixbuf_get_from_surface = gdk_pixbuf_get_from_surface
class GdkEventMask:
EXPOSURE_MASK = Gdk.EXPOSURE_MASK