'Normalize, rescale and color the image `A` from the given
in_bbox (in data space), to the given out_bbox (in pixel
space) clipped to the given clip_bbox (also in pixel space),
and magnified by the magnification factor.
`A` may be a greyscale image (MxN) with a dtype of `float32`,
`float64`, `uint16` or `uint8`, or an RGBA image (MxNx4) with
a dtype of `float32`, `float64`, or `uint8`.
If `unsampled` is True, the image will not be scaled, but an
appropriate affine transformation will be returned instead.
If `round_to_pixel_border` is True, the output image size will
be rounded to the nearest pixel boundary.  This makes the
images align correctly with the axes.  It should not be used
in cases where you want exact scaling, however, such as
FigureImage.
Returns the resulting (image, x, y, trans), where (x, y) is
the upper left corner of the result in pixel space, and
`trans` is the affine transformation from the image to pixel
space.'

def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, unsampled=False, round_to_pixel_border=True):

    if (A is None):
        raise RuntimeError(u'You    must    first    set    the    image    array    or    the    image    attribute')
    if (A.size == 0):
        raise RuntimeError(u"_make_image    must    get    a    non-empty    image.    Your    Artist's    draw    method    must    filter    before    this    method    is    called.")
    clipped_bbox = Bbox.intersection(out_bbox, clip_bbox)
    if (clipped_bbox is None):
        return (None, 0, 0, None)
    out_width_base = (clipped_bbox.width * magnification)
    out_height_base = (clipped_bbox.height * magnification)
    if ((out_width_base == 0) or (out_height_base == 0)):
        return (None, 0, 0, None)
    if (self.origin == u'upper'):
        t0 = Affine2D().translate(0, (- A.shape[0])).scale(1, (-1))
    else:
        t0 = IdentityTransform()
    t0 += (Affine2D().scale((in_bbox.width / A.shape[1]), (in_bbox.height / A.shape[0])).translate(in_bbox.x0, in_bbox.y0) + self.get_transform())
    t = (t0 + Affine2D().translate((- clipped_bbox.x0), (- clipped_bbox.y0)).scale(magnification, magnification))
    if (t.is_affine and round_to_pixel_border and (((out_width_base % 1.0) != 0.0) or ((out_height_base % 1.0) != 0.0))):
        out_width = int(ceil(out_width_base))
        out_height = int(ceil(out_height_base))
        extra_width = ((out_width - out_width_base) / out_width_base)
        extra_height = ((out_height - out_height_base) / out_height_base)
        t += Affine2D().scale((1.0 + extra_width), (1.0 + extra_height))
    else:
        out_width = int(out_width_base)
        out_height = int(out_height_base)
    if (not unsampled):
        created_rgba_mask = False
        if (A.ndim not in (2, 3)):
            raise ValueError(u'Invalid    dimensions,    got    {}'.format(A.shape))
        if (A.ndim == 2):
            A = self.norm(A)
            if (A.dtype.kind == u'f'):
                rgba = np.empty((A.shape[0], A.shape[1], 4), dtype=A.dtype)
                rgba[..., 0] = A
                with np.errstate(invalid=u'ignore'):
                    rgba[..., 1] = np.where((A < 0), np.nan, 1)
                    rgba[..., 2] = np.where((A > 1), np.nan, 1)
                rgba[..., 3] = 1
                if (A.mask.shape == A.shape):
                    mask = np.where(A.mask, np.nan, 1)
                else:
                    mask = A.mask
                A = rgba
                output = np.zeros((out_height, out_width, 4), dtype=A.dtype)
                alpha = 1.0
                created_rgba_mask = True
            else:
                A = self.cmap(A, alpha=self.get_alpha(), bytes=True)
        if (not created_rgba_mask):
            if (A.shape[2] == 3):
                A = _rgb_to_rgba(A)
            elif (A.shape[2] != 4):
                raise ValueError((u'Invalid    dimensions,    got    %s' % (A.shape,)))
            output = np.zeros((out_height, out_width, 4), dtype=A.dtype)
            alpha = self.get_alpha()
            if (alpha is None):
                alpha = 1.0
        _image.resample(A, output, t, _interpd_[self.get_interpolation()], self.get_resample(), alpha, (self.get_filternorm() or 0.0), (self.get_filterrad() or 0.0))
        if created_rgba_mask:
            hid_output = output
            if (len(mask.shape) == 2):
                out_mask = np.empty((out_height, out_width), dtype=mask.dtype)
                _image.resample(mask, out_mask, t, _interpd_[self.get_interpolation()], True, 1, (self.get_filternorm() or 0.0), (self.get_filterrad() or 0.0))
                out_mask = np.isnan(out_mask)
            else:
                out_mask = mask
            out_mask = (out_mask | (hid_output[..., 3] < 0.5))
            output = np.ma.masked_array(hid_output[..., 0], out_mask)
            del out_mask
            invalid_mask = ((~ output.mask) * (~ np.isnan(output.data)))
            output[(np.isnan(hid_output[..., 1]) * invalid_mask)] = (-1)
            output[(np.isnan(hid_output[..., 2]) * invalid_mask)] = 2
        output = self.to_rgba(output, bytes=True, norm=False)
        if ((A.ndim == 2) or created_rgba_mask):
            alpha = self.get_alpha()
            if ((alpha is not None) and (alpha != 1.0)):
                alpha_channel = output[:, :, 3]
                alpha_channel[:] = np.asarray((np.asarray(alpha_channel, np.float32) * alpha), np.uint8)
    else:
        if (self._imcache is None):
            self._imcache = self.to_rgba(A, bytes=True, norm=(A.ndim == 2))
        output = self._imcache
        subset = TransformedBbox(clip_bbox, t0.frozen().inverted()).frozen()
        output = output[int(max(subset.ymin, 0)):int(min((subset.ymax + 1), output.shape[0])), int(max(subset.xmin, 0)):int(min((subset.xmax + 1), output.shape[1]))]
        t = (Affine2D().translate(int(max(subset.xmin, 0)), int(max(subset.ymin, 0))) + t)
    return (output, clipped_bbox.x0, clipped_bbox.y0, t)
