Example #1
0
void huffman(OCTET *in, int width, int height) {
  int frequencies[UniqueSymbols] = {0};
 
  for (int i = 0; i < width * height; i++) {
    frequencies[in[i]]++;
  }

  INode* root = BuildTree(frequencies);

  HuffCodeMap codes;
  GenerateCodes(root, HuffCode(), codes);
  delete root;
  std::stack<bool> *vec = new std::stack<bool>();
  for (int i = 0; i < width * height; i++) {
    HuffCode c = codes.find(in[i])->second;
    std::for_each(c.begin(), c.end(), [=](bool b) {
	vec->push(b);
      });
    if(vec->size() > 8) {
      std::cout << toChar(vec);
    }
  }
}