DM642视频采集与回放 程序基本框架

void tskVideoLoopback()

{

    //设置显示的行数

    numLinesDis = EVMDM642_vDisParamsChan.imgVSizeFld1;   

//设置采集的行数

numLinesCap = EVMDM642_vCapParamsChan.fldYStop1 –

      EVMDM642_vCapParamsChan.fldYStrt1+1;                

//取二者中较小的为程序处理的行数

numLines = (numLinesDis > numLinesCap) ? numLinesCap : numLinesDis;

#ifdef _LOOPBACK

//设置每行显示的像素

       numPixels = EVMDM642_vCapParamsChan.fldXStop1 -

           EVMDM642_vCapParamsChan.fldXStrt1+1;    

      //采集图像一行的总像素  

       capLinePitch = EVMDM642_vCapParamsChan.fldXStop1 -

           EVMDM642_vCapParamsChan.fldXStrt1+1;      

       //显示图像一行的总像素

       disLinePitch = EVMDM642_vDisParamsChan.imgHSizeFld1;

#endif      

        numLines *= 2; /* both fields */

       //分配采集和显示图像的存放缓冲区

        EVMDM642_vCapParamsChan.segId = EXTERNALHEAP;

        EVMDM642_vDisParamsChan.segId = EXTERNALHEAP;

        EVMDM642_vDisParamsSAA7104.hI2C = EVMDM642_I2C_hI2C;

        EVMDM642_vCapParamsTVP5150A.hI2C = EVMDM642_I2C_hI2C;

//建立并初始化采集设备对象

#ifdef _LOOPBACK

#ifdef _VP2

    capChan = FVID_create("/VP2CAPTURE/A/1",

            IOM_INPUT, &status, (Ptr)&EVMDM642_vCapParamsChan, NULL);

#else 

    capChan = FVID_create("/VP0CAPTURE/A/0",

            IOM_INPUT, &status, (Ptr)&EVMDM642_vCapParamsChan, NULL);

#endif

#endif

    //建立并初始化显示设备对象

    disChan = FVID_create("/VP1DISPLAY", IOM_OUTPUT,

        &status, (Ptr)&EVMDM642_vDisParamsChan, NULL);

    //为保证采集和显示设备正常工作,为其设置驱动

    FVID_control(disChan, VPORT_CMD_EDC_BASE + EDC_CONFIG,

        (Ptr)&EVMDM642_vDisParamsSAA7104);

#ifdef _LOOPBACK

    FVID_control(capChan, VPORT_CMD_EDC_BASE + EDC_CONFIG,

        (Ptr)&EVMDM642_vCapParamsTVP5150A);

#endif

    //开始采集和显示操作

    FVID_control(disChan, VPORT_CMD_START, NULL);

#ifdef _LOOPBACK

    FVID_control(capChan, VPORT_CMD_START, NULL);

#endif   

    //分配采集和显示一帧图像存放的缓冲区

    FVID_alloc(disChan, &disFrameBuf);

#ifdef _LOOPBACK

    FVID_alloc(capChan, &capFrameBuf);

#endif

    frames ++;

while(1)

{

#ifdef _LOOPBACK

        Int i;

     //将采集缓冲区的内容复制到显示缓冲区中

     for(i = 0; i < numLines; i ++) {

          DAT_copy(capFrameBuf->frame.iFrm.y1 + i * capLinePitch,

               disFrameBuf->frame.iFrm.y1 + i * disLinePitch,

               numPixels);

           DAT_copy(capFrameBuf->frame.iFrm.cb1 + i * (capLinePitch >> 1),

                disFrameBuf->frame.iFrm.cb1 + i * (disLinePitch >> 1),

                numPixels>>1);

           DAT_copy(capFrameBuf->frame.iFrm.cr1 + i * (capLinePitch >> 1),

                 disFrameBuf->frame.iFrm.cr1 + i * (disLinePitch >> 1),

                 numPixels>>1);

       }

FVID_exchange(capChan, &capFrameBuf);

#else //如果定义CAPTURE则填充图像缓冲为8条带

           fillFrmBuf(&disFrameBuf->frame.iFrm,

EVMDM642_vDisParamsChan.imgHSizeFld1,

            EVMDM642_vDisParamsChan.imgVSizeFld1+

EVMDM642_vDisParamsChan.imgVSizeFld2, frames % 360);

#endif

       //将显示缓冲区中的一帧图像送给显示设备

        FVID_exchange(disChan, &disFrameBuf);

       //处理下一帧图像

        frames ++;             

   }

}

产生向左平移的8条带图案:

#include <std.h>
#include <csl_cache.h>
#include <fvid.h>
#include <csl_dat.h>  
#include "colorbar.h"  

 

 


/* static function declaration 定义每个颜色的Y CB CR值 白黄青绿紫红蓝黑*/
static void generateColorBar(Uint8* y, Uint8* cb, Uint8* cr, Int lineSize);

#define WHITE_Y        180
#define WHITE_CB       128
#define WHITE_CR       128

