コード例 #1
0
        public void BuildAnimation(AbstractSprite sprite, out IList <System.Drawing.Bitmap> bitmaps, out IList <double> delays, int paletteIndex, Zoom zoom)
        {
            // Given the set of unique frame indices, build the minimal amount of Bitmaps necessary
            Dictionary <int, System.Drawing.Bitmap> frameToBitmap = new Dictionary <int, System.Drawing.Bitmap>(uniqueFrames.Count);

            foreach (int frame in uniqueFrames)
            {
                if (sprite != null)
                {
                    frameToBitmap[frame] = sprite.Shape.Frames[frame].GetFrame(sprite, paletteIndex);
                }
                else
                {
                    frameToBitmap[frame] = null;
                }
            }

            List <System.Drawing.Bitmap> result = new List <System.Drawing.Bitmap>();
            List <double> ourDelays             = new List <double>();

            foreach (AnimationFrame frame in frames)
            {
                //result.Add( frameToBitmap[frame.Index] );
                result.Add(zoom.GetZoomedBitmap(frameToBitmap[frame.Index]));
                ourDelays.Add(((double)frame.Delay) / 60);
            }

            bitmaps = result.ToArray();
            delays  = ourDelays.ToArray();
        }
コード例 #2
0
        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            Bitmap b = pictureBox1.Image as Bitmap;

            pictureBox1.Image = null;
            GetBitmap(b, (int)numericUpDown2.Value, (int)numericUpDown1.Value);
            pictureBox1.Image = b;
            textBox3.Text     = StringFromBytes(evtchr[(int)numericUpDown2.Value].Palettes[(int)numericUpDown1.Value].ToByteArray()).ToString();

            IList <byte> paletteBytes = evtchr[(int)numericUpDown2.Value].Palettes[(int)numericUpDown1.Value].ToByteArray();
            int          foundSprite  = -1;
            int          foundPalette = -1;

            for (int i = 0; i < set.Sprites.Count && foundPalette == -1 && foundSprite == -1; i++)
            {
                for (int j = 0; j < set.Sprites[i].Palettes.Length && foundPalette == -1 && foundSprite == -1; j++)
                {
                    if (PatcherLib.Utilities.Utilities.CompareArrays(set.Sprites[i].Palettes[j].ToByteArray(), paletteBytes))
                    {
                        foundSprite  = i;
                        foundPalette = j;
                    }
                }
            }
            if (foundSprite != -1 && foundPalette != -1)
            {
                AbstractSprite sprite = set.Sprites[foundSprite];
                textBox2.Text = string.Format("{0}: {1}", sprite.Name, foundPalette);
            }
            else
            {
                textBox2.Text = string.Empty;
            }
        }
コード例 #3
0
 /// <summary>
 /// Draws a sprite.
 /// </summary>
 /// <param name="g">The <see cref="Graphics"/> object to draw on.</param>
 public static void DrawSprite(this Graphics g, AbstractSprite s, int palette, int portrait)
 {
     using (Bitmap b = new Bitmap(s.Width, s.Height))
     {
         b.DrawSprite(s, palette, portrait);
         g.DrawImage(b, 0, 0);
     }
 }
コード例 #4
0
        private AllSpritesDoWorkResult DumpAllSprites(Stream iso, string path, bool importExport8bpp, int paletteIndex, Action <int> progressReporter)
        {
            bool progress        = progressReporter != null;
            int  total           = 0;
            int  complete        = 0;
            int  imagesProcessed = 0;

            /*
             * if (progress)
             *  sprites.ForEach(i => total += 1);
             */

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            Dictionary <string, Sprite> fileMap = new Dictionary <string, Sprite>();

            foreach (Sprite sprite in sprites)
            {
                string name = sprite.GetSaveFileName();
                if (!fileMap.ContainsKey(name))
                {
                    fileMap.Add(name, sprite);
                    total = total + 1;
                }
            }

            //foreach (Sprite sprite in sprites)
            foreach (KeyValuePair <string, Sprite> singleFileMap in fileMap)
            {
                //string name = string.Empty;
                //name = sprite.GetSaveFileName();
                string name = singleFileMap.Key;

                if (!string.IsNullOrEmpty(name))
                {
                    //Bitmap bmp = img.GetImageFromIso( iso );
                    //bmp.Save( Path.Combine( path, name ), System.Drawing.Imaging.ImageFormat.Bmp );
                    string                fullPath       = Path.Combine(path, name);
                    Sprite                sprite         = singleFileMap.Value;
                    AbstractSprite        abstractSprite = sprite.GetAbstractSpriteFromIso(iso, true);
                    System.Drawing.Bitmap bitmap         = importExport8bpp ? abstractSprite.ToBitmap() : abstractSprite.To4bppBitmapUncached(paletteIndex);
                    bitmap.Save(fullPath, System.Drawing.Imaging.ImageFormat.Bmp);

                    imagesProcessed++;
                }

                if (progress)
                {
                    progressReporter((100 * (complete++)) / total);
                }
            }

            return(new AllSpritesDoWorkResult(AllSpritesDoWorkResult.Result.Success, imagesProcessed));
        }
コード例 #5
0
ファイル: Shape.cs プロジェクト: xjamxx/FFTPatcher
        public IList <Bitmap> GetFrames(AbstractSprite source)
        {
            List <Bitmap> result = new List <Bitmap>(frames.Count);

            foreach (Frame f in frames)
            {
                result.Add(f.GetFrame(source));
            }

            return(result);
        }
コード例 #6
0
ファイル: Frame.cs プロジェクト: Wi150nZ/lioneditor
        /// <summary>
        /// Gets this frame from the specified sprite.
        /// </summary>
        public Bitmap GetFrame( AbstractSprite source )
        {
            Bitmap result = new Bitmap( 210, 160, System.Drawing.Imaging.PixelFormat.Format8bppIndexed );

            Bitmap sourceBmp = source.ToBitmap();
            result.Palette = sourceBmp.Palette;

            foreach ( Tile t in tiles )
            {
                sourceBmp.CopyRectangleToPoint( t.Rectangle, result, t.Location, source.Palettes[0], t.Reverse );
            }

            return result;
        }
コード例 #7
0
ファイル: Sprite.cs プロジェクト: xjamxx/FFTPatcher
        internal virtual void ImportBitmap(Stream iso, System.Drawing.Bitmap bmp)
        {
            bool           bad    = false;
            AbstractSprite sprite = GetAbstractSpriteFromIso(iso);

            sprite.ImportBitmap(bmp, out bad);
            byte[] sprBytes = sprite.ToByteArray(0);
            if (sprBytes.Length > Size)
            {
                throw new SpriteTooLargeException(sprBytes.Length, (int)Size);
            }

            ImportSprite(iso, sprBytes);
        }
コード例 #8
0
ファイル: SpriteEditor.cs プロジェクト: xjamxx/FFTPatcher
        public void ReloadSprite()
        {
            bool oldIgnoreChanges = ignoreChanges;

            ignoreChanges        = true;
            AbstractSprite       = Sprite.GetAbstractSpriteFromIso(iso);
            spriteViewer1.Sprite = AbstractSprite;

            UpdateCheckBoxesEtc(Sprite as CharacterSprite);
            UpdateShapes(Sprite as CharacterSprite, Sprite);
            UpdateAnimationTab(Sprite as CharacterSprite, Sprite);
            maxSizeLabel.Visible = true;
            maxSizeLabel.Text    = string.Format("Max SPR size:" + Environment.NewLine + "{0} bytes", Sprite.Size);
            ignoreChanges        = oldIgnoreChanges;
        }
コード例 #9
0
        /// <summary>
        /// Gets this frame from the specified sprite.
        /// </summary>
        public Bitmap GetFrame(AbstractSprite source)
        {
            Bitmap result = new Bitmap(210, 160, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);

            Bitmap sourceBmp = source.ToBitmap();

            result.Palette = sourceBmp.Palette;

            foreach (Tile t in tiles)
            {
                sourceBmp.CopyRectangleToPoint(t.Rectangle, result, t.Location, source.Palettes[0], t.Reverse);
            }

            return(result);
        }
コード例 #10
0
ファイル: Sprite.cs プロジェクト: reddyashok257/FFTPatcher
        internal virtual void ImportBitmap4bpp(Stream iso, string filename, int paletteIndex)
        {
            AbstractSprite sprite = GetAbstractSpriteFromIso(iso);

            byte[]    importBytes       = System.IO.File.ReadAllBytes(filename);
            const int totalPaletteBytes = 32 * 16;

            byte[] originalPaletteBytes = Position.AddOffset(0, totalPaletteBytes - Position.Length).ReadIso(iso);
            sprite.ImportBitmap4bpp(paletteIndex, importBytes, originalPaletteBytes);
            byte[] sprBytes = sprite.ToByteArray(0);
            if (sprBytes.Length > Size)
            {
                throw new SpriteTooLargeException(sprBytes.Length, (int)Size);
            }

            ImportSprite(iso, sprBytes);
        }
