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

📄 unezw.c

📁 该程序把数字图像处理与小波变换结合起来
💻 C
📖 第 1 页 / 共 2 页
字号:
	for (i=0; i<4; i++){
		BasicCoderDealloc(DominantPassCoder[i]);
	}
	BasicCoderDealloc(SubordinateListCoder);
	free(DomList);
	free(SubList);
	MapDealloc(map);
	
}

/*----------------------------------------------------------------------------*/	
/*----------------------------------------------------------------------------*/	
void DecodeDominantPassMortonScan(DLNode *DomList, SLNode *SubList,
											 int *SubListSize, WTRANSFORM *transform, 
											 MAP *map, int threshold, 
											 ArithDecoder *decoder,
											 BasicCoder **DominantPassCoder, 
											 int DecodeBytes)
{
	int i, j, m, n;
	DLNode node;
	char NodeStatus;
	Boolean HighestSubband = FALSE;
	int IZCount;
	BasicCoder *Coder;
	Boolean ParentSignificant;
	Boolean PreviousCoeffSignificant;
	Boolean CurrentCoeffSignificant = FALSE;
	int DomListSize=0, DomListIndex;
	
	/* initialize LL_0 subband */
	for (j=0; j<transform->subbandVSize[0]; j+=2){
		for (i=0; i<transform->subbandHSize[0]; i+=2){
			/* begin quad_coeff */
			for (m=0; m<4; m++){
				/* parent */
				node.x = i+ScanOrderX[m];
				node.y = j+ScanOrderY[m];
				node.scale = 0;
				node.orientation = 0;

				NodeStatus = MapGetNodeSymbol(map, node.scale, node.orientation,
															node.x, node.y);

				if (!NodeStatus){
					/* node has not been decoded */
					PreviousCoeffSignificant = CurrentCoeffSignificant;
				
					/* perform context switching */
					ParentSignificant = BASEBAND_PARENT_SIGNIFICANT;
					
					if (ParentSignificant && PreviousCoeffSignificant){
						Coder = DominantPassCoder[0];
					}
					else if (ParentSignificant){
						Coder = DominantPassCoder[1];
					}
					else if (PreviousCoeffSignificant){
						Coder = DominantPassCoder[2];
					}
					else{
						Coder = DominantPassCoder[3];
					}

					node.code = BasicCoderDecode(Coder, decoder, TRUE);
					
					DecodeNode(SubList, SubListSize, transform, &node, threshold);

					if (ArithDecoderNBitsInput(decoder)/8 >= DecodeBytes){
						EndDecoding = TRUE;
						return;
					}

					CurrentCoeffSignificant = FALSE;

					if (node.code == POS || node.code == NEG){
						MapSetNodeSymbol(map, node.scale, node.orientation,
							node.x, node.y, 1);
						CurrentCoeffSignificant = TRUE;
					}
				}
				else{
					CurrentCoeffSignificant = TRUE;
				}

				if (node.code!=ZTR || NodeStatus){
					/* insert the offsprings - do the LH_1 first */
					/* LH_0 subband in the main list */
					DomList[DomListSize].x = node.x;
					DomList[DomListSize].y = node.y;
					DomList[DomListSize].scale = 1;
					DomList[DomListSize].orientation = 0;
					DomListSize++;
				}
			}
			/* end quad_coeff */
		}
	}
	
	/* add the HL_1 and HH_1 etries into the list */
	m = DomListSize;

	/* HL_1 */
	for (i=0; i<m; i++){
		DomList[DomListSize].x = DomList[i].x;
		DomList[DomListSize].y = DomList[i].y;
		DomList[DomListSize].scale = 1;
		DomList[DomListSize].orientation = 1;
		DomListSize++;
	}
	
	/* HH_1 */
	for (i=0; i<m; i++){
		DomList[DomListSize].x = DomList[i].x;
		DomList[DomListSize].y = DomList[i].y;
		DomList[DomListSize].scale = 1;
		DomList[DomListSize].orientation = 2;
		DomListSize++;
	}

	/* start the scanning */
	DomListIndex = 0;
	do {
		if (DomListIndex < DomListSize){
			node = DomList[DomListIndex];
	
			NodeStatus = MapGetNodeSymbol(map, node.scale, node.orientation, 
									node.x, node.y);

			if (!NodeStatus){
				PreviousCoeffSignificant = CurrentCoeffSignificant;
				
				if ((node.scale == transform->nsteps) && !HighestSubband){
					/* prevent entering the code again */
					HighestSubband = TRUE;
					/* switch to 3 symbols */
					for (i=0; i<4;i++){
						IZCount = ContextGetProb(DominantPassCoder[i]->context, IZ);
						ContextPutValue(DominantPassCoder[i]->context, -IZCount, IZ);
						ContextPutValue(DominantPassCoder[i]->context, IZCount, ZTR);
					}
				}
				
				/* check if parent is significant by looking at the map */
				/* special treatment for scale 1 subbands */
				if (node.scale==1){
					if (MapGetNodeSymbol(map, 0, 0, node.x, node.y)){
						ParentSignificant = TRUE;
					}
					else{
						ParentSignificant = FALSE;
					}
				}
				else{
					if ( MapGetNodeSymbol(map, node.scale - 1, node.orientation, 
						node.x>>1, node.y>>1)){
						ParentSignificant = TRUE;
					}
					else{
						ParentSignificant = FALSE;
					}
				}
				
				/* perform context switching */
				if (ParentSignificant && PreviousCoeffSignificant){
					Coder = DominantPassCoder[0];
				}
				else if (ParentSignificant){
					Coder = DominantPassCoder[1];
				}
				else if (PreviousCoeffSignificant){
					Coder = DominantPassCoder[2];
				}
				else{
					Coder = DominantPassCoder[3];
				}

				node.code = BasicCoderDecode(Coder, decoder, TRUE);
			
				DecodeNode(SubList, SubListSize, transform, &node, threshold);
			
				if (ArithDecoderNBitsInput(decoder)/8 >= DecodeBytes){
					EndDecoding = TRUE;
					return;
				}

				CurrentCoeffSignificant = FALSE;
				if (node.code == POS || node.code == NEG){
					MapSetNodeSymbol(map, node.scale, node.orientation, 
											node.x, node.y, 1);
					CurrentCoeffSignificant = TRUE;
				}
			}
			else{
				CurrentCoeffSignificant = TRUE;
			}

			/* check if need to insert children */
			if ((node.code!=ZTR || NodeStatus) && node.scale<transform->nsteps){
				i = node.x<<1;
				j = node.y<<1;
				node.scale = node.scale+1;

				/* same orientation */
				for (m=0; m<4; m++){
					DomList[DomListSize].x = i+ScanOrderX[m];
					DomList[DomListSize].y = j+ScanOrderY[m];
					DomList[DomListSize].scale = node.scale;
					DomList[DomListSize].orientation = node.orientation;
					DomListSize++;
				}
			}
			DomListIndex++;
		}
		else{
			break;
		}
	}while(1);

	return;
}

