Logo Search packages:      
Sourcecode: zebra version File versions  Download package

int zebra_negotiate_format ( zebra_video_t video,
zebra_window_t window 
)

select a compatible format between video input and output window. the selection algorithm attempts to use a format shared by video input and window output which is also most useful for barcode scanning. if a format conversion is necessary, it will heuristically attempt to minimize the cost of the conversion

Definition at line 979 of file convert.c.

References ZEBRA_ERR_INTERNAL, ZEBRA_ERR_UNSUPPORTED, zebra_negotiate_format(), and zebra_video_init().

Referenced by zebra_negotiate_format(), zebra_processor_init(), and zebra_video_enable().

{
    if(!vdo && !win)
        return(0);

    if(win)
        (void)window_lock(win);

    errinfo_t *errdst = (vdo) ? &vdo->err : &win->err;
    if(verify_format_sort()) {
        if(win)
            (void)window_unlock(win);
        return(err_capture(errdst, SEV_FATAL, ZEBRA_ERR_INTERNAL, __func__,
                           "image format list is not sorted!?"));
    }

    if((vdo && !vdo->formats) || (win && !win->formats)) {
        if(win)
            (void)window_unlock(win);
        return(err_capture(errdst, SEV_ERROR, ZEBRA_ERR_UNSUPPORTED, __func__,
                           "no input or output formats available"));
    }

    static const uint32_t y800[2] = { fourcc('Y','8','0','0'), 0 };
    const uint32_t *srcs = (vdo) ? vdo->formats : y800;
    const uint32_t *dsts = (win) ? win->formats : y800;

    unsigned min_cost = -1;
    uint32_t min_fmt = 0;
    const uint32_t *fmt;
    for(fmt = format_prefs; *fmt; fmt++) {
        /* only consider formats supported by video device */
        if(!has_format(*fmt, srcs))
            continue;
        uint32_t win_fmt = 0;
        int cost = _zebra_best_format(*fmt, &win_fmt, dsts);
        if(cost < 0) {
            zprintf(4, "%.4s(%08" PRIx32 ") -> ? (unsupported)\n",
                    (char*)fmt, *fmt);
            continue;
        }
        zprintf(4, "%.4s(%08" PRIx32 ") -> %.4s(%08" PRIx32 ") (%d)\n",
                (char*)fmt, *fmt, (char*)&win_fmt, win_fmt, cost);
        if(min_cost > cost) {
            min_cost = cost;
            min_fmt = *fmt;
            if(!cost)
                break;
        }
    }
    if(win)
        (void)window_unlock(win);

    if(!min_fmt)
        return(err_capture(errdst, SEV_ERROR, ZEBRA_ERR_UNSUPPORTED, __func__,
                           "no supported image formats available"));
    if(!vdo)
        return(0);

    zprintf(2, "setting best format %.4s(%08" PRIx32 ") (%d)\n",
            (char*)&min_fmt, min_fmt, min_cost);
    return(zebra_video_init(vdo, min_fmt));
}


Generated by  Doxygen 1.6.0   Back to index