コード例 #1
0
ファイル: Do.Controls.cs プロジェクト: jpmac26/LazyShell
        public static void DrawIcon(
            object sender, DrawItemEventArgs e, Preview preview, int iconIndex,
            Fonts.Glyph[] font, int[] palette, bool shadow, Bitmap bgimage)
        {
            // set the pixels
            var temp = preview.GetPreview(font, palette,
                                          new char[] { (char)(e.Index + iconIndex) }, shadow, false);

            int[] pixels = new int[256 * 14];
            for (int y = 0, c = 0; y < 14; y++, c++)
            {
                for (int x = 2, a = 0; x < 256; x++, a++)
                {
                    pixels[y * 256 + x] = temp[c * 256 + a];
                }
            }
            if (bgimage != null)
            {
                var background = new Rectangle(0, e.Index * 15 % bgimage.Height, bgimage.Width, 15);
                e.Graphics.DrawImage(bgimage, e.Bounds.X, e.Bounds.Y, background, GraphicsUnit.Pixel);
            }
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e.DrawBackground();
            }
            e.Graphics.DrawImage(Do.PixelsToImage(pixels, 256, 14), new Point(e.Bounds.X, e.Bounds.Y));
        }
コード例 #2
0
ファイル: CopyBuffer.cs プロジェクト: jpmac26/LazyShell
 /// <summary>
 /// Creates a bitmap of the copied tiles.
 /// </summary>
 public Bitmap GetImage()
 {
     if (Tiles != null && Pixels == null)
     {
         return(Do.PixelsToImage(Do.TilesetToPixels(Tiles, Width / 16, Height / 16, 0, false), Width, Height));
     }
     if (Tiles == null && Pixels != null)
     {
         return(Do.PixelsToImage(Pixels, Width, Height));
     }
     return(null);
 }
コード例 #3
0
ファイル: TileEditor.cs プロジェクト: jpmac26/LazyShell
 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();
 }
コード例 #4
0
 //
 public void SetTilesetImage()
 {
     if (Tileset.Tilesets_tiles[Layer] != null)
     {
         int   height          = Layer < 2 ? Tileset.Height : Tileset.HeightL3;
         int[] tileSetPixels   = Do.TilesetToPixels(Tileset.Tilesets_tiles[Layer], 16, height, 0, false);
         int[] priority1Pixels = Do.TilesetToPixels(Tileset.Tilesets_tiles[Layer], 16, height, 0, true);
         tilesetImage   = Do.PixelsToImage(tileSetPixels, 256, height * 16);
         priority1      = Do.PixelsToImage(priority1Pixels, 256, height * 16);
         Picture.Height = height * 16;
     }
     else
     {
         tilesetImage   = null;
         priority1      = null;
         Picture.Height = 0;
     }
     Picture.Invalidate();
 }
コード例 #5
0
ファイル: Do.Controls.cs プロジェクト: jpmac26/LazyShell
        public static void DrawName(
            object sender, DrawItemEventArgs e, Preview preview, string[] names,
            Fonts.Glyph[] font, int[] palette, int xOffset, int yOffset,
            int startIndex, int endIndex, bool lastEmpty, bool shadow, Bitmap bgimage)
        {
            if (e.Index < 0 || e.Index >= names.Length)
            {
                return;
            }
            string name = names[e.Index];

            // set the pixels
            var temp   = preview.GetPreview(font, palette, name.ToCharArray(), shadow, false);
            var pixels = new int[256 * 32];

            for (int y = 0, c = yOffset; y < 14; y++, c++)
            {
                for (int x = 2, a = xOffset; x < 256; x++, a++)
                {
                    pixels[y * 256 + x] = temp[c * 256 + a];
                }
            }
            if (bgimage != null)
            {
                var background = new Rectangle(0, e.Index * 16 % bgimage.Height, bgimage.Width, 16);
                e.Graphics.DrawImage(bgimage, e.Bounds.X, e.Bounds.Y, background, GraphicsUnit.Pixel);
            }
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e.DrawBackground();
            }
            if (lastEmpty && e.Index == names.Length - 1)
            {
                e.Graphics.DrawString("*** NOTHING ***", new Font("Arial Black", 7F), Brushes.White, e.Bounds.Location);
            }
            else
            {
                e.Graphics.DrawImage(Do.PixelsToImage(pixels, 256, 15), e.Bounds.Location);
            }
        }
