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

📄 postproc.c

📁 魔兽2Linux版
💻 C
📖 第 1 页 / 共 3 页
字号:
            dstRow[ rowOffset +0]= (INT8)newPixel[0];            dstRow[ rowOffset +1]= (INT8)newPixel[1];            dstRow[ rowOffset +2]= (INT8)newPixel[2];            dstRow[ rowOffset +3]= (INT8)newPixel[3];            dstRow[ rowOffset +4]= (INT8)newPixel[4];            dstRow[ rowOffset +5]= (INT8)newPixel[5];            dstRow[ rowOffset +6]= (INT8)newPixel[6];            dstRow[ rowOffset +7]= (INT8)newPixel[7];                        rowOffset += Pitch;    }}/**************************************************************************** *  *  ROUTINE       :     DeringBlockWeak() * *  INPUTS        :     None *                                *  OUTPUTS       :     None * *  RETURNS       :     None * *  FUNCTION      :     Filtering a block for deringing purpose * *  SPECIAL NOTES :      * *  ERRORS        :     None. * ****************************************************************************/void DeringBlockWeak(                      PB_INSTANCE *pbi,                      UINT8 *SrcPtr,                     UINT8 *DstPtr,                     INT32 Pitch,                     UINT32 FragQIndex,                     UINT32 *QuantScale){    short UDMod[72];    short LRMod[72];    unsigned int j,k;    const unsigned char * Src = SrcPtr;    unsigned int QValue = QuantScale[FragQIndex];    unsigned char p           ;    unsigned char pl          ;    unsigned char pr          ;    unsigned char pu          ;    unsigned char pd          ;    int  al          ;    int  ar          ;    int  au          ;    int  ad          ;    int  atot        ;    int  B           ;    int newVal      ;    const unsigned char *curRow = SrcPtr;    unsigned char *dstRow = DstPtr;    const unsigned char *lastRow = SrcPtr-Pitch;    const unsigned char *nextRow = SrcPtr+Pitch;        unsigned int rowOffset = 0;    unsigned int round = (1<<6);    int High;    int Low;    int TmpMod;    int Sharpen = SharpenModifier[FragQIndex];    //Sharpen = 0;    (void) pbi;    Low = 0 - QValue;    High = 3 * QValue;        if(High>24)        High=24;        if(Low < -16)        Low = -16;    Low = 0 ;    /* Initialize the Mod Data */    for(k=0;k<9;k++)    {                   for(j=0;j<8;j++)        {                        TmpMod = 32 + QValue - 2*(abs(Src[j]-Src[j-Pitch]));            if(TmpMod< -64)                TmpMod = Sharpen;            else if(TmpMod<Low)                TmpMod = Low;                        else if(TmpMod>High)                TmpMod = High;                        UDMod[k*8+j] = (INT16)TmpMod;        }        Src +=Pitch;    }    Src = SrcPtr;    for(k=0;k<8;k++)    {                   for(j=0;j<9;j++)        {            TmpMod = 32 + QValue - 2*(abs(Src[j]-Src[j-1]));                        if(TmpMod< -64 )                TmpMod = Sharpen;            else if(TmpMod<Low)                TmpMod = Low;                        else if(TmpMod>High)                TmpMod = High;            LRMod[k*9+j] = (INT16)TmpMod;        }        Src+=Pitch;    }    for(k=0;k<8;k++)    {        // loop expanded for speed        for(j=0;j<8;j++)        {            // column 0             atot = 128;            B = round;            p = curRow[ rowOffset +j];                        pl = curRow[ rowOffset +j-1];            al = LRMod[k*9+j];            atot -= al;            B += al * pl;                        pu = lastRow[ rowOffset +j];            au = UDMod[k*8+j];            atot -= au;            B += au * pu;                        pd = nextRow[ rowOffset +j];            ad = UDMod[(k+1)*8+j];            atot -= ad;            B += ad * pd;                        pr = curRow[ rowOffset +j+1];            ar = LRMod[k*9+j+1];            atot -= ar;            B += ar * pr;                        newVal = ( atot * p + B) >> 7;                        dstRow[ rowOffset +j] = (INT8) Clamp( newVal );        }                rowOffset += Pitch;    }}/**************************************************************************** *  *  ROUTINE       :     DeringBlock() * *  INPUTS        :     None *                                *  OUTPUTS       :     None * *  RETURNS       :     None * *  FUNCTION      :     Filtering a block for deringing purpose * *  SPECIAL NOTES :      * *  ERRORS        :     None. * ****************************************************************************/void DeringBlock(                  const PB_INSTANCE *pbi,                  const UINT8 *SrcPtr,                 UINT8 *DstPtr,                 const INT32 Pitch,                 UINT32 FragQIndex,                 const UINT32 *QuantScale,                 UINT32 Variance){    int N[8];   // neighbors    unsigned int j,k,l;    unsigned int QValue = QuantScale[FragQIndex];    int  atot        ;    int  B           ;    int newVal      ;    const unsigned char *srcRow = SrcPtr;    unsigned char *dstRow = DstPtr;        unsigned int round = (1<<7);    int High;    int Low;    int TmpMod;    int Sharpen = SharpenModifier[FragQIndex];    int Slope = 4;    if(pbi->PostProcessingLevel > 100)    {        QValue = pbi->PostProcessingLevel - 100;    }        //if(Variance > 262144 )    //{    //    Slope = 1;    //}    if ( Variance > 32768)    {        Slope = 4;    }    else if (Variance > 2048)    {        Slope = 8;    }                Low = 0 - QValue;    High = 3 * QValue;        if(High>32)        High=32;        if(Low < -16)        Low = -16;    Low = 0 ;    for(k=0;k<8;k++)    {        // loop expanded for speed        for(j=0;j<8;j++)        {            // set up 8 neighbors of pixel srcRow[j]            N[0] = srcRow[j  -Pitch  -1];             N[1] = srcRow[j  -Pitch    ];             N[2] = srcRow[j  -Pitch  +1];            N[3] = srcRow[j          -1];            N[4] = srcRow[j          +1];            N[5] = srcRow[j  +Pitch  -1];            N[6] = srcRow[j  +Pitch    ];            N[7] = srcRow[j  +Pitch  +1];            // column 0             atot = 256;            B = round;            for(l = 0; l<8; l++)            {                TmpMod = 32 + QValue - (Slope *(abs(srcRow[j]-N[l])) >> 2);                                if(TmpMod< -64)                    TmpMod = Sharpen;                                else if(TmpMod<Low)                    TmpMod = Low;                                else if(TmpMod>High)                    TmpMod = High;                atot -= TmpMod;                B += TmpMod * N[l];            }                       newVal = ( atot * srcRow[j] + B) >> 8;                        dstRow[j] = (INT8) Clamp( newVal );        }                dstRow += Pitch;        srcRow += Pitch;    }}/**************************************************************************** *  *  ROUTINE       :     DeringFrame * *  INPUTS        :     None *                                *  OUTPUTS       :     None * *  RETURNS       :     None * *  FUNCTION      :     Filtering the frame for deringing purpose * *  SPECIAL NOTES :     Due to the changes in the deblocking stage, the  *                      variances are now actually the accumulated SAD * *  ERRORS        :     None. * ****************************************************************************/void DeringFrame(PB_INSTANCE *pbi, UINT8 *Src, UINT8 *Dst){    UINT32  col,row;	UINT8  *SrcPtr;	            // Pointer to line of source image data	UINT8  *DestPtr;            // Pointer to line of destination image data	UINT32 BlocksAcross,BlocksDown;	UINT32 *QuantScale;	UINT32 Block;	UINT32 LineLength;	INT32 Thresh1,Thresh2,Thresh3,Thresh4;	Thresh1 = 384;                  	Thresh2 = 4 * Thresh1;          	Thresh3 = 5 * Thresh2/4;            Thresh4 = 5 * Thresh2/2;            QuantScale = DeringModifierV1;	BlocksAcross = pbi->HFragments;	BlocksDown = pbi->VFragments;	SrcPtr = Src + pbi->ReconYDataOffset;	DestPtr = Dst + pbi->ReconYDataOffset;	LineLength = pbi->Configuration.YStride;	Block = 0;		// dering the y plane 	for ( row = 0 ; row < BlocksDown; row ++)	{		for (col = 0; col < BlocksAcross; col ++)		{			UINT32 Quality = pbi->FragQIndex[Block]; 			INT32 Variance = pbi->FragmentVariances[Block]; 						if( pbi->PostProcessingLevel >5 && Variance > Thresh3 )            			{				DeringBlockStrong(pbi, SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);								if( (col > 0                && pbi->FragmentVariances[Block-1] > Thresh4 ) ||					(col + 1 < BlocksAcross && pbi->FragmentVariances[Block+1] > Thresh4 ) ||					(row + 1 < BlocksDown   && pbi->FragmentVariances[Block+BlocksAcross] > Thresh4) ||					(row > 0                && pbi->FragmentVariances[Block-BlocksAcross] > Thresh4) )				{					DeringBlockStrong(pbi, SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);					DeringBlockStrong(pbi, SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);				}							}			else if(Variance > Thresh2 )			{				DeringBlockStrong(pbi, SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);			}			else if(Variance > Thresh1 )			{				DeringBlockWeak(pbi, SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);			}			else			{				CopyBlock(SrcPtr + 8 * col, DestPtr + 8 * col, LineLength);			}						++Block;					}		SrcPtr += 8 * LineLength;		DestPtr += 8 * LineLength;    }    // Then U	BlocksAcross /= 2;	BlocksDown /= 2;	LineLength /= 2;	SrcPtr = Src + pbi->ReconUDataOffset;	DestPtr = Dst + pbi->ReconUDataOffset;	for ( row = 0 ; row < BlocksDown; row ++)	{		for (col = 0; col < BlocksAcross; col ++)		{			UINT32 Quality = pbi->FragQIndex[Block]; 			INT32 Variance = pbi->FragmentVariances[Block]; 						if( pbi->PostProcessingLevel >5 && Variance > Thresh4 )            			{				DeringBlockStrong(pbi,SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);				DeringBlockStrong(pbi,SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);				DeringBlockStrong(pbi,SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);							}			else if(Variance > Thresh2 )			{				DeringBlockStrong(pbi,SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);			}			else if(Variance > Thresh1 )			{				DeringBlockWeak(pbi,SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);			}			else			{				CopyBlock(SrcPtr + 8 * col, DestPtr + 8 * col, LineLength);			}						++Block;					}		SrcPtr += 8 * LineLength;		DestPtr += 8 * LineLength;    }    // Then V	SrcPtr = Src + pbi->ReconVDataOffset;	DestPtr = Dst + pbi->ReconVDataOffset;	for ( row = 0 ; row < BlocksDown; row ++)	{		for (col = 0; col < BlocksAcross; col ++)		{			UINT32 Quality = pbi->FragQIndex[Block]; 			INT32 Variance = pbi->FragmentVariances[Block]; 									if( pbi->PostProcessingLevel >5 && Variance > Thresh4 )            			{				DeringBlockStrong(pbi,SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);				DeringBlockStrong(pbi,SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);				DeringBlockStrong(pbi,SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);							}			else if(Variance > Thresh2 )			{				DeringBlockStrong(pbi,SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);			}			else if(Variance > Thresh1 )			{				DeringBlockWeak(pbi,SrcPtr + 8 * col, DestPtr + 8 * col, LineLength,Quality,QuantScale);			}			else			{				CopyBlock(SrcPtr + 8 * col, DestPtr + 8 * col, LineLength);			}						++Block;				}		SrcPtr += 8 * LineLength;		DestPtr += 8 * LineLength;    }    }/**************************************************************************** *  *  ROUTINE       :     UpdateFragQIndex * *  INPUTS        :     None *                                *  OUTPUTS       :     None * *  RETURNS       :     None * *  FUNCTION      :     Update the QIndex for each updated frag * *  SPECIAL NOTES :     None * *  ERRORS        :     None. * ****************************************************************************/void UpdateFragQIndex(PB_INSTANCE *pbi){	UINT32  ThisFrameQIndex;	// Corresponding Index in the QThreshTable	UINT32	i;	// Check this frame quality  index    ThisFrameQIndex = pbi->FrameQIndex;	    	// It is not a key frame, so only reset those are coded    for( i = 0; i < pbi->UnitFragments; i++  )    {        if( pbi->display_fragments[i])        {            pbi->FragQIndex[i] = ThisFrameQIndex;        }    }}/**************************************************************************** *  *  ROUTINE       :     DeblockLoopFilteredBand *

⌨️ 快捷键说明

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