Ejemplo n.º 1
0
        /// <summary>
        ///     Creates an array of raw bytes, including the necessary header.
        ///     The first 5 bytes of the byte array is the header. (Width, Height, LayerCount)
        /// </summary>
        /// <param name="bitpix"></param>
        /// <returns></returns>
        public static byte[] ToEncodedBytes(BitPix bitpix)
        {
            var resultIndex = 0;
            var w           = BitPixUtilities.ToBytes((short)bitpix.Width);
            var h           = BitPixUtilities.ToBytes((short)bitpix.Height);
            var l           = (byte)bitpix.Layers.GetLength(0);

            var result = new byte[2 + 2 + 1 + bitpix.GetTotalByteCount()]; //  w + h + l + img

            result[resultIndex++] = w[0];
            result[resultIndex++] = w[1];
            result[resultIndex++] = h[0];
            result[resultIndex++] = h[1];
            result[resultIndex++] = l;

            var layerCount = bitpix.Layers.GetLength(0);

            for (var i = 0; i < layerCount; i++)
            {
                var layerContentSize = bitpix.Layers[i].Length;
                for (var j = 0; j < layerContentSize; j++)
                {
                    result[resultIndex++] = bitpix.Layers[i][j];
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public void SetColorBitAt(int x, int y, bool value, int layer)
        {
            var l    = Layers[layer];
            var idx  = GetBitIndex(x, y);
            var bits = BitPixUtilities.ToBits(l);

            bits[idx] = (byte)(value ? 1 : 0);

            Layers[layer] = BitPixUtilities.ToBytes(bits);
        }
Ejemplo n.º 3
0
        private static byte[][] LayerFromLongs(params long[] layers)
        {
            if (layers == null || layers.Length == 0)
            {
                throw new ArgumentException("`layers` cannot be empty. At least 1 layer is required.");
            }
            var result = new byte[layers.Length][];

            for (var i = 0; i < layers.Length; i++)
            {
                result[i] = BitPixUtilities.ToBytes(layers[i]);
            }
            return(result);
        }