protected override void ReadContentFrom(BinaryReader reader)
 {
     //USHORT 	version 	Version number (0 or 1).
     //USHORT 	numRecs 	Number of VDMX groups present
     //USHORT 	numRatios 	Number of aspect ratio groupings
     //Ratio 	ratRange[numRatios] 	Ratio ranges (see below for more info)
     //USHORT 	offset[numRatios] 	Offset from start of this table to the VDMX group for this ratio range.
     //Vdmx 	groups 	The actual VDMX groupings (documented below)
     //Ratio Record Type 	Name 	Description
     //BYTE 	bCharSet 	Character set (see below).
     //BYTE 	xRatio 	Value to use for x-Ratio
     //BYTE 	yStartRatio 	Starting y-Ratio value.
     //BYTE 	yEndRatio 	Ending y-Ratio value.
     ushort version = reader.ReadUInt16();
     ushort numRecs = reader.ReadUInt16();
     ushort numRatios = reader.ReadUInt16();
     ratios = new Ratio[numRatios];
     for (int i = 0; i < numRatios; ++i)
     {
         ratios[i] = new Ratio(
             reader.ReadByte(),
             reader.ReadByte(),
             reader.ReadByte(),
             reader.ReadByte());
     }
     short[] offsets = Utils.ReadInt16Array(reader, numRatios);
     //------
     //actual vdmx group
     //TODO: implement this
 }
Esempio n. 2
0
        private static int CalculateFramesToOutputFromFramerate(TimeSpan index, Ratio framerate, TimeSpan totalDuration)
        {
            int numeratorMultiplier = index + PlaybackDuration < totalDuration
                ? (int)PlaybackDuration.TotalSeconds
                : (totalDuration - index).Seconds;

            return (framerate.Numerator * numeratorMultiplier) / framerate.Denominator;
        }
Esempio n. 3
0
        public Frequency(int f, Ratio r)
        {
            // check for improper/whole fractions
            if (r.n >= r.d)
                throw new ArgumentException("Improper and Whole fractions aren't allowed when defining clock source frequency.");

            if (r.d <= 0)
                throw new ArgumentException("Denominator must be positive, and non-zero.");

            this.f = f;
            this.r = r;
        }
Esempio n. 4
0
        private static void IndexEntriesAtIndex(
            string videoFile,
            TimeSpan startTime,
            Ratio framerate,
            TimeSpan totalDuration,
            IndexDatabase database
            )
        {
            string outputDirectory = Path.GetRandomFileName();
            Ratio quarterFramerate = new Ratio(framerate.Numerator, framerate.Denominator * 4);
            var ffmpegProcessSettings = new FFMPEGProcessSettings(
                videoFile,
                outputDirectory,
                startTime,
                CalculateFramesToOutputFromFramerate(startTime, quarterFramerate, totalDuration),
                framerate,
                FFMPEGOutputFormat.Y4M
            );

            if (Directory.Exists(outputDirectory) == false)
            {
                Directory.CreateDirectory(outputDirectory);
            }

            using (var ffmpegProcess = new FFMPEGProcess(ffmpegProcessSettings))
            {
                ffmpegProcess.Execute();
                IndexFilesInDirectory(videoFile, outputDirectory, startTime, database, quarterFramerate);
                try
                {
                    Directory.Delete(outputDirectory, true);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(string.Format("Could not clean up images: {0}", e.Message));
                }
            }
        }
        public void GetHashCode_Equals()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Equal(new { Ratio.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Equal(Ratio.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(RatioUnit)));
        }
        public void Convert_ToUInt64_EqualsValueAsSameType()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
        }
 public Note(int pitch, Ratio duration)
 {
     this.pitch = pitch;
     this.duration = duration;
 }
Esempio n. 10
0
 /// <inheritdoc cref="Ratio.FromPartsPerMillion(double)"/>
 public static Ratio PartsPerMillion(this long value) => Ratio.FromPartsPerMillion(value);
Esempio n. 11
0
 /// <inheritdoc cref="Ratio.FromPartsPerThousand(UnitsNet.QuantityValue)" />
 public static Ratio PartsPerThousand <T>(this T value) => Ratio.FromPartsPerThousand(Convert.ToDouble(value));
Esempio n. 12
0
 public Result(Ratio ratio, string word, int depth)
 {
     Word = word;
     Depth = depth;
     this.ratio = ratio;
 }
Esempio n. 13
0
        public TestsFile ParseTestsFile(string testsFile)
        {
            TestsFile result = new TestsFile();
            using (var fs = File.OpenRead(testsFile))
            {
                using (var br = new BinaryReader(fs))
                {
                    TestsFileHeader header = new TestsFileHeader();
                    header.RecSizeLabel = ConvertToString(br.ReadBytes(8));
                    header.RecSize = br.ReadInt32();
                    header.Unknown = br.ReadInt32();
                    result.Header = header;

                    result.Tests = new List<TestProperties>();
                    while (fs.Length > fs.Position)
                    {
                        var test = new TestProperties();
                        using (var ms = new MemoryStream(br.ReadBytes(header.RecSize)))
                        {
                            using (var br1 = new BinaryReader(ms))
                            {
                                // 读取TestIdentity
                                var identity = new TestIdentity();
                                // identity.Name = ConvertToString(br1.ReadBytes(21));
                                identity.Name = ConvertToGBString(br1.ReadBytes(21));
                                identity.Instrument = ConvertToString(br1.ReadBytes(11));
                                identity.GelSize = br1.ReadInt16();
                                identity.StainType = br1.ReadInt16();
                                test.Identity = identity;

                                // 
                                test.bIFE = br1.ReadBoolean();
                                test.Units = ConvertToString(br1.ReadBytes(11));
                                test.TotalUnits = ConvertToString(br1.ReadBytes(11));
                                test.AutoEditOptions = br1.ReadByte();
                                test.Precision = br1.ReadInt16();
                                test.UnitsFullScale = br1.ReadInt16();
                                test.ImageContrast = br1.ReadInt16();

                                // 读取DemoIdentity
                                var demos = new List<DemoIdentity>();
                                for (int i = 0; i < 10; i++)
                                {
                                    DemoIdentity d = new DemoIdentity();
                                    d.Label = ConvertToString(br1.ReadBytes(21));
                                    d.Type = br1.ReadByte();
                                    d.ASTMField = br1.ReadByte();
                                    demos.Add(d);
                                }
                                test.Demo = demos;

                                // 读取RangeSet
                                var rs = new List<Range>();
                                for (int i = 0; i < 9; i++)
                                {
                                    Range r = new Range();
                                    r.Sex = ConvertToString(br1.ReadBytes(2));
                                    r.Type = br1.ReadByte();
                                    r.AgeLow = br1.ReadByte();
                                    r.AgeLowUnits = br1.ReadByte();
                                    r.AgeHigh = br1.ReadByte();
                                    r.AgeHighUnits = br1.ReadByte();
                                    rs.Add(r);
                                }
                                test.RangeSet = rs;

                                br1.ReadByte();

                                // 读取Ratio
                                var ratios = new List<Ratio>();
                                for (int i = 0; i < 2; i++)
                                {
                                    Ratio r = new Ratio();
                                    r.Label = Encoding.ASCII.GetString(br1.ReadBytes(12));
                                    r.dRange = new List<KeyValuePair<double, double>>();
                                    for (int j = 0; j < 9; j++)
                                    {
                                        KeyValuePair<double, double> t = new KeyValuePair<double, double>(br1.ReadDouble(), br1.ReadDouble());
                                        r.dRange.Add(t);
                                    }
                                    ratios.Add(r);
                                }
                                test.Ratio = ratios;

                                // 读取Fraction
                                var fractions = new List<Fraction>();
                                for (int i = 0; i < 10 + 1; i++)
                                {
                                    Fraction f = new Fraction();
                                    f.Label = ConvertToString(br1.ReadBytes(13));
                                    f.Ratio = new List<byte>();
                                    f.Ratio.Add(br1.ReadByte());
                                    f.Ratio.Add(br1.ReadByte());
                                    f.bIstd = br1.ReadBoolean();
                                    f.dPctRange = new List<KeyValuePair<double, double>>();
                                    for (int j = 0; j < 9; j++)
                                    {
                                        KeyValuePair<double, double> t = new KeyValuePair<double, double>(br1.ReadDouble(), br1.ReadDouble());
                                        f.dPctRange.Add(t);
                                    }
                                    f.dUnitsRange = new List<KeyValuePair<double, double>>();
                                    for (int j = 0; j < 9; j++)
                                    {
                                        KeyValuePair<double, double> t = new KeyValuePair<double, double>(br1.ReadDouble(), br1.ReadDouble());
                                        f.dUnitsRange.Add(t);
                                    }
                                    fractions.Add(f);
                                }
                                test.Fraction = fractions;

                                // 不读取了
                                //test.RstrctBandLabel = ConvertToString(br1.ReadBytes(18));
                                //test.Reserved = Encoding.ASCII.GetString(br1.ReadBytes(2));
                                //test.Options = br1.ReadByte();
                            }
                        }
                        result.Tests.Add(test);
                    }
                }
            }
            return result;
        }
 // Group Types Weaknesses
 void ModifyGTW(int nl, int ol, int curLoc, int loc)
 {
     Ratio[] copyArr = new Ratio[ol];
     for(int x = 0; x < copyArr.Length; x++){
         copyArr[x] = new Ratio();
         copyArr[x] = target.types[loc].weaknesses[x];
     }
     target.types[loc].weaknesses = new Ratio[nl];
     int y = 0;
     if(nl < ol){
         for(int x = 0; x < copyArr.Length; x++){
             if(x != curLoc){
                 target.types[loc].weaknesses[y] = copyArr[x];
                 y++;
             }
         }
     }
     else{
         y = 0;
         for(int x = 0; x < target.types[loc].weaknesses.Length; x++){
             if(x != curLoc+1){
                 target.types[loc].weaknesses[x] = new Ratio();
                 target.types[loc].weaknesses[x] = copyArr[y];
                 y++;
             }
             else{
                 target.types[loc].weaknesses[x] = new Ratio();
             }
         }
     }
 }
