iTextSharp.text.pdf.LZWDecoder.Decode C# (CSharp) Метод

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

public Decode ( byte data, Stream uncompData ) : void
data byte
uncompData Stream
Результат void
        public void Decode(byte[] data, Stream uncompData) {
        
            if (data[0] == (byte)0x00 && data[1] == (byte)0x01) {
                throw new Exception("LZW flavour not supported.");
            }
        
            InitializeStringTable();
        
            this.data = data;
            this.uncompData = uncompData;
        
            // Initialize pointers
            bytePointer = 0;
        
            nextData = 0;
            nextBits = 0;
        
            int code, oldCode = 0;
            byte[] str;
        
            while ((code = this.NextCode) != 257) {
            
                if (code == 256) {
                
                    InitializeStringTable();
                    code = NextCode;
                
                    if (code == 257) {
                        break;
                    }
                
                    WriteString(stringTable[code]);
                    oldCode = code;
                
                } else {
                
                    if (code < tableIndex) {
                    
                        str = stringTable[code];
                    
                        WriteString(str);
                        AddStringToTable(stringTable[oldCode], str[0]);
                        oldCode = code;
                    
                    } else {
                    
                        str = stringTable[oldCode];
                        str = ComposeString(str, str[0]);
                        WriteString(str);
                        AddStringToTable(str);
                        oldCode = code;
                    }
                }
            }
        }
    

Usage Example

Пример #1
0
 /** Decodes a stream that has the LZWDecode filter.
 * @param in the input data
 * @return the decoded data
 */    
 public static byte[] LZWDecode(byte[] inp) {
     MemoryStream outp = new MemoryStream();
     LZWDecoder lzw = new LZWDecoder();
     lzw.Decode(inp, outp);
     return outp.ToArray();
 }