Exemple #1
0
        // Drawing
        private void SetActiveLocations()
        {
            pointActivePixels = new int[256 * 256];
            int[]    point = Do.GetPixelRegion(Model.Sprites_Graphics, 0x20, GetPointPalette(), 16, 0, 1, 2, 1, 0);
            Location temp;

            for (int i = 0; i < worldMap.Locations; i++)
            {
                temp = (Location)worldMapLocations[Index][i];
                for (int y = 0; y < 8; y++)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        if (point[y * 16 + x] != 0 &&
                            (y + temp.Y) >= 0 &&
                            (y + temp.Y) < 256 &&
                            (x + temp.X) >= 0 &&
                            (x + temp.X) < 256)
                        {
                            pointActivePixels[(y + temp.Y) * 256 + x + temp.X] = temp.Index + 1;
                        }
                    }
                }
            }
        }
 // Picture
 private void picture_Paint(object sender, PaintEventArgs e)
 {
     if (type < 2)
     {
         if (tilesetImage != null)
         {
             e.Graphics.DrawImage(tilesetImage, 0, 0, 256, 32);
         }
         if (textImage != null && toggleText.Checked)
         {
             e.Graphics.DrawImage(textImage, 0, 0, 256, 32);
         }
         if (toggleTileGrid.Checked)
         {
             overlay.DrawTileGrid(e.Graphics, Color.Black, picture.Size, new Size(16, 16), 1, true);
         }
     }
     else
     {
         int    x     = 0;
         string text  = Model.BonusMessages[this.Index].Text;
         int[]  table = Sprites.Model.Sprites[520].GetTilesetPixels();
         foreach (char letter in text)
         {
             int index = Lists.IndexOf(Lists.KeystrokesBonus, letter.ToString());
             if (index < 0 || index > 31)
             {
                 continue;
             }
             int[] pixels = Do.GetPixelRegion(table, 128, 16, 8, 8, index % 16 * 8, index / 16 * 8);
             e.Graphics.DrawImage(Do.PixelsToImage(pixels, 8, 8), x * 8 + 8, 8);
             x++;
         }
     }
 }
Exemple #3
0
        private int[] GetMarioPixels()
        {
            int[]     pixels = new int[16 * 32];
            int[]     bottom = Do.GetPixelRegion(Model.Sprites_Graphics, 0x20, GetPointPalette(), 16, 10, 0, 2, 2, 0);
            int[]     top    = Do.GetPixelRegion(Model.Sprites_Graphics, 0x20, GetPointPalette(), 16, 4, 0, 2, 2, 0);
            Rectangle r      = new Rectangle(0, 0, 16, 16);

            Do.PixelsToPixels(bottom, pixels, 16, 16, r, r);
            Do.PixelsToPixels(top, pixels, 16, 16, r, new Rectangle(0, 16, 16, 16));
            return(pixels);
        }
Exemple #4
0
 private int[] GetLocationPixels(bool hilite)
 {
     int[] pixels = Do.GetPixelRegion(Model.Sprites_Graphics, 0x20, GetPointPalette(), 16, 0, 1, 2, 1, 0);
     if (hilite)
     {
         return(Do.Hilite(pixels, 16, 8));
     }
     else
     {
         return(pixels);
     }
 }
Exemple #5
0
        private void DrawSingleMainscreenTile(int x, int y)
        {
            int bgcolor = paletteSet.Palette[16];

            CopySingleTileToArray(pixels, Do.GetPixelRegion(pixels, 1024, 1024, 16, 16, x, y), Width_p, x, y);
            // Apply BG color
            for (int b = y; b < y + 16; b++)
            {
                for (int a = x; a < x + 16; a++)
                {
                    if (pixels[b * Width_p + a] == 0)
                    {
                        pixels[b * Width_p + a] = bgcolor;
                    }
                }
            }
        }