コード例 #11
0
        private void exportBmpMenuItem_Click(object sender, EventArgs e)
        {
            Sprite currentSprite    = allSpritesEditor1.CurrentSprite;
            int    paletteIndex     = allSpritesEditor1.PaletteIndex;
            bool   importExport8Bpp = allSpritesEditor1.ImportExport8Bpp;

            saveFileDialog.Filter          = importExport8Bpp ? "8bpp paletted bitmap (*.BMP)|*.bmp" : "4bpp paletted bitmap (*.BMP)|*.bmp";
            saveFileDialog.OverwritePrompt = true;
            saveFileDialog.CreatePrompt    = false;
            saveFileDialog.FileName        = string.Empty;

            if (currentSprite != null && saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                AbstractSprite sprite = currentSprite.GetAbstractSpriteFromIso(currentStream, true);
                Bitmap         bitmap = importExport8Bpp ? sprite.ToBitmap() : sprite.To4bppBitmapUncached(paletteIndex);
                bitmap.Save(saveFileDialog.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
            }
        }
コード例 #12
0
        internal override void ImportBitmap(Stream iso, System.Drawing.Bitmap bmp)
        {
            bool           bad    = false;
            AbstractSprite sprite = GetAbstractSpriteFromIso(iso);

            sprite.ImportBitmap(bmp, out bad);
            byte[] sprBytes = sprite.ToByteArray(0);
            if (sprBytes.Length > Size)
            {
                throw new SpriteTooLargeException(sprBytes.Length, (int)Size);
            }

            ImportSprite(iso, sprBytes);
            for (int i = 0; i < NumChildren; i++)
            {
                ImportSp2(iso, sprite.ToByteArray(i + 1), i);
            }
        }
コード例 #13
0
        /// <summary>
        /// Gets this frame from the specified sprite.
        /// </summary>
        public Bitmap GetFrame(AbstractSprite source, int paletteIndex = 0)
        {
            Bitmap result = new Bitmap(defaultFrameSize.Width, defaultFrameSize.Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);

            Bitmap sourceBmp = source.ToBitmap(paletteIndex, true);

            //sourceBmp = sourceBmp.RotateImg(90, Color.Transparent);
            result.Palette = sourceBmp.Palette;
            float rotation = 0;

            foreach (Tile t in tiles)
            {
                rotation = t.Rotation;
                sourceBmp.CopyRectangleToPoint(t.Rectangle, result, t.Location, source.Palettes[0], t.ReverseX, t.ReverseY);
            }

            return(result);
        }
コード例 #14
0
        internal virtual void ImportBitmap8bpp(Stream iso, string filename)
        {
            AbstractSprite sprite = GetAbstractSpriteFromIso(iso);

            byte[]    importBytes       = System.IO.File.ReadAllBytes(filename);
            const int totalPaletteBytes = 512;

            byte[] originalPaletteBytes = Position.AddOffset(0, totalPaletteBytes - Position.Length).ReadIso(iso);
            sprite.ImportBitmap8bpp(importBytes, originalPaletteBytes);
            byte[] sprBytes = sprite.ToByteArray(0);

            byte[] newPaletteBytes = sprite.GetPaletteBytes(sprite.Palettes, originalPaletteBytes, Palette.ColorDepth._16bit).ToArray();
            Array.Copy(newPaletteBytes, sprBytes, totalPaletteBytes);

            if (sprBytes.Length > Size)
            {
                throw new SpriteTooLargeException(sprBytes.Length, (int)Size);
            }

            ImportSprite(iso, sprBytes);
        }
コード例 #15
0
ファイル: SpriteDialog.cs プロジェクト: Wi150nZ/lioneditor
        public void ShowDialog( AbstractSprite sprite, IWin32Window owner )
        {
            if ( Sprite != null )
            {
                Sprite.PixelsChanged -= sprite_PixelsChanged;
            }

            Sprite = sprite;
            spriteViewer1.Location = new Point( 3, 3 );
            spriteViewer1.Sprite = sprite;
            shapesListBox.Visible = sprite.Shape != null;
            paletteSelector.SelectedIndex = 0;
            Text = sprite.Name;

            sp2Menu.Visible = sprite is MonsterSprite;
            sp2Menu.Enabled = sprite is MonsterSprite;

            UpdateFrames();

            sprite.PixelsChanged += new EventHandler( sprite_PixelsChanged );

            base.ShowDialog( owner );
        }
コード例 #16
0
        public void ShowDialog(AbstractSprite sprite, IWin32Window owner)
        {
            if (Sprite != null)
            {
                Sprite.PixelsChanged -= sprite_PixelsChanged;
            }

            Sprite = sprite;
            spriteViewer1.Location        = new Point(3, 3);
            spriteViewer1.Sprite          = sprite;
            shapesListBox.Visible         = sprite.Shape != null;
            paletteSelector.SelectedIndex = 0;
            Text = sprite.Name;

            sp2Menu.Visible = sprite is MonsterSprite;
            sp2Menu.Enabled = sprite is MonsterSprite;

            UpdateFrames();

            sprite.PixelsChanged += new EventHandler(sprite_PixelsChanged);

            base.ShowDialog(owner);
        }
コード例 #17
0
        internal override void ImportBitmap8bpp(Stream iso, string filename)
        {
            AbstractSprite sprite = GetAbstractSpriteFromIso(iso);

            byte[]    importBytes       = System.IO.File.ReadAllBytes(filename);
            const int totalPaletteBytes = 512;

            byte[] originalPaletteBytes = Position.AddOffset(0, totalPaletteBytes - Position.Length).ReadIso(iso);
            sprite.ImportBitmap8bpp(importBytes, originalPaletteBytes);

            byte[] sprBytes = sprite.ToByteArray(0);
            if (sprBytes.Length > Size)
            {
                throw new SpriteTooLargeException(sprBytes.Length, (int)Size);
            }

            //System.IO.File.WriteAllBytes(@"spr8.bin", sprBytes);    // DEBUG
            ImportSprite(iso, sprBytes);
            for (int i = 0; i < NumChildren; i++)
            {
                //System.IO.File.WriteAllBytes(@"sp2_8.bin", sprite.ToByteArray(i + 1));    // DEBUG
                ImportSp2(iso, sprite.ToByteArray(i + 1), i);
            }
        }
コード例 #18
0
ファイル: Frame.cs プロジェクト: Glain/FFTPatcher
        /// <summary>
        /// Gets this frame from the specified sprite.
        /// </summary>
        public Bitmap GetFrame( AbstractSprite source )
        {
            Bitmap result = new Bitmap( defaultFrameSize.Width, defaultFrameSize.Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed );

            Bitmap sourceBmp = source.ToBitmap();
            //sourceBmp = sourceBmp.RotateImg(90, Color.Transparent);
            result.Palette = sourceBmp.Palette;
            float rotation = 0;

            foreach ( Tile t in tiles )
            {
                rotation = t.Rotation;
                sourceBmp.CopyRectangleToPoint( t.Rectangle, result, t.Location, source.Palettes[0], t.ReverseX, t.ReverseY );

            }

            return result;
        }
コード例 #19
0
 public ImageEventArgs(AbstractSprite sprite)
 {
     Sprite = sprite;
 }
コード例 #20
0
 /// <summary>
 /// Draws a sprite.
 /// </summary>
 /// <param name="b">The <see cref="Bitmap"/> object to draw on.</param>
 /// <param name="s">The <see cref="Sprite"/> to draw.</param>
 /// <param name="p">The <see cref="Palette"/> to use to draw the sprite.</param>
 public static void DrawSprite(this Bitmap b, AbstractSprite s, int palette, int portrait)
 {
     s.DrawSprite(b, palette, portrait);
 }
コード例 #21
0
ファイル: Sequence.cs プロジェクト: Glain/FFTPatcher
        public void BuildAnimation( AbstractSprite sprite, out IList<System.Drawing.Bitmap> bitmaps, out IList<double> delays )
        {
            // Given the set of unique frame indices, build the minimal amount of Bitmaps necessary
            Dictionary<int, System.Drawing.Bitmap> frameToBitmap = new Dictionary<int, System.Drawing.Bitmap>( uniqueFrames.Count );
            foreach ( int frame in uniqueFrames )
            {
                frameToBitmap[frame] = sprite.Shape.Frames[frame].GetFrame( sprite );
            }

            List<System.Drawing.Bitmap> result = new List<System.Drawing.Bitmap>();
            List<double> ourDelays = new List<double>();

            foreach ( AnimationFrame frame in frames )
            {
                result.Add( frameToBitmap[frame.Index] );
                ourDelays.Add( ( (double)frame.Delay ) / 60 );
            }

            bitmaps = result.ToArray();
            delays = ourDelays.ToArray();
        }
コード例 #22
0
 /// <summary>
 /// Draws a sprite.
 /// </summary>
 /// <param name="g">The <see cref="Graphics"/> object to draw on.</param>
 public static void DrawSprite( this Graphics g, AbstractSprite s, int palette, int portrait )
 {
     using ( Bitmap b = new Bitmap( s.Width, s.Height ) )
     {
         b.DrawSprite( s, palette, portrait );
         g.DrawImage( b, 0, 0 );
     }
 }
コード例 #23
0
 /// <summary>
 /// Draws a sprite.
 /// </summary>
 /// <param name="b">The <see cref="Bitmap"/> object to draw on.</param>
 /// <param name="s">The <see cref="Sprite"/> to draw.</param>
 /// <param name="p">The <see cref="Palette"/> to use to draw the sprite.</param>
 public static void DrawSprite( this Bitmap b, AbstractSprite s, int palette, int portrait )
 {
     s.DrawSprite( b, palette, portrait );
 }
コード例 #24
0
ファイル: Shape.cs プロジェクト: Wi150nZ/lioneditor
        public IList<Bitmap> GetFrames( AbstractSprite source )
        {
            List<Bitmap> result = new List<Bitmap>( frames.Count );
            foreach( Frame f in frames )
            {
                result.Add( f.GetFrame( source ) );
            }

            return result;
        }