Logo Search packages:      
Sourcecode: libdc1394-22 version File versions  Download package

dc1394error_t dc1394_format7_set_roi ( dc1394camera_t camera,
dc1394video_mode_t  video_mode,
dc1394color_coding_t  color_coding,
int32_t  packet_size,
int32_t  left,
int32_t  top,
int32_t  width,
int32_t  height 
)

Joint function that fully sets a certain ROI taking all parameters into account. Note that this function does not SWITCH to the video mode passed as argument, it mearly sets it

Definition at line 766 of file format7.c.

{
    uint32_t unit_bytes, max_bytes;
    uint32_t recom_packet_size;
    uint32_t camera_left = 0;
    uint32_t camera_top = 0;
    uint32_t camera_width = 0;
    uint32_t camera_height = 0;
    uint32_t max_width = 0;
    uint32_t max_height = 0;
    uint32_t uint_packet_size=0;
    dc1394error_t err;

    // ===========================================================
    // COLOR CODING
    // ===========================================================
    // deal with color coding early as it may have an effect on max bpp, sizes, etc...
    if (color_coding==DC1394_QUERY_FROM_CAMERA) {
        err=dc1394_format7_get_color_coding(camera, video_mode, &color_coding);
        DC1394_ERR_RTN(err, "Unable to get color_coding");
    }
    else {
        if (color_coding<0) {
            // error: other auto modes not supported
            return DC1394_INVALID_ARGUMENT_VALUE;
        }
        // set color coding
        err=_dc1394_format7_set_color_coding(camera, video_mode, color_coding);
        DC1394_ERR_RTN(err, "Unable to set color_coding");

        // do handshaking to be sure that the value is now effective
        err=_dc1394_v130_handshake(camera, video_mode);
        DC1394_ERR_RTN(err, "Handshaking failed after setting color_coding");
    }

    // ===========================================================
    // POSITION AND SIZE
    // ===========================================================
    // we do this together as they influence each other. Only one hadshaking at the end.
    if ( width == DC1394_QUERY_FROM_CAMERA || height == DC1394_QUERY_FROM_CAMERA) {
        err=dc1394_format7_get_image_size(camera, video_mode, &camera_width, &camera_height);
        DC1394_ERR_RTN(err, "Unable to query image size");

        /* Idea from Ralf Ebeling: we should check if the image sizes are > 0.
           If == 0, we use the maximum size available */
        if (width == DC1394_QUERY_FROM_CAMERA) {
            if (camera_width>0)
                width = camera_width;
            else
                width = DC1394_USE_MAX_AVAIL;
        }
        if (height == DC1394_QUERY_FROM_CAMERA) {
            if (camera_height>0)
                height = camera_height;
            else
                height = DC1394_USE_MAX_AVAIL;
        }
    }

    if ( left == DC1394_QUERY_FROM_CAMERA || top == DC1394_QUERY_FROM_CAMERA) {
        err=dc1394_format7_get_image_position(camera, video_mode, &camera_left, &camera_top);
        DC1394_ERR_RTN(err, "Unable to query image position");

        if( left == DC1394_QUERY_FROM_CAMERA)
            left = camera_left;
        if( top == DC1394_QUERY_FROM_CAMERA)
            top = camera_top;
    }

    if ( width == DC1394_USE_MAX_AVAIL || height == DC1394_USE_MAX_AVAIL) {
        err=dc1394_format7_get_max_image_size(camera, video_mode, &max_width, &max_height);
        DC1394_ERR_RTN(err, "Unable to query max image size");
        if( width == DC1394_USE_MAX_AVAIL)
            width  = max_width - left;
        if( height == DC1394_USE_MAX_AVAIL)
            height = max_height - top;
    }
    if ((left<0)||(top<0)) {
        // error: other auto modes not supported
        return DC1394_INVALID_ARGUMENT_VALUE;
    }
    /* First set image position to (0,0) to allow the size/position to change
       without passing through an impossible state. The order of the operations is
       1) set position to (0,0), 2) set size 3) set position. Other orders may fail
       to properly set the camera, even if the pos/size couple if OK. */
    err=_dc1394_format7_set_image_position(camera, video_mode, 0,0);
    DC1394_ERR_RTN(err, "Unable to set image position");
    err=_dc1394_format7_set_image_size(camera, video_mode, width, height);
    DC1394_ERR_RTN(err, "Unable to set format 7 image size");
    err=_dc1394_format7_set_image_position(camera, video_mode, left, top);
    DC1394_ERR_RTN(err, "Unable to set format 7 image position");
    // do handshaking to be sure that the value is now effective
    err=_dc1394_v130_handshake(camera, video_mode);
    DC1394_ERR_RTN(err, "Handshaking failed after setting size and position");

    // ===========================================================
    // PACKET SIZE
    // ===========================================================

    if (packet_size==DC1394_QUERY_FROM_CAMERA) {
        err=dc1394_format7_get_packet_size(camera, video_mode, &uint_packet_size);
        DC1394_ERR_RTN(err, "Unable to get F7 packet size");
        packet_size=uint_packet_size;
    }

    switch (packet_size) {
    case DC1394_USE_RECOMMENDED:
        err=dc1394_format7_get_recommended_packet_size(camera, video_mode, &recom_packet_size);
        DC1394_ERR_RTN(err, "Recommended packet size inq error");
        if (recom_packet_size>0) {
            packet_size=recom_packet_size;
        }
        else { // recom. bpp asked, but register is 0. IGNORED
            err=dc1394_format7_get_packet_parameters(camera, video_mode, &unit_bytes, &max_bytes); /* PACKET_PARA_INQ */
            DC1394_ERR_RTN(err, "Packet para inq error");
            dc1394_log_warning("Recommended packet size asked, but register is zero for mode %d. Falling back to MAX packet size", video_mode);
            packet_size=max_bytes;
        }
        break;
    case DC1394_USE_MAX_AVAIL:
        err=dc1394_format7_get_packet_parameters(camera, video_mode, &unit_bytes, &max_bytes); /* PACKET_PARA_INQ */
        DC1394_ERR_RTN(err, "Packet para inq error");
        packet_size = max_bytes;
        break;
    case DC1394_QUERY_FROM_CAMERA:
        // if we wanted QUERY_FROM_CAMERA, the QUERY_FROM_CAMERA value has been overwritten by
        // the current value at the beginning of the program. It is thus not possible to reach this code fragment.
        dc1394_log_error("Packet size error: we should not reach this code region");
        break;
    default:
        err=dc1394_format7_get_packet_parameters(camera, video_mode, &unit_bytes, &max_bytes); /* PACKET_PARA_INQ */
        DC1394_ERR_RTN(err, "Packet para inq error");
        // we have to take several tricks into account here:
        // 1) BPP could be zero, in which case it becomes MAX_BPP
        // 2) UNIT_BYTES could also be zero, in which case we force it to MAX_BPP.
        //    This actually further forces BPP to be set to MAX_BPP too.

        if (unit_bytes==0) {
            unit_bytes=max_bytes;
        }
        if (packet_size > max_bytes) {
            packet_size = max_bytes;
        }
        else {
            if (packet_size < unit_bytes) {
                packet_size = unit_bytes;
            }
        }
        packet_size-=packet_size % unit_bytes;
        break;
    }

    // set bpp:
    err=_dc1394_format7_set_packet_size(camera, video_mode, packet_size);
    DC1394_ERR_RTN(err, "Unable to set format 7 packet_size");

    // IIDC v1.30 handshaking:
    err=_dc1394_v130_handshake(camera, video_mode);
    DC1394_ERR_RTN(err, "F7 handshake failure");

    return err;
}


Generated by  Doxygen 1.6.0   Back to index