Added PutPixMapBytes() and GetPixMapBytes() functions that allow getting at
authorJack Jansen <jack.jansen@cwi.nl>
Fri, 3 Mar 2000 16:03:06 +0000 (16:03 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Fri, 3 Mar 2000 16:03:06 +0000 (16:03 +0000)
pixmap data.
Added an as_GrafPort() method to be able to use a GWorld as argument to
routines that expect a GrafPort.

Mac/Modules/qdoffs/Qdoffsmodule.c
Mac/Modules/qdoffs/qdoffssupport.py

index 13ec478c6503c63deed47fe6022798b4d85beeaa..37c774ee0ae63305ec26984ecf696aef533a2510 100644 (file)
@@ -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}
 };
 
index 43e1977e3ae4273faaeb7feeff2e5c52ccf687a9..e569feaea45fe389420eed9134652d30f5abd36f 100644 (file)
@@ -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)