Example #1
0
 public static EPFImage FromArchive(string file, bool ignoreCase, DATArchive archive)
 {
     if (!archive.Contains(file, ignoreCase))
     {
         return((EPFImage)null);
     }
     return(EPFImage.FromRawData(archive.ExtractFile(file, ignoreCase), file));
 }
Example #2
0
        private static EPFImage LoadEPF(Stream stream, string name)
        {
            stream.Seek(0L, SeekOrigin.Begin);
            BinaryReader binaryReader = new BinaryReader(stream);
            EPFImage     epfImage     = new EPFImage();

            if (name != null || name != string.Empty)
            {
                epfImage.Name = Path.GetFileName(name).ToLower();
            }
            epfImage.ExpectedFrames = (int)binaryReader.ReadUInt16();
            epfImage.Width          = (int)binaryReader.ReadUInt16();
            epfImage.Height         = (int)binaryReader.ReadUInt16();
            epfImage.Unknown        = (int)binaryReader.ReadUInt16();
            epfImage.TOCAddress     = (long)(binaryReader.ReadUInt32() + 12U);
            if (epfImage.ExpectedFrames <= 0)
            {
                return((EPFImage)null);
            }
            epfImage.Frames = new EPFFrame[epfImage.ExpectedFrames];
            for (int index = 0; index < epfImage.ExpectedFrames; ++index)
            {
                binaryReader.BaseStream.Seek(epfImage.TOCAddress + (long)(index * 16), SeekOrigin.Begin);
                int  top    = (int)binaryReader.ReadUInt16();
                int  left   = (int)binaryReader.ReadUInt16();
                int  num1   = (int)binaryReader.ReadUInt16();
                int  width  = (int)binaryReader.ReadUInt16() - left;
                int  height = num1 - top;
                uint num2   = binaryReader.ReadUInt32() + 12U;
                uint num3   = binaryReader.ReadUInt32() + 12U;
                binaryReader.BaseStream.Seek((long)num2, SeekOrigin.Begin);
                byte[] rawData = (long)(num3 - num2) == (long)(width * height) ? binaryReader.ReadBytes((int)num3 - (int)num2) : binaryReader.ReadBytes((int)(epfImage.TOCAddress - (long)num2));
                epfImage.Frames[index] = new EPFFrame(left, top, width, height, rawData);
            }
            return(epfImage);
        }
Example #3
0
        /// <summary>
        /// Internal function that loads an EPF image from a given data stream.
        /// </summary>
        /// <param name="stream">Data stream.</param>
        /// <returns></returns>
        private static EPFImage LoadEPF(Stream stream)
        {
            // Create Binary Reader
            stream.Seek(0, SeekOrigin.Begin);
            BinaryReader reader = new BinaryReader(stream);

            // Create EPF Image
            EPFImage epf = new EPFImage();

            #region Get Header Values
            epf.expectedFrames = reader.ReadUInt16();
            epf.width          = reader.ReadUInt16();
            epf.height         = reader.ReadUInt16();
            epf.unknown        = reader.ReadUInt16();
            epf.tocAddress     = reader.ReadUInt32() + 0x0C;
            #endregion

            // Create Frames
            if (epf.expectedFrames > 0)
            {
                epf.frames = new EPFFrame[epf.expectedFrames];
            }
            else
            {
                return(epf);
            }

            #region Get Each Frame
            for (int i = 0; i < epf.expectedFrames; i++)
            {
                // Seek to Table of Contents
                reader.BaseStream.Seek(epf.tocAddress + i * 16, SeekOrigin.Begin);

                #region Get Frame Header
                int left   = reader.ReadUInt16();
                int top    = reader.ReadUInt16();
                int right  = reader.ReadUInt16();
                int bottom = reader.ReadUInt16();

                int width  = right - left;
                int height = bottom - top;

                uint startAddress = reader.ReadUInt32() + 0x0C;
                uint endAddress   = reader.ReadUInt32() + 0x0C;
                #endregion

                #region Get Frame Data
                // Seek to Address
                reader.BaseStream.Seek(startAddress, SeekOrigin.Begin);

                byte[] frameBytes = null;
                if ((endAddress - startAddress) != (width * height))
                {
                    // Get Whole File as Single Frame
                    frameBytes = reader.ReadBytes((int)(epf.tocAddress - startAddress));
                }
                else
                {
                    // Get Frame Data
                    frameBytes = reader.ReadBytes((int)(endAddress - startAddress));
                }
                #endregion

                // Create Frame
                epf.frames[i] = new EPFFrame(left, top, width, height, frameBytes);
            }
            #endregion

            // Return EPF
            return(epf);
        }
Example #4
0
 public static EPFImage FromRawData(byte[] data, string name)
 {
     return(EPFImage.LoadEPF((Stream) new MemoryStream(data), name));
 }
Example #5
0
 public static EPFImage FromFile(string file)
 {
     return(EPFImage.LoadEPF((Stream) new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read), file));
 }