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

📄 dctprocess.c

📁 在ccs开发环境下实现的基于dsp的图像二维dct变换和压缩,完整可实现的工程文件, 源文件算法清晰,良好的实现效果
💻 C
字号:
#include "DCTProcess.h"

// #define _DEBUG

int m_iEncPels;
int m_iEncLines;

BYTE * m_pCurImage;	// Current encoding image
BYTE * m_pCurCb;
BYTE * m_pCurCr;
//int16 *m_pYdct;//by spinous, 2005-01-27, to store DCT coefficients of the frame
BYTE * m_pReconImage;	// Reconstruct image
BYTE * m_pReconCb;
BYTE * m_pReconCr;
BYTE * m_pResImage;
BYTE * m_pResCb;
BYTE * m_pResCr;

// Used in MB
int16 m_iBlock[MB_LENGTH*(MB_SECTION+1)];

// Used in reading Gobs of codec(for Dma)
BYTE m_pGobY[DATA_PELS * MB_SIZE * 3 / 2];
BYTE *m_pGobCr, *m_pGobCb;

//spinous, 2005-01-27
BYTE m_pGobY_DCT[DATA_PELS * MB_SIZE * 3 / 2];


void Init_Process(int iFormat)
{
//Set for CIF Format, spinous, 2005-01-28
	m_iEncLines = CIF_LINES;
	m_iEncPels = CIF_PELS;
//Set for QCIF Format, spinous, 2005-01-28
//	m_iEncLines = QCIF_LINES;
//	m_iEncPels = QCIF_PELS;

	// For DMA use
	m_pGobCb = m_pGobY + DATA_PELS * MB_SIZE;
	m_pGobCr = m_pGobCb + DATA_PELS * (MB_SIZE >> 2);
	
}

void DCTProcess(BYTE *pYmage, BYTE *pUmage,BYTE *pVmage, BYTE *pReconImage, BYTE *pResImage, BYTE threshold)
{
	int iLumSize, iChromSize; 
	
//!>	Process(ReconPic, threshold);
	int i, j, x, y, iLines, iPels, k;
	UINT32 *pDataY, *pDataCr, *pDataCb;
	BYTE *ResidualY;//Pointer to residual image Y
	BYTE *ResidualCb;//Pointer to residual image U
	BYTE *ResidualCr;//Pointer to residual image V
	BYTE *CurrentY;//Pointer to input image Y
	BYTE *ReconY;//Pointer to recon image Y
	int16 *p = m_iBlock;
	
	//Init, spinous, 2005-01-29
	iLumSize = m_iEncLines * m_iEncPels;
	iChromSize = iLumSize / 4;
	//Pointer to input image buffer	
	m_pCurImage = pYmage;
	m_pCurCb = pUmage; 
	m_pCurCr = pVmage;
	//Pointer to recon image buffer
	m_pReconImage = pReconImage;
	m_pReconCb = m_pReconImage + iLumSize;
	m_pReconCr = m_pReconCb + iChromSize;
	//Pointer to residual image buffer
	m_pResImage = pResImage;
	m_pResCb = m_pResImage + iLumSize;
	m_pResCr = m_pResCb + iChromSize;
	
	CurrentY = m_pCurImage;
	
	ResidualY = m_pResImage;
	ResidualCb = m_pResCb;
	ResidualCr = m_pResCr;
	ReconY = m_pReconImage;

	iLines = m_iEncLines/MB_SIZE;
	iPels = m_iEncPels/MB_SIZE;


	for (j = 0; j < iLines; j ++)
	{
		// Transfer one Gob;
		pDataY = (UINT32 *)(m_pCurImage + j * (m_iEncPels << 4));//以MB为处理单元取数,16行
		pDataCb = (UINT32 *)(m_pCurCb + j * (m_iEncPels << 2));	//UV分量块大小为8x8,8行
		pDataCr = (UINT32 *)(m_pCurCr + j * (m_iEncPels << 2));	//UV分量块大小为8x8,8行
		
//m_pGobY中存放的是当前帧的数据		
		memcpy((UINT32 *)m_pGobY, pDataY, (m_iEncPels << 2) * sizeof(UINT32));	// Channel A
		memcpy((UINT32 *)m_pGobCb, pDataCb, m_iEncPels * sizeof(UINT32));	// Channel B
		memcpy((UINT32 *)m_pGobCr, pDataCr, m_iEncPels * sizeof(UINT32));	// Channel C
	
		for (i = 0; i < iPels; i ++)
		{
			x = i * MB_SIZE;//img_x
			y = j * MB_SIZE;//img_y

			MB_FillData(x, y);//Get one MB data packed as 8x8 block
//perform 6 FDCT once,and store the results in the corresponding position of m_iBlock						
//			MB_Dct();
			IMG_fdct_8x8(p, 6);

//限幅,将DCT变换值小于10的元素设为0, spinous, 2005-01-28			
			for(k=0; k< DATA_PELS*MB_SIZE; k++)
				if(abs(p[k])<threshold && p[k]!=0) 
					p[k] = 0;

//perform 6 iDCT once,and store the results in the corresponding position of m_iBlock
//			MB_iDct();
			IMG_idct_8x8(p, 6);
			MB_ReconData(x, y);
		}
		pDataY = (UINT32 *)(m_pReconImage + j * (m_iEncPels << 4));
		pDataCb = (UINT32 *)(m_pReconCb + j * (m_iEncPels << 2));
		pDataCr = (UINT32 *)(m_pReconCr + j * (m_iEncPels << 2));

//m_pGobY中存放的是重建帧的数据
		memcpy(pDataY, (UINT32 *)m_pGobY, (m_iEncPels << 2) * sizeof(UINT32));	// Channel A
		memcpy(pDataCb, (UINT32 *)m_pGobCb, m_iEncPels * sizeof(UINT32));	// Channel B
		memcpy(pDataCr, (UINT32 *)m_pGobCr, m_iEncPels * sizeof(UINT32));	// Channel C
	}

//To get the residual image of the DCT mismatch, spinous, 2005-01-27
	for(i=0; i<DATA_LINES*DATA_PELS; i++)
		*ResidualY++ = abs((*CurrentY ++) - (*ReconY++))+128;
	for(i=0; i<(DATA_LINES*DATA_PELS)/4; i++)
	{
		*ResidualCb++ = 128;
		*ResidualCr++ = 128;
	}
}

⌨️ 快捷键说明

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