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

📄 quantize.c

📁 魔兽2Linux版
💻 C
📖 第 1 页 / 共 3 页
字号:
#define PBDLL#define COMPDLL//==========================================================================////  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR//  PURPOSE.////  Copyright (c) 1999 - 2001  On2 Technologies Inc. All Rights Reserved.////--------------------------------------------------------------------------/******************************************************************************   Module Title :     Quantise**   Description  :     Quantisation and dequanitsation of an 8x8 dct block. .********************************************************************************/						/*****************************************************************************  Header Frames******************************************************************************/#define STRICT              /* Strict type checking. */#include <string.h>  #include "pbdll.h"/*****************************************************************************  Module constants.******************************************************************************/        // MIN_LEGAL_QUANT_ENTRY = (X * the dct normalisation factor(4))// Designed to keep quantised values within the required number of bits#define MIN_LEGAL_QUANT_ENTRY	8  #define MIN_DEQUANT_VAL			2// Scale factors used to improve precision of DCT/IDCT#define IDCT_SCALE_FACTOR       2       // Shift left bits to improve IDCT precision//#define DCT_SCALE_FACTOR        4.0   // Not used at the moment#define OLD_SCHEME	1/*****************************************************************************  Imported Functions******************************************************************************//*****************************************************************************  Imported Global Variables******************************************************************************//*****************************************************************************  Exported Global Variables******************************************************************************/#ifdef COMPDLL#include "compdll.h"void init_quantizer ( CP_INSTANCE *cpi, UINT32 scale_factor, UINT8 QIndex );#endifvoid init_dequantizer ( PB_INSTANCE *pbi, UINT32 scale_factor, UINT8 QIndex );/*****************************************************************************  Foreward References******************************************************************************/              /*****************************************************************************  Module Statics******************************************************************************/      // Table that relates quality index values to quantizer values#ifdef PBDLL  	UINT32 QThreshTableV1[Q_TABLE_SIZE] = { 500,  450,  400,  370,  340,  310, 285, 265,  245,  225,  210,  195,  185,  180, 170, 160,   150,  145,  135,  130,  125,  115, 110, 107,  100,   96,   93,   89,   85,   82,  75,  74,   70,   68,   64,   60,   57,   56,  52,  50,     49,   45,   44,   43,   40,   38,  37,  35,     33,   32,   30,   29,   28,   25,  24,  22,   21,   19,   18,   17,   15,   13,  12,  10 };Q_LIST_ENTRY DcScaleFactorTableV1[ Q_TABLE_SIZE ] = { 220, 200, 190, 180, 170, 170, 160, 160,  150, 150, 140, 140, 130, 130, 120, 120,  110, 110, 100, 100, 90,  90,  90,  80,  80,  80,  70,  70,  70,  60,  60,  60,  60,  50,  50,  50,  50,  40,  40,  40,  40,  40,  30,  30,  30,  30,  30,  30,  30,  20,  20,  20,  20,  20,  20,  20,  20,  10,  10,  10,  10,  10,  10,  10 };Q_LIST_ENTRY Y_coeffsV1[64] ={	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,  58,  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};Q_LIST_ENTRY UV_coeffsV1[64] ={	17,	18,	24,	47,	99,	99,	99,	99,	18,	21,	26,	66,	99,	99,	99,	99,	24,	26,	56,	99,	99,	99,	99,	99,	47,	66,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99,	99};// Different matrices for different encoder versionsQ_LIST_ENTRY Inter_coeffsV1[64] ={   16,  16,  16,  20,  24,  28,  32,  40,	16,  16,  20,  24,  28,  32,  40,  48,     16,  20,  24,  28,  32,  40,  48,  64, 	20,  24,  28,  32,  40,  48,  64,  64, 	24,  28,  32,  40,  48,  64,  64,  64, 	28,  32,  40,  48,  64,  64,  64,  96,  	32,  40,  48,  64,  64,  64,  96,  128, 	40,  48,  64,  64,  64,  96,  128, 128};#else#ifdef COMPDLLextern UINT32 QThreshTableV1[Q_TABLE_SIZE] ; extern Q_LIST_ENTRY DcScaleFactorTableV1[ Q_TABLE_SIZE ] ; extern Q_LIST_ENTRY DcScaleFactorTableUV[ Q_TABLE_SIZE ] ; extern Q_LIST_ENTRY Y_coeffsV1[64] ;extern Q_LIST_ENTRY UV_coeffsV1[64] ;extern Q_LIST_ENTRY Inter_coeffsV1[64] ;#endif #endif /*	Inverse fast DCT index											*//*	This contains the offsets needed to convert zigzag order into	*//*	x, y order for decoding. It is generated from the input zigzag	*//*	indexat run time.												*//*	For maximum speed during both quantisation and dequantisation	*//*	we maintain separate quantisation and zigzag tables for each	*//*	operation.														*//*	pbi->quant_index:	the zigzag index used during quantisation		*//*	dequant_index:	zigzag index used during dequantisation			*//*					the pbi->quant_index is the inverse of dequant_index	*//*					and is calculated during initialisation			*//*	pbi->quant_Y_coeffs:	quantising coefficients used, corrected for		*//*					compression ratio and DCT algorithm-specific	*//*					scaling, for the Y plane						*//*	pbi->quant_UV_coeffs	similar for the UV planes						*//*	pbi->dequant_Y_coeffs similarly adjusted Y coefficients for			*//*					dequantisation, also reordered for zigzag		*//*					indexing										*//*	pbi->dequant_UV_coeffs ditto for UV planes							*/#ifdef PBDLL  	UINT32 dequant_index[64] = {	0,  1,  8,  16,  9,  2,  3, 10,	17, 24, 32, 25, 18, 11,  4,  5,    12, 19, 26, 33, 40, 48, 41, 34,    27, 20, 13,  6,  7, 14, 21, 28,    35, 42, 49, 56, 57, 50, 43, 36,     29, 22, 15, 23, 30, 37, 44, 51,    58, 59, 52, 45, 38, 31, 39, 46,    53, 60, 61, 54, 47, 55, 62, 63};#elseextern UINT32 dequant_index[64];#endif #ifdef PBDLL/**************************************************************************** *  *  ROUTINE       :     InitQTables * *  INPUTS        :      * *  OUTPUTS       :     None. * *  RETURNS       :     None * *  FUNCTION      :     Initialises Q tables based upon version number * *  SPECIAL NOTES :     None.  * * *  ERRORS        :     None. * ****************************************************************************/void InitQTables( PB_INSTANCE *pbi ){  	// Make version specific assignments.	memcpy ( pbi->QThreshTable, QThreshTableV1, sizeof( pbi->QThreshTable ) );}/**************************************************************************** *  *  ROUTINE       :     BuildQuantIndex_Generic * *  INPUTS        :      *                       * *  OUTPUTS       :     None. * *  RETURNS       :     None * *  FUNCTION      :     Builds the quant_index table. * *  SPECIAL NOTES :     None.  * * *  ERRORS        :     None. * ****************************************************************************/void BuildQuantIndex_Generic(PB_INSTANCE *pbi){    INT32 i,j;    // invert the dequant index into the quant index	for ( i = 0; i < BLOCK_SIZE; i++ )	{	        j = dequant_index[i];		pbi->quant_index[j] = i;	}}/**************************************************************************** *  *  ROUTINE       :     UpdateQ * *  INPUTS        :     UINT32  NewQ *                              (A New Q value (50 - 1000)) * *  OUTPUTS       :     None. * *  RETURNS       :     None * *  FUNCTION      :     Updates the quantisation tables for a new Q * *  SPECIAL NOTES :     None.  * * *  ERRORS        :     None. * ****************************************************************************/void UpdateQ( PB_INSTANCE *pbi, UINT32 NewQ ){      UINT32 qscale;	// Do bounds checking and convert to a float. 	qscale = NewQ; 	if ( qscale < pbi->QThreshTable[Q_TABLE_SIZE-1] )		qscale = pbi->QThreshTable[Q_TABLE_SIZE-1];	else if ( qscale > pbi->QThreshTable[0] )	   qscale = pbi->QThreshTable[0];       	// Set the inter/intra descision control variables.	pbi->FrameQIndex = Q_TABLE_SIZE - 1;	while ( (INT32) pbi->FrameQIndex >= 0 )	{		if ( (pbi->FrameQIndex == 0) || ( pbi->QThreshTable[pbi->FrameQIndex] >= NewQ) )			break;		pbi->FrameQIndex --;	}	// Re-initialise the q tables for forward and reverse transforms.    	init_dequantizer ( pbi, qscale, (UINT8) pbi->FrameQIndex );}#endif /********************* COMPRESSOR SPECIFIC **********************************/#ifdef COMPDLL/**************************************************************************** *  *  ROUTINE       :     UpdateQC (compressor's update q) * *  INPUTS        :     UINT32  NewQ *                              (A New Q value (50 - 1000)) * *  OUTPUTS       :     None. * *  RETURNS       :     None * *  FUNCTION      :     Updates the quantisation tables for a new Q * *  SPECIAL NOTES :     None.  * * *  ERRORS        :     None. * ****************************************************************************/void UpdateQC( CP_INSTANCE *cpi, UINT32 NewQ ){      UINT32 qscale;	PB_INSTANCE *pbi = &cpi->pb;    // Do bounds checking and convert to a float.     qscale = NewQ;     if ( qscale < pbi->QThreshTable[Q_TABLE_SIZE-1] )        qscale = pbi->QThreshTable[Q_TABLE_SIZE-1];    else if ( qscale > pbi->QThreshTable[0] )       qscale = pbi->QThreshTable[0];           // Set the inter/intra descision control variables.    pbi->FrameQIndex = Q_TABLE_SIZE - 1;    while ((INT32) pbi->FrameQIndex >= 0 )    {        if ( (pbi->FrameQIndex == 0) || ( pbi->QThreshTable[pbi->FrameQIndex] >= NewQ) )            break;

⌨️ 快捷键说明

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