Пример #1
0
        void SavePNG(Bitmap image, string filename)
        {
            IndexedBitmapHandler Handler = new IndexedBitmapHandler();

            byte[]       array   = Handler.GetArray(image);
            Bitmap       temp    = Handler.MakeImage(image.Width, image.Height, array, image.PixelFormat);
            ColorPalette cleaned = Handler.CleanPalette(image);

            temp.Palette = cleaned;
            temp.Save(filename, ImageFormat.Png);
        }
Пример #2
0
        void MakeShiny_Click(object sender, EventArgs e)
        {
            if (OpenPngs.Enabled == false)
            {
                return;
            }
            OpenPngs.Enabled = false;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title           = "Choose the base image";
            openFileDialog.CheckPathExists = true;
            openFileDialog.Filter          = "Supported fomats: *.bmp, *.gif, *.png | *.bmp; *.gif; *.png";
            openFileDialog.ShowHelp        = true;
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                OpenPngs.Enabled = true;
                return;
            }
            string filename = openFileDialog.FileName;

            openFileDialog.Title           = "Choose the shiny image";
            openFileDialog.CheckPathExists = true;
            openFileDialog.Filter          = "Supported fomats: *.bmp, *.gif, *.png | *.bmp; *.gif; *.png";
            openFileDialog.ShowHelp        = true;
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                OpenPngs.Enabled = true;
                return;
            }
            Bitmap parent = new Bitmap(filename);
            Bitmap child  = new Bitmap(openFileDialog.FileName);
            IndexedBitmapHandler Handler = new IndexedBitmapHandler();
            ColorPalette         temp    = Handler.AlternatePalette(parent, child);

            if (temp != null)
            {
                CurrentSprites.Shiny = temp;
            }
            else
            {
                MessageBox.Show("Failed!", "Failed");
            }
            OpenPngs.Enabled = true;
            LoadImages();
        }
Пример #3
0
        void btnLoadSheet_Click(object sender, EventArgs e)
        {
            if (OpenPngs.Enabled == false)
            {
                return;
            }
            OpenPngs.Enabled = false;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title           = "Select a sprite sheet";
            openFileDialog.CheckPathExists = true;
            openFileDialog.Filter          = "Supported fomats: *.bmp, *.gif, *.png | *.bmp; *.gif; *.png";
            openFileDialog.ShowHelp        = true;
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                OpenPngs.Enabled = true;
                return;
            }
            Bitmap image = new Bitmap(openFileDialog.FileName);

            if ((image.Width != 256) || (image.Height != 64))
            {
                MessageBox.Show("The sprite sheet should be 256x64.");
                return;
            }
            IndexedBitmapHandler Handler = new IndexedBitmapHandler();

            image         = Handler.Convert(image, PixelFormat.Format8bppIndexed);
            image.Palette = StandardizeColors(image);
            Bitmap[]  tiles   = Handler.Split(image, 64, 64);
            SpriteSet sprites = new SpriteSet();

            bool[] used = Handler.IsUsed(tiles[0]);
            used = Handler.IsUsed(tiles[2], used);
            Bitmap temp = Handler.ShrinkPalette(tiles[0], used);

            sprites.Normal     = temp.Palette;
            temp               = Handler.Resize(temp, 8, 8, 8, 8);
            temp               = Handler.Concat(temp, temp);
            sprites.Sprites[2] = temp;
            sprites.Sprites[3] = temp;
            temp               = Handler.ShrinkPalette(tiles[2], used);
            temp               = Handler.Resize(temp, 8, 8, 8, 8);
            if (DPCheck.Checked)
            {
                temp = Handler.Resize(temp, 0, 0, 0, 80);
            }
            else
            {
                temp = Handler.Concat(temp, temp);
            }
            sprites.Sprites[0] = temp;
            sprites.Sprites[1] = temp;
            temp             = Handler.ShrinkPalette(tiles[1], used);
            temp             = Handler.Resize(temp, 8, 8, 8, 8);
            temp             = Handler.Concat(temp, temp);
            sprites.Shiny    = Handler.AlternatePalette(sprites.Sprites[2], temp);
            CurrentSprites   = sprites;
            OpenPngs.Enabled = true;
            LoadImages();
        }
