On Mon, Feb 15, 2010 at 1:41 PM, Stefan Seefeld <seef...@sympatico.ca> wrote: > On 02/15/2010 04:26 PM, TP wrote: >> >> On Sun, Feb 14, 2010 at 5:04 PM, Stefan Seefeld<seef...@sympatico.ca> >> wrote: >> >>> >>> Yes. Do you have the definition of PIX available ? In that case, you >>> could >>> use that via class_<PIX>.... >>> >> >> Yes. The entire source of the Leptonica C Image Processing Library is >> available at http::/leptonica.com. >> >> Could you give a little more detail please? >> > > If PIX is a known type (as opposed to an opaque pointer), you can wrap that > directly, instead of having to use an indirection. > However, you still need to find a way to specify how PIX objects are to be > constructed and destroyed, and thus, you need to store PIX inside Python > objects via pointers that allow custom destructors (such as > boost::shared_ptr). > > I bet, all things considered, a wrapper class such as the one I proposed in > my previous mail is still the best way forward, as it best encapsulates how > PIX objects get constructed (incl. cloned) and destructed. > > Memory management is by far the most complex aspect of wrapping C and C++ > libraries in Python. And if your library mostly operates on raw pointers, > you really need to be careful about object lifetime, argument and return > value ownership, etc. > > > Regards, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig >
While the definition of a PIX is available, Leptonica users are supposed to use the supplied functions to access "attributes" (things like pixGetWidth(), pixSetWidth(), etc). See http://leptonica.com/library-notes.html#PIX for brief details. Since images can be large, Leptonica goes to great lengths to avoid copying them if possible so memory management is crucial. The PIX are reference counted, and it is up to the caller to make sure they use pixDestroy() at the right times. >From pix1.c: (2) The protocol to be used is: (a) Whenever you want a new handle to an existing image, call pixClone(), which just bumps a ref count. (b) Always call pixDestroy() on all handles. This decrements the ref count, nulls the handle, and only destroys the pix when pixDestroy() has been called on all handles. I probably should have picked a simpler library for my first foray into hooking C/C++ to Python :) I'm hoping I can initially do small pieces at a time as I need them. _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig