Exemple #1
0
        internal void SearchFramesByMagicPhase2(OnSearchProgressDelegate progressCallback)
        {
            m_Index = new AdvFramesIndex();

            int  percentCompleted;
            int  lastPercentCompleted = -1;
            int  framesRecovered      = 0;
            long startTimeTicks       = -1;

            m_CandidateFrameOffsets.Add(new RecoveredFrameHeader()
            {
                Position = m_FileReader.BaseStream.Length
            });

            ushort[,] prevFramePixels = null;

            for (int i = 0; i < m_CandidateFrameOffsets.Count - 1; i++)
            {
                RecoveredFrameHeader frameInfo1 = m_CandidateFrameOffsets[i];
                RecoveredFrameHeader frameInfo2 = m_CandidateFrameOffsets[i + 1];

                if (startTimeTicks == -1)
                {
                    startTimeTicks = frameInfo1.StartExposureUT.Ticks;
                }

                m_Index.Index.Add(new AdvFramesIndexEntry()
                {
                    ElapsedTime = new TimeSpan(frameInfo1.StartExposureUT.Ticks - startTimeTicks),
                    Offset      = frameInfo1.Position,
                    Length      = (uint)(frameInfo2.Position - frameInfo1.Position)
                });

                try
                {
                    object[]      data        = GetFrameSectionData(framesRecovered, prevFramePixels);
                    AdvImageData  imageData   = (AdvImageData)data[0];
                    AdvStatusData statusData  = (AdvStatusData)data[1];
                    int           frameWidth  = imageData.ImageData.GetLength(0);
                    int           frameHeight = imageData.ImageData.GetLength(1);
                    Trace.WriteLine(string.Format("Recovered frame #{0} with LayoutId {1} and {2} status tags. Dimentions: {3}x{4} pixels", framesRecovered, imageData.LayoutId, statusData.TagValues.Count, frameWidth, frameHeight));

                    // NOTE: Doesn't have to be right, just need something so we read the pixels
                    prevFramePixels = imageData.ImageData;

                    framesRecovered++;
                }
                catch (Exception)
                {
                    m_Index.Index.RemoveAt(m_Index.Index.Count - 1);
                }

                percentCompleted = (int)(100.0 * i / (m_CandidateFrameOffsets.Count - 1));
                if (lastPercentCompleted < percentCompleted)
                {
                    progressCallback(percentCompleted, framesRecovered);
                    lastPercentCompleted = percentCompleted;
                }
            }
        }
Exemple #2
0
        internal void ExportStatusSectionToCSV(string fileName, int firstFrame, int lastFrame, OnSearchProgressDelegate progressCallback)
        {
            progressCallback(5, 0);

            //string folder = Path.GetDirectoryName(fileName);

            bool headerAppended = false;

            using (FileStream fsOutput = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
                using (TextWriter writer = new StreamWriter(fsOutput))
                {
                    for (int i = firstFrame; i <= lastFrame; i++)
                    {
                        object[]      data       = GetFrameSectionData(i, null);
                        AdvImageData  imageData  = (AdvImageData)data[0];
                        AdvStatusData statusData = (AdvStatusData)data[1];

                        //using(FileStream fs = new FileStream(string.Format("{0}\\{1}.pix", folder, i), FileMode.CreateNew, FileAccess.Write))
                        //using (BinaryWriter wrt = new BinaryWriter(fs))
                        //{
                        //	for (int y = 0; y < ImageSection.Height; y++)
                        //	{
                        //		for (int x = 0; x < ImageSection.Width; x++)
                        //		{
                        //			ushort val = imageData.ImageData[x, y];
                        //			wrt.Write(val);
                        //		}
                        //	}
                        //}

                        string headerRow;
                        string nextRow = StatusDataToCsvRow(imageData, statusData, i, out headerRow);
                        if (!headerAppended)
                        {
                            writer.WriteLine(headerRow);
                            headerAppended = true;
                        }
                        writer.WriteLine(nextRow);

                        int percDone = (int)Math.Min(90, 90 * (i - firstFrame) * 1.0 / (lastFrame - firstFrame + 1));
                        progressCallback(5 + percDone, 0);
                    }

                    progressCallback(95, 0);

                    writer.Flush();
                }
        }
Exemple #3
0
        public Pixelmap CreatePixelmap(AdvImageData imageData)
        {
            uint[] pixels             = new uint[Width * Height];
            byte[] displayBitmapBytes = new byte[Width * Height];
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    pixels[x + y * Width] = imageData.ImageData[x, y];
                    if (BitsPerPixel == 8)
                    {
                        displayBitmapBytes[x + y * Width] = (byte)((imageData.ImageData[x, y] & 0xFF));
                    }
                    else if (BitsPerPixel == 12)
                    {
                        displayBitmapBytes[x + y * Width] = (byte)((imageData.ImageData[x, y] >> 4));
                    }
                    else if (BitsPerPixel == 14)
                    {
                        displayBitmapBytes[x + y * Width] = (byte)((imageData.ImageData[x, y] >> 6));
                    }
                    else if (BitsPerPixel == 16)
                    {
                        if (Adv16NormalisationValue.HasValue)
                        {
                            displayBitmapBytes[x + y * Width] = (byte)((255.0 * imageData.ImageData[x, y] / Adv16NormalisationValue.Value));
                        }
                        else
                        {
                            displayBitmapBytes[x + y * Width] = (byte)((imageData.ImageData[x, y] >> 8));
                        }
                    }
                    else
                    {
                        displayBitmapBytes[x + y * Width] = (byte)((imageData.ImageData[x, y] >> (BitsPerPixel - 8)));
                    }
                }
            }

            Bitmap displayBitmap = Pixelmap.ConstructBitmapFromBitmapPixels(displayBitmapBytes, (int)Width, (int)Height);

            Pixelmap rv = new Pixelmap((int)Width, (int)Height, BitsPerPixel, pixels, displayBitmap, displayBitmapBytes);

            return(rv);
        }
