Exemplo n.º 1
0
        static void BuildPixels(List <Pixel> pixels, List <byte> message, PixelOrder pixelOrder)
        {
            switch (pixelOrder)
            {
            case PixelOrder.GRB:
                foreach (var pixel in pixels)
                {
                    message.Add(pixel.Green);
                    message.Add(pixel.Red);
                    message.Add(pixel.Blue);
                }

                break;

            case PixelOrder.RGB:
                foreach (var pixel in pixels)
                {
                    message.Add(pixel.Red);
                    message.Add(pixel.Green);
                    message.Add(pixel.Blue);
                }

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(pixelOrder), pixelOrder, null);
            }
        }
Exemplo n.º 2
0
        public static List <byte> Generate(List <Pixel> pixels, int channel = 0, PixelOrder pixelOrder = PixelOrder.GRB)
        {
            var message = new List <byte>();

            BuildHeader(pixels, message, channel);
            BuildPixels(pixels, message, pixelOrder);

            return(message);
        }
Exemplo n.º 3
0
 public Apa102(ISpiBus spiBus,
               PixelOrder pixelOrder = PixelOrder.BGR,
               bool autoWrite        = false,
               int width             = 1,
               int height            = 1) : this(spiBus, width *height, pixelOrder, autoWrite)
 {
     this.width  = width;
     this.height = height;
 }
Exemplo n.º 4
0
        public static Dictionary<int, PixelMap[]> GeneratePixelMapping(
            int width,
            int height,
            int startUniverse = 0,
            RgbOrder rgbOrder = RgbOrder.RGB,
            PixelOrder pixelOrder = PixelOrder.HorizontalSnakeTopLeft,
            int channelShift = 0)
        {
            int universe = startUniverse;
            int mappingPos = channelShift;

            var pixelMapping = new Dictionary<int, PixelMap[]>();

            if (pixelOrder == PixelOrder.HorizontalLineWiseTopLeft)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                        MapPixelRGB(pixelMapping, x, y, ref universe, ref mappingPos, rgbOrder, channelShift);
                }
            }
            else if (pixelOrder == PixelOrder.HorizontalSnakeTopLeft)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                        MapPixelRGB(pixelMapping, x, y, ref universe, ref mappingPos, rgbOrder, channelShift);

                    y++;

                    if (y >= height)
                        break;

                    for (int x = width - 1; x >= 0; x--)
                        MapPixelRGB(pixelMapping, x, y, ref universe, ref mappingPos, rgbOrder, channelShift);
                }
            }

            else if (pixelOrder == PixelOrder.HorizontalSnakeBottomLeft)
            {
                for (int y = height - 1; y >= 0; y--)
                {
                    for (int x = 0; x < width; x++)
                        MapPixelRGB(pixelMapping, x, y, ref universe, ref mappingPos, rgbOrder, channelShift);

                    y--;

                    if (y < 0)
                        break;

                    for (int x = width - 1; x >= 0; x--)
                        MapPixelRGB(pixelMapping, x, y, ref universe, ref mappingPos, rgbOrder, channelShift);
                }
            }

            return pixelMapping;
        }
Exemplo n.º 5
0
        public YanagisawaPicLoader(byte[] bytesImageCompressed, PixelOrder orderPixelExtracted = PixelOrder.ARGB, DirectionY directionY = DirectionY.BottomToTop)
        {
            this.bytesImageCompressed = bytesImageCompressed;
            bool result = this.parseHeader();

            this.bytesImageExtracted = new byte[this.width * this.height * 4];
//			this.bytesImageExtracted = new byte[this.width * 4];

            this.orderPixel = orderPixelExtracted;
            this.directionY = directionY;
        }
Exemplo n.º 6
0
 public RpiWs281xClient(int ledCount,
                        PixelOrder pixelOrder = PixelOrder.GRB,
                        int gpioPin           = RpiWs281xSetupInfo.DefaultGpio,
                        ILog log = null
                        )
     : this(new RpiWs281xSetupInfo(ledCount)
 {
     GpioPin = gpioPin,
     PixelOrder = pixelOrder,
 }, log)
 {
 }
