⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adi_itu656.c

📁 ADI公司blackfin DSP开发板BF533 EZ-KIT LITE附带的全部原代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************

Copyright (c) 2005 Analog Devices.  All Rights Reserved.

This software is proprietary and confidential.  By using this software you agree
to the terms of the associated Analog Devices License Agreement.  
******************************************************************************

$File: video.c $
$Revision: 1.2 $
$Date: 2007/03/28 17:51:22 $

Description:
            Source file for ITU-656 utilities

References:
******************************************************************************


*****************************************************************************/


/***************************************************************************** 
*                          INCLUDES                                         *
*****************************************************************************/

#include <services/services.h>	// system service definitions
#include "adi_itu656.h"      	// ITU-656 utilities header file

/***************************************************************************** 
*                          DEFINES                                          *
*****************************************************************************/

// Local Definitions

#define     ADI_ITU656_EAV     1           // Defines End of Active Video
#define     ADI_ITU656_SAV     2           // Defines Start of Active video

/***************************************************************************** 
*                          STATIC FUNCTIONS                                  *
******************************************************************************/

static void generate_XY ( 
    u32                     scanline,      // Current scanline number
    ADI_ITU656_FRAME_TYPE   frametype,     // Video frame type
    u8                      *preambleXY,   // holds the calculated XY value for EAV / SAV
    u32                     videostatus    // indicates XY calculation for EAV or SAV
);
   
static void calculate_address ( 
    u8                      *frame_ptr,     // Pointer to the formated video frame in memory
    ADI_ITU656_FRAME_TYPE   frametype,      // Frame type of the formated memory
    u8                      **address1,     // Holds address of Field 1 first active line's active data start address (for interlaced frame type)
                                                // OR First active line's active data start address (for Progressive frame type)
    u8                      **address2,     // Holds address of Field 2 first active line's active data start address (for interlaced frame type)
    u32                     *f1start,       // Holds Field1 active line start value (for interlaced frameformat) 
                                                // OR Active line start value (for progressive frameformat)
    u32                     *f1end,         // Holds Field1 active line end value (for interlaced frameformat) 
                                                // OR Active line end value (for progressive frameformat)
    u32                     *f2start,       // Holds Field2 active line start value (for interlaced frameformat) 
    u32                     *f2end,         // Holds Field2 active line end value (for interlaced frameformat) 
    u32                     *widthcount     // Holds the value of NTSC / PAL frame width 
);


/***************************************************************************** 
*                          FUNCTION DEFINITIONS                             *
******************************************************************************
**
** Function:            adi_itu656_FrameFormat
**
** Description:         This function formats an area in memory into a video frame
**                      active fields set blank.
**
** Arguments:           
**
**  frame_ptr           Pointer to an area in memory that will be used for the frame
**                      
**  frametype           Type of frame to be formatted
**
** Return value:        None
**                      
**
**
*/

void adi_itu656_FrameFormat ( u8 *frame_ptr,ADI_ITU656_FRAME_TYPE frametype )
{

    u32     i,j,linecount,blankcount,widthcount;
    u8      preambleXY;

    switch (frametype) {    // Switch to frame type

    // Format frame as NTSC Interlaced or NTSC Progressive
    case (ADI_ITU656_NTSC_IL):
    case (ADI_ITU656_NTSC_PR):
        linecount = ADI_ITU656_NTSC_HEIGHT;
        blankcount = ADI_ITU656_NTSC_BLANKING;
        widthcount = ADI_ITU656_NTSC_WIDTH;
        break;

    // Format frame as PAL Interlaced or PAL Progressive
    case (ADI_ITU656_PAL_IL):
    case (ADI_ITU656_PAL_PR):
        linecount = ADI_ITU656_PAL_HEIGHT;
        blankcount = ADI_ITU656_PAL_BLANKING;
        widthcount = ADI_ITU656_PAL_WIDTH;
        break;

    default:    // Default as NTSC frame
        linecount = ADI_ITU656_NTSC_HEIGHT;
        blankcount = ADI_ITU656_NTSC_BLANKING;
        widthcount = ADI_ITU656_NTSC_WIDTH;
        break;
    }
    
    // Formats frame memory as EAV,Blanking,SAV,Active lines (Blanked)
    for(i = 1; i <= linecount; i++)    // loop to format frame memory
    {

        // Generate BT656 Preamble

        // EAV - FF 00 00 XY
        generate_XY(i,frametype,&preambleXY,ADI_ITU656_EAV);

        *frame_ptr++ = 0xFF;
        *frame_ptr++ = 0x00;
        *frame_ptr++ = 0x00;
        *frame_ptr++ = preambleXY;
        
        // Blanking
        for(j = 0; j < (blankcount / 2); j++)
        {
            *frame_ptr++ = 0x80;
            *frame_ptr++ = 0x10;
        }

        // SAV - FF 00 00 XY
        generate_XY(i,frametype,&preambleXY,ADI_ITU656_SAV);

        *frame_ptr++ = 0xFF;
        *frame_ptr++ = 0x00;
        *frame_ptr++ = 0x00;
        *frame_ptr++ = preambleXY;

        // Output empty horizontal data to blank all lines
        for(j = 0; j < (widthcount); j++)
        {
            *frame_ptr++ = 0x80;
            *frame_ptr++ = 0x10;
        }
    }
}

