Exemplo n.º 1
0
static int
processor_set_request_size (zbarProcessor *self,
                            PyObject *value,
                            void *closure)
{
    if(!value) {
        zbar_processor_request_size(self->zproc, 0, 0);
        return(0);
    }

    int dims[2];
    if(parse_dimensions(value, dims, 2) ||
       dims[0] < 0 || dims[1] < 0) {
        PyErr_SetString(PyExc_ValueError,
                        "request_size must be a sequence of two positive ints");
        return(-1);
    }

    zbar_processor_request_size(self->zproc, dims[0], dims[1]);
    return(0);
}
Exemplo n.º 2
0
/* wenop-add 
 *
 *    make python possible to set prescale as what can be done by --prescale 
 *
 */
static PyObject*
set_prescale (zbarProcessor *self,
                        PyObject *args,
                        PyObject *kwds)
{
    long int ps_width = 320;
    long int ps_height = 240;
    static char *kwlist[] = { "width", "height", NULL };
    if(!PyArg_ParseTupleAndKeywords(args, kwds, "ll", kwlist, 
                                    &ps_width, &ps_height))
        return(NULL);

    zbar_processor_request_size(self->zproc, ps_width, ps_height);
    /*
    if(zbar_processor_request_size(self->zproc, ps_width, ps_height)) {
        PyErr_SetString(PyExc_ValueError, "invalid prescale setting");        
        return(NULL);
    }
    */
    Py_RETURN_NONE;
}
Exemplo n.º 3
0
int main (int argc, const char *argv[])
{
    /* setup zbar library standalone processor,
     * threads will be used if available
     */
    proc = zbar_processor_create(1);
    if(!proc) {
        fprintf(stderr, "ERROR: unable to allocate memory?\n");
        return(1);
    }
    zbar_processor_set_data_handler(proc, data_handler, NULL);

    const char *video_device = "";
    int display = 1;
    unsigned long infmt = 0, outfmt = 0;
    int i;
    for(i = 1; i < argc; i++) {
        if(argv[i][0] != '-')
            video_device = argv[i];
        else if(argv[i][1] != '-') {
            int j;
            for(j = 1; argv[i][j]; j++) {
                if(argv[i][j] == 'S') {
                    if(!argv[i][++j]) {
                        i++;
                        j = 0;
                    }
                    if(parse_config(&argv[i][j], i, argc, "-S"))
                        return(usage(1));
                    break;
                }
                switch(argv[i][j]) {
                case 'h': return(usage(0));
                case 'v': zbar_increase_verbosity(); break;
                case 'q': quiet = 1; break;
                default:
                    fprintf(stderr, "ERROR: unknown bundled config: -%c\n\n",
                            argv[i][j]);
                    return(usage(1));
                }
            }
        }
        else if(!argv[i][2]) {
            if(i < argc - 1)
                video_device = argv[argc - 1];
            break;
        }
        else if(!strcmp(argv[i], "--help"))
            return(usage(0));
        else if(!strcmp(argv[i], "--version"))
            return(printf(PACKAGE_VERSION "\n") <= 0);
        else if(!strcmp(argv[i], "--set")) {
            i++;
            if(parse_config(argv[i], i, argc, "--set"))
                return(usage(1));
        }
        else if(!strncmp(argv[i], "--set=", 6)) {
            if(parse_config(&argv[i][6], i, argc, "--set="))
                return(usage(1));
        }
        else if(!strcmp(argv[i], "--quiet"))
            quiet = 1;
        else if(!strcmp(argv[i], "--xml"))
            format = XML;
        else if(!strcmp(argv[i], "--raw"))
            format = RAW;
        else if(!strcmp(argv[i], "--nodisplay"))
            display = 0;
        else if(!strcmp(argv[i], "--verbose"))
            zbar_increase_verbosity();
        else if(!strncmp(argv[i], "--verbose=", 10))
            zbar_set_verbosity(strtol(argv[i] + 10, NULL, 0));
        else if(!strncmp(argv[i], "--prescale=", 11)) {
            char *x = NULL;
            long int w = strtol(argv[i] + 11, &x, 10);
            long int h = 0;
            if(x && *x == 'x')
                h = strtol(x + 1, NULL, 10);
            if(!w || !h || !x || *x != 'x') {
                fprintf(stderr, "ERROR: invalid prescale: %s\n\n", argv[i]);
                return(usage(1));
            }
            zbar_processor_request_size(proc, w, h);
        }
        else if(!strncmp(argv[i], "--v4l=", 6)) {
            long int v = strtol(argv[i] + 6, NULL, 0);
            zbar_processor_request_interface(proc, v);
        }
        else if(!strncmp(argv[i], "--iomode=", 9)) {
            long int v = strtol(argv[i] + 9, NULL, 0);
            zbar_processor_request_iomode(proc, v);
        }
        else if(!strncmp(argv[i], "--infmt=", 8) &&
                strlen(argv[i]) == 12)
            infmt = (argv[i][8] | (argv[i][9] << 8) |
                     (argv[i][10] << 16) | (argv[i][11] << 24));
        else if(!strncmp(argv[i], "--outfmt=", 9) &&
                strlen(argv[i]) == 13)
            outfmt = (argv[i][9] | (argv[i][10] << 8) |
                      (argv[i][11] << 16) | (argv[i][12] << 24));
        else {
            fprintf(stderr, "ERROR: unknown option argument: %s\n\n",
                    argv[i]);
            return(usage(1));
        }
    }

    if(infmt || outfmt)
        zbar_processor_force_format(proc, infmt, outfmt);

    /* open video device, open window */
    if(zbar_processor_init(proc, video_device, display) ||
       /* show window */
       (display && zbar_processor_set_visible(proc, 1)))
        return(zbar_processor_error_spew(proc, 0));

    if(format == XML) {
#ifdef _WIN32
        fflush(stdout);
        _setmode(_fileno(stdout), _O_BINARY);
#endif
        printf(xml_head, video_device);
        fflush(stdout);
    }

    /* start video */
    int active = 1;
    if(zbar_processor_set_active(proc, active))
        return(zbar_processor_error_spew(proc, 0));

    /* let the callback handle data */
    int rc;
    while((rc = zbar_processor_user_wait(proc, -1)) >= 0) {
        if(rc == 'q' || rc == 'Q')
            break;
        if(rc == ' ') {
            active = !active;
            if(zbar_processor_set_active(proc, active))
                return(zbar_processor_error_spew(proc, 0));
        }
    }

    /* report any errors that aren't "window closed" */
    if(rc && rc != 'q' && rc != 'Q' &&
       zbar_processor_get_error_code(proc) != ZBAR_ERR_CLOSED)
        return(zbar_processor_error_spew(proc, 0));

    /* free resources (leak check) */
    zbar_processor_destroy(proc);

    if(format == XML) {
        printf("%s", xml_foot);
        fflush(stdout);
    }
    return(0);
}