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

📄 common.h

📁 LDPC码的实现,包括编码器和解码器,使用了DCT.
💻 H
字号:
//---------------------------------------------------------------------------
// common.h
//---------------------------------------------------------------------------
// David Chen*, David Varodayan, Markus Flierl, Bernd Girod
// Image, Video, and Multimedia Systems Group
// Information Systems Laboratory
// Stanford University
//
// *Contact: dmchen@stanford.edu
//----------------------------------------------------------------------------

#ifndef _COMMON_H_
#define _COMMON_H_
#include <stdio.h>
#include <time.h>

#pragma warning( disable : 4996 )
#pragma warning( disable : 4101 )

/* -----------------------------------------------------------------------------
 * Constants for video codec
 * -----------------------------------------------------------------------------
 */
#define BITPLANES			8
#define PI					3.14159265358979323846
#define MAX_SHIFT			5
#define NUM_SHIFTS			(2*MAX_SHIFT+1)
#define NUM_SHIFTS_2D		(NUM_SHIFTS*NUM_SHIFTS)
#define BLOCK_SIZE			8
#define BLOCK_SIZE_QUAD		4
#define BLOCK_ROWS			18
#define BLOCK_COLS			22
#define BLOCKS				(BLOCK_ROWS*BLOCK_COLS)
#define HEIGHT				(BLOCK_SIZE*BLOCK_ROWS)
#define WIDTH				(BLOCK_SIZE*BLOCK_COLS)
#define PIXELS				(WIDTH*HEIGHT)
#define BITS				(PIXELS*BITPLANES)
#define BLOCK_ROWS_QUAD		9
#define BLOCK_COLS_QUAD		11
#define BLOCKS_QUAD			(BLOCK_ROWS_QUAD*BLOCK_COLS_QUAD)
#define HEIGHT_QUAD			(BLOCK_SIZE*BLOCK_ROWS_QUAD)
#define WIDTH_QUAD			(BLOCK_SIZE*BLOCK_COLS_QUAD)
#define PIXELS_QUAD			(WIDTH_QUAD*HEIGHT_QUAD)
#define BITS_QUAD			(PIXELS_QUAD*BITPLANES)
#define MAX_ITERATIONS		50
#define NUM_COEFFS			(BLOCK_SIZE*BLOCK_SIZE)
#define NUM_COEFFS_QUAD		(NUM_COEFFS/4)
#define LEVELS				256
#define MIN_LAPLACIAN		0.1
#define MAX_LAPLACIAN		5.00
#define NUM_Q_FACTORS		4
#define CODING_IPPPPPPP		0
#define CODING_IPIPIPIP		1
#define CODING_SINGLE_I		2
#define RECON_MOTION		0
#define RECON_CENTROID		1
#define QUANT_JPEG			0
#define QUANT_FLAT			1
#define INTERP_NN			1
#define INTERP_LINEAR		2

/* -----------------------------------------------------------------------------
 * String descriptions of options
 * -----------------------------------------------------------------------------
 */
static const char* CodingStructureName[4] = { "ippppppp", "ipipipip", "single-i" };
static const char* ReconstructName[2] = { "motion", "centroid" };
static const char* QuantizationArrayName[2] = { "jpeg", "flat" };
static const char* InterpolationName[3] = {" ", "nearest neighbor", "bilinear" };

/* -----------------------------------------------------------------------------
 * Quantization tables for blockwise DCT
 * -----------------------------------------------------------------------------
 */
static const short QArrayUnity[NUM_COEFFS] = 
{ 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1
};

static const short QArrayJPEG[NUM_COEFFS] = 
{ 16, 11, 10, 16, 24, 40, 51, 61,
  12, 12, 14, 19, 26, 58, 60, 55,
  14, 13, 16, 24, 40, 57, 69, 56,
  14, 17, 22, 29, 51, 87, 80, 62,
  18, 22, 37, 56, 68, 109, 103, 77,
  24, 35, 55, 64, 81, 104, 113, 92, 
  49, 64, 78, 87, 103, 121, 120, 101, 
  72, 92, 95, 98, 112, 100, 103, 99 
};

static const short QArrayFlat[NUM_COEFFS] = 
{ 16, 16, 16, 16, 16, 16, 16, 16,
  16, 16, 16, 16, 16, 16, 16, 16,
  16, 16, 16, 16, 16, 16, 16, 16,
  16, 16, 16, 16, 16, 16, 16, 16,
  16, 16, 16, 16, 16, 16, 16, 16,
  16, 16, 16, 16, 16, 16, 16, 16,
  16, 16, 16, 16, 16, 16, 16, 16,
  16, 16, 16, 16, 16, 16, 16, 16
};

/* -----------------------------------------------------------------------------
 * Structure to describe coding options
 * -----------------------------------------------------------------------------
 */
typedef struct CodingOptionTags
{
	bool  bSaveDecodedFrame;			// Saves decoded frame
	bool  bSaveMotionField;				// Saves decoded motion field
	int   nInterpolateMethod;			// INTERP_NN, INTERP_LINEAR
	bool  bMotionEstimate;				// Use the blockwise motion estimator
	bool  bMotionOracle;				// Use a motion oracle
	char  pExperimentFolderName[1024];  // Folder for experiment
	char  pLadderFileName[1024];		// Ladder file name
	char  pLogFileName[1024];			// Log file name
	char  pLogFileRDName[1024];			// Log file RD name (only RD points)
	FILE* pLogFile;						// Log file handle
	FILE* pLogFileRD;					// Log file RD
	char  pLastImageName[1024];			// Last saved image's name
	char  pVideoFileName[1024];         // Name of input video file
	int   nCodingStructure;				// CODING_IPPPPPPP, CODING_IPIPIPIP, CODING_SINGLE_I
	int   nReconstructMethod;			// RECON_MOTION, RECON_CENTROID
	int   nQuantizationArray;			// QUANT_JPEG, QUANT_FLAT
	int   nQuantizationLevel;			// 0, 1, 2, 3 (larger = coarser quantization)
	int   nStartFrame;
	int   nEndFrame;
	int	  nCurrFrame;
	bool  bTestMotionLearning;
	bool  bTestMotionOracle;
	bool  bTestZeroMotion;
	bool  bTestIntra;
} CodingOption;

/* -----------------------------------------------------------------------------
 * fprintTitle
 * -----------------------------------------------------------------------------
 * Prints a subsection title in a file.
 *
 * Inputs:
 * FILE* pFile -- handle to file
 * const char* pTitle -- title of subsection
 * const char* pTabs -- indentation tabs
 * -----------------------------------------------------------------------------
 */
int fprintTitle(FILE* pFile, const char* pTitle, const char* pTabs = NULL);

/* -----------------------------------------------------------------------------
 * printTitle
 * -----------------------------------------------------------------------------
 * Prints a subsection title to stdout.
 *
 * Inputs:
 * const char* pTitle -- title of subsection
 * const char* pTabs -- indentation tabs
 * -----------------------------------------------------------------------------
 */
int printTitle(const char* pTitle, const char* pTabs = NULL);

/* -----------------------------------------------------------------------------
 * Convenience macros for printing
 * -----------------------------------------------------------------------------
 */
#define SCREEN_AND_LOG(pTextBuffer, pLogFile) \
	printf(pTextBuffer); fprintf(pLogFile, pTextBuffer); fflush(stdout); fflush(pLogFile);

#define SCREEN_AND_LOG_TITLE(pTextBuffer, pLogFile) \
	printTitle(pTextBuffer); fprintTitle(pLogFile, pTextBuffer); 

/* -----------------------------------------------------------------------------
 * timeStamp
 * -----------------------------------------------------------------------------
 * Generates a string representative of the current time.
 *
 * Outputs:
 * const char* pTimeString
 * -----------------------------------------------------------------------------
 */
const char* timeStamp();

/* -----------------------------------------------------------------------------
 * saveDecodedFrame
 * -----------------------------------------------------------------------------
 * Saves the decoded frame to three separate JPEG files.
 *
 * Inputs:
 * CodingOption* pOption -- structure containing all coding options
 * const char* pDescriptor -- description for current decoding mode
 * short** pDecodedFrame -- YUV [4:2:0] frame
 * -----------------------------------------------------------------------------
 */
int saveDecodedFrame(CodingOption* pOption, const char* pDescriptor, const short** pDecodedFrame);

/* -----------------------------------------------------------------------------
 * saveDecodedMotion
 * -----------------------------------------------------------------------------
 * Saves the decoded motion field and probability to two separate JPEG files.
 *
 * Inputs:
 * CodingOption* pOption -- structure containing all coding options
 * const char* pDescriptor -- description for current decoding mode
 * const short** pDecodedShiftsX
 * const short** pDecodedShiftsY
 * -----------------------------------------------------------------------------
 */
int saveDecodedMotion(CodingOption* pOption, const char* pDescriptor, const short** pDecodedShiftsX, const short** pDecodedShiftsY, const float** pDecodedShiftProb);

#endif

⌨️ 快捷键说明

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