Exemple #1
0
        /// <summary>
        /// Creates a new color range from memory.
        /// </summary>
        /// <param name="buffer">A <see cref="byte"/> array that contains the <see cref="ColorRange"/> data.</param>
        public ColorRange(byte[] buffer)
        {
            if (buffer.Length != SIZE)
            {
                throw new ArgumentOutOfRangeException($"The buffer must be contains a {SIZE} array length.");
            }

            using (var stream = new BinaryReader(new MemoryStream(buffer)))
            {
                this.colors       = (RangeColors)stream.ReadByte();
                this.type         = (RangeTypes)stream.ReadByte();
                this.isFixed      = stream.ReadBoolean();
                this.blackColor   = stream.ReadByte();
                this._rangeColors = stream.ReadBytes(LENGTH);
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates a new <see cref="ColorRange"/> instance with default values.
        /// </summary>
        /// <param name="startColorIndex">The start color index to setup the range.</param>
        /// <remarks>By default, when initialize the 16 ranges in a <see cref="PAL"/>,
        /// the idea is create a ramp values from 0 to 255 values and repeat until completes all 16 ranges.
        /// This process is automatically setup in <see cref="ColorRangeTable"/> default constructor.</remarks>
        public ColorRange(ref byte startColorIndex)
        {
            this.colors     = DEFAULT_RANGE_COLORS;
            this.type       = DEFAULT_TYPE;
            this.isFixed    = DEFAULT_FIXED_STATE;
            this.blackColor = DEFAULT_BLACK_COLOR;

            this._rangeColors = new byte[LENGTH];

            byte range = startColorIndex;

            for (int i = 0; i < LENGTH; i++)
            {
                this._rangeColors[i] = range;
                if (++range > byte.MaxValue)
                {
                    range = 0;
                }
            }

            startColorIndex = range;
        }