~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to enthought/chaco/image_plot.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-04-06 19:03:54 UTC
  • mfrom: (7.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110406190354-rwd55l2ezjecfo41
Tags: 3.4.0-2
d/rules: fix pyshared directory path (Closes: #621116)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
""" Defines the ImagePlot class.
2
2
"""
 
3
 
 
4
from __future__ import with_statement
 
5
 
3
6
# Standard library imports
4
7
from math import ceil, floor, pi
5
8
 
65
68
        if self.orientation == "v" and sx == sy:
66
69
            sx, sy = -sx, -sy
67
70
            
68
 
        gc.save_state()
69
 
        gc.clip_to_rect(self.x, self.y, self.width, self.height)
70
 
        gc.set_alpha(self.alpha)
 
71
        with gc:
 
72
            gc.clip_to_rect(self.x, self.y, self.width, self.height)
 
73
            gc.set_alpha(self.alpha)
71
74
 
72
 
        # Kiva image interpolation note:
73
 
        # Kiva's Agg backend uses the interpolation setting of the *source*
74
 
        # image to determine the type of interpolation to use when drawing the
75
 
        # image.  The mac backend uses the interpolation setting on the
76
 
        # destination GC.
77
 
        old_interp = self._cached_image.get_image_interpolation()
78
 
        if hasattr(gc, "set_interpolation_quality"):
79
 
            from enthought.kiva.mac.ABCGI import InterpolationQuality
80
 
            interp_quality_dict = {"nearest": InterpolationQuality.none,
81
 
                    "bilinear": InterpolationQuality.low,
82
 
                    "bicubic": InterpolationQuality.high}
83
 
            gc.set_interpolation_quality(interp_quality_dict[self.interpolation])
84
 
        elif hasattr(gc, "set_image_interpolation"):
85
 
            self._cached_image.set_image_interpolation(self.interpolation)
86
 
        x, y, w, h = self._cached_dest_rect
87
 
        if self.orientation == "h":        # for horizontal orientation:
88
 
            gc.translate_ctm(x+w/2, y+h/2)   # translate back normally
89
 
        else:                              # for vertical orientation:
90
 
            gc.translate_ctm(y+h/2, x+w/2)   # translate back with dx,dy swap
91
 
        gc.scale_ctm(sx, sy)               # flip axes as appropriate
92
 
        if self.orientation == "v":        # for vertical orientation:
93
 
            gc.scale_ctm(1,-1)               # restore origin to lower left
94
 
            gc.rotate_ctm(pi/2)              # rotate 1/4 turn clockwise
95
 
        gc.translate_ctm(-x-w/2, -y-h/2)   # translate image center to origin
96
 
        gc.draw_image(self._cached_image, self._cached_dest_rect)
97
 
        self._cached_image.set_image_interpolation(old_interp)
98
 
        gc.restore_state()
 
75
            # Kiva image interpolation note:
 
76
            # Kiva's Agg backend uses the interpolation setting of the *source*
 
77
            # image to determine the type of interpolation to use when drawing the
 
78
            # image.  The mac backend uses the interpolation setting on the
 
79
            # destination GC.
 
80
            old_interp = self._cached_image.get_image_interpolation()
 
81
            if hasattr(gc, "set_interpolation_quality"):
 
82
                from enthought.kiva.quartz.ABCGI import InterpolationQuality
 
83
                interp_quality_dict = {"nearest": InterpolationQuality.none,
 
84
                        "bilinear": InterpolationQuality.low,
 
85
                        "bicubic": InterpolationQuality.high}
 
86
                gc.set_interpolation_quality(interp_quality_dict[self.interpolation])
 
87
            elif hasattr(gc, "set_image_interpolation"):
 
88
                self._cached_image.set_image_interpolation(self.interpolation)
 
89
            x, y, w, h = self._cached_dest_rect
 
90
            if self.orientation == "h":        # for horizontal orientation:
 
91
                gc.translate_ctm(x+w/2, y+h/2)   # translate back normally
 
92
            else:                              # for vertical orientation:
 
93
                gc.translate_ctm(y+h/2, x+w/2)   # translate back with dx,dy swap
 
94
            gc.scale_ctm(sx, sy)               # flip axes as appropriate
 
95
            if self.orientation == "v":        # for vertical orientation:
 
96
                gc.scale_ctm(1,-1)               # restore origin to lower left
 
97
                gc.rotate_ctm(pi/2)              # rotate 1/4 turn clockwise
 
98
            gc.translate_ctm(-x-w/2, -y-h/2)   # translate image center to origin
 
99
            gc.draw_image(self._cached_image, self._cached_dest_rect)
 
100
            self._cached_image.set_image_interpolation(old_interp)
99
101
 
100
102
    def map_index(self, screen_pt, threshold=0.0, outside_returns_none=True,
101
103
                  index_only=False):