iTextSharp.text.pdf.codec.TiffWriter.CompressLZW C# (CSharp) Method

CompressLZW() public static method

public static CompressLZW ( Stream stream, int predictor, byte b, int height, int samplesPerPixel, int stride ) : void
stream Stream
predictor int
b byte
height int
samplesPerPixel int
stride int
return void
        public static void CompressLZW(Stream stream, int predictor, byte[] b, int height, int samplesPerPixel, int stride) {

            LZWCompressor lzwCompressor = new LZWCompressor(stream, 8, true);
            bool usePredictor = predictor == TIFFConstants.PREDICTOR_HORIZONTAL_DIFFERENCING;

            if (!usePredictor) {
                lzwCompressor.Compress(b, 0, b.Length);
            } else {
                int off = 0;
                byte[] rowBuf = usePredictor ? new byte[stride] : null;
                for (int i = 0; i < height; i++) {
                    System.Array.Copy(b, off, rowBuf, 0, stride);
                    for (int j = stride - 1; j >= samplesPerPixel; j--) {
                        rowBuf[j] -= rowBuf[j - samplesPerPixel];
                    }
                    lzwCompressor.Compress(rowBuf, 0, stride);
                    off += stride;
                }
            }

            lzwCompressor.Flush();
        }
    }