Esempio n. 1
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);
            var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            unsafe
            {
                int* q = (int*)data.Scan0.ToPointer();
                var stride = data.Stride >> 2;

                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] = p.GetColor(rawImage[i + ts.TileSize * j]).ToArgb();
                        }
                        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] = Color.Transparent.ToArgb();
                        }
            }

            bitmap.UnlockBits(data);
            return bitmap;
        }
Esempio n. 2
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 };
            }
        }
Esempio n. 3
0
        public static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, Palette p)
        {
            var image = RenderSimple.GetImage(info, tileset.Id);

            using (var s = FileSystem.OpenWithExts(image, tileset.Extensions))
            {
                var shp = new ShpReader(s);
                var bitmap = RenderShp(shp, p);

                try
                {
                    using (var s2 = FileSystem.OpenWithExts(image + "2", tileset.Extensions))
                    {
                        var shp2 = new ShpReader(s2);
                        var roofBitmap = RenderShp(shp2, p);

                        using (var g = System.Drawing.Graphics.FromImage(bitmap))
                            g.DrawImage(roofBitmap, 0, 0);
                    }
                }
                catch { }

                return new ActorTemplate
                {
                    Bitmap = bitmap,
                    Info = info,
                    Appearance = info.Traits.GetOrDefault<EditorAppearanceInfo>()
                };
            }
        }
Esempio n. 4
0
        static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, Palette p)
        {
            var ri = info.Traits.Get<RenderSimpleInfo>();
            string image = null;
            if (ri.OverrideTheater != null)
                for (int i = 0; i < ri.OverrideTheater.Length; i++)
                    if (ri.OverrideTheater[i] == tileset.Id)
                        image = ri.OverrideImage[i];

            image = image ?? ri.Image ?? info.Name;
            using (var s = FileSystem.OpenWithExts(image, tileset.Extensions))
            {
                var shp = new ShpReader(s);
                var frame = shp[0];

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

                unsafe
                {
                    int* q = (int*)data.Scan0.ToPointer();
                    var stride = data.Stride >> 2;

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

                bitmap.UnlockBits(data);
                return new ActorTemplate { Bitmap = bitmap, Info = info, Centered = !info.Traits.Contains<BuildingInfo>() };
            }
        }
Esempio n. 5
0
        public static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, Palette p)
        {
            var ri = info.Traits.Get<RenderSimpleInfo>();
            string image = null;
            if (ri.OverrideTheater != null)
                for (int i = 0; i < ri.OverrideTheater.Length; i++)
                    if (ri.OverrideTheater[i] == tileset.Id)
                        image = ri.OverrideImage[i];

            image = image ?? ri.Image ?? info.Name;
            using (var s = FileSystem.OpenWithExts(image, tileset.Extensions))
            {
                var shp = new ShpReader(s);
                var bitmap = RenderShp(shp, p);

                try
                {
                    using (var s2 = FileSystem.OpenWithExts(image + "2", tileset.Extensions))
                    {
                        var shp2 = new ShpReader(s2);
                        var roofBitmap = RenderShp(shp2, p);

                        using (var g = System.Drawing.Graphics.FromImage(bitmap))
                            g.DrawImage(roofBitmap, 0, 0);
                    }
                }
                catch { }

                return new ActorTemplate { Bitmap = bitmap, Info = info, Centered = !info.Traits.Contains<BuildingInfo>() };
            }
        }
Esempio n. 6
0
        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 = MakeSystemPalette(p);
                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 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 };
            }
        }
Esempio n. 7
0
		public void Bind(Map m, TileSet ts, Palette p)
		{
			Map = m;
			TileSet = ts;
			Palette = p;
			Brush = null;
			Chunks.Clear();
		}
Esempio n. 8
0
		public void Bind(Map m, TileSet ts, Palette p)
		{
			Map = m;
			TileSet = ts;
			Palette = p;
			PlayerPalettes = null;
			Chunks.Clear();
			Tool = null;
		}
