// The MIT License
|
// The MIT License
|
|
|
// Copyright (c) 2006-2007 Massachusetts Institute of Technology
|
// Copyright (c) 2006-2007 Massachusetts Institute of Technology
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
// in the Software without restriction, including without limitation the rights
|
// in the Software without restriction, including without limitation the rights
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// copies of the Software, and to permit persons to whom the Software is
|
// copies of the Software, and to permit persons to whom the Software is
|
// furnished to do so, subject to the following conditions:
|
// furnished to do so, subject to the following conditions:
|
|
|
// The above copyright notice and this permission notice shall be included in
|
// The above copyright notice and this permission notice shall be included in
|
// all copies or substantial portions of the Software.
|
// all copies or substantial portions of the Software.
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// THE SOFTWARE.
|
// THE SOFTWARE.
|
//**********************************************************************
|
//**********************************************************************
|
// Exp-Golomb codes
|
// Exp-Golomb codes
|
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
//
|
//
|
//
|
//
|
//
|
//
|
|
|
package ExpGolomb;
|
package ExpGolomb;
|
|
|
import H264Types::*;
|
import H264Types::*;
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
// Helper functions
|
// Helper functions
|
(* noinline *)
|
(* noinline *)
|
function Bufcount expgolomb_numbits32( Buffer inbuffer );//number of bits consumed by exp-golomb code
|
function Bufcount expgolomb_numbits32( Buffer inbuffer );//number of bits consumed by exp-golomb code
|
Bufcount tempout = 100;
|
Bufcount tempout = 100;
|
for(Integer ii=33; ii>0; ii=ii-1)
|
for(Integer ii=33; ii>0; ii=ii-1)
|
begin
|
begin
|
if(inbuffer[buffersize-fromInteger(ii)]==1'b1)
|
if(inbuffer[buffersize-fromInteger(ii)]==1'b1)
|
tempout = fromInteger(ii);
|
tempout = fromInteger(ii);
|
end
|
end
|
return tempout;
|
return tempout;
|
endfunction
|
endfunction
|
|
|
(* noinline *)
|
(* noinline *)
|
function Bit#(33) expgolomb_codenum32( Buffer inbuffer, Bufcount egnumbits );//exp-golomb codenum calculation
|
function Bit#(33) expgolomb_codenum32( Buffer inbuffer, Bufcount egnumbits );//exp-golomb codenum calculation
|
Bit#(33) tempbuffer = inbuffer[buffersize-1:buffersize-33];
|
Bit#(33) tempbuffer = inbuffer[buffersize-1:buffersize-33];
|
Bufcount shiftamount = 33-egnumbits;
|
Bufcount shiftamount = 33-egnumbits;
|
return (tempbuffer >> zeroExtend(shiftamount))-1;
|
return (tempbuffer >> zeroExtend(shiftamount))-1;
|
endfunction
|
endfunction
|
|
|
(* noinline *)
|
(* noinline *)
|
function Bit#(32) expgolomb_unsigned32( Buffer inbuffer, Bufcount egnumbits );//unsigned exp-golomb code calculation
|
function Bit#(32) expgolomb_unsigned32( Buffer inbuffer, Bufcount egnumbits );//unsigned exp-golomb code calculation
|
Bit#(33) codenum = expgolomb_codenum32( inbuffer, egnumbits );
|
Bit#(33) codenum = expgolomb_codenum32( inbuffer, egnumbits );
|
return truncate(codenum);
|
return truncate(codenum);
|
endfunction
|
endfunction
|
|
|
(* noinline *)
|
(* noinline *)
|
function Bit#(32) expgolomb_signed32( Buffer inbuffer, Bufcount egnumbits );//signed exp-golomb code calculation
|
function Bit#(32) expgolomb_signed32( Buffer inbuffer, Bufcount egnumbits );//signed exp-golomb code calculation
|
Bit#(33) codenum = expgolomb_codenum32( inbuffer, egnumbits );
|
Bit#(33) codenum = expgolomb_codenum32( inbuffer, egnumbits );
|
Bit#(33) tempout = (codenum+1) >> 1;
|
Bit#(33) tempout = (codenum+1) >> 1;
|
Bit#(33) tempout2 = (codenum[0]==1 ? tempout : (~tempout)+1 );
|
Bit#(33) tempout2 = (codenum[0]==1 ? tempout : (~tempout)+1 );
|
return truncate(tempout2);
|
return truncate(tempout2);
|
endfunction
|
endfunction
|
|
|
|
|
|
|
(* noinline *)
|
(* noinline *)
|
function Bufcount expgolomb_numbits( Buffer inbuffer );//number of bits consumed by exp-golomb code
|
function Bufcount expgolomb_numbits( Buffer inbuffer );//number of bits consumed by exp-golomb code
|
Bufcount tempout = 100;
|
Bufcount tempout = 100;
|
for(Integer ii=17; ii>0; ii=ii-1)
|
for(Integer ii=17; ii>0; ii=ii-1)
|
begin
|
begin
|
if(inbuffer[buffersize-fromInteger(ii)]==1'b1)
|
if(inbuffer[buffersize-fromInteger(ii)]==1'b1)
|
tempout = (fromInteger(ii)*2)-1;
|
tempout = (fromInteger(ii)*2)-1;
|
end
|
end
|
return tempout;
|
return tempout;
|
endfunction
|
endfunction
|
|
|
(* noinline *)
|
(* noinline *)
|
function Bit#(17) expgolomb_codenum( Buffer inbuffer );//exp-golomb codenum calculation
|
function Bit#(17) expgolomb_codenum( Buffer inbuffer );//exp-golomb codenum calculation
|
Bufcount egnumbits = expgolomb_numbits( inbuffer ) >> 1;
|
Bufcount egnumbits = expgolomb_numbits( inbuffer ) >> 1;
|
Bit#(33) tempbuffer = inbuffer[buffersize-1:buffersize-33] << zeroExtend(egnumbits);
|
Bit#(33) tempbuffer = inbuffer[buffersize-1:buffersize-33] << zeroExtend(egnumbits);
|
Bit#(17) tempout = tempbuffer[32:16];
|
Bit#(17) tempout = tempbuffer[32:16];
|
Bufcount shiftamount = 17-egnumbits-1;
|
Bufcount shiftamount = 17-egnumbits-1;
|
return (tempout >> zeroExtend(shiftamount))-1;
|
return (tempout >> zeroExtend(shiftamount))-1;
|
endfunction
|
endfunction
|
|
|
(* noinline *)
|
(* noinline *)
|
function Bit#(16) expgolomb_unsigned( Buffer inbuffer );//unsigned exp-golomb code calculation
|
function Bit#(16) expgolomb_unsigned( Buffer inbuffer );//unsigned exp-golomb code calculation
|
Bit#(17) codenum = expgolomb_codenum( inbuffer );
|
Bit#(17) codenum = expgolomb_codenum( inbuffer );
|
return truncate(codenum);
|
return truncate(codenum);
|
endfunction
|
endfunction
|
|
|
(* noinline *)
|
(* noinline *)
|
function Bit#(16) expgolomb_signed( Buffer inbuffer );//signed exp-golomb code calculation
|
function Bit#(16) expgolomb_signed( Buffer inbuffer );//signed exp-golomb code calculation
|
Bit#(17) codenum = expgolomb_codenum( inbuffer );
|
Bit#(17) codenum = expgolomb_codenum( inbuffer );
|
Bit#(17) tempout = (codenum+1) >> 1;
|
Bit#(17) tempout = (codenum+1) >> 1;
|
Bit#(17) tempout2 = (codenum[0]==1 ? tempout : (~tempout)+1 );
|
Bit#(17) tempout2 = (codenum[0]==1 ? tempout : (~tempout)+1 );
|
return truncate(tempout2);
|
return truncate(tempout2);
|
endfunction
|
endfunction
|
|
|
(* noinline *)
|
(* noinline *)
|
function Bit#(6) expgolomb_coded_block_pattern( Buffer inbuffer, MbType mbtype );//unsigned exp-golomb code calculation
|
function Bit#(6) expgolomb_coded_block_pattern( Buffer inbuffer, MbType mbtype );//unsigned exp-golomb code calculation
|
Bit#(6) codenum = truncate(expgolomb_codenum( inbuffer ));
|
Bit#(6) codenum = truncate(expgolomb_codenum( inbuffer ));
|
if(mbPartPredMode(mbtype,0) == Intra_4x4)
|
if(mbPartPredMode(mbtype,0) == Intra_4x4)
|
begin
|
begin
|
case(codenum)
|
case(codenum)
|
0: return 47;
|
0: return 47;
|
1: return 31;
|
1: return 31;
|
2: return 15;
|
2: return 15;
|
3: return 0;
|
3: return 0;
|
4: return 23;
|
4: return 23;
|
5: return 27;
|
5: return 27;
|
6: return 29;
|
6: return 29;
|
7: return 30;
|
7: return 30;
|
8: return 7;
|
8: return 7;
|
9: return 11;
|
9: return 11;
|
10: return 13;
|
10: return 13;
|
11: return 14;
|
11: return 14;
|
12: return 39;
|
12: return 39;
|
13: return 43;
|
13: return 43;
|
14: return 45;
|
14: return 45;
|
15: return 46;
|
15: return 46;
|
16: return 16;
|
16: return 16;
|
17: return 3;
|
17: return 3;
|
18: return 5;
|
18: return 5;
|
19: return 10;
|
19: return 10;
|
20: return 12;
|
20: return 12;
|
21: return 19;
|
21: return 19;
|
22: return 21;
|
22: return 21;
|
23: return 26;
|
23: return 26;
|
24: return 28;
|
24: return 28;
|
25: return 35;
|
25: return 35;
|
26: return 37;
|
26: return 37;
|
27: return 42;
|
27: return 42;
|
28: return 44;
|
28: return 44;
|
29: return 1;
|
29: return 1;
|
30: return 2;
|
30: return 2;
|
31: return 4;
|
31: return 4;
|
32: return 8;
|
32: return 8;
|
33: return 17;
|
33: return 17;
|
34: return 18;
|
34: return 18;
|
35: return 20;
|
35: return 20;
|
36: return 24;
|
36: return 24;
|
37: return 6;
|
37: return 6;
|
38: return 9;
|
38: return 9;
|
39: return 22;
|
39: return 22;
|
40: return 25;
|
40: return 25;
|
41: return 32;
|
41: return 32;
|
42: return 33;
|
42: return 33;
|
43: return 34;
|
43: return 34;
|
44: return 36;
|
44: return 36;
|
45: return 40;
|
45: return 40;
|
46: return 38;
|
46: return 38;
|
47: return 41;
|
47: return 41;
|
endcase
|
endcase
|
end
|
end
|
else
|
else
|
begin
|
begin
|
case(codenum)
|
case(codenum)
|
0: return 0;
|
0: return 0;
|
1: return 16;
|
1: return 16;
|
2: return 1;
|
2: return 1;
|
3: return 2;
|
3: return 2;
|
4: return 4;
|
4: return 4;
|
5: return 8;
|
5: return 8;
|
6: return 32;
|
6: return 32;
|
7: return 3;
|
7: return 3;
|
8: return 5;
|
8: return 5;
|
9: return 10;
|
9: return 10;
|
10: return 12;
|
10: return 12;
|
11: return 15;
|
11: return 15;
|
12: return 47;
|
12: return 47;
|
13: return 7;
|
13: return 7;
|
14: return 11;
|
14: return 11;
|
15: return 13;
|
15: return 13;
|
16: return 14;
|
16: return 14;
|
17: return 6;
|
17: return 6;
|
18: return 9;
|
18: return 9;
|
19: return 31;
|
19: return 31;
|
20: return 35;
|
20: return 35;
|
21: return 37;
|
21: return 37;
|
22: return 42;
|
22: return 42;
|
23: return 44;
|
23: return 44;
|
24: return 33;
|
24: return 33;
|
25: return 34;
|
25: return 34;
|
26: return 36;
|
26: return 36;
|
27: return 40;
|
27: return 40;
|
28: return 39;
|
28: return 39;
|
29: return 43;
|
29: return 43;
|
30: return 45;
|
30: return 45;
|
31: return 46;
|
31: return 46;
|
32: return 17;
|
32: return 17;
|
33: return 18;
|
33: return 18;
|
34: return 20;
|
34: return 20;
|
35: return 24;
|
35: return 24;
|
36: return 19;
|
36: return 19;
|
37: return 21;
|
37: return 21;
|
38: return 26;
|
38: return 26;
|
39: return 28;
|
39: return 28;
|
40: return 23;
|
40: return 23;
|
41: return 27;
|
41: return 27;
|
42: return 29;
|
42: return 29;
|
43: return 30;
|
43: return 30;
|
44: return 22;
|
44: return 22;
|
45: return 25;
|
45: return 25;
|
46: return 38;
|
46: return 38;
|
47: return 41;
|
47: return 41;
|
endcase
|
endcase
|
end
|
end
|
endfunction
|
endfunction
|
|
|
|
|
|
|
endpackage
|
endpackage
|
|
|