📄 vtcenc.cpp
字号:
actual values. Also assign skip modes. */
updateResidMaxAndAssignSkips(col);
noteDebug("resid_max=%d\n",snr_image->residual_max);
/* quantize and mark zerotree structure for AC coefficients */
if (encQuantizeAndMarkAC(col))
errorHandler("encQuantizeAndMarkAC");
// Put_Quant_and_Max(snr_image); // hjlee 0901
Put_Quant_and_Max(snr_image,spa_lev,col); // hjlee 0901
}
wavelet_higher_bands_encode_MQ(mzte_codec.m_iScanDirection);
for(col=0;
col < NCOL;
col++)
{
/* Set global color variable */
mzte_codec.m_iCurColor = col;
/* Update states of AC coefficients */
if (encUpdateStateAC(mzte_codec.m_iCurColor))
errorHandler("encUpdateStateAC");
}
}
Void CVTCEncoder::textureLayerMQ_Enc(FILE *bitfile)
{
Int err, spa_lev, snr_lev=0, snr_scalability_levels;
Char fname[100]; // hjlee
getSpatialLayerDims(); // hjlee 0901
// hjlee 0901
/*------- AC: Initialize QList Structure -------*/
if ((err=ztqQListInit()))
errorHandler("Allocating memory for QList information.");
/* Initialize coeffs */
setSpatialLevelAndDimensions(0,0);
if ((err=ztqInitAC(0,0)))
errorHandler("ztqInitAC");
if (mzte_codec.m_iColors > 1)
{
if (mzte_codec.m_lastWvtDecompInSpaLayer[0][1]<0)
setSpatialLevelAndDimensions(1,1);
else
setSpatialLevelAndDimensions(0,1);
if ((err=ztqInitAC(0,1)))
errorHandler("ztqInitAC");
}
if (mzte_codec.m_iColors > 2)
{
if (mzte_codec.m_lastWvtDecompInSpaLayer[0][2]<0)
setSpatialLevelAndDimensions(1,2);
else
setSpatialLevelAndDimensions(0,2);
if ((err=ztqInitAC(0,2)))
errorHandler("ztqInitAC");
}
/* Loop through spatial layers */
for (spa_lev=0; spa_lev<mzte_codec.m_iSpatialLev;
spa_lev++)
{
/*----- AC: Set global spatial layer and SNR scalability level. -----*/
/* Assumes all three color components have the same number of SNR
levels */
mzte_codec.m_iCurSpatialLev = spa_lev;
mzte_codec.m_SPlayer[0].SNR_scalability_levels =
mzte_codec.m_Qinfo[0][spa_lev].SNR_scalability_levels;
snr_scalability_levels = mzte_codec.m_SPlayer[0].SNR_scalability_levels;
/* Update spatial level coeff info if changing spatial levels.
Do this for all color components. */
if (spa_lev != 0)
{
for (mzte_codec.m_iCurColor = 0; mzte_codec.m_iCurColor<mzte_codec.m_iColors;
mzte_codec.m_iCurColor++)
{
setSpatialLevelAndDimensions(mzte_codec.m_iCurSpatialLev,
mzte_codec.m_iCurColor);
// hjlee 0901
if (mzte_codec.m_lastWvtDecompInSpaLayer[spa_lev-1][mzte_codec.m_iCurColor]
>=0)
spatialLayerChangeUpdate(mzte_codec.m_iCurColor);
}
}
if (!mzte_codec.m_bStartCodeEnable)
/*------- AC: Write header info to bitstream file -------*/
emit_bits(snr_scalability_levels, 5);
/* Loop through SNR layers */
for (snr_lev=0; snr_lev<snr_scalability_levels; snr_lev++)
{
/*----- AC: Set global SNR layer -----*/
mzte_codec.m_iCurSNRLev = snr_lev;
if (mzte_codec.m_bStartCodeEnable)
{
/*------- AC: Open and initialize bitstream file -------*/
if (mzte_codec.m_iSingleBitFile==0)
{
sprintf(fname,mzte_codec.m_cBitFileAC,
mzte_codec.m_iCurSpatialLev, mzte_codec.m_iCurSNRLev);
if ((bitfile=fopen(fname,"wb"))==NULL)
errorHandler("Can't open file '%s' for writing.",fname);
}
/* initialize the buffer */
init_bit_packing_fp(bitfile,1);
if (snr_lev==0) {
/*------- 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);
emit_bits(snr_scalability_levels, 5);
flush_bits(); /* byte alignment before start code */
}
}
/*------- AC: Quantize and encode all color components -------*/
TextureSNRLayerMQ_encode(spa_lev, snr_lev, bitfile);
if (mzte_codec.m_bStartCodeEnable)
{
if (mzte_codec.m_iSingleBitFile)
flush_buffer_file();
else
close_buffer_file(bitfile);
}
} /* snr_lev */
} /* 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 = spa_lev;
mzte_codec.m_iTargetSNRLev = snr_lev;
/*------- AC: Free Qlist structure -------*/
ztqQListExit();
}
/**********************************************************/
Void CVTCEncoder::TextureObjectLayer_enc(FILE *bitfile) // modified by Sharp (99/2/16)
//Void CVTCEncoder::TextureObjectLayer_enc(FILTER *wvtfilter) // hjlee 0901
{
#if 0
FILE *bitfile;
/*------- DC: Open and initialize bitstream file -------*/
if ( iTile == 0 ){ // added by Sharp (99/2/16)
if ((bitfile=fopen(mzte_codec.m_cBitFile,"wb"))==NULL)
errorHandler("Can't open file '%s' for writing.",
mzte_codec.m_cBitFile);
}
// begin: added by Sharp (99/2/16)
else {
/* sprintf(filename,"%s%d",bitFile,iTile);*/
if ((bitfile=fopen(mzte_codec.m_cBitFile,"ab"))==NULL)
errorHandler("Can't open file '%s' for writing.",mzte_codec.m_cBitFile);
fseek(bitfile,0,SEEK_END);
}
// end: added by Sharp (99/2/16)
/* initialize variables */
init_bit_packing_fp(bitfile,1);
#endif
/* for PEZW, always enabled */
if (mzte_codec.m_iQuantType == BILEVEL_Q)
mzte_codec.m_bStartCodeEnable = 1;
/* Write header info to bitstream */
// begin: added by Sharp (99/2/16)
#if 0
if ( mzte_codec.m_tiling_disable == 0 ){
if ( iTile == 0 ){
*tile_table = header_Enc(wvtfilter);
}
tile_header_Enc(iTile);
}
if ( mzte_codec.m_tiling_disable == 1 ){
assert (iTile == 0);
header_Enc(wvtfilter); // Encode start_code only
//header_Enc_Common(wvtfilter); deleted by SL 030399
}
#endif
// end: added by Sharp (99/2/16)
// header_Enc(wvtfilter); // deleted by Sharp (99/2/16)
/*------- DC: Quantize and encode all color components -------*/
textureLayerDC_Enc();
/*------- DC: Close bitstream file -------*/
/* hjlee 001 */
if (mzte_codec.m_bStartCodeEnable){
if(mzte_codec.m_iSingleBitFile)
flush_buffer_file();
else
close_buffer_file(bitfile);
}
/*-------------------------------------------------*/
/*--------------------- AC ------------------------*/
/*-------------------------------------------------*/
#if 1
/*------- AC: SINGLE-QUANT MODE -------*/
if (mzte_codec.m_iQuantType == SINGLE_Q)
textureLayerSQ_Enc(bitfile);
/*------- AC: MULTI-QUANT MODE -------*/
else if (mzte_codec.m_iQuantType == MULTIPLE_Q)
textureLayerMQ_Enc(bitfile);
else if (mzte_codec.m_iQuantType == BILEVEL_Q) {
textureLayerBQ_Enc(bitfile);
}
#endif
if (mzte_codec.m_iSingleBitFile){
if(!mzte_codec.m_bStartCodeEnable)
close_buffer_file(bitfile);
else
fclose(bitfile);
}
}
Void CVTCEncoder::TextureObjectLayer_enc_V1(FILTER **wvtfilter)
{
FILE *bitfile;
/*------- DC: Open and initialize bitstream file -------*/
if ((bitfile=fopen(mzte_codec.m_cBitFile,"wb"))==NULL)
errorHandler("Can't open file '%s' for writing.",
mzte_codec.m_cBitFile);
/* for PEZW, always enabled */
if (mzte_codec.m_iQuantType == BILEVEL_Q)
mzte_codec.m_bStartCodeEnable = 1;
/* initialize variables */
init_bit_packing_fp(bitfile,1);
/* Write header info to bitstream */
header_Enc_V1(wvtfilter);
/*------- DC: Quantize and encode all color components -------*/
textureLayerDC_Enc();
/*------- DC: Close bitstream file -------*/
/* hjlee 001 */
if (mzte_codec.m_bStartCodeEnable){
if(mzte_codec.m_iSingleBitFile)
flush_buffer_file();
else
close_buffer_file(bitfile);
}
/*-------------------------------------------------*/
/*--------------------- AC ------------------------*/
/*-------------------------------------------------*/
/*------- AC: SINGLE-QUANT MODE -------*/
if (mzte_codec.m_iQuantType == SINGLE_Q)
textureLayerSQ_Enc(bitfile);
/*------- AC: MULTI-QUANT MODE -------*/
else if (mzte_codec.m_iQuantType == MULTIPLE_Q)
textureLayerMQ_Enc(bitfile);
else if (mzte_codec.m_iQuantType == BILEVEL_Q) {
textureLayerBQ_Enc(bitfile);
}
if (mzte_codec.m_iSingleBitFile){
if(!mzte_codec.m_bStartCodeEnable)
close_buffer_file(bitfile);
else
fclose(bitfile);
}
}
/**************************************************************/
Void CVTCEncoder::encode()
{
FILTER **synfilter,**anafilter; // hjlee 0901
Int i; // hjlee 0901
// begin: added by Sharp (99/2/16)
Int tile_width, tile_height;
long tile_table_pos, garbage;
// DATA *dat[3];
Int *table = NULL;
FILE *bitfile;
Int col; // added by Sharp (99/2/16)
// end: added by Sharp (99/2/16)
// mzte_codec.m_visual_object_verid = VERSION; /* version 2 */ // deleted by Sharp (99/11/18)
// begin: added by Sharp (99/4/7)
struct stat file_info;
int init_size;
// end: added by Sharp (99/4/7)
if ( mzte_codec.m_visual_object_verid != 1 ){ /* version 2 */
// allocate memory for source image
mzte_codec.m_Image = new PICTURE[3];
mzte_codec.m_ImageOrg = new PICTURE[3]; // added by Sharp (99/2/16)
// hjlee 0901
anafilter = (FILTER **) malloc(sizeof(FILTER *)*mzte_codec.m_iWvtDecmpLev);
synfilter = (FILTER **) malloc(sizeof(FILTER *)*mzte_codec.m_iWvtDecmpLev);
if(anafilter == NULL || synfilter == NULL)
errorHandler("Error allocating memory for filters\n");
for(i=0;i<mzte_codec.m_iWvtDecmpLev; i++) {
choose_wavelet_filter(&(anafilter[i]),
&(synfilter[mzte_codec.m_iWvtDecmpLev-1-i]),
mzte_codec.m_WvtFilters[mzte_codec.m_iWvtUniform?0:i]);
}
// read source image
// m_Image.data is allocated here
read_image( m_cImagePath, mzte_codec.m_iWidth, mzte_codec.m_iHeight,
mzte_codec.m_iColors, 8, mzte_codec.m_Image);
if (mzte_codec.m_iAlphaChannel != 0) { // arbitrary shape coding
// allocate meory for segmentation
mzte_codec.m_SegImage = new PICTURE[3];
printf("Reading in seg map '%s(%dx%d)'....\n", m_cSegImagePath,mzte_codec.m_Image[0].width,mzte_codec.m_Image[0].height );
// read the segmentation map of the source image */
// m_Image.mask[0] is allocated here
mzte_codec.m_iAlphaChannel = read_segimage(m_cSegImagePath,
mzte_codec.m_Image[0].width,
mzte_codec.m_Image[0].height,
mzte_codec.m_iColors,
mzte_codec.m_Image);
}
// begin: added by Sharp (99/2/16)
mzte_codec.m_display_width = mzte_codec.m_iWidth;
mzte_codec.m_display_height = mzte_codec.m_iHeight;
tile_width = mzte_codec.m_tile_width;
tile_height = mzte_codec.m_tile_height;
if ( mzte_codec.m_tiling_disable == 0 ){
printf("Wavelet Tiling ON....\n");
// FPDAM begin: added by Sharp
get_real_image(mzte_codec.m_Image,
mzte_codec.m_iWvtDecmpLev, mzte_codec.m_iAlphaChannel,
mzte_codec.m_iColors, mzte_codec.m_iAlphaTh,
anafilter[0]);
for(col=0; col<3; col++) {
mzte_codec.m_Image[col].width = (mzte_codec.m_iWidth + (col>0 ? 1 : 0)) >> (col>0 ? 1 : 0);
mzte_codec.m_Image[col].height = (mzte_codec.m_iHeight + (col>0 ? 1 : 0)) >> (col>0 ? 1 : 0);
}
// FPDAM end: added by Sharp
/* change the members of mzte_codec to handle tiled image */
/* original image is stored by m_ImageOrg */
init_tile(tile_width, tile_height);
mzte_codec.m_iWidth = tile_width;
mzte_codec.m_iHeight = tile_height;
mzte_codec.m_iDCWidth = GetDCWidth();
mzte_codec.m_iDCHeight = GetDCHeight();
// begin: modified by Sharp (99/5/10)
mzte_codec.m_iNumOfTile =
((mzte_codec.m_ImageOrg[0].width)/tile_width + ((mzte_codec.m_ImageOrg[0].width%tile_width)?1:0) ) *
((mzte_codec.m_ImageOrg[0].height)/tile_height + ((mzte_codec.m_ImageOrg[0].height%tile_height)?1:0));
/* printf("%d %d\n", mzte_codec.m_ImageOrg[0].width, mzte_codec.m_ImageOrg[0].height);*/
// mzte_codec.m_iNumOfTile = (mzte_codec.m_ImageOrg[0].width)/tile_width *
// (mzte_codec.m_ImageOrg[0].height)/tile_height;
// end: modified by Sharp (99/5/10)
table = (Int *)malloc(sizeof(Int)*mzte_codec.m_iNumOfTile);
#ifdef _FPDAM_DBG_
fprintf(stderr,"....... origin_x=%d, origin_y=%d, org width=%d org height=%d m_iNumOfTile=%d\n",
mzte_codec.m_iOriginX, mzte_codec.m_iOriginY,
mzte_codec.m_ImageOrg[0].width, mzte_codec.m_ImageOrg[0].height, mzte_codec.m_iNumOfTile);
getchar();
#endif _FPDAM_DBG_
} else {
mzte_codec.m_iNumOfTile = 1;
}
// end: added by Sharp (99/2/16)
// m_Image.mask is allocated here
get_virtual_image(mzte_codec.m_Image, mzte_codec.m_iWvtDecmpLev,
// FPDAM begin: modified by Sharp
// mzte_codec.m_iAlphaChannel,
((mzte_codec.m_tiling_disable==0) ? 0 : mzte_codec.m_iAlphaChannel),
// FPDAM end: modified by Sharp
mzte_codec.m_iColors, mzte_codec.m_iAlphaTh,
// mzte_codec.m_iChangeCRDisable, // modified by SL@Sarnoff (03/03/99)
anafilter[0]);
/* FPDAM begin : added by Samsung AIT (99/09/03) */
if ( mzte_codec.m_tiling_disable==1 ){
mzte_codec.m_iObjectWidth = mzte_codec.m_iWidth;
mzte_codec.m_iObjectHeight = mzte_codec.m_iHeight;
mzte_codec.m_iObjectOriginX = mzte_codec.m_iOriginX;
mzte_codec.m_iObjectOriginY = mzte_codec.m_iOriginY;
}
/* FPDAM end : added by Samsung AIT (99/09/03) */
for (col=0; col<mzte_codec.m_iColors; col++) { // modified by Sharp (99/2/16)
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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -