示例#1
0
        /// <summary> Creates a new Codec object.</summary>
        public IWCodec()
        {
            _ctxStart = new MutableValue<sbyte>[32];

            for (int i = 0; i < _ctxStart.Length; i++)
            {
                _ctxStart[i] = new MutableValue<sbyte>();
            }

            _ctxBucket = new MutableValue<sbyte>[10][];
            for (int i2 = 0; i2 < _ctxBucket.Length; i2++)
            {
                _ctxBucket[i2] = new MutableValue<sbyte>[8];
            }

            for (int i = 0; i < _ctxBucket.Length; i++)
            {
                for (int j = 0; j < _ctxBucket[i].Length; j++)
                {
                    _ctxBucket[i][j] = new MutableValue<sbyte>();
                }
            }

            _quantHi = new int[10];
            _quantLo = new int[16];
            _coeffstate = new sbyte[256];
            _bucketstate = new sbyte[16];
            _curband = 0;
            _curbit = 1;
            _ctxMant = new MutableValue<sbyte>();
            _ctxRoot = new MutableValue<sbyte>();
        }
示例#2
0
        public override void Copy(MutableValue source)
        {
            MutableValueSingle s = (MutableValueSingle)source;

            Value  = s.Value;
            Exists = s.Exists;
        }
示例#3
0
        public override void Copy(MutableValue source)
        {
            MutableValueInt32 s = (MutableValueInt32)source;

            Value  = s.Value;
            Exists = s.Exists;
        }
        public void ReadOnlyValueShouldNotExposeOriginal()
        {
            var mutable = new MutableValue<int>(10);
            var value = new ReadOnlyValue<int>(mutable);

            Object.ReferenceEquals(mutable, value.Changed).Should().BeFalse();
        }
示例#5
0
        public override void Copy(MutableValue source)
        {
            MutableValueLong s = (MutableValueLong)source;

            Exists = s.Exists;
            Value  = s.Value;
        }
示例#6
0
文件: IWCodec.cs 项目: dronab/DjvuNet
        /// <summary> Creates a new Codec object.</summary>
        public IWCodec()
        {
            _ctxStart = new MutableValue <sbyte> [32];

            for (int i = 0; i < _ctxStart.Length; i++)
            {
                _ctxStart[i] = new MutableValue <sbyte>();
            }

            _ctxBucket = new MutableValue <sbyte> [10][];
            for (int i2 = 0; i2 < _ctxBucket.Length; i2++)
            {
                _ctxBucket[i2] = new MutableValue <sbyte> [8];
            }

            for (int i = 0; i < _ctxBucket.Length; i++)
            {
                for (int j = 0; j < _ctxBucket[i].Length; j++)
                {
                    _ctxBucket[i][j] = new MutableValue <sbyte>();
                }
            }

            _quantHi     = new int[10];
            _quantLo     = new int[16];
            _coeffstate  = new sbyte[256];
            _bucketstate = new sbyte[16];
            _curband     = 0;
            _curbit      = 1;
            _ctxMant     = new MutableValue <sbyte>();
            _ctxRoot     = new MutableValue <sbyte>();
        }
示例#7
0
        public override void Copy(MutableValue source)
        {
            MutableValueBool s = (MutableValueBool)source;

            Value  = s.Value;
            Exists = s.Exists;
        }
示例#8
0
        public override void Copy(MutableValue source)
        {
            MutableValueStr s = (MutableValueStr)source;

            Exists = s.Exists;
            Value.CopyBytes(s.Value);
        }
示例#9
0
        protected override bool CodeBit(bool ignored, MutableValue <sbyte> ctx)
        {
            byte ctxVal = unchecked ((byte)ctx.Value);
            int  value  = _Coder.Decoder(ref ctxVal);

            ctx.Value = (sbyte)ctxVal;
            return(value != 0);
        }
示例#10
0
        protected override int GetDiff(int ignored, MutableValue <int> rel_loc)
        {
            //Console.WriteLine("Jb2D gd(i mi) rel_loc: " + rel_loc);
            int result = CodeNum(Bignegative, Bigpositive, rel_loc);

            //Console.WriteLine("Jb2D gd(i mi) result: " + result);

            return(result);
        }
示例#11
0
        public override void SetNextReader(AtomicReaderContext context)
        {
            FunctionValues values = groupSource.GetValues(vsContext, context);

            groupFiller = values.GetValueFiller();
            groupMval   = groupFiller.Value;
            values      = countSource.GetValues(vsContext, context);
            countFiller = values.GetValueFiller();
            countMval   = countFiller.Value;
        }
