Пример #1
0
        public void TestPixelDeserialization(AdvSourceDataFormat dataFormat, byte dynaBits, CompressionType compression)
        {
            var fileGen = new AdvGenerator();
            var cfg     = new AdvGenerationConfig()
            {
                DynaBits         = dynaBits,
                SourceFormat     = dataFormat,
                NumberOfFrames   = 1,
                Compression      = compression,
                NormalPixelValue = null
            };

            string fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            AdvFile2 file = null;

            try
            {
                // Generate
                fileGen.GenerateaAdv_V2(cfg, fileName);

                var    hasher = new Hasher();
                string h1     = hasher.CalcMd5(fileName);
                Console.WriteLine("File hash for {0} at {1} bits: {2}", dataFormat, dynaBits, h1);

                // Verify
                using (file = new AdvFile2(fileName))
                {
                    uint[] pixels = file.GetMainFramePixels(0);

                    var imageGenerator = new ImageGenerator();
                    var verified       = imageGenerator.VerifyImagePattern1UInt32(pixels, cfg.DynaBits);
                    Assert.IsTrue(verified);
                }
            }
            finally
            {
                try
                {
                    if (file != null)
                    {
                        file.Close();
                    }
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Trace.WriteLine(ex);
                }
            }
        }
Пример #2
0
        public void TestReadingFileWithErrorMessageInTheStatusChannel()
        {
            var fileGen = new AdvGenerator();
            var cfg     = new AdvGenerationConfig()
            {
                DynaBits             = 16,
                SourceFormat         = AdvSourceDataFormat.Format16BitUShort,
                NumberOfFrames       = 1,
                Compression          = CompressionType.Uncompressed,
                NormalPixelValue     = null,
                SystemErrorsCallback = delegate(int id) { return("Sample Error Message"); }
            };

            string fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            AdvFile2 file = null;

            try
            {
                // Generate
                fileGen.GenerateaAdv_V2(cfg, fileName);

                // Verify
                using (file = new AdvFile2(fileName))
                {
                    uint[] pixels = file.GetMainFramePixels(0);

                    var imageGenerator = new ImageGenerator();
                    var verified       = imageGenerator.VerifyImagePattern1UInt32(pixels, cfg.DynaBits);
                    Assert.IsTrue(verified);
                }
            }
            finally
            {
                try
                {
                    if (file != null)
                    {
                        file.Close();
                    }
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Trace.WriteLine(ex);
                }
            }
        }
Пример #3
0
        private void SaveAdvVer2Sample()
        {
            string fileName = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + @"Filename2.adv");

            if (File.Exists(fileName))
            {
                if (MessageBox.Show(string.Format("Output file exists:\r\n\r\n{0}\r\n\r\nOverwrite?", fileName), "Confirmation", MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return;
                }

                File.Delete(fileName);
            }

            var config = new AdvGenerationConfig();

            config.SaveLocationData = cbxLocationData.Checked;

            // Define the image size and bit depth
            config.DynaBits = 16;
            if (rbPixel16.Checked)
            {
                config.DynaBits = 16;
            }
            else if (rbPixel12.Checked)
            {
                config.DynaBits = 12;
            }
            else if (rbPixel8.Checked)
            {
                config.DynaBits = 8;
            }

            config.NormalPixelValue = null;
            if (nudMaxPixelValue.Value > 0)
            {
                config.NormalPixelValue = (int)nudMaxPixelValue.Value;
            }

            config.Compression = CompressionType.Uncompressed;
            if (cbxCompress.Checked)
            {
                config.Compression = rbLagarith16.Checked ? CompressionType.Lagarith16 : CompressionType.QuickLZ;
            }

            if (rb16BitUShort.Checked)
            {
                config.SourceFormat = AdvSourceDataFormat.Format16BitUShort;
            }
            else if (rb16BitByte.Checked)
            {
                config.SourceFormat = AdvSourceDataFormat.Format16BitLittleEndianByte;
            }
            else if (rb12BitByte.Checked)
            {
                config.SourceFormat = AdvSourceDataFormat.Format12BitPackedByte;
            }
            else if (rb8BitByte.Checked)
            {
                config.SourceFormat = AdvSourceDataFormat.Format8BitByte;
            }
            else if (rb24bitRGB.Checked || rb24bitBGR.Checked)
            {
                config.SourceFormat = AdvSourceDataFormat.Format24BitColour;
                config.BayerPattern = rb24bitRGB.Checked ? BayerPattern.RGB : BayerPattern.BGR;
            }

            config.NumberOfFrames = GetTotalImages();

            config.ExposureCallback     = GetCurrentImageExposure;
            config.TimeStampCallback    = GetCurrentImageTimeStamp;
            config.GainCallback         = GetCurrentImageGain;
            config.GammaCallback        = GetCurrentImageGamma;
            config.SystemErrorsCallback = GetCurrentSystemErrors;
            config.MainStreamMetadata.Add("Name1", "Христо");
            config.MainStreamMetadata.Add("Name2", "Frédéric");
            config.MainStreamMetadata.Add("Name3", "好的茶");

            if (cbxZeroTicks.Checked)
            {
                config.MainStreamCustomClock = new CustomClockConfig()
                {
                    ClockFrequency      = 1,
                    ClockTicksCallback  = () => 0,
                    TicksTimingAccuracy = 1
                };
                config.CalibrationStreamCustomClock = new CustomClockConfig()
                {
                    ClockFrequency      = 1,
                    ClockTicksCallback  = () => 0,
                    TicksTimingAccuracy = 1
                };
            }
            var advGen = new AdvGenerator();

            advGen.GenerateaAdv_V2(config, fileName);

            ActionFileOperation(fileName);
        }
Пример #4
0
        public void TestTimestampsAreSavedAndReadCorrectly()
        {
            DateTime frameTimeStamp  = new DateTime(2016, 6, 24, 20, 42, 15).AddMilliseconds(1234);
            long     tickStamp       = frameTimeStamp.Ticks;
            float    exposureMS      = 16.7f;
            DateTime frameTimeStamp2 = frameTimeStamp.AddMilliseconds(17);
            long     tickStamp2      = frameTimeStamp2.Ticks;

            var utcTimeStamps = new DateTime[] { frameTimeStamp, frameTimeStamp2 };
            var tickStamps    = new long[] { tickStamp, tickStamp2 };

            AdvTimeStamp ts           = AdvTimeStamp.FromDateTime(frameTimeStamp);
            var          tdBackFromMS = new DateTime((long)AdvTimeStamp.ADV_EPOCH_ZERO_TICKS).AddMilliseconds(ts.MillisecondsAfterAdvZeroEpoch);

            Assert.AreEqual(frameTimeStamp.Ticks, tdBackFromMS.Ticks);

            Assert.AreEqual(ts.MillisecondsAfterAdvZeroEpoch, ts.NanosecondsAfterAdvZeroEpoch / 1000000);

            var tdBackFromNS = new DateTime((long)AdvTimeStamp.ADV_EPOCH_ZERO_TICKS).AddMilliseconds(ts.NanosecondsAfterAdvZeroEpoch / 1000000.0);

            Assert.AreEqual(frameTimeStamp.Ticks, tdBackFromNS.Ticks);

            var maxTimeStamp = new DateTime((long)AdvTimeStamp.ADV_EPOCH_ZERO_TICKS).AddMilliseconds(ulong.MaxValue / 1000000.0);

            Console.WriteLine(string.Format("Max ADV UTC Timestamp: {0}", maxTimeStamp.ToString("yyyy-MMM-dd HH:mm:ss")));

            Assert.AreEqual(frameTimeStamp.Ticks, new DateTime((long)AdvTimeStamp.ADV_EPOCH_ZERO_TICKS).AddMilliseconds(204496936234000000 / 1000000.0).Ticks);

            var fileGen = new AdvGenerator();

            int tickId = -1;
            var cfg    = new AdvGenerationConfig()
            {
                DynaBits              = 16,
                SourceFormat          = AdvSourceDataFormat.Format16BitUShort,
                NumberOfFrames        = 2,
                Compression           = CompressionType.Uncompressed,
                NormalPixelValue      = null,
                MainStreamCustomClock = new CustomClockConfig()
                {
                    ClockFrequency      = 10000000,
                    ClockTicksCallback  = () => { tickId++; return(tickStamps[tickId]); },
                    TicksTimingAccuracy = 1
                },
                CalibrationStreamCustomClock = new CustomClockConfig()
                {
                    ClockFrequency      = 10000000,
                    ClockTicksCallback  = () => 0,
                    TicksTimingAccuracy = 1
                },
                TimeStampCallback = new GetCurrentImageTimeStampCallback((frameId) => utcTimeStamps[frameId]),
                ExposureCallback  = id => (uint)(exposureMS * 1000000.0)
            };

            string fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            try
            {
                // Generate
                fileGen.GenerateaAdv_V2(cfg, fileName);

                // Verify
                using (var loadedFile = new AdvFile2(fileName))
                {
                    AdvFrameInfo frameInfo;
                    loadedFile.GetMainFramePixels(0, out frameInfo);

                    Assert.IsNotNull(frameInfo);
                    Assert.IsTrue(frameInfo.HasUtcTimeStamp);
                    Assert.AreEqual(frameTimeStamp.Ticks, frameInfo.UtcStartExposureTimeStamp.Ticks);
                    Assert.AreEqual(exposureMS, frameInfo.UtcExposureMilliseconds, 0.00001);

                    Assert.AreEqual(0, frameInfo.TickStampStartTicks);
                    Assert.AreEqual(tickStamp, frameInfo.TickStampEndTicks);

                    loadedFile.GetMainFramePixels(1, out frameInfo);

                    Assert.IsNotNull(frameInfo);
                    Assert.IsTrue(frameInfo.HasUtcTimeStamp);
                    Assert.AreEqual(frameTimeStamp2.Ticks, frameInfo.UtcStartExposureTimeStamp.Ticks);
                    Assert.AreEqual(exposureMS, frameInfo.UtcExposureMilliseconds, 0.00001);

                    Assert.AreEqual(tickStamp, frameInfo.TickStampStartTicks);
                    Assert.AreEqual(tickStamp2, frameInfo.TickStampEndTicks);
                }
            }
            finally
            {
                try
                {
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Trace.WriteLine(ex);
                }
            }
        }