Revision: 7624
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7624&view=rev
Author:   mdboom
Date:     2009-09-01 13:03:20 +0000 (Tue, 01 Sep 2009)

Log Message:
-----------
Use numpy to generate the PDF shading triangles stream, which should be faster 
and more portable than using struct.

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py     2009-09-01 
12:13:12 UTC (rev 7623)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py     2009-09-01 
13:03:20 UTC (rev 7624)
@@ -17,7 +17,6 @@
 from cStringIO import StringIO
 from datetime import datetime
 from math import ceil, cos, floor, pi, sin
-import struct
 try:
     set
 except NameError:
@@ -1068,11 +1067,10 @@
             gouraudDict[name] = ob
             shape = points.shape
             flat_points = points.reshape((shape[0] * shape[1], 2))
+            flat_colors = colors.reshape((shape[0] * shape[1], 4))
             points_min = npy.min(flat_points, axis=0) - (1 << 8)
             points_max = npy.max(flat_points, axis=0) + (1 << 8)
             factor = float(0xffffffff) / (points_max - points_min)
-            adjpoints = npy.array((points - points_min) * factor, 
dtype=npy.uint32)
-            adjcolors = npy.array(colors * 255.0, dtype=npy.uint8)
 
             self.beginStream(
                 ob.id, None,
@@ -1087,10 +1085,16 @@
                              0, 1, 0, 1, 0, 1]
                   })
 
-            for tpoints, tcolors in zip(adjpoints, adjcolors):
-                for p, c in zip(tpoints, tcolors):
-                    values = [int(x) for x in [0] + list(p) + list(c[:3])]
-                    self.write(struct.pack('>BLLBBB', *values))
+            streamarr = npy.empty(
+                (shape[0] * shape[1],),
+                dtype=[('flags', 'u1'),
+                       ('points', '>u4', (2,)),
+                       ('colors', 'u1', (3,))])
+            streamarr['flags'] = 0
+            streamarr['points'] = (flat_points - points_min) * factor
+            streamarr['colors'] = flat_colors[:, :3] * 255.0
+
+            self.write(streamarr.tostring())
             self.endStream()
         self.writeObject(self.gouraudObject, gouraudDict)
 
@@ -1375,11 +1379,20 @@
                                     colors.reshape((1, 3, 4)), trans)
 
     def draw_gouraud_triangles(self, gc, points, colors, trans):
+        assert len(points) == len(colors)
+        assert points.ndim == 3
+        assert points.shape[1] == 3
+        assert points.shape[2] == 2
+        assert colors.ndim == 3
+        assert colors.shape[1] == 3
+        assert colors.shape[2] == 4
+
         shape = points.shape
         points = points.reshape((shape[0] * shape[1], 2))
         tpoints = trans.transform(points)
         tpoints = tpoints.reshape(shape)
         name = self.file.addGouraudTriangles(tpoints, colors)
+        self.check_gc(gc)
         self.file.output(name, Op.shading)
 
     def _setup_textpos(self, x, y, descent, angle, oldx=0, oldy=0, 
olddescent=0, oldangle=0):


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to