Exemplo n.º 1
0
        /// <summary>
        /// Internal function that loads an HPF image from a given data stream.
        /// </summary>
        /// <param name="stream">Data stream to read from.</param>
        /// <returns>HPF image.</returns>
        private static HPFImage LoadHPF(Stream stream)
        {
            // Create Reader from Stream
            stream.Seek(0, SeekOrigin.Begin);
            BinaryReader reader = new BinaryReader(stream);

            #region Check HPF Signature
            uint signature = reader.ReadUInt32();
            reader.BaseStream.Seek(-4, SeekOrigin.Current);

            if (signature != 0xFF02AA55)
            {
                throw new ArgumentException("Invalid file format, does not contain HPF signature bytes.");
            }
            #endregion

            // Create HPF Image
            HPFImage hpf = new HPFImage();

            // Decompress HPF
            byte[] hpfData = HPFCompression.Decompress(
                reader.ReadBytes((int)reader.BaseStream.Length));

            // Closer Reader
            reader.Close();

            #region Open Memory Stream and Reader
            MemoryStream memStream = new MemoryStream(hpfData);
            reader = new BinaryReader(memStream);
            #endregion

            // Get Header and Body Data
            hpf.headerData = reader.ReadBytes(8);
            hpf.rawData    = reader.ReadBytes(hpfData.Length - 8);
            reader.Close();

            #region Get Dimensions
            hpf.width = 28;

            if (hpf.rawData.Length % hpf.width != 0)
            {
                throw new ArgumentException("HPF file does not use the standard 28 pixel width.");
            }

            hpf.height = hpf.rawData.Length / hpf.width;
            #endregion

            return(hpf);
        }
Exemplo n.º 2
0
 public unsafe static Bitmap RenderImage(HPFImage hpf, Palette256 palette)
 {
     return(SimpleRender(hpf.Width, hpf.Height, hpf.RawData, palette, ImageType.HPF));
 }