Thanks Nicolas,

I learnt a lot from your way of doing it!

Simon

On 13/01/2010 11:17, Nicolas Lelong wrote:
Simon,

it seems that I wrapped the same videoinput library you're using.

I wrapped the getPixels the following way : python script is responsible of the memory allocation for pixels buffer (in a correctly sized string).

The getPixels function is wrapped as follows :

namespace {

bool videoInput_getPixels(videoInput& input, int device_id, python::object memory_buffer)
  {
    PyObject* pyObject = memory_buffer.ptr();
    if (PyString_CheckExact(pyObject))
    {
      Py_ssize_t string_size = PyString_Size(pyObject);
if (string_size >= Py_ssize_t(input.getWidth(device_id)) * Py_ssize_t(input.getHeight(device_id)) * Py_ssize_t(3))
      {
unsigned char* pixels = reinterpret_cast<unsigned char*>(PyString_AsString(pyObject));

        return input.getPixels(device_id, pixels, false, false);
      }
    }
    return false;
  }

};

python::class_<videoInput, boost::noncopyable> klass("VideoInput");
klass.def("getPixels", videoInput_getPixels);

This certainly lacks some error checking for the actual 'memory_buffer' parameter type, but can give you a clue.

HTH,

Nicolas

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to