|
26 | 26 | #include "agg_scanline_bin.h" |
27 | 27 | #include "agg_scanline_u.h" |
28 | 28 | #include "agg_renderer_scanline.h" |
29 | | - |
| 29 | +#include "util/agg_color_conv_rgb8.h" |
30 | 30 | #include "_image.h" |
31 | 31 | #include "mplutils.h" |
32 | 32 |
|
@@ -200,6 +200,38 @@ Image::as_str(const Py::Tuple& args) { |
200 | 200 | } |
201 | 201 |
|
202 | 202 |
|
| 203 | +char Image::buffer_argb32__doc__[] = |
| 204 | +"buffer = buffer_argb32)" |
| 205 | +"\n" |
| 206 | +"Return the image buffer as agbr32\n" |
| 207 | +; |
| 208 | +Py::Object |
| 209 | +Image::buffer_argb32(const Py::Tuple& args) { |
| 210 | + //"Return the image object as argb32"; |
| 211 | + |
| 212 | + _VERBOSE("RendererAgg::buffer_argb32"); |
| 213 | + |
| 214 | + args.verify_length(0); |
| 215 | + int row_len = colsOut * 4; |
| 216 | + |
| 217 | + unsigned char* buf_tmp = new unsigned char[row_len * rowsOut]; |
| 218 | + if (buf_tmp ==NULL) |
| 219 | + throw Py::MemoryError("RendererAgg::buffer_argb32 could not allocate memory"); |
| 220 | + |
| 221 | + agg::rendering_buffer rtmp; |
| 222 | + rtmp.attach(buf_tmp, colsOut, rowsOut, row_len); |
| 223 | + |
| 224 | + color_conv(&rtmp, rbufOut, agg::color_conv_rgba32_to_argb32()); |
| 225 | + |
| 226 | + |
| 227 | + //todo: how to do this with native CXX |
| 228 | + PyObject* o = Py_BuildValue("s#", buf_tmp, row_len * rowsOut); |
| 229 | + delete [] buf_tmp; |
| 230 | + return Py::asObject(o); |
| 231 | + |
| 232 | + |
| 233 | +} |
| 234 | + |
203 | 235 | char Image::reset_matrix__doc__[] = |
204 | 236 | "reset_matrix()" |
205 | 237 | "\n" |
@@ -583,6 +615,7 @@ Image::init_type() { |
583 | 615 | add_varargs_method( "apply_scaling", &Image::apply_scaling, Image::apply_scaling__doc__); |
584 | 616 | add_varargs_method( "apply_translation", &Image::apply_translation, Image::apply_translation__doc__); |
585 | 617 | add_varargs_method( "as_str", &Image::as_str, Image::as_str__doc__); |
| 618 | + add_varargs_method( "buffer_argb32", &Image::buffer_argb32, Image::buffer_argb32__doc__); |
586 | 619 | add_varargs_method( "get_aspect", &Image::get_aspect, Image::get_aspect__doc__); |
587 | 620 | add_varargs_method( "get_interpolation", &Image::get_interpolation, Image::get_interpolation__doc__); |
588 | 621 | add_varargs_method( "get_size", &Image::get_size, Image::get_size__doc__); |
|
0 commit comments