private SprType GetSelectedSpriteType()
        {
            SprType newSprType = SprType.VP_PARALLEL_UPRIGHT;

            if (radioParallelUpright.Checked)
            {
                newSprType = SprType.VP_PARALLEL_UPRIGHT;
            }
            else if (radioFacingUpright.Checked)
            {
                newSprType = SprType.FACING_UPRIGHT;
            }
            else if (radioParallel.Checked)
            {
                newSprType = SprType.VP_PARALLEL;
            }
            else if (radioOriented.Checked)
            {
                newSprType = SprType.ORIENTED;
            }
            else if (radioParallelOriented.Checked)
            {
                newSprType = SprType.VP_PARALLEL_ORIENTED;
            }
            return(newSprType);
        }
Esempio n. 2
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                SprType newSprType = SprType.VP_PARALLEL_UPRIGHT;
                if (radioButton1.Checked)
                {
                    newSprType = SprType.VP_PARALLEL_UPRIGHT;
                }
                else if (radioButton2.Checked)
                {
                    newSprType = SprType.FACING_UPRIGHT;
                }
                else if (radioButton3.Checked)
                {
                    newSprType = SprType.VP_PARALLEL;
                }
                else if (radioButton4.Checked)
                {
                    newSprType = SprType.ORIENTED;
                }
                else if (radioButton5.Checked)
                {
                    newSprType = SprType.VP_PARALLEL_ORIENTED;
                }

                SprTextFormat newTextFormat = SprTextFormat.SPR_NORMAL;
                if (radioButton6.Checked)
                {
                    newTextFormat = SprTextFormat.SPR_NORMAL;
                }
                else if (radioButton7.Checked)
                {
                    newTextFormat = SprTextFormat.SPR_ADDITIVE;
                }
                else if (radioButton8.Checked)
                {
                    newTextFormat = SprTextFormat.SPR_INDEXALPHA;
                }
                else if (radioButton9.Checked)
                {
                    newTextFormat = SprTextFormat.SPR_ALPHTEST;
                }


                SpriteLoader.CreateSpriteFile(saveFileDialog1.FileName, GetInputFilenames(), newSprType, newTextFormat, (int)numericUpDown1.Value - 1);
                if (MessageBox.Show("Sprite file created! Open it now in viewer?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
                {
                    if (openFileNow != null)
                    {
                        openFileNow(saveFileDialog1.FileName);
                    }
                }
                this.Close();
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Only change sprite type. This method doesn't check header.
 /// </summary>
 /// <param name="inputFile">Sprite file.</param>
 /// <param name="newType">New sprite type.</param>
 public void FixSpriteType(SprType newType)
 {
     if (fs.Length >= 12)
     {
         fs.Seek(8, SeekOrigin.Begin); //Skip first
         byte[] type = BitConverter.GetBytes((int)newType);
         fs.Write(type, 0, type.Length);
         fs.Flush();
     }
     else
     {
         throw new ArgumentOutOfRangeException();
     }
 }
        private void buttonSaveSprite_Click(object sender, EventArgs e)
        {
            if (saveSpriteFileDialog.ShowDialog() == DialogResult.OK)
            {
                progBar.Show();
                progLbl.Show();
                buttonSaveSprite.Enabled = false;
                tabControl1.Enabled      = false;

                try
                {
                    string[]      filenames    = GetInputFilenames();
                    string        savePath     = saveSpriteFileDialog.FileName;
                    SprType       spriteType   = GetSelectedSpriteType();
                    SprTextFormat spriteFormat = GetSelectedSpriteFormat();
                    int           paletteIndex = (int)inputPaletteIndex.Value - 1;

                    Thread thCreator = new Thread((o) =>
                    {
                        SpriteLoader.CreateSpriteFile(savePath, filenames, spriteType, spriteFormat, paletteIndex);
                    });
                    thCreator.Start();

                    while (thCreator.IsAlive)
                    {
                        Thread.Sleep(10);
                        Application.DoEvents();
                    }

                    progBar.Hide();
                    progLbl.Hide();

                    if (MessageBox.Show("Sprite file created! Open it now in viewer?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        openFileNow(saveSpriteFileDialog.FileName);
                    }
                }
                finally
                {
                    Close();
                }
            }
        }
Esempio n. 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            SprType newSprType = SprType.VP_PARALLEL_UPRIGHT;

            if (radioButton1.Checked)
            {
                newSprType = SprType.VP_PARALLEL_UPRIGHT;
            }
            else if (radioButton2.Checked)
            {
                newSprType = SprType.FACING_UPRIGHT;
            }
            else if (radioButton3.Checked)
            {
                newSprType = SprType.VP_PARALLEL;
            }
            else if (radioButton4.Checked)
            {
                newSprType = SprType.ORIENTED;
            }
            else if (radioButton5.Checked)
            {
                newSprType = SprType.VP_PARALLEL_ORIENTED;
            }
            //Save sprite
            try
            {
                sprLoader.FixSpriteType(newSprType);

                //Close window
                Close();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            SprType newSprType = SprType.VP_PARALLEL_UPRIGHT;

            if (radioParallelUpright.Checked)
            {
                newSprType = SprType.VP_PARALLEL_UPRIGHT;
            }
            else if (radioFacingUpright.Checked)
            {
                newSprType = SprType.FACING_UPRIGHT;
            }
            else if (radioParallel.Checked)
            {
                newSprType = SprType.VP_PARALLEL;
            }
            else if (radioOriented.Checked)
            {
                newSprType = SprType.ORIENTED;
            }
            else if (radioParallelOriented.Checked)
            {
                newSprType = SprType.VP_PARALLEL_ORIENTED;
            }

            //Save sprite
            try
            {
                sprLoader.FixSpriteType(newSprType);
                Close();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Create new sprite file from image files.
        /// </summary>
        /// <param name="outputPath">Output filename *.SPR</param>
        /// <param name="files">Input image paths.</param>
        /// <param name="spriteType">SprType</param>
        /// <param name="textFormat">SprTextFormat</param>
        /// <param name="palIndex">Which palette use from files</param>
        public static void CreateSpriteFile(string outputPath, string[] files, SprType spriteType, SprTextFormat textFormat, int palIndex)
        {
            List <FreeImageBitmap> images = new List <FreeImageBitmap>();

            foreach (string item in files)
            {
                images.Add(new FreeImageBitmap(item));
            }
            //Retrieve maximum width, height
            int prevSize = 0;
            int maxW = 0, maxH = 0;

            foreach (Bitmap item in images)
            {
                if ((item.Height + item.Width) > prevSize)
                {
                    prevSize = item.Height + item.Width;
                    maxW     = item.Width;
                    maxH     = item.Height;
                }
            }

            //Calc. bounding box
            float f = (float)Math.Sqrt((maxW >> 1) * (maxW >> 1) + (maxH >> 1) * (maxH >> 1));

            using (BinaryWriter bw = new BinaryWriter(new FileStream(outputPath, FileMode.Create)))
            {
                //Write header first
                bw.Write(SpriteHeaderId.ToCharArray());
                bw.Write(2);
                bw.Write((uint)spriteType);
                bw.Write((uint)textFormat);
                bw.Write(f);
                bw.Write(maxW);
                bw.Write(maxH);
                bw.Write(images.Count);
                bw.Write(0.0f);                     //Always 0 ?
                bw.Write(1);                        //Synch. type
                //Color palette
                bw.Write((ushort)MaxPaletteColors); //Always 256 ?

                if ((palIndex > (images.Count - 1)) || palIndex < images.Count)
                {
                    palIndex = 0;
                }

                if (!images[palIndex].HasPalette || images[palIndex].Palette.Length != 256)
                {
                    images[palIndex].ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP);
                }

                Palette pal = images[palIndex].Palette;

                for (int i = 0; i < 256; i++)
                {
                    bw.Write(pal[i].rgbRed);
                    bw.Write(pal[i].rgbGreen);
                    bw.Write(pal[i].rgbBlue);
                }

                //Write images
                for (int i = 0; i < images.Count; i++)
                {
                    bw.Write(0);                           //group
                    bw.Write(-(int)(images[i].Width / 2)); //origin x
                    bw.Write((int)(images[i].Height / 2)); //origin y
                    bw.Write(images[i].Width);             //w
                    bw.Write(images[i].Height);            //h

                    byte[] arr = new byte[images[i].Width * images[i].Height];
                    images[i].RotateFlip(RotateFlipType.RotateNoneFlipX);
                    System.Runtime.InteropServices.Marshal.Copy(images[i].GetScanlinePointer(0), arr, 0, arr.Length);
                    Array.Reverse(arr);
                    bw.Write(arr);
                }
            }

            //Free resources
            for (int i = 0; i < images.Count; i++)
            {
                images[i].Dispose();
            }
        }
 public static void CreateSpriteFile(string outputPath, string[] files, SprType spriteType, SprTextFormat textFormat, int palIndex)
 {
     CreateSpriteFile(outputPath, files, spriteType, textFormat, palIndex, Color.Blue);
 }
 /// <summary>
 /// Only change sprite type. This method doesn't check header.
 /// </summary>
 /// <param name="inputFile">Sprite file.</param>
 /// <param name="newType">New sprite type.</param>
 public void FixSpriteType(SprType newType)
 {
     if (fs.Length >= 12)
     {
         fs.Seek(8, SeekOrigin.Begin); //Skip first
         byte[] type = BitConverter.GetBytes((int)newType);
         fs.Write(type, 0, type.Length);
         fs.Flush();
     }
     else
     {
         throw new ArgumentOutOfRangeException();
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Create new sprite file from image files.
        /// </summary>
        /// <param name="outputPath">Output filename *.SPR</param>
        /// <param name="files">Input image paths.</param>
        /// <param name="spriteType">SprType</param>
        /// <param name="textFormat">SprTextFormat</param>
        /// <param name="palIndex">Which palette use from files</param>
        public static void CreateSpriteFile(string outputPath, string[] files, SprType spriteType, SprTextFormat textFormat, int palIndex)
        {
            List<FreeImageBitmap> images = new List<FreeImageBitmap>();
            foreach (string item in files)
            {
                images.Add(new FreeImageBitmap(item));
            }
            //Retrieve maximum width, height
            int prevSize = 0;
            int maxW = 0, maxH = 0;
            foreach (Bitmap item in images)
            {
                if ((item.Height + item.Width) > prevSize)
                {
                    prevSize = item.Height + item.Width;
                    maxW = item.Width;
                    maxH = item.Height;
                }
            }

            //Calc. bounding box
            float f = (float)Math.Sqrt((maxW >> 1) * (maxW >> 1) + (maxH >> 1) * (maxH >> 1));

            using (BinaryWriter bw = new BinaryWriter(new FileStream(outputPath, FileMode.Create)))
            {
                //Write header first
                bw.Write(SpriteHeaderId.ToCharArray());
                bw.Write(2);
                bw.Write((uint)spriteType);
                bw.Write((uint)textFormat);
                bw.Write(f);
                bw.Write(maxW);
                bw.Write(maxH);
                bw.Write(images.Count);
                bw.Write(0.0f); //Always 0 ?
                bw.Write(1); //Synch. type
                //Color palette
                bw.Write((ushort)MaxPaletteColors); //Always 256 ?

                if ((palIndex > (images.Count - 1)) || palIndex < images.Count)
                {
                    palIndex = 0;
                }

                if (!images[palIndex].HasPalette || images[palIndex].Palette.Length != 256)
                {
                    images[palIndex].ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP);
                }

                Palette pal = images[palIndex].Palette;

                for (int i = 0; i < 256; i++)
                {
                    bw.Write(pal[i].rgbRed);
                    bw.Write(pal[i].rgbGreen);
                    bw.Write(pal[i].rgbBlue);
                }

                //Write images
                for (int i = 0; i < images.Count; i++)
                {
                    bw.Write(0); //group
                    bw.Write(-(int)(images[i].Width / 2)); //origin x
                    bw.Write((int)(images[i].Height / 2)); //origin y
                    bw.Write(images[i].Width); //w
                    bw.Write(images[i].Height); //h

                    byte[] arr = new byte[images[i].Width * images[i].Height];
                    images[i].RotateFlip(RotateFlipType.RotateNoneFlipX);
                    System.Runtime.InteropServices.Marshal.Copy(images[i].GetScanlinePointer(0), arr, 0, arr.Length);
                    Array.Reverse(arr);
                    bw.Write(arr);

                }
            }

            //Free resources
            for (int i = 0; i < images.Count; i++)
            {
                images[i].Dispose();
            }
        }