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