📄 vtcdec.cpp
字号:
{
FILE *bitfile;
Int x,y,w,h,k;
FILTER **wvtfilter; // hjlee 0901
UChar *inmask[3], *outmask[3];
Int nLevels[3], ret;
Int Width[3], Height[3];
Int Nx[3], Ny[3];
Int usemask;
Int useInt=1;
PICTURE *Image;
Int col,l;
/*-------------------------------------------------*/
/*--------- DC (and overall header info) ----------*/
/*-------------------------------------------------*/
/*------- DC: Open and initialize bitstream file -------*/
if ((bitfile=fopen(m_cInBitsFile,"rb"))==NULL)
errorHandler("Can't open file '%s' for reading.",m_cInBitsFile);
/* initialize variables */
init_bit_packing_fp(bitfile,1);
/*------- DC: Read header info from bitstream file -------*/
header_Dec_V1(pwvtfilter, &Image); // hjlee 0901
wvtfilter = *pwvtfilter; // hjlee 0901
/*--------------- CREATE DATA STRUCTURES -----------------*/
noteDetail("Creating and initializing data structures....");
mzte_codec.m_iColors = 3;
mzte_codec.m_iBitDepth = 8;
usemask = mzte_codec.m_iAlphaChannel = 0;
useInt =1;
init_acm_maxf_dec(); // hjlee 0901
for (col=0; col<mzte_codec.m_iColors; col++) // hjlee 0901 BUG
for (l=0; l<mzte_codec.m_iWvtDecmpLev; l++) {
mzte_codec.m_SPlayer[col].SNRlayer.snr_image.wvtDecompNumBitPlanes[l] = 0;
// mzte_codec.m_SPlayer[col].SNRlayer.snr_image.wvtDecompResNumBitPlanes[l] = 0;
}
for (col=0; col<mzte_codec.m_iColors; col++) {
h = mzte_codec.m_iHeight >> (Int)(col>0);
w = mzte_codec.m_iWidth >> (Int)(col>0);
mzte_codec.m_SPlayer[col].coeffinfo = new COEFFINFO * [h];
if (mzte_codec.m_SPlayer[col].coeffinfo == NULL)
exit(fprintf(stderr,"Allocating memory for coefficient structure (I)."));
mzte_codec.m_SPlayer[col].coeffinfo[0] = new COEFFINFO [h*w];
if (mzte_codec.m_SPlayer[col].coeffinfo[0] == NULL)
exit(fprintf(stderr,"Allocating memory for coefficient structure (II)."));
for (int y = 1; y < h; ++y)
mzte_codec.m_SPlayer[col].coeffinfo[y] =
mzte_codec.m_SPlayer[col].coeffinfo[y-1]+w;
for (y=0; y<h; y++)
for (int x=0; x<w; x++) {
mzte_codec.m_SPlayer[col].coeffinfo[y][x].skip =0;
mzte_codec.m_SPlayer[col].coeffinfo[y][x].wvt_coeff = 0;
mzte_codec.m_SPlayer[col].coeffinfo[y][x].rec_coeff = 0;
mzte_codec.m_SPlayer[col].coeffinfo[y][x].quantized_value = 0;
// mzte_codec.m_SPlayer[col].coeffinfo[y][x].qState = 0;
mzte_codec.m_SPlayer[col].coeffinfo[y][x].type = 0;
mzte_codec.m_SPlayer[col].coeffinfo[y][x].mask = 0;
}
}
noteDetail("Completed creating and initializing data structures.");
mzte_codec.m_iDCHeight = mzte_codec.m_iHeight >> mzte_codec.m_iWvtDecmpLev;
mzte_codec.m_iDCWidth = mzte_codec.m_iWidth >> mzte_codec.m_iWvtDecmpLev;
/* copy over the inmask[0] */
Width[0] = mzte_codec.m_iWidth;
Width[1] = Width[2] = (Width[0] >> 1);
Height[0] = mzte_codec.m_iHeight;
Height[1] = Height[2] = (Height[0] >> 1);
nLevels[0] = mzte_codec.m_iWvtDecmpLev ;
nLevels[1] = nLevels[2] = nLevels[0]-1;
Nx[0] = Ny[0]=2;
for(col=1;col<3;col++) Nx[col]=Ny[col]=1;
// #ifdef _DECODER_ // hjlee
mzte_codec.m_Image = Image;
// #endif
for (col=0; col<mzte_codec.m_iColors; col++) {
mzte_codec.m_Image[col].height = mzte_codec.m_iHeight >> (Int)(col>0);
mzte_codec.m_Image[col].width = mzte_codec.m_iWidth >> (Int)(col>0);
inmask[col] = mzte_codec.m_Image[col].mask;
outmask[col] = (UChar *)malloc(sizeof(UChar) * Width[col]*Height[col]);
ret = do_DWTMask(inmask[col], outmask[col],
Width[col], Height[col],
nLevels[col], &(wvtfilter[col==0?0:1]));
if (ret!= DWT_OK)
errorHandler("DWT Error Code %d\n", ret);
for (k=0,y=0; y<Height[col]; y++)
for (x=0; x<Width[col]; x++)
COEFF_MASK(x,y,col) = outmask[col][k++];
free(outmask[col]);
}
if (target_spatial_levels<=0 || target_snr_levels<= 0)
errorHandler("Neither target_spatial_levels nor target_snr_levels" \
"can be zero");
/*------- DC: Decode and inverse quantize all color components -------*/
textureLayerDC_Dec();
/*------- DC: Close bitstream file -------*/
/* hjlee 0901 */
if (mzte_codec.m_bStartCodeEnable){
align_byte();
if(!mzte_codec.m_iSingleBitFile)
fclose(bitfile);
}
/*-------------------------------------------------*/
/*--------------------- AC ------------------------*/
/*-------------------------------------------------*/
/*------- AC: SINGLE-QUANT MODE -------*/
if (mzte_codec.m_iQuantType == SINGLE_Q)
textureLayerSQ_Dec(bitfile);
/*------- AC: MULTI-QUANT MODE -------*/
else if (mzte_codec.m_iQuantType == MULTIPLE_Q)
// hjlee 0901
textureLayerMQ_Dec(bitfile, target_spatial_levels, target_snr_levels,
wvtfilter);
/*------- AC: BILEVEL-QUANT MODE -------*/
else if (mzte_codec.m_iQuantType == BILEVEL_Q) {
PEZW_target_spatial_levels=target_spatial_levels;
PEZW_target_snr_levels=target_snr_levels;
PEZW_target_bitrate=0;
textureLayerBQ_Dec(bitfile);
}
for(col=0; col< mzte_codec.m_iColors; col++)
free(Image[col].mask);
free(Image);
if (mzte_codec.m_iSingleBitFile==0){
if(!mzte_codec.m_bStartCodeEnable)
align_byte();
fclose(bitfile);
}
}
// hjlee 0901
Void CVTCDecoder::TextureObjectLayer_dec(
Int target_spatial_levels,
Int target_snr_levels,
FILTER ***pwvtfilter,
Int iTile, Int count, FILE *bitfile, Int **table, PICTURE *Image) // Modified by Sharp (99/2/16) // FPDAM : added by SAIT (99/09/03)
{
// FILE *bitfile; // deleted by Sharp (99/2/16)
Int x,y,w,h,k;
FILTER **wvtfilter; // hjlee 0901
UChar *inmask[3], *outmask[3];
Int nLevels[3], ret;
Int Width[3], Height[3];
Int Nx[3], Ny[3];
Int usemask;
Int useInt=1;
Int target_shape_layer = target_spatial_levels;
// PICTURE *Image; deleted by SL 03/03/99
Int l;
Int col;
// FPDAM
if(!mzte_codec.m_iAlphaChannel || mzte_codec.m_tiling_disable==1 || mzte_codec.m_iTextureTileType!=TRANSP_TILE) {
#if 0
if ( mzte_codec.m_tiling_disable == 0 ) {
tile_header_Dec();
/*-------------------------------------------------*/
/*--------- DC (and overall header info) ----------*/
/*-------------------------------------------------*/
/*------- DC: Open and initialize bitstream file -------*/
//deleted by SL@Sarnoff (03/03/99),
//Shape mask are decoded from header_Dec_common already
//If you need the shape for the tiles, you have to write
// your own routines to extract it from the global mask
// begin: added by Sharp (99/2/16)
/* if ( mzte_codec.m_tiling_disable == 0 ) {*/
/* if(mzte_codec.m_iAlphaChannel)*/
/* noteProgress("Decoding Shape Information...");*/
/* Image = (PICTURE *)malloc(sizeof(PICTURE)*3);*/
/* get_virtual_mask(Image, mzte_codec.m_iWvtDecmpLev,*/
/* mzte_codec.m_iWidth, mzte_codec.m_iHeight, */
/* 0, mzte_codec.m_iColors,*/
/* &target_shape_layer,*/
/* mzte_codec.m_bStartCodeEnable,*/
/* *pwvtfilter); //modified by SL @Sarnoff (03/03/99)*/
/* }*/
// end: added by Sharp (99/2/16)
// end: deleted by SL@Sarnoff (03/03/99)
// begin: deleted by Sharp (99/2/16)
if ((bitfile=fopen(m_cInBitsFile,"rb"))==NULL)
errorHandler("Can't open file '%s' for reading.",m_cInBitsFile);
/* initialize variables */
init_bit_packing_fp(bitfile,1);
/*------- DC: Read header info from bitstream file -------*/
header_Dec(pwvtfilter, &Image); // hjlee 0901
// end: deleted by Sharp (99/2/16)
}
#endif
wvtfilter = *pwvtfilter; // hjlee 0901
/*--------------- CREATE DATA STRUCTURES -----------------*/
noteDetail("Creating and initializing data structures....");
mzte_codec.m_iColors = 3;
mzte_codec.m_iBitDepth = 8;
usemask = mzte_codec.m_iAlphaChannel;//= 0; // modified by SL@Sarnoff (03/03/99)
useInt =1;
init_acm_maxf_dec(); // hjlee 0901
for (col=0; col<mzte_codec.m_iColors; col++) // hjlee 0901 BUG
for (l=0; l<mzte_codec.m_iWvtDecmpLev; l++) {
mzte_codec.m_SPlayer[col].SNRlayer.snr_image.wvtDecompNumBitPlanes[l] = 0;
// mzte_codec.m_SPlayer[col].SNRlayer.snr_image.wvtDecompResNumBitPlanes[l] = 0;
}
// if ( iTile == 0 ) // added by Sharp (99/2/16)
if ( count == 0 ) // FPDAM: added by SAIT (99/09/03)
{
for (col=0; col<mzte_codec.m_iColors; col++) {
h = mzte_codec.m_iHeight >> (Int)(col>0);
w = mzte_codec.m_iWidth >> (Int)(col>0);
mzte_codec.m_SPlayer[col].coeffinfo = new COEFFINFO * [h];
if (mzte_codec.m_SPlayer[col].coeffinfo == NULL)
exit(fprintf(stderr,"Allocating memory for coefficient structure (I)."));
mzte_codec.m_SPlayer[col].coeffinfo[0] = new COEFFINFO [h*w];
if (mzte_codec.m_SPlayer[col].coeffinfo[0] == NULL)
exit(fprintf(stderr,"Allocating memory for coefficient structure (II)."));
for (/*int*/ y = 1; y < h; ++y)
mzte_codec.m_SPlayer[col].coeffinfo[y] =
mzte_codec.m_SPlayer[col].coeffinfo[y-1]+w;
for (y=0; y<h; y++)
for (/*int*/ x=0; x<w; x++) {
mzte_codec.m_SPlayer[col].coeffinfo[y][x].skip =0;
mzte_codec.m_SPlayer[col].coeffinfo[y][x].wvt_coeff = 0;
mzte_codec.m_SPlayer[col].coeffinfo[y][x].rec_coeff = 0;
mzte_codec.m_SPlayer[col].coeffinfo[y][x].quantized_value = 0;
// mzte_codec.m_SPlayer[col].coeffinfo[y][x].qState = 0;
mzte_codec.m_SPlayer[col].coeffinfo[y][x].type = 0;
mzte_codec.m_SPlayer[col].coeffinfo[y][x].mask = 0;
}
}
noteDetail("Completed creating and initializing data structures.");
} // added by Sharp (99/2/16)
mzte_codec.m_iDCHeight = mzte_codec.m_iHeight >> mzte_codec.m_iWvtDecmpLev;
mzte_codec.m_iDCWidth = mzte_codec.m_iWidth >> mzte_codec.m_iWvtDecmpLev;
/* copy over the inmask[0] */
Width[0] = mzte_codec.m_iWidth;
Width[1] = Width[2] = (Width[0] >> 1);
Height[0] = mzte_codec.m_iHeight;
Height[1] = Height[2] = (Height[0] >> 1);
nLevels[0] = mzte_codec.m_iWvtDecmpLev ;
nLevels[1] = nLevels[2] = nLevels[0]-1;
Nx[0] = Ny[0]=2;
for(col=1;col<3;col++) Nx[col]=Ny[col]=1;
//#ifdef _DECODER_ // hjlee
mzte_codec.m_Image = Image;
//#endif
for (col=0; col<mzte_codec.m_iColors; col++) {
mzte_codec.m_Image[col].height = mzte_codec.m_iHeight >> (Int)(col>0);
mzte_codec.m_Image[col].width = mzte_codec.m_iWidth >> (Int)(col>0);
inmask[col] = Image[col].mask; //mzte_codec.m_Image[col].mask; //modified by SL 03/03/99
outmask[col] = (UChar *)malloc(sizeof(UChar) * Width[col]*Height[col]);
ret = do_DWTMask(inmask[col], outmask[col],
Width[col], Height[col],
nLevels[col], &(wvtfilter[col==0?0:1]));
if (ret!= DWT_OK)
errorHandler("DWT Error Code %d\n", ret);
for (k=0,y=0; y<Height[col]; y++)
for (x=0; x<Width[col]; x++)
COEFF_MASK(x,y,col) = outmask[col][k++];
free(outmask[col]);
}
if (target_spatial_levels<=0 || target_snr_levels<= 0)
errorHandler("Neither target_spatial_levels nor target_snr_levels" \
"can be zero");
/*------- DC: Decode and inverse quantize all color components -------*/
textureLayerDC_Dec();
/*------- DC: Close bitstream file -------*/
/* hjlee 0901 */
if (mzte_codec.m_bStartCodeEnable){
align_byte();
if(!mzte_codec.m_iSingleBitFile)
fclose(bitfile);
}
/*-------------------------------------------------*/
/*--------------------- AC ------------------------*/
/*-------------------------------------------------*/
#if 1
//Added by Sarnoff for error resilience, 3/5/99
if(!mzte_codec.m_usErrResiDisable)
error_bits_stat(0); /* register the dc part as no error */
//End: Added by Sarnoff for error resilience, 3/5/99
/*------- AC: SINGLE-QUANT MODE -------*/
if (mzte_codec.m_iQuantType == SINGLE_Q)
textureLayerSQ_Dec(bitfile);
/*------- AC: MULTI-QUANT MODE -------*/
else if (mzte_codec.m_iQuantType == MULTIPLE_Q)
// hjlee 0901
textureLayerMQ_Dec(bitfile, target_spatial_levels, target_snr_levels,
wvtfilter);
/*------- AC: BILEVEL-QUANT MODE -------*/
else if (mzte_codec.m_iQuantType == BILEVEL_Q) {
PEZW_target_spatial_levels=target_spatial_levels;
PEZW_target_snr_levels=target_snr_levels;
PEZW_target_bitrate=0;
textureLayerBQ_Dec(bitfile);
}
// begin: deleted by sharp (99/3/29)
// This section is moved to encode()
#if 0
for(col=0; col< mzte_codec.m_iColors; col++)
free(Image[col].mask);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -