Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Modules/svmodule.c

    r2 r388  
    1010#include "Python.h"
    1111#include "compile.h"
    12 #include "yuv.h"                /* for YUV conversion functions */
     12#include "yuv.h"                /* for YUV conversion functions */
    1313
    1414typedef struct {
    15         PyObject_HEAD
    16         SV_nodeP ob_svideo;
    17         svCaptureInfo ob_info;
     15    PyObject_HEAD
     16    SV_nodeP ob_svideo;
     17    svCaptureInfo ob_info;
    1818} svobject;
    1919
    2020typedef struct {
    21         PyObject_HEAD
    22         void *ob_capture;
    23         int ob_mustunlock;
    24         svCaptureInfo ob_info;
    25         svobject *ob_svideo;
     21    PyObject_HEAD
     22    void *ob_capture;
     23    int ob_mustunlock;
     24    svCaptureInfo ob_info;
     25    svobject *ob_svideo;
    2626} captureobject;
    2727
    28 static PyObject *SvError;               /* exception sv.error */
     28static PyObject *SvError;               /* exception sv.error */
    2929
    3030static PyObject *newcaptureobject(svobject *, void *, int);
     
    3434sv_error(void)
    3535{
    36         PyErr_SetString(SvError, svStrerror(svideo_errno));
    37         return NULL;
    38 }
    39 
    40 static PyObject *
    41 svc_conversion(captureobject *self, PyObject *args, void (*function)(), float factor)
    42 {
    43         PyObject *output;
    44         int invert;
    45         char* outstr;
    46 
    47         if (!PyArg_Parse(args, "i", &invert))
    48                 return NULL;
    49 
    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         }
    60 
    61         (*function)((boolean)invert, self->ob_capture,
    62                     outstr,
    63                     self->ob_info.width, self->ob_info.height);
    64 
    65         return output;
     36    PyErr_SetString(SvError, svStrerror(svideo_errno));
     37    return NULL;
     38}
     39
     40static PyObject *
     41svc_conversion(captureobject *self, PyObject *args, void (*function)(), float factor)
     42{
     43    PyObject *output;
     44    int invert;
     45    char* outstr;
     46
     47    if (!PyArg_Parse(args, "i", &invert))
     48        return NULL;
     49
     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    }
     60
     61    (*function)((boolean)invert, self->ob_capture,
     62                outstr,
     63                self->ob_info.width, self->ob_info.height);
     64
     65    return output;
    6666}
    6767
     
    7373svc_YUVtoYUV422DC(captureobject *self, PyObject *args)
    7474{
    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);
     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);
    8080}
    8181
     
    8383svc_YUVtoYUV422DC_quarter(captureobject *self, PyObject *args)
    8484{
    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);
     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);
    9191}
    9292
     
    9494svc_YUVtoYUV422DC_sixteenth(captureobject *self, PyObject *args)
    9595{
    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);
     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);
    102102}
    103103
     
    105105svc_YUVtoRGB(captureobject *self, PyObject *args)
    106106{
    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));
     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));
    116116}
    117117
     
    119119svc_RGB8toRGB32(captureobject *self, PyObject *args)
    120120{
    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));
     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));
    126126}
    127127
     
    129129svc_InterleaveFields(captureobject *self, PyObject *args)
    130130{
    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);
     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);
    136136}
    137137
     
    139139svc_GetFields(captureobject *self, PyObject *args)
    140140{
    141         PyObject *f1 = NULL;
    142         PyObject *f2 = NULL;
    143         PyObject *ret = NULL;
    144         int fieldsize;
    145         char* obcapture;
    146 
    147         if (self->ob_info.format != SV_RGB8_FRAMES) {
    148                 PyErr_SetString(SvError, "data has bad format");
    149                 return NULL;
    150         }
    151 
    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);
     141    PyObject *f1 = NULL;
     142    PyObject *f2 = NULL;
     143    PyObject *ret = NULL;
     144    int fieldsize;
     145    char* obcapture;
     146
     147    if (self->ob_info.format != SV_RGB8_FRAMES) {
     148        PyErr_SetString(SvError, "data has bad format");
     149        return NULL;
     150    }
     151
     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);
    161161
    162162  finally:
    163         Py_XDECREF(f1);
    164         Py_XDECREF(f2);
    165         return ret;
    166 }
    167        
     163    Py_XDECREF(f1);
     164    Py_XDECREF(f2);
     165    return ret;
     166}
     167
    168168static PyObject *
    169169svc_UnlockCaptureData(captureobject *self, PyObject *args)
    170170{
    171         if (!PyArg_Parse(args, ""))
    172                 return NULL;
    173 
    174         if (!self->ob_mustunlock) {
    175                 PyErr_SetString(SvError, "buffer should not be unlocked");
    176                 return NULL;
    177         }
    178 
    179         if (svUnlockCaptureData(self->ob_svideo->ob_svideo, self->ob_capture))
    180                 return sv_error();
    181 
    182         self->ob_mustunlock = 0;
    183 
    184         Py_INCREF(Py_None);
    185         return Py_None;
     171    if (!PyArg_Parse(args, ""))
     172        return NULL;
     173
     174    if (!self->ob_mustunlock) {
     175        PyErr_SetString(SvError, "buffer should not be unlocked");
     176        return NULL;
     177    }
     178
     179    if (svUnlockCaptureData(self->ob_svideo->ob_svideo, self->ob_capture))
     180        return sv_error();
     181
     182    self->ob_mustunlock = 0;
     183
     184    Py_INCREF(Py_None);
     185    return Py_None;
    186186}
    187187
     
    192192svc_lrectwrite(captureobject *self, PyObject *args)
    193193{
    194         Screencoord x1, x2, y1, y2;
    195 
    196         if (!PyArg_Parse(args, "(hhhh)", &x1, &x2, &y1, &y2))
    197                 return NULL;
    198 
    199         lrectwrite(x1, x2, y1, y2, (unsigned long *) self->ob_capture);
    200 
    201         Py_INCREF(Py_None);
    202         return Py_None;
     194    Screencoord x1, x2, y1, y2;
     195
     196    if (!PyArg_Parse(args, "(hhhh)", &x1, &x2, &y1, &y2))
     197        return NULL;
     198
     199    lrectwrite(x1, x2, y1, y2, (unsigned long *) self->ob_capture);
     200
     201    Py_INCREF(Py_None);
     202    return Py_None;
    203203}
    204204#endif
     
    207207svc_writefile(captureobject *self, PyObject *args)
    208208{
    209         PyObject *file;
    210         int size;
    211         FILE* fp;
    212 
    213         if (!PyArg_Parse(args, "O", &file))
    214                 return NULL;
    215 
    216         if (!PyFile_Check(file)) {
    217                 PyErr_SetString(SvError, "not a file object");
    218                 return NULL;
    219         }
    220 
    221         if (!(fp = PyFile_AsFile(file)))
    222                 return NULL;
    223 
    224         size = self->ob_info.width * self->ob_info.height;
    225 
    226         if (fwrite(self->ob_capture, sizeof(long), size, fp) != size) {
    227                 PyErr_SetString(SvError, "writing failed");
    228                 return NULL;
    229         }
    230 
    231         Py_INCREF(Py_None);
    232         return Py_None;
     209    PyObject *file;
     210    int size;
     211    FILE* fp;
     212
     213    if (!PyArg_Parse(args, "O", &file))
     214        return NULL;
     215
     216    if (!PyFile_Check(file)) {
     217        PyErr_SetString(SvError, "not a file object");
     218        return NULL;
     219    }
     220
     221    if (!(fp = PyFile_AsFile(file)))
     222        return NULL;
     223
     224    size = self->ob_info.width * self->ob_info.height;
     225
     226    if (fwrite(self->ob_capture, sizeof(long), size, fp) != size) {
     227        PyErr_SetString(SvError, "writing failed");
     228        return NULL;
     229    }
     230
     231    Py_INCREF(Py_None);
     232    return Py_None;
    233233}
    234234
     
    236236svc_FindVisibleRegion(captureobject *self, PyObject *args)
    237237{
    238         void *visible;
    239         int width;
    240 
    241         if (!PyArg_Parse(args, ""))
    242                 return NULL;
    243 
    244         if (svFindVisibleRegion(self->ob_svideo->ob_svideo,
    245                                 self->ob_capture, &visible,
    246                                 self->ob_info.width))
    247                 return sv_error();
    248 
    249         if (visible == NULL) {
    250                 PyErr_SetString(SvError, "data in wrong format");
    251                 return NULL;
    252         }
    253 
    254         return newcaptureobject(self->ob_svideo, visible, 0);
     238    void *visible;
     239    int width;
     240
     241    if (!PyArg_Parse(args, ""))
     242        return NULL;
     243
     244    if (svFindVisibleRegion(self->ob_svideo->ob_svideo,
     245                            self->ob_capture, &visible,
     246                            self->ob_info.width))
     247        return sv_error();
     248
     249    if (visible == NULL) {
     250        PyErr_SetString(SvError, "data in wrong format");
     251        return NULL;
     252    }
     253
     254    return newcaptureobject(self->ob_svideo, visible, 0);
    255255}
    256256
    257257static PyMethodDef capture_methods[] = {
    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},
     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},
    267267#ifdef USE_GL
    268         {"lrectwrite",          (PyCFunction)svc_lrectwrite, METH_OLDARGS},
     268    {"lrectwrite",              (PyCFunction)svc_lrectwrite, METH_OLDARGS},
    269269#endif
    270         {"writefile",           (PyCFunction)svc_writefile, METH_OLDARGS},
    271         {NULL,                  NULL}           /* sentinel */
     270    {"writefile",               (PyCFunction)svc_writefile, METH_OLDARGS},
     271    {NULL,                      NULL}           /* sentinel */
    272272};
    273273
     
    275275capture_dealloc(captureobject *self)
    276276{
    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;
    282                 Py_DECREF(self->ob_svideo);
    283                 self->ob_svideo = NULL;
    284         }
    285         PyObject_Del(self);
     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;
     282        Py_DECREF(self->ob_svideo);
     283        self->ob_svideo = NULL;
     284    }
     285    PyObject_Del(self);
    286286}
    287287
     
    289289capture_getattr(svobject *self, char *name)
    290290{
    291         return Py_FindMethod(capture_methods, (PyObject *)self, name);
     291    return Py_FindMethod(capture_methods, (PyObject *)self, name);
    292292}
    293293
    294294PyTypeObject Capturetype = {
    295         PyObject_HEAD_INIT(&PyType_Type)
    296         0,                              /*ob_size*/
    297         "sv.capture",                   /*tp_name*/
    298         sizeof(captureobject),          /*tp_size*/
    299         0,                              /*tp_itemsize*/
    300         /* methods */
    301         (destructor)capture_dealloc,    /*tp_dealloc*/
    302         0,                              /*tp_print*/
    303         (getattrfunc)capture_getattr,   /*tp_getattr*/
    304         0,                              /*tp_setattr*/
    305         0,                              /*tp_compare*/
    306         0,                              /*tp_repr*/
     295    PyObject_HEAD_INIT(&PyType_Type)
     296    0,                                  /*ob_size*/
     297    "sv.capture",                       /*tp_name*/
     298    sizeof(captureobject),              /*tp_size*/
     299    0,                                  /*tp_itemsize*/
     300    /* methods */
     301    (destructor)capture_dealloc,        /*tp_dealloc*/
     302    0,                                  /*tp_print*/
     303    (getattrfunc)capture_getattr,       /*tp_getattr*/
     304    0,                                  /*tp_setattr*/
     305    0,                                  /*tp_compare*/
     306    0,                                  /*tp_repr*/
    307307};
    308308
     
    310310newcaptureobject(svobject *self, void *ptr, int mustunlock)
    311311{
    312         captureobject *p;
    313 
    314         p = PyObject_New(captureobject, &Capturetype);
    315         if (p == NULL)
    316                 return NULL;
    317         p->ob_svideo = self;
    318         Py_INCREF(self);
    319         p->ob_capture = ptr;
    320         p->ob_mustunlock = mustunlock;
    321         p->ob_info = self->ob_info;
    322         return (PyObject *) p;
     312    captureobject *p;
     313
     314    p = PyObject_New(captureobject, &Capturetype);
     315    if (p == NULL)
     316        return NULL;
     317    p->ob_svideo = self;
     318    Py_INCREF(self);
     319    p->ob_capture = ptr;
     320    p->ob_mustunlock = mustunlock;
     321    p->ob_info = self->ob_info;
     322    return (PyObject *) p;
    323323}
    324324
     
    326326sv_GetCaptureData(svobject *self, PyObject *args)
    327327{
    328         void *ptr;
    329         long fieldID;
    330         PyObject *res, *c;
    331 
    332         if (!PyArg_Parse(args, ""))
    333                 return NULL;
    334 
    335         if (svGetCaptureData(self->ob_svideo, &ptr, &fieldID))
    336                 return sv_error();
    337 
    338         if (ptr == NULL) {
    339                 PyErr_SetString(SvError, "no data available");
    340                 return NULL;
    341         }
    342 
    343         c = newcaptureobject(self, ptr, 1);
    344         if (c == NULL)
    345                 return NULL;
    346         res = Py_BuildValue("(Oi)", c, fieldID);
    347         Py_DECREF(c);
    348         return res;
     328    void *ptr;
     329    long fieldID;
     330    PyObject *res, *c;
     331
     332    if (!PyArg_Parse(args, ""))
     333        return NULL;
     334
     335    if (svGetCaptureData(self->ob_svideo, &ptr, &fieldID))
     336        return sv_error();
     337
     338    if (ptr == NULL) {
     339        PyErr_SetString(SvError, "no data available");
     340        return NULL;
     341    }
     342
     343    c = newcaptureobject(self, ptr, 1);
     344    if (c == NULL)
     345        return NULL;
     346    res = Py_BuildValue("(Oi)", c, fieldID);
     347    Py_DECREF(c);
     348    return res;
    349349}
    350350
     
    352352sv_BindGLWindow(svobject *self, PyObject *args)
    353353{
    354         long wid;
    355         int mode;
    356 
    357         if (!PyArg_Parse(args, "(ii)", &wid, &mode))
    358                 return NULL;
    359 
    360         if (svBindGLWindow(self->ob_svideo, wid, mode))
    361                 return sv_error();
    362 
    363         Py_INCREF(Py_None);
    364         return Py_None;
     354    long wid;
     355    int mode;
     356
     357    if (!PyArg_Parse(args, "(ii)", &wid, &mode))
     358        return NULL;
     359
     360    if (svBindGLWindow(self->ob_svideo, wid, mode))
     361        return sv_error();
     362
     363    Py_INCREF(Py_None);
     364    return Py_None;
    365365}
    366366
     
    369369{
    370370
    371         if (!PyArg_Parse(args, ""))
    372                 return NULL;
    373 
    374         if (svEndContinuousCapture(self->ob_svideo))
    375                 return sv_error();
    376 
    377         Py_INCREF(Py_None);
    378         return Py_None;
     371    if (!PyArg_Parse(args, ""))
     372        return NULL;
     373
     374    if (svEndContinuousCapture(self->ob_svideo))
     375        return sv_error();
     376
     377    Py_INCREF(Py_None);
     378    return Py_None;
    379379}
    380380
     
    382382sv_IsVideoDisplayed(svobject *self, PyObject *args)
    383383{
    384         int v;
    385 
    386         if (!PyArg_Parse(args, ""))
    387                 return NULL;
    388 
    389         v = svIsVideoDisplayed(self->ob_svideo);
    390         if (v == -1)
    391                 return sv_error();
    392 
    393         return PyInt_FromLong((long) v);
     384    int v;
     385
     386    if (!PyArg_Parse(args, ""))
     387        return NULL;
     388
     389    v = svIsVideoDisplayed(self->ob_svideo);
     390    if (v == -1)
     391        return sv_error();
     392
     393    return PyInt_FromLong((long) v);
    394394}
    395395
     
    397397sv_OutputOffset(svobject *self, PyObject *args)
    398398{
    399         int x_offset;
    400         int y_offset;
    401 
    402         if (!PyArg_Parse(args, "(ii)", &x_offset, &y_offset))
    403                 return NULL;
    404 
    405         if (svOutputOffset(self->ob_svideo, x_offset, y_offset))
    406                 return sv_error();
    407 
    408         Py_INCREF(Py_None);
    409         return Py_None;
     399    int x_offset;
     400    int y_offset;
     401
     402    if (!PyArg_Parse(args, "(ii)", &x_offset, &y_offset))
     403        return NULL;
     404
     405    if (svOutputOffset(self->ob_svideo, x_offset, y_offset))
     406        return sv_error();
     407
     408    Py_INCREF(Py_None);
     409    return Py_None;
    410410}
    411411
     
    413413sv_PutFrame(svobject *self, PyObject *args)
    414414{
    415         char *buffer;
    416 
    417         if (!PyArg_Parse(args, "s", &buffer))
    418                 return NULL;
    419 
    420         if (svPutFrame(self->ob_svideo, buffer))
    421                 return sv_error();
    422 
    423         Py_INCREF(Py_None);
    424         return Py_None;
     415    char *buffer;
     416
     417    if (!PyArg_Parse(args, "s", &buffer))
     418        return NULL;
     419
     420    if (svPutFrame(self->ob_svideo, buffer))
     421        return sv_error();
     422
     423    Py_INCREF(Py_None);
     424    return Py_None;
    425425}
    426426
     
    428428sv_QuerySize(svobject *self, PyObject *args)
    429429{
    430         int w;
    431         int h;
    432         int rw;
    433         int rh;
    434 
    435         if (!PyArg_Parse(args, "(ii)", &w, &h))
    436                 return NULL;
    437 
    438         if (svQuerySize(self->ob_svideo, w, h, &rw, &rh))
    439                 return sv_error();
    440 
    441         return Py_BuildValue("(ii)", (long) rw, (long) rh);
     430    int w;
     431    int h;
     432    int rw;
     433    int rh;
     434
     435    if (!PyArg_Parse(args, "(ii)", &w, &h))
     436        return NULL;
     437
     438    if (svQuerySize(self->ob_svideo, w, h, &rw, &rh))
     439        return sv_error();
     440
     441    return Py_BuildValue("(ii)", (long) rw, (long) rh);
    442442}
    443443
     
    445445sv_SetSize(svobject *self, PyObject *args)
    446446{
    447         int w;
    448         int h;
    449 
    450         if (!PyArg_Parse(args, "(ii)", &w, &h))
    451                 return NULL;
    452 
    453         if (svSetSize(self->ob_svideo, w, h))
    454                 return sv_error();
    455 
    456         Py_INCREF(Py_None);
    457         return Py_None;
     447    int w;
     448    int h;
     449
     450    if (!PyArg_Parse(args, "(ii)", &w, &h))
     451        return NULL;
     452
     453    if (svSetSize(self->ob_svideo, w, h))
     454        return sv_error();
     455
     456    Py_INCREF(Py_None);
     457    return Py_None;
    458458}
    459459
     
    462462{
    463463
    464         if (!PyArg_Parse(args, ""))
    465                 return NULL;
    466 
    467         if (svSetStdDefaults(self->ob_svideo))
    468                 return sv_error();
    469 
    470         Py_INCREF(Py_None);
    471         return Py_None;
     464    if (!PyArg_Parse(args, ""))
     465        return NULL;
     466
     467    if (svSetStdDefaults(self->ob_svideo))
     468        return sv_error();
     469
     470    Py_INCREF(Py_None);
     471    return Py_None;
    472472}
    473473
     
    475475sv_UseExclusive(svobject *self, PyObject *args)
    476476{
    477         boolean onoff;
    478         int mode;
    479 
    480         if (!PyArg_Parse(args, "(ii)", &onoff, &mode))
    481                 return NULL;
    482 
    483         if (svUseExclusive(self->ob_svideo, onoff, mode))
    484                 return sv_error();
    485 
    486         Py_INCREF(Py_None);
    487         return Py_None;
     477    boolean onoff;
     478    int mode;
     479
     480    if (!PyArg_Parse(args, "(ii)", &onoff, &mode))
     481        return NULL;
     482
     483    if (svUseExclusive(self->ob_svideo, onoff, mode))
     484        return sv_error();
     485
     486    Py_INCREF(Py_None);
     487    return Py_None;
    488488}
    489489
     
    491491sv_WindowOffset(svobject *self, PyObject *args)
    492492{
    493         int x_offset;
    494         int y_offset;
    495 
    496         if (!PyArg_Parse(args, "(ii)", &x_offset, &y_offset))
    497                 return NULL;
    498 
    499         if (svWindowOffset(self->ob_svideo, x_offset, y_offset))
    500                 return sv_error();
    501 
    502         Py_INCREF(Py_None);
    503         return Py_None;
     493    int x_offset;
     494    int y_offset;
     495
     496    if (!PyArg_Parse(args, "(ii)", &x_offset, &y_offset))
     497        return NULL;
     498
     499    if (svWindowOffset(self->ob_svideo, x_offset, y_offset))
     500        return sv_error();
     501
     502    Py_INCREF(Py_None);
     503    return Py_None;
    504504}
    505505
     
    507507sv_CaptureBurst(svobject *self, PyObject *args)
    508508{
    509         int bytes, i;
    510         svCaptureInfo info;
    511         void *bitvector = NULL;
    512         PyObject *videodata = NULL;
    513         PyObject *bitvecobj = NULL;
    514         PyObject *res = NULL;
    515         static PyObject *evenitem, *odditem;
    516 
    517         if (!PyArg_Parse(args, "(iiiii)", &info.format,
    518                         &info.width, &info.height,
    519                         &info.size, &info.samplingrate))
    520                 return NULL;
    521 
    522         switch (info.format) {
    523         case SV_RGB8_FRAMES:
    524                 bitvector = malloc(SV_BITVEC_SIZE(info.size));
    525                 break;
    526         case SV_YUV411_FRAMES_AND_BLANKING_BUFFER:
    527                 break;
    528         default:
    529                 PyErr_SetString(SvError, "illegal format specified");
    530                 return NULL;
    531         }
    532 
    533         if (svQueryCaptureBufferSize(self->ob_svideo, &info, &bytes)) {
    534                 res = sv_error();
    535                 goto finally;
    536         }
    537 
    538         if (!(videodata = PyString_FromStringAndSize(NULL, bytes)))
    539                 goto finally;
    540 
    541         /* XXX -- need to do something about the bitvector */
    542         {
    543                 char* str = PyString_AsString(videodata);
    544                 if (!str)
    545                         goto finally;
    546                
    547                 if (svCaptureBurst(self->ob_svideo, &info, str, bitvector)) {
    548                         res = sv_error();
    549                         goto finally;
    550                 }
    551         }
    552 
    553         if (bitvector) {
    554                 if (evenitem == NULL) {
    555                         if (!(evenitem = PyInt_FromLong(0)))
    556                                 goto finally;
    557                 }
    558                 if (odditem == NULL) {
    559                         if (!(odditem = PyInt_FromLong(1)))
    560                                 goto finally;
    561                 }
    562                 if (!(bitvecobj = PyTuple_New(2 * info.size)))
    563                         goto finally;
    564 
    565                 for (i = 0; i < 2 * info.size; i++) {
    566                         int sts;
    567 
    568                         if (SV_GET_FIELD(bitvector, i) == SV_EVEN_FIELD) {
    569                                 Py_INCREF(evenitem);
    570                                 sts = PyTuple_SetItem(bitvecobj, i, evenitem);
    571                         } else {
    572                                 Py_INCREF(odditem);
    573                                 sts = PyTuple_SetItem(bitvecobj, i, odditem);
    574                         }
    575                         if (sts < 0)
    576                                 goto finally;
    577                 }
    578         } else {
    579                 bitvecobj = Py_None;
    580                 Py_INCREF(Py_None);
    581         }
    582 
    583         res = Py_BuildValue("((iiiii)OO)", info.format,
    584                             info.width, info.height,
    585                             info.size, info.samplingrate,
    586                             videodata, bitvecobj);
     509    int bytes, i;
     510    svCaptureInfo info;
     511    void *bitvector = NULL;
     512    PyObject *videodata = NULL;
     513    PyObject *bitvecobj = NULL;
     514    PyObject *res = NULL;
     515    static PyObject *evenitem, *odditem;
     516
     517    if (!PyArg_Parse(args, "(iiiii)", &info.format,
     518                    &info.width, &info.height,
     519                    &info.size, &info.samplingrate))
     520        return NULL;
     521
     522    switch (info.format) {
     523    case SV_RGB8_FRAMES:
     524        bitvector = malloc(SV_BITVEC_SIZE(info.size));
     525        break;
     526    case SV_YUV411_FRAMES_AND_BLANKING_BUFFER:
     527        break;
     528    default:
     529        PyErr_SetString(SvError, "illegal format specified");
     530        return NULL;
     531    }
     532
     533    if (svQueryCaptureBufferSize(self->ob_svideo, &info, &bytes)) {
     534        res = sv_error();
     535        goto finally;
     536    }
     537
     538    if (!(videodata = PyString_FromStringAndSize(NULL, bytes)))
     539        goto finally;
     540
     541    /* XXX -- need to do something about the bitvector */
     542    {
     543        char* str = PyString_AsString(videodata);
     544        if (!str)
     545            goto finally;
     546
     547        if (svCaptureBurst(self->ob_svideo, &info, str, bitvector)) {
     548            res = sv_error();
     549            goto finally;
     550        }
     551    }
     552
     553    if (bitvector) {
     554        if (evenitem == NULL) {
     555            if (!(evenitem = PyInt_FromLong(0)))
     556                goto finally;
     557        }
     558        if (odditem == NULL) {
     559            if (!(odditem = PyInt_FromLong(1)))
     560                goto finally;
     561        }
     562        if (!(bitvecobj = PyTuple_New(2 * info.size)))
     563            goto finally;
     564
     565        for (i = 0; i < 2 * info.size; i++) {
     566            int sts;
     567
     568            if (SV_GET_FIELD(bitvector, i) == SV_EVEN_FIELD) {
     569                Py_INCREF(evenitem);
     570                sts = PyTuple_SetItem(bitvecobj, i, evenitem);
     571            } else {
     572                Py_INCREF(odditem);
     573                sts = PyTuple_SetItem(bitvecobj, i, odditem);
     574            }
     575            if (sts < 0)
     576                goto finally;
     577        }
     578    } else {
     579        bitvecobj = Py_None;
     580        Py_INCREF(Py_None);
     581    }
     582
     583    res = Py_BuildValue("((iiiii)OO)", info.format,
     584                        info.width, info.height,
     585                        info.size, info.samplingrate,
     586                        videodata, bitvecobj);
    587587
    588588  finally:
    589         if (bitvector)
    590                 free(bitvector);
    591 
    592         Py_XDECREF(videodata);
    593         Py_XDECREF(bitvecobj);
    594         return res;
     589    if (bitvector)
     590        free(bitvector);
     591
     592    Py_XDECREF(videodata);
     593    Py_XDECREF(bitvecobj);
     594    return res;
    595595}
    596596
     
    598598sv_CaptureOneFrame(svobject *self, PyObject *args)
    599599{
    600         svCaptureInfo info;
    601         int format, width, height;
    602         int bytes;
    603         PyObject *videodata = NULL;
    604         PyObject *res = NULL;
    605         char *str;
    606        
    607         if (!PyArg_Parse(args, "(iii)", &format, &width, &height))
    608                 return NULL;
    609 
    610         info.format = format;
    611         info.width = width;
    612         info.height = height;
    613         info.size = 0;
    614         info.samplingrate = 0;
    615         if (svQueryCaptureBufferSize(self->ob_svideo, &info, &bytes))
    616                 return sv_error();
    617 
    618         if (!(videodata = PyString_FromStringAndSize(NULL, bytes)))
    619                 return NULL;
    620        
    621         str = PyString_AsString(videodata);
    622         if (!str)
    623                 goto finally;
    624 
    625         if (svCaptureOneFrame(self->ob_svideo, format, &width, &height, str)) {
    626                 res = sv_error();
    627                 goto finally;
    628         }
    629 
    630         res = Py_BuildValue("(iiO)", width, height, videodata);
     600    svCaptureInfo info;
     601    int format, width, height;
     602    int bytes;
     603    PyObject *videodata = NULL;
     604    PyObject *res = NULL;
     605    char *str;
     606
     607    if (!PyArg_Parse(args, "(iii)", &format, &width, &height))
     608        return NULL;
     609
     610    info.format = format;
     611    info.width = width;
     612    info.height = height;
     613    info.size = 0;
     614    info.samplingrate = 0;
     615    if (svQueryCaptureBufferSize(self->ob_svideo, &info, &bytes))
     616        return sv_error();
     617
     618    if (!(videodata = PyString_FromStringAndSize(NULL, bytes)))
     619        return NULL;
     620
     621    str = PyString_AsString(videodata);
     622    if (!str)
     623        goto finally;
     624
     625    if (svCaptureOneFrame(self->ob_svideo, format, &width, &height, str)) {
     626        res = sv_error();
     627        goto finally;
     628    }
     629
     630    res = Py_BuildValue("(iiO)", width, height, videodata);
    631631
    632632  finally:
    633         Py_XDECREF(videodata);
    634         return res;
     633    Py_XDECREF(videodata);
     634    return res;
    635635}
    636636
     
    638638sv_InitContinuousCapture(svobject *self, PyObject *args)
    639639{
    640         svCaptureInfo info;
    641 
    642         if (!PyArg_Parse(args, "(iiiii)", &info.format,
    643                         &info.width, &info.height,
    644                         &info.size, &info.samplingrate))
    645                 return NULL;
    646 
    647         if (svInitContinuousCapture(self->ob_svideo, &info))
    648                 return sv_error();
    649 
    650         self->ob_info = info;
    651 
    652         return Py_BuildValue("(iiiii)", info.format, info.width, info.height,
    653                              info.size, info.samplingrate);
     640    svCaptureInfo info;
     641
     642    if (!PyArg_Parse(args, "(iiiii)", &info.format,
     643                    &info.width, &info.height,
     644                    &info.size, &info.samplingrate))
     645        return NULL;
     646
     647    if (svInitContinuousCapture(self->ob_svideo, &info))
     648        return sv_error();
     649
     650    self->ob_info = info;
     651
     652    return Py_BuildValue("(iiiii)", info.format, info.width, info.height,
     653                         info.size, info.samplingrate);
    654654}
    655655
     
    657657sv_LoadMap(svobject *self, PyObject *args)
    658658{
    659         PyObject *rgb;
    660         PyObject *res = NULL;
    661         rgb_tuple *mapp = NULL;
    662         int maptype;
    663         int i, j;                            /* indices */
    664 
    665         if (!PyArg_Parse(args, "(iO)", &maptype, &rgb))
    666                 return NULL;
    667 
    668         if (!PyList_Check(rgb) || PyList_Size(rgb) != 256) {
    669                 PyErr_BadArgument();
    670                 return NULL;
    671         }
    672 
    673         if (!(mapp = PyMem_NEW(rgb_tuple, 256)))
    674                 return PyErr_NoMemory();
    675 
    676         for (i = 0; i < 256; i++) {
    677                 PyObject* v = PyList_GetItem(rgb, i);
    678                 if (!v)
    679                         goto finally;
    680 
    681                 if (!PyTuple_Check(v) || PyTuple_Size(v) != 3) {
    682                         PyErr_BadArgument();
    683                         goto finally;
    684                 }
    685                 for (j = 0; j < 3; j++) {
    686                         PyObject* cell = PyTuple_GetItem(v, j);
    687                         if (!cell)
    688                                 goto finally;
    689 
    690                         if (!PyInt_Check(cell)) {
    691                                 PyErr_BadArgument();
    692                                 goto finally;
    693                         }
    694                         switch (j) {
    695                         case 0: mapp[i].red = PyInt_AsLong(cell); break;
    696                         case 1: mapp[i].blue = PyInt_AsLong(cell); break;
    697                         case 2: mapp[i].green = PyInt_AsLong(cell); break;
    698                         }
    699                         if (PyErr_Occurred())
    700                                 goto finally;
    701                 }
    702         }
    703 
    704         if (svLoadMap(self->ob_svideo, maptype, mapp)) {
    705                 res = sv_error();
    706                 goto finally;
    707         }
    708 
    709         Py_INCREF(Py_None);
    710         res = Py_None;
     659    PyObject *rgb;
     660    PyObject *res = NULL;
     661    rgb_tuple *mapp = NULL;
     662    int maptype;
     663    int i, j;                                /* indices */
     664
     665    if (!PyArg_Parse(args, "(iO)", &maptype, &rgb))
     666        return NULL;
     667
     668    if (!PyList_Check(rgb) || PyList_Size(rgb) != 256) {
     669        PyErr_BadArgument();
     670        return NULL;
     671    }
     672
     673    if (!(mapp = PyMem_NEW(rgb_tuple, 256)))
     674        return PyErr_NoMemory();
     675
     676    for (i = 0; i < 256; i++) {
     677        PyObject* v = PyList_GetItem(rgb, i);
     678        if (!v)
     679            goto finally;
     680
     681        if (!PyTuple_Check(v) || PyTuple_Size(v) != 3) {
     682            PyErr_BadArgument();
     683            goto finally;
     684        }
     685        for (j = 0; j < 3; j++) {
     686            PyObject* cell = PyTuple_GetItem(v, j);
     687            if (!cell)
     688                goto finally;
     689
     690            if (!PyInt_Check(cell)) {
     691                PyErr_BadArgument();
     692                goto finally;
     693            }
     694            switch (j) {
     695            case 0: mapp[i].red = PyInt_AsLong(cell); break;
     696            case 1: mapp[i].blue = PyInt_AsLong(cell); break;
     697            case 2: mapp[i].green = PyInt_AsLong(cell); break;
     698            }
     699            if (PyErr_Occurred())
     700                goto finally;
     701        }
     702    }
     703
     704    if (svLoadMap(self->ob_svideo, maptype, mapp)) {
     705        res = sv_error();
     706        goto finally;
     707    }
     708
     709    Py_INCREF(Py_None);
     710    res = Py_None;
    711711
    712712  finally:
    713         PyMem_DEL(mapp);
    714         return res;
    715 }
    716                
     713    PyMem_DEL(mapp);
     714    return res;
     715}
     716
    717717static PyObject *
    718718sv_CloseVideo(svobject *self, PyObject *args)
    719719{
    720         if (!PyArg_Parse(args, ""))
    721                 return NULL;
    722 
    723         if (svCloseVideo(self->ob_svideo))
    724                 return sv_error();
    725 
    726         self->ob_svideo = NULL;
    727         Py_INCREF(Py_None);
    728         return Py_None;
     720    if (!PyArg_Parse(args, ""))
     721        return NULL;
     722
     723    if (svCloseVideo(self->ob_svideo))
     724        return sv_error();
     725
     726    self->ob_svideo = NULL;
     727    Py_INCREF(Py_None);
     728    return Py_None;
    729729}
    730730
     
    733733         int (*func)(SV_nodeP, long *, int), int modified)
    734734{
    735         PyObject *list;
    736         PyObject *res = NULL;
    737         long *PVbuffer = NULL;
    738         long length;
    739         int i;
    740        
    741         if (!PyArg_Parse(args, "O", &list))
    742                 return NULL;
    743 
    744         if (!PyList_Check(list)) {
    745                 PyErr_BadArgument();
    746                 return NULL;
    747         }
    748 
    749         if ((length = PyList_Size(list)) < 0)
    750                 return NULL;
    751 
    752         PVbuffer = PyMem_NEW(long, length);
    753         if (PVbuffer == NULL)
    754                 return PyErr_NoMemory();
    755 
    756         for (i = 0; i < length; i++) {
    757                 PyObject *v = PyList_GetItem(list, i);
    758                 if (!v)
    759                         goto finally;
    760 
    761                 if (!PyInt_Check(v)) {
    762                         PyErr_BadArgument();
    763                         goto finally;
    764                 }
    765                 PVbuffer[i] = PyInt_AsLong(v);
    766                 /* can't just test the return value, because what if the
    767                    value was -1?!
    768                 */
    769                 if (PVbuffer[i] == -1 && PyErr_Occurred())
    770                         goto finally;
    771         }
    772 
    773         if ((*func)(self->ob_svideo, PVbuffer, length)) {
    774                 res = sv_error();
    775                 goto finally;
    776         }
    777 
    778         if (modified) {
    779                 for (i = 0; i < length; i++) {
    780                         PyObject* v = PyInt_FromLong(PVbuffer[i]);
    781                         if (!v || PyList_SetItem(list, i, v) < 0)
    782                                 goto finally;
    783                 }
    784         }
    785 
    786         Py_INCREF(Py_None);
    787         res = Py_None;
     735    PyObject *list;
     736    PyObject *res = NULL;
     737    long *PVbuffer = NULL;
     738    long length;
     739    int i;
     740
     741    if (!PyArg_Parse(args, "O", &list))
     742        return NULL;
     743
     744    if (!PyList_Check(list)) {
     745        PyErr_BadArgument();
     746        return NULL;
     747    }
     748
     749    if ((length = PyList_Size(list)) < 0)
     750        return NULL;
     751
     752    PVbuffer = PyMem_NEW(long, length);
     753    if (PVbuffer == NULL)
     754        return PyErr_NoMemory();
     755
     756    for (i = 0; i < length; i++) {
     757        PyObject *v = PyList_GetItem(list, i);
     758        if (!v)
     759            goto finally;
     760
     761        if (!PyInt_Check(v)) {
     762            PyErr_BadArgument();
     763            goto finally;
     764        }
     765        PVbuffer[i] = PyInt_AsLong(v);
     766        /* can't just test the return value, because what if the
     767           value was -1?!
     768        */
     769        if (PVbuffer[i] == -1 && PyErr_Occurred())
     770            goto finally;
     771    }
     772
     773    if ((*func)(self->ob_svideo, PVbuffer, length)) {
     774        res = sv_error();
     775        goto finally;
     776    }
     777
     778    if (modified) {
     779        for (i = 0; i < length; i++) {
     780            PyObject* v = PyInt_FromLong(PVbuffer[i]);
     781            if (!v || PyList_SetItem(list, i, v) < 0)
     782                goto finally;
     783        }
     784    }
     785
     786    Py_INCREF(Py_None);
     787    res = Py_None;
    788788
    789789  finally:
    790         PyMem_DEL(PVbuffer);
    791         return res;
     790    PyMem_DEL(PVbuffer);
     791    return res;
    792792}
    793793
     
    795795sv_GetParam(PyObject *self, PyObject *args)
    796796{
    797         return doParams(self, args, svGetParam, 1);
     797    return doParams(self, args, svGetParam, 1);
    798798}
    799799
     
    801801sv_GetParamRange(PyObject *self, PyObject *args)
    802802{
    803         return doParams(self, args, svGetParamRange, 1);
     803    return doParams(self, args, svGetParamRange, 1);
    804804}
    805805
     
    807807sv_SetParam(PyObject *self, PyObject *args)
    808808{
    809         return doParams(self, args, svSetParam, 0);
     809    return doParams(self, args, svSetParam, 0);
    810810}
    811811
    812812static PyMethodDef svideo_methods[] = {
    813         {"BindGLWindow",        (PyCFunction)sv_BindGLWindow, METH_OLDARGS},
    814         {"EndContinuousCapture",(PyCFunction)sv_EndContinuousCapture, METH_OLDARGS},
    815         {"IsVideoDisplayed",    (PyCFunction)sv_IsVideoDisplayed, METH_OLDARGS},
    816         {"OutputOffset",        (PyCFunction)sv_OutputOffset, METH_OLDARGS},
    817         {"PutFrame",            (PyCFunction)sv_PutFrame, METH_OLDARGS},
    818         {"QuerySize",           (PyCFunction)sv_QuerySize, METH_OLDARGS},
    819         {"SetSize",             (PyCFunction)sv_SetSize, METH_OLDARGS},
    820         {"SetStdDefaults",      (PyCFunction)sv_SetStdDefaults, METH_OLDARGS},
    821         {"UseExclusive",        (PyCFunction)sv_UseExclusive, METH_OLDARGS},
    822         {"WindowOffset",        (PyCFunction)sv_WindowOffset, METH_OLDARGS},
    823         {"InitContinuousCapture",(PyCFunction)sv_InitContinuousCapture, METH_OLDARGS},
    824         {"CaptureBurst",        (PyCFunction)sv_CaptureBurst, METH_OLDARGS},
    825         {"CaptureOneFrame",     (PyCFunction)sv_CaptureOneFrame, METH_OLDARGS},
    826         {"GetCaptureData",      (PyCFunction)sv_GetCaptureData, METH_OLDARGS},
    827         {"CloseVideo",          (PyCFunction)sv_CloseVideo, METH_OLDARGS},
    828         {"LoadMap",             (PyCFunction)sv_LoadMap, METH_OLDARGS},
    829         {"GetParam",            (PyCFunction)sv_GetParam, METH_OLDARGS},
    830         {"GetParamRange",       (PyCFunction)sv_GetParamRange, METH_OLDARGS},
    831         {"SetParam",            (PyCFunction)sv_SetParam, METH_OLDARGS},
    832         {NULL,                  NULL}           /* sentinel */
     813    {"BindGLWindow",            (PyCFunction)sv_BindGLWindow, METH_OLDARGS},
     814    {"EndContinuousCapture",(PyCFunction)sv_EndContinuousCapture, METH_OLDARGS},
     815    {"IsVideoDisplayed",        (PyCFunction)sv_IsVideoDisplayed, METH_OLDARGS},
     816    {"OutputOffset",            (PyCFunction)sv_OutputOffset, METH_OLDARGS},
     817    {"PutFrame",                (PyCFunction)sv_PutFrame, METH_OLDARGS},
     818    {"QuerySize",               (PyCFunction)sv_QuerySize, METH_OLDARGS},
     819    {"SetSize",                 (PyCFunction)sv_SetSize, METH_OLDARGS},
     820    {"SetStdDefaults",          (PyCFunction)sv_SetStdDefaults, METH_OLDARGS},
     821    {"UseExclusive",            (PyCFunction)sv_UseExclusive, METH_OLDARGS},
     822    {"WindowOffset",            (PyCFunction)sv_WindowOffset, METH_OLDARGS},
     823    {"InitContinuousCapture",(PyCFunction)sv_InitContinuousCapture, METH_OLDARGS},
     824    {"CaptureBurst",            (PyCFunction)sv_CaptureBurst, METH_OLDARGS},
     825    {"CaptureOneFrame",         (PyCFunction)sv_CaptureOneFrame, METH_OLDARGS},
     826    {"GetCaptureData",          (PyCFunction)sv_GetCaptureData, METH_OLDARGS},
     827    {"CloseVideo",              (PyCFunction)sv_CloseVideo, METH_OLDARGS},
     828    {"LoadMap",                 (PyCFunction)sv_LoadMap, METH_OLDARGS},
     829    {"GetParam",                (PyCFunction)sv_GetParam, METH_OLDARGS},
     830    {"GetParamRange",           (PyCFunction)sv_GetParamRange, METH_OLDARGS},
     831    {"SetParam",                (PyCFunction)sv_SetParam, METH_OLDARGS},
     832    {NULL,                      NULL}           /* sentinel */
    833833};
    834834
     
    837837              int inputfactor, float factor)
    838838{
    839         int invert, width, height, inputlength;
    840         char *input, *str;
    841         PyObject *output;
    842 
    843         if (!PyArg_Parse(args, "(is#ii)", &invert,
    844                         &input, &inputlength, &width, &height))
    845                 return NULL;
    846 
    847         if (width * height * inputfactor > inputlength) {
    848                 PyErr_SetString(SvError, "input buffer not long enough");
    849                 return NULL;
    850         }
    851 
    852         if (!(output = PyString_FromStringAndSize(NULL,
    853                                               (int)(width * height * factor))))
    854                 return NULL;
    855 
    856         str = PyString_AsString(output);
    857         if (!str) {
    858                 Py_DECREF(output);
    859                 return NULL;
    860         }
    861         (*function)(invert, input, str, width, height);
    862 
    863         return output;
     839    int invert, width, height, inputlength;
     840    char *input, *str;
     841    PyObject *output;
     842
     843    if (!PyArg_Parse(args, "(is#ii)", &invert,
     844                    &input, &inputlength, &width, &height))
     845        return NULL;
     846
     847    if (width * height * inputfactor > inputlength) {
     848        PyErr_SetString(SvError, "input buffer not long enough");
     849        return NULL;
     850    }
     851
     852    if (!(output = PyString_FromStringAndSize(NULL,
     853                                          (int)(width * height * factor))))
     854        return NULL;
     855
     856    str = PyString_AsString(output);
     857    if (!str) {
     858        Py_DECREF(output);
     859        return NULL;
     860    }
     861    (*function)(invert, input, str, width, height);
     862
     863    return output;
    864864}
    865865
     
    867867sv_InterleaveFields(PyObject *self, PyObject *args)
    868868{
    869         return sv_conversion(self, args, svInterleaveFields, 1, 1.0);
     869    return sv_conversion(self, args, svInterleaveFields, 1, 1.0);
    870870}
    871871
     
    873873sv_RGB8toRGB32(PyObject *self, PyObject *args)
    874874{
    875         return sv_conversion(self, args, svRGB8toRGB32, 1, (float) sizeof(long));
     875    return sv_conversion(self, args, svRGB8toRGB32, 1, (float) sizeof(long));
    876876}
    877877
     
    879879sv_YUVtoRGB(PyObject *self, PyObject *args)
    880880{
    881         return sv_conversion(self, args, svYUVtoRGB, 2, (float) sizeof(long));
     881    return sv_conversion(self, args, svYUVtoRGB, 2, (float) sizeof(long));
    882882}
    883883
     
    885885svideo_dealloc(svobject *self)
    886886{
    887         if (self->ob_svideo != NULL)
    888                 (void) svCloseVideo(self->ob_svideo);
    889         PyObject_Del(self);
     887    if (self->ob_svideo != NULL)
     888        (void) svCloseVideo(self->ob_svideo);
     889    PyObject_Del(self);
    890890}
    891891
     
    893893svideo_getattr(svobject *self, char *name)
    894894{
    895         return Py_FindMethod(svideo_methods, (PyObject *)self, name);
     895    return Py_FindMethod(svideo_methods, (PyObject *)self, name);
    896896}
    897897
    898898PyTypeObject Svtype = {
    899         PyObject_HEAD_INIT(&PyType_Type)
    900         0,                      /*ob_size*/
    901         "sv.sv",                /*tp_name*/
    902         sizeof(svobject),       /*tp_size*/
    903         0,                      /*tp_itemsize*/
    904         /* methods */
    905         (destructor)svideo_dealloc, /*tp_dealloc*/
    906         0,                      /*tp_print*/
    907         (getattrfunc)svideo_getattr, /*tp_getattr*/
    908         0,                      /*tp_setattr*/
    909         0,                      /*tp_compare*/
    910         0,                      /*tp_repr*/
     899    PyObject_HEAD_INIT(&PyType_Type)
     900    0,                          /*ob_size*/
     901    "sv.sv",                    /*tp_name*/
     902    sizeof(svobject),           /*tp_size*/
     903    0,                          /*tp_itemsize*/
     904    /* methods */
     905    (destructor)svideo_dealloc, /*tp_dealloc*/
     906    0,                          /*tp_print*/
     907    (getattrfunc)svideo_getattr, /*tp_getattr*/
     908    0,                          /*tp_setattr*/
     909    0,                          /*tp_compare*/
     910    0,                          /*tp_repr*/
    911911};
    912912
     
    914914newsvobject(SV_nodeP svp)
    915915{
    916         svobject *p;
    917 
    918         p = PyObject_New(svobject, &Svtype);
    919         if (p == NULL)
    920                 return NULL;
    921         p->ob_svideo = svp;
    922         p->ob_info.format = 0;
    923         p->ob_info.size = 0;
    924         p->ob_info.width = 0;
    925         p->ob_info.height = 0;
    926         p->ob_info.samplingrate = 0;
    927         return (PyObject *) p;
     916    svobject *p;
     917
     918    p = PyObject_New(svobject, &Svtype);
     919    if (p == NULL)
     920        return NULL;
     921    p->ob_svideo = svp;
     922    p->ob_info.format = 0;
     923    p->ob_info.size = 0;
     924    p->ob_info.width = 0;
     925    p->ob_info.height = 0;
     926    p->ob_info.samplingrate = 0;
     927    return (PyObject *) p;
    928928}
    929929
     
    931931sv_OpenVideo(PyObject *self, PyObject *args)
    932932{
    933         SV_nodeP svp;
    934 
    935         if (!PyArg_Parse(args, ""))
    936                 return NULL;
    937 
    938         svp = svOpenVideo();
    939         if (svp == NULL)
    940                 return sv_error();
    941 
    942         return newsvobject(svp);
     933    SV_nodeP svp;
     934
     935    if (!PyArg_Parse(args, ""))
     936        return NULL;
     937
     938    svp = svOpenVideo();
     939    if (svp == NULL)
     940        return sv_error();
     941
     942    return newsvobject(svp);
    943943}
    944944
    945945static PyMethodDef sv_methods[] = {
    946         {"InterleaveFields",    (PyCFunction)sv_InterleaveFields, METH_OLDARGS},
    947         {"RGB8toRGB32",         (PyCFunction)sv_RGB8toRGB32, METH_OLDARGS},
    948         {"YUVtoRGB",            (PyCFunction)sv_YUVtoRGB, METH_OLDARGS},
    949         {"OpenVideo",           (PyCFunction)sv_OpenVideo, METH_OLDARGS},
    950         {NULL,                  NULL}   /* Sentinel */
     946    {"InterleaveFields",        (PyCFunction)sv_InterleaveFields, METH_OLDARGS},
     947    {"RGB8toRGB32",             (PyCFunction)sv_RGB8toRGB32, METH_OLDARGS},
     948    {"YUVtoRGB",                (PyCFunction)sv_YUVtoRGB, METH_OLDARGS},
     949    {"OpenVideo",               (PyCFunction)sv_OpenVideo, METH_OLDARGS},
     950    {NULL,                      NULL}   /* Sentinel */
    951951};
    952952
     
    954954initsv(void)
    955955{
    956         PyObject *m, *d;
    957        
    958         if (PyErr_WarnPy3k("the sv module has been removed in "
    959                            "Python 3.0", 2) < 0)
    960             return;
    961 
    962         m = Py_InitModule("sv", sv_methods);
    963         if (m == NULL)
    964                 return;
    965         d = PyModule_GetDict(m);
    966 
    967         SvError = PyErr_NewException("sv.error", NULL, NULL);
    968         if (SvError == NULL || PyDict_SetItemString(d, "error", SvError) != 0)
    969                 return;
    970 }
     956    PyObject *m, *d;
     957
     958    if (PyErr_WarnPy3k("the sv module has been removed in "
     959                       "Python 3.0", 2) < 0)
     960        return;
     961
     962    m = Py_InitModule("sv", sv_methods);
     963    if (m == NULL)
     964        return;
     965    d = PyModule_GetDict(m);
     966
     967    SvError = PyErr_NewException("sv.error", NULL, NULL);
     968    if (SvError == NULL || PyDict_SetItemString(d, "error", SvError) != 0)
     969        return;
     970}
Note: See TracChangeset for help on using the changeset viewer.