Esempio n. 9
0
        public static ColorPalette MakeSystemPalette(Palette p)
        {
            ColorPalette pal;
            using (var b = new Bitmap(1, 1, PixelFormat.Format8bppIndexed))
                pal = b.Palette;

            for (var i = 0; i < 256; i++)
                pal.Entries[i] = p.GetColor(i);
            return pal;
        }
Esempio n. 10
0
		public void Bind(Map m, TileSet ts, TileSetRenderer tsr, Palette p, Palette pp)
		{
			Map = m;
			TileSet = ts;
			TileSetRenderer = tsr;
			Palette = p;
			PlayerPalette = pp;
			playerPalettes = null;
			Chunks.Clear();
			currentTool = null;
		}
Esempio n. 11
0
        public PlayerColorPalette(Actor self, PlayerColorPaletteInfo info)
        {
            var wr = self.World.WorldRenderer;
            var pal = wr.GetPalette(info.BasePalette);
            var newpal = new Palette(pal, new PlayerColorRemap(
                        Util.ArrayToColor(info.Color1),
                        Util.ArrayToColor(info.Color2),
                        info.SplitRamp));

            wr.AddPalette(info.Name, newpal);
        }
Esempio n. 12
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++)
                    {
                        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;
        }
Esempio n. 13
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;
        }
        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;
        }
Esempio n. 15
0
        static void Main( string[] args )
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length != 3)
            {
                MessageBox.Show( "usage: SequenceEditor mod[,mod]* sequences-file.xml palette.pal");
                return;
            }

            var mods = args[0].Split(',');
            var manifest = new Manifest(mods);
            FileSystem.LoadFromManifest( manifest );

            XmlFilename = args[1];
            Doc = new XmlDocument();
            Doc.Load(XmlFilename);

            var tempPal = new Palette(FileSystem.Open(args[2]), true);
            Pal = tempPal;

            UnitName = GetTextForm.GetString("Unit to edit?", "e1");
            if (string.IsNullOrEmpty(UnitName))
                return;

            LoadAndResolve(UnitName);

            var xpath = string.Format("//unit[@name=\"{0}\"]/sequence", UnitName);
            foreach (XmlElement e in Doc.SelectNodes(xpath))
            {
                if (e.HasAttribute("src"))
                    LoadAndResolve(e.GetAttribute("src"));
                Sequences[e.GetAttribute("name")] = new Sequence(e);
            }

            Application.Run(new Form1());
        }
Esempio n. 16
0
 public Palette(Palette p)
 {
     colors = (uint[])p.colors.Clone();
 }
Esempio n. 17
0
 public Palette(Palette p, IPaletteRemap r)
 {
     colors = new uint[256];
     for(int i = 0; i < 256; i++)
         colors[i] = (uint)r.GetRemappedColor(Color.FromArgb((int)p.colors[i]),i).ToArgb();
 }
Esempio n. 18
0
        void PrepareMapResources(Manifest manifest, Map map)
        {
            Rules.LoadRules(manifest, map);
            tileset = Rules.TileSets[map.Theater];
            tileset.LoadTiles();
            var palette = new Palette(FileSystem.Open(tileset.Palette), true);

            surface1.Bind(map, tileset, palette);

            // construct the palette of tiles
            var palettes = new[] { tilePalette, actorPalette, resourcePalette };
            foreach (var p in palettes) { p.Visible = false; p.SuspendLayout(); }

            foreach (var t in tileset.Templates)
            {
                try
                {
                    var bitmap = RenderTemplate(tileset, (ushort)t.Key, palette);
                    var ibox = new PictureBox
                    {
                        Image = bitmap,
                        Width = bitmap.Width / 2,
                        Height = bitmap.Height / 2,
                        SizeMode = PictureBoxSizeMode.StretchImage
                    };

                    var brushTemplate = new BrushTemplate { Bitmap = bitmap, N = t.Key };
                    ibox.Click += (_, e) => surface1.SetBrush(brushTemplate);

                    var template = t.Value;
                    tilePalette.Controls.Add(ibox);

                    tt.SetToolTip(ibox,
                        "{1}:{0} ({2}x{3})".F(
                        template.Image,
                        template.Id,
                        template.Size.X,
                        template.Size.Y));
                }
                catch { }
            }

            var actorTemplates = new List<ActorTemplate>();

            foreach (var a in Rules.Info.Keys)
            {
                try
                {
                    var info = Rules.Info[a];
                    if( !info.Traits.Contains<RenderSimpleInfo>() ) continue;
                    var template = RenderActor(info, tileset, palette);
                    var ibox = new PictureBox
                    {
                        Image = template.Bitmap,
                        Width = template.Bitmap.Width / 2,
                        Height = template.Bitmap.Height / 2,
                        SizeMode = PictureBoxSizeMode.StretchImage
                    };

                    ibox.Click += (_, e) => surface1.SetActor(template);

                    actorPalette.Controls.Add(ibox);

                    tt.SetToolTip(ibox,
                        "{0}:{1}".F(
                        info.Name,
                        info.Category));

                    actorTemplates.Add(template);
                }
                catch { }
            }

            surface1.BindActorTemplates(actorTemplates);

            var resourceTemplates = new List<ResourceTemplate>();

            foreach (var a in Rules.Info["world"].Traits.WithInterface<ResourceTypeInfo>())
            {
                try
                {
                    var template = RenderResourceType(a, tileset.Extensions, palette);
                    var ibox = new PictureBox
                    {
                        Image = template.Bitmap,
                        Width = template.Bitmap.Width,
                        Height = template.Bitmap.Height,
                        SizeMode = PictureBoxSizeMode.StretchImage
                    };

                    ibox.Click += (_, e) => surface1.SetResource(template);

                    resourcePalette.Controls.Add(ibox);

                    tt.SetToolTip(ibox,
                        "{0}:{1}cr".F(
                        template.Info.Name,
                        template.Info.ValuePerUnit));

                    resourceTemplates.Add(template);
                }
                catch { }
            }

            surface1.BindResourceTemplates(resourceTemplates);

            foreach (var p in palettes) { p.Visible = true; p.ResumeLayout(); }
        }
Esempio n. 19
0
 public Palette(Palette p, IPaletteRemap r)
 {
     colors = (uint[])p.colors.Clone();
     ApplyRemap(r);
 }
Esempio n. 20
0
        public static void ConvertTmpToPng(string[] args)
        {
            var mods = args[1].Split(',');
            var theater = args[2];
            var templateNames = args.Skip(3);

            var manifest = new Manifest(mods);
            FileSystem.LoadFromManifest(manifest);

            var tileset = manifest.TileSets.Select( a => new TileSet(a) )
                .FirstOrDefault( ts => ts.Name == theater );

            if (tileset == null)
                throw new InvalidOperationException("No theater named '{0}'".F(theater));

            tileset.LoadTiles();
            var palette = new Palette(FileSystem.Open(tileset.Palette), true);

            foreach( var templateName in templateNames )
            {
                var template = tileset.Templates.FirstOrDefault(tt => tt.Value.Image == templateName);
                if (template.Value == null)
                    throw new InvalidOperationException("No such template '{0}'".F(templateName));

                using( var image = tileset.RenderTemplate(template.Value.Id, palette) )
                    image.Save( Path.ChangeExtension( templateName, ".png" ) );
            }
        }
Esempio n. 21
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;
        }
Esempio n. 22
0
 public Palette(Palette p, IPaletteRemap r)
 {
     for (int i = 0; i < 256; i++)
         colors.Add(r.GetRemappedColor(p.GetColor(i), i));
 }
Esempio n. 23
0
 public void RegisterPlayerColor(World world, string palette)
 {
     var info = Rules.Info["world"].Traits.Get<PlayerColorPaletteInfo>();
     var newpal = new Palette(world.WorldRenderer.GetPalette(info.BasePalette),
                      new PlayerColorRemap(Color, Color2, info.PaletteFormat));
     world.WorldRenderer.AddPalette(palette, newpal);
 }
Esempio n. 24
0
 public Palette(Palette p)
 {
     colors = (uint[])p.colors.Clone();
 }
Esempio n. 25
0
        public Bitmap RenderShp(Palette p, int pos)
        {
            int swidth = 0;
            int sheight = 0;
            byte hk;
            byte s;
            byte l;

            if (oldshp == false)
                {swidth = shp.Width; sheight = shp.Height;}

            if (oldshp == true)
                {swidth = shpold.Width; sheight = shpold.Height;}

            hk = Convert.ToByte(pbColor.BackColor.GetHue()*0.7+1);
            s = Convert.ToByte(pbColor.BackColor.GetSaturation()*255);
            l = Convert.ToByte(pbColor.BackColor.GetBrightness() * 255);

            ColorRamp CRamp = new ColorRamp(hk, s, l, 25);
            if (mnuRemap.Checked)
            {
                p = new Palette(p, new PlayerColorRemap(CRamp, palf));
            }
            CRamp.GetColor(0).ToArgb();
            var bitmap = new Bitmap(swidth, sheight);
            var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            unsafe
            {
                int* q = (int*)data.Scan0.ToPointer();
                var stride2 = data.Stride >> 2;
                for (var i = 0; i < swidth; i++)
                    for (var j = 0; j < sheight; j++)
                    {
                        if (oldshp == false)
                        { var frame = shp[pos]; q[j * stride2 + i] = p.GetColor(frame.Image[i + swidth * j]).ToArgb(); }
                        if (oldshp == true)
                        { var frame = shpold[pos]; q[j * stride2 + i] = p.GetColor(frame.Image[i + swidth * j]).ToArgb(); }

                    }
            }
            bitmap.UnlockBits(data);

            return bitmap;
        }
Esempio n. 26
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;
        }
Esempio n. 27
0
        public void ApplyNewPalettePNG(string palette)
        {
            lastpal = palette;

            FileStream F = new FileStream(palette, FileMode.Open, FileAccess.Read);
            var p = new Palette(F, transparentColorsToolStripMenuItem.Checked);
            F.Close();

            fnum = tbPlay.Value;
            Frame = new Bitmap(png.ToBitmap(fnum).Width, png.ToBitmap(fnum).Height);
            if (png.NumEmbeddedPNG > 1)
            {
                if (shadowToolStripMenuItem.Checked)
                {
                    var bitmap = new Bitmap(png.ToBitmap(fnum).Width, png.ToBitmap(fnum).Height);
                    var fbitmap = new Bitmap(png.ToBitmap(fnum).Width, png.ToBitmap(fnum).Height);
                    var obitmap = new Bitmap(png.ToBitmap(fnum).Width, png.ToBitmap(fnum).Height);
                    int limit = (int)(png.NumEmbeddedPNG / 2);
                    frcx = new int[1];
                    frcy = new int[1];
                    frcx[0] = 0;
                    frcy[0] = 0;
                    bitmap = RenderPNG(p, fnum - 1);
                    obitmap = RenderPNG(p, fnum - 1);
                    fbitmap = RenderPNG(p, (fnum + limit - 1));
                    using (var g = System.Drawing.Graphics.FromImage(fbitmap))
                        g.DrawImage(obitmap, 0, 0);
                    using (var g = System.Drawing.Graphics.FromImage(bitmap))
                        g.DrawImage(fbitmap, 0, 0);
                    tbPlay.Maximum = limit;
                    Frame = bitmap;
                }
                if (turretToolStripMenuItem.Checked)
                {
                    var bitmap = new Bitmap(png.ToBitmap(fnum).Width, png.ToBitmap(fnum).Height);
                    var fbitmap = new Bitmap(png.ToBitmap(fnum).Width, png.ToBitmap(fnum).Height);
                    int limit = (int)(png.NumEmbeddedPNG / 2);
                    if ((shadowToolStripMenuItem.Checked))
                    {
                        limit = (int)(limit / 2);
                    }
                    frcx = new int[1];
                    frcy = new int[1];
                    frcx[0] = 0;
                    frcy[0] = 0;
                    int tnum = 0;
                    bitmap = RenderPNG(p, fnum - 1);
                    tnum = tbTurret.Value + limit;
                    fbitmap = RenderPNG(p, (tnum));
                    using (var g = System.Drawing.Graphics.FromImage(bitmap))
                        g.DrawImage(fbitmap, (int)numTurretOffsetX.Value, (int)numTurretOffsetY.Value);
                    Frame = bitmap;
                    tbPlay.Maximum = limit;
                    tbTurret.Maximum = limit - 1;
                }
            }
            else
            {
                Frame = RenderPNG(p, fnum - 1);
                frcx = new int[1];
                frcy = new int[1];
                frcx[0] = 0;
                frcy[0] = 0;
                tbPlay.Maximum = png.NumEmbeddedPNG - 1;
            }

            if ((turretToolStripMenuItem.Checked == false) && (shadowToolStripMenuItem.Checked == false))
            {
                Frame = RenderPNG(p, fnum - 1);
                frcx = new int[1];
                frcy = new int[1];
                frcx[0] = 0;
                frcy[0] = 0;
                tbPlay.Maximum = png.NumEmbeddedPNG - 1;
            }

            bLoaded = true;

            if (bLoaded)
            {
                if (turretToolStripMenuItem.Checked)
                {
                    gpTurretOffset.Enabled = true;
                }
                else
                {
                    gpTurretOffset.Enabled = false;
                }
            }
            pbFrame.Image = Frame;
            txtX.Text = Convert.ToString(Frame.Width);
            txtY.Text = Convert.ToString(Frame.Height);
            txtCX.Text = Convert.ToString(frcx[0]);
            txtCY.Text = Convert.ToString(frcy[0]);
        }
Esempio n. 28
0
        static Bitmap RenderShp(ShpReader shp, Palette p)
        {
            var frame = shp[0];

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

            unsafe
            {
                int* q = (int*)data.Scan0.ToPointer();
                var stride2 = data.Stride >> 2;

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

            bitmap.UnlockBits(data);
            return bitmap;
        }
Esempio n. 29
0
        public void ExportFrames(string palette, string filename, ImageFormat ExportFormat)
        {
            lastpal = palette;

            if (oldshp == false)
            {
                FramesEx = new Image[shp.ImageCount + 1];
                BitmapEx = new Bitmap[shp.ImageCount + 1];
                FramesEx[0] = new Bitmap(shp.Width, shp.Height);

                for (int i = 1; i <= (int)(shp.ImageCount / 2); i++)
                {
                    FileStream P = new FileStream(palette, FileMode.Open, FileAccess.Read);
                    var p = new Palette(P, true);
                    P.Close();
                    FramesEx[i] = RenderShp(p, i - 1);
                }
                for (int i = (int)(shp.ImageCount / 2); i <= shp.ImageCount; i++)
                {
                    FileStream P = new FileStream(palette, FileMode.Open, FileAccess.Read);
                    var p = new Palette(P, transparentColorsToolStripMenuItem.Checked);
                    P.Close();
                    FramesEx[i] = RenderShp(p, i - 1);
                }
                if (shp.ImageCount > 1)
                {
                    if (shadowToolStripMenuItem.Checked)
                    {
                        if (shp.ImageCount > 1)
                        {
                            var bitmap = new Bitmap(shp.Width, shp.Height);
                            var fbitmap = new Bitmap(shp.Width, shp.Height);
                            var obitmap = new Bitmap(shp.Width, shp.Height);

                            for (int i = 1; i <= (int)(shp.ImageCount / 2); i++)
                            {
                                BitmapEx[i] = new Bitmap(shp.Width, shp.Height);
                                bitmap = (Bitmap)FramesEx[i];
                                obitmap = (Bitmap)FramesEx[i];
                                fbitmap = (Bitmap)FramesEx[i + (int)(shp.ImageCount / 2)];
                                using (var g = System.Drawing.Graphics.FromImage(fbitmap))
                                    g.DrawImage(obitmap, 0, 0);
                                using (var g = System.Drawing.Graphics.FromImage(bitmap))
                                    g.DrawImage(fbitmap, 0, 0);
                                BitmapEx[i] = bitmap;
                            }
                            frexp = (int)(shp.ImageCount / 2);
                        }
                    }
                    if (turretToolStripMenuItem.Checked)
                    {
                        if (shp.ImageCount > 1)
                        {
                            var bitmap = new Bitmap(shp.Width, shp.Height);
                            var fbitmap = new Bitmap(shp.Width, shp.Height);
                            int limit = (int)(shp.ImageCount / 2);
                            if ((shadowToolStripMenuItem.Checked) || (palf == PaletteFormat.ts))
                            {
                                limit = (int)(limit / 2);
                            }

                            for (int i = 1; i <= limit; i++)
                            {
                                BitmapEx[i] = new Bitmap(shp.Width, shp.Height);
                                bitmap = (Bitmap)FramesEx[i];
                                fbitmap = (Bitmap)FramesEx[i + limit];

                                using (var g = System.Drawing.Graphics.FromImage(bitmap))
                                    g.DrawImage(fbitmap, (int)numTurretOffsetX.Value, (int)numTurretOffsetY.Value);
                                BitmapEx[i] = bitmap;
                            }
                            frexp = limit;
                        }
                    }
                }
                else
                {
                    for (int i = 1; i <= shp.ImageCount; i++)
                    {
                        BitmapEx[i] = new Bitmap(shp.Width, shp.Height);
                        BitmapEx[i] = (Bitmap)FramesEx[i];
                    }
                    frexp = shp.ImageCount;
                }
                if ((turretToolStripMenuItem.Checked == false) && (shadowToolStripMenuItem.Checked == false))
                {

                    for (int i = 1; i <= shp.ImageCount; i++)
                    {
                        BitmapEx[i] = new Bitmap(shp.Width, shp.Height);
                        BitmapEx[i] = (Bitmap)FramesEx[i];
                    }
                    frexp = shp.ImageCount;
                }
            }
            if (oldshp == true)
            {
                FramesEx = new Image[shpold.ImageCount + 1];
                BitmapEx = new Bitmap[shpold.ImageCount + 1];
                FramesEx[0] = new Bitmap(shpold.Width, shpold.Height);
                for (int i = 1; i <= (int)(shpold.ImageCount / 2); i++)
                {
                    FileStream P = new FileStream(palette, FileMode.Open, FileAccess.Read);
                    var p = new Palette(P, transparentColorsToolStripMenuItem.Checked);
                    P.Close();
                    FramesEx[i] = RenderShp(p, i - 1);
                }
                for (int i = (int)(shpold.ImageCount / 2); i <= shpold.ImageCount; i++)
                {
                    FileStream P = new FileStream(palette, FileMode.Open, FileAccess.Read);
                    var p = new Palette(P, transparentColorsToolStripMenuItem.Checked);
                    P.Close();
                    FramesEx[i] = RenderShp(p, i - 1);
                }
                if (shpold.ImageCount > 1)
                {
                if (shadowToolStripMenuItem.Checked)
                {
                    if (shpold.ImageCount > 1)
                    {
                        var bitmap = new Bitmap(shpold.Width, shpold.Height);
                        var fbitmap = new Bitmap(shpold.Width, shpold.Height);
                        var obitmap = new Bitmap(shpold.Width, shpold.Height);

                        for (int i = 1; i <= (int)(shpold.ImageCount / 2); i++)
                        {
                            BitmapEx[i] = new Bitmap(shpold.Width, shpold.Height);
                            bitmap = (Bitmap)FramesEx[i];
                            obitmap = (Bitmap)FramesEx[i];
                            fbitmap = (Bitmap)FramesEx[i + (int)(shpold.ImageCount / 2)];
                            using (var g = System.Drawing.Graphics.FromImage(fbitmap))
                                g.DrawImage(obitmap, 0, 0);
                            using (var g = System.Drawing.Graphics.FromImage(bitmap))
                                g.DrawImage(fbitmap, 0, 0);
                            BitmapEx[i] = bitmap;
                        }
                        frexp = (int)(shpold.ImageCount / 2);
                    }
                }
                if (turretToolStripMenuItem.Checked)
                {
                    if (shpold.ImageCount > 1)
                    {
                        var bitmap = new Bitmap(shpold.Width, shpold.Height);
                        var fbitmap = new Bitmap(shpold.Width, shpold.Height);
                        int limit = (int)(shpold.ImageCount / 2);
                        if ((shadowToolStripMenuItem.Checked) || (palf == PaletteFormat.ts))
                        {
                            limit = (int)(limit / 2);
                        }

                        for (int i = 1; i <= limit; i++)
                        {
                            BitmapEx[i] = new Bitmap(shpold.Width, shpold.Height);
                            bitmap = (Bitmap)FramesEx[i];
                            fbitmap = (Bitmap)FramesEx[i + limit];
                            using (var g = System.Drawing.Graphics.FromImage(bitmap))
                                g.DrawImage(fbitmap, (int)numTurretOffsetX.Value, (int)numTurretOffsetY.Value);
                            BitmapEx[i] = bitmap;
                        }
                        frexp = limit;
                    }
                }
                }
                else
                {
                    for (int i = 1; i <= shpold.ImageCount; i++)
                    {
                        BitmapEx[i] = new Bitmap(shpold.Width, shpold.Height);
                        BitmapEx[i] = (Bitmap)FramesEx[i];
                    }
                    frexp = shpold.ImageCount;
                }
                if ((turretToolStripMenuItem.Checked == false) && (shadowToolStripMenuItem.Checked == false))
                {
                    for (int i = 1; i <= shpold.ImageCount; i++)
                    {
                        BitmapEx[i] = new Bitmap(shpold.Width, shpold.Height);
                        BitmapEx[i] = (Bitmap)FramesEx[i];
                    }
                    frexp = shpold.ImageCount;
                }
            }
            remapmain = pbColor.BackColor;
            if (ExportFormat == ImageFormat.Png)
            {
                string changed = Path.ChangeExtension(filename, "");
                changed = changed.Replace('.', ' ');
                for (int i = 0; i < frexp; i++)
                {
                    int num = 0;
                    if (i > 0) { num = GetIntegerDigitCount(i); }
                    string filen = "000";
                    switch (num)
                    {
                        case 1:
                            filen = "000";
                            break;
                        case 2:
                            filen = "00";
                            break;
                        case 3:
                            filen = "00";
                            break;
                        case 4:
                            filen = "";
                            break;
                        default:
                            filen = "000";
                            break;
                    }
                    BitmapEx[i + 1].Save((changed + filen + i.ToString() + ".png"), ImageFormat.Png);
                }
            }
            if (ExportFormat == ImageFormat.Gif)
            {
                string changed = Path.ChangeExtension(filename, ".gif");
                String outputFilePath = changed;
                AnimatedGifEncoder e = new AnimatedGifEncoder();
                e.Start(outputFilePath);
                e.SetDelay(66);
                //-1:no repeat,0:always repeat
                e.SetRepeat(0);
                for (int i = 0; i < frexp; i++)
                {
                    e.AddFrame((Image)BitmapEx[i + 1]);
                }
                e.Finish();
            }
        }
Esempio n. 30
0
        public Bitmap RenderPNG(Palette p, int pos)
        {
            Bitmap bmp = png.ToBitmap(pos);

            if (mnuRemap.Checked)
            {
                byte hk = Convert.ToByte(pbColor.BackColor.GetHue() * 0.7 + 1);
                byte s = Convert.ToByte(pbColor.BackColor.GetSaturation() * 255);
                byte l = Convert.ToByte(pbColor.BackColor.GetBrightness() * 255);
                ColorRamp CRamp = new ColorRamp(hk, s, l, 25);

                for (int x = 0; x < bmp.Width - 1; x++)
                {
                    for (int y = 0; y < bmp.Height - 1; y++)
                    {
                        Color c = bmp.GetPixel(x, y);
                        c = Color.FromArgb(c.A, CalculateHueChange(c, CRamp.GetColor(0).GetHue(), CRamp.GetColor(0).GetSaturation(), CRamp.GetColor(0).GetBrightness()));
                        bmp.SetPixel(x, y, c);
                    }
                }
            }

            return bmp;
        }
Esempio n. 31
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();
            }
        }
Esempio n. 32
0
 public Palette(Palette p, IPaletteRemap r)
 {
     colors = (uint[])p.colors.Clone();
     ApplyRemap(r);
 }