Ejemplo n.º 1
0
        public NDIRender(CancellationToken cancellationToken, NDIConfig config, Font font)
        {
            this.cancellationToken = cancellationToken;

            // We are going to create a 1920x180 frame at 50p, progressive (default).
            this.videoFrame = new VideoFrame(config.NDI_width, config.NDI_height, config.aspectRatio, config.frameRateNumerator, config.frameRateDenominator);
            bmp             = new Bitmap(videoFrame.Width, videoFrame.Height, videoFrame.Stride,
                                         System.Drawing.Imaging.PixelFormat.Format32bppArgb, videoFrame.BufferPtr);
            graphics = Graphics.FromImage(bmp);
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            // NDI Renderer
            program = SubTitle.Empty;
            fading  = SubTitle.Empty;

            // Style
            defaultBrush = new SolidBrush(config.Default_Color);
            this.font    = font;

            // Fade Setting
            isFading = false;
            // For delta_X, We plus delta_X into alpha
            // Fade Effect will last for 500ms
            // So every frame it will change 255/(50frames/2steps) = 10
            delta_X = Alpha_Max / (config.frameRateNumerator / config.frameRateDenominator) * 2;

            // If Fading_X <  Alpha_Max / 2 ,it's the former part (from program to empty)
            // If Fading_X >= Alpha_Max / 2 ,it's the latter part (from empty to fading )
            // If Fading_X >= Alpha_Max     ,it means fade ends   (set program as fading)
            Fading_X = 0;
        }
Ejemplo n.º 2
0
        public static NDIConfig ReadNDIConfig(JObject jo)
        {
            try
            {
                NDIConfig config = new NDIConfig();
                config.NDI_width            = Convert.ToInt32(jo["NDI_width"].ToString());
                config.NDI_height           = Convert.ToInt32(jo["NDI_height"].ToString());
                config.aspectRatio          = Convert.ToSingle(config.NDI_width) / Convert.ToSingle(config.NDI_height);
                config.frameRateNumerator   = Convert.ToInt32(jo["frameRateNumerator"].ToString());
                config.frameRateDenominator = Convert.ToInt32(jo["frameRateDenominator"].ToString());

                config.Point_Sub1 = new Point(Convert.ToInt32(jo["Point1_X"].ToString()), Convert.ToInt32(jo["Point1_Y"].ToString()));
                config.Point_Sub2 = new Point(Convert.ToInt32(jo["Point2_X"].ToString()), Convert.ToInt32(jo["Point2_Y"].ToString()));
                if (jo.ContainsKey("Color_Name"))
                {
                    config.Default_Color = Color.FromName(jo["Color_Name"].ToString());
                }
                else
                {
                    config.Default_Color = Color.FromArgb(Convert.ToInt32(jo["Color"]["alpha"].ToString()),
                                                          Convert.ToInt32(jo["Color"]["red"].ToString()),
                                                          Convert.ToInt32(jo["Color"]["green"].ToString()),
                                                          Convert.ToInt32(jo["Color"]["blue"].ToString()));
                }
                config.Fade_Time = Convert.ToInt32(jo["Fade_Time"].ToString());
                return(config);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(new NDIConfig(true));//Return Default Setting
            }
        }
Ejemplo n.º 3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Init Fonts
            using (InstalledFontCollection fontsCollection = new InstalledFontCollection())
            {
                FontFamily[]  fontFamilies = fontsCollection.Families;
                List <string> fonts        = new List <string>();
                foreach (FontFamily font in fontFamilies)
                {
                    cmb_Fonts.Items.Add(font.Name);
                }
            }
            cmb_Fonts.SelectedIndex = 1;
            // Read Config
            var config_path = Path.Combine(Directory.GetCurrentDirectory(), "NDI-SubTitle.config");

            try
            {
                Config = JObject.Parse(File.ReadAllText(config_path));
                if (Config.ContainsKey("NDI"))
                {
                    NDI_Config = NDIConfig.ReadNDIConfig(Config["NDI"] as JObject);
                }
                else
                {
                    NDI_Config = new NDIConfig(true);
                }
                if (Config.ContainsKey("Font-Size"))
                {
                    Font_Size = Convert.ToSingle(Config["Font-Size"].ToString());
                }
                else
                {
                    Font_Size = 50;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Reading Config File Failed");
                Console.WriteLine(ex.ToString());
                NDI_Config = new NDIConfig(true);
                Font_Size  = 50;
            }
        }