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

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

public ExpandCode ( byte buf, int offset, short code, int skipHead ) : int
buf byte
offset int
code short
skipHead int
Результат int
        public int ExpandCode(byte[] buf, int offset, short code, int skipHead)
        {
            if (offset == -2) {
                if (skipHead == 1) skipHead = 0;
            }
            if (code == -1 ||				// just in case
                skipHead == strLen_[code])				// DONE no more unpacked
                return 0;

            int expandLen;							// how much data we are actually expanding
            int codeLen = strLen_[code] - skipHead;	// length of expanded code left
            int bufSpace = buf.Length - offset;		// how much space left
            if (bufSpace > codeLen)
                expandLen = codeLen;				// only got this many to unpack
            else
                expandLen = bufSpace;

            int skipTail = codeLen - expandLen;		// only > 0 if codeLen > bufSpace [left overs]

            int idx = offset + expandLen;			// initialise to exclusive end address of buffer area

            // NOTE: data unpacks in reverse direction and we are placing the
            // unpacked data directly into the array in the correct location.
            while ((idx > offset) && (code != -1)) {
                if (--skipTail < 0) {				// skip required of expanded data
                    buf[--idx] = strChr_[code];
                }
                code = strNxt_[code];				// to predecessor code
            }

            if (codeLen > expandLen)
                return -expandLen;					// indicate what part of codeLen used
            else
                return expandLen;					// indicate length of dat unpacked
        }