本文整理汇总了C++中OutBuffer::writebits方法的典型用法代码示例。如果您正苦于以下问题:C++ OutBuffer::writebits方法的具体用法?C++ OutBuffer::writebits怎么用?C++ OutBuffer::writebits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutBuffer
的用法示例。
在下文中一共展示了OutBuffer::writebits方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deflate_dynamic
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);
}
示例2: print_encoded
void print_encoded(OutBuffer &buf, vector<Symb> coded, vector<int> litCodes, vector<int> litLens, vector<int> dstCodes, vector<int> dstLens) {
for (int i = 0; i < coded.size(); i++) {
Symb cur = coded[i];
vector<int> &code = (cur.isLit) ? litCodes : dstCodes;
vector<int> &len = (cur.isLit) ? litLens : dstLens;
buf.writebits(code[cur.lit], len[cur.lit], false);
buf.writebits(cur.add, cur.addLen, true);
}
}
示例3: print_hc_encoded
void print_hc_encoded(OutBuffer &buf, int HCLEN, vector<int> hcCodes, vector<int> hcLens, vector<Symb> coded) {
for (int i = 0; i < HCLEN; i++)
buf.writebits(hcLens[hcOrder[i]], 3, true);
for (int i = 0; i < coded.size(); i++) {
Symb cur = coded[i];
buf.writebits(hcCodes[cur.lit], hcLens[cur.lit], false);
buf.writebits(cur.add, cur.addLen, true);
}
}
示例4: deflate_stored
void deflate_stored(OutBuffer &buf, vector<unsigned char> &charList) {
short BTYPE = 0;
buf.writebits(BTYPE, 2, true);
buf.writebits(0, 5, true); //stored bytes should start from byte bound
short LEN = charList.size();
buf.writebits(LEN, 16, true);
buf.writebits(~LEN, 16, true);
for (int i = 0; i < LEN; ++i)
buf.writebits(charList[i], 8, true);
}
示例5: deflate_fixed
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);
}