コード例 #6
0
ファイル: TileEditor.cs プロジェクト: jpmac26/LazyShell
 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();
 }
コード例 #7
0
ファイル: PaletteEditor.cs プロジェクト: jpmac26/LazyShell
 private void SetPaletteImage()
 {
     palettePixels = Do.PaletteToPixels(paletteSet.Palettes, 12, 12, 16, count, startRow, 0);
     paletteImage  = Do.PixelsToImage(palettePixels, 192, (count * 12) - (startRow * 12));
     pictureBoxPalette.Invalidate();
 }
コード例 #8
0
ファイル: PaletteEditor.cs プロジェクト: jpmac26/LazyShell
        private void SetColorMapImage()
        {
            int width  = pictureBoxColorMap.Width;
            int height = pictureBoxColorMap.Height;

            //
            colorMapPixels = new int[width * height];
            int r = 248, g = 0, b = 0;
            int l            = -248;
            int lumIncrement = height / 24;

            for (int y = 0; y < height; y++, l += y % 3 == 0 ? 6 : 0)
            {
                int x        = 0;
                int colWidth = width / 6;
                for (int a = 0; a < colWidth; a++, x++, g += 8)
                {
                    colorMapPixels[y * width + x] = Color.FromArgb(
                        Math.Min(Math.Max(r + l, 0), 248),
                        Math.Min(Math.Max(g + l, 0), 248),
                        Math.Min(Math.Max(b + l, 0), 248)).ToArgb();
                }
                for (int a = 0; a < colWidth; a++, x++, r -= 8)
                {
                    colorMapPixels[y * width + x] = Color.FromArgb(
                        Math.Min(Math.Max(r + l, 0), 248),
                        Math.Min(Math.Max(g + l, 0), 248),
                        Math.Min(Math.Max(b + l, 0), 248)).ToArgb();
                }
                for (int a = 0; a < colWidth; a++, x++, b += 8)
                {
                    colorMapPixels[y * width + x] = Color.FromArgb(
                        Math.Min(Math.Max(r + l, 0), 248),
                        Math.Min(Math.Max(g + l, 0), 248),
                        Math.Min(Math.Max(b + l, 0), 248)).ToArgb();
                }
                for (int a = 0; a < colWidth; a++, x++, g -= 8)
                {
                    colorMapPixels[y * width + x] = Color.FromArgb(
                        Math.Min(Math.Max(r + l, 0), 248),
                        Math.Min(Math.Max(g + l, 0), 248),
                        Math.Min(Math.Max(b + l, 0), 248)).ToArgb();
                }
                for (int a = 0; a < colWidth; a++, x++, r += 8)
                {
                    colorMapPixels[y * width + x] = Color.FromArgb(
                        Math.Min(Math.Max(r + l, 0), 248),
                        Math.Min(Math.Max(g + l, 0), 248),
                        Math.Min(Math.Max(b + l, 0), 248)).ToArgb();
                }
                for (int a = 0; a < colWidth; a++, x++, b -= 8)
                {
                    colorMapPixels[y * width + x] = Color.FromArgb(
                        Math.Min(Math.Max(r + l, 0), 248),
                        Math.Min(Math.Max(g + l, 0), 248),
                        Math.Min(Math.Max(b + l, 0), 248)).ToArgb();
                }
            }
            colorMapImage = Do.PixelsToImage(colorMapPixels, width, height);
            pictureBoxColorMap.Invalidate();
        }
コード例 #9
0
 public static Bitmap Hilite(Bitmap image, int width, int height)
 {
     int[] src = Do.ImageToPixels(image);
     int[] dst = Hilite(src, width, height);
     return(Do.PixelsToImage(dst, width, height));
 }
コード例 #10
0
ファイル: ExportImages.cs プロジェクト: jpmac26/LazyShell
 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);
         }
     }
 }
コード例 #11
0
ファイル: Do.Controls.cs プロジェクト: jpmac26/LazyShell
        public static void DrawText(string text, int x, int y, Graphics g, Preview preview, Fonts.Glyph[] font, int[] palette)
        {
            var temp = preview.GetPreview(font, palette, text.ToCharArray(), false, false);

            g.DrawImage(Do.PixelsToImage(temp, 256, 14), x, y);
        }