diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2000-03-03 16:01:11 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2000-03-03 16:01:11 (GMT) |
commit | 484be6152fc767a947060a2d0dfba56695ff5a2c (patch) | |
tree | de190475fcd75d885d9c963acefc5dba8d1d5eff | |
parent | 9428fa607b6edc7c5ef46814cd869291a8b4619e (diff) | |
download | cpython-484be6152fc767a947060a2d0dfba56695ff5a2c.zip cpython-484be6152fc767a947060a2d0dfba56695ff5a2c.tar.gz cpython-484be6152fc767a947060a2d0dfba56695ff5a2c.tar.bz2 |
Added methods getdata() and putdata() to obtain the data in a bitmap.
-rw-r--r-- | Mac/Modules/qd/Qdmodule.c | 38 | ||||
-rw-r--r-- | Mac/Modules/qd/qdsupport.py | 30 |
2 files changed, 68 insertions, 0 deletions
diff --git a/Mac/Modules/qd/Qdmodule.c b/Mac/Modules/qd/Qdmodule.c index f8dba7e..299c9ca 100644 --- a/Mac/Modules/qd/Qdmodule.c +++ b/Mac/Modules/qd/Qdmodule.c @@ -297,7 +297,45 @@ static void BMObj_dealloc(self) PyMem_DEL(self); } +static PyObject *BMObj_getdata(_self, _args) + BitMapObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + + int from, length; + char *cp; + + if ( !PyArg_ParseTuple(_args, "ii", &from, &length) ) + return NULL; + cp = _self->ob_itself->baseAddr+from; + return PyString_FromStringAndSize(cp, length); + +} + +static PyObject *BMObj_putdata(_self, _args) + BitMapObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + + int from, length; + char *cp, *icp; + + if ( !PyArg_ParseTuple(_args, "is#", &from, &icp, &length) ) + return NULL; + cp = _self->ob_itself->baseAddr+from; + memcpy(cp, icp, length); + Py_INCREF(Py_None); + return Py_None; + +} + static PyMethodDef BMObj_methods[] = { + {"getdata", (PyCFunction)BMObj_getdata, 1, + "(int start, int size) -> string. Return bytes from the bitmap"}, + {"putdata", (PyCFunction)BMObj_putdata, 1, + "(int start, string data). Store bytes into the bitmap"}, {NULL, NULL, 0} }; diff --git a/Mac/Modules/qd/qdsupport.py b/Mac/Modules/qd/qdsupport.py index 7f1db82..33e8832 100644 --- a/Mac/Modules/qd/qdsupport.py +++ b/Mac/Modules/qd/qdsupport.py @@ -310,6 +310,36 @@ for f in functions: module.add(f) ##for f in r_methods: r_object.add(f) ##for f in po_methods: po_object.add(f) +# Manual generator: get data out of a bitmap +getdata_body = """ +int from, length; +char *cp; + +if ( !PyArg_ParseTuple(_args, "ii", &from, &length) ) + return NULL; +cp = _self->ob_itself->baseAddr+from; +return PyString_FromStringAndSize(cp, length); +""" +f = ManualGenerator("getdata", getdata_body) +f.docstring = lambda: """(int start, int size) -> string. Return bytes from the bitmap""" +bm_object.add(f) + +# Manual generator: store data in a bitmap +putdata_body = """ +int from, length; +char *cp, *icp; + +if ( !PyArg_ParseTuple(_args, "is#", &from, &icp, &length) ) + return NULL; +cp = _self->ob_itself->baseAddr+from; +memcpy(cp, icp, length); +Py_INCREF(Py_None); +return Py_None; +""" +f = ManualGenerator("putdata", putdata_body) +f.docstring = lambda: """(int start, string data). Store bytes into the bitmap""" +bm_object.add(f) + # # We manually generate a routine to create a BitMap from python data. # |