示例#12
0
        public ZPCodec()
        {
            Ffzt = new sbyte[FFZT.Length];
            Array.Copy(FFZT, 0, Ffzt, 0, Ffzt.Length);

            for (int i = 0; i < _arraySize; i++)
            {
                Up[i] = new MutableValue<sbyte>();
                Down[i] = new MutableValue<sbyte>();
            }
        }
示例#13
0
        public void MutableValueShouldReturnValuePassedToConstructor()
        {
            var value            = new MutableValue <int>(10);
            var changedValues    = new List <int>();
            var changedCompleted = false;

            value.Changed.Subscribe((v) => changedValues.Add(v), () => changedCompleted = true);

            value.GetValue().Should().Be(10);
            changedValues.Count.Should().Be(1);
            changedValues[0].Should().Be(10);
            changedCompleted.Should().BeFalse();
        }
        public void ReadOnlyValueShouldReturnValueOfOriginal()
        {
            var mutable = new MutableValue<int>(10);
            var value = new ReadOnlyValue<int>(mutable);
            var changedValues = new List<int>();
            var changedCompleted = false;

            value.Changed.Subscribe((v) => changedValues.Add(v), () => changedCompleted = true);

            value.GetValue().Should().Be(10);
            changedValues.Count.Should().Be(1);
            changedValues[0].Should().Be(10);
            changedCompleted.Should().BeFalse();
        }
示例#15
0
        public void ObservableValueShouldNotChangeWhenSetToValueItAlreadyHas()
        {
            var value            = new MutableValue <int>(10);
            var changedValues    = new List <int>();
            var changedCompleted = false;

            value.Changed.Subscribe((v) => changedValues.Add(v), () => changedCompleted = true);
            value.SetValue(10);

            value.GetValue().Should().Be(10);
            changedValues.Count.Should().Be(1);
            changedValues[0].Should().Be(10);
            changedCompleted.Should().BeFalse();
        }
示例#16
0
        public void TestConvert()
        {
            var val        = new MutableValue(2350, 1, new Length(), new Metre());
            var canConvert = val.CanConvert(new Metre());

            Assert.IsTrue(canConvert);

            var res = val.Convert(new Metre());

            Assert.IsTrue(res);

            Assert.IsInstanceOfType(val.Unit, typeof(Metre));
            Assert.AreEqual(2.350, val.Value);
            Assert.AreEqual(0.001, val.Precision);
        }
示例#17
0
 protected override void RetrieveGroupHeadAndAddIfNotExist(int doc)
 {
     filler.FillValue(doc);
     if (!groups.TryGetValue(mval, out GroupHead groupHead))
     {
         MutableValue groupValue = mval.Duplicate();
         groupHead             = new GroupHead(this, groupValue, sortWithinGroup, doc);
         groups[groupValue]    = groupHead;
         m_temporalResult.Stop = true;
     }
     else
     {
         m_temporalResult.Stop = false;
     }
     this.m_temporalResult.GroupHead = groupHead;
 }
        public override void SetNextReader(AtomicReaderContext context)
        {
            this.readerContext = context;
            FunctionValues values = groupBy.GetValues(vsContext, context);

            filler = values.GetValueFiller();
            mval   = filler.Value;

            foreach (GroupHead groupHead in groups.Values)
            {
                for (int i = 0; i < groupHead.comparers.Length; i++)
                {
                    groupHead.comparers[i] = groupHead.comparers[i].SetNextReader(context);
                }
            }
        }
            internal GroupHead(FunctionAllGroupHeadsCollector outerInstance, MutableValue groupValue, Sort sort, int doc)
                : base(doc + outerInstance.readerContext.DocBase)
            {
                this.outerInstance = outerInstance;
                this.groupValue    = groupValue;

                SortField[] sortFields = sort.GetSort();
                comparers = new FieldComparer[sortFields.Length];
                for (int i = 0; i < sortFields.Length; i++)
                {
                    comparers[i] = sortFields[i].GetComparer(1, i).SetNextReader(outerInstance.readerContext);
                    comparers[i].SetScorer(outerInstance.scorer);
                    comparers[i].Copy(0, doc);
                    comparers[i].SetBottom(0);
                }
            }
示例#20
0
        public void ObservableValueShouldNotChangeWhenSetToValueThatFailsValidation()
        {
            var value            = new MutableValue <int>(10, v => v != 20);
            var changedValues    = new List <int>();
            var changedCompleted = false;

            value.Changed.Subscribe((v) => changedValues.Add(v), () => changedCompleted = true);

            Action setter = () => value.SetValue(20);

            setter.ShouldThrow <InvalidOperationException>();

            value.GetValue().Should().Be(10);
            changedValues.Count.Should().Be(1);
            changedValues[0].Should().Be(10);
            changedCompleted.Should().BeFalse();
        }
示例#21
0
        protected JB2Codec(bool encoding)
        {
            _BitCells           = new List <MutableValue <sbyte> >();
            _DistRefinementFlag = new MutableValue <sbyte>();
            _LeftCell           = new List <MutableValue <int> >();
            _LibInfo            = new List <Rectangle>();
            _OffsetTypeDist     = new MutableValue <sbyte>();
            _RelLocXCurrent     = new MutableValue <int>();
            _RelLocXLast        = new MutableValue <int>();
            _RelLocYCurrent     = new MutableValue <int>();
            _RelLocYLast        = new MutableValue <int>();
            _RightCell          = new List <MutableValue <int> >();
            _Shape2Lib          = new List <int>();
            _ShortList          = new int[3];

            _AbsLocX           = new MutableValue <int>();
            _AbsLocY           = new MutableValue <int>();
            _AbsSizeX          = new MutableValue <int>();
            _AbsSizeY          = new MutableValue <int>();
            _BitDist           = new sbyte[1024];
            _CBitDist          = new sbyte[2048];
            _DistCommentByte   = new MutableValue <int>();
            _DistCommentLength = new MutableValue <int>();
            _DistMatchIndex    = new MutableValue <int>();

            _DistRecordType          = new MutableValue <int>();
            _ImageSizeDist           = new MutableValue <int>();
            _InheritedShapeCountDist = new MutableValue <int>();
            _Lib2Shape = new List <int>();
            _RelSizeX  = new MutableValue <int>();
            _RelSizeY  = new MutableValue <int>();

            _Encoding = encoding;

            _BitCells.Add(new MutableValue <sbyte>());
            _LeftCell.Add(new MutableValue <int>());
            _RightCell.Add(new MutableValue <int>());
        }
