| 147 | } |
| 148 | |
| 149 | STATIC |
| 150 | UINT16 |
| 151 | MakeTable ( |
| 152 | IN SCRATCH_DATA *Sd, |
| 153 | IN UINT16 NumOfChar, |
| 154 | IN UINT8 *BitLen, |
| 155 | IN UINT16 TableBits, |
| 156 | OUT UINT16 *Table |
| 157 | ) |
| 158 | /*++ |
| 159 | |
| 160 | Routine Description: |
| 161 | |
| 162 | Creates Huffman Code mapping table according to code length array. |
| 163 | |
| 164 | Arguments: |
| 165 | |
| 166 | Sd - The global scratch data |
| 167 | NumOfChar - Number of symbols in the symbol set |
| 168 | BitLen - Code length array |
| 169 | TableBits - The width of the mapping table |
| 170 | Table - The table |
| 171 | |
| 172 | Returns: |
| 173 | |
| 174 | 0 - OK. |
| 175 | BAD_TABLE - The table is corrupted. |
| 176 | |
| 177 | --*/ |
| 178 | { |
| 179 | UINT16 Count[17]; |
| 180 | UINT16 Weight[17]; |
| 181 | UINT16 Start[18]; |
| 182 | UINT16 *Pointer; |
| 183 | UINT16 Index3; |
| 184 | UINT16 Index; |
| 185 | UINT16 Len; |
| 186 | UINT16 Char; |
| 187 | UINT16 JuBits; |
| 188 | UINT16 Avail; |
| 189 | UINT16 NextCode; |
| 190 | UINT16 Mask; |
| 191 | UINT16 MaxTableLength; |
| 192 | |
| 193 | for (Index = 1; Index <= 16; Index++) { |
| 194 | Count[Index] = 0; |
| 195 | } |
| 196 | |
| 197 | for (Index = 0; Index < NumOfChar; Index++) { |
| 198 | if (BitLen[Index] > 16) { |
| 199 | return (UINT16) BAD_TABLE; |
| 200 | } |
| 201 | Count[BitLen[Index]]++; |
| 202 | } |
| 203 | |
| 204 | Start[1] = 0; |
| 205 | |
| 206 | for (Index = 1; Index <= 16; Index++) { |