コード例 #1
0
        public LinePair GetLinePair(byte[] buffer)
        {
            //176*144
            //88 * 72 packet with 2 lines in each
            if (buffer.Length != BytesPerPacket)
            {
                throw new ApplicationException("Bad byte count");
            }
            if (buffer[0] != 0x0B)
            {
                throw new ApplicationException("Bad start byte");
            }
            if (buffer[BytesPerPacket - 1] != 0x0F)
            {
                throw new ApplicationException("Bad end byte");
            }
            int line = buffer[1];

            if (line < 0 || line > 144)
            {
                throw new ApplicationException(string.Format("Bad line number {0}", line));
            }
            var pixelData = new byte[PixelsPerPacket];

            Array.Copy(buffer, 2, pixelData, 0, pixelData.Length);
            _bytesByLine.Add(line, buffer);
            int      x        = 0;
            int      y        = line * 2;
            LinePair linePair = new LinePair(y);

            //update the 2 lines now
            for (int index = 0; index < PixelsPerPacket; index++)
            {
                if (index % 2 == 0)
                {
                    Color blue = Color.FromArgb(0x0, 0x0, (pixelData[index] & 0x0F) * 16);
                    linePair.Colors[x, 1] = blue;
                    BmBayer.SetPixel(x, y + 1, blue);
                    Color green = Color.FromArgb(0x0, (pixelData[index] >> 4) * 16, 0x0);
                    linePair.Colors[x + 1, 1] = green;
                    BmBayer.SetPixel(x + 1, y + 1, green);
                }
                else
                {
                    Color green = Color.FromArgb(0x0, (pixelData[index] & 0x0F) * 16, 0x0);
                    linePair.Colors[x, 0] = green;
                    BmBayer.SetPixel(x, y, green);
                    Color red = Color.FromArgb((pixelData[index] >> 4) * 16, 0x0, 0x0);
                    linePair.Colors[x + 1, 0] = red;
                    BmBayer.SetPixel(x + 1, y, red);
                    x += 2;
                }
            }
            return(linePair);
        }
コード例 #2
0
ファイル: DumpFrameCommand.cs プロジェクト: dlech/NXTCamView
        public override void Execute()
        {
            ////DEBUG
            //_isSuccessful = true;
            //_isCompleted = true;
            //return;

            try
            {
                _request = "DF";
                SendAndReceive();
                if (_isLogging)
                {
                    Debug.WriteLine("Capture start:");
                }
                for (int count = 0; count < PacketsInDump; count++)
                {
                    var buffer    = new byte[BytesPerPacket];
                    int totalRead = 0;
                    while (totalRead < BytesPerPacket)
                    {
                        totalRead += _commsPort.Read(buffer, totalRead, BytesPerPacket - totalRead);
                    }

                    if (_isLogging)
                    {
                        Debug.WriteLine(string.Format("Pkt:{0} :{1}", count, DumpBytes(buffer)));
                    }
                    LinePair linePair = GetLinePair(buffer);
                    Worker.ReportProgress(100 * count / PacketsInDump, linePair);
                    if (Worker.CancellationPending)
                    {
                        SetAborted();
                        return;
                    }
                }
                UpdateInterpolateImage();
            }
            catch (Exception ex)
            {
                setError(ex);
            }
            finally
            {
                completeCommand();
            }
        }