Exemple #4
0
        public object GetDataFromDataBytes(byte[] bytes, ushort[,] prevImageData, int size, int startIndex)
        {
            byte layoutId = bytes[startIndex];
            byte byteMode = bytes[startIndex + 1];

            startIndex += 2;
            size       -= 2;

            AdvImageLayout imageLayout = ImageLayouts[layoutId];

            AdvImageData rv = imageLayout.IsNoImageLayout
                                        ? new AdvImageData()
            {
                Bpp = 8, ImageData = new ushort[imageLayout.Width, imageLayout.Height], LayoutId = layoutId, ByteMode = AdvImageLayout.GetByteMode.Normal
            }
                                    : (AdvImageData)imageLayout.GetDataFromDataBytes(bytes, prevImageData, (AdvImageLayout.GetByteMode)byteMode, size, startIndex);

            rv.LayoutId             = layoutId;
            rv.ByteMode             = (AdvImageLayout.GetByteMode)byteMode;
            rv.DataBlocksBytesCount = size;

            return(rv);
        }
Exemple #5
0
        private string StatusDataToCsvRow(AdvImageData imageData, AdvStatusData statusData, int frameNo, out string headerRow)
        {
            var output = new StringBuilder();
            output.AppendFormat("\"{0}\"", frameNo);
            output.AppendFormat(",\"{0}\"", imageData.MidExposureUtc.AddMilliseconds( - 1 * imageData.ExposureMilliseconds / 2.0).ToString("dd-MMM-yyyy HH:mm:ss.fff"));
            output.AppendFormat(",\"{0}\"", imageData.MidExposureUtc.AddMilliseconds(imageData.ExposureMilliseconds / 2.0).ToString("dd-MMM-yyyy HH:mm:ss.fff"));

            var header = new StringBuilder();
            header.Append("FrameNo,OCRStartTimestamp,OCREndTimestamp");

            foreach (AdvTagDefinition statusTag in statusData.TagValues.Keys)
            {
                string tagValue = statusData.TagValues[statusTag];
                if ((statusTag.Name == "SystemTime" || statusTag.Name == "NTPStartTimestamp" || statusTag.Name == "NTPEndTimestamp" || statusTag.Name == "StartTimestampSecondary" || statusTag.Name == "EndTimestampSecondary") &&
                    !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = AdvFile.ADV_ZERO_DATE_REF.AddMilliseconds(long.Parse(tagValue)).ToString("dd-MMM-yyyy HH:mm:ss.fff");
                }
                else if (statusTag.Name == "GPSTrackedSatellites" && !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = int.Parse(tagValue).ToString();
                }
                else if (statusTag.Name == "Gamma" && !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = string.Format("{0:0.000}", float.Parse(tagValue));
                }
                else if (statusTag.Name == "Gain" && !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = string.Format("{0:0} dB", float.Parse(tagValue));
                }
                else if (statusTag.Name == "Shutter" && !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = string.Format("{0:0.000} sec", float.Parse(tagValue));
                }
                else if (statusTag.Name == "Offset" && !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = string.Format("{0:0.00} %", float.Parse(tagValue));
                }
                else if ((statusTag.Name == "VideoCameraFrameId" || statusTag.Name == "HardwareTimerFrameId") &&
                         !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = int.Parse(tagValue).ToString("#,###,###,###,###");
                }
                else if (statusTag.Name == "GPSAlmanacStatus" && !string.IsNullOrEmpty(tagValue))
                {
                    int almanacStatus = int.Parse(tagValue);
                    tagValue = AdvStatusValuesHelper.TranslateGpsAlmanacStatus(almanacStatus);
                }
                else if (statusTag.Name == "GPSAlmanacOffset" && !string.IsNullOrEmpty(tagValue))
                {
                    int almanacOffset = int.Parse(tagValue);
                    if ((almanacOffset & 0x80) == 0x80)
                        almanacOffset = (short) (almanacOffset + (0xFF << 8));

                    tagValue = AdvStatusValuesHelper.TranslateGpsAlmanacOffset(1, almanacOffset, false);
                }
                else if (statusTag.Name == "GPSFixStatus" && !string.IsNullOrEmpty(tagValue))
                {
                    int fixStatus = int.Parse(tagValue);
                    tagValue = AdvStatusValuesHelper.TranslateGpsFixStatus(fixStatus);
                }

                if (!string.IsNullOrEmpty(tagValue) && (statusTag.Name == "UserCommand" || statusTag.Name == "SystemError" || statusTag.Name == "GPSFix"))
                {
                    string[] tokens = tagValue.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    tagValue = string.Empty;
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        tagValue += string.Format("{0}[{1}];", statusTag.Name, i + 1);
                    }
                }

                if (tagValue == null) tagValue = string.Empty;

                output.AppendFormat(",\"{0}\"", tagValue.Replace("\"", "\"\""));
                header.AppendFormat(",{0}", statusTag.Name);
            }

            headerRow = header.ToString();
            return output.ToString();
        }
