Hi,

I'm porting a lib to Python-3.

This code works with Python-2

------------------------------------------------------
const std::string Image::getExifThumbnailData()
{
    Exiv2::DataBuf buffer = _getExifThumbnail()->copy();
    // Copy the data buffer in a string.
    // First allocate the memory for the whole string...
    std::string data = std::string(buffer.size_, ' ');
    // ... then fill it with the raw data.
    for(unsigned int i = 0; i < buffer.size_; ++i)
    {
        data[i] = buffer.pData_[i];
    }
    return data;
-----------------------------------------------------

The object Exiv2::DataBuf contain the pixel's values of an image [R,G,B,R,G,B,...]
It is described here (1)

With Python-3 I get this error:

    buf_ = self._metadata._image._getExifThumbnailData()
TypeError: No to_python (by-value) converter found for C++ type: std::vector<char, std::allocator<char> >


Then, I've made some tests with memoryView, like this:

-----------------------------------------------------
boost::python::object Image::getExifThumbnailData()
{
    Exiv2::DataBuf buffer = _getExifThumbnail()->copy();
    Py_ssize_t size = buffer.size_;
    Py_buffer py_buffer;
    PyObject exporter;
int res = PyBuffer_FillInfo(&py_buffer, &exporter, &buffer.pData_, size,
                                true, PyBUF_CONTIG_RO);
    if (res == -1) {
        PyErr_Print();
        exit(EXIT_FAILURE);
    }
    boost::python::object memoryView(boost::python::handle<>
                                    (PyMemoryView_FromMemory
                                    (&exporter, size, PyBUF_READ)));
    return memoryView;
}
----------------------------------------------------
But that doesn't compile.

src/exiv2wrapper.cpp: In member function ‘boost::python::api::object exiv2wrapper::Image::getExifThumbnailData()’: src/exiv2wrapper.cpp:504:65: error: cannot convert ‘PyObject* {aka _object*}’ to ‘char*’ for argument ‘1’ to ‘PyObject* PyMemoryView_FromMemory(char*, Py_ssize_t, int)’
                                     (&exporter, size, PyBUF_READ)));


(1) DataBuf: http://www.exiv2.org/doc/classExiv2_1_1DataBuf.html


Regards,


Vincent

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

Reply via email to