8000 Merge pull request #3646 from mdboom/decxx-backend-agg · matplotlib/matplotlib@be34210 · GitHub
[go: up one dir, main page]

Skip to content

Commit be34210

Browse files
committed
Merge pull request #3646 from mdboom/decxx-backend-agg
MNT : Remove PyCXX dependency for core extension modules
2 parents 585c1ad + c8493ea commit be34210

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+9998
-10104
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ matrix:
2424

2525
install:
2626
- pip install -q --use-mirrors nose python-dateutil $NUMPY pep8 pyparsing pillow
27-
- sudo apt-get update && sudo apt-get -qq install inkscape libav-tools
28-
# We use --no-install-recommends to avoid pulling in additional large latex docs that we don't need
27+
- sudo apt-get update && sudo apt-get -qq install inkscape libav-tools gdb
28+
# We use --no-install-recommends to avoid pulling in additional large latex docs that we don't need
2929
- if [[ $BUILD_DOCS == true ]]; then sudo apt-get install -qq --no-install-recommends dvipng texlive-latex-base texlive-latex-extra texlive-fonts-recommended graphviz; fi
3030
- if [[ $BUILD_DOCS == true ]]; then pip install sphinx numpydoc linkchecker; fi
3131
- python setup.py install
@@ -37,11 +37,12 @@ script:
3737
- echo Testing using 8 processes
3838
# Generate the font caches in a single process before starting the
3939
# multiple processes
40+
- gcc --version
4041
- python -c "from matplotlib import font_manager"
4142
- if [[ $BUILD_DOCS == false ]]; then export MPL_REPO_DIR=$PWD; fi # pep8-conformance test of the examples
4243
- if [[ $BUILD_DOCS == false ]]; then mkdir ../tmp_test_dir; fi
4344
- if [[ $BUILD_DOCS == false ]]; then cd ../tmp_test_dir; fi
44-
- if [[ $BUILD_DOCS == false ]]; then python ../matplotlib/tests.py -sv --processes=8 --process-timeout=300 $TEST_ARGS; fi
45+
- if [[ $BUILD_DOCS == false ]]; then gdb -return-child-result -batch -ex r -ex bt --args python ../matplotlib/tests.py -sv --processes=8 --process-timeout=300 $TEST_ARGS; fi
4546
- if [[ $BUILD_DOCS == true ]]; then cd doc; python make.py html --small; fi
4647
# We don't build the LaTeX docs here, so linkchecker will complain
4748
- if [[ $BUILD_DOCS == true ]]; then touch build/html/Matplotlib.pdf; fi

examples/pylab_examples/agg_buffer_to_array.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
fig.canvas.draw()
99

1010
# grab the pixel buffer and dump it into a numpy array
11-
buf = fig.canvas.buffer_rgba()
12-
l, b, w, h = fig.bbox.bounds
13-
# The array needs to be copied, because the underlying buffer
14-
# may be reallocated when the window is resized.
15-
X = np.frombuffer(buf, np.uint8).copy()
16-
X.shape = h,w,4
11+
X = np.array(fig.canvas.renderer._renderer)
1712

1813
# now display the array X as an Axes in a new figure
1914
fig2 = plt.figure()

examples/pylab_examples/mathtext_demo.py

100644100755
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@
2424

2525
ax.set_title(r'$\Delta_i^j \hspace{0.4} \mathrm{versus} \hspace{0.4} \Delta_{i+1}^j$', fontsize=20)
2626

27-
2827
show()

lib/matplotlib/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,13 @@ def tk_window_focus():
14051405

14061406
def test(verbosity=1):
14071407
"""run the matplotlib test suite"""
1408+
try:
1409+
import faulthandler
1410+
except ImportError:
1411+
pass
1412+
else:
1413+
faulthandler.enable()
1414+
14081415
old_backend = rcParams['backend']
14091416
try:
14101417
use('agg')

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,8 +2063,8 @@ def draw(self, renderer=None, inframe=False):
20632063
for z, im in zorder_images]
20642064

