Example #1
0
        private SERVideoStream(string fileName, double frameRate, int cameraBitPix, bool grayScaleRGB, SerUseTimeStamp useTimeStamp, Dictionary <int, DateTime> fireCaptureTimeStamps, SerTimeStampReference timeStampReference = SerTimeStampReference.MidFrame)
        {
            m_FileInfo = new SerFileInfo();

            byte[] observer   = new byte[40];
            byte[] instrument = new byte[40];
            byte[] telescope  = new byte[40];

            TangraCore.SEROpenFile(fileName, ref m_FileInfo, observer, instrument, telescope, false, grayScaleRGB);

            m_FileName = fileName;

            BitPix                  = cameraBitPix;
            FrameRate               = frameRate;
            MillisecondsPerFrame    = 1000.0 / frameRate;
            UseTimeStamp            = useTimeStamp;
            TimeStampReference      = timeStampReference;
            m_FireCaptureTimeStamps = fireCaptureTimeStamps;

            Observer   = Encoding.UTF8.GetString(observer).Trim();
            Instrument = Encoding.UTF8.GetString(instrument).Trim();
            Telescope  = Encoding.UTF8.GetString(telescope).Trim();

            HasTimeStamps            = false;
            HasUTCTimeStamps         = false;
            HasFireCaptureTimeStamps = false;

            if (useTimeStamp != SerUseTimeStamp.None)
            {
                HasFireCaptureTimeStamps = useTimeStamp == SerUseTimeStamp.FireCaptureLog;

                if (!HasFireCaptureTimeStamps)
                {
                    HasTimeStamps =
                        m_FileInfo.SequenceStartTimeHi != 0 &&
                        m_FileInfo.SequenceStartTimeHi >> 0x1F == 0;

                    HasUTCTimeStamps =
                        m_FileInfo.SequenceStartTimeUTCHi != 0 &&
                        m_FileInfo.SequenceStartTimeUTCHi >> 0x1F == 0;
                }
            }
        }
Example #2
0
        public static SERVideoStream OpenFile(string fileName, IWin32Window parentForm, TangraOpenFileArgs args, out SerEquipmentInfo equipmentInfo)
        {
            var fileInfo = new SerFileInfo();

            equipmentInfo = new SerEquipmentInfo();

            byte[] observer   = new byte[40];
            byte[] instrument = new byte[40];
            byte[] telescope  = new byte[40];

            TangraCore.SEROpenFile(fileName, ref fileInfo, observer, instrument, telescope, false);

            string fireCaptureLogFileName = Path.ChangeExtension(fileName, ".txt");
            var    fireCaptureTimeStamps  = new Dictionary <int, DateTime>();

            if (File.Exists(fireCaptureLogFileName))
            {
                string[] fireCaptureLogLines = File.ReadAllLines(fireCaptureLogFileName);
                fireCaptureLogLines = fireCaptureLogLines.Where(x => x != null && x.StartsWith("Frame ")).ToArray();
                if (fireCaptureLogLines.Any())
                {
                    // Parse FireCapture timestamps
                    Regex timestampRegEx = new Regex(@"Frame (\d+):\s+(UT)?\s+(\d\d\d\d\d\d)\s+(\d\d\d\d\d\d)\.(\d+)");
                    foreach (string line in fireCaptureLogLines)
                    {
                        Match match = timestampRegEx.Match(line);
                        if (match.Success)
                        {
                            string frameNo = match.Groups[1].Value;
                            bool   isUT    = match.Groups[2].Value == "UT";
                            string ddmmyy  = match.Groups[isUT ? 3 : 2].Value;
                            string hhmmss  = match.Groups[isUT ? 4 : 3].Value;
                            double fffff   = double.Parse("0." + match.Groups[isUT ? 5 : 4].Value, CultureInfo.InvariantCulture);

                            DateTime dt = new DateTime(
                                2000 + int.Parse(ddmmyy.Substring(4, 2)),
                                int.Parse(ddmmyy.Substring(2, 2)),
                                int.Parse(ddmmyy.Substring(0, 2)),
                                int.Parse(hhmmss.Substring(0, 2)),
                                int.Parse(hhmmss.Substring(2, 2)),
                                int.Parse(hhmmss.Substring(4, 2))).AddMilliseconds(fffff * 1000);

                            fireCaptureTimeStamps.Add(int.Parse(frameNo), dt);
                        }
                    }
                }
            }

            UsageStats.Instance.ProcessedSerFiles++;
            UsageStats.Instance.Save();

            int             bitPix;
            double          frameRate;
            SerUseTimeStamp serTiming;

            if (args != null)
            {
                bitPix    = args.BitPix;
                frameRate = args.FrameRate;
                serTiming = args.SerTiming;
            }
            else
            {
                var frmInfo = new frmEnterSERFileInfo(fileInfo, fireCaptureTimeStamps.Count > 0);
                if (frmInfo.ShowDialog(parentForm) != DialogResult.OK)
                {
                    return(null);
                }
                frameRate = frmInfo.FrameRate;
                bitPix    = frmInfo.BitPix;
                serTiming = frmInfo.UseEmbeddedTimeStamps;
            }

            TangraCore.SERCloseFile();

            var rv = new SERVideoStream(fileName, frameRate, bitPix, serTiming, fireCaptureTimeStamps);

            equipmentInfo.Instrument = rv.Instrument;
            equipmentInfo.Observer   = rv.Observer;
            equipmentInfo.Telescope  = rv.Telescope;

            if (rv.HasTimeStamps || rv.HasUTCTimeStamps || rv.HasFireCaptureTimeStamps)
            {
                var frmCheckTS = new frmCheckTimeStampsIntegrity(rv);
                frmCheckTS.ShowDialog(parentForm);
            }
            return(rv);
        }
Example #3
0
        public frmEnterSERFileInfo(SerFileInfo info, bool hasFireCaptureTimestamps)
        {
            InitializeComponent();

            cbxBitPix.Items.Clear();

            bool hasEmbeddedTimeStamps =
                info.SequenceStartTimeUTCHi != 0 &&
                info.SequenceStartTimeUTCHi >> 0x1F == 0;

            if (info.PixelDepthPerPlane == 8)
            {
                cbxBitPix.Items.Add("8");
                cbxBitPix.SelectedIndex = 0;
            }
            else
            {
                cbxBitPix.Items.Add("8");
                cbxBitPix.Items.Add("12");
                cbxBitPix.Items.Add("14");
                cbxBitPix.Items.Add("16");

                switch (info.PixelDepthPerPlane)
                {
                case 12:
                    cbxBitPix.SelectedIndex = 1;
                    break;

                case 14:
                    cbxBitPix.SelectedIndex = 2;
                    break;

                case 16:
                    cbxBitPix.SelectedIndex = 3;
                    break;

                default:
                    int selIndex = cbxBitPix.Items.IndexOf(TangraConfig.Settings.LastUsed.SerFileLastBitPix.ToString());
                    if (selIndex != -1)
                    {
                        cbxBitPix.SelectedIndex = selIndex;
                    }
                    else
                    {
                        cbxBitPix.SelectedIndex = 4;
                    }
                    break;
                }
            }

            nudFrameRate.SetNUDValue(TangraConfig.Settings.LastUsed.SerFileLastFrameRate);
            pnlFrameRate.Visible = !hasEmbeddedTimeStamps;

            if (hasFireCaptureTimestamps)
            {
                cbxTimeSource.Items.Add("FireCapture Log File");
                cbxTimeSource.SelectedIndex = cbxTimeSource.Items.Count - 1;
            }
            else
            {
                cbxTimeSource.SelectedIndex = hasEmbeddedTimeStamps ? 1 : 0;
                if (!hasEmbeddedTimeStamps)
                {
                    cbxTimeSource.Enabled = false;
                }
            }
        }