Esempio n. 15
0
 internal override Ratio GetHumidity(byte[] readBuff)
 {
     return(Ratio.FromPercent(readBuff[0] + readBuff[1] * 0.1));
 }
Esempio n. 16
0
 /// <inheritdoc cref="Ratio.FromPartsPerBillion(double)"/>
 public static Ratio PartsPerBillion(this decimal value) => Ratio.FromPartsPerBillion(Convert.ToDouble(value));
Esempio n. 17
0
 /// <inheritdoc cref="Ratio.FromPartsPerTrillion(UnitsNet.QuantityValue)" />
 public static Ratio PartsPerTrillion <T>(this T value) => Ratio.FromPartsPerTrillion(Convert.ToDouble(value));
Esempio n. 18
0
 public void TestWriteRatio()
 {
     IRatio r = new Ratio(BigInteger.One, new BigInteger(2));
     Assert.AreEqual("{\"~#ratio\":[\"~n1\",\"~n2\"]}", WriteJsonVerbose(r));
     Assert.AreEqual("[\"~#ratio\",[\"~n1\",\"~n2\"]]", WriteJson(r));
 }
Esempio n. 19
0
 /// <inheritdoc cref="Ratio.FromPercent(UnitsNet.QuantityValue)" />
 public static Ratio Percent <T>(this T value) => Ratio.FromPercent(Convert.ToDouble(value));
Esempio n. 20
0
 public static bool TryParse(string rawValue, out Ratio value)
 {
     return TryParse<Ratio>(rawValue, out value);
 }
        public void Ctor_WithNaNValue_CreateQuantityAndAffectNaNValue()
        {
            var nanQuantity = new Ratio(double.NaN, RatioUnit.DecimalFraction);

            Assert.True(double.IsNaN(nanQuantity.Value));
        }
