Skip to content
This repository

Mac OS X Backend: Removing clip that is no longer needed #1562

Merged
merged 1 commit into from over 1 year ago

3 participants

mdehoon Michael Droettboom Damon McDougall
mdehoon

Same thing as for the Cairo backend (pull request #1538). The same simplifications can be made in the Mac OS X backend.

Michael Droettboom
Owner

@mdehoon: Do you think this may have something to do with #1563?

mdehoon

No that is a separate issue.

Damon McDougall
Collaborator

Thanks @mdehoon. Do we have tests for the OS X infrastructure? If not, it'd be nice if, as a larger more ambitious goal, the C/C++/Objc code got code coverage. Though, having said that, this might be a moot point if we decide to make the move towards a Cython-backed infrastructure.

mdehoon

No we don't have specific tests for the Mac OS X backend. Realistically speaking I don't think I will find time to write such tests, but I wouldn't object if somebody else does.
Even if we do go towards a Cython-backed infrastructure, I think it would be a really bad idea to convert the Mac OS X backend to Cython. For one thing, it's hard to have the event loop, ObjC memory management, and Python reference counting play nice with each other. I don't want to add Cython to the mix. Also, let's not fix what is not broken.

Damon McDougall dmcdougall merged commit b77afc6 into from December 08, 2012
Damon McDougall dmcdougall closed this December 08, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 05, 2012
mdehoon Removing clip that is no longer needed 8260a5a
This page is out of date. Refresh to see the latest.
3  lib/matplotlib/backends/backend_macosx.py
@@ -107,8 +107,7 @@ def draw_gouraud_triangle(self, gc, points, colors, transform):
107 107
     def draw_image(self, gc, x, y, im):
108 108
         im.flipud_out()
109 109
         nrows, ncols, data = im.as_rgba_str()
110  
-        gc.draw_image(x, y, nrows, ncols, data, gc.get_clip_rectangle(),
111  
-                      *gc.get_clip_path())
  110
+        gc.draw_image(x, y, nrows, ncols, data)
112 111
         im.flipud_out()
113 112
 
114 113
     def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
88  src/_macosx.m
@@ -1157,43 +1157,6 @@ static int _get_snap(GraphicsContext* self, enum e_snap_mode* mode)
1157 1157
     return Py_None;
1158 1158
 }
1159 1159
 
1160  
-static BOOL _clip(CGContextRef cr, PyObject* object)
1161  
-{
1162  
-    if (object == Py_None) return true;
1163  
-
1164  
-    PyArrayObject* array = NULL;
1165  
-    array = (PyArrayObject*) PyArray_FromObject(object, PyArray_DOUBLE, 2, 2);
1166  
-    if (!array)
1167  
-    {
1168  
-        PyErr_SetString(PyExc_ValueError, "failed to read clipping bounding box");
1169  
-        return false;
1170  
-    }
1171  
-
1172  
-    if (PyArray_NDIM(array)!=2 || PyArray_DIM(array, 0)!=2 || PyArray_DIM(array, 1)!=2)
1173  
-    {
1174  
-        Py_DECREF(array);
1175  
-        PyErr_SetString(PyExc_ValueError, "clipping bounding box should be a 2x2 array");
1176  
-        return false;
1177  
-    }
1178  
-
1179  
-    const double l = *(double*)PyArray_GETPTR2(array, 0, 0);
1180  
-    const double b = *(double*)PyArray_GETPTR2(array, 0, 1);
1181  
-    const double r = *(double*)PyArray_GETPTR2(array, 1, 0);
1182  
-    const double t = *(double*)PyArray_GETPTR2(array, 1, 1);
1183  
-
1184  
-    Py_DECREF(array);
1185  
-
1186  
-    CGRect rect;
1187  
-    rect.origin.x = (CGFloat) l;
1188  
-    rect.origin.y = (CGFloat) b;
1189  
-    rect.size.width = (CGFloat) (r-l);
1190  
-    rect.size.height = (CGFloat) (t-b);
1191  
-
1192  
-    CGContextClipToRect(cr, rect);
1193  
-
1194  
-    return true;
1195  
-}
1196  
-
1197 1160
 static int _transformation_converter(PyObject* object, void* pointer)
1198 1161
 {
1199 1162
     CGAffineTransform* matrix = (CGAffineTransform*)pointer;
@@ -3038,9 +3001,6 @@ static void _data_provider_release(void* info, const void* data, size_t size)
3038 3001
     const char* data;
3039 3002
     int n;
3040 3003
     PyObject* image;
3041  
-    PyObject* cliprect;
3042  
-    PyObject* clippath;
3043  
-    PyObject* clippath_transform;
3044 3004
 
3045 3005
     CGContextRef cr = self->cr;
3046 3006
     if (!cr)
@@ -3049,18 +3009,14 @@ static void _data_provider_release(void* info, const void* data, size_t size)
3049 3009
         return NULL;
3050 3010
     }
3051 3011
 
3052  
-    if(!PyArg_ParseTuple(args, "ffiiOOOO", &x,
3053  
-                                           &y,
3054  
-                                           &nrows,
3055  
-                                           &ncols,
3056  
-                                           &image,
3057  
-                                           &cliprect,
3058  
-                                           &clippath,
3059  
-                                           &clippath_transform)) return NULL;
  3012
+    if(!PyArg_ParseTuple(args, "ffiiO", &x,
  3013
+                                        &y,
  3014
+                                        &nrows,
  3015
+                                        &ncols,
  3016
+                                        &image)) return NULL;
3060 3017
 
3061 3018
     CGColorSpaceRef colorspace;
3062 3019
     CGDataProviderRef provider;
3063  
-    double rect[4] = {0.0, 0.0, self->size.width, self->size.height};
3064 3020
 
3065 3021
     if (!PyBytes_Check(image))
3066 3022
     {
@@ -3118,40 +3074,8 @@ static void _data_provider_release(void* info, const void* data, size_t size)
3118 3074
         return NULL;
3119 3075
     }
3120 3076
 
3121  
-    BOOL ok = true;
3122  
-    CGContextSaveGState(cr);
3123  
-    if (!_clip(cr, cliprect)) ok = false;
3124  
-    else if (clippath!=Py_None)
3125  
-    {
3126  
-        int n;
3127  
-        void* iterator  = get_path_iterator(clippath,
3128  
-                                            clippath_transform,
3129  
-                                            0,
3130  
-                                            0,
3131  
-                                            rect,
3132  
-                                            SNAP_AUTO,
3133  
-                                            1.0,
3134  
-                                            0);
3135  
-        if (iterator)
3136  
-        {
3137  
-            n = _draw_path(cr, iterator);
3138  
-            free_path_iterator(iterator);
3139  
-            if (n > 0) CGContextClip(cr);
3140  
-        }
3141  
-        else
3142  
-        {
3143  
-            PyErr_SetString(PyExc_RuntimeError,
3144  
-                "draw_image: failed to obtain path iterator for clipping");
3145  
-            ok = false;
3146  
-        }
3147  
-    }
3148  
-
3149  
-    if (ok) CGContextDrawImage(cr, CGRectMake(x,y,ncols,nrows), bitmap);
3150  
-
  3077
+    CGContextDrawImage(cr, CGRectMake(x,y,ncols,nrows), bitmap);
3151 3078
     CGImageRelease(bitmap);
3152  
-    CGContextRestoreGState(cr);
3153  
-
3154  
-    if (!ok) return NULL;
3155 3079
 
3156 3080
     Py_INCREF(Py_None);
3157 3081
     return Py_None;
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.