Ejemplo n.º 1
0
        public ZLibStatus InflateSetDictionary(byte[] dictionary, int dictLength)
        {
            int index  = 0;
            int length = dictLength;

            if (this._mode != InflateMode.DICT0)
            {
                return(ZLibStatus.Z_STREAM_ERROR);
            }

            if (Adler32.adler32(1L, dictionary, 0, dictLength) != base.adler)
            {
                return(ZLibStatus.Z_DATA_ERROR);
            }

            base.adler = Adler32.adler32(0, null, 0, 0);

            if (length >= (1 << this._wbits))
            {
                length = (1 << this._wbits) - 1;
                index  = dictLength - length;
            }
            this._blocks.set_dictionary(dictionary, index, length);
            this._mode = InflateMode.BLOCKS;
            return(ZLibStatus.Z_OK);
        }
Ejemplo n.º 2
0
 private ZLibStatus InflateReset()
 {
     base.total_in = base.total_out = 0;
     base.msg      = null;
     this._mode    = this._nowrap != 0 ? InflateMode.BLOCKS : InflateMode.METHOD;
     this._blocks.reset(this, null);
     return(ZLibStatus.Z_OK);
 }
Ejemplo n.º 3
0
        public ZLibStatus InflateSync(ZStream z)
        {
            int  n;      // number of bytes to look at
            int  p;      // pointer to bytes
            int  m;      // number of marker bytes found in a row
            long r, w;   // temporaries to save total_in and total_out

            // set up
            if (this._mode != InflateMode.BAD)
            {
                this._mode   = InflateMode.BAD;
                this._marker = 0;
            }
            if ((n = base.avail_in) == 0)
            {
                return(ZLibStatus.Z_BUF_ERROR);
            }
            p = base.next_in_index;
            m = this._marker;

            // search
            while (n != 0 && m < 4)
            {
                if (base.next_in[p] == mark[m])
                {
                    m++;
                }
                else if (base.next_in[p] != 0)
                {
                    m = 0;
                }
                else
                {
                    m = 4 - m;
                }
                p++; n--;
            }

            // restore
            base.total_in     += p - base.next_in_index;
            base.next_in_index = p;
            base.avail_in      = n;
            this._marker       = m;

            // return no joy or set up to restart on a new block
            if (m != 4)
            {
                return(ZLibStatus.Z_DATA_ERROR);
            }
            r = base.total_in; w = base.total_out;
            InflateReset();
            base.total_in = r; base.total_out = w;
            this._mode    = InflateMode.BLOCKS;
            return(ZLibStatus.Z_OK);
        }
 public TextBoxRenderSet(Color backgroundColor, Color boundaryColor, Font font, Color textColor, float boundaryWidth = 1, int colorChange = -40, float cornerRadius = 3, InflateMode mode = InflateMode.Horizontal)
 {
     this.BackGroundColor = backgroundColor;
     this.BoundaryColor   = boundaryColor;
     this.Font            = font;
     this.TextColor       = textColor;
     this.BoundaryWidth   = boundaryWidth;
     this.ColorChange     = colorChange;
     this.CornerRadius    = cornerRadius;
     this.InflateMode     = mode;
 }
Ejemplo n.º 5
0
        public ZLibStatus InflateSync(ZStream z)
        {
            int n;       // number of bytes to look at
            int p;       // pointer to bytes
            int m;       // number of marker bytes found in a row
            long r, w;   // temporaries to save total_in and total_out

            // set up
            if (this._mode != InflateMode.BAD)
            {
                this._mode = InflateMode.BAD;
                this._marker = 0;
            }
            if ((n = base.avail_in) == 0)
                return ZLibStatus.Z_BUF_ERROR;
            p = base.next_in_index;
            m = this._marker;

            // search
            while (n != 0 && m < 4)
            {
                if (base.next_in[p] == mark[m])
                {
                    m++;
                }
                else if (base.next_in[p] != 0)
                {
                    m = 0;
                }
                else
                {
                    m = 4 - m;
                }
                p++; n--;
            }

            // restore
            base.total_in += p - base.next_in_index;
            base.next_in_index = p;
            base.avail_in = n;
            this._marker = m;

            // return no joy or set up to restart on a new block
            if (m != 4)
            {
                return ZLibStatus.Z_DATA_ERROR;
            }
            r = base.total_in; w = base.total_out;
            InflateReset();
            base.total_in = r; base.total_out = w;
            this._mode = InflateMode.BLOCKS;
            return ZLibStatus.Z_OK;
        }