Exemplo n.º 7
0
        internal RpiWs281xClient(Ws281x_t data, PixelOrder pixelOrder = PixelOrder.GRB, ILog log = null)
        {
            _data           = data;
            _defaultChannel = 0;
            _log            = log ?? NullLogger.Instance;
            _pixelOrder     = PixelOrder.GRB;

            _init = NativeMethods.ws2811_init(ref _data);
            if (_init != 0)
            {
                throw new Exception(string.Format("ws2811_init failed - returned {0}", _init));
            }
        }
Exemplo n.º 8
0
        public static bool ISPIXELFORMAT_ALPHA(uint format)
        {
            if (ISPIXELFORMAT_FOURCC(format))
            {
                return(false);
            }
            PixelOrder pOrder =
                (PixelOrder)PIXELORDER(format);

            return(
                pOrder == PixelOrder.PackedOrderARGB ||
                pOrder == PixelOrder.PackedOrderRGBA ||
                pOrder == PixelOrder.PackedOrderABGR ||
                pOrder == PixelOrder.PackedOrderBGRA
                );
        }
Exemplo n.º 9
0
 public static uint DEFINE_PIXELFORMAT(
     PixelType type,
     PixelOrder order,
     PackedLayout layout,
     byte bits,
     byte bytes
     )
 {
     return((uint)(
                (1 << 28) |
                (((byte)type) << 24) |
                (((byte)order) << 20) |
                (((byte)layout) << 16) |
                (bits << 8) |
                (bytes)
                ));
 }
Exemplo n.º 10
0
        public static Dictionary <int, PixelMap[]> GeneratePixelMapping(
            int width,
            int height,
            int startUniverse     = 0,
            RgbOrder rgbOrder     = RgbOrder.RGB,
            PixelOrder pixelOrder = PixelOrder.HorizontalSnakeTopLeft,
            int channelShift      = 0)
        {
            int universe   = startUniverse;
            int mappingPos = channelShift;

            var pixelMapping = new Dictionary <int, PixelMap[]>();

            if (pixelOrder == PixelOrder.HorizontalLineWiseTopLeft)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        MapPixelRGB(pixelMapping, x, y, ref universe, ref mappingPos, rgbOrder, channelShift);
                    }
                }
            }
            else if (pixelOrder == PixelOrder.HorizontalSnakeTopLeft)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        MapPixelRGB(pixelMapping, x, y, ref universe, ref mappingPos, rgbOrder, channelShift);
                    }

                    y++;

                    if (y >= height)
                    {
                        break;
                    }

                    for (int x = width - 1; x >= 0; x--)
                    {
                        MapPixelRGB(pixelMapping, x, y, ref universe, ref mappingPos, rgbOrder, channelShift);
                    }
                }
            }

            else if (pixelOrder == PixelOrder.HorizontalSnakeBottomLeft)
            {
                for (int y = height - 1; y >= 0; y--)
                {
                    for (int x = 0; x < width; x++)
                    {
                        MapPixelRGB(pixelMapping, x, y, ref universe, ref mappingPos, rgbOrder, channelShift);
                    }

                    y--;

                    if (y < 0)
                    {
                        break;
                    }

                    for (int x = width - 1; x >= 0; x--)
                    {
                        MapPixelRGB(pixelMapping, x, y, ref universe, ref mappingPos, rgbOrder, channelShift);
                    }
                }
            }

            return(pixelMapping);
        }
Exemplo n.º 11
0
        public ImageSection(byte[] File, int Offset)
        {
            this.Offset = Offset;


            Type              = BitConverter.ToUInt16(File, Offset);
            Unknown           = BitConverter.ToUInt16(File, Offset + 0x02);
            PartSizeDuplicate = BitConverter.ToUInt32(File, Offset + 0x04);
            PartSize          = BitConverter.ToUInt32(File, Offset + 0x08);
            Unknown2          = BitConverter.ToUInt32(File, Offset + 0x0C);

            DataOffset = BitConverter.ToUInt16(File, Offset + 0x10);
            Unknown3   = BitConverter.ToUInt16(File, Offset + 0x12);
            Format     = (ImageFormat)BitConverter.ToUInt16(File, Offset + 0x14);
            PxOrder    = (PixelOrder)BitConverter.ToUInt16(File, Offset + 0x16);
            Width      = BitConverter.ToUInt16(File, Offset + 0x18);
            Height     = BitConverter.ToUInt16(File, Offset + 0x1A);
            ColorDepth = BitConverter.ToUInt16(File, Offset + 0x1C);
            Unknown7   = BitConverter.ToUInt16(File, Offset + 0x1E);

            Unknown8  = BitConverter.ToUInt16(File, Offset + 0x20);
            Unknown9  = BitConverter.ToUInt16(File, Offset + 0x22);
            Unknown10 = BitConverter.ToUInt16(File, Offset + 0x24);
            Unknown11 = BitConverter.ToUInt16(File, Offset + 0x26);
            Unknown12 = BitConverter.ToUInt32(File, Offset + 0x28);
            Unknown13 = BitConverter.ToUInt32(File, Offset + 0x2C);

            PartSizeMinus0x10 = BitConverter.ToUInt32(File, Offset + 0x30);
            Unknown14         = BitConverter.ToUInt32(File, Offset + 0x34);
            Unknown15         = BitConverter.ToUInt16(File, Offset + 0x38);
            LayerCount        = BitConverter.ToUInt16(File, Offset + 0x3A);
            Unknown17         = BitConverter.ToUInt16(File, Offset + 0x3C);
            FrameCount        = BitConverter.ToUInt16(File, Offset + 0x3E);

            ImageCount   = Math.Max(LayerCount, FrameCount);
            ImageOffsets = new uint[ImageCount];
            for (int i = 0; i < ImageCount; ++i)
            {
                ImageOffsets[i] = BitConverter.ToUInt32(File, Offset + 0x40 + i * 0x04);
            }


            ImagesRawBytes = new byte[ImageCount][];
            for (int i = 0; i < ImageOffsets.Length; ++i)
            {
                uint poffs = ImageOffsets[i];
                uint nextpoffs;
                if (i == ImageOffsets.Length - 1)
                {
                    nextpoffs = PartSizeMinus0x10;
                }
                else
                {
                    nextpoffs = ImageOffsets[i + 1];
                }
                uint size = nextpoffs - poffs;
                ImagesRawBytes[i] = new byte[size];

                ArrayUtils.CopyByteArrayPart(File, Offset + (int)poffs + 0x10, ImagesRawBytes[i], 0, (int)size);
            }



            Images = new List <List <uint> >();
            foreach (byte[] img in ImagesRawBytes)
            {
                int         BitPerPixel     = GetBitPerPixel();
                List <uint> IndividualImage = new List <uint>();
                for (int cnt = 0; cnt < img.Length * 8; cnt += BitPerPixel)
                {
                    uint color = 0;
                    int  i     = cnt / 8;
                    switch (BitPerPixel)
                    {
                    case 4:
                        if (cnt % 8 != 0)
                        {
                            color = (img[i] & 0xF0u) >> 4;
                        }
                        else
                        {
                            color = (img[i] & 0x0Fu);
                        }
                        break;

                    case 8:
                        color = img[i];
                        break;

                    case 16:
                        color = BitConverter.ToUInt16(img, i);
                        break;

                    case 32:
                        color = BitConverter.ToUInt32(img, i);
                        break;
                    }
                    IndividualImage.Add(color);
                }
                Images.Add(IndividualImage);
            }


            return;
        }
