iTextSharp.text.pdf.codec.LZWStringTable.FindCharString C# (CSharp) Method

FindCharString() public method

public FindCharString ( short index, byte b ) : short
index short
b byte
return short
        public short FindCharString(short index, byte b)
        {
            int hshidx, nxtidx;

            if (index == HASH_FREE)
                return (short)(b & 0xFF);    // Rob fixed used to sign extend

            hshidx = Hash(index, b);
            while ((nxtidx = strHsh_[hshidx]) != HASH_FREE) {	// search
                if (strNxt_[nxtidx] == index && strChr_[nxtidx] == b)
                    return (short)nxtidx;
                hshidx = (hshidx + HASHSTEP) % HASHSIZE;
            }

            return -1;
        }

Usage Example

示例#1
0
        /**
         * @param buf data to be compressed to output stream
         * @exception IOException if underlying output stream error
         **/
        public void Compress(byte[] buf, int offset, int length)
        {
            int   idx;
            byte  c;
            short index;

            int maxOffset = offset + length;

            for (idx = offset; idx < maxOffset; ++idx)
            {
                c = buf[idx];
                if ((index = lzss_.FindCharString(prefix_, c)) != -1)
                {
                    prefix_ = index;
                }
                else
                {
                    bf_.WriteBits(prefix_, numBits_);
                    if (lzss_.AddCharString(prefix_, c) > limit_)
                    {
                        if (numBits_ == 12)
                        {
                            bf_.WriteBits(clearCode_, numBits_);
                            lzss_.ClearTable(codeSize_);
                            numBits_ = codeSize_ + 1;
                        }
                        else
                        {
                            ++numBits_;
                        }

                        limit_ = (1 << numBits_) - 1;
                        if (tiffFudge_)
                        {
                            --limit_;
                        }
                    }
                    prefix_ = (short)((short)c & 0xFF);
                }
            }
        }