Ejemplo n.º 6
0
        public ZLibStatus InflateSetDictionary(byte[] dictionary, int dictLength)
        {
            int index = 0;
            int length = dictLength;
            if (this._mode != InflateMode.DICT0)
                return ZLibStatus.Z_STREAM_ERROR;

            if (Adler32.adler32(1L, dictionary, 0, dictLength) != base.adler)
            {
                return ZLibStatus.Z_DATA_ERROR;
            }

            base.adler = Adler32.adler32(0, null, 0, 0);

            if (length >= (1 << this._wbits))
            {
                length = (1 << this._wbits) - 1;
                index = dictLength - length;
            }
            this._blocks.set_dictionary(dictionary, index, length);
            this._mode = InflateMode.BLOCKS;
            return ZLibStatus.Z_OK;
        }
Ejemplo n.º 7
0
        public ZLibStatus inflate(FlushType ff)
        {
            ZLibStatus r;
            int b;

            if (base.next_in == null)
                return ZLibStatus.Z_STREAM_ERROR;
            var f = ff == FlushType.Z_FINISH ? ZLibStatus.Z_BUF_ERROR : ZLibStatus.Z_OK;
            r = ZLibStatus.Z_BUF_ERROR;
            while (true)
            {
                //System.out.println("mode: "+this.mode);
                switch (this._mode)
                {
                    case InflateMode.METHOD:

                        if (base.avail_in == 0) return r; r = f;

                        base.avail_in--; base.total_in++;
                        if (((this.method = base.next_in[base.next_in_index++]) & 0xf) != Z_DEFLATED)
                        {
                            this._mode = InflateMode.BAD;
                            base.msg = "unknown compression method";
                            this._marker = 5;       // can't try inflateSync
                            break;
                        }
                        if ((this.method >> 4) + 8 > this._wbits)
                        {
                            this._mode = InflateMode.BAD;
                            base.msg = "invalid window size";
                            this._marker = 5;       // can't try inflateSync
                            break;
                        }
                        this._mode = InflateMode.FLAG;
                        goto case InflateMode.FLAG;
                    case InflateMode.FLAG:

                        if (base.avail_in == 0) return r; r = f;

                        base.avail_in--; base.total_in++;
                        b = (base.next_in[base.next_in_index++]) & 0xff;

                        if ((((this.method << 8) + b) % 31) != 0)
                        {
                            this._mode = InflateMode.BAD;
                            base.msg = "incorrect header check";
                            this._marker = 5;       // can't try inflateSync
                            break;
                        }

                        if ((b & PRESET_DICT) == 0)
                        {
                            this._mode = InflateMode.BLOCKS;
                            break;
                        }
                        this._mode = InflateMode.DICT4;
                        goto case InflateMode.DICT4;
                    case InflateMode.DICT4:

                        if (base.avail_in == 0) return r; r = f;

                        base.avail_in--; base.total_in++;
                        this._need = ((base.next_in[base.next_in_index++] & 0xff) << 24) & 0xff000000L;
                        this._mode = InflateMode.DICT3;
                        goto case InflateMode.DICT3;
                    case InflateMode.DICT3:

                        if (base.avail_in == 0) return r; r = f;

                        base.avail_in--; base.total_in++;
                        this._need += ((base.next_in[base.next_in_index++] & 0xff) << 16) & 0xff0000L;
                        this._mode = InflateMode.DICT2;
                        goto case InflateMode.DICT2;
                    case InflateMode.DICT2:

                        if (base.avail_in == 0) return r; r = f;

                        base.avail_in--; base.total_in++;
                        this._need += ((base.next_in[base.next_in_index++] & 0xff) << 8) & 0xff00L;
                        this._mode = InflateMode.DICT1;
                        goto case InflateMode.DICT1;
                    case InflateMode.DICT1:

                        if (base.avail_in == 0) return r; r = f;

                        base.avail_in--; base.total_in++;
                        this._need += (base.next_in[base.next_in_index++] & 0xffL);
                        base.adler = this._need;
                        this._mode = InflateMode.DICT0;
                        return ZLibStatus.Z_NEED_DICT;
                    case InflateMode.DICT0:
                        this._mode = InflateMode.BAD;
                        base.msg = "need dictionary";
                        this._marker = 0;       // can try inflateSync
                        return ZLibStatus.Z_STREAM_ERROR;
                    case InflateMode.BLOCKS:

                        r = this._blocks.proc(this, r);
                        if (r == ZLibStatus.Z_DATA_ERROR)
                        {
                            this._mode = InflateMode.BAD;
                            this._marker = 0;     // can try inflateSync
                            break;
                        }
                        if (r == ZLibStatus.Z_OK)
                        {
                            r = f;
                        }
                        if (r != ZLibStatus.Z_STREAM_END)
                        {
                            return r;
                        }
                        r = f;
                        this._blocks.reset(this, this._was);
                        if (this._nowrap != 0)
                        {
                            this._mode = InflateMode.DONE;
                            break;
                        }
                        this._mode = InflateMode.CHECK4;
                        goto case InflateMode.CHECK4;
                    case InflateMode.CHECK4:

                        if (base.avail_in == 0) return r; r = f;

                        base.avail_in--; base.total_in++;
                        this._need = ((base.next_in[base.next_in_index++] & 0xff) << 24) & 0xff000000L;
                        this._mode = InflateMode.CHECK3;
                        goto case InflateMode.CHECK3;
                    case InflateMode.CHECK3:

                        if (base.avail_in == 0) return r; r = f;

                        base.avail_in--; base.total_in++;
                        this._need += ((base.next_in[base.next_in_index++] & 0xff) << 16) & 0xff0000L;
                        this._mode = InflateMode.CHECK2;
                        goto case InflateMode.CHECK2;
                    case InflateMode.CHECK2:

                        if (base.avail_in == 0) return r; r = f;

                        base.avail_in--; base.total_in++;
                        this._need += ((base.next_in[base.next_in_index++] & 0xff) << 8) & 0xff00L;
                        this._mode = InflateMode.CHECK1;
                        goto case InflateMode.CHECK1;
                    case InflateMode.CHECK1:

                        if (base.avail_in == 0) return r; r = f;

                        base.avail_in--; base.total_in++;
                        this._need += (base.next_in[base.next_in_index++] & 0xffL);

                        if (((int)(this._was[0])) != ((int)(this._need)))
                        {
                            this._mode = InflateMode.BAD;
                            base.msg = "incorrect data check";
                            this._marker = 5;       // can't try inflateSync
                            break;
                        }

                        this._mode = InflateMode.DONE;
                        goto case InflateMode.DONE;
                    case InflateMode.DONE:
                        return ZLibStatus.Z_STREAM_END;
                    case InflateMode.BAD:
                        return ZLibStatus.Z_DATA_ERROR;
                    default:
                        return ZLibStatus.Z_STREAM_ERROR;
                }
            }
        }
Ejemplo n.º 8
0
 private ZLibStatus InflateReset()
 {
     base.total_in = base.total_out = 0;
     base.msg = null;
     this._mode = this._nowrap != 0 ? InflateMode.BLOCKS : InflateMode.METHOD;
     this._blocks.reset(this, null);
     return ZLibStatus.Z_OK;
 }
Ejemplo n.º 9
0
        public static void DrawTextBox(Graphics graphics, RectangleF rect, Color backgroundColor, Color boundaryColor, string text, Font font, Color textColor, float boundaryWidth = 1, int colorChange = -40, float cornerRadius = 3, InflateMode mode = InflateMode.Horizontal, bool isCenter = false)
        {
            DrawRectangleBox(graphics, rect, backgroundColor, boundaryColor, boundaryWidth, colorChange, cornerRadius, mode);
            StringFormat format = new StringFormat();

            if (isCenter)
            {
                format.Alignment = StringAlignment.Center;
            }
            graphics.DrawString(text, font, new SolidBrush(textColor), rect, format);
        }
Ejemplo n.º 10
0
        protected static void DrawRectangleBox(Graphics graphics, RectangleF rect, Color backgroundColor, Color boundaryColor, float boundaryWidth = 1, int colorChange = -40, float cornerRadius = 3, InflateMode mode = InflateMode.Horizontal)
        {
            if (boundaryWidth <= 0)
            {
                throw new ArgumentOutOfRangeException("boundaryWidth", "boundaryWidth must be larger than 0!");
            }

            switch (mode)
            {
            case InflateMode.Horizontal:
                rect.Inflate(cornerRadius, 0);
                break;

            case InflateMode.Vertical:
                rect.Inflate(0, cornerRadius);
                break;

            case InflateMode.Both:
                rect.Inflate(cornerRadius, cornerRadius);
                break;

            default:
                rect.Inflate(cornerRadius, 0);
                break;
            }

            LinearGradientBrush brush = new LinearGradientBrush(rect, backgroundColor, backgroundColor.LightenColor(colorChange), LinearGradientMode.Vertical);

            if (cornerRadius == 0)
            {
                graphics.FillRectangle(brush, rect);
                graphics.DrawRectangle(new Pen(boundaryColor, boundaryWidth), rect.X, rect.Y, rect.Width, rect.Height);
            }
            else
            {
                GraphicsPath path = GetRoundRectangle(rect, cornerRadius);
                graphics.FillPath(brush, path);
                graphics.DrawPath(new Pen(boundaryColor, boundaryWidth), path);
            }
        }
