Ejemplo n.º 1
0
static void symbol_handler (zbar_decoder_t *dcode)
{
	zbar_image_scanner_t *iscn = zbar_decoder_get_userdata(dcode);
	zbar_symbol_type_t type = zbar_decoder_get_type(dcode);
	/* FIXME assert(type == ZBAR_PARTIAL) */
	/* FIXME debug flag to save/display all PARTIALs */
	if(type <= ZBAR_PARTIAL)
		return;

#ifdef ENABLE_QRCODE
	if(type == ZBAR_QRCODE) {
		qr_handler(iscn);
		return;
	}
#else
	assert(type != ZBAR_QRCODE);
#endif

	const char *data = zbar_decoder_get_data(dcode);
	unsigned datalen = zbar_decoder_get_data_length(dcode);

	int x = 0, y = 0;
	if(TEST_CFG(iscn, ZBAR_CFG_POSITION)) {
		/* tmp position fixup */
		int w = zbar_scanner_get_width(iscn->scn);
		int u = iscn->umin + iscn->du * zbar_scanner_get_edge(iscn->scn, w, 0);
		if(iscn->dx) {
			x = u;
			y = iscn->v;
		}
		else {
			x = iscn->v;
			y = u;
		}
	}

	/* FIXME need better symbol matching */
	zbar_symbol_t *sym;
	for(sym = iscn->syms->head; sym; sym = sym->next)
		if(sym->type == type &&
		   sym->datalen == datalen &&
		   !memcmp(sym->data, data, datalen)) {
			sym->quality++;
			if(TEST_CFG(iscn, ZBAR_CFG_POSITION))
				/* add new point to existing set */
				/* FIXME should be polygon */
				sym_add_point(sym, x, y);
			return;
		}

	sym = _zbar_image_scanner_alloc_sym(iscn, type, datalen + 1);
	/* FIXME grab decoder buffer */
	memcpy(sym->data, data, datalen + 1);

	/* initialize first point */
	if(TEST_CFG(iscn, ZBAR_CFG_POSITION))
		sym_add_point(sym, x, y);

	_zbar_image_scanner_add_sym(iscn, sym);
}
Ejemplo n.º 2
0
void
decode_handler (zbar_decoder_t *zdcode)
{
    assert(zdcode);
    zbarDecoder *self = zbar_decoder_get_userdata(zdcode);
    assert(self);
    assert(self->zdcode == zdcode);
    assert(self->handler);
    assert(self->args);
    PyObject *junk = PyObject_Call(self->handler, self->args, NULL);
    Py_XDECREF(junk);
}
Ejemplo n.º 3
0
static void symbol_handler (zbar_decoder_t *dcode)
{
    zbar_image_scanner_t *iscn = zbar_decoder_get_userdata(dcode);
    zbar_symbol_type_t type = zbar_decoder_get_type(dcode);
    int x = 0, y = 0, dir;
    const char *data;
    unsigned datalen;
    zbar_symbol_t *sym;

#ifdef ENABLE_QRCODE
    if(type == ZBAR_QRCODE) {
        qr_handler(iscn);
        return;
    }
#else
    assert(type != ZBAR_QRCODE);
#endif

    if(TEST_CFG(iscn, ZBAR_CFG_POSITION)) {
        /* tmp position fixup */
        int w = zbar_scanner_get_width(iscn->scn);
        int u = iscn->umin + iscn->du * zbar_scanner_get_edge(iscn->scn, w, 0);
        if(iscn->dx) {
            x = u;
            y = iscn->v;
        }
        else {
            x = iscn->v;
            y = u;
        }
    }

    /* FIXME debug flag to save/display all PARTIALs */
    if(type <= ZBAR_PARTIAL) {
        zprintf(256, "partial symbol @(%d,%d)\n", x, y);
        return;
    }

    data = zbar_decoder_get_data(dcode);
    datalen = zbar_decoder_get_data_length(dcode);

    /* FIXME need better symbol matching */
    for(sym = iscn->syms->head; sym; sym = sym->next)
        if(sym->type == type &&
           sym->datalen == datalen &&
           !memcmp(sym->data, data, datalen)) {
            sym->quality++;
            zprintf(224, "dup symbol @(%d,%d): dup %s: %.20s\n",
                    x, y, zbar_get_symbol_name(type), data);
            if(TEST_CFG(iscn, ZBAR_CFG_POSITION))
                /* add new point to existing set */
                /* FIXME should be polygon */
                sym_add_point(sym, x, y);
            return;
        }

    sym = _zbar_image_scanner_alloc_sym(iscn, type, datalen + 1);
    sym->configs = zbar_decoder_get_configs(dcode, type);
    sym->modifiers = zbar_decoder_get_modifiers(dcode);
    /* FIXME grab decoder buffer */
    memcpy(sym->data, data, datalen + 1);

    /* initialize first point */
    if(TEST_CFG(iscn, ZBAR_CFG_POSITION)) {
        zprintf(192, "new symbol @(%d,%d): %s: %.20s\n",
                x, y, zbar_get_symbol_name(type), data);
        sym_add_point(sym, x, y);
    }

    dir = zbar_decoder_get_direction(dcode);
    if(dir)
        sym->orient = (iscn->dy != 0) + ((iscn->du ^ dir) & 2);

    _zbar_image_scanner_add_sym(iscn, sym);
}