20652065
l, b, r, t = self.bbox.extents
2066-
width = mag * ((round(r) + 0.5) - (round(l) - 0.5))
2067-
height = mag * ((round(t) + 0.5) - (round(b) - 0.5))
2066+
width = int(mag * ((round(r) + 0.5) - (round(l) - 0.5)))
2067+
height = int(mag * ((round(t) + 0.5) - (round(b) - 0.5)))
20682068
im = mimage.from_images(height,
20692069
width,
20702070
ims)

lib/matplotlib/backends/backend_agg.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,19 @@ def draw_path_collection(self, *kl, **kw):
127127
return self._renderer.draw_path_collection(*kl, **kw)
128128

129129
def _update_methods(self):
130-
#self.draw_path = self._renderer.draw_path # see below
131-
#self.draw_markers = self._renderer.draw_markers
132-
#self.draw_path_collection = self._renderer.draw_path_collection
133130
self.draw_quad_mesh = self._renderer.draw_quad_mesh
134131
self.draw_gouraud_triangle = self._renderer.draw_gouraud_triangle
135132
self.draw_gouraud_triangles = self._renderer.draw_gouraud_triangles
136133
self.draw_image = self._renderer.draw_image
137134
self.copy_from_bbox = self._renderer.copy_from_bbox
138-
self.tostring_rgba_minimized = self._renderer.tostring_rgba_minimized
135+
self.get_content_extents = self._renderer.get_content_extents
136+
137+
def tostring_rgba_minimized(self):
138+
extents = self.get_content_extents()
139+
bbox = [[extents[0], self.height - (extents[1] + extents[3])],
140+
[extents[0] + extents[2], self.height - extents[1]]]
141+
region = self.copy_from_bbox(bbox)
142+
return np.array(region), extents
139143

140144
def draw_path(self, gc, path, transform, rgbFace=None):
141145
"""
@@ -203,7 +207,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
203207

204208
#print x, y, int(x), int(y), s
205209
self._renderer.draw_text_image(
206-
font.get_image(), np.round(x - xd), np.round(y + yd) + 1, angle, gc)
210+
font, np.round(x - xd), np.round(y + yd) + 1, angle, gc)
207211

208212
def get_text_width_height_descent(self, s, prop, ismath):
209213
"""
@@ -354,7 +358,7 @@ def restore_region(self, region, bbox=None, xy=None):
354358
else:
355359
ox, oy = xy
356360

357-
self._renderer.restore_region2(region, x1, y1, x2, y2, ox, oy)
361+
self._renderer.restore_region(region, x1, y1, x2, y2, ox, oy)
358362

359363
else:
360364
self._renderer.restore_region(region)
@@ -394,7 +398,7 @@ def post_processing(image, dpi):
394398

395399
width, height = int(self.width), int(self.height)
396400

397-
buffer, bounds = self._renderer.tostring_rgba_minimized()
401+
buffer, bounds = self.tostring_rgba_minimized()
398402

399403
l, b, w, h = bounds
400404

@@ -407,7 +411,6 @@ def post_processing(image, dpi):
407411
img, ox, oy = post_processing(img.reshape((h, w, 4)) / 255.,
408412
self.dpi)
409413
image = fromarray(img, 1)
410-
image.flipud_out()
411414

