John,
I'm attaching an another patch, which seems to give a correct result
for the figimage_demo.
The flipud_out() calls before compositing seems to have no effect, so
I deleted those lines. The make_image() routine seems to take care of
the fliping already, but note the comments I added. Let me know if
there are cases this patch does not work.

-JJ




On Sat, Nov 8, 2008 at 7:28 PM, John Hunter <[EMAIL PROTECTED]> wrote:
> On Sat, Nov 8, 2008 at 6:10 PM, Jae-Joon Lee <[EMAIL PROTECTED]> wrote:
>
>> My original patch does not work for this case, because the figimage is
>> drawn by Figure.draw() not by Axes.draw() method.
>> I'm attaching a new patch where I applied the same correction to the
>> Figure.draw().
>> I tested GtkAgg, Gtk, GtkCairo, Pdf, Ps and they all worked fine.
>
> So I managed to sneak some time to apply and test these after all --
> but I am getting in a little trouble with my wife :-)
>
> The layer images demo looks great for pdf, svg and png, but I am still
> seeing problems with the figimage_demo for origin "upper".  On svg and
> pdf in my tests, blue still appears down, though is correctly up on
> png.  I went ahead and committed your changes (with a minor variation
> that the list comprehensions are expressed as plain-ol-loops because
> some people consider the use of a list comprehension simply to do in
> place modifications where the list itself is discarded to be an abuse
> of the construct) to revision 6380.
>
> Make sure I didn't screw something up, but the figimage_demo still
> looks broken to me for the case currently in fsvn
>
> Thanks for all the progress!
> JDH
>
Index: lib/matplotlib/image.py
===================================================================
--- lib/matplotlib/image.py	(revision 6380)
+++ lib/matplotlib/image.py	(working copy)
@@ -154,6 +154,8 @@
             iy0 = max(0, int(y0 - self._filterrad))
             y1 = (self.axes.viewLim.y1-ymin)/dyintv * numrows
             iy1 = min(numrows, int(y1 + self._filterrad))
+            # Do we need to take care of the image origin here?
+            # Isn't it enought to have im.flipud_in() in line 194?
             if self.origin == 'upper':
                 yslice = slice(numrows-iy1, numrows-iy0)
             else:
@@ -670,14 +672,25 @@
 
         x = self.to_rgba(self._A, self._alpha)
 
-        im = _image.fromarray(x, 1)
+
+        # im.flipud_out() does not seem to work well with
+        # from_images().  It seems that from_images() do not respect
+        # the image stride. Thus, we need to actually flip the memory
+        # area, not just the stride.
+        
+        numrows, numcols = self.get_size()
+
+        if self.origin == 'upper':
+            yslice = slice(numrows-1, None, -1)
+        else:
+            yslice = slice(0, numrows)
+
+        im = _image.fromarray(x[yslice], 1)
         fc = self.figure.get_facecolor()
         im.set_bg( *mcolors.colorConverter.to_rgba(fc, 0) )
         im.is_grayscale = (self.cmap.name == "gray" and
                            len(self._A.shape) == 2)
-        if self.origin=='upper':
-            im.flipud_out()
-
+        
         return im
 
     def draw(self, renderer, *args, **kwargs):
Index: lib/matplotlib/axes.py
===================================================================
--- lib/matplotlib/axes.py	(revision 6380)
+++ lib/matplotlib/axes.py	(working copy)
@@ -1536,12 +1536,6 @@
             ims = [(im.make_image(mag),0,0)
                    for im in self.images if im.get_visible()]
 
-            #flip the images if their origin is "upper"
-            for _im, (im,_,_) in zip(self.images, ims):
-                if _im.origin=="upper":
-                    im.flipud_out()
-
-
             l, b, r, t = self.bbox.extents
             width = mag*((round(r) + 0.5) - (round(l) - 0.5))
             height = mag*((round(t) + 0.5) - (round(b) - 0.5))
Index: lib/matplotlib/figure.py
===================================================================
--- lib/matplotlib/figure.py	(revision 6380)
+++ lib/matplotlib/figure.py	(working copy)
@@ -743,7 +743,7 @@
         if self.suppressComposite is not None:
             composite = self.suppressComposite
 
-        if len(self.images)<=1 or composite or not allequal([im.origin for im in self.images]):
+        if len(self.images)<=1 or composite:
             for im in self.images:
                 im.draw(renderer)
         else:
@@ -753,11 +753,6 @@
             ims = [(im.make_image(mag), im.ox*mag, im.oy*mag)
                    for im in self.images]
 
-            for _im, (im,_,_) in zip(self.images, ims):
-                if _im.origin=="upper":
-                    im.flipud_out()
-
-
             im = _image.from_images(self.bbox.height * mag,
                                     self.bbox.width * mag,
                                     ims)
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to