Esempio n. 22
0
 private static TimeSpan CalculateEndTime(TimeSpan startTime, Ratio frameRate, long frameNumber)
 {
     return startTime + TimeSpan.FromSeconds((frameRate.Denominator / (double)frameRate.Numerator) * frameNumber);
 }
        public void FromDecimalFractions_WithNanValue_CreateQuantityAndAffectNaNValue()
        {
            var nanQuantity = Ratio.FromDecimalFractions(double.NaN);

            Assert.True(double.IsNaN(nanQuantity.Value));
        }
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(Ratio)));
        }
        public void CompareToThrowsOnTypeMismatch()
        {
            Ratio decimalfraction = Ratio.FromDecimalFractions(1);

            Assert.Throws <ArgumentException>(() => decimalfraction.CompareTo(new object()));
        }
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Equal(QuantityType.Ratio, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
        public void CompareToThrowsOnNull()
        {
            Ratio decimalfraction = Ratio.FromDecimalFractions(1);

            Assert.Throws <ArgumentNullException>(() => decimalfraction.CompareTo(null));
        }
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
        public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException()
        {
            var v = Ratio.FromDecimalFractions(1);

            Assert.Throws <ArgumentOutOfRangeException>(() => v.Equals(Ratio.FromDecimalFractions(1), -1, ComparisonType.Relative));
        }
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = Ratio.FromDecimalFractions(value);

            Assert.Equal(Ratio.FromDecimalFractions(-value), -quantity);
        }
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            Ratio decimalfraction = Ratio.FromDecimalFractions(1);

            Assert.False(decimalfraction.Equals(new object()));
        }
Esempio n. 32
0
 /// <inheritdoc cref="Ratio.FromPartsPerBillion(double?)"/>
 public static Ratio?PartsPerBillion(this float?value) => Ratio.FromPartsPerBillion(value);
        public void EqualsReturnsFalseOnNull()
        {
            Ratio decimalfraction = Ratio.FromDecimalFractions(1);

            Assert.False(decimalfraction.Equals(null));
        }
Esempio n. 34
0
 /// <inheritdoc cref="Ratio.FromPartsPerBillion(double?)"/>
 public static Ratio?PartsPerBillion(this decimal?value) => Ratio.FromPartsPerBillion(value == null ? (double?)null : Convert.ToDouble(value.Value));
        public void ToString_NullArgs_ThrowsArgumentNullException()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null));
        }
Esempio n. 36
0
 /// <inheritdoc cref="Ratio.FromPartsPerMillion(double?)"/>
 public static Ratio?PartsPerMillion(this double?value) => Ratio.FromPartsPerMillion(value);
        public void ToString_NullProvider_EqualsCurrentUICulture()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g"));
        }
Esempio n. 38
0
 public void TestWriteCDictionary()
 {
     IRatio r = new Ratio(BigInteger.One, new BigInteger(2));
     IDictionary<object, object> d = new Dictionary<object, object>();
     d.Add(r, 1);
     Assert.AreEqual("{\"~#cmap\":[{\"~#ratio\":[\"~n1\",\"~n2\"]},1]}", WriteJsonVerbose(d));
     Assert.AreEqual("[\"~#cmap\",[[\"~#ratio\",[\"~n1\",\"~n2\"]],1]]", WriteJson(d));
 }
        public void Convert_ToDateTime_ThrowsInvalidCastException()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity));
        }