412415
gc = self.new_gc()
413416
self._renderer.draw_image(gc,
@@ -505,12 +508,13 @@ def print_raw(self, filename_or_obj, *args, **kwargs):
505508
original_dpi = renderer.dpi
506509
renderer.dpi = self.figure.dpi
507510
if is_string_like(filename_or_obj):
508-
filename_or_obj = open(filename_or_obj, 'wb')
511+
fileobj = open(filename_or_obj, 'wb')
509512
close = True
510513
else:
514+
fileobj = filename_or_obj
511515
close = False
512516
try:
513-
renderer._renderer.write_rgba(filename_or_obj)
517+
fileobj.write(renderer._renderer.buffer_rgba())
514518
finally:
515519
if close:
516520
filename_or_obj.close()
@@ -528,9 +532,7 @@ def print_png(self, filename_or_obj, *args, **kwargs):
528532
else:
529533
close = False
530534
try:
531-
_png.write_png(renderer._renderer.buffer_rgba(),
532-
renderer.width, renderer.height,
533-
filename_or_obj, self.figure.dpi)
535+
_png.write_png(renderer._renderer, filename_or_obj, self.figure.dpi)
534536
finally:
535537
if close:
536538
filename_or_obj.close()

lib/matplotlib/backends/backend_cairo.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ def draw_image(self, gc, x, y, im):
167167
# bbox - not currently used
168168
if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name()))
169169

170-
im.flipud_out()
171-
172170
rows, cols, buf = im.color_conv (BYTE_FORMAT)
173171
surface = cairo.ImageSurface.create_for_data (
174172
buf, cairo.FORMAT_ARGB32, cols, rows, cols*4)
@@ -183,8 +181,6 @@ def draw_image(self, gc, x, y, im):
183181
ctx.paint()
184182
ctx.restore()
185183

186-
im.flipud_out()
187-
188184
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
189185
# Note: x,y are device/display coords, not user-coords, unlike other
190186
# draw_* methods

lib/matplotlib/backends/backend_gdk.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def draw_image(self, gc, x, y, im):
109109
# int(w), int(h))
110110
# set clip rect?
111111

112-
im.flipud_out()
113112
rows, cols, image_str = im.as_rgba_str()
114113

115114
image_array = np.fromstring(image_str, np.uint8)
@@ -120,7 +119,7 @@ def draw_image(self, gc, x, y, im):
120119
width=cols, height=rows)
121120

122121
array = pixbuf_get_pixels_array(pixbuf)
123-
array[:,:,:] = image_array
122+
array[:,:,:] = image_array[::-1]
124123

125124
gc = self.new_gc()
126125

@@ -138,9 +137,6 @@ def draw_image(self, gc, x, y, im):
138137
int(x), int(y), cols, rows,
139138
gdk.RGB_DITHER_NONE, 0, 0)
140139

141-
# unflip
142-
im.flipud_out()
143-
144140

145141
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
146142
x, y = int(x), int(y)

lib/matplotlib/backends/backend_macosx.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,8 @@ def get_image_magnification(self):
110110
return self.gc.get_image_magnification()
111111

112112
def draw_image(self, gc, x, y, im):
113-
im.flipud_out()
114113
nrows, ncols, data = im.as_rgba_str()
115114
gc.draw_image(x, y, nrows, ncols, data)
116-
im.flipud_out()
117115

118116
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
119117
# todo, handle props, angle, origins

lib/matplotlib/backends/backend_mixed.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def stop_rasterizing(self):
121121
if w > 0 and h > 0:
122122
image = frombuffer(buffer, w, h, True)
123123
image.is_grayscale = False
124-
image.flipud_out()
125124
gc = self._renderer.new_gc()
126125
# TODO: If the mixedmode resolution differs from the figure's
127126
# dpi, the image must be scaled (dpi->_figdpi). Not all

lib/matplotlib/backends/backend_pdf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ def _rgb(self, im):
12411241

