FACT++  1.0
void Huffman::Encoder::Encode ( std::string &  out,
const uint16_t *  bufin,
size_t  bufinlen 
) const
inline

Definition at line 137 of file huffman.h.

References Huffman::Encoder::Code::bits, i, Huffman::Encoder::Code::numbits, and Huffman::TreeNode::symbol.

Referenced by Huffman::Encode().

138  {
139  if (count==1)
140  return;
141 
142  uint8_t curbyte = 0;
143  uint8_t curbit = 0;
144 
145  for (uint32_t i=0; i<bufinlen; ++i)
146  {
147  const uint16_t &symbol = bufin[i];
148 
149  const Code *code = lut+symbol;
150 
151  uint8_t nbits = code->numbits;
152  const uint8_t *bits = (uint8_t*)&code->bits;
153 
154  while (nbits>0)
155  {
156  // Number of bits available in the current byte
157  const uint8_t free_bits = 8 - curbit;
158 
159  // Write bits to current byte
160  curbyte |= *bits<<curbit;
161 
162  // If the byte has been filled, put it into the output buffer
163  // If the bits exceed the current byte step to the next byte
164  // and fill it properly
165  if (nbits>=free_bits)
166  {
167  out += curbyte;
168  curbyte = *bits>>free_bits;
169 
170  bits++;
171  }
172 
173  // Adapt the number of available bits, the number of consumed bits
174  // and the bit-pointer accordingly
175  const uint8_t consumed = nbits>8 ? 8 : nbits;
176  nbits -= consumed;
177  curbit += consumed;
178  curbit %= 8;
179  }
180  }
181 
182  // If the buffer-byte is half-full, also add it to the output buffer
183  if (curbit>0)
184  out += curbyte;
185  }
int i
Definition: db_dim_client.c:21
Code lut[1<< 16]
Definition: huffman.h:85
size_t count
Definition: huffman.h:84

+ Here is the caller graph for this function: