TI中文支持网
TI专业的中文技术问题搜集分享网站

达芬奇视频采集显示 ,怎么把DM6467t提供的demo演示将视频转换为灰度视频进行输出。

下面是demo里面的代码,我应该怎么改才能将视频转换为灰度在输出,刚开始学这个还不太懂,主要是里面的那个YCbCr不能直接转换为RGB再处理。

/*
* Copyright 2007 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*/

/*
* Video Test Case
*
*/
#define DM6467_FIELDORFRAM 288

#include "vpif.h"

/* ======================================================================== *
* Video Buffers *
* ======================================================================== */

#pragma DATA_SECTION ( bt656NtscYT, ".ddr2_video" );
#pragma DATA_ALIGN(bt656NtscYT,32);
Uint8 bt656NtscYT[720 * DM6467_FIELDORFRAM];
#pragma DATA_SECTION ( bt656NtscCT, ".ddr2_video" );
Uint8 bt656NtscCT[720 * DM6467_FIELDORFRAM];
#pragma DATA_SECTION ( bt656NtscYB, ".ddr2_video" );
Uint8 bt656NtscYB[720 * DM6467_FIELDORFRAM];
#pragma DATA_SECTION ( bt656NtscCB, ".ddr2_video" );
Uint8 bt656NtscCB[720 * DM6467_FIELDORFRAM];

/* ———————————————————————— *
* VPIF Handles *
* ———————————————————————— */
static VPIF_CAP_Handle channel0 = ( VPIF_CAP_Handle )&VPIF_MODULE_0;
static VPIF_CAP_Handle channel1 = ( VPIF_CAP_Handle )&VPIF_MODULE_1;
static VPIF_DIS_Handle channel2 = ( VPIF_DIS_Handle )&VPIF_MODULE_2;

//static VPIF_DIS_Handle channel3 = ( VPIF_DIS_Handle )&VPIF_MODULE_3;
/* ———————————————————————— *
* vpif_sd_display( mode ) *
* ———————————————————————— */
Int16 vpif_sd_display( Int16 mode )
{

/* —————————————————————- *
* Setup VPIF controls *
* —————————————————————- */

VPIF_DMA_SIZE = 32; // DMA request size
VPIF_EMU_CTRL = 1; // Free from Emulation

VPIF_CHCTRL2 = 0; // Disable Display Channel 2

/* Clear Channel 2 */
channel2->regs->FLD0_Y_STRTADR = 0;
channel2->regs->FLD1_Y_STRTADR = 0;
channel2->regs->FLD0_C_STRTADR = 0;
channel2->regs->FLD1_C_STRTADR = 0;

channel2->regs->IMG_LINE_OFFSET = 0;
channel2->regs->HSIZE_CFG = 0;
channel2->regs->VSIZE_CFG0 = 0;
channel2->regs->VSIZE_CFG1 = 0;
channel2->regs->VSIZE_CFG2 = 0;
channel2->regs->VSIZE_CFG3 = 0;

/* Disable Interrupts */
VPIF_INTEN &= ~VPIF_INT_CH2;

/* Output Video Clocks – 27 MHz */
SYS_VSCLKDIS &= ~(7<<8);
SYS_VSCLKDIS &= (3<<8);

/* ——————————————————– *
* Setup Display Channel 2 -> [YCbCr] *
* ——————————————————– */

channel2->regs->FLD0_Y_STRTADR = ( ( Uint32 )bt656NtscYT );
channel2->regs->FLD0_C_STRTADR = ( ( Uint32 )bt656NtscCT );channel2->regs->FLD1_Y_STRTADR = ( ( Uint32 )bt656NtscYB );
channel2->regs->FLD1_C_STRTADR = ( ( Uint32 )bt656NtscCB );

/* 480I */

VPIF_CHCTRL2 = 0
| ( 0 << 12 ) // Output Field
| ( 0 << 11 ) // Interlaced Format
| ( 1 << 10 ) // Pixel Data
| ( 0 << 9 ) // No Vertical Ancillary
| ( 0 << 8 ) // No Horizontal Ancillary
| ( 1 << 6 ) // [2] Interrupt on Bottom Field
| ( 0 << 4 ) // Raster
| ( 1 << 3 ) // Y/C on same byte stream
| ( 0 << 0 ); // Channel Disabled

channel2->regs->IMG_LINE_OFFSET = 720;
channel2->regs->HSIZE_CFG = ( 280 << 16 ) | ( 1440 << 0 );
channel2->regs->VSIZE_CFG0 = ( 1 << 16 ) | ( 23 << 0 );
channel2->regs->VSIZE_CFG1 = ( 311 << 16 ) | ( 313 << 0 );
channel2->regs->VSIZE_CFG2 = ( 336 << 16 ) | ( 624 << 0 );
channel2->regs->VSIZE_CFG3 = ( 625 );

/* —————————————————————- *
* Synchronize : Channel 2 *
* —————————————————————- */
VPIF_INTEN |= VPIF_INT_CH2; // Enable Interrupts
VPIF_INTENSET |= VPIF_INT_CH2; // Set Interrupts
VPIF_INTENCLR |= VPIF_INT_CH2; // Clear Interrupts

/* Wait for Channel 0/1 frame sync */
VPIF_INTENCLR = ( VPIF_INT_CH0 | VPIF_INT_CH1 );
if ( VPIF_INTEN & ( VPIF_INT_CH0 | VPIF_INT_CH1 ) )
{
while ( ( VPIF_INTSTAT & ( VPIF_INT_CH0 | VPIF_INT_CH1 ) ) == 0 );
VPIF_INTENCLR = ( VPIF_INT_CH0 | VPIF_INT_CH1 );
}

/* —————————————————————- *
* Start Output: Channel 2 *
* —————————————————————- */
VPIF_CHCTRL2 |= 3;

return 0;
}

/* ———————————————————————— *
* vpif_sd_capture( mode, connector ) *
* ———————————————————————— */
Int16 vpif_sd_capture( Int16 mode, Int16 connector )
{

/* —————————————————————- *
* Setup VPIF controls *
* —————————————————————- */
VPIF_DMA_SIZE = 128; // DMA request size
VPIF_EMU_CTRL = 1; // Free from Emulation

VPIF_CHCTRL0 = 0; // Disable Capture Channel 0
VPIF_CHCTRL1 = 0; // Disable Capture Channel 1

/* Clear Channel 0 */
channel0->regs->FLD0_Y_STRTADR = 0;
channel0->regs->FLD1_Y_STRTADR = 0;
channel0->regs->FLD0_C_STRTADR = 0;
channel0->regs->FLD1_C_STRTADR = 0;

channel0->regs->IMG_LINE_OFFSET = 0;
channel0->regs->HSIZE_CFG = 0;
channel0->regs->VSIZE_CFG0 = 0;
channel0->regs->VSIZE_CFG1 = 0;
channel0->regs->VSIZE_CFG2 = 0;
channel0->regs->VSIZE_CFG3 = 0;

/* Clear Channel 1 */
channel1->regs->FLD0_Y_STRTADR = 0;
channel1->regs->FLD1_Y_STRTADR = 0;
channel1->regs->FLD0_C_STRTADR = 0;
channel1->regs->FLD1_C_STRTADR = 0;

channel1->regs->IMG_LINE_OFFSET = 0;
channel1->regs->HSIZE_CFG = 0;
channel1->regs->VSIZE_CFG0 = 0;
channel1->regs->VSIZE_CFG1 = 0;
channel1->regs->VSIZE_CFG2 = 0;
channel1->regs->VSIZE_CFG3 = 0;

/* Disable Interrupts */
VPIF_INTEN &= ~VPIF_INT_CH0;
VPIF_INTEN &= ~VPIF_INT_CH1;

/* Clear Interrupt */
VPIF_INTENCLR |= VPIF_INT_CH0;
VPIF_INTENCLR |= VPIF_INT_CH1;

/* Input Video Clocks */
vpif_clock_setup( VCH0CLK, 0 ); // from TVP5147_1
// Top Y's field start address
channel0->regs->FLD0_Y_STRTADR = ( ( Uint32 )bt656NtscYT );
// Top C's field start adress
channel0->regs->FLD0_C_STRTADR = ( ( Uint32 )bt656NtscCT );
// Bottom Y's field start address
channel0->regs->FLD1_Y_STRTADR = ( ( Uint32 )bt656NtscYB ); // BOttom C's field start address
channel0->regs->FLD1_C_STRTADR = ( ( Uint32 )bt656NtscCB );

// set flied mode ,offset for line store is 720 pixes
channel0->regs->IMG_LINE_OFFSET =720;
channel0->regs->HSIZE_CFG = ( 280 << 16 ) | ( 1440 << 0 );
channel0->regs->VSIZE_CFG0 = ( 1 << 16 ) | ( 23 << 0 );
channel0->regs->VSIZE_CFG1 = ( 311 << 16 ) | ( 313 << 0 );
channel0->regs->VSIZE_CFG2 = ( 336 << 16 ) | ( 624 << 0 );
channel0->regs->VSIZE_CFG3 = 625;

/* 480I */
VPIF_CHCTRL0 = 0
| ( 0 << 12 ) // Input Field mode
| ( 0 << 10 ) // Interlaced Format
| ( 0 << 9 ) // No Vertical Ancillary
| ( 0 << 8 ) // No Horizontal Ancillary
| ( 1 << 6 ) // [2] Interrupt on Bottom Field
| ( 0 << 5 ) // FID top field
| ( 0 << 4 ) // Raster
| ( 1 << 3 ) // Y/C on same byte stream
| ( 1 << 1 ) // FORMAT BT Video
| ( 0 << 0 ); // Channel Disabled

/* —————————————————————- *
* Start Input: Channel 0 *
* —————————————————————- */
VPIF_INTEN |= VPIF_INT_CH0; // Enable Interrupt
VPIF_INTENSET |= VPIF_INT_CH0; // Set Interrupt
VPIF_INTENCLR |= VPIF_INT_CH0; // Clear Interrupt

VPIF_CHCTRL0 |= 1; // Start Channel 0
return 0;
}

/* ———————————————————————— *
* vpif_sd_generate_pattern( mode ) *
* ———————————————————————— */
Int16 vpif_sd_generate_pattern( Int16 mode )
{
Int16 i, j, k;
Int16 hor_incr, ver_incr;
Uint8 ycrcb[8][3] = {
0xeb, 0x80, 0x80, // white *[cr=cb]
0x10, 0x80, 0x80, // black *[cr=cb]
0x51, 0xf0, 0x5a, // red
0x91, 0x22, 0x36, // green
0x29, 0x6e, 0xf0, // blue
0xd2, 0x92, 0x10, // yellow
0xaa, 0x10, 0xa6, // cyan
0x6a, 0xde, 0xca // magenta
};

Uint8 y, cr, cb;
Uint32 y32, cbcr32;

Uint32* ptrYT = ( Uint32* )bt656NtscYT;
Uint32* ptrYB = ( Uint32* )bt656NtscYB;
Uint32* ptrCT = ( Uint32* )bt656NtscCT;
Uint32* ptrCB = ( Uint32* )bt656NtscCB;

if ( mode == MODE_SDTV_480I )
{
hor_incr = 720;
ver_incr = 244;
}
else
return -1;

i = 0;

y = ycrcb[i][0];
y32 = ( y << 24 ) | ( y << 16 ) | ( y << 8 ) | ( y << 0 );

cr = ycrcb[i][1];
cb = ycrcb[i][2];
cbcr32 = ( cr << 24 ) | ( cb << 16 ) | ( cr << 8 ) | ( cb << 0 );

/* Color Bars */
for ( k = 0 ; k < ver_incr ; k++ )
{
for ( j = 0 ; j < hor_incr ; j++ )
{
*ptrYT++ = y32;
*ptrYB++ = y32;
}
}

for ( k = 0 ; k < ver_incr ; k++ )
{
for ( j = 0 ; j < hor_incr ; j++ )
{
*ptrCT++ = cbcr32;
*ptrCB++ = cbcr32;
}
}

return 0;
}

