Beispiel #1
0
        public IWCodec Init(IWMap map)
        {
            this._map = map;

            int i = 0;

            int[] q    = IwQuant;
            int   qidx = 0;

            for (int j = 0; i < 4; j++)
            {
                _quantLo[i++] = q[qidx++];
            }

            for (int j = 0; j < 4; j++)
            {
                _quantLo[i++] = q[qidx];
            }

            qidx++;

            for (int j = 0; j < 4; j++)
            {
                _quantLo[i++] = q[qidx];
            }

            qidx++;

            for (int j = 0; j < 4; j++)
            {
                _quantLo[i++] = q[qidx];
            }

            qidx++;
            _quantHi[0] = 0;

            for (int j = 1; j < 10; j++)
            {
                _quantHi[j] = q[qidx++];
            }

            while (_quantLo[0] >= 32768)
            {
                NextQuant();
            }

            return(this);
        }
Beispiel #2
0
        public IWMap Duplicate()
        {
            IWMap retval = null;

            try
            {
                retval = new IWMap {
                    Bh = Bh, Blocks = this.Blocks, Bw = Bw, Ih = Ih, Iw = Iw, Nb = Nb, Top = Top
                };

                IWBlock[] blocks = (IWBlock[])this.Blocks.Clone();
                ((IWMap)retval).Blocks = blocks;

                for (int i = 0; i < Nb; i++)
                {
                    blocks[i] = (IWBlock)blocks[i].Duplicate();
                }
            }
            catch (Exception ignored)
            {
            }

            return(retval);
        }
Beispiel #3
0
        public IWCodec Init(IWMap map)
        {
            this._map = map;

            int i = 0;
            int[] q = IwQuant;
            int qidx = 0;

            for (int j = 0; i < 4; j++)
            {
                _quantLo[i++] = q[qidx++];
            }

            for (int j = 0; j < 4; j++)
            {
                _quantLo[i++] = q[qidx];
            }

            qidx++;

            for (int j = 0; j < 4; j++)
            {
                _quantLo[i++] = q[qidx];
            }

            qidx++;

            for (int j = 0; j < 4; j++)
            {
                _quantLo[i++] = q[qidx];
            }

            qidx++;
            _quantHi[0] = 0;

            for (int j = 1; j < 10; j++)
            {
                _quantHi[j] = q[qidx++];
            }

            while (_quantLo[0] >= 32768)
            {
                NextQuant();
            }

            return this;
        }
Beispiel #4
0
        public IWMap Duplicate()
        {
            IWMap retval = null;

            try
            {
                retval = new IWMap { Bh = Bh, Blocks = this.Blocks, Bw = Bw, Ih = Ih, Iw = Iw, Nb = Nb, Top = Top };

                IWBlock[] blocks = (IWBlock[])this.Blocks.Clone();
                ((IWMap)retval).Blocks = blocks;

                for (int i = 0; i < Nb; i++)
                {
                    blocks[i] = (IWBlock)blocks[i].Duplicate();
                }
            }
            catch (Exception ignored)
            {
            }

            return retval;
        }
Beispiel #5
0
        public virtual void Decode(BinaryReader bs)
        {
            if (_ycodec == null)
            {
                _cslice = _cserial = 0;
                _ymap = null;
            }

            byte serial = bs.ReadByte();
            if (serial != _cserial)
            {
                throw new IOException("Chunk does not bear expected serial number");
            }

            int nslices = _cslice + bs.ReadByte();

            if (_cserial == 0)
            {
                int major = bs.ReadByte();
                int minor = bs.ReadByte();

                if ((major & 0x7f) != 1)
                {
                    throw new IOException("File has been compressed with an incompatible Codec");
                }

                if (minor > 2)
                {
                    throw new IOException("File has been compressed with a more recent Codec");
                }

                int header3size = 5;

                if (minor < 2)
                {
                    header3size = 4;
                }

                int w = (bs.ReadByte() << 8);
                w |= bs.ReadByte();

                int h = (bs.ReadByte() << 8);
                h |= bs.ReadByte();
                _crcbDelay = 0;
                _crcbHalf = false;

                int b = bs.ReadByte();

                if (minor >= 2)
                {
                    _crcbDelay = 0x7f & b;
                }

                if (minor >= 2)
                {
                    _crcbHalf = ((0x80 & b) == 0);
                }

                if ((major & 0x80) != 0)
                {
                    _crcbDelay = -1;
                }

                _ymap = new IWMap().Init(w, h);
                _ycodec = new IWCodec().Init(_ymap);

                if (_crcbDelay >= 0)
                {
                    _cbmap = new IWMap().Init(w, h);
                    _crmap = new IWMap().Init(w, h);
                    _cbcodec = new IWCodec().Init(_cbmap);
                    _crcodec = new IWCodec().Init(_crmap);
                }
            }

            ZPCodec zp = new ZPCodec().Init(bs.BaseStream);

            for (int flag = 1; (flag != 0) && (_cslice < nslices); _cslice++)
            {
                flag = _ycodec.CodeSlice(zp);

                if ((_crcodec != null) && (_cbcodec != null) && (_crcbDelay <= _cslice))
                {
                    flag |= _cbcodec.CodeSlice(zp);
                    flag |= _crcodec.CodeSlice(zp);
                }
            }

            _cserial++;

            //    return nslices;
        }
Beispiel #6
0
        public virtual void Decode(BinaryReader bs)
        {
            if (_ycodec == null)
            {
                _cslice = _cserial = 0;
                _ymap   = null;
            }

            byte serial = bs.ReadByte();

            if (serial != _cserial)
            {
                throw new IOException("Chunk does not bear expected serial number");
            }

            int nslices = _cslice + bs.ReadByte();

            if (_cserial == 0)
            {
                int major = bs.ReadByte();
                int minor = bs.ReadByte();

                if ((major & 0x7f) != 1)
                {
                    throw new IOException("File has been compressed with an incompatible Codec");
                }

                if (minor > 2)
                {
                    throw new IOException("File has been compressed with a more recent Codec");
                }

                int header3size = 5;

                if (minor < 2)
                {
                    header3size = 4;
                }

                int w = (bs.ReadByte() << 8);
                w |= bs.ReadByte();

                int h = (bs.ReadByte() << 8);
                h         |= bs.ReadByte();
                _crcbDelay = 0;
                _crcbHalf  = false;

                int b = bs.ReadByte();

                if (minor >= 2)
                {
                    _crcbDelay = 0x7f & b;
                }

                if (minor >= 2)
                {
                    _crcbHalf = ((0x80 & b) == 0);
                }

                if ((major & 0x80) != 0)
                {
                    _crcbDelay = -1;
                }

                _ymap   = new IWMap().Init(w, h);
                _ycodec = new IWCodec().Init(_ymap);

                if (_crcbDelay >= 0)
                {
                    _cbmap   = new IWMap().Init(w, h);
                    _crmap   = new IWMap().Init(w, h);
                    _cbcodec = new IWCodec().Init(_cbmap);
                    _crcodec = new IWCodec().Init(_crmap);
                }
            }

            ZPCodec zp = new ZPCodec().Init(bs.BaseStream);

            for (int flag = 1; (flag != 0) && (_cslice < nslices); _cslice++)
            {
                flag = _ycodec.CodeSlice(zp);

                if ((_crcodec != null) && (_cbcodec != null) && (_crcbDelay <= _cslice))
                {
                    flag |= _cbcodec.CodeSlice(zp);
                    flag |= _crcodec.CodeSlice(zp);
                }
            }

            _cserial++;

            //    return nslices;
        }