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

📄 common.cpp

📁 LDPC码的实现,包括编码器和解码器,使用了DCT.
💻 CPP
字号:
// common.cpp

//------------------------------------------------------------
// David Chen*, David Varodayan, Markus Flierl, Bernd Girod
// Image, Video, and Multimedia Systems Group
// Information Systems Laboratory
// Stanford University
//
// *Contact: dmchen@stanford.edu
//------------------------------------------------------------

#include "common.h"
#include <ChenImage.h>
#include <ChenImageMatlab.h>

int fprintTitle(FILE* pFile, const char* pTitle, const char* pTabs)
{
	const char* pTabsDecide = (pTabs == NULL ? "" : pTabs); 
	fprintf(pFile, "%s-------------------------------------------\n", pTabsDecide);
	fprintf(pFile, "%s%s\n", pTabsDecide, pTitle);
	fprintf(pFile, "%s-------------------------------------------\n", pTabsDecide);
	fflush(pFile);
	return GOOD_RETURN;
}

int printTitle(const char* pTitle, const char* pTabs) 
{
	fprintTitle(stdout, pTitle, pTabs);
	return GOOD_RETURN;
}

const char* timeStamp()
{
	time_t nTime = time(NULL);
	char* pTimeText = ctime(&nTime);
	for (int nChar = 0; nChar < (int)strlen(pTimeText); nChar++) {
		if (pTimeText[nChar] == ' ' || pTimeText[nChar] == ':') pTimeText[nChar] = '-';
	}
	pTimeText[strlen(pTimeText)-1] = '\0';
	return pTimeText;
}

int saveDecodedFrame(CodingOption* pOption, const char* pDescriptor, const short** pDecodedFrame)
{
	bool bSuccess = true;
	int nQuality = 100;

	char pTextBuffer[1024];
	sprintf(pTextBuffer, "mkdir %s\\quant-%d-images", pOption->pExperimentFolderName, pOption->nQuantizationLevel);
	SAFE_FUNC( ChenImageMatlab_systemCommand(pTextBuffer) );

	// Save Y component
	sprintf(pOption->pLastImageName, "%s\\quant-%d-images\\quant-%d-frame-%d-%s-Y.jpg", pOption->pExperimentFolderName, pOption->nQuantizationLevel, pOption->nQuantizationLevel, pOption->nCurrFrame, pDescriptor);
	RECORD_SUCCESS( ChenImageMatlab_saveImageJPEG(pOption->pLastImageName, WIDTH, HEIGHT, 1, pDecodedFrame[0], nQuality), bSuccess );
	
	// Save U component
	sprintf(pOption->pLastImageName, "%s\\quant-%d-images\\quant-%d-frame-%d-%s-U.jpg", pOption->pExperimentFolderName, pOption->nQuantizationLevel, pOption->nQuantizationLevel, pOption->nCurrFrame, pDescriptor);
	RECORD_SUCCESS( ChenImageMatlab_saveImageJPEG(pOption->pLastImageName, WIDTH/2, HEIGHT/2, 1, pDecodedFrame[1], nQuality), bSuccess );
	
	// Save V component
	sprintf(pOption->pLastImageName, "%s\\quant-%d-images\\quant-%d-frame-%d-%s-V.jpg", pOption->pExperimentFolderName, pOption->nQuantizationLevel, pOption->nQuantizationLevel, pOption->nCurrFrame, pDescriptor);
	RECORD_SUCCESS( ChenImageMatlab_saveImageJPEG(pOption->pLastImageName, WIDTH/2, HEIGHT/2, 1, pDecodedFrame[2], nQuality), bSuccess );
	
	return bSuccess ? GOOD_RETURN : BAD_RETURN;
}

int saveDecodedMotion(CodingOption* pOption, const char* pDescriptor, const short** pDecodedShiftsX, const short** pDecodedShiftsY, const float** pDecodedShiftProb)
{
	bool bSuccess = true;
	int nQuality = 100;

	char pTextBuffer[1024];
	sprintf(pTextBuffer, "mkdir %s\\quant-%d-images", pOption->pExperimentFolderName, pOption->nQuantizationLevel);
	SAFE_FUNC( ChenImageMatlab_systemCommand(pTextBuffer) );

	short* pDecodedShiftsXLocal = new short[BLOCKS_QUAD];
	short* pDecodedShiftsYLocal = new short[BLOCKS_QUAD];
	short* pDecodedShiftProbLocal = new short[BLOCKS_QUAD];
	for (int nQuad = 0; nQuad < 6; nQuad++) {
		// Level shift motion fields
		for (int nBlock = 0; nBlock < BLOCKS_QUAD; nBlock++) {
			pDecodedShiftsXLocal[nBlock] = pDecodedShiftsX[nQuad][nBlock] + MAX_SHIFT;
			pDecodedShiftsYLocal[nBlock] = pDecodedShiftsY[nQuad][nBlock] + MAX_SHIFT;
			if (pDecodedShiftProb != NULL)
				pDecodedShiftProbLocal[nBlock] = (short)ROUND(pDecodedShiftProb[nQuad][nBlock] * 255);
		}

		// Save X component
		sprintf(pOption->pLastImageName, "%s\\quant-%d-images\\quant-%d-frame-%d-%s-quad-%d-motionX.jpg", pOption->pExperimentFolderName, pOption->nQuantizationLevel, pOption->nQuantizationLevel, pOption->nCurrFrame, pDescriptor, nQuad);
		RECORD_SUCCESS( ChenImageMatlab_saveImageJPEG(pOption->pLastImageName, BLOCK_COLS_QUAD, BLOCK_ROWS_QUAD, 1, pDecodedShiftsXLocal, nQuality), bSuccess );

		// Save Y component
		sprintf(pOption->pLastImageName, "%s\\quant-%d-images\\quant-%d-frame-%d-%s-quad-%d-motionY.jpg", pOption->pExperimentFolderName, pOption->nQuantizationLevel, pOption->nQuantizationLevel, pOption->nCurrFrame, pDescriptor, nQuad);
		RECORD_SUCCESS( ChenImageMatlab_saveImageJPEG(pOption->pLastImageName, BLOCK_COLS_QUAD, BLOCK_ROWS_QUAD, 1, pDecodedShiftsYLocal, nQuality), bSuccess );

		// Save probability component
		if (pDecodedShiftProb != NULL) {
			sprintf(pOption->pLastImageName, "%s\\quant-%d-images\\quant-%d-frame-%d-%s-quad-%d-motionP.jpg", pOption->pExperimentFolderName, pOption->nQuantizationLevel, pOption->nQuantizationLevel, pOption->nCurrFrame, pDescriptor, nQuad);
			RECORD_SUCCESS( ChenImageMatlab_saveImageJPEG(pOption->pLastImageName, BLOCK_COLS_QUAD, BLOCK_ROWS_QUAD, 1, pDecodedShiftProbLocal, nQuality), bSuccess );
		}
	}
	delete [] pDecodedShiftProbLocal;
	delete [] pDecodedShiftsXLocal;
	delete [] pDecodedShiftsYLocal;
	return bSuccess ? GOOD_RETURN : BAD_RETURN;
}

⌨️ 快捷键说明

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