Exemplo n.º 1
0
 public ValueDecoderSpec(RawDecoderSpec rawDecoderSpec, ValueConversionSpec valueConversionSpec,
                         DisplayConversionSpec displayConversionSpec)
 {
     RawDecoderSpec        = rawDecoderSpec;
     ValueConversionSpec   = valueConversionSpec;
     DisplayConversionSpec = displayConversionSpec;
 }
Exemplo n.º 2
0
        protected NumericBufferBase(IDecodable decodable) : base(decodable)
        {
            var decoder = decodable.DecoderSpec;

            Raw    = decoder.RawDecoderSpec;
            Val    = decoder.ValueConversionSpec;
            Stride = (int)Raw.Stride;
        }
Exemplo n.º 3
0
        private void CreateValueConversionSpec(Mdf4CCBlock c, ref ValueConversionSpec val, ref DisplayConversionSpec disp)
        {
            if (c == null)
            {
                return;
            }

            var p = c.Params;

            if (ChannelGroup.File.ConversionCache.TryGetValue(c, out var specs))
            {
                val  = specs.Item1;
                disp = specs.Item2;
                return;
            }

            void MappingHelper(int numBlocks, ref ValueConversionSpec val, ref DisplayConversionSpec disp)
            {
                var blks             = Enumerable.Range(0, numBlocks).Select(k => c.Ref(k)).ToArray();
                var singleConversion = blks.OfType <Mdf4CCBlock>().ToArray();

                if (singleConversion.Length > 1)
                {
                    Check.NotImplemented();
                }

                else if (singleConversion.Length == 1)
                {
                    CreateValueConversionSpec(singleConversion[0], ref val, ref disp);
                }

                var lookup = new DisplayConversionSpec.LookupTable();

                for (int i = 0; i < blks.Length; i++)
                {
                    if (blks[i] is Mdf4TXBlock str)
                    {
                        lookup[p[i]] = str;
                    }
                }

                disp = lookup;
            }

            switch (c.Data.ConversionType)
            {
            case Mdf4CCBlock.ConversionType.Identity:
                val = ValueConversionSpec.Default;
                break;

            case Mdf4CCBlock.ConversionType.Linear:
                if (c.Params[0] == 0 && c.Params[1] == 1)
                {
                    val = ValueConversionSpec.Default;
                }
                else
                {
                    val = new ValueConversionSpec.Linear(p[0], p[1]);
                }
                break;

            case Mdf4CCBlock.ConversionType.Rational:
                if (p[0] == 0 && p[3] == 0 && p[4] == 0 && p[5] == 1)
                {
                    if (p[2] == 0 && p[1] == 1)
                    {
                        val = ValueConversionSpec.Default;
                    }
                    else
                    {
                        val = new ValueConversionSpec.Linear(p[2], p[1]);
                    }
                }
                else
                {
                    val = new ValueConversionSpec.Rational3(p[2], p[1], p[0], p[5], p[4], p[3]);
                }

                break;

            case Mdf4CCBlock.ConversionType.AlgebraicText:
                Check.NotImplemented(new NotImplementedException());
                break;

            case Mdf4CCBlock.ConversionType.ValToValInterp:
                if (p.Length == 4 && p[0] == p[1] && p[2] == p[3])
                {
                    val = ValueConversionSpec.Default;
                }
                else
                {
                    Check.NotImplemented(new NotImplementedException());
                }
                break;

            case Mdf4CCBlock.ConversionType.ValToValNoInterp:
                Check.NotImplemented(new NotImplementedException());
                break;

            case Mdf4CCBlock.ConversionType.ValRangeToValTab:
                Check.NotImplemented(new NotImplementedException());
                break;

            case Mdf4CCBlock.ConversionType.ValToTextScaleTab:
            {
                MappingHelper(p.Length, ref val, ref disp);
                break;
            }

            case Mdf4CCBlock.ConversionType.ValRangeToTextScaleTab:
            {
                var noRange = true;
                for (var i = 0; i < p.Length; i += 2)
                {
                    noRange &= p[i] == p[i + 1];
                }

                if (!noRange)
                {
                    Check.NotImplemented();
                }

                MappingHelper(p.Length / 2 + 1, ref val, ref disp);
                break;
            }

            case Mdf4CCBlock.ConversionType.TextToVal:
                Check.NotImplemented(new NotImplementedException());
                break;

            case Mdf4CCBlock.ConversionType.TextToText:
                Check.NotImplemented(new NotImplementedException());
                break;

            case Mdf4CCBlock.ConversionType.BitfieldText:
                Check.NotImplemented(new NotImplementedException());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            ChannelGroup.File.ConversionCache[c] = (val, disp);
        }