iTextSharp.text.pdf.codec.LZWStringTable.AddCharString C# (CSharp) Метод

AddCharString() публичный Метод

public AddCharString ( short index, byte b ) : int
index short
b byte
Результат int
        public int AddCharString(short index, byte b)
        {
            int hshidx;

            if (numStrings_ >= MAXSTR) {	// if used up all codes
                return 0xFFFF;
            }

            hshidx = Hash(index, b);
            while (strHsh_[hshidx] != HASH_FREE)
                hshidx = (hshidx + HASHSTEP) % HASHSIZE;

            strHsh_[hshidx] = numStrings_;
            strChr_[numStrings_] = b;
            if (index == HASH_FREE) {
                strNxt_[numStrings_] = NEXT_FIRST;
                strLen_[numStrings_] = 1;
            }
            else {
                strNxt_[numStrings_] = index;
                strLen_[numStrings_] = strLen_[index] + 1;
            }

            return numStrings_++;	// return the code and inc for next code
        }

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);
                }
            }
        }