예제 #1
0
파일: DMIFile.cs 프로젝트: AnturK/DMISharp
 /// <summary>
 /// Removes a state from a DMI File
 /// </summary>
 /// <param name="toRemove">The DMIState to remove</param>
 /// <returns>True if the state was removed, otherwise false</returns>
 public bool RemoveState(DMIState toRemove)
 {
     if (toRemove != null && toRemove.Data != null && _states.Remove(toRemove))
     {
         return(Metadata.States.Remove(toRemove.Data));
     }
     else
     {
         return(false);
     }
 }
예제 #2
0
파일: DMIFile.cs 프로젝트: AnturK/DMISharp
 /// <summary>
 /// Adds a state to a DMI File
 /// </summary>
 /// <param name="toAdd">The DMIState to add</param>
 /// <returns>True if the state was added, otherwise false</returns>
 public bool AddState(DMIState toAdd)
 {
     if (StateValidForFile(toAdd) && toAdd?.Data != null)
     {
         _states.Add(toAdd);
         Metadata.States.Add(toAdd.Data);
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #3
0
파일: DMIFile.cs 프로젝트: AnturK/DMISharp
        /// <summary>
        /// Processes DMI metadata into DMI State objects.
        /// </summary>
        /// <param name="source">The stream containing the DMI file data.</param>
        /// <returns>An enumerable collection of DMI State objects representing the states of the DMI File.</returns>
        private IEnumerable <DMIState> GetStates(Stream source)
        {
            var states = new List <DMIState>();

            using (var img = Image.Load <Rgba32>(source))
            {
                // DMI data did not include widths or heights, assume that it is then
                // perfect squares, thus we will determine the w/h programatically...
                if (Metadata.FrameWidth == -1 || Metadata.FrameHeight == -1)
                {
                    var totalFrames = Metadata.States.Sum(x => x.Frames * x.Dirs);

                    for (int rows = 1; totalFrames >= rows; rows++)
                    {
                        if (img.Width / (totalFrames / rows) == img.Height / rows)
                        {
                            Metadata.FrameHeight = img.Height / rows;
                            Metadata.FrameWidth  = img.Width / (totalFrames / rows);
                        }
                    }
                }

                if (Metadata.FrameHeight == 0 || Metadata.FrameWidth == 0)
                {
                    return(states);
                }

                int wFrames         = img.Width / Metadata.FrameWidth;
                int hFrames         = img.Height / Metadata.FrameHeight;
                int processedImages = 0;
                int currWIndex      = 0;
                int currHIndex      = 0;

                foreach (var state in Metadata.States)
                {
                    var toAdd = new DMIState(state, img, currWIndex, wFrames, currHIndex, hFrames, Metadata.FrameWidth, Metadata.FrameHeight);
                    processedImages += toAdd.TotalFrames;
                    currHIndex       = processedImages / wFrames;
                    currWIndex       = processedImages % wFrames;
                    states.Add(toAdd);
                }
            }

            return(states);
        }
예제 #4
0
파일: DMIFile.cs 프로젝트: AnturK/DMISharp
 /// <summary>
 /// Ensures that a state is valid for a DMI File's existing dimensions
 /// </summary>
 /// <param name="toCheck">The DMIState to check against the file</param>
 /// <returns>True if the state is compatable with the file, false otherwise</returns>
 private bool StateValidForFile(DMIState toCheck)
 {
     return(toCheck != null &&
            toCheck.Height == Metadata.FrameHeight &&
            toCheck.Width == Metadata.FrameWidth);
 }