Beispiel #1
0
        internal bool CanStartProducingFrame(FrameType frameType, int numFramesToTake)
        {
            if (frameType == FrameType.MasterFlat &&
                !m_MakeDarkFlatController.HasDarkFrameBytes)
            {
                m_VideoController.ShowMessageBox(
                    "Please load a dark frame from the 'Reduction' -> 'Load Calibration Frame' menu in order to dark frame correct the produced master flat frame. You may need to produce your dark frame first.",
                    "Dark frame required",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return(false);
            }

            if (frameType == FrameType.MasterDark &&
                !m_MakeDarkFlatController.HasBiasFrameBytes)
            {
                m_VideoController.ShowMessageBox(
                    "Please load a bias frame from the 'Reduction' -> 'Load Calibration Frame' menu in order to bias frame correct the produced master dark frame. You may need to produce your bias frame first.",
                    "Bias frame required",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return(false);
            }

            if (m_VideoController.VideoLastFrame - m_FrameNumber < numFramesToTake)
            {
                m_VideoController.ShowMessageBox(
                    "The operation cannot start because there are insufficient number of frames remaining until the end of the video.",
                    "Dark frame required",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        private static bool ProcessAAVv1File(string fileName, IVideoController videoController)
        {
            Tuple <long, string> aavNormValTag;
            int expectedMaxPixelVal;

            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                using (BinaryReader rdr = new BinaryReader(fs))
                {
                    int  magic  = rdr.ReadInt32();
                    byte aavVer = rdr.ReadByte();
                    if (magic != 0x46545346 || aavVer != 1)
                    {
                        // Not an AAVv1 File
                        return(false);
                    }

                    fs.Seek(12, SeekOrigin.Current);

                    long systemTableOffs = rdr.ReadInt64();
                    long userTableOffs   = rdr.ReadInt64();

                    fs.Seek(systemTableOffs, SeekOrigin.Begin);
                    var sysTags = ReadTagsVer1(rdr);

                    fs.Seek(userTableOffs, SeekOrigin.Begin);
                    var userTags = ReadTagsVer1(rdr);

                    if (!sysTags.ContainsKey("BITPIX") ||
                        !sysTags.ContainsKey("EFFECTIVE-FRAME-RATE") ||
                        !sysTags.ContainsKey("NATIVE-FRAME-RATE") ||
                        !sysTags.ContainsKey("AAV16-NORMVAL"))
                    {
                        return(false);
                    }

                    int bitPix = int.Parse(sysTags["BITPIX"].Item2);
                    if (bitPix == 8)
                    {
                        // This is an 8-bit file and it is not affected by a MaxPixelValue issue.
                        return(false);
                    }

                    double effectiveFrameRate = double.Parse(sysTags["EFFECTIVE-FRAME-RATE"].Item2, CultureInfo.InvariantCulture);
                    double nativeFrameRate    = double.Parse(sysTags["NATIVE-FRAME-RATE"].Item2, CultureInfo.InvariantCulture);

                    expectedMaxPixelVal = (int)Math.Round(256 * nativeFrameRate / effectiveFrameRate);

                    if (sysTags.ContainsKey("AAV16-NORMVAL"))
                    {
                        aavNormValTag = sysTags["AAV16-NORMVAL"];
                    }
                    else if (userTags.ContainsKey("AAV16-NORMVAL"))
                    {
                        aavNormValTag = userTags["AAV16-NORMVAL"];
                    }
                    else
                    {
                        return(false);
                    }

                    int maxPixelValue = int.Parse(aavNormValTag.Item2);

                    if (expectedMaxPixelVal >= maxPixelValue)
                    {
                        // The MaxPixelValue s correct for this file. Nothing to do
                        return(false);
                    }

                    if (videoController.ShowMessageBox(
                            string.Format("This AAV file appears to have an incorrect MaxPixelValue which can result in incorrectly displayed object brightness. Press 'Yes' to fix the MaxPixelValue to the correct value of {0}.", expectedMaxPixelVal),
                            "Tangra",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return(false);
                    }
                }

            string expectedStringValue = expectedMaxPixelVal.ToString();

            if (expectedStringValue.Length > aavNormValTag.Item2.Length)
            {
                videoController.ShowMessageBox(string.Format("Error changing MaxPixelValue from {0} to {1}", aavNormValTag.Item2, expectedMaxPixelVal), "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            expectedStringValue = expectedStringValue.PadLeft(aavNormValTag.Item2.Length, '0');

            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Write))
                using (BinaryWriter wrt = new BinaryWriter(fs))
                {
                    fs.Seek(aavNormValTag.Item1 + 1, SeekOrigin.Begin);
                    wrt.Write(Encoding.UTF8.GetBytes(expectedStringValue));
                }

            return(true);
        }
Beispiel #3
0
        private static bool ProcessAAVv2File(string fileName, IVideoController videoController)
        {
            Tuple <long, string> currMaxPixelValue;
            Tuple <long, string> currMaxPixelValueImgSec;
            int expectedMaxPixelVal;

            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                using (BinaryReader rdr = new BinaryReader(fs))
                {
                    int  magic  = rdr.ReadInt32();
                    byte aavVer = rdr.ReadByte();
                    if (magic != 0x46545346 || aavVer != 2)
                    {
                        // Not an AAVv2 File
                        return(false);
                    }

                    fs.Seek(12, SeekOrigin.Current);

                    long sysMetaOffs = rdr.ReadInt64();

                    long userMetaOffs = rdr.ReadInt64();

                    fs.Seek(1, SeekOrigin.Current);

                    string stream1 = ReadString(rdr);

                    fs.Seek(24, SeekOrigin.Current);

                    string stream2 = ReadString(rdr);
                    fs.Seek(24, SeekOrigin.Current);

                    rdr.ReadByte();
                    string section1   = ReadString(rdr);
                    long   imgSecOffs = rdr.ReadInt64();

                    if (stream1 != "MAIN" || stream2 != "CALIBRATION" || section1 != "IMAGE")
                    {
                        // Not a standard AAVv2 File
                        return(false);
                    }

                    fs.Seek(sysMetaOffs, SeekOrigin.Begin);
                    var sysTags = ReadTags(rdr);

                    fs.Seek(userMetaOffs, SeekOrigin.Begin);
                    var userTags = ReadTags(rdr);
                    foreach (var kvp in userTags)
                    {
                        sysTags[kvp.Key] = kvp.Value;
                    }

                    fs.Seek(imgSecOffs + 10, SeekOrigin.Begin);
                    byte numLayouts = rdr.ReadByte();
                    for (int i = 0; i < numLayouts; i++)
                    {
                        fs.Seek(3, SeekOrigin.Current);
                        int tagsCount = rdr.ReadByte();
                        ReadTags(rdr, tagsCount);
                    }
                    int imgTagsCnt = rdr.ReadByte();
                    var imgTags    = ReadTags(rdr, imgTagsCnt);

                    if (!sysTags.ContainsKey("BITPIX") ||
                        !sysTags.ContainsKey("EFFECTIVE-FRAME-RATE") ||
                        !sysTags.ContainsKey("NATIVE-FRAME-RATE") ||
                        !sysTags.ContainsKey("AAV16-NORMVAL") ||
                        !imgTags.ContainsKey("IMAGE-MAX-PIXEL-VALUE"))
                    {
                        return(false);
                    }

                    int bitPix = int.Parse(sysTags["BITPIX"].Item2);
                    if (bitPix == 8)
                    {
                        // This is an 8-bit file and it is not affected by a MaxPixelValue issue.
                        return(false);
                    }

                    double effectiveFrameRate = double.Parse(sysTags["EFFECTIVE-FRAME-RATE"].Item2, CultureInfo.InvariantCulture);
                    double nativeFrameRate    = double.Parse(sysTags["NATIVE-FRAME-RATE"].Item2, CultureInfo.InvariantCulture);

                    expectedMaxPixelVal = (int)Math.Round(256 * nativeFrameRate / effectiveFrameRate);
                    int maxPixelValue       = int.Parse(sysTags["AAV16-NORMVAL"].Item2);
                    int maxPixelValueImgSec = int.Parse(imgTags["IMAGE-MAX-PIXEL-VALUE"].Item2);

                    if (expectedMaxPixelVal == maxPixelValue && expectedMaxPixelVal == maxPixelValueImgSec)
                    {
                        // The MaxPixelValue s correct for this file. Nothing to do
                        return(false);
                    }

                    if (videoController.ShowMessageBox(
                            string.Format("This AAV file appears to have an incorrect MaxPixelValue which can result in incorrectly displayed object brightness. Press 'Yes' to fix the MaxPixelValue to the correct value of {0}.", expectedMaxPixelVal),
                            "Tangra",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return(false);
                    }

                    currMaxPixelValue       = sysTags["AAV16-NORMVAL"];
                    currMaxPixelValueImgSec = imgTags["IMAGE-MAX-PIXEL-VALUE"];
                }

            string expectedStringValue = expectedMaxPixelVal.ToString();

            if (expectedStringValue.Length > currMaxPixelValue.Item2.Length || expectedStringValue.Length > currMaxPixelValueImgSec.Item2.Length)
            {
                videoController.ShowMessageBox(string.Format("Error changing MaxPixelValue from {0}|{1} to {2}", currMaxPixelValue.Item2, currMaxPixelValueImgSec.Item2, expectedMaxPixelVal), "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            expectedStringValue = expectedStringValue.PadLeft(currMaxPixelValue.Item2.Length, '0');

            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Write))
                using (BinaryWriter wrt = new BinaryWriter(fs))
                {
                    fs.Seek(currMaxPixelValue.Item1 + 2, SeekOrigin.Begin);
                    wrt.Write(Encoding.UTF8.GetBytes(expectedStringValue));

                    fs.Seek(currMaxPixelValueImgSec.Item1 + 2, SeekOrigin.Begin);
                    wrt.Write(Encoding.UTF8.GetBytes(expectedStringValue));
                }

            return(true);
        }