Exemple #1
0
 /// <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);
     }
 }
Exemple #2
0
 /// <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);
     }
 }
Exemple #3
0
        /// <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);
        }
Exemple #4
0
 /// <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);
 }