#define YELLOW_Y       162
#define YELLOW_CB      44
#define YELLOW_CR      142

#define CYAN_Y         131
#define CYAN_CB        156
#define CYAN_CR        44

#define GREEN_Y        112
#define GREEN_CB       72
#define GREEN_CR       58

#define MAGENTA_Y       84
#define MAGENTA_CB     184
#define MAGENTA_CR     198

#define RED_Y          65
#define RED_CB         100
#define RED_CR         212

#define BLUE_Y          35
#define BLUE_CB        212
#define BLUE_CR        114

#define BLACK_Y        16
#define BLACK_CB       129
#define BLACK_CR       129

/* defines arrays to hold a line of image for color bar generating */
#pragma DATA_ALIGN(imgLineY, 8);
#pragma DATA_ALIGN(imgLineCb, 8);
#pragma DATA_ALIGN(imgLineCr, 8);

static Uint8 imgLineY[1920 * 3];
static Uint8 imgLineCb[960 * 3];
static Uint8 imgLineCr[960 * 3];

/*
 * ======== fillFrmBuf ========
 * This function fill a frame with color bar of Y/Cb/Cr format.
 */

void fillFrmBuf(FVID_IFrame* frame, Int lineSz, Int numLines, Int offset )
{
    Int i;
    static Int init = 0;
    Int id;
    if(!init) {
        generateColorBar(imgLineY, imgLineCb, imgLineCr, lineSz);
        CACHE_clean(CACHE_L2ALL, NULL, NULL);
        init = 1;
    }   
    for(i = 0; i < numLines; i ++) {       
        DAT_copy(imgLineY + offset * 2, frame->y1 + lineSz * i, lineSz);
        DAT_copy(imgLineCb + offset, frame->cb1 + (lineSz >> 1) * i,
            (lineSz >> 1));
        id = DAT_copy(imgLineCr + offset, frame->cr1+(lineSz >> 1) * i,
            (lineSz >> 1));
    }            
    DAT_wait(id);        
}         

/*
 * ======== generateColorBar ========
 * This function generates a line of color bar with y/cb/cr format.
 */

static void generateColorBar(Uint8* y, Uint8* cb, Uint8* cr, Int lineSize)
{
    Int i;  
    Int fillSize = lineSize >> 3;
    Int k;
   
    if(fillSize & 0x1) {
        fillSize ++;
    }
    /* white bar */
    for(k = 0; k < 3; k ++) {
        for(i = 0; i<(fillSize >> 1); i++) {

            y[2 * i] = WHITE_Y;
            y[2 * i + 1] = WHITE_Y;
            cb[i] = WHITE_CR;
            cr[i] = WHITE_CB;

            y[fillSize * 1 + 2 * i] = YELLOW_Y;
            y[fillSize * 1 + 2 * i + 1] = YELLOW_Y;
            cb[(fillSize >> 1) * 1 + i] = YELLOW_CB;
            cr[(fillSize >> 1) * 1 + i] = YELLOW_CR;

            y[fillSize * 2 + 2 * i] = CYAN_Y;
            y[fillSize * 2 + 2 * i + 1] = CYAN_Y;
            cb[(fillSize >> 1) * 2 + i] = CYAN_CB;
            cr[(fillSize >> 1) * 2 + i] = CYAN_CR;

            y[fillSize * 3 + 2 * i] = GREEN_Y;
            y[fillSize * 3 + 2 * i + 1] = GREEN_Y;
            cb[(fillSize >> 1) * 3 + i] = GREEN_CB;
            cr[(fillSize >> 1) * 3 + i] = GREEN_CR;


            y[fillSize * 4 + 2 * i] = MAGENTA_Y;
            y[fillSize * 4 + 2 * i + 1] = MAGENTA_Y;
            cb[(fillSize >> 1) * 4 + i] = MAGENTA_CB;
            cr[(fillSize >> 1) * 4 + i] = MAGENTA_CR;

            y[fillSize * 5 + 2 * i] = RED_Y;
            y[fillSize * 5 + 2 * i + 1] = RED_Y;
            cb[(fillSize >> 1) * 5 + i] = RED_CB;
            cr[(fillSize >> 1) * 5 + i] = RED_CR;


 
            y[fillSize * 6 + 2 * i] = BLUE_Y;
            y[fillSize * 6 + 2 * i + 1] = BLUE_Y;
            cb[(fillSize >> 1) * 6 + i] = BLUE_CB;
            cr[(fillSize >> 1) * 6 + i] = BLUE_CR;

 

            y[fillSize * 7 + 2 * i] = BLACK_Y;
            y[fillSize * 7 + 2 * i + 1] = BLACK_Y;
            cb[(fillSize >> 1) * 7 + i] = BLACK_CB;
            cr[(fillSize >> 1) * 7 + i] = BLACK_CR;
        }   
        y  += lineSize;
        cb += lineSize >> 1;
        cr += lineSize >> 1;
    }

}

你可能感兴趣的:(框架,function,cmd,null,Arrays,Exchange)