Mercurial > cpython-lru_cache-weakref
annotate Modules/svmodule.c @ 16798:258dcafe2d0b legacy-trunk
Gustavo Niemeyer <niemeyer@conectiva.com>:
Fixed recno support (keys are integers rather than strings).
Work around DB bug that cause stdin to be closed by rnopen() when the
DB file needed to exist but did not (no longer segfaults).
This closes SF tracker patch #403445.
Also wrapped some long lines and added whitespace around operators -- FLD.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Tue, 27 Feb 2001 18:56:46 +0000 |
| parents | 6f6f965c5e2d |
| children | 91dd223829c6 |
| rev | line source |
|---|---|
| 1179 | 1 /* SV module -- interface to the Indigo video board */ |
| 2 | |
|
4762
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
3 /* 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
|
4 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
|
5 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
|
6 -- user beware! */ |
|
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
7 |
| 1179 | 8 #include <sys/time.h> |
| 9 #include <svideo.h> | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
10 #include "Python.h" |
| 1179 | 11 #include "compile.h" |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
12 #include "yuv.h" /* for YUV conversion functions */ |
| 1179 | 13 |
| 14 typedef struct { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
15 PyObject_HEAD |
| 1179 | 16 SV_nodeP ob_svideo; |
| 17 svCaptureInfo ob_info; | |
| 18 } svobject; | |
| 19 | |
| 20 typedef struct { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
21 PyObject_HEAD |
| 1179 | 22 void *ob_capture; |
| 23 int ob_mustunlock; | |
| 24 svCaptureInfo ob_info; | |
| 25 svobject *ob_svideo; | |
| 26 } captureobject; | |
| 27 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
28 static PyObject *SvError; /* exception sv.error */ |
| 1179 | 29 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
30 static PyObject *newcaptureobject(svobject *, void *, int); |
| 1179 | 31 |
| 32 /* 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
|
33 static PyObject * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13503
diff
changeset
|
34 sv_error(void) |
| 1179 | 35 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
36 PyErr_SetString(SvError, svStrerror(svideo_errno)); |
| 1179 | 37 return NULL; |
| 38 } | |
| 39 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
40 static PyObject * |
| 13503 | 41 svc_conversion(captureobject *self, PyObject *args, void (*function)(), float factor) |
| 1179 | 42 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
43 PyObject *output; |
| 1179 | 44 int invert; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
45 char* outstr; |
| 1179 | 46 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
47 if (!PyArg_Parse(args, "i", &invert)) |
| 1179 | 48 return NULL; |
| 49 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
50 if (!(output = PyString_FromStringAndSize( |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
51 NULL, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
52 (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
|
53 { |
| 1179 | 54 return NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
55 } |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
56 if (!(outstr = PyString_AsString(output))) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
57 Py_DECREF(output); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
58 return NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
59 } |
| 1179 | 60 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
61 (*function)((boolean)invert, self->ob_capture, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
62 outstr, |
| 1179 | 63 self->ob_info.width, self->ob_info.height); |
| 64 | |
| 65 return output; | |
| 66 } | |
| 67 | |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
68 /* |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
69 * 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
|
70 * Compression Library 4:2:2 Duplicate Chroma format. |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
71 */ |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
72 static PyObject * |
| 13503 | 73 svc_YUVtoYUV422DC(captureobject *self, PyObject *args) |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
74 { |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
75 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
|
76 PyErr_SetString(SvError, "data has bad format"); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
77 return NULL; |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
78 } |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
79 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
|
80 } |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
81 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
82 static PyObject * |
| 13503 | 83 svc_YUVtoYUV422DC_quarter(captureobject *self, PyObject *args) |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
84 { |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
85 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
|
86 PyErr_SetString(SvError, "data has bad format"); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
87 return NULL; |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
88 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
89 return svc_conversion(self, args, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
90 yuv_sv411_to_cl422dc_quartersize, 0.5); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
91 } |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
92 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
93 static PyObject * |
| 13503 | 94 svc_YUVtoYUV422DC_sixteenth(captureobject *self, PyObject *args) |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
95 { |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
96 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
|
97 PyErr_SetString(SvError, "data has bad format"); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
98 return NULL; |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
99 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
100 return svc_conversion(self, args, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
101 yuv_sv411_to_cl422dc_sixteenthsize, 0.125); |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
102 } |
|
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
103 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
104 static PyObject * |
| 13503 | 105 svc_YUVtoRGB(captureobject *self, PyObject *args) |
| 1179 | 106 { |
| 107 switch (self->ob_info.format) { | |
| 108 case SV_YUV411_FRAMES: | |
| 109 case SV_YUV411_FRAMES_AND_BLANKING_BUFFER: | |
| 110 break; | |
| 111 default: | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
112 PyErr_SetString(SvError, "data had bad format"); |
| 1179 | 113 return NULL; |
| 114 } | |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
115 return svc_conversion(self, args, svYUVtoRGB, (float) sizeof(long)); |
| 1179 | 116 } |
| 117 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
118 static PyObject * |
| 13503 | 119 svc_RGB8toRGB32(captureobject *self, PyObject *args) |
| 1179 | 120 { |
| 121 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
|
122 PyErr_SetString(SvError, "data has bad format"); |
| 1179 | 123 return NULL; |
| 124 } | |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
125 return svc_conversion(self, args, svRGB8toRGB32, (float) sizeof(long)); |
| 1179 | 126 } |
| 127 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
128 static PyObject * |
| 13503 | 129 svc_InterleaveFields(captureobject *self, PyObject *args) |
| 1179 | 130 { |
| 131 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
|
132 PyErr_SetString(SvError, "data has bad format"); |
| 1179 | 133 return NULL; |
| 134 } | |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
135 return svc_conversion(self, args, svInterleaveFields, 1.0); |
| 1179 | 136 } |
| 137 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
138 static PyObject * |
| 13503 | 139 svc_GetFields(captureobject *self, PyObject *args) |
| 1179 | 140 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
141 PyObject *f1 = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
142 PyObject *f2 = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
143 PyObject *ret = NULL; |
| 1179 | 144 int fieldsize; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
145 char* obcapture; |
| 1179 | 146 |
| 147 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
|
148 PyErr_SetString(SvError, "data has bad format"); |
| 1179 | 149 return NULL; |
| 150 } | |
| 151 | |
| 152 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
|
153 obcapture = (char*)self->ob_capture; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
154 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
155 if (!(f1 = PyString_FromStringAndSize(obcapture, fieldsize))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
156 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
157 if (!(f2 = PyString_FromStringAndSize(obcapture + fieldsize, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
158 fieldsize))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
159 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
160 ret = Py_BuildValue("(OO)", f1, f2); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
161 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
162 finally: |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
163 Py_XDECREF(f1); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
164 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
|
165 return ret; |
| 1179 | 166 } |
| 167 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
168 static PyObject * |
| 13503 | 169 svc_UnlockCaptureData(captureobject *self, PyObject *args) |
| 1179 | 170 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
171 if (!PyArg_Parse(args, "")) |
| 1179 | 172 return NULL; |
| 173 | |
| 174 if (!self->ob_mustunlock) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
175 PyErr_SetString(SvError, "buffer should not be unlocked"); |
| 1179 | 176 return NULL; |
| 177 } | |
| 178 | |
| 179 if (svUnlockCaptureData(self->ob_svideo->ob_svideo, self->ob_capture)) | |
| 180 return sv_error(); | |
| 181 | |
| 182 self->ob_mustunlock = 0; | |
| 183 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
184 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
185 return Py_None; |
| 1179 | 186 } |
| 187 | |
| 188 #ifdef USE_GL | |
| 189 #include <gl.h> | |
| 190 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
191 static PyObject * |
| 13503 | 192 svc_lrectwrite(captureobject *self, PyObject *args) |
| 1179 | 193 { |
| 194 Screencoord x1, x2, y1, y2; | |
| 195 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
196 if (!PyArg_Parse(args, "(hhhh)", &x1, &x2, &y1, &y2)) |
| 1179 | 197 return NULL; |
| 198 | |
| 199 lrectwrite(x1, x2, y1, y2, (unsigned long *) self->ob_capture); | |
| 200 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
201 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
202 return Py_None; |
| 1179 | 203 } |
| 204 #endif | |
| 205 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
206 static PyObject * |
| 13503 | 207 svc_writefile(captureobject *self, PyObject *args) |
| 1179 | 208 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
209 PyObject *file; |
| 1179 | 210 int size; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
211 FILE* fp; |
| 1179 | 212 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
213 if (!PyArg_Parse(args, "O", &file)) |
| 1179 | 214 return NULL; |
| 215 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
216 if (!PyFile_Check(file)) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
217 PyErr_SetString(SvError, "not a file object"); |
| 1179 | 218 return NULL; |
| 219 } | |
| 220 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
221 if (!(fp = PyFile_AsFile(file))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
222 return NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
223 |
| 1179 | 224 size = self->ob_info.width * self->ob_info.height; |
| 225 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
226 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
|
227 PyErr_SetString(SvError, "writing failed"); |
| 1179 | 228 return NULL; |
| 229 } | |
| 230 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
231 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
232 return Py_None; |
| 1179 | 233 } |
| 234 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
235 static PyObject * |
| 13503 | 236 svc_FindVisibleRegion(captureobject *self, PyObject *args) |
| 1179 | 237 { |
| 238 void *visible; | |
| 239 int width; | |
| 240 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
241 if (!PyArg_Parse(args, "")) |
| 1179 | 242 return NULL; |
| 243 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
244 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
|
245 self->ob_capture, &visible, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
246 self->ob_info.width)) |
| 1179 | 247 return sv_error(); |
| 248 | |
| 249 if (visible == NULL) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
250 PyErr_SetString(SvError, "data in wrong format"); |
| 1179 | 251 return NULL; |
| 252 } | |
| 253 | |
| 254 return newcaptureobject(self->ob_svideo, visible, 0); | |
| 255 } | |
| 256 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
257 static PyMethodDef capture_methods[] = { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
258 {"YUVtoRGB", (PyCFunction)svc_YUVtoRGB}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
259 {"RGB8toRGB32", (PyCFunction)svc_RGB8toRGB32}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
260 {"InterleaveFields", (PyCFunction)svc_InterleaveFields}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
261 {"UnlockCaptureData", (PyCFunction)svc_UnlockCaptureData}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
262 {"FindVisibleRegion", (PyCFunction)svc_FindVisibleRegion}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
263 {"GetFields", (PyCFunction)svc_GetFields}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
264 {"YUVtoYUV422DC", (PyCFunction)svc_YUVtoYUV422DC}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
265 {"YUVtoYUV422DC_quarter",(PyCFunction)svc_YUVtoYUV422DC_quarter}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
266 {"YUVtoYUV422DC_sixteenth",(PyCFunction)svc_YUVtoYUV422DC_sixteenth}, |
| 1179 | 267 #ifdef USE_GL |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
268 {"lrectwrite", (PyCFunction)svc_lrectwrite}, |
| 1179 | 269 #endif |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
270 {"writefile", (PyCFunction)svc_writefile}, |
| 1179 | 271 {NULL, NULL} /* sentinel */ |
| 272 }; | |
| 273 | |
| 274 static void | |
| 13503 | 275 capture_dealloc(captureobject *self) |
| 1179 | 276 { |
| 277 if (self->ob_capture != NULL) { | |
| 278 if (self->ob_mustunlock) | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
279 (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
|
280 self->ob_capture); |
| 1179 | 281 self->ob_capture = NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
282 Py_DECREF(self->ob_svideo); |
| 1179 | 283 self->ob_svideo = NULL; |
| 284 } | |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
285 PyObject_Del(self); |
| 1179 | 286 } |
| 287 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
288 static PyObject * |
| 13503 | 289 capture_getattr(svobject *self, char *name) |
| 1179 | 290 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
291 return Py_FindMethod(capture_methods, (PyObject *)self, name); |
| 1179 | 292 } |
| 293 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
294 PyTypeObject Capturetype = { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
295 PyObject_HEAD_INIT(&PyType_Type) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
296 0, /*ob_size*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
297 "capture", /*tp_name*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
298 sizeof(captureobject), /*tp_size*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
299 0, /*tp_itemsize*/ |
| 1179 | 300 /* methods */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
301 (destructor)capture_dealloc, /*tp_dealloc*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
302 0, /*tp_print*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
303 (getattrfunc)capture_getattr, /*tp_getattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
304 0, /*tp_setattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
305 0, /*tp_compare*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
306 0, /*tp_repr*/ |
| 1179 | 307 }; |
| 308 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
309 static PyObject * |
| 13503 | 310 newcaptureobject(svobject *self, void *ptr, int mustunlock) |
| 1179 | 311 { |
| 312 captureobject *p; | |
| 313 | |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
314 p = PyObject_New(captureobject, &Capturetype); |
| 1179 | 315 if (p == NULL) |
| 316 return NULL; | |
| 317 p->ob_svideo = self; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
318 Py_INCREF(self); |
| 1179 | 319 p->ob_capture = ptr; |
| 320 p->ob_mustunlock = mustunlock; | |
| 321 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
|
322 return (PyObject *) p; |
| 1179 | 323 } |
| 324 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
325 static PyObject * |
| 13503 | 326 sv_GetCaptureData(svobject *self, PyObject *args) |
| 1179 | 327 { |
| 328 void *ptr; | |
| 329 long fieldID; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
330 PyObject *res, *c; |
| 1179 | 331 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
332 if (!PyArg_Parse(args, "")) |
| 1179 | 333 return NULL; |
| 334 | |
| 335 if (svGetCaptureData(self->ob_svideo, &ptr, &fieldID)) | |
| 336 return sv_error(); | |
| 337 | |
| 338 if (ptr == NULL) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
339 PyErr_SetString(SvError, "no data available"); |
| 1179 | 340 return NULL; |
| 341 } | |
| 342 | |
| 343 c = newcaptureobject(self, ptr, 1); | |
| 344 if (c == NULL) | |
| 345 return NULL; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
346 res = Py_BuildValue("(Oi)", c, fieldID); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
347 Py_DECREF(c); |
| 1179 | 348 return res; |
| 349 } | |
| 350 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
351 static PyObject * |
| 13503 | 352 sv_BindGLWindow(svobject *self, PyObject *args) |
| 1179 | 353 { |
| 354 long wid; | |
| 355 int mode; | |
| 356 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
357 if (!PyArg_Parse(args, "(ii)", &wid, &mode)) |
| 1179 | 358 return NULL; |
| 359 | |
| 360 if (svBindGLWindow(self->ob_svideo, wid, mode)) | |
| 361 return sv_error(); | |
| 362 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
363 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
364 return Py_None; |
| 1179 | 365 } |
| 366 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
367 static PyObject * |
| 13503 | 368 sv_EndContinuousCapture(svobject *self, PyObject *args) |
| 1179 | 369 { |
| 370 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
371 if (!PyArg_Parse(args, "")) |
| 1179 | 372 return NULL; |
| 373 | |
| 374 if (svEndContinuousCapture(self->ob_svideo)) | |
| 375 return sv_error(); | |
| 376 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
377 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
378 return Py_None; |
| 1179 | 379 } |
| 380 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
381 static PyObject * |
| 13503 | 382 sv_IsVideoDisplayed(svobject *self, PyObject *args) |
| 1179 | 383 { |
| 384 int v; | |
| 385 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
386 if (!PyArg_Parse(args, "")) |
| 1179 | 387 return NULL; |
| 388 | |
| 389 v = svIsVideoDisplayed(self->ob_svideo); | |
| 390 if (v == -1) | |
| 391 return sv_error(); | |
| 392 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
393 return PyInt_FromLong((long) v); |
| 1179 | 394 } |
| 395 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
396 static PyObject * |
| 13503 | 397 sv_OutputOffset(svobject *self, PyObject *args) |
| 1179 | 398 { |
| 399 int x_offset; | |
| 400 int y_offset; | |
| 401 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
402 if (!PyArg_Parse(args, "(ii)", &x_offset, &y_offset)) |
| 1179 | 403 return NULL; |
| 404 | |
| 405 if (svOutputOffset(self->ob_svideo, x_offset, y_offset)) | |
| 406 return sv_error(); | |
| 407 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
408 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
409 return Py_None; |
| 1179 | 410 } |
| 411 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
412 static PyObject * |
| 13503 | 413 sv_PutFrame(svobject *self, PyObject *args) |
| 1179 | 414 { |
| 415 char *buffer; | |
| 416 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
417 if (!PyArg_Parse(args, "s", &buffer)) |
| 1179 | 418 return NULL; |
| 419 | |
| 420 if (svPutFrame(self->ob_svideo, buffer)) | |
| 421 return sv_error(); | |
| 422 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
423 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
424 return Py_None; |
| 1179 | 425 } |
| 426 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
427 static PyObject * |
| 13503 | 428 sv_QuerySize(svobject *self, PyObject *args) |
| 1179 | 429 { |
| 430 int w; | |
| 431 int h; | |
| 432 int rw; | |
| 433 int rh; | |
| 434 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
435 if (!PyArg_Parse(args, "(ii)", &w, &h)) |
| 1179 | 436 return NULL; |
| 437 | |
| 438 if (svQuerySize(self->ob_svideo, w, h, &rw, &rh)) | |
| 439 return sv_error(); | |
| 440 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
441 return Py_BuildValue("(ii)", (long) rw, (long) rh); |
| 1179 | 442 } |
| 443 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
444 static PyObject * |
| 13503 | 445 sv_SetSize(svobject *self, PyObject *args) |
| 1179 | 446 { |
| 447 int w; | |
| 448 int h; | |
| 449 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
450 if (!PyArg_Parse(args, "(ii)", &w, &h)) |
| 1179 | 451 return NULL; |
| 452 | |
| 453 if (svSetSize(self->ob_svideo, w, h)) | |
| 454 return sv_error(); | |
| 455 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
456 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
457 return Py_None; |
| 1179 | 458 } |
| 459 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
460 static PyObject * |
| 13503 | 461 sv_SetStdDefaults(svobject *self, PyObject *args) |
| 1179 | 462 { |
| 463 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
464 if (!PyArg_Parse(args, "")) |
| 1179 | 465 return NULL; |
| 466 | |
| 467 if (svSetStdDefaults(self->ob_svideo)) | |
| 468 return sv_error(); | |
| 469 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
470 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
471 return Py_None; |
| 1179 | 472 } |
| 473 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
474 static PyObject * |
| 13503 | 475 sv_UseExclusive(svobject *self, PyObject *args) |
| 1179 | 476 { |
| 477 boolean onoff; | |
| 478 int mode; | |
| 479 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
480 if (!PyArg_Parse(args, "(ii)", &onoff, &mode)) |
| 1179 | 481 return NULL; |
| 482 | |
| 483 if (svUseExclusive(self->ob_svideo, onoff, mode)) | |
| 484 return sv_error(); | |
| 485 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
486 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
487 return Py_None; |
| 1179 | 488 } |
| 489 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
490 static PyObject * |
| 13503 | 491 sv_WindowOffset(svobject *self, PyObject *args) |
| 1179 | 492 { |
| 493 int x_offset; | |
| 494 int y_offset; | |
| 495 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
496 if (!PyArg_Parse(args, "(ii)", &x_offset, &y_offset)) |
| 1179 | 497 return NULL; |
| 498 | |
| 499 if (svWindowOffset(self->ob_svideo, x_offset, y_offset)) | |
| 500 return sv_error(); | |
| 501 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
502 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
503 return Py_None; |
| 1179 | 504 } |
| 505 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
506 static PyObject * |
| 13503 | 507 sv_CaptureBurst(svobject *self, PyObject *args) |
| 1179 | 508 { |
| 509 int bytes, i; | |
| 510 svCaptureInfo info; | |
| 511 void *bitvector = NULL; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
512 PyObject *videodata = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
513 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
|
514 PyObject *res = NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
515 static PyObject *evenitem, *odditem; |
| 1179 | 516 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
517 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
|
518 &info.width, &info.height, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
519 &info.size, &info.samplingrate)) |
| 1179 | 520 return NULL; |
| 521 | |
| 522 switch (info.format) { | |
| 523 case SV_RGB8_FRAMES: | |
| 524 bitvector = malloc(SV_BITVEC_SIZE(info.size)); | |
| 525 break; | |
| 526 case SV_YUV411_FRAMES_AND_BLANKING_BUFFER: | |
| 527 break; | |
| 528 default: | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
529 PyErr_SetString(SvError, "illegal format specified"); |
| 1179 | 530 return NULL; |
| 531 } | |
| 532 | |
| 533 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
|
534 res = sv_error(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
535 goto finally; |
| 1179 | 536 } |
| 537 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
538 if (!(videodata = PyString_FromStringAndSize(NULL, bytes))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
539 goto finally; |
| 1179 | 540 |
| 541 /* 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
|
542 { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
543 char* str = PyString_AsString(videodata); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
544 if (!str) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
545 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
546 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
547 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
|
548 res = sv_error(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
549 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
550 } |
| 1179 | 551 } |
| 552 | |
| 553 if (bitvector) { | |
| 554 if (evenitem == NULL) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
555 if (!(evenitem = PyInt_FromLong(0))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
556 goto finally; |
| 1179 | 557 } |
| 558 if (odditem == NULL) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
559 if (!(odditem = PyInt_FromLong(1))) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
560 goto finally; |
| 1179 | 561 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
562 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
|
563 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
564 |
| 1179 | 565 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
|
566 int sts; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
567 |
| 1179 | 568 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
|
569 Py_INCREF(evenitem); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
570 sts = PyTuple_SetItem(bitvecobj, i, evenitem); |
| 1179 | 571 } else { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
572 Py_INCREF(odditem); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
573 sts = PyTuple_SetItem(bitvecobj, i, odditem); |
| 1179 | 574 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
575 if (sts < 0) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
576 goto finally; |
| 1179 | 577 } |
| 578 } else { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
579 bitvecobj = Py_None; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
580 Py_INCREF(Py_None); |
| 1179 | 581 } |
| 582 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
583 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
|
584 info.width, info.height, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
585 info.size, info.samplingrate, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
586 videodata, bitvecobj); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
587 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
588 finally: |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
589 if (bitvector) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
590 free(bitvector); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
591 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
592 Py_XDECREF(videodata); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
593 Py_XDECREF(bitvecobj); |
| 1179 | 594 return res; |
| 595 } | |
| 596 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
597 static PyObject * |
| 13503 | 598 sv_CaptureOneFrame(svobject *self, PyObject *args) |
| 1179 | 599 { |
| 600 svCaptureInfo info; | |
| 601 int format, width, height; | |
| 602 int bytes; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
603 PyObject *videodata = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
604 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
|
605 char *str; |
| 1179 | 606 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
607 if (!PyArg_Parse(args, "(iii)", &format, &width, &height)) |
| 1179 | 608 return NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
609 |
| 1179 | 610 info.format = format; |
| 611 info.width = width; | |
| 612 info.height = height; | |
| 613 info.size = 0; | |
| 614 info.samplingrate = 0; | |
| 615 if (svQueryCaptureBufferSize(self->ob_svideo, &info, &bytes)) | |
| 616 return sv_error(); | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
617 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
618 if (!(videodata = PyString_FromStringAndSize(NULL, bytes))) |
| 1179 | 619 return NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
620 |
|
4762
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
621 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
|
622 if (!str) |
|
f926263fb654
Corrected two errors introduced by the renaming (and the subsequent
Guido van Rossum <guido@python.org>
parents:
4712
diff
changeset
|
623 goto finally; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
624 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
625 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
|
626 res = sv_error(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
627 goto finally; |
| 1179 | 628 } |
| 629 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
630 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
|
631 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
632 finally: |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
633 Py_XDECREF(videodata); |
| 1179 | 634 return res; |
| 635 } | |
| 636 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
637 static PyObject * |
| 13503 | 638 sv_InitContinuousCapture(svobject *self, PyObject *args) |
| 1179 | 639 { |
| 640 svCaptureInfo info; | |
| 641 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
642 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
|
643 &info.width, &info.height, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
644 &info.size, &info.samplingrate)) |
| 1179 | 645 return NULL; |
| 646 | |
| 647 if (svInitContinuousCapture(self->ob_svideo, &info)) | |
| 648 return sv_error(); | |
| 649 | |
| 650 self->ob_info = info; | |
| 651 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
652 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
|
653 info.size, info.samplingrate); |
| 1179 | 654 } |
| 655 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
656 static PyObject * |
| 13503 | 657 sv_LoadMap(svobject *self, PyObject *args) |
| 1179 | 658 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
659 PyObject *rgb; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
660 PyObject *res = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
661 rgb_tuple *mapp = NULL; |
| 1179 | 662 int maptype; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
663 int i, j; /* indices */ |
| 1179 | 664 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
665 if (!PyArg_Parse(args, "(iO)", &maptype, &rgb)) |
| 1179 | 666 return NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
667 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
668 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
|
669 PyErr_BadArgument(); |
| 1179 | 670 return NULL; |
| 671 } | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
672 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
673 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
|
674 return PyErr_NoMemory(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
675 |
| 1179 | 676 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
|
677 PyObject* v = PyList_GetItem(rgb, i); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
678 if (!v) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
679 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
680 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
681 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
|
682 PyErr_BadArgument(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
683 goto finally; |
| 1179 | 684 } |
| 685 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
|
686 PyObject* cell = PyTuple_GetItem(v, j); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
687 if (!cell) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
688 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
689 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
690 if (!PyInt_Check(cell)) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
691 PyErr_BadArgument(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
692 goto finally; |
| 1179 | 693 } |
| 694 switch (j) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
695 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
|
696 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
|
697 case 2: mapp[i].green = PyInt_AsLong(cell); break; |
| 1179 | 698 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
699 if (PyErr_Occurred()) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
700 goto finally; |
| 1179 | 701 } |
| 702 } | |
| 703 | |
| 704 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
|
705 res = sv_error(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
706 goto finally; |
| 1179 | 707 } |
| 708 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
709 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
710 res = Py_None; |
| 1179 | 711 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
712 finally: |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
713 PyMem_DEL(mapp); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
714 return res; |
| 1179 | 715 } |
| 716 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
717 static PyObject * |
| 13503 | 718 sv_CloseVideo(svobject *self, PyObject *args) |
| 1179 | 719 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
720 if (!PyArg_Parse(args, "")) |
| 1179 | 721 return NULL; |
| 722 | |
| 723 if (svCloseVideo(self->ob_svideo)) | |
| 724 return sv_error(); | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
725 |
| 1179 | 726 self->ob_svideo = NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
727 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
728 return Py_None; |
| 1179 | 729 } |
| 730 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
731 static PyObject * |
| 13503 | 732 doParams(svobject *self, PyObject *args, |
| 733 int (*func)(SV_nodeP, long *, int), int modified) | |
| 1179 | 734 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
735 PyObject *list; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
736 PyObject *res = NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
737 long *PVbuffer = NULL; |
| 1179 | 738 long length; |
| 739 int i; | |
| 740 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
741 if (!PyArg_Parse(args, "O", &list)) |
| 1179 | 742 return NULL; |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
743 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
744 if (!PyList_Check(list)) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
745 PyErr_BadArgument(); |
| 1179 | 746 return NULL; |
| 747 } | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
748 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
749 if ((length = PyList_Size(list)) < 0) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
750 return NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
751 |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
752 PVbuffer = PyMem_NEW(long, length); |
| 1179 | 753 if (PVbuffer == NULL) |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
754 return PyErr_NoMemory(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
755 |
| 1179 | 756 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
|
757 PyObject *v = PyList_GetItem(list, i); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
758 if (!v) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
759 goto finally; |
|
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 (!PyInt_Check(v)) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
762 PyErr_BadArgument(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
763 goto finally; |
| 1179 | 764 } |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
765 PVbuffer[i] = PyInt_AsLong(v); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
766 /* 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
|
767 value was -1?! |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
768 */ |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
769 if (PVbuffer[i] == -1 && PyErr_Occurred()) |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
770 goto finally; |
| 1179 | 771 } |
| 772 | |
| 773 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
|
774 res = sv_error(); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
775 goto finally; |
| 1179 | 776 } |
| 777 | |
| 778 if (modified) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
779 for (i = 0; i < length; i++) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
780 PyObject* v = PyInt_FromLong(PVbuffer[i]); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
781 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
|
782 goto finally; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
783 } |
| 1179 | 784 } |
| 785 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
786 Py_INCREF(Py_None); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
787 res = Py_None; |
| 1179 | 788 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
789 finally: |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
790 PyMem_DEL(PVbuffer); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
791 return res; |
| 1179 | 792 } |
| 793 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
794 static PyObject * |
| 13503 | 795 sv_GetParam(PyObject *self, PyObject *args) |
| 1179 | 796 { |
| 797 return doParams(self, args, svGetParam, 1); | |
| 798 } | |
| 799 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
800 static PyObject * |
| 13503 | 801 sv_GetParamRange(PyObject *self, PyObject *args) |
| 1179 | 802 { |
| 803 return doParams(self, args, svGetParamRange, 1); | |
| 804 } | |
| 805 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
806 static PyObject * |
| 13503 | 807 sv_SetParam(PyObject *self, PyObject *args) |
| 1179 | 808 { |
| 809 return doParams(self, args, svSetParam, 0); | |
| 810 } | |
| 811 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
812 static PyMethodDef svideo_methods[] = { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
813 {"BindGLWindow", (PyCFunction)sv_BindGLWindow}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
814 {"EndContinuousCapture",(PyCFunction)sv_EndContinuousCapture}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
815 {"IsVideoDisplayed", (PyCFunction)sv_IsVideoDisplayed}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
816 {"OutputOffset", (PyCFunction)sv_OutputOffset}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
817 {"PutFrame", (PyCFunction)sv_PutFrame}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
818 {"QuerySize", (PyCFunction)sv_QuerySize}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
819 {"SetSize", (PyCFunction)sv_SetSize}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
820 {"SetStdDefaults", (PyCFunction)sv_SetStdDefaults}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
821 {"UseExclusive", (PyCFunction)sv_UseExclusive}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
822 {"WindowOffset", (PyCFunction)sv_WindowOffset}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
823 {"InitContinuousCapture",(PyCFunction)sv_InitContinuousCapture}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
824 {"CaptureBurst", (PyCFunction)sv_CaptureBurst}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
825 {"CaptureOneFrame", (PyCFunction)sv_CaptureOneFrame}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
826 {"GetCaptureData", (PyCFunction)sv_GetCaptureData}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
827 {"CloseVideo", (PyCFunction)sv_CloseVideo}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
828 {"LoadMap", (PyCFunction)sv_LoadMap}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
829 {"GetParam", (PyCFunction)sv_GetParam}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
830 {"GetParamRange", (PyCFunction)sv_GetParamRange}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
831 {"SetParam", (PyCFunction)sv_SetParam}, |
| 1179 | 832 {NULL, NULL} /* sentinel */ |
| 833 }; | |
| 834 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
835 static PyObject * |
| 13503 | 836 sv_conversion(PyObject *self, PyObject *args, void (*function)(), |
| 837 int inputfactor, float factor) | |
| 1179 | 838 { |
| 839 int invert, width, height, inputlength; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
840 char *input, *str; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
841 PyObject *output; |
| 1179 | 842 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
843 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
|
844 &input, &inputlength, &width, &height)) |
| 1179 | 845 return NULL; |
| 846 | |
| 847 if (width * height * inputfactor > inputlength) { | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
848 PyErr_SetString(SvError, "input buffer not long enough"); |
| 1179 | 849 return NULL; |
| 850 } | |
| 851 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
852 if (!(output = PyString_FromStringAndSize(NULL, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
853 (int)(width * height * factor)))) |
| 1179 | 854 return NULL; |
| 855 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
856 str = PyString_AsString(output); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
857 if (!str) { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
858 Py_DECREF(output); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
859 return NULL; |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
860 } |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
861 (*function)(invert, input, str, width, height); |
| 1179 | 862 |
| 863 return output; | |
| 864 } | |
| 865 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
866 static PyObject * |
| 13503 | 867 sv_InterleaveFields(PyObject *self, PyObject *args) |
| 1179 | 868 { |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
869 return sv_conversion(self, args, svInterleaveFields, 1, 1.0); |
| 1179 | 870 } |
| 871 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
872 static PyObject * |
| 13503 | 873 sv_RGB8toRGB32(PyObject *self, PyObject *args) |
| 1179 | 874 { |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
875 return sv_conversion(self, args, svRGB8toRGB32, 1, (float) sizeof(long)); |
| 1179 | 876 } |
| 877 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
878 static PyObject * |
| 13503 | 879 sv_YUVtoRGB(PyObject *self, PyObject *args) |
| 1179 | 880 { |
|
1253
685b31fe89c6
Added conversion routines to sv module.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1207
diff
changeset
|
881 return sv_conversion(self, args, svYUVtoRGB, 2, (float) sizeof(long)); |
| 1179 | 882 } |
| 883 | |
| 884 static void | |
| 13503 | 885 svideo_dealloc(svobject *self) |
| 1179 | 886 { |
| 887 if (self->ob_svideo != NULL) | |
| 888 (void) svCloseVideo(self->ob_svideo); | |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
889 PyObject_Del(self); |
| 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 * |
| 13503 | 893 svideo_getattr(svobject *self, char *name) |
| 1179 | 894 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
895 return Py_FindMethod(svideo_methods, (PyObject *)self, name); |
| 1179 | 896 } |
| 897 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
898 PyTypeObject Svtype = { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
899 PyObject_HEAD_INIT(&PyType_Type) |
| 1179 | 900 0, /*ob_size*/ |
| 901 "sv", /*tp_name*/ | |
| 902 sizeof(svobject), /*tp_size*/ | |
| 903 0, /*tp_itemsize*/ | |
| 904 /* methods */ | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
905 (destructor)svideo_dealloc, /*tp_dealloc*/ |
| 1179 | 906 0, /*tp_print*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1253
diff
changeset
|
907 (getattrfunc)svideo_getattr, /*tp_getattr*/ |
| 1179 | 908 0, /*tp_setattr*/ |
| 909 0, /*tp_compare*/ | |
| 910 0, /*tp_repr*/ | |
| 911 }; | |
| 912 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
913 static PyObject * |
| 13503 | 914 newsvobject(SV_nodeP svp) |
| 1179 | 915 { |
| 916 svobject *p; | |
| 917 | |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
918 p = PyObject_New(svobject, &Svtype); |
| 1179 | 919 if (p == NULL) |
| 920 return NULL; | |
| 921 p->ob_svideo = svp; | |
| 922 p->ob_info.format = 0; | |
| 923 p->ob_info.size = 0; | |
| 924 p->ob_info.width = 0; | |
| 925 p->ob_info.height = 0; | |
| 926 p->ob_info.samplingrate = 0; | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
927 return (PyObject *) p; |
| 1179 | 928 } |
| 929 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
930 static PyObject * |
| 13503 | 931 sv_OpenVideo(PyObject *self, PyObject *args) |
| 1179 | 932 { |
| 933 SV_nodeP svp; | |
| 934 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
935 if (!PyArg_Parse(args, "")) |
| 1179 | 936 return NULL; |
| 937 | |
| 938 svp = svOpenVideo(); | |
| 939 if (svp == NULL) | |
| 940 return sv_error(); | |
| 941 | |
| 942 return newsvobject(svp); | |
| 943 } | |
| 944 | |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
945 static PyMethodDef sv_methods[] = { |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
946 {"InterleaveFields", (PyCFunction)sv_InterleaveFields}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
947 {"RGB8toRGB32", (PyCFunction)sv_RGB8toRGB32}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
948 {"YUVtoRGB", (PyCFunction)sv_YUVtoRGB}, |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
949 {"OpenVideo", (PyCFunction)sv_OpenVideo}, |
| 1179 | 950 {NULL, NULL} /* Sentinel */ |
| 951 }; | |
| 952 | |
| 953 void | |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13503
diff
changeset
|
954 initsv(void) |
| 1179 | 955 { |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
956 PyObject *m, *d; |
| 1179 | 957 |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
958 m = Py_InitModule("sv", sv_methods); |
|
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
959 d = PyModule_GetDict(m); |
| 1179 | 960 |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
4762
diff
changeset
|
961 SvError = PyErr_NewException("sv.error", NULL, NULL); |
|
4712
0253ef267b68
Renamed, and scrutinized for missed potential error conditions.
Barry Warsaw <barry@python.org>
parents:
4503
diff
changeset
|
962 if (SvError == NULL || PyDict_SetItemString(d, "error", SvError) != 0) |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
4762
diff
changeset
|
963 return; |
| 1179 | 964 } |
