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

📄 vtc_shape_shapeenhencode.cpp

📁 完整的RTP RTSP代码库
💻 CPP
📖 第 1 页 / 共 3 页
字号:
56482, 65535, 1, 1, 11905, 3034, 1, 1,65537, 65537, 65537, 65537, 65537, 65537, 65537, 65537,61103, 56650, 925, 8814, 11845, 2075, 828, 223,65537, 65537, 65537, 65537, 65537, 65537, 65537, 65537,4161, 1, 494, 5041, 52508, 32195, 11005, 2463,65537, 65537, 65537, 65537, 65537, 65537, 65537, 65537,63286, 32768, 39133, 49486, 53351, 8541, 37603, 15011,65537, 65537, 65537, 65537, 65537, 65537, 65537, 65537,18805, 13107, 1039, 1214, 5060, 21845, 3830, 387,65537, 65537, 65537, 65537, 65537, 65537, 65537, 65537,31654, 32951, 490, 1496, 2535, 11699, 328, 13};/***********************************************************HeaderBegin******* * * File:        ShapeEnhEncode.c * * Author:      Samsung AIT * Created:     10-13-97 * * Description: Contains functions used to implement scan interleaving *                               coding of spatial scalable binary alpha blocks. * * Copyright (C) 1997, 1998 Samsung AIT All Rights Reserved.                  * ***********************************************************HeaderEnd*********/#define Error -1Int CVTCEncoder::ShapeEnhEnCoding(UChar *LowShape,	 /* shape mask in the lower layer */		 UChar *HalfShape, /* shape mask in the half-higher layer */			UChar *CurShape, /* shape mask in the current layer */			Int object_width,  /* object_width in the current layer */			Int object_height,/* object_height in the current layer */			FILTER *filter){    Int i, j, k, l, p, q, x, y, x2, y2;    Int bab_type, ret;	Int scan_order; // SAIT_PDAM : ADDED by D.-S. Cho (Samsung AIT)     Int width2		= object_width,	height2		= object_height,	width		= width2 >> 1,	height		= height2 >> 1;    Int NB = (object_width >= 1024 || object_height >=1024)? 6:      (object_width >=512|| object_height >=512)?5:4;    Int mborder		= MBORDER,    	mblks           = NB,	mbsize          = 1<<mblks,		/* bab size in the current layer : 16 */	mbsize_ext      = mbsize+(mborder<<1);  /* bordered bab size in the current layer: 20 */     Int border		= BORDER,    	blks            = mblks-1,	bsize           = 1<<blks,		/* bab size in the lower layer : 8 */	bsize_ext       = bsize+(border<<1);	/* bordered bab size in the lower layer: 8 */     Int blkx            = (object_width+mbsize-1)/mbsize,	blky            = (object_height+mbsize-1)/mbsize;    //    static int first=0;    //    Int cnt_mode0=0, cnt_mode1=0, cnt_mode2=0, cnt_total=0;        UInt prob;    UChar *lower_bab;			/* alpha block in the lower layer */    UChar *bordered_lower_bab;		/* bordered alpha block in the lower layer */    UChar *half_bab;			/* alpha block in the half-higher layer */    UChar *bordered_half_bab;		/* bordered alpha block in the half-higher layer */         UChar *curr_bab;			/* alpha mb in the current layer */    UChar *bordered_curr_bab;		/* bordered alpha mb in the current layer */    ArCoder       ar_coder;	ShapeBitstream=NULL;	ShapeBitstreamLength=0;    /*-- Memory allocation ---------------------------------------------------------*/    lower_bab = (UChar *) calloc(bsize*bsize, sizeof(UChar));    bordered_lower_bab = (UChar *) calloc(bsize_ext*bsize_ext, sizeof(UChar));    half_bab = (UChar *) calloc(bsize*mbsize, sizeof(UChar));    bordered_half_bab = (UChar *) calloc(bsize_ext*mbsize_ext, sizeof(UChar));    curr_bab = (UChar *) calloc(mbsize*mbsize, sizeof(UChar));    bordered_curr_bab = (UChar *) calloc(mbsize_ext*mbsize_ext, sizeof(UChar));    /*-- Initialize the shape bitstream --------------------------------------------*/    ShapeBitstream = (BSS *)malloc(sizeof(BSS));    if(ShapeBitstream==NULL) {      fprintf(stderr,"Memory allocation failed\n");      return Error;    }    ShapeBitstream->bs = (UChar *)malloc(sizeof(UChar)*object_width*object_height);    if(ShapeBitstream->bs==NULL) {      fprintf(stderr,"Memory allocation failed\n");      return Error;    }    /*-- Clear the output buffer ---------------------------------------------------*/    memset(ShapeBitstream->bs, (UChar )0, object_width*object_height);    InitBitstream(1,ShapeBitstream);    /*-- Encode the Enhancement Layer ------------------------------------------------*//*     fprintf(stderr,"-- Encode the BAB in the enhancement layer !\n"); */    StartArCoder_Still(&ar_coder);      for ( j=y=y2=0; j<blky; j++, y+=bsize, y2+=mbsize )     {      for ( i=x=x2=0; i<blkx; i++, x+=bsize, x2+=mbsize )       {	/*-- Initialize BABs --*/	q = y2*width2;        for ( l=p=0; l<mbsize; l++, q+=width2 ) {          for ( k=0; k<mbsize; k++, p++ ) {	      if( y2+l < height2 && x2+k < width2)                curr_bab[p]= (CurShape[ q+x2+k ] != 0);	      else                curr_bab[p]= 0;	  }	}	q = y2*width;        for ( l=p=0; l<mbsize; l++, q+=width ) {          for ( k=0; k<bsize; k++, p++ ) {	      if( y2+l < height2 && x+k < width)                half_bab[p]= (HalfShape[ q+x+k ] != 0);	      else                half_bab[p]= 0;	  }	}	q = y*width;	for ( l=p=0; l<bsize; l++, q+=width ) {	  for ( k=0; k<bsize; k++, p++ ) {              if(  y+l < height && x+k < width )                lower_bab[p] = (LowShape[ q+x+k ] != 0);              else                lower_bab[p] = 0;          }	}	AddBorderToBABs(LowShape, HalfShape, CurShape,			lower_bab, half_bab, curr_bab,			bordered_lower_bab, bordered_half_bab,			bordered_curr_bab,			object_width, object_height,			i, j, mbsize, blkx);	scan_order = DecideScanOrder(bordered_lower_bab, mbsize); // SAIT_PDAM: ADDED by D.-S.Cho (Samsung AIT) 		bab_type = DecideBABtype(bordered_lower_bab, bordered_half_bab,				 bordered_curr_bab, mbsize,				 scan_order // SAIT_PDAM ADDED by D.-S.Cho (Samsung AIT) 				 );	if(filter->DWT_Class==DWT_ODD_SYMMETRIC){	  prob=scalable_bab_type_prob[0];	} else if(filter->DWT_Class==DWT_EVEN_SYMMETRIC) {	  prob=scalable_bab_type_prob[1];	} else {	  fprintf(stderr,"Error: filter type in ShapeEnhEncoding()!\n");	  exit(0);	}	ArCodeSymbol_Still(&ar_coder, ShapeBitstream, bab_type, prob);	/* Encode mask pixel values in the enhancement layer */	ret = ShapeEnhContentEncode(bordered_lower_bab, 				    bordered_half_bab,				    bordered_curr_bab, 				    bab_type,					scan_order, // SAIT_PDAM: ADDED by D.-S.Cho (Samsung AIT)				    mbsize, 				    filter,				    ShapeBitstream,					    &ar_coder);	if( ret == Error )	{          fprintf(stderr,"\n SI arithmetic coding Error !\n");          return  Error;        }      }    }    StopArCoder_Still(&ar_coder,ShapeBitstream);    ShapeBitstreamLength = ShapeBitstream -> cnt;    /*-- Memory free ---------------------------------------------------------*/     free(lower_bab);    free(bordered_lower_bab);    free(half_bab);    free(bordered_half_bab);    free(curr_bab);    free(bordered_curr_bab);    return ( ShapeBitstreamLength );}/* Modified by shson */Int CVTCEncoder::DecideBABtype(UChar *bordered_lower_bab, 		      UChar *bordered_half_bab, 	      UChar *bordered_curr_bab, 	      Int mbsize,		  Int scan_order // SAIT_PDAM: ADDED by D.-S.Cho (Samsung AIT)		  ){	Int	i,j,i2,j2,k,l;	Int	mborder = MBORDER;	Int	mbsize_ext = mbsize+(mborder<<1);	Int	border = BORDER;	Int	bsize = mbsize >> 1;	Int	bsize_ext = bsize+(border<<1);	Int	b_differ,b_except,curr,prev,next;	Int	bab_type;	UChar	*lower_bab_data,		*curr_bab_data, *half_bab_data;	UChar *curr_bab_data_tr =NULL; // SAIT_PDAM: ADDED by D.-S.Cho (Samsung AIT) 		lower_bab_data = bordered_lower_bab + border * bsize_ext + border;	curr_bab_data = bordered_curr_bab + mborder * mbsize_ext + mborder;	half_bab_data = bordered_half_bab + mborder * bsize_ext + border;	/* P0, P1,	   P2, P3 */	/* compare P0 pixels in the current layer  with the pixels in the lower layer  and half layer  */	/* SL: we need to take care of half layer even in transitional BAB 	   case */	b_differ=0;        for(j=j2=k=l=0; j<bsize; j++, j2+=2, k+=(mbsize_ext<<1),	      l+=bsize_ext)	{           for(i=i2=0; i<bsize; i++, i2+=2)	   {		if( curr_bab_data[k+i2] != lower_bab_data[l+i] )		{			b_differ = 1;	/* 010 case */			break;		}	   }	   if( b_differ ) break;	}	/* SL added for every line*/	if(!b_differ) {	  for(j=k=l=0; j<bsize; j++, k+=mbsize_ext,	        l+=bsize_ext)	    {	      for(i=i2=0; i<bsize; i++, i2+=2)		{		  if( curr_bab_data[k+i2] != half_bab_data[l+i] )		    {		      b_differ = 1;	/* 010 case */		      break;		    }		}	      if( b_differ ) break;	    }	}	// SAIT_PDAM: BEGIN - ADDED by D.-S.Cho (Samsung AIT) 	if (scan_order == 1) {		curr_bab_data_tr = (UChar *)calloc(mbsize_ext*mbsize_ext, sizeof(UChar));		for (j=0; j<mbsize_ext; j++) 			for (i=0; i<mbsize_ext; i++)				curr_bab_data_tr[j*mbsize_ext+i] = bordered_curr_bab[i*mbsize_ext+j];		curr_bab_data = curr_bab_data_tr + mborder * mbsize_ext + mborder;		// memory free ??	}	// SAIT_PDAM: END - ADDED by D.-S.Cho (Samsung AIT) 	/* 000 111 110 100 001 011 and 101 cases */	if(!b_differ) {	   /* check wheather there are some exceptional samples or not */	   b_except=0;	   /* check for P1 pixel decoding */	   for(j2=k=0; j2<mbsize; j2+=2, k+=(mbsize_ext<<1) )	   {	      for(i2=1; i2<mbsize; i2+=2)              {		prev= curr_bab_data[k+i2-1];		curr= curr_bab_data[k+i2];                next= curr_bab_data[k+i2+1];		if((prev==next) && (curr!=prev)) 		{			b_except = 1;   	/*101 case*/			break;		}	      }	      if(b_except) break;	   }	   if(!b_except)	   {		/*-- check for P2/P3 pixel decoding --*/		for(j2=1,k=mbsize_ext; j2<mbsize; j2+=2, k+=(mbsize_ext<<1) )		{		   for(i2=0; i2<mbsize; i2++)		   {			prev= curr_bab_data[k-mbsize_ext+i2];			curr= curr_bab_data[k+i2]; 			next= curr_bab_data[k+mbsize_ext+i2]; 		        if((prev==next) && (curr!=prev)) 			{			   b_except = 1; 	/*101 case */			   break;			}		    }		    if(b_except) break;		}	   }	} else {	   b_except = 1;	} 	if(b_except)	bab_type = 1; /* full_coded */	else		bab_type = 0; /* xor_coded (Modified SISC) */		if (scan_order == 1) free(curr_bab_data_tr); // SAIT_PDAM: ADDED by D.-S.Cho (Samsung AIT)        /* 0: XOR_coded, 1: Full_coded, 2:XOR+P0  */	return bab_type;}/***********************************************************CommentBegin****** * * -- ShapeEnhContentEncode -- Encodes a binary alpha block using SI. *

⌨️ 快捷键说明

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