Exemple #6
0
        internal Pixelmap GetFrameData(int index, out AdvImageData imageData, out AdvStatusData statusData, out Bitmap displayBitmap)
        {
            imageData = null;

            if (index < NumberOfFrames)
            {
                byte layoutId;
                AdvImageLayout.GetByteMode byteMode;

                GetFrameImageSectionHeader(index, out layoutId, out byteMode);

                AdvImageLayout layout = ImageSection.GetImageLayoutFromLayoutId(layoutId);

                if (layout.IsDiffCorrLayout && byteMode == AdvImageLayout.GetByteMode.DiffCorrBytes && prevFrameNo != index - 1)
                {
                    // Move back and find the nearest previous key frame
                    int keyFrameIdx = index;
                    do
                    {
                        keyFrameIdx--;
                        GetFrameImageSectionHeader(keyFrameIdx, out layoutId, out byteMode);
                    }
                    while (keyFrameIdx > 0 && byteMode != AdvImageLayout.GetByteMode.KeyFrameBytes);

                    object[] keyFrameData = GetFrameSectionData(keyFrameIdx, null);
                    prevFramePixels = ((AdvImageData)keyFrameData[0]).ImageData;

                    if (layout.DiffCorrFrame == DiffCorrFrameMode.PrevFrame)
                    {
                        for (int i = keyFrameIdx + 1; i < index; i++)
                        {
                            object[] frameData = GetFrameSectionData(i, prevFramePixels);

                            prevFramePixels = ((AdvImageData)frameData[0]).ImageData;
                        }
                    }
                }

                object[] data;

                data = GetFrameSectionData(index, prevFramePixels);

                imageData = (AdvImageData)data[0];
                statusData = (AdvStatusData)data[1];

                if (prevFramePixels == null)
                    prevFramePixels = new ushort[ImageSection.Width, ImageSection.Height];

                if (layout.IsDiffCorrLayout)
                {
                    for (int x = 0; x < ImageSection.Width; x++)
                        for (int y = 0; y < ImageSection.Height; y++)
                        {
                            prevFramePixels[x, y] = imageData.ImageData[x, y];
                        }
                }

                prevFrameNo = index;

                Pixelmap rv = ImageSection.CreatePixelmap(imageData);

                //Pixelmap rv = new Pixelmap((int)m_AdvFile.ImageSection.Width, (int)m_AdvFile.ImageSection.Height, m_AdvFile.ImageSection.BitsPerPixel, null, null, null);
                //rv.Width = (int) m_AdvFile.ImageSection.Width;
                //rv.Height = (int) m_AdvFile.ImageSection.Height;
                //rv.BitPixCamera = m_AdvFile.ImageSection.BitsPerPixel;
                //rv.Array = new uint[Width * Height];
                //rv.CopyPixelsFrom(imageData.ImageData, imageData.Bpp);
                //displayBitmap = PixelmapFactory.ConstructBitmapFrom12BitPixelmap(rv);

                displayBitmap = rv.DisplayBitmap;

                return rv;
            }
            else
            {
                displayBitmap = null;
                statusData = null;
                return null;
            }
        }