12421242
rgba = np.fromstring(s, np.uint8)
12431243
rgba.shape = (h, w, 4)
1244+
rgba = rgba[::-1]
12441245
rgb = rgba[:, :, :3]
12451246
a = rgba[:, :, 3:]
12461247
return h, w, rgb.tostring(), a.tostring()
@@ -1249,6 +1250,7 @@ def _gray(self, im, rc=0.3, gc=0.59, bc=0.11):
12491250
rgbat = im.as_rgba_str()
12501251
rgba = np.fromstring(rgbat[2], np.uint8)
12511252
rgba.shape = (rgbat[0], rgbat[1], 4)
1253+
rgba = rgba[::-1]
12521254
rgba_f = rgba.astype(np.float32)
12531255
r = rgba_f[:, :, 0]
12541256
g = rgba_f[:, :, 1]
@@ -1258,7 +1260,6 @@ def _gray(self, im, rc=0.3, gc=0.59, bc=0.11):
12581260

12591261
def writeImages(self):
12601262
for img, pair in six.iteritems(self.images):
1261-
img.flipud_out()
12621263
if img.is_grayscale:
12631264
height, width, data = self._gray(img)
12641265
self.beginStream(
@@ -1294,8 +1295,6 @@ def writeImages(self):
12941295
self.currentstream.write(data)
12951296
self.endStream()
12961297

1297-
img.flipud_out()
1298-
12991298
def markerObject(self, path, trans, fillp, strokep, lw, joinstyle,
13001299
capstyle):
13011300
"""Return name of a marker XObject representing the given path."""

lib/matplotlib/backends/backend_pgf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import weakref
1515
import warnings
1616

17+
import numpy as np
18+
1719
import matplotlib as mpl
1820
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
1921
FigureManagerBase, FigureCanvasBase
@@ -619,9 +621,7 @@ def draw_image(self, gc, x, y, im):
619621
fname = os.path.splitext(os.path.basename(self.fh.name))[0]
620622
fname_img = "%s-img%d.png" % (fname, self.image_counter)
621623
self.image_counter += 1
622-
im.flipud_out()
623-
rows, cols, buf = im.as_rgba_str()
624-
_png.write_png(buf, cols, rows, os.path.join(path, fname_img))
624+
_png.write_png(np.array(im)[::-1], os.path.join(path, fname_img))
625625

626626
# reference the image in the pgf picture
627627
writeln(self.fh, r"\begin{pgfscope}")

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,14 @@ def _rgb(self, im):
414414

415415
rgba = np.fromstring(s, np.uint8)
416416
rgba.shape = (h, w, 4)
417-
rgb = rgba[:,:,:3]
417+
rgb = rgba[::-1,:,:3]
418418
return h, w, rgb.tostring()
419419

420420
def _gray(self, im, rc=0.3, gc=0.59, bc=0.11):
421421
rgbat = im.as_rgba_str()
422422
rgba = np.fromstring(rgbat[2], np.uint8)
423423
rgba.shape = (rgbat[0], rgbat[1], 4)
424+
rgba = rgba[::-1]
424425
rgba_f = rgba.astype(np.float32)
425426
r = rgba_f[:,:,0]
426427
g = rgba_f[:,:,1]
@@ -472,8 +473,6 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
472473
interpreted as the coordinate of the transform.
473474
"""
474475

475-
im.flipud_out()
476-
477476
h, w, bits, imagecmd = self._get_image_h_w_bits_command(im)
478477
hexlines = b'\n'.join(self._hex_lines(bits)).decode('ascii')
479478

@@ -524,9 +523,6 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
524523
""" % locals()
525524
self._pswriter.write(ps)
526525

527-
# unflip
528-
im.flipud_out()
529-
530526
def _convert_path(self, path, transform, clip=False, simplify=None):
531527
ps = []
532528
last_points = None

lib/matplotlib/backends/backend_svg.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,7 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
800800
self.writer.start('a', attrib={'xlink:href': url})
801801
if rcParams['svg.image_inline']:
802802
bytesio = io.BytesIO()
803-
im.flipud_out()
804-
rows, cols, buffer = im.as_rgba_str()
805-
_png.write_png(buffer, cols, rows, bytesio)
806-
im.flipud_out()
803+
_png.write_png(np.array(im)[::-1], bytesio)
807804
oid = oid or self._make_id('image', bytesio)
808805
attrib['xlink:href'] = (
809806
"data:image/png;base64,\n" +
@@ -812,10 +809,7 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
812809
self._imaged[self.basename] = self._imaged.get(self.basename,0) + 1
813810
filename = '%s.image%d.png'%(self.basename, self._imaged[self.basename])
814811
verbose.report( 'Writing image file for inclusion: %s' % filename)
815-
im.flipud_out()
816-
rows, cols, buffer = im.as_rgba_str()
817-
_png.write_png(buffer, cols, rows, filename)
818-
im.flipud_out()
812+
_png.write_png(np.array(im)[::-1], filename)
819813
oid = oid or 'Im_' + self._make_id('image', filename)
820814
attrib['xlink:href'] = filename
821815

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ def get_diff_image(self):
143143
# TODO: We should write a new version of write_png that
144144
# handles the differencing inline
145145
_png.write_png(
146-
output.tostring(),
147-
output.shape[1], output.shape[0],
146+
output,
148147
self._png_buffer)
149148

150149
# Swap the renderer frames

lib/matplotlib/delaunay/_delaunay.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "VoronoiDiagramGenerator.h"
77
#include "delaunay_utils.h"
88
#include "natneighbors.h"
9-
#include "numpy/noprefix.h"
9+
#include "numpy/ndarrayobject.h"
1010

1111
// support numpy 1.6 - this macro got renamed and deprecated at once in 1.7
1212
#ifndef NPY_ARRAY_IN_ARRAY
@@ -123,7 +123,7 @@ static PyObject* getMesh(int npoints, double *x, double *y)
123123
int tri0, tri1, reg0, reg1;
124124
double tri0x, tri0y, tri1x, tri1y;
125125
int length, numtri, i, j;
126-
intp dim[MAX_DIMS];
126+
npy_intp dim[NPY_MAXDIMS];
127127
int *edge_db_ptr, *tri_edges_ptr, *tri_nbrs_ptr;
128128
double *vertices_ptr;
129129
VoronoiDiagramGenerator vdg;
@@ -221,7 +221,7 @@ static PyObject* getMesh(int npoints, double *x, double *y)
221221
static PyObject *linear_planes(int ntriangles, double *x, double *y, double *z,
222222
int *nodes)
223223
{
224-
intp dims[2];
224+
npy_intp dims[2];
225225
PyObject *planes;
226226
int i;
227227
double *planes_ptr;
@@ -286,7 +286,7 @@ static PyObject *linear_interpolate_grid(double x0, double x1, int xsteps,
286286
int rowtri, coltri, tri;
287287
PyObject *z;
288288
double *z_ptr;
289-
intp dims[2];
289+
npy_intp dims[2];
290290

291291
dims[0] = ysteps;
292292
dims[1] = xsteps;
@@ -596,7 +596,7 @@ static PyObject *nn_interpolate_method(PyObject *self, PyObject *args)
596596
double x0, x1, y0, y1, defvalue;
597597
int xsteps, ysteps;
598598
int npoints, ntriangles;
599-
intp dims[2];
599+
npy_intp dims[2];
600600

601601
if (!PyArg_ParseTuple(args, "ddiddidOOOOOO", &x0, &x1, &xsteps,
602602
&y0, &y1, &ysteps, &defvalue, &pyx, &pyy, &pyz, &pycenters, &pynodes,

lib/matplotlib/figure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,8 @@ def draw(self, renderer):
10451045
ims = [(im.make_image(mag), im.ox, im.oy, im.get_alpha())
10461046
for im in self.images]
10471047

1048-
im = _image.from_images(self.bbox.height * mag,
1049-
self.bbox.width * mag,
1048+
im = _image.from_images(int(self.bbox.height * mag),
1049+
int(self.bbox.width * mag),
10501050
ims)
10511051

10521052
im.is_grayscale = False

0 commit comments

Comments
 (0)
0