Exemplo n.º 1
0
        private unsafe void UpdatePreview()
        {
            if ((bool)MPCheckBox.IsChecked)
            {
                MatrixFrame.Pixel[,] frameData = frame.GetFrame();
                try
                {
                    MatrixBitmap.Lock();

                    int stride = MatrixBitmap.BackBufferStride;
                    for (int x = 0; x < frame.Width; x++)
                    {
                        for (int y = 0; y < frame.Height; y++)
                        {
                            int pixelAddress = (int)MatrixBitmap.BackBuffer;
                            pixelAddress += (y * stride);
                            pixelAddress += (x * 4);
                            int color_data = frameData[x, y].R << 16;        // R
                            color_data            |= frameData[x, y].G << 8; // G
                            color_data            |= frameData[x, y].B << 0; // B
                            *((int *)pixelAddress) = color_data;
                        }
                    }
                    MatrixBitmap.AddDirtyRect(new Int32Rect(0, 0, frame.Width, frame.Height));
                }
                finally
                {
                    MatrixBitmap.Unlock();
                }
            }
        }
Exemplo n.º 2
0
        byte[] GetOrderedSerialFrame(MatrixFrame frame)
        {
            MatrixFrame.Pixel[,] pixelArray = frame.GetFrame();
            byte[] orderedFrame = new byte[frame.Width * frame.Height * 3];

            int index = 0;

            int startX = pixelOrder.startCorner == StartCorner.TR || pixelOrder.startCorner == StartCorner.BR ? frame.Width - 1 : 0;
            int termX  = pixelOrder.startCorner == StartCorner.TR || pixelOrder.startCorner == StartCorner.BR ? -1 : frame.Width;
            int incX   = pixelOrder.startCorner == StartCorner.TR || pixelOrder.startCorner == StartCorner.BR ? -1 : 1;

            int startY = pixelOrder.startCorner == StartCorner.BL || pixelOrder.startCorner == StartCorner.BR ? frame.Height - 1 : 0;
            int termY  = pixelOrder.startCorner == StartCorner.BL || pixelOrder.startCorner == StartCorner.BR ? -1 : frame.Height;
            int incY   = pixelOrder.startCorner == StartCorner.BL || pixelOrder.startCorner == StartCorner.BR ? -1 : 1;

            if (pixelOrder.orientation == Orientation.HZ)
            {
                for (int y = startY; y != termY; y += incY)
                {
                    for (int x = startX; x != termX; x += incX)
                    {
                        int xPos = pixelOrder.newLine == NewLine.SC || y % 2 == 0 ? x : frame.Width - 1 - x;
                        orderedFrame[index * 3]     = pixelArray[xPos, y].R;
                        orderedFrame[index * 3 + 1] = pixelArray[xPos, y].G;
                        orderedFrame[index * 3 + 2] = pixelArray[xPos, y].B;
                        index++;
                    }
                }
            }
            else
            {
                for (int x = startX; x != termX; x += incX)
                {
                    for (int y = startY; y != termY; y += incY)
                    {
                        int yPos = pixelOrder.newLine == NewLine.SC || x % 2 == 0 ? y : frame.Height - 1 - y;
                        orderedFrame[index * 3]     = pixelArray[x, yPos].R;
                        orderedFrame[index * 3 + 1] = pixelArray[x, yPos].G;
                        orderedFrame[index * 3 + 2] = pixelArray[x, yPos].B;
                        index++;
                    }
                }
            }
            return(orderedFrame);
        }