Exemplo 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;
        }
Exemplo n.º 2
0
        public SubTitle Clone()
        {
            var _new = new SubTitle(id, First_Sub, Second_Sub);

            _new.Has_Shown = this.Has_Shown;
            _new.alpha     = this.alpha;
            return(_new);
        }
Exemplo n.º 3
0
 private void lst_SubTitle_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         Previewing = subTitles[lst_SubTitle.SelectedIndex];
         Preview(Previewing);
     }
     catch (Exception ex)
     { Console.WriteLine(ex.ToString()); }
 }
Exemplo n.º 4
0
 public void Cut(SubTitle sub)
 {
     lock (syncLock)
     {
         if (isFading)
         {
             return;
         }
         program = sub;
     }
 }
Exemplo n.º 5
0
 private void DrawFrame()
 {
     lock (syncLock)
     {
         graphics.Clear(Color.Transparent);
         if (!isFading)
         { // As Normal
             graphics.DrawString(program.First_Sub, font, defaultBrush, Point_Sub1);
             graphics.DrawString(program.Second_Sub, font, defaultBrush, Point_Sub2);
         }
         else
         {   // BUG   !!!!
             // FADING
             if (Fading_X >= Alpha_Max)
             {
                 Fading_X = 255;
                 isFading = false; //end fade
                 program  = fading;
             }
             if (Fading_X < Alpha_Max / 2) //Alpha_Max/2 = 127.5
             {
                 // from program to empty
                 // It's 0 -> 127 , but alpha should be 255 -> 0
                 // So we use 255 - Fading_X * 2
                 int alpha = Alpha_Max - Fading_X * 2;
                 if (alpha < 0)
                 {
                     alpha = 0;
                 }
                 var brush = new SolidBrush(Color.FromArgb(alpha, Color.White));
                 graphics.DrawString(program.First_Sub, font, brush, Point_Sub1);
                 graphics.DrawString(program.Second_Sub, font, brush, Point_Sub2);
             }
             else if (Fading_X >= Alpha_Max / 2)
             {
                 // from empty to fading
                 // It's 128 -> 255,but alpha should be 0 -> 255
                 // So we use Fading_X * 2 - 255
                 int alpha = Fading_X * 2 - Alpha_Max;
                 if (alpha > 255)
                 {
                     alpha = 255;
                 }
                 var brush = new SolidBrush(Color.FromArgb(alpha, Color.White));
                 graphics.DrawString(fading.First_Sub, font, brush, Point_Sub1);
                 graphics.DrawString(fading.Second_Sub, font, brush, Point_Sub2);
             }
             Fading_X += delta_X;
         }
     }
 }
Exemplo n.º 6
0
 public void Fade(SubTitle sub)
 {
     lock (syncLock)
     {
         if (isFading)
         {
             return;
         }
         fading       = sub.Clone();
         fading.alpha = Alpha_Min;
         isFading     = true;
         Fading_X     = 0; //Reset Fading_X
     }
 }
Exemplo n.º 7
0
 private void Program(SubTitle st)
 {
     lb_pgm_id.Text  = "Program " + st.id.ToString();
     lb_program.Text = st.ToString(true);
 }
Exemplo n.º 8
0
 private void Preview(SubTitle st)
 {
     lb_pre_id.Text  = "Preview " + st.id.ToString();
     lb_preview.Text = st.ToString(true);
 }