Пример #4
0
        void InitializeComponent()
        {
            used           = null;
            Handler        = new IndexedBitmapHandler();
            CurrentSprites = new SpriteSet();
            BuildPictureBoxes(96, 56);

            mainMenu1       = new MainMenu();
            menuFile        = new MenuItem();
            menuOpenNarc    = new MenuItem();
            menuWriteToNarc = new MenuItem();
            menuOpenPng     = new MenuItem();
            menuSavePng     = new MenuItem();
            menuLoadSheet   = new MenuItem();
            menuItem10      = new MenuItem();
            menuAbout       = new MenuItem();
            menuOptions     = new MenuItem();
            AutoColor       = new MenuItem();
            AutoConvert     = new MenuItem();
            UseShrinking    = new MenuItem();

            AutoColor.Checked   = true;
            AutoConvert.Checked = true;

            OpenPngs   = new Button();
            LoadSheet  = new Button();
            LoadNarc   = new Button();
            SaveSingle = new Button();
            MakeShiny  = new Button();
            DPCheck    = new CheckBox();

            lblMale   = new Label();
            lblFemale = new Label();
            BackN     = new Label();
            BackS     = new Label();
            FrontN    = new Label();
            FrontS    = new Label();
            lblNormal = new Label();
            lblShiny  = new Label();

            SuspendLayout();

            mainMenu1.MenuItems.AddRange(new MenuItem[3] {
                menuFile, menuOptions, menuItem10
            });
            menuFile.Index = 0;
            menuFile.MenuItems.AddRange(new MenuItem[5] {
                menuOpenNarc, menuWriteToNarc, menuOpenPng, menuSavePng, menuLoadSheet
            });
            menuFile.Text            = "&File";
            menuOpenNarc.Index       = 0;
            menuOpenNarc.Text        = "&Open narc...";
            menuOpenNarc.Click      += (menuItem2_Click);
            menuOpenNarc.Shortcut    = Shortcut.CtrlO;
            menuWriteToNarc.Index    = 1;
            menuWriteToNarc.Text     = "&Write to narc...";
            menuWriteToNarc.Click   += (menuItem8_Click);
            menuWriteToNarc.Shortcut = Shortcut.CtrlW;
            menuOpenPng.Index        = 2;
            menuOpenPng.Text         = "&Load Sprite Set";
            menuOpenPng.Click       += (OpenPng_Click);
            menuOpenPng.Shortcut     = Shortcut.CtrlL;
            menuSavePng.Index        = 3;
            menuSavePng.Text         = "&Save Sprite Set";
            menuSavePng.Click       += (btnSaveAs_Click);
            menuSavePng.Shortcut     = Shortcut.CtrlS;
            menuLoadSheet.Index      = 4;
            menuLoadSheet.Text       = "Load Spr&ite Sheet";
            menuLoadSheet.Click     += (btnLoadSheet_Click);
            menuLoadSheet.Shortcut   = Shortcut.CtrlI;
            menuOptions.Index        = 1;
            menuOptions.MenuItems.AddRange(new MenuItem[3] {
                AutoColor, AutoConvert, UseShrinking
            });
            menuOptions.Text    = "Options";
            AutoColor.Index     = 0;
            AutoColor.Text      = "Fix Non-standard Colors";
            AutoColor.Click    += (menuCheck_Click);
            AutoConvert.Index   = 1;
            AutoConvert.Text    = "Convert Wrong Format Images";
            AutoConvert.Click  += (menuCheck_Click);
            UseShrinking.Index  = 2;
            UseShrinking.Text   = "Allow Shrinking of Expanded Images";
            UseShrinking.Click += (menuCheck_Click);
            menuItem10.Index    = 2;
            menuItem10.MenuItems.AddRange(new MenuItem[1] {
                menuAbout
            });
            menuItem10.Text  = "Help";
            menuAbout.Index  = 0;
            menuAbout.Text   = "Credits";
            menuAbout.Click += (menuItem13_Click);

            IndexBox = new ComboBox();
            IndexBox.DropDownWidth         = 160;
            IndexBox.Location              = new Point(340, 8);
            IndexBox.MaxDropDownItems      = 16;
            IndexBox.Name                  = "IndexBox";
            IndexBox.Size                  = new Size(160, 21);
            IndexBox.TabIndex              = 6;
            IndexBox.SelectedIndexChanged += (IndexBox_SelectedIndexChanged);

            OpenPngs.Location = new Point(646, 8);
            OpenPngs.Name     = "OpenPng";
            OpenPngs.Size     = new Size(100, 25);
            OpenPngs.TabIndex = 3;
            OpenPngs.Text     = "Load Sprite Set";
            OpenPngs.Click   += (OpenPng_Click);

            LoadSheet.Location = new Point(538, 8);
            LoadSheet.Name     = "LoadSheet";
            LoadSheet.Size     = new Size(100, 25);
            LoadSheet.Text     = "Load Sprite Sheet";
            LoadSheet.Click   += (btnLoadSheet_Click);

            SaveBox = new ComboBox();
            SaveBox.DropDownWidth    = 160;
            SaveBox.Location         = new Point(512, 728);
            SaveBox.MaxDropDownItems = 8;
            SaveBox.Name             = "SaveBox";
            SaveBox.Size             = new Size(160, 21);

            SaveBox.Items.Add("Normal Female Backsprite");
            SaveBox.Items.Add("Normal Male Backsprite");
            SaveBox.Items.Add("Normal Female Frontsprite");
            SaveBox.Items.Add("Normal Male Frontprite");
            SaveBox.Items.Add("Shiny Female Backsprite");
            SaveBox.Items.Add("Shiny Male Backsprite");
            SaveBox.Items.Add("Shiny Female Frontsprite");
            SaveBox.Items.Add("Shiny Male Frontprite");
            SaveBox.SelectedIndex = 0;

            SaveSingle.Location = new Point(674, 728);
            SaveSingle.Name     = "SaveSingle";
            SaveSingle.Size     = new Size(70, 21);
            SaveSingle.Text     = "Save PNG";
            SaveSingle.Click   += (SaveSingle_Click);

            MakeShiny.Location = new Point(96, 728);
            MakeShiny.Name     = "MakeShiny";
            MakeShiny.Size     = new Size(120, 21);
            MakeShiny.Text     = "Create Shiny Palette";
            MakeShiny.Click   += (MakeShiny_Click);

            LoadNarc.Location = new Point(96, 8);
            LoadNarc.Name     = "LoadNarc";
            LoadNarc.Size     = new Size(70, 25);
            LoadNarc.TabIndex = 2;
            LoadNarc.Text     = "Open narc";
            LoadNarc.Click   += (menuItem2_Click);

            DPCheck.Location = new Point(170, 8);
            DPCheck.Name     = "DPCheck";
            DPCheck.Text     = "Diamond/Pearl";

            lblFemale.Text     = "Female";
            lblFemale.Location = new Point(232, 36);
            Controls.Add(lblFemale);
            lblMale.Text     = "Male";
            lblMale.Location = new Point(564, 36);
            Controls.Add(lblMale);
            BackN.Text     = "Back";
            BackN.Location = new Point(52, 126);
            Controls.Add(BackN);
            BackS.Text     = "Back";
            BackS.Location = new Point(52, 462);
            Controls.Add(BackS);
            FrontN.Text     = "Front";
            FrontN.Location = new Point(52, 294);
            Controls.Add(FrontN);
            FrontS.Text     = "Front";
            FrontS.Location = new Point(52, 630);
            Controls.Add(FrontS);
            lblNormal.Text     = "Normal";
            lblNormal.Location = new Point(8, 210);
            Controls.Add(lblNormal);
            lblShiny.Text     = "Shiny";
            lblShiny.Location = new Point(8, 546);
            Controls.Add(lblShiny);

            ResumeLayout(false);

            Menu = mainMenu1;
            Controls.Add(IndexBox);
            Controls.Add(SaveBox);
            Controls.Add(OpenPngs);
            Controls.Add(LoadSheet);
            Controls.Add(LoadNarc);
            Controls.Add(SaveSingle);
            Controls.Add(DPCheck);
            Controls.Add(MakeShiny);
            AutoScaleMode     = System.Windows.Forms.AutoScaleMode.Font;
            Width             = 760;
            Height            = 808;
            Text              = "Gen IV Sprite Editor";
            Name              = "MainForm";
            AutoScaleBaseSize = new Size(5, 13);
            FormBorderStyle   = System.Windows.Forms.FormBorderStyle.FixedDialog;
            MaximizeBox       = false;
            OpenPngs.Enabled  = false;
        }