Chris Meng:

你好,

当UV的值为0x8080的时候,图像就是灰色的了。

user5274107:

回复 Chris Meng:

我想想函数vpif_sd_generate_pattern( Int16 mode )里面去修改,里面的代码如下:Int16 i, j, k;Int16 hor_incr, ver_incr;Uint8 ycrcb[8][3] = {0xeb, 0x80, 0x80, // white *[cr=cb]0x10, 0x80, 0x80, // black *[cr=cb]0x51, 0xf0, 0x5a, // red0x91, 0x22, 0x36, // green0x29, 0x6e, 0xf0, // blue0xd2, 0x92, 0x10, // yellow0xaa, 0x10, 0xa6, // cyan0x6a, 0xde, 0xca// magenta};

Uint8 y, cr, cb;Uint8 R,G,B;Uint32 y32, cbcr32;

Uint32* ptrYT = ( Uint32* )bt656NtscYT;Uint32* ptrYB = ( Uint32* )bt656NtscYB;Uint32* ptrCT = ( Uint32* )bt656NtscCT;Uint32* ptrCB = ( Uint32* )bt656NtscCB;

if ( mode == MODE_SDTV_576I )//480{hor_incr = 720;// ver_incr = 244;ver_incr = 288;}elsereturn -1;
i = 6;
// y = ycrcb[i][0];// cr = ycrcb[i][1];// cb = ycrcb[i][2];//R = 0x80;
// G = 0x80;//B = 0x80;//并没有报错
R = 12;G = 12;B = 12;//并没有报错y= 0.257*R+0.564*G+0.098*B+16;cb = -0.148*R-0.291*G+0.439*B+128;cr = 0.439*R-0.368*G-0.071*B+128;
printf("y32 is %X\n",y);printf("y32 is %X\n",cb);printf("y32 is %X\n",cr);y32 = ( y << 24 ) | ( y << 16 ) | ( y << 8 ) | ( y << 0 );
printf("y32 is %X\n",y32);//cr = ycrcb[i][1];//cb = ycrcb[i][2];

//R = 1.164*(y-16)+1.596*(cr-128);
// G = 1.164*(y-16)-0.392*(cb-128)-0.813*(cr-128);//B = 1.164*(y-16)+2.017*(cb-128);//并没有报错
cbcr32 = ( cr << 24 ) | ( cb << 16 ) | ( cr << 8 ) | ( cb << 0 );printf("cbcr32 is %X\n",cbcr32);/* Color Bars */for ( k = 0 ; k < ver_incr ; k++ ){for ( j = 0 ; j < hor_incr ; j++ ){*ptrYT++ = y32;*ptrYB++ = y32;}}
for ( k = 0 ; k < ver_incr ; k++ ){for ( j = 0 ; j < hor_incr ; j++ ){*ptrCT++ = cbcr32;*ptrCB++ = cbcr32;}}
printf("call function vpif_sd_generate_pattern()\n");return 0;
}
但是有一个问题就是我在这里面修改了代码,但是发现并没有函数去调用这个函数,即使我自己去添加代码调用,但是发现改了参数,视频还是不能灰度输出。

Chris Meng:

回复 user5274107:

你好,

如果图像的分辨率不变,可以事先在内存里放好一个相应大小的内容为0x8080的buffer ,显示时直接作为uv的内容显示。

赞(0)
未经允许不得转载:TI中文支持网 » 达芬奇视频采集显示 ,怎么把DM6467t提供的demo演示将视频转换为灰度视频进行输出。
分享到: 更多 (0)