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

📄 huff_de.h

📁 熵编码的源程序
💻 H
字号:
/////////////////////////////////////////////
//
//    huff_de.h
//    文件内容:霍夫曼解码
//    
//    作    者:丁贵广
//    制作日期:2003.6.26
//    西安电子科技大学 AI Lab    
//
/////////////////////////////////////////////
short           decomp_tree[512];
/**************************************************************************
 BUILD_DECOMP_TREE ()
 This function builds the decompression tree.
 **************************************************************************/
void  build_decomp_tree ()
{
   register unsigned short  loop1;
   register unsigned short  current_index;
   unsigned short  loop;
   unsigned short  current_node = 1;
   decomp_tree[1] = 1;
   for (loop = 0; loop < 256; loop++)
   {
      if (code_length[loop])
      {
	 current_index = 1;
	 for (loop1 = code_length[loop] - 1; loop1 > 0; loop1--)
	 {
	    current_index = (decomp_tree[current_index] << 1) +
			    ((code[loop] >> loop1) & 1);
	    if (!(decomp_tree[current_index]))
	       decomp_tree[current_index] = ++current_node;
	 }
	 decomp_tree[(decomp_tree[current_index] << 1) +
	   (code[loop] & 1)] = -loop;
      }
   }
}
/**************************************************************************
 DECOMPRESS_IMAGE ()
 This function decompresses the compressed image.
 **************************************************************************/
void  decompress_image ()
{
   register unsigned short  cindex = 1;
   register char            curchar;
   register short           bitshift;
   unsigned long  charcount = 0L;
   while (charcount < file_size)
   {
      curchar = (char) getc (ifile);

      for (bitshift = 7; bitshift >= 0; --bitshift)
      {
	 cindex = (cindex << 1) + ((curchar >> bitshift) & 1);

	 if (decomp_tree[cindex] <= 0)
	 {
	    putc ((int) (-decomp_tree[cindex]), ofile);

	    if ((++charcount) == file_size)
               bitshift = 0;
            else
               cindex = 1;
	 }
	 else
	    cindex = decomp_tree[cindex];
      }
   }
}

⌨️ 快捷键说明

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