/***************************************************************************** 
**
** Function:            adi_itu656_FrameFill
**
** Description:         This function fills the active video portion(s)
**                      of a formatted frame with a specified color.
**
** Arguments:           
**
**  frame_ptr           Pointer to the formated video frame in memory
**                      
**  frametype           Frame type of the formated memory
**
**  ycbcr_data          32 bit value color value corresponding to a 4 byte array of 8-bit YCbYCr data
**
** Return value:        None
**                      
**
**
*/
void adi_itu656_FrameFill ( u8 *frame_ptr,ADI_ITU656_FRAME_TYPE frametype,u8 *ycbcr_data )
{

    u32     i,j,f1start,f1end,f2start,f2end,widthcount;
    u8      *address1,*address2;
	
    // initialise the pointers
    address1 = frame_ptr;
    address2 = frame_ptr;
	
    // Calculate the active line address & update widthcount, frame field start and end values 
    calculate_address (frame_ptr,frametype,&address1,&address2,&f1start,&f1end,&f2start,&f2end,&widthcount);
  
    // Paints active lines with provided YCbCr color value
    // Paints Field1 if frameformat is interlaced OR whole frame is frameformat is Progressive
    for(i = f1start; i <= f1end; i++)    
    {
        // Output YCbCr data (4:2:2 format)
        for(j = 0; j < (widthcount / 2); j++)
        {
            *address1++ = *ycbcr_data;
            *address1++ = *(ycbcr_data+1);
            *address1++ = *(ycbcr_data+2);
            *address1++ = *(ycbcr_data+3);
        }
        if ((frametype == ADI_ITU656_NTSC_IL) || (frametype == ADI_ITU656_NTSC_PR))
            address1 = address1 + 276;
        else
            address1 = address1 + 288;
    }
	
    // Paints Field2 only when frametype is Interlaced
    if ((frametype == ADI_ITU656_NTSC_IL) || (frametype == ADI_ITU656_PAL_IL))    
    {
    	
        for(i = f2start; i <= f2end; i++)
        {
            // Output YCbCr data (4:2:2 format)
            for(j = 0; j < (widthcount / 2); j++)
            {
                *address2++ = *ycbcr_data;
                *address2++ = *(ycbcr_data+1);
                *address2++ = *(ycbcr_data+2);
                *address2++ = *(ycbcr_data+3);
            }
        if (frametype == ADI_ITU656_NTSC_IL)
            address2 = address2 + 276;
        else
            address2 = address2 + 288;
        }
    }
}

