video_scaling.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:6k
- /*
- * Copyright 2003 by Texas Instruments Incorporated.
- * All rights reserved. Property of Texas Instruments Incorporated.
- * Restricted rights to use, duplicate or disclose this code are
- * granted through contract.
- *
- */
- /* "@(#) DDK 1.10.00.21 06-26-03 (ddk-b10)" */
- #include <std.h>
- #include <tsk.h>
- #include <sem.h>
- #include <gio.h>
- #include <csl_dat.h>
- #include <csl_cache.h>
- #include <fvid.h>
- #include <edc.h>
- #include <vport.h>
- #include <vportcap.h>
- #include <vportdis.h>
- #include <saa7105.h>
- #include <saa7115.h>
- #include <evmdm642.h>
- #include "colorbar.h"
- #include "evmdm642_vcapparams.h"
- #include "evmdm642_vdisparams.h"
- #ifdef _NTSC_SRC
- #include "../settings/evmdm642_vdisparamsNTSC.c"
- #endif
- #ifdef _PAL_SRC
- #include "../settings/evmdm642_vdisparamsPAL.c"
- #endif
- /* heap IDs defined in the BIOS configuration file */
- extern Int EXTERNALHEAP;
- /*
- * ======== main ========
- */
- main()
- {
- /******************************************************/
- /* open CSL DAT module for fast copy */
- /******************************************************/
- CSL_init();
- CACHE_clean(CACHE_L2ALL, 0, 0);
- CACHE_setL2Mode(CACHE_256KCACHE);
- CACHE_enableCaching(CACHE_EMIFA_CE00);
- CACHE_enableCaching(CACHE_EMIFA_CE01);
- DAT_open(DAT_CHAANY, DAT_PRI_LOW, DAT_OPEN_2D);
- }
- /*
- * ======== tskVideoLoopback ========
- * video loopback function.
- */
- void tskVideoLoopback()
- {
- Int status;
- FVID_Handle disChan;
- Int frames = 0;
- FVID_Frame *disFrameBuf;
- Int numLinesDis = EVMDM642_vDisParamsChan.imgVSizeFld1;
- Int numLinesCap = EVMDM642_vCapParamsChan.fldYStop1 -
- EVMDM642_vCapParamsChan.fldYStrt1+1;
-
- Int numLines;
- Int xOffset;
- Int yOffset;
- FVID_Handle capChan;
- Int numPixels = EVMDM642_vCapParamsChan.fldXStop1 -
- EVMDM642_vCapParamsChan.fldXStrt1+1;
- FVID_Frame *capFrameBuf;
- Int capLinePitch = EVMDM642_vCapParamsChan.fldXStop1 -
- EVMDM642_vCapParamsChan.fldXStrt1+1;
- Int disLinePitch = EVMDM642_vDisParamsChan.imgHSizeFld1;
- /* since the default setting is for NTSC, we need to adjust */
- /* that if capture input is in PAL format */
- #ifdef _PAL
- EVMDM642_vCapParamsSAA7115.inMode = SAA7115_MODE_PAL720;
- #endif
-
-
- if(EVMDM642_vCapParamsChan.fldOp == VPORT_FLDOP_FRAME) {
- numLinesCap *= 2; /* account for both fields */
- }
- if(EVMDM642_vDisParamsChan.fldOp == VPORT_FLDOP_FRAME) {
- numLinesDis *= 2; /* account for both fields */
- }
- numLines = (numLinesCap < numLinesDis) ? numLinesCap : numLinesDis;
-
- xOffset = (disLinePitch - capLinePitch) >> 1;
- yOffset = (numLinesDis - numLinesCap ) >> 1;
- yOffset &= ~1; /* make sure it is even */
- if( xOffset < 0) {
- xOffset = 0;
- }
- if( yOffset < 0) {
- yOffset = 0;
- }
- /******************************************************/
- /* allocate both capture and display frame buffers */
- /* in external heap memory */
- /******************************************************/
- EVMDM642_vCapParamsChan.segId = EXTERNALHEAP;
- EVMDM642_vDisParamsChan.segId = EXTERNALHEAP;
- EVMDM642_vDisParamsSAA7105.hI2C = EVMDM642_I2C_hI2C;
- EVMDM642_vCapParamsSAA7115.hI2C = EVMDM642_I2C_hI2C;
- /******************************************************/
- /* initialization of capture driver */
- /******************************************************/
- capChan = FVID_create("/VP0CAPTURE/A/0",
- IOM_INPUT, &status, (Ptr)&EVMDM642_vCapParamsChan, NULL);
- /******************************************************/
- /* initialization of display driver */
- /******************************************************/
- disChan = FVID_create("/VP2DISPLAY", IOM_OUTPUT,
- &status, (Ptr)&EVMDM642_vDisParamsChan, NULL);
-
- /******************************************************/
- /* configure video encoder & decoder */
- /******************************************************/
- FVID_control(disChan, VPORT_CMD_EDC_BASE + EDC_CONFIG,
- (Ptr)&EVMDM642_vDisParamsSAA7105);
- FVID_control(capChan, VPORT_CMD_EDC_BASE + EDC_CONFIG,
- (Ptr)&EVMDM642_vCapParamsSAA7115);
- /******************************************************/
- /* start capture & display operation */
- /******************************************************/
- FVID_control(disChan, VPORT_CMD_START, NULL);
- FVID_control(capChan, VPORT_CMD_START, NULL);
-
- /********************************************************/
- /* request a frame buffer from display & capture driver */
- /********************************************************/
- FVID_alloc(disChan, &disFrameBuf);
- FVID_alloc(capChan, &capFrameBuf);
- frames ++;
- while(1){/* loop forever */
- Int i;
- /* copy data from capture buffer to display buffer */
- /***************************************************/
- for(i = 0; i < numLines; i ++) {
- DAT_copy(capFrameBuf->frame.iFrm.y1 + i * capLinePitch,
- disFrameBuf->frame.iFrm.y1 + i * disLinePitch
- + xOffset + yOffset * disLinePitch,
- numPixels);
- DAT_copy(capFrameBuf->frame.iFrm.cb1 + i * (capLinePitch >> 1),
- disFrameBuf->frame.iFrm.cb1 +
- (i + yOffset) * (disLinePitch >> 1) + (xOffset >> 1),
- numPixels>>1);
- DAT_copy(capFrameBuf->frame.iFrm.cr1 + i * (capLinePitch >> 1),
- disFrameBuf->frame.iFrm.cr1 +
- (i + yOffset) * (disLinePitch >> 1) + (xOffset >> 1),
- numPixels>>1);
- }
- FVID_exchange(capChan, &capFrameBuf);
- FVID_exchange(disChan, &disFrameBuf);
-
- frames ++;
- }
- }