Exemple #7
0
        internal bool FixAavFile18Aug(string fileName, int firstFrame, int lastFrame)
        {
            fileName = m_FileName;
            string newFile = Path.ChangeExtension(fileName, ".new.aav");

            File.Copy(fileName, newFile, true);

            using (FileStream fsr = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                using (BinaryReader reader = new BinaryReader(fsr))
                    using (FileStream fs = new FileStream(newFile, FileMode.Open, FileAccess.Write))
                        using (BinaryWriter writer = new BinaryWriter(fs))
                        {
                            uint numFrames = m_Index.NumberOfFrames;

                            long ZEROTICKS = (new DateTime(2013, 8, 18).Ticks - ADV_ZERO_DATE_REF.Ticks) / 10000;

                            for (int i = 0; i < numFrames; i++)
                            {
                                AdvFramesIndexEntry entry = m_Index.Index[i];

                                uint elapsedMiliseconds = (uint)entry.ElapsedTime.TotalMilliseconds;
                                long offset             = entry.Offset;
                                uint length             = entry.Length;

                                object[]      data       = GetFrameSectionData(i, null);
                                AdvImageData  imageData  = (AdvImageData)data[0];
                                AdvStatusData statusData = (AdvStatusData)data[1];

                                AdvTagDefinition startTS = StatusSection.TagDefinitions[3];
                                AdvTagDefinition endTS   = StatusSection.TagDefinitions[4];
                                AdvTagDefinition gpsFix  = StatusSection.TagDefinitions[7];

                                string startTSString = statusData.TagValues[startTS];
                                string endTSString   = statusData.TagValues[endTS];
                                string gpsFixString  = statusData.TagValues[gpsFix];

                                long ticksStart = FixOSD(ref startTSString, true);
                                long ticksEnd   = FixOSD(ref endTSString, false);

                                long midTicks     = ZEROTICKS + (ticksStart - 20 * 10000 + ticksEnd) / 20000;
                                long exposureMs10 = new TimeSpan(ticksEnd - ticksStart + 20 * 10000).Milliseconds * 10;

                                fsr.Seek(12 + (4 + entry.Offset), SeekOrigin.Begin);
                                int bytesToSkip = reader.ReadInt32();

                                WriteInt16((short)exposureMs10, 8 + (4 + entry.Offset), writer, reader);
                                WriteInt64(midTicks, (4 + entry.Offset), writer, reader);

                                WriteString(startTSString, 16 + (4 + entry.Offset) + bytesToSkip + 0x22, writer, reader);
                                WriteString(endTSString, 16 + (4 + entry.Offset) + bytesToSkip + 0x43, writer, reader);

                                int gspFixByte = int.Parse(gpsFixString);
                                if (gspFixByte >= 1)
                                {
                                    gspFixByte++;
                                }

                                WriteInt8((byte)gspFixByte, 16 + (4 + entry.Offset) + bytesToSkip + 0x1f, writer, reader);
                                //writer.Write(elapsedMiliseconds);
                                //writer.Write(offset);
                                //writer.Write(length);
                            }

                            fs.Flush();
                        }

            return(false);
        }
Exemple #8
0
        private string StatusDataToCsvRow(AdvImageData imageData, AdvStatusData statusData, int frameNo, out string headerRow)
        {
            var output = new StringBuilder();

            output.AppendFormat("\"{0}\"", frameNo);
            output.AppendFormat(",\"{0}\"", imageData.MidExposureUtc.AddMilliseconds(-1 * imageData.ExposureMilliseconds / 2.0).ToString("dd-MMM-yyyy HH:mm:ss.fff"));
            output.AppendFormat(",\"{0}\"", imageData.MidExposureUtc.AddMilliseconds(imageData.ExposureMilliseconds / 2.0).ToString("dd-MMM-yyyy HH:mm:ss.fff"));

            var header = new StringBuilder();

            header.Append("FrameNo,OCRStartTimestamp,OCREndTimestamp");

            foreach (AdvTagDefinition statusTag in statusData.TagValues.Keys)
            {
                string tagValue = statusData.TagValues[statusTag];
                if ((statusTag.Name == "SystemTime" || statusTag.Name == "NTPStartTimestamp" || statusTag.Name == "NTPEndTimestamp" || statusTag.Name == "StartTimestampSecondary" || statusTag.Name == "EndTimestampSecondary") &&
                    !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = AdvFile.ADV_ZERO_DATE_REF.AddMilliseconds(long.Parse(tagValue)).ToString("dd-MMM-yyyy HH:mm:ss.fff");
                }
                else if (statusTag.Name == "GPSTrackedSatellites" && !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = int.Parse(tagValue).ToString();
                }
                else if (statusTag.Name == "Gamma" && !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = string.Format("{0:0.000}", float.Parse(tagValue));
                }
                else if (statusTag.Name == "Gain" && !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = string.Format("{0:0} dB", float.Parse(tagValue));
                }
                else if (statusTag.Name == "Shutter" && !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = string.Format("{0:0.000} sec", float.Parse(tagValue));
                }
                else if (statusTag.Name == "Offset" && !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = string.Format("{0:0.00} %", float.Parse(tagValue));
                }
                else if ((statusTag.Name == "VideoCameraFrameId" || statusTag.Name == "HardwareTimerFrameId") &&
                         !string.IsNullOrEmpty(tagValue))
                {
                    tagValue = int.Parse(tagValue).ToString("#,###,###,###,###");
                }
                else if (statusTag.Name == "GPSAlmanacStatus" && !string.IsNullOrEmpty(tagValue))
                {
                    int almanacStatus = int.Parse(tagValue);
                    tagValue = AdvStatusValuesHelper.TranslateGpsAlmanacStatus(almanacStatus);
                }
                else if (statusTag.Name == "GPSAlmanacOffset" && !string.IsNullOrEmpty(tagValue))
                {
                    int almanacOffset = int.Parse(tagValue);
                    if ((almanacOffset & 0x80) == 0x80)
                    {
                        almanacOffset = (short)(almanacOffset + (0xFF << 8));
                    }

                    tagValue = AdvStatusValuesHelper.TranslateGpsAlmanacOffset(1, almanacOffset, false);
                }
                else if (statusTag.Name == "GPSFixStatus" && !string.IsNullOrEmpty(tagValue))
                {
                    int fixStatus = int.Parse(tagValue);
                    tagValue = AdvStatusValuesHelper.TranslateGpsFixStatus(fixStatus);
                }

                if (!string.IsNullOrEmpty(tagValue) && (statusTag.Name == "UserCommand" || statusTag.Name == "SystemError" || statusTag.Name == "GPSFix"))
                {
                    string[] tokens = tagValue.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    tagValue = string.Empty;
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        tagValue += string.Format("{0}[{1}];", statusTag.Name, i + 1);
                    }
                }

                if (tagValue == null)
                {
                    tagValue = string.Empty;
                }

                output.AppendFormat(",\"{0}\"", tagValue.Replace("\"", "\"\""));
                header.AppendFormat(",{0}", statusTag.Name);
            }

            headerRow = header.ToString();
            return(output.ToString());
        }
