1 /* File : Fl_PNG_Image.i */ 2 //%module Fl_PNG_Image 3 4 %feature("docstring") ::Fl_PNG_Image 5 """ 6 The Fl_PNG_Image class supports loading, caching, and drawing of Portable 7 Network Graphics (PNG) image files. The class loads colormapped and 8 full-color images and handles color- and alpha-based transparency. 9 """ ; 10 11 %{ 12 #include "FL/Fl_PNG_Image.H" 13 %} 14 15 //%include "macros.i" 16 //CHANGE_OWNERSHIP(Fl_PNG_Image) 17 18 %typemap(in) const unsigned char *buffer { 19 /* Check if the input support the buffer protocol */ 20 Py_ssize_t size_buffer; 21 const void * buffer; 22 int failure = PyObject_AsReadBuffer($input,&buffer,&size_buffer); 23 if (!failure) { 24 // work with array object 25 $1 = (uchar *) buffer; 26 } else { 27 // work with list object 28 // clear the error from PyObject_AsReadBuffer 29 PyErr_Clear(); 30 size_buffer=0; 31 buffer=0; 32 /* Check if is a list */ 33 if (PyList_Check($input)) { 34 int size = PyList_Size($input); 35 int i = 0; 36 $1 = (uchar *) malloc((size+1)*sizeof(char)); 37 for (i = 0; i < size; i++) { 38 PyObject *o = PyList_GetItem($input,i); 39 if (PyInt_Check(o)) 40 $1[i] = (uchar)PyInt_AsLong(o); 41 else { 42 PyErr_SetString(PyExc_TypeError,"list must contain ints"); 43 free($1); 44 return NULL; 45 } 46 } 47 $1[i] = 0; 48 } else { 49 PyErr_SetString(PyExc_TypeError,"not a list or does not support single-segment readable buffer interface"); 50 return NULL; 51 } 52 } 53 } 54 55 %include "FL/Fl_PNG_Image.H" 56