Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3879436

Browse files
committed
added argb32 image support
svn path=/trunk/matplotlib/; revision=662
1 parent a7b574c commit 3879436

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# numarray. You can build the image module with either Numeric or
1515
# numarray or both. By default, matplotlib will build support for
1616
# whatever array packages you have installed.
17-
BUILD_IMAGE = 0
17+
BUILD_IMAGE = 1
1818

1919
# Build the antigrain geometry toolkit. Agg makes heavy use of
2020
# templates, so it probably requires a fairly recent compiler to build
@@ -23,14 +23,14 @@
2323
BUILD_AGG = 1
2424

2525
# Render Agg to the GTK canvas
26-
BUILD_GTKAGG = 0
27-
#BUILD_GTKAGG = 'auto'
26+
#BUILD_GTKAGG = 0
27+
BUILD_GTKAGG = 'auto'
2828

2929
# build TK GUI with Agg renderer ; requires Tkinter Python extension
3030
# and Tk includes
3131
# Use False or 0 if you don't want to build
32-
BUILD_TKAGG = 0
33-
#BUILD_TKAGG = 'auto'
32+
#BUILD_TKAGG = 0
33+
BUILD_TKAGG = 'auto'
3434

3535
# build a small extension to manage the focus on win32 platforms.
3636
#BUILD_WINDOWING = 0

src/_image.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "agg_scanline_bin.h"
2727
#include "agg_scanline_u.h"
2828
#include "agg_renderer_scanline.h"
29-
29+
#include "util/agg_color_conv_rgb8.h"
3030
#include "_image.h"
3131
#include "mplutils.h"
3232

@@ -200,6 +200,38 @@ Image::as_str(const Py::Tuple& args) {
200200
}
201201

202202

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+
203235
char Image::reset_matrix__doc__[] =
204236
"reset_matrix()"
205237
"\n"
@@ -583,6 +615,7 @@ Image::init_type() {
583615
add_varargs_method( "apply_scaling", &Image::apply_scaling, Image::apply_scaling__doc__);
584616
add_varargs_method( "apply_translation", &Image::apply_translation, Image::apply_translation__doc__);
585617
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__);
586619
add_varargs_method( "get_aspect", &Image::get_aspect, Image::get_aspect__doc__);
587620
add_varargs_method( "get_interpolation", &Image::get_interpolation, Image::get_interpolation__doc__);
588621
add_varargs_method( "get_size", &Image::get_size, Image::get_size__doc__);

src/_image.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Image : public Py::PythonExtension<Image> {
2727
Py::Object apply_scaling(const Py::Tuple& args);
2828
Py::Object apply_translation(const Py::Tuple& args);
2929
Py::Object as_str(const Py::Tuple& args);
30+
Py::Object buffer_argb32(const Py::Tuple& args);
3031
Py::Object reset_matrix(const Py::Tuple& args);
3132
Py::Object resize(const Py::Tuple& args);
3233
Py::Object get_aspect(const Py::Tuple& args);
@@ -61,6 +62,7 @@ class Image : public Py::PythonExtension<Image> {
6162
static char apply_scaling__doc__[];
6263
static char apply_translation__doc__[];
6364
static char as_str__doc__[];
65+
static char buffer_argb32__doc__[];
6466
static char reset_matrix__doc__[];
6567
static char resize__doc__[];
6668
static char get_aspect__doc__[];

0 commit comments

Comments
 (0)