Exemplo n.º 1
0
JNIEXPORT jint JNICALL
Java_net_sourceforge_zbar_Symbol_getLocationSize (JNIEnv *env,
                                                  jobject obj,
                                                  jlong peer)
{
    return(zbar_symbol_get_loc_size(PEER_CAST(peer)));
}
Exemplo n.º 2
0
static PyObject*
symbol_get_location (zbarSymbol *self,
                     void *closure)
{
    if(!self->loc) {
        /* build tuple of 2-tuples representing location polygon */
        unsigned int n = zbar_symbol_get_loc_size(self->zsym);
        self->loc = PyTuple_New(n);
        unsigned int i;
        for(i = 0; i < n; i++) {
            PyObject *x, *y;
            x = PyInt_FromLong(zbar_symbol_get_loc_x(self->zsym, i));
            y = PyInt_FromLong(zbar_symbol_get_loc_y(self->zsym, i));
            PyTuple_SET_ITEM(self->loc, i, PyTuple_Pack(2, x, y));
        }
    }
    Py_INCREF(self->loc);
    return(self->loc);
}
Exemplo n.º 3
0
int c_zbar(IMG(x), int*m, TBarcode* result) {
    
    //printf("hello\n");
    /* create a reader */
    zbar_image_scanner_t * scanner = zbar_image_scanner_create();

    /* configure the reader */
    zbar_image_scanner_set_config(scanner, 0, ZBAR_CFG_ENABLE, 1);

    /* obtain image data */
    int width = xsc2+1, height = xsr2+1;
    if (xsc1!=0 || xsr1!=0 || xsstep != width) {
        printf("c1=%d c2=%d r1=%d r2=%d step=%d\n",xsc1,xsc2,xsr1,xsr2,xsstep);
        return 1;
    }

    void *raw = xpSrc;
    //get_data(argv[1], &width, &height, &raw);

    /* wrap image data */
    zbar_image_t *image = zbar_image_create();
    zbar_image_set_format(image, *(int*)"Y800");
    zbar_image_set_size(image, width, height);
    zbar_image_set_data(image, raw, width * height, NULL);
    
    //printf("after set\n");
    /* scan the image for barcodes */
    int n = zbar_scan_image(scanner, image);
    //printf("scan_image code: %d\n",n);
    /* extract results */
    int k = 0;
    const zbar_symbol_t *symbol = zbar_image_first_symbol(image);
    for(; symbol; symbol = zbar_symbol_next(symbol)) {
        /* do something useful with results */
        zbar_symbol_type_t typ = zbar_symbol_get_type(symbol);
        result[k].symbol_type = zbar_get_symbol_name(typ);
        const char *data = zbar_symbol_get_data(symbol);
        result[k].symbol_value = data;
        // printf("decoded %s symbol \"%s\"\n",zbar_get_symbol_name(typ), data);

        int np = zbar_symbol_get_loc_size(symbol);
        //printf("np=%d\n",np);
        int j,x,y,r1,c1,r2,c2;
        c1 = c2 = zbar_symbol_get_loc_x(symbol,0);
        r1 = r2 = zbar_symbol_get_loc_y(symbol,0);
        for (j=1; j<np; j++) {
            x = zbar_symbol_get_loc_x(symbol,j);
            y = zbar_symbol_get_loc_y(symbol,j);
            if (y<r1) r1 = y;
            if (y>r2) r2 = y;
            if (x<c1) c1 = x;
            if (x>c2) c2 = x;
            //printf("j=%d\n",j);
        }
        result[k].bbr1 = r1;
        result[k].bbr2 = r2;
        result[k].bbc1 = c1;
        result[k].bbc2 = c2;
        k++;
        if(k>=50) break;
    }

    /* clean up */
    zbar_image_destroy(image);

    *m = k;
    
    return n;
}
Exemplo n.º 4
0
/* API lock is already held */
int _zbar_process_image (zbar_processor_t *proc,
                         zbar_image_t *img)
{
    uint32_t force_fmt = proc->force_output;
    int nsyms, rc;
    if(img) {
        zbar_image_t *tmp;
        uint32_t format = zbar_image_get_format(img);
        zprintf(16, "processing: %.4s(%08lx) %dx%d @%p\n",
                (char*)&format, format,
                zbar_image_get_width(img), zbar_image_get_height(img),
                zbar_image_get_data(img));

        /* FIXME locking all other interfaces while processing is conservative
         * but easier for now and we don't expect this to take long...
         */
        tmp = zbar_image_convert(img, fourcc('Y','8','0','0'));
        if(!tmp)
            goto error;

        if(proc->syms) {
            zbar_symbol_set_ref(proc->syms, -1);
            proc->syms = NULL;
        }
        zbar_image_scanner_recycle_image(proc->scanner, img);
        nsyms = zbar_scan_image(proc->scanner, tmp);
        _zbar_image_swap_symbols(img, tmp);

        zbar_image_destroy(tmp);
        tmp = NULL;
        if(nsyms < 0)
            goto error;

        proc->syms = zbar_image_scanner_get_results(proc->scanner);
        if(proc->syms)
            zbar_symbol_set_ref(proc->syms, 1);

        if(_zbar_verbosity >= 8) {
            const zbar_symbol_t *sym = zbar_image_first_symbol(img);
            while(sym) {
                zbar_symbol_type_t type = zbar_symbol_get_type(sym);
                int count = zbar_symbol_get_count(sym);
                zprintf(8, "%s%s: %s (%d pts) (q=%d) (%s)\n",
                        zbar_get_symbol_name(type),
                        zbar_get_addon_name(type),
                        zbar_symbol_get_data(sym),
                        zbar_symbol_get_loc_size(sym),
                        zbar_symbol_get_quality(sym),
                        (count < 0) ? "uncertain" :
                        (count > 0) ? "duplicate" : "new");
                sym = zbar_symbol_next(sym);
            }
        }

        if(nsyms) {
            /* FIXME only call after filtering */
            _zbar_mutex_lock(&proc->mutex);
            _zbar_processor_notify(proc, EVENT_OUTPUT);
            _zbar_mutex_unlock(&proc->mutex);
            if(proc->handler)
                proc->handler(img, proc->userdata);
        }

        if(force_fmt) {
            zbar_symbol_set_t *syms = img->syms;
            img = zbar_image_convert(img, force_fmt);
            if(!img)
                goto error;
            img->syms = syms;
            zbar_symbol_set_ref(syms, 1);
        }
    }

    /* display to window if enabled */
    rc = 0;
    
    if(force_fmt && img)
        zbar_image_destroy(img);
    return(rc);

error:
    return(err_capture(proc, SEV_ERROR, ZBAR_ERR_UNSUPPORTED,
                       __func__, "unknown image format"));
}