我用合众达DM642灰度均衡化的例程跑出来的图像全部花掉了。
但是我把图像均衡化的函数注释掉的话,是可以正常显示的。
以下是该例程的代码,有用过合众达的朋友帮帮忙。谢谢啦~!
/********************************************************************/
/* 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 <csl.h>
#include <csl_emifa.h>
#include <csl_i2c.h>
#include <csl_gpio.h>
#include <csl_irq.h>
#include <csl_chip.h>
#include <csl_dat.h>
#include "iic.h"
#include "vportcap.h"
#include "vportdis.h"
#include "sa7121h.h"
#include "TVP51xx.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 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, /*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 control 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;²ÉÓÃÖ÷ģʽ */
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), /* 4MHz clock, i2cpsc */
};
CHIP_Config SEEDDM642percfg = {
CHIP_VP2+\
CHIP_VP1+\
CHIP_VP0+\
CHIP_I2C
};
I2C_Handle hSeeddm642i2c;
int portNumber;
extern SA7121H_ConfParams sa7121hPAL[45];
extern SA7121H_ConfParams sa7121hNTSC[45];
Uint8 vFromat = 0;
Uint8 misc_ctrl = 0x6D;
Uint8 output_format = 0x47;
// µØַΪ0 for cvbs port1,Ñ¡Ôñ¸´ºÏÐźÅ×öΪÊäÈë
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 intAPixels = 190;
int intALines = 59;
int intDPixels = 530;
int intDLines = 229;
/******************************/
/*****»¾ØÐα߿òº¯ÊýµÄÉùÃ÷*****/
void drawRectangle();
/*****½øÐлҶȾùºâ´¦Àí*********/
void inteEqualize();
/*²É¼¯ÓëÏÔʾ»º³åÇøµÄÊ×Ö·*/
Uint32 capYbuffer = 0x80000000;
Uint32 capCbbuffer = 0x800675c0;
Uint32 capCrbuffer = 0x8009b0a0;
Uint32 disYbuffer = 0x80100000;
Uint32 disCbbuffer = 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 initializations */
/*-------------------------------------------------------*/
/*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_nmiEnable();
IRQ_globalEnable();
IRQ_map(IRQ_EVT_VINT1, 11);
IRQ_map(IRQ_EVT_VINT0, 12);
IRQ_reset(IRQ_EVT_VINT1);
IRQ_reset(IRQ_EVT_VINT1);
/*´ò¿ªÒ»¸öÊý¾Ý¿½±´µÄÊý¾Ýͨ·*/
DAT_open(DAT_CHAANY, DAT_PRI_LOW, DAT_OPEN_2D);
/*----------------------------------------------------------*/
/*½øÐÐIICµÄ³õʼ»¯*/
hSeeddm642i2c = I2C_open(I2C_PORT0,I2C_OPEN_RESET);
I2C_config(hSeeddm642i2c,&SEEDDM642IIC_Config);
/*----------------------------------------------------------*/
/*½øÐÐTVP5150pbsµÄ³õʼ»¯*/
/*Ñ¡Ôñ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_write(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:
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; /*Ñ¡ÔñµÚ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);
addrI2C = 0x88 >>1;
for(i =0; i<43; i++)
{
if(NTSCorPAL == 1)
{
_IIC_write(hSeeddm642i2c,
addrI2C,
(sa7121hNTSC[i].regsubaddr),
(sa7121hNTSC[i].regvule));
}
else
{
_IIC_write(hSeeddm642i2c,
addrI2C,
(sa7121hPAL[i].regsubaddr),
(sa7121hPAL[i].regvule));
}
}
/*----------------------------------------------------------*/
/*³õʼ»¯Video Port1*/
/*½«Vedio Port1ÉèΪ²É¼¯ÊäÈë*/
portNumber = 1;
vpHchannel1 = bt656_8bit_ncfc(portNumber);
bt656_capture_start(vpHchannel1);
/*µÈ´ýµÚÒ»Ö¡Êý¾Ý²É¼¯Íê³É*/
while(capNewFrame == 0){}
/*½«Êý¾Ý´æÈëÏÔʾ»º³åÇø£¬²¢Çå²É¼¯Íê³ÉµÄ±êÖ¾*/
capNewFrame =0;
for(i=0;i<numLines;i++)
{
/*´«ËÍÁÙʱY»º³åÇø*/
DAT_copy((void *)(capYbuffer + i * numPixels),
(void *)(tempYbuffer + i * numPixels),
numPixels);
}
/*»±ß¿ò*/
drawRectangle();
/*½øÐлҶȾùºâ´¦Àí*/
inteEqualize();
// inteEqualizeLai();
for(i=0;i<0x33ae0;i++)
{
*((Uint8 *)(disCrbuffer +i)) =0x80;
*((Uint8 *)(disCbbuffer +i)) =0x80;
}
for(i=0;i<numLines;i++)
{
/*´«ËÍY»º³åÇø*/
DAT_copy((void *)(tempYbuffer + i * numPixels),
(void *)(disYbuffer + i * numPixels),
numPixels);
}
/*Æô¶¯ÏÔʾģ¿é*/
bt656_display_start(vpHchannel0);
/*½¨Á¢ÏÔʾµÄʵʱѻ·*/
for(;;)
{
/*µ±²É¼¯ÇøµÄÊý¾ÝÒѾ²É¼¯ºÃ£¬¶øÏÔʾ»º³åÇøµÄÊý¾ÝÒÑ¿Õ*/
if((capNewFrame == 1)&&(disNewFrame == 1))
{
/*½«Êý¾Ý×°ÈëÏÔʾ»º³åÇø£¬²¢Çå²É¼¯Íê³ÉµÄ±êÖ¾*/
capNewFrame =0;
disNewFrame =0;
for(i=0;i<numLines;i++)
{
/*´«ËÍÁÙʱY»º³åÇø*/
DAT_copy((void *)(capYbuffer + i * numPixels),
(void *)(tempYbuffer + i * numPixels),
numPixels);
}
/*»±ß¿ò*/
drawRectangle();
/*½øÐлҶȾùºâ´¦Àí*/
inteEqualize();
// inteEqualizeLai();
for(i=0;i<numLines;i++)
{
/*´«ËÍY»º³åÇø*/
DAT_copy((void *)(tempYbuffer + i * numPixels),
(void *)(disYbuffer + i * numPixels),
numPixels);
}
}
}
for(;;)
{}
/*----------------------------------------------------------*/
/*²É¼¯Óë»Ø·Å*/
}
/*»¾ØÐα߿òº¯ÊýµÄ¶¨Òå*/
void drawRectangle()
{
int i,j;
/*ȃ챧*/
//ÆæÊýÐÐ
for(i=intALines-4;i<intALines;i++)
{
for(j=intAPixels-6;j<intDPixels+6;j++)
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
//żÊýÐÐ
for(i=numLines/2+intALines-4;i<numLines/2+intALines;i++)
{
for(j=intAPixels-6;j<intDPixels+6;j++)
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
/*»Ï±ß*/
//ÆæÊýÐÐ
for(i=intDLines;i<intDLines+4;i++)
{
for(j=intAPixels-6;j<intDPixels+6;j++)
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
//żÊýÐÐ
for(i=numLines/2+intDLines;i<numLines/2+intDLines+4;i++)
{
for(j=intAPixels-6;j<intDPixels+6;j++)
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
/*»×ó±ß*/
//ÆæÊýÐÐ
for(i=intALines;i<intDLines;i++)
{
for(j=intAPixels-6;j<intAPixels;j++)
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
//żÊýÐÐ
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)
{
for(j=intAPixels-6;j<intAPixels;j++)
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
/*»ÓÒ±ß*/
//ÆæÊýÐÐ
for(i=intALines;i<intDLines;i++)
{
for(j=intDPixels;j<intDPixels+6;j++)
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
//żÊýÐÐ
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)
{
for(j=intDPixels;j<intDPixels+6;j++)
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
}
/*½øÐлҶȾùºâ´¦Àí*/
void inteEqualize()
{
int i,j,intTemp;
int intArea = (intDPixels-intAPixels)*(intDLines-intALines)*2; //Ãæ»ý£¨×ܵÄÏñËØ£©
Uint8 grayMap[256]; //»Ò¶ÈÓ³Éä±í
int intCount[256]; //µÚi¼¶»Ò¶È¼ÆÊý
/*ÖØÖüÆÊýΪ0*/
for(i=0;i<256;i++)
{
//ÇåÁã
intCount[i]=0;
}
/*¼ÆËã¸÷¸ö»Ò¶ÈÖµµÃ¼ÆÊý*/
//·½¿òÄÚÆæÊýÐÐ
for(i=intALines;i<intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
intTemp = *(Uint8 *)(tempYbuffer + i*numPixels + j);
//¼ÆÊý¼Ó1
intCount[intTemp]++;
}
}
//·½¿òÄÚżÊýÐÐ
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
intTemp = *(Uint8 *)(tempYbuffer + i*numPixels + j);
//¼ÆÊý¼Ó1
intCount[intTemp]++;
}
}
/*¼ÆËã»Ò¶ÈÓ³Éä±í*/
for(i=0;i<256;i++)
{
//³õʼ»¯Îª0
intTemp = 0;
for(j=0;j<=i;j++)
{
intTemp+=intCount[j];
}
//¼ÆËã¶ÔÓ¦µÄлҶÈÖµ
grayMap[i] = (Uint8)(intTemp*255/intArea);
}
/*½øÐлҶȾùºâ£¬ÖØи³Öµ*/
//·½¿òÄÚÆæÊýÐÐ
for(i=intALines;i<intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
intTemp = *(Uint8 *)(tempYbuffer + i*numPixels + j);
//¸³ÐµĻҶÈÖµ
*(Uint8 *)(tempYbuffer + i*numPixels + j) = grayMap[intTemp];
}
}
//·½¿òÄÚżÊýÐÐ
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
intTemp = *(Uint8 *)(tempYbuffer + i*numPixels + j);
//¸³ÐµĻҶÈÖµ
*(Uint8 *)(tempYbuffer + i*numPixels + j) = grayMap[intTemp];
}
}
}
inteEqualizeLai()
{
int i,j,intTemp;
long pixelNum = (intDPixels-intAPixels)*(intDLines-intALines)*2; //Ãæ»ý£¨×ܵÄÏñËØ£©
long hist[256];
long nNum = 0;
double pr;
//Uint8 grayMap[256]; //»Ò¶ÈÓ³Éä±í
//int intCount[256]; //µÚi¼¶»Ò¶È¼ÆÊý
/*ÖØÖüÆÊýΪ0*/
for(i=0;i<256;i++)
{
//ÇåÁã
hist[i]=0;
}
//¼ÆËãͼÏñÖ±·½Í¼
/*¼ÆËã¸÷¸ö»Ò¶ÈÖµµÃ¼ÆÊý*/
//·½¿òÄÚÆæÊýÐÐ
for(i=intALines;i<intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
//¼ÆÊý¼Ó1
hist[*(Uint8 *)(tempYbuffer + i*numPixels + j)]++;
}
}
//·½¿òÄÚżÊýÐÐ
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
//¼ÆÊý¼Ó1
hist[*(Uint8 *)(tempYbuffer + i*numPixels + j)]++;
}
}
/*¼ÆËã±ä»»ºóµÄ»Ò¶ÈÖµ*/
for(i=0;i<256;i++)
{
nNum += hist[i];
pr = (double)nNum/pixelNum;
hist[i] = (Uint8)255*pr;
}
/*½øÐлҶȾùºâ£¬ÖØи³Öµ*/
//·½¿òÄÚÆæÊýÐÐ
for(i=intALines;i<intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
//¸³ÐµĻҶÈÖµ
*(Uint8 *)(tempYbuffer + i*numPixels + j) = hist[*(Uint8 *)(tempYbuffer + i*numPixels + j)];
}
}
//·½¿òÄÚżÊýÐÐ
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
//¸³ÐµĻҶÈÖµ
*(Uint8 *)(tempYbuffer + i*numPixels + j) = hist[*(Uint8 *)(tempYbuffer + i*numPixels + j)];
}
}
}
|