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