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

Skip to content

Commit 6dd270a

Browse files
committed
added bgra32 converion buffer to image
svn path=/trunk/matplotlib/; revision=2976
1 parent e7f4654 commit 6dd270a

4 files changed

Lines changed: 56 additions & 0 deletions

File tree

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2007-01-10 Added "Subplot.label_outer" method. It will set the
2+
visibility of the ticklabels so that yticklabels are only
3+
visible in the first column and xticklabels are only
4+
visible in the last row - JDH
5+
16
2007-01-02 Added additional kwarg documentation - JDH
27

38
2006-12-28 Improved error message for nonpositive input to log

lib/matplotlib/axes.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4769,6 +4769,20 @@ def is_last_row(self):
47694769
def is_last_col(self):
47704770
return self.colNum==self.numCols-1
47714771

4772+
def label_outer(self):
4773+
"""
4774+
set the visible property on ticklabels so xticklabels are
4775+
visible only if the subplot is in the last row and yticklabels
4776+
are visible only if the subplot is in the first column
4777+
"""
4778+
lastrow = self.is_last_row()
4779+
firstcol = self.is_first_col()
4780+
for label in self.get_xticklabels():
4781+
label.set_visible(lastrow)
4782+
4783+
for label in self.get_yticklabels():
4784+
label.set_visible(firstcol)
4785+
47724786
class Subplot(SubplotBase, Axes):
47734787
"""
47744788
Emulate matlab's(TM) subplot command, creating axes with

src/_image.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,40 @@ Image::buffer_argb32(const Py::Tuple& args) {
252252
}
253253

254254

255+
char Image::buffer_bgra32__doc__[] =
256+
"buffer = buffer_bgra32()"
257+
"\n"
258+
"Return the image buffer as agbr32\n"
259+
;
260+
Py::Object
261+
Image::buffer_bgra32(const Py::Tuple& args) {
262+
//"Return the image object as bgra32";
263+
264+
_VERBOSE("RendererAgg::buffer_bgra32");
265+
266+
args.verify_length(0);
267+
268+
int row_len = colsOut * 4;
269+
270+
unsigned char* buf_tmp = new unsigned char[row_len * rowsOut];
271+
if (buf_tmp ==NULL)
272+
throw Py::MemoryError("RendererAgg::buffer_bgra32 could not allocate memory");
273+
274+
agg::rendering_buffer rtmp;
275+
rtmp.attach(buf_tmp, colsOut, rowsOut, row_len);
276+
277+
agg::color_conv(&rtmp, rbufOut, agg::color_conv_rgba32_to_bgra32());
278+
279+
//todo: how to do this with native CXX
280+
//PyObject* o = Py_BuildValue("s#", buf_tmp, row_len * rowsOut);
281+
PyObject* o = Py_BuildValue("lls#", rowsOut, colsOut,
282+
buf_tmp, row_len * rowsOut);
283+
delete [] buf_tmp;
284+
return Py::asObject(o);
285+
286+
287+
}
288+
255289
char Image::buffer_rgba__doc__[] =
256290
"buffer = buffer_rgba()"
257291
"\n"
@@ -752,6 +786,7 @@ Image::init_type() {
752786
add_varargs_method( "apply_translation", &Image::apply_translation, Image::apply_translation__doc__);
753787
add_keyword_method( "as_rgba_str", &Image::as_rgba_str, Image::as_rgba_str__doc__);
754788
add_varargs_method( "buffer_argb32", &Image::buffer_argb32, Image::buffer_argb32__doc__);
789+
add_varargs_method( "buffer_bgra32", &Image::buffer_bgra32, Image::buffer_bgra32__doc__);
755790
add_varargs_method( "buffer_rgba", &Image::buffer_rgba, Image::buffer_rgba__doc__);
756791
add_varargs_method( "get_aspect", &Image::get_aspect, Image::get_aspect__doc__);
757792
add_varargs_method( "get_interpolation", &Image::get_interpolation, Image::get_interpolation__doc__);

src/_image.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Image : public Py::PythonExtension<Image> {
2828
Py::Object apply_translation(const Py::Tuple& args);
2929
Py::Object as_rgba_str(const Py::Tuple& args, const Py::Dict& kwargs);
3030
Py::Object buffer_argb32(const Py::Tuple& args);
31+
Py::Object buffer_bgra32(const Py::Tuple& args);
3132
Py::Object buffer_rgba(const Py::Tuple& args);
3233
Py::Object reset_matrix(const Py::Tuple& args);
3334
Py::Object get_matrix(const Py::Tuple& args);
@@ -87,6 +88,7 @@ class Image : public Py::PythonExtension<Image> {
8788
static char apply_translation__doc__[];
8889
static char as_rgba_str__doc__[];
8990
static char buffer_argb32__doc__[];
91+
static char buffer_bgra32__doc__[];
9092
static char buffer_rgba__doc__[];
9193
static char reset_matrix__doc__[];
9294
static char get_matrix__doc__[];

0 commit comments

Comments
 (0)