1、图像反色程序教材/*/* Copyright 2004 by SEED Incorporated. */* All rights reserved. Property of SEED Incorporated. */* Restricted rights to use, duplicate or disclose this code are */* granted through contract. */* */*/*/* 图像反色 */*/#include #include #include #include #include #include #include #include iic.h
2、#include vportcap.h#include vportdis.h#include sa7121h.h#include TVP51xx.h#include TVP51xx.h#include seeddm642.h/*SEEDDM642的emifa的设置结构*/EMIFA_Config Seeddm642ConfigA = 0x00052078,/*gblctl EMIFA(B)global control register value */ /*将CLK6、4、1使能;将MRMODE置1;使能EK2EN,EK2RATE*/ 0xffffffd3,/*cectl0 CE0 space
3、 control register value*/ /*将CE0空间设为SDRAM*/ 0x73a28e01,/*cectl1 CE1 space control register value*/ /*Read hold: 1 clock; MTYPE : 0000,选择8位的异步接口 Read strobe :001110;14个clock宽度 TA:2 clock; Read setup 2 clock; Write hold :2 clock; Write strobe: 14 clock Write setup :7 clock - - 14c /1c -/ */ 0x22a28a22
4、, /*cectl2 CE2 space control register value*/ 0x22a28a42, /*cectl3 CE3 space control register value*/ 0x57115000, /*sdctl SDRAM control register value*/ 0x0000081b, /*sdtim SDRAM timing register value*/ 0x001faf4d, /*sdext SDRAM extension register value*/ 0x00000002, /*cesec0 CE0 space secondary con
5、trol register value*/ 0x00000002, /*cesec1 CE1 space secondary control register value*/ 0x00000002, /*cesec2 CE2 space secondary control register value*/ 0x00000073 /*cesec3 CE3 space secondary control register value*/ ;/*SEEDDM642的IIC的设置结构*/I2C_Config SEEDDM642IIC_Config = 0, /* master mode, i2coar
6、;采用主模式 */ 0, /* no interrupt, i2cimr;只写,不读,采用无中断方式*/ (20-5), /* scl low time, i2cclkl; */ (20-5), /* scl high time,i2cclkh; */ 1, /* configure later, i2ccnt;*/ 0, /* configure later, i2csar;*/ 0x4ea0, /* master tx mode, */ /* i2c runs free, */ /* 8-bit data + NACK */ /* no repeat mode */ (75-1), /*
7、4MHz clock, i2cpsc */;CHIP_Config SEEDDM642percfg = CHIP_VP2+ CHIP_VP1+ CHIP_VP0+ CHIP_I2C;I2C_Handle hSeeddm642i2c;int portNumber;extern SA7121H_ConfParams sa7121hPAL45;extern SA7121H_ConfParams sa7121hNTSC45;Uint8 vFromat = 0;Uint8 misc_ctrl = 0x6D;Uint8 output_format = 0x47;/ 地址为0 for cvbs port1,
8、选择复合信号做为输入Uint8 input_sel = 0x00;/*地址为0xf,将Pin27设置成为CAPEN功能*/ Uint8 pin_cfg = 0x02;/*地址为1B*/Uint8 chro_ctrl_2 = 0x14;/*图像句柄的声明*/VP_Handle vpHchannel0;VP_Handle vpHchannel1;VP_Handle vpHchannel2;/*确定图像的参数*/int numPixels = 720;/每行720个像素int numLines = 576;/每帧576行(PAL)/*确定处理的范围*/*A */* */* D*/ int intAP
9、ixels = 190;int intALines = 59;int intDPixels = 530;int intDLines = 229; /*画矩形边框函数的声明*/void drawRectangle();/*进行图像反色处理*/void videoReverse();/*采集与显示缓冲区的首址*/Uint32 capYbuffer = 0x80000000;Uint32 capCbbuffer = 0x800675c0;Uint32 capCrbuffer = 0x8009b0a0;Uint32 disYbuffer = 0x80100000;Uint32 disCbbuffer
10、= 0x801675c0; Uint32 disCrbuffer = 0x8019b0a0;Uint32 tempYbuffer = 0x80200000; /临时/*图像格式标志*/Uint8 NTSCorPAL = 0;extern far void vectors();extern volatile Uint32 capNewFrame;extern volatile Uint32 disNewFrame;/*此程序可将四个采集口的数据经过Video Port0送出*/void main() Uint8 addrI2C; int i; /*-*/* perform all initial
11、izations */*-*/ /*Initialise CSL,初始化CSL库*/ CSL_init(); CHIP_config(&SEEDDM642percfg);/*-*/ /*EMIFA的初始化,将CE0设为SDRAM空间,CE1设为异步空间 注,DM642支持的是EMIFA,而非EMIF*/ EMIFA_config(&Seeddm642ConfigA);/*-*/ /*中断向量表的初始化*/ /Point to the IRQ vector table IRQ_setVecs(vectors); IRQ_map(IRQ_EVT_VINT1,11); IRQ_map(IRQ_EVT
12、_VINT0, 12); IRQ_reset(IRQ_EVT_VINT0); IRQ_reset(IRQ_EVT_VINT1); IRQ_nmiEnable(); IRQ_globalEnable(); /*打开一个数据拷贝的数据通路*/ DAT_open(DAT_CHAANY, DAT_PRI_LOW, DAT_OPEN_2D); /*-*/ /*进行IIC的初始化*/ hSeeddm642i2c = I2C_open(I2C_PORT0,I2C_OPEN_RESET); I2C_config(hSeeddm642i2c,&SEEDDM642IIC_Config);/*-*/ /*进行TVP
13、5150pbs的初始化*/ /*选择TVP5150,设置第三通路*/ GPIO_RSET(GPGC,0x0);/*将GPIO0不做为GPINT使用*/ GPIO_RSET(GPDIR,0x1);/*将GPIO0做为输出*/ GPIO_RSET(GPVAL,0x0);/*GPIO0输出为高,选择IIC1总线,配置 第二路,即为U21*/ addrI2C = 0xBA 1; _IIC_write(hSeeddm642i2c, addrI2C,0x00, input_sel); _IIC_write(hSeeddm642i2c, addrI2C,0x03, misc_ctrl); _IIC_writ
14、e(hSeeddm642i2c, addrI2C,0x0D, output_format); _IIC_write(hSeeddm642i2c, addrI2C,0x0F, pin_cfg); _IIC_write(hSeeddm642i2c, addrI2C,0x1B, chro_ctrl_2); /*回读当前摄像设备的格式*/ _IIC_read(hSeeddm642i2c, addrI2C,0x8c, &vFromat); vFromat = vFromat & 0xff; switch (vFromat) case TVP51XX_NTSCM: case TVP51XX_NTSC443
15、: NTSCorPAL = 1;/*系统为NTSC的模式*/ break; case TVP51XX_PALBGHIN: case TVP51XX_PALM: NTSCorPAL = 0;/*系统为PAL的模式*/ break; default: NTSCorPAL = 2;/*系统为不支持的模式*/ break; if(NTSCorPAL =2) /*系统不支持的模式,重新配置*/ for(;) /*-*/ /*进行SAA7121H的初始化*/ GPIO_RSET(GPVAL,0x0);/*GPIO0输出为低,选择IIC1总线,配置图像输出*/ addrI2C = 0xB8 1; /*选择第
16、0路的I2C的地址*/ /*将第0路的视频输入口的数据口设为高阻状态, 使能SCLK,将第27脚设为输入*/ _IIC_write(hSeeddm642i2c, addrI2C,0x03, 0x1); /*配置SAA7121H*/ GPIO_RSET(GPVAL,0x1);/*GPIO0输出为低,选择IIC1总线,配置图像输出*/ /*初始化Video Port0*/ /*将Vedio Port1设为encoder输出*/ portNumber = 0; vpHchannel0 = bt656_8bit_ncfd(portNumber); for(i = 0; i 1; for(i =0; i
17、43; i+) if(NTSCorPAL = 1) _IIC_write(hSeeddm642i2c, addrI2C, (sa7121hNTSCi.regsubaddr), (sa7121hNTSCi.regvule); else _IIC_write(hSeeddm642i2c, addrI2C, (sa7121hPALi.regsubaddr), (sa7121hPALi.regvule); /*-*/ /*初始化Video Port1*/ /*将Vedio Port1设为采集输入*/ portNumber = 1; vpHchannel1 = bt656_8bit_ncfc(portN
18、umber); bt656_capture_start(vpHchannel1); /*等待第一帧数据采集完成*/ while(capNewFrame = 0) /*将数据存入显示缓冲区,并清采集完成的标志*/ capNewFrame =0; for(i=0;inumLines;i+) /*传送临时Y缓冲区*/ DAT_copy(void *)(capYbuffer + i * numPixels), (void *)(tempYbuffer + i * numPixels), numPixels); /*画边框*/ drawRectangle(); /*进行图像反色处理*/ videoRev
19、erse(); /*给显示缓存区内的UV赋值*/ for(i=0;i0x33ae0;i+) *(Uint8 *)(disCrbuffer +i) =0x80; *(Uint8 *)(disCbbuffer +i) =0x80; for(i=0;inumLines;i+) /*传送Y缓冲区*/ DAT_copy(void *)(tempYbuffer + i * numPixels), (void *)(disYbuffer + i * numPixels), numPixels); /*启动显示模块*/ bt656_display_start(vpHchannel0); /*建立显示的实时循环
20、*/ /*此循环中没有将采集缓存区中的UV值传给显示缓存区*/ /*此时显示缓存区的UV值为0x80*/ for(;) /*当采集区的数据已经采集好,而显示缓冲区的数据已空*/ if(capNewFrame = 1)&(disNewFrame = 1) /*将数据装入显示缓冲区,并清采集完成的标志*/ capNewFrame =0; disNewFrame =0; for(i=0;inumLines;i+) /*传送临时Y缓冲区*/ DAT_copy(void *)(capYbuffer + i * numPixels), (void *)(tempYbuffer + i * numPixel
21、s), numPixels); /*画边框*/ drawRectangle(); /*进行图像反色处理*/ videoReverse(); for(i=0;inumLines;i+) /*传送Y缓冲区*/ DAT_copy(void *)(tempYbuffer + i * numPixels), (void *)(disYbuffer + i * numPixels), numPixels); for(;) /*-*/ /*采集与回放*/ /*画矩形边框函数的定义*/void drawRectangle() int i,j; /*画上边*/ /奇数行 for(i=intALines-4;ii
22、ntALines;i+) /边框长度 for(j=intAPixels-6;jintDPixels+6;j+) /奇数行边框宽度 *(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00; /偶数行 for(i=numLines/2+intALines-4;inumLines/2+intALines;i+) /边框长度 for(j=intAPixels-6;jintDPixels+6;j+) /偶数行边框宽度 *(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00; /*画下边*/ /奇数行 for(i=intD
23、Lines;iintDLines+4;i+)/边框长度 for(j=intAPixels-6;jintDPixels+6;j+) /奇数行边框宽度 *(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00; /偶数行 for(i=numLines/2+intDLines;inumLines/2+intDLines+4;i+)/边框长度 for(j=intAPixels-6;jintDPixels+6;j+) /偶数行边框宽度 *(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00; /*画左边*/ /奇数行 fo
24、r(i=intALines;iintDLines;i+)/边框长度 for(j=intAPixels-6;jintAPixels;j+) /奇数行边框宽度 *(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00; /偶数行 for(i=numLines/2+intALines;inumLines/2+intDLines;i+)/边框长度 for(j=intAPixels-6;jintAPixels;j+) /偶数行边框宽度 *(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00; /*画右边*/ /奇数行 fo
25、r(i=intALines;iintDLines;i+)/边框长度 for(j=intDPixels;jintDPixels+6;j+) /奇数行边框宽度 *(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00; /偶数行 for(i=numLines/2+intALines;inumLines/2+intDLines;i+)/边框长度 for(j=intDPixels;jintDPixels+6;j+) /偶数行边框宽度 *(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00; /*进行图像反色处理*/void videoReverse() int i,j; /方框内奇数行 for(i=intALines;iintDLines;i+) /行数 for(j=intAPixels;jintDPixels;j+) /像素个数/每行 *(Uint8 *)(tempYbuffer + i*numPixels + j) = 0xFF-*(Uint8
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1