Exemplo n.º 1
0
        /// <summary>
        /// Reads the specified number of BGR555 colors from the stream and advances the position by twice that many bytes.
        /// </summary>
        /// <param name="colors">The number of expected colors in the palette.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException">colors was not 16 or 256.</exception>
        public Palette ReadPalette(int colors = 16)
        {
            var pal = new Palette(new GbaColor(), colors);

            for (int i = 0; i < colors; i++)
            {
                pal[i] = new GbaColor(ReadColor());
            }
            return(pal);
        }
Exemplo n.º 2
0
        public void WriteCompressedPalette(Palette palette)
        {
            // buffer to hold uncompressed color data
            byte[] buffer = new byte[palette.Length * 2];

            // copy colors to buffer
            for (int i = 0; i < palette.Length; i++)
            {
                GbaColor color = palette[i];
                ushort   u     = (ushort)((color.RgbColor.R / 8) | (color.RgbColor.G / 8 << 5) | (color.RgbColor.B / 3 << 10));

                buffer[i * 2]     = (byte)u;
                buffer[i * 2 + 1] = (byte)(u >> 8);
            }

            // write compressed bytes
            WriteCompressedBytes(buffer);
        }