📄 postproc.c
字号:
//==========================================================================//// 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 : PostProc.c * * Description : Post Processing * * ***************************************************************************** *//**************************************************************************** * Header Frames ***************************************************************************** */#if defined(POSTPROCESS)#define STRICT /* Strict type checking. */#include <string.h>#include "pbdll.h"#include "BlockMapping.h"#include <stdio.h>#include <stdlib.h>/**************************************************************************** * Module constants. ***************************************************************************** */ #ifdef _MSC_VER#define abs(x) ((x>0)?(x):(-(x)))#endif#define MAX(a, b) ((a>b)?a:b)#define MIN(a, b) ((a<b)?a:b)#define Clamp(val) ( val<0 ? 0: ( val>255 ? 255:val ) )#define PP_QUALITY_THRESH 49extern Q_LIST_ENTRY DcScaleFactorTableV1[ Q_TABLE_SIZE ] ; static UINT32 DCQuantScaleV1[ Q_TABLE_SIZE ] ;static UINT32 DeringModifierV1[ Q_TABLE_SIZE ] ;INT32 SharpenModifier[ Q_TABLE_SIZE ] ={ -12, -11, -10, -10, -9, -9, -9, -9, -6, -6, -6, -6, -6, -6, -6, -6, -4, -4, -4, -4, -4, -4, -4, -4, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};/*INT32 SharpenModifier[ Q_TABLE_SIZE ] ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};*/unsigned char FragDeblockingFlag[7200];/**************************************************************************** * Explicit Imports ***************************************************************************** */ extern void SimpleDeblockFrame(PB_INSTANCE *pbi, UINT8* SrcBuffer, UINT8* DestBuffer);extern void SetupLoopFilter(PB_INSTANCE *pbi);extern void UpdateUMVBorder( PB_INSTANCE *pbi, UINT8 * DestReconPtr );extern UINT32 LoopFilterLimitValuesV2[];extern UINT32 LoopFilterLimitValuesV1[];extern void UpdateFragQIndex(PB_INSTANCE *pbi);/**************************************************************************** * Exported Global Variables ***************************************************************************** *//**************************************************************************** * Exported Functions ***************************************************************************** */ /**************************************************************************** * Module Statics ***************************************************************************** */void DeblockVerticalEdgesInLoopFilteredBand( PB_INSTANCE *pbi, UINT8 *SrcPtr, UINT8 *DesPtr, UINT32 PlaneLineStep, UINT32 FragsAcross, UINT32 StartFrag, UINT32 *QuantScale );/**************************************************************************** * * ROUTINE : InitPostProcessing * * INPUTS : FrameQValue * * OUTPUTS : None * * RETURNS : None * * FUNCTION : Setup static initialized variables for postprocessing * * SPECIAL NOTES : None * * ERRORS : None. * ****************************************************************************/void InitPostProcessing(void){ int i; for( i = 0 ; i < Q_TABLE_SIZE; i++) { DCQuantScaleV1[i] = (5 + DcScaleFactorTableV1[i]) / 10; DeringModifierV1[i] = DCQuantScaleV1[i]; //LoopFilterLimitValuesV1[i] / 2; }}/**************************************************************************** * * ROUTINE : DeringBlockStrong() * * INPUTS : None * * OUTPUTS : None * * RETURNS : None * * FUNCTION : Filtering a block for deringing purpose * * SPECIAL NOTES : * * ERRORS : None. * ****************************************************************************/void DeringBlockStrong( 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>32) High=32; //if(Low < -24) // Low = -24; Low = 0; /* Initialize the Mod Data */ for(k=0;k<9;k++) { for(j=0;j<8;j++) { TmpMod = 32 + QValue - (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 - (abs(Src[j]-Src[j-1])); if(TmpMod< -64 ) TmpMod = Sharpen; else if(TmpMod<0) TmpMod = Low; else if(TmpMod>High) TmpMod = High; LRMod[k*9+j] = (INT16)TmpMod; } Src+=Pitch; } for(k=0;k<8;k++) { // In the case that this function called with // same buffer for source and destination, To // keep the c and the mmx version to have // consistant results, intermediate buffer is // used to store the eight pixel value before // writing them to destination(i.e. Overwriting // souce for the speical case) // column 0 int newPixel[8]; atot = 128; B = round; p = curRow[ rowOffset +0]; pl = curRow[ rowOffset +0-1]; al = LRMod[k*9+0]; atot -= al; B += al * pl; pu = lastRow[ rowOffset +0]; au = UDMod[k*8+0]; atot -= au; B += au * pu; pd = nextRow[ rowOffset +0]; ad = UDMod[(k+1)*8+0]; atot -= ad; B += ad * pd; pr = curRow[ rowOffset +0+1]; ar = LRMod[k*9+0+1]; atot -= ar; B += ar * pr; newVal = ( atot * p + B) >> 7; newPixel[0] = Clamp( newVal ); // column 1 atot = 128; B = round; p = curRow[ rowOffset +1]; pl = curRow[ rowOffset +1-1]; al = LRMod[k*9+1]; atot -= al; B += al * pl; pu = lastRow[ rowOffset +1]; au = UDMod[k*8+1]; atot -= au; B += au * pu; pd = nextRow[ rowOffset +1]; ad = UDMod[(k+1)*8+1]; atot -= ad; B += ad * pd; pr = curRow[ rowOffset +1+1]; ar = LRMod[k*9+1+1]; atot -= ar; B += ar * pr; newVal = ( atot * p + B) >> 7; newPixel[1] = Clamp( newVal ); // column 2 atot = 128; B = round; p = curRow[ rowOffset +2]; pl = curRow[ rowOffset +2-1]; al = LRMod[k*9+2]; atot -= al; B += al * pl; pu = lastRow[ rowOffset +2]; au = UDMod[k*8+2]; atot -= au; B += au * pu; pd = nextRow[ rowOffset +2]; ad = UDMod[(k+1)*8+2]; atot -= ad; B += ad * pd; pr = curRow[ rowOffset +2+1]; ar = LRMod[k*9+2+1]; atot -= ar; B += ar * pr; newVal = ( atot * p + B) >> 7; newPixel[2] = Clamp( newVal ); // column 3 atot = 128; B = round; p = curRow[ rowOffset +3]; pl = curRow[ rowOffset +3-1]; al = LRMod[k*9+3]; atot -= al; B += al * pl; pu = lastRow[ rowOffset +3]; au = UDMod[k*8+3]; atot -= au; B += au * pu; pd = nextRow[ rowOffset +3]; ad = UDMod[(k+1)*8+3]; atot -= ad; B += ad * pd; pr = curRow[ rowOffset +3+1]; ar = LRMod[k*9+3+1]; atot -= ar; B += ar * pr; newVal = ( atot * p + B) >> 7; newPixel[3] = Clamp( newVal ); // column 4 atot = 128; B = round; p = curRow[ rowOffset +4]; pl = curRow[ rowOffset +4-1]; al = LRMod[k*9+4]; atot -= al; B += al * pl; pu = lastRow[ rowOffset +4]; au = UDMod[k*8+4]; atot -= au; B += au * pu; pd = nextRow[ rowOffset +4]; ad = UDMod[(k+1)*8+4]; atot -= ad; B += ad * pd; pr = curRow[ rowOffset +4+1]; ar = LRMod[k*9+4+1]; atot -= ar; B += ar * pr; newVal = ( atot * p + B) >> 7; newPixel[4] = Clamp( newVal ); // column 5 atot = 128; B = round; p = curRow[ rowOffset +5]; pl = curRow[ rowOffset +5-1]; al = LRMod[k*9+5]; atot -= al; B += al * pl; pu = lastRow[ rowOffset +5]; au = UDMod[k*8+5]; atot -= au; B += au * pu; pd = nextRow[ rowOffset +5]; ad = UDMod[(k+1)*8+5]; atot -= ad; B += ad * pd; pr = curRow[ rowOffset +5+1]; ar = LRMod[k*9+5+1]; atot -= ar; B += ar * pr; newVal = ( atot * p + B) >> 7; newPixel[5] = Clamp( newVal ); // column 6 atot = 128; B = round; p = curRow[ rowOffset +6]; pl = curRow[ rowOffset +6-1]; al = LRMod[k*9+6]; atot -= al; B += al * pl; pu = lastRow[ rowOffset +6]; au = UDMod[k*8+6]; atot -= au; B += au * pu; pd = nextRow[ rowOffset +6]; ad = UDMod[(k+1)*8+6]; atot -= ad; B += ad * pd; pr = curRow[ rowOffset +6+1]; ar = LRMod[k*9+6+1]; atot -= ar; B += ar * pr; newVal = ( atot * p + B) >> 7; newPixel[6] = Clamp( newVal ); // column 7 atot = 128; B = round; p = curRow[ rowOffset +7]; pl = curRow[ rowOffset +7-1]; al = LRMod[k*9+7]; atot -= al; B += al * pl; pu = lastRow[ rowOffset +7]; au = UDMod[k*8+7]; atot -= au; B += au * pu; pd = nextRow[ rowOffset +7]; ad = UDMod[(k+1)*8+7]; atot -= ad; B += ad * pd; pr = curRow[ rowOffset +7+1]; ar = LRMod[k*9+7+1]; atot -= ar; B += ar * pr; newVal = ( atot * p + B) >> 7; newPixel[7] = Clamp( newVal );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -