Re: help with typemap
William S Fulton <[email protected]> Wed, 23 Dec 2020 19:51:53 +0000
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CANGqftBLA8EUR3HC0o+YpOi4FvD3E9wXVvdw04evdP_UEqshag@mail.gmail.com> |
Looks like you are using it in an overloaded C++ function. You need to also provide a 'typecheck' typemap in addition to the 'in' typemap. William On Sat, 28 Nov 2020 at 03:12, Robert Arkiletian <[email protected]> wrote: > Hi, I'm trying to add support to read a JPEG from memory from a C++ > library (FLTK) to a python wrapper library (pyFltk) using swig 4.0.1 > in Ubuntu 20.04 > > Here is my typemap in Fl_JPEG_Image.i > ---------------------------------------------------------------- > > %{ > #include "FL/Fl_JPEG_Image.H" > %} > > %typemap(in) const unsigned char *buffer { > > const void *buffer; > Py_buffer view; > int failure = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO); > if (!failure) { > buffer = view.buf; > PyBuffer_Release(&view); > $1 = (uchar *)buffer; > } > else { > PyErr_Clear(); > PyErr_SetString(PyExc_TypeError,"does not support > single-segment readable buffer interface"); > return NULL; > } > } > %include "FL/Fl_JPEG_Image.H" > ---------------------------------------------------------------- > > Here is the header for the C++ library: > Parameters for ctor of JPEG image from memory > name: A unique name or NULL > data: A pointer to the memory location of the JPEG image > > class FL_EXPORT Fl_JPEG_Image : public Fl_RGB_Image { > > public: > > Fl_JPEG_Image(const char *filename); > Fl_JPEG_Image(const char *name, const unsigned char *data); > }; > ---------------------------------------------------------------- > > I keep getting this error > > Traceback (most recent call last): > File "image_pil_jpg.py", line 17, in <module> > pic = jpg_resize('cat.jpg', 300) > File "image_pil_jpg.py", line 15, in jpg_resize > return Fl_JPEG_Image(None, temp.getvalue()) > File > "/usr/local/lib/python3.8/dist-packages/pyFltk-1.3.5-py3.8-linux-x86_64.egg/fltk/fltk.py", > line 8732, in __init__ > _fltk.Fl_JPEG_Image_swiginit(self, _fltk.new_Fl_JPEG_Image(_self, > *args)) > TypeError: in method 'new_Fl_JPEG_Image', argument 3 of type 'unsigned > char const *' > Additional information: > Wrong number or type of arguments for overloaded function > 'new_Fl_JPEG_Image'. > Possible C/C++ prototypes are: > Fl_JPEG_Image::Fl_JPEG_Image(char const *) > Fl_JPEG_Image::Fl_JPEG_Image(PyObject *,char const *,unsigned char > const *) > ---------------------------------------------------------------- > > Here is the python test code > > import fltk > from PIL import Image > import io > > img = Image.open('cat.jpg') > temp = io.BytesIO() #byte stream memory object > img.save(temp,format="JPEG") > pic= fltk.Fl_JPEG_Image(None, temp.getbuffer()) > > > _______________________________________________ > Swig-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/swig-user > _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user