diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2000-03-03 16:03:06 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2000-03-03 16:03:06 (GMT) |
commit | 6dc8ce9108a051ccf3337e11d5dfdcc011c325e9 (patch) | |
tree | 33796bd2aeee6961e81373a5e76f5f708ec84f5d /Mac/Modules | |
parent | 484be6152fc767a947060a2d0dfba56695ff5a2c (diff) | |
download | cpython-6dc8ce9108a051ccf3337e11d5dfdcc011c325e9.zip cpython-6dc8ce9108a051ccf3337e11d5dfdcc011c325e9.tar.gz cpython-6dc8ce9108a051ccf3337e11d5dfdcc011c325e9.tar.bz2 |
Added PutPixMapBytes() and GetPixMapBytes() functions that allow getting at
pixmap data.
Added an as_GrafPort() method to be able to use a GWorld as argument to
routines that expect a GrafPort.
Diffstat (limited to 'Mac/Modules')
-rw-r--r-- | Mac/Modules/qdoffs/Qdoffsmodule.c | 58 | ||||
-rw-r--r-- | Mac/Modules/qdoffs/qdoffssupport.py | 38 |
2 files changed, 96 insertions, 0 deletions
diff --git a/Mac/Modules/qdoffs/Qdoffsmodule.c b/Mac/Modules/qdoffs/Qdoffsmodule.c index 13ec478..37c774e 100644 --- a/Mac/Modules/qdoffs/Qdoffsmodule.c +++ b/Mac/Modules/qdoffs/Qdoffsmodule.c @@ -44,6 +44,8 @@ extern PyObject *WinObj_WhichWindow(WindowPtr); #include <QDOffscreen.h> +#define as_GrafPtr(gworld) ((GrafPtr)(gworld)) + #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ @@ -118,11 +120,27 @@ static PyObject *GWorldObj_GetGWorldPixMap(_self, _args) return _res; } +static PyObject *GWorldObj_as_GrafPtr(_self, _args) + GWorldObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + GrafPtr _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = as_GrafPtr(_self->ob_itself); + _res = Py_BuildValue("O&", + GrafObj_New, _rv); + return _res; +} + static PyMethodDef GWorldObj_methods[] = { {"GetGWorldDevice", (PyCFunction)GWorldObj_GetGWorldDevice, 1, "() -> (GDHandle _rv)"}, {"GetGWorldPixMap", (PyCFunction)GWorldObj_GetGWorldPixMap, 1, "() -> (PixMapHandle _rv)"}, + {"as_GrafPtr", (PyCFunction)GWorldObj_as_GrafPtr, 1, + "() -> (GrafPtr _rv)"}, {NULL, NULL, 0} }; @@ -544,6 +562,42 @@ static PyObject *Qdoffs_PixMap32Bit(_self, _args) return _res; } +static PyObject *Qdoffs_GetPixMapBytes(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + + PixMapHandle pm; + int from, length; + char *cp; + + if ( !PyArg_ParseTuple(_args, "O&ii", ResObj_Convert, &pm, &from, &length) ) + return NULL; + cp = GetPixBaseAddr(pm)+from; + return PyString_FromStringAndSize(cp, length); + +} + +static PyObject *Qdoffs_PutPixMapBytes(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + + PixMapHandle pm; + int from, length; + char *cp, *icp; + + if ( !PyArg_ParseTuple(_args, "O&is#", ResObj_Convert, &pm, &from, &icp, &length) ) + return NULL; + cp = GetPixBaseAddr(pm)+from; + memcpy(cp, icp, length); + Py_INCREF(Py_None); + return Py_None; + +} + static PyMethodDef Qdoffs_methods[] = { {"NewGWorld", (PyCFunction)Qdoffs_NewGWorld, 1, "(short PixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldPtr offscreenGWorld)"}, @@ -587,6 +641,10 @@ static PyMethodDef Qdoffs_methods[] = { "(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)"}, {"PixMap32Bit", (PyCFunction)Qdoffs_PixMap32Bit, 1, "(PixMapHandle pmHandle) -> (Boolean _rv)"}, + {"GetPixMapBytes", (PyCFunction)Qdoffs_GetPixMapBytes, 1, + "(pixmap, int start, int size) -> string. Return bytes from the pixmap"}, + {"PutPixMapBytes", (PyCFunction)Qdoffs_PutPixMapBytes, 1, + "(pixmap, int start, string data). Store bytes into the pixmap"}, {NULL, NULL, 0} }; diff --git a/Mac/Modules/qdoffs/qdoffssupport.py b/Mac/Modules/qdoffs/qdoffssupport.py index 43e1977..e569fea 100644 --- a/Mac/Modules/qdoffs/qdoffssupport.py +++ b/Mac/Modules/qdoffs/qdoffssupport.py @@ -36,6 +36,8 @@ QDErr = OSErrType("QDErr", 'h') includestuff = includestuff + """ #include <%s>""" % MACHEADERFILE + """ +#define as_GrafPtr(gworld) ((GrafPtr)(gworld)) + #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ """ @@ -75,6 +77,42 @@ functions = [] methods = [] execfile(INPUTFILE) +# A method to convert a GWorldPtr to a GrafPtr +f = Method(GrafPtr, 'as_GrafPtr', (GWorldPtr, 'p', InMode)) +methods.append(f) + +# +# Manual generator: get data out of a pixmap +pixmapgetbytes_body = """ +PixMapHandle pm; +int from, length; +char *cp; + +if ( !PyArg_ParseTuple(_args, "O&ii", ResObj_Convert, &pm, &from, &length) ) + return NULL; +cp = GetPixBaseAddr(pm)+from; +return PyString_FromStringAndSize(cp, length); +""" +f = ManualGenerator("GetPixMapBytes", pixmapgetbytes_body) +f.docstring = lambda: """(pixmap, int start, int size) -> string. Return bytes from the pixmap""" +functions.append(f) + +# Manual generator: store data in a pixmap +pixmapputbytes_body = """ +PixMapHandle pm; +int from, length; +char *cp, *icp; + +if ( !PyArg_ParseTuple(_args, "O&is#", ResObj_Convert, &pm, &from, &icp, &length) ) + return NULL; +cp = GetPixBaseAddr(pm)+from; +memcpy(cp, icp, length); +Py_INCREF(Py_None); +return Py_None; +""" +f = ManualGenerator("PutPixMapBytes", pixmapputbytes_body) +f.docstring = lambda: """(pixmap, int start, string data). Store bytes into the pixmap""" +functions.append(f) # add the populated lists to the generator groups # (in a different wordl the scan program would generate this) |