예제 #1
0
        public virtual void CloseCodec()
        {
            _ycodec = _crcodec = _cbcodec = null;
            _cslice = _cbytes = _cserial = 0;

            GC.Collect();
        }
예제 #2
0
        public virtual void CloseCodec()
        {
            _ycodec = _crcodec = _cbcodec = null;
            _cslice = _cbytes = _cserial = 0;

            GC.Collect();
        }
예제 #3
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;
        }
예제 #4
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;
        }