Пример #5
0
        void Picturebox_Click(object sender, EventArgs e)
        {
            if (OpenPngs.Enabled == false)
            {
                return;
            }
            OpenPngs.Enabled = false;
            PictureBox     source         = sender as PictureBox;
            int            index          = Convert.ToInt32(source.Name);
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title           = "Choose an image";
            openFileDialog.CheckPathExists = true;
            openFileDialog.Filter          = "Supported fomats: *.bmp, *.gif, *.png | *.bmp; *.gif; *.png";
            openFileDialog.ShowHelp        = true;
            Bitmap image;

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                OpenPngs.Enabled = true;
                return;
            }
            image = new Bitmap(openFileDialog.FileName);
            IndexedBitmapHandler Handler = new IndexedBitmapHandler();

            if (index > 3)
            {
                image = CheckSize(image, openFileDialog.FileName, "Shiny");
                if (image == null)
                {
                    OpenPngs.Enabled = true;
                    return;
                }
                ColorPalette temp = Handler.AlternatePalette(CurrentSprites.Sprites[index % 4], image);
                if (temp != null)
                {
                    CurrentSprites.Shiny = temp;
                }
                else
                {
                    CurrentSprites.Shiny = image.Palette;
                }
            }
            else
            {
                image = CheckSize(image, openFileDialog.FileName, names[index], index);
                if (image == null)
                {
                    OpenPngs.Enabled = true;
                    return;
                }
                bool match = Handler.PaletteEquals(CurrentSprites.Normal, image);
                if (!match)
                {
                    DialogResult yesno = MessageBox.Show("Image's palette does not match the current palette.  Use PaletteMatch?", "Palette mismatch", MessageBoxButtons.YesNo);
                    if (yesno == DialogResult.Yes)
                    {
                        image = Handler.PaletteMatch(CurrentSprites.Normal, image, used);
                        used  = Handler.IsUsed(image, used);
                    }
                    else
                    {
                        used = Handler.IsUsed(image);
                    }
                    CurrentSprites.Normal = image.Palette;
                }
                CurrentSprites.Sprites[index] = image;
            }
            OpenPngs.Enabled = true;
            LoadImages();
        }
