8000 Increase performance of draw_markers in Agg backend · dmcdougall/matplotlib@8705b9e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8705b9e

Browse files
committed
Increase performance of draw_markers in Agg backend
svn path=/branches/transforms/; revision=4488
1 parent 383bc28 commit 8705b9e

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/_backend_agg.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ RendererAgg::draw_markers(const Py::Tuple& args) {
549549
agg::serialized_scanlines_adaptor_aa8 sa;
550550
agg::serialized_scanlines_adaptor_aa8::embedded_scanline sl;
551551

552-
while (path_quantized.vertex(&x, &y) != agg::path_cmd_stop) {
553-
if (has_clippath) {
552+
if (has_clippath) {
553+
while (path_quantized.vertex(&x, &y) != agg::path_cmd_stop) {
554554
pixfmt_amask_type pfa(*pixFmt, *alphaMask);
555555
amask_ren_type r(pfa);
556556
amask_aa_renderer_type ren(r);
@@ -563,7 +563,9 @@ RendererAgg::draw_markers(const Py::Tuple& args) {
563563
ren.color(gc.color);
564564
sa.init(strokeCache, strokeSize, x, y);
565565
agg::render_scanlines(sa, sl, ren);
566-
} else {
566+
}
567+
} else {
568+
while (path_quantized.vertex(&x, &y) != agg::path_cmd_stop) {
567569
if (face.first) {
568570
rendererAA->color(face.second);
569571
sa.init(fillCache, fillSize, x, y);
@@ -1139,6 +1141,7 @@ class QuadMeshGenerator {
11391141
m_iterator(0), m_m(m), m_n(n), m_coordinates(coordinates) {
11401142
}
11411143

1144+
private:
11421145
inline unsigned vertex(unsigned idx, double* x, double* y) {
11431146
size_t m = (idx & 0x2) ? (m_m + 1) : m_m;
11441147
size_t n = (idx+1 & 0x2) ? (m_n + 1) : m_n;
@@ -1148,8 +1151,9 @@ class QuadMeshGenerator {
11481151
return (idx) ? agg::path_cmd_line_to : agg::path_cmd_move_to;
11491152
}
11501153

1154+
public:
11511155
inline unsigned vertex(double* x, double* y) {
1152-
if (m_iterator >= total_vertices())
1156+
if (m_iterator >= total_vertices())
11531157
return agg::path_cmd_stop;
11541158
return vertex(m_iterator++, x, y);
11551159
}
@@ -1496,7 +1500,7 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args) {
14961500
int ymin = height;
14971501
int xmax = 0;
14981502
int ymax = 0;
1499-
1503+
15001504
// Looks at the alpha channel to find the minimum extents of the image
15011505
unsigned char* pixel = pixBuffer + 3;
15021506
for (int y = 0; y < (int)height; ++y) {
@@ -1520,11 +1524,11 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args) {
15201524
ymin = std::max(0, ymin - 1);
15211525
xmax = std::min(xmax, (int)width);
15221526
ymax = std::min(ymax, (int)height);
1523-
1527+
15241528
newwidth = xmax - xmin;
15251529
newheight = ymax - ymin;
15261530
int newsize = newwidth * newheight * 4;
1527-
1531+
15281532
unsigned char* buf = new unsigned char[newsize];
15291533
unsigned int* dst = (unsigned int*)buf;
15301534
unsigned int* src = (unsigned int*)pixBuffer;
@@ -1540,7 +1544,7 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args) {
15401544
bounds[1] = Py::Int(ymin);
15411545
bounds[2] = Py::Int(newwidth);
15421546
bounds[3] = Py::Int(newheight);
1543-
1547+
15441548
Py::Tuple result(2);
15451549
result[0] = data;
15461550
result[1] = bounds;

src/agg_py_path_iterator.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PathIterator {
1717
m_vertices(NULL), m_codes(NULL), m_iterator(0) {
1818
Py::Object vertices_obj = path_obj.getAttr("vertices");
1919
Py::Object codes_obj = path_obj.getAttr("codes");
20-
20+
2121
m_vertices = (PyArrayObject*)PyArray_FromObject
2222
(vertices_obj.ptr(), PyArray_DOUBLE, 2, 2);
2323
if (!m_vertices || PyArray_NDIM(m_vertices) != 2 || PyArray_DIM(m_vertices, 1) != 2)
@@ -26,7 +26,7 @@ class PathIterator {
2626
if (codes_obj.ptr() != Py_None) {
2727
m_codes = (PyArrayObject*)PyArray_FromObject
2828
(codes_obj.ptr(), PyArray_UINT8, 1, 1);
29-
if (!m_codes)
29+
if (!m_codes)
3030
throw Py::ValueError("Invalid codes array.");
3131
}
3232

@@ -40,18 +40,19 @@ class PathIterator {
4040

4141
static const char code_map[];
4242

43+
private:
4344
inline unsigned vertex(unsigned idx, double* x, double* y) {
44-
if (idx > m_total_vertices)
45-
throw Py::RuntimeError("Requested vertex past end");
46-
*x = *(double*)PyArray_GETPTR2(m_vertices, idx, 0);
47-
*y = *(double*)PyArray_GETPTR2(m_vertices, idx, 1);
45+
char* pair = (char*)PyArray_GETPTR2(m_vertices, idx, 0);
46+
*x = *(double*)pair;
47+
*y = *(double*)(pair + PyArray_STRIDE(m_vertices, 1));
4848
if (m_codes) {
4949
return code_map[(int)*(char *)PyArray_GETPTR1(m_codes, idx)];
5050
} else {
5151
return idx == 0 ? agg::path_cmd_move_to : agg::path_cmd_line_to;
5252
}
5353
}
5454

55+
public:
5556
inline unsigned vertex(double* x, double* y) {
5657
if (m_iterator >= m_total_vertices) return agg::path_cmd_stop;
5758
return vertex(m_iterator++, x, y);
@@ -71,10 +72,10 @@ class PathIterator {
7172
};
7273

7374
// Maps path codes on the Python side to agg path commands
74-
const char PathIterator::code_map[] =
75-
{0,
76-
agg::path_cmd_move_to,
77-
agg::path_cmd_line_to,
75+
const char PathIterator::code_map[] =
76+
{0,
77+
agg::path_cmd_move_to,
78+
agg::path_cmd_line_to,
7879
agg::path_cmd_curve3,
7980
agg::path_cmd_curve4,
8081
agg::path_cmd_end_poly | agg::path_flags_close};

0 commit comments

Comments
 (0)
0