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