How to create Huffman tree from FFC4 (DHT) header in jpeg file?

六眼飞鱼酱① 提交于 2019-12-04 07:38:58

As to how to implement this directly I'm not entirely sure, as it takes a while to process the information, but the algorithm should be pretty straight forward if you know about tries. It seems from point 7 that you do not?

I'll add an example:

         °
        / \
       /   \
      °     °
     / \   / \
    a   b  c  d 

In this simple trie, if we go left we'll assume left is a 0, right is a 1. So If you encounter the pattern '00' this corresponds with an a. The pattern '10' corresponds with a c. Usually with huffman trees the trie will be unbalanced, i.e.

     °
    / \
   a   °
      / \
     b   °
        / \
       c   d

In this case, the prefix code '0' corresponds to an a. The code 111 to a 'd'.

As @wds said, tries help. The core idea with Huffman decoding is that the bits of the code seqence should be used to "walk" the trie, taking a left when the code has a 0, and a right for a 1, until the code word ends. Then you will be in the trie node storing the replacement data for that code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!