/***************************************************************************** 
**
** Function:            adi_itu656_RowFill
**
** Description:         This function fills a row of pixels in active video 
**                      portion of formated frame with specified color
**
** Arguments:           
**
**  frame_ptr           Pointer to the formated video frame in memory
**                      
**  frametype           Frame type of the formated memory
**
**  row_value           32 bit value corresponding to row number of active field
**
**  ycbcr_data          32 bit value color value corresponding to a 4 byte array of 8-bit YCbYCr data
**
** Return value:        None
**                      
**
**
*/
void adi_itu656_RowFill ( u8 *frame_ptr,ADI_ITU656_FRAME_TYPE frametype,u32 row_value,u8 *ycbcr_data )
{

    u32     i,j,f1start,f1end,f2start,f2end,widthcount;
    u8      *address1,*address2;
          
    // initialise the pointers
    address1 = frame_ptr;
    address2 = frame_ptr;
	
    // Calculate the active line address & update widthcount, frame field start and end values 
    calculate_address (frame_ptr,frametype,&address1,&address2,&f1start,&f1end,&f2start,&f2end,&widthcount);

    // Paints active lines with provided YCbCr color value
    // Paints Field1 if frameformat is interlaced OR whole frame is frameformat is Progressive
    for(i = f1start; i <= f1end; i++)    
    {
        if (i == row_value)    // is this the row to be painted with YCbCr data?
        {
            // Output YCbCr data (4:2:2 format)
            for(j = 0; j < (widthcount / 2); j++)
            {
                *address1++ = *ycbcr_data;
                *address1++ = *(ycbcr_data+1);
                *address1++ = *(ycbcr_data+2);
                *address1++ = *(ycbcr_data+3);
            }   
        }
        else    // Paint all other rows as blank
        {
            for(j = 0; j < (widthcount); j++)
            {
                *address1++ = 0x80;
                *address1++ = 0x10;
            }   
        }
        if ((frametype == ADI_ITU656_NTSC_IL) || (frametype == ADI_ITU656_NTSC_PR))
            address1 = address1 + 276;
        else
            address1 = address1 + 288;
    }
    
    // Paints Field2 only when frametype is Interlaced
    if ((frametype == ADI_ITU656_NTSC_IL) || (frametype == ADI_ITU656_PAL_IL))    
    {
        for(i = f2start; i <= f2end; i++)
        {
            if (i == row_value)     // is this the row to be painted with YCbCr data?
            {
                // Output YCbCr data (4:2:2 format)
                for(j = 0; j < (widthcount / 2); j++)
                {
                    *address2++ = *ycbcr_data;
                    *address2++ = *(ycbcr_data+1);
                    *address2++ = *(ycbcr_data+2);
                    *address2++ = *(ycbcr_data+3);
                }   
            }
            else    // Paint all other rows as blank
            {
                for(j = 0; j < (widthcount); j++)
                {
                    *address2++ = 0x80;
                    *address2++ = 0x10;
                }   
            }
            if (frametype == ADI_ITU656_NTSC_IL)
            	address2 = address2 + 276;
        	else
            	address2 = address2 + 288;
        }
    }
}

/***************************************************************************** 
**
** Function:            adi_itu656_ColumnFill
**
** Description:         This function fills a column of pixels in active video 
**                      portion of formated frame with specified color
**
** Arguments:           
**
**  frame_ptr           Pointer to the formated video frame in memory
**                      
**  frametype           Frame type of the formated memory
**
**  column_value        32 bit value corresponding to column number of active field
**
**  ycbcr_data          32 bit value color value corresponding to a 4 byte array of 8-bit YCbYCr data
**
** Return value:        None
**                      
**
**
*/
void adi_itu656_ColumnFill ( u8 *frame_ptr,ADI_ITU656_FRAME_TYPE frametype,u32 column_value,u8 *ycbcr_data )
{

    u32     i,j,f1start,f1end,f2start,f2end,widthcount;
    u8      *address1,*address2;
    
	// initialise the pointers
    address1 = frame_ptr;
    address2 = frame_ptr;
	
    // Calculate the active line address & update widthcount, frame field start and end values 
    calculate_address (frame_ptr,frametype,&address1,&address2,&f1start,&f1end,&f2start,&f2end,&widthcount);

    // Paints active lines with provided YCbCr color value
    // Paints Field1 if frameformat is interlaced OR whole frame is frameformat is Progressive
    for(i = f1start; i <= f1end; i++)    
    {
        for(j = 0; j < (widthcount / 2); j++)
        {
            if (j == column_value)      // is this the column to be painted with YCbCr data?
            {                           // Yes, Output YCbCr data (4:2:2 format)
                *address1++ = *ycbcr_data;
                *address1++ = *(ycbcr_data+1);
                *address1++ = *(ycbcr_data+2);
                *address1++ = *(ycbcr_data+3);
            }
            else
            {                           // No - Paint the column as blank
                *address1++ = 0x80;
                *address1++ = 0x10;
                *address1++ = 0x80;
                *address1++ = 0x10;
            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -