int main(){ int frequencies[UniqueSymbols] = {0}; const char *ptr = SampleString; while (*ptr != '\0') ++frequencies[*ptr++]; iNode *root = buildTree(frequencies); HuffCodeMap codes; generateCodes(root, HuffCode(), codes); delete root; for (HuffCodeMap::const_iterator it = codes.begin(); it != codes.end(); it++){ std::cout << it->first << " "; std::copy(it->second.begin(), it->second().end(), std::ostream_iterator<bool>(std::cout)); std::cout << std::endl; } return 0; }
int main() { string text; cout << "Enter your line of text below:\n"; getline(cin, text); const char* ptr = text.c_str(); int frequencies[UNIQUE_SYMBOLS] = {0}; while (*ptr != '\0') ++frequencies[*ptr++]; INode* root = buildTree(frequencies); HuffCodeMap codes; generateCodes(root, HuffCode(), codes); delete root; for(HuffCodeMap::const_iterator it = codes.begin(); it != codes.end(); ++it) { cout << it->first << " "; copy(it->second.begin(), it->second.end(), ostream_iterator<bool>(cout)); cout << endl; } return 0; }
int main(int argc, char* argv[]) { char cNomImgLue[250], cNomImgOut[250]; int nH, nW, nTaille; if (argc != 2) { printf("Usage: ImageIn.pgm\n"); exit (1) ; } sscanf (argv[1],"%s",cNomImgLue); OCTET *ImgIn; lire_nb_lignes_colonnes_image_pgm(cNomImgLue, &nH, &nW); nTaille = nH * nW; allocation_tableau(ImgIn, OCTET, nTaille); lire_image_pgm(cNomImgLue, ImgIn, nH * nW); // Build frequency table int frequencies[UniqueSymbols] = {0}; //const char* ptr = SampleString; //while (*ptr != '\0') // ++frequencies[*ptr++]; for (int i = 0; i < nW; i++){ for (int j = 0; j < nH; j++){ frequencies[ImgIn[i*nW+j]]++; } } INode* root = BuildTree(frequencies); HuffCodeMap codes; GenerateCodes(root, HuffCode(), codes); delete root; // for (HuffCodeMap::const_iterator it = codes.begin(); it != codes.end(); ++it){ // cout << it->first << " "; // copy(it->second.begin(), it->second.end(), // std::ostream_iterator<bool>(std::cout)); // cout << std::endl; // } stringstream ss; int cpt = 0; for (int i = 0; i < nW; i++){ for (int j = 0; j < nH; j++){ for (HuffCodeMap::const_iterator it = codes.begin(); it != codes.end(); ++it){ if(it->first == ImgIn[i*nW+j]){ for(int k =0; k< it->second.size();k++){ ss << it->second[k]; } } } } } string all = ss.str(); for (int i = 0; i < all.size(); i+=8){ char c = strtol(all.substr(i,8).c_str(),0,2); cout << c; } //écriture de l'image //ecrire_image_pgm(cNomImgOut, ImgOut, nH, nW); free(ImgIn); return 1; }