Exemplo n.º 1
0
 public bool AddAviVideoFrame(Pixelmap pixmap, double addedGamma, int?adv16NormalisationValue)
 {
     if (!TangraVideo.AddAviVideoFrame(pixmap, addedGamma, adv16NormalisationValue))
     {
         MessageBox.Show("There was an error calling AddAviVideoFrame:\r\n\r\n" + TangraVideo.GetLastAviErrorMessage(), "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
     return(true);
 }
Exemplo n.º 2
0
        private void GenerateAVIVideo(ModelConfig modelConfig, List <IStar> stars)
        {
            TangraVideo.CloseAviFile();
            TangraVideo.StartNewAviFile(modelConfig.FileName, modelConfig.FrameWidth, modelConfig.FrameHeight, 8, 25, false);

            m_MagnitudeToPeakDict = null;

            try
            {
                //Pixelmap pixmap = new Pixelmap(modelConfig.FrameWidth, modelConfig.FrameHeight, bitPix, new uint[modelConfig.FrameWidth * modelConfig.FrameHeight], null, null);
                //AddOnScreenText(bmp, modelConfig, "The simulated video stars from the next frame");
                //TangraVideo.AddAviVideoFrame(pixmap, modelConfig.Gamma, null);

                uint maxSignalValue = (uint)(255 * modelConfig.Integration);

                Random rndGen = new Random((int)DateTime.Now.Ticks);
                m_SimulatedDarkFrame = new int[modelConfig.FrameWidth, modelConfig.FrameHeight];
                for (int x = 0; x < modelConfig.FrameWidth; x++)
                {
                    for (int y = 0; y < modelConfig.FrameHeight; y++)
                    {
                        if (modelConfig.DarkFrameMean > 0)
                        {
                            double randomPeak = rndGen.Next(0, 100) == 66 ? 255 : 0;
                            double darkPixel  = Math.Abs(VideoModelUtils.Random((modelConfig.DarkFrameMean + randomPeak) * modelConfig.Integration, 1));
                            double bgPixel    = Math.Min(maxSignalValue, Math.Max(0, darkPixel));
                            m_SimulatedDarkFrame[x, y] = (int)bgPixel;
                        }
                        else
                        {
                            m_SimulatedDarkFrame[x, y] = 0;
                        }
                    }
                }

                for (int i = 0; i <= modelConfig.TotalFrames; i++)
                {
                    using (Pixelmap pixmap = new Pixelmap(modelConfig.FrameWidth, modelConfig.FrameHeight, 16, new uint[modelConfig.FrameWidth * modelConfig.FrameHeight], null, null))
                    {
                        pixmap.SetMaxSignalValue(maxSignalValue);

                        VideoModelUtils.GenerateNoise(pixmap, m_SimulatedDarkFrame, modelConfig.NoiseMean * modelConfig.Integration, modelConfig.NoiseStdDev * modelConfig.Integration);
                        GenerateFrame(pixmap, stars, modelConfig);

                        TangraVideo.AddAviVideoFrame(pixmap, modelConfig.LinearityCoefficient, (int)pixmap.MaxSignalValue);
                    }

                    InvokeUpdateUI(2, (int)(100.0 * i / modelConfig.TotalFrames), true);
                }
            }
            finally
            {
                TangraVideo.CloseAviFile();
            }
        }
        private void GenerateSimulatedVideo(object state)
        {
            InvokeUpdateUI(2, 0, true);

            try
            {
                ModelConfig modelConfig = (ModelConfig)state;

                TangraVideo.CloseAviFile();
                TangraVideo.StartNewAviFile(modelConfig.FileName, 300, 200, 8, 25, false);
                try
                {
                    using (Bitmap bmp = new Bitmap(300, 200, PixelFormat.Format24bppRgb))
                    {
                        AddOnScreenText(bmp, modelConfig, "The simulated video stars from the next frame");
                        Pixelmap pixmap = Pixelmap.ConstructFromBitmap(bmp, TangraConfig.ColourChannel.Red);
                        TangraVideo.AddAviVideoFrame(pixmap, modelConfig.Gamma, null);
                    }

                    for (int i = 1; i <= modelConfig.TotalFrames; i++)
                    {
                        using (Pixelmap pixmap = GenerateFrame(i * 1.0 / modelConfig.TotalFrames, i, modelConfig))
                        {
                            TangraVideo.AddAviVideoFrame(pixmap, modelConfig.Gamma, null);
                        }

                        InvokeUpdateUI(2, (int)(100.0 * i / modelConfig.TotalFrames), true);
                    }
                }
                finally
                {
                    TangraVideo.CloseAviFile();
                }
            }
            finally
            {
                InvokeUpdateUI(2, 100, false);
            }
        }