📄 vtcenc.cpp
字号:
tile_table_position = current_fp();
if ( mzte_codec.m_tiling_jump_table_enable == 1 )
for ( i=0; i<mzte_codec.m_iNumOfTile; i++ ) {
emit_bits((UShort)1, 34);
}
/* next_start_code */
emit_bits(0, 1);
{
Int bits, data;
bits = current_put_bits();
bits = 8 - (bits % 8);
if (bits != 0 && bits != 8) {
data = (1 << bits) - 1;
emit_bits(data, bits);
}
}
}
return tile_table_position;
}
// end: modified by Sharp (99/2/16)
// begin: added by Sharp (99/2/16)
Void CVTCEncoder::header_Enc_Common(FILTER **wvtfilter, Int SkipShape) // hjlee 0901
{
Int texture_object_id=0;
Int texture_object_layer_shape=mzte_codec.m_iAlphaChannel;
Int wavelet_stuffing = 0x0f;
// Int wavelet_upload;
Int wavelet_uniform; // hjlee 0901
Int i; // hjlee 0901
/*------- Write header info to bitstream file -------*/
emit_bits((UShort)texture_object_id, 16);
emit_bits((UShort)MARKER_BIT, 1);
emit_bits((UShort)(mzte_codec.m_iWvtType==0?0:1), 1); // hjlee 0901
emit_bits((UShort)mzte_codec.m_iWvtDownload, 1); // hjlee 0901
emit_bits((UShort)mzte_codec.m_iWvtDecmpLev, 4); // hjlee 0901
emit_bits((UShort)mzte_codec.m_iScanDirection,1);
emit_bits((UShort)mzte_codec.m_bStartCodeEnable, 1);
emit_bits((UShort)texture_object_layer_shape, 2);
emit_bits((UShort)mzte_codec.m_iQuantType, 2);
/* hjlee 0901 */
if (mzte_codec.m_iQuantType==2) {
Int i;
emit_bits((UShort)mzte_codec.m_iSpatialLev, 4);
/* Calc number decomp layers for all spatial layers */
if (mzte_codec.m_iSpatialLev == 1)
{
mzte_codec.m_lastWvtDecompInSpaLayer[0][0]=mzte_codec.m_iWvtDecmpLev-1;
}
else if (mzte_codec.m_iSpatialLev != mzte_codec.m_iWvtDecmpLev)
{
emit_bits((UShort)mzte_codec.m_defaultSpatialScale, 1);
if (mzte_codec.m_defaultSpatialScale==0)
{
/* For the 1st spatial_scalability_levels-1 layers the luma componant
of lastWvtDecompInSpaLayer should have been filled in from the
parameter file. */
for (i=0; i<mzte_codec.m_iSpatialLev-1; ++i)
emit_bits((UShort)mzte_codec.m_lastWvtDecompInSpaLayer[i][0], 4);
mzte_codec.m_lastWvtDecompInSpaLayer[mzte_codec.m_iSpatialLev-1][0]
=mzte_codec.m_iWvtDecmpLev-1;
}
else
{
Int sp0;
sp0=mzte_codec.m_iWvtDecmpLev-mzte_codec.m_iSpatialLev;
mzte_codec.m_lastWvtDecompInSpaLayer[0][0]=sp0;
for (i=1; i<mzte_codec.m_iSpatialLev; ++i)
mzte_codec.m_lastWvtDecompInSpaLayer[i][0]=sp0+i;
}
}
else
{
for (i=0; i<mzte_codec.m_iSpatialLev; ++i)
mzte_codec.m_lastWvtDecompInSpaLayer[i][0]=i;
}
/* Calculate for chroma (one less than luma) */
for (i=0; i<mzte_codec.m_iSpatialLev; ++i)
mzte_codec.m_lastWvtDecompInSpaLayer[i][1]
=mzte_codec.m_lastWvtDecompInSpaLayer[i][2]
=mzte_codec.m_lastWvtDecompInSpaLayer[i][0]-1;
}
if (mzte_codec.m_iWvtDownload == 1) {
// hjlee 0901
wavelet_uniform = (mzte_codec.m_iWvtUniform!=0)?1:0;
emit_bits((UShort)wavelet_uniform, 1);
if(wavelet_uniform) {
upload_wavelet_filters(wvtfilter[0]);
}
else {
for(i=0;i<mzte_codec.m_iWvtDecmpLev;i++)
upload_wavelet_filters(wvtfilter[i]);
}
}
emit_bits((UShort)wavelet_stuffing, 3);
// added for FDAM1 by Samsung AIT on 2000/02/03
if(!mzte_codec.m_usErrResiDisable && SkipShape==0) {
emit_bits((UShort)mzte_codec.m_usSegmentThresh,16);
emit_bits((UShort)MARKER_BIT, 1);
}
// ~added for FDAM1 by Samsung AIT on 2000/02/03
if (texture_object_layer_shape == 0x00) {
// begin: added by Sharp (99/2/16)
emit_bits((UShort)mzte_codec.m_display_width, 15);
emit_bits((UShort)MARKER_BIT, 1);
emit_bits((UShort)mzte_codec.m_display_height, 15);
emit_bits((UShort)MARKER_BIT, 1);
// end: added by Sharp (99/2/16)
// begin: deleted by Sharp (99/2/16)
#if 0
emit_bits((UShort)mzte_codec.m_iRealWidth, 15);
emit_bits((UShort)MARKER_BIT, 1);
emit_bits((UShort)mzte_codec.m_iRealHeight, 15);
emit_bits((UShort)MARKER_BIT, 1);
#endif
// end: deleted by Sharp (99/2/16)
}
else { /* Arbitrary shape info, SL */
emit_bits((UShort)mzte_codec.m_iObjectOriginX, 15); /*horizontal_ref */
emit_bits((UShort)MARKER_BIT, 1); /* marker_bit */
emit_bits((UShort)mzte_codec.m_iObjectOriginY, 15); /*vertical_ref */
emit_bits((UShort)MARKER_BIT, 1); /* marker_bit */
emit_bits((UShort)mzte_codec.m_iObjectWidth, 15); /* object_width */
emit_bits((UShort)MARKER_BIT, 1); /* marker_bit */
emit_bits((UShort)mzte_codec.m_iObjectHeight, 15); /* object_height */
emit_bits((UShort)MARKER_BIT, 1); /* marker_bit */
//noteProgress("Merge Shape Bitstream ....");
// MergeShapeBitstream();
// FPDAM begin: added by Sharp
if ( mzte_codec.m_tiling_disable == 1 && SkipShape == 0 ){ // @@@@@@@
// FPDAM end: added by Sharp
//begin: added by SL@Sarnoff (03/03/99)
noteProgress("Encoding Shape Bitstream ....");
ShapeEnCoding(mzte_codec.m_Image[0].mask, mzte_codec.m_iWidth, mzte_codec.m_iHeight,
mzte_codec.m_iWvtDecmpLev,
mzte_codec.m_iSTOConstAlpha,
mzte_codec.m_iSTOConstAlphaValue,
mzte_codec.m_iChangeCRDisable,
mzte_codec.m_iShapeScalable,
mzte_codec.m_bStartCodeEnable,
wvtfilter);
//end: added by SL@Sarnoff (03/03/99)
// FPDAM begin: added by Sharp
}
// FPDAM end: added by Sharp
}
// @@@@@@@@@@@@
if ( mzte_codec.m_tiling_disable == 0 && SkipShape == 1){
emit_bits((UShort)mzte_codec.m_tile_width, 15); // modified by Sharp (99/11/16)
emit_bits((UShort)1, 1);
emit_bits((UShort)mzte_codec.m_tile_height, 15); // modified by Sharp (99/11/16)
emit_bits((UShort)1, 1);
}
#if 0
//Added by Sarnoff for error resilience, 3/5/99
if(!mzte_codec.m_usErrResiDisable)
emit_bits((UShort)mzte_codec.m_usSegmentThresh,16);
//End: Added by Sarnoff for error resilience, 3/5/99
#endif
}
// end: added by Sharp (99/2/16)
/**********************************************************/
/* put quant value and maximums on the bitstream */
/* put quant value and maximums on the bitstream */
Void CVTCEncoder::Put_Quant_and_Max(SNR_IMAGE *snr_image, Int spaLayer, Int color)
{
/* put quant value and maximums on the bitstream */
put_param(snr_image->quant, 7);
// emit_bits((UShort)MARKER_BIT, 1); // 1124
{
Int l;
for (l=0; l<=mzte_codec.m_lastWvtDecompInSpaLayer[spaLayer][color];++l)
{
emit_bits((UShort)snr_image->wvtDecompNumBitPlanes[l],5);
if (((l+1) % 4) == 0)
emit_bits((UShort)MARKER_BIT, 1);
}
}
}
// hjlee 0901
Void CVTCEncoder::Put_Quant_and_Max_SQBB(SNR_IMAGE *snr_image, Int spaLayer,
Int color)
{
/* put quant value and maximums on the bitstream */
if ((color==0 && spaLayer==0) || (color>0 && spaLayer==1))
put_param(snr_image->quant, 7);
if (color==0)
emit_bits((UShort)snr_image->wvtDecompNumBitPlanes[spaLayer],5);
else if (spaLayer)
emit_bits((UShort)snr_image->wvtDecompNumBitPlanes[spaLayer-1],5);
}
/**********************************************************/
Void CVTCEncoder::textureLayerDC_Enc()
{
Int col, err;
noteProgress("Encoding DC coefficients....");
for (col=0; col<mzte_codec.m_iColors; col++)
{
/* Set global color variable */
mzte_codec.m_iCurColor=col;
/* initialize DC coefficient info */
if ((err=ztqInitDC(0, col)))
errorHandler("ztqInitDC");
/* quantize DC coefficients */
if ((err=encQuantizeDC(col)))
errorHandler("encQuantizeDC");
/* losslessly encoding DC coefficients */
wavelet_dc_encode(col);
// writeStats();
}
noteProgress("Completed encoding DC coefficients.");
}
/**********************************************************/
Void CVTCEncoder::TextureSpatialLayerSQNSC_enc(Int spa_lev)
{
Int col;
SNR_IMAGE *snr_image; // hjlee 0901
/* hjlee 0901 */
/* hjlee 0827 */
for (col=0; col<mzte_codec.m_iColors; col++) {
snr_image = &(mzte_codec.m_SPlayer[col].SNRlayer.snr_image);
Put_Quant_and_Max_SQBB(snr_image, spa_lev, col);
}
for (col=0; col<mzte_codec.m_iColors; col++) {
noteProgress("Single-Quant Mode (Band by Band) - Spatial %d, SNR 0, "\
"Color %d",spa_lev,col);
mzte_codec.m_iCurColor = col;
if (spa_lev !=0 || col ==0) {
wavelet_higher_bands_encode_SQ_band(col);
}
}
}
Void CVTCEncoder::TextureSpatialLayerSQ_enc(Int spa_lev, FILE *bitfile)
{
Char fname[100]; // hjlee
/*------- AC: Open and initialize bitstream file -------*/
if (mzte_codec.m_iSingleBitFile==0)
{
sprintf(fname,mzte_codec.m_cBitFileAC,spa_lev,0);
if ((bitfile=fopen(fname,"wb"))==NULL)
errorHandler("Can't open file '%s' for writing.",fname);
}
/* initialize the buffer */
init_bit_packing_fp(bitfile,1);
/*------- AC: Write header info to bitstream file -------*/
emit_bits(TEXTURE_SPATIAL_LAYER_START_CODE >> 16, 16);
emit_bits(TEXTURE_SPATIAL_LAYER_START_CODE, 16);
emit_bits(spa_lev, 5);
TextureSpatialLayerSQNSC_enc(spa_lev);
/*------- AC: Close bitstream file -------*/
if (mzte_codec.m_iSingleBitFile)
flush_buffer_file();
else
close_buffer_file(bitfile);
}
Void CVTCEncoder::textureLayerSQ_Enc(FILE *bitfile)
{
Int col, err, spa_lev;
SNR_IMAGE *snr_image;
noteProgress("Encoding AC coefficients - Single-Quant Mode....");
/*------- AC: Set spatial and SNR levels to zero -------*/
mzte_codec.m_iCurSpatialLev = 0;
mzte_codec.m_iCurSNRLev = 0;
// mzte_codec.m_iSpatialLev=1; // hjlee 0901
setSpatialLayerDimsSQ(0); // hjlee 0901
for (col=0; col<mzte_codec.m_iColors; col++)
{
snr_image=&(mzte_codec.m_SPlayer[col].SNRlayer.snr_image);
/* Set global color variable */
mzte_codec.m_iCurColor = col;
snr_image->quant = mzte_codec.m_Qinfo[col][0].Quant[0];
/* initialization of spatial dimensions for each color component */
setSpatialLevelAndDimensions(0, col);
/* initialize AC coefficient info for each color component */
if (err=ztqInitAC(0, col))
errorHandler("ztqInitAC");
/* quantize and mark zerotree structure for AC coefficients */
if (err=encQuantizeAndMarkAC(col))
errorHandler("encQuantizeAndMarkAC");
}
/*------- AC: encode all color components -------*/
if (mzte_codec.m_iScanDirection==0) /* tree-depth scan */
{
/* put quant value and maximums on the bitstream */
for(col=0;col<mzte_codec.m_iColors; col++){
snr_image=&(mzte_codec.m_SPlayer[col].SNRlayer.snr_image);
Put_Quant_and_Max(snr_image,0,col); // hjlee 0901
}
/* losslessly encoding AC coefficients */
wavelet_higher_bands_encode_SQ_tree();
}
else /* band by band scan */
{
setSpatialLayerDimsSQ(1); // hjlee 0901
/* Assumes all three color components have the same number of SNR
levels */
for (col=0; col<mzte_codec.m_iColors; col++)
mzte_codec.m_SPlayer[col].SNR_scalability_levels = 1;
/* Loop through spatial layers */
for (spa_lev=0; spa_lev<mzte_codec.m_iSpatialLev;
spa_lev++)
{
mzte_codec.m_iCurSpatialLev=spa_lev;
for (col=0; col<mzte_codec.m_iColors; col++)
setSpatialLevelAndDimensions(spa_lev,col);
/*----- AC: Set global spatial layer. -----*/
mzte_codec.m_iCurSpatialLev = spa_lev;
/* Update spatial level coeff info if changing spatial levels.
Do this for all color components */
if (mzte_codec.m_bStartCodeEnable) {
TextureSpatialLayerSQ_enc(spa_lev,bitfile);
}
else
TextureSpatialLayerSQNSC_enc(spa_lev);
}
}
/* store the max snr_lev and spa_lev so that the decoder can
decode the bitstream up to the max level. */
/*mzte_codec.m_iTargetSpatialLev = 1;
mzte_codec.m_iTargetSNRLev = 1; */ //deleted by SL@Sarnoff (03/03/99)
noteProgress("Completed encoding AC coefficients - Single-Quant Mode.");
}
/**********************************************************/
Void CVTCEncoder::TextureSNRLayerMQ_encode(Int spa_lev, Int snr_lev, FILE *fp)
{
SNR_IMAGE *snr_image;
Int col;
static Int texture_snr_layer_id=0;
if(mzte_codec.m_bStartCodeEnable){
noteProgress("Encoding Multi-Quant Mode Layer with SNR start code....");
/* header */
emit_bits((UShort)texture_snr_layer_start_code>>16,16);
emit_bits((UShort)texture_snr_layer_start_code,16);
emit_bits((UShort)texture_snr_layer_id++,5);
}
else
noteProgress("Encoding Multi-Quant Mode Layer without SNR start code....");
noteProgress("Multi-Quant Mode - Spatial %d, SNR %d", spa_lev,snr_lev);
for(col=0;
col < NCOL;
col++)
{
noteDetail("width=%d height=%d",mzte_codec.m_SPlayer[col].width,
mzte_codec.m_SPlayer[col].height);
/* Set global color variable */
mzte_codec.m_iCurColor = col;
/* Set quant value */
snr_image=&(mzte_codec.m_SPlayer[col].SNRlayer.snr_image);
snr_image->quant = mzte_codec.m_Qinfo[col][spa_lev].Quant[snr_lev];
noteDebug("AC quant=%d",
mzte_codec.m_Qinfo[col][spa_lev].Quant[snr_lev]);
/* initialization of spatial dimensions for each color component */
if (snr_lev==0)
setSpatialLevelAndDimensions(spa_lev, col);
/* get maximum residual value - this one is derived from user Q inputs not
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -