Skip to content

Commit 82da311

Browse files
committed
Fixing bugs in recent changes to Qt blitting.
svn path=/branches/v0_91_maint/; revision=5123
1 parent 56f9427 commit 82da311

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

lib/matplotlib/backends/backend_qt4agg.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ def paintEvent( self, e ):
109109
# we are blitting here
110110
else:
111111
bbox = self.replot
112-
w, h = int(bbox.width()), int(bbox.height())
113-
l, t = bbox.ll().x().get(), bbox.ur().y().get()
112+
l, t = int(bbox.ll().x().get()), int(bbox.ur().y().get())
113+
r, b = int(bbox.ur().x().get()), int(bbox.ll().y().get())
114+
w = r - l
115+
h = t - b
114116
reg = self.copy_from_bbox(bbox)
115117
stringBuffer = reg.to_string_argb()
116118
qImage = QtGui.QImage(stringBuffer, w, h, QtGui.QImage.Format_ARGB32)

lib/matplotlib/backends/backend_qtagg.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ def paintEvent( self, e ):
115115
# we are blitting here
116116
else:
117117
bbox = self.replot
118-
w, h = int(bbox.width()), int(bbox.height())
119-
l, t = bbox.ll().x().get(), bbox.ur().y().get()
118+
l, t = int(bbox.ll().x().get()), int(bbox.ur().y().get())
119+
r, b = int(bbox.ur().x().get()), int(bbox.ll().y().get())
120+
w = r - l
121+
h = t - b
120122
reg = self.copy_from_bbox(bbox)
121123
stringBuffer = reg.to_string_argb()
122124
qImage = qt.QImage(stringBuffer, w, h, 32, None, 0, qt.QImage.IgnoreEndian)

src/_backend_agg.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -227,26 +227,28 @@ Py::Object BufferRegion::to_string(const Py::Tuple &args) {
227227
Py::Object BufferRegion::to_string_argb(const Py::Tuple &args) {
228228
// owned=true to prevent memory leak
229229
Py_ssize_t length;
230-
char* pix;
231-
char* begin;
232-
char* end;
233-
char tmp;
230+
unsigned char* pix;
231+
unsigned char* begin;
232+
unsigned char* end;
233+
unsigned char tmp;
234+
size_t i, j;
234235

235236
PyObject* str = PyString_FromStringAndSize((const char*)aggbuf.data, aggbuf.height*aggbuf.stride);
236-
if (PyString_AsStringAndSize(str, &begin, &length)) {
237+
if (PyString_AsStringAndSize(str, (char**)&begin, &length)) {
237238
throw Py::TypeError("Could not create memory for blit");
238239
}
239240

240241
pix = begin;
241242
end = begin + (aggbuf.height * aggbuf.stride);
242-
while (pix != end) {
243-
// Convert rgba to argb
244-
tmp = pix[3];
245-
pix[3] = pix[2];
246-
pix[2] = pix[1];
247-
pix[1] = pix[0];
248-
pix[0] = pix[3];
249-
pix += 4;
243+
for (i = 0; i < aggbuf.height; ++i) {
244+
pix = begin + i * aggbuf.stride;
245+
for (j = 0; j < aggbuf.width; ++j) {
246+
// Convert rgba to argb
247+
tmp = pix[2];
248+
pix[2] = pix[0];
249+
pix[0] = tmp;
250+
pix += 4;
251+
}
250252
}
251253

252254
return Py::String(str, true);

0 commit comments

Comments
 (0)