Esempio n. 40
0
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if (image1.Source == null)
            {
                MessageBox.Show("Please select an image.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (textBox1.Text == String.Empty || textBox1_selected == false)
            {
                MessageBox.Show("Please enter at least one word.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (thesaurus == null)
            {
                MessageBox.Show("Please please select a valid thesaurus file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            //
            //Find the synonyms of the words given
            //
            List<string> words;
            string wordString = textBox1.Text.Replace(" ", "");
            string[] wordsArray = wordString.Split(',');
            words = wordsArray.ToList<string>();
            words = GetSynonyms(words);

            string bigWords = String.Join("", words);
            int totalLetters = bigWords.Length;
            Ratio targetAR = new Ratio(image1.Source.Width, image1.Source.Height);

            // Theoretically you should be able to multiply this number by anything you want
            // to get a higher resolution picture... but in practice this is a very bad idea
            totalLetters = bigWords.Length;

            Ratio actualAR = GetAspectRatio(totalLetters, targetAR.Value);

            // Freakishly slow
            BitmapSource bitImage = ResizeBitmap((BitmapImage)image1.Source, actualAR.X, actualAR.Y);

            Color[,] colors = new Color[bitImage.PixelWidth, bitImage.PixelHeight];

            for (int pixely = 0; pixely < bitImage.PixelHeight; pixely++)
            {
                for (int pixelx = 0; pixelx < bitImage.PixelWidth; pixelx++)
                {
                    colors[pixelx, pixely] = GetPixel(bitImage, pixelx, pixely);
                }
            }

            string pageBuilder = "<html>\n<body style=\"font-family: monospace; background-color: #000000\">\n";
            char[] bigChars = bigWords.ToCharArray();
            int charPos = 0;

            for (int pixely = 0; pixely < bitImage.PixelHeight; pixely++)
            {
                for (int pixelx = 0; pixelx < bitImage.PixelWidth; pixelx++)
                {
                    pageBuilder = pageBuilder + "<font color=\"" + colors[pixelx, pixely].ToString() + "\">" + bigChars[charPos] + "</font>";

                    charPos++;
                    if (charPos == bigWords.Length)
                        charPos = 0;
                }

                pageBuilder = pageBuilder + "<br/>\n";
            }

            pageBuilder = pageBuilder + "</body>\n</html>";

            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Filter = "HTML Files (*.html, *.htm)|*.html;*.htm";

            bool? isSelected = saveDialog.ShowDialog(this);

            if (isSelected == true)
            {
                File.WriteAllText(saveDialog.FileName, pageBuilder);
            }
        }
        public void Convert_ToInt32_EqualsValueAsSameType()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity));
        }
        public void Convert_ToSingle_EqualsValueAsSameType()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
        }
        public void Convert_ToString_EqualsToString()
        {
            var quantity = Ratio.FromDecimalFractions(1.0);

            Assert.Equal(quantity.ToString(), Convert.ToString(quantity));
        }
Esempio n. 44
0
 public object add(object x, object y)
 {
     Ratio rx = toRatio(x);
     Ratio ry = toRatio(y);
     //return divide(ry.numerator.multiply(rx.denominator)
     //    .add(rx.numerator.multiply(ry.denominator)),
     //    ry.denominator.multiply(rx.denominator));
     BigInteger n1 = ry.numerator * rx.denominator;
     BigInteger n2 = rx.numerator * ry.denominator;
     BigInteger n = n1 + n2;
     BigInteger d = ry.denominator * rx.denominator;
     Ratio r = new Ratio(n, d);
     return divide(
         ry.numerator * rx.denominator + rx.numerator * ry.denominator,
         ry.denominator * rx.denominator);
 }
Esempio n. 45
0
        private static void IndexFilesInDirectory(string originalFileName, string directory, TimeSpan startTime, IndexDatabase database, Ratio frameRate)
        {
            foreach (string file in Directory.EnumerateFiles(directory, "*.y4m"))
            {
                using (var parser = new VideoFileParser(file))
                {
                    Maybe<VideoFile> videoFileMaybe = parser.TryParseVideoFile();
                    if (videoFileMaybe.IsNothing())
                    {
                        return;
                    }

                    VideoFile videoFile = videoFileMaybe.Value;
                    int frameNumber = 0;
                    foreach (VideoFrame frame in videoFile.Frames)
                    {
                        database.QueueAddEntry(new IndexEntry
                        {
                            VideoFile = originalFileName,
                            StartTime = startTime,
                            EndTime = CalculateEndTime(startTime, frameRate, frameNumber),
                            FrameHash = ImageFingerPrinter.CalculateFingerPrint(frame),
                        });
                        frameNumber++;
                    }
                }
            }
        }