⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vtc_zte_ztscan_dec.cpp

📁 完整的RTP RTSP代码库
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* $Id: vtc_zte_ztscan_dec.cpp,v 1.1 2005/05/09 21:29:49 wmaycisco Exp $ *//****************************************************************************//*   MPEG4 Visual Texture Coding (VTC) Mode Software                        *//*                                                                          *//*   This software was jointly developed by the following participants:     *//*                                                                          *//*   Single-quant,  multi-quant and flow control                            *//*   are provided by  Sarnoff Corporation                                   *//*     Iraj Sodagar   (iraj@sarnoff.com)                                    *//*     Hung-Ju Lee    (hjlee@sarnoff.com)                                   *//*     Paul Hatrack   (hatrack@sarnoff.com)                                 *//*     Shipeng Li     (shipeng@sarnoff.com)                                 *//*     Bing-Bing Chai (bchai@sarnoff.com)                                   *//*     B.S. Srinivas  (bsrinivas@sarnoff.com)                               *//*                                                                          *//*   Bi-level is provided by Texas Instruments                              *//*     Jie Liang      (liang@ti.com)                                        *//*                                                                          *//*   Shape Coding is provided by  OKI Electric Industry Co., Ltd.           *//*     Zhixiong Wu    (sgo@hlabs.oki.co.jp)                                 *//*     Yoshihiro Ueda (yueda@hlabs.oki.co.jp)                               *//*     Toshifumi Kanamaru (kanamaru@hlabs.oki.co.jp)                        *//*                                                                          *//*   OKI, Sharp, Sarnoff, TI and Microsoft contributed to bitstream         *//*   exchange and bug fixing.                                               *//*                                                                          *//*                                                                          *//* In the course of development of the MPEG-4 standard, this software       *//* module is an implementation of a part of one or more MPEG-4 tools as     *//* specified by the MPEG-4 standard.                                        *//*                                                                          *//* The copyright of this software belongs to ISO/IEC. ISO/IEC gives use     *//* of the MPEG-4 standard free license to use this  software module or      *//* modifications thereof for hardware or software products claiming         *//* conformance to the MPEG-4 standard.                                      *//*                                                                          *//* Those intending to use this software module in hardware or software      *//* products are advised that use may infringe existing  patents. The        *//* original developers of this software module and their companies, the     *//* subsequent editors and their companies, and ISO/IEC have no liability    *//* and ISO/IEC have no liability for use of this software module or         *//* modification thereof in an implementation.                               *//*                                                                          *//* Permission is granted to MPEG members to use, copy, modify,              *//* and distribute the software modules ( or portions thereof )              *//* for standardization activity within ISO/IEC JTC1/SC29/WG11.              *//*                                                                          *//* Copyright 1995, 1996, 1997, 1998 ISO/IEC                                 *//****************************************************************************//************************************************************//*     Sarnoff Very Low Bit Rate Still Image Coder          *//*     Copyright 1995, 1996, 1997, 1998 Sarnoff Corporation *//************************************************************//************************************************************//*  Filename: ztscan_dec.c                                  *//*  Author: Bing-Bing CHai                                  *//*  Date: Dec. 17, 1997                                     *//*                                                          *//*  Descriptions:                                           *//*    This file contains the routines that performs         *//*    zero tree scanning and entropy decoding.              *//*                                                          *//************************************************************/#include <stdio.h>#include <stdlib.h>#ifndef WIN32#include <unistd.h>#endif#include <ctype.h>#include <string.h>#include <math.h>#include "basic.hpp"#include "Utils.hpp"#include "startcode.hpp"#include "dataStruct.hpp"#include "states.hpp"#include "globals.hpp"#include "errorHandler.hpp"#include "ac.hpp"#include "bitpack.hpp"//#include "context.hpp"#include "ztscan_common.hpp"#include "ztscanUtil.hpp"// added for FDAM1 by Samsung AIT on 2000/02/03#ifndef	_SHAPE_#define	_SHAPE_#endif// ~added for FDAM1 by Samsung AIT on 2000/02/03static ac_decoder acd;static COEFFINFO **coeffinfo;static Int color;static Int height, width;/* The following functions assume that mzte_codec is a global variable *///Added by Sarnoff for error resilience, 3/5/99static Int init_ac=0 /*, prev_good_TU, prev_good_height,		       prev_good_width */;//End: Added by Sarnoff for error resilience, 3/5/99/******************************************************************//****************************  DC  ********************************//******************************************************************//*******************************************************//**************  Inverse DC Prediction  ****************//*******************************************************//********************************************************  Function Name  -------------  static DATA iDC_pred_pix(Int i, Int j)  Arguments  ---------  Int i, Int j: Index of wavelet coefficient (row, col)    Description  -----------  Inverse DPCM prediction for a DC coefficient, refer   to syntax for algorithm.   Functions Called  ----------------  None.  Return Value  ------------    inverse prediction for coeffinfo[i][j].quantized_value********************************************************/ Short  CVTCDecoder::iDC_pred_pix(Int i, Int j){  /*  modified by Z. Wu @ OKI */  Int pred_i, pred_j, pred_d;//Added by Sarnoff for error resilience, 3/5/99#ifdef _DC_PACKET_  if(!mzte_codec.m_usErrResiDisable)	  return 0; // no predicition currently#endif//End: Added by Sarnoff for error resilience, 3/5/99  if ( i==0 || coeffinfo[i-1][j].mask == 0 )	    pred_i = 0;  else    pred_i = coeffinfo[i-1][j].quantized_value;  if ( j==0 || coeffinfo[i][j-1].mask == 0 )	    pred_j = 0;  else     pred_j = coeffinfo[i][j-1].quantized_value;  if ( i==0 || j== 0 || coeffinfo[i-1][j-1].mask == 0 )	    pred_d = 0;  else	    pred_d = coeffinfo[i-1][j-1].quantized_value;  if ( abs(pred_d-pred_j) < abs(pred_d-pred_i))	    return(pred_i);  else    return(pred_j);}/*****************************************************  Function Name  -------------  Void iDC_predict()  Arguments  ---------  None    Description  -----------  control program for inverse DC prediction  Functions Called  ----------------  iDC_pred_pix(i,j).  Return Value  ------------  none******************************************************/Void CVTCDecoder::iDC_predict(Int color){  Int i,j,dc_h,dc_w,offset_dc;  dc_h=mzte_codec.m_iDCHeight;  dc_w=mzte_codec.m_iDCWidth;   coeffinfo=mzte_codec.m_SPlayer[color].coeffinfo;  offset_dc=mzte_codec.m_iOffsetDC;  for(i=0;i<dc_h;i++)    for(j=0;j<dc_w;j++)      if (coeffinfo[i][j].mask != 0)	coeffinfo[i][j].quantized_value += offset_dc;  for(i=0;i<dc_h;i++)    for(j=0;j<dc_w;j++)      if (coeffinfo[i][j].mask != 0)	coeffinfo[i][j].quantized_value+=iDC_pred_pix(i,j);}/********************************************************  Function Name  -------------  Void wavelet_dc_decode(Int c)  Arguments  ---------  Int c - color component.    Description  -----------  Control program for decode DC information for one   color component.  Functions Called  ----------------  None.  iDC_predict()a*  get_param()  cacll_decode()    Return Value  ------------  None.********************************************************/ Void CVTCDecoder::wavelet_dc_decode(Int c){  noteDetail("Decoding DC (wavelet_dc_decode)....");  color=c;//Added by Sarnoff for error resilience, 3/5/99  if(!mzte_codec.m_usErrResiDisable){#ifdef _DC_PACKET_	acmSGMK.Max_frequency = Bitplane_Max_frequency;#endif	// Maximum TU number excluding DC part	if (color==0){	  if (mzte_codec.m_iScanDirection==0) // TD		  TU_max = mzte_codec.m_iDCHeight*mzte_codec.m_iDCWidth*9-1;	  else // BB		  TU_max = mzte_codec.m_iDCHeight*(3*mzte_codec.m_iWvtDecmpLev-2) - 1;	}  }//End: Added by Sarnoff for error resilience, 3/5/99  mzte_codec.m_iMean[color] = get_X_bits(8);  /* mzte_codec.m_iQDC[color]  = get_X_bits(8); */  mzte_codec.m_iQDC[color]  = get_param(7);  mzte_codec.m_iOffsetDC=-get_param(7);  mzte_codec.m_iMaxDC=get_param(7);   /* mzte_codec.m_iMaxDC=get_param(7)-mzte_codec.m_iOffsetDC; */ /* hjlee */  callc_decode();  iDC_predict(color);  noteDetail("Completed decoding DC.");}/********************************************************  Function Name  -------------  static Void cacll_decode()  Arguments  ---------  None.    Description  -----------  Decode DC information for one color component.  Functions Called  ----------------  mzte_ac_decoder_init()  mzte_ac_model_init()  mzte_ac_decode_symbol()  mzte_ac_model_done()  mzte_ac_decoder_done()  Return Value  ------------  None.********************************************************/ Void CVTCDecoder::callc_decode(){  Int dc_h, dc_w,i,j;  Int numBP, bp; // 1127  dc_w=mzte_codec.m_iDCWidth;  dc_h=mzte_codec.m_iDCHeight;  /* init arithmetic model */  /* ac_decoder_open(acd,NULL); */  mzte_ac_decoder_init(&acd);  // 1127  numBP = ceilLog2(mzte_codec.m_iMaxDC+1); // modified by Sharp  if ((acm_bpdc=(ac_model *)calloc(numBP,sizeof(ac_model)))==NULL)    errorHandler("Can't allocate memory for prob model.");  for (i=0; i<numBP; i++) {    acm_bpdc[i].Max_frequency = Bitplane_Max_frequency;    mzte_ac_model_init(&(acm_bpdc[i]),2,NULL,ADAPT,1);  }  coeffinfo=mzte_codec.m_SPlayer[color].coeffinfo;//Modified by Sarnoff for error resilience, 3/5/99 if(mzte_codec.m_usErrResiDisable){  //no error resilience case  for (bp=numBP-1; bp>=0; bp--) {    for(i=0;i<dc_h;i++)      for(j=0;j<dc_w;j++){		//   printf("%d %d \n", i,j);	if(coeffinfo[i][j].mask == 1) 	   coeffinfo[i][j].quantized_value +=	     (mzte_ac_decode_symbol(&acd,&(acm_bpdc[bp])) << bp);	else	  coeffinfo[i][j].quantized_value=-mzte_codec.m_iOffsetDC;      }  }  /* close arithmetic coder */  for (i=0; i<numBP; i++)     mzte_ac_model_done(&(acm_bpdc[i]));  free(acm_bpdc);  mzte_ac_decoder_done(&acd); } else{  //error resilience case#ifdef _DC_PACKET_  TU_max_dc += numBP;  TU_max += numBP;  mzte_ac_model_init(&acmType[color][0][CONTEXT_INIT],NUMCHAR_TYPE,					NULL,ADAPT,1);	  while (LTU<TU_max_dc){	bp=TU_max_dc-1-LTU;	for(i=0;i<dc_h;i++){		for(j=0;j<dc_w;j++){			if(coeffinfo[i][j].mask == 1) 			  coeffinfo[i][j].quantized_value +=				(mzte_ac_decode_symbol(&acd,&(acm_bpdc[bp])) << bp);			else			  coeffinfo[i][j].quantized_value=-mzte_codec.m_iOffsetDC;		}		if (found_segment_error(TU_color)==1){			// handle error 		}	}	check_end_of_DC_packet(numBP);	LTU++;  }  if (LTU-1 != TU_last){	  	  for (i=0; i<numBP; ++i)		  mzte_ac_model_done(&(acm_bpdc[i]));	  mzte_ac_model_done(&(acmType[color][0][CONTEXT_INIT]));	  mzte_ac_decoder_done(&acd);  }  mzte_ac_model_done(&acmType[color][0][CONTEXT_INIT]);#else   //same as no error resi case  for (bp=numBP-1; bp>=0; bp--) {    for(i=0;i<dc_h;i++)      for(j=0;j<dc_w;j++){		//   printf("%d %d \n", i,j);	if(coeffinfo[i][j].mask == 1) 	   coeffinfo[i][j].quantized_value +=	     (mzte_ac_decode_symbol(&acd,&(acm_bpdc[bp])) << bp);	else	  coeffinfo[i][j].quantized_value=-mzte_codec.m_iOffsetDC;      }  }  /* close arithmetic coder */  for (i=0; i<numBP; i++)     mzte_ac_model_done(&(acm_bpdc[i]));  free(acm_bpdc);  mzte_ac_decoder_done(&acd);#endif  }//End: modified by Sarnoff for error resilience, 3/5/99}/*********************************************************************//*****************************  AC  **********************************//*************************  Single quant  ****************************//*********************************************************************/  Int CVTCDecoder::bitplane_decode(Int l,Int max_bplane){  register Int i,val=0,k=0;  for(i=max_bplane-1;i>=0;i--,k++)    val+=mzte_ac_decode_symbol(&acd,&acm_bpmag[l][k])<<i;  return val;}/*******************************************************  The following single quant routines are for band by  band scan order.*******************************************************//********************************************************  Function Name  -------------  Void wavelet_higher_bands_decode_SQ_band(Int col)  Arguments  ---------  None.  Description  -----------  Control program for decoding AC information for one   color component. Single quant mode.  Functions Called  ----------------  cachb_encode_SQ_band()  ac_encoder_init()  mzte_ac_model_init()  mzte_ac_model_done()  ac_encoder_done()  Return Value  ------------  None.********************************************************/ Void CVTCDecoder::wavelet_higher_bands_decode_SQ_band(Int col){  SNR_IMAGE *snr_image;      noteDetail("Encoding AC (wavelet_higher_bands_encode_SQ)....");  color=col;  snr_image=&(mzte_codec.m_SPlayer[color].SNRlayer.snr_image);  //Modified by Sarnoff for error resilience, 3/5/99  if(mzte_codec.m_usErrResiDisable){  //no error resilience  /* init arithmetic coder */  mzte_ac_decoder_init(&acd);  probModelInitSQ(color);  // hjlee 0901  cachb_decode_SQ_band(snr_image);      probModelFreeSQ(color);  // hjlee 0901  mzte_ac_decoder_done(&acd); } else{ //error resilience  init_arith_decoder_model(color);  cachb_decode_SQ_band(snr_image);  close_arith_decoder_model(color); }//End modified by Sarnoff for error resilience, 3/5/99  noteDetail("Completed encoding AC.");}/********************************************************  Function Name  -------------  static Void cachb_decode_SQ_band(SNR_IMAGE *snr_img)  Arguments  ---------  None.  Description  -----------  Decode AC information for single quant mode, tree-depth scan.  Functions Called  ----------------  codeBlocks();  decode_pixel_SQ_band()  Return Value  ------------  None.********************************************************/ Void CVTCDecoder::cachb_decode_SQ_band(SNR_IMAGE *snr_image){  Int h,w,ac_h,ac_w,ac_h2,ac_w2;  Int n; /* layer index - for codeBlocks function */  Int k; /* block jump for the layer */  /* ac_h, ac_w init */  ac_h2=mzte_codec.m_SPlayer[color].height;;  ac_w2=mzte_codec.m_SPlayer[color].width;  ac_h=ac_h2>>1;  ac_w=ac_w2>>1;  height=mzte_codec.m_Image[color].height;  width=mzte_codec.m_Image[color].width;  /* Get layer index - for codeBlocks function */  n = -1;  for (w=mzte_codec.m_iDCWidth; w < ac_w2; w<<=1)    n++;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -