Some patches for figimage

As a follow-up to my message on the users list dated 23 March, here are some patches for one of you keen developers. Here's the message to save you looking it up:

I've found the source of this figimage problem. In _backend_agg.cpp
RendererAgg::draw_image is expecting 4 arguments and is being passed
5 by the FigureImage draw method in image.py The offending line is:

renderer.draw_image(self.ox, self.oy, im, self.origin,
self.figure.bbox)

Changing this to

renderer.draw_image(self.ox, self.oy, im, self.figure.bbox)

solved the problem for me.

I checked and found that the RendererAgg draw_image() virtual method
has 5 arguments, which seems to be the source of the problem, so
either this needs changing or the backend code does.

_draw_image() in backend_agg.py makes the call with 3 arguments, so
this needs fixing too.

The draw_image() method in backend_emf.py has a stub override with 5
arguments, so this may need changing too, although it isn't causing
harm yet. I'm not sure all of these are real problems because I
didn't try too hard to understand how the backends work.

I don't really know what to exercise to test these out. I'm not familiar enough with all the interactions. The patches deal directly with my above findings, but could well break something. With those caveats, here are the patches (also attached). The one which absolutely needs fixing is image.py. The others are what I'm guessing needs to be done to clean up the slight messiness I found.

Gary R.

--- image.py 2006-04-07 22:02:08.000000000 +1000
+++ new_image.py 2006-04-07 23:02:36.000000000 +1000
@@ -422,7 +422,7 @@
      def draw(self, renderer, *args, **kwargs):
          if not self.get_visible(): return
          im = self.make_image()
- renderer.draw_image(self.ox, self.oy, im, self.origin, self.figure.bbox)
+ renderer.draw_image(self.ox, self.oy, im, self.figure.bbox)

      def write_png(self, fname):
          """Write the image to png file with fname"""

--- backend_emf.py 2006-04-07 22:51:12.000000000 +1000
+++ new_backend_emf.py 2006-04-07 23:18:02.000000000 +1000
@@ -179,15 +179,11 @@
self.emf.Arc(int(x-hw),int(self.height-(y-hh)),int(x+hw),int(self.height-(y+hh)),int(x+math.cos(angle1*math.pi/180.0)*hw),int(self.height-(y+math.sin(angle1*math.pi/180.0)*hh)),int(x+math.cos(angle2*math.pi/180.0)*hw),int(self.height-(y+math.sin(angle2*math.pi/180.0)*hh)))

- def draw_image(self, x, y, im, origin, bbox):
+ def draw_image(self, x, y, im, bbox):
          """
          Draw the Image instance into the current axes; x is the
          distance in pixels from the left hand side of the canvas. y is
- the distance from the origin. That is, if origin is upper, y
- is the distance from top. If origin is lower, y is the
- distance from bottom

diff_backend_agg2.txt (385 Bytes)

diff_backend_agg.txt (767 Bytes)

diff_backend_emf.txt (1008 Bytes)

diff_image.txt (485 Bytes)

···

-
- origin is 'upper' or 'lower'
+ the distance from the origin.

          bbox is a matplotlib.transforms.BBox instance for clipping, or
          None

--- backend_agg.py 2006-04-07 22:51:38.000000000 +1000
+++ new_backend_agg.py 2006-04-07 23:04:00.000000000 +1000
@@ -155,14 +155,14 @@
              gcEdge, rgbFace, x, y, width/2, height/2) # ellipse takes radius

- def _draw_image(self, x, y, im):
+ def _draw_image(self, x, y, im, bbox):
          """
          Draw the Image instance into the current axes; x, y is the
          upper left hand corner of the image
          """
          if __debug__: verbose.report('RendererAgg.draw_image', 'debug-annoying')
          #self._renderer.draw_image(int(x), int(self.height-y), im)
- self._renderer.draw_image(int(x), int(y), im)
+ self._renderer.draw_image(int(x), int(y), im, bbox)

      def draw_line(self, gc, x1, y1, x2, y2):
          """

--- backend_agg2.py 2006-04-07 22:56:56.000000000 +1000
+++ new_backend_agg2.py 2006-04-07 23:04:20.000000000 +1000
@@ -90,7 +90,7 @@
      def draw_arc(self, gcEdge, rgbFace, x, y, width, height, angle1, angle2):
          pass

- def draw_image(self, x, y, im, origin, bbox):
+ def draw_image(self, x, y, im, bbox):
          pass

      def draw_line(self, gc, x1, y1, x2, y2):

Since noone has picked this up and I notice John Hunter is active at the moment, I'll ask directly whether you, John, can apply my figimage patches. Better now than when the diffed versions become outdated (some may be already). Alternatively, please let me know if I should be posting it somewhere so it isn't forgotten.
thanks,
Gary R.