The coding/decoding method of the Variable Length Code based on context-adaptive and system
Technical field
The present invention relates to video multimedia Technical Development Area, relate in particular to a kind of coding/decoding method and system of the Variable Length Code based on context-adaptive.
Background technology
H.264 be the common latest generation video compression standard of releasing of ITU-T (International Telecommunications Union's telecommunication standardsization tissue) and MPEG (dynamic image expert group) tissue, it to H.263 and MPEG-4 similar, belong to the hybrid coding framework based on predictive transformation together, in cataloged procedure, be divided into four major parts:
1) every frame video is divided into block of pixels;
2) infra-frame prediction, trimming space redundancy;
3) by Motion estimation and compensation, carry out the pre-side of interframe, cut down time redundancy;
4) by the residual block to difference forms between original block and corresponding prediction piece convert, quantification and entropy encode, further trimming space redundancy.
H.264 increase a lot of new coding techniquess, greatly improved code efficiency.But its high-performance is the cost that rises to the complexity of its encoding and decoding, for one and same coding sequence, normally 2-3 is H.263 doubly for the required time of H.264 decoding.The complexity of code decode algorithm directly has influence on exploitation based on the efficiency of video scheme H.264.
At entropy coded portion, H.264 there is two sets of plan: one is CAVLC (Variable Length Code based on context-adaptive), and another is CABAC (based on contextual adaptive binary arithmetic coding).Wherein, the essence of CAVLC is variable-length encoding, and its characteristic is mainly reflected in adaptive ability, and CAVLC can dynamically select the code table using in coding according to the situation of the syntax elements of encoding, and upgrade at any time the length of hangover coefficient suffix, thereby obtain high compression ratio.CAVLC for brightness and colourity residual error data through conversion, quantize after the coding of coefficient of 4x4 piece, the correlation of utilizing adjacent coded identification to provide, for the symbol that will encode is selected suitable context model.In CAVLC, the selection of context model is mainly reflected in selects elongated form, has approximately 450 code words of four elongated forms available.
In video decoding process, all video code flows all will be through entropy decoding computing, therefore in whole mixed encoding and decoding system, it has very important status, and the operand of decoder module and stream rate are closely related, residual error data after high bit rate situation down conversion coefficient the quantizes shared code stream of encoding has occupied the more than 70% of code stream total amount, and this just means that decoder module will bear the most operand of entropy decoder.
In prior art, entropy decoding scheme is to resolve syntax elements by reading the code stream of regular length, mainly has following defect:
(1) code stream that first reads regular length while resolving syntax elements can not guarantee to resolve correct, if parse error needs again to read code stream, decodes, and efficiency is lower; And a large amount of judgement of process need of parsing is controlled, and has also affected analyzing efficiency;
(2) memory space that takies of decoding code table is larger, for the embedded device of limited storage space, is a restriction.
Summary of the invention
The embodiment of the present invention provides a kind of coding/decoding method and system of the Variable Length Code based on context-adaptive, to improve decoding efficiency, saves memory space.
For this reason, the embodiment of the present invention provides following technical scheme:
A coding/decoding method for Variable Length Code based on context-adaptive, comprising:
Obtain the code stream that needs decoding;
Determine the nonzero coefficient number predicted value nC in described code stream;
According to described predicted value nC, search the first decoding code table of setting up in advance, obtain nonzero coefficient number and hangover coefficient number in described code stream, described the first decoding code table is the decoding code table that comprises nonzero coefficient number and hangover coefficient number;
If described nonzero coefficient number is greater than 0, and described hangover coefficient number is greater than 0, the even symbol of 1 coefficient of hangover of decoding;
If described nonzero coefficient number is less than the maximum of nonzero coefficient number, according to described nonzero coefficient number, search the second decoding code table of setting up in advance, obtain total number of last nonzero coefficient front 0 in described code stream, described the second decoding code table is the decoding code table of total number of comprising last nonzero coefficient front 0;
According to 0 total number and described nonzero coefficient number before described last nonzero coefficient, the number of other nonzero coefficients front 0 in the described code stream of decoding.
A decode system for Variable Length Code based on context-adaptive, comprising:
Code stream acquiring unit, for obtaining the code stream that needs decoding;
Computing unit, for determining the nonzero coefficient number predicted value nC of described code stream;
The first decoding unit, for search the first decoding code table of setting up in advance according to described predicted value nC, obtain nonzero coefficient number and hangover coefficient number in described code stream, described the first decoding code table is the decoding code table that comprises nonzero coefficient number and hangover coefficient number;
The first judging unit, for judging whether described nonzero coefficient number is greater than 0, and whether described hangover coefficient number is greater than 0;
Symbol resolution unit, for judging that at described the first judging unit described nonzero coefficient number is greater than 0, and described hangover coefficient number is greater than at 0 o'clock, the even symbol of 1 coefficient of hangover of decoding;
The second judging unit, for judging whether described nonzero coefficient number is less than the maximum of nonzero coefficient number;
The second decoding unit, for when described the second judging unit judges that described nonzero coefficient number is less than the maximum of nonzero coefficient number, according to described nonzero coefficient number, search the second decoding code table of setting up in advance, obtain total number of last nonzero coefficient front 0 in described code stream, described the second decoding code table is the decoding code table of total number of comprising last nonzero coefficient front 0;
The 3rd decoding unit, for according to 0 total number and described nonzero coefficient number before described last nonzero coefficient, the number of other nonzero coefficients front 0 in the described code stream of decoding.
Coding/decoding method and the system of the Variable Length Code of the embodiment of the present invention based on context-adaptive, based on code stream, connecting zero number divides into groups again to decoding code table, the decoding of most of syntax has been adopted to the realization of tabling look-up, not only greatly saved the memory space of decoding code table, and effectively improved decoding efficiency, can be advantageously applied in the embedded device of video decode H.264.
Accompanying drawing explanation
In order to be illustrated more clearly in the embodiment of the present application or technical scheme of the prior art, to the accompanying drawing of required use in embodiment be briefly described below, apparently, the accompanying drawing the following describes is only some embodiment that record in the present invention, for those of ordinary skills, can also obtain according to these accompanying drawings other accompanying drawing.
Fig. 1 is the standard code code table while encoding nonzero coefficient number and hangover coefficient number in prior art;
Fig. 2 is the flow chart of embodiment of the present invention CAVLC coding/decoding method;
Fig. 3 is that the nonzero coefficient of encoding in prior art is standard code code table during total number of 0 before 1 to 7 o'clock last nonzero coefficient;
Fig. 4 is the standard code code table of number of some nonzero coefficients front 0 of encoding in prior art;
Fig. 5 be in the embodiment of the present invention, decode nonzero coefficient number and hangover coefficient number flow chart;
Fig. 6 is the flow chart of total number of last nonzero coefficient front 0 of decoding in the embodiment of the present invention;
Fig. 7 is the flow chart of number of some nonzero coefficients front 0 of decoding in the embodiment of the present invention;
Fig. 8 is the structural representation of embodiment of the present invention CAVLC decode system.
Embodiment
In order to make those skilled in the art person understand better the scheme of the embodiment of the present invention, below in conjunction with drawings and embodiments, the embodiment of the present invention is described in further detail.
First, the basic principle of CAVLC Code And Decode in prior art is done to simple introduction.
CAVLC is for encoding to the residual error data of 4 * 4, and the scope of nonzero coefficient number is 0~16, and hangover coefficient number scope is 0~3.If ± 1 number is greater than 3, only have last three to be regarded as the coefficient that trails, remaining is regarded as common nonzero coefficient.To the coding of nonzero coefficient number and hangover coefficient number, by the realization of tabling look-up, coding form is the form in standard agreement, different with decoding table lattice.Have 5 coding forms available, according to nonzero coefficient number predicted value, nC selects form.
For example, 4 * 4 residual error data are: 0,3,0,1 ,-1 ,-1,0,1,0,0,0,0,0,0,0,0, to these 4 * 4 residual error data following syntax elements of need to encoding:
A, nonzero coefficient number numcoeff are 5 in this example; Hangover coefficient number numtrailingones, this example is 3; The coding code table (Fig. 1 only shows the partial content of form) of the standard agreement that Fig. 1 uses while being coding nonzero coefficient number and hangover coefficient number; Suppose nC=0, looking into the code stream that this table can obtain after numcoeff=5 and coding corresponding to numtrailingones=3 is 0000100;
B, three hangover coefficients (-1 in this example ,-1,1) of coding and nonzero coefficient amplitude Levels (3,1 in this example) except hangover coefficient;
The number TotalZeros of c, last nonzero coefficient leading zero of encoding is 3 in this example;
The number RunBefore of d, each nonzero coefficient leading zero of encoding
CAVLC decoding is the reverse procedure of coding, need to from code stream, parse each syntax elements of coding, according to these syntax elements reconstruct residual error data of 4 * 4 out.Decoding is also the process of oppositely tabling look-up to coding code table, for example, knows after encoding code stream 0000100, and tabling look-up and can obtaining nonzero coefficient number is 5, and hangover coefficient number is 3.Other syntax elements of decoding are also similarly, have resolved the residual error data before can being encoded after all syntaxes.
Read code stream in decode procedure after, can repeatedly compare with the code stream of coding code table, find after matching value and just can table look-up and obtain the value of syntax elements, but this analytic method efficiency is extremely low, code table space is also very large, be not suitable for being applied in embedded device, therefore need to redesign decoding code table and improve analyzing efficiency, reduce code table space.
For above-mentioned deficiency, inventor is by the statistics of code table code word rule is found, H.264 in a lot of code tables of CAVLC decoding there is a common feature, its code word is many 0, and its code word is less in first 1 number of bits below.Therefore, embodiment of the present invention CAVLC coding/decoding method and system, the company's zero number based on code word, first obtain the number leadingzeros of initial company zero, the table of looking into again a n bit just can pass through table lookup operation, obtains the value of syntax elements, and described n is first 1 bit number below.
Further, for the design of code table, based on connecting zero number, divide into groups, by connecting the identical code word of zero number, be divided into one group, the code word of every group is further distinguished by first 1 n Bit data below.Therefore, in decode procedure, can first obtain company's zero number of code word, based on this, find the group at code word place, then read the data of n bit, further find code word concrete in this group, can obtain the value of syntax elements.
Further, because CAVLC decoding is the company's zero number based on code word, in decode procedure, need to read repeatedly company's zero number of code word, therefore in embodiments of the present invention, also can obtain by hardware mode company's zero number of code word, improve the speed of the company's zero number that obtains code word, promote decoding efficiency.
As shown in Figure 2, be the flow chart of embodiment of the present invention CAVLC coding/decoding method, comprise following basic step:
Step 201, obtains the code stream that needs decoding.
Step 202, determines the nonzero coefficient number predicted value nC in described code stream.
The nonzero coefficient number nB of the nonzero coefficient number nA of the value of nC based on current block left side and current block upside calculates and gets.If current block left side and upper lateral mass are all available, nC=(nA+nB+1) > > 1; If one of current block left side and upper lateral mass are available, nC equals nA or nB; If current block left side and upper lateral mass are all unavailable, nC equals 0.
Step 203, searches the first decoding code table of setting up in advance according to described predicted value nC, obtain nonzero coefficient number and hangover coefficient number in described code stream, and described the first decoding code table is the decoding code table that comprises nonzero coefficient number and hangover coefficient number.
Step 204, if described nonzero coefficient number is greater than 0, and described hangover coefficient number is greater than 0, the even symbol of 1 coefficient of hangover of decoding.
If nonzero coefficient number is less than or equal to 0, show that code word is full 0, does not now need to carry out other decode procedures again; Equally, if hangover coefficient number is less than or equal to 0, show not trail coefficient, therefore, the hangover of also just need not decoding has connected the symbol of 1 coefficient.
When decoding hangover connects the symbol of 1 coefficient, can carry out the symbol of Coefficient of determination 1 by the Bit data directly reading in code stream, if the Bit data reading is 1, the symbol that represents coefficient 1 is "-"; If the Bit data reading is 0, the symbol that represents coefficient 1 is "+".
Step 205, if described nonzero coefficient number is less than the maximum of nonzero coefficient number, according to described nonzero coefficient number, search the second decoding code table of setting up in advance, obtain total number of last nonzero coefficient front 0 in described code stream, described the second decoding code table is the decoding code table of total number of comprising last nonzero coefficient front 0.
Step 206, the number of other nonzero coefficients front 0 in the described code stream of decoding.
If nonzero coefficient number is more than or equal to the maximum of nonzero coefficient number, 16, showing does not have 0 in described code stream, therefore, also just without carrying out above-mentioned steps 205 and step 206.
It should be noted that, between above-mentioned steps 204 and step 205, also can be further comprising the steps: other nonzero coefficient amplitudes of decoding.Concrete decode procedure can adopt mode same as the prior art.
The embodiment of the present invention, when carrying out CAVLC decoding, need to be set up the decoding code table that corresponding each syntax is resolved in advance, i.e. foregoing the first decoding code table, the second decoding code table, the 3rd decoding code table.The method for building up of the code table of respectively decoding will be described in detail below.
The form of the nonzero coefficient number of encoding shown in analysis chart 1 and the standard agreement of hangover during coefficient number, can find that there is following characteristics: its code word is many 0, and Dalian zero number is 14, and first 1 only has at most three bits below.Therefore, based on these features, can set up a nonzero coefficient number and hangover coefficient number decoding code table, for convenience of description, be referred to as the first decoding code table.According to bit stream data, search described the first decoding code table, obtain decoded two syntax elements information: nonzero coefficient number, hangover coefficient number obtain first 1 code stream length below, for mobile code stream bit pointers simultaneously.
When setting up described the first decoding code table, first based on connecting zero number, code word is divided into groups, by connecting the identical code word of zero number, be divided into one group, the code word of every group is further distinguished code word concrete in this group by first 1 n Bit data below, can obtain the value of syntax elements.
The design process that the 0 <=nC < 2 (nC is nonzero coefficient number predicted value) of take is below example explanation nonzero coefficient number and hangover coefficient number decoding code table, detailed process is as follows:
First, according to the standard code code table shown in Fig. 1, by connecting the identical code stream of zero number, be divided into one group, obtain:
Connecting the code stream that zero number is 0 has 1, is code stream " 1 ";
Connecting the code stream that zero number is 1 has 1, is code stream " 01 ";
Connecting the code stream that zero number is 2 has 1, is code stream " 001 ";
Connecting the code stream that zero number is 3 has 3, is respectively code stream " 000101 ", " 000100 ", " 00011 ";
Connecting the code stream that zero number is 4 has 3, is respectively code stream " 0000101 ", " 000011 ", " 0000100 ";
Connecting the code stream that zero number is 5 has 3, is respectively code stream " 00000111 ", " 00000110 ", " 00000101 ";
Connecting the code stream that zero number is 6 has 3, is respectively code stream " 000000111 ", " 000000110 ", " 000000101 ";
Connecting the code stream that zero number is 7 has 2, is respectively code stream " 0000000111 ", " 0000000110 ";
Connecting the code stream that zero number is 8 has 1, is respectively code stream " 00000000111 ";
By above-mentioned each group code stream, can be found out, first of these code streams 1 only has at most two bits of data below, therefore when company's zero number is identical, utilizes in code stream first 1 two bits of data below can distinguish concrete code stream.
For example, connecting the code stream that zero number is 4 has 3, is respectively " 0000101 ", " 000011 ", " 0000100 ", has determined that connecting zero number is to read in code stream first 1 two bits of data below after 4 again during parsing.
If first reading 1 two bits of data is below 0, be expressed as code stream " 0000100 ", hangover coefficient number and the nonzero coefficient number of known its correspondence of code table of encoding are as shown in Figure 1 respectively 3 and 5, first 1 code stream length is below that 2 (this value is not the syntax elements of standard, be only used to mobile code flow index when resolving, also can design in nonzero coefficient number and hangover coefficient number decoding code table);
If first reading 1 two bits of data is below 1, be expressed as code stream " 0000101 ", hangover coefficient number and the nonzero coefficient number of known its correspondence of code table of encoding are as shown in Figure 1 respectively 2 and 3, and first 1 code stream length is below 2;
If first reading 1 two bits of data is below 2 or 3, (first 1 actually below only has 1 Bit data this code stream to be expressed as code stream " 000011 ", second 1 Bit data is unknown, therefore the two bits of data of reading is 2 or 3 all to represent this code stream), hangover coefficient number and the nonzero coefficient number of its correspondence are respectively 4 and 3, and first 1 code stream length is below 1.
Therefore when connecting the nonzero coefficient number and the hangover coefficient number decoding code table that design when zero number is 4, be, { { 2,5,3}, { 2,3,2}, { Isosorbide-5-Nitrae, 3}, { Isosorbide-5-Nitrae, 3}}, wherein, three values in each set represent respectively in code stream first 1 code stream length, nonzero coefficient number and coefficient number of trailing below.Such as, { 2,5,3} represents that code stream length is 2, and nonzero coefficient number is 5, and hangover coefficient number is 3.
According to above-mentioned thought, can design for nC nonzero coefficient number and hangover coefficient number decoding code table under different value condition, i.e. described the first decoding code table.
In order to make whole decoding code table keep alignment, to calculate to more convenient and quicker code table index value when tabling look-up, in this decoding code table, can also comprise some repetition values or invalid filling value.For example, when connecting zero number and be n (0=< n <=8), directly n is moved to left 2 (taking advantage of 4), can obtain the group at place:
{
0,0,0}, and 0,0,0}, 0,0,0}, 0,0,0}, // even zero number is 0 o'clock
0,1,1}, and 0,1,1}, 0,1,1}, 0,1,1}, // even zero number is 1 o'clock
0,2,2}, and 0,2,2}, 0,2,2}, 0,2,2}, // even zero number is 2 o'clock
2,2,1}, and 2,1,0}, 1,3,3}, 1,3,3}, // even zero number is 3 o'clock
2,5,3}, 2,3,2}, Isosorbide-5-Nitrae, 3}, Isosorbide-5-Nitrae, 3}, // even zero number is 4 o'clock
100 ,-100 ,-100}, 2,4,2}, 2,3,1}, 2,2,0}, // even zero number is 5 o'clock ,-100 represent can not
There is this situation
100 ,-100 ,-100}, 2,5,2}, 2,4,1}, 2,3,0}, // even zero number is 6 o'clock
100 ,-100 ,-100}, 100 ,-100 ,-100}, 2,5,1}, 2,4,0}, // even zero number is 7 o'clock
100 ,-100 ,-100}, 100 ,-100 ,-100}, 100 ,-100 ,-100}, 2,5,0}, // even zero number is 8
Time
}
In embodiments of the present invention, can design described the second decoding code table based on connecting zero number equally.
As shown in Figure 3, be the standard code code table of nonzero coefficient while being total number of 0 before 1 to 7 o'clock last nonzero coefficient (below represent with TotalZeros) of encoding in prior art.
Standard code code table based on shown in above-mentioned Fig. 3, the nonzero coefficient of take below equals 2, and (shown in Fig. 3 in form the 3rd row) be example, describe in detail the TotalZeros that decodes decoding code table design process, detailed process is as follows:
First, need to find out the maximum Maxnum_LeadingZeros that connects in this case zero number, when nonzero coefficient is 2, observe the known Maxnum_LeadingZeros=6 of coding code table shown in Fig. 3.
Secondly, by connecting the identical code stream of zero number, be divided into one group, when nonzero coefficient is 2, be grouped as follows:
Connecting the code stream that zero number is 0 has 4, is respectively " 111 ", " 110 ", " 101 ", " 100 ";
Connecting the code stream that zero number is 1 has 3, is respectively " 011 ", " 0101 ", " 0100 ";
Connecting the code stream that zero number is 2 has 2, is respectively " 0011 ", " 0010 ";
Connecting the code stream that zero number is 3 has 2, is respectively " 00011 ", " 00010 ";
Connecting the code stream that zero number is 4 has 2, is respectively " 000011 ", " 000010 ";
Connecting the code stream that zero number is 5 has 1, is respectively " 000001 ";
Connecting the code stream that zero number is 6 has 1, is respectively " 000000 ".
By above-mentioned each group code stream, can be found out, first 1 only has at most below dibit (complete zero situation special processing), therefore, when connecting zero number when identical, can distinguish concrete code stream with first 1 two bits of data below.For example, the decoding code table when even zero number is 0 is { 2,3}, { 2,2}, { 2,1}, { 2,0}.Wherein, in each set, comprise two values, first value representation first " 1 " has two bits of data below, second value is TotalZeors, such as, { 2, first 1 has below two bits of data, second value representation TotalZeors=3 first value representation in 3}.
The decoding code table of the TotalZeros that finally to design when nonzero coefficient be 2 is as follows:
{
2,3}, and 2,2}, 2,1}, 2,0}, // even zero number is 0 o'clock
2,6}, and 2,5}, { Isosorbide-5-Nitrae }, { Isosorbide-5-Nitrae }, // even zero number is 1 o'clock
1,8}, and 1,8}, 1,7}, 1,7}, // even zero number is 2 o'clock
1,10}, and 1,10}, 1,9}, 1,9}, // even zero number is 3 o'clock
1,12}, and 1,12}, 1,11}, 1,11}, // even zero number is 4 o'clock
0,13}, and 0,13}, 0,13}, 0,13}, // even zero number is 5 o'clock
0,14}, and 0,14}, 0,14}, 0,14}, // even zero number is 6 o'clock
}
It should be noted that, observe the coding code table shown in Fig. 3 known, when being 2, nonzero coefficient has complete zero situation, now read and when code stream connects zero and counts, may occur connecting the situation that zero number is greater than 6, therefore in decode procedure, need to count Maxnum_LeadingZeros by Dalian zero and control, if the company's of parsing zero number is greater than 6 and makes it equal 6 in decode procedure.
According to above-mentioned principle, can design the decoding code table of TotalZeros when nonzero coefficient is different value, and be combined, can generate the decoding code table of total number of last nonzero coefficient front 0, i.e. foregoing the second decoding code table.
It should be noted that, when nonzero coefficient is got different value, the decoding code table size of TotalZeros is different, therefore can design in addition a skew code table TotalZerosTable_indexoffset[15], this code table be take nonzero coefficient number as index value, the content that obtains of tabling look-up be nonzero coefficient while getting this value TotalZeros decoding code table at the deviation post of total code table.
In addition, the Dalian zero array that nonzero coefficient number can also be got to different value code stream is combined in a code table Maxnum_LeadingZerosTable[15] in, this code table be take nonzero coefficient number as index value, and the content obtaining of tabling look-up is the Dalian zero number that nonzero coefficient is got this value code stream.
In embodiments of the present invention, can set up described the 3rd decoding code table based on connecting zero number equally.
As shown in Figure 4, be the standard code code table of number of some nonzero coefficients front 0 of encoding in prior art.
The code book of encoding is as shown in Figure 4 known, only has when zeroleft is greater than 6 code stream length and is greater than 3, therefore can only to code stream length, be less than or equal to 3 code stream design code table decoding; The value that can find out before some nonzero coefficients 0 number RunBefore when code stream length is greater than 3 with connect zero number and have relation one to one, be that RunBefore=connects zero number+4, therefore adopt in this case the mode of calculating can obtain the value of RunBefore.
The zeroleft of take is below greater than 6 design processes as example explanation RunBefore decoding code table.
Decoding can directly be read three Bit datas during RunBefore from code stream, and the size of this three Bit data of take is tabled look-up and obtained value and the code stream length value of RunBefore as index, when the value that obtains RunBefore if table look-up is 7 (this value is equivalent to a special mark, can set arbitrarily a value), obtain code stream and connect zero number, the value of RunBefore equals to connect zero number and adds 4, and corresponding code table is: { 7,0}, { 6,3}, { 5,3}, { 4,3}, { 3,3}, { 2,3}, { 1,3}, { 0,3}.
According to above-mentioned principle, can design the decoding code table of RunBefore, i.e. foregoing the 3rd decoding code table, whole code table is as follows:
VLCtab2?RunBeforeTable_vlc[]=
{//{run_before,len},run_before?table
{ 1,1}, { 1,1}, { 1,1}, { 1,1}, { 0,1}, { 0,1}, { 0,1}, { 0,1}, //zeroleft equals at 1 o'clock
{ 2,2}, { 2,2}, { 1,2}, { 1,2}, { 0,1}, { 0,1}, { 0,1}, { 0,1}, //zeroleft equals at 2 o'clock
{ 3,2}, { 3,2}, { 2,2}, { 2,2}, { 1,2}, { 1,2}, { 0,2}, { 0,2}, //zeroleft equals at 3 o'clock
{ 4,3}, { 3,3}, { 2,2}, { 2,2}, { 1,2}, { 1,2}, { 0,2}, { 0,2}, //zeroleft equals at 4 o'clock
{ 5,3}, { 4,3}, { 3,3}, { 2,3}, { 1,2}, { 1,2}, { 0,2}, { 0,2}, //zeroleft equals at 5 o'clock
{ 1,3}, { 2,3}, { 4,3}, { 3,3}, { 6,3}, { 5,3}, { 0,2}, { 0,2}, //zeroleft equals at 6 o'clock
{ 7,0}, { 6,3}, { 5,3}, { 4,3}, { 3,3}, { 2,3}, { 1,3}, { 0,3} //zeroleft is greater than at 6 o'clock
};
In embodiments of the present invention, the gross space of required decoding code table is: 360+312+240+128+72+734+48+112+12+64=2082words.
All decoding code tables illustrate in table 1:
Table 1
Concrete code table design is as follows:
VLCtab1?CoeffTokenTable_vlcN[]=
{//{len,numcoeffs,trallingones},0<=nC<2
{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},
{0,1,1},{0,1,1},{0,1,1},{0,1,1},{0,1,1},{0,1,1},{0,1,1},{0,1,1},
{0,2,2},{0,2,2},{0,2,2},{0,2,2},{0,2,2},{0,2,2},{0,2,2},{0,2,2},
{2,2,1},{2,2,1},{2,1,0},{2,1,0},{1,3,3},{1,3,3},{1,3,3},{1,3,3},
{2,5,3},{2,5,3},{2,3,2},{2,3,2},{1,4,3},{1,4,3},{1,4,3},{1,4,3},
{2,6,3},{2,6,3},{2,4,2},{2,4,2},{2,3,1},{2,3,1},{2,2,0},{2,2,0},
{2,7,3},{2,7,3},{2,5,2},{2,5,2},{2,4,1},{2,4,1},{2,3,0},{2,3,0},
{2,8,3},{2,8,3},{2,6,2},{2,6,2},{2,5,1},{2,5,1},{2,4,0},{2,4,0},
{2,9,3},{2,9,3},{2,7,2},{2,7,2},{2,6,1},{2,6,1},{2,5,0},{2,5,0},
{3,8,0},{3,9,2},{3,8,1},{3,7,0},{3,10,3},{3,8,2},{3,7,1},{3,6,0},
{3,12,3},{3,11,2},{3,10,1},{3,10,0},{3,11,3},{3,10,2},{3,9,1},{3,9,0},
{3,14,3},{3,13,2},{3,12,1},{3,12,0},{3,13,3},{3,12,2},{3,11,1},{3,11,0},
{3,16,3},{3,15,2},{3,15,1},{3,14,0},{3,15,3},{3,14,2},{3,14,1},{3,13,0},
{2,16,0},{2,16,0},{2,16,2},{2,16,2},{2,16,1},{2,16,1},{2,15,0},{2,15,0},
{0,13,1},{0,13,1},{0,13,1},{0,13,1},{0,13,1},{0,13,1},{0,13,1},{0,13,1},
{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},
//{len,numcoeffs,trallingones},2<=nC<4
{1,1,1},{1,1,1},{1,1,1},{1,1,1},{1,0,0},{1,0,0},{1,0,0},{1,0,0},
{2,4,3},{2,4,3},{2,3,3},{2,3,3},{1,2,2},{1,2,2},{1,2,2},{1,2,2},
{3,6,3},{3,3,2},{3,3,1},{3,1,0},{2,5,3},{2,5,3},{2,2,1},{2,2,1},
{2,7,3},{2,7,3},{2,4,2},{2,4,2},{2,4,1},{2,4,1},{2,2,0},{2,2,0},
{2,8,3},{2,8,3},{2,5,2},{2,5,2},{2,5,1},{2,5,1},{2,3,0},{2,3,0},
{2,5,0},{2,5,0},{2,6,2},{2,6,2},{2,6,1},{2,6,1},{2,4,0},{2,4,0},
{2,9,3},{2,9,3},{2,7,2},{2,7,2},{2,7,1},{2,7,1},{2,6,0},{2,6,0},
{3,11,3},{3,9,2},{3,9,1},{3,8,0},{3,10,3},{3,8,2},{3,8,1},{3,7,0},
{3,11,0},{3,11,2},{3,11,1},{3,10,0},{3,12,3},{3,10,2},{3,10,1},{3,9,0},
{3,14,3},{3,13,2},{3,13,1},{3,13,0},{3,13,3},{3,12,2},{3,12,1},{3,12,0},
{3,15,1},{3,15,0},{3,15,2},{3,14,1},{2,14,2},{2,14,2},{2,14,0},{2,14,0},
{2,16,3},{2,16,3},{2,16,2},{2,16,2},{2,16,1},{2,16,1},{2,16,0},{2,16,0},
{0,15,3},{0,15,3},{0,15,3},{0,15,3},{0,15,3},{0,15,3},{0,15,3},{0,15,3},
{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},
{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},
{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},
//{len,numcoeffs,trallingones},4<=nC<8
{3,7,3},{3,6,3},{3,5,3},{3,4,3},{3,3,3},{3,2,2},{3,1,1},{3,0,0},
{3,5,1},{3,5,2},{3,4,1},{3,4,2},{3,3,1},{3,8,3},{3,3,2},{3,2,1},
{3,3,0},{3,7,2},{3,7,1},{3,2,0},{3,9,3},{3,6,2},{3,6,1},{3,1,0},
{3,7,0},{3,6,0},{3,9,2},{3,5,0},{3,10,3},{3,8,2},{3,8,1},{3,4,0},
{3,12,3},{3,11,2},{3,10,1},{3,9,0},{3,11,3},{3,10,2},{3,9,1},{3,8,0},
{3,12,0},{3,13,2},{3,12,1},{3,11,0},{3,13,3},{3,12,2},{3,11,1},{3,10,0},
{3,15,1},{3,14,0},{3,14,3},{3,14,2},{3,14,1},{3,13,0},{2,13,1},{2,13,1},
{2,16,1},{2,16,1},{2,15,0},{2,15,0},{2,15,3},{2,15,3},{2,15,2},{2,15,2},
{1,16,3},{1,16,3},{1,16,3},{1,16,3},{1,16,2},{1,16,2},{1,16,2},{1,16,2},
{0,16,0},{0,16,0},{0,16,0},{0,16,0},{0,16,0},{0,16,0},{0,16,0},{0,16,0}
};
VLCtab2?CoeffTokenTable_vlc3[]=
{//{numcoeffs,trallingones},Chroma?DC,nC=-1
{1,1},{1,1},{1,1},{1,1},
{0,0},{0,0},{0,0},{0,0},
{2,2},{2,2},{2,2},{2,2},
{2,0},{3,3},{2,1},{1,0},
{4,0},{4,0},{3,0},{3,0},
{3,2},{3,2},{3,1},{3,1},
{4,2},{4,2},{4,1},{4,1},
{4,3},{4,3},{4,3},{4,3}
};
const?INT16?CoeffTokenTable_vlc3_len[8]=
{//{len},Chroma?DC,nC=-1
0,0,0,2,1,1,1,0
};
VLCtab2?CoeffTokenTable_vlc4[]=
{//{numcoeffs,trallingones},8<=nC,len=6
{1,0},{1,1},{-1,-1},{0,0},
{2,0},{2,1},{2,2},{-1,-1},
{3,0},{3,1},{3,2},{3,3},
{4,0},{4,1},{4,2},{4,3},
{5,0},{5,1},{5,2},{5,3},
{6,0},{6,1},{6,2},{6,3},
{7,0},{7,1},{7,2},{7,3},
{8,0},{8,1},{8,2},{8,3},
{9,0},{9,1},{9,2},{9,3},
{10,0},{10,1},{10,2},{10,3},
{11,0},{11,1},{11,2},{11,3},
{12,0},{12,1},{12,2},{12,3},
{13,0},{13,1},{13,2},{13,3},
{14,0},{14,1},{14,2},{14,3},
{15,0},{15,1},{15,2},{15,3},
{16,0},{16,1},{16,2},{16,3}
};
VLCtab2?TotalZerosTable[]=
{//{len,totalzeros},total_zeros?table
{0,0},{0,0},{0,0},{0,0},{1,2},{1,2},{1,1},{1,1},{1,4},{1,4},{1,3},{1,3},
{1,6},{1,6},{1,5},{1,5},{1,8},{1,8},{1,7},{1,7},{1,10},{1,10},{1,9},{1,9},
{1,12},{1,12},{1,11},{1,11},{1,14},{1,14},{1,13},{1,13},{1,15},{1,15},{1,15},{1,15},
{2,3},{2,2},{2,1},{2,0},{2,6},{2,5},{1,4},{1,4},{1,8},{1,8},{1,7},{1,7},
{1,10},{1,10},{1,9},{1,9},{1,12},{1,12},{1,11},{1,11},{0,13},{0,13},{0,13},{0,13},
{0,14},{0,14},{0,14},{0,14},{2,6},{2,3},{2,2},{2,1},{2,4},{2,0},{1,7},{1,7},
{1,8},{1,8},{1,5},{1,5},{1,10},{1,10},{1,9},{1,9},{0,12},{0,12},{0,12},{0,12},
{0,11},{0,11},{0,11},{0,11},{0,13},{0,13},{0,13},{0,13},{2,6},{2,5},{2,4},{2,1},
{2,3},{2,2},{1,8},{1,8},{1,9},{1,9},{1,7},{1,7},{1,10},{1,10},{1,0},{1,0},
{0,11},{0,11},{0,11},{0,11},{0,12},{0,12},{0,12},{0,12},{2,6},{2,5},{2,4},{2,3},
{2,1},{2,0},{1,7},{1,7},{1,8},{1,8},{1,2},{1,2},{0,10},{0,10},{0,10},{0,10},
{0,9},{0,9},{0,9},{0,9},{0,11},{0,11},{0,11},{0,11},{2,5},{2,4},{2,3},{2,2},
{1,7},{1,7},{1,6},{1,6},{0,9},{0,9},{0,9},{0,9},{0,8},{0,8},{0,8},{0,8},
{0,1},{0,1},{0,1},{0,1},{0,0},{0,0},{0,0},{0,0},{0,10},{0,10},{0,10},{0,10},
{2,3},{2,2},{1,5},{1,5},{1,6},{1,6},{1,4},{1,4},{0,8},{0,8},{0,8},{0,8},
{0,7},{0,7},{0,7},{0,7},{0,1},{0,1},{0,1},{0,1},{0,0},{0,0},{0,0},{0,0},
{0,9},{0,9},{0,9},{0,9},{1,5},{1,5},{1,4},{1,4},{1,6},{1,6},{1,3},{1,3},
{0,7},{0,7},{0,7},{0,7},{0,1},{0,1},{0,1},{0,1},{0,2},{0,2},{0,2},{0,2},
{0,0},{0,0},{0,0},{0,0},{0,8},{0,8},{0,8},{0,8},{1,4},{1,4},{1,3},{1,3},
{0,6},{0,6},{0,6},{0,6},{0,5},{0,5},{0,5},{0,5},{0,2},{0,2},{0,2},{0,2},
{0,7},{0,7},{0,7},{0,7},{0,0},{0,0},{0,0},{0,0},{0,1},{0,1},{0,1},{0,1},
{1,4},{1,4},{1,3},{1,3},{0,5},{0,5},{0,5},{0,5},{0,2},{0,2},{0,2},{0,2},
{0,6},{0,6},{0,6},{0,6},{0,0},{0,0},{0,0},{0,0},{0,1},{0,1},{0,1},{0,1},
{0,4},{0,4},{0,4},{0,4},{1,3},{1,3},{1,5},{1,5},{0,2},{0,2},{0,2},{0,2},
{0,1},{0,1},{0,1},{0,1},{0,0},{0,0},{0,0},{0,0},{0,3},{0,3},{0,3},{0,3},
{0,2},{0,2},{0,2},{0,2},{0,4},{0,4},{0,4},{0,4},{0,1},{0,1},{0,1},{0,1},
{0,0},{0,0},{0,0},{0,0},{0,2},{0,2},{0,2},{0,2},{0,3},{0,3},{0,3},{0,3},
{0,1},{0,1},{0,1},{0,1},{0,0},{0,0},{0,0},{0,0},{0,2},{0,2},{0,2},{0,2},
{0,1},{0,1},{0,1},{0,1},{0,0},{0,0},{0,0},{0,0},{0,1},{0,1},{0,1},{0,1},
{0,0},{0,0},{0,0},{0,0}
};
const?INT16?Maxnum_LeadingZerosTable[15]=
{//total_zeros?table
8,6,6,5,5,
6,6,6,6,5,
4,4,3,2,1
};
const?INT16?TotalZerosTable_indexoffset[15]=
{
0,36,64,92,116,
140,168,196,224,252,
276,296,316,332,344
};
VLCtab2?TotalZerosChromaDCTable_vlc[]=
{//{len,totalzeros},total_zeros?table,Chroma?DC
{3,3},{3,2},{2,1},{2,1},{1,0},{1,0},{1,0},{1,0},
{2,2},{2,2},{2,1},{2,1},{1,0},{1,0},{1,0},{1,0},
{1,1},{1,1},{1,1},{1,1},{1,0},{1,0},{1,0},{1,0}
};
VLCtab2?RunBeforeTable_vlc[]=
{//{run_before,len},run_before?table
{1,1},{1,1},{1,1},{1,1},{0,1},{0,1},{0,1},{0,1},
{2,2},{2,2},{1,2},{1,2},{0,1},{0,1},{0,1},{0,1},
{3,2},{3,2},{2,2},{2,2},{1,2},{1,2},{0,2},{0,2},
{4,3},{3,3},{2,2},{2,2},{1,2},{1,2},{0,2},{0,2},
{5,3},{4,3},{3,3},{2,3},{1,2},{1,2},{0,2},{0,2},
{1,3},{2,3},{4,3},{3,3},{6,3},{5,3},{0,2},{0,2},
{7,0},{6,3},{5,3},{4,3},{3,3},{2,3},{1,3},{0,3}
};
const?INT16?TrailingOnes_Index[]=
{//-100:just?for?efficiency,invalid?value
0,0,0,-100,0,-1,-1,-100,0,-1,-2,-100
};
const?INT16?TrailingOnes_Table[]=
{//-100:just?for?efficiency,invalid?value
1,1,1,-100,-1,-1,-1,-100,-100,-100,-100,-100,-100,-100,-100,-100,
1,1,1,-100,1,-1,-1,-100,-1,1,1,-100,-1,-1,-1,-100,
1,1,1,-100,1,1,-1,-100,1,-1,1,-100,1,-1,-1,-100,
-1,1,1,-100,-1,1,-1,-100,-1,-1,1,-100,-1,-1,-1,-100
};
Based on the above-mentioned code table of respectively decoding, below the detailed process of each syntax elements of decoding in the embodiment of the present invention is elaborated.
As shown in Figure 5, be in the embodiment of the present invention, decode nonzero coefficient number and hangover coefficient number flow chart, comprise the following steps:
Judge the scope of definite nonzero coefficient number predicted value nC, then according to the different values of nC, nonzero coefficient number NumCoeff and hangover coefficient number TrailingOnes are decoded.
(1) in 0 <=nC < 2,2 <=nC < 4,4 <=nC <, 8 these three kinds of situations, according to connecting in zero number and described code stream first 1 three Bit datas below in code stream, calculate code table index, search corresponding decoding code table and obtain NumCoeff and TrailingOnes, specific as follows:
NumCoeff and TrailingOnes while a) decoding 0 <=nC < 2
Known according to the code table of standard code shown in Fig. 1, the longest in this code stream to connect zero number be 14, and first 1 only has three bits below.Therefore, when decoding, obtain company's zero number in code stream and first 1 three Bit datas below, according to connecting zero number and described three Bit datas, calculate code table index value, searching decoding code table CoeffTokenTable_vlcN can obtain: first 1 code stream length, NumCoeff and TrailingOnes below in described code stream.
NumCoeff during corresponding 0 <=nC < 2 and the decoding code table space of TrailingOnes are: 15 * 8 * 3=360words.
NumCoeff and TrailingOnes while b) decoding 2 <=nC < 4
Known according to the code table of standard code shown in Fig. 1, the longest in this code stream to connect zero number be 12, and first 1 only has three Bit datas below.Therefore, when decoding, obtain company's zero number in code stream and first 1 three bits below, according to connecting zero number and described three Bit datas, calculate code table index value, searching decoding code table CoeffTokenTable_vlcN can obtain: first 1 code stream length, NumCoeff and TrailingOnes below in described code stream.
NumCoeff during corresponding 2 <=nC < 4 and the decoding code table space of TrailingOnes are: 13 * 8 * 3=312words.
NumCoeff and TrailingOnes while c) decoding 4 <=nC < 8
Known according to the code table of standard code shown in Fig. 1, the longest in this code stream to connect zero number be 9, and first 1 only has three Bit datas below.Therefore, when decoding, obtain company's zero number of code stream and first 1 three Bit datas below, according to connecting zero number and described three Bit datas, calculate code table index value, the CoeffTokenTable_vlcN that tables look-up can obtain: first 1 code stream length, NumCoeff and TrailingOnes below in described code stream.
NumCoeff during corresponding 4 <=nC < 8 and the decoding code table space of TrailingOnes are: 10 * 8 * 3=240words.
(2) in the situation that of when 8 <=nC, this code stream length is fixed as 6 bits, therefore directly reads 6 Bit datas as code table index.
In decoding code table CoeffTokenTable_vlc4 for this situation, only comprise nonzero coefficient number and hangover coefficient number, therefore, directly from described code stream, read in 6 bits, using its numerical value as index value, scope is 0~63, and the CoeffTokenTable_vlc4 that tables look-up can obtain NumCoeff and TrailingOnes.
NumCoeff during corresponding 8 <=nC and the decoding code table space of TrailingOnes are: 64 * 2=128words.
(3) NumCoeff and TrailingOnes while decoding nC=-1 (colourity DC)
In this case, according to connecting in zero number and described code stream first 1 two bits of data below in code stream, calculate code table index, search corresponding decoding code table and obtain NumCoeff and TrailingOnes,
Known according to the code table of standard code shown in Fig. 1, in this code stream, the longest even zero number is 7, first 1 only has at most below two bits, and code length and connect zero number and have relation one to one, with front 5 code streams " 01 " when the nC=-1 in Fig. 1, " 000111 ", " 1 ", " 000100 ", " 000110 " is example, company's zero number of their correspondences is respectively 1, 3, 0, 3, 3, first " 1 " code stream length is below respectively 0, 2, 0, 2, 2, when even zero number is got certain value, first " 1 " code stream length is below a fixed value.Therefore can set up two code tables: the value in a code table is first 1 code stream length (can table look-up as index with company's zero number) below, and code table space is 8; Value in another code table is nonzero coefficient number and hangover coefficient number, and code table space is 64words.
Therefore, in when decoding, first obtain the company's zero number in code stream, then read first 1 two bits below.According to connecting the zero number CoeffTokenTable_vlc3_len that tables look-up, obtain in code stream first 1 code stream length below; According to the two bits of data that connects zero number and read, calculate another code table index value, the CoeffTokenTable_vlc3 that tables look-up can obtain NumCoeff and TrailingOnes.
NumCoeff during corresponding nC=-1 and the decoding code table space of TrailingOnes are: 8+64=72words.
It should be noted that, when code stream connects zero number and is 7, belong to complete zero situation, need special processing.Because in this case, connect zero number and mostly be 7 most, therefore after the company's of having read zero number, judge whether to be greater than 7, if be greater than 7, make it equal 7.
As shown in Figure 6, be the flow chart of total number TotalZeros of last nonzero coefficient front 0 of decoding in the embodiment of the present invention.
Step 601, the nonzero coefficient number obtaining according to decoding is searched standard code code table and is obtained corresponding Dalian zero number, and determines code table deviant according to described nonzero coefficient number;
Step 602, reads and in code stream, connects zero and count leadingzeros and first 1 two Bit datas below;
Step 603, judge described connect zero count leadingzeros whether be greater than described in Dalian zero number; If so, perform step 604; Otherwise, execution step 605;
Step 604, the company's zero reading count leadingzeros be set to described in Dalian zero number;
Step 605, according to described code table deviant, describedly connect that zero is counted leadingzeros and described two bits of data calculates code table index;
Step 606, according to described code table index search decoding code table TotalZerosTable[704], obtain total number of last nonzero coefficient front 0 in described code stream.
Based on above-mentioned decode procedure, the concrete condition of the TotalZeros when TotalZeros during below for the non-colourity DC of decoding and decoding colourity DC describes.
(1) TotalZeros while decoding non-colourity DC (DC coefficient)
First, according to the nonzero coefficient number TotalCoeff that obtained, obtain two data: one is Dalian zero number (obtaining according to the code word statistics in standard code code table) corresponding to this nonzero coefficient number; Another deviation post that is some code words corresponding to this nonzero coefficient number in decoding look-up table is above-mentioned code table deviant, and this deviation post TotalZerosTable_indexoffset that tables look-up can obtain.According to known first of standard code code table, 1 only have at most below two bits, therefore obtain and read first 1 two Bit datas below after company's zero number of code stream, then, according to described two bits of data and the code table deviant of having determined above with connect zero number and calculate code table index value, from table TotalZerosTable, find practical codeword lengths and TotalZeros, successfully decoded finishes.
The decoding code table space of TotalZeros during corresponding non-colourity DC is: 352 * 2=704words.
Because decoding needs, can also set up two code tables, that is:
Dalian zero digital table Maxnum_LeadingZerosTable and TotalZeros skew code table TotalZerosTable_indexoffset.
It should be noted that, in this case, a lot of code streams there will be complete zero situation, need special processing.Concrete processing procedure is as follows:
Because the value in the digital table of Dalian zero Maxnum_LeadingZerosTable is the Dalian zero number of nonzero coefficient number TotalCoeff while getting different value, therefore, after the company's of having read zero numerical value, judge whether this value is greater than the Dalian zero numerical value that this code table is corresponding, if be greater than, make this value equal corresponding Dalian zero numerical value in code table.
The gross space of Dalian zero digital table Maxnum_LeadingZerosTable and TotalZeros skew code table TotalZerosTable_indexoffset is: 30words.
(2) TotalZeros while decoding colourity DC
In this case, code stream length is all less than or equal to 3 bits.From code stream, read three Bit datas, according to three Bit datas that obtain, together with the nonzero coefficient number obtaining of having decoded, calculate code table index value above, from code table TotalZerosChromaDCTable_vlc, find practical codeword lengths and TotalZeros.
The space of code table TotalZerosChromaDCTable_vlc is: 3 * 8 * 2=48words.
As shown in Figure 7, be the flow chart of number of some nonzero coefficients front 0 of decoding in the embodiment of the present invention.
In this decode procedure, need according to total number TotalZeros of last nonzero coefficient front 0 that decoding obtains before and the number RunBefore that a nonzero coefficient number decoder obtains some nonzero coefficients front 0.
According to the feature of standard code code table, a minute code length is less than or equal to 3 and be greater than 3 two kinds of situation analysis.In embodiments of the present invention, only code length is less than or equal to 3 partial design decoding code table, code length is greater than 3 situation and uses the method for calculating to decode.For code length, be less than or equal to 3 situation, first from code stream, read three Bit datas, according to the number zerosleft that remains 0 before its numerical value and known this nonzero coefficient, calculate code table index value (i.e. the 3rd index value), look into decoding code table RunBeforeTable_vlc, obtain the practical codeword lengths of code stream and the number RunBefore of this nonzero coefficient front 0.
This process comprises the following steps:
Step 701, variable zerosleft is set, described zerosleft remains total number of 0 before representing other nonzero coefficient, its initial value is total number Totalzeros of last nonzero coefficient front 0, i.e. zerosleft=Totalzeros, and, variable i is set, described i represents the sequence number of nonzero coefficient number in code stream, and its initial value is the nonzero coefficient number numcoeff-1 that decoding obtains before, i.e. i=numcoeff-1;
Step 702, judges whether zerosleft > 0 and i > 0; If so, perform step 703; Otherwise, represent 0 individual number decoder before all nonzero coefficients complete, end decode procedure;
Step 703, reads three Bit datas in code stream;
Step 704, calculates code table index according to described zeroleft with three Bit datas that read;
Step 705, looks into decoding code table RunBeforeTable_vlc according to the code table index obtaining, and obtains the number RunBefore of i nonzero coefficient front 0;
Step 706, whether the number RunBefore of the nonzero coefficient front 0 that judgement obtains equaled for 7 (this value is equivalent to a special mark, can set arbitrarily a particular value); If so, perform step 707; Otherwise, execution step 709;
Step 707, reads and in code stream, connects zero and count leadingzeros;
Step 708, determines the number RunBefore=leadingzeros+4 of i nonzero coefficient front 0;
Step 709, arranges zerosleft-=runbefore, and i--, obtains next nonzero coefficient;
Step 710, judgement zerosleft unequal to 0 and i unequal to 0; If so, show also to need to continue decoding, execution step 703; Otherwise, show 0 number before all nonzero coefficients to decode complete, finish decode procedure.
Visible, embodiment of the present invention CAVLC coding/decoding method, connects zero number based on code stream decoding code table is divided into groups again, and the parsing of part nonzero coefficient has also been adopted to the realization of tabling look-up.By testing authentication, the method analyzing efficiency of the embodiment of the present invention has promoted 1 times of left and right compared with prior art, and memory space has also reduced a lot, can well be applied in Embedded Hardware Platform design.
Compare with the coding/decoding method of prior art, difference be mainly reflected in following some:
1. processing speed
Prior art is when decoding to video code flow, according to statistical probability, directly to have read the data of fixed bit, need a large amount of auxiliary judgment to complete decoding, nonzero coefficient decoder module prior art 13 judgements of need at every turn such as maximum consuming time in existing version, and the method for the embodiment of the present invention only needs 4 judgements, greatly promoted decoding efficiency; In addition, the method for the embodiment of the present invention has redesigned code table according to code word feature, during the decoding of hangover coefficient, has also adopted the realization of tabling look-up, and has reduced by 3 judgements, has promoted decoding efficiency.Under identical test environment, having tested respectively resolution is the parsing time of qcif (176 * 144), cif (352 * 288), qvga (320 * 240) code stream CAVLC module, utilize the method for the embodiment of the present invention, the parsing time of the CAVLC of three kinds of code streams is respectively 50%, 47.6%, 51.5% of prior art, and visual efficiency has promoted 1 times of left and right.
2. memory space
Prior art need to be stored the code table element of 3208words, and the method for the embodiment of the present invention only need to be stored the code table element of 2082words, reduced the memory space of 2Kbytes left and right, this is significant for limited embedded device space, can be applied in well in the embedded device of video decode H.264.
One of ordinary skill in the art will appreciate that all or part of step realizing in above-described embodiment method is to come the hardware that instruction is relevant to complete by program, described program can be stored in a computer read/write memory medium, described storage medium, as: ROM/RAM, magnetic disc, CD etc.
Correspondingly, the embodiment of the present invention also provides a kind of CAVLC decode system, as shown in Figure 8, is the structural representation of embodiment of the present invention CAVLC decode system.
In this embodiment, described system comprises:
Code stream acquiring unit 801, for obtaining the code stream that needs decoding;
Computing unit 802, for determining the nonzero coefficient number predicted value nC of described code stream;
The first decoding unit 803, for search the first decoding code table of setting up in advance according to described predicted value nC, obtain nonzero coefficient number and hangover coefficient number in described code stream, described the first decoding code table is the decoding code table that comprises nonzero coefficient number and hangover coefficient number;
The first judging unit 804, for judging whether described nonzero coefficient number is greater than 0, and whether described hangover coefficient number is greater than 0;
Symbol resolution unit 805, for judging that at described the first judging unit described nonzero coefficient number is greater than 0, and described hangover coefficient number is greater than at 0 o'clock, the even symbol of 1 coefficient of hangover of decoding;
The second judging unit 806, for judging whether described nonzero coefficient number is less than the maximum of nonzero coefficient number;
The second decoding unit 807, for when described the second judging unit judges that described nonzero coefficient number is less than the maximum of nonzero coefficient number, according to described nonzero coefficient number, search the second decoding code table of setting up in advance, obtain total number of last nonzero coefficient front 0 in described code stream, described the second decoding code table is the decoding code table of total number of comprising last nonzero coefficient front 0;
The 3rd decoding unit 808, for according to 0 total number and described nonzero coefficient number before described last nonzero coefficient, the number of other nonzero coefficients front 0 in the described code stream of decoding.
In embodiments of the present invention, described system also can further comprise: the first decoding code table is set up unit (not shown), company's zero number of each code word of standard code while being used for based on coding nonzero coefficient number and hangover coefficient number divides into groups to code stream, by connecting the identical code word of zero number, is divided into one group; And according to first 1 dibit or three Bit datas (definite according to nC value) below in company's zero number of each group code stream and this group code stream, set up described the first decoding code table, described the first decoding comprises in code table: first 1 code stream length, nonzero coefficient number, coefficient number of trailing below in code stream.
Correspondingly, described the first decoding unit 803 comprises:
The first coefficient decoding subelement, for when described predicted value 0 <=nC < 8, calculates the first index value according to first 1 company's zero number above in described code stream and first 1 three Bit datas below; And search described the first decoding code table according to described the first index value, obtain in described code stream first 1 code stream length, nonzero coefficient number and coefficient number of trailing below;
The second coefficient decoding subelement, for when described predicted value 8 <=nC, determines that described code stream length is fixed as 6; And search described the first decoding code table according to code word corresponding to described code stream, obtain nonzero coefficient number and hangover coefficient number in described code stream;
The 3rd coefficient decoding subelement, for when the described predicted value nC=-1, searches described the first decoding code table according to first 1 company's zero number above in described code stream, obtains in described code stream first 1 code stream length below; And search described the first decoding code table according to first 1 two bits of data below in described code stream, obtain nonzero coefficient number and hangover coefficient number in described code stream.
In embodiments of the present invention, described system also can further comprise: the second decoding code table is set up unit (not shown), for the company's zero number based on each code word of standard code of total number of 0 before last nonzero coefficient of coding, code stream is divided into groups, by connecting the identical code word of zero number, be divided into one group; And according to first 1 two bits of data below in company's zero number of each group code stream and this group code stream, set up described the second decoding code table, described the second decoding comprises in code table: first 1 bit number below in code stream, total number of last nonzero coefficient front 0.
Correspondingly, described the second decoding unit 807 comprises:
Index value computation subunit, calculates the second index value for connect zero number and first 1 two bits of data below according to described nonzero coefficient number, described code stream;
Decoding subelement, searches described the second decoding code table according to described the second index value, obtains total number of last nonzero coefficient front 0 in described code stream.
In embodiments of the present invention, described system also can further comprise: the 3rd decoding code table is set up unit (not shown), for be less than or equal to 3 code stream for code stream length, set up the 3rd decoding code table, described the 3rd decoding code table is the decoding code table of the length value of the number that comprises other nonzero coefficients front 0 and described code stream;
Described the 3rd decoding unit 808 comprises:
The decoding subelement of tabling look-up, for the length at described code stream, be less than or equal at 3 o'clock, according to the total number that remains 0 before three Bit datas in described code stream and this nonzero coefficient, calculate the 3rd index value, and search described the 3rd decoding code table according to described the 3rd index value, obtain the number of code stream length and described other nonzero coefficients front 0;
Calculate decoding subelement, for total number of 0 before described other nonzero coefficients, be greater than 6 and three Bit datas that read while being predetermined value, obtain company's zero number of described code stream, and using described connect zero number add 4 before described other nonzero coefficients 0 number.
It should be noted that, embodiment of the present invention CAVLC decode system is not limited in said structure form, can also have other distressed structures, at this, describes no longer one by one.
Embodiment of the present invention CAVLC decode system, connects zero number based on code stream decoding code table is divided into groups again, and the decoding of most of syntax elements has also been adopted to the realization of tabling look-up.The present invention has not only saved the memory space of decoding code table greatly, and has effectively improved decoding efficiency, can be advantageously applied in the embedded device of video decode H.264.
Each embodiment in this specification all adopts the mode of going forward one by one to describe, between each embodiment identical similar part mutually referring to, each embodiment stresses is the difference with other embodiment.Especially, for system embodiment, because it is substantially similar in appearance to embodiment of the method, so describe fairly simplely, relevant part is referring to the part explanation of embodiment of the method.System embodiment described above is only schematic, the wherein said unit as separating component explanation can or can not be also physically to separate, the parts that show as unit can be or can not be also physical locations, can be positioned at a place, or also can be distributed in a plurality of network element.Can select according to the actual needs some or all of module wherein to realize the object of the present embodiment scheme.Those of ordinary skills, in the situation that not paying creative work, are appreciated that and implement.
The embodiment of the present invention can be used in numerous general or special purpose computingasystem environment or configuration.For example: personal computer, server computer, handheld device or portable set, plate equipment, multicomputer system, the system based on microprocessor, set top box, programmable consumer-elcetronics devices, network PC, minicom, mainframe computer, comprise distributed computing environment (DCE) of above any system or equipment etc.
The embodiment of the present invention can be described in the general context of the computer executable instructions of being carried out by computer, for example program module.Usually, program module comprises the routine carrying out particular task or realize particular abstract data type, program, object, assembly, data structure etc.Also can in distributed computing environment (DCE), put into practice the application, in these distributed computing environment (DCE), by the teleprocessing equipment being connected by communication network, be executed the task.In distributed computing environment (DCE), program module can be arranged in the local and remote computer-readable storage medium that comprises memory device.
Above the embodiment of the present invention is described in detail, has applied embodiment herein the present invention is set forth, the explanation of above embodiment is just for helping to understand method and apparatus of the present invention; , for one of ordinary skill in the art, according to thought of the present invention, all will change in specific embodiments and applications, in sum, this description should not be construed as limitation of the present invention meanwhile.