Ejemplo n.º 1
0
 public void OpenPalette(string filename)
 {
     if (filename.EndsWith(".aco"))
     {
         var p = new AcoPalette(
             File.ReadAllBytes(filename));
         appPal.NewFromPalette(p, filename);
     }
     else if (filename.EndsWith(".ase"))
     {
         var p = new AsePalette(
             File.ReadAllBytes(filename));
         appPal.NewFromPalette(p, filename);
     }
     else if (filename.EndsWith(".act"))
     {
         var p = new ActPalette(
             File.ReadAllBytes(filename));
         appPal.NewFromPalette(p, filename);
     }
     else if (filename.EndsWith(".acb"))
     {
         var p = new AcbPalette(
             File.ReadAllBytes(filename));
         appPal.NewFromPalette(p, filename);
     }
     else
     {
         appPal.NewFromPalette(new GimpPalette(File.ReadAllText(filename)), filename);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the color palette, with the following parameters.
        /// </summary>
        /// <param name="newFileName">
        /// The new file name of the file to convert, including extension.
        /// </param>
        /// <param name="keepHistory">If undo should have been added.</param>
        /// <param name="fireEvent">If the event should fire.</param>
        /// <param name="action">If the undo is added, the action it is described as.</param>
        public void ConvertPalette(string newFileName, bool keepHistory = true, bool fireEvent = true, string action = null)
        {
            action = action ?? "Palette Conversion";

            var extension = Path.GetExtension(newFileName);

            IPalette newPal = null;

            switch (extension)
            {
            case ".colors":
                if (!(Palette is NativePalette))
                {
                    newPal = new NativePalette(Palette);
                }
                break;

            case ".gpl":
                if (!(Palette is GimpPalette))
                {
                    newPal = new GimpPalette(Palette);
                }
                break;

            case ".psppalette":
                if (!(Palette is PspPalette))
                {
                    newPal = new PspPalette(Palette);
                }
                break;

            case ".aco":
                if (!(Palette is AcoPalette))
                {
                    newPal = new AcoPalette(Palette);
                }
                break;

            case ".ase":
                if (!(Palette is AsePalette))
                {
                    newPal = new AsePalette(Palette);
                }
                break;

            case ".act":
                if (!(Palette is ActPalette))
                {
                    newPal = new ActPalette(Palette);
                }
                break;

            case ".acb":
                if (!(Palette is AcbPalette))
                {
                    newPal = new AcbPalette(Palette);
                }
                break;

            case ".pal":
                if (!(Palette is MsRiffPalette))
                {
                    newPal = new MsRiffPalette(Palette);
                }
                break;
            }

            // in case we convert from a non INamed to an INamed, give it a name at least
            if (newPal is INamedPalette && string.IsNullOrEmpty(((INamedPalette)newPal).Name))
            {
                ((INamedPalette)newPal).Name = Path.GetFileNameWithoutExtension(newFileName);
            }

            if (newPal != null)
            {
                SetPalette(newPal, keepHistory, fireEvent, action);
            }
        }