Ejemplo n.º 1
0
zbar_image_scanner_t *zbar_image_scanner_create ()
{
    zbar_image_scanner_t *iscn = calloc(1, sizeof(zbar_image_scanner_t));
    if(!iscn)
        return(NULL);
    iscn->dcode = zbar_decoder_create();
    iscn->scn = zbar_scanner_create(iscn->dcode);
    if(!iscn->dcode || !iscn->scn) {
        zbar_image_scanner_destroy(iscn);
        return(NULL);
    }
    zbar_decoder_set_userdata(iscn->dcode, iscn);
    zbar_decoder_set_handler(iscn->dcode, symbol_handler);

#ifdef ENABLE_QRCODE
    iscn->qr = _zbar_qr_create();
#endif

    /* apply default configuration */
    CFG(iscn, ZBAR_CFG_X_DENSITY) = 1;
    CFG(iscn, ZBAR_CFG_Y_DENSITY) = 1;
    zbar_image_scanner_set_config(iscn, 0, ZBAR_CFG_POSITION, 1);
    zbar_image_scanner_set_config(iscn, 0, ZBAR_CFG_UNCERTAINTY, 2);
    zbar_image_scanner_set_config(iscn, ZBAR_QRCODE, ZBAR_CFG_UNCERTAINTY, 0);
    zbar_image_scanner_set_config(iscn, ZBAR_CODE128, ZBAR_CFG_UNCERTAINTY, 0);
    zbar_image_scanner_set_config(iscn, ZBAR_CODE93, ZBAR_CFG_UNCERTAINTY, 0);
    zbar_image_scanner_set_config(iscn, ZBAR_CODE39, ZBAR_CFG_UNCERTAINTY, 0);
    zbar_image_scanner_set_config(iscn, ZBAR_CODABAR, ZBAR_CFG_UNCERTAINTY, 1);
    zbar_image_scanner_set_config(iscn, ZBAR_COMPOSITE, ZBAR_CFG_UNCERTAINTY, 0);
    return(iscn);
}
Ejemplo n.º 2
0
static int
decoder_clear (zbarDecoder *self)
{
    zbar_decoder_set_handler(self->zdcode, NULL);
    zbar_decoder_set_userdata(self->zdcode, NULL);
    Py_CLEAR(self->handler);
    Py_CLEAR(self->args);
    return(0);
}
Ejemplo n.º 3
0
static PyObject*
decoder_set_handler (zbarDecoder *self,
                     PyObject *args,
                     PyObject *kwds)
{
    PyObject *handler = Py_None;
    PyObject *closure = Py_None;

    static char *kwlist[] = { "handler", "closure", NULL };
    if(!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist,
                                    &handler, &closure))
        return(NULL);

    if(handler != Py_None && !PyCallable_Check(handler)) {
        PyErr_Format(PyExc_ValueError, "handler %.50s is not callable",
                     handler->ob_type->tp_name);
        return(NULL);
    }
    Py_CLEAR(self->handler);
    Py_CLEAR(self->args);

    if(handler != Py_None) {
        self->args = PyTuple_New(2);
        if(!self->args)
            return(NULL);
        Py_INCREF(self);
        Py_INCREF(closure);
        PyTuple_SET_ITEM(self->args, 0, (PyObject*)self);
        PyTuple_SET_ITEM(self->args, 1, closure);

        Py_INCREF(handler);
        self->handler = handler;

        zbar_decoder_set_handler(self->zdcode, decode_handler);
    }
    else {
        self->handler = self->args = NULL;
        zbar_decoder_set_handler(self->zdcode, NULL);
    }
    Py_RETURN_NONE;
}