📄 nltgen.c
字号:
#include "NLTGen.h"
#include <alloc.h>
#include "fp.h"
#include "vp.h"
#include "regtbl.h"
#include "vdp1.h"
/*---------------------------------------------------------------------------*/
int VDP1_NLTableGenerator( unsigned short usTin,
unsigned short usTout,
TOutputRegion Region,
TScaleAxis ScaleAxis,
TNLTableGeneratorResult *Result )
/*
Return values:
0 => Successfully
1 => Required outputs too large
2 => Dynamic memory allocation problem
3 => Unknown error
*/
{
/* These constant parameters generates by NL Calibrator Tool */
/* The resolution of each element of these tables is 9.7 */
const static unsigned short BaseRefTable_X_DS[] = {
0, 128, 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1408, 1536, 1664, 1792, 1920,
2048, 2176, 2304, 2432, 2560, 2688, 2816, 2944, 3072, 3200, 3328, 3456, 3584, 3712, 3840, 3968,
4096, 4224, 4352, 4480, 4608, 4736, 4864, 4992, 5120, 5248, 5376, 5504, 5632, 5760, 5888, 6016,
6144, 6272, 6400, 6528, 6656, 6784, 6912, 7040, 7168, 7296, 7424, 7552, 7680, 7808, 7936, 8064,
8192, 8320, 8448, 8576, 8704, 8832, 8960, 9088, 9216, 9344, 9472, 9600, 9728, 9856, 9984, 10112,
10240, 10368, 10496, 10624, 10752, 10880, 11008, 11136, 11264, 11392, 11520, 11648, 11776, 11904, 12032, 12160,
12288, 12416, 12544, 12672, 12800, 12928, 13056, 13184, 13312, 13440, 13568, 13696, 13824, 13952, 14080, 14208,
14336, 14464, 14592, 14720, 14848, 14976, 15104, 15232, 15360, 15488, 15616, 15744, 15872, 16000, 16128, 16256,
16384
};
const static unsigned short BaseRefTable_Y_DS[] = {
0, 128, 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1408, 1536, 1664, 1792, 1920,
2048, 2176, 2304, 2432, 2560, 2688, 2816, 2944, 3072, 3200, 3328, 3456, 3584, 3712, 3840, 3968,
4096, 4224, 4352, 4480, 4608, 4736, 4864, 4992, 5120, 5248, 5376, 5504, 5632, 5760, 5888, 6016,
6144, 6272, 6400, 6528, 6656, 6784, 6912, 7040, 7168, 7296, 7424, 7552, 7680, 7808, 7936, 8064,
8192, 8320, 8448, 8576, 8704, 8832, 8960, 9088, 9216, 9344, 9472, 9600, 9728, 9856, 9984, 10112,
10240, 10368, 10496, 10624, 10752, 10880, 11008, 11136, 11264, 11392, 11520, 11648, 11776, 11904, 12032, 12160,
12288, 12416, 12544, 12672, 12800, 12928, 13056, 13184, 13312, 13440, 13568, 13696, 13824, 13952, 14080, 14208,
14336, 14464, 14592, 14720, 14848, 14976, 15104, 15232, 15360, 15488, 15616, 15744, 15872, 16000, 16128, 16256,
16384
};
const static unsigned short BaseRefTable_X_VS[] = {
0, 128, 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1408, 1536, 1664, 1792, 1920,
2048, 2176, 2304, 2432, 2560, 2688, 2816, 2944, 3072, 3200, 3328, 3456, 3584, 3712, 3840, 3968,
4096, 4224, 4352, 4480, 4608, 4736, 4864, 4992, 5120, 5248, 5376, 5504, 5632, 5760, 5888, 6016,
6144, 6272, 6400, 6528, 6656, 6784, 6912, 7040, 7168, 7296, 7424, 7552, 7680, 7808, 7936, 8064,
8192, 8320, 8448, 8576, 8704, 8832, 8960, 9088, 9216, 9344, 9472, 9600, 9728, 9856, 9984, 10112,
10240, 10368, 10496, 10624, 10752, 10880, 11008, 11136, 11264, 11392, 11520, 11648, 11776, 11904, 12032, 12160,
12288, 12416, 12544, 12672, 12800, 12928, 13056, 13184, 13312, 13440, 13568, 13696, 13824, 13952, 14080, 14208,
14336, 14464, 14592, 14720, 14848, 14976, 15104, 15232, 15360, 15488, 15616, 15744, 15872, 16000, 16128, 16256,
16384
};
const static unsigned short BaseRefTable_Y_VS[] = {
0, 128, 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1408, 1536, 1664, 1792, 1920,
2048, 2176, 2304, 2432, 2560, 2688, 2816, 2944, 3072, 3200, 3328, 3456, 3584, 3712, 3840, 3968,
4096, 4224, 4352, 4480, 4608, 4736, 4864, 4992, 5120, 5248, 5376, 5504, 5632, 5760, 5888, 6016,
6144, 6272, 6400, 6528, 6656, 6784, 6912, 7040, 7168, 7296, 7424, 7552, 7680, 7808, 7936, 8064,
8192, 8320, 8448, 8576, 8704, 8832, 8960, 9088, 9216, 9344, 9472, 9600, 9728, 9856, 9984, 10112,
10240, 10368, 10496, 10624, 10752, 10880, 11008, 11136, 11264, 11392, 11520, 11648, 11776, 11904, 12032, 12160,
12288, 12416, 12544, 12672, 12800, 12928, 13056, 13184, 13312, 13440, 13568, 13696, 13824, 13952, 14080, 14208,
14336, 14464, 14592, 14720, 14848, 14976, 15104, 15232, 15360, 15488, 15616, 15744, 15872, 16000, 16128, 16256,
16384
};
const static unsigned short usTref_in = 257;
const static unsigned short usTref_out = 257;
/* -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- */
unsigned short usInputMagnifyValue, usOutputMagnifyValue, usDeltaMax, usDeltaMin,
usDeltaRefMin, usDeltaRefMax, usTmpValue, usKi, usKf, usDeltaYiMax;
unsigned short *RefTable, *BaseRefTable;
unsigned long ulInvOMV, ulInvOMVSum, ulIntMask, *NLPositionTable;
int i;
unsigned char *NLTable;
TValueResolution SourceValueResolution, RequiredValueResolution;
switch(ScaleAxis)
{
case saX:
if(usTout > GRP_NlX.Size)
return 1;
switch(Region)
{
case orVideo:
BaseRefTable = (unsigned short *)BaseRefTable_X_VS;
break;
case orData:
BaseRefTable = (unsigned short *)BaseRefTable_X_DS;
break;
default:
return 3;
}
break;
case saY:
if(usTout > GRP_NlY.Size)
return 1;
switch(Region)
{
case orVideo:
BaseRefTable = (unsigned short *)BaseRefTable_Y_VS;
break;
case orData:
BaseRefTable = (unsigned short *)BaseRefTable_Y_DS;
break;
default:
return 3;
}
break;
default:
return 3;
}
/*-*-*-*-*-* Construct Referense Table *-*-*-*-*-*/
if( (RefTable = (unsigned short *)malloc(usTref_out * sizeof(unsigned short))) == NULL )
return 2;
usTmpValue = (usTref_out - 1) / 2;
for(i=0; i<usTmpValue; i++)
RefTable[i] = (((usTref_in - 1) / 2) << 7) - BaseRefTable[usTmpValue - i];
for(; i<usTref_out; i++)
RefTable[i] = (((usTref_in - 1) / 2) << 7) + BaseRefTable[i - usTmpValue];
/*-*-*-* Calculate Delta_min and Delta_max *-*-*-*/
usDeltaRefMin = RefTable[1] - RefTable[0];
usDeltaRefMax = usDeltaRefMin;
for(i=1; i<usTref_out - 1; i++)
{
usTmpValue = RefTable[i+1] - RefTable[i];
if( usDeltaRefMin > usTmpValue )
usDeltaRefMin = usTmpValue;
if( usDeltaRefMax < usTmpValue )
usDeltaRefMax = usTmpValue;
}
/* The resolution of RefTable is 9.7. */
SourceValueResolution.ucIntegerBits = 9;
SourceValueResolution.ucFractionBits = 7;
/* The required resolution of Delata_ref is 4.7. */
RequiredValueResolution.ucIntegerBits = 4;
RequiredValueResolution.ucFractionBits = 7;
usDeltaRefMax = (unsigned short)VP_ConvertValueResolution( usDeltaRefMax,
SourceValueResolution,
RequiredValueResolution );
usDeltaRefMin = (unsigned short)VP_ConvertValueResolution( usDeltaRefMin,
SourceValueResolution,
RequiredValueResolution );
/*-*-*-* Step 1 - Global decisions *-*-*-*/
/* The resolution of FP_SerDiv result is 16.16 */
SourceValueResolution.ucIntegerBits = FP_SERDIVINSIZE;
SourceValueResolution.ucFractionBits = FP_SERDIVPRECISION;
/* The required resolution of IMV and OMV is 3.8
(because usTref_in = usTref_out = 257 and Tin_max = Tout_max = 1920) */
RequiredValueResolution.ucIntegerBits = 3;
RequiredValueResolution.ucFractionBits = 8;
/* IMV = (Tin - 1) / (Tref_in - 1) */
usInputMagnifyValue = (unsigned short)VP_ConvertValueResolution(
FP_SerDiv((usTin - 1), (usTref_in - 1)),
SourceValueResolution,
RequiredValueResolution );
/* OMV = (Tout - 1) / (Tref_out - 1) */
usOutputMagnifyValue = (unsigned short)VP_ConvertValueResolution(
FP_SerDiv((usTout - 1), (usTref_out - 1)),
SourceValueResolution,
RequiredValueResolution );
/*
Delta = DeltaRef * (IMV / OMV) = (DeltaRef * IMV) / OMV
The resolution of IMV and OMV is 3.8
The resolution of FP_SerDiv result is 16.16
The resolution of DeltaRef is 4.7
The required resolution of Delta is 6.5
1. DeltaRef * IMV = (4.7) * (3.8) = (7.15) => must be cut to 7.9
(Inputs to FP_SerDiv must be 16 bits numbers with identical resolution in fraction bits)
2. Convert OMV from resolution 3.8 to resolution 3.9
3. Use FP_SerDiv((DeltaRef * IMV) >> 6, OMV << 1)
4. Convert the result of paragraph 3 to required resolution (16.16 => 6.5)
*/
SourceValueResolution.ucIntegerBits = FP_SERDIVINSIZE;
SourceValueResolution.ucFractionBits = FP_SERDIVPRECISION;
RequiredValueResolution.ucIntegerBits = 6;
RequiredValueResolution.ucFractionBits = 5;
usDeltaMax = (unsigned short)VP_ConvertValueResolution(
FP_SerDiv( (unsigned short)(( (unsigned long)usDeltaRefMax *
(unsigned long)usInputMagnifyValue ) >> 6),
usOutputMagnifyValue << 1 ),
SourceValueResolution,
RequiredValueResolution);
usDeltaMin = (unsigned short)VP_ConvertValueResolution(
FP_SerDiv( (unsigned short)(( (unsigned long)usDeltaRefMin *
(unsigned long)usInputMagnifyValue ) >> 6),
usOutputMagnifyValue << 1 ),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -