|
6 | 6 | #ifndef MPL_BACKEND_AGG_H
|
7 | 7 | #define MPL_BACKEND_AGG_H
|
8 | 8 |
|
| 9 | +#include <pybind11/pybind11.h> |
| 10 | + |
9 | 11 | #include <cmath>
|
10 | 12 | #include <algorithm>
|
| 13 | +#include <functional> |
11 | 14 |
|
12 | 15 | #include "agg_alpha_mask_u8.h"
|
13 | 16 | #include "agg_conv_curve.h"
|
|
40 | 43 | #include "array.h"
|
41 | 44 | #include "agg_workaround.h"
|
42 | 45 |
|
| 46 | +namespace py = pybind11; |
| 47 | + |
43 | 48 | /**********************************************************************/
|
44 | 49 |
|
45 | 50 | // a helper class to pass agg::buffer objects around.
|
@@ -728,7 +733,7 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
|
728 | 733 | rendererBase.reset_clipping(true);
|
729 | 734 | if (angle != 0.0) {
|
730 | 735 | agg::rendering_buffer srcbuf(
|
731 |
| - image.data(), (unsigned)image.shape(1), |
| 736 | + image.mutable_data(0, 0), (unsigned)image.shape(1), |
732 | 737 | (unsigned)image.shape(0), (unsigned)image.shape(1));
|
733 | 738 | agg::pixfmt_gray8 pixf_img(srcbuf);
|
734 | 739 |
|
@@ -828,8 +833,9 @@ inline void RendererAgg::draw_image(GCAgg &gc,
|
828 | 833 | bool has_clippath = render_clippath(gc.clippath.path, gc.clippath.trans, gc.snap_mode);
|
829 | 834 |
|
830 | 835 | agg::rendering_buffer buffer;
|
831 |
| - buffer.attach( |
832 |
| - image.data(), (unsigned)image.shape(1), (unsigned)image.shape(0), -(int)image.shape(1) * 4); |
| 836 | + buffer.attach(image.mutable_data(0, 0, 0), |
| 837 | + (unsigned)image.shape(1), (unsigned)image.shape(0), |
| 838 | + -(int)image.shape(1) * 4); |
833 | 839 | pixfmt pixf(buffer);
|
834 | 840 |
|
835 | 841 | if (has_clippath) {
|
@@ -1226,14 +1232,27 @@ inline void RendererAgg::draw_gouraud_triangles(GCAgg &gc,
|
1226 | 1232 | ColorArray &colors,
|
1227 | 1233 | agg::trans_affine &trans)
|
1228 | 1234 | {
|
| 1235 | + if (points.shape(0) && !check_trailing_shape(points, "points", 3, 2)) { |
| 1236 | + throw py::error_already_set(); |
| 1237 | + } |
| 1238 | + if (colors.shape(0) && !check_trailing_shape(colors, "colors", 3, 4)) { |
| 1239 | + throw py::error_already_set(); |
| 1240 | + } |
| 1241 | + if (points.shape(0) != colors.shape(0)) { |
| 1242 | + throw py::value_error( |
| 1243 | + "points and colors arrays must be the same length, got " + |
| 1244 | + std::to_string(points.shape(0)) + " points and " + |
| 1245 | + std::to_string(colors.shape(0)) + "colors"); |
| 1246 | + } |
| 1247 | + |
1229 | 1248 | theRasterizer.reset_clipping();
|
1230 | 1249 | rendererBase.reset_clipping(true);
|
1231 | 1250 | set_clipbox(gc.cliprect, theRasterizer);
|
1232 | 1251 | bool has_clippath = render_clippath(gc.clippath.path, gc.clippath.trans, gc.snap_mode);
|
1233 | 1252 |
|
1234 | 1253 | for (int i = 0; i < points.shape(0); ++i) {
|
1235 |
| - typename PointArray::sub_t point = points.subarray(i); |
1236 |
| - typename ColorArray::sub_t color = colors.subarray(i); |
| 1254 | + auto point = std::bind(points, i, std::placeholders::_1, std::placeholders::_2); |
| 1255 | + auto color = std::bind(colors, i, std::placeholders::_1, std::placeholders::_2); |
1237 | 1256 |
|
1238 | 1257 | _draw_gouraud_triangle(point, color, trans, has_clippath);
|
1239 | 1258 | }
|
|
0 commit comments