summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/aacenc/src/bit_cnt.c
diff options
context:
space:
mode:
Diffstat (limited to 'media/libstagefright/codecs/aacenc/src/bit_cnt.c')
-rw-r--r--media/libstagefright/codecs/aacenc/src/bit_cnt.c1014
1 files changed, 507 insertions, 507 deletions
diff --git a/media/libstagefright/codecs/aacenc/src/bit_cnt.c b/media/libstagefright/codecs/aacenc/src/bit_cnt.c
index 24837e8..dd0b9b4 100644
--- a/media/libstagefright/codecs/aacenc/src/bit_cnt.c
+++ b/media/libstagefright/codecs/aacenc/src/bit_cnt.c
@@ -1,23 +1,23 @@
-/*
- ** Copyright 2003-2010, VisualOn, Inc.
- **
- ** Licensed under the Apache License, Version 2.0 (the "License");
- ** you may not use this file except in compliance with the License.
- ** You may obtain a copy of the License at
- **
- ** http://www.apache.org/licenses/LICENSE-2.0
- **
- ** Unless required by applicable law or agreed to in writing, software
- ** distributed under the License is distributed on an "AS IS" BASIS,
- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ** See the License for the specific language governing permissions and
- ** limitations under the License.
- */
-/*******************************************************************************
- File: bit_cnt.c
-
- Content: Huffman Bitcounter & coder functions
-
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+ File: bit_cnt.c
+
+ Content: Huffman Bitcounter & coder functions
+
*******************************************************************************/
#include "bit_cnt.h"
@@ -45,7 +45,7 @@ static void count1_2_3_4_5_6_7_8_9_10_11(const Word16 *values,
{
Word32 t0,t1,t2,t3,i;
Word32 bc1_2,bc3_4,bc5_6,bc7_8,bc9_10;
- Word16 bc11,sc;
+ Word16 bc11,sc;
bc1_2=0;
bc3_4=0;
@@ -162,7 +162,7 @@ static void count3_4_5_6_7_8_9_10_11(const Word16 *values,
sc = sc + (t0>0) + (t1>0) + (t2>0) + (t3>0);
- }
+ }
bitCount[1]=INVALID_BITCOUNT;
bitCount[2]=INVALID_BITCOUNT;
@@ -196,7 +196,7 @@ static void count5_6_7_8_9_10_11(const Word16 *values,
Word32 t0,t1,i;
Word32 bc5_6,bc7_8,bc9_10;
- Word16 bc11,sc;
+ Word16 bc11,sc;
bc5_6=0;
bc7_8=0;
@@ -294,43 +294,43 @@ static void count7_8_9_10_11(const Word16 *values,
* output: bitCount for tables 9-11
*
*****************************************************************************/
-static void count9_10_11(const Word16 *values,
- const Word16 width,
- Word16 *bitCount)
-{
-
- Word32 t0,t1,i;
- Word32 bc9_10;
- Word16 bc11,sc;
-
- bc9_10=0;
- bc11=0;
- sc=0;
-
- for(i=0;i<width;i+=2){
-
- t0=ABS(values[i+0]);
- t1=ABS(values[i+1]);
-
-
- bc9_10 += EXPAND(huff_ltab9_10[t0][t1]);
- bc11 = bc11 + huff_ltab11[t0][t1];
-
-
- sc = sc + (t0>0) + (t1>0);
- }
- bitCount[1]=INVALID_BITCOUNT;
- bitCount[2]=INVALID_BITCOUNT;
- bitCount[3]=INVALID_BITCOUNT;
- bitCount[4]=INVALID_BITCOUNT;
- bitCount[5]=INVALID_BITCOUNT;
- bitCount[6]=INVALID_BITCOUNT;
- bitCount[7]=INVALID_BITCOUNT;
- bitCount[8]=INVALID_BITCOUNT;
- bitCount[9]=extract_h(bc9_10) + sc;
- bitCount[10]=extract_l(bc9_10) + sc;
- bitCount[11]=bc11 + sc;
-
+static void count9_10_11(const Word16 *values,
+ const Word16 width,
+ Word16 *bitCount)
+{
+
+ Word32 t0,t1,i;
+ Word32 bc9_10;
+ Word16 bc11,sc;
+
+ bc9_10=0;
+ bc11=0;
+ sc=0;
+
+ for(i=0;i<width;i+=2){
+
+ t0=ABS(values[i+0]);
+ t1=ABS(values[i+1]);
+
+
+ bc9_10 += EXPAND(huff_ltab9_10[t0][t1]);
+ bc11 = bc11 + huff_ltab11[t0][t1];
+
+
+ sc = sc + (t0>0) + (t1>0);
+ }
+ bitCount[1]=INVALID_BITCOUNT;
+ bitCount[2]=INVALID_BITCOUNT;
+ bitCount[3]=INVALID_BITCOUNT;
+ bitCount[4]=INVALID_BITCOUNT;
+ bitCount[5]=INVALID_BITCOUNT;
+ bitCount[6]=INVALID_BITCOUNT;
+ bitCount[7]=INVALID_BITCOUNT;
+ bitCount[8]=INVALID_BITCOUNT;
+ bitCount[9]=extract_h(bc9_10) + sc;
+ bitCount[10]=extract_l(bc9_10) + sc;
+ bitCount[11]=bc11 + sc;
+
}
/*****************************************************************************
@@ -342,35 +342,35 @@ static void count9_10_11(const Word16 *values,
* output: bitCount for table 11
*
*****************************************************************************/
- static void count11(const Word16 *values,
- const Word16 width,
- Word16 *bitCount)
-{
- Word32 t0,t1,i;
- Word16 bc11,sc;
-
- bc11=0;
- sc=0;
- for(i=0;i<width;i+=2){
- t0=ABS(values[i+0]);
- t1=ABS(values[i+1]);
- bc11 = bc11 + huff_ltab11[t0][t1];
-
-
- sc = sc + (t0>0) + (t1>0);
- }
-
- bitCount[1]=INVALID_BITCOUNT;
- bitCount[2]=INVALID_BITCOUNT;
- bitCount[3]=INVALID_BITCOUNT;
- bitCount[4]=INVALID_BITCOUNT;
- bitCount[5]=INVALID_BITCOUNT;
- bitCount[6]=INVALID_BITCOUNT;
- bitCount[7]=INVALID_BITCOUNT;
- bitCount[8]=INVALID_BITCOUNT;
- bitCount[9]=INVALID_BITCOUNT;
- bitCount[10]=INVALID_BITCOUNT;
- bitCount[11]=bc11 + sc;
+ static void count11(const Word16 *values,
+ const Word16 width,
+ Word16 *bitCount)
+{
+ Word32 t0,t1,i;
+ Word16 bc11,sc;
+
+ bc11=0;
+ sc=0;
+ for(i=0;i<width;i+=2){
+ t0=ABS(values[i+0]);
+ t1=ABS(values[i+1]);
+ bc11 = bc11 + huff_ltab11[t0][t1];
+
+
+ sc = sc + (t0>0) + (t1>0);
+ }
+
+ bitCount[1]=INVALID_BITCOUNT;
+ bitCount[2]=INVALID_BITCOUNT;
+ bitCount[3]=INVALID_BITCOUNT;
+ bitCount[4]=INVALID_BITCOUNT;
+ bitCount[5]=INVALID_BITCOUNT;
+ bitCount[6]=INVALID_BITCOUNT;
+ bitCount[7]=INVALID_BITCOUNT;
+ bitCount[8]=INVALID_BITCOUNT;
+ bitCount[9]=INVALID_BITCOUNT;
+ bitCount[10]=INVALID_BITCOUNT;
+ bitCount[11]=bc11 + sc;
}
/*****************************************************************************
@@ -383,54 +383,54 @@ static void count9_10_11(const Word16 *values,
*
*****************************************************************************/
-static void countEsc(const Word16 *values,
- const Word16 width,
- Word16 *bitCount)
-{
- Word32 t0,t1,t00,t01,i;
- Word16 bc11,ec,sc;
-
- bc11=0;
- sc=0;
- ec=0;
- for(i=0;i<width;i+=2){
- t0=ABS(values[i+0]);
- t1=ABS(values[i+1]);
-
-
- sc = sc + (t0>0) + (t1>0);
-
- t00 = min(t0,16);
- t01 = min(t1,16);
- bc11 = bc11 + huff_ltab11[t00][t01];
-
-
- if(t0 >= 16){
- ec = ec + 5;
- while(sub(t0=(t0 >> 1), 16) >= 0) {
- ec = ec + 2;
- }
- }
-
-
- if(t1 >= 16){
- ec = ec + 5;
- while(sub(t1=(t1 >> 1), 16) >= 0) {
- ec = ec + 2;
- }
- }
- }
- bitCount[1]=INVALID_BITCOUNT;
- bitCount[2]=INVALID_BITCOUNT;
- bitCount[3]=INVALID_BITCOUNT;
- bitCount[4]=INVALID_BITCOUNT;
- bitCount[5]=INVALID_BITCOUNT;
- bitCount[6]=INVALID_BITCOUNT;
- bitCount[7]=INVALID_BITCOUNT;
- bitCount[8]=INVALID_BITCOUNT;
- bitCount[9]=INVALID_BITCOUNT;
- bitCount[10]=INVALID_BITCOUNT;
- bitCount[11]=bc11 + sc + ec;
+static void countEsc(const Word16 *values,
+ const Word16 width,
+ Word16 *bitCount)
+{
+ Word32 t0,t1,t00,t01,i;
+ Word16 bc11,ec,sc;
+
+ bc11=0;
+ sc=0;
+ ec=0;
+ for(i=0;i<width;i+=2){
+ t0=ABS(values[i+0]);
+ t1=ABS(values[i+1]);
+
+
+ sc = sc + (t0>0) + (t1>0);
+
+ t00 = min(t0,16);
+ t01 = min(t1,16);
+ bc11 = bc11 + huff_ltab11[t00][t01];
+
+
+ if(t0 >= 16){
+ ec = ec + 5;
+ while(sub(t0=(t0 >> 1), 16) >= 0) {
+ ec = ec + 2;
+ }
+ }
+
+
+ if(t1 >= 16){
+ ec = ec + 5;
+ while(sub(t1=(t1 >> 1), 16) >= 0) {
+ ec = ec + 2;
+ }
+ }
+ }
+ bitCount[1]=INVALID_BITCOUNT;
+ bitCount[2]=INVALID_BITCOUNT;
+ bitCount[3]=INVALID_BITCOUNT;
+ bitCount[4]=INVALID_BITCOUNT;
+ bitCount[5]=INVALID_BITCOUNT;
+ bitCount[6]=INVALID_BITCOUNT;
+ bitCount[7]=INVALID_BITCOUNT;
+ bitCount[8]=INVALID_BITCOUNT;
+ bitCount[9]=INVALID_BITCOUNT;
+ bitCount[10]=INVALID_BITCOUNT;
+ bitCount[11]=bc11 + sc + ec;
}
@@ -492,376 +492,376 @@ Word16 bitCount(const Word16 *values,
* description: write huffum bits
*
*****************************************************************************/
-Word16 codeValues(Word16 *values, Word16 width, Word16 codeBook, HANDLE_BIT_BUF hBitstream)
-{
-
- Word32 i, t0, t1, t2, t3, t00, t01;
- Word16 codeWord, codeLength;
- Word16 sign, signLength;
-
-
- switch (codeBook) {
- case CODE_BOOK_ZERO_NO:
- break;
-
- case CODE_BOOK_1_NO:
- for(i=0; i<width; i+=4) {
- t0 = values[i+0];
- t1 = values[i+1];
- t2 = values[i+2];
- t3 = values[i+3];
- codeWord = huff_ctab1[t0+1][t1+1][t2+1][t3+1];
- codeLength = HI_LTAB(huff_ltab1_2[t0+1][t1+1][t2+1][t3+1]);
- WriteBits(hBitstream, codeWord, codeLength);
- }
- break;
-
- case CODE_BOOK_2_NO:
- for(i=0; i<width; i+=4) {
- t0 = values[i+0];
- t1 = values[i+1];
- t2 = values[i+2];
- t3 = values[i+3];
- codeWord = huff_ctab2[t0+1][t1+1][t2+1][t3+1];
- codeLength = LO_LTAB(huff_ltab1_2[t0+1][t1+1][t2+1][t3+1]);
- WriteBits(hBitstream,codeWord,codeLength);
- }
- break;
-
- case CODE_BOOK_3_NO:
- for(i=0; i<width; i+=4) {
- sign=0;
- signLength=0;
- t0 = values[i+0];
-
- if(t0 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t0 < 0){
- sign|=1;
- t0=-t0;
- }
- }
- t1 = values[i+1];
-
- if(t1 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t1 < 0){
- sign|=1;
- t1=-t1;
- }
- }
- t2 = values[i+2];
-
- if(t2 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t2 < 0){
- sign|=1;
- t2=-t2;
- }
- }
- t3 = values[i+3];
- if(t3 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t3 < 0){
- sign|=1;
- t3=-t3;
- }
- }
-
- codeWord = huff_ctab3[t0][t1][t2][t3];
- codeLength = HI_LTAB(huff_ltab3_4[t0][t1][t2][t3]);
- WriteBits(hBitstream,codeWord,codeLength);
- WriteBits(hBitstream,sign,signLength);
- }
- break;
-
- case CODE_BOOK_4_NO:
- for(i=0; i<width; i+=4) {
- sign=0;
- signLength=0;
- t0 = values[i+0];
-
- if(t0 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
- if(t0 < 0){
- sign|=1;
- t0=-t0;
- }
- }
- t1 = values[i+1];
-
- if(t1 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t1 < 0){
- sign|=1;
- t1=-t1;
- }
- }
- t2 = values[i+2];
-
- if(t2 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t2 < 0){
- sign|=1;
- t2=-t2;
- }
- }
- t3 = values[i+3];
-
- if(t3 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t3 < 0){
- sign|=1;
- t3=-t3;
- }
- }
- codeWord = huff_ctab4[t0][t1][t2][t3];
- codeLength = LO_LTAB(huff_ltab3_4[t0][t1][t2][t3]);
- WriteBits(hBitstream,codeWord,codeLength);
- WriteBits(hBitstream,sign,signLength);
- }
- break;
-
- case CODE_BOOK_5_NO:
- for(i=0; i<width; i+=2) {
- t0 = values[i+0];
- t1 = values[i+1];
- codeWord = huff_ctab5[t0+4][t1+4];
- codeLength = HI_LTAB(huff_ltab5_6[t0+4][t1+4]);
- WriteBits(hBitstream,codeWord,codeLength);
- }
- break;
-
- case CODE_BOOK_6_NO:
- for(i=0; i<width; i+=2) {
- t0 = values[i+0];
- t1 = values[i+1];
- codeWord = huff_ctab6[t0+4][t1+4];
- codeLength = LO_LTAB(huff_ltab5_6[t0+4][t1+4]);
- WriteBits(hBitstream,codeWord,codeLength);
- }
- break;
-
- case CODE_BOOK_7_NO:
- for(i=0; i<width; i+=2){
- sign=0;
- signLength=0;
- t0 = values[i+0];
-
- if(t0 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t0 < 0){
- sign|=1;
- t0=-t0;
- }
- }
-
- t1 = values[i+1];
-
- if(t1 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t1 < 0){
- sign|=1;
- t1=-t1;
- }
- }
- codeWord = huff_ctab7[t0][t1];
- codeLength = HI_LTAB(huff_ltab7_8[t0][t1]);
- WriteBits(hBitstream,codeWord,codeLength);
- WriteBits(hBitstream,sign,signLength);
- }
- break;
-
- case CODE_BOOK_8_NO:
- for(i=0; i<width; i+=2) {
- sign=0;
- signLength=0;
- t0 = values[i+0];
-
- if(t0 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t0 < 0){
- sign|=1;
- t0=-t0;
- }
- }
-
- t1 = values[i+1];
-
- if(t1 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t1 < 0){
- sign|=1;
- t1=-t1;
- }
- }
- codeWord = huff_ctab8[t0][t1];
- codeLength = LO_LTAB(huff_ltab7_8[t0][t1]);
- WriteBits(hBitstream,codeWord,codeLength);
- WriteBits(hBitstream,sign,signLength);
- }
- break;
-
- case CODE_BOOK_9_NO:
- for(i=0; i<width; i+=2) {
- sign=0;
- signLength=0;
- t0 = values[i+0];
-
- if(t0 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t0 < 0){
- sign|=1;
- t0=-t0;
- }
- }
-
- t1 = values[i+1];
-
- if(t1 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t1 < 0){
- sign|=1;
- t1=-t1;
- }
- }
- codeWord = huff_ctab9[t0][t1];
- codeLength = HI_LTAB(huff_ltab9_10[t0][t1]);
- WriteBits(hBitstream,codeWord,codeLength);
- WriteBits(hBitstream,sign,signLength);
- }
- break;
-
- case CODE_BOOK_10_NO:
- for(i=0; i<width; i+=2) {
- sign=0;
- signLength=0;
- t0 = values[i+0];
-
- if(t0 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t0 < 0){
- sign|=1;
- t0=-t0;
- }
- }
-
- t1 = values[i+1];
-
- if(t1 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t1 < 0){
- sign|=1;
- t1=-t1;
- }
- }
- codeWord = huff_ctab10[t0][t1];
- codeLength = LO_LTAB(huff_ltab9_10[t0][t1]);
- WriteBits(hBitstream,codeWord,codeLength);
- WriteBits(hBitstream,sign,signLength);
- }
- break;
-
- case CODE_BOOK_ESC_NO:
- for(i=0; i<width; i+=2) {
- sign=0;
- signLength=0;
- t0 = values[i+0];
-
- if(t0 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t0 < 0){
- sign|=1;
- t0=-t0;
- }
- }
-
- t1 = values[i+1];
-
- if(t1 != 0){
- signLength = signLength + 1;
- sign = sign << 1;
-
- if(t1 < 0){
- sign|=1;
- t1=-t1;
- }
- }
- t00 = min(t0,16);
- t01 = min(t1,16);
-
- codeWord = huff_ctab11[t00][t01];
- codeLength = huff_ltab11[t00][t01];
- WriteBits(hBitstream,codeWord,codeLength);
- WriteBits(hBitstream,sign,signLength);
-
- if(t0 >= 16){
- Word16 n, p;
- n=0;
- p=t0;
- while(sub(p=(p >> 1), 16) >= 0){
-
- WriteBits(hBitstream,1,1);
- n = n + 1;
- }
- WriteBits(hBitstream,0,1);
- n = n + 4;
- WriteBits(hBitstream,(t0 - (1 << n)),n);
- }
-
- if(t1 >= 16){
- Word16 n, p;
- n=0;
- p=t1;
- while(sub(p=(p >> 1), 16) >= 0){
-
- WriteBits(hBitstream,1,1);
- n = n + 1;
- }
- WriteBits(hBitstream,0,1);
- n = n + 4;
- WriteBits(hBitstream,(t1 - (1 << n)),n);
- }
- }
- break;
-
- default:
- break;
- }
- return(0);
+Word16 codeValues(Word16 *values, Word16 width, Word16 codeBook, HANDLE_BIT_BUF hBitstream)
+{
+
+ Word32 i, t0, t1, t2, t3, t00, t01;
+ Word16 codeWord, codeLength;
+ Word16 sign, signLength;
+
+
+ switch (codeBook) {
+ case CODE_BOOK_ZERO_NO:
+ break;
+
+ case CODE_BOOK_1_NO:
+ for(i=0; i<width; i+=4) {
+ t0 = values[i+0];
+ t1 = values[i+1];
+ t2 = values[i+2];
+ t3 = values[i+3];
+ codeWord = huff_ctab1[t0+1][t1+1][t2+1][t3+1];
+ codeLength = HI_LTAB(huff_ltab1_2[t0+1][t1+1][t2+1][t3+1]);
+ WriteBits(hBitstream, codeWord, codeLength);
+ }
+ break;
+
+ case CODE_BOOK_2_NO:
+ for(i=0; i<width; i+=4) {
+ t0 = values[i+0];
+ t1 = values[i+1];
+ t2 = values[i+2];
+ t3 = values[i+3];
+ codeWord = huff_ctab2[t0+1][t1+1][t2+1][t3+1];
+ codeLength = LO_LTAB(huff_ltab1_2[t0+1][t1+1][t2+1][t3+1]);
+ WriteBits(hBitstream,codeWord,codeLength);
+ }
+ break;
+
+ case CODE_BOOK_3_NO:
+ for(i=0; i<width; i+=4) {
+ sign=0;
+ signLength=0;
+ t0 = values[i+0];
+
+ if(t0 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t0 < 0){
+ sign|=1;
+ t0=-t0;
+ }
+ }
+ t1 = values[i+1];
+
+ if(t1 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t1 < 0){
+ sign|=1;
+ t1=-t1;
+ }
+ }
+ t2 = values[i+2];
+
+ if(t2 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t2 < 0){
+ sign|=1;
+ t2=-t2;
+ }
+ }
+ t3 = values[i+3];
+ if(t3 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t3 < 0){
+ sign|=1;
+ t3=-t3;
+ }
+ }
+
+ codeWord = huff_ctab3[t0][t1][t2][t3];
+ codeLength = HI_LTAB(huff_ltab3_4[t0][t1][t2][t3]);
+ WriteBits(hBitstream,codeWord,codeLength);
+ WriteBits(hBitstream,sign,signLength);
+ }
+ break;
+
+ case CODE_BOOK_4_NO:
+ for(i=0; i<width; i+=4) {
+ sign=0;
+ signLength=0;
+ t0 = values[i+0];
+
+ if(t0 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+ if(t0 < 0){
+ sign|=1;
+ t0=-t0;
+ }
+ }
+ t1 = values[i+1];
+
+ if(t1 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t1 < 0){
+ sign|=1;
+ t1=-t1;
+ }
+ }
+ t2 = values[i+2];
+
+ if(t2 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t2 < 0){
+ sign|=1;
+ t2=-t2;
+ }
+ }
+ t3 = values[i+3];
+
+ if(t3 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t3 < 0){
+ sign|=1;
+ t3=-t3;
+ }
+ }
+ codeWord = huff_ctab4[t0][t1][t2][t3];
+ codeLength = LO_LTAB(huff_ltab3_4[t0][t1][t2][t3]);
+ WriteBits(hBitstream,codeWord,codeLength);
+ WriteBits(hBitstream,sign,signLength);
+ }
+ break;
+
+ case CODE_BOOK_5_NO:
+ for(i=0; i<width; i+=2) {
+ t0 = values[i+0];
+ t1 = values[i+1];
+ codeWord = huff_ctab5[t0+4][t1+4];
+ codeLength = HI_LTAB(huff_ltab5_6[t0+4][t1+4]);
+ WriteBits(hBitstream,codeWord,codeLength);
+ }
+ break;
+
+ case CODE_BOOK_6_NO:
+ for(i=0; i<width; i+=2) {
+ t0 = values[i+0];
+ t1 = values[i+1];
+ codeWord = huff_ctab6[t0+4][t1+4];
+ codeLength = LO_LTAB(huff_ltab5_6[t0+4][t1+4]);
+ WriteBits(hBitstream,codeWord,codeLength);
+ }
+ break;
+
+ case CODE_BOOK_7_NO:
+ for(i=0; i<width; i+=2){
+ sign=0;
+ signLength=0;
+ t0 = values[i+0];
+
+ if(t0 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t0 < 0){
+ sign|=1;
+ t0=-t0;
+ }
+ }
+
+ t1 = values[i+1];
+
+ if(t1 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t1 < 0){
+ sign|=1;
+ t1=-t1;
+ }
+ }
+ codeWord = huff_ctab7[t0][t1];
+ codeLength = HI_LTAB(huff_ltab7_8[t0][t1]);
+ WriteBits(hBitstream,codeWord,codeLength);
+ WriteBits(hBitstream,sign,signLength);
+ }
+ break;
+
+ case CODE_BOOK_8_NO:
+ for(i=0; i<width; i+=2) {
+ sign=0;
+ signLength=0;
+ t0 = values[i+0];
+
+ if(t0 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t0 < 0){
+ sign|=1;
+ t0=-t0;
+ }
+ }
+
+ t1 = values[i+1];
+
+ if(t1 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t1 < 0){
+ sign|=1;
+ t1=-t1;
+ }
+ }
+ codeWord = huff_ctab8[t0][t1];
+ codeLength = LO_LTAB(huff_ltab7_8[t0][t1]);
+ WriteBits(hBitstream,codeWord,codeLength);
+ WriteBits(hBitstream,sign,signLength);
+ }
+ break;
+
+ case CODE_BOOK_9_NO:
+ for(i=0; i<width; i+=2) {
+ sign=0;
+ signLength=0;
+ t0 = values[i+0];
+
+ if(t0 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t0 < 0){
+ sign|=1;
+ t0=-t0;
+ }
+ }
+
+ t1 = values[i+1];
+
+ if(t1 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t1 < 0){
+ sign|=1;
+ t1=-t1;
+ }
+ }
+ codeWord = huff_ctab9[t0][t1];
+ codeLength = HI_LTAB(huff_ltab9_10[t0][t1]);
+ WriteBits(hBitstream,codeWord,codeLength);
+ WriteBits(hBitstream,sign,signLength);
+ }
+ break;
+
+ case CODE_BOOK_10_NO:
+ for(i=0; i<width; i+=2) {
+ sign=0;
+ signLength=0;
+ t0 = values[i+0];
+
+ if(t0 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t0 < 0){
+ sign|=1;
+ t0=-t0;
+ }
+ }
+
+ t1 = values[i+1];
+
+ if(t1 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t1 < 0){
+ sign|=1;
+ t1=-t1;
+ }
+ }
+ codeWord = huff_ctab10[t0][t1];
+ codeLength = LO_LTAB(huff_ltab9_10[t0][t1]);
+ WriteBits(hBitstream,codeWord,codeLength);
+ WriteBits(hBitstream,sign,signLength);
+ }
+ break;
+
+ case CODE_BOOK_ESC_NO:
+ for(i=0; i<width; i+=2) {
+ sign=0;
+ signLength=0;
+ t0 = values[i+0];
+
+ if(t0 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t0 < 0){
+ sign|=1;
+ t0=-t0;
+ }
+ }
+
+ t1 = values[i+1];
+
+ if(t1 != 0){
+ signLength = signLength + 1;
+ sign = sign << 1;
+
+ if(t1 < 0){
+ sign|=1;
+ t1=-t1;
+ }
+ }
+ t00 = min(t0,16);
+ t01 = min(t1,16);
+
+ codeWord = huff_ctab11[t00][t01];
+ codeLength = huff_ltab11[t00][t01];
+ WriteBits(hBitstream,codeWord,codeLength);
+ WriteBits(hBitstream,sign,signLength);
+
+ if(t0 >= 16){
+ Word16 n, p;
+ n=0;
+ p=t0;
+ while(sub(p=(p >> 1), 16) >= 0){
+
+ WriteBits(hBitstream,1,1);
+ n = n + 1;
+ }
+ WriteBits(hBitstream,0,1);
+ n = n + 4;
+ WriteBits(hBitstream,(t0 - (1 << n)),n);
+ }
+
+ if(t1 >= 16){
+ Word16 n, p;
+ n=0;
+ p=t1;
+ while(sub(p=(p >> 1), 16) >= 0){
+
+ WriteBits(hBitstream,1,1);
+ n = n + 1;
+ }
+ WriteBits(hBitstream,0,1);
+ n = n + 4;
+ WriteBits(hBitstream,(t1 - (1 << n)),n);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ return(0);
}
Word16 bitCountScalefactorDelta(Word16 delta)