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

📄 wpccoding.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 2 页
字号:
	/* silence coding blocks, no bound checking necessary */	for(iblock=0; iblock<codenblock; iblock++){	    pbuff = huffbuff[iblock];	    codeSilence(rlebuff[iblock], pbuff);	    /* adjust the buffer size */	    buffRealloc1((void *)pbuff, pbuff->pos);	}	/* Huffman encoding */	for(iblock=0; iblock<codenblock; iblock++){		    pbuff = huffbuff[iblock];	    /* rewind the buffers */	    buffRewind(pbuff);	    /* Huffman encoding */	    nsize = huffCompress(pbuff, outbuff);	    if( nsize == WPC_EOB) break;	    outputsize += nsize;	}	/* free the spaces */	buffFree2((void **)quantbuff, nblock);	buffFree2((void **)rlebuff, codenblock);	buffFree2((void **)huffbuff, codenblock);	return ((nsize == WPC_EOB)? WPC_EOB: outputsize);}int codeDecoder(void  *inconf, void *qstate, void *ibuff, void *interblock)/*******************************************************************************decode********************************************************************************Input:inconf		configuration infoibuff		buffer to hold encoded symbolsinterblock	reserved for inter block communication (unused)Output:qstate		quantization statusReturn:		consistency flag, 1 if wpcCompressed data, 0 otherwise********************************************************************************Author:		Tong Chen, 08/01/94*******************************************************************************/{	wpcCONFIG *config = (wpcCONFIG *) inconf;	wpcQUANT *quant = (wpcQUANT *) qstate;	wpcBUFF *inbuff = (wpcBUFF *) ibuff; 	wpcBUFF *pbuff = (wpcBUFF *) interblock; /* dummy */	wpcBUFF **quantbuff, **rlebuff, **huffbuff;	int i, j, bind, retval, shortsize, *bufflen;	int iblock, nblock, lblock, codenblock, codelblock;	unsigned int s;	int **qx;	unsigned char c=0, zeroflag, *flowflag, *blockind;	signed char sc;	float ave, step;	int huffmbound;	/* obtain the configuartion info */	nblock = config->nblock;	lblock = config->lblock;	codenblock = config->codenblock;	codelblock = config->codelblock;	/* the quantized coefficients and etc */	flowflag = quant->flowflag;	blockind = quant->blockind;	qx = quant->qx;		/* read the zero flag */	if(buffGetc(inbuff, zeroflag) == WPC_EOB) return 0;	/* if all zero */	if(zeroflag == QUANTZEROFLAGY){	    /* read the average as well */	    if(buffRead(inbuff, sizeof(float), 1, &ave) == WPC_EOB)		return 0;	     return 1;	}	/* else if other flag values */	else if(zeroflag != QUANTZEROFLAGN) return 0;	/* read the average and stepsize */	if(buffRead(inbuff, sizeof(float), 1, &ave) == WPC_EOB)	    return 0;	if(buffRead(inbuff, sizeof(float), 1, &step) == WPC_EOB)	    return 0;	/* put them into the struct */	quant->ave = ave;	quant->step = step;	/* decide the bound for the buffers */	huffmbound = ((int) sizeof(int))*codelblock*lblock;/* garantee to be enough */	/* allocate and init buffers for RLE and Huffman */	bufflen = (int *) malloc(nblock*sizeof(int));	quantbuff = (wpcBUFF **) malloc(nblock*sizeof(wpcBUFF *));	rlebuff = (wpcBUFF **) buffAlloc2(codenblock, huffmbound);	huffbuff = (wpcBUFF **) buffAlloc2(codenblock, huffmbound);	/* this flag is set to free space even return abnormally */    	retval = 1;	/* Huffman decode all the blocks */	for(iblock=0; iblock < codenblock; iblock ++){	    pbuff = huffbuff[iblock];	    if(huffDecompress(inbuff, pbuff) == WPC_EOB){	    	retval = 0;			 	break;	    }	    /* adjust the buffers */	    buffRealloc1((void *)pbuff, pbuff->pos);	    /* rewind the buffer */	    buffRewind(pbuff);	}	/* get the header */	if(retval){	   /* obtain the block indices  */ 	   for(iblock = 0; iblock < nblock; iblock ++){		/* consistency check *//*		if((buffGetc(huffbuff[0], blockind[iblock]) == WPC_EOB) ||		      (blockind[iblock] > nblock) || (blockind[iblock] < 0)){*/		if((buffGetc(huffbuff[0], blockind[iblock]) == WPC_EOB) ||		      (blockind[iblock] > nblock)){		    retval = 0; 		    break;		}	   }	   if(retval){	      /* obtain the block lengths */	      for(iblock = 0; iblock < nblock; iblock ++){		/* consistency check */		if((buffRead(huffbuff[0], sizeof(int), 1, bufflen+iblock)			== WPC_EOB) || bufflen[iblock]<0){		    retval = 0; 		    break;		}	      }	      /* silence decoding */	      if(retval){		/* decode all the blocks, no checking */		for(iblock=0; iblock < codenblock; iblock++){		    pbuff = rlebuff[iblock];		    /* silence decoding */		    codeDesilence(huffbuff[iblock], pbuff);	    	    /* adjust the buffers */	    	    buffRealloc1((void *)pbuff, pbuff->pos);		}		/* allocate spaces for quantization buffers */	        for(iblock = 0; iblock < nblock; iblock ++)	 	  quantbuff[iblock] = (wpcBUFF *) buffAlloc1(bufflen[iblock]);		/* partition into subbands */		for(iblock=0; iblock<codenblock; iblock++){		    pbuff = rlebuff[iblock];		    /* rewind the buffers */		    buffRewind(pbuff);            	    for(i=0; i< codelblock; i++){                    	j = (codenblock-1-iblock)*codelblock + i;                    	bind = blockind[j];                    	buffPart(quantbuff[bind],pbuff,bufflen[bind]);		    }                }		/* decode to obtain the quantized coefficients */		for(iblock = 0; iblock < nblock; iblock ++){		    pbuff = quantbuff[iblock];		    /* rewind the buffers */		    buffRewind(pbuff);					    i = 0;		    /* get the flow flag */		    buffGetc(pbuff, flowflag[iblock]); 		    /* if no overflow, then fast version */		    if(flowflag[iblock] == QUANTFLOWFLAGN){			while(buffGetc(pbuff, sc) != WPC_EOB)			    qx[iblock][i++] = sc; 		    }		    /* else, slow version */		    else{			while(buffGetc(pbuff, sc) != WPC_EOB){						    /* if overflow */			    if(sc == CODEOVERFLOW){				/* get the following short */				shortsize = CODESHORTSIZE;				buffGetc(pbuff, c);				s = c;				while(--shortsize > 0){				    buffGetc(pbuff, c);				    s += c << ((CODESHORTSIZE-shortsize)*						CODEBYTEBIT);				}				/* convert to integer */				qx[iblock][i++] =  s >> 1;			    }			    /* else if underflow */			    else if(sc == CODEUNDERFLOW){                                /* get the following short */                                shortsize = CODESHORTSIZE;				buffGetc(pbuff, c);				s = c;				while(--shortsize > 0){				    buffGetc(pbuff, c);				    s += c << ((CODESHORTSIZE-shortsize)*						CODEBYTEBIT);				}                                /* convert to integer */                                qx[iblock][i++] =  - (s >> 1);                            }   						    else{                                qx[iblock][i++] =  sc;			    }			}		    }			 	    if(i != lblock){			retval = 0;				break;		    }		}	    }	  }	}	/* free the spaces */	free((void *) bufflen);	buffFree2((void **)quantbuff, nblock);	buffFree2((void **)rlebuff, codenblock);	buffFree2((void **)huffbuff, codenblock);	/* return */	return (retval);}

⌨️ 快捷键说明

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