Exemple #6
0
        private void bonusPreview_Paint(object sender, PaintEventArgs e)
        {
            int    x    = 0;
            string text = Model.BonusMessages[this.index].Text;

            int[] table = Model.Sprites[520].GetTilesetPixels();
            foreach (char letter in text)
            {
                int index = Lists.IndexOf(Lists.KeystrokesBonus, letter.ToString());
                if (index < 0 || index > 31)
                {
                    continue;
                }
                int[] pixels = Do.GetPixelRegion(table, 128, 16, 8, 8, index % 16 * 8, index / 16 * 8);
                e.Graphics.DrawImage(Do.PixelsToImage(pixels, 8, 8), x * 8, 0);
                x++;
            }
        }
 private void Export_Worker_DoWork(object sender, DoWorkEventArgs e, string fullPath,
                                   bool crop, bool contact, bool gif, int maxwidth, int start, int end, bool current)
 {
     for (int a = start; a < end; a++)
     {
         if (Export_Worker.CancellationPending)
         {
             break;
         }
         Sprite s = null;
         if (element == "levels")
         {
             Export_Worker.ReportProgress(a);
         }
         else
         {
             s = sprites[a];
             Export_Worker.ReportProgress(s.Index);
         }
         // if NOT sprite sheet or animated gif (ie. if NOT single image for each element)
         if (!contact && element == "sprites")
         {
             DirectoryInfo di = new DirectoryInfo(fullPath + "Sprite #" + s.Index.ToString("d4"));
             if (!di.Exists)
             {
                 di.Create();
             }
         }
         int index = 0;
         int x = 0, y = 0;
         if (this.element == "levels")
         {
             LevelMap     lmap = levelMaps[levels[a].LevelMap];
             LevelLayer   layr = levels[a].Layer;
             PaletteSet   pset = paletteSets[levelMaps[levels[a].LevelMap].PaletteSet];
             Tileset      tset = new Tileset(lmap, pset);
             LevelTilemap tmap = new LevelTilemap(levels[a], tset);
             int[]        pixels;
             Rectangle    region;
             if (crop)
             {
                 region = new Rectangle(
                     layr.MaskLowX * 16, layr.MaskLowY * 16,
                     (layr.MaskHighX - layr.MaskLowX) * 16 + 16,
                     (layr.MaskHighY - layr.MaskLowY) * 16 + 16);
                 pixels = Do.GetPixelRegion(tmap.Pixels, region, 1024, 1024);
             }
             else
             {
                 region = new Rectangle(0, 0, 1024, 1024);
                 pixels = tmap.Pixels;
             }
             Bitmap image = Do.PixelsToImage(pixels, region.Width, region.Height);
             if (!current)
             {
                 image.Save(fullPath + "Level #" + a.ToString("d3") + ".png", ImageFormat.Png);
             }
             else
             {
                 image.Save(fullPath, ImageFormat.Png);
             }
             continue;
         }
         // sprites
         if (gif)
         {
             Animation animation = animations[s.AnimationPacket];
             foreach (Mold m in animation.Molds)
             {
                 foreach (Mold.Tile t in m.Tiles)
                 {
                     t.DrawSubtiles(s.Graphics, s.Palette, m.Gridplane);
                 }
             }
             foreach (Sequence sequence in animation.Sequences)
             {
                 List <int> durations     = new List <int>();
                 Bitmap[]   croppedFrames = sequence.GetSequenceImages(animation, ref durations);
                 //
                 string path = fullPath + "Sprite #" + s.Index.ToString("d4") + "\\sequence." + index.ToString("d2") + ".gif";
                 if (croppedFrames.Length > 0)
                 {
                     Do.ImagesToAnimatedGIF(croppedFrames, durations.ToArray(), path);
                 }
                 index++;
             }
             continue;
         }
         int[][]          molds = new int[animations[s.AnimationPacket].Molds.Count][];
         int[]            sheet;
         int              biggestHeight = 0;
         int              biggestWidth = 0;
         List <Rectangle> sheetRegions = new List <Rectangle>();
         foreach (Mold m in animations[s.AnimationPacket].Molds)
         {
             foreach (Mold.Tile t in m.Tiles)
             {
                 t.DrawSubtiles(
                     images[s.Image].Graphics(spriteGraphics),
                     palettes[images[s.Image].PaletteNum + s.PaletteIndex].Palette,
                     m.Gridplane);
             }
             Rectangle region;
             if (crop)
             {
                 if (m.Gridplane)
                 {
                     region = Do.Crop(m.GridplanePixels(), out molds[index], 32, 32);
                 }
                 else
                 {
                     region = Do.Crop(m.MoldPixels(), out molds[index], 256, 256);
                 }
                 m.MoldTilesPerPixel = null;
                 if (x + region.Width < maxwidth && biggestWidth < x + region.Width)
                 {
                     biggestWidth = x + region.Width;
                 }
                 // if reached far right boundary of a row, add current row's height
                 if (x + region.Width >= maxwidth)
                 {
                     x  = region.Width; // reset width counter
                     y += biggestHeight;
                     sheetRegions.Add(new Rectangle(x - region.Width, y, region.Width, region.Height));
                     biggestHeight = 0; // start next row
                 }
                 else
                 {
                     sheetRegions.Add(new Rectangle(x, y, region.Width, region.Height));
                     x += region.Width;
                 }
                 if (biggestHeight < region.Height)
                 {
                     biggestHeight = region.Height;
                 }
             }
             else
             {
                 region       = new Rectangle(new Point(0, 0), m.Gridplane ? new Size(32, 32) : new Size(256, 256));
                 molds[index] = m.Gridplane ? m.GridplanePixels() : m.MoldPixels();
             }
             if (!contact)
             {
                 Do.PixelsToImage(molds[index], region.Width, region.Height).Save(
                     fullPath + "Sprite #" + s.Index.ToString("d4") + "\\mold." + index.ToString("d2") + ".png", ImageFormat.Png);
             }
             index++;
         }
         if (contact)
         {
             sheet = new int[biggestWidth * (y + biggestHeight)];
             for (int i = 0; i < molds.Length; i++)
             {
                 Do.PixelsToPixels(molds[i], sheet, biggestWidth, sheetRegions[i]);
             }
             string path = fullPath + (current ? "" : "Sprite #" + s.Index.ToString("d4") + ".png");
             Do.PixelsToImage(sheet, biggestWidth, y + biggestHeight).Save(path, ImageFormat.Png);
         }
     }
 }