Exemple #9
0
        internal Pixelmap GetFrameData(int index, out AdvImageData imageData, out AdvStatusData statusData, out Bitmap displayBitmap)
        {
            imageData = null;

            if (index < NumberOfFrames)
            {
                byte layoutId;
                AdvImageLayout.GetByteMode byteMode;

                GetFrameImageSectionHeader(index, out layoutId, out byteMode);

                AdvImageLayout layout = ImageSection.GetImageLayoutFromLayoutId(layoutId);

                if (layout.IsDiffCorrLayout && byteMode == AdvImageLayout.GetByteMode.DiffCorrBytes && prevFrameNo != index - 1)
                {
                    // Move back and find the nearest previous key frame
                    int keyFrameIdx = index;
                    do
                    {
                        keyFrameIdx--;
                        GetFrameImageSectionHeader(keyFrameIdx, out layoutId, out byteMode);
                    }while (keyFrameIdx > 0 && byteMode != AdvImageLayout.GetByteMode.KeyFrameBytes);

                    object[] keyFrameData = GetFrameSectionData(keyFrameIdx, null);
                    prevFramePixels = ((AdvImageData)keyFrameData[0]).ImageData;

                    if (layout.DiffCorrFrame == DiffCorrFrameMode.PrevFrame)
                    {
                        for (int i = keyFrameIdx + 1; i < index; i++)
                        {
                            object[] frameData = GetFrameSectionData(i, prevFramePixels);

                            prevFramePixels = ((AdvImageData)frameData[0]).ImageData;
                        }
                    }
                }

                object[] data;

                data = GetFrameSectionData(index, prevFramePixels);

                imageData  = (AdvImageData)data[0];
                statusData = (AdvStatusData)data[1];

                if (prevFramePixels == null)
                {
                    prevFramePixels = new ushort[ImageSection.Width, ImageSection.Height];
                }

                if (layout.IsDiffCorrLayout)
                {
                    for (int x = 0; x < ImageSection.Width; x++)
                    {
                        for (int y = 0; y < ImageSection.Height; y++)
                        {
                            prevFramePixels[x, y] = imageData.ImageData[x, y];
                        }
                    }
                }

                prevFrameNo = index;

                Pixelmap rv = ImageSection.CreatePixelmap(imageData);

                //Pixelmap rv = new Pixelmap((int)m_AdvFile.ImageSection.Width, (int)m_AdvFile.ImageSection.Height, m_AdvFile.ImageSection.BitsPerPixel, null, null, null);
                //rv.Width = (int) m_AdvFile.ImageSection.Width;
                //rv.Height = (int) m_AdvFile.ImageSection.Height;
                //rv.BitPixCamera = m_AdvFile.ImageSection.BitsPerPixel;
                //rv.Array = new uint[Width * Height];
                //rv.CopyPixelsFrom(imageData.ImageData, imageData.Bpp);
                //displayBitmap = PixelmapFactory.ConstructBitmapFrom12BitPixelmap(rv);

                displayBitmap = rv.DisplayBitmap;

                return(rv);
            }
            else
            {
                displayBitmap = null;
                statusData    = null;
                return(null);
            }
        }
