Esempio n. 1
0
inline void zbar_image_scanner_recycle_image (zbar_image_scanner_t *iscn,
											  zbar_image_t *img)
{
	zbar_symbol_set_t *syms = iscn->syms;
	if(syms && syms->refcnt) {
		if(recycle_syms(iscn, syms)) {
			STAT(iscn_syms_inuse);
			iscn->syms = NULL;
		}
		else
			STAT(iscn_syms_recycle);
	}

	syms = img->syms;
	img->syms = NULL;
	if(syms && recycle_syms(iscn, syms)) {
		STAT(img_syms_inuse);
		syms = iscn->syms;
	}
	else if(syms) {
		STAT(img_syms_recycle);

		/* select one set to resurrect, destroy the other */
		if(iscn->syms) {
			_zbar_symbol_set_free(syms);
			syms = iscn->syms;
		}
		else
			iscn->syms = syms;
	}
}
Esempio n. 2
0
int zebra_scan_image (zebra_image_scanner_t *iscn,
                      zebra_image_t *img)
{
    recycle_syms(iscn, img);

    /* get grayscale image, convert if necessary */
    /*img = zebra_image_convert(img, fourcc('Y','8','0','0'));*/
    if(!img)
        return(-1);

    unsigned w = zebra_image_get_width(img);
    unsigned h = zebra_image_get_height(img);
    const uint8_t *data = zebra_image_get_data(img);
    const uint8_t *p = data;
    int x = 0, y = 0;
#ifdef DEBUG_IMG_SCANNER
    movedelta(0, (h + 1) / 2);
#else
    movedelta(0, 8);
#endif

    if(zebra_scanner_new_scan(iscn->scn))
        symbol_handler(iscn, x, y);

    /* FIXME add density config api */
    /* FIXME less arbitrary lead-out default */
    int quiet = w / 32;
    if(quiet < 8)
        quiet = 8;

    while(y < h) {
        zprintf(32, "img_x+: %03x,%03x @%p\n", x, y, p);
        while(x < w) {
            ASSERT_POS;
            if(zebra_scan_y(iscn->scn, *p))
                symbol_handler(iscn, x, y);
            movedelta(1, 0);
        }
        quiet_border(iscn, quiet, x, y);

        movedelta(-1, 16);
        if(y >= h)
            break;

        zprintf(32, "img_x-: %03x,%03x @%p\n", x, y, p);
        while(x > 0) {
            ASSERT_POS;
            if(zebra_scan_y(iscn->scn, *p))
                symbol_handler(iscn, x, y);
            movedelta(-1, 0);
        }
        quiet_border(iscn, quiet, x, y);

        movedelta(1, 16);
#ifdef DEBUG_IMG_SCANNER
        break;
#endif
    }

#ifndef DEBUG_IMG_SCANNER
    x = y = 0;
    p = data;
    movedelta(8, 0);

    while(x < w) {
        zprintf(32, "img_y+: %03x,%03x @%p\n", x, y, p);
        while(y < h) {
            ASSERT_POS;
            if(zebra_scan_y(iscn->scn, *p))
                symbol_handler(iscn, x, y);
            movedelta(0, 1);
        }
        quiet_border(iscn, quiet, x, y);

        movedelta(16, -1);
        if(x >= w)
            break;

        zprintf(32, "img_y-: %03x,%03x @%p\n", x, y, p);
        while(y >= 0) {
            ASSERT_POS;
            if(zebra_scan_y(iscn->scn, *p))
                symbol_handler(iscn, x, y);
            movedelta(0, -1);
        }
        quiet_border(iscn, quiet, x, y);

        movedelta(16, 1);
    }
#endif

    /* flush scanner pipe */
    if(zebra_scanner_new_scan(iscn->scn))
        symbol_handler(iscn, x, y);

    /* release reference */
    zebra_image_destroy(img);
    return(iscn->img->nsyms);
}
Esempio n. 3
0
int zbar_scan_image (zbar_image_scanner_t *iscn,
                     zbar_image_t *img)
{
    recycle_syms(iscn, img);

    /* get grayscale image, convert if necessary */
    img = zbar_image_convert(img, fourcc('Y','8','0','0'));
    if(!img)
        return(-1);

    unsigned w = zbar_image_get_width(img);
    unsigned h = zbar_image_get_height(img);
    const uint8_t *data = zbar_image_get_data(img);

    /* FIXME less arbitrary lead-out default */
    int quiet = w / 32;
    if(quiet < 8)
        quiet = 8;

    int density = CFG(iscn, ZBAR_CFG_Y_DENSITY);
    if(density > 0) {
        const uint8_t *p = data;
        int x = 0, y = 0;

        int border = (((h - 1) % density) + 1) / 2;
        if(border > h / 2)
            border = h / 2;
        movedelta(0, border);

        if(zbar_scanner_new_scan(iscn->scn))
            symbol_handler(iscn, x, y);

        while(y < h) {
            zprintf(32, "img_x+: %03x,%03x @%p\n", x, y, p);
            while(x < w) {
                ASSERT_POS;
                if(zbar_scan_y(iscn->scn, *p))
                    symbol_handler(iscn, x, y);
                movedelta(1, 0);
            }
            quiet_border(iscn, quiet, x, y);

            movedelta(-1, density);
            if(y >= h)
                break;

            zprintf(32, "img_x-: %03x,%03x @%p\n", x, y, p);
            while(x > 0) {
                ASSERT_POS;
                if(zbar_scan_y(iscn->scn, *p))
                    symbol_handler(iscn, x, y);
                movedelta(-1, 0);
            }
            quiet_border(iscn, quiet, x, y);

            movedelta(1, density);
        }
    }

    density = CFG(iscn, ZBAR_CFG_X_DENSITY);
    if(density > 0) {
        const uint8_t *p = data;
        int x = 0, y = 0;

        int border = (((w - 1) % density) + 1) / 2;
        if(border > w / 2)
            border = w / 2;
        movedelta(border, 0);

        while(x < w) {
            zprintf(32, "img_y+: %03x,%03x @%p\n", x, y, p);
            while(y < h) {
                ASSERT_POS;
                if(zbar_scan_y(iscn->scn, *p))
                    symbol_handler(iscn, x, y);
                movedelta(0, 1);
            }
            quiet_border(iscn, quiet, x, y);

            movedelta(density, -1);
            if(x >= w)
                break;

            zprintf(32, "img_y-: %03x,%03x @%p\n", x, y, p);
            while(y >= 0) {
                ASSERT_POS;
                if(zbar_scan_y(iscn->scn, *p))
                    symbol_handler(iscn, x, y);
                movedelta(0, -1);
            }
            quiet_border(iscn, quiet, x, y);

            movedelta(density, 1);
        }
    }

    /* release reference to converted image */
    zbar_image_destroy(img);
    return(iscn->img->nsyms);
}