MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / HuffmanCompressText

Function HuffmanCompressText

neo/framework/DeclManager.cpp:480–501  ·  view source on GitHub ↗

================ HuffmanCompressText ================ */

Source from the content-addressed store, hash-verified

478================
479*/
480int 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================

Callers 1

SetTextLocalMethod · 0.85

Calls 4

BeginWritingMethod · 0.80
InitMethod · 0.45
WriteBitsMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected