------------------------------------------------------------------------------------------------------
问题描述:
-------------------------------------------------------------------------------------------------------
用C语言的huffman 图像压缩解压缩算法,改了改变成了MFC程序。可以实现图像压缩解压。但问题是第一次压缩和解压没错,不关闭程序,再进行第二或三次压缩解压以后就错,图像不能显示。
-------------------------------------------------------------------------------------------------------
得出上面错误的测试方法是:
------------------------------------------------------------------------------------------------------
1、压缩in1.bmp,得到压缩的中间文件(此文件不能显示为正常,只有解压缩后才能正常显示)inout1.bmp,然后再解压缩得到out1.bmp 此图可显示且与in.bmp完全相同。
2、关闭程序,换另一幅图in2.bmp用同样方法得到inout2.bmp,out2.bmp,此时\]out2.bmp 与in2.bmp相同.
3、关闭程序,使用解压缩解压inout1.bmp ,得到正常图片。继续解压inout2.bmp,得到图片不能显示。(先解压inout2.bmp ,再解压inout1.bmp也是后面解压的不能正常显示。)
还有其他实验也证明多次压缩或解压不正常,此处略。
---------------------------------------------------------------------------------------------------------
我曾在用此程序做的MFC程序中调试发现,在2到3次运行时以下代码中的decomp_tree[]数值异常大,达到过65535
void  build_decomp_tree ()
{
   register unsigned short  loop1;
   register unsigned long  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;
      }
   }
}
-----------------------------------------------------------------------------------------------------
为了便于调试,我把程序拿出来放在我的资源里面,名字叫 “运行2次就出错”希望有兴趣的朋友和调试高手们帮帮~~~
-----------------------------------------------------------------------------------------------------
分不太多,还望见谅~