void deflate_dynamic(OutBuffer &buf, vector<Symb> &lz77Coded, vector<int> &litLens, vector<int> &dstLens) { short BTYPE = 2; buf.writebits(BTYPE, 2, true); int HLIT = Hcount(litLens, 257); int HDIST = Hcount(dstLens, 1); vector<Symb> HCcoded = HC_encode(HLIT, HDIST, litLens, dstLens); vector<int> hcProbs(19, 0); for (int i = 0; i < HCcoded.size(); i++) hcProbs[HCcoded[i].lit]++; vector<int> hcLens(19); Huffman_builder(hcProbs, hcLens); vector<int> hcCodes = get_codes(hcLens, 8); int HCLEN = 4; for (int i = 4; i < hcLens.size(); i++) if (hcLens[hcOrder[i]]) HCLEN = i + 1; buf.writebits(HLIT - 257, 5, true); buf.writebits(HDIST - 1, 5, true); buf.writebits(HCLEN - 4, 4, true); print_hc_encoded(buf, HCLEN, hcCodes, hcLens, HCcoded); int maxLen = 20; vector<int> litCodes = get_codes(litLens, maxLen); vector<int> dstCodes = get_codes(dstLens, maxLen); print_encoded(buf, lz77Coded, litCodes, litLens, dstCodes, dstLens); }
void deflate_fixed(OutBuffer &buf, vector<Symb> &lz77Coded, vector<int> litLens, vector<int> dstLens) { short BTYPE = 1; buf.writebits(BTYPE, 2, true); int maxLen = 20; vector<int> litCodes = get_codes(litLens, maxLen); vector<int> dstCodes = get_codes(dstLens, maxLen); print_encoded(buf, lz77Coded, litCodes, litLens, dstCodes, dstLens); }
void HuffmanEncoder::encode(dict d) { ofstream out; out.open((path + ".ashf").c_str()); vector < Code > word_concat; for (int i = 0; i < d.size(); i++) { if (d[i].c.q == -1 || d[i].c.r == -1) continue; word_concat.push_back(d[i].c); } // coding of min(i1, i2) vector < string > r_s; int k = 0; for (int i = 0; i < word_concat.size(); i++) { int q_log = get_log(word_concat[i].q); string kemp = ""; for (int i = 0; i <= q_log; i++) { kemp += (1 << i) & word_concat[i].r ? "1" : "0"; } reverse(kemp.begin(), kemp.end()); r_s.push_back(kemp); int r = word_concat[i].q; word_concat[i].q -= k; k = r; } root = build_tree(word_concat); get_codes(root); print_tree(root); string long_string = ""; int q = 0; for (int i = 0; i < word_concat.size(); i++) { string tempor = get_code(word_concat[i].q) + r_s[i] + (word_concat[i].d == true ? "1" : "0"); long_string = long_string + tempor; } int l_str_size = long_string.size(); int cur_p = 0; while (cur_p < l_str_size) { unsigned char c = 0; for (int i = 0; i < min(8, l_str_size - cur_p); i++) { int t = long_string[i + cur_p] == '0' ? 0 : 1; c += (t << i); } cur_p += 8; out << c; } out.close(); }
void HuffmanEncoder::get_codes(HTNode* v) { if (v->c != -1) { haffm_codes[v->c] = code_to_haffm_codes; return; } code_to_haffm_codes.push_back('0'); get_codes(v->left_son); code_to_haffm_codes.pop_back(); code_to_haffm_codes.push_back('1'); get_codes(v->right_son); code_to_haffm_codes.pop_back(); }
int main ( int argc, char **argv ) { int i; /* loop iterator */ int height, width; /* image dimensions */ string param; /* passed parameter */ void *raw_data; /* raw image data */ Magick::Blob blob; /* image in blob format */ vector <string> qr_data; /* decoded qr codes */ /* Check that a file was passed - provide usage statement if not */ if( argc != 2 ) { error( TRUE, "Usage: read_img (imagefile | 'webcam')" ); } /* get command line arg as c++ style string */ param = argv[ 1 ]; /* process the image into the raw data */ if( param == "webcam" ) { /* obtain the image from the webcam */ dbg_msg( "Attempting to get data from webcam using OpenCV" ); get_cam_img( raw_data, width, height ); } else { /* initalize image magick c++ library and use it to get image data */ dbg_msg( "Using ImageMagick to read QR codes from image file %s", param.c_str() ); Magick::InitializeMagick( NULL ); read_img( param, blob, width, height ); raw_data = (void *) blob.data(); } /* process the qr codes */ if( raw_data == NULL ) { error( TRUE, "Could not read image data" ); } get_codes( qr_data, raw_data, width, height ); /* output all of the recognized codes */ for( i = 0; i < qr_data.size(); i++ ) { printf( "symbol %d - data: %s\n", i, qr_data[ i ].c_str() ); } /* be tidy -- don't leak memory */ if( raw_data != NULL && param == "webcam" ) free( raw_data ); return 0; }
unsigned long flash_get_size(ulong baseaddr, flash_info_t * info, int bank_flag) { int id = 0, i = 0; static int FlagDev = 1; id = get_codes(); if (FlagDev) { #ifdef DEBUG printf("Device ID of the Flash is %x\n", id); #endif FlagDev = 0; } info->flash_id = id; switch (bank_flag) { case 0: for (i = PriFlashABegin; i < SecFlashABegin; i++) info->start[i] = (baseaddr + (i * AFP_SectorSize1)); info->size = 0x200000; info->sector_count = 32; break; case 1: info->start[0] = baseaddr + SecFlashASec1Off; info->start[1] = baseaddr + SecFlashASec2Off; info->start[2] = baseaddr + SecFlashASec3Off; info->start[3] = baseaddr + SecFlashASec4Off; info->size = 0x10000; info->sector_count = 4; break; case 2: info->start[0] = baseaddr + SecFlashBSec1Off; info->start[1] = baseaddr + SecFlashBSec2Off; info->start[2] = baseaddr + SecFlashBSec3Off; info->start[3] = baseaddr + SecFlashBSec4Off; info->size = 0x10000; info->sector_count = 4; break; } return (info->size); }
unsigned long flash_get_size(ulong baseaddr, flash_info_t * info, int bank_flag) { int id = 0, i = 0; static int FlagDev = 1; id = get_codes(); if(FlagDev) { FlagDev = 0; } info->flash_id = id; switch (bank_flag) { case 0: for (i = PriFlashABegin; i < SecFlashABegin; i++) info->start[i] = (baseaddr + (i * AFP_SectorSize1)); for (i = SecFlashABegin; i < NUM_SECTORS; i++) info->start[i] = (baseaddr + SecFlashAOff + ((i-SecFlashABegin) * AFP_SectorSize2)); info->size = 0x400000; info->sector_count = NUM_SECTORS; break; case 1: info->start[0] = baseaddr + SecFlashASec1Off; info->start[1] = baseaddr + SecFlashASec2Off; info->start[2] = baseaddr + SecFlashASec3Off; info->start[3] = baseaddr + SecFlashASec4Off; info->size = 0x10000; info->sector_count = 4; break; case 2: info->start[0] = baseaddr + SecFlashBSec1Off; info->start[1] = baseaddr + SecFlashBSec2Off; info->start[2] = baseaddr + SecFlashBSec3Off; info->start[3] = baseaddr + SecFlashBSec4Off; info->size = 0x10000; info->sector_count = 4; break; } return (info->size); }
std::set<std::string> get_codes(rdf::graph &data, const rdf::uri &type) { std::set<std::string> codes; get_codes(codes, data, type); return codes; }
std::string found; if (codes.find(code) != codes.end()) found = code; assert_location(code == found, file, line); } #define contains(codes, code) contains_(codes, code, __FILE__, __LINE__) REGISTER_TESTSUITE("TTS Languages"); TEST_CASE("language codes") { rdf::graph data; cainteoir::createDocumentReader("data/languages.rdf.gz", data, std::string()); auto languages = get_codes(data, rdf::iana("Language")); get_codes(languages, data, rdf::iana("MacroLanguage")); auto extlangs = get_codes(data, rdf::iana("ExtLang")); auto scripts = get_codes(data, rdf::iana("Script")); auto regions = get_codes(data, rdf::iana("Region")); auto variants = get_codes(data, rdf::iana("Variant")); auto private_use = get_codes(data, rdf::iana("Private")); rdf::graph metadata; cainteoir::tts::engines tts(metadata); for (auto &voice : rql::select(metadata, rql::predicate == rdf::rdf("type") && rql::object == rdf::tts("Voice"))) { std::string language; std::string name;