@@ -36,6 +36,9 @@ extern int CtlObj_Convert(PyObject *, ControlHandle *);
3636extern PyObject * GrafObj_New (GrafPtr );
3737extern int GrafObj_Convert (PyObject * , GrafPtr * );
3838
39+ extern PyObject * BMObj_New (BitMapPtr );
40+ extern int BMObj_Convert (PyObject * , BitMapPtr * );
41+
3942extern PyObject * WinObj_WhichWindow (WindowPtr );
4043
4144#include <QuickDraw.h>
@@ -102,6 +105,8 @@ static PyObject *GrafObj_getattr(self, name)
102105{
103106 if ( strcmp (name , "device" ) == 0 )
104107 return PyInt_FromLong ((long )self -> ob_itself -> device );
108+ if ( strcmp (name , "portBits" ) == 0 )
109+ return BMObj_New (& self -> ob_itself -> portBits );
105110 if ( strcmp (name , "portRect" ) == 0 )
106111 return Py_BuildValue ("O&" , PyMac_BuildRect , & self -> ob_itself -> portRect );
107112 /* XXXX Add more, as needed */
@@ -127,6 +132,91 @@ PyTypeObject GrafPort_Type = {
127132/* -------------------- End object type GrafPort -------------------- */
128133
129134
135+ /* ----------------------- Object type BitMap ----------------------- */
136+
137+ PyTypeObject BitMap_Type ;
138+
139+ #define BMObj_Check (x ) ((x)->ob_type == &BitMap_Type)
140+
141+ typedef struct BitMapObject {
142+ PyObject_HEAD
143+ BitMapPtr ob_itself ;
144+ PyObject * referred_object ;
145+ BitMap * referred_bitmap ;
146+ } BitMapObject ;
147+
148+ PyObject * BMObj_New (itself )
149+ BitMapPtr itself ;
150+ {
151+ BitMapObject * it ;
152+ if (itself == NULL ) return PyMac_Error (resNotFound );
153+ it = PyObject_NEW (BitMapObject , & BitMap_Type );
154+ if (it == NULL ) return NULL ;
155+ it -> ob_itself = itself ;
156+ it -> referred_object = NULL ;
157+ it -> referred_bitmap = NULL ;
158+ return (PyObject * )it ;
159+ }
160+ BMObj_Convert (v , p_itself )
161+ PyObject * v ;
162+ BitMapPtr * p_itself ;
163+ {
164+ if (!BMObj_Check (v ))
165+ {
166+ PyErr_SetString (PyExc_TypeError , "BitMap required" );
167+ return 0 ;
168+ }
169+ * p_itself = ((BitMapObject * )v )-> ob_itself ;
170+ return 1 ;
171+ }
172+
173+ static void BMObj_dealloc (self )
174+ BitMapObject * self ;
175+ {
176+ Py_XDECREF (self -> referred_object );
177+ if (self -> referred_bitmap ) free (self -> referred_bitmap );
178+ PyMem_DEL (self );
179+ }
180+
181+ static PyMethodDef BMObj_methods [] = {
182+ {NULL , NULL , 0 }
183+ };
184+
185+ PyMethodChain BMObj_chain = { BMObj_methods , NULL };
186+
187+ static PyObject * BMObj_getattr (self , name )
188+ BitMapObject * self ;
189+ char * name ;
190+ {
191+ if ( strcmp (name , "baseAddr" ) == 0 )
192+ return PyInt_FromLong ((long )self -> ob_itself -> baseAddr );
193+ if ( strcmp (name , "rowBytes" ) == 0 )
194+ return PyInt_FromLong ((long )self -> ob_itself -> rowBytes );
195+ if ( strcmp (name , "bounds" ) == 0 )
196+ return Py_BuildValue ("O&" , PyMac_BuildRect , & self -> ob_itself -> bounds );
197+ /* XXXX Add more, as needed */
198+
199+ return Py_FindMethodInChain (& BMObj_chain , (PyObject * )self , name );
200+ }
201+
202+ #define BMObj_setattr NULL
203+
204+ PyTypeObject BitMap_Type = {
205+ PyObject_HEAD_INIT (& PyType_Type )
206+ 0 , /*ob_size*/
207+ "BitMap" , /*tp_name*/
208+ sizeof (BitMapObject ), /*tp_basicsize*/
209+ 0 , /*tp_itemsize*/
210+ /* methods */
211+ (destructor ) BMObj_dealloc , /*tp_dealloc*/
212+ 0 , /*tp_print*/
213+ (getattrfunc ) BMObj_getattr , /*tp_getattr*/
214+ (setattrfunc ) BMObj_setattr , /*tp_setattr*/
215+ };
216+
217+ /* --------------------- End object type BitMap --------------------- */
218+
219+
130220static PyObject * Qd_SetPort (_self , _args )
131221 PyObject * _self ;
132222 PyObject * _args ;
@@ -171,6 +261,21 @@ static PyObject *Qd_GrafDevice(_self, _args)
171261 return _res ;
172262}
173263
264+ static PyObject * Qd_SetPortBits (_self , _args )
265+ PyObject * _self ;
266+ PyObject * _args ;
267+ {
268+ PyObject * _res = NULL ;
269+ BitMapPtr bm ;
270+ if (!PyArg_ParseTuple (_args , "O&" ,
271+ BMObj_Convert , & bm ))
272+ return NULL ;
273+ SetPortBits (bm );
274+ Py_INCREF (Py_None );
275+ _res = Py_None ;
276+ return _res ;
277+ }
278+
174279static PyObject * Qd_PortSize (_self , _args )
175280 PyObject * _self ;
176281 PyObject * _args ;
@@ -1001,6 +1106,26 @@ static PyObject *Qd_CloseRgn(_self, _args)
10011106 return _res ;
10021107}
10031108
1109+ static PyObject * Qd_BitMapToRegion (_self , _args )
1110+ PyObject * _self ;
1111+ PyObject * _args ;
1112+ {
1113+ PyObject * _res = NULL ;
1114+ OSErr _err ;
1115+ RgnHandle region ;
1116+ BitMapPtr bMap ;
1117+ if (!PyArg_ParseTuple (_args , "O&O&" ,
1118+ ResObj_Convert , & region ,
1119+ BMObj_Convert , & bMap ))
1120+ return NULL ;
1121+ _err = BitMapToRegion (region ,
1122+ bMap );
1123+ if (_err != noErr ) return PyMac_Error (_err );
1124+ Py_INCREF (Py_None );
1125+ _res = Py_None ;
1126+ return _res ;
1127+ }
1128+
10041129static PyObject * Qd_DisposeRgn (_self , _args )
10051130 PyObject * _self ;
10061131 PyObject * _args ;
@@ -1358,6 +1483,66 @@ static PyObject *Qd_ScrollRect(_self, _args)
13581483 return _res ;
13591484}
13601485
1486+ static PyObject * Qd_CopyBits (_self , _args )
1487+ PyObject * _self ;
1488+ PyObject * _args ;
1489+ {
1490+ PyObject * _res = NULL ;
1491+ BitMapPtr srcBits ;
1492+ BitMapPtr dstBits ;
1493+ Rect srcRect ;
1494+ Rect dstRect ;
1495+ short mode ;
1496+ RgnHandle maskRgn ;
1497+ if (!PyArg_ParseTuple (_args , "O&O&O&O&hO&" ,
1498+ BMObj_Convert , & srcBits ,
1499+ BMObj_Convert , & dstBits ,
1500+ PyMac_GetRect , & srcRect ,
1501+ PyMac_GetRect , & dstRect ,
1502+ & mode ,
1503+ ResObj_Convert , & maskRgn ))
1504+ return NULL ;
1505+ CopyBits (srcBits ,
1506+ dstBits ,
1507+ & srcRect ,
1508+ & dstRect ,
1509+ mode ,
1510+ maskRgn );
1511+ Py_INCREF (Py_None );
1512+ _res = Py_None ;
1513+ return _res ;
1514+ }
1515+
1516+ static PyObject * Qd_CopyMask (_self , _args )
1517+ PyObject * _self ;
1518+ PyObject * _args ;
1519+ {
1520+ PyObject * _res = NULL ;
1521+ BitMapPtr srcBits ;
1522+ BitMapPtr maskBits ;
1523+ BitMapPtr dstBits ;
1524+ Rect srcRect ;
1525+ Rect maskRect ;
1526+ Rect dstRect ;
1527+ if (!PyArg_ParseTuple (_args , "O&O&O&O&O&O&" ,
1528+ BMObj_Convert , & srcBits ,
1529+ BMObj_Convert , & maskBits ,
1530+ BMObj_Convert , & dstBits ,
1531+ PyMac_GetRect , & srcRect ,
1532+ PyMac_GetRect , & maskRect ,
1533+ PyMac_GetRect , & dstRect ))
1534+ return NULL ;
1535+ CopyMask (srcBits ,
1536+ maskBits ,
1537+ dstBits ,
1538+ & srcRect ,
1539+ & maskRect ,
1540+ & dstRect );
1541+ Py_INCREF (Py_None );
1542+ _res = Py_None ;
1543+ return _res ;
1544+ }
1545+
13611546static PyObject * Qd_OpenPicture (_self , _args )
13621547 PyObject * _self ;
13631548 PyObject * _args ;
@@ -1753,6 +1938,33 @@ static PyObject *Qd_MapPoly(_self, _args)
17531938 return _res ;
17541939}
17551940
1941+ static PyObject * Qd_StdBits (_self , _args )
1942+ PyObject * _self ;
1943+ PyObject * _args ;
1944+ {
1945+ PyObject * _res = NULL ;
1946+ BitMapPtr srcBits ;
1947+ Rect srcRect ;
1948+ Rect dstRect ;
1949+ short mode ;
1950+ RgnHandle maskRgn ;
1951+ if (!PyArg_ParseTuple (_args , "O&O&O&hO&" ,
1952+ BMObj_Convert , & srcBits ,
1953+ PyMac_GetRect , & srcRect ,
1954+ PyMac_GetRect , & dstRect ,
1955+ & mode ,
1956+ ResObj_Convert , & maskRgn ))
1957+ return NULL ;
1958+ StdBits (srcBits ,
1959+ & srcRect ,
1960+ & dstRect ,
1961+ mode ,
1962+ maskRgn );
1963+ Py_INCREF (Py_None );
1964+ _res = Py_None ;
1965+ return _res ;
1966+ }
1967+
17561968static PyObject * Qd_AddPt (_self , _args )
17571969 PyObject * _self ;
17581970 PyObject * _args ;
@@ -2253,6 +2465,42 @@ static PyObject *Qd_QDError(_self, _args)
22532465 return _res ;
22542466}
22552467
2468+ static PyObject * Qd_CopyDeepMask (_self , _args )
2469+ PyObject * _self ;
2470+ PyObject * _args ;
2471+ {
2472+ PyObject * _res = NULL ;
2473+ BitMapPtr srcBits ;
2474+ BitMapPtr maskBits ;
2475+ BitMapPtr dstBits ;
2476+ Rect srcRect ;
2477+ Rect maskRect ;
2478+ Rect dstRect ;
2479+ short mode ;
2480+ RgnHandle maskRgn ;
2481+ if (!PyArg_ParseTuple (_args , "O&O&O&O&O&O&hO&" ,
2482+ BMObj_Convert , & srcBits ,
2483+ BMObj_Convert , & maskBits ,
2484+ BMObj_Convert , & dstBits ,
2485+ PyMac_GetRect , & srcRect ,
2486+ PyMac_GetRect , & maskRect ,
2487+ PyMac_GetRect , & dstRect ,
2488+ & mode ,
2489+ ResObj_Convert , & maskRgn ))
2490+ return NULL ;
2491+ CopyDeepMask (srcBits ,
2492+ maskBits ,
2493+ dstBits ,
2494+ & srcRect ,
2495+ & maskRect ,
2496+ & dstRect ,
2497+ mode ,
2498+ maskRgn );
2499+ Py_INCREF (Py_None );
2500+ _res = Py_None ;
2501+ return _res ;
2502+ }
2503+
22562504static PyObject * Qd_GetPattern (_self , _args )
22572505 PyObject * _self ;
22582506 PyObject * _args ;
@@ -2556,13 +2804,47 @@ static PyObject *Qd_CharExtra(_self, _args)
25562804 return _res ;
25572805}
25582806
2807+ static PyObject * Qd_BitMap (_self , _args )
2808+ PyObject * _self ;
2809+ PyObject * _args ;
2810+ {
2811+ PyObject * _res = NULL ;
2812+
2813+ BitMap * ptr ;
2814+ PyObject * source ;
2815+ Rect bounds ;
2816+ int rowbytes ;
2817+ char * data ;
2818+
2819+ if ( !PyArg_ParseTuple (_args , "O!iO&" , & PyString_Type , & source , & rowbytes , PyMac_GetRect ,
2820+ & bounds ) )
2821+ return NULL ;
2822+ data = PyString_AsString (source );
2823+ if ((ptr = (BitMap * )malloc (sizeof (BitMap ))) == NULL )
2824+ return PyErr_NoMemory ();
2825+ ptr -> baseAddr = (Ptr )data ;
2826+ ptr -> rowBytes = rowbytes ;
2827+ ptr -> bounds = bounds ;
2828+ if ( (_res = BMObj_New (ptr )) == NULL ) {
2829+ free (ptr );
2830+ return NULL ;
2831+ }
2832+ ((BitMapObject * )_res )-> referred_object = source ;
2833+ Py_INCREF (source );
2834+ ((BitMapObject * )_res )-> referred_bitmap = ptr ;
2835+ return _res ;
2836+
2837+ }
2838+
25592839static PyMethodDef Qd_methods [] = {
25602840 {"SetPort" , (PyCFunction )Qd_SetPort , 1 ,
25612841 "(GrafPtr port) -> None" },
25622842 {"GetPort" , (PyCFunction )Qd_GetPort , 1 ,
25632843 "() -> (GrafPtr port)" },
25642844 {"GrafDevice" , (PyCFunction )Qd_GrafDevice , 1 ,
25652845 "(short device) -> None" },
2846+ {"SetPortBits" , (PyCFunction )Qd_SetPortBits , 1 ,
2847+ "(BitMapPtr bm) -> None" },
25662848 {"PortSize" , (PyCFunction )Qd_PortSize , 1 ,
25672849 "(short width, short height) -> None" },
25682850 {"MovePortTo" , (PyCFunction )Qd_MovePortTo , 1 ,
@@ -2661,6 +2943,8 @@ static PyMethodDef Qd_methods[] = {
26612943 "() -> None" },
26622944 {"CloseRgn" , (PyCFunction )Qd_CloseRgn , 1 ,
26632945 "(RgnHandle dstRgn) -> None" },
2946+ {"BitMapToRegion" , (PyCFunction )Qd_BitMapToRegion , 1 ,
2947+ "(RgnHandle region, BitMapPtr bMap) -> None" },
26642948 {"DisposeRgn" , (PyCFunction )Qd_DisposeRgn , 1 ,
26652949 "(RgnHandle rgn) -> None" },
26662950 {"CopyRgn" , (PyCFunction )Qd_CopyRgn , 1 ,
@@ -2699,6 +2983,10 @@ static PyMethodDef Qd_methods[] = {
26992983 "(RgnHandle rgn) -> None" },
27002984 {"ScrollRect" , (PyCFunction )Qd_ScrollRect , 1 ,
27012985 "(Rect r, short dh, short dv, RgnHandle updateRgn) -> None" },
2986+ {"CopyBits" , (PyCFunction )Qd_CopyBits , 1 ,
2987+ "(BitMapPtr srcBits, BitMapPtr dstBits, Rect srcRect, Rect dstRect, short mode, RgnHandle maskRgn) -> None" },
2988+ {"CopyMask" , (PyCFunction )Qd_CopyMask , 1 ,
2989+ "(BitMapPtr srcBits, BitMapPtr maskBits, BitMapPtr dstBits, Rect srcRect, Rect maskRect, Rect dstRect) -> None" },
27022990 {"OpenPicture" , (PyCFunction )Qd_OpenPicture , 1 ,
27032991 "(Rect picFrame) -> (PicHandle _rv)" },
27042992 {"PicComment" , (PyCFunction )Qd_PicComment , 1 ,
@@ -2745,6 +3033,8 @@ static PyMethodDef Qd_methods[] = {
27453033 "(RgnHandle rgn, Rect srcRect, Rect dstRect) -> None" },
27463034 {"MapPoly" , (PyCFunction )Qd_MapPoly , 1 ,
27473035 "(PolyHandle poly, Rect srcRect, Rect dstRect) -> None" },
3036+ {"StdBits" , (PyCFunction )Qd_StdBits , 1 ,
3037+ "(BitMapPtr srcBits, Rect srcRect, Rect dstRect, short mode, RgnHandle maskRgn) -> None" },
27483038 {"AddPt" , (PyCFunction )Qd_AddPt , 1 ,
27493039 "(Point src, Point dst) -> (Point dst)" },
27503040 {"EqualPt" , (PyCFunction )Qd_EqualPt , 1 ,
@@ -2803,6 +3093,8 @@ static PyMethodDef Qd_methods[] = {
28033093 "(short index, Boolean reserve) -> None" },
28043094 {"QDError" , (PyCFunction )Qd_QDError , 1 ,
28053095 "() -> (short _rv)" },
3096+ {"CopyDeepMask" , (PyCFunction )Qd_CopyDeepMask , 1 ,
3097+ "(BitMapPtr srcBits, BitMapPtr maskBits, BitMapPtr dstBits, Rect srcRect, Rect maskRect, Rect dstRect, short mode, RgnHandle maskRgn) -> None" },
28063098 {"GetPattern" , (PyCFunction )Qd_GetPattern , 1 ,
28073099 "(short patternID) -> (PatHandle _rv)" },
28083100 {"GetCursor" , (PyCFunction )Qd_GetCursor , 1 ,
@@ -2839,6 +3131,8 @@ static PyMethodDef Qd_methods[] = {
28393131 "(Buffer textBuf, short firstByte, short byteCount) -> (short _rv)" },
28403132 {"CharExtra" , (PyCFunction )Qd_CharExtra , 1 ,
28413133 "(Fixed extra) -> None" },
3134+ {"BitMap" , (PyCFunction )Qd_BitMap , 1 ,
3135+ "Take (string, int, Rect) argument and create BitMap" },
28423136 {NULL , NULL , 0 }
28433137};
28443138
0 commit comments