Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ImageView.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-10-01 20:15:35 (GMT)
committer Agustin Zubiaga <aguz@sugarlabs.org>2012-10-02 03:24:05 (GMT)
commitecb1f86526376bd8ddad004c50a157b1d0d2fb5b (patch)
tree5043dd7554417cb6a57906f0695275d914008f2e /ImageView.py
parente7f0e684a48ce1a7ad076e31ab3c7a068dbb50c1 (diff)
Use similar surface to improve performance
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org> Signed-off-by: Agustin Zubiaga <aguz@sugarlabs.org>
Diffstat (limited to 'ImageView.py')
-rw-r--r--ImageView.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/ImageView.py b/ImageView.py
index d73965d..cbfa560 100644
--- a/ImageView.py
+++ b/ImageView.py
@@ -100,7 +100,16 @@ class ImageViewer(Gtk.DrawingArea):
logging.debug('ImageViewer.draw start')
if self.surface is None:
- return
+ if self.file_location is None:
+ return
+
+ # http://cairographics.org/gdkpixbufpycairo/
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.file_location)
+ self.surface = ctx.get_target().create_similar(
+ cairo.CONTENT_COLOR_ALPHA, pixbuf.get_width(),
+ pixbuf.get_height())
+ ctx_surface = cairo.Context(self.surface)
+ self._pixbuf_to_context(pixbuf, ctx_surface)
if self.zoom is None:
self.zoom = self._calc_optimal_zoom()
@@ -176,14 +185,6 @@ class ImageViewer(Gtk.DrawingArea):
def set_file_location(self, file_location):
logging.debug('Loading image from: %s', file_location)
- # http://cairographics.org/gdkpixbufpycairo/
- pixbuf = GdkPixbuf.Pixbuf.new_from_file(file_location)
-
- self.surface = cairo.ImageSurface(
- cairo.FORMAT_ARGB32, pixbuf.get_width(), pixbuf.get_height())
- ctx = cairo.Context(self.surface)
- self._pixbuf_to_context(pixbuf, ctx)
-
self.file_location = file_location
self.zoom = None
self.queue_draw()