示例#22
0
        public static bool Convert(this MutableValue source, IUnit unit)
        {
            var methodInfo = source.GetConversionMethod(unit);

            if (methodInfo == null)
            {
                return(false);
            }

            try
            {
                if (!(methodInfo.Invoke(source.Unit, new object[] { unit }) is Action <MutableValue> converter))
                {
                    return(false);
                }

                converter(source);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
示例#23
0
 protected abstract int GetDiff(int ignored, MutableValue <int> rel_loc);
示例#24
0
        protected virtual int CodeNum(int low, int high, MutableValue <int> ctx, int v)
        {
            bool negative = false;
            int  cutoff   = 0;

            int ictx = ctx.Value;

            if (ictx >= _bitcells.Count)
            {
                throw new IndexOutOfRangeException("Image bad MutableValue<int>");
            }

            for (int phase = 1, range = -1; range != 1; ictx = ctx.Value)
            {
                bool decision;

                if (ictx == 0)
                {
                    ictx      = _bitcells.Count;
                    ctx.Value = ictx;

                    MutableValue <sbyte> pbitcells  = new MutableValue <sbyte>();
                    MutableValue <int>   pleftcell  = new MutableValue <int>();
                    MutableValue <int>   prightcell = new MutableValue <int>();

                    _bitcells.Add(pbitcells);
                    _leftcell.Add(pleftcell);
                    rightcell.Add(prightcell);
                    decision = _encoding
                                   ? (((low < cutoff) && (high >= cutoff))
                                          ? CodeBit((v >= cutoff), pbitcells)
                                          : (v >= cutoff))
                                   : ((low >= cutoff) || ((high >= cutoff) && CodeBit(false, pbitcells)));

                    ctx = (decision ? prightcell : pleftcell);
                }
                else
                {
                    decision = _encoding
                                   ? (((low < cutoff) && (high >= cutoff))
                                          ? CodeBit((v >= cutoff), (MutableValue <sbyte>)_bitcells[ictx])
                                          : (v >= cutoff))
                                   : ((low >= cutoff) ||
                                      ((high >= cutoff) && CodeBit(false, (MutableValue <sbyte>)_bitcells[ictx])));

                    ctx = (MutableValue <int>)(decision ? rightcell[ictx] : _leftcell[ictx]);
                }

                switch (phase)
                {
                case 1:
                {
                    negative = !decision;

                    if (negative)
                    {
                        if (_encoding)
                        {
                            v = -v - 1;
                        }

                        int temp = -low - 1;
                        low  = -high - 1;
                        high = temp;
                    }

                    phase  = 2;
                    cutoff = 1;

                    break;
                }

                case 2:
                {
                    if (!decision)
                    {
                        phase = 3;
                        range = (cutoff + 1) >> 1;

                        if (range == 1)
                        {
                            cutoff = 0;
                        }
                        else
                        {
                            cutoff -= (range >> 1);
                        }
                    }
                    else
                    {
                        cutoff = (cutoff << 1) + 1;
                    }

                    break;
                }

                case 3:
                {
                    range /= 2;

                    if (range != 1)
                    {
                        if (!decision)
                        {
                            cutoff -= (range >> 1);
                        }
                        else
                        {
                            cutoff += (range >> 1);
                        }
                    }
                    else if (!decision)
                    {
                        cutoff--;
                    }

                    break;
                }
                }
            }

            int result = negative ? (-cutoff - 1) : cutoff;

            return(result);
        }
示例#25
0
        protected override bool CodeBit(bool ignored, MutableValue <sbyte> ctx)
        {
            int value = _zp.Decoder(ctx);

            return(value != 0);
        }
示例#26
0
 protected override bool CodeBit(bool bit, MutableValue <sbyte> ctx)
 {
     throw new NotImplementedException();
 }
示例#27
0
 protected abstract int GetDiff(int ignored, MutableValue<int> rel_loc);
示例#28
0
        protected virtual int CodeNum(int low, int high, MutableValue<int> ctx, int v)
        {
            bool negative = false;
            int cutoff = 0;

            int ictx = ctx.Value;

            if (ictx >= _bitcells.Count)
            {
                throw new IndexOutOfRangeException("Image bad MutableValue<int>");
            }

            for (int phase = 1, range = -1; range != 1; ictx = ctx.Value)
            {
                bool decision;

                if (ictx == 0)
                {
                    ictx = _bitcells.Count;
                    ctx.Value = ictx;

                    MutableValue<sbyte> pbitcells = new MutableValue<sbyte>();
                    MutableValue<int> pleftcell = new MutableValue<int>();
                    MutableValue<int> prightcell = new MutableValue<int>();

                    _bitcells.Add(pbitcells);
                    _leftcell.Add(pleftcell);
                    rightcell.Add(prightcell);
                    decision = _encoding
                                   ? (((low < cutoff) && (high >= cutoff))
                                          ? CodeBit((v >= cutoff), pbitcells)
                                          : (v >= cutoff))
                                   : ((low >= cutoff) || ((high >= cutoff) && CodeBit(false, pbitcells)));

                    ctx = (decision ? prightcell : pleftcell);
                }
                else
                {
                    decision = _encoding
                                   ? (((low < cutoff) && (high >= cutoff))
                                          ? CodeBit((v >= cutoff), (MutableValue<sbyte>)_bitcells[ictx])
                                          : (v >= cutoff))
                                   : ((low >= cutoff) ||
                                      ((high >= cutoff) && CodeBit(false, (MutableValue<sbyte>)_bitcells[ictx])));

                    ctx = (MutableValue<int>)(decision ? rightcell[ictx] : _leftcell[ictx]);
                }

                switch (phase)
                {
                    case 1:
                        {
                            negative = !decision;

                            if (negative)
                            {
                                if (_encoding)
                                {
                                    v = -v - 1;
                                }

                                int temp = -low - 1;
                                low = -high - 1;
                                high = temp;
                            }

                            phase = 2;
                            cutoff = 1;

                            break;
                        }

                    case 2:
                        {
                            if (!decision)
                            {
                                phase = 3;
                                range = (cutoff + 1) >> 1;

                                if (range == 1)
                                {
                                    cutoff = 0;
                                }
                                else
                                {
                                    cutoff -= (range >> 1);
                                }
                            }
                            else
                            {
                                cutoff = (cutoff << 1) + 1;
                            }

                            break;
                        }

                    case 3:
                        {
                            range /= 2;

                            if (range != 1)
                            {
                                if (!decision)
                                {
                                    cutoff -= (range >> 1);
                                }
                                else
                                {
                                    cutoff += (range >> 1);
                                }
                            }
                            else if (!decision)
                            {
                                cutoff--;
                            }

                            break;
                        }
                }
            }

            int result = negative ? (-cutoff - 1) : cutoff;

            return result;
        }
示例#29
0
 protected abstract bool CodeBit(bool bit, MutableValue<sbyte> ctx);
示例#30
0
 public override void Copy(MutableValue source)
 {
     MutableValueStr s = (MutableValueStr)source;
     Exists = s.Exists;
     Value.CopyBytes(s.Value);
 }
示例#31
0
        protected override int GetDiff(int ignored, MutableValue<int> rel_loc)
        {
            //Console.WriteLine("Jb2D gd(i mi) rel_loc: " + rel_loc);
            int result = CodeNum(Bignegative, Bigpositive, rel_loc);
            //Console.WriteLine("Jb2D gd(i mi) result: " + result);

            return result;
        }
示例#32
0
        public int Decoder(MutableValue<sbyte> ctx)
        {
            int ictx = 0xff & ctx.Value;
            int z = AValue + PArray[ictx];

            if (z <= _fence)
            {
                AValue = z;

                return ictx & 1;
            }
            else
            {
                return DecodeSub(ctx, z);
            }
        }
示例#33
0
        public int DecodeSub(MutableValue<sbyte> ctx, int z)
        {
            int bit = ctx.Value & 1;

            int d = 24576 + ((z + AValue) >> 2);

            if (z > d)
            {
                z = d;
            }

            if (z > _code)
            {
                z = 0x10000 - z;
                AValue += z;
                _code += z;
                ctx.Value = Down[0xff & ctx.Value].Value;

                int shift = FFZ(AValue);
                _scount = (short)(_scount - shift);
                AValue = 0xffff & (AValue << shift);
                _code = 0xffff & ((_code << shift) | ((_buffer >> _scount) & ((1 << shift) - 1)));

                if (_scount < 16)
                {
                    Preload();
                }

                _fence = _code;

                if (_code >= 32768L)
                {
                    _fence = 32767L;
                }

                return bit ^ 1;
            }

            if ((unchecked((int)0xffffffffL) & AValue) >= (unchecked((int)0xffffffffL) & MArray[0xff & ctx.Value]))
            {
                ctx.Value = Up[0xff & ctx.Value].Value;
            }

            _scount--;
            AValue = 0xffff & (z << 1);
            _code = 0xffff & ((_code << 1) | ((_buffer >> _scount) & 1));

            if (_scount < 16)
            {
                Preload();
            }

            _fence = _code;

            if (_code >= 32768L)
            {
                _fence = 32767L;
            }

            return bit;
        }
示例#34
0
 protected abstract bool CodeBit(bool bit, MutableValue <sbyte> ctx);
示例#35
0
 public override void Copy(MutableValue source)
 {
     MutableValueFloat s = (MutableValueFloat)source;
     Value = s.Value;
     Exists = s.Exists;
 }
示例#36
0
        public static bool CanConvert(this MutableValue source, IUnit unit)
        {
            var conversions = source.GetConversions();

            return(conversions.Contains(unit.GetType()));
        }
示例#37
0
 public override void Copy(MutableValue source)
 {
     MutableValueLong s = (MutableValueLong)source;
     Exists = s.Exists;
     Value = s.Value;
 }
示例#38
0
 protected override int GetDiff(int ignored, MutableValue <int> rel_loc)
 {
     throw new NotImplementedException();
 }
示例#39
0
        protected override int GetDiff(int ignored, MutableValue <int> rel_loc)
        {
            int result = CodeNum(Bignegative, Bigpositive, rel_loc);

            return(result);
        }
示例#40
0
        protected override bool CodeBit(bool ignored, MutableValue<sbyte> ctx)
        {
            int value = _zp.Decoder(ctx);

            return (value != 0);
        }
示例#41
0
        protected virtual int CodeNum(int low, int high, MutableValue <int> ctx)
        {
            int result = CodeNum(low, high, ctx, 0);

            return(result);
        }
示例#42
0
        protected virtual int CodeNum(int low, int high, MutableValue<int> ctx)
        {
            int result = CodeNum(low, high, ctx, 0);

            return result;
        }