CN101051846A - Quick Huffman decoding method based on context - Google Patents
Quick Huffman decoding method based on context Download PDFInfo
- Publication number
- CN101051846A CN101051846A CN 200710040446 CN200710040446A CN101051846A CN 101051846 A CN101051846 A CN 101051846A CN 200710040446 CN200710040446 CN 200710040446 CN 200710040446 A CN200710040446 A CN 200710040446A CN 101051846 A CN101051846 A CN 101051846A
- Authority
- CN
- China
- Prior art keywords
- val
- value
- code
- huffman
- bitcnt
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Landscapes
- Compression, Expansion, Code Conversion, And Decoders (AREA)
Abstract
The method includes following steps: code table is so constructed that structure of code table is based on regularity distribution of code value; next, using constructed code table to implement decoding stream of bits; in procedure of decoding stream of bits, searched result at previous time is adopted as starting position for this search; then, this time of searching is carried out to make each searching the code table work out substantial contribution on final searching result. The method reduces operative complexity farthest.
Description
Technical field
The present invention relates to the encoding and decoding technique field, relate in particular to a kind of method of Hafman decoding of being undertaken by tabling look-up.
Background technology
Huffman encoding is a kind of elongated destructive data compressing method, be widely used in voice, audio frequency, video, multimedia such as text and data compression field, in MPEG (Moving Picture ExpertsGroup), AVS (digital video-audio encoding and decoding technique standardization effort group), AC (Audio Coding) series with H.26x in the audio/video encoding standards such as (ITU-T video encoding standards), Huffman encoding extensively is used.Huffman encoding has utilized the probability distribution of signal source symbol to determine character-coded amount of information, for the high symbol of probability of occurrence, adopts short code word to describe; For the low symbol of probability of occurrence, adopt long code word to describe.Come redundancy between the elimination information by variable-length encoding, realize purpose the signal lossless compression.
Common Hafman decoding method has linear search method, table look-at method, binary search method and substep look-up table at present.Wherein the efficient of linear search method efficient and binary search method is lower, is not suitable for the demanding occasion of real-time; Table look-at method efficient is high slightly, but memory cost is bigger; The substep look-up table is the compromise of binary search method and table look-at method; But efficient also is not very high.
In Huffman is tabled look-up process, can carry out following search according to the Search Results of front tables look-up, obtain decoded results, making computing each time all is that final result contributes, thereby farthest reduce the complexity of calculating, reduce the expense of buffering area simultaneously, proposed in Here it is this patent based on contextual quick code word searching algorithm.
Summary of the invention
The present invention proposes a kind ofly based on contextual quick Huffman decoding method, the contribution of essence is all made in each search to final search result, reduced the complexity of computing to greatest extent.
In order to achieve the above object, the invention provides a kind ofly, comprise following steps based on contextual quick Huffman decoding method:
Re-constructing of step 1, Huffman code table;
Step 1.1, according to the size of code value in the Huffman code table, sort according to from small to large order, the new code value table that the ordering back is obtained is stored among the table Table_val;
Step 1.2, will store into from the mapping relations that original Huffman code value table is mapped to new code value table Table_val the table Table_Index;
Step 1.3, according to the table Table_Index in mapping relations, with the code length table in the former Huffman code table be mapped to the table Table_len in;
The table Table_val of this moment, Table_len and Table_Index are exactly the new Huffman code table that step 1 is configured to;
Step 2, carry out based on contextual quick code word searching method based on the new Huffman code table of being constructed in the step 1:
Step 2.1, at first from bit stream, take out 1 bit, and give the val variable value assignment that reads:
val=unpack(1);
bitCnt=1;
m=0;
Unpack (1) function representation extracts a bit from code stream; BitCnt is used for storing the number of bits of extracting from bit stream; The location index that m once searches in code table before being used for storing; Val is used for storing the value after the current bitCnt of the reading out number of bits;
Step 2.2, constantly from bit stream, extract bit number: assignment j=1;
Step 2.3, if j<Maxbits, carry out step 2.4; Wherein, Maxbits is the figure place of maximum extracted bit from code stream; If j>=Maxbits illustrates that Maxbits is provided with mistake, quit a program, proofread and correct the Maxbits value;
Step 2.4, the position of currency in Huffman code value table Table_val of searching the val variable, this lookup method are based on the monotonic increase value on the last lookup result m basis, satisfy relation of plane down:
Step 2.4.1, the value in the code value table is carried out value one by one;
Step 2.4.2, judge that currency val is whether smaller or equal to a value Table_val[i among the table Table_val], wherein, i<Size, Size represent the size of code table; If the more laggard capable step 2.5 of new variables if not, is returned step 2.4.1 and is continued value;
Step 2.6, variable assignments:
n=(m+Rg);k=m;
What wherein, Rg represented is to have the maximum number of identical code value in the Huffman code value table;
Step 2.7, judge whether currency val and pairing bit number bitCnt are to decode:
Step 2.7.1, judge whether the current figure place bitCnt that reads altogether equals Table_len[k from code stream], wherein, k≤n is if carry out step 2.7.2; If not, carry out step 2.7.3;
Step 2.7.2, Table_Index[k] and bitCnt be the information that obtains of decoding, finish computing;
Step 2.7.3, the value of k is added 1:k=k+1;
Step 2.7.4, judge whether the value of val is not equal to Table_val[k], if carry out step 2.8.
Step 2.8, with the val value to 1 of left, val=val<<1; From bit stream, read a unpack (1), and the result is added on the val value, val=val+unpack (1); The bit number that is extracted increases by 1, bitCnt=bitCnt+1; Then j++ returns and carry out step 2.3;
The present invention proposes a kind of based on contextual quick Huffman decoding method, structure by the structure code table, code table is constructed with based on code value becomes regularity distribution, utilize posttectonic code table to realize then to bit stream decoding, in the bit stream decoding process, employing is based on the Search Results of the last time original position as this search, carry out this then and search for essence is all made in the each search that makes in the code table to final search result contribution, reduce the complexity of computing to greatest extent.
Description of drawings
Fig. 1 is a kind of flow chart of steps based on step 2 in the contextual quick Huffman decoding method provided by the invention.
Embodiment
Following according to Fig. 1, specify better embodiment of the present invention:
As shown in Figure 1, the invention provides a kind ofly, comprise following steps based on contextual quick Huffman decoding method:
Re-constructing of step 1, Huffman code table;
Step 1.1, according to the size of code value in the Huffman code table, sort according to from small to large order, the new code value table that the ordering back is obtained is stored among the table Table_val;
Step 1.2, will store into from the mapping relations that original Huffman code value table is mapped to new code value table Table_val the table Table_Index;
Step 1.3, according to the table Table_Index in mapping relations, with the code length table in the former Huffman code table be mapped to the table Table_len in;
The table Table_val of this moment, Table_len and Table_Index are exactly the new Huffman code table that step 1 is configured to;
Step 2, carry out based on contextual quick code word searching method based on the new Huffman code table of being constructed in the step 1:
Step 2.1, at first from bit stream, take out 1 bit, and give the val variable value assignment that reads:
val=unpack(1);
bitCnt=1;
m=0;
Unpack (1) function representation extracts a bit from code stream; BitCnt is used for storing the number of bits of extracting from bit stream; The location index that m once searches in code table before being used for storing; Val is used for storing the value after the current bitCnt of the reading out number of bits;
Step 2.2, constantly from bit stream, extract bit number: assignment j=1;
Step 2.3, if j<Maxbits, carry out step 2.4; Wherein, Maxbits is the figure place of maximum extracted bit from code stream; If j>=Maxbits illustrates that Maxbits is provided with mistake, quit a program, proofread and correct the Maxbits value;
Step 2.4, the position of currency in Huffman code value table Table_val of searching the val variable, this lookup method are based on the monotonic increase value on the last lookup result m basis, satisfy relation of plane down:
Step 2.4.1, assignment i=m; If i<Size carries out step 2.4.2; Size represents the size of code table; If i>=Size illustrates that Size is provided with mistake, quit a program, proofread and correct the Size value;
Step 2.4.2, judge that currency val is whether smaller or equal to a value Table_val[i among the table Table_val], if, index i value is stored among the variable m, and jump out step 2.4, carry out step 2.5; If not, then i++ returns step 2.4.1;
Step 2.5, judge whether currency val equals Table_val[m], if, carry out step 2.6, if not, carry out step 2.8;
Step 2.6, variable assignments:
n=(m+Rg);k=m;
What wherein, Rg represented is to have the maximum number of identical code value in the Huffman code value table;
Step 2.7, judge whether currency val and pairing bit number bitCnt are to decode:
Step 2.7.1, judge whether the current figure place bitCnt that reads altogether equals Table_len[k from code check], if, Table_Index[k] and bitCnt be the information that decoding obtains, finish computing; If not, carry out step 2.7.2;
Step 2.7.2, the value of k is added 1; Whether the value of judging val is not equal to Table_val[k], if, carry out step 2.8, if not, whether the value of judging k is smaller or equal to n, if return and carry out step 2.7.1; If not, illustrate that the code stream of transmission is made mistakes, finish the decode procedure computing.
Step 2.8, with the val value to 1 of left, val=val<<1; From bit stream, read a unpack (1), and the result is added on the val value, val=val+unpack (1); The bit number that is extracted increases by 1, bitCnt=bitCnt+ 1; Then j++ returns and carry out step 2.3.
Followingly the present invention is described according to an object lesson:
If Huffman code table originally is as follows:
Table[16]={1,0,7,26,1,110,24,222,2,446,108,894,25,1790,109,1791};
Len[16]={1,3,4,6,3,8,6,9,3,10,8,11,6,12,8,12};
Wherein Table is the code value table, and Len is the code length table.
According to provided by the invention a kind of based on contextual quick Huffman decoding method, search the information that binary number " 001 " decodes, comprise following steps:
Re-constructing of step 1, Huffman code table;
Step 1.1, according to the size of code value among the Huffman code table Table, sort according to from small to large order, obtain:
Table_val[16]=[0,1,1,2,7,24,25,26,108,109,110,222,446,894,1790,1791];
Step 1.2, will store into from the mapping relations that original Huffman code value table Table is mapped to new code value table Table_val the table Table_Index:
Table_Idx[16]=[2,1,5,9,3,7,13,4,11,15,6,8,10,12,14,16];
Step 1.3, according to the table Table_Index in mapping relations, with the code length table Len in the former Huffman code table be mapped to the table Table_len in:
Table_len[16]=[3,1,3,3,4,6,6,6,8,8,8,9,10,11,12,12];
The table Table_val of this moment, Table_len and Table_Index are exactly the new Huffman code table that step 1 is configured to;
Step 2, carry out based on contextual quick code word searching method based on the new Huffman code table of being constructed in the step 1:
Step 2.1, at first from bit stream, take out 1 bit 0, and give the val variable value assignment that reads:
val=unpack(1)=0;
bitCnt=1;
m=0;
Step 2.2, j=1;
Step 2.3, Maxbits=32; J<Maxbits carry out step 2.4;
Step 2.4, the position of currency in Huffman code value table Table_val of searching the val variable;
Step 2.4.1, assignment i=m=0; Size=16; I<Size carries out step 2.4.2;
Step 2.4.2, val=0; Table_val[i]=Table_val[0]=0; So val is smaller or equal to Table_val[i], index i value is stored among the variable m, i.e. m=i=0; And jump out step 2.4, carry out step 2.5;
Step 2.5, val=0; Table_val[m]=Table_val[0]=0; So val equals Table_val[m]; Carry out step 2.6;
Step 2.6, variable assignments:
n=(m+Rg);k=m;
Wherein, Rg=2;
So n=2; K=m=0;
Step 2.7, judge whether currency val and pairing bit number bitCnt can decode:
Step 2.7.1, bitCnt=1; Table_len[k]=Table_len[0]=3; So bitCnt is not equal to Table_len[k]; Carry out step 2.7.2;
Step 2.7.2, the value of k is added 1:k=k+1=1; This moment val=0; Table_val[k]=Table_val[1]=1; So val is not equal to Table_val[k], jump out step 2.7, carry out step 2.8;
Step 2.8, with the val value to 1 of left, val=val<<1=0; Reading a unpack (1) value from bit stream is 0, and the result is added on the val value, val=val+unpack (1)=0; The bit number that is extracted increases by 1, bitCnt=bitCnt+1=2; J++ returns and carry out step 2.3;
Step 2.3, this moment j=2, Maxbits=32; J<Maxbits enters step 2.4 and carries out the circulation second time;
Step 2.4, the position of currency in Huffman code value table Table_val of searching the val variable;
Step 2.4.1, this moment i=m=0; Size=16; I<Size carries out the circulation first time;
Step 2.4.2, val=0; Table_val[i]=Table_val[0]=0; So val is smaller or equal to Table_val[i]; Index i value is stored among the variable m, i.e. m=i=0; And jump out step 2.4, carry out step 2.5;
Step 2.5, val=0; Table_val[m]=Table_val[0]=0; So val equals Table_val[m]; Carry out step 2.6;
Step 2.6, variable assignments:
n=(m+Rg);k=m;
Wherein, Rg=2;
So n=2; K=m=0;
Step 2.7, judge whether currency val and pairing bit number bitCnt can decode:
Step 2.7.1, bitCnt=2; Table_len[k]=Table_len[0]=3; So bitCnt is not equal to Table_len[k]; Carry out step 2.7.2;
Step 2.7.3, the value of k is added 1:k=k+1=1; This moment val=0; Table_val[k]=Table_val[1]=1; So val is not equal to Table_val[k], jump out step 2.7, carry out step 2.8;
Step 2.8, with the val value to 1 of left, val=val<<1=0; Reading a unpack (1) value from bit stream is 1, and the result is added on the val value, val=val+unpack (1)=1; The bit number that is extracted increases by 1, bitCnt=bitCnt+1=3; J++ returns and carry out step 2.3;
Step 2.3, this moment j=3, Maxbits=32; J<Maxbits enters step 2.4 and circulates for the third time;
Step 2.4, the position of currency in Huffman code value table Table_val of searching the val variable;
Step 2.4.1, this moment i=m=0; Size=16; I<Size carries out the circulation first time;
Step 2.4.2, val=1; Table_val[i]=Table_val[0]=0; So val is not below or equal to Table_val[i]; Return step 2.4.2;
Step 2.4.1, this moment i=i+1=1; Size=16; I<Size carries out the circulation second time;
Step 2.4.2, val=1; Table_val[i]=Table_val[1]=1; So val is smaller or equal to Table_val[i]; Index i value is stored among the variable m, i.e. m=i=1; And jump out step 2.4, carry out step 2.5;
Step 2.5, val=1; Table_val[m]=Table_val[1]=1; So val equals Table_val[m]; Carry out step 2.6;
Step 2.6, variable assignments:
n=(m+Rg);k=m;
Wherein, Rg=2;
So n=3; K=m=1;
Step 2.7, judge whether currency val and pairing bit number bitCnt can decode:
Step 2.7.1, bitCnt=3; Table_len[k]=Table_len[1]=1; So bitCnt is not equal to Table_len[k]; Carry out step 2.7.2;
Step 2.7.2, the value of k is added 1:k=k+1=2; This moment val=1; Table_val[k]=Table_val[2]=1; So val equals Table_val[k], k=2, n=3; So k<n returns and carries out step 2.7.1;
Step 2.7.1, bitCnt=3; Table_len[k]=Table_len[2]=3; So bitCnt equals Table_len[k]; Table_Index[k] and bitCnt be the information that obtains of decoding, finish computing;
If adopt original binary system look-up table, search the value of information that binary number " 001 " decodes, utilization table Table and Len obtain the value that " 001 " decodes, and the number of times that need carry out logic determines altogether is 80;
Adopt the present invention now, solve " 001 " corresponding information, obtain identical result, the number of times that need carry out logic determines altogether is 24 times.
By more as can be seen, adopt the method that is proposed among the present invention to decode, with respect to adopting the binary system look-up table, only need 30% of original operand just can obtain with the original same decoding effect of method.
Claims (6)
1. one kind based on contextual quick Huffman decoding method, it is characterized in that, comprises following steps:
Re-constructing of step 1, Huffman code table;
Step 2, carry out based on contextual quick code word searching method based on the new Huffman code table of being constructed in the step 1.
2. as claimed in claim 1ly it is characterized in that based on contextual quick Huffman decoding method described step 1 comprises following steps:
Step 1.1, according to the size of code value in the Huffman code table, sort in order, the new code value table that ordering back is obtained is stored among the table Table_val;
Step 1.2, will store into from the mapping relations that original Huffman code value table is mapped to new code value table Table_val the table Table_Index;
Step 1.3, according to the table Table_Index in mapping relations, with the code length table in the former Huffman code table be mapped to the table Table_len in;
The table Table_val of this moment, Table_len and Table_Index are exactly the new Huffman code table that step 1 is configured to.
3. as claimed in claim 1ly it is characterized in that based on contextual quick Huffman decoding method described claim 2 comprises following steps:
Step 2.1, at first from bit stream, take out 1 bit, and give the val variable value assignment that reads:
val=unpack(1);bitCnt=1;m=0;
Unpack (1) function representation extracts a bit from code stream; BitCnt is used for storing the number of bits of extracting from bit stream; The location index that m once searches in code table before being used for storing; Val is used for storing the value after the current bitCnt of the reading out number of bits;
Step 2.2, constantly from bit stream, extract bit number: assignment j=1;
Step 2.3, if j<Maxbits, carry out step 2.4; If j>=Maxbits illustrates that Maxbits is provided with mistake, withdraw from decode procedure, proofread and correct the Maxbits value.
Wherein, Maxbits is the figure place of maximum extracted bit from code stream;
Step 2.4, the position of currency in Huffman code value table Table_val of searching the val variable, this lookup method are based on the monotonic increase value on the last lookup result m basis, satisfy relation of plane down:
Step 2.5, judge whether currency val equals Table_val[m], if, carry out step 2.6, if not, carry out step 2.8;
Step 2.6, variable assignments: n=(m+Rg); K=m;
What wherein, Rg represented is to have the maximum number of identical code value in the Huffman code value table;
Step 2.7, judge whether currency val and pairing bit number bitCnt are to decode;
Step 2.8, with the val value to 1 of left, val=val<<1; From bit stream, read a unpack (1), and the result is added on the val value, val=val+unpack (1); The bit number that is extracted increases by 1, bitCnt=bitCnt+1; Then j++ returns and carry out step 2.3.
4. as claimed in claim 3ly it is characterized in that based on contextual quick Huffman decoding method described step 2.4 comprises following steps:
Step 2.4.1, the value in the code value table is carried out value one by one;
Step 2.4.2, judge that currency val is whether smaller or equal to a value Table_val[i among the table Table_val], wherein, i<Size, Size represent the size of code table; If the more laggard capable step 2.5 of new variables if not, is returned step 2.4.1 and is continued value.
5. as claimed in claim 3ly it is characterized in that based on contextual quick Huffman decoding method described step 2.7 comprises following steps:
Step 2.7.1, judge whether the current figure place bitCnt that reads altogether equals Table_len[k from code stream], wherein, k≤n, if, Table_Index[k] and bitCnt be the information that decoding obtains, finish computing; If not, carry out step 2.7.2;
Step 2.7.2, judge whether the value of val is not equal to Table_val[k+1], if carry out step 2.8.
6. as claimed in claim 2ly it is characterized in that based on contextual quick Huffman decoding method, in the described step 1.1, in the Huffman code table code value according to from small to large or order from big to small sort.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN 200710040446 CN101051846A (en) | 2007-05-09 | 2007-05-09 | Quick Huffman decoding method based on context |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN 200710040446 CN101051846A (en) | 2007-05-09 | 2007-05-09 | Quick Huffman decoding method based on context |
Publications (1)
Publication Number | Publication Date |
---|---|
CN101051846A true CN101051846A (en) | 2007-10-10 |
Family
ID=38783070
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN 200710040446 Pending CN101051846A (en) | 2007-05-09 | 2007-05-09 | Quick Huffman decoding method based on context |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN101051846A (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102136270A (en) * | 2010-12-27 | 2011-07-27 | 华为软件技术有限公司 | Audio frequency decoding method and device |
CN106446235A (en) * | 2016-10-10 | 2017-02-22 | Tcl集团股份有限公司 | Video searching method and device |
CN107592118A (en) * | 2016-07-08 | 2018-01-16 | 华为技术有限公司 | The coding/decoding method and device of Variable Length Code file |
CN107682018A (en) * | 2017-09-28 | 2018-02-09 | 西安万像电子科技有限公司 | Coding/decoding method and device |
-
2007
- 2007-05-09 CN CN 200710040446 patent/CN101051846A/en active Pending
Cited By (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102136270A (en) * | 2010-12-27 | 2011-07-27 | 华为软件技术有限公司 | Audio frequency decoding method and device |
CN102136270B (en) * | 2010-12-27 | 2012-08-08 | 华为软件技术有限公司 | Audio frequency decoding method and device |
CN107592118A (en) * | 2016-07-08 | 2018-01-16 | 华为技术有限公司 | The coding/decoding method and device of Variable Length Code file |
CN107592118B (en) * | 2016-07-08 | 2021-06-22 | 华为技术有限公司 | Decoding method and device for variable-length coded file |
US11284119B2 (en) | 2016-07-08 | 2022-03-22 | Huawei Technologies Co., Ltd. | Method and apparatus for decoding variable-length coded file |
CN106446235A (en) * | 2016-10-10 | 2017-02-22 | Tcl集团股份有限公司 | Video searching method and device |
CN107682018A (en) * | 2017-09-28 | 2018-02-09 | 西安万像电子科技有限公司 | Coding/decoding method and device |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN1593011A (en) | Method and apparatus for adaptive data compression | |
CN1178515C (en) | Image encoding method and device thereof | |
CN101034891A (en) | Cabac encoding method and apparatus and cabac decoding method and apparatus | |
CN101051845A (en) | Huffman decoding method for quick extracting bit stream | |
CN1228888A (en) | Variable length coding with error protection | |
CN1882090A (en) | Image encoder and image decoder | |
CN1166171C (en) | Partial retrieval of images in compressed domain | |
CN1787641A (en) | Picture information decoding method and picture information encoding method | |
CN1492589A (en) | Engine encoder and channel encoding method | |
CN1940859A (en) | Instruction set extension using 3-byte escape opcode | |
CN1868127A (en) | Data compression system and method | |
CN101040535A (en) | Two step arithmetic decoding with conversion into an intermediate format | |
CN1256848C (en) | Device for decoding and variable length coding and method | |
CN1703089A (en) | A two-value arithmetic coding method of digital signal | |
CN101047733A (en) | Short message processing method and device | |
CN101051846A (en) | Quick Huffman decoding method based on context | |
CN1257621A (en) | Method and apparatus for lossless digital data compression | |
CN1531348A (en) | Image encoder, encodnig method and programm, image decoder, decoding method and programm | |
CN1826732A (en) | Huffman coding and decoding | |
CN101056221A (en) | A method for computing the data loss in the network transfer | |
CN1633184A (en) | Multi-reference frame rapid movement estimation method based on effective coverage | |
CN101075261A (en) | Method and device for compressing index | |
CN101043633A (en) | Quantization matrix selecting method, apparatus of coding and coding/decoding method and system | |
CN1650625A (en) | Adaptive method and system for mapping parameter values to codeword indexes | |
CN100346577C (en) | Signal coding device and signal decoding device, and signal coding method and signal decoding method |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C02 | Deemed withdrawal of patent application after publication (patent law 2001) | ||
WD01 | Invention patent application deemed withdrawn after publication |
Open date: 20071010 |