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