Exemple #10
0
        public Pixelmap CreatePixelmap(AdvImageData imageData)
        {
            uint[] pixels = new uint[Width * Height];
            byte[] displayBitmapBytes = new byte[Width * Height];
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    pixels[x + y * Width] = imageData.ImageData[x, y];
                    if (BitsPerPixel == 8)
                        displayBitmapBytes[x + y * Width] = (byte)((imageData.ImageData[x, y] & 0xFF));
                    else if (BitsPerPixel == 12)
                        displayBitmapBytes[x + y * Width] = (byte)((imageData.ImageData[x, y] >> 4));
                    else if (BitsPerPixel == 14)
                        displayBitmapBytes[x + y * Width] = (byte)((imageData.ImageData[x, y] >> 6));
                    else if (BitsPerPixel == 16)
                    {
                        if (Adv16NormalisationValue.HasValue)
                            displayBitmapBytes[x + y * Width] = (byte)(( 255.0 * imageData.ImageData[x, y] / Adv16NormalisationValue.Value));
                        else
                            displayBitmapBytes[x + y * Width] = (byte)((imageData.ImageData[x, y] >> 8));
                    }
                    else
                        displayBitmapBytes[x + y*Width] = (byte) ((imageData.ImageData[x, y] >> (BitsPerPixel - 8)));
                }
            }

            Bitmap displayBitmap = Pixelmap.ConstructBitmapFromBitmapPixels(displayBitmapBytes, (int) Width, (int) Height);

            Pixelmap rv = new Pixelmap((int)Width, (int)Height, BitsPerPixel, pixels, displayBitmap, displayBitmapBytes);

            return rv;
        }