huffdecode.m
上传用户:mgf822
上传日期:2022-06-06
资源大小:51k
文件大小:1k
源码类别:

压缩解压

开发平台:

Matlab

  1. function vector=huffdecode(zipped,info,image)
  2. % if ~isa(zipped,'uint8')
  3. %     error('input argument must be a uint8 vector');
  4. %     
  5. % end
  6. len=length(zipped);
  7. string=repmat(uint8(0),1,len.*8);
  8. bitindex=1:8;
  9. for index=1:len
  10. string(bitindex+8.*(index-1))=uint8(bitget(zipped(index),bitindex));
  11. end
  12. string=logical(string(:));
  13. len=length(string);
  14. string((len-info.pad+1):end)=[];
  15. len=length(string);
  16. weights=2.^(0:51);
  17. vector=repmat(uint8(0),1,info.length);
  18. vectorindex=1;
  19. codeindex=1;
  20. code=0;
  21. for index=1:len
  22.     code=bitset(code,codeindex,string(index));
  23.     codeindex=codeindex+1;
  24.     byte=decode(bitset(code,codeindex),info);
  25.     if byte>0
  26.         vector(vectorindex)=byte-1;
  27.         codeindex=1;
  28.         code=0;
  29.         vectorindex=vectorindex+1;
  30.     end
  31. end
  32. vector=reshape(vector,info.rows,info.cols);
  33.     
  34.         
  35.