Port all buffer related code to the new Shiboken buffer interface.
Reviewer: Renato Araújo <renato.filho@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
7109418dbe
commit
f1c7c78694
3 changed files with 36 additions and 66 deletions
|
|
@ -415,13 +415,11 @@
|
|||
<value-type name="QBitmap" >
|
||||
<modify-function signature="fromData(QSize,const uchar*,QImage::Format)">
|
||||
<modify-argument index="2">
|
||||
<replace-type modified-type="PyObject"/>
|
||||
<replace-type modified-type="PyBuffer"/>
|
||||
</modify-argument>
|
||||
<inject-code>
|
||||
const void* buffer;
|
||||
Py_ssize_t size;
|
||||
if (PyObject_AsReadBuffer(%PYARG_2, &buffer, &size) != -1)
|
||||
%PYARG_0 = %CONVERTTOPYTHON[QBitmap](QBitmap::fromData(%1, (const uchar*)buffer, %3));
|
||||
uchar* buffer = (uchar*) Shiboken::Buffer::getPointer(%PYARG_2);
|
||||
%PYARG_0 = %CONVERTTOPYTHON[QBitmap](QBitmap::fromData(%1, buffer, %3));
|
||||
</inject-code>
|
||||
</modify-function>
|
||||
</value-type>
|
||||
|
|
@ -553,25 +551,24 @@
|
|||
<replace-type modified-type="PyObject"/>
|
||||
</modify-argument>
|
||||
<inject-code>
|
||||
%PYARG_0 = PyBuffer_FromMemory(const_cast<char*>(%CPPSELF.data()), %CPPSELF.size());
|
||||
%PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.data(), %CPPSELF.size());
|
||||
</inject-code>
|
||||
</modify-function>
|
||||
<modify-function signature="setData(const char*,uint)">
|
||||
<modify-argument index="1">
|
||||
<replace-type modified-type="PyBuffer"/>
|
||||
<conversion-rule class="target">
|
||||
PyObject *%out = PyBuffer_FromMemory(const_cast<char*>(%in), size);
|
||||
PyObject* %out = Shiboken::Buffer::newObject(%in, size);
|
||||
</conversion-rule>
|
||||
<conversion-rule class="native">
|
||||
const char *%out;
|
||||
Py_ssize_t buffer_len;
|
||||
PyObject_AsCharBuffer(arg, &%out, &buffer_len);
|
||||
Py_ssize_t bufferLen;
|
||||
char* %out = (char*) Shiboken::Buffer::getPointer(arg, &bufferLen);
|
||||
</conversion-rule>
|
||||
</modify-argument>
|
||||
<modify-argument index="2">
|
||||
<remove-argument/>
|
||||
<conversion-rule class="native">
|
||||
uint %out = buffer_len;
|
||||
uint %out = bufferLen;
|
||||
</conversion-rule>
|
||||
</modify-argument>
|
||||
</modify-function>
|
||||
|
|
@ -975,20 +972,12 @@
|
|||
</extra-includes>
|
||||
|
||||
<template name="qimage_buffer_constructor">
|
||||
PyTypeObject* pyType = reinterpret_cast<PyTypeObject*>(%PYARG_1->ob_type);
|
||||
if (pyType->tp_as_buffer
|
||||
&& pyType->tp_as_buffer->bf_getreadbuffer
|
||||
&& pyType->tp_as_buffer->bf_getsegcount(%PYARG_1, 0) == 1) {
|
||||
void* ptr;
|
||||
pyType->tp_as_buffer->bf_getreadbuffer(%PYARG_1, 0, &ptr);
|
||||
%0 = new %TYPE((uchar*)ptr, %ARGS);
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "The object must support buffer protocol with just one segment.");
|
||||
}
|
||||
uchar* ptr = (uchar*) Shiboken::Buffer::getPointer(%PYARG_1);
|
||||
%0 = new %TYPE(ptr, %ARGS);
|
||||
</template>
|
||||
<modify-function signature="QImage(uchar *,int,int,int,QImage::Format)">
|
||||
<modify-argument index="1">
|
||||
<replace-type modified-type="PyObject"/>
|
||||
<replace-type modified-type="PyBuffer"/>
|
||||
</modify-argument>
|
||||
<inject-code>
|
||||
<insert-template name="qimage_buffer_constructor">
|
||||
|
|
@ -998,7 +987,7 @@
|
|||
</modify-function>
|
||||
<modify-function signature="QImage(uchar*,int,int,QImage::Format)">
|
||||
<modify-argument index="1">
|
||||
<replace-type modified-type="PyObject"/>
|
||||
<replace-type modified-type="PyBuffer"/>
|
||||
</modify-argument>
|
||||
<inject-code>
|
||||
<insert-template name="qimage_buffer_constructor">
|
||||
|
|
@ -1054,23 +1043,23 @@
|
|||
|
||||
<modify-function signature="constBits()const" since="4.7">
|
||||
<inject-code>
|
||||
%PYARG_0 = PyBuffer_FromMemory(const_cast<uchar*>(%CPPSELF.%FUNCTION_NAME()), %CPPSELF.byteCount());
|
||||
%PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.byteCount());
|
||||
</inject-code>
|
||||
</modify-function>
|
||||
<modify-function signature="bits()">
|
||||
<inject-code>
|
||||
// byteCount() is only available on Qt4.7, so we use bytesPerLine * height
|
||||
%PYARG_0 = PyBuffer_FromReadWriteMemory(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.bytesPerLine() * %CPPSELF.height());
|
||||
%PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.bytesPerLine() * %CPPSELF.height(), Shiboken::Buffer::ReadWrite);
|
||||
</inject-code>
|
||||
</modify-function>
|
||||
<modify-function signature="constScanLine(int)const" since="4.7">
|
||||
<inject-code>
|
||||
%PYARG_0 = PyBuffer_FromMemory(const_cast<uchar*>(%CPPSELF.%FUNCTION_NAME(%1)), %CPPSELF.bytesPerLine());
|
||||
%PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1), %CPPSELF.bytesPerLine());
|
||||
</inject-code>
|
||||
</modify-function>
|
||||
<modify-function signature="scanLine(int)">
|
||||
<inject-code>
|
||||
%PYARG_0 = PyBuffer_FromReadWriteMemory(%CPPSELF.%FUNCTION_NAME(%1), %CPPSELF.bytesPerLine());
|
||||
%PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1), %CPPSELF.bytesPerLine(), Shiboken::Buffer::ReadWrite);
|
||||
</inject-code>
|
||||
</modify-function>
|
||||
<!--
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue