Exemple #1
0
        public static ResourceTemplate RenderResourceType(ResourceTypeInfo info, string[] exts, Palette p)
        {
            var image = info.EditorSprite;
            using (var s = FileSystem.OpenWithExts(image, exts))
            {
                // TODO: Do this properly
                var shp = new ShpReader(s) as ISpriteSource;
                var frame = shp.Frames.Last();

                var bitmap = new Bitmap(frame.Size.Width, frame.Size.Height, PixelFormat.Format8bppIndexed);
                bitmap.Palette = p.AsSystemPalette();
                var data = bitmap.LockBits(bitmap.Bounds(),
                    ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

                unsafe
                {
                    byte* q = (byte*)data.Scan0.ToPointer();
                    var stride = data.Stride;

                    for (var i = 0; i < frame.Size.Width; i++)
                        for (var j = 0; j < frame.Size.Height; j++)
                            q[j * stride + i] = frame.Data[i + frame.Size.Width * j];
                }

                bitmap.UnlockBits(data);
                return new ResourceTemplate { Bitmap = bitmap, Info = info, Value = shp.Frames.Count() - 1 };
            }
        }
        public static ResourceTemplate RenderResourceType(ResourceTypeInfo info, string[] exts, Palette p)
        {
            var image = info.SpriteNames[0];
            using (var s = FileSystem.OpenWithExts(image, exts))
            {
                var shp = new ShpReader(s);
                var frame = shp[shp.ImageCount - 1];

                var bitmap = new Bitmap(shp.Width, shp.Height, PixelFormat.Format8bppIndexed);
                bitmap.Palette = p.AsSystemPalette();
                var data = bitmap.LockBits(bitmap.Bounds(),
                    ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

                unsafe
                {
                    byte* q = (byte*)data.Scan0.ToPointer();
                    var stride = data.Stride;

                    for (var i = 0; i < shp.Width; i++)
                        for (var j = 0; j < shp.Height; j++)
                            q[j * stride + i] = frame.Image[i + shp.Width * j];
                }

                bitmap.UnlockBits(data);
                return new ResourceTemplate { Bitmap = bitmap, Info = info, Value = shp.ImageCount - 1 };
            }
        }
Exemple #3
0
        public Bitmap RenderTemplate(ushort id, Palette p)
        {
            var template     = TileSet.Templates[id];
            var templateData = templates[id];

            var bitmap = new Bitmap(TileSize.Width * template.Size.X, TileSize.Height * template.Size.Y,
                                    PixelFormat.Format8bppIndexed);

            bitmap.Palette = p.AsSystemPalette();

            var data = bitmap.LockBits(bitmap.Bounds(),
                                       ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

            unsafe
            {
                var q      = (byte *)data.Scan0.ToPointer();
                var stride = data.Stride;

                for (var u = 0; u < template.Size.X; u++)
                {
                    for (var v = 0; v < template.Size.Y; v++)
                    {
                        if (templateData[u + v * template.Size.X] != null)
                        {
                            var rawImage = templateData[u + v * template.Size.X];
                            for (var i = 0; i < TileSize.Width; i++)
                            {
                                for (var j = 0; j < TileSize.Height; j++)
                                {
                                    q[(v * TileSize.Width + j) * stride + u * TileSize.Width + i] = rawImage[i + TileSize.Width * j];
                                }
                            }
                        }
                        else
                        {
                            for (var i = 0; i < TileSize.Width; i++)
                            {
                                for (var j = 0; j < TileSize.Height; j++)
                                {
                                    q[(v * TileSize.Width + j) * stride + u * TileSize.Width + i] = 0;
                                }
                            }
                        }
                    }
                }
            }

            bitmap.UnlockBits(data);
            return(bitmap);
        }
        public Bitmap RenderTemplate(ushort id, Palette p)
        {
            var template = TileSet.Templates[id];
            var templateData = templates[id];

            var bitmap = new Bitmap(TileSize.Width * template.Size.X, TileSize.Height * template.Size.Y,
                PixelFormat.Format8bppIndexed);

            bitmap.Palette = p.AsSystemPalette();

            var data = bitmap.LockBits(bitmap.Bounds(),
                ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

            unsafe
            {
                var q = (byte*)data.Scan0.ToPointer();
                var stride = data.Stride;

                for (var u = 0; u < template.Size.X; u++)
                {
                    for (var v = 0; v < template.Size.Y; v++)
                    {
                        var rawImage = templateData[u + v * template.Size.X];
                        if (rawImage != null && rawImage.Length > 0)
                        {
                            for (var i = 0; i < TileSize.Width; i++)
                                for (var j = 0; j < TileSize.Height; j++)
                                    q[(v * TileSize.Width + j) * stride + u * TileSize.Width + i] = rawImage[i + TileSize.Width * j];
                        }
                        else
                        {
                            for (var i = 0; i < TileSize.Width; i++)
                                for (var j = 0; j < TileSize.Height; j++)
                                    q[(v * TileSize.Width + j) * stride + u * TileSize.Width + i] = 0;
                        }
                    }
                }
            }

            bitmap.UnlockBits(data);
            return bitmap;
        }
Exemple #5
0
		public Bitmap RenderTemplate(ushort n, Palette p)
		{
			var template = Templates[n];

			var bitmap = new Bitmap(TileSize * template.Size.X, TileSize * template.Size.Y,
				PixelFormat.Format8bppIndexed);

			bitmap.Palette = p.AsSystemPalette();

			var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
				ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

			unsafe
			{
				byte* q = (byte*)data.Scan0.ToPointer();
				var stride = data.Stride;

				for (var u = 0; u < template.Size.X; u++)
					for (var v = 0; v < template.Size.Y; v++)
						if (template.Data.TileBitmapBytes[u + v * template.Size.X] != null)
						{
							var rawImage = template.Data.TileBitmapBytes[u + v * template.Size.X];
							for (var i = 0; i < TileSize; i++)
								for (var j = 0; j < TileSize; j++)
									q[(v * TileSize + j) * stride + u * TileSize + i] = rawImage[i + TileSize * j];
						}
						else
						{
							for (var i = 0; i < TileSize; i++)
								for (var j = 0; j < TileSize; j++)
									q[(v * TileSize + j) * stride + u * TileSize + i] = 0;
						}
			}

			bitmap.UnlockBits(data);
			return bitmap;
		}
Exemple #6
0
        public void CreateNewTileset()
        {
            this.Show();
            using (var fNew = new frmNew { })
            if (DialogResult.OK == fNew.ShowDialog())
            {
            PaletteFromImage = fNew.PaletteFromImage;
            PaletteFile = fNew.PaletteFile;
            ImageFile = fNew.ImageFile;
            TileSize = fNew.TileSize;

            srcfile = ImageFile;
            this.size = TileSize;
            surface1.TileSize = TileSize;

            Bitmap fbitmap = new Bitmap(ImageFile);
            Bitmap rbitmap = fbitmap.Clone(new Rectangle(0, 0, fbitmap.Width, fbitmap.Height),
                    fbitmap.PixelFormat);

            int[] ShadowIndex = { };

            if (!PaletteFromImage)
            {
                tpal = Palette.Load(PaletteFile, ShadowIndex);
                rbitmap.Palette = tpal.AsSystemPalette();
            }

            surface1.Image = (Bitmap)rbitmap;
            surface1.TilesPerRow = surface1.Image.Size.Width / surface1.TileSize;
            surface1.Image.SetResolution(96, 96); // people keep being noobs about DPI, and GDI+ cares.
            surface1.TerrainTypes = new int[surface1.Image.Width / size, surface1.Image.Height / size];		/* all passable by default */
            surface1.Templates = new List<Template>();
            surface1.Size = surface1.Image.Size;
            surface1.Enabled = true;
            Load();
            }
        }
Exemple #7
0
        public Bitmap RenderTemplate(ushort n, Palette p)
        {
            var template = Templates[n];

            var bitmap = new Bitmap(TileSize * template.Size.X, TileSize * template.Size.Y,
                PixelFormat.Format8bppIndexed);

            bitmap.Palette = p.AsSystemPalette();

            var data = bitmap.LockBits(bitmap.Bounds(),
                ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

            unsafe
            {
                byte* q = (byte*)data.Scan0.ToPointer();
                var stride = data.Stride;

                for (var u = 0; u < template.Size.X; u++)
                    for (var v = 0; v < template.Size.Y; v++)
                        if (template.Data.TileBitmapBytes[u + v * template.Size.X] != null)
                        {
                            var rawImage = template.Data.TileBitmapBytes[u + v * template.Size.X];
                            for (var i = 0; i < TileSize; i++)
                                for (var j = 0; j < TileSize; j++)
                                    q[(v * TileSize + j) * stride + u * TileSize + i] = rawImage[i + TileSize * j];
                        }
                        else
                        {
                            for (var i = 0; i < TileSize; i++)
                                for (var j = 0; j < TileSize; j++)
                                    q[(v * TileSize + j) * stride + u * TileSize + i] = 0;
                        }
            }

            bitmap.UnlockBits(data);
            return bitmap;
        }
        static Bitmap RenderShp(ShpReader shp, Palette p)
        {
            var frame = shp[0];

            var bitmap = new Bitmap(shp.Width, shp.Height, PixelFormat.Format8bppIndexed);

            bitmap.Palette = p.AsSystemPalette();

            var data = bitmap.LockBits(bitmap.Bounds(),
                ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

            unsafe
            {
                byte* q = (byte*)data.Scan0.ToPointer();
                var stride2 = data.Stride;

                for (var i = 0; i < shp.Width; i++)
                    for (var j = 0; j < shp.Height; j++)
                        q[j * stride2 + i] = frame.Image[i + shp.Width * j];
            }

            bitmap.UnlockBits(data);
            return bitmap;
        }
Exemple #9
0
        static Bitmap RenderShp(ISpriteSource shp, Palette p)
        {
            var frame = shp.Frames.First();

            var bitmap = new Bitmap(frame.Size.Width, frame.Size.Height, PixelFormat.Format8bppIndexed);

            bitmap.Palette = p.AsSystemPalette();

            var data = bitmap.LockBits(bitmap.Bounds(),
                ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

            unsafe
            {
                byte* q = (byte*)data.Scan0.ToPointer();
                var stride2 = data.Stride;

                for (var i = 0; i < frame.Size.Width; i++)
                    for (var j = 0; j < frame.Size.Height; j++)
                        q[j * stride2 + i] = frame.Data[i + frame.Size.Width * j];
            }

            bitmap.UnlockBits(data);
            return bitmap;
        }
Exemple #10
0
        public static Bitmap RenderTemplate(TileSet ts, ushort n, Palette p)
        {
            var template = ts.Templates[n];
            var tile = ts.Tiles[n];

            var bitmap = new Bitmap(ts.TileSize * template.Size.X, ts.TileSize * template.Size.Y,
                PixelFormat.Format8bppIndexed);

            bitmap.Palette = p.AsSystemPalette();

            var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

            unsafe
            {
                byte* q = (byte*)data.Scan0.ToPointer();
                var stride = data.Stride;

                for (var u = 0; u < template.Size.X; u++)
                    for (var v = 0; v < template.Size.Y; v++)
                        if (tile.TileBitmapBytes[u + v * template.Size.X] != null)
                        {
                            var rawImage = tile.TileBitmapBytes[u + v * template.Size.X];
                            for (var i = 0; i < ts.TileSize; i++)
                                for (var j = 0; j < ts.TileSize; j++)
                                    q[(v * ts.TileSize + j) * stride + u * ts.TileSize + i] = rawImage[i + ts.TileSize * j];
                        }
                        else
                        {
                            for (var i = 0; i < ts.TileSize; i++)
                                for (var j = 0; j < ts.TileSize; j++)
                                    q[(v * ts.TileSize + j) * stride + u * ts.TileSize + i] = 0;
                        }
            }

            bitmap.UnlockBits(data);
            return bitmap;
        }