示例#1
0
        /// <summary>
        /// Add embEntry if new. If a similar one already exists then that will be returned.
        /// </summary>
        /// <returns></returns>
        public EmbEntry Add(EmbEntry embEntry, List <IUndoRedo> undos = null)
        {
            foreach (var entry in Entry)
            {
                if (entry == embEntry)
                {
                    return(entry);
                }

                if (entry.Compare(embEntry))
                {
                    return(entry);
                }
            }

            //Check entry size
            if (Entry.Count >= MAX_EFFECT_TEXTURES)
            {
                throw new Exception(String.Format("EMB_File.Add: Texture limit has been reached. Cannot add any more."));
            }

            if (undos != null)
            {
                undos.Add(new UndoableListAdd <EmbEntry>(Entry, embEntry));
            }

            Entry.Add(embEntry);

            return(embEntry);
        }
示例#2
0
        public void RemoveEntry(string _idx, EmbEntry original = null)
        {
            int idx = int.Parse(_idx);

            if (idx == Entry.Count - 1)
            {
                //Last entry, so just remove it
                Entry.RemoveAt(idx);

                if (original != null)
                {
                    Entry.Add(original);
                }
            }
            else if (idx < Entry.Count - 1 && idx >= 0)
            {
                //Replace entry with an empty entry
                if (original != null)
                {
                    Entry[idx] = original;
                }
                else
                {
                    Entry[idx] = EmbEntry.Empty(idx);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Add embEntry if new. If a similar one already exists then that will be returned.
        /// </summary>
        /// <returns></returns>
        public EmbEntry Add(EmbEntry embEntry)
        {
            foreach (var entry in Entry)
            {
                if (entry == embEntry)
                {
                    return(entry);
                }

                if (entry.Compare(embEntry))
                {
                    return(entry);
                }
            }

            //Check entry size
            if (Entry.Count >= MAX_EFFECT_TEXTURES)
            {
                throw new Exception(String.Format("EMB_File.Add: Texture limit has been reached. Cannot add any more."));
            }

            Entry.Add(embEntry);

            return(embEntry);
        }
示例#4
0
        public EmbEntry Clone()
        {
            EmbEntry newEntry = new EmbEntry();

            newEntry.Name      = Name;
            newEntry.Data      = Data;
            newEntry.DdsImage  = DdsImage;
            newEntry.LocalCopy = LocalCopy;
            return(newEntry);
        }
示例#5
0
 public bool Compare(EmbEntry embEntry2, bool ignoreName = false)
 {
     //Name and bytes must be the same to return true
     if (embEntry2.Name == Name || ignoreName)
     {
         return(Data.SequenceEqual(embEntry2.Data));
     }
     else
     {
         return(false);
     }
 }
示例#6
0
        //Make this an extension method so there's not an AForge dependence wherever EMB is used
        public static void ChangeHue(this EmbEntry entry, double hue, double _saturation, double lightness)
        {
            float brightness = (float)lightness / 5f;
            float saturation = (float)_saturation;

            Bitmap bitmap = (Bitmap)entry.DdsImage;

            // Apply filters
            var hueFilter = new AForge.Imaging.Filters.HueAdjustment((int)hue);
            var hslFilter = new AForge.Imaging.Filters.HSLLinear();

            //Apply filters
            hueFilter.ApplyInPlace(bitmap);

            if (lightness > 0 || saturation > 0)
            {
                //Taken from: https://csharp.hotexamples.com/examples/AForge.Imaging.Filters/HSLLinear/-/php-hsllinear-class-examples.html
                // create luminance filter
                if (brightness > 0)
                {
                    hslFilter.InLuminance  = new Range(0.0f, 1.0f - brightness); //TODO - isn't it better not to truncate, but compress?
                    hslFilter.OutLuminance = new Range(brightness, 1.0f);
                }
                else
                {
                    hslFilter.InLuminance  = new Range(-brightness, 1.0f);
                    hslFilter.OutLuminance = new Range(0.0f, 1.0f + brightness);
                }
                // create saturation filter
                if (saturation > 0)
                {
                    hslFilter.InSaturation  = new Range(0.0f, 1.0f - saturation); //Ditto?
                    hslFilter.OutSaturation = new Range(saturation, 1.0f);
                }
                else
                {
                    hslFilter.InSaturation  = new Range(-saturation, 1.0f);
                    hslFilter.OutSaturation = new Range(0.0f, 1.0f + saturation);
                }

                if (hslFilter.FormatTranslations.ContainsKey(bitmap.PixelFormat))
                {
                    hslFilter.ApplyInPlace(bitmap);
                }
            }

            //Convert back to WPF Bitmap
            entry.DdsImage  = (WriteableBitmap)bitmap;
            entry.wasEdited = true;
        }
示例#7
0
        public EmbEntry Compare(EmbEntry embEntry2)
        {
            foreach (var entry in Entry)
            {
                if (entry == embEntry2)
                {
                    return(entry);
                }

                if (entry.Compare(embEntry2))
                {
                    return(entry);
                }
            }

            return(null);
        }
示例#8
0
        public int AddEntry(EmbEntry embEntry, string _idx, InstallMode _installMode)
        {
            int idx = int.Parse(_idx);

            if (_installMode == InstallMode.MatchIndex)
            {
                if (idx <= (Entry.Count - 1))
                {
                    Entry[idx] = embEntry;
                    return(idx);
                }
                else
                {
                    //Add empty entries until idx is reached
                    while ((Entry.Count - 1) < (idx - 1))
                    {
                        Entry.Add(new EmbEntry()
                        {
                            Name = "dummy_" + (Entry.Count - 1).ToString(), Data = new List <byte>()
                        });
                    }

                    Entry.Add(embEntry);
                    return(Entry.Count - 1);
                }
            }
            else if (_installMode == InstallMode.MatchName)
            {
                for (int i = 0; i < Entry.Count; i++)
                {
                    if (Entry[i].Name == embEntry.Name)
                    {
                        Entry[i] = embEntry;
                        return(i);
                    }
                }

                Entry.Add(embEntry);
                return(Entry.Count - 1);
            }

            return(-1);
        }
示例#9
0
        //Make this an extension method so there's not an AForge dependence wherever EMB is used
        public static void ChangeHue(this EmbEntry entry, double hue, double _saturation, double lightness, List <IUndoRedo> undos = null, bool hueSet = false, int variance = 0)
        {
            float brightness = (float)lightness / 5f;
            float saturation = (float)_saturation;

            WriteableBitmap oldBitmap = entry.DdsImage;
            Bitmap          bitmap    = (Bitmap)entry.DdsImage;

            if (hueSet)
            {
                if (variance != 0)
                {
                    hue += Random.Range(-variance, variance);
                }

                var hueFilter = new AForge.Imaging.Filters.HueModifier((int)hue);
                hueFilter.ApplyInPlace(bitmap);
            }
            else
            {
                //Hue Adjustment (shifting)

                // Apply filters
                var hueFilter = new AForge.Imaging.Filters.HueAdjustment((int)hue);
                var hslFilter = new AForge.Imaging.Filters.HSLLinear();

                //Apply filters
                hueFilter.ApplyInPlace(bitmap);

                if (lightness > 0 || saturation > 0)
                {
                    //Taken from: https://csharp.hotexamples.com/examples/AForge.Imaging.Filters/HSLLinear/-/php-hsllinear-class-examples.html
                    // create luminance filter
                    if (brightness > 0)
                    {
                        hslFilter.InLuminance  = new Range(0.0f, 1.0f - brightness); //TODO - isn't it better not to truncate, but compress?
                        hslFilter.OutLuminance = new Range(brightness, 1.0f);
                    }
                    else
                    {
                        hslFilter.InLuminance  = new Range(-brightness, 1.0f);
                        hslFilter.OutLuminance = new Range(0.0f, 1.0f + brightness);
                    }
                    // create saturation filter
                    if (saturation > 0)
                    {
                        hslFilter.InSaturation  = new Range(0.0f, 1.0f - saturation); //Ditto?
                        hslFilter.OutSaturation = new Range(saturation, 1.0f);
                    }
                    else
                    {
                        hslFilter.InSaturation  = new Range(-saturation, 1.0f);
                        hslFilter.OutSaturation = new Range(0.0f, 1.0f + saturation);
                    }

                    if (hslFilter.FormatTranslations.ContainsKey(bitmap.PixelFormat))
                    {
                        hslFilter.ApplyInPlace(bitmap);
                    }
                }
            }

            //Convert back to WPF Bitmap
            entry.DdsImage  = (WriteableBitmap)bitmap;
            entry.wasEdited = true;

            if (undos != null)
            {
                undos.Add(new UndoableProperty <EmbEntry>(nameof(EmbEntry.DdsImage), entry, oldBitmap, entry.DdsImage));
            }
        }