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