/// <summary> /// 開啟RealSense相機並進行取像 /// </summary> internal void Open(out Image <Bgr, byte> ColorImg, out Image <Rgb, byte> DepthImg, out Image <Rgb, byte> FilteredImg, out VideoFrame color, out DepthFrame depth, out Frame filtered) { DepthImg = null; ColorImg = null; FilteredImg = null; color = null; depth = null; filtered = null; if (CamState != CameraState.Opened) { PipelineProfile = Camera.Start(cfg); // 以cfg設定並開始串流 vsp = PipelineProfile.GetStream <VideoStreamProfile>(Intel.RealSense.Stream.Depth); // 取得內部參數 intrinsics = vsp.GetIntrinsics(); sp = PipelineProfile.GetStream(Intel.RealSense.Stream.Color); // 取得外部參數 extrinsics = vsp.GetExtrinsicsTo(sp); CamState = CameraState.Opened; // 更新相機狀態 } else { try { FrameSet frames = Camera.WaitForFrames(); depth = frames.DepthFrame.DisposeWith(frames); color = frames.ColorFrame.DisposeWith(frames); filtered = depth; if (depth != null) { //Thres_Filter.Options[Option.MinDistance].Value = float.Parse(form1.textBox2.Text); //Thres_Filter.Options[Option.MaxDistance].Value = float.Parse(form1.textBox1.Text); //filtered = Thres_Filter.Process(filtered); //Spa_Filter.Options[Option.FilterMagnitude].Value = 1; //Spa_Filter.Options[Option.FilterSmoothAlpha].Value = 0.6f; //Spa_Filter.Options[Option.FilterSmoothDelta].Value = 8; //filtered = Spa_Filter.Process(filtered); Temp_Filter.Options[Option.FilterSmoothAlpha].Value = 0.5f; Temp_Filter.Options[Option.FilterSmoothDelta].Value = 20; Temp_Filter.Options[Option.HolesFill].Value = 2; filtered = Temp_Filter.Process(filtered); depColor = colorizer.Colorize(depth); filteredColor = colorizer.Colorize(filtered); ColorImg = new Image <Bgr, byte>(color.Width, color.Height, color.Stride, color.Data); DepthImg = new Image <Rgb, byte>(depColor.Width, depColor.Height, depColor.Stride, depColor.Data); FilteredImg = new Image <Rgb, byte>(filteredColor.Width, filteredColor.Height, filteredColor.Stride, filteredColor.Data); } } catch (Exception ex) { throw ex; } } }
public void ToHtml_ProperLineNumbers_ReturnsProperData() { // arrange var language = Substitute.For <ILanguage>(); var theme = Substitute.For <ITheme>(); const string SourceCode = "Line 1\nLine 2"; language.GetRules().Returns(Enumerable.Empty <Rule>()); theme.GetStyle(Arg.Any <TokenScope>()) .Returns(new Style { HexColor = string.Empty }); theme.BackgroundHexColor.Returns(string.Empty); theme.BaseHexColor.Returns(string.Empty); // act var result = Colorizer.Colorize(SourceCode) .WithLanguage(language) .WithTheme(theme).AddLineNumbers().ToHtml(); // assert Assert.AreEqual( "<pre style=\"color: ; background-color: ;\" class=\"code-colorizer\">\n<span class=\"code-colorizer-line\"><span style=\"color: ; background-color: ;\" class=\"code-colorizer-line-indicator\">1.</span>Line 1</span>\n<span class=\"code-colorizer-line\"><span style=\"color: ; background-color: ;\" class=\"code-colorizer-line-indicator\">2.</span>Line 2</span></pre>", result); }
public void ToHtml_ColorizeSampleCsharpCodeWithEmptyColorsTheme_WillReturnResult() { // arrange const string SampleCode = "public void Main()\n{\n\tvar a = new MyObject();\n}"; var language = new Csharp(); var theme = Substitute.For <ITheme>(); theme.GetStyle(Arg.Any <TokenScope>()) .Returns(new Style { HexColor = string.Empty }); theme.BackgroundHexColor.Returns(string.Empty); theme.BaseHexColor.Returns(string.Empty); // act var html = Colorizer.Colorize(SampleCode) .WithLanguage(language) .WithTheme(theme).ToHtml(); // assert Assert.AreEqual( "<pre style=\"color: ; background-color: ;\" class=\"code-colorizer\">\n<span class=\"code-colorizer-line\"><span style=\"color: ;\">public</span> <span style=\"color: ;\">void</span> Main()</span>\n<span class=\"code-colorizer-line\">{</span>\n<span class=\"code-colorizer-line\"> <span style=\"color: ;\">var</span> a = <span style=\"color: ;\">new</span> MyObject();</span>\n<span class=\"code-colorizer-line\">}</span></pre>", html); }
public void ToHtml_ColoringTextWithLangaugeThatHasNoRules_ReturnValueWillContainSourceText() { // arrange var language = Substitute.For <ILanguage>(); var theme = Substitute.For <ITheme>(); language.GetRules().Returns(Enumerable.Empty <Rule>()); theme.GetStyle(Arg.Any <TokenScope>()) .Returns(new Style { HexColor = string.Empty }); theme.BackgroundHexColor.Returns(string.Empty); theme.BaseHexColor.Returns(string.Empty); const string SourceText = "sample text that could be anything"; // act var coloredHtml = Colorizer.Colorize(SourceText) .WithLanguage(language) .WithTheme(theme) .ToHtml(); // assert Assert.IsTrue(coloredHtml.Contains(SourceText)); }
public static void Log(string message, LogType type, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { string fileName = Path.GetFileName(sourceFilePath); switch (type) { case LogType.Client: { Debug.Log($"[{Colorizer.Colorize("Client", Color.cyan)}][{memberName}:{fileName}:{sourceLineNumber}] {message}"); } break; case LogType.Server: { Debug.unityLogger.Log($"[{Colorizer.Colorize("Server", Color.green)}][{memberName}:{fileName}:{sourceLineNumber}] {message}"); } break; case LogType.Normal: { Debug.Log($"[{Colorizer.Colorize("Normal", Color.black)}][{memberName}:{fileName}:{sourceLineNumber}] {message}"); } break; } }
public DetailsView() { InitializeComponent(); Colorizer.Colorize((Layout)Content, true); //Colorizer.LoremText((Layout)Content, true); //Colorizer.Image((Layout)Content, true); }
public DashBoardView() { InitializeComponent(); Colorizer.Colorize((Layout)Content, true); Colorizer.LoremText((Layout)Content, false); Colorizer.RandomImage((Layout)Content, false); }
public void ToHtml_NoLanguageProvided_WillThrowException() { // arrange var theme = Substitute.For <ITheme>(); var colorizer = Colorizer.Colorize(string.Empty).WithTheme(theme); // act => assert ExceptionAssert.Throws <NoLanguageProvidedException>( () => colorizer.ToHtml()); }
public void ToHtml_NoThemeProvided_ThrowsException() { // arrange var language = Substitute.For <ILanguage>(); var colorizer = Colorizer.Colorize(string.Empty).WithLanguage(language); // act => assert ExceptionAssert.Throws <NoThemeProvidedException>( () => colorizer.ToHtml()); }
public void WithLanguage_ProvidingLanguage_ReturnsSameCodeColorizerReference() { // arrange var sourceCode = string.Empty; var language = Substitute.For <ILanguage>(); // act var codeColorizer = Colorizer.Colorize(sourceCode); var withLanguageColorizer = codeColorizer.WithLanguage(language); // assert Assert.AreSame(codeColorizer, withLanguageColorizer); }
public void ToHtml_ProvidingNullStylesInTheme_WillThrowException() { // arrange var language = Substitute.For <ILanguage>(); var theme = Substitute.For <ITheme>(); theme.GetStyle(TokenScope.Keyword).Returns((Style)null); // act Colorizer.Colorize(string.Empty) .WithLanguage(language) .WithTheme(theme) .ToHtml(); }
public void ToHtml_ProvidingNullColorsInStylesInTheme_WillThrowException() { // arrange var language = Substitute.For <ILanguage>(); var theme = Substitute.For <ITheme>(); theme.GetStyle(Arg.Any <TokenScope>()).Returns(new Style()); // act => assert ExceptionAssert.Throws <NoStyleColorProvidedException>( () => Colorizer.Colorize(string.Empty) .WithLanguage(language) .WithTheme(theme) .ToHtml()); }
public BackerView() { InitializeComponent(); Colorizer.Colorize((Layout)Content); var er = new Label().Text; //back.Source = "https://lorempixel.com/100/100"; // back.Source = new UriImageSource //{ // Uri = new Uri("https://lorempixel.com/400/200/"), // CachingEnabled = true, // CacheValidity = new TimeSpan(5, 0, 0, 0) //}; }
override protected Frame ProcessFrame(Frame frame) { if (prevColorMap != colorMap) { try { m_colorizer.Options[Option.ColorScheme].Value = (float)colorMap; prevColorMap = colorMap; } catch (Exception e) { Debug.LogError("Failed to change color scheme for colorizer. " + e.Message); colorMap = prevColorMap; } } return(m_colorizer.Colorize(frame as VideoFrame)); }
/// <summary> /// Colorizes the selected text using the selected programming language. This method is usually called when the user clicks on the Colorize button. /// The method creates the pharagraph formatting of the text, and then redirects to the Colorizer to determine the syntax based coloring. The Colorizer will then call back the Formatter to color individual words or characters. /// </summary> /// <param name="language">The programming language that the selected text is written in</param> /// <param name="use_frame">Determines whether the code block will be put in a frame</param> /// <param name="use_linenumbering">Determines whether line numbering should be used</param> public void Colorize(string language, bool use_frame, bool use_linenumbering) { if (wordApp.Selection.Text.Length > 1) // If there is nothing selected, this property still contains 1 character. { if (TooLargeInput(use_frame, use_linenumbering, wordApp.Selection.Paragraphs.Count)) { return; } // Using an UndoRecord enables the user the "undo" all the coloring at once. Without it every formatting action would be an individual element in the undo stack. Word.UndoRecord ur = wordApp.UndoRecord; ur.StartCustomRecord("Syntax Highlighting"); //wordApp.ScreenUpdating = false; // might be useful on slow computers? // Vertical tab characters are replaced with newlines, as they would usually mess up the pharagraph formatting if (wordApp.Selection.Text.Contains("\x0B")) { string temp = wordApp.Selection.Text.Replace("\x0B", "\n"); wordApp.Selection.Text = temp.Remove(temp.Length - 1); // Replace inserts a '\n' at the end that must be removed } wordApp.Selection.ClearFormatting(); // All previous formatting is removed! Otherwise the result of the formatting could be quiet unpredictable wordApp.Selection.NoProofing = 1; // Spell checks usually just add noise to a code block in a document wordApp.Selection.Font.Name = this.fontName; wordApp.Selection.Font.Size = this.fontSize; try { // Calculates what colors should be used for each word or character, and calls back the formatter colorizer.Colorize(this, language, wordApp.Selection.Text); } catch (InvalidLanguageException e) { MessageBox.Show(e.Message, "Syntax Highlighter Error"); } catch (InvalidRegexException e) { MessageBox.Show(e.Message, "Syntax Highlighter Error"); } this.ParagraphFormatting(use_frame, use_linenumbering); wordApp.ScreenUpdating = true; ur.EndCustomRecord(); } }
public void ToHtmlColorizeSampleHtmlWithEncoding_WillReturnProperResult() { // arrange const string sampleCode = "<pre></pre>"; var language = new Csharp(); var theme = new ObsidianTheme(); //act var html = Colorizer.Colorize(sampleCode) .WithTheme(theme) .WithLanguage(language) .WithHtmlEncoding() .ToHtml(); // assert Assert.AreEqual("<pre style=\"color: #F1F2F3; background-color: #111;\" class=\"code-colorizer\">\n<span class=\"code-colorizer-line\"><pre></pre></span></pre>", html); }
public void ToHtml_ProvidingSimpleCSharpSourceCode_CallsGetStyleFromTheme() { // arrange var language = new Csharp(); var theme = Substitute.For <ITheme>(); const string SourceCode = "public void Main()\n{\n\tvar a = new MyObject();\n}"; theme.GetStyle(Arg.Any <TokenScope>()) .Returns(new Style { HexColor = string.Empty }); theme.BackgroundHexColor.Returns(string.Empty); theme.BaseHexColor.Returns(string.Empty); // act Colorizer.Colorize(SourceCode) .WithLanguage(language) .WithTheme(theme).ToHtml(); // assert theme.Received().GetStyle(Arg.Any <TokenScope>()); }
public override Frame Process(Frame frame, FrameSource frameSource, FramesReleaser releaser) { return(_enabled ? _pb.Colorize(frame as VideoFrame) : frame); }