// -------------------------------------------------------------- #region LOCAL FUNCTIONS // -------------------------------------------------------------- /// <summary> /// Read the animation file /// </summary> /// <param name="memoryStream">Data stream of the file</param> /// <param name="loadImages">Do we have to load the images now? (default: false)</param> private void ReadFile(Stream memoryStream, bool loadImages = false) { // open the reader using (BinaryReader reader = new BinaryReader((Stream)memoryStream)) { // do we have a correct file header? if (ReadHeader(reader)) { // do we have to load all the images? if (loadImages == true) { // read the frame colors ReadColours(reader); // read the frames ReadFrames(reader); // read the pixels ReadPixels(reader); // store the action ID m_ActionID = m_Frames[0].ID; } else // data only { // move to the frames table address reader.BaseStream.Seek((long)m_FrameAddress, SeekOrigin.Begin); // we need to load the first frame to determine the action ID FrameEntry firstFrame = new FrameEntry(reader.ReadUInt16(), reader.ReadUInt16(), reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16(), (uint)((ulong)m_FrameAddress + (ulong)(16) + (ulong)reader.ReadUInt32())); // store the action ID m_ActionID = firstFrame.ID; } } // terminate the reader reader.Close(); // destroy the reader reader.Dispose(); } }
/// <summary> /// Duplicate the frame /// </summary> /// <param name="original"></param> private FrameEntry(FrameEntry original) { m_ID = original.ID; m_Frame = original.Frame; m_CenterX = original.CenterX; m_CenterY = original.CenterY; m_InitCoordsX = original.InitCoordsX; m_InitCoordsY = original.InitCoordsY; m_EndCoordsX = original.EndCoordsX; m_EndCoordsY = original.EndCoordsY; m_DataOffset = original.DataOffset; m_width = original.Width; m_height = original.Height; // copy the image only if we have it if (m_image != null) { m_image = new DirectBitmap(original.Image.Bitmap); } }