private void LoadDeltas(string fileName) { var dict = TextureAtlas.Deserialize <TextureAtlasDeltas>(fileName); _deltaImage = new LockBitmap((Bitmap)Image.FromFile(Extensions.CheckDirectorySeparator(Path.GetDirectoryName(fileName)) + dict.ImagePath)); TextureAtlasSprites.MergeDeltas(_spriteListWindow.TextureAltas.SpriteDictionary, dict.DeltaDictionary); }
private void LoadSprites(string fileName) { var dict = TextureAtlas.Deserialize <TextureAtlasSprites>(fileName); TextureAtlasSprites.FillSpriteId(dict.SpriteDictionary); _spriteListWindow.TextureAltas = dict; _spriteImage = new LockBitmap((Bitmap)_spriteListWindow.Image); }
private void PaintSprite() { var item = _spriteListWindow.SelectedSprite; var remap = _spriteRemapsWindow.SelectedItem; int palette = remap.Key == -1 ? _spriteListWindow.SelectedSprite.DefaultPalette : remap.Palette; var activeDeltas = _spriteDeltasWindow.CheckedDeltaItems; Image previousImage = null; if (_spritePreviewWindow.Image != null) { previousImage = _spritePreviewWindow.Image; } var outputBitmap = new LockBitmap(new Bitmap(item.Rectangle.Width, item.Rectangle.Height)); outputBitmap.LockBits(); for (var x = 0; x < item.Rectangle.Width; x++) { for (var y = 0; y < item.Rectangle.Height; y++) { var value = _spriteData[item.Rectangle.X + x, item.Rectangle.Y + y]; if (value != 0) { outputBitmap.SetPixel(x, y, _paletteImage.GetPixel(palette, value)); } } } foreach (var delta in activeDeltas) { for (var x = 0; x < delta.Rectangle.Width; x++) { for (var y = 0; y < delta.Rectangle.Height; y++) { var value = _deltaData[delta.Rectangle.X + x, delta.Rectangle.Y + y]; if (value != 0) { outputBitmap.SetPixel(delta.RelativePosition.X + x, delta.RelativePosition.Y + y, _paletteImage.GetPixel(palette, value)); } } } } outputBitmap.UnlockBits(); _spritePreviewWindow.Image = outputBitmap.Source; if (previousImage != null) { previousImage.Dispose(); } }
private static int DetectPalette(LockBitmap palettes, LockBitmap lockBmp, CompactRectangle rect) { var max = 0; var value = -1; var dict = new Dictionary <int, List <Color> >(); for (var i = 0; i < palettes.Width; i++) { dict.Add(i, new List <Color>()); for (var x = rect.X; x < rect.X + rect.Width; x++) { for (var y = rect.Y; y < rect.Y + rect.Height; y++) { var orgColor = lockBmp.GetPixel(x, y); for (var c = 0; c < 256; c++) { if (orgColor != palettes.GetPixel(i, c)) { continue; } if (!dict[i].Contains(orgColor)) { dict[i].Add(orgColor); } if (dict[i].Count <= max) { continue; } value = i; max = dict[i].Count; } } } } return(value); }
private void PaintSprite() { var item = _spriteListWindow.SelectedSprite; var remap = _spriteRemapsWindow.SelectedItem; int palette = remap.Key == -1 ? _spriteListWindow.SelectedSprite.DefaultPalette : remap.Palette; var activeDeltas = _spriteDeltasWindow.CheckedDeltaItems; Image previousImage = null; if (_spritePreviewWindow.Image != null) previousImage = _spritePreviewWindow.Image; var outputBitmap = new LockBitmap(new Bitmap(item.Rectangle.Width, item.Rectangle.Height)); outputBitmap.LockBits(); for (var x = 0; x < item.Rectangle.Width; x++) { for (var y = 0; y < item.Rectangle.Height; y++) { var value = _spriteData[item.Rectangle.X + x, item.Rectangle.Y + y]; if (value != 0) outputBitmap.SetPixel(x, y, _paletteImage.GetPixel(palette, value)); } } foreach (var delta in activeDeltas) { for (var x = 0; x < delta.Rectangle.Width; x++) { for (var y = 0; y < delta.Rectangle.Height; y++) { var value = _deltaData[delta.Rectangle.X + x, delta.Rectangle.Y + y]; if (value != 0) outputBitmap.SetPixel(delta.RelativePosition.X + x, delta.RelativePosition.Y + y, _paletteImage.GetPixel(palette, value)); } } } outputBitmap.UnlockBits(); _spritePreviewWindow.Image = outputBitmap.Source; if (previousImage != null) previousImage.Dispose(); }
private void LoadSprites(string fileName) { var dict = TextureAtlas.Deserialize<TextureAtlasSprites>(fileName); TextureAtlasSprites.FillSpriteId(dict.SpriteDictionary); _spriteListWindow.TextureAltas = dict; _spriteImage = new LockBitmap((Bitmap) _spriteListWindow.Image); }
private void LoadPalette(string fileName) { var image = Image.FromFile(fileName); _paletteImage = new LockBitmap((Bitmap) image); }
private void LoadDeltas(string fileName) { var dict = TextureAtlas.Deserialize<TextureAtlasDeltas>(fileName); _deltaImage = new LockBitmap((Bitmap) Image.FromFile(Extensions.CheckDirectorySeparator(Path.GetDirectoryName(fileName)) + dict.ImagePath)); TextureAtlasSprites.MergeDeltas(_spriteListWindow.TextureAltas.SpriteDictionary, dict.DeltaDictionary); }
private static int DetectPalette(LockBitmap palettes, LockBitmap lockBmp, CompactRectangle rect) { var max = 0; var value = -1; var dict = new Dictionary<int, List<Color>>(); for (var i = 0; i < palettes.Width; i++) { dict.Add(i, new List<Color>()); for (var x = rect.X; x < rect.X + rect.Width; x++) { for (var y = rect.Y; y < rect.Y + rect.Height; y++) { var orgColor = lockBmp.GetPixel(x, y); for (var c = 0; c < 256; c++) { if (orgColor != palettes.GetPixel(i, c)) continue; if (!dict[i].Contains(orgColor)) dict[i].Add(orgColor); if (dict[i].Count <= max) continue; value = i; max = dict[i].Count; } } } } return value; }
private void LoadPalette(string fileName) { var image = Image.FromFile(fileName); _paletteImage = new LockBitmap((Bitmap)image); }