Exemplo n.º 12
0
 public OpcClient(string server = "127.0.0.1", int port = OpcConstants.DefaultPort, PixelOrder pixelOrder = PixelOrder.GRB)
 {
     Server     = server;
     Port       = port;
     PixelOrder = pixelOrder;
 }
Exemplo n.º 13
0
 public AnimationConverter(ColorOrder colorOder, PixelOrder pixelOrder, DataType dataType)
 {
     InputFile = new BMAFormat();
     SetInputFileOptions(colorOder, pixelOrder, dataType);
 }
Exemplo n.º 14
0
        public bool Encode(string FilePath, int StartFrame, int EndFrame, ColorOrder colorOrder, PixelOrder pixelOrder, DataType dataType)
        {
            //if (Lock) return false;
            int   x, y, data_pos = 0;
            Frame frame;

            OutputFile             = new BMAFormat();
            OutputFile.colorOrder  = colorOrder;
            OutputFile.dataType    = dataType;
            OutputFile.pixelOrder  = pixelOrder;
            OutputFile.fps         = (byte)animation.Fps;
            OutputFile.FramesCount = EndFrame - StartFrame + 1;
            OutputFile.Width       = (ushort)animation.SizeX;
            OutputFile.Height      = (ushort)animation.SizeY;

            bool CT_Enable = (OutputFile.dataType == DataType.WithColorTable);

            if (CT_Enable)
            {
                if (!CreateColorTable())
                {
                    return(false);
                }
            }

            OutputFile.Data = new byte[OutputFile.FramesCount * OutputFile.Height * OutputFile.Width * 3];
            for (int frame_num = StartFrame; frame_num <= EndFrame; frame_num++)
            {
                frame = animation.frames[frame_num];
                if (frame.bitmap == null)
                {
                    FrameRender(frame);
                }
                switch (OutputFile.pixelOrder)
                {
                case PixelOrder.VS_TR:
                    for (x = animation.SizeX - 1; x >= 0; x--)
                    {
                        for (y = 0; y < animation.SizeY; y++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                        x--;
                        if (x < 0)
                        {
                            break;
                        }
                        for (y = animation.SizeY - 1; y >= 0; y--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.VS_TL:
                    for (x = 0; x < animation.SizeX; x++)
                    {
                        for (y = 0; y < animation.SizeY; y++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                        x++;
                        if (x == animation.SizeX)
                        {
                            break;
                        }
                        for (y = animation.SizeY - 1; y >= 0; y--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.VS_BR:
                    for (x = animation.SizeX - 1; x >= 0; x--)
                    {
                        for (y = animation.SizeY - 1; y >= 0; y--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                        x--;
                        if (x < 0)
                        {
                            break;
                        }
                        for (y = 0; y < animation.SizeY; y++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.VS_BL:
                    for (x = 0; x < animation.SizeX; x++)
                    {
                        for (y = animation.SizeY - 1; y >= 0; y--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                        x++;
                        if (x == animation.SizeX)
                        {
                            break;
                        }
                        for (y = 0; y < animation.SizeY; y++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.HS_TL:
                    for (y = 0; y < animation.SizeY; y++)
                    {
                        for (x = 0; x < animation.SizeX; x++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                        y++;
                        if (y == animation.SizeY)
                        {
                            break;
                        }
                        for (x = animation.SizeX - 1; x >= 0; x--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.HS_TR:
                    for (y = 0; y < animation.SizeY; y++)
                    {
                        for (x = animation.SizeX - 1; x >= 0; x--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                        y++;
                        if (y == animation.SizeY)
                        {
                            break;
                        }
                        for (x = 0; x < animation.SizeX; x++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.HS_BL:
                    for (y = animation.SizeY - 1; y >= 0; y--)
                    {
                        for (x = 0; x < animation.SizeX; x++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                        y--;
                        if (y < 0)
                        {
                            break;
                        }
                        for (x = animation.SizeX - 1; x >= 0; x--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.HS_BR:
                    for (y = animation.SizeY - 1; y >= 0; y--)
                    {
                        for (x = animation.SizeX - 1; x >= 0; x--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                        y--;
                        if (y < 0)
                        {
                            break;
                        }
                        for (x = 0; x < animation.SizeX; x++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.HL_TL:
                    for (y = 0; y < animation.SizeY; y++)
                    {
                        for (x = 0; x < animation.SizeX; x++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.HL_TR:
                    for (y = 0; y < animation.SizeY; y++)
                    {
                        for (x = animation.SizeX - 1; x >= 0; x--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.HL_BL:
                    for (y = animation.SizeY - 1; y >= 0; y--)
                    {
                        for (x = 0; x < animation.SizeX; x++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.HL_BR:
                    for (y = animation.SizeY - 1; y >= 0; y--)
                    {
                        for (x = animation.SizeX - 1; x >= 0; x--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.VL_TR:
                    for (x = animation.SizeX - 1; x >= 0; x--)
                    {
                        for (y = 0; y < animation.SizeY; y++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.VL_TL:
                    for (x = 0; x < animation.SizeX; x++)
                    {
                        for (y = 0; y < animation.SizeY; y++)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.VL_BR:
                    for (x = animation.SizeX - 1; x >= 0; x--)
                    {
                        for (y = animation.SizeY - 1; y >= 0; y--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                case PixelOrder.VL_BL:
                    for (x = 0; x < animation.SizeX; x++)
                    {
                        for (y = animation.SizeY - 1; y >= 0; y--)
                        {
                            WriteDataToOutput(x, y, frame.bitmap.GetPixel(x, y), CT_Enable, ref data_pos);
                        }
                    }
                    break;

                default: break;
                }
            }


            //*****************Save Animation to file*******************
            FileInfo f_info = new FileInfo(FilePath);

            switch (f_info.Extension)
            {
            case ".bma":
                using (BinaryWriter writer = new BinaryWriter(File.Open(FilePath, FileMode.OpenOrCreate)))
                {
                    writer.Flush();
                    writer.Seek(0, SeekOrigin.Begin);
                    writer.Write('b');
                    writer.Write('m');
                    writer.Write('a');
                    writer.Write((byte)OutputFile.version);
                    writer.Write((byte)OutputFile.pixelOrder);
                    writer.Write((byte)OutputFile.colorOrder);
                    writer.Write((byte)OutputFile.dataType);
                    writer.Write(OutputFile.FramesCount);
                    writer.Write(OutputFile.fps);
                    writer.Write(OutputFile.Width);
                    writer.Write(OutputFile.Height);
                    if (OutputFile.dataType == DataType.Default)
                    {
                        writer.Write(OutputFile.Data, 0, (int)(OutputFile.FramesCount * OutputFile.Width * OutputFile.Height * 3));
                    }
                    else if (OutputFile.dataType == DataType.WithColorTable)
                    {
                        writer.Write((ushort)(OutputFile.ColorTableSize * 3));
                        for (int ct_pos = 0; ct_pos < OutputFile.ColorTableSize; ct_pos++)
                        {
                            writer.Write(OutputFile.ColorTable[ct_pos, 0]);
                            writer.Write(OutputFile.ColorTable[ct_pos, 1]);
                            writer.Write(OutputFile.ColorTable[ct_pos, 2]);
                        }
                        writer.Write(OutputFile.Data, 0, (int)(OutputFile.FramesCount * OutputFile.Width * OutputFile.Height));
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(true);

            default: return(false);
            }
        }
Exemplo n.º 15
0
 public void SetInputFileOptions(ColorOrder colorOder, PixelOrder pixelOrder, DataType dataType)
 {
     InputFile.colorOrder = colorOder;
     InputFile.pixelOrder = pixelOrder;
     InputFile.dataType   = dataType;
 }