Mercurial > cpython-lru_cache-weakref
annotate Modules/svmodule.c @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | f926263fb654 |
| children | 2c29b8982643 |
| rev | line source |
|---|---|
| 1179 | 1 /********************************************************** |
|
2061
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
3 The Netherlands. |
| 1179 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 1179 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 1179 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
15 permission. |
| 1179 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 1179 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 32 /* SV module -- interface to the Indigo video board */ | |
| 33 | |
|
4762
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
34 /* WARNING! This module is for hardware that we don't have any more, |
|
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
35 so it hasn't been tested. It has been converted to the new coding |
|
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
36 style, and it is possible that this conversion has broken something |
|
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
37 -- user beware! */ |
|
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
38 |
| 1179 | 39 #include <sys/time.h> |
| 40 #include <svideo.h> | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
41 #include "Python.h" |
| 1179 | 42 #include "compile.h" |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
43 #include "yuv.h" /* for YUV conversion functions */ |
| 1179 | 44 |
| 45 typedef struct { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
46 PyObject_HEAD |
| 1179 | 47 SV_nodeP ob_svideo; |
| 48 svCaptureInfo ob_info; | |
| 49 } svobject; | |
| 50 | |
| 51 typedef struct { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
52 PyObject_HEAD |
| 1179 | 53 void *ob_capture; |
| 54 int ob_mustunlock; | |
| 55 svCaptureInfo ob_info; | |
| 56 svobject *ob_svideo; | |
| 57 } captureobject; | |
| 58 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
59 static PyObject *SvError; /* exception sv.error */ |
| 1179 | 60 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
61 static PyObject *newcaptureobject Py_PROTO((svobject *, void *, int)); |
| 1179 | 62 |
| 63 /* Set a SV-specific error from svideo_errno and return NULL */ | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
64 static PyObject * |
| 1179 | 65 sv_error() |
| 66 { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
67 PyErr_SetString(SvError, svStrerror(svideo_errno)); |
| 1179 | 68 return NULL; |
| 69 } | |
| 70 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
71 static PyObject * |
| 1179 | 72 svc_conversion(self, args, function, factor) |
| 73 captureobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
74 PyObject *args; |
| 1179 | 75 void (*function)(); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
76 float factor; |
| 1179 | 77 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
78 PyObject *output; |
| 1179 | 79 int invert; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
80 char* outstr; |
| 1179 | 81 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
82 if (!PyArg_Parse(args, "i", &invert)) |
| 1179 | 83 return NULL; |
| 84 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
85 if (!(output = PyString_FromStringAndSize( |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
86 NULL, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
87 (int)(self->ob_info.width * self->ob_info.height * factor)))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
88 { |
| 1179 | 89 return NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
90 } |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
91 if (!(outstr = PyString_AsString(output))) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
92 Py_DECREF(output); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
93 return NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
94 } |
| 1179 | 95 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
96 (*function)((boolean)invert, self->ob_capture, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
97 outstr, |
| 1179 | 98 self->ob_info.width, self->ob_info.height); |
| 99 | |
| 100 return output; | |
| 101 } | |
| 102 | |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
103 /* |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
104 * 3 functions to convert from Starter Video YUV 4:1:1 format to |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
105 * Compression Library 4:2:2 Duplicate Chroma format. |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
106 */ |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
107 static PyObject * |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
108 svc_YUVtoYUV422DC(self, args) |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
109 captureobject *self; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
110 PyObject *args; |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
111 { |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
112 if (self->ob_info.format != SV_YUV411_FRAMES) { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
113 PyErr_SetString(SvError, "data has bad format"); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
114 return NULL; |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
115 } |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
116 return svc_conversion(self, args, yuv_sv411_to_cl422dc, 2.0); |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
117 } |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
118 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
119 static PyObject * |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
120 svc_YUVtoYUV422DC_quarter(self, args) |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
121 captureobject *self; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
122 PyObject *args; |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
123 { |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
124 if (self->ob_info.format != SV_YUV411_FRAMES) { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
125 PyErr_SetString(SvError, "data has bad format"); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
126 return NULL; |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
127 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
128 return svc_conversion(self, args, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
129 yuv_sv411_to_cl422dc_quartersize, 0.5); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
130 } |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
131 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
132 static PyObject * |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
133 svc_YUVtoYUV422DC_sixteenth(self, args) |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
134 captureobject *self; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
135 PyObject *args; |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
136 { |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
137 if (self->ob_info.format != SV_YUV411_FRAMES) { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
138 PyErr_SetString(SvError, "data has bad format"); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
139 return NULL; |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
140 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
141 return svc_conversion(self, args, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
142 yuv_sv411_to_cl422dc_sixteenthsize, 0.125); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
143 } |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
144 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
145 static PyObject * |
| 1179 | 146 svc_YUVtoRGB(self, args) |
| 147 captureobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
148 PyObject *args; |
| 1179 | 149 { |
| 150 switch (self->ob_info.format) { | |
| 151 case SV_YUV411_FRAMES: | |
| 152 case SV_YUV411_FRAMES_AND_BLANKING_BUFFER: | |
| 153 break; | |
| 154 default: | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
155 PyErr_SetString(SvError, "data had bad format"); |
| 1179 | 156 return NULL; |
| 157 } | |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
158 return svc_conversion(self, args, svYUVtoRGB, (float) sizeof(long)); |
| 1179 | 159 } |
| 160 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
161 static PyObject * |
| 1179 | 162 svc_RGB8toRGB32(self, args) |
| 163 captureobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
164 PyObject *args; |
| 1179 | 165 { |
| 166 if (self->ob_info.format != SV_RGB8_FRAMES) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
167 PyErr_SetString(SvError, "data has bad format"); |
| 1179 | 168 return NULL; |
| 169 } | |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
170 return svc_conversion(self, args, svRGB8toRGB32, (float) sizeof(long)); |
| 1179 | 171 } |
| 172 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
173 static PyObject * |
| 1179 | 174 svc_InterleaveFields(self, args) |
| 175 captureobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
176 PyObject *args; |
| 1179 | 177 { |
| 178 if (self->ob_info.format != SV_RGB8_FRAMES) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
179 PyErr_SetString(SvError, "data has bad format"); |
| 1179 | 180 return NULL; |
| 181 } | |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
182 return svc_conversion(self, args, svInterleaveFields, 1.0); |
| 1179 | 183 } |
| 184 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
185 static PyObject * |
| 1179 | 186 svc_GetFields(self, args) |
| 187 captureobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
188 PyObject *args; |
| 1179 | 189 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
190 PyObject *f1 = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
191 PyObject *f2 = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
192 PyObject *ret = NULL; |
| 1179 | 193 int fieldsize; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
194 char* obcapture; |
| 1179 | 195 |
| 196 if (self->ob_info.format != SV_RGB8_FRAMES) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
197 PyErr_SetString(SvError, "data has bad format"); |
| 1179 | 198 return NULL; |
| 199 } | |
| 200 | |
| 201 fieldsize = self->ob_info.width * self->ob_info.height / 2; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
202 obcapture = (char*)self->ob_capture; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
203 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
204 if (!(f1 = PyString_FromStringAndSize(obcapture, fieldsize))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
205 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
206 if (!(f2 = PyString_FromStringAndSize(obcapture + fieldsize, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
207 fieldsize))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
208 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
209 ret = Py_BuildValue("(OO)", f1, f2); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
210 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
211 finally: |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
212 Py_XDECREF(f1); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
213 Py_XDECREF(f2); |
|
1207
b564bd4e57e1
* ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
214 return ret; |
| 1179 | 215 } |
| 216 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
217 static PyObject * |
| 1179 | 218 svc_UnlockCaptureData(self, args) |
| 219 captureobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
220 PyObject *args; |
| 1179 | 221 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
222 if (!PyArg_Parse(args, "")) |
| 1179 | 223 return NULL; |
| 224 | |
| 225 if (!self->ob_mustunlock) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
226 PyErr_SetString(SvError, "buffer should not be unlocked"); |
| 1179 | 227 return NULL; |
| 228 } | |
| 229 | |
| 230 if (svUnlockCaptureData(self->ob_svideo->ob_svideo, self->ob_capture)) | |
| 231 return sv_error(); | |
| 232 | |
| 233 self->ob_mustunlock = 0; | |
| 234 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
235 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
236 return Py_None; |
| 1179 | 237 } |
| 238 | |
| 239 #ifdef USE_GL | |
| 240 #include <gl.h> | |
| 241 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
242 static PyObject * |
| 1179 | 243 svc_lrectwrite(self, args) |
| 244 captureobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
245 PyObject *args; |
| 1179 | 246 { |
| 247 Screencoord x1, x2, y1, y2; | |
| 248 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
249 if (!PyArg_Parse(args, "(hhhh)", &x1, &x2, &y1, &y2)) |
| 1179 | 250 return NULL; |
| 251 | |
| 252 lrectwrite(x1, x2, y1, y2, (unsigned long *) self->ob_capture); | |
| 253 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
254 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
255 return Py_None; |
| 1179 | 256 } |
| 257 #endif | |
| 258 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
259 static PyObject * |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
260 svc_writefile(self, args) |
| 1179 | 261 captureobject *self; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
262 PyObject *args; |
| 1179 | 263 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
264 PyObject *file; |
| 1179 | 265 int size; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
266 FILE* fp; |
| 1179 | 267 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
268 if (!PyArg_Parse(args, "O", &file)) |
| 1179 | 269 return NULL; |
| 270 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
271 if (!PyFile_Check(file)) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
272 PyErr_SetString(SvError, "not a file object"); |
| 1179 | 273 return NULL; |
| 274 } | |
| 275 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
276 if (!(fp = PyFile_AsFile(file))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
277 return NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
278 |
| 1179 | 279 size = self->ob_info.width * self->ob_info.height; |
| 280 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
281 if (fwrite(self->ob_capture, sizeof(long), size, fp) != size) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
282 PyErr_SetString(SvError, "writing failed"); |
| 1179 | 283 return NULL; |
| 284 } | |
| 285 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
286 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
287 return Py_None; |
| 1179 | 288 } |
| 289 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
290 static PyObject * |
| 1179 | 291 svc_FindVisibleRegion(self, args) |
| 292 captureobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
293 PyObject *args; |
| 1179 | 294 { |
| 295 void *visible; | |
| 296 int width; | |
| 297 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
298 if (!PyArg_Parse(args, "")) |
| 1179 | 299 return NULL; |
| 300 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
301 if (svFindVisibleRegion(self->ob_svideo->ob_svideo, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
302 self->ob_capture, &visible, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
303 self->ob_info.width)) |
| 1179 | 304 return sv_error(); |
| 305 | |
| 306 if (visible == NULL) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
307 PyErr_SetString(SvError, "data in wrong format"); |
| 1179 | 308 return NULL; |
| 309 } | |
| 310 | |
| 311 return newcaptureobject(self->ob_svideo, visible, 0); | |
| 312 } | |
| 313 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
314 static PyMethodDef capture_methods[] = { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
315 {"YUVtoRGB", (PyCFunction)svc_YUVtoRGB}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
316 {"RGB8toRGB32", (PyCFunction)svc_RGB8toRGB32}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
317 {"InterleaveFields", (PyCFunction)svc_InterleaveFields}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
318 {"UnlockCaptureData", (PyCFunction)svc_UnlockCaptureData}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
319 {"FindVisibleRegion", (PyCFunction)svc_FindVisibleRegion}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
320 {"GetFields", (PyCFunction)svc_GetFields}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
321 {"YUVtoYUV422DC", (PyCFunction)svc_YUVtoYUV422DC}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
322 {"YUVtoYUV422DC_quarter",(PyCFunction)svc_YUVtoYUV422DC_quarter}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
323 {"YUVtoYUV422DC_sixteenth",(PyCFunction)svc_YUVtoYUV422DC_sixteenth}, |
| 1179 | 324 #ifdef USE_GL |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
325 {"lrectwrite", (PyCFunction)svc_lrectwrite}, |
| 1179 | 326 #endif |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
327 {"writefile", (PyCFunction)svc_writefile}, |
| 1179 | 328 {NULL, NULL} /* sentinel */ |
| 329 }; | |
| 330 | |
| 331 static void | |
| 332 capture_dealloc(self) | |
| 333 captureobject *self; | |
| 334 { | |
| 335 if (self->ob_capture != NULL) { | |
| 336 if (self->ob_mustunlock) | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
337 (void)svUnlockCaptureData(self->ob_svideo->ob_svideo, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
338 self->ob_capture); |
| 1179 | 339 self->ob_capture = NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
340 Py_DECREF(self->ob_svideo); |
| 1179 | 341 self->ob_svideo = NULL; |
| 342 } | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
343 PyMem_DEL(self); |
| 1179 | 344 } |
| 345 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
346 static PyObject * |
| 1179 | 347 capture_getattr(self, name) |
| 348 svobject *self; | |
| 349 char *name; | |
| 350 { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
351 return Py_FindMethod(capture_methods, (PyObject *)self, name); |
| 1179 | 352 } |
| 353 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
354 PyTypeObject Capturetype = { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
355 PyObject_HEAD_INIT(&PyType_Type) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
356 0, /*ob_size*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
357 "capture", /*tp_name*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
358 sizeof(captureobject), /*tp_size*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
359 0, /*tp_itemsize*/ |
| 1179 | 360 /* methods */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
361 (destructor)capture_dealloc, /*tp_dealloc*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
362 0, /*tp_print*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
363 (getattrfunc)capture_getattr, /*tp_getattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
364 0, /*tp_setattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
365 0, /*tp_compare*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
366 0, /*tp_repr*/ |
| 1179 | 367 }; |
| 368 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
369 static PyObject * |
| 1179 | 370 newcaptureobject(self, ptr, mustunlock) |
| 371 svobject *self; | |
| 372 void *ptr; | |
| 373 int mustunlock; | |
| 374 { | |
| 375 captureobject *p; | |
| 376 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
377 p = PyObject_NEW(captureobject, &Capturetype); |
| 1179 | 378 if (p == NULL) |
| 379 return NULL; | |
| 380 p->ob_svideo = self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
381 Py_INCREF(self); |
| 1179 | 382 p->ob_capture = ptr; |
| 383 p->ob_mustunlock = mustunlock; | |
| 384 p->ob_info = self->ob_info; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
385 return (PyObject *) p; |
| 1179 | 386 } |
| 387 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
388 static PyObject * |
| 1179 | 389 sv_GetCaptureData(self, args) |
| 390 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
391 PyObject *args; |
| 1179 | 392 { |
| 393 void *ptr; | |
| 394 long fieldID; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
395 PyObject *res, *c; |
| 1179 | 396 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
397 if (!PyArg_Parse(args, "")) |
| 1179 | 398 return NULL; |
| 399 | |
| 400 if (svGetCaptureData(self->ob_svideo, &ptr, &fieldID)) | |
| 401 return sv_error(); | |
| 402 | |
| 403 if (ptr == NULL) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
404 PyErr_SetString(SvError, "no data available"); |
| 1179 | 405 return NULL; |
| 406 } | |
| 407 | |
| 408 c = newcaptureobject(self, ptr, 1); | |
| 409 if (c == NULL) | |
| 410 return NULL; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
411 res = Py_BuildValue("(Oi)", c, fieldID); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
412 Py_DECREF(c); |
| 1179 | 413 return res; |
| 414 } | |
| 415 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
416 static PyObject * |
| 1179 | 417 sv_BindGLWindow(self, args) |
| 418 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
419 PyObject *args; |
| 1179 | 420 { |
| 421 long wid; | |
| 422 int mode; | |
| 423 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
424 if (!PyArg_Parse(args, "(ii)", &wid, &mode)) |
| 1179 | 425 return NULL; |
| 426 | |
| 427 if (svBindGLWindow(self->ob_svideo, wid, mode)) | |
| 428 return sv_error(); | |
| 429 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
430 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
431 return Py_None; |
| 1179 | 432 } |
| 433 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
434 static PyObject * |
| 1179 | 435 sv_EndContinuousCapture(self, args) |
| 436 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
437 PyObject *args; |
| 1179 | 438 { |
| 439 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
440 if (!PyArg_Parse(args, "")) |
| 1179 | 441 return NULL; |
| 442 | |
| 443 if (svEndContinuousCapture(self->ob_svideo)) | |
| 444 return sv_error(); | |
| 445 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
446 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
447 return Py_None; |
| 1179 | 448 } |
| 449 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
450 static PyObject * |
| 1179 | 451 sv_IsVideoDisplayed(self, args) |
| 452 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
453 PyObject *args; |
| 1179 | 454 { |
| 455 int v; | |
| 456 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
457 if (!PyArg_Parse(args, "")) |
| 1179 | 458 return NULL; |
| 459 | |
| 460 v = svIsVideoDisplayed(self->ob_svideo); | |
| 461 if (v == -1) | |
| 462 return sv_error(); | |
| 463 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
464 return PyInt_FromLong((long) v); |
| 1179 | 465 } |
| 466 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
467 static PyObject * |
| 1179 | 468 sv_OutputOffset(self, args) |
| 469 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
470 PyObject *args; |
| 1179 | 471 { |
| 472 int x_offset; | |
| 473 int y_offset; | |
| 474 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
475 if (!PyArg_Parse(args, "(ii)", &x_offset, &y_offset)) |
| 1179 | 476 return NULL; |
| 477 | |
| 478 if (svOutputOffset(self->ob_svideo, x_offset, y_offset)) | |
| 479 return sv_error(); | |
| 480 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
481 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
482 return Py_None; |
| 1179 | 483 } |
| 484 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
485 static PyObject * |
| 1179 | 486 sv_PutFrame(self, args) |
| 487 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
488 PyObject *args; |
| 1179 | 489 { |
| 490 char *buffer; | |
| 491 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
492 if (!PyArg_Parse(args, "s", &buffer)) |
| 1179 | 493 return NULL; |
| 494 | |
| 495 if (svPutFrame(self->ob_svideo, buffer)) | |
| 496 return sv_error(); | |
| 497 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
498 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
499 return Py_None; |
| 1179 | 500 } |
| 501 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
502 static PyObject * |
| 1179 | 503 sv_QuerySize(self, args) |
| 504 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
505 PyObject *args; |
| 1179 | 506 { |
| 507 int w; | |
| 508 int h; | |
| 509 int rw; | |
| 510 int rh; | |
| 511 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
512 if (!PyArg_Parse(args, "(ii)", &w, &h)) |
| 1179 | 513 return NULL; |
| 514 | |
| 515 if (svQuerySize(self->ob_svideo, w, h, &rw, &rh)) | |
| 516 return sv_error(); | |
| 517 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
518 return Py_BuildValue("(ii)", (long) rw, (long) rh); |
| 1179 | 519 } |
| 520 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
521 static PyObject * |
| 1179 | 522 sv_SetSize(self, args) |
| 523 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
524 PyObject *args; |
| 1179 | 525 { |
| 526 int w; | |
| 527 int h; | |
| 528 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
529 if (!PyArg_Parse(args, "(ii)", &w, &h)) |
| 1179 | 530 return NULL; |
| 531 | |
| 532 if (svSetSize(self->ob_svideo, w, h)) | |
| 533 return sv_error(); | |
| 534 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
535 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
536 return Py_None; |
| 1179 | 537 } |
| 538 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
539 static PyObject * |
| 1179 | 540 sv_SetStdDefaults(self, args) |
| 541 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
542 PyObject *args; |
| 1179 | 543 { |
| 544 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
545 if (!PyArg_Parse(args, "")) |
| 1179 | 546 return NULL; |
| 547 | |
| 548 if (svSetStdDefaults(self->ob_svideo)) | |
| 549 return sv_error(); | |
| 550 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
551 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
552 return Py_None; |
| 1179 | 553 } |
| 554 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
555 static PyObject * |
| 1179 | 556 sv_UseExclusive(self, args) |
| 557 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
558 PyObject *args; |
| 1179 | 559 { |
| 560 boolean onoff; | |
| 561 int mode; | |
| 562 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
563 if (!PyArg_Parse(args, "(ii)", &onoff, &mode)) |
| 1179 | 564 return NULL; |
| 565 | |
| 566 if (svUseExclusive(self->ob_svideo, onoff, mode)) | |
| 567 return sv_error(); | |
| 568 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
569 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
570 return Py_None; |
| 1179 | 571 } |
| 572 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
573 static PyObject * |
| 1179 | 574 sv_WindowOffset(self, args) |
| 575 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
576 PyObject *args; |
| 1179 | 577 { |
| 578 int x_offset; | |
| 579 int y_offset; | |
| 580 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
581 if (!PyArg_Parse(args, "(ii)", &x_offset, &y_offset)) |
| 1179 | 582 return NULL; |
| 583 | |
| 584 if (svWindowOffset(self->ob_svideo, x_offset, y_offset)) | |
| 585 return sv_error(); | |
| 586 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
587 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
588 return Py_None; |
| 1179 | 589 } |
| 590 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
591 static PyObject * |
| 1179 | 592 sv_CaptureBurst(self, args) |
| 593 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
594 PyObject *args; |
| 1179 | 595 { |
| 596 int bytes, i; | |
| 597 svCaptureInfo info; | |
| 598 void *bitvector = NULL; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
599 PyObject *videodata = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
600 PyObject *bitvecobj = NULL; |
|
4762
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
601 PyObject *res = NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
602 static PyObject *evenitem, *odditem; |
| 1179 | 603 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
604 if (!PyArg_Parse(args, "(iiiii)", &info.format, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
605 &info.width, &info.height, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
606 &info.size, &info.samplingrate)) |
| 1179 | 607 return NULL; |
| 608 | |
| 609 switch (info.format) { | |
| 610 case SV_RGB8_FRAMES: | |
| 611 bitvector = malloc(SV_BITVEC_SIZE(info.size)); | |
| 612 break; | |
| 613 case SV_YUV411_FRAMES_AND_BLANKING_BUFFER: | |
| 614 break; | |
| 615 default: | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
616 PyErr_SetString(SvError, "illegal format specified"); |
| 1179 | 617 return NULL; |
| 618 } | |
| 619 | |
| 620 if (svQueryCaptureBufferSize(self->ob_svideo, &info, &bytes)) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
621 res = sv_error(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
622 goto finally; |
| 1179 | 623 } |
| 624 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
625 if (!(videodata = PyString_FromStringAndSize(NULL, bytes))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
626 goto finally; |
| 1179 | 627 |
| 628 /* XXX -- need to do something about the bitvector */ | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
629 { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
630 char* str = PyString_AsString(videodata); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
631 if (!str) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
632 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
633 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
634 if (svCaptureBurst(self->ob_svideo, &info, str, bitvector)) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
635 res = sv_error(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
636 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
637 } |
| 1179 | 638 } |
| 639 | |
| 640 if (bitvector) { | |
| 641 if (evenitem == NULL) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
642 if (!(evenitem = PyInt_FromLong(0))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
643 goto finally; |
| 1179 | 644 } |
| 645 if (odditem == NULL) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
646 if (!(odditem = PyInt_FromLong(1))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
647 goto finally; |
| 1179 | 648 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
649 if (!(bitvecobj = PyTuple_New(2 * info.size))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
650 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
651 |
| 1179 | 652 for (i = 0; i < 2 * info.size; i++) { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
653 int sts; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
654 |
| 1179 | 655 if (SV_GET_FIELD(bitvector, i) == SV_EVEN_FIELD) { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
656 Py_INCREF(evenitem); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
657 sts = PyTuple_SetItem(bitvecobj, i, evenitem); |
| 1179 | 658 } else { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
659 Py_INCREF(odditem); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
660 sts = PyTuple_SetItem(bitvecobj, i, odditem); |
| 1179 | 661 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
662 if (sts < 0) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
663 goto finally; |
| 1179 | 664 } |
| 665 } else { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
666 bitvecobj = Py_None; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
667 Py_INCREF(Py_None); |
| 1179 | 668 } |
| 669 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
670 res = Py_BuildValue("((iiiii)OO)", info.format, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
671 info.width, info.height, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
672 info.size, info.samplingrate, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
673 videodata, bitvecobj); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
674 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
675 finally: |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
676 if (bitvector) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
677 free(bitvector); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
678 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
679 Py_XDECREF(videodata); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
680 Py_XDECREF(bitvecobj); |
| 1179 | 681 return res; |
| 682 } | |
| 683 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
684 static PyObject * |
| 1179 | 685 sv_CaptureOneFrame(self, args) |
| 686 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
687 PyObject *args; |
| 1179 | 688 { |
| 689 svCaptureInfo info; | |
| 690 int format, width, height; | |
| 691 int bytes; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
692 PyObject *videodata = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
693 PyObject *res = NULL; |
|
4762
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
694 char *str; |
| 1179 | 695 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
696 if (!PyArg_Parse(args, "(iii)", &format, &width, &height)) |
| 1179 | 697 return NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
698 |
| 1179 | 699 info.format = format; |
| 700 info.width = width; | |
| 701 info.height = height; | |
| 702 info.size = 0; | |
| 703 info.samplingrate = 0; | |
| 704 if (svQueryCaptureBufferSize(self->ob_svideo, &info, &bytes)) | |
| 705 return sv_error(); | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
706 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
707 if (!(videodata = PyString_FromStringAndSize(NULL, bytes))) |
| 1179 | 708 return NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
709 |
|
4762
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
710 str = PyString_AsString(videodata); |
|
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
711 if (!str) |
|
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
712 goto finally; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
713 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
714 if (svCaptureOneFrame(self->ob_svideo, format, &width, &height, str)) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
715 res = sv_error(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
716 goto finally; |
| 1179 | 717 } |
| 718 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
719 res = Py_BuildValue("(iiO)", width, height, videodata); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
720 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
721 finally: |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
722 Py_XDECREF(videodata); |
| 1179 | 723 return res; |
| 724 } | |
| 725 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
726 static PyObject * |
| 1179 | 727 sv_InitContinuousCapture(self, args) |
| 728 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
729 PyObject *args; |
| 1179 | 730 { |
| 731 svCaptureInfo info; | |
| 732 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
733 if (!PyArg_Parse(args, "(iiiii)", &info.format, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
734 &info.width, &info.height, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
735 &info.size, &info.samplingrate)) |
| 1179 | 736 return NULL; |
| 737 | |
| 738 if (svInitContinuousCapture(self->ob_svideo, &info)) | |
| 739 return sv_error(); | |
| 740 | |
| 741 self->ob_info = info; | |
| 742 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
743 return Py_BuildValue("(iiiii)", info.format, info.width, info.height, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
744 info.size, info.samplingrate); |
| 1179 | 745 } |
| 746 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
747 static PyObject * |
| 1179 | 748 sv_LoadMap(self, args) |
| 749 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
750 PyObject *args; |
| 1179 | 751 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
752 PyObject *rgb; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
753 PyObject *res = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
754 rgb_tuple *mapp = NULL; |
| 1179 | 755 int maptype; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
756 int i, j; /* indices */ |
| 1179 | 757 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
758 if (!PyArg_Parse(args, "(iO)", &maptype, &rgb)) |
| 1179 | 759 return NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
760 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
761 if (!PyList_Check(rgb) || PyList_Size(rgb) != 256) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
762 PyErr_BadArgument(); |
| 1179 | 763 return NULL; |
| 764 } | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
765 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
766 if (!(mapp = PyMem_NEW(rgb_tuple, 256))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
767 return PyErr_NoMemory(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
768 |
| 1179 | 769 for (i = 0; i < 256; i++) { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
770 PyObject* v = PyList_GetItem(rgb, i); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
771 if (!v) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
772 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
773 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
774 if (!PyTuple_Check(v) || PyTuple_Size(v) != 3) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
775 PyErr_BadArgument(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
776 goto finally; |
| 1179 | 777 } |
| 778 for (j = 0; j < 3; j++) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
779 PyObject* cell = PyTuple_GetItem(v, j); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
780 if (!cell) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
781 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
782 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
783 if (!PyInt_Check(cell)) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
784 PyErr_BadArgument(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
785 goto finally; |
| 1179 | 786 } |
| 787 switch (j) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
788 case 0: mapp[i].red = PyInt_AsLong(cell); break; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
789 case 1: mapp[i].blue = PyInt_AsLong(cell); break; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
790 case 2: mapp[i].green = PyInt_AsLong(cell); break; |
| 1179 | 791 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
792 if (PyErr_Occurred()) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
793 goto finally; |
| 1179 | 794 } |
| 795 } | |
| 796 | |
| 797 if (svLoadMap(self->ob_svideo, maptype, mapp)) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
798 res = sv_error(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
799 goto finally; |
| 1179 | 800 } |
| 801 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
802 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
803 res = Py_None; |
| 1179 | 804 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
805 finally: |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
806 PyMem_DEL(mapp); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
807 return res; |
| 1179 | 808 } |
| 809 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
810 static PyObject * |
| 1179 | 811 sv_CloseVideo(self, args) |
| 812 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
813 PyObject *args; |
| 1179 | 814 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
815 if (!PyArg_Parse(args, "")) |
| 1179 | 816 return NULL; |
| 817 | |
| 818 if (svCloseVideo(self->ob_svideo)) | |
| 819 return sv_error(); | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
820 |
| 1179 | 821 self->ob_svideo = NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
822 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
823 return Py_None; |
| 1179 | 824 } |
| 825 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
826 static PyObject * |
| 1179 | 827 doParams(self, args, func, modified) |
| 828 svobject *self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
829 PyObject *args; |
| 1179 | 830 int (*func)(SV_nodeP, long *, int); |
| 831 int modified; | |
| 832 { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
833 PyObject *list; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
834 PyObject *res = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
835 long *PVbuffer = NULL; |
| 1179 | 836 long length; |
| 837 int i; | |
| 838 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
839 if (!PyArg_Parse(args, "O", &list)) |
| 1179 | 840 return NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
841 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
842 if (!PyList_Check(list)) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
843 PyErr_BadArgument(); |
| 1179 | 844 return NULL; |
| 845 } | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
846 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
847 if ((length = PyList_Size(list)) < 0) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
848 return NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
849 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
850 PVbuffer = PyMem_NEW(long, length); |
| 1179 | 851 if (PVbuffer == NULL) |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
852 return PyErr_NoMemory(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
853 |
| 1179 | 854 for (i = 0; i < length; i++) { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
855 PyObject *v = PyList_GetItem(list, i); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
856 if (!v) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
857 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
858 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
859 if (!PyInt_Check(v)) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
860 PyErr_BadArgument(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
861 goto finally; |
| 1179 | 862 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
863 PVbuffer[i] = PyInt_AsLong(v); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
864 /* can't just test the return value, because what if the |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
865 value was -1?! |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
866 */ |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
867 if (PVbuffer[i] == -1 && PyErr_Occurred()) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
868 goto finally; |
| 1179 | 869 } |
| 870 | |
| 871 if ((*func)(self->ob_svideo, PVbuffer, length)) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
872 res = sv_error(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
873 goto finally; |
| 1179 | 874 } |
| 875 | |
| 876 if (modified) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
877 for (i = 0; i < length; i++) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
878 PyObject* v = PyInt_FromLong(PVbuffer[i]); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
879 if (!v || PyList_SetItem(list, i, v) < 0) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
880 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
881 } |
| 1179 | 882 } |
| 883 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
884 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
885 res = Py_None; |
| 1179 | 886 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
887 finally: |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
888 PyMem_DEL(PVbuffer); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
889 return res; |
| 1179 | 890 } |
| 891 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
892 static PyObject * |
| 1179 | 893 sv_GetParam(self, args) |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
894 PyObject *self, *args; |
| 1179 | 895 { |
| 896 return doParams(self, args, svGetParam, 1); | |
| 897 } | |
| 898 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
899 static PyObject * |
| 1179 | 900 sv_GetParamRange(self, args) |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
901 PyObject *self, *args; |
| 1179 | 902 { |
| 903 return doParams(self, args, svGetParamRange, 1); | |
| 904 } | |
| 905 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
906 static PyObject * |
| 1179 | 907 sv_SetParam(self, args) |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
908 PyObject *self, *args; |
| 1179 | 909 { |
| 910 return doParams(self, args, svSetParam, 0); | |
| 911 } | |
| 912 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
913 static PyMethodDef svideo_methods[] = { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
914 {"BindGLWindow", (PyCFunction)sv_BindGLWindow}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
915 {"EndContinuousCapture",(PyCFunction)sv_EndContinuousCapture}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
916 {"IsVideoDisplayed", (PyCFunction)sv_IsVideoDisplayed}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
917 {"OutputOffset", (PyCFunction)sv_OutputOffset}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
918 {"PutFrame", (PyCFunction)sv_PutFrame}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
919 {"QuerySize", (PyCFunction)sv_QuerySize}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
920 {"SetSize", (PyCFunction)sv_SetSize}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
921 {"SetStdDefaults", (PyCFunction)sv_SetStdDefaults}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
922 {"UseExclusive", (PyCFunction)sv_UseExclusive}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
923 {"WindowOffset", (PyCFunction)sv_WindowOffset}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
924 {"InitContinuousCapture",(PyCFunction)sv_InitContinuousCapture}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
925 {"CaptureBurst", (PyCFunction)sv_CaptureBurst}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
926 {"CaptureOneFrame", (PyCFunction)sv_CaptureOneFrame}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
927 {"GetCaptureData", (PyCFunction)sv_GetCaptureData}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
928 {"CloseVideo", (PyCFunction)sv_CloseVideo}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
929 {"LoadMap", (PyCFunction)sv_LoadMap}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
930 {"GetParam", (PyCFunction)sv_GetParam}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
931 {"GetParamRange", (PyCFunction)sv_GetParamRange}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
932 {"SetParam", (PyCFunction)sv_SetParam}, |
| 1179 | 933 {NULL, NULL} /* sentinel */ |
| 934 }; | |
| 935 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
936 static PyObject * |
| 1179 | 937 sv_conversion(self, args, function, inputfactor, factor) |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
938 PyObject *self, *args; |
| 1179 | 939 void (*function)(); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
940 int inputfactor; |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
941 float factor; |
| 1179 | 942 { |
| 943 int invert, width, height, inputlength; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
944 char *input, *str; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
945 PyObject *output; |
| 1179 | 946 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
947 if (!PyArg_Parse(args, "(is#ii)", &invert, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
948 &input, &inputlength, &width, &height)) |
| 1179 | 949 return NULL; |
| 950 | |
| 951 if (width * height * inputfactor > inputlength) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
952 PyErr_SetString(SvError, "input buffer not long enough"); |
| 1179 | 953 return NULL; |
| 954 } | |
| 955 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
956 if (!(output = PyString_FromStringAndSize(NULL, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
957 (int)(width * height * factor)))) |
| 1179 | 958 return NULL; |
| 959 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
960 str = PyString_AsString(output); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
961 if (!str) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
962 Py_DECREF(output); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
963 return NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
964 } |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
965 (*function)(invert, input, str, width, height); |
| 1179 | 966 |
| 967 return output; | |
| 968 } | |
| 969 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
970 static PyObject * |
| 1179 | 971 sv_InterleaveFields(self, args) |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
972 PyObject *self, *args; |
| 1179 | 973 { |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
974 return sv_conversion(self, args, svInterleaveFields, 1, 1.0); |
| 1179 | 975 } |
| 976 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
977 static PyObject * |
| 1179 | 978 sv_RGB8toRGB32(self, args) |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
979 PyObject *self, *args; |
| 1179 | 980 { |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
981 return sv_conversion(self, args, svRGB8toRGB32, 1, (float) sizeof(long)); |
| 1179 | 982 } |
| 983 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
984 static PyObject * |
| 1179 | 985 sv_YUVtoRGB(self, args) |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
986 PyObject *self, *args; |
| 1179 | 987 { |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
988 return sv_conversion(self, args, svYUVtoRGB, 2, (float) sizeof(long)); |
| 1179 | 989 } |
| 990 | |
| 991 static void | |
| 992 svideo_dealloc(self) | |
| 993 svobject *self; | |
| 994 { | |
| 995 if (self->ob_svideo != NULL) | |
| 996 (void) svCloseVideo(self->ob_svideo); | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
997 PyMem_DEL(self); |
| 1179 | 998 } |
| 999 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1000 static PyObject * |
| 1179 | 1001 svideo_getattr(self, name) |
| 1002 svobject *self; | |
| 1003 char *name; | |
| 1004 { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1005 return Py_FindMethod(svideo_methods, (PyObject *)self, name); |
| 1179 | 1006 } |
| 1007 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1008 PyTypeObject Svtype = { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1009 PyObject_HEAD_INIT(&PyType_Type) |
| 1179 | 1010 0, /*ob_size*/ |
| 1011 "sv", /*tp_name*/ | |
| 1012 sizeof(svobject), /*tp_size*/ | |
| 1013 0, /*tp_itemsize*/ | |
| 1014 /* methods */ | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
1015 (destructor)svideo_dealloc, /*tp_dealloc*/ |
| 1179 | 1016 0, /*tp_print*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
1017 (getattrfunc)svideo_getattr, /*tp_getattr*/ |
| 1179 | 1018 0, /*tp_setattr*/ |
| 1019 0, /*tp_compare*/ | |
| 1020 0, /*tp_repr*/ | |
| 1021 }; | |
| 1022 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1023 static PyObject * |
| 1179 | 1024 newsvobject(svp) |
| 1025 SV_nodeP svp; | |
| 1026 { | |
| 1027 svobject *p; | |
| 1028 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1029 p = PyObject_NEW(svobject, &Svtype); |
| 1179 | 1030 if (p == NULL) |
| 1031 return NULL; | |
| 1032 p->ob_svideo = svp; | |
| 1033 p->ob_info.format = 0; | |
| 1034 p->ob_info.size = 0; | |
| 1035 p->ob_info.width = 0; | |
| 1036 p->ob_info.height = 0; | |
| 1037 p->ob_info.samplingrate = 0; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1038 return (PyObject *) p; |
| 1179 | 1039 } |
| 1040 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1041 static PyObject * |
| 1179 | 1042 sv_OpenVideo(self, args) |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1043 PyObject *self, *args; |
| 1179 | 1044 { |
| 1045 SV_nodeP svp; | |
| 1046 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1047 if (!PyArg_Parse(args, "")) |
| 1179 | 1048 return NULL; |
| 1049 | |
| 1050 svp = svOpenVideo(); | |
| 1051 if (svp == NULL) | |
| 1052 return sv_error(); | |
| 1053 | |
| 1054 return newsvobject(svp); | |
| 1055 } | |
| 1056 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1057 static PyMethodDef sv_methods[] = { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1058 {"InterleaveFields", (PyCFunction)sv_InterleaveFields}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1059 {"RGB8toRGB32", (PyCFunction)sv_RGB8toRGB32}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1060 {"YUVtoRGB", (PyCFunction)sv_YUVtoRGB}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1061 {"OpenVideo", (PyCFunction)sv_OpenVideo}, |
| 1179 | 1062 {NULL, NULL} /* Sentinel */ |
| 1063 }; | |
| 1064 | |
| 1065 void | |
| 1066 initsv() | |
| 1067 { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1068 PyObject *m, *d; |
| 1179 | 1069 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1070 m = Py_InitModule("sv", sv_methods); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1071 d = PyModule_GetDict(m); |
| 1179 | 1072 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1073 SvError = PyString_FromString("sv.error"); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1074 if (SvError == NULL || PyDict_SetItemString(d, "error", SvError) != 0) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
1075 Py_FatalError("can't define sv.error"); |
| 1179 | 1076 } |