Exemple #8
0
        /// <summary>
        /// Creates an image collection from the molds used by this sequence
        /// in the order that they are referenced by the frames.
        /// </summary>
        /// <param name="animation">The animation containing the mold data.</param>
        /// <param name="durations">Will contain the durations of each frame in this sequence.</param>
        /// <returns></returns>
        public Bitmap[] GetSequenceImages(Animation animation, ref List <int> durations)
        {
            durations.Clear();
            List <Bitmap> croppedFrames = new List <Bitmap>();
            List <int[]>  frames        = new List <int[]>();
            Rectangle     thisBounds    = new Rectangle();
            //
            Point UL = new Point(256, 256);
            Point BR = new Point(0, 0);

            foreach (Sequence.Frame frame in this.Frames)
            {
                Rectangle bounds = new Rectangle(0, 0, 1, 1);
                if (frame.Mold < animation.Molds.Count)
                {
                    int[] pixels = animation.Molds[frame.Mold].MoldPixels();
                    animation.Molds[frame.Mold].MoldTilesPerPixel = null;
                    frames.Add(pixels);
                    durations.Add(frame.Duration * (1000 / 60));
                    bounds = Do.Crop(pixels, 256, 256);
                }
                // if the mold is empty
                if (bounds.X == 0 &&
                    bounds.Y == 0 &&
                    bounds.Width == 1 &&
                    bounds.Height == 1)
                {
                    continue;
                }
                if (bounds.X < UL.X)
                {
                    UL.X = bounds.X;
                }
                if (bounds.Y < UL.Y)
                {
                    UL.Y = bounds.Y;
                }
                if (bounds.X + bounds.Width > BR.X)
                {
                    BR.X = bounds.X + bounds.Width;
                }
                if (bounds.Y + bounds.Height > BR.Y)
                {
                    BR.Y = bounds.Y + bounds.Height;
                }
            }
            if (UL.X >= BR.X ||
                UL.Y >= BR.Y)
            {
                return(croppedFrames.ToArray());
            }
            thisBounds.X      = UL.X;
            thisBounds.Y      = UL.Y;
            thisBounds.Width  = BR.X - UL.X;
            thisBounds.Height = BR.Y - UL.Y;
            foreach (int[] pixels in frames)
            {
                int[] cropped = Do.GetPixelRegion(pixels, thisBounds, 256, 256);
                Bits.Fill(cropped, Color.FromArgb(127, 127, 127).ToArgb(), true);
                Bitmap imageCropped = Do.PixelsToImage(cropped, thisBounds.Width, thisBounds.Height);
                croppedFrames.Add(new Bitmap(imageCropped));
            }
            return(croppedFrames.ToArray());
        }