================ HuffmanCompressText ================ */
| 478 | ================ |
| 479 | */ |
| 480 | int HuffmanCompressText( const char *text, int textLength, byte *compressed, int maxCompressedSize ) { |
| 481 | int i, j; |
| 482 | idBitMsg msg; |
| 483 | |
| 484 | totalUncompressedLength += textLength; |
| 485 | |
| 486 | msg.Init( compressed, maxCompressedSize ); |
| 487 | msg.BeginWriting(); |
| 488 | for ( i = 0; i < textLength; i++ ) { |
| 489 | const huffmanCode_t &code = huffmanCodes[(unsigned char)text[i]]; |
| 490 | for ( j = 0; j < ( code.numBits >> 5 ); j++ ) { |
| 491 | msg.WriteBits( code.bits[j], 32 ); |
| 492 | } |
| 493 | if ( code.numBits & 31 ) { |
| 494 | msg.WriteBits( code.bits[j], code.numBits & 31 ); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | totalCompressedLength += msg.GetSize(); |
| 499 | |
| 500 | return msg.GetSize(); |
| 501 | } |
| 502 | |
| 503 | /* |
| 504 | ================ |
no test coverage detected