Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 484be61

Browse files
committed
Added methods getdata() and putdata() to obtain the data in a bitmap.
1 parent 9428fa6 commit 484be61

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

Mac/Modules/qd/Qdmodule.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,45 @@ static void BMObj_dealloc(self)
297297
PyMem_DEL(self);
298298
}
299299

300+
static PyObject *BMObj_getdata(_self, _args)
301+
BitMapObject *_self;
302+
PyObject *_args;
303+
{
304+
PyObject *_res = NULL;
305+
306+
int from, length;
307+
char *cp;
308+
309+
if ( !PyArg_ParseTuple(_args, "ii", &from, &length) )
310+
return NULL;
311+
cp = _self->ob_itself->baseAddr+from;
312+
return PyString_FromStringAndSize(cp, length);
313+
314+
}
315+
316+
static PyObject *BMObj_putdata(_self, _args)
317+
BitMapObject *_self;
318+
PyObject *_args;
319+
{
320+
PyObject *_res = NULL;
321+
322+
int from, length;
323+
char *cp, *icp;
324+
325+
if ( !PyArg_ParseTuple(_args, "is#", &from, &icp, &length) )
326+
return NULL;
327+
cp = _self->ob_itself->baseAddr+from;
328+
memcpy(cp, icp, length);
329+
Py_INCREF(Py_None);
330+
return Py_None;
331+
332+
}
333+
300334
static PyMethodDef BMObj_methods[] = {
335+
{"getdata", (PyCFunction)BMObj_getdata, 1,
336+
"(int start, int size) -> string. Return bytes from the bitmap"},
337+
{"putdata", (PyCFunction)BMObj_putdata, 1,
338+
"(int start, string data). Store bytes into the bitmap"},
301339
{NULL, NULL, 0}
302340
};
303341

Mac/Modules/qd/qdsupport.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,36 @@ def outputGetattrHook(self):
310310
##for f in r_methods: r_object.add(f)
311311
##for f in po_methods: po_object.add(f)
312312

313+
# Manual generator: get data out of a bitmap
314+
getdata_body = """
315+
int from, length;
316+
char *cp;
317+
318+
if ( !PyArg_ParseTuple(_args, "ii", &from, &length) )
319+
return NULL;
320+
cp = _self->ob_itself->baseAddr+from;
321+
return PyString_FromStringAndSize(cp, length);
322+
"""
323+
f = ManualGenerator("getdata", getdata_body)
324+
f.docstring = lambda: """(int start, int size) -> string. Return bytes from the bitmap"""
325+
bm_object.add(f)
326+
327+
# Manual generator: store data in a bitmap
328+
putdata_body = """
329+
int from, length;
330+
char *cp, *icp;
331+
332+
if ( !PyArg_ParseTuple(_args, "is#", &from, &icp, &length) )
333+
return NULL;
334+
cp = _self->ob_itself->baseAddr+from;
335+
memcpy(cp, icp, length);
336+
Py_INCREF(Py_None);
337+
return Py_None;
338+
"""
339+
f = ManualGenerator("putdata", putdata_body)
340+
f.docstring = lambda: """(int start, string data). Store bytes into the bitmap"""
341+
bm_object.add(f)
342+
313343
#
314344
# We manually generate a routine to create a BitMap from python data.
315345
#

0 commit comments

Comments
 (0)