Ejemplo n.º 11
0
        public ZLibStatus inflate(FlushType ff)
        {
            ZLibStatus r;
            int        b;

            if (base.next_in == null)
            {
                return(ZLibStatus.Z_STREAM_ERROR);
            }
            var f = ff == FlushType.Z_FINISH ? ZLibStatus.Z_BUF_ERROR : ZLibStatus.Z_OK;

            r = ZLibStatus.Z_BUF_ERROR;
            while (true)
            {
                //System.out.println("mode: "+this.mode);
                switch (this._mode)
                {
                case InflateMode.METHOD:

                    if (base.avail_in == 0)
                    {
                        return(r);
                    }
                    r = f;

                    base.avail_in--; base.total_in++;
                    if (((this.method = base.next_in[base.next_in_index++]) & 0xf) != Z_DEFLATED)
                    {
                        this._mode   = InflateMode.BAD;
                        base.msg     = "unknown compression method";
                        this._marker = 5;           // can't try inflateSync
                        break;
                    }
                    if ((this.method >> 4) + 8 > this._wbits)
                    {
                        this._mode   = InflateMode.BAD;
                        base.msg     = "invalid window size";
                        this._marker = 5;           // can't try inflateSync
                        break;
                    }
                    this._mode = InflateMode.FLAG;
                    goto case InflateMode.FLAG;

                case InflateMode.FLAG:

                    if (base.avail_in == 0)
                    {
                        return(r);
                    }
                    r = f;

                    base.avail_in--; base.total_in++;
                    b = (base.next_in[base.next_in_index++]) & 0xff;

                    if ((((this.method << 8) + b) % 31) != 0)
                    {
                        this._mode   = InflateMode.BAD;
                        base.msg     = "incorrect header check";
                        this._marker = 5;           // can't try inflateSync
                        break;
                    }

                    if ((b & PRESET_DICT) == 0)
                    {
                        this._mode = InflateMode.BLOCKS;
                        break;
                    }
                    this._mode = InflateMode.DICT4;
                    goto case InflateMode.DICT4;

                case InflateMode.DICT4:

                    if (base.avail_in == 0)
                    {
                        return(r);
                    }
                    r = f;

                    base.avail_in--; base.total_in++;
                    this._need = ((base.next_in[base.next_in_index++] & 0xff) << 24) & 0xff000000L;
                    this._mode = InflateMode.DICT3;
                    goto case InflateMode.DICT3;

                case InflateMode.DICT3:

                    if (base.avail_in == 0)
                    {
                        return(r);
                    }
                    r = f;

                    base.avail_in--; base.total_in++;
                    this._need += ((base.next_in[base.next_in_index++] & 0xff) << 16) & 0xff0000L;
                    this._mode  = InflateMode.DICT2;
                    goto case InflateMode.DICT2;

                case InflateMode.DICT2:

                    if (base.avail_in == 0)
                    {
                        return(r);
                    }
                    r = f;

                    base.avail_in--; base.total_in++;
                    this._need += ((base.next_in[base.next_in_index++] & 0xff) << 8) & 0xff00L;
                    this._mode  = InflateMode.DICT1;
                    goto case InflateMode.DICT1;

                case InflateMode.DICT1:

                    if (base.avail_in == 0)
                    {
                        return(r);
                    }
                    r = f;

                    base.avail_in--; base.total_in++;
                    this._need += (base.next_in[base.next_in_index++] & 0xffL);
                    base.adler  = this._need;
                    this._mode  = InflateMode.DICT0;
                    return(ZLibStatus.Z_NEED_DICT);

                case InflateMode.DICT0:
                    this._mode   = InflateMode.BAD;
                    base.msg     = "need dictionary";
                    this._marker = 0;           // can try inflateSync
                    return(ZLibStatus.Z_STREAM_ERROR);

                case InflateMode.BLOCKS:

                    r = this._blocks.proc(this, r);
                    if (r == ZLibStatus.Z_DATA_ERROR)
                    {
                        this._mode   = InflateMode.BAD;
                        this._marker = 0;         // can try inflateSync
                        break;
                    }
                    if (r == ZLibStatus.Z_OK)
                    {
                        r = f;
                    }
                    if (r != ZLibStatus.Z_STREAM_END)
                    {
                        return(r);
                    }
                    r = f;
                    this._blocks.reset(this, this._was);
                    if (this._nowrap != 0)
                    {
                        this._mode = InflateMode.DONE;
                        break;
                    }
                    this._mode = InflateMode.CHECK4;
                    goto case InflateMode.CHECK4;

                case InflateMode.CHECK4:

                    if (base.avail_in == 0)
                    {
                        return(r);
                    }
                    r = f;

                    base.avail_in--; base.total_in++;
                    this._need = ((base.next_in[base.next_in_index++] & 0xff) << 24) & 0xff000000L;
                    this._mode = InflateMode.CHECK3;
                    goto case InflateMode.CHECK3;

                case InflateMode.CHECK3:

                    if (base.avail_in == 0)
                    {
                        return(r);
                    }
                    r = f;

                    base.avail_in--; base.total_in++;
                    this._need += ((base.next_in[base.next_in_index++] & 0xff) << 16) & 0xff0000L;
                    this._mode  = InflateMode.CHECK2;
                    goto case InflateMode.CHECK2;

                case InflateMode.CHECK2:

                    if (base.avail_in == 0)
                    {
                        return(r);
                    }
                    r = f;

                    base.avail_in--; base.total_in++;
                    this._need += ((base.next_in[base.next_in_index++] & 0xff) << 8) & 0xff00L;
                    this._mode  = InflateMode.CHECK1;
                    goto case InflateMode.CHECK1;

                case InflateMode.CHECK1:

                    if (base.avail_in == 0)
                    {
                        return(r);
                    }
                    r = f;

                    base.avail_in--; base.total_in++;
                    this._need += (base.next_in[base.next_in_index++] & 0xffL);

                    if (((int)(this._was[0])) != ((int)(this._need)))
                    {
                        this._mode   = InflateMode.BAD;
                        base.msg     = "incorrect data check";
                        this._marker = 5;           // can't try inflateSync
                        break;
                    }

                    this._mode = InflateMode.DONE;
                    goto case InflateMode.DONE;

                case InflateMode.DONE:
                    return(ZLibStatus.Z_STREAM_END);

                case InflateMode.BAD:
                    return(ZLibStatus.Z_DATA_ERROR);

                default:
                    return(ZLibStatus.Z_STREAM_ERROR);
                }
            }
        }