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