Revision: 4159
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4159&view=rev
Author:   mdboom
Date:     2007-11-08 06:06:25 -0800 (Thu, 08 Nov 2007)

Log Message:
-----------
Get wxagg extension working again.  Factor out the new Bbox conversion
code into agg_py_transforms.h

Modified Paths:
--------------
    branches/transforms/src/_backend_agg.cpp
    branches/transforms/src/_backend_agg.h
    branches/transforms/src/_gtkagg.cpp
    branches/transforms/src/_tkagg.cpp
    branches/transforms/src/_wxagg.cpp
    branches/transforms/src/agg_py_transforms.h

Modified: branches/transforms/src/_backend_agg.cpp
===================================================================
--- branches/transforms/src/_backend_agg.cpp    2007-11-08 14:05:18 UTC (rev 
4158)
+++ branches/transforms/src/_backend_agg.cpp    2007-11-08 14:06:25 UTC (rev 
4159)
@@ -273,33 +273,6 @@
   
 };
 
-bool
-RendererAgg::bbox_to_rect(const Py::Object& bbox_obj, double* l, double* b, 
double* r, double* t) {
-  PyArrayObject* bbox = NULL;
-
-  if (bbox_obj.ptr() != Py_None) {
-    bbox = (PyArrayObject*) PyArray_FromObject(bbox_obj.ptr(), PyArray_DOUBLE, 
2, 2);   
-
-    if (!bbox || PyArray_NDIM(bbox) != 2 || PyArray_DIM(bbox, 0) != 2 || 
PyArray_DIM(bbox, 1) != 2) {
-      Py_XDECREF(bbox);
-      throw Py::TypeError
-       ("Expected a Bbox object.");
-    }
-    
-    *l       = *(double*)PyArray_GETPTR2(bbox, 0, 0);
-    double _b = *(double*)PyArray_GETPTR2(bbox, 0, 1);
-    *r       = *(double*)PyArray_GETPTR2(bbox, 1, 0);
-    double _t = *(double*)PyArray_GETPTR2(bbox, 1, 1);
-    *b       = height - _t;
-    *t       = height - _b;
-
-    Py_XDECREF(bbox);
-    return true;
-  }
-
-  return false;
-}
-
 template<class R>
 void
 RendererAgg::set_clipbox(const Py::Object& cliprect, R rasterizer) {
@@ -308,7 +281,7 @@
   _VERBOSE("RendererAgg::set_clipbox");
 
   double l, b, r, t;
-  if (bbox_to_rect(cliprect, &l, &b, &r, &t)) {
+  if (py_convert_bbox(cliprect.ptr(), l, b, r, t)) {
     rasterizer->clip_box((int)l, (int)b, (int)r, (int)t);
   }
 
@@ -408,7 +381,7 @@
 
   Py::Object box_obj = args[0];
   double l, b, r, t;
-  if (!bbox_to_rect(box_obj, &l, &b, &r, &t)) 
+  if (!py_convert_bbox(box_obj.ptr(), l, b, r, t)) 
     throw Py::TypeError("Invalid bbox provided to copy_from_bbox");
   
   agg::rect rect((int)l, (int)b, (int)r, (int)t);

Modified: branches/transforms/src/_backend_agg.h
===================================================================
--- branches/transforms/src/_backend_agg.h      2007-11-08 14:05:18 UTC (rev 
4158)
+++ branches/transforms/src/_backend_agg.h      2007-11-08 14:06:25 UTC (rev 
4159)
@@ -215,7 +215,6 @@
   double points_to_pixels_snapto( const Py::Object& points);
   agg::rgba rgb_to_color(const Py::SeqBase<Py::Object>& rgb, double alpha);
   facepair_t _get_rgba_face(const Py::Object& rgbFace, double alpha);
-  bool bbox_to_rect(const Py::Object& bbox, double* l, double* b, double* r, 
double* t);
   template<class R>
   void set_clipbox(const Py::Object& cliprect, R rasterizer);
   bool render_clippath(const Py::Object& clippath, const agg::trans_affine& 
clippath_trans);

Modified: branches/transforms/src/_gtkagg.cpp
===================================================================
--- branches/transforms/src/_gtkagg.cpp 2007-11-08 14:05:18 UTC (rev 4158)
+++ branches/transforms/src/_gtkagg.cpp 2007-11-08 14:06:25 UTC (rev 4159)
@@ -14,6 +14,7 @@
 #include "_backend_agg.h"
 #define PY_ARRAY_TYPES_PREFIX NumPy
 #include "numpy/arrayobject.h"
+#include "agg_py_transforms.h"
 
 // the extension module
 class _gtkagg_module : public Py::ExtensionModule<_gtkagg_module>
@@ -71,31 +72,12 @@
     else {
       //bbox is not None; copy the image in the bbox
       PyObject* clipbox = args[2].ptr();
-      PyArrayObject* bbox = NULL;
       double l, b, r, t;
 
-      try {
-       bbox = (PyArrayObject*) PyArray_FromObject(clipbox, PyArray_DOUBLE, 2, 
2);   
-       
-       if (!bbox || bbox->nd != 2 || bbox->dimensions[0] != 2 || 
bbox->dimensions[1] != 2) {
-         throw Py::TypeError
-           ("Argument 3 to agg_to_gtk_drawable must be a Bbox object.");
-       }
-       
-       l = *(double*)PyArray_GETPTR2(bbox, 0, 0);
-       b = *(double*)PyArray_GETPTR2(bbox, 0, 1);
-       r = *(double*)PyArray_GETPTR2(bbox, 1, 0);
-       t = *(double*)PyArray_GETPTR2(bbox, 1, 1);
-
-       Py_XDECREF(bbox);
-       bbox = NULL;
-      } catch (...) {
-       Py_XDECREF(bbox);
-       bbox = NULL;
-       throw;
+      if (!py_convert_bbox(clipbox, l, b, r, t)) {
+       throw Py::TypeError
+         ("Argument 3 to agg_to_gtk_drawable must be a Bbox object.");
       }
-      //std::cout << b << " "
-      //               << t << " ";
 
       destx = (int)l;
       desty = srcheight-(int)t;
@@ -118,11 +100,8 @@
       agg::rect_base<int> region(destx, desty, (int)r, srcheight-(int)b);
       destrb.copy_from(*aggRenderer->renderingBuffer, &region,
                       -destx, -desty);
-
-
     }
 
-
     /*std::cout << desty << " "
              << destheight << " "
              << srcheight << std::endl;*/

Modified: branches/transforms/src/_tkagg.cpp
===================================================================
--- branches/transforms/src/_tkagg.cpp  2007-11-08 14:05:18 UTC (rev 4158)
+++ branches/transforms/src/_tkagg.cpp  2007-11-08 14:06:25 UTC (rev 4159)
@@ -14,6 +14,7 @@
 
 #include "agg_basics.h"
 #include "_backend_agg.h"
+#include "agg_py_transforms.h"
 
 extern "C" {
 #ifdef __APPLE__
@@ -85,30 +86,9 @@
 
     /* check for bbox/blitting */
     bboxo = (PyObject*)atol(argv[4]);
-    if (bboxo != Py_None) {
+    if (py_convert_bbox(bboxo, l, b, r, t)) {
       has_bbox = true;
-      PyArrayObject* bbox = NULL;
-      try {
-       bbox = (PyArrayObject*) PyArray_FromObject(bboxo, PyArray_DOUBLE, 2, 
2);   
-       
-       if (!bbox || bbox->nd != 2 || bbox->dimensions[0] != 2 || 
bbox->dimensions[1] != 2) {
-         throw Py::TypeError
-           ("Argument 3 to agg_to_gtk_drawable must be a Bbox object.");
-       }
-       
-       l = *(double*)PyArray_GETPTR2(bbox, 0, 0);
-       b = *(double*)PyArray_GETPTR2(bbox, 0, 1);
-       r = *(double*)PyArray_GETPTR2(bbox, 1, 0);
-       t = *(double*)PyArray_GETPTR2(bbox, 1, 1);
 
-       Py_XDECREF(bbox);
-       bbox = NULL;
-      } catch (...) {
-       Py_XDECREF(bbox);
-       bbox = NULL;
-       throw;
-      }
-
       destx = (int)l;
       desty = srcheight-(int)t;
       destwidth = (int)(r-l);

Modified: branches/transforms/src/_wxagg.cpp
===================================================================
--- branches/transforms/src/_wxagg.cpp  2007-11-08 14:05:18 UTC (rev 4158)
+++ branches/transforms/src/_wxagg.cpp  2007-11-08 14:06:25 UTC (rev 4159)
@@ -46,9 +46,9 @@
 
 #include "agg_basics.h"
 #include "_backend_agg.h"
-#include "_transforms.h"
 #include "agg_pixfmt_rgba.h"
 #include "util/agg_color_conv_rgb8.h"
+#include "agg_py_transforms.h"
 
 #include <wx/image.h>
 #include <wx/bitmap.h>
@@ -56,8 +56,8 @@
 
 
 // forward declarations
-static wxImage  *convert_agg2image(RendererAgg *aggRenderer, Bbox *clipbox);
-static wxBitmap *convert_agg2bitmap(RendererAgg *aggRenderer, Bbox *clipbox);
+static wxImage  *convert_agg2image(RendererAgg *aggRenderer, Py::Object 
clipbox);
+static wxBitmap *convert_agg2bitmap(RendererAgg *aggRenderer, Py::Object 
clipbox);
 
 
 // the extension module
@@ -94,9 +94,7 @@
     RendererAgg* aggRenderer = static_cast<RendererAgg*>(
         args[0].getAttr("_renderer").ptr());
 
-    Bbox *clipbox = NULL;
-    if (args[1].ptr() != Py_None)
-        clipbox = static_cast<Bbox*>(args[1].ptr());
+    Py::Object clipbox = args[1];
 
     // convert the buffer
     wxImage *image = convert_agg2image(aggRenderer, clipbox);
@@ -118,9 +116,7 @@
     RendererAgg* aggRenderer = static_cast<RendererAgg*>(
        args[0].getAttr("_renderer").ptr());
 
-    Bbox *clipbox = NULL;
-    if (args[1].ptr() != Py_None)
-        clipbox = static_cast<Bbox*>(args[1].ptr());
+    Py::Object clipbox = args[1];
 
     // convert the buffer
     wxBitmap *bitmap = convert_agg2bitmap(aggRenderer, clipbox);
@@ -141,7 +137,7 @@
 // Implementation Functions
 //
 
-static wxImage *convert_agg2image(RendererAgg *aggRenderer, Bbox *clipbox)
+static wxImage *convert_agg2image(RendererAgg *aggRenderer, Py::Object clipbox)
 {
     int srcWidth  = 1;
     int srcHeight = 1;
@@ -150,7 +146,9 @@
     bool deleteSrcBuffer = false;
     agg::int8u *srcBuffer = NULL;
 
-    if (clipbox == NULL) {
+    double l, b, r, t;
+
+    if (!py_convert_bbox(clipbox.ptr(), l, b, r, t)) {
         // Convert everything: rgba => rgb -> image
         srcBuffer = aggRenderer->pixBuffer;
         srcWidth  = (int) aggRenderer->get_width();
@@ -158,11 +156,6 @@
         srcStride = (int) aggRenderer->get_width()*4;
     } else {
         // Convert a region: rgba => clipped rgba => rgb -> image
-        double l = clipbox->ll_api()->x_api()->val() ;
-        double b = clipbox->ll_api()->y_api()->val();
-        double r = clipbox->ur_api()->x_api()->val() ;
-        double t = clipbox->ur_api()->y_api()->val() ;
-
         srcWidth = (int) (r-l);
         srcHeight = (int) (t-b);
         srcStride = srcWidth*4;
@@ -230,7 +223,7 @@
 }
 
 
-static wxBitmap *convert_agg2bitmap(RendererAgg *aggRenderer, Bbox *clipbox)
+static wxBitmap *convert_agg2bitmap(RendererAgg *aggRenderer, Py::Object 
clipbox)
 {
     // Convert everything: rgba => rgb -> image => bitmap
     // Convert a region:   rgba => clipped rgba => rgb -> image => bitmap

Modified: branches/transforms/src/agg_py_transforms.h
===================================================================
--- branches/transforms/src/agg_py_transforms.h 2007-11-08 14:05:18 UTC (rev 
4158)
+++ branches/transforms/src/agg_py_transforms.h 2007-11-08 14:06:25 UTC (rev 
4159)
@@ -7,7 +7,6 @@
 #include "CXX/Objects.hxx"
 #include "agg_trans_affine.h"
 
-
 /** A helper function to convert from a Numpy affine transformation matrix
  *  to an agg::trans_affine.
  */
@@ -20,10 +19,10 @@
     matrix = (PyArrayObject*) PyArray_FromObject(obj.ptr(), PyArray_DOUBLE, 2, 
2);
     if (!matrix)
       throw std::exception();
-    if (matrix->nd == 2 || matrix->dimensions[0] == 3 || matrix->dimensions[1] 
== 3) {
-      size_t stride0 = matrix->strides[0];
-      size_t stride1 = matrix->strides[1];
-      char* row0 = matrix->data;
+    if (PyArray_NDIM(matrix) == 2 || PyArray_DIM(matrix, 0) == 3 || 
PyArray_DIM(matrix, 1) == 3) {
+      size_t stride0 = PyArray_STRIDE(matrix, 0);
+      size_t stride1 = PyArray_STRIDE(matrix, 1);
+      char* row0 = PyArray_BYTES(matrix);
       char* row1 = row0 + stride0;
       
       double a = *(double*)(row0);
@@ -55,4 +54,35 @@
   return agg::trans_affine();
 }
 
+bool py_convert_bbox(PyObject* bbox_obj, double& l, double& b, double& r, 
double& t) {
+  PyArrayObject* bbox = NULL;
+
+  if (bbox_obj == Py_None)
+    return false;
+
+  try {
+    bbox = (PyArrayObject*) PyArray_FromObject(bbox_obj, PyArray_DOUBLE, 2, 
2);   
+       
+    if (!bbox || bbox->nd != 2 || bbox->dimensions[0] != 2 || 
bbox->dimensions[1] != 2) {
+      throw Py::TypeError
+       ("Argument 3 to agg_to_gtk_drawable must be a Bbox object.");
+    }
+       
+    l = *(double*)PyArray_GETPTR2(bbox, 0, 0);
+    b = *(double*)PyArray_GETPTR2(bbox, 0, 1);
+    r = *(double*)PyArray_GETPTR2(bbox, 1, 0);
+    t = *(double*)PyArray_GETPTR2(bbox, 1, 1);
+
+    Py_XDECREF(bbox);
+    bbox = NULL;
+    return true;
+  } catch (...) {
+    Py_XDECREF(bbox);
+    bbox = NULL;
+    throw;
+  }
+
+  return false;
+}
+
 #endif // __AGG_PY_TRANSFORMS_H__


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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to