📄 quant.c
字号:
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[0]] = ( val > 511 ) ? 511 : val;
} else if ( DCT_blockPtr[0] <= -FquantZBinSizePtr[0] ) {
temp = FquantCoeffsPtr[0] *
( DCT_blockPtr[0] - FquantRoundPtr[0] ) + MIN16;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[0]] = ( val < -511 ) ? -511 : val;
}
/* Column 1 */
if ( DCT_blockPtr[1] >= FquantZBinSizePtr[1] ) {
temp = FquantCoeffsPtr[1] *
( DCT_blockPtr[1] + FquantRoundPtr[1] ) ;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[1]] = ( val > 511 ) ? 511 : val;
} else if ( DCT_blockPtr[1] <= -FquantZBinSizePtr[1] ) {
temp = FquantCoeffsPtr[1] *
( DCT_blockPtr[1] - FquantRoundPtr[1] ) + MIN16;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[1]] = ( val < -511 ) ? -511 : val;
}
/* Column 2 */
if ( DCT_blockPtr[2] >= FquantZBinSizePtr[2] ) {
temp = FquantCoeffsPtr[2] *
( DCT_blockPtr[2] + FquantRoundPtr[2] ) ;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[2]] = ( val > 511 ) ? 511 : val;
} else if ( DCT_blockPtr[2] <= -FquantZBinSizePtr[2] ) {
temp = FquantCoeffsPtr[2] *
( DCT_blockPtr[2] - FquantRoundPtr[2] ) + MIN16;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[2]] = ( val < -511 ) ? -511 : val;
}
/* Column 3 */
if ( DCT_blockPtr[3] >= FquantZBinSizePtr[3] ) {
temp = FquantCoeffsPtr[3] *
( DCT_blockPtr[3] + FquantRoundPtr[3] ) ;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[3]] = ( val > 511 ) ? 511 : val;
} else if ( DCT_blockPtr[3] <= -FquantZBinSizePtr[3] ) {
temp = FquantCoeffsPtr[3] *
( DCT_blockPtr[3] - FquantRoundPtr[3] ) + MIN16;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[3]] = ( val < -511 ) ? -511 : val;
}
/* Column 4 */
if ( DCT_blockPtr[4] >= FquantZBinSizePtr[4] ) {
temp = FquantCoeffsPtr[4] *
( DCT_blockPtr[4] + FquantRoundPtr[4] ) ;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[4]] = ( val > 511 ) ? 511 : val;
} else if ( DCT_blockPtr[4] <= -FquantZBinSizePtr[4] ) {
temp = FquantCoeffsPtr[4] *
( DCT_blockPtr[4] - FquantRoundPtr[4] ) + MIN16;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[4]] = ( val < -511 ) ? -511 : val;
}
/* Column 5 */
if ( DCT_blockPtr[5] >= FquantZBinSizePtr[5] ) {
temp = FquantCoeffsPtr[5] *
( DCT_blockPtr[5] + FquantRoundPtr[5] ) ;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[5]] = ( val > 511 ) ? 511 : val;
} else if ( DCT_blockPtr[5] <= -FquantZBinSizePtr[5] ) {
temp = FquantCoeffsPtr[5] *
( DCT_blockPtr[5] - FquantRoundPtr[5] ) + MIN16;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[5]] = ( val < -511 ) ? -511 : val;
}
/* Column 6 */
if ( DCT_blockPtr[6] >= FquantZBinSizePtr[6] ) {
temp = FquantCoeffsPtr[6] *
( DCT_blockPtr[6] + FquantRoundPtr[6] ) ;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[6]] = ( val > 511 ) ? 511 : val;
} else if ( DCT_blockPtr[6] <= -FquantZBinSizePtr[6] ) {
temp = FquantCoeffsPtr[6] *
( DCT_blockPtr[6] - FquantRoundPtr[6] ) + MIN16;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[6]] = ( val < -511 ) ? -511 : val;
}
/* Column 7 */
if ( DCT_blockPtr[7] >= FquantZBinSizePtr[7] ) {
temp = FquantCoeffsPtr[7] *
( DCT_blockPtr[7] + FquantRoundPtr[7] ) ;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[7]] = ( val > 511 ) ? 511 : val;
} else if ( DCT_blockPtr[7] <= -FquantZBinSizePtr[7] ) {
temp = FquantCoeffsPtr[7] *
( DCT_blockPtr[7] - FquantRoundPtr[7] ) + MIN16;
val = (Q_LIST_ENTRY) (temp>>16);
quantized_list[ZigZagPtr[7]] = ( val < -511 ) ? -511 : val;
}
FquantRoundPtr += 8;
FquantCoeffsPtr += 8;
FquantZBinSizePtr += 8;
DCT_blockPtr += 8;
ZigZagPtr += 8;
}
}
static void init_dequantizer ( PB_INSTANCE *pbi,
ogg_uint32_t scale_factor,
unsigned char QIndex ){
int i, j;
Q_LIST_ENTRY * InterY_coeffs;
Q_LIST_ENTRY * InterU_coeffs;
Q_LIST_ENTRY * InterV_coeffs;
Q_LIST_ENTRY * Y_coeffs;
Q_LIST_ENTRY * U_coeffs;
Q_LIST_ENTRY * V_coeffs;
Q_LIST_ENTRY * DcScaleFactorTable;
InterY_coeffs = pbi->InterY_coeffs;
InterU_coeffs = pbi->InterU_coeffs;
InterV_coeffs = pbi->InterV_coeffs;
Y_coeffs = pbi->Y_coeffs;
U_coeffs = pbi->U_coeffs;
V_coeffs = pbi->V_coeffs;
DcScaleFactorTable = pbi->DcScaleFactorTable;
/* invert the dequant index into the quant index
the dxer has a different order than the cxer. */
BuildZigZagIndex(pbi);
/* Reorder dequantisation coefficients into dct zigzag order. */
for ( i = 0; i < BLOCK_SIZE; i++ ) {
j = pbi->zigzag_index[i];
pbi->dequant_Y_coeffs[j] = Y_coeffs[i];
}
for ( i = 0; i < BLOCK_SIZE; i++ ){
j = pbi->zigzag_index[i];
pbi->dequant_U_coeffs[j] = U_coeffs[i];
}
for ( i = 0; i < BLOCK_SIZE; i++ ){
j = pbi->zigzag_index[i];
pbi->dequant_V_coeffs[j] = V_coeffs[i];
}
for ( i = 0; i < BLOCK_SIZE; i++ ){
j = pbi->zigzag_index[i];
pbi->dequant_InterY_coeffs[j] = InterY_coeffs[i];
}
for ( i = 0; i < BLOCK_SIZE; i++ ){
j = pbi->zigzag_index[i];
pbi->dequant_InterU_coeffs[j] = InterU_coeffs[i];
}
for ( i = 0; i < BLOCK_SIZE; i++ ){
j = pbi->zigzag_index[i];
pbi->dequant_InterV_coeffs[j] = InterV_coeffs[i];
}
/* Intra Y DC coeff */
pbi->dequant_Y_coeffs[0] =
((DcScaleFactorTable[QIndex] * pbi->dequant_Y_coeffs[0])/100);
if ( pbi->dequant_Y_coeffs[0] < MIN_DEQUANT_VAL * 2 )
pbi->dequant_Y_coeffs[0] = MIN_DEQUANT_VAL * 2;
pbi->dequant_Y_coeffs[0] =
pbi->dequant_Y_coeffs[0] << IDCT_SCALE_FACTOR;
/* Intra UV */
pbi->dequant_U_coeffs[0] =
((DcScaleFactorTable[QIndex] * pbi->dequant_U_coeffs[0])/100);
if ( pbi->dequant_U_coeffs[0] < MIN_DEQUANT_VAL * 2 )
pbi->dequant_U_coeffs[0] = MIN_DEQUANT_VAL * 2;
pbi->dequant_U_coeffs[0] =
pbi->dequant_U_coeffs[0] << IDCT_SCALE_FACTOR;
pbi->dequant_V_coeffs[0] =
((DcScaleFactorTable[QIndex] * pbi->dequant_V_coeffs[0])/100);
if ( pbi->dequant_V_coeffs[0] < MIN_DEQUANT_VAL * 2 )
pbi->dequant_V_coeffs[0] = MIN_DEQUANT_VAL * 2;
pbi->dequant_V_coeffs[0] =
pbi->dequant_V_coeffs[0] << IDCT_SCALE_FACTOR;
/* Inter Y DC coeff */
pbi->dequant_InterY_coeffs[0] =
((DcScaleFactorTable[QIndex] * pbi->dequant_InterY_coeffs[0])/100);
if ( pbi->dequant_InterY_coeffs[0] < MIN_DEQUANT_VAL * 4 )
pbi->dequant_InterY_coeffs[0] = MIN_DEQUANT_VAL * 4;
pbi->dequant_InterY_coeffs[0] =
pbi->dequant_InterY_coeffs[0] << IDCT_SCALE_FACTOR;
/* Inter UV */
pbi->dequant_InterU_coeffs[0] =
((DcScaleFactorTable[QIndex] * pbi->dequant_InterU_coeffs[0])/100);
if ( pbi->dequant_InterU_coeffs[0] < MIN_DEQUANT_VAL * 4 )
pbi->dequant_InterU_coeffs[0] = MIN_DEQUANT_VAL * 4;
pbi->dequant_InterU_coeffs[0] =
pbi->dequant_InterU_coeffs[0] << IDCT_SCALE_FACTOR;
pbi->dequant_InterV_coeffs[0] =
((DcScaleFactorTable[QIndex] * pbi->dequant_InterV_coeffs[0])/100);
if ( pbi->dequant_InterV_coeffs[0] < MIN_DEQUANT_VAL * 4 )
pbi->dequant_InterV_coeffs[0] = MIN_DEQUANT_VAL * 4;
pbi->dequant_InterV_coeffs[0] =
pbi->dequant_InterV_coeffs[0] << IDCT_SCALE_FACTOR;
for ( i = 1; i < BLOCK_SIZE; i++ ){
/* now scale coefficients by required compression factor */
pbi->dequant_Y_coeffs[i] =
(( scale_factor * pbi->dequant_Y_coeffs[i] ) / 100);
if ( pbi->dequant_Y_coeffs[i] < MIN_DEQUANT_VAL )
pbi->dequant_Y_coeffs[i] = MIN_DEQUANT_VAL;
pbi->dequant_Y_coeffs[i] =
pbi->dequant_Y_coeffs[i] << IDCT_SCALE_FACTOR;
pbi->dequant_U_coeffs[i] =
(( scale_factor * pbi->dequant_U_coeffs[i] ) / 100);
if ( pbi->dequant_U_coeffs[i] < MIN_DEQUANT_VAL )
pbi->dequant_U_coeffs[i] = MIN_DEQUANT_VAL;
pbi->dequant_U_coeffs[i] =
pbi->dequant_U_coeffs[i] << IDCT_SCALE_FACTOR;
pbi->dequant_V_coeffs[i] =
(( scale_factor * pbi->dequant_V_coeffs[i] ) / 100);
if ( pbi->dequant_V_coeffs[i] < MIN_DEQUANT_VAL )
pbi->dequant_V_coeffs[i] = MIN_DEQUANT_VAL;
pbi->dequant_V_coeffs[i] =
pbi->dequant_V_coeffs[i] << IDCT_SCALE_FACTOR;
pbi->dequant_InterY_coeffs[i] =
(( scale_factor * pbi->dequant_InterY_coeffs[i] ) / 100);
if ( pbi->dequant_InterY_coeffs[i] < (MIN_DEQUANT_VAL * 2) )
pbi->dequant_InterY_coeffs[i] = MIN_DEQUANT_VAL * 2;
pbi->dequant_InterY_coeffs[i] =
pbi->dequant_InterY_coeffs[i] << IDCT_SCALE_FACTOR;
pbi->dequant_InterU_coeffs[i] =
(( scale_factor * pbi->dequant_InterU_coeffs[i] ) / 100);
if ( pbi->dequant_InterU_coeffs[i] < (MIN_DEQUANT_VAL * 2) )
pbi->dequant_InterU_coeffs[i] = MIN_DEQUANT_VAL * 2;
pbi->dequant_InterU_coeffs[i] =
pbi->dequant_InterU_coeffs[i] << IDCT_SCALE_FACTOR;
pbi->dequant_InterV_coeffs[i] =
(( scale_factor * pbi->dequant_InterV_coeffs[i] ) / 100);
if ( pbi->dequant_InterV_coeffs[i] < (MIN_DEQUANT_VAL * 2) )
pbi->dequant_InterV_coeffs[i] = MIN_DEQUANT_VAL * 2;
pbi->dequant_InterV_coeffs[i] =
pbi->dequant_InterV_coeffs[i] << IDCT_SCALE_FACTOR;
}
pbi->dequant_coeffs = pbi->dequant_Y_coeffs;
}
void UpdateQ( PB_INSTANCE *pbi, int NewQIndex ){
ogg_uint32_t qscale;
/* clamp to legal bounds */
if (NewQIndex >= Q_TABLE_SIZE) NewQIndex = Q_TABLE_SIZE - 1;
else if (NewQIndex < 0) NewQIndex = 0;
pbi->FrameQIndex = NewQIndex;
qscale = pbi->QThreshTable[NewQIndex];
pbi->ThisFrameQualityValue = qscale;
/* Re-initialise the Q tables for forward and reverse transforms. */
init_dequantizer ( pbi, qscale, (unsigned char) pbi->FrameQIndex );
}
void UpdateQC( CP_INSTANCE *cpi, ogg_uint32_t NewQ ){
ogg_uint32_t 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 ((ogg_int32_t) 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_quantizer ( cpi, qscale, (unsigned char) pbi->FrameQIndex );
init_dequantizer ( pbi, qscale, (unsigned char) pbi->FrameQIndex );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -