示例#1
0
 internal static int inflate_trees_fixed( int [] bl, int [] bd, int [] [] tl, int [] [] td, ZlibCodec z )
 {
     bl [ 0 ] = fixed_bl;
     bd [ 0 ] = fixed_bd;
     tl [ 0 ] = fixed_tl;
     td [ 0 ] = fixed_td;
     return Z_OK;
 }
示例#2
0
        internal int inflate_trees_dynamic( int nl, int nd, int [] c, int [] bl, int [] bd, int [] tl, int [] td, int [] hp, ZlibCodec z )
        {
            int result;

            initWorkArea ( 288 );
            hn [ 0 ] = 0;
            result = huft_build ( c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v );
            if ( result != Z_OK || bl [ 0 ] == 0 )
            {
                if ( result == Z_DATA_ERROR )
                {
                    z.Message = "oversubscribed literal/length tree";
                }
                else if ( result != Z_MEM_ERROR )
                {
                    z.Message = "incomplete literal/length tree";
                    result = Z_DATA_ERROR;
                }
                return result;
            }

            initWorkArea ( 288 );
            result = huft_build ( c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v );

            if ( result != Z_OK || ( bd [ 0 ] == 0 && nl > 257 ) )
            {
                if ( result == Z_DATA_ERROR )
                {
                    z.Message = "oversubscribed distance tree";
                }
                else if ( result == Z_BUF_ERROR )
                {
                    z.Message = "incomplete distance tree";
                    result = Z_DATA_ERROR;
                }
                else if ( result != Z_MEM_ERROR )
                {
                    z.Message = "empty distance tree with lengths";
                    result = Z_DATA_ERROR;
                }
                return result;
            }

            return Z_OK;
        }
示例#3
0
        internal int inflate_trees_bits( int [] c, int [] bb, int [] tb, int [] hp, ZlibCodec z )
        {
            int result;
            initWorkArea ( 19 );
            hn [ 0 ] = 0;
            result = huft_build ( c, 0, 19, 19, null, null, tb, bb, hp, hn, v );

            if ( result == Z_DATA_ERROR )
            {
                z.Message = "oversubscribed dynamic bit lengths tree";
            }
            else if ( result == Z_BUF_ERROR || bb [ 0 ] == 0 )
            {
                z.Message = "incomplete dynamic bit lengths tree";
                result = Z_DATA_ERROR;
            }
            return result;
        }
示例#4
0
 internal InflateBlocks( ZlibCodec codec, System.Object checkfn, int w )
 {
     _codec = codec;
     hufts = new int [ MANY * 3 ];
     window = new byte [ w ];
     end = w;
     this.checkfn = checkfn;
     mode = InflateBlockMode.TYPE;
     Reset ();
 }
示例#5
0
 internal int SyncPoint( ZlibCodec z )
 {
     return blocks.SyncPoint ();
 }
示例#6
0
        internal int Initialize( ZlibCodec codec, int w )
        {
            _codec = codec;
            _codec.Message = null;
            blocks = null;

            if ( w < 8 || w > 15 )
            {
                End ();
                throw new CompressionProcessException ( "Bad window size." );
            }
            wbits = w;

            blocks = new InflateBlocks ( codec,
                HandleRfc1950HeaderBytes ? this : null,
                1 << w );

            Reset ();
            return ZlibConstants.Z_OK;
        }
示例#7
0
        internal int InflateFast( int bl, int bd, int [] tl, int tl_index, int [] td, int td_index, InflateBlocks s, ZlibCodec z )
        {
            int t;
            int [] tp;
            int tp_index;
            int e;
            int b;
            int k;
            int p;
            int n;
            int q;
            int m;
            int ml;
            int md;
            int c;
            int d;
            int r;

            int tp_index_t_3;

            p = z.NextIn; n = z.AvailableBytesIn; b = s.bitb; k = s.bitk;
            q = s.writeAt; m = q < s.readAt ? s.readAt - q - 1 : s.end - q;

            ml = InternalInflateConstants.InflateMask [ bl ];
            md = InternalInflateConstants.InflateMask [ bd ];

            do
            {
                while ( k < ( 20 ) )
                {
                    n--;
                    b |= ( z.InputBuffer [ p++ ] & 0xff ) << k; k += 8;
                }

                t = b & ml;
                tp = tl;
                tp_index = tl_index;
                tp_index_t_3 = ( tp_index + t ) * 3;
                if ( ( e = tp [ tp_index_t_3 ] ) == 0 )
                {
                    b >>= ( tp [ tp_index_t_3 + 1 ] ); k -= ( tp [ tp_index_t_3 + 1 ] );

                    s.window [ q++ ] = ( byte ) tp [ tp_index_t_3 + 2 ];
                    m--;
                    continue;
                }
                do
                {

                    b >>= ( tp [ tp_index_t_3 + 1 ] ); k -= ( tp [ tp_index_t_3 + 1 ] );

                    if ( ( e & 16 ) != 0 )
                    {
                        e &= 15;
                        c = tp [ tp_index_t_3 + 2 ] + ( ( int ) b & InternalInflateConstants.InflateMask [ e ] );

                        b >>= e; k -= e;

                        while ( k < 15 )
                        {
                            n--;
                            b |= ( z.InputBuffer [ p++ ] & 0xff ) << k; k += 8;
                        }

                        t = b & md;
                        tp = td;
                        tp_index = td_index;
                        tp_index_t_3 = ( tp_index + t ) * 3;
                        e = tp [ tp_index_t_3 ];

                        do
                        {

                            b >>= ( tp [ tp_index_t_3 + 1 ] ); k -= ( tp [ tp_index_t_3 + 1 ] );

                            if ( ( e & 16 ) != 0 )
                            {
                                e &= 15;
                                while ( k < e )
                                {
                                    n--;
                                    b |= ( z.InputBuffer [ p++ ] & 0xff ) << k; k += 8;
                                }

                                d = tp [ tp_index_t_3 + 2 ] + ( b & InternalInflateConstants.InflateMask [ e ] );

                                b >>= e; k -= e;

                                m -= c;
                                if ( q >= d )
                                {
                                    r = q - d;
                                    if ( q - r > 0 && 2 > ( q - r ) )
                                    {
                                        s.window [ q++ ] = s.window [ r++ ];
                                        s.window [ q++ ] = s.window [ r++ ];
                                        c -= 2;
                                    }
                                    else
                                    {
                                        Array.Copy ( s.window, r, s.window, q, 2 );
                                        q += 2; r += 2; c -= 2;
                                    }
                                }
                                else
                                {
                                    r = q - d;
                                    do
                                    {
                                        r += s.end;
                                    }
                                    while ( r < 0 );
                                    e = s.end - r;
                                    if ( c > e )
                                    {
                                        c -= e;
                                        if ( q - r > 0 && e > ( q - r ) )
                                        {
                                            do
                                            {
                                                s.window [ q++ ] = s.window [ r++ ];
                                            }
                                            while ( --e != 0 );
                                        }
                                        else
                                        {
                                            Array.Copy ( s.window, r, s.window, q, e );
                                            q += e; r += e; e = 0;
                                        }
                                        r = 0;
                                    }
                                }

                                if ( q - r > 0 && c > ( q - r ) )
                                {
                                    do
                                    {
                                        s.window [ q++ ] = s.window [ r++ ];
                                    }
                                    while ( --c != 0 );
                                }
                                else
                                {
                                    Array.Copy ( s.window, r, s.window, q, c );
                                    q += c; r += c; c = 0;
                                }
                                break;
                            }
                            else if ( ( e & 64 ) == 0 )
                            {
                                t += tp [ tp_index_t_3 + 2 ];
                                t += ( b & InternalInflateConstants.InflateMask [ e ] );
                                tp_index_t_3 = ( tp_index + t ) * 3;
                                e = tp [ tp_index_t_3 ];
                            }
                            else
                            {
                                z.Message = "invalid distance code";

                                c = z.AvailableBytesIn - n; c = ( k >> 3 ) < c ? k >> 3 : c; n += c; p -= c; k -= ( c << 3 );

                                s.bitb = b; s.bitk = k;
                                z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                                s.writeAt = q;

                                return ZlibConstants.Z_DATA_ERROR;
                            }
                        }
                        while ( true );
                        break;
                    }

                    if ( ( e & 64 ) == 0 )
                    {
                        t += tp [ tp_index_t_3 + 2 ];
                        t += ( b & InternalInflateConstants.InflateMask [ e ] );
                        tp_index_t_3 = ( tp_index + t ) * 3;
                        if ( ( e = tp [ tp_index_t_3 ] ) == 0 )
                        {
                            b >>= ( tp [ tp_index_t_3 + 1 ] ); k -= ( tp [ tp_index_t_3 + 1 ] );
                            s.window [ q++ ] = ( byte ) tp [ tp_index_t_3 + 2 ];
                            m--;
                            break;
                        }
                    }
                    else if ( ( e & 32 ) != 0 )
                    {
                        c = z.AvailableBytesIn - n; c = ( k >> 3 ) < c ? k >> 3 : c; n += c; p -= c; k -= ( c << 3 );

                        s.bitb = b; s.bitk = k;
                        z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                        s.writeAt = q;

                        return ZlibConstants.Z_STREAM_END;
                    }
                    else
                    {
                        z.Message = "invalid literal/length code";

                        c = z.AvailableBytesIn - n; c = ( k >> 3 ) < c ? k >> 3 : c; n += c; p -= c; k -= ( c << 3 );

                        s.bitb = b; s.bitk = k;
                        z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
                        s.writeAt = q;

                        return ZlibConstants.Z_DATA_ERROR;
                    }
                }
                while ( true );
            }
            while ( m >= 258 && n >= 10 );

            c = z.AvailableBytesIn - n; c = ( k >> 3 ) < c ? k >> 3 : c; n += c; p -= c; k -= ( c << 3 );

            s.bitb = b; s.bitk = k;
            z.AvailableBytesIn = n; z.TotalBytesIn += p - z.NextIn; z.NextIn = p;
            s.writeAt = q;

            return ZlibConstants.Z_OK;
        }
示例#8
0
 private void end()
 {
     if ( z == null )
         return;
     if ( _wantCompress )
     {
         _z.EndDeflate ();
     }
     else
     {
         _z.EndInflate ();
     }
     _z = null;
 }
示例#9
0
        internal int Initialize( ZlibCodec codec, CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy )
        {
            _codec = codec;
            _codec.Message = null;

            if ( windowBits < 9 || windowBits > 15 )
                throw new CompressionProcessException ( "windowBits must be in the range 9..15." );

            if ( memLevel < 1 || memLevel > MEM_LEVEL_MAX )
                throw new CompressionProcessException ( String.Format ( "memLevel must be in the range 1.. {0}", MEM_LEVEL_MAX ) );

            _codec.dstate = this;

            w_bits = windowBits;
            w_size = 1 << w_bits;
            w_mask = w_size - 1;

            hash_bits = memLevel + 7;
            hash_size = 1 << hash_bits;
            hash_mask = hash_size - 1;
            hash_shift = ( ( hash_bits + MIN_MATCH - 1 ) / MIN_MATCH );

            window = new byte [ w_size * 2 ];
            prev = new short [ w_size ];
            head = new short [ hash_size ];

            lit_bufsize = 1 << ( memLevel + 6 );

            pending = new byte [ lit_bufsize * 4 ];
            _distanceOffset = lit_bufsize;
            _lengthOffset = ( 1 + 2 ) * lit_bufsize;

            this.compressionLevel = level;
            this.compressionStrategy = strategy;

            Reset ();
            return ZlibConstants.Z_OK;
        }
示例#10
0
 internal int Initialize( ZlibCodec codec, CompressionLevel level, int bits, CompressionStrategy compressionStrategy )
 {
     return Initialize ( codec, level, bits, MEM_LEVEL_DEFAULT, compressionStrategy );
 }
示例#11
0
 internal int Initialize( ZlibCodec codec, CompressionLevel level )
 {
     return Initialize ( codec, level, ZlibConstants.WindowBitsMax );
 }