예제 #1
0
 /// <summary>
 /// Performs a color math operation by applying the values of an RGB pixel array to another.
 /// The result is drawn over a specified destination pixel array, ignoring transparent pixels.
 /// All arrays must be the same size.
 /// </summary>
 /// <param name="src">The pixels to apply to the operand array.</param>
 /// <param name="operand">The RGB pixel array to perform the operation on.
 /// The original referenced array is not modified during the operation.</param>
 /// <param name="dst">The RGB pixel array draw the result over.</param>
 /// <param name="width">The width, in pixels, of the pixel maps.</param>
 /// <param name="height">The height, in pixels, of the pixel maps.</param>
 /// <param name="halfIntensity">Indicates whether to add the pixels at half their RGB value.</param>
 /// <param name="minusSubscreen">Indicates whether to subtract the pixels instead of adding them.</param>
 public static void ColorMath(int[] src, int[] operand, int[] dst, int width, int height, bool halfIntensity, bool minusSubscreen)
 {
     if (src == null || operand == null || dst == null)
     {
         return;
     }
     int[] pixels = Bits.Copy(operand);
     // Apply subscreen to priority layer pixels using color math
     Do.ColorMath(src, pixels, width, height, halfIntensity, minusSubscreen);
     // Draw color math result to this instance's RGB pixel array
     Do.PixelsToPixels(pixels, dst, true);
 }
예제 #2
0
 private void SetSubtileImage()
 {
     int[] temp   = new int[8 * 8];
     int[] pixels = new int[64 * 64];
     Do.PixelsToPixels(
         tile.Subtiles[currentSubtile].Pixels,
         temp, 8, new Rectangle(0, 0, 8, 8));
     for (int y = 0; y < 64; y++)
     {
         for (int x = 0; x < 64; x++)
         {
             pixels[y * 64 + x] = temp[y / 8 * 8 + (x / 8)];
         }
     }
     subtileImage = Do.PixelsToImage(pixels, 64, 64);
     pictureBoxSubtile.Invalidate();
 }
예제 #3
0
 private void SetTileImage()
 {
     int[] temp   = new int[16 * 16];
     int[] pixels = new int[64 * 64];
     for (int y = 0; y < 2; y++)
     {
         for (int x = 0; x < 2; x++)
         {
             Do.PixelsToPixels(
                 tile.Subtiles[y * 2 + x].Pixels,
                 temp, 16, new Rectangle(x * 8, y * 8, 8, 8));
         }
     }
     for (int y = 0; y < 64; y++)
     {
         for (int x = 0; x < 64; x++)
         {
             pixels[y * 64 + x] = temp[y / 4 * 16 + (x / 4)];
         }
     }
     tileImage = Do.PixelsToImage(pixels, 64, 64);
     pictureBoxTile.Invalidate();
 }
예제 #4
0
 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;
         }
         Sprites.Sprite s = null;
         if (element == ElementType.Area)
         {
             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 == ElementType.Sprite)
         {
             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 == ElementType.Area)
         {
             var       map        = maps[areas[a].Map];
             var       layering   = areas[a].Layering;
             var       paletteSet = paletteSets[maps[areas[a].Map].PaletteSet];
             var       tileset    = new Tileset(map, paletteSet);
             var       tilemap    = new Areas.AreaTilemap(areas[a], tileset);
             int[]     pixels;
             Rectangle region;
             if (crop)
             {
                 region = new Rectangle(
                     layering.MaskLowX * 16, layering.MaskLowY * 16,
                     (layering.MaskHighX - layering.MaskLowX) * 16 + 16,
                     (layering.MaskHighY - layering.MaskLowY) * 16 + 16);
                 pixels = Do.GetPixelRegion(tilemap.Pixels, region, 1024, 1024);
             }
             else
             {
                 region = new Rectangle(0, 0, 1024, 1024);
                 pixels = tilemap.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)
         {
             var animation = animations[s.AnimationPacket];
             foreach (var m in animation.Molds)
             {
                 foreach (var t in m.Tiles)
                 {
                     t.DrawSubtiles(s.Graphics, s.Palette, m.Gridplane);
                 }
             }
             foreach (var 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 (var m in animations[s.AnimationPacket].Molds)
         {
             foreach (var t in m.Tiles)
             {
                 t.DrawSubtiles(
                     images[s.ImageNum].Graphics(spriteGraphics),
                     palettes[images[s.ImageNum].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);
         }
     }
 }