예제 #1
0
파일: image.py 프로젝트: shaak/matplotlib
    def _draw_unsampled_image(self, renderer, gc):
        """
        draw unsampled image. The renderer should support a draw_image method
        with scale parameter.
        """
        trans = self.get_transform()  # axes.transData

        # convert the coordinates to the intermediate coordinate (ic).
        # The transformation from the ic to the canvas is a pure
        # affine transform.

        # A straight-forward way is to use the non-affine part of the
        # original transform for conversion to the ic.

        # firs, convert the image extent to the ic
        x_llc, x_trc, y_llc, y_trc = self.get_extent()

        xy = trans.transform(np.array([(x_llc, y_llc),
                                       (x_trc, y_trc)]))

        _xx1, _yy1 = xy[0]
        _xx2, _yy2 = xy[1]

        extent_in_ic = _xx1, _xx2, _yy1, _yy2

        # define trans_ic_to_canvas : unless _image_skew_coordinate is
        # set, it is simply a affine part of the original transform.
        if self._image_skew_coordinate:
            # skew the image when required.
            x_lrc, y_lrc = self._image_skew_coordinate
            xy2 = trans.transform(np.array([(x_lrc, y_lrc)]))
            _xx3, _yy3 = xy2[0]

            tr_rotate_skew = self._get_rotate_and_skew_transform(_xx1, _yy1,
                                                                 _xx2, _yy2,
                                                                 _xx3, _yy3)
            trans_ic_to_canvas = tr_rotate_skew
        else:
            trans_ic_to_canvas = IdentityTransform()

        # Now, viewLim in the ic.  It can be rotated and can be
        # skewed. Make it big enough.
        x1, y1, x2, y2 = self.axes.bbox.extents
        trans_canvas_to_ic = trans_ic_to_canvas.inverted()
        xy_ = trans_canvas_to_ic.transform(np.array([(x1, y1),
                                                     (x2, y1),
                                                     (x2, y2),
                                                     (x1, y2)]))
        x1_, x2_ = min(xy_[:, 0]), max(xy_[:, 0])
        y1_, y2_ = min(xy_[:, 1]), max(xy_[:, 1])
        viewLim_in_ic = Bbox.from_extents(x1_, y1_, x2_, y2_)

        # get the image, sliced if necessary. This is done in the ic.
        im, xmin, ymin, dxintv, dyintv, sx, sy = \
            self._get_unsampled_image(self._A, extent_in_ic, viewLim_in_ic)

        if im is None:
            return  # I'm not if this check is required. -JJL

        fc = self.axes.patch.get_facecolor()
        bg = mcolors.colorConverter.to_rgba(fc, 0)
        im.set_bg(*bg)

        # image input dimensions
        im.reset_matrix()
        numrows, numcols = im.get_size()

        if numrows <= 0 or numcols <= 0:
            return
        im.resize(numcols, numrows)  # just to create im.bufOut that
                                     # is required by backends. There
                                     # may be better solution -JJL

        im._url = self.get_url()
        im._gid = self.get_gid()

        renderer.draw_image(gc, xmin, ymin, im, dxintv, dyintv,
                            trans_ic_to_canvas)