Exemple #1
0
bool readReference(IBitStream& bstr, unsigned& reference, unsigned huffmanNumber) {
    int code = bstr.read(2);
    if (code == 3) {
        reference = bstr.read(32);
        return true;
    }
    int bitlen = BitLength(huffmanNumber);
    assert(bitlen >= 2);
    reference = (code << (bitlen - 2)) | bstr.read(bitlen - 2);
    return true;
}
Exemple #2
0
bool UserDictionaryDecoder::DecodeArticle(
        IBitStream *bstr,
        std::u16string &res,
        std::u16string const& prefix,
        LenTable& ltArticles,
        std::vector<char32_t>& articleSymbols)
{
    unsigned len = bstr->read(16);
    if (len == 0xFFFF) {
        len = bstr->read(32);
    }
    res.clear();
    unsigned symIdx;
    std::vector<uint32_t> vec;
    while ((unsigned)res.length() < len) {
        ltArticles.Decode(*bstr, symIdx);
        unsigned sym = articleSymbols.at(symIdx);
        vec.push_back(sym);
        if (sym >= 0x10000) {
            if (sym >= 0x10040) {
                unsigned startIdx = bstr->read(BitLength(len));
                unsigned len = sym - 0x1003d;
                res += res.substr(startIdx, len);
                vec.push_back(startIdx);
            } else {
                unsigned startIdx = bstr->read(BitLength(prefix.length()));
                unsigned len = sym - 0xfffd;
                res += prefix.substr(startIdx, len);
                vec.push_back(startIdx);
            }
        } else {
            res += (char16_t)sym;
        }
    }
    return true;
}
Exemple #3
0
void LenTable::Read(IBitStream &bitstr) {
    symidx2nodeidx.clear();
    nodes.clear();

    int count = bitstr.read(32);
    int bitsPerLen = bitstr.read(8);
    int idxBitSize = BitLength(count);

    symidx2nodeidx.resize(count);
    for (unsigned& nodeIdx : symidx2nodeidx) {
        nodeIdx = -1; // in case the root has a leaf as a child
    }
    nodes.resize(count - 1);
    int rootIdx = nodes.size() - 1;
    nodes.at(rootIdx) = {0,0,-1,-1};
    nextNodePosition = 0;
    for (int i = 0; i < count; ++i) {
        int symidx = bitstr.read(idxBitSize);
        int len = bitstr.read(bitsPerLen);
        placeSymidx(symidx, rootIdx, len);
    }
}