/*----------------------------------------------------------------------------*/	
/*----------------------------------------------------------------------------*/	
void DecodeNode(SLNode *SubList, int *SubListSize, WTRANSFORM *transform, 
					 DLNode *node, int threshold)
{
	int idx;
	
	if (node->scale==0){
		idx=0;
	}
	else{
		idx = 3*node->scale - 2 + node->orientation;
	}
	
	if (node->code == POS || node->code == NEG){
		if (node->code == POS){
			transform->subbandPtr[idx]
				[node->y*transform->subbandHSize[idx] + node->x] = 3*(threshold>>1);
		}
		else{
			transform->subbandPtr[idx]
				[node->y*transform->subbandHSize[idx] + node->x] = -3*(threshold>>1);
		}
		
		/* put node into subordinate list */
		SubList[*SubListSize].x = node->x;
		SubList[*SubListSize].y = node->y;
		SubList[*SubListSize].scale = node->scale;
		SubList[*SubListSize].orientation = node->orientation;
		SubList[*SubListSize].qvalue = 0;
		SubList[*SubListSize].rvalue = 0;
		(*SubListSize)++;
	}
}

/*----------------------------------------------------------------------------*/	
/*----------------------------------------------------------------------------*/	
void DecodeSubordinatePass(SLNode *SubList, int SubListSize, int threshold,
									WTRANSFORM *transform, ArithDecoder *decoder,
									BasicCoder *SubordinateListCoder, int DecodeBytes)
{
	double temp;
	int idx, i;
	
	if (threshold>0){
		for (i=0; i<SubListSize; i++){
			
			idx = 0;
			if (SubList[i].scale!=0){
				idx = 3*SubList[i].scale - 2 + SubList[i].orientation;
			}
			
			temp = transform->subbandPtr[idx]
						[SubList[i].y*transform->subbandHSize[idx] + SubList[i].x];
			
			if (BasicCoderDecode(SubordinateListCoder, decoder, TRUE) == 1){
				if (temp>=0){
					transform->subbandPtr[idx]
						[SubList[i].y*transform->subbandHSize[idx] + SubList[i].x] 
						= temp + (threshold>>1);
				}
				else{
					transform->subbandPtr[idx]
						[SubList[i].y*transform->subbandHSize[idx] + SubList[i].x]
						= temp - (threshold>>1);
				}
			}
			else{
				if (temp>=0){
					transform->subbandPtr[idx]
						[SubList[i].y*transform->subbandHSize[idx] + SubList[i].x]
						= temp - (threshold>>1);
				}
				else{
					transform->subbandPtr[idx]
						[SubList[i].y*transform->subbandHSize[idx] + SubList[i].x]
						= temp + (threshold>>1);
				}
			}
				
			SubList[i].rvalue = abs((int)transform->subbandPtr[idx]
										[SubList[i].y*transform->subbandHSize[idx] 
										+ SubList[i].x]);
			
			if (ArithDecoderNBitsInput(decoder)/8 >= DecodeBytes){
				EndDecoding = TRUE;
				break;;
			}
		}
	}
}

/*----------------------------------------------------------------------------*/	
/*----------------------------------------------------------------------------*/	
void UNEZW2Error(char *fmt, ...)
{
	va_list argptr;
	
	va_start( argptr, fmt );
	fprintf(stderr, "UNEZW2Error: " );
	vprintf( fmt, argptr );
	va_end( argptr );
	exit( -1 );
}

/*----------------------------------------------------------------------------*/	
/*----------------------------------------------------------------------------*/	
void UNEZW2Warning(char *fmt, ...)
{
	va_list argptr;
	
	va_start( argptr, fmt );
	fprintf( stderr, "UNEZW2Warning: " );
	vprintf( fmt, argptr );
	va_end( argptr );
}

⌨️ 快捷键说明

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