Пример #6
0
        Bitmap CheckSize(Bitmap image, string filename, string name, int spritenumber = 2)
        {
            DialogResult         yesno;
            IndexedBitmapHandler Handler = new IndexedBitmapHandler();

            if (image.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                if (AutoConvert.Checked)
                {
                    yesno = DialogResult.Yes;
                }
                else
                {
                    yesno = MessageBox.Show(filename + " is not 8bpp Indexed!  Attempt conversion?", "Incompatible image format", MessageBoxButtons.YesNo);
                }
                if (yesno != DialogResult.Yes)
                {
                    return(null);
                }
                image = Handler.Convert(image, PixelFormat.Format8bppIndexed);
                if (image == null)
                {
                    return(null);
                }
                if ((image.PixelFormat != PixelFormat.Format8bppIndexed) || (image.Palette == null))
                {
                    MessageBox.Show("Conversion failed.", "Failed");
                    return(null);
                }
            }
            if (((image.Height != 64) && (image.Height != 80)) || ((image.Width != 64) && (image.Width != 80) && (image.Width != 160)))
            {
                int imagescale = 0;
                if (UseShrinking.Checked)
                {
                    if ((image.Width / 64 == image.Height / 64) && (image.Width % 64 == 0) && (image.Height % 64 == 0))
                    {
                        imagescale = image.Width / 64;
                    }
                    if ((image.Width / 80 == image.Height / 80) && (image.Width % 80 == 0) && (image.Height % 80 == 0))
                    {
                        imagescale = image.Width / 80;
                    }
                    if ((image.Width / 160 == image.Height / 80) && (image.Width % 160 == 0) && (image.Height % 80 == 0))
                    {
                        imagescale = image.Width / 160;
                    }
                    if (imagescale > 1)
                    {
                        yesno = MessageBox.Show(filename + " is too large.  Attempt to shrink?", "Too large", MessageBoxButtons.YesNo);
                        if (yesno == DialogResult.Yes)
                        {
                            image = Handler.ShrinkImage(image, imagescale, imagescale);
                        }
                        else
                        {
                            imagescale = 0;
                        }
                    }
                }
                if (imagescale == 0)
                {
                    yesno = MessageBox.Show(filename + " size not recognized. Use Canvas Splitter?", "Unrecognized size", MessageBoxButtons.YesNo);
                    if (yesno != DialogResult.Yes)
                    {
                        return(null);
                    }
                    SizeChooser  Chooser    = new SizeChooser();
                    DialogResult success    = Chooser.ShowDialog();
                    int          sizeChoice = Chooser.choice;
                    Chooser.Dispose();
                    if (success == DialogResult.Cancel)
                    {
                        return(null);
                    }
                    int a = 80;
                    int b = 80;
                    if (sizeChoice == 0)
                    {
                        a = 64;
                        b = 64;
                    }
                    if (sizeChoice == 2)
                    {
                        a = 160;
                    }
                    if ((image.Width < a) || (image.Height < b))
                    {
                        MessageBox.Show("Image is too small");
                        return(null);
                    }
                    Bitmap[]      tiles   = Handler.Split(image, a, b);
                    SpriteCropper Cropper = new SpriteCropper(tiles, name);
                    success = Cropper.ShowDialog();
                    if (success == DialogResult.Cancel)
                    {
                        return(null);
                    }
                    image = Cropper.Chosen;
                    Cropper.Dispose();
                }
            }
            if (AutoColor.Checked)
            {
                image.Palette = StandardizeColors(image);
            }
            byte check = Handler.PaletteSize(image);

            if (check > 16)
            {
                yesno = MessageBox.Show("Image's palette contains more than sixteen colors.  Attempt to shrink?", "Improper palette size", MessageBoxButtons.YesNo);
                if (yesno == DialogResult.Yes)
                {
                    image = Handler.ShrinkPalette(image);
                    check = Handler.PaletteSize(image);
                    if (check > 16)
                    {
                        MessageBox.Show("Palette still too large.  Image will not save correctly.", "Failed");
                    }
                }
            }
            if (image.Height == 64 && image.Width == 64)
            {
                image = Handler.Resize(image, 8, 8, 8, 8);
            }
            if (image.Height == 80 && image.Width == 80)
            {
                if ((spritenumber < 2) && (DPCheck.Checked == true))
                {
                    image = Handler.Resize(image, 0, 0, 0, 80);
                }
                else
                {
                    image = Handler.Concat(image, image);
                }
            }
            if (image.Height == 80 && image.Width == 160)
            {
                return(image);
            }
            return(null);
        }